Exemple #1
0
function printS($id)
{
    $ci =& get_instance();
    $s = new Section();
    $s->get_by_id($id);
    $s->e = anchor($ci->app->app_url('edit/') . $s->id, 'Edit');
    $s->d = anchor($ci->app->app_url('delete/') . $s->id, 'Delete');
    $output = "<li>";
    $output .= $s->id . '|';
    $output .= $s->name;
    $output .= add($id, 0, "add first child for {$s->name}");
    $output .= '|';
    $output .= $s->e;
    $output .= '|';
    $output .= $s->d;
    $c = new Section();
    $c->where('parent_section', $id);
    $c->order_by('sort', 'asc');
    $c->get();
    if (count($c->all) > 0) {
        $output .= "<ul>";
        foreach ($c->all as $item) {
            $output .= printS($item->id);
            $output .= "<li>" . add($id, $item->sort + 1) . "</li>";
        }
        $output .= "</ul>";
    }
    $output .= "</li>";
    return $output;
}
 public static function findEntries($entries, Section $section)
 {
     $entries = explode(',', $entries);
     $ret = EntryManager::fetch($entries, $section->get('id'));
     if ($ret === false) {
         self::throwEx('An error occurred while processing entries');
     }
     return $ret;
 }
Exemple #3
0
 function get_section()
 {
     $CI =& get_instance();
     if ($this->installed()) {
         if (!isset($CI->uri)) {
             $CI->load->library('URI');
         }
         $sec = new Section();
         $sec->get_by_id($CI->uri->segment(1));
         if (!$sec->exists()) {
             $sec->get();
         }
         return $sec;
     }
 }
 public function onAfterWrite()
 {
     parent::onAfterWrite();
     if ($this->owner->Sections()->Count() == 0) {
         $section = Section::get()->filter(array('ClassName' => 'MainSection'))->first();
         if ($section) {
             $this->owner->Sections()->add($section->ID);
         } else {
             $section = MainSection::create();
             $section->AdminTitle = 'Placeholder for main content';
             $section->Public = true;
             $section->Write();
             $this->owner->Sections()->add($section);
         }
     }
 }
 /**
  * delete that section with all it's subsections
  * plus eliminate the gap between it's siblings sort
  **/
 public function delete($object = '', $related_field = '')
 {
     if (empty($object)) {
         // update all the sections sort after that section
         // that in the same parent section
         $s = new Section();
         $s->where('sort >', $this->sort);
         $s->where('parent_section', $this->parent_section);
         $s->get();
         foreach ($s as $item) {
             $item->sort--;
             $item->save();
         }
     }
     //delete this section
     parent::delete($object, $related_field);
 }
 public function dAdminPagePreGenerate($context)
 {
     if (!$this->_enabled) {
         return false;
     }
     $callback = Administration::instance()->getPageCallback();
     // index page
     if ($callback['context']['page'] === 'index') {
         /* Create button */
         if ($this->_max > 0 && $this->_total >= $this->_max) {
             $context['oPage']->Context->getChild(1)->removeChildAt(0);
         }
         /* Feedback message */
         $msg_total_entries = $this->_total === 1 ? __('There is %d entry', array($this->_total)) : __('There are %d entries', array($this->_total));
         $msg_max_entries = '';
         $msg_create_more = '';
         if ($this->_max !== 0) {
             $msg_max_entries = __(' out of a maximum of ') . $this->_max;
             if ($this->_total >= $this->_max) {
                 $msg_create_more = __("You can't create more entries.");
             } else {
                 $diff = $this->_max - $this->_total;
                 $msg_create_more = __("You can create %d more", array($diff));
                 $msg_create_more .= ' ' . ($diff === 1 ? __('entry') : __('entries')) . '.';
             }
         }
         $feedback = $msg_total_entries . $msg_max_entries . '. ' . $msg_create_more;
         $context['oPage']->Contents->prependChild(new XMLElement('p', $feedback, array('style' => 'margin: 10px 0 0 18px;')));
     } elseif (in_array($callback['context']['page'], array('new', 'edit'))) {
         // replace breadcrumbs (emulate static section)
         if ($this->_max === 1) {
             $breadcrumbs = $context['oPage']->Context->getChild(0);
             $children_count = $breadcrumbs->getNumberOfChildren();
             for ($i = $children_count - 1; $i >= 0; $i--) {
                 $breadcrumbs->removeChildAt($i);
             }
             $breadcrumbs->appendChild(new XMLElement('h2', $this->_section->get('name')));
         }
     }
 }
 /**
  * Prepare a Drawer to visualize section associations
  *
  * @param  Section $section The current Section object
  * @throws InvalidArgumentException
  * @throws Exception
  */
 private function prepareAssociationsDrawer($section)
 {
     $entry_id = !is_null($this->_context['entry_id']) ? $this->_context['entry_id'] : null;
     $show_entries = Symphony::Configuration()->get('association_maximum_rows', 'symphony');
     if (is_null($entry_id) && !isset($_GET['prepopulate']) || is_null($show_entries) || $show_entries == 0) {
         return;
     }
     $parent_associations = SectionManager::fetchParentAssociations($section->get('id'), true);
     $child_associations = SectionManager::fetchChildAssociations($section->get('id'), true);
     $content = null;
     $drawer_position = 'vertical-right';
     /**
      * Prepare Associations Drawer from an Extension
      *
      * @since Symphony 2.3.3
      * @delegate PrepareAssociationsDrawer
      * @param string $context
      * '/publish/'
      * @param integer $entry_id
      *  The entry ID or null
      * @param array $parent_associations
      *  Array of Sections
      * @param array $child_associations
      *  Array of Sections
      * @param string $drawer_position
      *  The position of the Drawer, defaults to `vertical-right`. Available
      *  values of `vertical-left, `vertical-right` and `horizontal`
      */
     Symphony::ExtensionManager()->notifyMembers('PrepareAssociationsDrawer', '/publish/', array('entry_id' => $entry_id, 'parent_associations' => &$parent_associations, 'child_associations' => &$child_associations, 'content' => &$content, 'drawer-position' => &$drawer_position));
     // If there are no associations, return now.
     if ((is_null($parent_associations) || empty($parent_associations)) && (is_null($child_associations) || empty($child_associations))) {
         return;
     }
     if (!$content instanceof XMLElement) {
         $content = new XMLElement('div', null, array('class' => 'content'));
         $content->setSelfClosingTag(false);
         // Process Parent Associations
         if (!is_null($parent_associations) && !empty($parent_associations)) {
             foreach ($parent_associations as $as) {
                 if ($field = FieldManager::fetch($as['parent_section_field_id'])) {
                     if (isset($_GET['prepopulate'])) {
                         $prepopulate_field = key($_GET['prepopulate']);
                     }
                     // get associated entries if entry exists,
                     if ($entry_id) {
                         $entry_ids = $field->findParentRelatedEntries($as['child_section_field_id'], $entry_id);
                         // get prepopulated entry otherwise
                     } elseif (isset($_GET['prepopulate'])) {
                         $entry_ids = array(intval(current($_GET['prepopulate'])));
                     } else {
                         $entry_ids = array();
                     }
                     // Use $schema for perf reasons
                     $schema = array($field->get('element_name'));
                     $where = !empty($entry_ids) ? sprintf(' AND `e`.`id` IN (%s)', implode(', ', $entry_ids)) : null;
                     $entries = !empty($entry_ids) || isset($_GET['prepopulate']) && $field->get('id') === $prepopulate_field ? EntryManager::fetchByPage(1, $as['parent_section_id'], $show_entries, $where, null, false, false, true, $schema) : array();
                     $has_entries = !empty($entries) && $entries['total-entries'] != 0;
                     if ($has_entries) {
                         $element = new XMLElement('section', null, array('class' => 'association parent'));
                         $header = new XMLElement('header');
                         $header->appendChild(new XMLElement('p', __('Linked to %s in', array('<a class="association-section" href="' . SYMPHONY_URL . '/publish/' . $as['handle'] . '/">' . $as['name'] . '</a>'))));
                         $element->appendChild($header);
                         $ul = new XMLElement('ul', null, array('class' => 'association-links', 'data-section-id' => $as['child_section_id'], 'data-association-ids' => implode(', ', $entry_ids)));
                         foreach ($entries['records'] as $e) {
                             // let the field create the mark up
                             $li = $field->prepareAssociationsDrawerXMLElement($e, $as);
                             // add it to the unordered list
                             $ul->appendChild($li);
                         }
                         $element->appendChild($ul);
                         $content->appendChild($element);
                     }
                 }
             }
         }
         // Process Child Associations
         if (!is_null($child_associations) && !empty($child_associations)) {
             foreach ($child_associations as $as) {
                 // Get the related section
                 $child_section = SectionManager::fetch($as['child_section_id']);
                 if (!$child_section instanceof Section) {
                     continue;
                 }
                 // Get the visible field instance (using the sorting field, this is more flexible than visibleColumns())
                 // Get the link field instance
                 $visible_field = current($child_section->fetchVisibleColumns());
                 $relation_field = FieldManager::fetch($as['child_section_field_id']);
                 // Get entries, using $schema for performance reasons.
                 $entry_ids = $relation_field->findRelatedEntries($entry_id, $as['parent_section_field_id']);
                 $schema = $visible_field ? array($visible_field->get('element_name')) : array();
                 $where = sprintf(' AND `e`.`id` IN (%s)', implode(', ', $entry_ids));
                 $entries = !empty($entry_ids) ? EntryManager::fetchByPage(1, $as['child_section_id'], $show_entries, $where, null, false, false, true, $schema) : array();
                 $has_entries = !empty($entries) && $entries['total-entries'] != 0;
                 // Build the HTML of the relationship
                 $element = new XMLElement('section', null, array('class' => 'association child'));
                 $header = new XMLElement('header');
                 $filter = '?filter[' . $relation_field->get('element_name') . ']=' . $entry_id;
                 $prepopulate = '?prepopulate[' . $as['child_section_field_id'] . ']=' . $entry_id;
                 // Create link with filter or prepopulate
                 $link = SYMPHONY_URL . '/publish/' . $as['handle'] . '/' . $filter;
                 $a = new XMLElement('a', $as['name'], array('class' => 'association-section', 'href' => $link));
                 // Create new entries
                 $create = new XMLElement('a', __('Create New'), array('class' => 'button association-new', 'href' => SYMPHONY_URL . '/publish/' . $as['handle'] . '/new/' . $prepopulate));
                 // Display existing entries
                 if ($has_entries) {
                     $header->appendChild(new XMLElement('p', __('Links in %s', array($a->generate()))));
                     $ul = new XMLElement('ul', null, array('class' => 'association-links', 'data-section-id' => $as['child_section_id'], 'data-association-ids' => implode(', ', $entry_ids)));
                     foreach ($entries['records'] as $key => $e) {
                         // let the first visible field create the mark up
                         if ($visible_field) {
                             $li = $visible_field->prepareAssociationsDrawerXMLElement($e, $as, $prepopulate);
                         } else {
                             $li = Field::createAssociationsDrawerXMLElement($e->get('id'), $e, $as, $prepopulate);
                         }
                         // add it to the unordered list
                         $ul->appendChild($li);
                     }
                     $element->appendChild($ul);
                     // If we are only showing 'some' of the entries, then show this on the UI
                     if ($entries['total-entries'] > $show_entries) {
                         $pagination = new XMLElement('li', null, array('class' => 'association-more', 'data-current-page' => '1', 'data-total-pages' => ceil($entries['total-entries'] / $show_entries), 'data-total-entries' => $entries['total-entries']));
                         $counts = new XMLElement('a', __('Show more entries'), array('href' => $link));
                         $pagination->appendChild($counts);
                         $ul->appendChild($pagination);
                     }
                     // No entries
                 } else {
                     $element->setAttribute('class', 'association child empty');
                     $header->appendChild(new XMLElement('p', __('No links in %s', array($a->generate()))));
                 }
                 $header->appendChild($create);
                 $element->prependChild($header);
                 $content->appendChild($element);
             }
         }
     }
     $drawer = Widget::Drawer('section-associations', __('Show Associations'), $content);
     $this->insertDrawer($drawer, $drawer_position, 'prepend');
 }
 /**
  * This function handles the Send Mail filter which will send an email
  * to each specified recipient informing them that an Entry has been
  * created.
  *
  * @param XMLElement $result
  *  The XMLElement of the XML that is going to be returned as part
  *  of this event to the page.
  * @param array $send_mail
  *  Associative array of `send-mail` parameters.
  * @param array $fields
  *  Array of post data to extract the values from
  * @param Section $section
  *  This Section for this event
  * @param Section $section
  *  This current Entry that has just been updated or created
  * @return XMLElement
  *  The modified `$result` with the results of the filter.
  */
 public function processSendMailFilter(XMLElement $result, array $send_email, array &$fields, Section $section, Entry $entry)
 {
     $fields['recipient'] = self::replaceFieldToken($send_email['recipient'], $fields);
     $fields['recipient'] = preg_split('/\\,/i', $fields['recipient'], -1, PREG_SPLIT_NO_EMPTY);
     $fields['recipient'] = array_map('trim', $fields['recipient']);
     $fields['subject'] = self::replaceFieldToken($send_email['subject'], $fields, __('[Symphony] A new entry was created on %s', array(Symphony::Configuration()->get('sitename', 'general'))));
     $fields['body'] = self::replaceFieldToken($send_email['body'], $fields, null, false, false);
     $fields['sender-email'] = self::replaceFieldToken($send_email['sender-email'], $fields);
     $fields['sender-name'] = self::replaceFieldToken($send_email['sender-name'], $fields);
     $fields['reply-to-name'] = self::replaceFieldToken($send_email['reply-to-name'], $fields);
     $fields['reply-to-email'] = self::replaceFieldToken($send_email['reply-to-email'], $fields);
     $edit_link = SYMPHONY_URL . '/publish/' . $section->get('handle') . '/edit/' . $entry->get('id') . '/';
     $language = Symphony::Configuration()->get('lang', 'symphony');
     $template_path = Event::getNotificationTemplate($language);
     $body = sprintf(file_get_contents($template_path), $section->get('name'), $edit_link);
     if (is_array($fields['body'])) {
         foreach ($fields['body'] as $field_handle => $value) {
             $body .= "// {$field_handle}" . PHP_EOL . $value . PHP_EOL . PHP_EOL;
         }
     } else {
         $body .= $fields['body'];
     }
     // Loop over all the recipients and attempt to send them an email
     // Errors will be appended to the Event XML
     $errors = array();
     foreach ($fields['recipient'] as $recipient) {
         $author = AuthorManager::fetchByUsername($recipient);
         if (empty($author)) {
             $errors['recipient'][$recipient] = __('Recipient not found');
             continue;
         }
         $email = Email::create();
         // Huib: Exceptions are also thrown in the settings functions, not only in the send function.
         // Those Exceptions should be caught too.
         try {
             $email->recipients = array($author->get('first_name') => $author->get('email'));
             if ($fields['sender-name'] != null) {
                 $email->sender_name = $fields['sender-name'];
             }
             if ($fields['sender-email'] != null) {
                 $email->sender_email_address = $fields['sender-email'];
             }
             if ($fields['reply-to-name'] != null) {
                 $email->reply_to_name = $fields['reply-to-name'];
             }
             if ($fields['reply-to-email'] != null) {
                 $email->reply_to_email_address = $fields['reply-to-email'];
             }
             $email->text_plain = str_replace('<!-- RECIPIENT NAME -->', $author->get('first_name'), $body);
             $email->subject = $fields['subject'];
             $email->send();
         } catch (EmailValidationException $e) {
             $errors['address'][$author->get('email')] = $e->getMessage();
         } catch (EmailGatewayException $e) {
             $errors['gateway'][$author->get('email')] = $e->getMessage();
         } catch (EmailException $e) {
             $errors['email'][$author->get('email')] = $e->getMessage();
         }
     }
     // If there were errors, output them to the event
     if (!empty($errors)) {
         $xml = self::buildFilterElement('send-email', 'failed');
         foreach ($errors as $type => $messages) {
             $xType = new XMLElement('error');
             $xType->setAttribute('error-type', $type);
             foreach ($messages as $recipient => $message) {
                 $xType->appendChild(new XMLElement('message', $message, array('recipient' => $recipient)));
             }
             $xml->appendChild($xType);
         }
         $result->appendChild($xml);
     } else {
         $result->appendChild(self::buildFilterElement('send-email', 'passed'));
     }
     return $result;
 }
