public static function __callStatic($kin, $arguments = array()) { $kin = get_called_class() . '::' . $kin; if (!isset(self::$o[$kin])) { Guardian::abort('Method <code>' . $kin . '()</code> does not exist.'); } return call_user_func_array(self::$o[$kin], $arguments); }
public static function take($files) { if (!extension_loaded('gd')) { Guardian::abort('<a href="http://www.php.net/manual/en/book.image.php" title="PHP – Image Processing and GD" rel="nofollow" target="_blank">PHP GD</a> extension is not installed on your web server.'); } if (is_array($files)) { self::$open = array(); foreach ($files as $file) { self::$open[] = File::path($file); } } else { self::$open = File::path($files); } $file = is_array(self::$open) ? self::$open[0] : self::$open; self::$placeholder = File::D($file) . DS . '__' . File::B($file); self::$original = $file; File::open($file)->copyTo(self::$placeholder); self::gen($file); return new static(); }
/** * ========================================================== * RENDER A PAGE * ========================================================== * * -- CODE: ------------------------------------------------- * * Shield::attach('article'); * * ---------------------------------------------------------- * */ public static function attach($name, $fallback = false, $buffer = true) { $path__ = File::path($name); $s = explode('-', File::N($name), 2); $G = array('data' => array('name' => $name, 'name_base' => $s[0])); if (strpos($path__, ROOT) === 0 && file_exists($path__) && is_file($path__)) { // do nothing ... } else { if ($_path = File::exist(self::path($path__, $fallback))) { $path__ = $_path; } else { if ($_path = File::exist(self::path($s[0], $fallback))) { $path__ = $_path; } else { Guardian::abort(Config::speak('notify_file_not_exist', '<code>' . $path__ . '</code>')); } } } $lot__ = self::cargo(); $path__ = Filter::apply('shield:path', $path__); $G['data']['lot'] = $lot__; $G['data']['path'] = $path__; $G['data']['path_base'] = $s[0]; $out = ""; // Begin shield Weapon::fire('shield_lot_before', array($G, $G)); extract(Filter::apply('shield:lot', $lot__)); Weapon::fire('shield_lot_after', array($G, $G)); Weapon::fire('shield_before', array($G, $G)); if ($buffer) { ob_start(function ($content) use($path__, &$out) { $content = Filter::apply('shield:input', $content, $path__); $out = Filter::apply('shield:output', $content, $path__); return $out; }); require $path__; ob_end_flush(); } else { require $path__; } $G['data']['content'] = $out; // Reset shield lot self::$lot = array(); // End shield Weapon::fire('shield_after', array($G, $G)); exit; }
public static function take($files) { if (!extension_loaded('zip')) { Guardian::abort('<a href="http://www.php.net/manual/en/book.zip.php" title="PHP – Zip" rel="nofollow" target="_blank">PHP Zip</a> extension is not installed on your web server.'); } self::$open = self::$opens = null; self::$zip = new ZipArchive(); if (is_array($files)) { self::$opens = array(); $taken = false; foreach ($files as $key => $value) { $key = File::path($key); $value = File::path($value); self::$opens[$key] = $value; if (!$taken) { self::$open = $key; $taken = true; } } } else { self::$open = File::path($files); } return new static(); }
/** * ============================================================ * CREATE POST REQUEST WITHOUT HTML FORM * ============================================================ * * -- CODE: --------------------------------------------------- * * HTTP::post('/path', array('test' => 'OK!')); * * ------------------------------------------------------------ * */ public static function post($url, $fields = array()) { if (!function_exists('curl_init')) { Guardian::abort('<a href="http://php.net/curl" title="PHP – cURL" rel="nofollow" target="_blank">PHP cURL</a> extension is not installed on your web server.'); } $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $fields); $output = curl_exec($curl); curl_close($curl); return $output; }
/** * Custom Widget * ------------- * * [1]. Widget::my_custom_widget($a, $b, $c); * */ public static function __callStatic($kin, $arguments = array()) { $c = get_called_class(); if (!isset(self::$w[$c][$kin])) { Guardian::abort(Config::speak('notify_not_exist', '<code>' . $c . '::' . $kin . '()</code>'), false); } else { // built-in if (!is_array(self::$w[$c][$kin])) { return call_user_func_array(self::$w[$c][$kin], $arguments); } // custom $snake = Text::parse($kin, '->snake_case'); $slug = Text::parse($snake, '->slug'); $id = Config::get('widget_custom_' . $snake . '_id', 0) + 1; $html = ""; if (self::$w[$c][$kin]['wrapper']) { $html .= O_BEGIN . '<div class="widget widget-custom widget-custom-' . $slug . '" id="widget-custom-' . $slug . '-' . $id . '">' . NL; } $html .= call_user_func_array(self::$w[$c][$kin]['fn'], $arguments); if (self::$w[$c][$kin]['wrapper']) { $html .= NL . '</div>' . O_END; } Config::set('widget_custom_' . $snake . '_id', $id); return Filter::apply(array('widget:custom.' . $snake, 'widget:custom.' . $kin, 'widget:custom', 'widget'), $html, $id); } }
if ($path === 'feed/json' || strpos($path, 'feed/json/') === 0 || $path === 'feeds/json' || strpos($path, 'feeds/json/') === 0) { $page = 'json'; } // Create a proper query string data if ($path !== "") { 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
/** * ========================================================== * RENDER A PAGE * ========================================================== * * -- CODE: ------------------------------------------------- * * Shield::attach('article', true, false); * * ---------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * --------- | ------- | ----------------------------------- * $name | string | Name of the shield * $minify | boolean | Minify HTML output? * $cache | boolean | Create a cache file on page visit? * $expire | integer | Define cache file expiration time * --------- | ------- | ----------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function attach($name, $minify = null, $cache = false, $expire = null) { $config = Config::get(); if (is_null($minify)) { $minify = $config->html_minifier; } $G = array('data' => array('name' => $name, 'minify' => $minify, 'cache' => $cache, 'expire' => $expire)); $shield = false; $shield_base = explode('-', $name, 2); if ($_file = File::exist(self::path($name))) { $shield = $_file; } else { if ($_file = File::exist(self::path($shield_base[0]))) { $shield = $_file; } else { Guardian::abort(Config::speak('notify_file_not_exist', '<code>' . self::path($name) . '</code>')); } } $G['data']['path'] = $shield; $q = !empty($config->url_query) ? '.' . md5($config->url_query) : ""; $cache_path = is_string($cache) ? $cache : CACHE . DS . str_replace(array('/', ':'), '.', $config->url_path) . $q . '.cache'; if ($G['data']['cache'] && file_exists($cache_path)) { if (is_null($expire) || is_int($expire) && time() - $expire < filemtime($cache_path)) { // Begin shield cache Weapon::fire('shield_cache_before', array($G, $G)); echo Filter::apply('shield:cache', File::open($cache_path)->read()); // Clear session Notify::clear(); Guardian::forget(); self::$lot = array(); // End shield cache Weapon::fire('shield_cache_after', array($G, $G)); exit; } } // Begin shield Weapon::fire('shield_before', array($G, $G)); ob_start($minify ? 'self::s_o' : 'self::s_o_d'); extract(Filter::apply('shield:lot', self::cargo())); require Filter::apply('shield:path', $shield); // Clear session Notify::clear(); Guardian::forget(); self::$lot = array(); // Get shield content $content = ob_get_contents(); ob_end_flush(); // Create shield cache $G['data']['content'] = $minify ? self::s_o($content) : self::s_o_d($content); if ($G['data']['cache']) { $G['data']['cache'] = $cache_path; File::write($G['data']['content'])->saveTo($cache_path); Weapon::fire('on_cache_construct', array($G, $G)); } // End shield Weapon::fire('shield_after', array($G, $G)); exit; }
/** * Alternate Method for Calling the Custom Widget * ---------------------------------------------- * * [1]. Widget::my_custom_widget($a, $b, $c); * */ public static function __callStatic($kin, $arguments = array()) { $_kin = get_called_class() . '::' . $kin; if (!isset(self::$o[$_kin])) { Guardian::abort('<code>Widget::' . $kin . '()</code> does not exist.'); } $html = call_user_func_array(self::$o[$_kin], $arguments); $html = Filter::apply('widget', $html); return Filter::apply('widget:custom.' . Text::parse($kin, '->snake_case'), Filter::apply('widget:custom.' . $kin, Filter::apply('widget:custom', $html))); }