Tobias
02-03-2007, 07:42 PM
Hi,
since a fellow customer of ours at SDDepot (http://www.sddepot.com) asked for it, I took some time to implement the following for the "p2_news" plugin (SD 2.4.0 core plugin):
Tags display of article's "Metakeywords" (which have to be entered comma-separated in the article settings per article). If no Metakeywords are entered, then there will be no "Tags" line of course.
Tags are clickable and will result in display of only those articles within the current category, that have the same tag as well.
"Search Bar" custom plugin file (attached file "p2_search.php") offering "Search Text" and "Search By" controls. The "Search By" includes Article, Author, Description, Tags and Title.
This Custom Plugin file is not required for the Tags display, but looks fine either above or below the Articles plugin.
Usage: 1. Rename the attached file to "p2_search.php" and upload it into your "p2_news" folder on your server. 2. Create a new Custom Plugin within the ACP and specify as "Include File": "p2_news/p2_search.php" (without quotes; if applicable, change "2" to the cloned plugin number).
Tested on SD 2.4.0 with "Friendly URLs" on/off.
For the tags and search functionality there are 2 code blocks in below order to be inserted in the file "p2_news.php" which needs to be of SD 2.4.0:
Step 0: Open an unpatched SD 2.4.0 version of "p2_news.php" in the "p2_news" folder within your SD installation. If you have already changed your "p2_news.php" file, be cautios to find the right code locations!
Step 1:
At line 552 you shall find these lines:
$getarticles = $DB->query("SELECT * FROM " . TABLE_PREFIX . "p2_news WHERE categoryid = '$categoryid'
AND (settings & 2) " . $extraquery . "
AND (datestart = 0 OR datestart < '" . time() . "')
AND (dateend = 0 OR dateend > '" . time() . "')
ORDER BY (settings & 8192) DESC, " . $order . " LIMIT $start, " . ($limit + 1) . "");
REPLACE above lines with this block:
// SDDEPOT 20070203 - Start -----------------------------------------------
// Check if a "search text" was submitted (which should be "posted" by
// a secondary search bar OR a "&p2_search=" link.
// If so, use the "$extraquery" variable to specify a WHERE clause.
$p2_catselect = " AND categoryid = '$categoryid' ";
$p2_search = isset($_POST['p2_search']) ? $_POST['p2_search'] : (isset($_GET['p2_search']) ? $_GET['p2_search'] : '');
$p2_search = urldecode($p2_search);
$p2_searchby = isset($_POST['p2_searchby']) ? $_POST['p2_searchby'] : (isset($_GET['p2_searchby']) ? $_GET['p2_searchby'] : 'article');
if(!empty($p2_search))
{
if(!(($p2_searchby=='article')||($p2_searchby=='au thor')||
($p2_searchby=='description')||($p2_searchby=='tag s')||
($p2_searchby=='title')))
{
$p2_searchby = 'article';
}
if($p2_searchby=='tags') $p2_searchby = 'metakeywords';
//REMOVE the BLANK in front of below 039 strings!!!
$p2_search = str_replace('$# 039;', '$# 39;', $p2_search);
$p2_search = str_replace('"', '"', $p2_search);
$p2_search = addslashes(str_replace('&# 39;', "'", $p2_search));
$extraquery = " AND ($p2_searchby LIKE '%$p2_search%')";
// *ONLY* uncomment below line if search shall search across ALL
// categories in all articles!
//$p2_catselect = '';
}
// SDDEPOT 20070203 - END -------------------------------------------------
$getarticles = $DB->query("SELECT * FROM " . TABLE_PREFIX . "p2_news
WHERE (settings & 2) " . $extraquery . " $p2_catselect
AND (datestart = 0 OR datestart < '" . time() . "')
AND (dateend = 0 OR dateend > '" . time() . "')
ORDER BY (settings & 8192) DESC, " . $order . "
LIMIT $start, " . ($limit + 1) . "");
IMPORTANT: when copying code from here, remove the blanks in both the quoted strings with the "39;" in it!!!
Step 2:
At line 451 you shall find these lines:
// display submit news link?
if(in_array(2, $userinfo['pluginsubmitids']))
INSERT ABOVE lines this block of code:
// SDDEPOT 20070203 - Start -------------------------------------------------
// Display Metakeywords of Article as "Tags":
if(!empty($article['metakeywords']))
{
echo '<br /><br />
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="text-align:left;padding-top:4px;padding-bottom:4px;" width="5%">Tags:</td>
<td style="text-align:left;padding-left:4px;padding-right:4px;" width="95%">
';
$atags = explode(',',$article['metakeywords']);
foreach($atags as $tag){
$tag = rtrim(ltrim($tag));
if(!empty($tag)){
echo '<span style="white-space:nowrap;padding-right:4px;">
<a href="'.RewriteLink('index.php?categoryid='.$categoryid. '&p2_searchby=tags&p2_search='.urlencode($tag)).'">'.$tag.'</a></span>
';
}
} //foreach
echo '</td>
</tr>
</table>
';
}
// SDDEPOT 20070203 - End ---------------------------------------------------
Step 3:
Around line 650ff (some lines below Step 1's location), you shall find these lines:
if($start > 0)
{
echo '<td><a href="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_start=' . ($start - $limit)) . '">' . $p2_language['previous'] . '</a></td>';
}
if($rows > $limit)
{
echo '<td align="right"><a href="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_start=' . ($start + $limit)) . '">' . $p2_language['next'] . '</a></td>';
}
REPLACE those lines with this block of code:
This shall ensure correct "Next" / "Previous" links whilst a search pattern is active.
// SDDEPOT - 20070205 - start
$extralink = '';
if(!empty($p2_search))
{
if($p2_searchby=='metakeywords') $p2_searchby = 'tags';
$extralink = '&p2_search='.urlencode($p2_search).'&p2_searchby='.$p2_searchby;
}
// SDDEPOT - 20070205 - end
// SDDEPOT - 20070205 - added $extralink variable to below links:
if($start > 0)
{
echo '<td><a href="' .
RewriteLink('index.php?categoryid=' . $categoryid . '&p2_start=' . ($start - $limit).$extralink) .
'">' . $p2_language['previous'] . '</a></td>';
}
if($rows > $limit)
{
echo '<td align="right"><a href="' .
RewriteLink('index.php?categoryid=' . $categoryid . '&p2_start=' . ($start + $limit).$extralink) .
'">' . $p2_language['next'] . '</a></td>';
}
Step X:
Make a backup of your "p2_news.php" on your server and upload the changed file.
EDIT (2/4/2007):
* A live demo page (http://www.sddepot.com/articles_demo) has been created!
EDIT (2/5/2007):
* Take into account "Next" / "Previous" links (revised Step 1 and added Step 3). Also the attached "search" file was updated to show a "Clear" button for the search.
EDIT (2/11/2007):
* Code for Step 1 updated to better handle single/double quotes. Please "repaste" that code into your "p2_news.php" file. IMPORTANT: I had to add a blank in front of the *39 in that one line or the vB editor would replace it, please remove that blank!
EDIT (2/12/2007):
* Code for Step 3: fixed Prev/Next links with Friendly URLs.
If there should be problems, please let me know.
Mass Media Pro Plugin - Live Demo : Mass Media Pro (http://www.sddepot.com/mass_media/)
My SDDepot Blog (http://www.sddepot.com/community/blog/tobias/) - SDDepot - Skins and Plugins (http://www.sddepot.com/)
since a fellow customer of ours at SDDepot (http://www.sddepot.com) asked for it, I took some time to implement the following for the "p2_news" plugin (SD 2.4.0 core plugin):
Tags display of article's "Metakeywords" (which have to be entered comma-separated in the article settings per article). If no Metakeywords are entered, then there will be no "Tags" line of course.
Tags are clickable and will result in display of only those articles within the current category, that have the same tag as well.
"Search Bar" custom plugin file (attached file "p2_search.php") offering "Search Text" and "Search By" controls. The "Search By" includes Article, Author, Description, Tags and Title.
This Custom Plugin file is not required for the Tags display, but looks fine either above or below the Articles plugin.
Usage: 1. Rename the attached file to "p2_search.php" and upload it into your "p2_news" folder on your server. 2. Create a new Custom Plugin within the ACP and specify as "Include File": "p2_news/p2_search.php" (without quotes; if applicable, change "2" to the cloned plugin number).
Tested on SD 2.4.0 with "Friendly URLs" on/off.
For the tags and search functionality there are 2 code blocks in below order to be inserted in the file "p2_news.php" which needs to be of SD 2.4.0:
Step 0: Open an unpatched SD 2.4.0 version of "p2_news.php" in the "p2_news" folder within your SD installation. If you have already changed your "p2_news.php" file, be cautios to find the right code locations!
Step 1:
At line 552 you shall find these lines:
$getarticles = $DB->query("SELECT * FROM " . TABLE_PREFIX . "p2_news WHERE categoryid = '$categoryid'
AND (settings & 2) " . $extraquery . "
AND (datestart = 0 OR datestart < '" . time() . "')
AND (dateend = 0 OR dateend > '" . time() . "')
ORDER BY (settings & 8192) DESC, " . $order . " LIMIT $start, " . ($limit + 1) . "");
REPLACE above lines with this block:
// SDDEPOT 20070203 - Start -----------------------------------------------
// Check if a "search text" was submitted (which should be "posted" by
// a secondary search bar OR a "&p2_search=" link.
// If so, use the "$extraquery" variable to specify a WHERE clause.
$p2_catselect = " AND categoryid = '$categoryid' ";
$p2_search = isset($_POST['p2_search']) ? $_POST['p2_search'] : (isset($_GET['p2_search']) ? $_GET['p2_search'] : '');
$p2_search = urldecode($p2_search);
$p2_searchby = isset($_POST['p2_searchby']) ? $_POST['p2_searchby'] : (isset($_GET['p2_searchby']) ? $_GET['p2_searchby'] : 'article');
if(!empty($p2_search))
{
if(!(($p2_searchby=='article')||($p2_searchby=='au thor')||
($p2_searchby=='description')||($p2_searchby=='tag s')||
($p2_searchby=='title')))
{
$p2_searchby = 'article';
}
if($p2_searchby=='tags') $p2_searchby = 'metakeywords';
//REMOVE the BLANK in front of below 039 strings!!!
$p2_search = str_replace('$# 039;', '$# 39;', $p2_search);
$p2_search = str_replace('"', '"', $p2_search);
$p2_search = addslashes(str_replace('&# 39;', "'", $p2_search));
$extraquery = " AND ($p2_searchby LIKE '%$p2_search%')";
// *ONLY* uncomment below line if search shall search across ALL
// categories in all articles!
//$p2_catselect = '';
}
// SDDEPOT 20070203 - END -------------------------------------------------
$getarticles = $DB->query("SELECT * FROM " . TABLE_PREFIX . "p2_news
WHERE (settings & 2) " . $extraquery . " $p2_catselect
AND (datestart = 0 OR datestart < '" . time() . "')
AND (dateend = 0 OR dateend > '" . time() . "')
ORDER BY (settings & 8192) DESC, " . $order . "
LIMIT $start, " . ($limit + 1) . "");
IMPORTANT: when copying code from here, remove the blanks in both the quoted strings with the "39;" in it!!!
Step 2:
At line 451 you shall find these lines:
// display submit news link?
if(in_array(2, $userinfo['pluginsubmitids']))
INSERT ABOVE lines this block of code:
// SDDEPOT 20070203 - Start -------------------------------------------------
// Display Metakeywords of Article as "Tags":
if(!empty($article['metakeywords']))
{
echo '<br /><br />
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="text-align:left;padding-top:4px;padding-bottom:4px;" width="5%">Tags:</td>
<td style="text-align:left;padding-left:4px;padding-right:4px;" width="95%">
';
$atags = explode(',',$article['metakeywords']);
foreach($atags as $tag){
$tag = rtrim(ltrim($tag));
if(!empty($tag)){
echo '<span style="white-space:nowrap;padding-right:4px;">
<a href="'.RewriteLink('index.php?categoryid='.$categoryid. '&p2_searchby=tags&p2_search='.urlencode($tag)).'">'.$tag.'</a></span>
';
}
} //foreach
echo '</td>
</tr>
</table>
';
}
// SDDEPOT 20070203 - End ---------------------------------------------------
Step 3:
Around line 650ff (some lines below Step 1's location), you shall find these lines:
if($start > 0)
{
echo '<td><a href="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_start=' . ($start - $limit)) . '">' . $p2_language['previous'] . '</a></td>';
}
if($rows > $limit)
{
echo '<td align="right"><a href="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_start=' . ($start + $limit)) . '">' . $p2_language['next'] . '</a></td>';
}
REPLACE those lines with this block of code:
This shall ensure correct "Next" / "Previous" links whilst a search pattern is active.
// SDDEPOT - 20070205 - start
$extralink = '';
if(!empty($p2_search))
{
if($p2_searchby=='metakeywords') $p2_searchby = 'tags';
$extralink = '&p2_search='.urlencode($p2_search).'&p2_searchby='.$p2_searchby;
}
// SDDEPOT - 20070205 - end
// SDDEPOT - 20070205 - added $extralink variable to below links:
if($start > 0)
{
echo '<td><a href="' .
RewriteLink('index.php?categoryid=' . $categoryid . '&p2_start=' . ($start - $limit).$extralink) .
'">' . $p2_language['previous'] . '</a></td>';
}
if($rows > $limit)
{
echo '<td align="right"><a href="' .
RewriteLink('index.php?categoryid=' . $categoryid . '&p2_start=' . ($start + $limit).$extralink) .
'">' . $p2_language['next'] . '</a></td>';
}
Step X:
Make a backup of your "p2_news.php" on your server and upload the changed file.
EDIT (2/4/2007):
* A live demo page (http://www.sddepot.com/articles_demo) has been created!
EDIT (2/5/2007):
* Take into account "Next" / "Previous" links (revised Step 1 and added Step 3). Also the attached "search" file was updated to show a "Clear" button for the search.
EDIT (2/11/2007):
* Code for Step 1 updated to better handle single/double quotes. Please "repaste" that code into your "p2_news.php" file. IMPORTANT: I had to add a blank in front of the *39 in that one line or the vB editor would replace it, please remove that blank!
EDIT (2/12/2007):
* Code for Step 3: fixed Prev/Next links with Friendly URLs.
If there should be problems, please let me know.
Mass Media Pro Plugin - Live Demo : Mass Media Pro (http://www.sddepot.com/mass_media/)
My SDDepot Blog (http://www.sddepot.com/community/blog/tobias/) - SDDepot - Skins and Plugins (http://www.sddepot.com/)