Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- require "db.inc.php";
- //require "funcs.inc.php";
- //----------------------------------
- function draw_form() {
- $f_draw=<<<LABEL
- <form name="goo" onsubmit="send_form(this);return false;" method="post" enctype="application/x-www-form-urlencoded">
- <fieldset>
- <legend>Input RSS Name and address below</legend>
- <p> <label for="rssname">RSS Name</label><input type="text" name="rssname" size="40"></p>
- <p> <label for="rssquey">RSS Query</label><input type="text" name="rssquery" size="40"></p>
- <p> <input type="submit" name="subm" value="Submit"></p>
- </fieldset>
- </form>
- LABEL;
- return $f_draw;
- }
- //----------------------------------------
- function drawList($items) {
- $rez="<ul>";
- foreach ($items as $item) {
- $rez.='<li>';
- //$rez.='<a href="#" onclick="ajax_request(\'req=getrss&rssq='.$item[2].'\',\'detail\');return false;">'.$item[1].'</a>';
- //$rez.='<a href="#" onclick="get_rss(\''.$item[1].'\',5,\'detail\');return false;">'.$item[1].'</a>';
- $rez.='<a href="#" onclick="get_block(\''.$item[1].'\',\'detail\');return false;">'.$item[1].'</a>';
- $rez.='</li>';
- }
- $rez.="</ul>";
- //$rez='<pre>'.print_r($items).'</pre>';
- return $rez;
- }
- //----------------------------------------
- function getlist() {
- //require "db.inc.php";
- $rez = "<div id='querylist'><h3>Query list</h3>";
- $items=getQuery('select * from gqueries order by id desc');
- if (is_string($items)) {
- return 'error: '.$items;
- }
- $rez.=drawList($items);
- //$rez.='<pre>'.print_r($items).'</pre>';
- $rez.=$items."</div>";
- return $rez;
- }
- //----------------------------------------
- function post_query($rssname,$rssquery) {
- $rez=insertQuery('insert into gqueries(%fields%) values(%values%)',
- array('name','http_query'),array('\''.$rssname.'\'','\''.addslashes($rssquery).'\''));
- return $rez;
- }
- //---------------------------------------------------
- function draw_block($blockname) {
- $blockquery=getSingle("select http_query from gqueries where name='$blockname'");
- //echo $blockquery;
- $rez=file_get_contents($blockquery);
- return $rez;
- }
- //---------------------------------------------------
- function draw_rss($rssname,$count) {
- $rssquery=getSingle("select http_query from gqueries where name='$rssname'");
- //$rez=$rssquery;
- //return $rez;
- $ver=1;
- $rez='';
- $xml=simplexml_load_file($rssquery);
- $i=1;
- foreach ($xml->children() as $a=>$b) {
- if ($a=='channel') {
- $ver=2;
- }
- }
- if ($ver==1) {
- //------------------------------Atom format
- foreach ($xml->entry as $item) {
- $title=$item->title;
- $content=$item->content;
- $link=$item->link;
- $published=$item->published;
- $rez.= <<<RSS
- <div class="rsscontent">
- <h3><a href="$link">$title<a></h3>
- <p>$content</p>
- <p class="rssdate">$published</p>
- </div>
- <div class="rsssplit"></div>
- RSS;
- $i++;
- if ($i>$count)
- break;
- }
- }
- //----------------------------------RSS 2.0 format
- else
- {//return '<pre>'.print_r($xml->channel->item->title).'</pre>';
- foreach ($xml->channel->item as $item) {
- /*foreach ($item->children() as $a=>$b) {
- $rez.=$a.'='.$b.'<br>';
- }}*/
- $title=$item->title;
- $description=$item->description;
- $link=$item->link;
- $pubDate=$item->pubDate;
- $rez.= <<<RSS
- <div class="rsscontent">
- <h3><a href="$link">$title</a></h3>
- <p>$description</p>
- <p class="rssdate">$pubDate</p>
- </div>
- <div class="rsssplit"></div>
- RSS;
- $i++;
- if ($i>$count)
- break;
- }
- }
- return $rez;
- }
- //---------------------------------------------------
- //---------------------------------------------------
- $cn_status=conn();
- if ($cn_status!=0) {
- echo $cn_status;
- exit;
- }
- $req=$_POST["req"];
- switch ($req) {
- case 'new':
- echo (draw_form());
- break;
- case 'list':
- echo (getList());
- break;
- case 'postform':
- echo(post_query($_POST["rssname"],$_POST["rssquery"]));
- break;
- case 'getrss':
- echo draw_rss($_POST["rssq"],$_POST["count"]);
- break;
- case 'getblock':
- echo draw_block($_POST["bname"]);
- break;
- case 'phpinfo':
- echo phpinfo();
- break;
- default:
- echo 'empty request';}
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement