Example #1
0
 /**
  * Lists entries based on passed parameters
  *
  * @return array|string
  */
 public function listing()
 {
     // grab common parameters
     $settings = $this->parseCommonParameters();
     // grab content set based on the common parameters
     $content_set = $this->getContentSet($settings);
     // 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);
         }
     }
     // check for results
     if (!$content_set->count()) {
         return Parse::template($this->content, array('no_results' => true));
     }
     return Parse::tagLoop($this->content, $content_set->get(), true, $this->context);
 }
 /**
  * List entries
  */
 public function map_listing()
 {
     // parse settings
     $settings = $this->parseParameters();
     // check for valid center point
     if (preg_match(Pattern::COORDINATES, $settings['center_point'], $matches)) {
         $settings['starting_latitude'] = $matches[1];
         $settings['starting_longitude'] = $matches[2];
     }
     // get related content
     $content_set = $this->getContentSet($settings);
     // 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);
         }
     }
     $content_set->prepare(false, true);
     $content = $content_set->get();
     return $this->buildScript($content, $settings);
 }
Example #3
0
File: pi.pages.php Project: 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));
 }
Example #4
0
 /**
  * Search over data
  * 
  * @return string
  */
 public function search()
 {
     // determine configuration
     $dataset = $this->fetch('dataset', null, false, false, false);
     $parameters = $this->gatherParameters();
     $config = $this->tasks->loadDataset($dataset, $parameters);
     // short-circuit this if no query
     if (!trim($config['query'])) {
         return Parse::tagLoop($this->content, array(array('no_query' => true, '_query' => '')));
     }
     // do search
     $output = $this->tasks->lookUp($config['query'], $config);
     $total_found = count($output);
     // limit if we need to
     if ($config['limit'] || $config['offset']) {
         if ($config['limit'] && $config['paginate'] && !$config['offset']) {
             // pagination requested, isolate the appropriate page
             $count = count($output);
             $page = URL::getCurrentPaginationPage();
             // return the last page of results if $page is out of range
             if (Config::getFixOutOfRangePagination()) {
                 if ($config['page_limit'] && $page > $config['page_limit']) {
                     $page = $config['page_limit'];
                 } elseif ($config['limit'] * $page > $count) {
                     $page = ceil($count / $config['limit']);
                 } elseif ($page < 1) {
                     $page = 1;
                 }
             }
             $offset = ($page - 1) * $config['limit'];
             $output = array_slice($output, $offset, $config['limit']);
         } else {
             // just limit or offset
             $output = array_slice($output, $config['offset'], $config['limit']);
         }
     }
     // supplement with first, last, etc.
     $output = $this->tasks->supplement($output, array('total_found' => $total_found));
     return Parse::tagLoop($this->content, $output);
 }
Example #5
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()), "/"));

        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_hidden' => $this->fetchParam('show_hidden', false, null, true, false),
            'show_drafts' => $this->fetchParam('show_drafts', 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))
        ));
        
        // prepare if needed
        $parse_content = (bool) preg_match(Pattern::USING_CONTENT, $this->content);
        if ($parse_content) {
            $content_set->prepare();
        }

        // supplement
        $content_set->supplement(array(
            'locate_with'     => $this->fetchParam('locate_with'),
            'center_point'    => $this->fetchParam('center_point')
        ));

        // 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
        $content_set->prepare(false, true);
        $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' => Content::parse($pop_up_template, $item, 'html')
            );

            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;
    }
Example #6
0
 public function listing()
 {
     if (Config::get('disable_member_cache')) {
         $this->log->error("Cannot use `member:listing` when `_disable_member_cache` is `true`.");
         return Parse::template($this->content, array('no_results' => true));
     }
     // grab common parameters
     $settings = $this->parseCommonParameters();
     // grab member set based on the common parameters
     $member_set = $this->getMemberSet($settings);
     // grab total members for setting later
     $total_members = $member_set->count();
     // no users found? return no results
     if (!$total_members) {
         return Parse::template($this->content, array('no_results' => true));
     }
     // 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
             $member_set->isolatePage($limit, URL::getCurrentPaginationPage());
         } else {
             // just limit or offset
             $member_set->limit($limit, $offset);
         }
     }
     // manually supplement
     $member_set->supplement(array('total_found' => $total_members));
     // check for results
     if (!$member_set->count()) {
         return Parse::template($this->content, array('no_results' => true));
     }
     return Parse::tagLoop($this->content, $member_set->get(), true, $this->context);
 }