public function index()
 {
     $from = $this->fetchParam('from', false);
     if (!$from) {
         return null;
     }
     // account for subfolder
     if (strpos($from, Config::getSiteRoot()) !== 0) {
         $from = Path::tidy(Config::getSiteRoot() . $from);
     }
     $from = Path::addStartingSlash($from);
     $content_set = ContentService::getContentByURL($from);
     // filter
     $content_set->filter(array('show_hidden' => $this->fetchParam('show_hidden', false, null, true, false), 'show_drafts' => $this->fetchParam('show_drafts', false, null, true, false), 'show_past' => $this->fetchParam('show_past', true, null, true), 'show_future' => $this->fetchParam('show_future', false, null, true), 'type' => 'all', 'conditions' => trim($this->fetchParam('conditions', null, false, false, false))));
     // limit
     $limit = $this->fetchParam('limit', 1, 'is_numeric');
     $offset = $this->fetchParam('offset', 0, 'is_numeric');
     $content_set->limit($limit, $offset);
     // check for results
     if (!$content_set->count()) {
         return Parse::tagLoop($this->content, array(array('no_results' => true)));
     }
     // if content is used in this entries loop, parse it
     $parse_content = (bool) preg_match(Pattern::USING_CONTENT, $this->content);
     return Parse::tagLoop($this->content, $content_set->get($parse_content), false, $this->context);
 }
 public function __call($method, $arguments)
 {
     // Get all the parameter/filters
     $filters = $this->attributes;
     // Default content to context
     $content = $this->context;
     // Override content by a specific page if needed
     if ($from = $this->fetchParam('from')) {
         $content = current(ContentService::getContentByURL($from)->get());
         unset($filters['from']);
     }
     // Grab the field data
     $field_data = array_get($content, $method);
     // Filter down to what we're looking for
     $values = array_values(array_filter($field_data, function ($i) use($filters) {
         foreach ($filters as $key => $val) {
             $match = array_get($i, $key) == $val;
             if (!$match) {
                 break;
             }
         }
         return $match;
     }));
     // No results?
     if (empty($values)) {
         return array('no_results' => true);
     }
     // Got something. Yay. Return it.
     return Parse::tagLoop($this->content, $values, true);
 }
 /**
  * Lists entries based on passed parameters
  *
  * @return array|string
  */
 public function getContent($variable)
 {
     $urls = array_get($this->context, $variable);
     if (!$urls) {
         return null;
     }
     // grab common parameters
     $settings = $this->parseCommonParameters();
     // grab content set based on the common parameters
     // $content_set = $this->getContentSet($settings);
     $content_set = ContentService::getContentByURL($urls);
     $content_set->filter(array('show_hidden' => $this->fetchParam('show_hidden', false, null, true, false), 'show_drafts' => $this->fetchParam('show_drafts', false, null, true, false), 'show_past' => $this->fetchParam('show_past', true, null, true), 'show_future' => $this->fetchParam('show_future', false, null, true), 'type' => 'all', 'conditions' => trim($this->fetchParam('conditions', null, false, false, false))));
     // limit
     $limit = $this->fetchParam('limit', null, 'is_numeric');
     $offset = $this->fetchParam('offset', 0, 'is_numeric');
     if ($limit || $offset) {
         $content_set->limit($limit, $offset);
     }
     // sort
     $sort_by = $this->fetchParam('sort_by');
     $sort_dir = $this->fetchParam('sort_dir');
     if ($sort_by || $sort_dir) {
         $content_set->sort($sort_by, $sort_dir);
     }
     // check for results
     if (!$content_set->count()) {
         return Parse::template($this->content, array('no_results' => true));
     }
     return Parse::tagLoop($this->content, $content_set->get(), false, $this->context);
 }
Ejemplo n.º 4
0
 public function index()
 {
     $from = $this->fetchParam('from', false);
     // defaults to null
     if (!$from) {
         return null;
     }
     $from = Path::addStartingSlash($from);
     $from = strlen($from) > 1 ? rtrim($from, "/") : $from;
     $content_set = ContentService::getContentByURL($from);
     // filter
     $content_set->filter(array('show_all' => $this->fetchParam('show_hidden', false, null, true, false), 'show_past' => $this->fetchParam('show_past', true, null, true), 'show_future' => $this->fetchParam('show_future', false, null, true), 'type' => 'all', 'conditions' => trim($this->fetchParam('conditions', null, false, false, false))));
     // limit
     $limit = $this->fetchParam('limit', 1, 'is_numeric');
     $offset = $this->fetchParam('offset', 0, 'is_numeric');
     $content_set->limit($limit, $offset);
     // check for results
     if (!$content_set->count()) {
         return Parse::tagLoop($this->content, array(array('no_results' => true)));
     }
     // if content is used in this entries loop, parse it
     $parse_content = (bool) preg_match(Pattern::USING_CONTENT, $this->content);
     return Parse::tagLoop($this->content, $content_set->get($parse_content));
 }
