/**
  * Displays an entry.
  *
  * @param EntryModel $entry
  *
  * @throws HttpException
  * @return null
  */
 private function _showEntry(EntryModel $entry)
 {
     $section = $entry->getSection();
     $type = $entry->getType();
     if ($section && $type) {
         craft()->setLanguage($entry->locale);
         if (!$entry->postDate) {
             $entry->postDate = new DateTime();
         }
         craft()->templates->getTwig()->disableStrictVariables();
         $this->renderTemplate($section->template, array('entry' => $entry));
     } else {
         Craft::log('Attempting to preview an entry that doesn’t have a section/type', LogLevel::Error);
         throw new HttpException(404);
     }
 }
 /**
  * Parse entry fields.
  *
  * @param EntryModel $entry
  * @param bool       $empty
  *
  * @return array
  */
 public function fields(EntryModel $entry, $empty = false)
 {
     // Always save id and title
     $fields = array('id' => array('label' => Craft::t('ID'), 'value' => $entry->id), 'title' => array('label' => Craft::t('Title'), 'value' => (string) $entry->getTitle()), 'section' => array('label' => Craft::t('Section'), 'value' => (string) $entry->getSection()));
     // Get element type
     $elementType = craft()->elements->getElementType(ElementType::Entry);
     // Get nice attributes
     $availableAttributes = $elementType->defineAvailableTableAttributes();
     // Make 'em fit
     $attributes = array();
     foreach ($availableAttributes as $key => $result) {
         $attributes[$key] = $result['label'];
     }
     // Get static "fields"
     foreach ($entry->getAttributes() as $handle => $value) {
         // Only show nice attributes
         if (array_key_exists($handle, $attributes)) {
             $fields[$handle] = array('label' => $attributes[$handle], 'value' => StringHelper::arrayToString(is_array($value) ? array_filter(ArrayHelper::flattenArray($value), 'strlen') : $value, ', '));
         }
     }
     // Get fieldlayout
     $entrytype = $entry->getType();
     if ($entrytype) {
         $tabs = craft()->fields->getLayoutById($entrytype->fieldLayoutId)->getTabs();
         foreach ($tabs as $tab) {
             foreach ($tab->getFields() as $field) {
                 // Get field values
                 $field = $field->getField();
                 $handle = $field->handle;
                 $label = $field->name;
                 $value = $empty ? '' : craft()->auditLog->parseFieldData($handle, $entry->{$handle});
                 // Set on fields
                 $fields[$handle] = array('label' => $label, 'value' => $value);
             }
         }
     }
     // Return
     return $fields;
 }
 /**
  * Displays an entry.
  *
  * @param EntryModel $entry
  *
  * @throws HttpException
  * @return null
  */
 private function _showEntry(EntryModel $entry)
 {
     $section = $entry->getSection();
     $type = $entry->getType();
     if (!$section || !$type) {
         Craft::log('Attempting to preview an entry that doesn’t have a section/type', LogLevel::Error);
         throw new HttpException(404);
     }
     craft()->setLanguage($entry->locale);
     if (!$entry->postDate) {
         $entry->postDate = new DateTime();
     }
     // Have this entry override any freshly queried entries with the same ID/locale
     craft()->elements->setPlaceholderElement($entry);
     craft()->templates->getTwig()->disableStrictVariables();
     $this->renderTemplate($section->template, array('entry' => $entry));
 }
 /**
  * Applies the rules which relate to a given entry.
  *
  * @param EntryModel $entry
  */
 public function applyRules($entry)
 {
     foreach (craft()->autoExpire->getRules() as $rule) {
         if ($entry->sectionId == $rule->sectionId && $entry->getType()->id == $rule->entryTypeId) {
             $ruleName = $entry->id . '::' . $rule->id;
             // Did we already re-save the entry for this rule? Necessary because of the recursive
             // call of EntriesService::saveEntry().
             if (!in_array($ruleName, $this->_handledRules)) {
                 $this->_handledRules[] = $ruleName;
                 $this->applyRule($entry, $rule);
             }
         }
     }
 }