public function getFiles($formset, $path, $extension = "yaml") { if (!Folder::exists($path)) { return array(); } $finder = new Finder(); $matches = $finder->name("*." . $extension)->depth(0)->files()->followLinks()->in($path); $files = array(); foreach ($matches as $file) { // Ignore page.md if ($file->getFilename() == 'page.md') { continue; } $file_data = Parse::yaml($file->getContents()); $file_data['datestamp'] = date(array_get($this->config, 'datestamp_format', "m/d/Y"), $file->getMTime()); $meta = array('path' => $file->getRealpath(), 'filename' => $file->getFilename(), 'formset' => $formset, 'extension' => $file->getExtension(), 'datestamp' => $file->getMTime()); $meta['edit_path'] = Path::trimSlashes(Path::trimFileSystemFromContent(substr($meta['path'], 0, -1 - strlen($meta['extension'])))); $data = array('meta' => $meta, 'fields' => $file_data); $files[] = $data; } return array_reverse($files); }
public static function get_listings() { $listings = array(); $finder = new Finder(); $files = $finder->files()->in(Config::getContentRoot())->name('fields.yaml')->followLinks(); foreach ($files as $file) { $slug = Path::trimSlashes(Path::makeRelative($file->getPath(), Config::getContentRoot())); $meta = array('slug' => $slug, 'title' => ucwords(ltrim(Path::pretty('/' . $slug), '/'))); $item = self::yamlize_content(BASE_PATH . '/' . $file->getPath() . '/page.' . Config::getContentType()); $listings[] = is_array($item) ? array_merge($meta, $item) : $meta; } // Sort by Title uasort($listings, function ($a, $b) { return strcmp($a['title'], $b['title']); }); return $listings; }
|-------------------------------------------------------------------------- | Done. Let's redirect! |-------------------------------------------------------------------------- | | Pages go back to the tree, entries to their respective Entry Listing | Or, if a custom return was specified, we'll go there. | */ if ($form_data['type'] == 'none') { $app->flash('success', Localization::fetch('page_saved')); } else { $app->flash('success', Localization::fetch('entry_saved')); } $return = Request::post('return'); if (Request::post('continue')) { $path = Path::trimSlashes(str_replace(Config::getContentRoot(), '', Path::tidy($file))); $path = preg_replace('/\\.' . Config::getContentType() . '$/', '', $path); $redirect_url = $admin_app->urlFor('publish') . '?path=' . $path; if (strpos(Request::getReferrer(), 'return=')) { // maintain the 'return' in the URL $return_uri = substr($return, strlen($app->request()->getRootUri())); $redirect_url .= '&return=' . $return_uri; } $app->redirect($redirect_url); } else { $app->redirect($return); } }); // GET: DELETE ENTRY $admin_app->map('/delete/entry', function () use($admin_app) { authenticateForRole('admin');
/* |-------------------------------------------------------------------------- | Done. Let's redirect! |-------------------------------------------------------------------------- | | Pages go back to the tree, entries to their respective Entry Listing | Or, if a custom return was specified, we'll go there. | */ if ($form_data['type'] == 'none') { $app->flash('success', Localization::fetch('page_saved')); } else { $app->flash('success', Localization::fetch('entry_saved')); } if (Request::post('continue')) { $path = rtrim(Path::trimSlashes(str_replace(Config::getContentRoot(), '', Path::tidy($file))), '.' . Config::getContentType()); $app->redirect($admin_app->urlFor('publish') . '?path=' . $path); } else { $app->redirect(Request::post('return')); } }); // GET: DELETE ENTRY $admin_app->map('/delete/entry', function () use($admin_app) { authenticateForRole('admin'); doStatamicVersionCheck($admin_app); $content_root = Config::getContentRoot(); $content_type = Config::getContentType(); $entries = (array) Request::fetch('entries'); $count = count($entries); foreach ($entries as $path) { $file = $content_root . "/" . $path . "." . $content_type;
/** * trim_slashes * Removes any extra "/" at the beginning or end of a given $string * * @deprecated Use Path::trimSlashes() instead * * @param string $string String to trim * @return string */ public static function trim_slashes($string) { Log::warn("Use of Statamic_Helper::trim_slashes() is deprecated. Use Path::trimSlashes() instead.", "core", "Statamic_Helper"); return Path::trimSlashes($string); }