Ejemplo n.º 5
0
 /**
  * Fetch a single content entry or page
  *
  * @param string  $url  URL to fetch
  * @param bool  $parse_content  Should we parse content?
  * @param bool  $supplement  Should we supplement the content?
  * @return array
  */
 public static function get($url, $parse_content = true, $supplement = true)
 {
     $hash = Debug::markStart('content', 'getting');
     $url_hash = Helper::makeHash($url, $parse_content, $supplement);
     if (!isset(self::$fetched_content[$url_hash])) {
         $content_set = ContentService::getContentByURL($url);
         $content = $content_set->get($parse_content, $supplement);
         self::$fetched_content[$url_hash] = isset($content[0]) ? $content[0] : array();
     }
     Debug::markEnd($hash);
     return self::$fetched_content[$url_hash];
 }
Ejemplo n.º 6
0
 private function completeEdit($submission, $config, $entry)
 {
     $content_set = ContentService::getContentByURL(Helper::decrypt($entry))->extract();
     // Bail if the content doesn't exist. Someone tweaked it. Tsk tsk.
     if (!count($content_set)) {
         return;
     }
     // Get front-matter from existing submission
     $content = current($content_set);
     $yaml = YAML::parseFile($content['_file']);
     // MERGE!@#!
     $submission = array_merge($yaml, $submission);
     // Update the entry
     $file_content = File::buildContent($submission, '');
     File::put($content['_file'], $file_content);
     // Shall we send?
     if (array_get($config, 'send_notification_email', false) === true) {
         $this->sendEmails($submission, $config, 'update');
     }
     // Save data to flash for use in raven:submission
     $this->flash->set('submission', $submission);
 }
