static function error($errorNumber, $message = null, $pos = null)
 {
     $GLOBALS['%s']->push("PHP::error");
     $__hx__spos = $GLOBALS['%s']->length;
     Debug::error($errorNumber, $message, $pos->fileName, $pos->lineNumber);
     $GLOBALS['%s']->pop();
 }
 public function getOpt($section = 'options', $opt)
 {
     if (!empty($this->aConfig[$section][$opt])) {
         return $this->aConfig[$section][$opt];
     } else {
         Debug::error("Config option not found: " . $section . "->" . $opt);
     }
 }
Exemple #3
0
 /**
  *
  * Reads a file and returns it as a string.
  * @param string $file Filename
  */
 public static function Read($file)
 {
     if (!file_exists($file)) {
         Debug::error("File '{$file}' not found.");
     }
     Debug::say("Including '{$file}'");
     return file_get_contents($file, 1024);
 }
Exemple #4
0
 private function _connect($config)
 {
     $this->_mysql = new mysqli($config['database.host'], $config['database.user'], $config['database.password'], $config['database.name']);
     if (!$this->_mysql || mysqli_connect_errno()) {
         Debug::error("No Connection. " . mysqli_connect_error());
         return false;
     }
     return true;
 }
function setParams($newParams)
{
    if (is_array($newParams)) {
        global $params;
        $params = array_merge($params, $newParams);
    } else {
        Debug::error("No params.");
    }
}
Exemple #6
0
 protected function _execute($queries)
 {
     $result = true;
     foreach ($queries as $query) {
         if ($response = $this->_db->query($query)) {
             Debug::info("Applied: " . get_class($this));
         } else {
             Debug::error("Error: " . get_class($this));
             $result = false;
         }
     }
     return $result;
 }
Exemple #7
0
 public function setCode($code)
 {
     $code = intval($code);
     if (!in_array($code, $this->_validCodes)) {
         Debug::error("Invalid Code Value: " . $code);
         return false;
     }
     if ($this->_code == 0) {
         Debug::warning("Response has already failed. Ignore new code: " . $code);
         return false;
     }
     $this->_code = $code;
     return true;
 }
Exemple #8
0
 public static function fetch($url, $xml = false, $fields = false)
 {
     if (empty($url)) {
         Debug::error("Missing Url for Curl");
         return false;
     }
     if (!self::$instance) {
         self::$instance = new self();
     }
     if ($xml) {
         $results = self::$instance->xml($url, $fields);
     } else {
         $results = self::$instance->curl($url, $fields);
     }
     return $results;
 }
Exemple #9
0
 public function getCategories()
 {
     if ($result = SQL::query("\r\nSELECT\r\n\t[blog_categories]p.[category_id] AS [category_id],\r\n\t[blog_categories]p.[category_header] AS [category_header],\r\n\t[blog_categories]p.[category_slug] AS [category_slug],\r\n\tcount([blog_posts]p.[post_id]) AS [posts_count]\r\nFROM [blog_categories]p\r\nLEFT JOIN [blog_posts]p\r\n\tON ([blog_categories]p.[category_id] == [blog_posts]p.[category_id] AND [blog_posts]p.[post_published] == 1)\r\nGROUP BY [blog_posts]p.[category_id]\r\nORDER BY [blog_categories]p.[category_header] ASC")) {
         $loop = new TPLLoop(TPL_LOOP_BLOG_CATEGORIES);
         foreach ($result->fetch() as $category) {
             $item = new TPLLoopItem();
             $item->add('CATEGORY_LINK', str_replace(array('%slug', '%id'), array($category->category_slug, $category->category_id), CFG_URL_BLOG_CATEGORY));
             $item->add('CATEGORY_ID', $category->category_id);
             $item->add('CATEGORY_SLUG', $category->category_slug);
             $item->add('CATEGORY_HEADER', $category->category_header);
             $item->add('POSTS_COUNT', $category->posts_count);
             $loop->append($item);
         }
         $loop->pack();
     } else {
         Debug::error('The blog categories could not be loaded.');
     }
 }
 public function fetchXML($url, $token)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     // URL to Scrape
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // Return string from curl_exec
     curl_setopt($ch, CURLOPT_HEADER, false);
     // Include the header info
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("GData-Version: 2.0", "Authorization: AuthSub token=\"{$token}\""));
     $results = curl_exec($ch);
     curl_close($ch);
     $string = simplexml_load_string($results);
     if ($string === FALSE) {
         Debug::error("Not XML");
         return false;
     } else {
         $oXML = new SimpleXMLElement($results);
         return $oXML;
     }
 }
