Ejemplo n.º 1
0
 public static function content($data = "")
 {
     if ($data === false) {
         $data = "";
     }
     // Restrict user(s) from inputting the `SEPARATOR` constant
     // to prevent mistake(s) in parsing the file content
     $data = Converter::ES($data);
     self::$bucket_alt = trim(self::$bucket_alt) !== "" && is_null(self::$open) ? trim(self::$bucket_alt) . (trim($data) !== "" ? "\n\n" . SEPARATOR . "\n\n" . $data : "") : $data;
     return new static();
 }
Ejemplo n.º 2
0
     File::open($post->path)->renameTo(File::B($_));
     $custom_ = CUSTOM . DS . Date::slug($post->date->W3C);
     if (file_exists($custom_ . $extension_o)) {
         Weapon::fire('on_custom_update', array($G, $P));
         if (trim(File::open($custom_ . $extension_o)->read()) === "" || trim(File::open($custom_ . $extension_o)->read()) === SEPARATOR || empty($css) && empty($js) || $css === $config->defaults->{$segment . '_css'} && $js === $config->defaults->{$segment . '_js'}) {
             // Always delete empty custom CSS and JavaScript file(s) ...
             File::open($custom_ . $extension_o)->delete();
             Weapon::fire('on_custom_destruct', array($G, $P));
         } else {
             File::write(Converter::ES($css) . "\n\n" . SEPARATOR . "\n\n" . Converter::ES($js))->saveTo($custom_ . $extension_o);
             File::open($custom_ . $extension_o)->renameTo(Date::slug($date) . $extension);
             Weapon::fire('on_custom_repair', array($G, $P));
         }
     } else {
         if (!empty($css) && $css !== $config->defaults->{$segment . '_css'} || !empty($js) && $js !== $config->defaults->{$segment . '_js'}) {
             File::write(Converter::ES($css) . "\n\n" . SEPARATOR . "\n\n" . Converter::ES($js))->saveTo(CUSTOM . DS . Date::slug($date) . $extension_o);
             Weapon::fire(array('on_custom_update', 'on_custom_construct'), array($G, $P));
         }
     }
     if ($post->slug !== $slug && ($php_file = File::exist(File::D($post->path) . DS . $post->slug . '.php'))) {
         File::open($php_file)->renameTo($slug . '.php');
     }
     // Rename all response file(s) related to post if post date has been changed
     if ((string) $date !== (string) $post->date->W3C && ($responses = call_user_func('Get::' . $response . 's', 'DESC', 'post:' . $id, 'txt,hold'))) {
         foreach ($responses as $v) {
             $parts = explode('_', File::B($v));
             $parts[0] = Date::slug($date);
             File::open($v)->renameTo(implode('_', $parts));
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * ==========================================================================
  *  EXTRACT POST FILE INTO LIST OF POST DATA FROM ITS PATH/SLUG/ID
  * ==========================================================================
  *
  * -- CODE: -----------------------------------------------------------------
  *
  *    var_dump(Get::post('about'));
  *
  * --------------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter  | Type   | Description
  *  ---------- | ------ | ---------------------------------------------------
  *  $reference | mixed  | Slug, ID, path or array of `Get::postExtract()`
  *  $excludes  | array  | Exclude some field(s) from result(s)
  *  $folder    | string | Folder of the post(s)
  *  $connector | string | Path connector for post URL
  *  $FP        | string | Filter prefix for `Text::toPage()`
  *  ---------- | ------ | ---------------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function post($reference, $excludes = array(), $folder = POST, $connector = '/', $FP = 'post:')
 {
     $config = Config::get();
     $speak = Config::speak();
     $excludes = array_flip($excludes);
     $results = false;
     if (!is_array($reference)) {
         // By slug => `post-slug` or by ID => `1403355917`
         if (strpos($reference, $folder) !== 0) {
             $reference = self::postPath($reference, $folder);
         }
         // By path => `lot\posts\$folder\2014-06-21-20-05-17_1,2,3_page-slug.txt`
         $results = self::postExtract($reference, $FP);
     } else {
         // From `Get::postExtract()`
         $results = $reference;
     }
     if (!$results || !file_exists($results['path'])) {
         return false;
     }
     // RULES: Do not do any tags looping, content parsing
     // and external file requesting if it has been marked as
     // the excluded field(s). For better performance.
     $results = $results + Text::toPage(file_get_contents($results['path']), isset($excludes['content']) ? false : 'content', $FP, array('link' => "", 'author' => $config->author->name, 'description' => "", 'content_type' => $config->html_parser->active, 'fields' => array(), 'content' => "", 'css' => "", 'js' => ""), $results);
     $content = $results['content_raw'];
     $time = str_replace(array(' ', ':'), '-', $results['time']);
     $e = File::E($results['path']);
     // Custom post content with PHP file, named as the post slug
     if ($php = File::exist(File::D($results['path']) . DS . $results['slug'] . '.php')) {
         ob_start();
         include $php;
         $results['content'] = ob_get_clean();
     }
     $results['date'] = Filter::colon($FP . 'date', Date::extract($results['time']), $results);
     $results['url'] = Filter::colon($FP . 'url', $config->url . $connector . $results['slug'], $results);
     $results['excerpt'] = $more = "";
     if ($content !== "") {
         $exc = isset($excludes['content']) && strpos($content, '<!--') !== false ? Text::toPage(Converter::ES($content), 'content', $FP, array(), $results) : $results;
         $exc = $exc['content'];
         $exc = is_array($exc) ? implode("", $exc) : $exc;
         // Generate fake description data
         if ($results['description'] === "") {
             $results['description'] = Converter::curt($exc, $config->excerpt->length, $config->excerpt->suffix);
         }
         // Manual post excerpt with `<!-- cut+ "Read More" -->`
         if (strpos($exc, '<!-- cut+ ') !== false) {
             preg_match('#<!-- cut\\+( +([\'"]?)(.*?)\\2)? -->#', $exc, $matches);
             $more = !empty($matches[3]) ? $matches[3] : $speak->read_more;
             $more = '<p><a class="fi-link" href="' . $results['url'] . '#' . sprintf($config->excerpt->id, $results['id']) . '">' . $more . '</a></p>';
             $exc = preg_replace('#<!-- cut\\+( +(.*?))? -->#', '<!-- cut -->', $exc);
         }
         // ... or `<!-- cut -->`
         if (strpos($exc, '<!-- cut -->') !== false) {
             $parts = explode('<!-- cut -->', $exc, 2);
             $results['excerpt'] = Filter::colon($FP . 'excerpt', trim($parts[0]) . $more, $results);
             $results['content'] = trim($parts[0]) . NL . NL . '<span class="fi" id="' . sprintf($config->excerpt->id, $results['id']) . '" aria-hidden="true"></span>' . NL . NL . trim($parts[1]);
         }
     }
     // Post Tags
     if (!isset($excludes['tags'])) {
         $tags = array();
         foreach ($results['kind'] as $id) {
             $tags[] = call_user_func('self::' . rtrim($FP, ':') . 'Tag', 'id:' . $id);
         }
         $results['tags'] = Filter::colon($FP . 'tags', Mecha::eat($tags)->order('ASC', 'name')->vomit(), $results);
     }
     // Post Images
     $results['images'] = Filter::colon($FP . 'images', self::imagesURL($results['content']), $results);
     $results['image'] = Filter::colon($FP . 'image', isset($results['images'][0]) ? $results['images'][0] : Image::placeholder(), $results);
     // Post CSS and JS
     if ($file = File::exist(CUSTOM . DS . Date::slug($results['time']) . '.' . File::E($results['path']))) {
         $custom = explode(SEPARATOR, File::open($file)->read());
         $css = isset($custom[0]) ? Converter::DS(trim($custom[0])) : "";
         $js = isset($custom[1]) ? Converter::DS(trim($custom[1])) : "";
         // css_raw
         // post:css_raw
         // custom:css_raw
         // shortcode
         // custom:shortcode
         // css:shortcode
         // css
         // post:css
         // custom:css
         $css = Filter::colon($FP . 'css_raw', $css, $results);
         $results['css_raw'] = Filter::apply('custom:css_raw', $css, $results);
         $css = Filter::colon('css:shortcode', $css, $results);
         $css = Filter::apply('custom:shortcode', $css, $results);
         $css = Filter::colon($FP . 'css', $css, $results);
         $results['css'] = Filter::apply('custom:css', $css, $results);
         // js_raw
         // post:js_raw
         // custom:js_raw
         // shortcode
         // custom:shortcode
         // js:shortcode
         // js
         // post:js
         // custom:js
         $js = Filter::colon($FP . 'js_raw', $js, $results);
         $results['js_raw'] = Filter::apply('custom:js_raw', $js, $results);
         $js = Filter::colon('js:shortcode', $js, $results);
         $js = Filter::apply('custom:shortcode', $js, $results);
         $js = Filter::colon($FP . 'js', $js, $results);
         $results['js'] = Filter::apply('custom:js', $js, $results);
     }
     // Post Field(s)
     if (!isset($excludes['fields'])) {
         self::__fields($results, $FP);
     }
     // Exclude some field(s) from result(s)
     foreach ($results as $key => $value) {
         if (isset($excludes[$key])) {
             unset($results[$key]);
         }
     }
     return Mecha::O($results);
 }