Overview

Namespaces

  • Alpha
    • Controller
      • Front
    • Exception
    • Model
      • Type
    • Task
    • Util
      • Backup
      • Cache
      • Code
        • Highlight
        • Metric
      • Config
      • Convertor
      • Email
      • Extension
      • Feed
      • File
      • Graph
      • Helper
      • Http
        • Filter
        • Session
      • Image
      • Logging
      • Search
      • Security
    • View
      • Renderer
        • Html
        • Json
      • Widget

Classes

  • ArticleCommentView
  • ArticleView
  • DEnumView
  • PersonView
  • SequenceView
  • View
  • ViewState
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace Alpha\View;
  4: 
  5: use Alpha\Util\Config\ConfigProvider;
  6: use Alpha\Util\Extension\MarkdownFacade;
  7: use Alpha\Util\Security\SecurityUtils;
  8: use Alpha\Util\Http\Session\SessionProviderFactory;
  9: use Alpha\Model\Person;
 10: use Alpha\View\Widget\TextBox;
 11: use Alpha\View\Widget\Button;
 12: use Alpha\Controller\Front\FrontController;
 13: 
 14: /**
 15:  * The rendering class for the ArticleComment class.
 16:  *
 17:  * @since 1.0
 18:  *
 19:  * @author John Collins <dev@alphaframework.org>
 20:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 21:  * @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework).
 22:  * All rights reserved.
 23:  *
 24:  * <pre>
 25:  * Redistribution and use in source and binary forms, with or
 26:  * without modification, are permitted provided that the
 27:  * following conditions are met:
 28:  *
 29:  * * Redistributions of source code must retain the above
 30:  *   copyright notice, this list of conditions and the
 31:  *   following disclaimer.
 32:  * * Redistributions in binary form must reproduce the above
 33:  *   copyright notice, this list of conditions and the
 34:  *   following disclaimer in the documentation and/or other
 35:  *   materials provided with the distribution.
 36:  * * Neither the name of the Alpha Framework nor the names
 37:  *   of its contributors may be used to endorse or promote
 38:  *   products derived from this software without specific
 39:  *   prior written permission.
 40:  *
 41:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 42:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 43:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 44:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 45:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 46:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 47:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 48:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 49:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 50:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 51:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 52:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 53:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 54:  * </pre>
 55:  */
 56: class ArticleCommentView extends View
 57: {
 58:     /**
 59:      * Method to generate the markdown HTML render of the ArticleComment content.
 60:      *
 61:      * @param array $fields hash array of HTML fields to pass to the template
 62:      *
 63:      * @since 1.0
 64:      *
 65:      * @return string
 66:      */
 67:     public function markdownView($fields = array())
 68:     {
 69:         $config = ConfigProvider::getInstance();
 70:         $sessionProvider = $config->get('session.provider.name');
 71:         $session = SessionProviderFactory::getInstance($sessionProvider);
 72: 
 73:         $markdown = new MarkdownFacade($this->BO);
 74:         $author = new Person();
 75:         $id = $this->BO->getCreatorID();
 76:         $author->load($id->getValue());
 77: 
 78:         $html = '<blockquote class="usercomment">';
 79: 
 80:         $createTS = $this->BO->getCreateTS();
 81:         $updateTS = $this->BO->getUpdateTS();
 82: 
 83:         $html .= '<p>Posted by '.($author->get('URL') == '' ? $author->get('displayname') : '<a href="'.$author->get('URL').'" target="new window">'.$author->get('displayname').'</a>').' at '.$createTS->getValue().'.';
 84:         $html .= '&nbsp;'.$author->get('displayname').' has posted ['.$author->getCommentCount().'] comments on articles since joining.';
 85:         $html .= '</p>';
 86:         if ($config->get('cms.comments.allowed') && $session->get('currentUser') != null && $session->get('currentUser')->getID() == $author->getID()) {
 87:             $html .= $this->editView($fields);
 88:         } else {
 89:             $html .= $markdown->getContent();
 90:         }
 91: 
 92:         if ($createTS->getValue() != $updateTS->getValue()) {
 93:             $updator = new Person();
 94:             $id = $this->BO->getCreatorID();
 95:             $updator->load($id->getValue());
 96:             $html .= '<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>';
 97:         }
 98:         $html .= '</blockquote>';
 99: 
100:         return $html;
101:     }
102: 
103:     /**
104:      * Renders the custom create view.
105:      *
106:      * @param array $fields hash array of HTML fields to pass to the template
107:      *
108:      * @since 1.0
109:      *
110:      * @return string
111:      */
112:     public function createView($fields = array())
113:     {
114:         $config = ConfigProvider::getInstance();
115: 
116:         $html = '<h2>Post a new comment:</h2>';
117: 
118:         $html .= '<table cols="2" class="create_view">';
119:         $html .= '<form action="'.$fields['formAction'].'" method="POST" accept-charset="UTF-8">';
120: 
121:         $textBox = new TextBox($this->BO->getPropObject('content'), $this->BO->getDataLabel('content'), 'content', '', 10);
122:         $html .= $textBox->render();
123: 
124:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('articleOID')) : 'articleOID');
125:         $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->BO->get('articleOID').'"/>';
126:         $html .= '<tr><td colspan="2">';
127: 
128:         $button = new Button('submit', 'Post Comment', 'createCommentBut');
129:         $html .= $button->render();
130: 
131:         $html .= '</td></tr>';
132: 
133:         $html .= View::renderSecurityFields();
134: 
135:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('statusMessage')) : 'statusMessage');
136:         $html .= '<input type="hidden" name="'.$fieldname.'" value="Thank you for your comment!"/>';
137: 
138:         $html .= '</form></table>';
139:         $html .= '<p class="warning">Please note that any comment you post may be moderated for spam or offensive material.</p>';
140: 
141:         return $html;
142:     }
143: 
144:     /**
145:      * Custom edit view.
146:      *
147:      * @param array $fields Hash array of HTML fields to pass to the template.
148:      *
149:      * @since 1.0
150:      *
151:      * @return string
152:      */
153:     public function editView($fields = array())
154:     {
155:         $config = ConfigProvider::getInstance();
156:         $sessionProvider = $config->get('session.provider.name');
157:         $session = SessionProviderFactory::getInstance($sessionProvider);
158: 
159:         $html = '<table cols="2" class="edit_view" style="width:100%; margin:0px">';
160:         $html .= '<form action="'.$fields['formAction'].'" method="POST" accept-charset="UTF-8">';
161: 
162:         $textBox = new TextBox($this->BO->getPropObject('content'), $this->BO->getDataLabel('content'), 'content', '', 5, $this->BO->getID());
163:         $html .= $textBox->render();
164: 
165:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('version_num')) : 'version_num');
166:         $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->BO->getVersion().'"/>';
167:         $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID');
168:         $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->BO->getID().'"/>';
169: 
170:         // render special buttons for admins only
171:         if ($session->get('currentUser')->inGroup('Admin') && strpos($fields['formAction'], '/tk/') !== false) {
172:             $html .= '<tr><td colspan="2">';
173: 
174:             $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('saveBut')) : 'saveBut');
175:             $temp = new Button('submit', 'Save', $fieldname);
176:             $html .= $temp->render();
177:             $html .= '&nbsp;&nbsp;';
178:             $js = "$('#dialogDiv').text('Are you sure you wish to delete this item?');
179:                 $('#dialogDiv').dialog({
180:                 buttons: {
181:                     'OK': function(event, ui) {
182:                         $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID')."\"]').attr('value', '".$this->BO->getOID()."');
183:                         $('#deleteForm').submit();
184:                     },
185:                     'Cancel': function(event, ui) {
186:                         $(this).dialog('close');
187:                     }
188:                 }
189:             })
190:             $('#dialogDiv').dialog('open');
191:             return false;";
192:             $temp = new Button($js, 'Delete', 'deleteBut');
193:             $html .= $temp->render();
194:             $html .= '&nbsp;&nbsp;';
195:             $temp = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.get_class($this->BO))."'", 'Back to List', 'cancelBut');
196:             $html .= $temp->render();
197:             $html .= '</td></tr>';
198: 
199:             $html .= View::renderSecurityFields();
200: 
201:             $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('_METHOD')) : '_METHOD');
202:             $html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value="PUT"/>';
203: 
204:             $html .= '</form></table>';
205:         } else {
206:             $html .= '</table>';
207: 
208:             $html .= '<div align="center">';
209:             $temp = new Button('submit', 'Update Your Comment', 'saveBut'.$this->BO->getID());
210:             $html .= $temp->render();
211:             $html .= '</div>';
212: 
213:             $html .= View::renderSecurityFields();
214: 
215:             $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('_METHOD')) : '_METHOD');
216:             $html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value="PUT"/>';
217: 
218:             $html .= '</form>';
219:         }
220: 
221:         return $html;
222:     }
223: }
224: 
Alpha Framework 2.0.4 API Documentation API documentation generated by ApiGen 2.8.0