コード例 #1
0
 /**
  * reinstate - Pull an old version of a content asset back and insert it as the current version.
  *
  * @param  int Version id you want reinstated.
  * @return     void
  **/
 function reinstate($parameter)
 {
     // pull the version and save the content into the asset record
     if (($model =& $this->getDefaultModel()) && $model->get($parameter)) {
         $version = unserialize($model->version);
         $asset_controller =& NController::factory($model->asset);
         $asset_controller->_auth =& $this->_auth;
         $asset_model =& $asset_controller->getDefaultModel();
         if ($asset_controller && $asset_model && $asset_model->get($model->asset_id)) {
             foreach ($version as $k => $v) {
                 if (!preg_match('/^cms_/', $k) && $k != 'id') {
                     $asset_model->{$k} = $v;
                 }
             }
             // insert a new version as part of the process
             $asset_controller->insertVersion();
             // save the new record
             $asset_model->save();
         }
         unset($asset_model);
         $this->flash->set('notice', 'The version has been reinstated.');
         $referer = isset($this->params['_referer']) ? $this->params['_referer'] : false;
         if (!$referer) {
             include_once 'view/helpers/url_helper.php';
             $referer = urlHelper::urlFor($this, array('controller' => $model->asset, 'action' => 'edit', 'id' => $model->asset_id));
         }
         header('Location:' . $referer);
         exit;
     }
 }
コード例 #2
0
 function removeContent($parameter, $redirect = true, $timed_remove = false)
 {
     $model =& $this->getDefaultModel();
     $referer = isset($this->params['_referer']) && $this->params['_referer'] ? $this->params['_referer'] : false;
     if ($model->get($parameter)) {
         // check for workflow
         // if it's a timed remove, the timed portion went through workflow, so it's okay
         if (SITE_WORKFLOW && $timed_remove == false) {
             // get the users rights and bit compare them below
             $workflow =& NController::factory('workflow');
             $page_model =& $model->getLink('page_id', 'page');
             $user_rights = $workflow->getWorkflowUserRights($page_model);
             if ($workflow_group_model =& $workflow->getWorkflowGroup($page_model)) {
                 if (!($user_rights & WORKFLOW_RIGHT_EDIT)) {
                     // they don't belong here - go to the dashboard
                     header('Location:/' . APP_DIR . '/dashboard');
                     exit;
                 }
                 $asset_controller =& NController::factory($model->content_asset);
                 $asset_controller->_auth = new NAuth();
                 $asset_model =& $asset_controller->getDefaultModel();
                 $asset_model->get($model->content_asset_id);
                 // workflow values for saveWorkflow
                 $workflow_values = array();
                 $workflow_values['page_content_id'] = $model->{$model->primaryKey()};
                 $workflow_values['workflow_group_id'] = $workflow_group_model->{$workflow_group_model->primaryKey()};
                 // save the workflow
                 $workflow->saveWorkflow($workflow_values, WORKFLOW_ACTION_REMOVE, $asset_controller);
                 if ($redirect) {
                     include_once 'view/helpers/url_helper.php';
                     $referer = isset($this->params['referer']) ? urldecode($this->params['referer']) : urlHelper::urlFor($this, array('controller' => 'page', 'action' => 'surftoedit', 'id' => $page_model->{$page_model->primaryKey()}));
                     header('Location:' . $referer);
                     exit;
                 }
             }
             unset($workflow);
         }
         include_once 'view/helpers/url_helper.php';
         $page_id = $model->page_id;
         if (!$referer) {
             $referer = urlHelper::urlFor($this, array('controller' => 'page', 'action' => 'surftoedit', 'id' => $page_id));
         }
         // delete the page cache
         $page =& NController::singleton('page');
         $page->deletePageCache($model->page_id);
         unset($page);
         $audit_trail_array = array('asset' => $model->content_asset, 'asset_id' => $model->content_asset_id, 'action_taken' => AUDIT_ACTION_CONTENT_REMOVE, 'page_content_id' => $model->{$model->primaryKey()}, 'page_id' => $model->page_id);
         if (defined('SITE_AUDIT_TRAIL') && SITE_AUDIT_TRAIL) {
             // audit trail just before the delete or we lose the info
             if ($timed_remove == false) {
                 $audit_trail =& NController::factory('audit_trail');
                 $audit_trail->insert($audit_trail_array);
                 // Bit of an ugly hack, but I didn't want to mess with the controller.
                 // The model doesn't require authentication, so we can force it through when
                 // we're removing timed_content auto-magically.
             } elseif ($timed_remove == true) {
                 $audit_trail =& NModel::factory('cms_audit_trail');
                 $audit_trail->insert_audit_trail($audit_trail_array);
             }
             unset($audit_trail);
         }
         unset($audit_trail_array);
         // delete the page_content record
         $deleted = $model->delete();
         // if delete was successful and there is an unsubmitted workflow, then cascade delete the workflow
         if ($timed_remove == false && $deleted && SITE_WORKFLOW && ($workflow_model =& $this->loadModel('workflow'))) {
             $workflow_model->page_id = $page_id;
             $workflow_model->asset = $model->content_asset;
             $workflow_model->asset_id = $model->content_asset_id;
             $workflow_model->submitted = 0;
             $workflow_model->parent_workflow = 0;
             $workflow_model->cms_modified_by_user = $this->_auth->currentUserID();
             if ($workflow_model->find()) {
                 while ($workflow_model->fetch()) {
                     $workflow_model->delete();
                 }
             }
             unset($workflow_model);
         }
         unset($model);
     }
     if ($redirect) {
         header('Location:' . $referer);
         exit;
     }
 }
