Hack: Article Center Trashcan v0.1b

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
terry_b
Posts: 32
Joined: Wed 10. May 2006, 05:44

Hack: Article Center Trashcan v0.1b

Post by terry_b »

Article Center Trashcan v0.1b

*tested with v1.2.6 and v1.2.8*

This hack will allow you to have a list of deleted articles and article content parts under the article center box.

You will be able to:

- recover an article and its content parts from the trashcan (if you deleted the entire article)
- recover an article content parts
- or clean all the articles and content parts in one click
- enable/disable the trashcan in the config.inc.php
- allow only one admin to use the trashcan


This hack is in beta phase so please do a backup of your database and files before installing.

Here we go:

First part : edit the file include/inc_tmpl/article.structlist.tmpl.php

1) At line 30: (right after this // ----------------------------------------------------------------)

INSERT:

Code: Select all


function check_admn($dbcon) 
	{
		$sq_usr = "SELECT logged_user FROM ".DB_PREPEND."phpwcms_userlog WHERE logged_in=1";
		$result_usr = mysql_query($sq_usr);
		$check_usr = mysql_result($result_usr, "logged_user");
		return $check_usr;
	}

if(isset($_SESSION["wcs_user_admin"]) && $_SESSION["wcs_user_admin"] == 1) 
	{
		if (check_admn($db) == $phpwcms['admin_trashcan'] && $phpwcms['content_trashcan'] == "1") 
			{
				// Recover Article
				if ($_GET["recart"] == "1" && $_GET["artid"]) 
					{
						$sql = "UPDATE ".DB_PREPEND."phpwcms_article SET article_deleted=0".
							   " WHERE (article_uid=".$_SESSION["wcs_user_id"]." OR ".$_SESSION["wcs_user_admin"].")".
							   " AND article_id=".$_GET["artid"].";";
							   mysql_query($sql, $db) or die("error while receovering article");
								$ref = "http://" . $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'] . "?do=articles";
								headerRedirect($ref);
					}

				// Recover Article Content Part
				if ($_GET["recartct"] == "1" && $_GET["artctid"]) 
					{
						$sql = "UPDATE ".DB_PREPEND."phpwcms_articlecontent SET acontent_trash=0".
							   " WHERE (acontent_uid=".$_SESSION["wcs_user_id"]." OR ".$_SESSION["wcs_user_admin"].")".
							   " AND acontent_aid=".$_GET["artctid"].";";
							   mysql_query($sql, $db) or die("error while receovering article content part");
								$ref = "http://" . $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'] . "?do=articles";
								headerRedirect($ref);
					}

				// Delete Article
				if ($_GET["delart"] == "1" && $_GET["artid"]) 
					{
						$sql = "DELETE FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=9".
							   " AND(article_uid=".$_SESSION["wcs_user_id"]." OR ".$_SESSION["wcs_user_admin"].")".
							   " AND article_id=".$_GET["artid"].";";
							   mysql_query($sql, $db) or die("error while deleting article");
				
						$sqlcont = "DELETE FROM ".DB_PREPEND."phpwcms_articlecontent WHERE acontent_aid=".$_GET["artid"]. 
							   " AND(acontent_uid=".$_SESSION["wcs_user_id"]." OR ".$_SESSION["wcs_user_admin"].")";
							   mysql_query($sqlcont, $db) or die("error while deleting articles");
				
								$ref = "http://" . $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'] . "?do=articles";
								headerRedirect($ref);
					}

				// Delete Article Content Part
				if ($_GET["delartct"] == "1" && $_GET["artctid"]) 
					{
						$sql = "DELETE FROM ".DB_PREPEND."phpwcms_articlecontent WHERE acontent_trash=9".
							   " AND (acontent_id=".$_GET["artctid"].")";
							   mysql_query($sql, $db) or die("error while deleting article content part");
								$ref = "http://" . $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'] . "?do=articles";
								headerRedirect($ref);
					}				
				
				// Delete All Articles
				if ($_GET["delart"] == "2") 
					{
						$sql_art = "SELECT * FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=9";
						$result_article = mysql_query($sql_art);	
						$count_deleted_art = mysql_num_rows($result_article);
						$i=0;
						while ($i < $count_deleted_art) 
							{
								$art_id_array[$i]  = mysql_result($result_article,$i,"article_id");
								$i++;
							}
						$sql = "DELETE FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=9";
							   mysql_query($sql, $db) or die("error while deleting article");
				
						$i=0;
						while ($i < $count_deleted_art) 
							{
								$sqlcont = "DELETE FROM ".DB_PREPEND."phpwcms_articlecontent WHERE acontent_aid=".$art_id_array[$i]. "";
								mysql_query($sqlcont, $db) or die("error while deleting article");
								$i++;
							}
					
								$ref = "http://" . $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'] . "?do=articles";
								headerRedirect($ref);

					}

				// Delete All Article Content Part
				if ($_GET["delartct"] == "2") 
					{
						$sql = "DELETE FROM ".DB_PREPEND."phpwcms_articlecontent WHERE acontent_trash=9";
							   mysql_query($sql, $db) or die("error while deleting article content part");
								$ref = "http://" . $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'] . "?do=articles";
								headerRedirect($ref);
					}				
			}
	}

2) At the last line of the file:

