public function control_panel__add_to_head()
 {
     if (URL::getCurrent(false) == '/publish') {
         $file = 'defined-links.json';
         $current_content_list = file_get_contents($file, true);
         $current_content_list = json_decode($current_content_list);
         $content_set = ContentService::getContentByFolders(array("/*"));
         $content_set->multisort('url');
         $content_set = $content_set->get();
         $content_list = [];
         $content_list[] = ['name' => 'Select...', 'url' => false];
         foreach ($content_set as $content) {
             if (isset($content['url']) && isset($content['title'])) {
                 $name = '[' . $content['url'] . '] ' . $content['title'];
                 $url = $content['url'];
                 $content_list[] = ['name' => $name, 'url' => $url];
             }
         }
         if ($current_content_list !== $content_list) {
             $json = json_encode($content_list);
             file_put_contents($file, $json, FILE_USE_INCLUDE_PATH);
         }
         return $this->js->link('definedlinks.js');
     }
 }
Exemplo n.º 2
0
Arquivo: pi.pages.php Projeto: nob/joi
 /**
  * Lists entries based on passed parameters
  *
  * @return array|string
  */
 public function listing()
 {
     $folders = $this->fetchParam('folder', $this->fetchParam('folders', ltrim($this->fetchParam('from', URL::getCurrent()), "/")));
     $folders = $folders === "/" ? "" : $folders;
     if ($this->fetchParam('taxonomy', false, null, true, null)) {
         $taxonomy_parts = Taxonomy::getCriteria(URL::getCurrent());
         $taxonomy_type = $taxonomy_parts[0];
         $taxonomy_slug = Config::get('_taxonomy_slugify') ? Slug::humanize($taxonomy_parts[1]) : urldecode($taxonomy_parts[1]);
         $content_set = ContentService::getContentByTaxonomyValue($taxonomy_type, $taxonomy_slug, $folders);
     } else {
         $content_set = ContentService::getContentByFolders($folders);
     }
     // filter
     $content_set->filter(array('show_all' => $this->fetchParam('show_hidden', false, null, true, false), 'since' => $this->fetchParam('since'), 'until' => $this->fetchParam('until'), 'show_past' => $this->fetchParam('show_past', TRUE, NULL, TRUE), 'show_future' => $this->fetchParam('show_future', FALSE, NULL, TRUE), 'type' => 'pages', 'conditions' => trim($this->fetchParam('conditions', ""))));
     // sort
     $content_set->sort($this->fetchParam('sort_by', 'order_key'), $this->fetchParam('sort_dir'));
     // grab total entries for setting later
     $total_entries = $content_set->count();
     // limit
     $limit = $this->fetchParam('limit', null, 'is_numeric');
     $offset = $this->fetchParam('offset', 0, 'is_numeric');
     $paginate = $this->fetchParam('paginate', true, null, true, false);
     if ($limit || $offset) {
         if ($limit && $paginate && !$offset) {
             // pagination requested, isolate the appropriate page
             $content_set->isolatePage($limit, URL::getCurrentPaginationPage());
         } else {
             // just limit
             $content_set->limit($limit, $offset);
         }
     }
     // manually supplement
     $content_set->supplement(array('total_found' => $total_entries));
     // check for results
     if (!$content_set->count()) {
         return 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));
 }
Exemplo n.º 3
0
    /**
     * Returns a ContentSet object with the appropriate content
     *
     * @param array  $settings  Settings for filtering content and such
     * @return ContentSet
     */
    private function getContentSet($settings)
    {
        // create a unique hash for these settings
        $content_hash = Helper::makeHash($settings);

        if ($this->blink->exists($content_hash)) {
            // blink content exists, use that
            $content_set = new ContentSet($this->blink->get($content_hash));
        } else {
            // no blink content exists, get data the hard way
            if ($settings['taxonomy']) {
                $taxonomy_parts  = Taxonomy::getCriteria(URL::getCurrent());
                $taxonomy_type   = $taxonomy_parts[0];
                $taxonomy_slug   = Config::get('_taxonomy_slugify') ? Slug::humanize($taxonomy_parts[1]) : urldecode($taxonomy_parts[1]);

                $content_set = ContentService::getContentByTaxonomyValue($taxonomy_type, $taxonomy_slug, $settings['folders']);
            } else {
                $content_set = ContentService::getContentByFolders($settings['folders']);
            }

            // filter
            $content_set->filter($settings);

            // grab total entries for setting later
            $total_entries = $content_set->count();

            // pre-sort supplement
            $content_set->supplement(array('total_found' => $total_entries) + $settings);

            // sort
            $content_set->multisort($settings['sort']);            
            
            // post-sort supplement
            $content_set->supplement(array(
                'group_by_date' => trim($this->fetchParam("group_by_date", null, null, false, false))
            ), true);

            // store content as blink content for future use
            $this->blink->set($content_hash, $content_set->extract());
        }

        return $content_set;
    }