Exemple #11
0
 public static function loadModules()
 {
     //Debug::dump(self::$cfg);
     //SQL::exec("INSERT INTO [modules]p ([codename],[core],[active],[order]) VALUES ('blog',0,1,1)");
     if ($result = SQL::query("SELECT [codename],[core] FROM [modules]p WHERE ([active] == 1) ORDER BY [core] DESC, [order] ASC")) {
         foreach ($result->fetch() as $module) {
             if (defined('IN_ACP')) {
                 $ext = '.acp';
             } elseif (defined('IN_ACTION')) {
                 $ext = '.action';
             } else {
                 $ext = '.sys';
             }
             if ((bool) $module->core) {
                 $path = './app/modules/' . $module->codename . '.mod.php';
             } else {
                 $path = './modules/' . $module->codename . '.mod.php';
             }
             if (file_exists($path)) {
                 if (!(include_once $path)) {
                     Debug::error('The module <strong>' . $module->codename . '</strong> could not be loaded.');
                 }
             }
             if ((bool) $module->core) {
                 $path = './app/modules/' . $module->codename . $ext . '.mod.php';
             } else {
                 $path = './modules/' . $module->codename . $ext . '.mod.php';
             }
             if (file_exists($path)) {
                 if (!(include_once $path)) {
                     Debug::error('The module <strong>' . $module->codename . '</strong> could not be loaded.');
                 }
             }
         }
     } else {
         throw new Exception('The system modules could not be loaded.');
     }
 }
 /**
  * Переписанный подписывальщик форм.
  */
 function postprocText($text)
 {
     // Split text by forms.
     $formChunks = preg_split('/(' . $this->_mf_hash . 'form\\d+\\|)/s', $text, 0, PREG_SPLIT_DELIM_CAPTURE);
     $text = $formChunks[0];
     // Remove hashes from text outside all the forms.
     $this->_getMetasInText($text);
     // Now process each form separately.
     for ($i = 1, $n = count($formChunks); $i < $n; $i += 2) {
         $hash = $formChunks[$i];
         $content = $formChunks[$i + 1];
         // This form tag.
         $formTag = $this->_mf_collectForms[$hash];
         // Extract stored hashes for form fields & clean hashes from text.
         $metas = $this->_getMetasInText($content);
         /// Step 0. Check whether the "name" attribute within <form> container is provided
         if (empty($formTag['name'])) {
             Core::Error('Container &lt;form&gt; should have a "name" attribute ' . 'with the unique identifier that is registered in global form pool ' . '(Form_Observer)');
         }
         $form = FormObserver::getForm($formTag['name']);
         if ($formTag['action'] != $form->getAction()) {
             Debug::error('Invalid form action is specified: %s found, but %s is expected', $formTag['action'], $form->getAction());
         }
         /// Step 2. We sign the form name to invoke an appropriate form object
         $metas['items'][self::ID_ELT] = array("type" => "text", "original" => $formTag['name'], "name" => self::ID_ELT);
         /// Step 3. Ok, now we compare the form object and the elements found in the container
         $components = array();
         foreach ($metas['items'] as $meta) {
             $components[$meta['name']] = $meta;
         }
         $hiddenComponents = $form->compare($components);
         // Process only POST forms!
         if (strtoupper(@$formTag['method']) == 'POST') {
             // Generate hidden tag.
             $packed = $this->_packMeta($metas);
             if ($this->MF_USE_SESSION) {
                 // If session is used, store data in session.
                 $contentHash = $this->_getHashcode($packed);
                 $_SESSION[$this->MF_META_ELT][$contentHash] = $packed;
                 $packed = $contentHash;
             }
             // Add suffix (e.g. - current timestamp) to metadata as comment. This
             // should help debugging: we always know when form metadata was generated
             // and detect stupid proxy requests when page is cached for weeks. This
             // date must NOT be included in digital signature!
             if ($this->MF_SIGN_SUFFIX !== null) {
                 $packed .= " " . $this->MF_SIGN_SUFFIX;
             }
             $hidden = array('_tagName' => 'input', 'type' => 'hidden', 'name' => $this->MF_META_ELT, 'value' => $packed, '_text' => null);
             $text .= $this->makeTag($hidden);
             /// So right now we add the signed element containing the ID of a form
             $hidden = array('_tagName' => 'input', 'type' => 'hidden', 'name' => self::ID_ELT, 'value' => $formTag['name'], '_text' => null);
             $text .= $this->makeTag($hidden);
             foreach ((array) $hiddenComponents as $component) {
                 $defVal = $component->getDefaultValue();
                 $tag = array('_tagName' => 'input', 'type' => 'hidden', 'name' => $component->getName(), 'value' => is_null($defVal) ? @$_POST[$component->getName()] : $defVal, '_text' => null);
                 $text .= $this->makeTag($tag);
             }
         }
         $text .= $content;
     }
     return $text;
 }
 /**
  * Gets the form component
  *
  * @param string $componentName
  * @return FormComponent
  */
 function getComponent($componentName)
 {
     if (isset($this->components[$componentName])) {
         return $this->components[$componentName];
     } else {
         Debug::error('unknown compoentn %s', $componentName);
     }
 }
 private function _query($query)
 {
     if (!$this->_connected) {
         return false;
     }
     $result = $this->_mysql->query($query);
     //print_r($result->fetch_object());
     //exit();
     if ($result) {
         return $result;
     } else {
         Debug::error($this->_mysql->error);
         return false;
     }
 }