Ejemplo n.º 7
0
 public function render()
 {
     $field_data = $this->field_data;
     /*
     |--------------------------------------------------------------------------
     | Multi-select
     |--------------------------------------------------------------------------
     |
     | We need to set an empty array brace [] and add the "multiple" attribute
     | in the event we want to allow multi-selects. We also change the
     | plurality of the placeholder content.
     |
     */
     $max_items = array_get($this->field_config, 'max_items', 'null');
     $force_list = array_get($this->field_config, 'force_list', false);
     $multiple = array_get($this->field_config, 'multiple', true);
     $allow_blank = array_get($this->field_config, 'allow_blank', false);
     $placeholder = array_get($this->field_config, 'placeholder', false);
     if ($max_items === 1 && !$force_list) {
         $multiple = false;
     }
     $multiple_array_holder = $multiple ? '[]' : '';
     $multiple_string = $multiple ? "multiple='multiple'" : '';
     $placeholder_string = $placeholder ? "placeholder='{$placeholder}'" : '';
     $suggestions = array();
     /*
     |--------------------------------------------------------------------------
     | Hardcoded list of options
     |--------------------------------------------------------------------------
     |
     | Any list can contain a preset list of options available for suggestion,
     | exactly like how the Select fieldtype works.
     |
     */
     if (isset($this->field_config['options'])) {
         $options = $this->field_config['options'];
         $suggestions = array_merge($suggestions, $options);
     }
     /*
     |--------------------------------------------------------------------------
     | Array from a page
     |--------------------------------------------------------------------------
     |
     | Fetch an array from another page. Like hardcoding the options, but it's
     | managed through the content.
     |
     */
     if (isset($this->field_config['array'])) {
         $config = $this->field_config['array'];
         $url = array_get($config, 'from');
         $field = array_get($config, 'field');
         $content = ContentService::getContentByURL($url)->extract();
         $content = $content[0];
         $values = array_get($content, $field);
         // Grid-style, associative array?
         if (is_array(reset($values))) {
             $key = array_get($config, 'key');
             $vs = array();
             foreach ($values as $k => $v) {
                 $vs[] = array_get($v, $key);
             }
             $values = $vs;
         }
         $suggestions = array_merge($suggestions, $values);
     }
     /*
     |--------------------------------------------------------------------------
     | Entries & Pages
     |--------------------------------------------------------------------------
     |
     | Fetch a list of pages and/or entries, using any existing fields as
     | labels and values
     |
     */
     if (isset($this->field_config['content'])) {
         $config = $this->field_config['content'];
         $value = array_get($config, 'value', 'url');
         $label = array_get($config, 'label', 'title');
         $folder = array_get($config, 'folder');
         $content_set = ContentService::getContentByFolders(array($folder));
         $content_set->filter(array('show_hidden' => array_get($config, array('show_hidden', 'show_all'), false), 'show_drafts' => array_get($config, 'show_drafts', false), 'since' => array_get($config, 'since'), 'until' => array_get($config, 'until'), 'show_past' => array_get($config, 'show_past', true), 'show_future' => array_get($config, 'show_future', true), 'type' => array_get($config, 'type', 'entries'), 'conditions' => trim(array_get($config, 'conditions'))));
         $entries = $content_set->get();
         foreach ($entries as $entry) {
             $pieces = array();
             foreach (Helper::ensureArray($label) as $label_part) {
                 if (isset($entry[$label_part]) && isset($entry[$value])) {
                     $pieces[] = $entry[$label_part];
                 }
             }
             $suggestions[$entry[$value]] = join(' – ', $pieces);
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Taxonomies
     |--------------------------------------------------------------------------
     |
     | Single taxonomy types can be fetched from any folder. The taxonomy label
     | and value will be identical to ensure consistency with template logic
     |
     */
     if (isset($this->field_config['taxonomy'])) {
         $taxonomy_type = array_get($this->field_config, 'taxonomy:type');
         $folder = array_get($this->field_config, 'taxonomy:folder');
         $taxonomy_set = ContentService::getTaxonomiesByType($taxonomy_type);
         // now filter that down to just what we want
         $taxonomy_set->filter(array("min_count" => 1, "folders" => array($folder)));
         $taxonomy_set->contextualize($folder);
         $taxonomies = $taxonomy_set->get();
         foreach ($taxonomies as $key => $value) {
             $taxonomies[$key] = $value['name'];
         }
         $suggestions = array_merge($suggestions, $taxonomies);
     }
     /*
     |--------------------------------------------------------------------------
     | Members
     |--------------------------------------------------------------------------
     |
     | Fetch a list of members, using any existing fields as labels and values
     |
     */
     if (isset($this->field_config['members'])) {
         $config = $this->field_config['members'];
         $value = array_get($config, 'value', '_uid');
         $label = array_get($config, 'label', 'username');
         $member_set = MemberService::getMembers();
         $member_set->filter(array('role' => array_get($config, 'role'), 'conditions' => trim(array_get($config, 'conditions'))));
         $members = $member_set->get();
         foreach ($members as $key => $member) {
             if (isset($member[$label]) && isset($member[$value])) {
                 $suggestions[$member[$value]] = $member[$label];
             }
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Input HTML
     |--------------------------------------------------------------------------
     |
     | Generate the HTML for the select field. A single, blank option is
     | needed if allow blank is true.
     |
     */
     if ($max_items === null && $multiple === false) {
         $max_items = 1;
     }
     $options = json_encode(array('sortField' => 'text', 'maxItems' => $max_items, 'delimiter' => ',', 'create' => array_get($this->field_config, 'create', false), 'persist' => array_get($this->field_config, 'persist', true), 'hideSelected' => array_get($this->field_config, 'hide_selected', true), 'sortDirection' => array_get($this->field_config, 'sort_dir', 'asc'), 'plugins' => array('drag_drop'), 'dropdownParent' => 'body'));
     $required_str = $this->is_required ? 'required' : '';
     $html = "<div id='{$this->field_id}' class='suggest-field-container' data-config='{$options}'>";
     $html .= "<select {$required_str} name='{$this->fieldname}{$multiple_array_holder}' tabindex='{$this->tabindex}' {$multiple_string} {$placeholder_string} class='suggest'>\n";
     $is_indexed = array_values($suggestions) === $suggestions;
     // Preserve existing data's order
     if (is_array($field_data)) {
         $field_data = array_combine($field_data, $field_data);
         $suggestions = array_merge($field_data, $suggestions);
     }
     if ($allow_blank) {
         $html .= "<option value=''></option>\n";
     }
     foreach ($suggestions as $value => $label) {
         $value = $is_indexed ? $label : $value;
         #allows setting custom values and labels
         if ($multiple && is_array($field_data)) {
             $selected = in_array($value, $field_data, true) ? " selected " : '';
         } else {
             $selected = $field_data == $value ? " selected " : '';
         }
         $html .= '<option value="' . $value . '" ' . $selected . '>' . $label . '</option>';
     }
     $html .= "</select>";
     $html .= "<div class='count-placeholder'></div></div>";
     $html .= "<script>\$('#{$this->field_id}').statamicSuggest();</script>";
     return $html;
 }
Ejemplo n.º 8
0
Archivo: content.php Proyecto: nob/joi
 /**
  * Fetch a single content entry or page
  *
  * @param string  $url  URL to fetch
  * @return array
  */
 public static function get($url)
 {
     $content_set = ContentService::getContentByURL($url);
     $content = $content_set->get();
     return isset($content[0]) ? $content[0] : array();
 }