      1: <?php
      2:
      3: /**
      4:  *
      5:  * The rendering class for the ArticleCommentObject class
      6:  *
      7:  * @package alpha::view
      8:  * @since 1.0
      9:  * @author John Collins <dev@alphaframework.org>
     10:  * @version $Id: ArticleCommentView.inc 1581 2012-10-30 15:48:57Z alphadevx $
     11:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
     12:  * @copyright Copyright (c) 2012, John Collins (founder of Alpha Framework).
     13:  * All rights reserved.
     14:  *
     15:  * <pre>
     16:  * Redistribution and use in source and binary forms, with or
     17:  * without modification, are permitted provided that the
     18:  * following conditions are met:
     19:  *
     20:  * * Redistributions of source code must retain the above
     21:  *   copyright notice, this list of conditions and the
     22:  *   following disclaimer.
     23:  * * Redistributions in binary form must reproduce the above
     24:  *   copyright notice, this list of conditions and the
     25:  *   following disclaimer in the documentation and/or other
     26:  *   materials provided with the distribution.
     27:  * * Neither the name of the Alpha Framework nor the names
     28:  *   of its contributors may be used to endorse or promote
     29:  *   products derived from this software without specific
     30:  *   prior written permission.
     31:  *
     32:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
     33:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
     34:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     35:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     36:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
     37:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     38:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     39:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     40:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     41:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     42:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     43:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     44:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     45:  * </pre>
     46:  *
     47:  */
     48: class ArticleCommentView extends AlphaView {
     49:     /**
     50:      * Method to generate the markdown HTML render of the ArticleComment content
     51:      *
     52:      * @since 1.0
     53:      */
     54:     public function markdownView() {
     55:         global $config;
     56:
     57:         $markdown = new MarkdownFacade($this->BO);
     58:         $author = new PersonObject();
     59:         $id = $this->BO->getCreatorID();
     60:         $author->load($id->getValue());
     61:
     62:         echo '<blockquote class="usercomment">';
     63:
     64:         $createTS = $this->BO->getCreateTS();
     65:         $updateTS = $this->BO->getUpdateTS();
     66:
     67:         echo '<p>Posted by '.($author->get('URL') == ''? $author->get('displayname') : '<a href="'.$author->get('URL').'" target="new window">'.$author->get('displayname').'</a>').' at '.$createTS->getValue().'.';
     68:         echo '&nbsp;'.$author->get('displayname').' has posted ['.$author->getCommentCount().'] comments on articles since joining.';
     69:         echo '</p>';
     70:         if($config->get('cms.comments.allowed') && isset($_SESSION['currentUser']) && $_SESSION['currentUser']->getID() == $author->getID())
     71:             $this->editView();
     72:         else
     73:             echo $markdown->getContent();
     74:
     75:         if($createTS->getValue() != $updateTS->getValue()) {
     76:             $updator = new PersonObject();
     77:             $id = $this->BO->getCreatorID();
     78:             $updator->load($id->getValue());
     79:             echo '<p>Updated by '.($updator->get('URL') == ''? $updator->get('displayname') : '<a href="'.$updator->get('URL').'" target="new window">'.$updator->get('displayname').'</a>').' at '.$updateTS->getValue().'.</p>';
     80:         }
     81:         echo '</blockquote>';
     82:     }
     83:
     84:     /**
     85:      * Renders the custom create view
     86:      *
     87:      * @param array $fields hash array of HTML fields to pass to the template
     88:      * @since 1.0
     89:      */
     90:     public function createView($fields=array()) {
     91:         echo '<h2>Post a new comment:</h2>';
     92:
     93:         echo '<table cols="2" class="create_view">';
     94:         echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST">';
     95:
     96:         $textBox = new TextBox($this->BO->getPropObject('content'), $this->BO->getDataLabel('content'), 'content', '', 10);
     97:         echo $textBox->render();
     98:
     99:         echo '<input type="hidden" name="articleOID" value="'.$this->BO->get('articleOID').'"/>';
    100:         echo '<tr><td colspan="2">';
    101:
    102:         $button = new Button('submit', 'Post Comment', 'createBut');
    103:         echo $button->render();
    104:
    105:         echo '</td></tr>';
    106:
    107:         echo AlphaView::renderSecurityFields();
    108:
    109:         echo '</form></table>';
    110:         echo '<p class="warning">Please note that any comment you post may be moderated for spam or offensive material.</p>';
    111:     }
    112:
    113:     /**
    114:      * Custom edit view
    115:      *
    116:      * @param array $fields Hash array of HTML fields to pass to the template.
    117:      * @since 1.0
    118:      */
    119:     public function editView($fields=array()) {
    120:         global $config;
    121:
    122:         echo '<table cols="2" class="edit_view" style="width:100%; margin:0px">';
    123:         echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST">';
    124:
    125:         $textBox = new TextBox($this->BO->getPropObject('content'), $this->BO->getDataLabel('content'), 'content', '', 5, $this->BO->getID());
    126:         echo $textBox->render();
    127:
    128:         echo '<input type="hidden" name="version_num" value="'.$this->BO->getVersion().'"/>';
    129:         echo '<input type="hidden" name="article_comment_id" value="'.$this->BO->getID().'"/>';
    130:
    131:         // render special buttons for admins only
    132:         if ($_SESSION['currentUser']->inGroup('Admin') && strpos($_SERVER['REQUEST_URI'], '/tk/') !== false) {
    133:             echo '<tr><td colspan="2">';
    134:
    135:             $temp = new Button('submit', 'Save', 'saveBut');
    136:             echo $temp->render();
    137:             echo '&nbsp;&nbsp;';
    138:             $js = "$('#dialogDiv').text('Are you sure you wish to delete this item?');
    139:                 $('#dialogDiv').dialog({
    140:                 buttons: {
    141:                     'OK': function(event, ui) {
    142:                         $('#deleteOID').attr('value', '".$this->BO->getOID()."');
    143:                         $('#deleteForm').submit();
    144:                     },
    145:                     'Cancel': function(event, ui) {
    146:                         $(this).dialog('close');
    147:                     }
    148:                 }
    149:             })
    150:             $('#dialogDiv').dialog('open');
    151:             return false;";
    152:             $temp = new Button($js, "Delete", "deleteBut");
    153:             echo $temp->render();
    154:             echo '&nbsp;&nbsp;';
    155:             $temp = new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'",'Back to List','cancelBut');
    156:             echo $temp->render();
    157:             echo '</td></tr>';
    158:
    159:             echo AlphaView::renderSecurityFields();
    160:
    161:             echo '</form></table>';
    162:         }else{
    163:             echo '</table>';
    164:
    165:             echo '<div align="center">';
    166:             $temp = new Button('submit', 'Update Your Comment', 'saveBut'.$this->BO->getID());
    167:             echo $temp->render();
    168:             echo '</div>';
    169:
    170:             echo AlphaView::renderSecurityFields();
    171:
    172:             echo '</form>';
    173:         }
    174:     }
    175: }
    176:
    177: ?>