Exemple #15
0
 private function execute($code)
 {
     $output = "";
     $sig = $this->createSignature($code);
     $safe_code = htmlentities($code);
     $safe_sig = htmlentities($sig);
     $raw_sig = "";
     $safe_raw_sig = "";
     $foundRawSig = false;
     if (strpos($code, "@^") !== False || strpos($code, "@\$") !== False || strpos($code, "@@") !== False) {
         $code = $this->expandLists($code);
         DEBUG::log("Expand list new code :" . $code);
     }
     if ($sig) {
         DEBUG::log("Executing : Code = " . $safe_code . " | Signature = " . $safe_sig);
     }
     if ($sig && isset($this->symbolTable[$sig])) {
         DEBUG::log("Matched terminating signature : {$safe_sig} | rvalue = " . htmlentities($this->symbolTable[$sig]['rvalue']));
         $rvalue = $this->symbolTable[$sig]['rvalue'];
         list($raw_sig, $r) = $this->createRawSignature($rvalue, false);
         if (isset($this->symbolTable[$raw_sig])) {
             $output = $this->execute($rvalue);
         } else {
             $output = $rvalue;
         }
         $foundRawSig = true;
         $rvalue = $output;
         while (strpos($rvalue, "(") !== False) {
             $rvalue = $this->processComplex($rvalue);
         }
         $output = $rvalue;
         if (sizeof(explode(" ", $output)) > 1) {
             $output = $this->execute($output);
         }
     }
     for ($k = 0; !$foundRawSig && $k < sizeof(explode(" ", $code)); $k++) {
         list($raw_sig, $r) = $this->createRawSignature($code, $k);
         if ($raw_sig === False) {
             break;
         }
         if (trim($raw_sig) == "") {
             break;
         }
         $safe_raw_sig = htmlentities($raw_sig);
         DEBUG::log("Executing : Code = " . $safe_code . " | raw signature : " . $safe_raw_sig);
         if (isset($this->symbolTable[$raw_sig])) {
             $foundRawSig = true;
             DEBUG::log("Matched raw signature : " . $safe_raw_sig);
             $args = $this->symbolTable[$raw_sig]['args'];
             $rvalue = $this->symbolTable[$raw_sig]['rvalue'];
             //$l = explode(" ", $code);
             for ($i = 0; $i < sizeof($args); $i++) {
                 if (isset($r[$i + 1])) {
                     if (substr($args[$i], 0, 1) == "@") {
                         $rvalue = trim(str_replace(" " . $args[$i] . " ", " [ " . $r[$i + 1] . " ] ", " " . $rvalue . " "));
                         $rvalue = trim(str_replace(" #" . $args[$i] . " ", " #[" . $r[$i + 1] . " ] ", " " . $rvalue . " "));
                     } else {
                         $rvalue = trim(str_replace(" " . $args[$i] . " ", " " . $r[$i + 1] . " ", " " . $rvalue . " "));
                         $rvalue = trim(str_replace(" #" . $args[$i] . " ", " #" . $r[$i + 1] . " ", " " . $rvalue . " "));
                     }
                 } else {
                     $output .= "Error {$code} - Argument count mismatch\n";
                 }
             }
             while (strpos($rvalue, "(") !== False) {
                 $rvalue = $this->processComplex($rvalue);
             }
             //if(strpos($rvalue,"[") !== False) {$output .= $this->execute($rvalue); break;}
             $fn = explode(" ", $rvalue);
             DEBUG::traceDump("Arguments", $r);
             switch ($r[0]) {
                 case "+":
                     $output .= $this->add($r[1], $r[2]);
                     break;
                 case "-":
                     $output .= $this->substract($r[1], $r[2]);
                     break;
                 case "*":
                     $output .= $this->multiply($r[1], $r[2]);
                     break;
                 case "/":
                     $output .= $this->divide($r[1], $r[2]);
                     break;
                 case "\\":
                     $output .= $this->divide_int($r[1], $r[2]);
                     break;
                 case "%":
                     $output .= $this->modulus($r[1], $r[2]);
                     break;
                 case "&&":
                     $output .= $this->f_and($r[1], $r[2]);
                     break;
                 case "||":
                     $output .= $this->f_or($r[1], $r[2]);
                     break;
                 case "&":
                     $output .= $this->b_and($r[1], $r[2]);
                     break;
                 case "|":
                     $output .= $this->b_or($r[1], $r[2]);
                     break;
                 case "^":
                     $output .= $this->b_xor($r[1], $r[2]);
                     break;
                 case "~":
                     $output .= $this->b_complement($r[1]);
                     break;
                 case "<<":
                     $output .= $this->leftShift($r[1], $r[2]);
                     break;
                 case ">>":
                     $output .= $this->rightShift($r[1], $r[2]);
                     break;
                 case "<":
                     $output .= $this->f_less($r[1], $r[2]);
                     break;
                 case ">":
                     $output .= $this->f_greater($r[1], $r[2]);
                     break;
                 case "<=":
                     $output .= $this->f_less_or_equal($r[1], $r[2]);
                     break;
                 case ">=":
                     $output .= $this->f_greater_or_equal($r[1], $r[2]);
                     break;
                 case "==":
                     $output .= $this->f_equal($r[1], $r[2]);
                     break;
                 case "!=":
                     $output .= $this->f_notEqual($r[1], $r[2]);
                     break;
                 case "!":
                     $output .= $this->f_not($r[1]);
                     break;
                 case "..":
                     if (isset($r[3])) {
                         $output .= $this->createRange($r[1], $r[2], $r[3]);
                     } else {
                         if (isset($r[2])) {
                             $output .= $this->createRange($r[1], $r[2], 1);
                         } else {
                             $output .= $this->createRange(0, $r[1], 1);
                         }
                     }
                     break;
                 case "@&":
                     $output .= $this->listLen($r[1]);
                     break;
                 case "@#":
                     $output .= $this->listItem($r[1], $r[2]);
                     break;
                 default:
                     DEBUG::log("Recursing :" . htmlentities($rvalue));
                     $output .= $this->execute($rvalue);
                     break;
             }
         }
         if ($foundRawSig) {
             break;
         }
     }
     if (!$foundRawSig) {
         if (strpos($code, "(") !== False) {
             $newcode = $code;
             while (strpos($newcode, "(") != False) {
                 DEBUG::log("Processing Complex : {$safe_code}");
                 $newcode = $this->processComplex($newcode);
             }
             if (sizeof(explode(" ", $newcode)) > 1) {
                 $output .= $this->execute($newcode);
             }
         } else {
             if (strpos($code, '[') !== False) {
                 list($lvalue, $rvalue) = explode('[', $code);
                 $lvalue = trim($lvalue);
                 $rvalue = substr($rvalue, 0, strpos($rvalue, ']'));
                 $listVal = explode(",", $rvalue);
                 if (strlen($lvalue) != 0) {
                     $output .= " [ ";
                     $size = sizeof($listVal);
                     for ($i = 0; $i < $size; $i++) {
                         $newCode = trim($lvalue . " " . trim($listVal[$i]));
                         $output .= trim($this->execute($newCode));
                         if ($i != $size - 1) {
                             $output .= ", ";
                         }
                     }
                     $output .= " ] ";
                 } else {
                     $output .= " [" . $rvalue . "] ";
                 }
             } else {
                 if (preg_match("/^[-+]?[0-9]*[.]?[0-9]+[eE]?[0-9]*\$/", trim($code)) != False) {
                     $output .= $safe_code;
                 } else {
                     Debug::error("Error: No match found for symbol `{$safe_code}'");
                 }
             }
         }
     }
     Debug::log("Output : " . $output);
     return $output;
 }