INSERT:

Code: Select all

<? 
if(isset($_SESSION["wcs_user_admin"]) && $_SESSION["wcs_user_admin"] == 1) 
	{
		if (check_admn($db) == $phpwcms['admin_trashcan'] && $phpwcms['content_trashcan'] == "1") 
			{
				function get_category_parent($art_id)
					{
						$sq_art = "SELECT article_cid FROM ".DB_PREPEND."phpwcms_article WHERE article_id=" . $art_id;		
						$result_art = mysql_query($sq_art);	
						$art_cid = mysql_result($result_art,"article_cid");
						return get_article_parent($art_cid);
					}

				function get_article_parent($cat_id)
					{
						$acat_name = "Root";
						if (!$cat_id == "0") 
							{
								$sq_cat = "SELECT acat_name FROM ".DB_PREPEND."phpwcms_articlecat WHERE acat_id=" . $cat_id;		
								$result_categ = mysql_query($sq_cat);	
								$acat_name = mysql_result($result_categ,"acat_name");
							}
						return $acat_name;
					}
				
				function get_articlecont_parent($art_id)
					{
						$sq_art = "SELECT article_title FROM ".DB_PREPEND."phpwcms_article WHERE article_id=" . $art_id;		
						$result_art = mysql_query($sq_art);	
						$art_title = mysql_result($result_art,"article_title");
						return $art_title;
					}

				$fullurl = "http://" . $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
			
				// Show Deleted Articles
				$sql_art = "SELECT article_id, article_title, article_cid FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=9";
				$result_article = mysql_query($sql_art);	
				$count_deleted_art = mysql_num_rows($result_article);
				if ($count_deleted_art > "0") 
					{
						echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
						echo "  <tr style=\"background.color: #CCCCCC;\">\n";
						echo "    <td height=\"20\" valign=\"middle\" colspan=\"4\"><strong>Deleted Articles: </strong>" . $count_deleted_art . "</td>\n";
						echo "    <td align=\"right\" valign=\"middle\">\n";
						echo "	    <a href=\"$fullurl?do=articles&delart=2\" onclick=\"GP_popupConfirmMsg('clean all trashed articles?');return document.MM_returnValue\"><img src=\"img/button/trash_13x13_1.gif\" alt=\"Clean All Articles\" border=\"0\" />\n";
						echo "    </td>\n";
						echo "  </tr>\n";
						echo "  <tr>\n";
						echo "    <td height=\"20\" colspan=\"2\" width=\"70\" align=\"left\" valign=\"middle\"><strong>Art. ID</strong></td>";
						echo "    <td height=\"20\" width=\"250\" align=\"left\" valign=\"middle\"><strong>Article Title</strong></td>";
						echo "    <td height=\"20\" width=\"150\" align=\"left\" valign=\"middle\"><strong>Parent</strong></td>";
						echo "  </tr>\n";
						$i=0;
						while ($i < $count_deleted_art) 
							{
								$art_cid = mysql_result($result_article,$i,"article_cid");
								$art_id  = mysql_result($result_article,$i,"article_id");
								$art_ttl = mysql_result($result_article,$i,"article_title");
								$at = $art_ttl;
								echo "  <tr onMouseOver=\"this.bgColor='#CCFF00';\" onMouseOut=\"this.bgColor='#FFFFFF';\">\n";
								echo "    <td width=\"20\" align=\"center\" valign=\"middle\"><img src=\"img/symbole/text_1.gif\" alt=\"\" border=\"0\" /></td>\n";
								echo "    <td width=\"50\" align=\"left\" valign=\"middle\">[ID:" . $art_id . "]</td>\n";
								echo "    <td width=\"250\" align=\"left\" valign=\"middle\">" . $art_ttl . "</td>\n";
								if ($art_cid =="0") {$article_parent = "Root";} else {$article_parent = get_article_parent($art_cid);}
								echo "    <td>". $article_parent . "</td>\n";
								echo "    <td align=\"right\">\n";
								echo "      <a href=\"$fullurl?do=articles&recart=1&artid=". $art_id ."\" onclick=\"GP_popupConfirmMsg(' recover this article? \\n [".js_singlequote($at)."]');return document.MM_returnValue\"><img src=\"img/button/copy_11x11_0.gif\" alt=\"Recover [". $at ."]\" border=\"0\" /></a>\n";
								echo "      <a href=\"$fullurl?do=articles&delart=1&artid=". $art_id ."\" onclick=\"GP_popupConfirmMsg(' delete this article? \\n[".js_singlequote($at)."] ');return document.MM_returnValue\"><img src=\"img/button/trash_13x13_1.gif\" alt=\"Delete [". $at ."]\" border=\"0\" /></a>\n";
								echo "    </td>\n";
								echo "  </tr>\n";
								$i++;
							}
						echo "</table>\n";
						echo "<br \>\n";
					}
				
				// Show Deleted Articles Content Parts
				$sql_artcont = "SELECT acontent_id, acontent_title, acontent_type, acontent_aid FROM ".DB_PREPEND."phpwcms_articlecontent WHERE acontent_trash=9"; // Query for the deleted categories
				$result_artcont = mysql_query($sql_artcont);
				$count_deleted_artcont = mysql_num_rows($result_artcont);
				if ($count_deleted_artcont > "0") 
					{
						echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
						echo "  <tr style=\"background.color: #CCCCCC;\">\n";
						echo "    <td height=\"20\" valign=\"middle\" colspan=\"4\"><strong>Deleted Article Content Parts: </strong>" . $count_deleted_artcont . "</td>\n";;
						echo "    <td align=\"right\" valign=\"middle\">\n";
						echo "      <a href=\"$fullurl?do=articles&delartct=2\" onclick=\"GP_popupConfirmMsg('clean all trashed article content parts?');return document.MM_returnValue\"><img src=\"img/button/trash_13x13_1.gif\" alt=\"Clean All Articles CP\" border=\"0\" /></a>\n";
						echo "    </td>\n";
						echo "  </tr>\n";
						echo "  <tr>\n";
						echo "    <td height=\"20\" colspan=\"2\" width=\"70\" align=\"left\" valign=\"middle\"><strong>CP ID</strong></td>";
						echo "    <td height=\"20\" width=\"250\" align=\"left\" valign=\"middle\"><strong>Content Type (title)</strong></td>";
						echo "    <td height=\"20\" width=\"150\" align=\"left\" valign=\"middle\"><strong>Parent</strong></td>";
						echo "  </tr>\n";
						$i=0;
						while ($i < $count_deleted_artcont) 
							{
								$articlecont_aid  = mysql_result($result_artcont,$i,"acontent_aid");
								$articlecont_id  = mysql_result($result_artcont,$i,"acontent_id");
								$articlecont_title = mysql_result($result_artcont,$i,"acontent_title");
								$articlecont_type = mysql_result($result_artcont,$i,"acontent_type");
								if ($articlecont_title == "") {$articlecont_title = "no title";}
								$at = $GLOBALS["wcs_content_type"][$articlecont_type] . " - " . $articlecont_title;
								echo "  <tr onMouseOver=\"this.bgColor='#FFDE01';\" onMouseOut=\"this.bgColor='#FFFFFF';\">\n";
								echo "    <td width=\"20\" align=\"center\" valign=\"middle\"><img src=\"img/symbole/content_9x11.gif\" alt=\"\" border=\"0\" /></td>\n";
								echo "    <td width=\"50\" align=\"left\" valign=\"middle\">[ID:" . $articlecont_id . "]</td>\n";
								echo "    <td width=\"250\" align=\"left\" valign=\"middle\">" . $GLOBALS["wcs_content_type"][$articlecont_type] . "&nbsp;(" . $articlecont_title . ")</td>\n";
								if ($articlecont_aid =="0") {$articlecont_parent = "deleted";} else {$articlecont_parent = get_articlecont_parent($articlecont_aid);}
								echo "    <td width=\"150\" align=\"left\" valign=\"middle\">" . $articlecont_parent . " / " . get_category_parent($articlecont_aid) . "</td>\n";
								echo "    <td align=\"right\">\n";
								echo "      <a href=\"$fullurl?do=articles&recartct=1&artctid=". $articlecont_aid ."\" onclick=\"GP_popupConfirmMsg(' recover this article content part? \\n[".js_singlequote($at)."] ');return document.MM_returnValue\"><img src=\"img/button/copy_11x11_0.gif\" alt=\"Recover [". $at ."]\" border=\"0\" /></a>\n";
								echo "      <a href=\"$fullurl?do=articles&delartct=1&artctid=". $articlecont_id ."\" onclick=\"GP_popupConfirmMsg(' delete this content part? \\n[".js_singlequote($at)."] ');return document.MM_returnValue\"><img src=\"img/button/trash_13x13_1.gif\" alt=\"Delete [". $at ."]\" border=\"0\" />\n";
								echo "    </td>\n";
								echo "  </tr>\n";
								$i++;
							}
						echo "</table>\n";
						echo "<br \>\n";
					}
			}
	}
