/**
  * Construct page versions controller
  *
  * @param Request $request
  * @return PageVersionsController
  */
 function __construct($request)
 {
     parent::__construct($request);
     if ($this->active_page->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $version = $this->request->getId('version');
     if ($version) {
         $this->active_page_version = PageVersions::findById(array('page_id' => $this->active_page->getId(), 'version' => $version));
     }
     // if
     if (!instance_of($this->active_page_version, 'PageVersion')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $this->smarty->assign(array('active_page_version' => $this->active_page_version));
 }
 /**
  * Render Page Version
  * 
  * @param void
  * @return null
  */
 function version()
 {
     if (!instance_of($this->active_page, 'Page')) {
         $this->httpError(HTTP_ERR_NOT_FOUND, null, true, $this->request->isApiCall());
     }
     // if
     if (!$this->active_page->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall());
     }
     // if
     $version = PageVersions::findByPage($this->active_page, $this->request->get('version'));
     if (!instance_of($version, 'PageVersion')) {
         $this->httpError(HTTP_ERR_NOT_FOUND, null, true, $this->request->isApiCall());
     }
     // if
     $this->addBreadcrumb($this->active_page->getName(), mobile_access_module_get_view_url($this->active_page));
     $this->addBreadcrumb(lang('Version #:version', array('version' => $version->getVersion())));
     $this->smarty->assign(array('page_back_url' => mobile_access_module_get_view_url($this->active_page), 'version' => $version));
 }
 /**
  * Export project pages
  *
  * @param void
  * @return null
  */
 function export()
 {
     $object_visibility = array_var($_GET, 'visibility', VISIBILITY_NORMAL);
     $exportable_modules = explode(',', array_var($_GET, 'modules', null));
     if (!is_foreachable($exportable_modules)) {
         $exportable_modules = null;
     }
     // if
     require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php';
     $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, $this->active_module, $exportable_modules);
     if (!$output_builder->createOutputFolder()) {
         $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
     }
     // if
     $output_builder->createAttachmentsFolder();
     $module_categories = Categories::findByModuleSection($this->active_project, PAGES_MODULE, 'pages');
     $output_builder->smarty->assign(array('categories' => $module_categories, 'visibility' => $object_visibility));
     $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'index');
     $output_builder->outputToFile('index');
     if (is_foreachable($module_categories)) {
         foreach ($module_categories as $module_category) {
             $output_builder->smarty->assign('current_category', $module_category);
             $output_builder->smarty->assign('objects', Pages::findByCategory($module_category, STATE_VISIBLE, $object_visibility));
             $output_builder->outputToFile('category_' . $module_category->getId());
         }
         // foreach
     }
     // if
     $pages = ProjectObjects::find(array("conditions" => array("project_id = ? AND module = ? AND type = ?", $this->active_project->getId(), 'pages', 'Page')));
     $page_ids = array();
     if (is_foreachable($pages)) {
         $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'object');
         foreach ($pages as $page) {
             if (instance_of($page, 'Page')) {
                 $page_ids[] = $page->getId();
                 $parent = $page->getParent();
                 $comments = $page->getComments($object_visibility);
                 $output_builder->smarty->assign(array('page' => $page, 'subpages' => $page->getSubpages($object_visibility), 'parent' => $parent, 'comments' => $comments));
                 if (instance_of($parent, 'Page')) {
                     $output_builder->smarty->assign('parent_url', './page_' . $parent->getId() . '.html');
                 } else {
                     if (instance_of($parent, 'Category')) {
                         $output_builder->smarty->assign('parent_url', './category_' . $parent->getId() . '.html');
                     }
                 }
                 // if
                 $output_builder->outputToFile('page_' . $page->getId());
                 $output_builder->outputObjectsAttachments($comments);
                 $output_builder->outputAttachments($page->getAttachments());
             }
             // if
         }
         // foreach
         $revisions = PageVersions::findByPageIds($page_ids);
         if (is_foreachable($revisions)) {
             $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'revision');
             foreach ($revisions as $revision) {
                 $output_builder->smarty->assign('revision', $revision);
                 $output_builder->outputToFile('revision_' . $revision->getPageId() . '_' . $revision->getVersion());
             }
             // foreach
         }
         // if
     }
     // if
     $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
 }
 function print_old_versions()
 {
     $version_id = $this->request->getId('version_id');
     $old_version = PageVersions::findById(array('page_id' => $this->active_object->getId(), 'version' => $version_id));
     $this->smarty->assign(array('old_version' => $old_version, 'created_on' => date('m-d-Y', strtotime($old_version->getCreatedOn()))));
 }
Ejemplo n.º 5
0
 /**
  * Return last page version
  *
  * @return PageVersion
  */
 function getLatestVersion()
 {
     if ($this->latest_version === false) {
         $this->latest_version = PageVersions::findLatestByPage($this);
     }
     // if
     return $this->latest_version;
 }
 /**
  * Find page versions by list of ID-s
  *
  * @param array $ids
  * @return array
  */
 function findByPageIds($ids)
 {
     return PageVersions::find(array('conditions' => array('page_id IN (?)', $ids), 'order' => 'created_on DESC'));
 }