Plugins PrettyUrls and Comment Center are activated by default; LastComments and LastCommentsAdmin aren't. Also: Protected Mail Links isn't a plugin any more (see eed50e31e8d80e172a4a444a7a556c24f499a6fa).

And: Properly named constructor for class commentcenter_list.
This commit is contained in:
azett 2020-01-03 22:05:36 +01:00
parent 8ddcfda7ce
commit 5050117c41
2 changed files with 260 additions and 219 deletions

View File

@ -1,36 +1,32 @@
<?php <?php
$fp_plugins = array(
$fp_plugins = array(
// to disable put // or # before the plugin name // to disable put // or # before the plugin name
// remove it to enable :) // remove it to enable :)
'jquery', //needed by ligthbox2 (quite heavy in size) 'jquery', // needed by ligthbox2 (quite heavy in size)
'lightbox2', //fancy usable img overlay effect, needs jquery 'lightbox2', // fancy usable img overlay effect, needs jquery
'thumb', //creates thumbnails adding scale=NN% to [img] tags :) 'thumb', // creates thumbnails adding scale=NN% to [img] tags :)
'bbcode', // bbcode-style formatting; if you disable this 'bbcode', // bbcode-style formatting; if you disable this
// you'll loose some features, but you will be able to use xhtml // you'll loose some features, but you will be able to use xhtml
// as a default // as a default
//'syntaxhighlighter',//fancy js to color code // 'syntaxhighlighter',//fancy js to color code
'accessibleantispam', 'accessibleantispam',
'qspam', // quick spam filter 'qspam', // quick spam filter
// 'akismet', // powerful antispam; requires you to have a wordpress api key // 'akismet', // powerful antispam; requires you to have a wordpress api key
// open the plugin file to set your key // open the plugin file to set your key
'adminarea', 'adminarea',
'archives', 'archives',
//'calendar', //time consuming, not really recommended :p // 'calendar', //time consuming, not really recommended :p
// 'lastcomments', // cache-based last-comments block
// 'lastcommentsadmin',
'lastentries', 'lastentries',
//'lastcomments', // cache-based last-comments block 'prettyurls',
//'prettyurls', //rename htaccess.txt in BLOG_ROOT to enable EXPERIMENTAL
'categories', 'categories',
'searchbox', 'searchbox',
'blockparser', 'blockparser',
'readmore', 'readmore',
'favicon', 'favicon',
'protectedmaillinks', 'commentcenter',
'lastcommentsadmin', 'mediamanager'
'mediamanager', );
);
?>

View File