?>

Second part : edit the file config/phpwcms/config.inc.php

At the end of the file, add those lines:

Code: Select all

// values for the Article Center Trashcan ;
$phpwcms['content_trashcan']    = '1';         // Enable the Article Center Trashcan
$phpwcms['admin_trashcan']      = 'admin';    // The admin's username (for ea here: 'admin') allowed to see and use the Article Center Trashcan
... and that's it.

Now log in and go to the article center. You will see all the deleted elements.

Please report any bugs and/or suggestion.

I am not a pro in PHP as I am still learning so if you can enhance this hack, please do ;)

Enjoy!

Terry 8)
Last edited by terry_b on Wed 16. Aug 2006, 04:21, edited 8 times in total.
rushclub
Posts: 915
Joined: Tue 17. Feb 2004, 18:52

Post by rushclub »

nice ;)

rush
3 (!) Jahre warten reichen mir. Ich bin erst mal weg.
Ben
Posts: 558
Joined: Wed 14. Jan 2004, 08:05
Location: Atlanta
Contact:

Post by Ben »

Uh ... wow! That looks like a great addition, Terry. This might be something Oliver would want to implement. Great work!
terry_b
Posts: 32
Joined: Wed 10. May 2006, 05:44

Post by terry_b »

Thank you!

I had to take the categories trash function out due to the complexity of the categories.... but I'll be working on it for a next release of the hack I am developping.

