Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Stats_news{
- function __construct(){
- add_action("admin_menu",array(&$this,"add_menus"));
- }
- function add_menus(){
- add_submenu_page("options-general.php","Stats news","Stats news","administrator","stats_news",array(&$this,"create_menu"));
- }
- function create_menu(){
- ?>
- <div class="wrap">
- <h2>Stats news</h2><br/>
- <form method="post" action="">
- <ul style='list-style-type:none;'>
- <li><input type="hidden" name="data_posted" value="update_news_posted" /></li>
- <li><p class="submit"><input type="submit" class="button-primary" value="Update news" name="update_news" /></li>
- </ul>
- </form><br/>
- <?php
- if(isset($_POST["data_posted"])){
- switch($_POST["data_posted"]){
- case "update_news_posted":
- $this->update_news_posted();
- break;
- case "add_news_posted":
- $this->add_news_posted($_POST["news_headline"]);
- break;
- }
- }
- ?>
- </div>
- <?php
- $this->print_news();
- }
- function update_news_posted(){
- set_time_limit(3600);
- $dir=dirname(__FILE__);
- $local_file=fopen($dir."/news.xml","w");
- $server_file="demo/CFB_STORY$20111106142743765857508.XML";
- $ftp_user="general";
- $ftp_pass="g3n3ral";
- $ftp_server="ftp.stats.com";
- $conn_id=ftp_connect($ftp_server) or die("Could not connect");
- $login_result=ftp_login($conn_id,$ftp_user,$ftp_pass) or die("Could not login");
- $res=ftp_fget($conn_id,$local_file,$server_file,FTP_BINARY);
- //var_dump($res);
- fclose($local_file);
- ftp_close($conn_id);
- }
- function print_news(){
- $plugin_path=plugins_url()."/".basename(dirname(__FILE__));
- $file=$plugin_path."/news.xml";
- $xml=simplexml_load_file($file);
- foreach($xml->{sports-news-stories}->{news-stories}->{news-story} as $story){
- $str.="<form method='post' action=''>";
- $str.="<ul style='list-style-type:none;'>";
- $str.="<li>{$story->header['headline']}</li>";
- $str.="<li><input type='hidden' name='news_headline' value='{$story->header['headline']}' /></li>";
- $str.="<li><input type='hidden' name='data_posted' value='add_news_posted' /></li>";
- $str.="<li><p class='submit'><input type='submit' class='button-primary' value='Add news' name='add_news' /></li>";
- $str.="</ul>";
- $str.="</form>";
- $str.="<hr/>";
- }
- echo $str;
- print_r($story);
- }
- function add_news_posted($news_headline){
- $args=array(
- "post_title"=>$news_headline,
- "post_name"=>$news_headline
- );
- wp_insert_post($args);
- }
- }
- $sn=& new Stats_news();
Add Comment
Please, Sign In to add comment