예제 #1
0
 public static function getSchemas()
 {
     $pages = array();
     $prefix = Pages::getAvailablePages();
     foreach ($prefix as $p) {
         $pages[$p] = Pages::getSchema($p);
     }
     return $pages;
 }
예제 #2
0
 public function saveAction()
 {
     // We'll need to access the pages database
     $pages = new Pages();
     // Is the form correctly posted ?
     if (!$this->getRequest()->isPost()) {
         throw new Stuffpress_Exception("Invalid request - must be post");
     }
     // Get the source from the request
     $id = (int) $this->_getParam('id');
     $type = (string) $this->_getParam('type');
     // Validate the parameters
     if (!($id >= 0 && in_array($type, Pages::getAvailablePages()))) {
         throw new Stuffpress_Exception("Parameters failed validation");
     }
     // If it is an edit; are we the owner ?
     if ($id > 0) {
         // Does the page exist ?
         if (!($page = $pages->getPage($id))) {
             throw new Stuffpress_Exception("Unknown page with id {$id}");
         }
         // Are we the owner ?
         if ($page['user_id'] != $this->_application->user->id) {
             throw new Stuffpress_AccessDeniedException("Not the owner of page {$id}");
         }
     }
     // Get the page descriptor
     $model = Pages::getModel($type);
     // Validate the form
     $form = $model->getForm();
     if (!$form->isValid($_POST)) {
         return $this->_helper->json->sendJson($form->getErrorArray());
     }
     // Get the form values
     $values = $form->getValues();
     // Proceed and save the values
     $title = @$values['title'];
     // There shoudl always be a title
     // Create the page if it does not exist
     if ($id == 0) {
         $id = $pages->addPage($type, $title);
     } else {
         $pages->setTitle($id, $title);
     }
     // Save the page configuration
     $model->processForm($id, $values);
     // Ok
     return $this->_helper->json->sendJson(false);
 }