Exemple #16
0
 private function schemaTableExists()
 {
     global $config;
     $query = "SELECT table_name\n        FROM information_schema.tables\n        WHERE table_schema = '" . $config['database.name'] . "'\n        AND table_name = 'schema_versions_applied'";
     $result = $this->_db->query($query);
     if ($result) {
         Debug::info("Schema_Versions_Applied table found.");
         return true;
     }
     Debug::error("Schema_Versions_Applied table not found.");
     $query = "\n\t\t\tCREATE TABLE `schema_versions_applied` (\n            `change_id` int(11) NOT NULL AUTO_INCREMENT,\n            `change_filename` varchar(255) NOT NULL,\n            `applied` int(11) NOT NULL,\n            PRIMARY KEY (`change_id`),\n            UNIQUE KEY (`change_filename`)\n            ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;";
     $result = $this->_db->query($query);
     if ($result) {
         Debug::info("Schema_Versions_Applied table created.");
         return true;
     }
     return false;
 }
	static function error($errorNumber, $message = null, $pos = null) {
		Debug::error($errorNumber, $message, $pos->fileName, $pos->lineNumber);
	}
Exemple #18
0
 /**
  *
  * Get posts from feeds:
  * @param array $feeds Array with the feeds.
  * @return array Array with the posts.
  */
 public function getPosts($feeds)
 {
     $posts = array();
     foreach ($feeds as $name => $feed) {
         Debug::info("Getting posts from " . $feed['url']);
         $rss = new SimplePie($feed['url']);
         $rss->handle_content_type();
         $rss->force_feed(true);
         $counter = 1;
         foreach ($rss->get_items() as $item) {
             Debug::info("  post {$counter} of " . MAXPOSTS . ".");
             if (!is_object($item)) {
                 Debug::error("Parsing item (" . $item . ").");
             } else {
                 if (strstr($item->get_title(), "[minipost]")) {
                     Debug::say("Minipost...passing.");
                 } else {
                     $counter++;
                     $timestamp = strtotime($item->get_date());
                     # Post:
                     $posts[$timestamp]['id'] = "p" . $timestamp . "-" . $counter;
                     $posts[$timestamp]['pubdate'] = $item->get_date('r');
                     $posts[$timestamp]['date'] = $item->get_local_date();
                     $posts[$timestamp]['time'] = $item->get_local_date("%T");
                     $posts[$timestamp]['permalink'] = $item->get_permalink();
                     $posts[$timestamp]['title'] = $item->get_title();
                     $posts[$timestamp]['description'] = $item->get_description();
                     $posts[$timestamp]['content'] = $item->get_content();
                     if ($posts[$timestamp]['description'] == $posts[$timestamp]['content'] and strlen($posts[$timestamp]['content']) < 400) {
                         $posts[$timestamp]['description'] = Html::Cut(Html::BurnerClean($item->get_description()));
                         $posts[$timestamp]['content'] = "";
                         $posts[$timestamp]['toggle'] = "";
                     } else {
                         $posts[$timestamp]['description'] = Html::Cut(Html::BurnerClean($item->get_description()));
                         $posts[$timestamp]['content'] = Html::Clean($item->get_content());
                         $posts[$timestamp]['toggle'] = "<a onclick='ToggleContent(\"" . $posts[$timestamp]['id'] . "\"); return false;' href=\"#\">&dArr; Read more</a>";
                     }
                     // Microblogging posts have same description as title
                     if (FALSE !== strpos($posts[$timestamp]['title'], $posts[$timestamp]['description'])) {
                         $posts[$timestamp]['description'] = "";
                         $posts[$timestamp]['content'] = "";
                         $posts[$timestamp]['toggle'] = "";
                     }
                     # Rss:
                     $posts[$timestamp]['description_rss'] = $posts[$timestamp]['description'];
                     $posts[$timestamp]['content_rss'] = $posts[$timestamp]['content'];
                     # author:
                     if (method_exists($item, 'get_author') and is_object($item->get_author())) {
                         # The feed ones:
                         $posts[$timestamp]['author'] = $item->get_author()->get_name();
                         $posts[$timestamp]['author_link'] = $item->get_author()->get_link();
                     } else {
                         Debug::say("No author data feed " . $name);
                         $posts[$timestamp]['author'] = $name;
                         $posts[$timestamp]['author_link'] = $rss->get_permalink();
                     }
                     # Si han quedado vacíos pese a todo:
                     if (empty($posts[$timestamp]['author'])) {
                         $posts[$timestamp]['author'] = $name;
                     }
                     if (empty($posts[$timestamp]['author_link'])) {
                         $posts[$timestamp]['author_link'] = $feed['url'];
                     }
                     $posts[$timestamp]['author_email'] = $feed['email'];
                     # Gravatar:
                     if (strlen($feed['avatar'])) {
                         $posts[$timestamp]['author_avatar'] = "http://www.gravatar.com/avatar.php?gravatar_id=" . md5($feed['avatar']) . "&amp;size=40&amp;default=" . urlencode(DEFAULT_AVATAR);
                     } else {
                         if (strlen($feed['avatar_url'])) {
                             $posts[$timestamp]['author_avatar'] = $feed['avatar_url'];
                         }
                     }
                     # Blog:
                     $posts[$timestamp]['blog_title'] = $rss->get_title();
                     $posts[$timestamp]['blog_url'] = $rss->get_permalink();
                     $posts[$timestamp]['blog_desc'] = $rss->get_description();
                     # Logo:
                     $posts[$timestamp]['logo_url'] = $rss->get_image_url();
                     $posts[$timestamp]['logo_link'] = $rss->get_image_link();
                     $posts[$timestamp]['logo_title'] = $rss->get_image_title();
                 }
             }
             if ($counter > MAXPOSTS) {
                 break;
             }
         }
     }
     krsort($posts);
     #Debug::dump($posts);
     return $posts;
 }
Exemple #19
0
 public function fetchXML($url)
 {
     if (function_exists('apc_fetch')) {
         $expiry = apc_fetch('expiry');
         if (!$expiry || $expiry < time()) {
             apc_clear_cache();
             apc_clear_cache('user');
             apc_store('expiry', time() + config('apc.expiry'));
         }
         if (apc_fetch($url)) {
             $results = apc_fetch($url, $results);
         } else {
             $results = Curl::fetch($url, true);
             apc_store($url, $results);
         }
     } else {
         $results = Curl::fetch($url, true);
     }
     $string = simplexml_load_string($results);
     if ($string === FALSE) {
         Debug::error("Not XML");
         return false;
     } else {
         $oXML = new SimpleXMLElement($results);
         return $oXML;
     }
 }