@ -1,33 +1,42 @@
<?php <?php
/* /*
Plugin Name: Flatpress Comment Center * Plugin Name: Comment Center
Version: 1.1.1.azifix * Version: 1.1.2
Plugin URI: http://www.vdfn.altervista.org/redirect/plugin_commentcenter.html * Plugin URI: https://www.flatpress.org
Description: This plugin is a Comment Center for Flatpress * Description: Manage your blog's comments: Set policies, publish or reject comments.
Author: Piero VDFN * Author: FlatPress (credits to Piero VDFN)
Author URI: http://www.vdfn.altervista.org/ * Author URI: https://www.flatpress.org
*/ */
/** /**
* This class interacts with Flaptress comment system. * This class interacts with Flaptress comment system.
*/ */
class plugin_commentcenter { class plugin_commentcenter {
# The plugin configuration // The plugin configuration
var $conf=array(); var $conf = array();
# The policies
var $policies=array(); // The policies
# The plugin_dir var $policies = array();
var $pl_dir='fp-content/plugin_commentcenter/';
// The plugin_dir
var $pl_dir = 'fp-content/plugin_commentcenter/';
/** /**
* This is the constructor. * This is the constructor.
*/ */
function __construct() { function __construct() {
add_action('entry_block', array(&$this, 'lock')); add_action('entry_block', array(
add_filter('comment_validate', array(&$this, 'validate'), 5, 2); &$this,
$this->pl_dir=FP_CONTENT.'plugin_commentcenter/'; 'lock'
if(!file_exists($this->pl_dir)) { ));
add_filter('comment_validate', array(
&$this,
'validate'
), 5, 2);
$this->pl_dir = FP_CONTENT . 'plugin_commentcenter/';
if (!file_exists($this->pl_dir)) {
fs_mkdir($this->pl_dir); fs_mkdir($this->pl_dir);
} }
} }
@ -35,14 +44,15 @@ class plugin_commentcenter {
/** /**
* This function loads the configuration of the plugin. * This function loads the configuration of the plugin.
* *
* @param boolean $foce: Force to load it? * @param boolean $foce:
* Force to load it?
* @return array: The configuration * @return array: The configuration
*/ */
function getConf($force=false) { function getConf($force = false) {
if(!empty($this->conf) && $force) { if (!empty($this->conf) && $force) {
return $this->conf; return $this->conf;
} }
$this->conf=plugin_getoptions('commentcenter'); $this->conf = plugin_getoptions('commentcenter');
return $this->conf; return $this->conf;
} }
@ -52,9 +62,9 @@ class plugin_commentcenter {
function lock() { function lock() {
global $fp_params, $post, $smarty; global $fp_params, $post, $smarty;
$this->loadPolicies(); $this->loadPolicies();
$cats=is_array($post['categories']) ? $post['categories'] : array(); $cats = is_array($post ['categories']) ? $post ['categories'] : array();
$behavoir=$this->behavoirFromPolicies($fp_params['entry'], $cats); $behavoir = $this->behavoirFromPolicies($fp_params ['entry'], $cats);
if($behavoir==-1 && !user_loggedin()) { if ($behavoir == -1 && !user_loggedin()) {
$smarty->assign('entry_commslock', true); $smarty->assign('entry_commslock', true);
} }
} }
@ -62,64 +72,66 @@ class plugin_commentcenter {
/** /**
* This function validates a comment. * This function validates a comment.
* *
* @param boolean $status: The current status of the comment validation * @param boolean $status:
* @param array $comment: The comment data * The current status of the comment validation
* @param array $comment:
* The comment data
* @return boolean: Is the comment valid? * @return boolean: Is the comment valid?
*/ */
function validate($status, $comment) { function validate($status, $comment) {
global $smarty, $fp_params, $lang; global $smarty, $fp_params, $lang;
# If the comment has been already stopped or this is the contact page, stop here our check // If the comment has been already stopped or this is the contact page, stop here our check
if(!$status || function_exists('contact_display')) { if (!$status || function_exists('contact_display')) {
return $status; return $status;
} }
# If the comment has been made from an administrator, don't check it // If the comment has been made from an administrator, don't check it
if(@$comment['loggedin']) { if (@$comment ['loggedin']) {
return true; return true;
} }
$entry=$fp_params['entry']; $entry = $fp_params ['entry'];
if (!isset($comment['date'])) { if (!isset($comment ['date'])) {
$comment['date'] = date_time(); $comment ['date'] = date_time();
} }
$comment['id']=bdb_idfromtime(BDB_COMMENT, $comment['date']); $comment ['id'] = bdb_idfromtime(BDB_COMMENT, $comment ['date']);
$conf=$this->getConf(); $conf = $this->getConf();
# This variables defines how the system has to behave. // This variables defines how the system has to behave.
$behavoir=1; $behavoir = 1;
$this->loadPolicies(); $this->loadPolicies();
# To get categories of the entry, we use the same method of PrettyURLs... // To get categories of the entry, we use the same method of PrettyURLs...
global $post; global $post;
$behavoir=$this->behavoirFromPolicies($entry, $post['categories']); $behavoir = $this->behavoirFromPolicies($entry, $post ['categories']);
// If comments are locked we don't send to Akismet // If comments are locked we don't send to Akismet
if(@$conf['akismet_check'] && $behavoir!=-1) { if (@$conf ['akismet_check'] && $behavoir != -1) {
$akismet=$this->akismetCheck($comment, $entry); $akismet = $this->akismetCheck($comment, $entry);
if(!$akismet) { if (!$akismet) {
$smarty->append('error', $lang['plugin']['commentcenter']['akismet_error']); $smarty->append('error', $lang ['plugin'] ['commentcenter'] ['akismet_error']);
$this->logComment($comment, $entry, 'akismet'); $this->logComment($comment, $entry, 'akismet');
return false; return false;
} }
} }
if($behavoir==0) { if ($behavoir == 0) {
$this->logComment($comment, $entry, 'confirm'); $this->logComment($comment, $entry, 'confirm');
$smarty->append('warnings', $lang['plugin']['commentcenter']['approvation']); $smarty->append('warnings', $lang ['plugin'] ['commentcenter'] ['approvation']);
if(@$conf['email_alert']) { if (@$conf ['email_alert']) {
$this->commentMail($comment, $post['subject']); $this->commentMail($comment, $post ['subject']);
} }
} elseif($behavoir==-1 && @$conf['log_all']) { } elseif ($behavoir == -1 && @$conf ['log_all']) {
$this->logComment($comment, $entry, 'denided'); $this->logComment($comment, $entry, 'denided');
$smarty->append('error', $lang['plugin']['commentcenter']['lock']); $smarty->append('error', $lang ['plugin'] ['commentcenter'] ['lock']);
} }
if($behavoir!=1) { if ($behavoir != 1) {
// Delete the comment content // Delete the comment content
$_POST['content']=''; $_POST ['content'] = '';
} }
# Also if the comment need to be approved, we return false. // Also if the comment need to be approved, we return false.
return $behavoir==1; return $behavoir == 1;
} }
/** /**
@ -131,35 +143,36 @@ class plugin_commentcenter {
* -3 if the response failed * -3 if the response failed
* -4 if the key isn't valid * -4 if the key isn't valid
* *
* @param string $key: A key for the service * @param string $key:
* A key for the service
* @return object: The akismet object * @return object: The akismet object
*/ */
function &akismetLoad($key='') { function &akismetLoad($key = '') {
$conf=$this->getConf(); $conf = $this->getConf();
if(!empty($key)) { if (!empty($key)) {
} elseif(empty($conf['akismet_key'])) { } elseif (empty($conf ['akismet_key'])) {
$e=-1; $e = -1;
return $e; return $e;
} else { } else {
$key=$conf['akismet_key']; $key = $conf ['akismet_key'];
} }
$url=empty($conf['akismet_url']) ? BLOG_BASEURL : $conf['akismet_url']; $url = empty($conf ['akismet_url']) ? BLOG_BASEURL : $conf ['akismet_url'];
include_once dirname(__FILE__).'/inc/akismet.class.php'; include_once dirname(__FILE__) . '/inc/akismet.class.php';
$akismet=new Akismet($url, $key); $akismet = new Akismet($url, $key);
if($akismet->errorsExist()) { if ($akismet->errorsExist()) {
$e=0; $e = 0;
switch(true) { switch (true) {
case $akismet->isError(AKISMET_SERVER_NOT_FOUND): case $akismet->isError(AKISMET_SERVER_NOT_FOUND):
$e=-2; $e = -2;
break; break;
case $akismet->isError(AKISMET_RESPONSE_FAILED): case $akismet->isError(AKISMET_RESPONSE_FAILED):
$e=-3; $e = -3;
break; break;
case $akismet->isError(AKISMET_INVALID_KEY): case $akismet->isError(AKISMET_INVALID_KEY):
$e=-4; $e = -4;
break; break;
} }
return $e; return $e;
@ -171,32 +184,34 @@ class plugin_commentcenter {
/** /**
* This function clean a comment to send it to Akismet. * This function clean a comment to send it to Akismet.
* *
* @param array $comment: The comment data * @param array $comment:
* @param string $entry: The entry id * The comment data
* @param string $entry:
* The entry id
* @return array: $comment cleaned * @return array: $comment cleaned
*/ */
function akismetClean($comment, $entry) { function akismetClean($comment, $entry) {
global $post; global $post;
$conf=$this->getConf(); $conf = $this->getConf();
$oldpost=$post; $oldpost = $post;
$o=new FPDB_Query("id:{$entry},fullparse:false", null); $o = new FPDB_Query("id:{$entry},fullparse:false", null);
$arr=$o->getEntry(); $arr = $o->getEntry();
$post=$arr[1]; $post = $arr [1];
$link=get_permalink($entry); $link = get_permalink($entry);
if(!empty($conf['akismet_url'])) { if (!empty($conf ['akismet_url'])) {
$link=$conf['akismet_url'].substr($link, strlen(BLOG_BASEURL)); $link = $conf ['akismet_url'] . substr($link, strlen(BLOG_BASEURL));
} }
$post=$oldpost; $post = $oldpost;
$clean=array( $clean = array(
'author'=>$comment['name'], 'author' => $comment ['name'],
'email'=>@$comment['email'], 'email' => @$comment ['email'],
'website'=>@$comment['url'], 'website' => @$comment ['url'],
'body'=>$comment['content'], 'body' => $comment ['content'],
'user_ip'=>@$comment['ip-address'], 'user_ip' => @$comment ['ip-address'],
'permalink'=>$link 'permalink' => $link
); );
return $clean; return $clean;
@ -205,47 +220,49 @@ class plugin_commentcenter {
/** /**
* This function manages the Akismet Check * This function manages the Akismet Check
* *
* @param array $comment: The comment data * @param array $comment:
* @param string $entry: The entry id * The comment data
* @param string $entry:
* The entry id
* @return boolean: Is the comment allowed? * @return boolean: Is the comment allowed?
*/ */
function akismetCheck($comment, $entry) { function akismetCheck($comment, $entry) {
$akismet=&$this->akismetLoad(); $akismet = &$this->akismetLoad();
if(!is_object($akismet)) { if (!is_object($akismet)) {
# Failed to load it. We return true, but the comment isn't checked // Failed to load it. We return true, but the comment isn't checked
// TODO: Add an error logger? Or make different, configurable behaves? // TODO: Add an error logger? Or make different, configurable behaves?
return true; return true;
} }
$clean=$this->akismetClean($comment, $entry); $clean = $this->akismetClean($comment, $entry);
$akismet->setComment($clean); $akismet->setComment($clean);
if($akismet->isSpam()) { if ($akismet->isSpam()) {
# Akismet sign the comment as spam. Let's stop it. // Akismet sign the comment as spam. Let's stop it.
return false; return false;
} else { } else {
return true; return true;
} }
} }
/** /**
* This function loads the comment policies. * This function loads the comment policies.
* *
* @param boolean $force: Force to load them? * @param boolean $force:
* Force to load them?
* @return array: The policies * @return array: The policies
*/ */
function &loadPolicies($force=false) { function &loadPolicies($force = false) {
if(!$force && !empty($this->policies)) { if (!$force && !empty($this->policies)) {
return $this->policies; return $this->policies;
} }
if(!file_exists($f=$this->pl_dir.'policies.txt')) { if (!file_exists($f = $this->pl_dir . 'policies.txt')) {
$this->policies=array(); $this->policies = array();
return $this->policies; return $this->policies;
} }
include $f; include $f;
$this->policies=$policies; $this->policies = $policies;
return $this->policies; return $this->policies;
} }
@ -255,42 +272,50 @@ class plugin_commentcenter {
* @return boolean * @return boolean
*/ */
function savePolicies() { function savePolicies() {
$this->policies=array_values($this->policies); $this->policies = array_values($this->policies);
return system_save($this->pl_dir.'policies.txt', array('policies'=>$this->policies)); return system_save($this->pl_dir . 'policies.txt', array(
'policies' => $this->policies
));
} }
/** /**
* This function adds a policy in a certain position. * This function adds a policy in a certain position.
* *
* @param mixed $policy: The policy * @param mixed $policy:
* @param integer $position: The position * The policy
* @param integer $position:
* The position
*/ */
function addPolicyAt($policy, $position) { function addPolicyAt($policy, $position) {
if($position<0) { if ($position < 0) {
$position=count($this->policies)+$position+1; $position = count($this->policies) + $position + 1;
} }
$before=array_slice($this->policies, 0, $position); $before = array_slice($this->policies, 0, $position);
$after=array_slice($this->policies, $position); $after = array_slice($this->policies, $position);
$this->policies=array_merge($before, array($policy), $after); $this->policies = array_merge($before, array(
$policy
), $after);
} }
/** /**
* This function moves a policy from a postition to another one. * This function moves a policy from a postition to another one.
* *
* @param integer $old: The old position * @param integer $old:
* @param integer $new: The new position * The old position
* @param integer $new:
* The new position
*/ */
function policyMove($old, $new) { function policyMove($old, $new) {
if(!isset($this->policies[$old])) { if (!isset($this->policies [$old])) {
return false; return false;
} }
$new=$new>$old ? $new+1 : $new; $new = $new > $old ? $new + 1 : $new;
$del=$new>$old ? $old : $old+1; $del = $new > $old ? $old : $old + 1;
$this->addPolicyAt($this->policies[$old], $new); $this->addPolicyAt($this->policies [$old], $new);
if(isset($this->policies[$del])) { if (isset($this->policies [$del])) {
unset($this->policies[$del]); unset($this->policies [$del]);
} }
$this->policies=array_values($this->policies); $this->policies = array_values($this->policies);
return true; return true;
} }
@ -300,44 +325,46 @@ class plugin_commentcenter {
* 0: The comment need to be approved * 0: The comment need to be approved
* -1: The user can't comment * -1: The user can't comment
* *
* @param string $entry: The entry id * @param string $entry:
* @param array $cats: The categories * The entry id
* @param array $cats:
* The categories
* @return integer: The behavoir * @return integer: The behavoir
*/ */
function behavoirFromPolicies($entry, $cats=array()) { function behavoirFromPolicies($entry, $cats = array()) {
$date=date_from_id($entry); $date = date_from_id($entry);
$time=$date['time']; $time = $date ['time'];
$return=1; $return = 1;
$pols=&$this->policies; $pols = &$this->policies;
if(count($pols)) { if (count($pols)) {
foreach($pols as $policy) { foreach ($pols as $policy) {
if(@$policy['is_all']) { if (@$policy ['is_all']) {
$return=$policy['do']; $return = $policy ['do'];
} elseif(!empty($policy['entry']) && is_array($policy['entry'])) { } elseif (!empty($policy ['entry']) && is_array($policy ['entry'])) {
if(in_array($entry, $policy['entry'])) { if (in_array($entry, $policy ['entry'])) {
$return=$policy['do']; $return = $policy ['do'];
} }
} elseif(!empty($policy['entry'])) { } elseif (!empty($policy ['entry'])) {
if($entry==$policy['entry']) { if ($entry == $policy ['entry']) {
$return=$policy['do']; $return = $policy ['do'];
} }
} else { } else {
$consider=true; $consider = true;
if(!empty($policy['categories'])) { if (!empty($policy ['categories'])) {
$consider=count(array_intersect($policy['categories'], $cats))>0; $consider = count(array_intersect($policy ['categories'], $cats)) > 0;
} }
if(!empty($policy['older'])) { if (!empty($policy ['older'])) {
$consider=(time()-$time)>$policy['older']; $consider = (time() - $time) > $policy ['older'];
} else { } else {
if(!empty($policy['time_less'])) { if (!empty($policy ['time_less'])) {
$consider=$time>$policy['time_less']; $consider = $time > $policy ['time_less'];
} }
if(!empty($policy['time_more'])) { if (!empty($policy ['time_more'])) {
$consider=$time<$policy['time_more']; $consider = $time < $policy ['time_more'];
} }
} }
$return=$consider ? $policy['do'] : $return; $return = $consider ? $policy ['do'] : $return;
} }
} }
} }
@ -350,95 +377,113 @@ class plugin_commentcenter {
* Maybe it's considered SPAM by Akismet or the comment requires * Maybe it's considered SPAM by Akismet or the comment requires
* the Administrator's approvation. * the Administrator's approvation.
* *
* @param array $comment: The comment data * @param array $comment:
* @param string $entry: The entry id * The comment data
* @param string $why: The reason of the log * @param string $entry:
* The entry id
* @param string $why:
* The reason of the log
* @return boolean: Can it saves the log? * @return boolean: Can it saves the log?
*/ */
function logComment($comment, $entry, $why='') { function logComment($comment, $entry, $why = '') {
$f=$this->pl_dir."e{$entry}_c{$comment['id']}.txt"; $f = $this->pl_dir . "e{$entry}_c{$comment['id']}.txt";
if(!empty($why)) { if (!empty($why)) {
$comment['log_reason']=$why; $comment ['log_reason'] = $why;
} }
return system_save($f, array('comment'=>$comment)); return system_save($f, array(
'comment' => $comment
));
} }
/** /**
* This function send an email to the administrator with the comment data. * This function send an email to the administrator with the comment data.
* It's based on the code of comment.php * It's based on the code of comment.php
* *
* @param array $comment: The comment data * @param array $comment:
* @param string $entry_title: The title of the entry * The comment data
* @param string $entry_title:
* The title of the entry
* @return boolean * @return boolean
*/ */
function commentMail($comment, $entry_title) { function commentMail($comment, $entry_title) {
global $lang, $fp_config; global $lang, $fp_config;
$subject=$lang['plugin']['commentcenter']['mail_subj']; $subject = $lang ['plugin'] ['commentcenter'] ['mail_subj'];
$subject=sprintf($subject, $fp_config['general']['title']); $subject = sprintf($subject, $fp_config ['general'] ['title']);
$comm_mail=empty($comment['email'])? '' : "<{$comment['email']}>"; $comm_mail = empty($comment ['email']) ? '' : "<{$comment['email']}>";
$from_mail=$fp_config['general']['email']; $from_mail = $fp_config ['general'] ['email'];
$text=$lang['plugin']['commentcenter']['mail_text']; $text = $lang ['plugin'] ['commentcenter'] ['mail_text'];
$text=str_replace(array('%toname%', '%fromname%', '%frommail%', $text = str_replace(array(
'%entrytitle%', '%content%', '%blogtitle%' '%toname%',
), array($fp_config['general']['author'], $comment['name'], $comm_mail, '%fromname%',
$entry_title, $comment['content'], $fp_config['general']['title'] '%frommail%',
), $text '%entrytitle%',
); '%content%',
'%blogtitle%'
), array(
$fp_config ['general'] ['author'],
$comment ['name'],
$comm_mail,
$entry_title,
$comment ['content'],
$fp_config ['general'] ['title']
), $text);
return @utils_mail($from_mail, $subject, $text); return @utils_mail($from_mail, $subject, $text);
} }
} }
$GLOBALS['plugin_commentcenter']=new plugin_commentcenter(); $GLOBALS ['plugin_commentcenter'] = new plugin_commentcenter();
/** /**
* This class makes the list of comments that needs to be approved. * This class makes the list of comments that needs to be approved.
*/ */
class commentcenter_list extends fs_filelister { class commentcenter_list extends fs_filelister {
/** /**
* This is the constructor of the class. * This is the constructor of the class.
* *
* @params string $dir: The directory to list * @params string $dir: The directory to list
*/ */
function commentcenter_list($dir) { function __construct($dir) {
parent::__construct($dir); parent::__construct($dir);
} }
function _checkFile($directory, $file) { function _checkFile($directory, $file) {
if(fnmatch('eentry*.txt', $file)) { if (fnmatch('eentry*.txt', $file)) {
$entry=substr($file, 1, 18); $entry = substr($file, 1, 18);
$comment=substr($file, 21, 20); $comment = substr($file, 21, 20);
$this->_list[$entry][]=$comment; $this->_list [$entry] [] = $comment;
} }
return 0; return 0;
} }
function toDetails($entry=null) { function toDetails($entry = null) {
$list=array(); $list = array();
if(!is_null($entry) && @is_array($this->_list[$entry])) { if (!is_null($entry) && @is_array($this->_list [$entry])) {
foreach($this->_list[$entry] as $commentid) { foreach ($this->_list [$entry] as $commentid) {
include $this->_directory."/e{$entry}_c{$commentid}.txt"; include $this->_directory . "/e{$entry}_c{$commentid}.txt";
if(empty($comment['log_reason'])) { if (empty($comment ['log_reason'])) {
$comment['log_reason']='nd'; $comment ['log_reason'] = 'nd';
} }
$list[$comment['log_reason']][$commentid]=$comment; $list [$comment ['log_reason']] [$commentid] = $comment;
} }
} else { } else {
foreach($this->_list as $key=>$comments) { foreach ($this->_list as $key => $comments) {
$list[$key]=$this->toDetails($key); $list [$key] = $this->toDetails($key);
} }
} }
return $list; return $list;
} }
} }
# If we're in administration area, we load admin panel // If we're in administration area, we load admin panel
if(defined('MOD_ADMIN_PANEL')) { if (defined('MOD_ADMIN_PANEL')) {
include dirname(__FILE__).'/inc/admin.php'; include dirname(__FILE__) . '/inc/admin.php';
include dirname(__FILE__).'/inc/jslang.php'; include dirname(__FILE__) . '/inc/jslang.php';
include dirname(__FILE__).'/inc/editor.php'; include dirname(__FILE__) . '/inc/editor.php';
} }