// ---------------------------------------------------------------------------------- // Check to make sure directory permissions are correct @set_time_limit(0); $configfile = "articles.xml"; $updateurl = "http://www.contentspooling.net/update.php?w=".$_SERVER['HTTP_HOST']; $articleurl = "http://www.contentspooling.net/update.php?did="; if (!file_exists($configfile)){ $fp = @fopen($configfile, "w+"); if (!$fp){ $perms_error = true; } else { if (@fwrite($fp, "temp") === FALSE){ $perms_error = true; } } } if ($perms_error){ echo "

Permissions Error:
Your directory cannot be written to. Please ensure the permissions are set to 755 or 777.

"; } else { // open config information $fp = @fopen($configfile, "r+"); if ($fp){ $configxml = @fread($fp, filesize($configfile)); @fclose($fp); } // ------------------------------------ // update if ($configxml == "temp" || $_GET['update']){ echo "

Updating, please wait...

"; echo '
'; flush(); $fp = @fopen($updateurl, "r"); $updatexml = ""; if ($fp){ while (!feof($fp)){ $updatexml .= @fread($fp, 8192); } @fclose($fp); } else { $updatexml = curl_get_file($updateurl); } if ($updatexml){ $fp = @fopen($configfile, "w+"); fwrite($fp, $updatexml); fclose($fp); $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parse_into_struct($parser, $updatexml, $values, $tags); xml_parser_free($parser); if (!$tags['error']){ // ------------------------------------ // preferences $preferences = array(); foreach ($tags['preferences'] as $key=>$val){ if ($values[$val+1]['type'] == "complete"){ $pref_name = $values[$val+1]['tag']; $pref_value = $values[$val+1]['value']; $preferences[$pref_name] = $pref_value; }} $topics = split(",", $preferences['topics']); if ($topics[0]){ foreach ($topics as $key=>$val){ $topics[$key] = trim($val); } asort($topics); $preferences['topics'] = $topics; } $index_format = split(",", $preferences['index_format']); if ($index_format[0]){ foreach ($index_format as $key=>$val){ $index_format[$key] = trim($val); } $preferences['index_format'] = $index_format; } // ------------------------------------ // articles $articles = array(); $filenames = array(); if ($tags['article']){ foreach ($tags['article'] as $key=>$val){ if ($values[$val]['type'] == "open"){ $last_did = $values[$val]['attributes']['did']; $articles[$last_did] = array('articleid'=>$values[$val]['attributes']['id']); } elseif ($values[$val]['type'] == "cdata"){ if ($values[$val-1]['tag'] == "filename"){ $filenames[] = $values[$val-1]['value']; } if ($values[$val-1]['tag'] == "topics"){ $article_topics = $values[$val-1]['value']; $article_topics = split(",", $article_topics); if ($article_topics[0]){ foreach ($article_topics as $key=>$val){ $article_topics[$key] = trim($val); } asort($article_topics); $articles[$last_did]['topics'] = $article_topics; } } else { $articles[$last_did][$values[$val-1]['tag']] = $values[$val-1]['value']; } } } foreach ($articles as $did=>$article){ // if file doesn't exist or update==2, download and create article file if (!file_exists($article['filename']) || $_GET['update'] == 2){ $fp = @fopen($articleurl.$did, r); $articlehtml = ""; if ($fp){ while (!feof($fp)){ $articlehtml .= @fread($fp, 8192); } @fclose($fp); } else { $articlehtml = curl_get_file($articleurl.$did); } if ($articlehtml){ $fp = @fopen($article['filename'], "w+"); @fwrite($fp, $articlehtml); @fclose($fp); @chmod($article['filename'], 0644); } } // delete any articles that exist but aren't in the xmlfile $dh = @opendir("./"); while (($file = readdir($dh)) !== false){ if (is_numeric(substr($file, 0, 1))){ if (!in_array($file, $filenames)){ @unlink($file); } } } } } } // end if no errors // remove updating div echo ''; } // end if xml downloaded ok } else { $fp = fopen($configfile, "r"); if ($fp){ $updatexml = fread($fp, filesize($configfile)); fclose($fp); } } // end if update required if (!strlen($updatexml)){ echo "

Update Error:
Your website could not be updated. Please try again later."; } // ------------------------------------ if ($updatexml && $updatexml <> "temp"){ // load xml $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parse_into_struct($parser, $updatexml, $values, $tags); xml_parser_free($parser); if ($tags['error']){ $error_message = $values[$tags['error'][0]+1]['value']; echo "

