Esempio n. 1
0
 public static function __callStatic($id, $arguments = array())
 {
     $c = get_called_class();
     $d = Tree::$config;
     $dd = self::$config['classes'];
     if (!isset(self::$menus[$c][$id])) {
         return false;
     }
     $AD = array('ul', "", $id . ':');
     $arguments = Mecha::extend($AD, $arguments);
     $type = $arguments[0];
     $arguments[0] = Filter::apply('menu:input', self::$menus[$c][$id], $id);
     if (!is_array($arguments[0])) {
         return "";
     }
     Tree::$config['trunk'] = $type;
     Tree::$config['branch'] = $type;
     Tree::$config['twig'] = 'li';
     Tree::$config['classes']['trunk'] = $dd['parent'];
     Tree::$config['classes']['branch'] = $dd['child'];
     Tree::$config['classes']['twig'] = false;
     Tree::$config['classes']['current'] = $dd['current'];
     Tree::$config['classes']['chink'] = $dd['separator'];
     $output = call_user_func_array('Tree::grow', $arguments);
     Tree::$config = $d;
     // reset to the previous state
     return Filter::apply('menu:output', $output, $id);
 }
/** save field in database, if field is valid */
function cdbr_register_verify_field()
{
    $reponse = array();
    $filter = new Filter();
    $validator = new Validator();
    foreach ($_POST as $stepfield => $value) {
        $field = $stepfield;
        $filter->apply('register', $field, $value);
        $result = $validator->validate_field('register', $field, $value, $type_user);
        $response[$field] = $result;
    }
    print json_encode($response);
    die;
    // or wordpress will print 0
}
Esempio n. 3
0
 /**
  */
 public function save($sid, array $params)
 {
     //$params should be array of "key"=>"value". So query will be "  update set `key`='value'  "
     $sql_k = $sql_v = array();
     foreach ($params as $k => $v) {
         if (is_string($k)) {
             $sql_k[] = "`{$k}`";
             $sql_v[] = "'" . Filter::apply($v, Filter::STRING_QUOTE_ENCODE) . "'";
         }
     }
     if (empty($sql_k)) {
         throw new CasseaException("Cannot save session. Data array is empty");
     }
     DB::query("replace into " . self::TABLE . " ( " . implode(", ", $sql_k) . " ) values (" . implode(", ", $sql_v) . ")");
 }
Esempio n. 4
0
 /**
  * Get Page Block
  *
  *  <code>
  *      $block = Blocks::get('my-block');
  *  </code>
  *
  * @access public
  * @param  string $name Block name
  * @return string Formatted Block content
  */
 public static function get($name)
 {
     if (File::exists($block_path = STORAGE_PATH . '/blocks/' . $name . '.md')) {
         // Create Unique Cache ID for Block
         $block_cache_id = md5('block' . ROOT_DIR . $block_path . filemtime($block_path));
         if (Cache::driver()->contains($block_cache_id)) {
             return Cache::driver()->fetch($block_cache_id);
         } else {
             Cache::driver()->save($block_cache_id, $block = Filter::apply('content', file_get_contents($block_path)));
             return $block;
         }
     } else {
         return 'Block ' . $name . ' is not found!';
     }
 }
Esempio n. 5
0
 public static function send($from, $to, $subject, $message, $FP = 'common:')
 {
     if (trim($to) === "" || !Guardian::check($to, '->email')) {
         return false;
     }
     $header = "MIME-Version: 1.0\n";
     $header .= "Content-Type: text/html; charset=ISO-8859-1\n";
     $header .= "From: " . $from . "\n";
     $header .= "Reply-To: " . $from . "\n";
     $header .= "Return-Path: " . $from . "\n";
     $header .= "X-Mailer: PHP/" . phpversion();
     $header = Filter::apply($FP . 'notification.email.header', $header);
     $message = Filter::apply($FP . 'notification.email.message', $message);
     return mail($to, $subject, $message, $header);
 }
 /**
  * Returns block content for shortcode {block get="blockname"}
  *
  * @param array $attributes block filename
  */
 public static function _content($attributes)
 {
     if (isset($attributes['get'])) {
         $name = (string) $attributes['get'];
     } else {
         $name = '';
     }
     $block_path = STORAGE . DS . 'blocks' . DS . $name . '.block.html';
     if (File::exists($block_path)) {
         ob_start();
         include $block_path;
         $block_contents = ob_get_contents();
         ob_end_clean();
         return Filter::apply('content', Text::toHtml($block_contents));
     } else {
         if (Session::exists('admin') && Session::get('admin') == true) {
             return __('<b>Block <u>:name</u> is not found!</b>', 'blocks', array(':name' => $name));
         }
     }
 }
Esempio n. 7
0
 public static function create($array, $type = 'ul', $depth = "", $FP = "", $i = 0)
 {
     $c_url = Config::get('url');
     $c_url_current = Config::get('url_current');
     $c_class = self::$config['classes'];
     $html = $depth . str_repeat(TAB, $i) . '<' . $type . ($i > 0 ? $c_class['children'] !== false ? ' class="' . sprintf($c_class['children'], $i / 2) . '"' : "" : ($c_class['parent'] !== false ? ' class="' . $c_class['parent'] . '"' : "")) . '>' . NL;
     foreach ($array as $key => $value) {
         if (!is_array($value)) {
             // List item separator: `array('|')`
             if ($key === '|' || is_int($key) && $value === '|') {
                 $html .= Filter::apply($FP . 'list.item.separator', Filter::apply($FP . 'list.item', $depth . str_repeat(TAB, $i + 1) . '<li class="' . $c_class['separator'] . '"></li>' . NL, $i + 1), $i + 1);
                 // List item without link: `array('foo')`
             } else {
                 if (is_int($key)) {
                     $html .= Filter::apply($FP . 'list.item', $depth . str_repeat(TAB, $i + 1) . '<li><span class="a">' . $value . '</span></li>' . NL, $i + 1);
                     // List item without link: `array('foo' => null)`
                 } else {
                     if (is_null($value)) {
                         $html .= Filter::apply($FP . 'list.item', $depth . str_repeat(TAB, $i + 1) . '<li><span class="a">' . $key . '</span></li>' . NL, $i + 1);
                         // List item with link: `array('foo' => '/')`
                     } else {
                         $value = Converter::url($value);
                         $html .= Filter::apply($FP . 'list.item', $depth . str_repeat(TAB, $i + 1) . '<li' . ($value === $c_url_current || $value !== $c_url && strpos($c_url_current . '/', $value . '/') === 0 ? ' class="' . $c_class['selected'] . '"' : "") . '><a href="' . $value . '">' . $key . '</a></li>' . NL, $i + 1);
                     }
                 }
             }
         } else {
             if (preg_match('#(.*?)\\s*\\((.*?)\\)\\s*$#', $key, $matches)) {
                 $_key = $matches[1];
                 $_value = Converter::url($matches[2]);
             } else {
                 $_key = $key;
                 $_value = '#';
             }
             $html .= Filter::apply($FP . 'list.item', $depth . str_repeat(TAB, $i + 1) . '<li' . ($_value === $c_url_current || $_value !== $c_url && strpos($c_url_current . '/', $_value . '/') === 0 ? ' class="' . $c_class['selected'] . '"' : "") . '>' . NL . str_repeat(TAB, $i + 2) . '<a href="' . $_value . '">' . $_key . '</a>' . NL . self::create($value, $type, $depth, $FP, $i + 2) . $depth . str_repeat(TAB, $i + 1) . '</li>' . NL, $i + 1);
         }
     }
     return Filter::apply($FP . 'list', rtrim($html, NL) . (!empty($array) ? NL . $depth . str_repeat(TAB, $i) : "") . '</' . $type . '>' . NL, $i);
 }
