<? /* update_xml.php * Purpose: To update your database repository with the latest * mudmagic xml files */ include_once( dirname(__FILE__)."/include/config.php"); //very simple access control check to prevent folks from hurting //the poor mudmagic server and your own server. Make sure to change //the values in config.php with your own admin useraname and password //You can delete these next two ifchecks if you make sure this file is //put somewhere in a secured place and accessible only to you. =) if( empty( $_POST ) ) { echo "Input user name: <form method='POST'> <input type=text name=form_username value='username'><br> <input type=password name=form_passwd><br> <input type=submit value='Submit'></form>"; exit(); } if( !empty( $_POST ) ) { if( !array_key_exists( "form_username", $_POST ) || !array_key_exists( "form_passwd", $_POST ) ) exit(); if( $_POST["form_username"] != $admin_username || $_POST["form_passwd"] != $admin_passwd ) { echo "erugh?"; exit(); } } //initialize MagPIE - this file uses MagPIE's functions //the sole purpose of this file is to update your database by downloading //the most recent xml files for a directory and all subdirectories. You can //create your own updater system/database. This is just to show how to recurse //through the XML feeds mudmagic provides to get your data and directories //If you grab a top directory such as diku/ this could take awhile to grab all //subdirectory files based on your internet speed. Set the following timeout //as appropriate set_time_limit(400); init(); // the mudmagic_url variable is stored in config.php $remote_url = $mudmagic_url."/$first_catid"; $file_data = _fetch_remote_file( $remote_url ); if ( !is_success( $file_data->status ) ) { //no data at top directory - bail echo "Unable to parse remote url file for xml info: $directory_url"; } //We now have the Top directory RSS feed object. First save the file to our //database directory - then look for any subcategories and grab that data //as well. Continue this till the loop is completed. The $first_catid variable //is stored in config.php save_to_database( $file_data->results, $first_catid ); echo "Saved: $remote_url<br>"; //grab all subcategories in one swoop - saved in a '|' seperated list $subcat_list = get_subcats( $file_data, $first_catid ); if( !empty( $subcat_list ) ) { $subcat_arr = explode( "|", $subcat_list ); foreach( $subcat_arr as $category_id ) { if( !empty( $category_id ) ) { $remote_url = $mudmagic_url."/$category_id"; $file_data = _fetch_remote_file( $remote_url ); if ( is_success( $file_data->status ) ) { save_to_database( $file_data->results , $category_id ); echo "Saved: $remote_url<br>"; } } } } //Should be done: /* Below are functions specific to this update file */ function get_subcats( $rss_object, $cat_id ) { global $mudmagic_url; //pretty simple - use the MagPie functionality to parse our RSS //page and look for any SubCatId values. If we find them, return //a '|' dillemeted list containing them $out_list = ""; $rss = _response_to_rss( $rss_object ); foreach( $rss->items as $tag ) { if( !empty( $tag["subcatid"] ) ) { $next_cat_id = $tag["subcatid"]; //loop back till done $remote_url = $mudmagic_url."/$next_cat_id"; $next_rss_object = _fetch_remote_file( $remote_url ); if ( is_success( $next_rss_object->status ) ) { $out_list .= get_subcats( $next_rss_object, $next_cat_id ); } usleep(4); } } $out_list .= "$cat_id|"; return( $out_list ); } /*=======================================================================*\ Function: save_to_database: Purpose: a wrapper to save an XML page to a location. in this case to a directory. You could loop through the the rss page and save it to a database if desired Input: the XML page && category id Output: TRUE on success save FALSE if not \*=======================================================================*/ function save_to_database( $rss_page, $category_id ) { global $database_dir; if( empty( $rss_page ) || empty( $category_id ) ) return FALSE; $file_to_save = $database_dir."/$category_id"; //add a .xml to the end of the file name $file_to_save .= ".xml"; $fp = fopen( $file_to_save, "w" ); if( !$fp ) { echo "Can't open file [ $file_to_save ] for saving! did you <b>chmod 777 $database_dir ?</b><br>"; return FALSE; } fputs( $fp, $rss_page ); fclose($fp); return TRUE; } ?>