Esempio n. 1
0
 public function __construct($path, $sanitized = false)
 {
     if ($sanitized) {
         $this->path = $path;
     } else {
         $this->path = Path::resolve($path);
     }
 }
Esempio n. 2
0
File: pi.nav.php Progetto: nob/joi
 public function count()
 {
     $url = $this->fetchParam('from', URL::getCurrent());
     $url = Path::resolve($url);
     $max_depth = $this->fetchParam('max_depth', 1, 'is_numeric');
     $tree = Statamic::get_content_tree($url, 1, $max_depth);
     if ($this->content != '') {
         return Parse::tagLoop($this->content, $tree);
     } else {
         return count($tree);
     }
 }
Esempio n. 3
0
File: routes.php Progetto: nob/joi
 if (substr($path, -5) == '.html') {
     $path = str_replace('.html', '', $path);
 }
 $app->config['current_path'] = $path;
 // init some variables for below
 $content_root = Config::getContentRoot();
 $content_type = Config::getContentType();
 $response_code = 200;
 $visible = true;
 $add_prev_next = false;
 $template_list = array('default');
 // set up the app based on if a
 if (File::exists("{$content_root}/{$path}.{$content_type}") || Folder::exists("{$content_root}/{$path}")) {
     // endpoint or folder exists!
 } else {
     $path = Path::resolve($path);
     $app->config['current_url'] = $app->config['current_path'];
     $app->config['current_path'] = $path;
     # override global current_path
 }
 // routes via routes.yaml
 if (isset($app->config['_routes']['routes'][$current_url]) || isset($app->config['_routes'][$current_url])) {
     # allows the route file to run without "route:" as the top level array key (backwards compatibility)
     $current_route = isset($app->config['_routes']['routes'][$current_url]) ? $app->config['_routes']['routes'][$current_url] : $app->config['_routes'][$current_url];
     $route = $current_route;
     $template = $route;
     $data = array();
     if (is_array($route)) {
         $template = isset($route['template']) ? $route['template'] : 'default';
         if (isset($route['layout'])) {
             $data['_layout'] = $route['layout'];
Esempio n. 4
0
 public static function get_content_all($folder = null, $future = false, $past = true, $conditions = null, $skip_status = false, $parse = true, $since = null, $until = null, $location = null, $distance_from = null)
 {
     $content_type = Config::getContentType();
     $site_root = Config::getSiteRoot();
     $absolute_folder = Path::resolve($folder);
     $posts = self::get_file_list($absolute_folder);
     $list = array();
     // should we factor in location and distance?
     $measure_distance = !is_null($location) && !is_null($distance_from) && preg_match(Pattern::COORDINATES, $distance_from, $matches);
     if ($measure_distance) {
         $center_point = array($matches[1], $matches[2]);
     }
     foreach ($posts as $key => $post) {
         // starts with numeric value
         unset($list[$key]);
         if ((preg_match(Pattern::DATE, $key) || preg_match(Pattern::NUMERIC, $key)) && File::exists($post . ".{$content_type}")) {
             $data = Statamic::get_content_meta($key, $absolute_folder, false, $parse);
             $list[$key] = $data;
             $list[$key]['url'] = $folder ? $site_root . $folder . "/" . $key : $site_root . $key;
             $list[$key]['raw_url'] = $list[$key]['url'];
             // Clean the folder numbers out
             $list[$key]['url'] = Path::clean($list[$key]['url']);
             # Set status and "raw" slug
             if (substr($key, 0, 2) === "__") {
                 $list[$key]['status'] = 'draft';
                 $list[$key]['slug'] = substr($key, 2);
             } elseif (substr($key, 0, 1) === "_") {
                 $list[$key]['status'] = 'hidden';
                 $list[$key]['slug'] = substr($key, 1);
             } else {
                 $list[$key]['slug'] = $key;
             }
             $slug = $list[$key]['slug'];
             $date_entry = false;
             if (Config::getEntryTimestamps() && Slug::isDateTime($slug)) {
                 $datestamp = Slug::getTimestamp($key);
                 $date_entry = true;
                 # strip the date
                 $list[$key]['slug'] = preg_replace(Pattern::DATETIME, '', $slug);
                 $list[$key]['url'] = preg_replace(Pattern::DATETIME, '', $list[$key]['url']);
                 #override
                 $list[$key]['datestamp'] = $data['datestamp'];
                 $list[$key]['date'] = $data['date'];
             } elseif (Slug::isDate($slug)) {
                 $datestamp = Slug::getTimestamp($slug);
                 $date_entry = true;
                 # strip the date
                 // $list[$key]['slug'] = substr($key, 11);
                 $list[$key]['slug'] = preg_replace(Pattern::DATE, '', $slug);
                 $list[$key]['url'] = preg_replace(Pattern::DATE, '', $list[$key]['url']);
                 #override
                 $list[$key]['datestamp'] = $data['datestamp'];
                 $list[$key]['date'] = $data['date'];
             } else {
                 $list[$key]['slug'] = preg_replace(Pattern::NUMERIC, '', $slug);
                 $list[$key]['url'] = preg_replace(Pattern::NUMERIC, '', $list[$key]['url'], 1);
                 #override
             }
             $list[$key]['url'] = Path::tidy('/' . $list[$key]['url']);
             # fully qualified url
             $list[$key]['permalink'] = Path::tidy(Config::getSiteURL() . '/' . $list[$key]['url']);
             /* $content  = preg_replace('/<img(.*)src="(.*?)"(.*)\/?>/', '<img \/1 src="'.Statamic::get_asset_path(null).'/\2" /\3 />', $data['content']); */
             //$list[$key]['content'] = Statamic::transform_content($data['content']);
             // distance
             if (isset($list[$key][$location]['latitude']) && $list[$key][$location]['latitude'] && isset($list[$key][$location]['longitude']) && $list[$key][$location]['longitude']) {
                 $list[$key]['coordinates'] = $list[$key][$location]['latitude'] . "," . $list[$key][$location]['longitude'];
             }
             if ($measure_distance && is_array($center_point)) {
                 if (!isset($list[$key][$location]) || !is_array($list[$key][$location])) {
                     unset($list[$key]);
                 }
                 if (isset($list[$key][$location]['latitude']) && $list[$key][$location]['latitude'] && isset($list[$key][$location]['longitude']) && $list[$key][$location]['longitude']) {
                     $list[$key]['distance_km'] = Statamic_Helper::get_distance_in_km($center_point, array($list[$key][$location]['latitude'], $list[$key][$location]['longitude']));
                     $list[$key]['distance_mi'] = Statamic_Helper::convert_km_to_miles($list[$key]['distance_km']);
                 } else {
                     unset($list[$key]);
                 }
             }
             if (!$skip_status) {
                 if (isset($data['status']) && $data['status'] != 'live') {
                     unset($list[$key]);
                 }
             }
             // Remove future entries
             if ($date_entry && $future === false && $datestamp > time()) {
                 unset($list[$key]);
             }
             // Remove past entries
             if ($date_entry && $past === false && $datestamp < time()) {
                 unset($list[$key]);
             }
             // Remove entries before $since
             if ($date_entry && !is_null($since) && $datestamp < strtotime($since)) {
                 unset($list[$key]);
             }
             // Remove entries after $until
             if ($date_entry && !is_null($until) && $datestamp > strtotime($until)) {
                 unset($list[$key]);
             }
             if ($conditions) {
                 $keepers = array();
                 $conditions_array = explode(",", $conditions);
                 foreach ($conditions_array as $condition) {
                     $condition = trim($condition);
                     $inclusive = true;
                     list($condition_key, $condition_values) = explode(":", $condition);
                     # yay php!
                     $pos = strpos($condition_values, 'not ');
                     if ($pos === false) {
                     } else {
                         if ($pos == 0) {
                             $inclusive = false;
                             $condition_values = substr($condition_values, 4);
                         }
                     }
                     $condition_values = explode("|", $condition_values);
                     foreach ($condition_values as $k => $condition_value) {
                         $keep = false;
                         if (isset($list[$key][$condition_key])) {
                             if (is_array($list[$key][$condition_key])) {
                                 foreach ($list[$key][$condition_key] as $key2 => $value2) {
                                     #todo add regex driven taxonomy matching here
                                     if ($inclusive) {
                                         if (strtolower($value2['name']) == strtolower($condition_value)) {
                                             $keepers[$key] = $key;
                                             break;
                                         }
                                     } else {
                                         if (strtolower($value2['name']) != strtolower($condition_value)) {
                                             $keepers[$key] = $key;
                                         } else {
                                             // EXCLUDE!
                                             unset($keepers[$key]);
                                             break;
                                         }
                                     }
                                 }
                             } else {
                                 if ($list[$key][$condition_key] == $condition_value) {
                                     if ($inclusive) {
                                         $keepers[$key] = $key;
                                     } else {
                                         unset($keepers[$key]);
                                     }
                                 } else {
                                     if (!$inclusive) {
                                         $keepers[$key] = $key;
                                     }
                                 }
                             }
                         } else {
                             $keep = false;
                         }
                     }
                     if (!$keep && !in_array($key, $keepers)) {
                         unset($list[$key]);
                     }
                 }
             }
         }
     }
     return $list;
 }
})->name('files');
// Delete file
$admin_app->get('/file/delete', function () use($admin_app) {
    authenticateForRole('admin');
    doStatamicVersionCheck($admin_app);
    $result = Addon::getAPI('file')->deleteFile();
    $response = $admin_app->response();
    $response['Content-Type'] = 'application/json';
    $response->status(200);
    $response->body(json_encode($result));
})->name('delete_file');
$admin_app->get('/url/unique', function () use($admin_app) {
    $folder = Request::get('folder');
    $url = Request::get('url');
    $path = URL::assemble($folder, $url);
    $data = array('exists' => Content::exists(Path::resolve($path)));
    $response = $admin_app->response();
    $response['Content-Type'] = 'application/json';
    $response->body(json_encode($data));
});
/*
|--------------------------------------------------------------------------
| Hook: Add Routes
|--------------------------------------------------------------------------
|
| Allows add-ons to add their own hooks to the control panel.
|
*/
Hook::run('control_panel', 'add_routes');
// GET: 404
// --------------------------------------------------------
Esempio n. 6
0
File: helper.php Progetto: nob/joi
 /**
  * resolve_path
  * Finds the actual path from a URL-friendly $path
  *
  * @deprecated As of v1.5
  * @param string  $path  Path to resolve
  * @return string
  */
 public static function resolve_path($path)
 {
     Log::warn("Use of Statamic_Helper::resolve_path() is deprecated. Use Path::resolve() instead.", "core", "Statamic_Helper");
     return Path::resolve($path);
 }
 function cleanFoldersList($folder_params)
 {
     $folder_params_array = Helper::explodeOptions($folder_params, false);
     foreach ($folder_params_array as $part) {
         $folders[] = '/_content' . Path::resolve($part) . '/';
     }
     return $folders;
 }