Terry
User avatar
Oliver Georgi
Site Admin
Posts: 9889
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

Sorry, but there is no chance for implementation in this way at the moment. It's against the concept behind of marking an entry as deleted and having no option to remove such entry from db.

This might be an option for a coming release having better permissions and a superuser mode.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
terry_b
Posts: 32
Joined: Wed 10. May 2006, 05:44

Post by terry_b »

Sorry, but there is no chance for implementation in this way at the moment. It's against the concept behind of marking an entry as deleted and having no option to remove such entry from db.

This might be an option for a coming release having better permissions and a superuser mode.

Oliver
Hello Oliver,

I don't think it's against the concept you are describing.

I set 2 new values in the confing.inc.php:

1) to enable the trashcan
2) to design which admin as the superuser mode so only one admin will be allowed to see and delete the articles/content part.

Isn't it the opposite of what you described to be against?

Cheers,

Terry
User avatar
Oliver Georgi
Site Admin
Posts: 9889
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

Terry, you are right - but sorry again - no chance to see it in the system in this way. It is still against the concept of "delete" inside of phpwcms.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
phalancs
Posts: 793
Joined: Thu 19. Feb 2004, 05:09
Location: Germany

interesting

Post by phalancs »

Hi this is an interestign thing. :) thanx for your work
2008
Post Reply