/**
  * Get the path of the current file
  *
  * @return string Full path
  */
 public function getPath()
 {
     // Get the query string and remove the ordering
     $url = Path::pretty(Request::get('path'));
     // Remove the 'page' if it's a page.md
     $url = Pattern::endsWith($url, 'page') ? URL::popLastSegment($url) : $url;
     // Get the content
     $content = Content::get($url);
     // Path is inside the content
     return ltrim($content['_local_path'], '/');
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
        $admin_app->flash('success', Localization::fetch('entry_deleted'));
    }
    $url = $admin_app->request()->getReferrer();
    $admin_app->redirect($url);
})->name('delete_entry')->via('GET', 'POST');
// GET: DELETE PAGE
$admin_app->get('/delete/page', function () use($admin_app) {
    authenticateForRole('admin');
    doStatamicVersionCheck($admin_app);
    $path = Path::assemble(BASE_PATH, Config::getContentRoot(), $admin_app->request()->get('path'));
    $type = $admin_app->request()->get('type');
    if ($type == "folder" && Folder::exists($path)) {
        Folder::delete($path);
        $admin_app->flash('success', Localization::fetch('page_deleted'));
    } else {
        if (!Pattern::endsWith($path, Config::getContentType())) {
            $path .= Config::getContentType();
        }
        if (File::exists($path)) {
            /*
            |--------------------------------------------------------------------------
            | Delete Hook
            |--------------------------------------------------------------------------
            |
            | Runs the delete hook, passing the file path
            |
            */
            Hook::run('control_panel', 'delete', null, $path);
            File::delete($path);
            $admin_app->flash('success', Localization::fetch('page_deleted'));
        } else {
Exemplo n.º 4
0
 public static function yamlize_content($meta_raw, $content_key = 'content')
 {
     if (File::exists($meta_raw)) {
         $meta_raw = File::get($meta_raw);
     }
     if (Pattern::endsWith($meta_raw, "---")) {
         $meta_raw .= "\n";
         # prevent parse failure
     }
     // Parse YAML Front Matter
     if (strpos($meta_raw, "---") === false) {
         $meta = YAML::parse($meta_raw);
         $meta['content'] = "";
     } else {
         list($yaml, $content) = preg_split("/---/", $meta_raw, 2, PREG_SPLIT_NO_EMPTY);
         $meta = YAML::parse($yaml);
         $meta[$content_key . '_raw'] = trim($content);
         $meta[$content_key] = Content::transform($content);
         return $meta;
     }
 }
Exemplo n.º 5
0
    /**
     * Returns the full path of a given script
     *
     * @param string  $file  Script file to find
     * @return string
     */
    public function get($file)
    {
        $bundle_location = "/core/bundles/" . $this->context->getAddonName() . "/";
        $file_location = Config::getAddOnPath($this->context->getAddonName()) . '/';

        if (File::exists(APP_PATH . $bundle_location . $file)) {
            return URL::assemble(Config::getSiteRoot(), ENVIRONMENT_PATH_PREFIX, $file_location . $file);
        } elseif (File::exists(APP_PATH . $bundle_location . 'js/' . $file)) {
            return URL::assemble(Config::getSiteRoot(), ENVIRONMENT_PATH_PREFIX, $file_location, 'js', $file);
        } elseif (File::exists(BASE_PATH . $file_location . $file)) {
            return URL::assemble(Config::getSiteRoot(), $file_location . $file);
        } elseif (File::exists(BASE_PATH . $file_location . 'js/' . $file)) {
            return URL::assemble(Config::getSiteRoot(), $file_location, 'js', $file);
        } elseif ( ! Pattern::endsWith($file, ".js", false)) {
            return $this->get($file . ".js");
        }

        Log::error("JavaScript file `" . $file . "` doesn't exist.", $this->context->getAddonName(), $this->context->getAddonType());
        return "";
    }
Exemplo n.º 6
0
Arquivo: addon.php Projeto: nob/joi
 /**
  * Returns the full path of a given script
  *
  * @param string  $file  Script file to find
  * @return string
  */
 public function get($file)
 {
     $file_location = Config::getAddOnPath($this->context->addon_name) . '/';
     if (File::exists(BASE_PATH . $file_location . $file)) {
         return URL::assemble(Config::getSiteRoot(), $file_location . $file);
     } elseif (File::exists(BASE_PATH . $file_location . 'js/' . $file)) {
         return URL::assemble(Config::getSiteRoot(), $file_location, 'js', $file);
     } elseif (!Pattern::endsWith($file, ".js", false)) {
         return $this->get($file . ".js");
     }
     $this->context->log->error("JavaScript file `" . $file . "` doesn't exist.");
     return "";
 }
Exemplo n.º 7
0
Arquivo: user.php Projeto: nob/joi
 public static function load($username)
 {
     $meta_raw = "";
     if (File::exists("_config/users/{$username}.yaml")) {
         $meta_raw = file_get_contents("_config/users/{$username}.yaml");
     } else {
         return NULL;
     }
     if (Pattern::endsWith($meta_raw, "---")) {
         $meta_raw .= "\n";
         # prevent parse failure
     }
     # Parse YAML Front Matter
     if (stripos($meta_raw, "---") === FALSE) {
         $meta = YAML::Parse($meta_raw);
         $meta['content'] = "";
     } else {
         list($yaml, $content) = preg_split("/---/", $meta_raw, 2, PREG_SPLIT_NO_EMPTY);
         $meta = YAML::Parse($yaml);
         $meta['biography_raw'] = trim($content);
         $meta['biography'] = Content::transform($content);
         $u = new Statamic_User($meta);
         $u->set_name($username);
         return $u;
     }
 }
Exemplo n.º 8
0
Arquivo: helper.php Projeto: nob/joi
 /**
  * ends_with
  * Determines if a given $haystack ends with $needle
  *
  * @deprecated  Use Pattern::endsWith() instead
  *
  * @param string  $haystack  String to inspect
  * @param string  $needle  Character to look for
  * @param boolean  $case  Perform a case-sensitive search?
  * @return boolean
  */
 public static function ends_with($haystack, $needle, $case = TRUE)
 {
     Log::warn("Use of Statamic_Helper::ends_with() is deprecated. Use Pattern::endsWith() instead.", "core", "Statamic_Helper");
     return Pattern::endsWith($haystack, $needle, $case);
 }
 /**
  * Takes a URL and responds the corresponding static html filename
  * 
  * @param  string $url    URL
  * @param  array $detail  Optional details from cache. Saves another lookup if we already have it.
  * @return string
  */
 private function filename($url, $detail = null)
 {
     if (!$detail) {
         $detail = array_get($this->getCache(), $url);
     }
     $filename = $url;
     $filename .= Pattern::endsWith($detail['file'], '/page.md') ? '/index' : '';
     $filename .= '.html';
     return $filename;
 }