Exemple #9
0
 public function processResults(SymRead $query, Section $section, array $pagination, array $entries)
 {
     $this->data = array('section' => array('id' => (int) $section->get('id'), 'handle' => $section->get('handle'), 'name' => $section->get('name')), 'pagination' => $pagination, 'entries' => array());
     foreach ($entries as $entry) {
         $entry_id = (int) $entry->get('id');
         $entry_date = strtotime($entry->creationDate);
         $entry_array = array();
         foreach ($query->selects as $select) {
             $field = $select->get('object');
             if ($field == SymQuery::SYSTEM_ID) {
                 $entry_array[SymQuery::SYSTEM_ID] = $entry_id;
             }
             if ($field == SymQuery::SYSTEM_DATE) {
                 $entry_array[SymQuery::SYSTEM_DATE] = array('value' => DateTimeObj::get('c', $entry_date), 'local' => strtotime(DateTimeObj::get('c', $entry_date)), 'gmt' => strtotime(DateTimeObj::getGMT('c', $entry_date)));
             } else {
                 if ($field instanceof Field) {
                     $field_id = (int) $field->get('id');
                     $field_handle = $field->get('element_name');
                     $entry_array[$field_handle] = $entry->getData($field_id);
                 }
             }
         }
         $this->data['entries'][] = $entry_array;
     }
     return $this;
 }
