Example #1
0
File: url.php Project: nob/joi
 /**
  * Get the full URL for the current request.
  *
  * @param boolean  $include_root  Should this include the site root itself?
  * @return string
  */
 public static function getCurrent($include_root = true)
 {
     $url = Request::getResourceURI();
     if ($include_root) {
         $url = Config::getSiteRoot() . '/' . $url;
     }
     return self::format($url);
 }
 /**
  * Add the modal to the footer
  *
  * @return string
  */
 public function control_panel__add_to_foot()
 {
     // don't do anything on the login screen
     if (Request::getResourceURI() == '/login') {
         return false;
     }
     // master switch for revisions
     if (!$this->core->isEnabled()) {
         return false;
     }
     if (!URL::getCurrent() == '/publish') {
         return false;
     }
     $path = $this->core->getPath();
     $view_data = array('revisions' => $this->core->getRevisions($path), 'path' => $path);
     // revision selector
     $view = File::get($this->getAddonLocation() . 'views/modal.html');
     $html = Parse::template($view, $view_data);
     // revision message
     $view = File::get($this->getAddonLocation() . 'views/commit_modal.html');
     $html .= Parse::template($view, $view_data);
     return $html;
 }
Example #3
0
 /**
  * Supplements the content in the set
  *
  * @param array  $context  Context for supplementing
  * @return void
  */
 public function supplement($context = array())
 {
     $hash = Debug::markStart('content', 'supplementing');
     if ($this->supplemented) {
         return;
     }
     $this->supplemented = true;
     $context = Helper::ensureArray($context);
     // determine context
     $given_context = $context;
     $context = array('locate_with' => isset($given_context['locate_with']) ? $given_context['locate_with'] : null, 'center_point' => isset($given_context['center_point']) ? $given_context['center_point'] : null, 'list_helpers' => isset($given_content['list_helpers']) ? $given_context['list_helpers'] : true, 'context_urls' => isset($given_context['context_urls']) ? $given_context['context_urls'] : true, 'total_found' => isset($given_context['total_found']) ? $given_context['total_found'] : null, 'group_by_date' => isset($given_context['group_by_date']) ? $given_context['group_by_date'] : null, 'inherit_folder_data' => isset($given_context['inherit_folder_data']) ? $given_context['inherit_folder_data'] : true, 'merge_with_data' => isset($given_context['merge_with_data']) ? $given_context['merge_with_data'] : true);
     // set up helper variables
     $center_point = false;
     if ($context['center_point'] && preg_match(Pattern::COORDINATES, $context['center_point'], $matches)) {
         $center_point = array($matches[1], $matches[2]);
     }
     // contextual urls are based on current page, not individual data records
     // we can figure this out once and then set it with each one
     if ($context['context_urls']) {
         $raw_url = Request::getResourceURI();
         $page_url = Path::tidy($raw_url);
     }
     // iteration memory
     $last_date = null;
     // loop through content, supplementing each record with data
     foreach ($this->content as $content_key => $data) {
         // locate
         if ($context['locate_with']) {
             $location_data = isset($data[$context['locate_with']]) ? $data[$context['locate_with']] : null;
             // check that location data is fully set
             if (is_array($location_data) && isset($location_data['latitude']) && $location_data['latitude'] && isset($location_data['longitude']) && $location_data['longitude']) {
                 $data['latitude'] = $location_data['latitude'];
                 $data['longitude'] = $location_data['longitude'];
                 $data['coordinates'] = $location_data['latitude'] . "," . $location_data['longitude'];
                 // get distance from center
                 if ($center_point) {
                     $location = array($data['latitude'], $data['longitude']);
                     $data['distance_km'] = Math::getDistanceInKilometers($center_point, $location);
                     $data['distance_mi'] = Math::convertKilometersToMiles($data['distance_km']);
                 }
             }
         }
         // contextual urls
         if ($context['context_urls']) {
             $data['raw_url'] = $raw_url;
             $data['page_url'] = $page_url;
         }
         // total entries
         if ($context['total_found']) {
             $data['total_found'] = (int) $context['total_found'];
         }
         // group by date
         if ($context['group_by_date'] && $data['datestamp']) {
             $formatted_date = Date::format($context['group_by_date'], $data['datestamp']);
             if ($formatted_date !== $last_date) {
                 $last_date = $formatted_date;
                 $data['grouped_date'] = $formatted_date;
             } else {
                 $data['grouped_date'] = '';
             }
         }
         // loop through content to add data for variables that are arrays
         foreach ($data as $key => $value) {
             // Only run on zero indexed arrays/loops
             if (is_array($value) && isset($value[0]) && !is_array($value[0])) {
                 // list helpers
                 if ($context['list_helpers']) {
                     // make automagic lists
                     $data[$key . "_list"] = join(", ", $value);
                     $data[$key . "_spaced_list"] = join(" ", $value);
                     $data[$key . "_option_list"] = join("|", $value);
                     $data[$key . "_ordered_list"] = "<ol><li>" . join("</li><li>", $value) . "</li></ol>";
                     $data[$key . "_unordered_list"] = "<ul><li>" . join("</li><li>", $value) . "</li></ul>";
                     $data[$key . "_sentence_list"] = Helper::makeSentenceList($value);
                     $data[$key . "_ampersand_sentence_list"] = Helper::makeSentenceList($value, "&", false);
                     // handle taxonomies
                     if (Taxonomy::isTaxonomy($key)) {
                         $url_list = array_map(function ($item) use($data, $key, $value) {
                             return '<a href="' . Taxonomy::getURL($data['_folder'], $key, $item) . '">' . $item . '</a>';
                         }, $value);
                         $data[$key . "_url_list"] = join(", ", $url_list);
                         $data[$key . "_spaced_url_list"] = join(" ", $url_list);
                         $data[$key . "_ordered_url_list"] = "<ol><li>" . join("</li><li>", $url_list) . "</li></ol>";
                         $data[$key . "_unordered_url_list"] = "<ul><li>" . join("</li><li>", $url_list) . "</li></ul>";
                         $data[$key . "_sentence_url_list"] = Helper::makeSentenceList($url_list);
                         $data[$key . "_ampersand_sentence_url_list"] = Helper::makeSentenceList($url_list, "&", false);
                     }
                 }
             }
         }
         // update content with supplemented data merged with global config data
         if ($context['merge_with_data'] || $context['inherit_folder_data']) {
             $folder_data = array();
             $all_config = array();
             if ($context['inherit_folder_data']) {
                 $folder_data = $this->getFolderData($data['_file']);
             }
             if ($context['merge_with_data']) {
                 $all_config = Config::getAll();
             }
             // merge them all together
             $this->content[$content_key] = $data + $folder_data + $all_config;
         } else {
             $this->content[$content_key] = $data;
         }
     }
     Debug::markEnd($hash);
 }
