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

View File

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