Esempio n. 8
0
 /**
  * ==========================================================
  *  RENDER A SHIELD CHUNK
  * ==========================================================
  *
  * -- CODE: -------------------------------------------------
  *
  *    Shield::chunk('header');
  *
  * ----------------------------------------------------------
  *
  *    Shield::chunk('header', array('title' => 'Yo!'));
  *
  * ----------------------------------------------------------
  *
  */
 public static function chunk($name, $fallback = false, $buffer = true)
 {
     $path__ = File::path($name);
     $G = array('data' => array('name' => $name));
     if (is_array($fallback)) {
         self::$lot = array_merge(self::$lot, $fallback);
         $fallback = false;
     }
     $path__ = Filter::apply('chunk:path', self::path($path__, $fallback));
     $G['data']['lot'] = self::$lot;
     $G['data']['path'] = $path__;
     $out = "";
     if ($path__) {
         // Begin chunk
         Weapon::fire('chunk_lot_before', array($G, $G));
         extract(Filter::apply('chunk:lot', self::$lot));
         Weapon::fire('chunk_lot_after', array($G, $G));
         Weapon::fire('chunk_before', array($G, $G));
         if ($buffer) {
             ob_start(function ($content) use($path__, &$out) {
                 $content = Filter::apply('chunk:input', $content, $path__);
                 $out = Filter::apply('chunk:output', $content, $path__);
                 return $out;
             });
             require $path__;
             ob_end_flush();
         } else {
             require $path__;
         }
         $G['data']['content'] = $out;
         // End chunk
         Weapon::fire('chunk_after', array($G, $G));
     }
 }
Esempio n. 9
0
 /**
  * Parses given XML node and extracting info about from where to
  * take parameters for user's models methods.
  * Additionally, it filters and re-arrange this data to give more
  * flexibility to the models design.
  *
  * Base syntax is 
  * <pre><code>
  * <param from="p2" count="2" offset="1">
  *		<filter>int</filter>
  * </param>
  * </code></pre>
  *
  * It takes two parameters ("count" attribute), starting from 
  * the second ("offset" attribute). Indexing is zero-based.  
  * Then, received values  might be passed to, for example, dataset as first and second parameters.
  * Besides, {@link Filter} int applies to each parameter. If parameters were 
  * strings, after applying they becomes NULL values.
  *
  * Offset and count attributes are valid only while retrieving "p2" parameters.
  *
  * Another example:
  * <pre><code>
  * <param from="p2" count="2" offset="1" as="array">
  *		<filter>array_int</filter>
  * </param>
  * </code></pre>
  *
  * Here "as" attribute was presented. If "as" equals to "array", than collected data will be
  * passed to the model's method as single parameter as int-indexed array. "array_int" 
  * filter will be applied to the obtained array. Applying "int" filter int this case will cause
  * to receiving a NULL value.
  *
  * To receive "p1" parameter, you should use this syntax:
  * <pre><code>
  * <param from="p1">
  *		<filter>int</filter>
  * </param>
  * </code></pre>
  *
  * Specifying "count" and "offset" attributes will give no effect. There is single "p1" parameter.
  * It also may be filtered.
  *
  * System allows you to retrieve certain $_GET parameters. To do so use such syntax:
  * <pre><code>
  * <param from="p3" var="q">
  *		<filter>int</filter>
  * </param>
  * </code></pre>
  *
  * For example, if current url is <code>http://example.com/index.html?q=123</code>, value "123" will be
  * passed to the model's method.
  *
  * If you want to pass some constant value to the method (ie some flag), use syntax:
  * <pre><code>
  * <param constant="1">
  * </param>
  * </code></pre>
  *
  * Internal pagination system could pass predicted 'from' and 'limit' values to the model.
  * Use:
  * <pre><code>
  * <param from="limit">
  * </param>
  * </code></pre>
  * In this case, <code>array("from"=>$from, "limit"=>$limit)</code> will be passed.
  *
  * @param SimpleXMLElement XML document node with parameters.
  * @return null
  */
 function __construct(SimpleXMLElement $elem = null)
 {
     if (!isset($elem, $elem->param)) {
         return;
     }
     $controller = Controller::getInstance();
     $p2_cursor = 0;
     foreach ($elem->param as $param) {
         if ($param['from'] == "p1") {
             $this->params_from[] = "p1";
             $p = $controller->p1;
             if (isset($param['as']) && $param['as'] == "array") {
                 $p = array($p);
             }
             //slightly idiotic usage
             if (isset($param->filter)) {
                 $p = Filter::apply($p, (string) $param->filter);
             }
             $this->params[] = $p;
         } elseif ($param['from'] == "p2") {
             $total_count = count($controller->p2);
             if (isset($param['offset'])) {
                 if ((int) $param['offset'] > 0) {
                     $p2_cursor = (int) $param['offset'];
                 } elseif ((int) $param['offset'] < 0) {
                     $p2_cursor = max(0, $total_count - abs((int) $param['offset']));
                 }
             }
             $c = 1;
             if (isset($param['count'])) {
                 $c = abs(0 + $param['count']);
             }
             $p = array();
             for ($i = 0; $i < $c; $p2_cursor++, $i++) {
                 $p[$i] = isset($controller->p2[$p2_cursor]) ? $controller->p2[$p2_cursor] : null;
             }
             if (isset($param['as']) && $param['as'] == "array") {
                 $this->params[] = isset($param->filter) ? Filter::apply($p, (string) $param->filter) : $p;
                 $this->params_from[] = "p2";
             } else {
                 foreach ($p as $_p) {
                     $this->params[] = isset($param->filter) ? Filter::apply($_p, (string) $param->filter) : $_p;
                     $this->params_from[] = "p2";
                 }
             }
         } elseif ($param['from'] == "p3" && isset($param['var'])) {
             $this->params_from[] = "p3";
             $p = $controller->get->{$param}['var'];
             if (isset($param['as']) && $param['as'] == "array") {
                 $p = array($p);
             }
             if (isset($param->filter)) {
                 $p = Filter::apply($p, (string) $param->filter);
             }
             $this->params[] = $p;
         } elseif (isset($param['constant'])) {
             $this->params_from[] = "constant";
             $p = (string) $param['constant'];
             if (isset($param->filter)) {
                 $p = Filter::apply($p, (string) $param->filter);
             }
             $this->params[] = $p;
         } elseif ($param['from'] == "limit") {
             $this->params_from[] = "limit";
             $this->params[] = array();
         }
     }
 }
