View Full Version : Cross Links list in Admin panel
Bryan Ex
12-04-2006, 08:05 PM
Okay... so your shiny new directory is really starting to take off. You have 100+ categories and you are approaching 1,000 link listings in your database. In your admin panel it shows you have 957 active links but you know 6 of those are cross links. How the heck can you find them to review or delete without having to spend hours browsing each and every category looking for the @ symbol?
What I'm trying to add to my Pro 1.2 is a menu item just like featured, non-reciprocal, banned, etc only one that will list all (and only) cross links. This list would only need to display the cross link, the category the cross link is in, and a button to delete it. Being able to move it would be nice but I have a feeling that would be far more complicated.
I thought I could do this with some trial and error coding based on both the List Reciprocal Links and Report Broken Link mods but both use fields in the links table where as cross links are indexed in link_categories and I'm at a loss on how to produce a cross-link.php file that will list all cross links.
So far I have add to includes/admin_menu.ic.php
$mnuLink['cross']['caption'] = 'cross links';
$mnuLink['cross']['url'] = 'cross-links.php';
To admin/index.php I have added
echo '<tr>';
echo "<td><a href=\"cross-links.php\">cross links</a>:</td>";
$crossed = $gAdminDb->getNumCrossLinks();
echo "<td align=\"right\"><strong>{$crossed}</strong></td>";
echo '</tr>';
... and to classes/DirAdmin.php I have added
/**
* Returns number of cross links
*
* @return int
*/
function getNumCrossLinks()
{
$sql = "SELECT COUNT(`id_link`) ";
$sql .= "FROM `{$this->mPrefix}link_categories` ";
$sql .= "WHERE `crossed` = '1' ";
return $this->mDb->getOne($sql);
}
/**
* Returns links that are cross links
*
* @param int $aStart starting position
* @param int $aLimit number of links to be returned
*
* @return arr
*/
function getCrossLinks($aStart = 0, $aLimit = 0)
{
$cause = "WHERE `crossed` = '1' ";
return $this->getLinksBy($aStart, $aLimit, $cause);
}
This much gives me a cross link menu item in admin along with the total number of cross links but here is where I'm stuck. I am not certain if function getCrossLinks() is written correctly and have no idea on how to code a cross-links.php page because (I believe) it will be quite different than something like recip-links.php.
Are there any coders willing to pick up on this and help add an admin function that really should be included for larger directories?
Dave Baker
12-21-2006, 11:36 PM
For Pro1.2 version
***Make a backup copy of files which will change***
***Open classes/DirAdmin.php and find function***
function getNumLinksByStatus($aStatus = "active")
{
$cause = "WHERE t1.`status` = '{$aStatus}'";
return $this->getNumLinksBy($cause);
}
***Below this code add following functions***
function getNumCrossedLinks()
{
$sql = "SELECT COUNT(t1.`id`) ";
$sql .= "FROM `{$this->mPrefix}links` t1 ";
$sql .= "LEFT JOIN `{$this->mPrefix}link_categories` t2 ";
$sql .= "ON t1.`id` = t2.`id_link` ";
$sql .= "WHERE t2.`crossed` = '1' ";
return $this->mDb->getOne($sql);
}
function deleteCrossedLink($aLink, $aCategory)
{
$sql = "DELETE FROM `{$this->mPrefix}link_categories` ";
$sql .= "WHERE `id_link` = '{$aLink}' ";
$sql .= "AND `id_category` = '{$aCategory}' ";
return $this->mDb->query($sql);
}
function getCrossedLinks($aStart = 0, $aLimit = 0)
{
$sql = "SELECT t1.*, t41.`title` title_category, t41.`id` id_category, t41.`path` path_category ";
$sql .= "FROM `{$this->mPrefix}link_categories` t4 ";
$sql .= "LEFT JOIN `{$this->mPrefix}links` t1 ";
$sql .= "ON t4.`id_link` = t1.`id` ";
$sql .= "LEFT JOIN `{$this->mPrefix}categories` t41 ";
$sql .= "ON t4.`id_category` = t41.`id` ";
$sql .= "WHERE t4.`crossed` = '1' ";
$sql .= "ORDER BY `date` DESC ";
$sql .= $aLimit ? "LIMIT {$aStart}, {$aLimit}" : '';
$links =& $this->mDb->getAll($sql);
return $links;
}
function getAllCategories($aLink)
{
$sql .= "SELECT t2.`id_link`, t1.`id`, t1.`title` ";
$sql .= "FROM `{$this->mPrefix}categories` t1 ";
$sql .= "LEFT JOIN `{$this->mPrefix}link_categories` t2 ";
$sql .= "ON t1.`id` = t2.`id_category` ";
$sql .= "WHERE `id_link` = {$aLink} ";
$sql .= "ORDER BY t1.`title` ";
if ($sql)
{
$categories =& $this->mDb->getAssoc($sql);
}
return $categories;
}
***Save file***
***Open admin/index.php and find code***
if ($gDirConfig['sponsored_links'])
{
echo '<tr class="tr">';
echo "<td><a href=\"sponsored-links.php\">sponsored</a>: </td>";
$broken_links = $gAdminDb->getNumSponsoredLinks();
echo "<td align=\"right\"><strong>{$broken_links}</strong></td>";
echo '</tr>';
}
***Before this code add***
echo '<tr>';
echo "<td><a href=\"crossed-links.php\">crossed</a>: </td>";
$crossed_links = $gAdminDb->getNumCrossedLinks();
echo "<td align=\"right\"><strong>{$crossed_links}</strong></td>";
echo '</tr>';
***Save file***
***Open includes/admin_menu.inc.php and find code***
$mnuLink['nonrecip']['caption'] = 'non-reciprocal links';
$mnuLink['nonrecip']['url'] = 'norecip-links.php';
***Below this code add***
$mnuLink['crossed']['caption'] = 'crossed links';
$mnuLink['crossed']['url'] = 'crossed-links.php';
***Save file***
***Open admin/js/functions.js and find code***
function crossed_del_confirm1()
{
answer = confirm("Are you sure you want to delete these links from crossed links?")
if (answer == 0)
{
return false;
}
document.getElementById('delete_crossed').value = 1;
document.links.submit();
return true;
}
function crossed_del_confirm2()
{
answer = confirm("Are you sure you want to delete this link from crossed links?")
if (answer == 0)
{
return false;
}
return true;
}
***Below this code add***
function crossed_del_confirm1()
{
answer = confirm("Are you sure you want to delete crossed category?\nNote: you just delete link to it, not category itself!")
if (answer == 0)
{
return false;
}
document.getElementById('delete_crossed').value = 1;
document.links.submit();
return true;
}
***Save file***
***Upload, unzip attachment and copy it in the category admin/***
Bryan Ex
12-22-2006, 12:25 AM
It is impressive how fast you can come up with these answers David. I will install this tonight, test things out, and report back with my results and any changes I make (if any). Thank you once again!
Bryan Ex
12-23-2006, 04:31 PM
I don't use crossed categories at all so never knew there was a manage crossed category admin option because the link only appears if it applies. Great idea Dave and this addition is wonderful! I've installed this and had some time to test it out, both for function and how cross links are likely to be managed so here are a new notes;
In your instructions above for admin/index.php the opening table row is missing. echo '<tr>'; needs to be added as the first line.
In admin/js/functions.js the line "Are you sure you want to delete crossed category?" should be changed from "category" to "link". The function works correctly but the java alert box concerned me so I backed up my database right before testing it.
I've adjusted the statistics on the admin index page to reflect the true counts for real links and cross links and then changed the total at the bottom with;
$all_links = $approval_links + $active_links + $crossed_links + $banned_links;
I've also added pages to the bottom of the crossed-links page so I do not have to keep scrolling back to the top for each page by adding
$url = "crossed-links.php";
navigation($links_num, $url, ITEMS_PER_PAGE);
The link display is EXCELLENT! This is a much needed tool for certain and really should be included in future releases of eSyndiCat. One thing that should be adjusted is the edit link icon. If you look at the crossed categories page there is an icon to delete the crossed category. In the crossed link page the icon is to edit the real link and this does not make sense unless it will edit only the specific cross link. The category path only showed as ROOT so I could not tell if it was the real link or the cross link. This is the snip of code I'm referring to (see cross13.gif attached);
echo '<div class="buttons">';
echo "<a href=\"edit-link.php?id={$value['id']}\"><img src=\"img/ico-edit.gif\" title=\"Edit link\" alt=\"edit\" /></a> ";
echo '</div>';
The category display is also excellent and gives me exactly what I need but like many other directories often have duplicate sub-category names. To prevent confusion and/or errors I have installed the category breadcrumb mod for category display (mod is posted here (http://www.esyndicat.com/forum/showthread.php?p=48264#post48264)) and you can see a sample in crossed14.gif. Would it be possible to also do this for each category listed in crossed-link.php with a line break after each?
Other than that... this addition is a big piece of what I felt was missing for proper admin and I'm thrilled to see it's implementation. Merry Christmas to you David and Merry Christmas to me with this mod. :yahoo:
Dave Baker
12-23-2006, 07:28 PM
In your instructions above for admin/index.php the opening table row is missing. echo '<tr>'; needs to be added as the first line.
Yes, I missed it. :batz:
I've also added pages to the bottom of the crossed-links page so I do not have to keep scrolling back to the top for each page by adding
$url = "crossed-links.php";
navigation($links_num, $url, ITEMS_PER_PAGE);
Useful change.
Are you sure you want to delete crossed category?
LOL. Really this confirmation text doesn't concern to action. I've corrected this function and have added one more function for confirmation at removal when you will click on the icon "delete".
***Open admin/js/functions.js and find code***
function crossed_del_confirm1()
{
answer = confirm("Are you sure you want to delete crossed category?\nNote: you just delete link to it, not category itself!")
if (answer == 0)
{
return false;
}
document.getElementById('delete_crossed').value = 1;
document.links.submit();
return true;
}
***Replace with following code***
function crossed_del_confirm1()
{
answer = confirm("Are you sure you want to delete these links from crossed links?")
if (answer == 0)
{
return false;
}
document.getElementById('delete_crossed').value = 1;
document.links.submit();
return true;
}
function crossed_del_confirm2()
{
answer = confirm("Are you sure you want to delete this link from crossed links?")
if (answer == 0)
{
return false;
}
return true;
}
***Save file***
I've added the icon "delete" and necessary code for removal in the attachment file.
Would it be possible to also do this for each category listed in crossed-link.php with a line break after each?
***Open classes/DirAdmin.php and find function***
function getCrossedLinks($aStart = 0, $aLimit = 0)
***In the function find code***
$sql = "SELECT t1.*, t41.`title` title_category, t41.`id` id_category ";
***Replace with the following code***
$sql = "SELECT t1.*, t41.`title` title_category, t41.`id` id_category, t41.`path` path_category ";
***Save file***
Reupload attachment file from my post.
Merry Christmas to you Bryan!
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.