Exemple #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] = self::$menus[$c][$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 $output;
 }
Exemple #2
0
 public static function header($data = array(), $value = "")
 {
     if (!is_array($data)) {
         $data = array(self::fix($data) => $value);
     }
     foreach ($data as $k => $v) {
         if ($v === false) {
             unset($data[self::fix($k)], self::$bucket[self::fix($k)]);
         } else {
             // Restrict user(s) from inputting the `SEPARATOR` constant
             // to prevent mistake(s) in parsing the file content
             $data[self::fix($k)] = Text::ES($v);
         }
     }
     Mecha::extend(self::$bucket, $data);
     return new static();
 }
Exemple #3
0
 /**
  * =============================================================
  *  REGISTER NEW VARIABLE(S)
  * =============================================================
  *
  * -- CODE: ----------------------------------------------------
  *
  *    Config::set('foo', 'bar');
  *
  * -------------------------------------------------------------
  *
  *    Config::set(array(
  *        'a' => 1,
  *        'b' => 2
  *    ));
  *
  * -------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type   | Description
  *  --------- | ------ | ---------------------------------------
  *  $key      | string | Key of data to be called
  *  $key      | array  | Array of data's key and value
  *  $value    | mixed  | The value of your data key
  *  --------- | ------ | ---------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function set($key, $value = "")
 {
     if (is_object($key)) {
         $key = Mecha::A($key);
     }
     if (is_object($value)) {
         $value = Mecha::A($value);
     }
     $cargo = array();
     if (!is_array($key)) {
         Mecha::SVR($cargo, $key, $value);
     } else {
         foreach ($key as $k => $v) {
             Mecha::SVR($cargo, $k, $v);
         }
     }
     Mecha::extend(self::$bucket, $cargo);
 }
Exemple #4
0
 public static function configure($key, $value = null)
 {
     if (is_array($key)) {
         Mecha::extend(self::$config, $key);
     } else {
         if (is_array($value)) {
             Mecha::extend(self::$config[$key], $value);
         } else {
             self::$config[$key] = $value;
         }
     }
     return new static();
 }
Exemple #5
0
 /**
  * ====================================================================
  *  CONVERT ATTRIBUTE(S) OF ELEMENT INTO ARRAY OF DATA
  * ====================================================================
  *
  * -- CODE: -----------------------------------------------------------
  *
  *    var_dump(Converter::attr('<div id="foo">'));
  *
  * --------------------------------------------------------------------
  *
  *    var_dump(Converter::attr('<div id="foo">test content</div>'));
  *
  * --------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type    | Description
  *  --------- | ------- | ---------------------------------------------
  *  $input    | string  | The string of element to be converted
  *  $element  | array   | Tag open, tag close, tag separator
  *  $attr     | array   | Value open, value close, attribute separator
  *  $str_eval | boolean | Convert value with `Converter::strEval()` ?
  *  --------- | ------- | ---------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function attr($input, $element = array(), $attr = array(), $str_eval = true)
 {
     $ED = array('<', '>', ' ', '/', '[a-zA-Z0-9\\-._:]+');
     $AD = array('"', '"', '=', '[a-zA-Z0-9\\-._:]+');
     $E = Mecha::extend($ED, $element);
     $A = Mecha::extend($AD, $attr);
     $E0 = preg_quote($E[0], '#');
     $E1 = preg_quote($E[1], '#');
     $E2 = preg_quote($E[2], '#');
     $E3 = preg_quote($E[3], '#');
     $A0 = preg_quote($A[0], '#');
     $A1 = preg_quote($A[1], '#');
     $A2 = preg_quote($A[2], '#');
     if (!preg_match('#^\\s*(' . $E0 . ')(' . $E[4] . ')((' . $E2 . ')+(.*?))?((' . $E1 . ')([\\s\\S]*?)((' . $E0 . ')' . $E3 . '\\2(' . $E1 . '))|(' . $E2 . ')*' . $E3 . '?(' . $E1 . '))\\s*$#', $input, $M)) {
         return false;
     }
     $M[5] = preg_replace('#(^|(' . $E2 . ')+)(' . $A[3] . ')(' . $A2 . ')(' . $A0 . ')(' . $A1 . ')#', '$1$2$3$4$5<attr:value>$6', $M[5]);
     $results = array('element' => $M[2], 'attributes' => null, 'content' => isset($M[8]) && $M[9] === $E[0] . $E[3] . $M[2] . $E[1] ? $M[8] : null);
     if (preg_match_all('#(' . $A[3] . ')((' . $A2 . ')(' . $A0 . ')(.*?)(' . $A1 . '))?(?:(' . $E2 . ')|$)#', $M[5], $A)) {
         $results['attributes'] = array();
         foreach ($A[1] as $k => $v) {
             $results['attributes'][$v] = isset($A[5][$k]) && !empty($A[5][$k]) ? strpos($A[5][$k], '<attr:value>') === false ? $A[5][$k] : str_replace('<attr:value>', "", $A[5][$k]) : $v;
         }
     }
     return $str_eval ? self::strEval($results) : $results;
 }
Exemple #6
0
 public static function state_shortcode($key = null, $fallback = array(), $all = true)
 {
     $config = Config::get();
     $d = DECK . DS . 'workers' . DS . 'repair.state.shortcode.php';
     $shortcode = file_exists($d) ? include $d : $fallback;
     if ($file = File::exist(STATE . DS . 'shortcode.txt')) {
         $file = File::open($file)->unserialize();
         foreach ($file as $k => $v) {
             unset($shortcode[$k]);
         }
         $shortcode = array_merge($shortcode, $file);
     }
     if ($all) {
         /**
          * Allow shield to add custom built-in shortcode(s) dynamically
          * by creating a file named as `shortcodes.php` stored in a folder
          * named as `workers`. This file contains array of shortcode(s) data.
          *
          * -- EXAMPLE CONTENT OF `shortcodes.php`: --------------------------------
          *
          *    return array(
          *        '{{shortcode:%s}}' => '<span>\1</span>'
          *    );
          *
          * --------------------------------------------------------------------
          *
          */
         if ($e = File::exist(SHIELD . DS . $config->shield . DS . 'workers' . DS . 'shortcodes.php')) {
             $shortcode_e = (include $e);
             Mecha::extend($shortcode, $shortcode_e);
         }
         /**
          * Allow plugin to add custom built-in shortcode(s) dynamically
          * by creating a file named as `shortcodes.php` stored in a folder
          * named as `workers`. This file contains array of shortcode(s) data.
          */
         foreach (glob(PLUGIN . DS . '*' . DS . '{__launch,launch}.php', GLOB_BRACE | GLOB_NOSORT) as $active) {
             if ($e = File::exist(File::D($active) . DS . 'workers' . DS . 'shortcodes.php')) {
                 $shortcode_e = (include $e);
                 Mecha::extend($shortcode, $shortcode_e);
             }
         }
     }
     $shortcode = Converter::strEval($shortcode);
     // Filter output(s) by `key`
     if (!is_null($key)) {
         return isset($shortcode[$key]) ? $shortcode[$key] : $fallback;
     }
     // No filter
     return $shortcode;
 }