Esempio n. 10
0
 /**
  * Magic method for setting value to given profile field.
  *
  * It also updates DB table with new value.
  *
  * @param string name of the profile field
  * @param scalar value 
  * @throws ProfileException in case of error
  */
 function __set($field_name, $value)
 {
     if (!is_scalar($value) || !array_key_exists($field_name, $this->fields)) {
         throw new ProfileException("Incorrect value or profile parameter '{$field_name}' doesn't exist");
     }
     $this->fields[$field_name] = $value;
     $field_name = Filter::apply($field_name, Filter::STRING_QUOTE_ENCODE);
     $value = Filter::apply($value, Filter::STRING_QUOTE_ENCODE);
     DB::query("update " . self::TABLE . " set " . $field_name . " = '" . $value . "' where user_id='" . $this->user_id . "' limit 1");
 }
Esempio n. 11
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);
 }
Esempio n. 12
0
 /**
  * ============================================================================
  *  PAGINATION EXTRACTOR FOR LIST OF FILE(S)
  * ============================================================================
  *
  * -- CODE: -------------------------------------------------------------------
  *
  *    $pager = Navigator::extract(glob('some/files/*.txt'), 1, 5, 'foo/bar');
  *    echo $pager->prev->anchor;
  *
  * ----------------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter  | Type    | Description
  *  ---------- | ------- | ----------------------------------------------------
  *  $pages     | array   | Array of file(s) to be paginated
  *  $current   | integer | The current page offset
  *  $current   | string  | The current page path
  *  $per_page  | integer | Number of file(s) to show per page request
  *  $connector | string  | Extra path to be inserted into URL
  *  ---------- | ------- | ----------------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function extract($pages = array(), $current = 1, $per_page = 10, $connector = '/')
 {
     // Set default next, previous and step data
     $bucket = array('prev' => false, 'next' => false, 'step' => false);
     $pages = (array) $pages;
     $config = Config::get();
     $speak = Config::speak();
     $base = $config->url;
     $q = str_replace('&', '&amp;', $config->url_query);
     $qq = strpos($connector, '?') !== false ? str_replace('?', '&amp;', $q) : $q;
     $total = count($pages);
     $c = self::$config;
     if (strpos($connector, '%s') === false) {
         if (trim($connector, '/') !== "") {
             $connector = '/' . trim($connector, '/') . '/%s';
         } else {
             $connector = '/%s';
         }
     }
     if (is_int($current)) {
         $current = (int) $current;
         $prev = $current > 1 ? $current - 1 : false;
         $next = $current < ceil($total / $per_page) ? $current + 1 : false;
         // Generate next/previous URL for index page
         $bucket['prev']['url'] = Filter::apply(array('pager:prev.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, $prev) . $qq : $base . $q, $prev, $connector);
         $bucket['next']['url'] = Filter::apply(array('pager:next.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $next) . $qq : $base . $q, $next, $connector);
         // Generate next/previous anchor for index page
         $bucket['prev']['anchor'] = Filter::apply(array('pager:prev.anchor', 'pager:anchor', 'anchor'), $prev ? '<a href="' . $bucket['prev']['url'] . '" rel="prev">' . $speak->newer . '</a>' : "", $prev, $connector);
         $bucket['next']['anchor'] = Filter::apply(array('pager:next.anchor', 'pager:anchor', 'anchor'), $next ? '<a href="' . $bucket['next']['url'] . '" rel="next">' . $speak->older . '</a>' : "", $next, $connector);
         // Generate pagination anchor(s) for index page
         $html = '<span' . ($c['classes']['pagination'] !== false ? ' class="' . $c['classes']['pagination'] . '"' : "") . '>';
         $chunk = (int) ceil($total / $per_page);
         $step = $chunk > self::$config['step'] ? self::$config['step'] : $chunk;
         $left = $current - $step;
         if ($left < 1) {
             $left = 1;
         }
         if ($chunk > 1) {
             $bucket['step']['url']['first'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, 1) . $qq : false, 1, $connector);
             $bucket['step']['url']['prev'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, $prev) . $qq : false, $prev, $connector);
             $bucket['step']['anchor']['first'] = Filter::apply(array('pager:step.anchor', 'pager:anchor', 'anchor'), $prev ? '<a href="' . $bucket['step']['url']['first'] . '">' . $speak->first . '</a>' : '<span>' . $speak->first . '</span>', 1, $connector);
             $bucket['step']['anchor']['prev'] = Filter::apply(array('pager:step.anchor', 'pager:anchor', 'anchor'), $prev ? '<a href="' . $bucket['step']['url']['prev'] . '" rel="prev">' . $speak->prev . '</a>' : '<span>' . $speak->prev . '</span>', $prev, $connector);
             $html .= $bucket['step']['anchor']['first'] . $bucket['step']['anchor']['prev'];
             $html .= '<span>';
             for ($i = $current - $step + 1; $i < $current + $step; ++$i) {
                 if ($chunk > 1) {
                     if ($i - 1 < $chunk && ($i > 0 && $i + 1 > $current - $left - round($chunk / 2))) {
                         $bucket['step']['url'][$i] = Filter::apply(array('pager:step.url', 'pager:url'), $i !== $current ? $base . sprintf($connector, $i) . $qq : false, $i, $connector);
                         $bucket['step']['anchor'][$i] = Filter::apply(array('pager:step.anchor', 'pager:anchor', 'anchor'), $i !== $current ? '<a href="' . $bucket['step']['url'][$i] . '">' . $i . '</a>' : '<strong' . ($c['classes']['current'] !== false ? ' class="' . $c['classes']['current'] . '"' : "") . '>' . $i . '</strong>', $i, $connector);
                         $html .= $bucket['step']['anchor'][$i];
                     }
                 }
             }
             $html .= '</span>';
             $bucket['step']['url']['next'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $next) . $qq : false, $next, $connector);
             $bucket['step']['url']['last'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $chunk) . $qq : false, $chunk, $connector);
             $bucket['step']['anchor']['next'] = Filter::apply(array('pager:step.anchor', 'pager:anchor'), $next ? '<a href="' . $bucket['step']['url']['next'] . '" rel="next">' . $speak->next . '</a>' : '<span>' . $speak->next . '</span>', $next, $connector);
             $bucket['step']['anchor']['last'] = Filter::apply(array('pager:step.anchor', 'pager:anchor'), $next ? '<a href="' . $bucket['step']['url']['last'] . '">' . $speak->last . '</a>' : '<span>' . $speak->last . '</span>', $chunk, $connector);
             $html .= $bucket['step']['anchor']['next'] . $bucket['step']['anchor']['last'];
         }
         $bucket['step']['html'] = Filter::apply('pager:step.html', $html . '</span>');
     }
     if (is_string($current)) {
         for ($i = 0; $i < $total; ++$i) {
             if ($pages[$i] === $current) {
                 $prev = isset($pages[$i - 1]) ? $pages[$i - 1] : false;
                 $next = isset($pages[$i + 1]) ? $pages[$i + 1] : false;
                 // Generate next/previous URL for single page
                 $bucket['prev']['url'] = Filter::apply(array('pager:prev.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, $prev) . $qq : $base . $q, $prev, $connector);
                 $bucket['next']['url'] = Filter::apply(array('pager:next.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $next) . $qq : $base . $q, $next, $connector);
                 // Generate next/previous anchor for single page
                 $bucket['prev']['anchor'] = Filter::apply(array('pager:prev.anchor', 'pager:anchor', 'anchor'), $bucket['prev']['url'] !== $base ? '<a href="' . $bucket['prev']['url'] . '" rel="prev">' . $speak->newer . '</a>' : "", $prev, $connector);
                 $bucket['next']['anchor'] = Filter::apply(array('pager:next.anchor', 'pager:anchor', 'anchor'), $bucket['next']['url'] !== $base ? '<a href="' . $bucket['next']['url'] . '" rel="next">' . $speak->older . '</a>' : "", $next, $connector);
                 break;
             }
         }
     }
     return Mecha::O($bucket);
 }
Esempio n. 13
0
 public static function image($path, $addon = "", $merge = false)
 {
     if ($merge) {
         return self::merge($path, $merge, $addon, 'image');
     }
     $path = is_string($path) && strpos($path, ';') !== false ? explode(';', $path) : (array) $path;
     $html = "";
     for ($i = 0, $count = count($path); $i < $count; ++$i) {
         if (self::url($path[$i]) !== false) {
             self::$loaded[$path[$i]] = 1;
             $html .= !self::ignored($path[$i]) ? Filter::apply('asset:image', '<img src="' . self::url($path[$i]) . '"' . (is_array($addon) ? $addon[$i] : $addon) . ES . NL, $path[$i]) : "";
         } else {
             // File does not exist
             $html .= '<!-- ' . $path[$i] . ' -->' . NL;
         }
     }
     return O_BEGIN . rtrim($html, NL) . O_END;
 }
 /**
  * Get pages contents
  *
  * @return string
  */
 public static function content($slug = '')
 {
     if (!empty($slug)) {
         $page = Table::factory('pages')->select('[slug="' . $slug . '"]', null);
         if (!empty($page)) {
             $content = Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . $page['id'] . '.page.txt'));
             $content = Filter::apply('content', $content);
             return $content;
         } else {
             return '';
         }
     } else {
         return Text::toHtml(File::getContent(STORAGE . DS . 'pages' . DS . Pages::$page['id'] . '.page.txt'));
     }
 }
