/** * 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')); }
/** * Handle GET requests. * * @param Alpha\Util\Http\Request * * @return Alpha\Util\Http\Response * * @throws Alpha\Exception\ResourceNotFoundException * * @since 1.0 */ public function doGET($request) { self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])'); $config = ConfigProvider::getInstance(); $params = $request->getParams(); $body = ''; // handle requests for PDFs if (isset($params['title']) && (isset($params['pdf']) || $request->getHeader('Accept') == 'application/pdf')) { try { $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) { $record = new $params['ActiveRecordType'](); } else { $record = new Article(); } $record->loadByAttribute('title', $title); $this->record = $record; ActiveRecord::disconnect(); $pdf = new TCPDFFacade($record); $pdfData = $pdf->getPDFData(); $pdfDownloadName = str_replace(' ', '-', $record->get('title') . '.pdf'); $headers = array('Pragma' => 'public', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Content-Transfer-Encoding' => 'binary', 'Content-Type' => 'application/pdf', 'Content-Length' => strlen($pdfData), 'Content-Disposition' => 'attachment; filename="' . $pdfDownloadName . '";'); return new Response(200, $pdfData, $headers); } catch (IllegalArguementException $e) { self::$logger->error($e->getMessage()); throw new ResourceNotFoundException($e->getMessage()); } catch (RecordNotFoundException $e) { self::$logger->error($e->getMessage()); throw new ResourceNotFoundException($e->getMessage()); } } // view edit article requests if (isset($params['view']) && $params['view'] == 'edit' && (isset($params['title']) || isset($params['ActiveRecordOID']))) { if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) { $record = new $params['ActiveRecordType'](); } else { $record = new Article(); } try { if (isset($params['title'])) { $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); $record->loadByAttribute('title', $title); } else { $record->load($params['ActiveRecordOID']); } } catch (RecordNotFoundException $e) { self::$logger->warn($e->getMessage()); $body .= View::renderErrorPage(404, 'Failed to find the requested article!'); return new Response(404, $body, array('Content-Type' => 'text/html')); } ActiveRecord::disconnect(); $this->record = $record; $view = View::getInstance($record); // set up the title and meta details $this->setTitle($record->get('title') . ' (editing)'); $this->setDescription('Page to edit ' . $record->get('title') . '.'); $this->setKeywords('edit,article'); $body .= View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $body .= $view->editView(array('URI' => $request->getURI())); $body .= View::renderDeleteForm($request->getURI()); $body .= View::displayPageFoot($this); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); } // handle requests for viewing articles if (isset($params['title']) || isset($params['ActiveRecordOID'])) { $KDP = new KPI('viewarticle'); if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) { $record = new $params['ActiveRecordType'](); } else { $record = new Article(); } try { if (isset($params['title'])) { $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); $record->loadByAttribute('title', $title, false, array('OID', 'version_num', 'created_ts', 'updated_ts', 'title', 'author', 'published', 'content', 'headerContent')); } else { $record->load($params['ActiveRecordOID']); } if (!$record->get('published')) { throw new RecordNotFoundException('Attempted to load an article which is not published yet'); } $record->set('tags', $record->getOID()); } catch (IllegalArguementException $e) { self::$logger->warn($e->getMessage()); throw new ResourceNotFoundException('The file that you have requested cannot be found!'); } catch (RecordNotFoundException $e) { self::$logger->warn($e->getMessage()); throw new ResourceNotFoundException('The article that you have requested cannot be found!'); } $this->record = $record; $this->setTitle($record->get('title')); $this->setDescription($record->get('description')); $BOView = View::getInstance($record); $body .= View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $body .= $BOView->markdownView(); $body .= View::displayPageFoot($this); $KDP->log(); return new Response(200, $body, array('Content-Type' => 'text/html')); } // handle requests to view an article stored in a file if (isset($params['file'])) { try { $record = new Article(); // just checking to see if the file path is absolute or not if (mb_substr($params['file'], 0, 1) == '/') { $record->loadContentFromFile($params['file']); } else { $record->loadContentFromFile($config->get('app.root') . 'docs/' . $params['file']); } } catch (IllegalArguementException $e) { self::$logger->error($e->getMessage()); throw new ResourceNotFoundException($e->getMessage()); } catch (FileNotFoundException $e) { self::$logger->warn($e->getMessage() . ' File path is [' . $params['file'] . ']'); throw new ResourceNotFoundException('Failed to load the requested article from the file system!'); } $this->record = $record; $this->setTitle($record->get('title')); $BOView = View::getInstance($record); $body .= View::displayPageHead($this, false); $body .= $BOView->markdownView(); $body .= View::displayPageFoot($this); return new Response(200, $body, array('Content-Type' => 'text/html')); } // handle requests to view a list of articles if (isset($params['start'])) { return parent::doGET($request); } // create a new article requests $record = new Article(); $view = View::getInstance($record); // set up the title and meta details $this->setTitle('Creating article'); $this->setDescription('Page to create a new article.'); $this->setKeywords('create,article'); $body .= View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $fields = array('formAction' => $this->request->getURI()); $body .= $view->createView($fields); $body .= View::displayPageFoot($this); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); }