Guest User

Untitled

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