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

View File

@ -1,11 +1,12 @@
<?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
*/
/**
@ -13,19 +14,27 @@ Author URI: http://www.vdfn.altervista.org/
*/
class plugin_commentcenter {
# The plugin configuration
// The plugin configuration
var $conf = array();
# The policies
// The policies
var $policies = array();
# The plugin_dir
// 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);
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,7 +44,8 @@ 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) {
@ -62,18 +72,20 @@ 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 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 the comment has been made from an administrator, don't check it
if (@$comment ['loggedin']) {
return true;
}
@ -85,10 +97,10 @@ class plugin_commentcenter {
$comment ['id'] = bdb_idfromtime(BDB_COMMENT, $comment ['date']);
$conf = $this->getConf();
# This variables defines how the system has to behave.
// 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']);
@ -118,7 +130,7 @@ class plugin_commentcenter {
$_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;
}
@ -131,7 +143,8 @@ 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 = '') {
@ -171,8 +184,10 @@ 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) {
@ -205,14 +220,16 @@ 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
// 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;
}
@ -220,18 +237,18 @@ class plugin_commentcenter {
$clean = $this->akismetClean($comment, $entry);
$akismet->setComment($clean);
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;
} 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) {
@ -256,14 +273,18 @@ class plugin_commentcenter {
*/
function savePolicies() {
$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.
*
* @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) {
@ -271,14 +292,18 @@ class plugin_commentcenter {
}
$before = array_slice($this->policies, 0, $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.
*
* @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])) {
@ -300,8 +325,10 @@ 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()) {
@ -350,9 +377,12 @@ 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 = '') {
@ -360,15 +390,19 @@ class plugin_commentcenter {
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) {
@ -381,12 +415,21 @@ class plugin_commentcenter {
$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 = 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);
}
@ -399,12 +442,13 @@ $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);
}
@ -434,9 +478,10 @@ class commentcenter_list extends fs_filelister {
}
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')) {
include dirname(__FILE__) . '/inc/admin.php';
include dirname(__FILE__) . '/inc/jslang.php';