public function char($str = '', $limit = 500, $endChar = '...', $stripTags = false, $encoding = "utf-8") { if (!is_string($str)) { return Error::set(lang('Error', 'stringParameter', 'str')); } if (!is_numeric($limit)) { $limit = 500; } if (!is_string($endChar)) { $endChar = '...'; } if (!is_bool($stripTags)) { $stripTags = true; } $str = trim($str); if (empty($str)) { return $str; } if ($stripTags === true) { $str = strip_tags($str); } $str = preg_replace("/\\s+/", ' ', str_replace(array("\r\n", "\r", "\n", " "), ' ', $str)); if (strlen($str) <= $limit) { return $str; } else { return mb_substr($str, 0, $limit, $encoding) . $endChar; } }
public function decodeArray($data = '', $length = 512) { if (!is_string($data)) { return Error::set('Error', 'stringParameter', '1.(data)'); } return json_decode($data, true, $length); }
public function index($arguments) { $news = new news(ConnectionFactory::get('mongo')); $articles = new articles(ConnectionFactory::get('mongo')); $notices = new notices(ConnectionFactory::get('redis')); $irc = new irc(ConnectionFactory::get('redis')); $quotes = new quotes(ConnectionFactory::get('mongo')); $forums = new forums(ConnectionFactory::get('redis')); // Set all site-wide notices. foreach ($notices->getAll() as $notice) { Error::set($notice, true); } // Fetch the easy data. $this->view['news'] = $news->getNewPosts(); $this->view['shortNews'] = $news->getNewPosts(true); $this->view['newArticles'] = $articles->getNewPosts('new', 1, 5); $this->view['ircOnline'] = $irc->getOnline(); $this->view['randomQuote'] = $quotes->getRandom(); $this->view['fPosts'] = $forums->getNew(); // Get online users. $apc = new APCIterator('user', '/' . Cache::PREFIX . 'user_.*/'); $this->view['onlineUsers'] = array(); while ($apc->valid()) { $current = $apc->current(); array_push($this->view['onlineUsers'], substr($current['key'], strlen(Cache::PREFIX) + 5)); $apc->next(); } // Set title. Layout::set('title', 'Home'); }
public function word($string = '', $badWords = '', $changeChar = '[badwords]') { if (!isValue($string)) { return Error::set(lang('Error', 'valueParameter', 'string')); } if (!is_array($badWords)) { if (empty($badWords)) { return $string; } return $string = Regex::replace($badWords, $changeChar, $string, 'xi'); } $ch = ''; $i = 0; if (!empty($badWords)) { foreach ($badWords as $value) { if (!is_array($changeChar)) { $ch = $changeChar; } else { if (isset($changeChar[$i])) { $ch = $changeChar[$i]; $i++; } } $string = Regex::replace($value, $ch, $string, 'xi'); } } return $string; }
public function uncompress($data = '', $small = 0) { if (!isValue($data)) { return Error::set(lang('Error', 'valueParameter', '1.(data)')); } return lzf_decompress($data); }
public function check() { $this->setView('reclaim/index'); if (Session::isLoggedIn()) { return Error::set('You\'re logged in!'); } $this->view['valid'] = true; $this->view['publicKey'] = Config::get('recaptcha:publicKey'); if (empty($_POST['recaptcha_challenge_field']) || empty($_POST['recaptcha_response_field'])) { return Error::set('We could not find the captcha validation fields!'); } $recaptcha = Recaptcha::check($_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']); if (is_string($recaptcha)) { return Error::set(Recaptcha::$errors[$recaptcha]); } if (empty($_POST['username']) || empty($_POST['password'])) { return Error::set('All forms are required.'); } $reclaims = new reclaims(ConnectionFactory::get('mongo')); $good = $reclaims->authenticate($_POST['username'], $_POST['password']); if (!$good) { return Error::set('Invalid username/password.'); } $reclaims->import($_POST['username'], $_POST['password']); $users = new users(ConnectionFactory::get('mongo')); $users->authenticate($_POST['username'], $_POST['password']); header('Location: ' . Url::format('/')); }
private static function _init($access_type, $category_name) { $access_id = $category_id = 0; if (!strlen($access_type)) { Error::set(MISSING_ACCESS_TYPE); return false; } else { $access_id = self::getAccessTypeId($access_type); if (!$access_id) { Error::set(NOT_MATCHING_ACCESS_TYPE); return false; } } if (!strlen($category_name)) { Error::set(MISSING_CATEGORY_NAME); return false; } else { $category_id = self::getCategoryId($category_name); if (!$category_id) { Error::set(NOT_MATCHING_CATEGORY_NAME); return false; } } if ($category_id && $access_id) { $db = new Db(); $category_id = $db->quote($category_id); $access_id = $db->quote($access_id); $query = "SELECT * FROM menu where category_id = {$category_id} AND access_type = {$access_id} AND active = 1 order by menu_order ASC"; return $db->select($query); } return false; }
public function save() { if (is_numeric($this->page_id) && is_string($this->page_name)) { $db = new Db(); $id = $db->quote($this->page_id); $category_id = $db->quote($this->category_id); $name = $db->quote($this->page_name); $url = $db->quote($this->url); $top_description = $db->quote($this->top_description); $bottem_description = $db->quote($this->bottom_description); $keyword = $db->quote($this->keyword); $title = $db->quote($this->title); $description = $db->quote($this->description); $access_type = $db->quote($this->access_type); $active = $db->quote($this->page_status); $author = $db->quote(1); $modified = $db->quote(1); $query = "INSERT INTO " . $this->tableName() . " (page_id, category_id, name, url, top_description, bottem_description, \n Keyword, title, description, author, modified_by, access_type, active) \n VALUES({$id}, {$category_id}, {$name}, {$url}, {$top_description}, {$bottem_description}, {$keyword}, {$title}, {$description},\n {$author}, {$modified}, {$access_type}, {$active})\n ON DUPLICATE KEY UPDATE \n name= {$name}, category_id={$category_id}, url={$url},top_description={$top_description}, bottem_description={$bottem_description}, \n Keyword={$keyword}, title={$title}, description={$description}, author={$author}, modified_by={$modified}, \n active={$active}, access_type={$access_type}"; if ($db->query($query)) { return true; } else { Error::set($db->error()); } } return false; }
public function word($string = '', $badWords = '', $changeChar = '[badwords]') { if (!is_scalar($string)) { return Error::set('Error', 'valueParameter', 'string'); } return str_ireplace($badWords, $changeChar, $string); }
public function confirm($arguments) { if (Session::isLoggedIn()) { return Error::set(self::ERR_LOGGED_IN); } if (empty($arguments[0])) { return Error::set(self::ERR_NO_LOST_ID); } if (empty($arguments[1]) || $arguments[1] != 'auth' && $arguments[1] != 'password') { return Error::set(self::ERR_INIVALID_MODE); } $passReset = new passwordReset(ConnectionFactory::get('redis')); $info = $passReset->get($arguments[0], $arguments[1] == 'auth' ? true : false); if (is_string($info)) { return Error::set($info); } $users = new users(ConnectionFactory::get('mongo')); if ($arguments[1] == 'auth') { $users->changeAuth($info[1], true, false, false, false); $this->view['password'] = false; } else { $password = $users->resetPassword($info[1]); $this->view['password'] = $password; } }
public function data($str = '', $data = array()) { if (!is_string($str)) { return Error::set(lang('Error', 'stringParameter', 'str')); } $bladeChars = array('{{{' => '<?php echo "', '}}}' => '" ?>', '{{--' => '<!-- ', '--}}' => ' -->', '{{' => '<?php echo ', '}}' => ' ?>', '{[' => '<?php', ']}' => '?>'); $endKeywords = array('foreach', 'for', 'while', 'if', 'switch'); $newData = str_replace(array_keys($bladeChars), array_values($bladeChars), $str); $newDatas = array(); preg_match_all('/\\B@.+\\B/', $newData, $matchData); if (!empty($matchData[0])) { foreach ($matchData[0] as $val) { $new = str_replace('@', '??', $val); preg_match('/\\w+/', $new, $matchKeyword); $matchKeyword = isset($matchKeyword[0]) ? $matchKeyword[0] : NULL; if (in_array(strtolower(trim($matchKeyword)), $endKeywords) && !strstr($new, ':')) { $new .= ':'; } $newDatas[$val] = $new . ' ?>'; } } $newData = str_replace(array_keys($newDatas), array_values($newDatas), $newData); $newData = preg_replace('/\\?\\?/', '<?php ', $newData); if (is_array($data)) { extract($data, EXTR_OVERWRITE, 'extract'); } ob_start(); eval("?>{$newData}"); $content = ob_get_contents(); ob_end_clean(); return $content; }
public function error() { if (isset($this->error)) { return Error::set($this->error); } else { return false; } }
public function type($type = 'text/css') { if (!is_string($type)) { Error::set('Error', 'stringParameter', 'type'); return $this; } $this->type = $type; return $this; }
public function type($type = 'text/javascript') { if (!is_string($type)) { Error::set(lang('Error', 'stringParameter', 'type')); return $this; } $this->type = $type; return $this; }
public function data($string = '', $data = array()) { // Parametre konrolleri sağlanıyor. if (!is_string($string)) { return Error::set('Error', 'stringParameter', 'string'); } $eol = eol(); // Veri dizisi boş değilse işlemleri gerçekleştir. if (!empty($data)) { $space = '\\s*'; $all = '.*'; foreach ($data as $key => $val) { // Eleman dizi değilse değiştirme işlemi gerçekleştir. if (!is_array($val)) { $key = $this->ldel . $space . $key . $space . $this->rdel; $string = preg_replace('/' . $key . '/', $val, $string); } else { $allString = ''; $newResult = ''; if (!empty($val)) { $kstart = $this->ldel . $space . $key . $space . $this->rdel; $kend = $this->ldel . $space . '\\/' . $space . $key . $space . $this->rdel; preg_match('/' . $kstart . $all . $kend . '/s', $string, $result); if (!empty($result)) { // Bloğu değiştirme ve çoğalatma // işlemi gerçekleştir. foreach ($result as $res) { // Değiştirme işlemlerini gerçekleştir. foreach ($data[$key] as $item) { $newResult = preg_replace('/' . $kstart . '/', '', $res); $newResult = preg_replace('/' . $kend . '/', '', $newResult); $allString .= $this->data($newResult, $item) . $eol; } $string = str_replace($res, $allString, $string); } } } } } } $regexChar = '(([^@]|(\'|\\").*?(\'|\\"))*)'; $htmlRegexChar = '.*?'; $pattern = array('/\\s*\\#end(\\w+)/i' => '</$1>', '/\\#\\#(\\!*\\w+)\\s*\\((' . $htmlRegexChar . ')\\)/i' => '<$1 $2>', '/\\s*\\#\\#(\\w+)/i' => '</$1>', '/\\#(\\!*\\w+)\\s*\\((' . $htmlRegexChar . ')(\\s*\\,\\s*(' . $htmlRegexChar . '))*\\)/i' => '<$1 $4>$2</$1>', '/\\#(\\!*\\w+)\\s*(\\[(' . $htmlRegexChar . ')\\])*\\s*/i' => '<$1 $3>', '/\\<(\\!*\\w+)\\s+\\>/i' => '<$1>', '/\\$\\(\'\\s*\\<(.*?)\\>\\s*\'\\)/i' => '$(\'#$1\')', '/\\$\\(\\"\\s*\\<(.*?)\\>\\s*\\"\\)/i' => '$("#$1")', '/@(if)\\s*(\\(' . $htmlRegexChar . '\\))' . $eol . '\\s*/' => '<?php $1$2: ?>', '/\\s*@(elseif)\\s*(\\(' . $htmlRegexChar . '\\))' . $eol . '\\s*/' => '<?php $1$2: ?>', '/\\s*@(endif)/' => '<?php $1 ?>', '/@(foreach)\\s*(\\(' . $htmlRegexChar . '\\))' . $eol . '\\s*/' => '<?php $1$2: ?>', '/\\s*@(endforeach)/' => '<?php $1 ?>', '/@(for)\\s*(\\(' . $htmlRegexChar . '\\))' . $eol . '\\s*/' => '<?php $1$2: ?>', '/\\s*@(endfor)/' => '<?php $1 ?>', '/@(while)\\s*(\\(' . $htmlRegexChar . '\\))' . $eol . '\\s*/' => '<?php $1$2: ?>', '/\\s*@(endswhile)/' => '<?php $1 ?>', '/@(break)/' => '<?php $1 ?>', '/@(continue)/' => '<?php $1 ?>', '/@(default)/' => '<?php $1: ?>', '/@@((\\w+|\\$|::|\\s*\\-\\>\\s*)*\\s*\\(' . $regexChar . '\\))/' => '<?php echo $1 ?>', '/@((\\w+|\\$|::|\\s*\\-\\>\\s*)*\\s*\\(' . $regexChar . '\\))/' => '<?php $1 ?>', '/@(\\$\\w+(\\$|::|\\s*\\-\\>\\s*|\\(' . $regexChar . '\\))*)/' => '<?php echo $1 ?>', '/\\{\\-\\-\\s*(' . $htmlRegexChar . ')\\s*\\-\\-\\}/' => '<!--$1-->', '/\\{\\{\\{\\s*(' . $htmlRegexChar . ')\\s*\\}\\}\\}/' => '<?php echo htmlentities($1) ?>', '/\\{\\{(\\s*' . $htmlRegexChar . ')\\s*\\}\\}/' => '<?php echo $1 ?>', '/\\{\\[\\s*(' . $htmlRegexChar . ')\\s*\\]\\}/' => '<?php $1 ?>'); $string = preg_replace(array_keys($pattern), array_values($pattern), $string); if (is_array($data)) { extract($data, EXTR_OVERWRITE); } ob_start(); @eval("?>{$string}"); $content = ob_get_contents(); ob_end_clean(); if ($lastError = Error::last()) { Exceptions::table('', $lastError['message'], '', $lastError['line']); } else { return $content; } }
public function index() { $lectures = new lectures(ConnectionFactory::get('mongo')); $this->view['lectures'] = $lectures->getNew(); if (is_string($this->view['lectures'])) { return Error::set($this->view['lectures']); } $this->view['valid'] = true; Layout::set('title', 'Lectures'); }
public function decode($data = '', $length = 0) { if (!is_scalar($data)) { return Error::set('Error', 'valueParameter', '1.(data)'); } if (!is_numeric($length)) { return Error::set('Error', 'numericParameter', '2.(length)'); } return zlib_decode($data, $length); }
public function set($exp = 'H:i:s') { if (!is_string($exp)) { return Error::set('Error', 'stringParameter', 'exp'); } $chars = $this->config['setDateFormatChars']; $chars = Arrays::multikey($chars); $newClock = str_ireplace(array_keys($chars), array_values($chars), $exp); return date($newClock); }
public function set($exp = '') { if (!is_string($exp)) { return Error::set('Error', 'stringParameter', 'exp'); } $chars = $this->config['setTimeFormatChars']; $chars = Arrays::multikey($chars); $setExp = str_ireplace(array_keys($chars), array_values($chars), $exp); return strftime($setExp); }
public function staticCallArray($callback = '', $params = array()) { if (!is_callable($callback)) { return Error::set('Error', 'callableParameter', '1.(callback)'); } if (!is_array($params)) { return Error::set('Error', 'arrayParameter', '2.(params)'); } return forward_static_call_array($callback, $params); }
/** * Loads html from string or file */ public static function load_html($html, $is_file = false) { $doc = new DOMDocument(); $result = $is_file ? $doc->loadHTMLFile($html) : $doc->loadHTML($html); if (!$result) { $html_source = $is_file ? 'file' : 'string'; Error::set(__METHOD__, 'Unable to load HTML from ' . $html_source); } return $doc; }
public function property($property = '', $attr = array()) { if (!is_string($property)) { Error::set('Error', 'stringParameter', 'property'); return $this; } $this->property = $property; $this->attr = $attr; $this->propertyQueue .= JQ::property($property, $attr); return $this; }
public function checkpassword($Pass) { if (strlen($Pass)) { if (!Validation::valid_password($Pass)) { Error::set(INVALID_PASSWORD); return FALSE; } else { //return md5($Pass); return TRUE; } } }
public function index($arguments) { Layout::set('title', 'Search'); if (empty($_POST['query'])) { return Error::set('No search query found.'); } $query = substr(trim(htmlentities($_POST['query'], ENT_QUOTES, 'ISO8859-1', false)), 0, 250); $results = Search::query($query); if ($results['hits']['total'] == 0) { return Error::set('No results found.'); } $this->view['results'] = array(); $news = new news(ConnectionFactory::get('mongo')); $articles = new articles(ConnectionFactory::get('mongo')); $lectures = new lectures(ConnectionFactory::get('mongo')); $i = 1; if (empty($results['hits']['hits'])) { return; } foreach ($results['hits']['hits'] as $result) { $entry = $result['_source']; switch ($entry['type']) { case 'news': $post = $news->get($result['_id'], false, true); if (empty($post)) { continue; } $post['type'] = 'news'; array_push($this->view['results'], $post); break; case 'article': $article = $articles->get($result['_id'], false, true); if (empty($article)) { continue; } $article['type'] = 'article'; array_push($this->view['results'], $article); break; case 'lecture': $lecture = $lectures->get($result['_id'], false, true); if (empty($lecture)) { continue; } $lecture['type'] = 'lecture'; array_push($this->view['results'], $lecture); break; } if ($i == 5) { break; } ++$i; } }
public function name($symbolName = 'turkishLira') { if (!is_string($symbolName)) { return Error::set('Error', 'stringParameter', 'symbolName'); } $symbol = Config::get('Symbols', $symbolName); if (!empty($symbol)) { return $symbol; } else { return false; } }
public function get($configName = '', $name = '') { if (!is_string($name)) { return Error::set('Error', 'stringParameter', 'symbolName'); } $data = array_change_key_case(Config::get('Cdn', $configName)); $name = strtolower($name); if (isset($data[$name])) { return $data[$name]; } else { return $data; } }
public function read($file = '', $length = 1024, $mode = 'r') { if (!is_string($file) || empty($file)) { return Error::set('Error', 'stringParameter', '1.(file)'); } $open = zip_open($file); if (empty($open)) { return Error::set('Error', 'fileNotFound', $file); } $return = zip_read($open); zip_close($open); return $return; }
public function delete($arguments) { if (!CheckAcl::can('deleteNotices')) { return Error::set('You are not allowed to delete notices!'); } if (empty($arguments[0])) { return Error::set('No notice id was found!'); } $notices = new notices(ConnectionFactory::get('redis')); $return = $notices->delete($arguments[0]); if (is_string($return)) { return Error::set($return); } header('Location: ' . Url::format('/notice/')); }
public function vote($arguments) { if (!CheckAcl::can('voteOnNews')) { return Error::set('You can not vote on news posts.'); } if (empty($arguments[0]) || empty($arguments[1])) { return Error::set('Vote or news id not found.'); } $news = new news(ConnectionFactory::get('mongo')); $result = $news->castVote($arguments[0], $arguments[1]); $post = $news->get($arguments[0], false, true); if (is_string($result)) { return Error::set($result, false, array('Back' => Url::format('/news/view/' . Id::create($post, 'news')))); } Error::set('Vote cast!', true, array('Back' => Url::format('/news/view/' . Id::create($post, 'news')))); }
public function save() { if (is_numeric($this->state_id) && is_string($this->state_name)) { $db = new Db(); $id = $db->quote($this->state_id); $country_id = $db->quote($this->country_id); $name = $db->quote($this->state_name); $active = $db->quote($this->state_status); $query = "INSERT INTO " . $this->tableName() . " (id, country_id, name, active) VALUES({$id},{$country_id}, {$name} , {$active}) \n ON DUPLICATE KEY UPDATE \n name= {$name},country_id={$country_id}, active={$active}"; if ($db->query($query)) { return true; } else { Error::set($db->error()); } } return false; }