public function GET() { $model = new FlatCMSPluginPageModel(); $page = $model->getPage(sgContext::getCurrentPath()); if ($page) { $this->content = $page['content']; } else { return parent::GET(); } return $this->render($page['template']); }
public function preRender() { if (Zend_Auth::getInstance()->hasIdentity()) { $controller = sgContext::getInstance()->getController(); if ($controller instanceof FlatCMSPluginController) { $session = new Zend_Session_Namespace(Zend_Auth::getInstance()->getStorage()->getNamespace()); $session->FlatCMSEditorPluginFileMTime = filemtime(FlatCMSPluginPageModel::getPagePath(sgContext::getInstance()->getCurrentPath())); //figure out better way to handle this so libraries aren't double loaded $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.min.js'); $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.mini.js'); $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.autogrow.js'); $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/tinymce/jscripts/tiny_mce/jquery.tinymce.js'); $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.tinymce.js'); $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/init.js'); $controller->js_settings['FlatCMSEditorPlugin'] = array('saveURL' => sgToolkit::url(sgConfiguration::get('routing.FlatCMSEditorPlugin_save.path')), 'currentPath' => sgContext::getInstance()->getCurrentPath()); if (isset($controller->content) && is_array($controller->content)) { $textarea_fields = sgConfiguration::get('settings.FlatCMSEditorPlugin.textarea_fields', array()); foreach ($controller->content as $key => &$field) { if (in_array($key, $textarea_fields)) { $field = '<div class="editable-area" id="' . $key . '">' . $field . '</div>'; } else { $field = '<div class="editable" id="' . $key . '">' . $field . '</div>'; } } } } } }
public function PUT() { ZendAuthPluginConfiguration::redirectIfNotAuth(); $data = filter_input_array(INPUT_POST, array('id' => FILTER_SANITIZE_STRING, 'value' => FILTER_UNSAFE_RAW, 'path' => FILTER_SANITIZE_URL, '_method' => FILTER_SANITIZE_STRING)); $pagePath = FlatCMSPluginPageModel::getPagePath($data['path']); $session = new Zend_Session_Namespace(Zend_Auth::getInstance()->getStorage()->getNamespace()); if (filemtime($pagePath) !== $session->FlatCMSEditorPluginFileMTime) { exit('Has changed since you last edited. Please refresh page.'); } else { if (!$pagePath) { exit('Invalid path.'); } $page = FlatCMSPluginPageModel::getPage($data['path']); $clean = $this->filterValue($data['id'], $data['value']); $page['content'][$data['id']] = $clean; file_put_contents($pagePath, Spyc::YAMLDump($page), LOCK_EX); clearstatcache(); $session->FlatCMSEditorPluginFileMTime = filemtime($pagePath); return $clean; } }