示例#1
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;
 }
示例#2
0
 function convertDateTimesToClient(&$model)
 {
     $table = $model->table();
     foreach ($table as $field => $def) {
         if ($def & N_DAO_TIME) {
             switch (true) {
                 case $def & N_DAO_DATE && $def & N_DAO_TIME:
                     $format = '%Y-%m-%d %H:%M:%S';
                     break;
                 default:
                     $format = '%H:%M:%S';
             }
             $model->{$field} = NDate::convertTimeToClient($model->{$field}, $format);
         }
     }
 }