Topic: [HACK] Un-Archive hack for cutenews
Name: Un-Archive news
Author: FI-DD
CuteNews Compatibility: 1.3.6 - 1.4.0 (Higher versions have this option)
Description: take your news from the archive and make them active again.
Instructions:
Installation
1. Open massactions.mdu and find this at the end of the file:
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~
If No Action Is Chosen
~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
and add above:
/* ~~~~~~~~~~~~~~~~~~
Mass UN-Archive
~~~~~~~~~~~~~~~~~~~ */
elseif($action == "mass_unarchive"){
if(!$selected_news){ msg("error", "Error", "You have not specified any articles", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
if($source == ""){ msg("error", "Error", "That news is not in an archive", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
echoheader("options", "Un-Archive");
echo "<form method=post action=\"$PHP_SELF\"><table border=0 cellpadding=0 cellspacing=0 width=100% height=100%><tr><td >
Do you really want to un-archive the ([b]".count($selected_news)."[/b]) chosen articles?
<input type=button value=\" No \" onclick=\"java script:document.location='$PHP_SELF?mod=editnews&action=list&source=$source'\"> <input type=submit value=\" Yes \">
<input type=hidden name=source value=\"$source\">
<input type=hidden name=action value=\"do_mass_unarchive\">
<input type=hidden name=mod value=\"massactions\">";
foreach($selected_news as $null => $newsid){
echo"<input type=hidden name=selected_news[] value=\"$newsid\">\n";
}
echo"</td></tr></table></form>";
echofooter();
exit;
}
/* ~~~~~~~~~~~~~~~~~~~~~~
DO Mass UN-Archive
~~~~~~~~~~~~~~~~~~~~~~~ */
elseif($action == "do_mass_unarchive"){
if(!$selected_news){ msg("error", "Error", "You have not specified any articles", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
if($source == ""){ msg("error", "Error", "That news is not in an archive", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
$moved_articles = 0;
// build news
$arch_file = "./data/archives/$source.news.arch";
$news_file = "./data/news.txt";
$write_news = "";
$write_arch = "";
$old_arch = file("$arch_file");
foreach($old_arch as $null => $old_arch_line){
$old_arch_arr = explode("|", $old_arch_line);
if(in_array($old_arch_arr[0], $selected_news)){
$write_news = str_replace("\n", "", $old_arch_line)."\n".$write_news;
$write_arch = $write_arch;
$moved_articles ++;
} else {
$write_news = $write_news;
$write_arch = str_replace("\n", "", $old_arch_line)."\n".$write_arch;
}
}
$old_news = file("$news_file");
foreach($old_news as $null => $old_news_line){
$write_news = str_replace("\n", "", $old_news_line)."\n".$write_news;
}
// write news
$news_db = fopen("$news_file", "wb");
$news_sorted = explode("\n", $write_news); rsort($news_sorted); reset($news_sorted);
foreach ($news_sorted as $null => $line){ fwrite($news_db, "$line"); if ($line != "") { fwrite($news_db, "\n"); } }
fclose($news_db);
$arch_db = fopen("$arch_file", "wb");
$arch_sorted = explode("\n", $write_arch); rsort($arch_sorted); reset($arch_sorted);
foreach ($arch_sorted as $null => $line){ fwrite($arch_db, "$line"); if ($line != "") { fwrite($arch_db, "\n"); } }
fclose($arch_db);
// build comments
$arch_file = "./data/archives/$source.comments.arch";
$news_file = "./data/comments.txt";
$write_news = "";
$write_arch = "";
$old_arch = file("$arch_file");
foreach($old_arch as $null => $old_arch_line){
$old_arch_arr = explode("|>|", $old_arch_line);
if(in_array($old_arch_arr[0], $selected_news)){
$write_news = str_replace("\n", "", $old_arch_line)."\n".$write_news;
$write_arch = $write_arch;
} else {
$write_news = $write_news;
$write_arch = str_replace("\n", "", $old_arch_line)."\n".$write_arch;
}
}
$old_news = file("$news_file");
foreach($old_news as $null => $old_news_line){
$write_news = str_replace("\n", "", $old_news_line)."\n".$write_news;
}
// write comments
$news_db = fopen("$news_file", "wb");
$news_sorted = explode("\n", $write_news); rsort($news_sorted); reset($news_sorted);
foreach ($news_sorted as $null => $line){ fwrite($news_db, "$line"); if ($line != "") { fwrite($news_db, "\n"); } }
fclose($news_db);
$arch_db = fopen("$arch_file", "wb");
$arch_sorted = explode("\n", $write_arch); rsort($arch_sorted); reset($arch_sorted);
foreach ($arch_sorted as $null => $line){ fwrite($arch_db, "$line"); if ($line != "") { fwrite($arch_db, "\n"); } }
fclose($arch_db);
//delete the archive when empty
$arch_file = "./data/archives/$source.news.arch";
$arch_db_new = file("$arch_file");
if (!$arch_db_new[0]) {
if(!$handle = opendir("./data/archives")){ die("<center>Can not open directory $cutepath/data/archive "); }
while (false !== ($file = readdir($handle))){
if($file == "$source.news.arch" or $file == "$source.comments.arch"){
unlink("./data/archives/$file");
}
}
closedir($handle);
}
if(count($selected_news) == $moved_articles){ msg("info", "News Moved", "All articles that you selected ($moved_articles) were moved successfully to your active news.", "$PHP_SELF?mod=editnews&action=list"); }
else{ msg("error", "News Moved (with errors)", "$moved_articles of ".count($selected_news)." articles that you selected were moved successfully", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
}
2. Open editnews.mdu and find this:
if($member_db[1] == 1){ echo"<option title=\"make new archive with all selected news\" value=\"mass_archive\">Send to Archive</option>"; }
and replace with this:
if ($member_db[1] == 1) {
if($source == ""){ echo "<option title=\"make new archive with all selected news\" value=\"mass_archive\">Send to Archive</option>"; }
else { echo "<option title=\"bring selected back from archive\" value=\"mass_unarchive\">Un-Archive</option>"; }
}