Esempio n. 15
0
 /**
  * ==========================================================================
  *  EXTRACT PAGE FILE INTO LIST OF PAGE DATA FROM ITS PATH/SLUG/ID
  * ==========================================================================
  *
  * -- CODE: -----------------------------------------------------------------
  *
  *    var_dump(Get::page('about'));
  *
  * --------------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter  | Type   | Description
  *  ---------- | ------ | ---------------------------------------------------
  *  $reference | mixed  | Slug, ID, path or array of `Get::pageExtract()`
  *  $excludes  | array  | Exclude some field(s) from result(s)
  *  $folder    | string | Folder of the page(s)
  *  $connector | string | Path connector for page URL
  *  $FP        | string | Filter prefix for `Text::toPage()`
  *  ---------- | ------ | ---------------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function page($reference, $excludes = array(), $folder = PAGE, $connector = '/', $FP = 'page:')
 {
     $config = Config::get();
     $speak = Config::speak();
     $excludes = array_flip($excludes);
     $results = false;
     // From `Get::pageExtract()`
     if (is_array($reference)) {
         $results = $reference;
     } else {
         // By path => `cabinet\pages\0000-00-00-00-00-00_1,2,3_page-slug.txt`
         if (strpos($reference, $folder) === 0) {
             $results = self::pageExtract($reference, $FP);
         } else {
             // By slug => `page-slug` or by ID => 12345
             $results = self::pageExtract(self::pagePath($reference, $folder), $FP);
         }
     }
     if (!$results || !file_exists($results['path'])) {
         return false;
     }
     /**
      * RULES: Do not do any tags looping, content Markdown-ing
      * and external file requesting if it has been marked as
      * the excluded field(s). For better performance.
      */
     $results = $results + Text::toPage(File::open($results['path'])->read(), isset($excludes['content']) ? false : 'content', $FP);
     $content = isset($results['content_raw']) ? $results['content_raw'] : "";
     $time = str_replace(array(' ', ':'), '-', $results['time']);
     $extension = File::E($results['path']);
     if ($php_file = File::exist(File::D($results['path']) . DS . $results['slug'] . '.php')) {
         ob_start();
         include $php_file;
         $results['content'] = ob_get_clean();
     }
     $results['date'] = self::AMF(Date::extract($results['time']), $FP, 'date');
     $results['url'] = self::AMF($config->url . $connector . $results['slug'], $FP, 'url');
     $results['link'] = "";
     $results['excerpt'] = "";
     if (!isset($results['author'])) {
         $results['author'] = self::AMF($config->author, $FP, 'author');
     }
     if (!isset($results['description'])) {
         $summary = Converter::curt($content, $config->excerpt_length, $config->excerpt_tail);
         $results['description'] = self::AMF($summary, $FP, 'description');
     }
     $content_test = isset($excludes['content']) && strpos($content, '<!--') !== false ? Text::toPage(Text::ES($content), 'content', $FP) : $results;
     $content_test = $content_test['content'];
     $content_test = is_array($content_test) ? implode("", $content_test) : $content_test;
     // Redirect 301 with `<!-- kick: "http://example.com" -->`
     if (strpos($content_test, '<!-- kick:') !== false && $config->page_type === rtrim($FP, ':')) {
         preg_match('#<!-- kick\\: *([\'"]?)(.*?)\\1 -->#', $content_test, $matches);
         Guardian::kick($matches[2]);
     }
     // External link with `<!-- link: "http://example.com" -->`
     if (strpos($content_test, '<!-- link:') !== false) {
         preg_match('#<!-- link\\: *([\'"]?)(.*?)\\1 -->#', $content_test, $matches);
         $results['link'] = $matches[2];
         $results['content'] = preg_replace('#<!-- link\\:.*? -->#', "", $results['content']);
     }
     // Manual post excerpt with `<!-- cut+ "Read More" -->`
     if (strpos($content_test, '<!-- cut+ ') !== false) {
         preg_match('#<!-- cut\\+( +([\'"]?)(.*?)\\2)? -->#', $content_test, $matches);
         $more = !empty($matches[3]) ? $matches[3] : $speak->read_more;
         $content_test = preg_replace('#<!-- cut\\+( +(.*?))? -->#', '<p><a class="fi-link" href="' . $results['url'] . '#read-more:' . $results['id'] . '">' . $more . '</a></p><!-- cut -->', $content_test);
     }
     // ... or `<!-- cut -->`
     if (strpos($content_test, '<!-- cut -->') !== false) {
         $parts = explode('<!-- cut -->', $content_test, 2);
         $results['excerpt'] = self::AMF(trim($parts[0]), $FP, 'excerpt');
         $results['content'] = preg_replace('#<p><a class="fi-link" href=".*?">.*?<\\/a><\\/p>#', "", trim($parts[0])) . NL . NL . '<span class="fi" id="read-more:' . $results['id'] . '" aria-hidden="true"></span>' . NL . NL . trim($parts[1]);
     }
     if (!isset($excludes['tags'])) {
         $tags = array();
         foreach ($results['kind'] as $id) {
             $tags[] = self::rawTag($id);
         }
         $results['tags'] = self::AMF(Mecha::eat($tags)->order('ASC', 'name')->vomit(), $FP, 'tags');
     }
     if (!isset($excludes['css']) || !isset($excludes['js'])) {
         if ($file = File::exist(CUSTOM . DS . $time . '.' . $extension)) {
             $custom = explode(SEPARATOR, File::open($file)->read());
             $css = isset($custom[0]) ? Text::DS(trim($custom[0])) : "";
             $js = isset($custom[1]) ? Text::DS(trim($custom[1])) : "";
             /**
              * CSS
              * ---
              *
              * css_raw
              * page:css_raw
              * custom:css_raw
              *
              * shortcode
              * page:shortcode
              * custom:shortcode
              *
              * css
              * page:css
              * custom:css
              *
              */
             $css = self::AMF($css, $FP, 'css_raw');
             $results['css_raw'] = Filter::apply('custom:css_raw', $css);
             $css = self::AMF($css, $FP, 'shortcode');
             $css = Filter::apply('custom:shortcode', $css);
             $css = self::AMF($css, $FP, 'css');
             $results['css'] = Filter::apply('custom:css', $css);
             /**
              * JS
              * --
              *
              * js_raw
              * page:js_raw
              * custom:js_raw
              *
              * shortcode
              * page:shortcode
              * custom:shortcode
              *
              * js
              * page:js
              * custom:js
              *
              */
             $js = self::AMF($js, $FP, 'js_raw');
             $results['js_raw'] = Filter::apply('custom:js_raw', $js);
             $js = self::AMF($js, $FP, 'shortcode');
             $js = Filter::apply('custom:shortcode', $js);
             $js = self::AMF($js, $FP, 'js');
             $results['js'] = Filter::apply('custom:js', $js);
         } else {
             $results['css'] = $results['js'] = $results['css_raw'] = $results['js_raw'] = "";
         }
         $custom = $results['css'] . $results['js'];
     } else {
         $custom = "";
     }
     $results['images'] = self::AMF(self::imagesURL($results['content'] . $custom), $FP, 'images');
     $results['image'] = self::AMF(isset($results['images'][0]) ? $results['images'][0] : Image::placeholder(), $FP, 'image');
     $comments = self::comments($results['id'], 'ASC', Guardian::happy() ? 'txt,hold' : 'txt');
     $results['total_comments'] = self::AMF($comments !== false ? count($comments) : 0, $FP, 'total_comments');
     $results['total_comments_text'] = self::AMF($results['total_comments'] . ' ' . ($results['total_comments'] === 1 ? $speak->comment : $speak->comments), $FP, 'total_comments_text');
     if (!isset($excludes['comments'])) {
         if ($comments) {
             $results['comments'] = array();
             foreach ($comments as $comment) {
                 $results['comments'][] = self::comment($comment);
             }
             $results['comments'] = self::AMF($results['comments'], $FP, 'comments');
         }
     }
     unset($comments);
     /**
      * Custom Field(s)
      * ---------------
      */
     if (!isset($excludes['fields'])) {
         /**
          * Initialize custom field(s) with the default value(s) so that
          * user(s) don't have to write `isset()` function multiple time(s)
          * just to prevent error message(s) because of the object key(s)
          * that is not available in the old post(s).
          */
         $fields = self::state_field(rtrim($FP, ':'), null, array(), false);
         $init = array();
         foreach ($fields as $key => $value) {
             $init[$key] = $value['value'];
         }
         /**
          * Start re-writing ...
          */
         if (isset($results['fields']) && is_array($results['fields'])) {
             foreach ($results['fields'] as $key => $value) {
                 if (is_array($value) && isset($value['type'])) {
                     // <= 1.1.3
                     $value = isset($value['value']) ? $value['value'] : false;
                 }
                 $init[$key] = self::AMF($value, $FP, 'fields.' . $key);
             }
         }
         $results['fields'] = $init;
         unset($fields, $init);
     }
     /**
      * Exclude some field(s) from result(s)
      */
     foreach ($results as $key => $value) {
         if (isset($excludes[$key])) {
             unset($results[$key]);
         }
     }
     return Mecha::O($results);
 }
