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); } }
private function order_set($page_order, $entry_folder) { $content_path = Config::getContentRoot(); $entries = Statamic::get_content_tree('/' . $entry_folder, 3, 5, false, true); $result = array('linkage' => null, 'message' => 'Page order saved successfully!', 'status' => 'success'); // Array to store the links of old data coupled with new data. // We return this to the view so we can use JS to update the pathing on the page. $links = array(); // Loop over original folder structure and rename all folders to // reflect the new order. $entry_url = implode('/', explode('/', $page_order[0]->url, -1)); $entry_url = str_replace(Config::getSiteRoot(), '', $entry_folder); foreach ($page_order as $page) { $page_url = str_replace(Config::getSiteRoot(), '/', $page->url); foreach ($entries as $entry) { // Store original folder data. $file_ext = pathinfo($entry['raw_url'], PATHINFO_EXTENSION); // used to generate the old pathing info. $old_slug = $entry['slug']; // Match on the URL to get the correct order result for this item. if ($page_url == $entry['url']) { break; } } $slug = explode('/', $page->url); $slug = preg_replace("/^\\/(.+)/uis", "\$1", end($slug)); $new_name = sprintf("%02d", $page->index + 1) . '.' . $slug; $old_name = $old_slug; $links[] = array('old' => $old_name, 'new' => $new_name); $folder_path = $content_path . "/" . $entry_folder . "/"; // Generate pathing to pass to rename() $new_path = $folder_path . $new_name . '.' . $file_ext; $old_path = $folder_path . $old_name . '.' . $file_ext; if ($new_path !== $old_path) { // Check the old path actually exists and the new one doesn't. if (File::exists($old_path) && !File::exists($new_path)) { rename($old_path, $new_path); } else { $result['status'] = 'error'; $result['message'] = 'Aborting: Can\'t guarantee file integrity ' . 'for folders ' . $old_path . ' & ' . $new_path; Log::error($result['message'], 'pagereorder_redux'); break; } } } if ($result['status'] !== 'error') { // No error, set links $result['linkage'] = $links; } return $result; }
/** * Finds a given path on the server, adding in any ordering elements missing * * @param string $path Path to resolve * @return string */ public static function resolve($path) { $content_root = Config::getContentRoot(); $content_type = Config::getContentType(); if (strpos($path, "/") === 0) { $parts = explode("/", substr($path, 1)); } else { $parts = explode("/", $path); } $fixedpath = "/"; foreach ($parts as $part) { if (!File::exists(Path::assemble($content_root, $path . '.' . $content_type)) && !is_dir(Path::assemble($content_root, $part))) { // check folders $list = Statamic::get_content_tree($fixedpath, 1, 1, FALSE, TRUE, FALSE); foreach ($list as $item) { $t = basename($item['slug']); if (Slug::isNumeric($t)) { $nl = strlen(Slug::getOrderNumber($t)) + 1; if (strlen($part) >= strlen($item['slug']) - $nl && Pattern::endsWith($item['slug'], $part)) { $part = $item['slug']; break; } } else { if (Pattern::endsWith($item['slug'], $part)) { if (strlen($part) >= strlen($t)) { $part = $item['slug']; break; } } } } // check files $list = Statamic::get_file_list($fixedpath); foreach ($list as $key => $item) { if (Pattern::endsWith($key, $part)) { $t = basename($item); $offset = 0; if (Pattern::startsWith($key, '__')) { $offset = 2; } elseif (Pattern::startsWith($key, '_')) { $offset = 1; } if (Config::getEntryTimestamps() && Slug::isDateTime($t)) { if (strlen($part) >= strlen($key) - 16 - $offset) { $part = $key; break; } } elseif (Slug::isDate($t)) { if (strlen($part) >= strlen($key) - 12 - $offset) { $part = $key; break; } } elseif (Slug::isNumeric($t)) { $nl = strlen(Slug::getOrderNumber($key)) + 1; if (strlen($part) >= strlen($key) - $nl - $offset) { $part = $key; break; } } else { $t = basename($item); if (strlen($part) >= strlen($t) - $offset) { $part = $key; break; } } } } } if ($fixedpath != '/') { $fixedpath .= '/'; } $fixedpath .= $part; } return $fixedpath; }
$index_file = true; } $errors = array(); if (!$form_data['yaml']['title'] || $form_data['yaml']['title'] == '') { $errors['title'] = Localization::fetch('is_required'); } $slug = $form_data['meta']['slug'] === '/' ? '/' : Slug::make($form_data['meta']['slug']); if ($index_file) { // some different validation rules if ($slug == '') { $errors['slug'] = Localization::fetch('is_required'); } else { if ($slug != $form_data['original_slug']) { if ($form_data['type'] == 'none') { $file = $check_file = $content_root . "/" . $path . "/" . $slug . "/page." . $content_type; $folders = Statamic::get_content_tree($path, 1, 1, false, false, true); if (Statamic_Validate::folder_slug_exists($folders, $slug)) { $errors['slug'] = Localization::fetch('already_exists'); } } else { $file = $content_root . "/" . dirname($path) . "/page." . $content_type; $check_file = str_replace($form_data['original_slug'], $slug, $file); if (File::exists($check_file)) { $errors['slug'] = Localization::fetch('already_exists'); } } } } } elseif (isset($form_data['type']) && $form_data['type'] == 'none') { $file = $content_root . "/" . $path . "/" . $slug . "." . $content_type; if (File::exists($file)) {