/** * Handle GET requests. * * @param Alpha\Util\Http\Response $request * * @throws Alpha\Exception\IllegalArguementException * * @return Alpha\Util\Http\Response * * @since 1.0 */ public function doGET($request) { self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])'); $params = $request->getParams(); $config = ConfigProvider::getInstance(); if (!is_array($params)) { throw new IllegalArguementException('Bad $params [' . var_export($params, true) . '] passed to doGET method!'); } $body = View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $body .= '<h3>Listing contents of cache directory: ' . $this->dataDir . '</h3>'; $fileList = ''; $fileCount = FileUtils::listDirectoryContents($this->dataDir, $fileList, 0, array('.htaccess')); $body .= $fileList; $body .= '<h3>Total of ' . $fileCount . ' files in the cache.</h3>'; $body .= '<form action="' . $request->getURI() . '" method="post" name="clearForm" id="clearForm">'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('clearCache')) : 'clearCache'; $body .= '<input type="hidden" name="' . $fieldname . '" id="' . $fieldname . '" value="false"/>'; $js = "if(window.jQuery) {\n BootstrapDialog.show({\n title: 'Confirmation',\n message: 'Are you sure you want to delete all files in the cache?',\n buttons: [\n {\n icon: 'glyphicon glyphicon-remove',\n label: 'Cancel',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself){\n dialogItself.close();\n }\n },\n {\n icon: 'glyphicon glyphicon-ok',\n label: 'Okay',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself) {\n \$('[id=\"" . $fieldname . "\"]').attr('value', 'true');\n \$('#clearForm').submit();\n dialogItself.close();\n }\n }\n ]\n });\n }"; $button = new Button($js, 'Clear cache', 'clearBut'); $body .= $button->render(); $body .= View::renderSecurityFields(); $body .= '</form>'; $body .= View::displayPageFoot($this); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * Custom edit view. * * @param array $fields Hash array of HTML fields to pass to the template. * * @since 1.0 * * @return string */ public function editView($fields = array()) { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $html = '<table cols="2" class="edit_view" style="width:100%; margin:0px">'; $html .= '<form action="' . $fields['formAction'] . '" method="POST" accept-charset="UTF-8">'; $textBox = new TextBox($this->BO->getPropObject('content'), $this->BO->getDataLabel('content'), 'content', '', 5, $this->BO->getID()); $html .= $textBox->render(); $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('version_num')) : 'version_num'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . $this->BO->getVersion() . '"/>'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . $this->BO->getID() . '"/>'; // render special buttons for admins only if ($session->get('currentUser')->inGroup('Admin') && strpos($fields['formAction'], '/tk/') !== false) { $html .= '<tr><td colspan="2">'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('saveBut')) : 'saveBut'; $temp = new Button('submit', 'Save', $fieldname); $html .= $temp->render(); $html .= ' '; $js = "\$('#dialogDiv').text('Are you sure you wish to delete this item?');\n \$('#dialogDiv').dialog({\n buttons: {\n 'OK': function(event, ui) {\n \$('[id=\"" . ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID') . "\"]').attr('value', '" . $this->BO->getOID() . "');\n \$('#deleteForm').submit();\n },\n 'Cancel': function(event, ui) {\n \$(this).dialog('close');\n }\n }\n })\n \$('#dialogDiv').dialog('open');\n return false;"; $temp = new Button($js, 'Delete', 'deleteBut'); $html .= $temp->render(); $html .= ' '; $temp = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . get_class($this->BO)) . "'", 'Back to List', 'cancelBut'); $html .= $temp->render(); $html .= '</td></tr>'; $html .= View::renderSecurityFields(); $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('_METHOD')) : '_METHOD'; $html .= '<input type="hidden" name="' . $fieldname . '" id="' . $fieldname . '" value="PUT"/>'; $html .= '</form></table>'; } else { $html .= '</table>'; $html .= '<div align="center">'; $temp = new Button('submit', 'Update Your Comment', 'saveBut' . $this->BO->getID()); $html .= $temp->render(); $html .= '</div>'; $html .= View::renderSecurityFields(); $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('_METHOD')) : '_METHOD'; $html .= '<input type="hidden" name="' . $fieldname . '" id="' . $fieldname . '" value="PUT"/>'; $html .= '</form>'; } return $html; }
/** * Callback used to render footer content, including comments, votes and print/PDF buttons when * enabled to do so. * * @return string * * @since 1.0 */ public function before_displayPageFoot_callback() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $html = ''; $params = $this->request->getParams(); // this will ensure that direct requests to ActiveRecordController will be re-directed here. if (isset($this->record) && !$this->record->isTransient()) { $this->setName($config->get('app.url') . $this->request->getURI()); $this->setUnitOfWork(array($config->get('app.url') . $this->request->getURI(), $config->get('app.url') . $this->request->getURI())); } else { $this->setUnitOfWork(array()); } if ($this->record != null) { if (isset($params['view']) && $params['view'] == 'detailed') { if ($config->get('cms.display.comments')) { $html .= $this->renderComments(); } if ($config->get('cms.display.tags')) { $tags = $this->record->getPropObject('tags')->getRelatedObjects(); if (count($tags) > 0) { $html .= '<p>Tags:'; foreach ($tags as $tag) { $html .= ' <a href="' . $config->get('app.url') . '/search/' . $tag->get('content') . '">' . $tag->get('content') . '</a>'; } $html .= '</p>'; } } if ($config->get('cms.display.votes')) { $rating = $this->record->getArticleScore(); $votes = $this->record->getArticleVotes(); $html .= '<p>Average Article User Rating: <strong>' . $rating . '</strong> out of 10 (based on <strong>' . count($votes) . '</strong> votes)</p>'; } if (!$this->record->checkUserVoted() && $config->get('cms.voting.allowed')) { $URL = FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=Alpha\\Model\\ArticleVote'); $html .= '<form action="' . $URL . '" method="post" accept-charset="UTF-8">'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('score')) : 'score'; $html .= '<p>Please rate this article from 1-10 (10 being the best):' . '<select name="' . $fieldname . '">' . '<option value="1">1' . '<option value="2">2' . '<option value="3">3' . '<option value="4">4' . '<option value="5">5' . '<option value="6">6' . '<option value="7">7' . '<option value="8">8' . '<option value="9">9' . '<option value="10">10' . '</select></p> '; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('articleOID')) : 'articleOID'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . $this->record->getOID() . '"/>'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('personOID')) : 'personOID'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . $session->get('currentUser')->getID() . '"/>'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('statusMessage')) : 'statusMessage'; $html .= '<input type="hidden" name="' . $fieldname . '" value="Thank you for rating this article!"/>'; $temp = new Button('submit', 'Vote!', 'voteBut'); $html .= $temp->render(); $html .= View::renderSecurityFields(); $html .= '<form>'; } ActiveRecord::disconnect(); if ($config->get('cms.allow.print.versions')) { $html .= ' '; $temp = new Button("window.open('" . $this->record->get('printURL') . "')", 'Open Printer Version', 'printBut'); $html .= $temp->render(); } $html .= ' '; if ($config->get('cms.allow.pdf.versions')) { $html .= ' '; $temp = new Button("document.location = '" . FrontController::generateSecureURL("act=Alpha\\Controller\\ArticleController&mode=pdf&title=" . $this->record->get('title')) . "';", 'Open PDF Version', 'pdfBut'); $html .= $temp->render(); } // render edit button for admins only if ($session->get('currentUser') instanceof Alpha\Model\Person && $session->get('currentUser')->inGroup('Admin')) { $html .= ' '; $button = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ArticleController&mode=edit&ActiveRecordOID=' . $this->record->getID()) . "'", 'Edit', 'editBut'); $html .= $button->render(); } } if ($config->get('cms.display.standard.footer')) { $html .= '<p>Article URL: <a href="' . $this->record->get('URL') . '">' . $this->record->get('URL') . '</a><br>'; $html .= 'Title: ' . $this->record->get('title') . '<br>'; $html .= 'Author: ' . $this->record->get('author') . '</p>'; } } $html .= $config->get('cms.footer'); return $html; }
/** * Handle GET requests. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @throws Alpha\Exception\IllegalArguementException * @throws Alpha\Exception\FileNotFoundException * * @since 1.0 */ public function doGET($request) { self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])'); $params = $request->getParams(); $config = ConfigProvider::getInstance(); $body = ''; // render the tag manager screen if (!isset($params['ActiveRecordType']) && !isset($params['ActiveRecordOID'])) { $body .= View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $body .= '<h3>Listing active record which are tagged</h3>'; $ActiveRecordTypes = ActiveRecord::getBOClassNames(); foreach ($ActiveRecordTypes as $ActiveRecordType) { $record = new $ActiveRecordType(); if ($record->isTagged()) { $tag = new Tag(); $count = count($tag->loadAllByAttribute('taggedClass', $ActiveRecordType)); $body .= '<h4>' . $record->getFriendlyClassName() . ' record type is tagged (' . $count . ' tags found)</h4>'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('clearTaggedClass')) : 'clearTaggedClass'; $js = "if(window.jQuery) {\n BootstrapDialog.show({\n title: 'Confirmation',\n message: 'Are you sure you want to delete all tags attached to the " . $record->getFriendlyClassName() . " class, and have them re-created?',\n buttons: [\n {\n icon: 'glyphicon glyphicon-remove',\n label: 'Cancel',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself){\n dialogItself.close();\n }\n },\n {\n icon: 'glyphicon glyphicon-ok',\n label: 'Okay',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself) {\n \$('[id=\"" . $fieldname . "\"]').attr('value', '" . addslashes($ActiveRecordType) . "');\n \$('#clearForm').submit();\n dialogItself.close();\n }\n }\n ]\n });\n }"; $button = new Button($js, 'Re-create tags', 'clearBut' . stripslashes($ActiveRecordType)); $body .= $button->render(); } } ActiveRecord::disconnect(); $body .= '<form action="' . $request->getURI() . '" method="POST" id="clearForm">'; $body .= '<input type="hidden" name="' . $fieldname . '" id="' . $fieldname . '"/>'; $body .= View::renderSecurityFields(); $body .= '</form>'; } elseif (isset($params['ActiveRecordType']) && $params['ActiveRecordType'] != 'Alpha\\Model\\Tag' && isset($params['ActiveRecordOID'])) { // render screen for managing individual tags on a given active record $body .= View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $ActiveRecordType = urldecode($params['ActiveRecordType']); $ActiveRecordOID = $params['ActiveRecordOID']; if (class_exists($ActiveRecordType)) { $record = new $ActiveRecordType(); } else { throw new IllegalArguementException('No ActiveRecord available to display tags for!'); } try { $record->load($ActiveRecordOID); $tags = $record->getPropObject('tags')->getRelatedObjects(); ActiveRecord::disconnect(); $body .= '<form action="' . $request->getURI() . '" method="POST" accept-charset="UTF-8">'; $body .= '<h3>The following tags were found:</h3>'; foreach ($tags as $tag) { $labels = $tag->getDataLabels(); $temp = new StringBox($tag->getPropObject('content'), $labels['content'], 'content_' . $tag->getID(), ''); $body .= $temp->render(false); $js = "if(window.jQuery) {\n BootstrapDialog.show({\n title: 'Confirmation',\n message: 'Are you sure you wish to delete this tag?',\n buttons: [\n {\n icon: 'glyphicon glyphicon-remove',\n label: 'Cancel',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself){\n dialogItself.close();\n }\n },\n {\n icon: 'glyphicon glyphicon-ok',\n label: 'Okay',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself) {\n \$('[id=\"" . ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID') . "\"]').attr('value', '" . $tag->getID() . "');\n \$('#deleteForm').submit();\n dialogItself.close();\n }\n }\n ]\n });\n }"; $button = new Button($js, 'Delete', 'delete' . $tag->getID() . 'But'); $body .= $button->render(); } $body .= '<h3>Add a new tag:</h3>'; $temp = new StringBox(new String(), 'New tag', 'NewTagValue', ''); $body .= $temp->render(false); $temp = new Button('submit', 'Save', 'saveBut'); $body .= $temp->render(); $body .= ' '; if ($params['ActiveRecordType'] = 'Alpha\\Model\\Article') { $temp = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ArticleController&ActiveRecordType=' . $params['ActiveRecordType'] . '&ActiveRecordOID=' . $params['ActiveRecordOID'] . '&view=edit') . "'", 'Back to record', 'cancelBut'); } else { $temp = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . $params['ActiveRecordType'] . '&ActiveRecordOID=' . $params['ActiveRecordOID'] . '&view=edit') . "'", 'Back to record', 'cancelBut'); } $body .= $temp->render(); $body .= View::renderSecurityFields(); $body .= '</form>'; $body .= View::renderDeleteForm($request->getURI()); } catch (RecordNotFoundException $e) { $msg = 'Unable to load the ActiveRecord of id [' . $params['ActiveRecordOID'] . '], error was [' . $e->getMessage() . ']'; self::$logger->error($msg); throw new FileNotFoundException($msg); } } else { return parent::doGET($request); } $body .= View::displayPageFoot($this); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * Custom edit view. * * @return string * * @since 1.0 */ public function editView($fields = array()) { $config = ConfigProvider::getInstance(); $labels = $this->BO->getDataLabels(); $obj_type = ''; $html = '<form action="' . $fields['URI'] . '" method="POST" accept-charset="UTF-8">'; $temp = new StringBox($this->BO->getPropObject('name'), $labels['name'], 'name', '', 0, true, true); $html .= $temp->render(); $html .= '<h3>DEnum display values:</h3>'; // now get all of the options for the enum and render $denum = $this->BO; $tmp = new DEnumItem(); $denumItems = $tmp->loadItems($denum->getID()); foreach ($denumItems as $item) { $labels = $item->getDataLabels(); $temp = new StringBox($item->getPropObject('value'), $labels['value'], 'value_' . $item->getID(), ''); $html .= $temp->render(); } $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('version_num')) : 'version_num'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . $this->BO->getVersion() . '"/>'; $html .= '<h3>Add a new value to the DEnum dropdown list:</h3>'; $temp = new StringBox(new String(), 'Dropdown value', 'new_value', ''); $html .= $temp->render(); $temp = new Button('submit', 'Save', 'saveBut'); $html .= $temp->render(); $html .= ' '; $temp = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\DEnumController') . "'", 'Back to List', 'cancelBut'); $html .= $temp->render(); $html .= ''; $html .= View::renderSecurityFields(); $html .= '</form>'; return $html; }