Exemple #10
0
 function deattach_section($section = '')
 {
     //=========================
     //normalize the  sort numbers
     //=========================
     $cont = new Section();
     // we have to push all the content up to fill that hole
     // these content must me in the same section,parent,cell
     // and have sort nubmer greater than that content
     $cont->where('parent_section', $section->parent_section);
     //same section
     $cont->where('sort >', $section->sort);
     //greater sort
     $cont->get();
     //get them to process
     foreach ($cont->all as $item) {
         $item->sort--;
         $item->save();
     }
 }
Exemple #11
0
 /**
  * Generate the top-level menu for the sections of your app.
  *
  * @param string|bool $current
  *
  * @return string
  */
 public static function menu($current = false)
 {
     if (!\User::require_login()) {
         return '';
     }
     $customer = self::customer();
     if (!$customer) {
         return '';
     }
     $conf = self::$conf;
     if (!is_array($conf['Sections'])) {
         $conf['Sections'] = array();
     }
     if (!$current) {
         $current = Section::get();
     }
     $out = '<ul class="nav">';
     foreach ($conf['Sections'] as $key => $value) {
         if (strpos($key, 'dropdown:') === 0) {
             // handle dropdown menu options
             $key = str_replace('dropdown:', '', $key);
             $label = array_shift($value);
             $out .= '<li class="dropdown">' . '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' . $label . ' <b class="caret"></b></a>' . '<ul class="dropdown-menu">';
             foreach ($value as $handler => $label) {
                 $out .= sprintf('<li><a href="%s">%s</a></li>', self::make_href($handler), $label);
             }
             $out .= '</ul></li>';
             continue;
         }
         // handle regular menu options
         $class = $current && $current === $key ? ' class="active"' : '';
         $out .= sprintf('<li%s><a href="%s/%s">%s</a></li>', $class, self::href(), $key, array_shift($value));
     }
     // Add account
     $class = strpos($_SERVER['REQUEST_URI'], '/saasy/account') === 0 ? ' class="active"' : '';
     $out .= sprintf('<li%s><a href="%s/%s">%s</a></li>', $class, self::href(), 'account', __('Account'));
     // Add sign out
     $out .= sprintf('<li><a href="/user/logout">%s</a></li>', __('Sign Out'));
     return $out . '</ul>';
 }
Exemple #12
0
|--------------------------------------------------------------------------
| Maintenance Mode Handler
|--------------------------------------------------------------------------
|
| The "down" Artisan command gives you the ability to put an application
| into maintenance mode. Here, you will define what is displayed back
| to the user if maintenance mode is in effect for the application.
|
*/
App::down(function () {
    return Response::view('page.system.maintenance', ['sections' => []], 503);
});
App::missing(function (Exception $exception) {
    if (Request::is('*/.json')) {
        return Response::json(['error' => 'not found'], 404);
    }
    $section = new Section();
    return View::make('page.system.404', ['message' => $exception->getMessage(), 'sections' => $section->get()]);
});
/*
|--------------------------------------------------------------------------
| Require The Filters File
|--------------------------------------------------------------------------
|
| Next we will load the filters file for the application. This gives us
| a nice separate location to store our route and application filter
| definitions instead of putting them all in the main routes file.
|
*/
require app_path() . '/filters.php';
require app_path() . '/validators.php';
Exemple #13
0
 public static function getSection()
 {
     $s = Section::get();
     self::$section = $s;
     return new self();
 }