Esempio n. 16
0
});
/**
 * Response Killer
 * ---------------
 */
Route::accept($config->manager->slug . '/(' . $response . ')/kill/id:(:num)', function ($segment = "", $id = "") use($config, $speak, $post) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    if (!($response = call_user_func('Get::' . $segment, $id))) {
        Shield::abort();
        // File not found!
    }
    Config::set(array('page_title' => $speak->deleting . ': ' . $speak->{$segment} . $config->title_separator . $config->manager->title, 'page' => $response, 'cargo' => 'kill.response.php'));
    if ($request = Request::post()) {
        $request = Filter::apply('request:__' . $segment, $request, $id);
        $P = array('data' => Mecha::A($response));
        Guardian::checkToken($request['token']);
        File::open($response->path)->delete();
        $post_o = $post;
        $post = $response;
        include __DIR__ . DS . 'task.substance.kill.php';
        $post = $post_o;
        File::write($config->{'__total_' . $segment . 's'} - 1)->saveTo(LOG . DS . $segment . 's.total.log', 0600);
        Notify::success(Config::speak('notify_success_deleted', $speak->{$segment}));
        Weapon::fire(array('on_' . $segment . '_update', 'on_' . $segment . '_destruct'), array($P, $P));
        Guardian::kick($config->manager->slug . '/' . $segment);
    } else {
        File::write($config->{'__total_' . $segment . 's'})->saveTo(LOG . DS . $segment . 's.total.log', 0600);
        Notify::warning($speak->notify_confirm_delete);
    }
Esempio n. 17
0
 /**
  * Unsets config value or whole namespace if exists. 
  * If config value presents in DB it deletes from DB.
  * Otherwise behavior would be similar to {@link ConfigBase::__unset}.
  *
  * @param string config value name or namespace name
  * @return null
  */
 function __unset($name)
 {
     if (!isset($table_data)) {
         $this->loadData();
     }
     if (isset($this->table_data[$name])) {
         DB::query("delete from " . self::TABLE_NAME . " where `key`='" . Filter::apply($name, 'STRING_QUOTE') . "' limit 1");
     }
     parent::__unset($name);
 }
Esempio n. 18
0
 function do_comment_construct()
 {
     $config = Config::get();
     $speak = Config::speak();
     if ($config->page_type === 'article') {
         $comment_id = 'comment-%d';
         // Your comment ID
         $comment_form_id = 'comment-form';
         // Your comment form ID
         $article = isset($config->article->path) ? $config->article : false;
         $G = array('data' => array('article' => Mecha::A($article), 'comment_id' => $comment_id, 'comment_form_id' => $comment_form_id));
         if ($article !== false && ($request = Request::post())) {
             $request = Filter::apply('request:comment', $request, $G);
             $s = SHIELD . DS . $config->shield . DS . 'workers' . DS;
             if ($task = File::exist($s . 'task.comment.php')) {
                 require $task;
                 // Custom comment constructor
             } else {
                 if ($task = File::exist($s . 'task.comment.ignite.php')) {
                     require $task;
                     // --ibid
                 } else {
                     // Check token
                     Guardian::checkToken($request['token'], $article->url . '#' . $comment_form_id);
                     $extension = $config->comments->moderation && !Guardian::happy() ? '.hold' : '.txt';
                     // Check name
                     if (trim($request['name']) === "") {
                         Notify::error(Config::speak('notify_error_empty_field', $speak->name));
                     }
                     // Check email
                     if (trim($request['email']) !== "") {
                         if (!Guardian::check($request['email'], '->email')) {
                             Notify::error($speak->notify_invalid_email);
                         } else {
                             // Disallow passenger(s) from entering your email address in the comment email field
                             if (!Guardian::happy() && $request['email'] === $config->author->email) {
                                 Notify::warning(Config::speak('notify_warning_forbidden_input', array('<em>' . $request['email'] . '</em>', strtolower($speak->email))));
                             }
                         }
                     } else {
                         Notify::error(Config::speak('notify_error_empty_field', $speak->email));
                     }
                     // Check URL
                     if (trim($request['url']) !== "" && !Guardian::check($request['url'], '->url')) {
                         Notify::error($speak->notify_invalid_url);
                     }
                     // Check message
                     if (trim($request['message']) === "") {
                         Notify::error(Config::speak('notify_error_empty_field', $speak->message));
                     }
                     // Check challenge
                     if (!Guardian::checkMath($request['math'])) {
                         Notify::error($speak->notify_invalid_math_answer);
                     }
                     // Check name length
                     if (Guardian::check($request['name'], '->too_long', 100)) {
                         Notify::error(Config::speak('notify_error_too_long', $speak->name));
                     }
                     // Check email length
                     if (Guardian::check($request['email'], '->too_long', 100)) {
                         Notify::error(Config::speak('notify_error_too_long', $speak->email));
                     }
                     // Check URL length
                     if (Guardian::check($request['url'], '->too_long', 100)) {
                         Notify::error(Config::speak('notify_error_too_long', $speak->url));
                     }
                     // Check message length
                     if (Guardian::check($request['message'], '->too_long', 1700)) {
                         Notify::error(Config::speak('notify_error_too_long', $speak->message));
                     }
                     // Check for spam keyword(s) in comment
                     $fucking_words = explode(',', $config->keywords_spam);
                     foreach ($fucking_words as $spam) {
                         if ($f**k = trim($spam)) {
                             if ($request['email'] === $f**k || strpos(strtolower($request['message']), strtolower($f**k)) !== false) {
                                 Notify::warning($speak->notify_warning_intruder_detected . ' <strong class="text-error pull-right">' . $f**k . '</strong>');
                                 break;
                             }
                         }
                     }
                     if (!Notify::errors()) {
                         $post = $article->date->slug;
                         $id = (int) time();
                         $parent = Request::post('parent');
                         $P = array('data' => $request);
                         $P['data']['id'] = $id;
                         $name = strip_tags($request['name']);
                         $email = Text::parse($request['email'], '->broken_entity');
                         $url = isset($request['url']) && trim($request['url']) !== "" ? $request['url'] : false;
                         $parser = strip_tags(Request::post('content_type', $config->html_parser->active));
                         $message = Text::parse($request['message'], '->text', WISE_CELL . '<img>', false);
                         $field = Request::post('fields', array());
                         include __DIR__ . DS . 'task.fields.php';
                         // Temporarily disallow image(s) in comment to prevent XSS
                         $message = preg_replace('#<img(\\s[^<>]*?)>#i', '&lt;img$1&gt;', $message);
                         Page::header(array('Name' => $name, 'Email' => $email, 'URL' => $url, 'Status' => Guardian::happy() ? 1 : 2, 'Content Type' => $parser, 'Fields' => !empty($field) ? Text::parse($field, '->encoded_json') : false))->content($message)->saveTo(COMMENT . DS . $post . '_' . Date::slug($id) . '_' . ($parent ? Date::slug($parent) : '0000-00-00-00-00-00') . $extension);
                         Notify::success(Config::speak('notify_success_submitted', $speak->comment));
                         if ($extension === '.hold') {
                             Notify::info($speak->notify_info_comment_moderation);
                         }
                         Weapon::fire(array('on_comment_update', 'on_comment_construct'), array($G, $P));
                         Guardian::kick($config->url_current . $config->url_query . (!Guardian::happy() && $config->comments->moderation ? '#' . $comment_form_id : '#' . sprintf($comment_id, Date::format($id, 'U'))));
                     } else {
                         Guardian::kick($config->url_current . $config->url_query . '#' . $comment_form_id);
                     }
                 }
             }
         }
     }
 }
Esempio n. 19
0
 * ----------
 */
Route::accept($config->manager->slug . '/tag/kill/id:(:any)', function ($id = false) use($config, $speak, $tags) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    if (!isset($tags[$id])) {
        Shield::abort();
        // Tag not found!
    }
    $title = $tags[$id]['name'];
    Config::set(array('page_title' => $speak->deleting . ': ' . $title . $config->title_separator . $config->manager->title, 'cargo' => 'kill.tag.php'));
    $G = array('data' => $tags);
    $G['data']['id'] = $id;
    if ($request = Request::post()) {
        $request = Filter::apply('request:__tag', $request, $id);
        Guardian::checkToken($request['token']);
        unset($tags[$id]);
        // delete ...
        ksort($tags);
        $P = array('data' => $tags);
        $P['data']['id'] = $id;
        File::serialize($tags)->saveTo(STATE . DS . 'tag.txt', 0600);
        Notify::success(Config::speak('notify_success_deleted', $title));
        Weapon::fire(array('on_tag_update', 'on_tag_destruct'), array($G, $P));
        Guardian::kick($config->manager->slug . '/tag');
    } else {
        Notify::warning(Config::speak('notify_confirm_delete_', '<strong>' . $title . '</strong>'));
    }
    Shield::lot(array('segment' => 'tag', 'id' => $id, 'file' => Mecha::O($tags[$id])))->attach('manager');
});
Esempio n. 20
0
 * -----------
 */