Exemple #7
0
 public static function state_tag($id = null, $fallback = array(), $all = true, $scope = null)
 {
     $config = Config::get();
     $speak = Config::speak();
     $d = WORKER . DS . 'repair.state.tag.php';
     $tag = file_exists($d) ? include $d : $fallback;
     if ($file = File::exist(STATE . DS . 'tag.txt')) {
         Mecha::extend($tag, File::open($file)->unserialize());
     }
     if ($all) {
         if ($e = File::exist(SHIELD . DS . $config->shield . DS . 'workers' . DS . 'tags.php')) {
             $tag_e = (include $e);
             Mecha::extend($tag, $tag_e);
         }
         foreach (glob(PLUGIN . DS . '*' . DS . '{__launch,launch}.php', GLOB_NOSORT | GLOB_BRACE) as $active) {
             if ($e = File::exist(File::D($active) . DS . 'workers' . DS . 'tags.php')) {
                 $tag_e = (include $e);
                 Mecha::extend($tag, $tag_e);
             }
         }
     }
     // Filter output(s) by `scope`
     $tag_alt = array();
     if (!is_null($scope)) {
         foreach ($tag as $k => $v) {
             foreach (explode(',', $scope) as $s) {
                 if (!isset($v['scope']) || strpos(',' . $v['scope'] . ',', ',' . $s . ',') !== false) {
                     $tag_alt[$k] = $v;
                 }
             }
         }
         $tag = $tag_alt;
     }
     unset($tag_alt);
     $tag = Filter::apply('state:tag', Converter::strEval($tag));
     // Filter output(s) by `id`
     if (!is_null($id)) {
         return isset($tag[$id]) ? $tag[$id] : $fallback;
     }
     // No filter
     return $tag;
 }
Exemple #8
0
 /**
  * ============================================================
  *  STORE THE POSTED DATA INTO SESSION
  * ============================================================
  *
  * -- CODE: ---------------------------------------------------
  *
  *    if(Request::post()) {
  *        Guardian::memorize();
  *        // do another stuff ...
  *    }
  *
  * ------------------------------------------------------------
  *
  */
 public static function memorize($name = null, $value = "")
 {
     if (is_null($name)) {
         $name = $_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : array();
     }
     if (is_object($name)) {
         $name = Mecha::A($name);
     }
     if (!is_array($name)) {
         $name = array($name => $value);
     }
     $memory = Session::get(self::$form, array());
     Session::set(self::$form, Mecha::extend($memory, $name));
 }
