예제 #1
0
파일: pi.pages.php 프로젝트: 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));
 }
예제 #2
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;
    }
 /**
  * Returns a taxonomy slug's name if stored in cache
  *
  * @param string  $taxonomy  Taxonomy to use
  * @param string  $taxonomy_slug  Taxonomy slug to use
  * @return mixed
  */
 public static function getTaxonomyName($taxonomy, $taxonomy_slug)
 {
     self::loadCache();
     if (Config::getTaxonomySlugify()) {
         $taxonomy_slug = Slug::humanize($taxonomy_slug);
     }
     if (!isset(self::$cache['taxonomies'][$taxonomy]) || !isset(self::$cache['taxonomies'][$taxonomy][$taxonomy_slug])) {
         return null;
     }
     return self::$cache['taxonomies'][$taxonomy][$taxonomy_slug]['name'];
 }
예제 #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;
 }
예제 #5
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;
 }
예제 #6
0
파일: helper.php 프로젝트: nob/joi
 /**
  * deslugify
  * Converts a string from slug-format to normal-format
  *
  * @deprecated  Use Slug::humanize() instead
  *
  * @param string  $text  String to convert
  * @return string
  */
 public static function deslugify($text)
 {
     Log::warn("Use of Statamic_Helper::deslugify() is deprecated. Use Slug::humanize() instead.", "core", "Statamic_Helper");
     return Slug::humanize($text);
 }
예제 #7
0
파일: pi.entries.php 프로젝트: nob/joi
 /**
  * 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;
 }
예제 #8
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;
    }