Route::accept($config->manager->slug . '/menu/kill/key:(:any)', function ($key = false) use($config, $speak) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    $menus = Get::state_menu(null, array(), false);
    if (!isset($menus[$key])) {
        Shield::abort();
        // Menu not found!
    }
    Config::set(array('page_title' => $speak->deleting . ': ' . $speak->menu . $config->title_separator . $config->manager->title, 'cargo' => 'kill.menu.php'));
    $G = array('data' => $menus);
    $G['data']['key'] = $key;
    if ($request = Request::post()) {
        $request = Filter::apply('request:__menu', $request, $key);
        Guardian::checkToken($request['token']);
        unset($menus[$key]);
        // delete ...
        ksort($menus);
        $P = array('data' => $menus);
        $P['data']['key'] = $key;
        File::serialize($menus)->saveTo(STATE . DS . 'menu.txt', 0600);
        Notify::success(Config::speak('notify_success_deleted', $speak->menu));
        Weapon::fire(array('on_menu_update', 'on_menu_destruct'), array($G, $P));
        Guardian::kick($config->manager->slug . '/menu');
    } else {
        Notify::warning(Config::speak('notify_confirm_delete_', '<code>Menu::' . $key . '()</code>'));
    }
    Shield::lot(array('segment' => 'menu', 'id' => $key, 'file' => Mecha::O($menus[$key])))->attach('manager');
});
Esempio n. 21
0
 /**
  * Retrieves all the user's info with given state. If state == "all", all the users will be 
  * selected, otherwise only users with state $state will be selected.
  * The second parameter tells whether to load full info or only ids.
  *
  * @param string state of the users to be selected
  * @param bool whether to load full info about the users
  * @return array indexed array ids or with array of selected info
  */
 static function getAll($state = "all", $full_info = false)
 {
     $all = array();
     $state = Filter::apply($state, Filter::STRING_QUOTE_ENCODE);
     foreach (DB::query("select " . ($full_info ? "*" : "id") . " from " . self::TABLE . ($state !== "all" ? " where state='{$state}'" : "")) as $v) {
         $all[] = $full_info ? $v : $v['id'];
     }
     return $all;
 }