Exemple #9
0
 /**
  * =====================================================================
  *  READ A TEXT FILE AS A PAGE FILE
  * =====================================================================
  *
  * -- CODE: ------------------------------------------------------------
  *
  *    var_dump(Text::toPage($path));
  *
  * ---------------------------------------------------------------------
  *
  *    var_dump(Text::toPage($content));
  *
  * ---------------------------------------------------------------------
  *
  */
 public static function toPage($text, $content = 'content', $FP = 'page:', $results = array(), $data = array())
 {
     $c = $content !== false ? $content : 'content';
     foreach ($results as $k => $v) {
         $results[$k . '_raw'] = Filter::colon($FP . $k . '_raw', $v, $data);
         $results[$k] = Filter::colon($FP . $k, $v, $data);
     }
     if (!$content) {
         // By file path
         if (strpos($text, ROOT) === 0 && ($buffer = File::open($text)->get(SEPARATOR)) !== false) {
             Mecha::extend($results, self::__doParseHeaders($buffer, $FP, $data));
             unset($results['__'], $results['___raw']);
             // By file content
         } else {
             $text = str_replace("\r", "", $text);
             if (strpos($text, "\n" . SEPARATOR . "\n") !== false) {
                 $parts = explode("\n" . SEPARATOR . "\n", trim($text), 2);
                 Mecha::extend($results, self::__doParseHeaders($parts[0], $FP, $data));
                 $results[$c . '_raw'] = isset($parts[1]) ? trim($parts[1]) : "";
             }
         }
     } else {
         // By file path
         if (strpos($text, ROOT) === 0 && file_exists($text)) {
             $text = file_get_contents($text);
         }
         $text = str_replace("\r", "", $text);
         // By file content
         if (strpos($text, "\n" . SEPARATOR . "\n") === false) {
             $results[$c . '_raw'] = Converter::DS(trim($text));
         } else {
             $parts = explode(SEPARATOR, trim($text), 2);
             Mecha::extend($results, self::__doParseHeaders($parts[0], $FP, $data));
             $results[$c . '_raw'] = isset($parts[1]) ? trim($parts[1]) : "";
         }
         Mecha::extend($data, $results);
     }
     if (isset($results[$c . '_raw'])) {
         $content_extra = explode(SEPARATOR, $results[$c . '_raw']);
         if (count($content_extra) > 1) {
             $results[$c . '_raw'] = $results[$c] = array();
             foreach ($content_extra as $k => $v) {
                 $v = Converter::DS(trim($v));
                 $v = Filter::colon($FP . $c . '_raw', $v, $data, $k + 1);
                 $results[$c . '_raw'][$k] = $v;
                 $v = Filter::colon($FP . 'shortcode', $v, $data, $k + 1);
                 $v = Filter::colon($FP . $c, $v, $data, $k + 1);
                 $results[$c][$k] = $v;
             }
         } else {
             $v = Converter::DS($results[$c . '_raw']);
             $v = Filter::colon($FP . $c . '_raw', $v, $data, 1);
             $results[$c . '_raw'] = $v;
             $v = Filter::colon($FP . 'shortcode', $v, $data, 1);
             $v = Filter::colon($FP . $c, $v, $data, 1);
             $results[$c] = $v;
         }
     }
     return $results;
 }
Exemple #10
0
        array_shift($_GET);
    }
    $queries = array();
    foreach ($_GET as $k => $v) {
        $queries[] = $k . '=' . urlencode($v);
    }
    // Loading the language file(s)
    $lang = LANGUAGE . DS . 'en_US' . DS . 'speak.txt';
    $lang_a = LANGUAGE . DS . $config['language'] . DS . 'speak.txt';
    if (!file_exists($lang) && !file_exists($lang_a)) {
        Guardian::abort('Language file not found.');
    }
    $lang = file_exists($lang) ? Text::toArray(File::open($lang)->read(), S, '  ') : array();
    if ($config['language'] !== 'en_US') {
        $lang_a = file_exists($lang_a) ? Text::toArray(File::open($lang_a)->read(), S, '  ') : array();
        Mecha::extend($lang, $lang_a);
    }
    $config['url_query'] = !empty($queries) ? '?' . implode('&', $queries) : "";
    $config['offset'] = isset($s[1]) && is_numeric($s[1]) ? (int) $s[1] : 1;
    $config['page_type'] = $page;
    $config['speak'] = $lang;
    Config::set($config);
});
/**
 * =============================================================
 *  GET LANGUAGE FILE TO SPEAK
 * =============================================================
 *
 * -- CODE: ----------------------------------------------------
 *
 *    echo Config::speak('home');
Exemple #11
0
<?php

if ($config->page_type === 'article' && Request::method('post')) {
    if (!isset($_POST['fields'])) {
        $_POST['fields'] = array();
    }
    Mecha::extend($_POST['fields'], array('user_ip' => array('type' => 'hidden', 'value' => Get::IP()), 'user_agent' => array('type' => 'hidden', 'value' => Get::UA())));
    // Block comment by IP address
    $fucking_words = explode(',', $config->keywords_spam);
    foreach ($fucking_words as $spam) {
        if ($f**k = trim($spam)) {
            if (Get::IP() === $f**k) {
                Notify::warning($speak->notify_warning_intruder_detected . ' <strong class="text-error pull-right">' . $f**k . '</strong>');
                break;
            }
        }
    }
}