Guest User

Untitled

a guest
Apr 7th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.51 KB | None | 0 0
  1. <? class Stats_news{
  2.  
  3.  function __construct(){
  4.   add_action("admin_menu",array(&$this,"add_menus"));
  5.  }
  6.  
  7.  function add_menus(){
  8.   add_submenu_page("options-general.php","Stats news","Stats news","administrator","stats_news",array(&$this,"create_menu"));
  9.  }
  10.  
  11.  function create_menu(){
  12.   ?>
  13.   <div class="wrap">
  14.    <h2>Stats news</h2><br/>
  15.    <form method="post" action="">
  16.     <ul style='list-style-type:none;'>
  17.      <li><input type="hidden" name="data_posted" value="update_news_posted" /></li>
  18.      <li><p class="submit"><input type="submit" class="button-primary" value="Update news" name="update_news" /></li>
  19.     </ul>
  20.    </form><br/>
  21.  
  22.   <?php
  23.  
  24.   if(isset($_POST["data_posted"])){
  25.    switch($_POST["data_posted"]){
  26.     case "update_news_posted":
  27.      $this->update_news_posted();
  28.      break;
  29.      
  30.     case "add_news_posted":
  31.      $this->add_news_posted($_POST["news_headline"]);
  32.      break;
  33.    }
  34.   }
  35.  
  36.   ?>
  37.   </div>
  38.   <?php
  39.   $this->print_news();
  40.  }
  41.  
  42.  function update_news_posted(){
  43.   set_time_limit(3600);
  44.   $dir=dirname(__FILE__);
  45.   $local_file=fopen($dir."/news.xml","w");
  46.   $server_file="demo/CFB_STORY$20111106142743765857508.XML";
  47.   $ftp_user="admin";
  48.   $ftp_pass="pass";
  49.   $ftp_server="ftp.stats.com";
  50.   $conn_id=ftp_connect($ftp_server) or die("Could not connect");
  51.   $login_result=ftp_login($conn_id,$ftp_user,$ftp_pass) or die("Could not login");
  52.  
  53.   $res=ftp_fget($conn_id,$local_file,$server_file,FTP_BINARY);
  54.   //var_dump($res);
  55.    
  56.   fclose($local_file);
  57.   ftp_close($conn_id);
  58.  }
  59.  
  60.  function print_news(){
  61.   $plugin_path=plugins_url()."/".basename(dirname(__FILE__));
  62.   $file=$plugin_path."/news.xml";
  63.   $xml=simplexml_load_file($file);
  64.    
  65. foreach($xml->{sports-news-stories}->{news-stories}->{news-story} as $story){
  66.    $str.="<form method='post' action=''>";
  67.    $str.="<ul style='list-style-type:none;'>";
  68.    $str.="<li>{$story->header['headline']}</li>";
  69.    $str.="<li><input type='hidden' name='news_headline' value='{$story->header['headline']}' /></li>";
  70.    $str.="<li><input type='hidden' name='data_posted' value='add_news_posted' /></li>";
  71.    $str.="<li><p class='submit'><input type='submit' class='button-primary' value='Add news' name='add_news' /></li>";
  72.    $str.="</ul>";
  73.    $str.="</form>";
  74.    $str.="<hr/>";
  75.   }
  76.    
  77.   echo $str;
  78. print_r($story);
  79.  }
  80.  
  81.  function add_news_posted($news_headline){
  82.   $args=array(
  83.    "post_title"=>$news_headline,
  84.    "post_name"=>$news_headline
  85.   );
  86.  
  87.   wp_insert_post($args);
  88.  }
  89. }
  90.  
  91. $sn=& new Stats_news();
Add Comment
Please, Sign In to add comment