Esempio n. 22
0
 /**
  * Get page
  *
  *  <code>
  *      $page = Pages::getPage('downloads');
  *  </code>
  *
  * @access  public
  * @param  string $url Url
  * @return array
  */
 public static function getPage($url)
 {
     // If url is empty that its a homepage
     if ($url) {
         $file = STORAGE_PATH . '/pages/' . $url;
     } else {
         $file = STORAGE_PATH . '/pages/' . 'index';
     }
     // Select the file
     if (is_dir($file)) {
         $file = STORAGE_PATH . '/pages/' . $url . '/index.md';
     } else {
         $file .= '.md';
     }
     // Get 404 page if file not exists
     if (!file_exists($file)) {
         $file = STORAGE_PATH . '/pages/' . '404.md';
         Response::status(404);
     }
     // Create Unique Cache ID for requested page
     $page_cache_id = md5('page' . ROOT_DIR . $file . filemtime($file));
     if (Cache::driver()->contains($page_cache_id) && Config::get('system.pages.flush_cache') == false) {
         return Cache::driver()->fetch($page_cache_id);
     } else {
         $content = file_get_contents($file);
         $_page = explode('---', $content, 3);
         $page = Yaml::parse($_page[1]);
         $url = str_replace(STORAGE_PATH . '/pages', Url::getBase(), $file);
         $url = str_replace('index.md', '', $url);
         $url = str_replace('.md', '', $url);
         $url = str_replace('\\', '/', $url);
         $url = rtrim($url, '/');
         $page['url'] = $url;
         $_content = $_page[2];
         // Parse page for summary <!--more-->
         if (($pos = strpos($_content, "<!--more-->")) === false) {
             $_content = Filter::apply('content', $_content);
         } else {
             $_content = explode("<!--more-->", $_content);
             $_content['summary'] = Filter::apply('content', $_content[0]);
             $_content['content'] = Filter::apply('content', $_content[0] . $_content[1]);
         }
         if (is_array($_content)) {
             $page['summary'] = $_content['summary'];
             $page['content'] = $_content['content'];
         } else {
             $page['content'] = $_content;
         }
         $page['slug'] = basename($file, '.md');
         // Overload page title, keywords and description if needed
         empty($page['title']) and $page['title'] = Config::get('site.title');
         empty($page['keywords']) and $page['keywords'] = Config::get('site.keywords');
         empty($page['description']) and $page['description'] = Config::get('site.description');
         Cache::driver()->save($page_cache_id, $page);
         return $page;
     }
 }
Esempio n. 23
0
    $route_cache = $cache_config['path'][$config->url_path];
} else {
    foreach ($cache_config['path'] as $path => $exp) {
        if (Route::is($path)) {
            $route_cache = $exp;
            break;
        }
    }
}
if ($route_cache !== false) {
    Weapon::add('shield_before', function () use($config, $route_cache) {
        $q = !empty($config->url_query) ? '.' . md5($config->url_query) : "";
        $cache = CACHE . DS . str_replace(array('/', ':'), '.', $config->url_path) . $q . '.cache';
        $time = file_exists($cache) ? filemtime($cache) : false;
        if ($time !== false && ($route_cache === true || time() - $route_cache * 60 * 60 < $time)) {
            $content = file_get_contents($cache);
            if (strpos($content, '<?xml ') === 0 || strpos($content, '</html>') !== false) {
                $content .= '<!-- cached: ' . date('Y-m-d H:i:s', $time) . ' -->';
            }
            $content = Filter::apply('cache:input', $content);
            $content = Filter::apply('cache:output', $content);
            echo $content;
            exit;
        }
        Weapon::add('shield_after', function ($G) use($cache) {
            $G['data']['cache'] = $cache;
            File::write($G['data']['content'])->saveTo($cache);
            Weapon::fire('on_cache_construct', array($G, $G));
        });
    });
}
Esempio n. 24
0
            $_path = CACHE . DS . $v;
            File::open($_path)->delete();
            return $_path;
        });
        $P = array('data' => array('files' => $info_path));
        Notify::success(Config::speak('notify_file_deleted', '<code>' . implode('</code>, <code>', $deletes) . '</code>'));
        Weapon::fire(array('on_cache_update', 'on_cache_destruct'), array($P, $P));
        Guardian::kick($config->manager->slug . '/cache/1');
    } else {
        Notify::warning(count($deletes) === 1 ? Config::speak('notify_confirm_delete_', '<code>' . $path . '</code>') : $speak->notify_confirm_delete);
    }
    Shield::lot(array('segment' => 'cache', 'files' => Mecha::O($deletes)))->attach('manager');
});
/**
 * Multiple Cache Action
 * ---------------------
 */