Example #4
0
            $template_list[] = "post";
        }

        if ($path !== "/404") {
            $content_found = true;
        }

    // url is taxonomy-based
    } elseif (Taxonomy::isTaxonomyURL($path)) {
        list($type, $slug) = Taxonomy::getCriteria($path);

        // create data array
        $data = array_merge(Config::getAll(), array(
            'homepage'       => Config::getSiteRoot(),
            'raw_url'        => Request::getResourceURI(),
            'page_url'       => Request::getResourceURI(),
            'taxonomy_slug'  => urldecode($slug),
            'taxonomy_name'  => Taxonomy::getTaxonomyName($type, $slug)
        ));

        $template_list[] = "taxonomies";
        $template_list[] = $type;
        $content_found = true;
    }

    
    // content was found
    if ($content_found) {
        // mark milestone for debug panel
        Debug::markMilestone('content found');
        
Example #5
0
File: routes.php Project: nob/joi
     // actual file exists
 } elseif (File::exists("{$content_root}/{$path}.{$content_type}")) {
     $add_prev_next = true;
     $template_list[] = 'post';
     $page = basename($path);
     $data = Content::get($complete_current_url);
     $data['current_url'] = $current_url;
     $data['slug'] = basename($current_url);
     if ($path !== "404") {
         $content_found = true;
     }
     // url is taxonomy-based
 } elseif (Taxonomy::isTaxonomyURL($path)) {
     list($type, $slug) = Taxonomy::getCriteria($path);
     // create data array
     $data = array_merge(Config::getAll(), array('homepage' => Config::getSiteRoot(), 'raw_url' => Request::getResourceURI(), 'page_url' => Request::getResourceURI(), 'taxonomy_slug' => urldecode($slug), 'taxonomy_name' => Taxonomy::getTaxonomyName($type, $slug)));
     $template_list[] = "taxonomies";
     $template_list[] = $type;
     $content_found = true;
     // this is a directory,so we look for page.md
 } elseif (is_dir("{$content_root}/{$path}")) {
     $data = Content::get($complete_current_url);
     $content_found = true;
 }
 // Nothing found. 404 O'Clock.
 if (!$content_found || $requesting_xml && (!isset($data['_type']) || $data['_type'] != 'xml')) {
     // determine where user came from for log message
     if (strstr($path, 'favicon.ico')) {
         // Favicons are annoying.
         Log::info("The site favicon could not be found.", "site", "favicon");
     } else {
Example #6
0
 public static function get_asset_path($asset)
 {
     $content_root = Config::getContentRoot();
     return "{$content_root}" . Request::getResourceURI() . '' . $asset;
 }
     $page = basename($path);
     $data['current_url'] = $current_url;
     $data['slug'] = basename($current_url);
     // if this is an entry, default to the `post` template
     if ($data['_is_entry']) {
         $template_list[] = array_get($data, '_template', 'default');
         $template_list[] = "post";
     }
     if ($path !== "/404") {
         $content_found = true;
     }
     // url is taxonomy-based
 } elseif (Taxonomy::isTaxonomyURL($path)) {
     $taxonomy = Taxonomy::getCriteria($path);
     // create data array
     $data = array_merge(Config::getAll(), array('homepage' => Config::getSiteRoot(), 'raw_url' => Request::getResourceURI(), 'page_url' => Request::getResourceURI(), 'taxonomy_slug' => $taxonomy['slug'], 'taxonomy_name' => Taxonomy::getTaxonomyName($taxonomy['type'], $taxonomy['slug'])));
     $template_list[] = "taxonomies";
     $template_list[] = $taxonomy['type'];
     if (!$taxonomy['slug']) {
         $template_list[] = "taxonomy-index";
         $template_list[] = $taxonomy['type'] . "-index";
     }
     $content_found = true;
 }
 // content was found
 if ($content_found) {
     // mark milestone for debug panel
     Debug::markMilestone('content found');
     // protect
     if (is_array($data) && $data) {
         try {