コード例 #3
0
ファイル: url_helper.php プロジェクト: nonfiction/nterchange
 function linkTo(&$controller, $text, $href, $html_options = null)
 {
     $href = urlHelper::urlFor($controller, $href);
     if (!$href) {
         return $text ? $text : '';
     }
     if (isset($html_options['confirm'])) {
         $confirm = $html_options['confirm'];
         $confirm = htmlspecialchars($confirm, ENT_NOQUOTES);
         $confirm = str_replace("'", "\\'", $confirm);
         $confirm = str_replace('"', '"', $confirm);
         $html_options['onclick'] = "return confirm('{$confirm}');";
         unset($html_options['confirm']);
     }
     if (isset($html_options['referer']) && $html_options['referer']) {
         $href .= (preg_match('|\\?|', $href) ? '&' : '?') . '_referer=' . urlencode($_SERVER['REQUEST_URI']);
     }
     $html_options['href'] = $href;
     return TagHelper::contentTag('a', $text, $html_options);
 }
コード例 #4
0
ファイル: helper.php プロジェクト: nonfiction/nterchange
 function convertInternalLink($tpl_output, &$smarty)
 {
     return urlHelper::convertInternalLink($tpl_output, $smarty);
 }
コード例 #5
0
 function getContainerContent($page_id, $container_id, $page_content_id = null)
 {
     $page_model =& $this->getDefaultModel();
     $this->auto_render = false;
     $page_id = (int) $page_id;
     $container_id = (int) $container_id;
     if (!$page_id || !$container_id) {
         return null;
     }
     // instantiate the page content controller
     // TODO: put some methods into the page_content controller to do some of this.
     $page_content =& NController::factory('page_content');
     $page_content_model =& $page_content->getDefaultModel();
     $page_content_pk = $page_content_model->primaryKey();
     $asset_ctrl =& NController::singleton('cms_asset_template');
     if (SITE_WORKFLOW && $this->nterchange) {
         // get the users rights and bit compare them below
         $workflow =& NController::factory('workflow');
         $user_rights = $workflow->getWorkflowUserRights($page_model);
     }
     // load up the content
     $content = '';
     // set the time using a trusted source
     $now = new Date(gmdate('Y-m-d H:i:s'));
     $now->setTZbyID('UTC');
     if ($page_content_model->getContainerContent($page_id, $container_id, $this->nterchange, $page_content_id)) {
         $page_content->set('page_id', $page_id);
         while ($page_content_model->fetch()) {
             $page_content->set('page_content_id', $page_content_model->{$page_content_pk});
             $timed_start_obj = $page_content_model->timed_start && $page_content_model->timed_start != '0000-00-00 00:00:00' ? new Date($page_content_model->timed_start) : false;
             $timed_end_obj = $page_content_model->timed_end && $page_content_model->timed_end != '0000-00-00 00:00:00' ? new Date($page_content_model->timed_end) : false;
             if ($timed_start_obj) {
                 $timed_start_obj->setTZbyID('UTC');
             }
             if ($timed_end_obj) {
                 $timed_end_obj->setTZbyID('UTC');
             }
             // set cache lifetimes for the page
             if ($timed_start_obj) {
                 $time_diff = $timed_start_obj->getDate(DATE_FORMAT_UNIXTIME) - $now->getDate(DATE_FORMAT_UNIXTIME);
                 if ($time_diff > 0) {
                     $this->view_cache_lifetimes[] = $time_diff;
                 }
             }
             if ($timed_end_obj) {
                 $time_diff = $timed_end_obj->getDate(DATE_FORMAT_UNIXTIME) - $now->getDate(DATE_FORMAT_UNIXTIME);
                 if ($time_diff > 0) {
                     $this->view_cache_lifetimes[] = $time_diff;
                 }
             }
             if ($timed_end_obj && $timed_end_obj->before($now)) {
                 $timed_end_active = true;
             }
             // if the timed end is in the past then kill it and continue.
             if ($timed_end_obj && $now->after($timed_end_obj)) {
                 // remove the content, which also kills the page cache
                 $page_content_controller =& NController::factory('page_content');
                 $page_content_controller->_auth =& $this->_auth;
                 $page_content_controller->removeContent($page_content_model->{$page_content_pk}, false, true);
                 unset($page_content_controller);
                 continue;
             } else {
                 if ($this->nterchange || !$timed_start_obj || $timed_start_obj && $timed_start_obj->before($now)) {
                     $content_controller =& NController::factory($page_content_model->content_asset);
                     if ($content_controller && is_object($content_controller)) {
                         $content_model =& $content_controller->getDefaultModel();
                         $fields = $content_model->fields();
                         $pk = $content_model->primaryKey();
                         // if we're on the public site, don't grab workflow or draft inserts
                         $conditions = array();
                         if ($this->nterchange && in_array('cms_draft', $fields)) {
                             $conditions = '(cms_draft = 0 OR (cms_draft=1 AND cms_modified_by_user='******'))';
                         } else {
                             $content_model->cms_draft = 0;
                         }
                         $content_model->{$pk} = $page_content_model->content_asset_id;
                         if ($content_model->find(array('conditions' => $conditions), true)) {
                             // last modified
                             if (strtotime($content_model->cms_modified) > $this->page_last_modified) {
                                 $this->page_last_modified = strtotime($content_model->cms_modified);
                             }
                             $template = $asset_ctrl->getAssetTemplate($page_content_model->content_asset, $page_content_model->page_template_container_id);
                             if (SITE_DRAFTS && $this->nterchange) {
                                 $is_draft = false;
                                 $user_owned = false;
                                 $user_id = $this->_auth->currentUserId();
                                 $draft_model =& NModel::factory('cms_drafts');
                                 $draft_model->asset = $content_controller->name;
                                 $draft_model->asset_id = $content_model->{$pk};
                                 if ($draft_model->find(null, true)) {
                                     $is_draft = true;
                                     // fill the local model with the draft info
                                     $current_user_id = isset($this->_auth) && is_object($this->_auth) ? $this->_auth->currentUserID() : 0;
                                     if ($current_user_id == $draft_model->cms_modified_by_user) {
                                         $draft_content = unserialize($draft_model->draft);
                                         foreach ($draft_content as $field => $val) {
                                             $content_model->{$field} = $val;
                                         }
                                         $user_owned = true;
                                         $draft_msg = 'You have saved';
                                     } else {
                                         $user_model =& $this->loadModel('cms_auth');
                                         $user_model->get($draft_model->cms_modified_by_user);
                                         $draft_msg = $user_model->real_name . ' has saved';
                                         unset($user_model);
                                     }
                                 }
                                 unset($draft_model);
                             }
                             if (SITE_WORKFLOW && $this->nterchange) {
                                 if ($workflow_group_model =& $workflow->getWorkflowGroup($page_model)) {
                                     if ($current_workflow =& $workflow->getWorkflow($page_content_model->{$page_content_model->primaryKey()}, $workflow_group_model->{$workflow_group_model->primaryKey()}, $content_controller)) {
                                         $current_user_id = isset($this->_auth) && is_object($this->_auth) ? $this->_auth->currentUserID() : 0;
                                         $content_edit_allowed = $this->content_edit_allowed;
                                         $this->content_edit_allowed = !$current_workflow->submitted && $current_user_id == $current_workflow->cms_modified_by_user ? true : false;
                                         $workflow_draft = unserialize($current_workflow->draft);
                                         foreach ($workflow_draft as $field => $val) {
                                             $content_model->{$field} = $val;
                                         }
                                     }
                                 }
                             }
                             $values = $content_model->toArray();
                             $values['_EDIT_START_'] = '';
                             $values['_EDIT_END_'] = '';
                             if ($this->nterchange && $this->edit) {
                                 $values['_SURFTOEDIT_'] = true;
                             }
                             if ($this->edit) {
                                 if ($this->content_edit_allowed) {
                                     // $values['_EDIT_START_'] .= '<div class="pagecontent" id="pagecontent' . $page_content_model->$page_content_pk . '">' . "\n";
                                     $page_content->set(array('asset' => $content_controller->name, 'asset_id' => $content_model->{$pk}));
                                     $values['_EDIT_START_'] .= $page_content->render(array('action' => 'asset_edit', 'return' => true));
                                 }
                                 $page_content->set(array('asset' => $content_controller->name, 'asset_id' => $content_model->{$pk}, 'page_content_id' => $page_content_model->{$page_content_pk}, 'page_id' => $page_id));
                                 $values['_EDIT_START_'] .= '<div class="editable-region">' . "\n";
                                 if (SITE_WORKFLOW && isset($current_workflow) && $current_workflow) {
                                     if ($this->content_edit_allowed) {
                                         $values['_EDIT_START_'] .= '<div class="workflow">The following content is waiting to be submitted to workflow in the <a href="' . urlHelper::urlFor($dashboard =& NController::factory('dashboard'), null) . '">dashboard</a>.</div>' . "\n";
                                     } else {
                                         $values['_EDIT_START_'] .= '<div class="workflow">The following content is currently in workflow and cannot be edited.</div>' . "\n";
                                     }
                                 }
                                 $values['_EDIT_END_'] .= "</div>\n";
                                 if ($this->content_edit_allowed) {
                                     if (SITE_DRAFTS && $is_draft) {
                                         $values['_EDIT_START_'] .= '<div class="draft">' . $draft_msg . ' the following content as a draft.</div>' . "\n";
                                     }
                                     $values['_EDIT_END_'] .= "</div>\n";
                                 }
                             }
                             if ($this->nterchange && ($timed_start_obj && $timed_start_obj->after($now) || $timed_end_obj && $timed_end_obj->after($now))) {
                                 $format = '%a, %b %e, %Y @ %I:%M:%S %p';
                                 $values['_EDIT_START_'] .= '<div class="timedcontent">';
                                 $values['_EDIT_START_'] .= 'The following content is currently' . ($timed_start_obj && $timed_start_obj->after($now) ? ' NOT' : '') . ' visible (it is now ' . NDate::convertTimeToClient($now, $format) . ')';
                                 if ($timed_start_obj && $timed_start_obj->after($now)) {
                                     $values['_EDIT_START_'] .= '<br />It will appear: ' . NDate::convertTimeToClient($timed_start_obj, $format);
                                 }
                                 if ($timed_end_obj && $timed_end_obj->after($now)) {
                                     $values['_EDIT_START_'] .= '<br />It will be removed: ' . NDate::convertTimeToClient($timed_end_obj, $format);
                                 }
                                 $values['_EDIT_START_'] .= '</div>';
                             }
                             if (isset($content_edit_allowed)) {
                                 $this->content_edit_allowed = $content_edit_allowed;
                                 unset($content_edit_allowed);
                             }
                             // Remove extra whitespace/newlines
                             $values['_EDIT_START_'] = trim(preg_replace('/\\s+/', ' ', $values['_EDIT_START_']));
                             $values['_EDIT_END_'] = trim(preg_replace('/\\s+/', ' ', $values['_EDIT_END_']));
                             // Render the content
                             $content_controller->set($values);
                             $content .= $content_controller->render(array('action' => $template, 'return' => true));
                         }
                         unset($content_model);
                         unset($content_controller);
                     }
                 }
             }
         }
     }
     // free up some memory
     unset($page_content_model);
     unset($page_content);
     // return the content
     return $content;
 }
コード例 #6
0
 /**
  * Redirects the browser to another action in the same controller
  *
  * @param string|array $action - should be an underscored word (same as url) or an array of controller/action
  * @param unknown_type $parameter - optional parameter which is likely an int
  * @return null
  */
 function redirectTo($action, $parameter = null, $additional_params = array())
 {
     include_once 'view/helpers/url_helper.php';
     $url_params = array();
     if (is_array($action)) {
         $url_params['controller'] = $action[0];
         $url_params['action'] = isset($action[1]) ? $action[1] : ($parameter ? 'index' : '');
     } else {
         $url_params['action'] = $action;
         // If there's a starting slash - assume it's a direct URL.
         if (eregi('^/', $url_params['action'])) {
             header('Location:' . $url_params['action']);
             exit;
         }
     }
     $url_params['id'] = $parameter;
     $url = urlHelper::urlFor($this, array_merge($url_params, array_merge($_GET, $additional_params)));
     $url = html_entity_decode($url);
     header('Location:' . $url);
     exit;
 }