Route::accept($config->manager->slug . '/cache/do', function () use($config, $speak) {
    if ($request = Request::post()) {
        $request = Filter::apply('request:__cache', $request);
        Guardian::checkToken($request['token']);
        if (!isset($request['selected'])) {
            Notify::error($speak->notify_error_no_files_selected);
            Guardian::kick($config->manager->slug . '/cache/1');
        }
        $files = Mecha::walk($request['selected'], function ($v) {
            return str_replace('%2F', '/', Text::parse($v, '->encoded_url'));
        });
        Guardian::kick($config->manager->slug . '/cache/' . $request['action'] . '/files:' . implode(';', $files));
    }
});
Esempio n. 25
0
<?php

/**
 * Shortcode Manager
 * -----------------
 */
Route::accept($config->manager->slug . '/shortcode', function () use($config, $speak) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    $shortcodes = Get::state_shortcode(null, array(), false);
    $G = array('data' => $shortcodes);
    Config::set(array('page_title' => $speak->shortcodes . $config->title_separator . $config->manager->title, 'cargo' => 'cargo.shortcode.php'));
    if ($request = Request::post()) {
        $request = Filter::apply('request:__shortcode', $request);
        Guardian::checkToken($request['token']);
        $data = array();
        for ($i = 0, $keys = $request['key'], $count = count($keys); $i < $count; ++$i) {
            if (trim($keys[$i]) !== "") {
                $data[$keys[$i]] = $request['value'][$i];
            }
        }
        $P = array('data' => $data);
        File::serialize($data)->saveTo(STATE . DS . 'shortcode.txt', 0600);
        Notify::success(Config::speak('notify_success_updated', $speak->shortcode));
        Weapon::fire('on_shortcode_update', array($G, $P));
        Guardian::kick($config->url_current);
    }
    Shield::lot(array('segment' => 'shortcode', 'files' => Mecha::O($shortcodes)))->attach('manager');
});
Esempio n. 26
0
 /**
  * Deletes given token from the DB
  *
  * @param string token to delete
  * @return null
  */
 static function deleteByToken($token)
 {
     if (empty($token)) {
         throw new UserExeption("Incorrect token parameter was given");
     }
     DB::query("delete from " . self::TABLE . " where token='" . Filter::apply($token, Filter::STRING_QUOTE_ENCODE) . "' limit 1");
 }
Esempio n. 27
0
 * [1]. /
 *
 */
Route::accept('/', function () use($config, $excludes) {
    Session::kill('search.query');
    Session::kill('search.results');
    $s = Get::articles();
    if ($articles = Mecha::eat($s)->chunk(1, $config->index->per_page)->vomit()) {
        $articles = Mecha::walk($articles, function ($path) use($excludes) {
            return Get::article($path, $excludes);
        });
    } else {
        $articles = false;
    }
    Filter::add('pager:url', function ($url) {
        return Filter::apply('index:url', $url);
    });
    Config::set(array('articles' => $articles, 'pagination' => Navigator::extract($s, 1, $config->index->per_page, $config->index->slug)));
    Shield::attach('page-home');
}, 110);
/**
 * Route Hook: after
 * -----------------
 */
Weapon::fire('routes_after');
/**
 * Do Routing
 * ----------
 */
Route::execute();
/**
Esempio n. 28
0
function do_meta_3()
{
    $config = Config::get();
    $speak = Config::speak();
    $html = Cell::link(Filter::colon('favicon:url', $config->url . '/favicon.ico'), 'shortcut icon', 'image/x-icon', array(), 2) . NL;
    $html .= Cell::link(Filter::colon('canonical:url', $config->url_current), 'canonical', null, array(), 2) . NL;
    $html .= Cell::link(Filter::colon('sitemap:url', $config->url . '/sitemap'), 'sitemap', null, array(), 2) . NL;
    $html .= Cell::link(Filter::colon('feed:url', $config->url . '/feed/rss'), 'alternate', 'application/rss+xml', array('title' => $speak->feeds . $config->title_separator . $config->title), 2) . O_END;
    echo Filter::apply('meta', $html, 3);
}
Esempio n. 29
0
 /**
  * Gets client ip.
  * Return string like "151.2.41.55, 192.168.0.4". That means outer address and local 
  * address after the comma, if NAT is used.
  *
  * Behavior AfterGetfullIP is defined.
  *
  * @return string
  */
 private function getFullIP()
 {
     $strRemoteIP = $_SERVER['REMOTE_ADDR'];
     if (!$strRemoteIP) {
         $strRemoteIP = urldecode(getenv('HTTP_CLIENTIP'));
     }
     if (getenv('HTTP_X_FORWARDED_FOR')) {
         $strIP = getenv('HTTP_X_FORWARDED_FOR');
     } elseif (getenv('HTTP_X_FORWARDED')) {
         $strIP = getenv('HTTP_X_FORWARDED');
     } elseif (getenv('HTTP_FORWARDED_FOR')) {
         $strIP = getenv('HTTP_FORWARDED_FOR');
     } elseif (getenv('HTTP_FORWARDED')) {
         $strIP = getenv('HTTP_FORWARDED');
     } else {
         $strIP = $_SERVER['REMOTE_ADDR'];
     }
     if (ip2long($strRemoteIP) === false) {
         throw new SessionException("Session: user ip is invalid");
     }
     if ($strRemoteIP != $strIP && !empty($strIp)) {
         $strIP = $strRemoteIP . ', ' . $strIP;
     }
     $this->trigger("AfterGetfullIP", array(&$strIP));
     return Filter::apply($strIP, Filter::STRING_QUOTE_ENCODE);
 }
Esempio n. 30
0
        if ($_bars = Mecha::A(Config::get('manager_bar'))) {
            $_bars = Mecha::eat($_bars)->order('ASC', 'stack', true, 10)->vomit();
            foreach ($_bars as $k => $v) {
                if (is_string($v)) {
                    $bar = $v;
                } else {
                    $t = ' data-tooltip="' . Text::parse(isset($v['description']) ? $v['description'] : $k, '->encoded_html') . '"';
                    if (isset($v['url'])) {
                        $url = Filter::colon('manager:url', Converter::url($v['url']));
                        $c = $config->url_current === $url ? ' ' . Widget::$config['classes']['current'] : "";
                        $bar = '<a class="item' . $c . '" href="' . $url . '"' . $t . '>';
                    } else {
                        $bar = '<span class="item a"' . $t . '>';
                    }
                    $bar .= isset($v['icon']) ? strpos($v['icon'], '<') === false ? Jot::icon($v['icon']) : $v['icon'] : $k;
                    $bar .= ' <span class="label">' . $k . '</span>';
                    if (isset($v['count']) && ($v['count'] === '&infin;' || (double) $v['count'] > 0)) {
                        $bar .= ' <span class="counter">' . $v['count'] . '</span>';
                    }
                    $bar .= isset($v['url']) ? '</a>' : '</span>';
                }
                $bars[] = $bar;
            }
        }
        $html .= $T1 . implode(' ', $bars) . NL;
    }
    $html .= '</div>' . O_END;
    $html = Filter::apply('widget', $html);
    Config::set('widget_manager_' . $kin . '_id', $id);
    return Filter::apply('widget:manager.' . $kin, Filter::apply('widget:manager', $html));
});