Update Error:
".$error_message." (ERROR #".$values[$tags['error'][0]]['attributes']['id'].")

"; } else { // ------------------------------------ // preferences $preferences = array(); foreach ($tags['preferences'] as $key=>$val){ if ($values[$val+1]['type'] == "complete"){ $pref_name = $values[$val+1]['tag']; $pref_value = $values[$val+1]['value']; $preferences[$pref_name] = $pref_value; }} $topics = split(",", $preferences['topics']); if ($topics[0]){ foreach ($topics as $key=>$val){ $topics[$key] = trim($val); } asort($topics); $preferences['topics'] = $topics; } $index_format = split(",", $preferences['index_format']); if ($index_format[0]){ foreach ($index_format as $key=>$val){ $index_format[$key] = trim($val); } $preferences['index_format'] = $index_format; } if (!$_GET['c']){ // ------------------------------------ // category listing echo '
'; echo ''; $i = 0; $split = round(count($topics) / 3, 0) + 1; foreach ($topics as $topic){ $i++; if ($i == 1){ echo ""; } } if ($i <> 0){ echo ""; } echo '
"; } echo "

".$topic."

"; if ($i == $split){ $i = 0; echo "

'; echo '
'; } else { // ------------------------------------ // article listing (per category) $topic = urldecode($_GET['c']); $articles = array(); $articles_sorted = array(); $articles_index = array(); if ($tags['article']){ foreach ($tags['article'] as $key=>$val){ if ($values[$val]['type'] == "open"){ $last_did = $values[$val]['attributes']['did']; $articles[$last_did] = array('articleid'=>$values[$val]['attributes']['id']); } elseif ($values[$val]['type'] == "cdata"){ if ($values[$val-1]['tag'] == "filename"){ $filenames[] = $values[$val-1]['value']; } if ($values[$val-1]['tag'] == "topics"){ $article_topics = $values[$val-1]['value']; $article_topics = split(",", $article_topics); if ($article_topics[0]){ foreach ($article_topics as $key=>$val){ $article_topics[$key] = trim($val); } asort($article_topics); $articles[$last_did]['topics'] = $article_topics; } } else { $articles[$last_did][$values[$val-1]['tag']] = $values[$val-1]['value']; } } } foreach ($articles as $did=>$article){ // match categories if (!in_array($topic, $article['topics'])){ unset($articles[$did]); } else { if ($preferences['index_sort'] == "Most Recent First" || $preferences['index_sort'] == "Oldest First"){ $articles_sorted[$did] = $article['date_added']; } elseif ($preferences['index_sort'] == "Title A-Z" || $preferences['index_sort'] == "Title Z-A"){ $articles_sorted[$did] = $article['title']; } } } } $total_results = count($articles_sorted); if ($total_results){ // sort results if ($preferences['index_sort'] == "Most Recent First" || $preferences['index_sort'] == "Title Z-A"){ arsort($articles_sorted); } elseif ($preferences['index_sort'] == "Oldest First" || $preferences['index_sort'] == "Title A-Z"){ asort($articles_sorted); } foreach ($articles_sorted as $did=>$sortval){ $articles_index[] = $did; } } if (!$_GET['start']){ $start = 0; } else { $start = $_GET['start']; } $limit = $preferences['articles_per_page']; if ($preferences['text_view_categories']){ $text_view_categories = $preferences['text_view_categories']; } else { $text_view_categories = "View Categories"; } echo '
'; echo ''; echo ""; echo ''; echo '

".$topic."

'.$text_view_categories.'
'; if ($start + $limit > $total_results){ $end = $total_results; } else { $end = $start + $limit; } if ($total_results){ if ($total_results > $limit){ echo '

Showing '.($start+1).' - '.$end.' of '.$total_results.' articles.

'; } $i = $start; while ($i < $end){ $article = $articles[$articles_index[$i]]; echo '

'.$article['title'].''; if (in_array("Author", $preferences['index_format'])){ echo '
by '.$article['author']; } if (in_array("Date Added", $preferences['index_format'])){ if (in_array("Author", $preferences['index_format'])){ echo ", "; } else { echo "
"; } echo $article['date']; } if (in_array("Article Summary", $preferences['index_format'])){ echo '
'.$article['summary']; } echo '

'; $i++; } // page nav if ($total_results > $limit){ $query_string = "c=".$_GET['c']; echo ''; echo '
'; if ($start - $limit >= 0){ echo 'Prev  '; } $curr_page = $start / $limit + 1; if ($curr_page == 0){ $curr_page = 1; } $total_pages = $total_results / $limit; if (substr_count($total_pages, ".")){ $total_pages = $total_pages + 1; $pos = strpos($total_pages, "."); $total_pages = substr($total_pages, 0, $pos); } $next_pages = array(); $i = $curr_page + 1; while ($i < ($curr_page+10) && $i <= $total_pages){ $next_pages[] = $i; $i++; } $prev_pages = array(); $i = $curr_page - 1; while ($i > ($curr_page-10) && $i >= 1){ $prev_pages[] = $i; $i--; } asort($prev_pages); echo '
'; foreach($prev_pages as $pagenum){ echo ''; echo $pagenum; echo '  '; } echo ''.$curr_page.'  '; foreach($next_pages as $pagenum){ echo ''.$pagenum.'  '; } echo '
'; if ($start + $limit < $total_results){ echo 'Next'; } echo '
'; } } else { if ($preferences['text_no_articles']){ $text_no_articles = $preferences['text_no_articles']; } else { $text_no_articles = "There are no articles available for this category."; } echo "

".$text_no_articles."

"; } echo '
'; } // end if category or article listing } // end if no xml error } // end if there is xml to parse } // end if no permission error // ---------------------------------------------------------------------------------- function curl_get_file($url){ // ---------------------------------------------------------------------------------- $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HEADER, 0); ob_start(); curl_exec ($ch); curl_close ($ch); $string = ob_get_contents(); ob_end_clean(); return $string; } // ---------------------------------------------------------------------------------- // <-- END OF DO NOT MODIFY SECTION // ---------------------------------------------------------------------------------- ?>