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,5 +1,4 @@
<?php <?php
$fp_plugins = array( $fp_plugins = array(
// to disable put // or # before the plugin name // to disable put // or # before the plugin name
@ -19,18 +18,15 @@
'adminarea', 'adminarea',
'archives', 'archives',
// 'calendar', //time consuming, not really recommended :p // 'calendar', //time consuming, not really recommended :p
'lastentries',
// 'lastcomments', // cache-based last-comments block // 'lastcomments', // cache-based last-comments block
//'prettyurls', //rename htaccess.txt in BLOG_ROOT to enable EXPERIMENTAL // 'lastcommentsadmin',
'lastentries',
'prettyurls',
'categories', 'categories',
'searchbox', 'searchbox',
'blockparser', 'blockparser',
'readmore', 'readmore',
'favicon', 'favicon',
'protectedmaillinks', 'commentcenter',
'lastcommentsadmin', 'mediamanager'
'mediamanager',
); );
?>

View File

@ -1,11 +1,12 @@
<?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
*/ */
/** /**
@ -13,19 +14,27 @@ Author URI: http://www.vdfn.altervista.org/
*/ */
class plugin_commentcenter { class plugin_commentcenter {
# The plugin configuration // The plugin configuration
var $conf = array(); var $conf = array();
# The policies
// The policies
var $policies = array(); var $policies = array();
# The plugin_dir
// The plugin_dir
var $pl_dir = 'fp-content/plugin_commentcenter/'; 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,
'lock'
));
add_filter('comment_validate', array(
&$this,
'validate'
), 5, 2);
$this->pl_dir = FP_CONTENT . 'plugin_commentcenter/'; $this->pl_dir = FP_CONTENT . 'plugin_commentcenter/';
if (!file_exists($this->pl_dir)) { if (!file_exists($this->pl_dir)) {
fs_mkdir($this->pl_dir); fs_mkdir($this->pl_dir);
@ -35,7 +44,8 @@ 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) {
@ -62,18 +72,20 @@ 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;
} }
@ -85,10 +97,10 @@ class plugin_commentcenter {
$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']);
@ -118,7 +130,7 @@ class plugin_commentcenter {
$_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,7 +143,8 @@ 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 = '') {
@ -171,8 +184,10 @@ 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) {
@ -205,14 +220,16 @@ 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;
} }
@ -220,18 +237,18 @@ class plugin_commentcenter {
$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) {
@ -256,14 +273,18 @@ class plugin_commentcenter {
*/ */
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) {
@ -271,14 +292,18 @@ class plugin_commentcenter {
} }
$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])) {
@ -300,8 +325,10 @@ 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()) {
@ -350,9 +377,12 @@ 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 = '') {
@ -360,15 +390,19 @@ class plugin_commentcenter {
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) {
@ -381,12 +415,21 @@ class plugin_commentcenter {
$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);
} }
@ -399,12 +442,13 @@ $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);
} }
@ -434,9 +478,10 @@ class commentcenter_list extends fs_filelister {
} }
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';