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; }
$data['original_numeric'] = ''; if ($type == 'none') { $data['folder'] = $path; $data['full_slug'] = $path; $data['slug'] = 'page'; } } else { $page = basename($path); $folder = substr($path, 0, -1 * strlen($page) - 1); if (!Content::exists($page, $folder)) { $app->flash('error', Localization::fetch('content_not_found')); $url = $app->urlFor('pages'); $app->redirect($url); return; } $data = Statamic::get_content_meta($page, $folder, true); $data['title'] = isset($data['title']) ? $data['title'] : ''; $data['slug'] = basename($path); $data['full_slug'] = $folder . "/" . $page; $data['path'] = $path; $data['folder'] = $folder; $data['page'] = $page; $data['type'] = 'none'; $data['original_slug'] = ''; $data['original_datestamp'] = ''; $data['original_timestamp'] = ''; $data['original_numeric'] = ''; $data['datestamp'] = 0; if ($page == 'page') { $page = basename($folder); if ($page == '') {