Exemplo n.º 4
0
 /**
  * Gets the target data from the cache
  *
  * @param array  $config  Configuration array
  * @return array
  */
 public function getData($config)
 {
     // load data
     if ($config['taxonomy']) {
         $taxonomy_parts = Taxonomy::getCriteria(URL::getCurrent());
         $taxonomy_type = $taxonomy_parts[0];
         $taxonomy_slug = Config::get('_taxonomy_slugify') ? Slug::humanize($taxonomy_parts[1]) : urldecode($taxonomy_parts[1]);
         $content_set = ContentService::getContentByTaxonomyValue($taxonomy_type, $taxonomy_slug, $config['folders']);
     } else {
         $content_set = ContentService::getContentByFolders($config['folders']);
     }
     // filters
     $content_set->filter($config);
     // custom filter, remove the 404 page if needed
     if (!$config['include_404']) {
         $content_set->customFilter(function ($item) {
             return $item['url'] !== '/404';
         });
     }
     // custom filter, remove any excluded folders
     if ($config['exclude']) {
         $excluded = Parse::pipeList($config['exclude']);
         $content_set->customFilter(function ($item) use($excluded) {
             foreach ($excluded as $exclude) {
                 if ($exclude === "*" || $exclude === "/*") {
                     // exclude all
                     return false;
                 } elseif (substr($exclude, -1) === "*") {
                     // wildcard check
                     if (strpos($item['_folder'], substr($exclude, 0, -1)) === 0) {
                         return false;
                     }
                 } else {
                     // plain check
                     if ($exclude == $item['_folder']) {
                         return false;
                     }
                 }
             }
             return true;
         });
     }
     $content_set->supplement(array('merge_with_data' => false));
     $content_set->prepare($config['include_content']);
     $data = $content_set->get();
     return $data;
 }
Exemplo n.º 5
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);
        }

        /*
        |--------------------------------------------------------------------------
        | 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_all is legacy
                    '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')
            ));
            $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'
        ));

        $html = "<div id='$this->field_id' class='suggest-field-container' data-config='$options'>";
        $html .= "<select 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) ? " 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;
    }
Exemplo n.º 6
0
 public static function find_relative($current, $folder = null, $future = false, $past = true, $show_hidden = false)
 {
     $content_set = ContentService::getContentByFolders($folder);
     $content_set->filter(array('show_hidden' => $show_hidden, 'show_drafts' => false, 'show_future' => $future, 'show_past' => $past, 'type' => 'entries'));
     $content_set->sort();
     $content = $content_set->get(false, false);
     $relative = array('prev' => null, 'next' => null);
     $use_next = false;
     $prev = false;
     foreach ($content as $data) {
         // find previous
         if (!$prev && $current != $data['url']) {
             $relative['prev'] = $data['url'];
             continue;
         }
         // we have found the current url
         // set the currently-set previous url to be `prev`
         // and mark the next iteration to use its value as `next`
         if ($current == $data['url']) {
             $prev = true;
             $use_next = true;
             continue;
         }
         // we should use this url as `next`
         if ($use_next) {
             $relative['next'] = $data['url'];
             break;
         }
     }
     return $relative;
 }
Exemplo n.º 7
0
 /**
  * Returns a ContentSet object with the appropriate content
  *
  * @param array  $settings  Settings for filtering content and such
  * @return ContentSet
  */
 private function getContentSet($settings)
 {
     // create a unique hash for these settings
     $content_hash = Helper::makeHash($settings);
     if ($this->blink->exists($content_hash)) {
         // blink content exists, use that
         $content_set = new ContentSet($this->blink->get($content_hash));
     } else {
         // no blink content exists, get data the hard way
         if ($settings['taxonomy']) {
             $taxonomy_parts = Taxonomy::getCriteria(URL::getCurrent());
             $taxonomy_type = $taxonomy_parts[0];
             $taxonomy_slug = Config::get('_taxonomy_slugify') ? Slug::humanize($taxonomy_parts[1]) : urldecode($taxonomy_parts[1]);
             $content_set = ContentService::getContentByTaxonomyValue($taxonomy_type, $taxonomy_slug, $settings['folders']);
         } else {
             $content_set = ContentService::getContentByFolders($settings['folders']);
         }
         // filter
         $content_set->filter($settings);
         // sort
         $content_set->sort($settings['sort_by'], $settings['sort_dir']);
         // store content as blink content for future use
         $this->blink->set($content_hash, $content_set->extract());
     }
     return $content_set;
 }
