Advertisement
terorama

rssloader / upload3.php

Aug 21st, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.56 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5.  
  6.    require "db.inc.php";
  7.    //require "funcs.inc.php";
  8.    
  9.    
  10. //----------------------------------     
  11.      
  12. function draw_form() {
  13.    $f_draw=<<<LABEL
  14.    
  15.    <form name="goo" onsubmit="send_form(this);return false;" method="post" enctype="application/x-www-form-urlencoded">
  16.    <fieldset>
  17.       <legend>Input RSS Name and address below</legend>
  18.       <p> <label for="rssname">RSS Name</label><input type="text" name="rssname" size="40"></p>
  19.       <p> <label for="rssquey">RSS Query</label><input type="text" name="rssquery" size="40"></p>
  20.       <p> <input type="submit" name="subm" value="Submit"></p>   
  21.       </fieldset>
  22.    </form>
  23.    
  24. LABEL;
  25.  
  26. return $f_draw;
  27. }
  28.  
  29. //----------------------------------------
  30. function drawList($items) {
  31.    $rez="<ul>";
  32.    foreach ($items as $item) {
  33.       $rez.='<li>';
  34.      
  35.       //$rez.='<a href="#" onclick="ajax_request(\'req=getrss&rssq='.$item[2].'\',\'detail\');return false;">'.$item[1].'</a>';
  36.      
  37.       //$rez.='<a href="#" onclick="get_rss(\''.$item[1].'\',5,\'detail\');return false;">'.$item[1].'</a>';
  38.       $rez.='<a href="#" onclick="get_block(\''.$item[1].'\',\'detail\');return false;">'.$item[1].'</a>';
  39.      
  40.       $rez.='</li>';
  41.    }
  42.    $rez.="</ul>";
  43.    
  44.    //$rez='<pre>'.print_r($items).'</pre>';
  45.    return $rez;
  46. }
  47.  
  48. //----------------------------------------
  49. function getlist() {
  50.  
  51.    //require "db.inc.php";
  52.    $rez = "<div id='querylist'><h3>Query list</h3>";
  53.    
  54.    $items=getQuery('select * from gqueries order by id desc');
  55.    if (is_string($items)) {
  56.       return 'error: '.$items;
  57.       }
  58.    $rez.=drawList($items);
  59.    //$rez.='<pre>'.print_r($items).'</pre>';
  60.    
  61.    $rez.=$items."</div>";
  62.    return $rez;
  63. }
  64.  
  65. //----------------------------------------
  66. function post_query($rssname,$rssquery) {
  67.  
  68.    $rez=insertQuery('insert into gqueries(%fields%) values(%values%)',
  69.       array('name','http_query'),array('\''.$rssname.'\'','\''.addslashes($rssquery).'\''));
  70.      
  71.    return $rez;
  72.  
  73. }        
  74.  
  75. //---------------------------------------------------
  76. function draw_block($blockname) {
  77.  
  78.    $blockquery=getSingle("select http_query from gqueries where name='$blockname'");
  79.    //echo $blockquery;
  80.    $rez=file_get_contents($blockquery);
  81.    return $rez;
  82. }        
  83. //---------------------------------------------------
  84. function draw_rss($rssname,$count) {
  85.  
  86.    $rssquery=getSingle("select http_query from gqueries where name='$rssname'");
  87.    //$rez=$rssquery;
  88.    //return $rez;
  89.    $ver=1;
  90.  
  91.    $rez='';
  92.    $xml=simplexml_load_file($rssquery);
  93.    $i=1;
  94.    foreach ($xml->children() as $a=>$b) {
  95.       if ($a=='channel') {
  96.          $ver=2;
  97.       }
  98.    }
  99.    
  100.    if ($ver==1) {
  101.        //------------------------------Atom format  
  102.        foreach ($xml->entry as $item) {
  103.          $title=$item->title;
  104.          $content=$item->content;
  105.          $link=$item->link;
  106.          $published=$item->published;
  107.      
  108.          $rez.= <<<RSS
  109.             <div class="rsscontent">
  110.             <h3><a href="$link">$title<a></h3>
  111.             <p>$content</p>
  112.             <p class="rssdate">$published</p>
  113.             </div>
  114.             <div class="rsssplit"></div>
  115.            
  116. RSS;
  117.          $i++;
  118.          if ($i>$count)
  119.             break;
  120.         }
  121.         }
  122.         //----------------------------------RSS 2.0 format
  123.     else
  124.        {//return '<pre>'.print_r($xml->channel->item->title).'</pre>';
  125.        foreach ($xml->channel->item as $item) {
  126.        
  127.           /*foreach ($item->children() as $a=>$b) {
  128.              $rez.=$a.'='.$b.'<br>';
  129.           }}*/
  130.           $title=$item->title;
  131.           $description=$item->description;
  132.           $link=$item->link;
  133.           $pubDate=$item->pubDate;
  134.          
  135.           $rez.= <<<RSS
  136.           <div class="rsscontent">
  137.           <h3><a href="$link">$title</a></h3>
  138.           <p>$description</p>
  139.           <p class="rssdate">$pubDate</p>
  140.           </div>
  141.           <div class="rsssplit"></div>
  142. RSS;
  143.           $i++;
  144.           if ($i>$count)
  145.              break;
  146.           }
  147.        }
  148.  
  149.    return $rez;
  150. }
  151.  
  152.          
  153. //---------------------------------------------------
  154. //---------------------------------------------------
  155. $cn_status=conn();
  156. if ($cn_status!=0) {
  157.    echo $cn_status;
  158.    exit;
  159. }
  160.  
  161. $req=$_POST["req"];
  162.  
  163. switch ($req) {
  164.    case 'new':
  165.       echo (draw_form());
  166.       break;
  167.    case 'list':
  168.       echo (getList());
  169.       break;
  170.      
  171.    case 'postform':
  172.       echo(post_query($_POST["rssname"],$_POST["rssquery"]));      
  173.       break;
  174.      
  175.    case 'getrss':
  176.       echo draw_rss($_POST["rssq"],$_POST["count"]);
  177.       break;
  178.      
  179.    case 'getblock':
  180.       echo draw_block($_POST["bname"]);
  181.       break;
  182.      
  183.    case 'phpinfo':
  184.       echo phpinfo();
  185.       break;      
  186.          
  187.      
  188.    default:
  189.       echo 'empty request';}
  190.      
  191.  
  192.  
  193.  
  194. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement