Tobias
10-08-2006, 08:13 AM
This is ONLY for Subdreamer v2.3.5!
Hello,
some people requested it and I couldn't find it neither, so I here are the code changes to display a "Views: xxx" count for the "p2" plugin, tested and working up to SD v2.3.5.
Since I don't want to make a "new" plugin, I assume that you know how to run a single SQL (insert) command for your SD database (step 1 below).
Again, this code is based on "p2_news" plugin, not any other article related plugin - just to avoid misunderstandings.
Involved are basically 2 steps:
Step 1: adding a plugin setting for enabling/disabling display of views count
Step 2: opening file "plugins/p2_news/news.php" and applying below changes
Step 1:
To add a plugin setting to make display of views count optional, run below INSERT script within phpMyAdmin or however you do it.
Important:
You need to replace the "sd_" table prefix to match with your SD installation's table prefix.
Value "2" is the default plugin number, so you'd have to change it for any clones of your news plugin.
SQL Statement:
INSERT INTO `sd_pluginsettings` VALUES (NULL, 2,
'Article Display Settings', '', 'Display Views Count', 'yesno', '1', 10);
Step 2:
Code changes to file "plugins/p2_news/news.php" are as follows.
Please note that I removed some blanks off the indentation to make it read easier here in the forum.
Around line 28 search for line:
'displaycomments' => 1024);
Replace it with these lines:
'displaycomments' => 1024,
'displayviews' => 2048);
Around line 479 search for lines (including the curly bracket!):
}
// ############################### DISPLAY NEWS ###############################
Replace them with these lines:
// display "views" count?
if($article['settings'] & $p2_articlebitfield['displayviews'])
{
$count = $DB->query_first("SELECT views FROM `" . TABLE_PREFIX . "p2_news` WHERE articleid = '" . $article['articleid'] . "'");
echo iif(in_array(2, $userinfo['pluginsubmitids']) || ($article['settings'] & $p2_articlebitfield['displaycomments']), ' - ', '<br /><br />') .
'Views: '.$count[0];
}
}
// ############################### DISPLAY NEWS ###############################
Note: above "Views: " text should ideally be a language phrase which then would be accessible by the existing variable "$p2_language" in above code.
Around line 499 search for line:
$globalsettings += $p2_settings['Display User Comments'] == 1 ? 1024 : 0;
INSERT below line right after it:
$globalsettings += $p2_settings['Display Views Count'] == 1 ? 2048 : 0;
In the "Article Settings" you should now see an additional option for "Display Views Count" ("Yes" by default), above code changes add it as a potential flag and take care of the display.
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/)
Hello,
some people requested it and I couldn't find it neither, so I here are the code changes to display a "Views: xxx" count for the "p2" plugin, tested and working up to SD v2.3.5.
Since I don't want to make a "new" plugin, I assume that you know how to run a single SQL (insert) command for your SD database (step 1 below).
Again, this code is based on "p2_news" plugin, not any other article related plugin - just to avoid misunderstandings.
Involved are basically 2 steps:
Step 1: adding a plugin setting for enabling/disabling display of views count
Step 2: opening file "plugins/p2_news/news.php" and applying below changes
Step 1:
To add a plugin setting to make display of views count optional, run below INSERT script within phpMyAdmin or however you do it.
Important:
You need to replace the "sd_" table prefix to match with your SD installation's table prefix.
Value "2" is the default plugin number, so you'd have to change it for any clones of your news plugin.
SQL Statement:
INSERT INTO `sd_pluginsettings` VALUES (NULL, 2,
'Article Display Settings', '', 'Display Views Count', 'yesno', '1', 10);
Step 2:
Code changes to file "plugins/p2_news/news.php" are as follows.
Please note that I removed some blanks off the indentation to make it read easier here in the forum.
Around line 28 search for line:
'displaycomments' => 1024);
Replace it with these lines:
'displaycomments' => 1024,
'displayviews' => 2048);
Around line 479 search for lines (including the curly bracket!):
}
// ############################### DISPLAY NEWS ###############################
Replace them with these lines:
// display "views" count?
if($article['settings'] & $p2_articlebitfield['displayviews'])
{
$count = $DB->query_first("SELECT views FROM `" . TABLE_PREFIX . "p2_news` WHERE articleid = '" . $article['articleid'] . "'");
echo iif(in_array(2, $userinfo['pluginsubmitids']) || ($article['settings'] & $p2_articlebitfield['displaycomments']), ' - ', '<br /><br />') .
'Views: '.$count[0];
}
}
// ############################### DISPLAY NEWS ###############################
Note: above "Views: " text should ideally be a language phrase which then would be accessible by the existing variable "$p2_language" in above code.
Around line 499 search for line:
$globalsettings += $p2_settings['Display User Comments'] == 1 ? 1024 : 0;
INSERT below line right after it:
$globalsettings += $p2_settings['Display Views Count'] == 1 ? 2048 : 0;
In the "Article Settings" you should now see an additional option for "Display Views Count" ("Yes" by default), above code changes add it as a potential flag and take care of the display.
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/)