Exemplo n.º 8
0
Arquivo: statamic.php Projeto: nob/joi
 public static function find_next($current, $folder = NULL, $future = FALSE, $past = TRUE)
 {
     $content_set = ContentService::getContentByFolders($folder);
     $content_set->filter(array('show_future' => $future, 'show_past' => $past));
     $content_set->sort();
     $content = $content_set->get(false);
     $next = false;
     foreach ($content as $data) {
         if ($next) {
             return $data['url'];
         } elseif ($current == $data['url']) {
             $next = true;
         }
     }
     return $next;
     //    if ($folder == '') {
     //      $folder = '/';
     //    }
     //    $list = self::get_folder_list($folder, $future, $past);
     //    $keys = array_keys($list);
     //    $current_key = array_search($current, $keys);
     //    if ($current_key !== FALSE) {
     //      while (key($keys) !== $current_key) next($keys);
     //
     //        return prev($keys);
     //    }
     //
     //    return FALSE;
 }
Exemplo n.º 9
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);
     }
     /*
     |--------------------------------------------------------------------------
     | 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 $key => $entry) {
             if (isset($entry[$label]) && isset($entry[$value])) {
                 $suggestions[$entry[$value]] = $entry[$label];
             }
         }
     }
     /*
     |--------------------------------------------------------------------------
     | 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("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')));
         $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.
     |
     */
     $html = "<div id='{$this->field_id}'><select 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) ? " selected " : '';
         } else {
             $selected = $field_data == $value ? " selected " : '';
         }
         $html .= '<option value="' . $value . '" ' . $selected . '>' . $label . '</option>';
     }
     $html .= "</select>";
     $html .= "<div class='count-placeholder'></div></div>";
     /*
     |--------------------------------------------------------------------------
     | The JavaScript
     |--------------------------------------------------------------------------
     |
     | Set the config options, instantiate Selectize, and so forth.
     |
     */
     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'));
     $html .= "\n        <script>\n        \$(function() {\n\n            var selectize = \$('#{$this->field_id} select'),\n                options = {$options};\n\n            // @TODO: Rewrite in KO to avoid scoping issues in Grid fields\n            // if (max_items != null) {\n            //    var count = (value === null) ? 0 : value.length,\n            //        value = selectize.val(),\n            //        max_items = {$max_items};\n            //        remaining = max_items - count,\n            //        placeholder = \$('#{$this->field_id} .count-placeholder');\n            //     \$.extend(options, {\n            //             'onChange': function(value) {\n            //                 count = (value === null) ? 0 : value.length;\n            //                 remaining = max_items - count;\n            //                 placeholder.text(remaining + ' remaining');\n            //             }\n            //         }\n            //     );\n            //     placeholder.text(remaining + ' remaining');\n            // }\n\n            \$(selectize).selectize({$options});\n        });\n\n        </script>\n        ";
     return $html;
 }
Exemplo n.º 10
0
 public function render()
 {
     /*
     |--------------------------------------------------------------------------
     | 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.
     |
     */
     $multiple = array_get($this->field_config, 'multiple', true);
     $multiple_setting = $multiple ? "multiple" : "";
     $multiple_array_holder = $multiple ? "[]" : "";
     $default_placeholder = $multiple ? "Choose some options" : "Choose an option";
     $placeholder = isset($this->field_config['placeholder']) ? $this->field_config['placeholder'] : $default_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);
     }
     /*
     |--------------------------------------------------------------------------
     | 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_all' => array_get($config, 'show_all', 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' => 'entries', 'conditions' => trim(array_get($config, 'conditions'))));
         $entries = $content_set->get();
         // rd($entries);
         foreach ($entries as $key => $entry) {
             if (isset($entry[$label]) && isset($entry[$value])) {
                 $suggestions[$entry[$value]] = $entry[$label];
             }
         }
     }
     /*
     |--------------------------------------------------------------------------
     | 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("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);
     }
     /*
     |--------------------------------------------------------------------------
     | Input HTML
     |--------------------------------------------------------------------------
     |
     | Generate the HTML for the select field. A single, blank option is
     | needed if in single select mode.
     |
     */
     $html = "<div class='input-suggest-wrap'>";
     $html .= "<select name='{$this->fieldname}{$multiple_array_holder}' tabindex='{$this->tabindex}' {$multiple_setting} class='chosen-select' data-placeholder='{$placeholder}'>\n";
     if (!$multiple) {
         $html .= "<option value=''></option>\n";
     }
     foreach ($suggestions as $value => $label) {
         if ($multiple && is_array($this->field_data)) {
             $selected = in_array($value, $this->field_data) ? " selected " : '';
         } else {
             $selected = $this->field_data == $value ? " selected " : '';
         }
         $html .= "<option value='{$value}'{$selected}>{$label}</option>\n";
     }
     $html .= "</select></div>";
     return $html;
 }
