      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 1670 2013-09-12 20:41:08Z 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:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('version_num')) : 'version_num');
    129:         echo '<input type="hidden" name="'.$fieldname.'" value="'.$this->BO->getVersion().'"/>';
    130:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('article_comment_id')) : 'article_comment_id');
    131:         echo '<input type="hidden" name="'.$fieldname.'" value="'.$this->BO->getID().'"/>';
    132:
    133:         // render special buttons for admins only
    134:         if ($_SESSION['currentUser']->inGroup('Admin') && strpos($_SERVER['REQUEST_URI'], '/tk/') !== false) {
    135:             echo '<tr><td colspan="2">';
    136:
    137:             $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('saveBut')) : 'saveBut');
    138:             $temp = new Button('submit', 'Save', $fieldname);
    139:             echo $temp->render();
    140:             echo '&nbsp;&nbsp;';
    141:             $js = "$('#dialogDiv').text('Are you sure you wish to delete this item?');
    142:                 $('#dialogDiv').dialog({
    143:                 buttons: {
    144:                     'OK': function(event, ui) {
    145:                         $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(AlphaSecurityUtils::encrypt('deleteOID')) : 'deleteOID')."\"]').attr('value', '".$this->BO->getOID()."');
    146:                         $('#deleteForm').submit();
    147:                     },
    148:                     'Cancel': function(event, ui) {
    149:                         $(this).dialog('close');
    150:                     }
    151:                 }
    152:             })
    153:             $('#dialogDiv').dialog('open');
    154:             return false;";
    155:             $temp = new Button($js, "Delete", "deleteBut");
    156:             echo $temp->render();
    157:             echo '&nbsp;&nbsp;';
    158:             $temp = new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'",'Back to List','cancelBut');
    159:             echo $temp->render();
    160:             echo '</td></tr>';
    161:
    162:             echo AlphaView::renderSecurityFields();
    163:
    164:             echo '</form></table>';
    165:         }else{
    166:             echo '</table>';
    167:
    168:             echo '<div align="center">';
    169:             $temp = new Button('submit', 'Update Your Comment', 'saveBut'.$this->BO->getID());
    170:             echo $temp->render();
    171:             echo '</div>';
    172:
    173:             echo AlphaView::renderSecurityFields();
    174:
    175:             echo '</form>';
    176:         }
    177:     }
    178: }
    179:
    180: ?>