if (isset($_GET['hash'])) { $tweet = new Tweet(); $hash = $tweet->getHash($_GET['hash']); $check = $tweet->countHash_tweet($hash); if ($check > 0) { if (isset($_GET['num'])) { if ($_GET['num'] > 0) { $num = mysql_real_escape_string(intval($_GET['num'])); header("HTTP/1.1 200 Ok"); echo $tweet->get_output($hash, $num); } else { $error = new Header(); $error->error("<h2>HTTP 400 Bad Request</h2><hr/><h5><i>no of tweet asked is invalid</i></h5> "); } } else { $num = 10; header("HTTP/1.1 200 Ok"); echo $tweet->get_output($hash, $num); } } else { $error = new Header(); $error->error("<h2>HTTP 400 Bad Request</h2><hr/><h5><i>hashtag asked is invalid</i></h5> "); } mysql_close($con); unset($tweet); unset($error); } else { $error = new Header(); $error->error("<h2>HTTP 400 Bad Request</h2><hr/><h5><i>hashtag is not given</i></h5> "); unset($error); }
/** * It makes all transformation with page's DOM model in order to make * checks, extending and including functions. * * If current page is not allowed to show, Header::FORBIDDEN HTTP code will be returned. * * While extending page, system tries to overload ascending <block>'s with * blocks on the current page with same names. For example * <pre><code> * Page base.xml: * <root> * <block id="b1"> * <WText>Hello base.xml</WText> * </block> * <WText>Common text</WText> * </root> * * Page derived.xml: * <root extends="base"> * <block id="b1"> * <WText>Hello derived.xml</WText> * </block> * </root> * </pre></code> * * Since page derived.xml is extending base.xml, system tries to find base.xml in current controller's * directory and tries to substitute block "b1" in base.xml with derived.xml "b1". * * Also, <pre><code> <parent id="b1"/> </code></pre> may be used to include parent's block with id "b1". * * Ascending pages always checking upto ACL * * In case of including, * <pre><code> * <include src="base.xml" block="b1" allow="admin"/> * </code></pre> syntax is used. * * It includes block "b1" (may be optional) from the file "base.xml" and allows it only for group * "admin" (optional too). * * Triggers "BeforePageProcess", "BeforePageExtendsLookup", "BeforePageParentLookup", * "BeforePageExtending", "BeforePageIncluding","AfterPageProcess" events. * $this passed as 1st argument, $dom passed as 2nd parameter. * * @param DomDocument object to make transformation * @return DomDocument object that have been transofrmed * @throws ControllerException in case of unrecoverable error * @see ACL::check */ protected function processPage(DomDocument $dom) { $this->trigger("BeforePageProcess", array($this, &$dom)); if (!$dom instanceof DOMNode || !isset($dom->firstChild)) { throw new ControllerException("XML document not valid"); } // check rights $a = $dom->firstChild->getAttribute('allow'); $d = $dom->firstChild->getAttribute('deny'); if (!ACL::check($a, $d)) { Header::error(Header::FORBIDDEN); } $this->trigger("BeforPageExtendsLookup", array($this, &$dom)); // extends $adj_list = array($dom); $included_pages = array($this->page . ".xml"); $t_dom = $dom; while (($e_src = $t_dom->firstChild->getAttribute('extends')) != "" && !in_array($e_src, $included_pages)) { $t_dom = new DomDocument(); try { $t_dom->load($pp = $this->pagePath($e_src)); } catch (ControllerException $e) { throw new ControllerException('extends page not found'); } $_a = $t_dom->firstChild->getAttribute('allow'); $_d = $t_dom->firstChild->getAttribute('deny'); if (!ACL::check($_a, $_d)) { Header::error(Header::FORBIDDEN); } array_unshift($included_pages, $e_src); array_unshift($adj_list, $t_dom); $this->ie_files[] = $pp; } $this->trigger("BeforePageParentLookup", array($this, &$dom)); // searching for <parent> blocks for ($i = 1, $c = count($adj_list); $i < $c; $i++) { $nl = t(new DOMXPath($adj_list[$i]))->query("//parent[@id]"); for ($j = 0, $c2 = $nl->length; $j < $c2; $j++) { for ($k = $i - 1; $k >= 0; $k--) { $nl2 = t(new DOMXPath($adj_list[$k]))->query("//block[@id='" . $nl->item($j)->getAttribute('id') . "']"); if (!$nl2->length) { continue; } $el = $nl->item($j); $el2 = $nl2->item(0); $el2 = $adj_list[$i]->importNode($el2, true); $el->parentNode->replaceChild($el2, $el); break; } } } // extending $this->trigger("BeforePageExtending", array($this, &$dom)); if (count($adj_list) > 1) { for ($adj_i = count($adj_list) - 2; $adj_i >= 0; $adj_i--) { $dom = $adj_list[$adj_i]; $blocks = t(new DOMXPath($dom))->query("//block[@id]"); for ($i = 0, $c = $blocks->length; $i < $c; $i++) { if (($id = $blocks->item($i)->getAttribute("id")) == "") { continue; } for ($j = count($adj_list) - 1; $j > $adj_i; $j--) { $subst_blocks = t(new DOMXPath($adj_list[$j]))->query("//block[@id='" . $id . "']"); if (!$subst_blocks->length) { continue; } $el = $blocks->item($i); $el2 = $subst_blocks->item(0); $el2 = $dom->importNode($el2, true); $el->parentNode->replaceChild($el2, $el); break; } } } } $this->trigger("BeforePageClearingBlocks", array($this, &$dom)); // clean up from <block> $node_list = $dom->getElementsByTagName('block'); for ($i = 0, $c = $node_list->length; $i < $c; $i++) { $el = $node_list->item(0); if (ACL::check($el->getAttribute('allow'), $el->getAttribute('deny'))) { for ($el = $node_list->item(0), $el_cn = $el->childNodes, $j = 0, $c2 = $el_cn->length; $j < $c2; $j++) { $el->parentNode->insertBefore($el_cn->item($j)->cloneNode(true), $el); } } $el->parentNode->removeChild($el); } $this->trigger("BeforePageIncluding", array($this, &$dom)); // include $node = $dom->getElementsByTagName("include"); for ($i = 0, $c = $node->length; $i < $c; $i++) { $el = $node->item(0); if ($el && ($src = $el->getAttribute('src')) == "") { $el->parentNode->removeChild($el); continue; } $_a = $el->getAttribute('allow'); $_d = $el->getAttribute('deny'); if (!ACL::check($_a, $_d)) { $el->parentNode->removeChild($el); continue; } try { $src = $this->pagePath($src, (bool) $el->getAttribute('vendor')); } catch (ControllerException $e) { throw new ControllerException('include page file ' . $src . ' not found'); } $d = new DomDocument(); $d->load($src); $_a = $d->firstChild->getAttribute('allow'); $_d = $d->firstChild->getAttribute('deny'); if (!ACL::check($_a, $_d)) { $el->parentNode->removeChild($el); continue; } if ($el && ($block_id = $el->getAttribute("block")) !== "") { $block = t(new DOMXPath($d))->query("//block[@id='" . $block_id . "']"); if (!$block->length) { $el->parentNode->removeChild($el); continue; } else { $n_d = new DOMDocument('1.0', 'utf-8'); $n_el = $n_d->createElement('root'); $n_block = $n_d->importNode($block->item(0), true); $n_el->appendChild($n_block); $n_d->appendChild($n_el); $d = $n_d; } } $d = $this->processPage($d); $imported_node = $dom->importNode($d->firstChild, true); if ($imported_node->hasChildNodes()) { for ($node_list = $imported_node->childNodes, $j = 0, $c2 = $node_list->length; $j < $c2; $j++) { $el->parentNode->insertBefore($node_list->item($j)->cloneNode(true), $el); } } $el->parentNode->removeChild($el); $this->ie_files[] = $src; } $this->trigger("AfterPageProcess", array($this, &$dom)); return $dom; }