Exemplo n.º 11
0
 /**
  * Displays entries on a map
  *
  * @return string
  */
 public function map()
 {
     // check for valid center point
     if (!preg_match(Pattern::COORDINATES, $this->fetchParam('center_point'), $matches)) {
         print_r($this->fetchParam('center_point'));
         $this->log->error("Could not create map, invalid center point coordinates given");
         return NULL;
     } else {
         $latitude = $matches[1];
         $longitude = $matches[2];
     }
     // pop-up template
     $pop_up_template = NULL;
     // check for a valid pop_up template
     if (preg_match_all("/(?:\\{\\{\\s*pop_up\\s*\\}\\})\\s*(.*)\\s*(?:\\{\\{\\s*\\/pop_up\\s*\\}\\})/ism", $this->content, $matches) && is_array($matches[1]) && isset($matches[1][0])) {
         $pop_up_template = trim($matches[1][0]);
     }
     $folders = $this->fetchParam('folder', ltrim($this->fetchParam('from', URL::getCurrent()), "/"));
     $folders = $folders === "/" ? "" : $folders;
     if ($this->fetchParam('taxonomy', false, null, true, null)) {
         $taxonomy_parts = Taxonomy::getCriteria(URL::getCurrent());
         $taxonomy_type = $taxonomy_parts[0];
         $taxonomy_slug = Config::get('_taxonomy_slugify') ? Slug::humanize($taxonomy_parts[1]) : urldecode($taxonomy_parts[1]);
         $content_set = ContentService::getContentByTaxonomyValue($taxonomy_type, $taxonomy_slug, $folders);
     } else {
         $content_set = ContentService::getContentByFolders($folders);
     }
     // filter
     $content_set->filter(array('show_all' => $this->fetchParam('show_hidden', false, null, true, false), 'since' => $this->fetchParam('since'), 'until' => $this->fetchParam('until'), 'show_past' => $this->fetchParam('show_past', true, null, true), 'show_future' => $this->fetchParam('show_future', false, null, true), 'type' => 'entries', 'conditions' => trim($this->fetchParam('conditions', null))));
     // supplement
     $content_set->supplement(array('locate_with' => $this->fetchParam('locate_with'), 'center_point' => $this->fetchParam('center_point'), 'pop_up_template' => $pop_up_template));
     // re-filter, we only want entries that have been found
     $content_set->filter(array('located' => true));
     // sort
     $content_set->sort($this->fetchParam('sort_by', 'order_key'), $this->fetchParam('sort_dir'));
     // limit
     $limit = $this->fetchParam('limit', null, 'is_numeric');
     $offset = $this->fetchParam('offset', 0, 'is_numeric');
     $paginate = $this->fetchParam('paginate', true, null, true, false);
     if ($limit || $offset) {
         if ($limit && $paginate && !$offset) {
             // pagination requested, isolate the appropriate page
             $content_set->isolatePage($limit, URL::getCurrentPaginationPage());
         } else {
             // just limit
             $content_set->limit($limit, $offset);
         }
     }
     // get content
     $parse_content = (bool) preg_match(Pattern::USING_CONTENT, $this->content);
     $content = $content_set->get($parse_content);
     // set variables
     $map_id = $this->fetchParam('map_id', Helper::getRandomString());
     $zoom = $this->fetchParam('zoom', 12);
     // cluster options
     $clusters = $this->fetchParam('clusters', TRUE, NULL, TRUE);
     $clusters = $clusters ? "true" : "false";
     $spiderfy_on_max_zoom = $this->fetchParam('spiderfy_on_max_zoom', TRUE, NULL, TRUE);
     $spiderfy_on_max_zoom = $spiderfy_on_max_zoom ? "true" : "false";
     $show_coverage_on_hover = $this->fetchParam('show_coverage_on_hover', TRUE, NULL, TRUE);
     $show_coverage_on_hover = $show_coverage_on_hover ? "true" : "false";
     $zoom_to_bounds_on_click = $this->fetchParam('zoom_to_bounds_on_click', TRUE, NULL, TRUE);
     $zoom_to_bounds_on_click = $zoom_to_bounds_on_click ? "true" : "false";
     $single_marker_mode = $this->fetchParam('single_marker_mode', FALSE, NULL, TRUE);
     $single_marker_mode = $single_marker_mode ? "true" : "false";
     $animate_adding_markers = $this->fetchParam('animate_adding_markers', TRUE, NULL, TRUE);
     $animate_adding_markers = $animate_adding_markers ? "true" : "false";
     $disable_clustering_at_zoom = $this->fetchParam('disable_clustering_at_zoom', 15, 'is_numeric');
     $max_cluster_radius = $this->fetchParam('max_cluster_radius', 80, 'is_numeric');
     // create output
     $html = '<div class="map" id="' . $map_id . '"></div>';
     $html .= "\n";
     // only render inline javascript if a valid pop_up template was found
     $html .= '<script type="text/javascript">';
     $html .= "try{_location_maps.length;}catch(e){var _location_maps={};}\n";
     $html .= '_location_maps["' . $map_id . '"] = { markers: [ ';
     $markers = array();
     foreach ($content as $item) {
         $marker = array('latitude' => $item['latitude'], 'longitude' => $item['longitude'], 'marker_content' => $item['marker_pop_up_content']);
         array_push($markers, json_encode($marker));
     }
     $html .= join(",\n", $markers);
     $html .= '    ], ';
     $html .= ' clusters: ' . $clusters . ',';
     // cluster options
     $html .= ' spiderfy_on_max_zoom: ' . $spiderfy_on_max_zoom . ',';
     $html .= ' show_coverage_on_hover: ' . $show_coverage_on_hover . ',';
     $html .= ' zoom_to_bounds_on_click: ' . $zoom_to_bounds_on_click . ',';
     $html .= ' single_marker_mode: ' . $single_marker_mode . ',';
     $html .= ' animate_adding_markers: ' . $animate_adding_markers . ',';
     $html .= ' disable_clustering_at_zoom: ' . $disable_clustering_at_zoom . ',';
     $html .= ' max_cluster_radius: ' . $max_cluster_radius . ',';
     $html .= ' starting_latitude: ' . $latitude . ',';
     $html .= ' starting_longitude: ' . $longitude . ',';
     $html .= ' starting_zoom: ' . $zoom . ' };';
     $html .= '</script>';
     return $html;
 }
Exemplo n.º 12
0
    /**
     * Returns a ContentSet object with the appropriate content
     *
     * @param array  $settings  Settings for filtering content and such
     * @return ContentSet
     */
    private function getContentSet($settings)
    {
        // create a unique hash for these settings
        $content_hash = Helper::makeHash($settings);

        if ($this->blink->exists($content_hash)) {
            // blink content exists, use that
            $content_set = new ContentSet($this->blink->get($content_hash));
        } else {
            // no blink content exists, get data the hard way
            if ($settings['taxonomy']) {
                $taxonomy_parts  = Taxonomy::getCriteria(URL::getCurrent());
                $taxonomy_type   = $taxonomy_parts[0];
                $taxonomy_slug   = Config::get('_taxonomy_slugify') ? Slug::humanize($taxonomy_parts[1]) : urldecode($taxonomy_parts[1]);

                $content_set = ContentService::getContentByTaxonomyValue($taxonomy_type, $taxonomy_slug, $settings['folders']);
            } else {
                $content_set = ContentService::getContentByFolders($settings['folders']);
            }

            // filter
            $content_set->filter($settings);

            // supplement
            $content_set->supplement(array(
                'locate_with'     => $settings['locate_with'],
                'center_point'    => $settings['center_point'],
                'pop_up_template' => $this->content
            ));

            // re-filter, we only want entries that have been found
            $content_set->filter(array('located' => true));

            // sort
            $content_set->sort($settings['sort_by'], $settings['sort_dir']);

            // store content as blink content for future use
            $this->blink->set($content_hash, $content_set->extract());
        }

        return $content_set;
    }