2012-01-06 00:01:22 +01:00
< ? php
if ( IN_serendipity !== true ) {
die ( " Don't hack! " );
}
// Probe for a language include with constants. Still include defines later on, if some constants were missing
$probelang = dirname ( __FILE__ ) . '/' . $serendipity [ 'charset' ] . 'lang_' . $serendipity [ 'lang' ] . '.inc.php' ;
if ( file_exists ( $probelang )) {
include $probelang ;
}
include dirname ( __FILE__ ) . '/lang_en.inc.php' ;
2012-01-11 14:55:43 +01:00
require_once dirname ( __FILE__ ) . '/DbSpice.class.php' ;
require_once dirname ( __FILE__ ) . '/json/json.php4.include.php' ;
2012-01-21 16:10:06 +01:00
@ define ( 'PLUGIN_EVENT_COMMENTSPICE_DEBUG' , FALSE );
2012-01-06 00:01:22 +01:00
class serendipity_event_commentspice extends serendipity_event
{
var $title = PLUGIN_EVENT_COMMENTSPICE_TITLE ;
2012-01-28 15:37:19 +01:00
2012-01-06 00:01:22 +01:00
function introspect ( & $propbag )
{
global $serendipity ;
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_TITLE );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_DESC );
$propbag -> add ( 'stackable' , false );
$propbag -> add ( 'author' , 'Grischa Brockhaus' );
$propbag -> add ( 'requirements' , array (
'serendipity' => '0.8' ,
'smarty' => '2.6.7' ,
'php' => '4.1.0'
));
2012-01-21 16:10:06 +01:00
$propbag -> add ( 'version' , '1.0' );
2012-01-06 00:01:22 +01:00
$propbag -> add ( 'event_hooks' , array (
2012-01-28 15:37:19 +01:00
'entry_display' => true ,
2012-01-11 14:55:43 +01:00
'frontend_footer' => true ,
2012-01-06 00:01:22 +01:00
'frontend_comment' => true ,
2012-01-06 02:44:46 +01:00
'frontend_display' => true ,
2012-01-18 23:13:28 +01:00
'frontend_saveComment' => true ,
'frontend_saveComment_finish' => true ,
2012-01-11 14:55:43 +01:00
'backend_deletecomment' => true ,
2012-01-06 00:01:22 +01:00
'external_plugin' => true ,
2012-01-21 16:10:06 +01:00
'css' => true ,
2012-01-22 23:39:20 +01:00
'avatar_fetch_userinfos' => true ,
2012-01-06 00:01:22 +01:00
));
2012-06-23 17:58:43 +02:00
$propbag -> add ( 'groups' , array ( 'FRONTEND_VIEWS' , 'ANTISPAM' ));
2012-01-28 15:37:19 +01:00
$config_switchexpert = array ( 'expert_switch' );
$config_twitter = array ( 'title_twitter' , 'twitterinput' , 'followme_widget' , 'followme_widget_counter' , 'followme_widget_dark' );
$config_twitter_expert = array ( 'twitterinput_nofollow' , 'smartifytwitter' , 'inputpatched_twitter' );
$config_announce = array ( 'title_announcerss' , 'announcerss' , 'announcerssmax' );
$config_announce_expert = array ( 'announcersscachemin' , 'announcerss_nofollow' , 'smartifyannouncerss' , 'inputpatched_rss' );
2012-01-29 23:59:11 +01:00
$config_rules = array ( 'title_rules' , 'rule_extras_commentcount' , 'rule_extras_commentlength' );
$config_rules_extra = array ( 'rule_dofollow_commentcount' , 'rule_dofollow_commentlength' );
2012-02-03 02:05:50 +01:00
$config_boo = array ( 'title_boo' , 'allow_boo' , 'moderate_boo' );
2012-06-23 15:35:49 +02:00
$config_spam = array ( 'title_spam' , 'do_honeypot' );
$config_spam_expert = array ( 'spamlogtype' , 'spamlogfile' );
2012-01-28 15:37:19 +01:00
$config_general = array ( 'title_general' );
2012-01-29 15:15:16 +01:00
if ( ! class_exists ( 'serendipity_event_spamblock' )) { // Only do that, if spamblock is not installed.
$config_general [] = 'required_fields' ;
}
2012-01-26 13:50:43 +01:00
if ( function_exists ( 'fetchPingbackData' ) && $this -> isLocalConfigWritable ()) {
2012-01-28 15:37:19 +01:00
$config_general [] = 'fetchPingback' ;
}
$config_general_expert = array ( 'plugin_path' );
$open_expert_setting = isset ( $_GET [ 'pluginexpert' ]);
if ( $open_expert_setting ) {
2012-06-23 15:35:49 +02:00
$configuration = array_merge ( $config_switchexpert , $config_twitter , $config_twitter_expert , $config_announce , $config_announce_expert , $config_boo , $config_rules , $config_rules_extra , $config_spam , $config_spam_expert , $config_general , $config_general_expert );
2012-01-28 15:37:19 +01:00
}
else {
2012-06-23 15:35:49 +02:00
$configuration = array_merge ( $config_switchexpert , $config_twitter , $config_announce , $config_rules , $config_spam , $config_general );
2012-01-22 23:39:20 +01:00
}
2012-01-28 15:37:19 +01:00
$propbag -> add ( 'configuration' , $configuration );
2012-01-06 00:01:22 +01:00
}
function generate_content ( & $title ) {
$title = PLUGIN_EVENT_EMOTICONCHOOSER_TITLE ;
}
function introspect_config_item ( $name , & $propbag )
{
2012-01-11 14:55:43 +01:00
global $serendipity ;
2012-01-29 23:59:11 +01:00
$yesnorules = array (
" enabled " => PLUGIN_EVENT_COMMENTSPICE_ENABLED ,
" disabled " => PLUGIN_EVENT_COMMENTSPICE_DISABED ,
" rules " => PLUGIN_EVENT_COMMENTSPICE_RULES ,
);
2012-01-06 00:01:22 +01:00
switch ( $name ) {
2012-01-28 15:37:19 +01:00
case 'expert_switch' :
$actConfigUrl = $_SERVER [ " REQUEST_URI " ];
$querypar = " &pluginexpert " ;
if ( strpos ( $actConfigUrl , $querypar ) === FALSE ) {
$tablink = $actConfigUrl . $querypar ;
$tabvalue = PLUGIN_EVENT_COMMENTSPICE_EXPERTSETTINGS ;
}
else {
$tablink = str_replace ( $querypar , '' , $actConfigUrl );
$tabvalue = PLUGIN_EVENT_COMMENTSPICE_STANDARDSETTINGS ;
}
$htmlswitchline .= '<img src="' . $serendipity [ 'baseURL' ] . 'index.php?/plugin/commentspice.png" style="float:right"> [<a href="' . $tablink . '" class="serendipity_pluginconfig_tab">' . $tabvalue . '</a>] ' ;
$propbag -> add ( 'type' , 'content' );
$propbag -> add ( 'default' , $htmlswitchline );
break ;
2012-01-29 23:59:11 +01:00
case 'title_twitter' :
$propbag -> add ( 'type' , 'content' );
$propbag -> add ( 'default' , '<h3>' . PLUGIN_EVENT_COMMENTSPICE_CONFIG_TWITTERNAME . '</h3>' );
break ;
2012-01-06 00:01:22 +01:00
case 'twitterinput' :
2012-01-29 23:59:11 +01:00
$propbag -> add ( 'type' , 'select' );
2012-01-06 00:01:22 +01:00
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_TWITTERINPUT );
2012-01-18 23:13:28 +01:00
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_TWITTERINPUT_DESC );
2012-01-29 23:59:11 +01:00
$propbag -> add ( 'select_values' , $yesnorules );
$propbag -> add ( 'default' , 'enabled' );
2012-01-06 00:01:22 +01:00
break ;
2012-01-20 12:03:23 +01:00
case 'twitterinput_nofollow' :
2012-01-29 23:59:11 +01:00
$propbag -> add ( 'type' , 'select' );
2012-01-20 12:03:23 +01:00
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_TWITTERINPUT_NOFOLLOW );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_TWITTERINPUT_NOFOLLOW_DESC );
2012-01-29 23:59:11 +01:00
$propbag -> add ( 'select_values' , $yesnorules );
$propbag -> add ( 'default' , 'enabled' );
2012-01-24 01:49:44 +01:00
break ;
case 'followme_widget' :
$propbag -> add ( 'type' , 'boolean' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_FOLLOWME_WIDGET );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_FOLLOWME_WIDGET_DESC );
$propbag -> add ( 'default' , false );
break ;
case 'followme_widget_counter' :
$propbag -> add ( 'type' , 'boolean' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_FOLLOWME_WIDGET_COUNT );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_FOLLOWME_WIDGET_COUNT_DESC );
$propbag -> add ( 'default' , false );
break ;
case 'followme_widget_dark' :
$propbag -> add ( 'type' , 'boolean' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_FOLLOWME_WIDGET_DARK );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_FOLLOWME_WIDGET_DARK_DESC );
$propbag -> add ( 'default' , false );
2012-01-20 12:03:23 +01:00
break ;
2012-01-29 23:59:11 +01:00
case 'title_announcerss' :
$propbag -> add ( 'type' , 'content' );
$propbag -> add ( 'default' , '<br/><h3>' . PLUGIN_EVENT_COMMENTSPICE_CONFIG_ANNOUNC_RSS . '</h3>' );
break ;
2012-01-11 14:55:43 +01:00
case 'announcerss' :
2012-01-29 23:59:11 +01:00
$propbag -> add ( 'type' , 'select' );
2012-01-11 14:55:43 +01:00
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_ANNOUNCE_RSS );
2012-01-18 23:13:28 +01:00
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_ANNOUNCE_RSS_DESC );
2012-01-29 23:59:11 +01:00
$propbag -> add ( 'select_values' , $yesnorules );
$propbag -> add ( 'default' , 'disabled' );
2012-01-11 14:55:43 +01:00
break ;
2012-01-20 12:03:23 +01:00
case 'announcerss_nofollow' :
2012-01-29 23:59:11 +01:00
$propbag -> add ( 'type' , 'select' );
2012-01-20 12:03:23 +01:00
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_ANNOUNCE_RSS_NOFOLLOW );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_ANNOUNCE_RSS_NOFOLLOW_DESC );
2012-01-29 23:59:11 +01:00
$propbag -> add ( 'select_values' , $yesnorules );
$propbag -> add ( 'default' , 'disabled' );
2012-01-20 12:03:23 +01:00
break ;
2012-01-18 23:13:28 +01:00
case 'announcerssmax' :
$propbag -> add ( 'type' , 'string' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_ANNOUNCE_RSS_MAXSELECT );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_ANNOUNCE_RSS_MAXSELECT_DESC );
2012-01-21 16:10:06 +01:00
$propbag -> add ( 'default' , 3 );
2012-01-24 01:49:44 +01:00
break ;
2012-01-21 17:29:25 +01:00
case 'announcersscachemin' :
$propbag -> add ( 'type' , 'string' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_ANNOUNCE_RSS_CACHEMIN );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_ANNOUNCE_RSS_CACHEMIN_DESC );
$propbag -> add ( 'default' , 90 );
2012-01-24 01:49:44 +01:00
break ;
2012-01-21 18:46:54 +01:00
case 'smartifytwitter' :
$propbag -> add ( 'type' , 'boolean' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_SMARTIFY_TWITTER );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_SMARTIFY_TWITTER_DESC );
$propbag -> add ( 'default' , false );
break ;
case 'smartifyannouncerss' :
$propbag -> add ( 'type' , 'boolean' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_SMARTIFY_RSS );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_SMARTIFY_RSS_DESC );
$propbag -> add ( 'default' , false );
break ;
2012-01-28 15:37:19 +01:00
case 'inputpatched_twitter' :
$propbag -> add ( 'type' , 'boolean' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_PATCHEDINPUT_TWITTER );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_PATCHEDINPUT_TWITTER_DESC );
$propbag -> add ( 'default' , false );
break ;
case 'inputpatched_rss' :
$propbag -> add ( 'type' , 'boolean' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_PATCHEDINPUT_RSS );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_PATCHEDINPUT_RSS_DESC );
$propbag -> add ( 'default' , false );
break ;
2012-01-29 23:59:11 +01:00
2012-02-03 02:05:50 +01:00
case 'title_boo' :
$propbag -> add ( 'type' , 'content' );
$propbag -> add ( 'default' , '<br/><h3>' . PLUGIN_EVENT_COMMENTSPICE_CONFIG_BOO . '</h3>' . PLUGIN_EVENT_COMMENTSPICE_CONFIG_BOO_DESC );
break ;
case 'allow_boo' :
$propbag -> add ( 'type' , 'boolean' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_BOO_ALLOW );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_BOO_ALLOW_DESC );
$propbag -> add ( 'default' , false );
break ;
case 'moderate_boo' :
$propbag -> add ( 'type' , 'boolean' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_BOO_MODERATE );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_BOO_MODERATE_DESC );
$propbag -> add ( 'default' , true );
break ;
2012-01-29 23:59:11 +01:00
case 'title_rules' :
$propbag -> add ( 'type' , 'content' );
$propbag -> add ( 'default' , '<br/><h3>' . PLUGIN_EVENT_COMMENTSPICE_CONFIG_RULES . '</h3>' );
break ;
case 'rule_extras_commentcount' :
$propbag -> add ( 'type' , 'string' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_RULE_EXTRAS_COMMENTCOUNT );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_RULE_EXTRAS_COMMENTCOUNT_DESC );
$propbag -> add ( 'default' , 0 );
break ;
case 'rule_extras_commentlength' :
$propbag -> add ( 'type' , 'string' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_RULE_EXTRAS_COMMENTLENGTH );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_RULE_EXTRAS_COMMENTLENGTH_DESC );
$propbag -> add ( 'default' , 0 );
break ;
case 'rule_dofollow_commentcount' :
$propbag -> add ( 'type' , 'string' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_RULE_DOFOLLOW_COMMENTCOUNT );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_RULE_DOFOLLOW_COMMENTCOUNT_DESC );
$propbag -> add ( 'default' , 0 );
break ;
case 'rule_dofollow_commentlength' :
$propbag -> add ( 'type' , 'string' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_RULE_DOFOLLOW_COMMENTLENGTH );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_RULE_DOFOLLOW_COMMENTLENGTH_DESC );
$propbag -> add ( 'default' , 0 );
break ;
2012-06-23 15:35:49 +02:00
case 'title_spam' :
$propbag -> add ( 'type' , 'content' );
$propbag -> add ( 'default' , '<br/><h3>' . PLUGIN_EVENT_COMMENTSPICE_CONFIG_SPAM . '</h3>' );
break ;
case 'do_honeypot' :
$propbag -> add ( 'type' , 'boolean' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_CONFIG_SPAM_HONEYPOT );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_CONFIG_SPAM_HONEYPOT_DESC );
$propbag -> add ( 'default' , true );
break ;
case 'spamlogtype' :
$logtypevalues = array (
'none' => PLUGIN_EVENT_COMMENTSPICE_CONFIG_SPAM_LOGTYPE_NONE ,
'file' => PLUGIN_EVENT_COMMENTSPICE_CONFIG_SPAM_LOGTYPE_FILE ,
'db' => PLUGIN_EVENT_COMMENTSPICE_CONFIG_SPAM_LOGTYPE_DATABASE ,
);
$propbag -> add ( 'type' , 'select' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_CONFIG_SPAM_LOGTYPE );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_CONFIG_SPAM_LOGTYPE_DESC );
$propbag -> add ( 'select_values' , $logtypevalues );
$propbag -> add ( 'default' , 'none' );
break ;
case 'spamlogfile' :
$propbag -> add ( 'type' , 'string' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_CONFIG_SPAM_LOGFILE );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_CONFIG_SPAM_LOGFILE_DESC );
$propbag -> add ( 'default' , $serendipity [ 'serendipityPath' ] . 'spamblock.log' );
break ;
2012-01-29 23:59:11 +01:00
case 'title_general' :
$propbag -> add ( 'type' , 'content' );
$propbag -> add ( 'default' , '<br/><h3>' . PLUGIN_EVENT_COMMENTSPICE_CONFIG_GENERAL . '</h3>' );
break ;
2012-01-29 15:15:16 +01:00
case 'required_fields' :
$propbag -> add ( 'type' , 'string' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_REQUIRED_FIELDS );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_REQUIRED_FIELDS_DESC );
$propbag -> add ( 'default' , '' );
break ;
2012-01-11 14:55:43 +01:00
case 'plugin_path' :
$propbag -> add ( 'type' , 'string' );
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_PATH );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_PATH_DESC );
$propbag -> add ( 'default' , $serendipity [ 'serendipityHTTPPath' ] . 'plugins/serendipity_event_commentspice/' );
break ;
2012-01-22 23:39:20 +01:00
case 'fetchPingback' :
2012-01-26 13:50:43 +01:00
$fetchPingbackValues = array (
'none' => $serendipity [ 'pingbackFetchPage' ] ? PLUGIN_EVENT_COMMENTSPICE_FETCH_PINGBACK_LEAVE_ON : PLUGIN_EVENT_COMMENTSPICE_FETCH_PINGBACK_LEAVE_OFF ,
);
if ( $serendipity [ 'pingbackFetchPage' ]) $fetchPingbackValues [ 'false' ] = PLUGIN_EVENT_COMMENTSPICE_FETCH_PINGBACK_DONTFETCH ;
else $fetchPingbackValues [ 'true' ] = PLUGIN_EVENT_COMMENTSPICE_FETCH_PINGBACK_FETCH ;
$propbag -> add ( 'type' , 'select' );
2012-01-22 23:39:20 +01:00
$propbag -> add ( 'name' , PLUGIN_EVENT_COMMENTSPICE_FETCH_PINGBACK );
$propbag -> add ( 'description' , PLUGIN_EVENT_COMMENTSPICE_FETCH_PINGBACK_DESC );
2012-01-26 13:50:43 +01:00
$propbag -> add ( 'select_values' , $fetchPingbackValues );
$propbag -> add ( 'default' , 'none' );
2012-01-22 23:39:20 +01:00
break ;
2012-02-03 02:05:50 +01:00
2012-01-24 01:49:44 +01:00
default :
return false ;
2012-01-06 00:01:22 +01:00
}
2012-01-24 01:49:44 +01:00
return true ;
2012-01-06 00:01:22 +01:00
}
2012-06-13 12:52:47 +02:00
function event_hook ( $event , & $bag , & $eventData , $addData = null ) {
2012-01-06 00:01:22 +01:00
global $serendipity ;
$hooks = & $bag -> get ( 'event_hooks' );
if ( isset ( $hooks [ $event ])) {
switch ( $event ) {
case 'external_plugin' :
switch ( $eventData ) {
2012-01-21 16:10:06 +01:00
case 'spiceicotwitter.png' :
header ( 'Content-Type: image/png' );
echo file_get_contents ( dirname ( __FILE__ ) . '/img/twitter_icon.png' );
break ;
2012-03-11 04:02:15 +01:00
case 'spiceicoidentica.png' :
header ( 'Content-Type: image/png' );
echo file_get_contents ( dirname ( __FILE__ ) . '/img/identica_icon.png' );
break ;
2012-01-21 16:10:06 +01:00
case 'spiceicorss.png' :
2012-01-06 00:01:22 +01:00
header ( 'Content-Type: image/png' );
2012-01-21 16:10:06 +01:00
echo file_get_contents ( dirname ( __FILE__ ) . '/img/rss_icon.png' );
2012-01-06 00:01:22 +01:00
break ;
2012-01-21 16:10:06 +01:00
case 'commentspice.png' :
2012-01-06 02:44:46 +01:00
header ( 'Content-Type: image/png' );
2012-01-21 16:10:06 +01:00
echo file_get_contents ( dirname ( __FILE__ ) . '/img/commentspice.png' );
2012-01-06 02:44:46 +01:00
break ;
2012-01-11 14:55:43 +01:00
case 'commentspicefrss' :
2012-01-29 23:59:11 +01:00
//if (!serendipity_db_bool($this->get_config('announcerss', false))) break;
2012-01-11 14:55:43 +01:00
$this -> readRss ();
break ;
2012-02-03 02:05:50 +01:00
case 'audioboo.png' :
header ( 'Content-Type: image/png' );
echo file_get_contents ( dirname ( __FILE__ ) . '/img/audioboo.png' );
break ;
case 'spiceicorecord.png' :
header ( 'Content-Type: image/png' );
echo file_get_contents ( dirname ( __FILE__ ) . '/img/microphone.png' );
break ;
2012-01-06 00:01:22 +01:00
}
break ;
2012-01-28 15:37:19 +01:00
case 'entry_display' :
$this -> spiceEntry ( $eventData , $addData );
break ;
2012-01-18 23:13:28 +01:00
case 'frontend_saveComment' :
2012-01-22 23:39:20 +01:00
$result = $this -> checkComment ( $eventData , $addData );
return $result ;
2012-01-18 23:13:28 +01:00
break ;
2012-01-06 02:44:46 +01:00
case 'frontend_saveComment_finish' :
2012-01-11 14:55:43 +01:00
$this -> commentSaved ( $eventData , $addData );
break ;
case 'frontend_footer' :
2012-06-22 19:29:14 +02:00
// Comment header code only if in single article mode
if ( ! empty ( $eventData [ 'GET' ][ 'id' ])) {
$this -> printHeader ();
}
2012-01-06 02:44:46 +01:00
break ;
case 'frontend_display' :
2012-01-18 23:13:28 +01:00
$this -> spiceComment ( $eventData , $addData );
2012-01-06 02:44:46 +01:00
break ;
case 'frontend_comment' :
2012-01-11 14:55:43 +01:00
$this -> printCommentEditExtras ( $eventData , $addData );
break ;
case 'backend_deletecomment' :
$this -> commentDeleted ( $eventData , $addData );
2012-01-06 00:01:22 +01:00
break ;
2012-01-21 16:10:06 +01:00
case 'css' :
2012-06-23 15:35:49 +02:00
$this -> printCss ( $eventData , $addData );
2012-01-21 16:10:06 +01:00
break ;
2012-01-22 23:39:20 +01:00
case 'avatar_fetch_userinfos' :
$this -> log ( " caught avatar_fetch_userinfos " );
$this -> handleAvatar ( $eventData , $addData );
break ;
2012-01-06 00:01:22 +01:00
default :
return false ;
break ;
}
2012-01-11 14:55:43 +01:00
return true ;
2012-01-06 00:01:22 +01:00
} else {
return false ;
}
}
2012-01-11 14:55:43 +01:00
function install () {
DbSpice :: install ( $this );
}
function cleanup () {
2012-01-26 13:50:43 +01:00
global $serendipity ;
2012-01-11 14:55:43 +01:00
DbSpice :: install ( $this );
2012-01-21 16:10:06 +01:00
$announcerssmax = $this -> get_config ( 'announcerssmax' , 3 );
if ( ! is_numeric ( $announcerssmax )) {
$this -> set_config ( 'announcerssmax' , 3 );
}
2012-01-21 17:29:25 +01:00
$announcersscachemin = $this -> get_config ( 'announcersscachemin' , 90 );
if ( ! is_numeric ( $announcersscachemin )) {
$this -> set_config ( 'announcersscachemin' , 90 );
}
2012-01-29 23:59:11 +01:00
// Asure numeric inputs for rule settings
$config_rules = array ( 'rule_extras_commentcount' , 'rule_extras_commentlength' , 'rule_dofollow_commentcount' , 'rule_dofollow_commentlength' );
foreach ( $config_rules as $config_rule ) {
$check = $this -> get_config ( $config_rule , 0 );
if ( ! is_numeric ( $check )) {
$this -> set_config ( $check , 0 );
}
}
2012-01-21 17:29:25 +01:00
// clear cache
$cacheDir = dirname ( $this -> cacheRssFilename ( " doesntmatter " ));
if ( is_dir ( $cacheDir ) && $handle = opendir ( $cacheDir )) {
while ( false !== ( $file = readdir ( $handle ))) {
$filename = $cacheDir . '/' . $file ;
if ( ! is_dir ( $filename )) {
unlink ( $filename );
}
}
}
2012-01-11 14:55:43 +01:00
}
2012-01-21 17:29:25 +01:00
2012-01-11 14:55:43 +01:00
function printHeader () {
global $serendipity ;
2012-01-29 23:59:11 +01:00
if ( $this -> get_config ( 'announcerss' , 'disabled' ) != 'disabled' )
2012-01-11 14:55:43 +01:00
{
$path = $this -> path = $this -> get_config ( 'plugin_path' , $serendipity [ 'serendipityHTTPPath' ] . 'plugins/serendipity_event_commentspice/' );
2012-01-29 23:59:11 +01:00
$announce_changedby_email = ( 'rules' == $this -> get_config ( 'announcerss' , 'disabled' ) && $this -> get_config ( 'rule_extras_commentcount' , 0 )) ? 'true' : 'false' ;
2012-01-11 14:55:43 +01:00
echo "
< script >
var comentspice_fetchrss = '{$serendipity[' baseURL ']}index.php?/plugin/commentspicefrss' ;
2012-01-29 23:59:11 +01:00
var comentspice_fetchrss_emailchanges = $announce_changedby_email ;
2012-01-11 14:55:43 +01:00
var s9yCharset = '".LANG_CHARSET."' ;
</ script >
< script type = \ " text/javascript \" src= \" { $path } frontend_commentspice.js \" ></script>
" ;
}
2012-06-22 19:29:14 +02:00
2012-01-24 01:49:44 +01:00
if ( serendipity_db_bool ( $this -> get_config ( 'followme_widget' , false ))) {
2012-06-22 19:29:14 +02:00
echo '<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>' . " \n " ;
2012-01-24 01:49:44 +01:00
}
2012-01-11 14:55:43 +01:00
}
function commentSaved ( $eventData , $addData ) {
global $serendipity ;
2012-01-22 23:39:20 +01:00
$this -> log ( " commentSaved: " . print_r ( $eventData , true ) . " \n " . print_r ( $addData , TRUE ));
2012-01-11 14:55:43 +01:00
if ( " NORMAL " == $addData [ 'type' ]) { // only supported for normal comments
2012-01-18 23:13:28 +01:00
$promo_name = null ;
$promo_url = null ;
2012-01-29 23:59:11 +01:00
2012-02-03 02:05:50 +01:00
// I save no matter what the rules say, it wont display later.
2012-03-11 03:27:51 +01:00
$twittername = ltrim ( trim ( $serendipity [ 'POST' ][ 'twitter' ]), '@' );
2012-02-03 02:05:50 +01:00
$boourl = $serendipity [ 'POST' ][ 'boo' ];
2012-01-18 23:13:28 +01:00
if ( isset ( $serendipity [ 'POST' ][ 'promorss' ]) && ! empty ( $serendipity [ 'POST' ][ 'promorss' ])) {
$promorss = $serendipity [ 'POST' ][ 'promorss' ];
$parts = explode ( " \n " , $promorss );
$promo_hash = trim ( $parts [ 0 ]);
$promo_name = trim ( $parts [ 1 ]);
$promo_url = trim ( $parts [ 2 ]);
if ( ! $this -> hashString ( $promo_name . $promo_url ) == $promo_hash ) return false ;
2012-01-11 14:55:43 +01:00
}
2012-02-03 02:05:50 +01:00
$result = DbSpice :: saveCommentSpice ( $addData [ 'comment_cid' ], $twittername , $promo_name , $promo_url , $boourl );
2012-01-18 23:13:28 +01:00
$this -> rememberInputs ();
}
return true ;
}
2012-01-29 23:59:11 +01:00
function checkRules ( $email , $comment , $checkCommentLength = true , $checknofollow = false ) {
$rule_twitter = $this -> get_config ( 'twitterinput' , 'enabled' );
$rule_announce = $this -> get_config ( 'announcerss' , 'disabled' );
$rule_twitter_nofollow = $this -> get_config ( 'twitterinput_nofollow' , 'enabled' );
$rule_announce_nofollow = $this -> get_config ( 'announcerss_nofollow' , 'disabled' );
$this -> log ( " anf: $rule_announce_nofollow , tnf: $rule_twitter_nofollow " );
$result = array ();
$result [ 'allow_twitter' ] = $rule_twitter != 'disabled' ;
$result [ 'allow_announce' ] = $rule_announce != 'disabled' ;
$result [ 'nofollow_twitter' ] = $rule_twitter_nofollow == 'enabled' ;
$result [ 'nofollow_announce' ] = $rule_announce_nofollow == 'enabled' ;
2012-02-03 02:05:50 +01:00
$result [ 'allow_boo' ] = true ;
2012-01-29 23:59:11 +01:00
$commentcount = - 1 ;
if ( 'rules' == $rule_announce || 'rules' == $rule_twitter ) {
// Check for comment length
if ( $checkCommentLength ) {
$rule_commentlenght = ( int ) $this -> get_config ( 'rule_extras_commentlength' , 0 );
$commentlen = empty ( $comment ) ? 0 : strlen ( $comment );
$comment_enough = $commentlen >= $rule_commentlenght ;
if ( 'rules' == $rule_twitter ) $result [ 'allow_twitter' ] = $result [ 'allow_twitter' ] && $comment_enough ;
if ( 'rules' == $rule_announce ) $result [ 'allow_announce' ] = $result [ 'allow_announce' ] && $comment_enough ;
}
// Check for comment count
$rule_commentcount = ( int ) $this -> get_config ( 'rule_extras_commentcount' , 0 );
if ( $rule_commentcount > 0 ) {
$commentcount = DbSpice :: countComments ( $email );
$more_comments = ( int ) $commentcount >= $rule_commentcount ;
if ( 'rules' == $rule_twitter ) $result [ 'allow_twitter' ] = $result [ 'allow_twitter' ] && $more_comments ;
if ( 'rules' == $rule_announce ) $result [ 'allow_announce' ] = $result [ 'allow_announce' ] && $more_comments ;
}
}
if ( $checknofollow && ( 'rules' == $rule_announce_nofollow || 'rules' == $rule_twitter_nofollow )) {
// Check for comment length
if ( $checkCommentLength ) {
$rule_commentlenght = ( int ) $this -> get_config ( 'rule_dofollow_commentlength' , 0 );
$commentlen = empty ( $comment ) ? 0 : strlen ( $comment );
$comment_enough = $commentlen >= $rule_commentlenght ;
$this -> log ( " checkCommentLenght. len: $commentlen , rulen: $rule_commentlenght - enough: $comment_enough " );
if ( 'rules' == $rule_twitter_nofollow ) $result [ 'nofollow_twitter' ] = $result [ 'nofollow_twitter' ] || ! $comment_enough ;
if ( 'rules' == $rule_announce_nofollow ) $result [ 'nofollow_announce' ] = $result [ 'nofollow_announce' ] || ! $comment_enough ;
}
// Check for comment count
$rule_commentcount = ( int ) $this -> get_config ( 'rule_dofollow_commentcount' , 0 );
if ( $rule_commentcount > 0 ) {
$commentcount = ( $commentcount ==- 1 ? DbSpice :: countComments ( $email ) : $commentcount );
$more_comments = ( int ) $commentcount >= $rule_commentcount ;
$this -> log ( " checkCommentCount. cnt: $commentcount , rucnt: $rule_commentcount - more: $more_comments " );
if ( 'rules' == $rule_twitter_nofollow ) $result [ 'nofollow_twitter' ] = $result [ 'nofollow_twitter' ] || ! $more_comments ;
if ( 'rules' == $rule_announce_nofollow ) $result [ 'nofollow_announce' ] = $result [ 'nofollow_announce' ] || ! $more_comments ;
}
}
$this -> log ( " checkRules( $email , $comment , $checkCommentLength , $checknofollow ): " . print_r ( $result , true ));
return $result ;
}
2012-01-18 23:13:28 +01:00
function rememberInputs () {
global $serendipity ;
// Remember twitter name value into cookie, if user ordered to, else clear cookie
if ( isset ( $serendipity [ 'POST' ][ 'remember' ])) {
2012-03-11 03:27:51 +01:00
// Remember twitter name, remove leading @ if found
serendipity_rememberCommentDetails ( array ( 'twitter' => ltrim ( trim ( $serendipity [ 'POST' ][ 'twitter' ]), '@' )));
2012-01-18 23:13:28 +01:00
}
else {
serendipity_forgetCommentDetails ( array ( 'twitter' ));
}
}
function checkComment ( & $eventData , & $addData ) {
global $serendipity ;
if ( " NORMAL " == $addData [ 'type' ]) { // only supported for normal comments
$this -> rememberInputs ();
2012-06-23 15:35:49 +02:00
// Check for honeypot:
$do_honepot = serendipity_db_bool ( $this -> get_config ( 'do_honeypot' , true ));
if ( $do_honepot && ! empty ( $serendipity [ 'POST' ][ 'phone' ]) ) {
$logfile = $this -> get_config ( 'spamlogfile' , $serendipity [ 'serendipityPath' ] . 'spamblock.log' );
$this -> spamlog ( $logfile , $eventData [ 'id' ], 'REJECTED' , $serendipity [ 'POST' ][ 'phone' ], $addData );
$eventData = array ( 'allow_comments' => false );
return false ;
}
2012-01-18 23:13:28 +01:00
2012-01-29 15:15:16 +01:00
// Check, if all required fields are set, but only if spamblock is not installed.
if ( ! class_exists ( 'serendipity_event_spamblock' )) {
$required_fields = $this -> get_config ( 'required_fields' , '' );
if ( ! empty ( $required_fields )) {
$required_field_list = explode ( ',' , $required_fields );
foreach ( $required_field_list as $required_field ) {
$required_field = trim ( $required_field );
if ( empty ( $addData [ $required_field ])) {
$this -> log ( $logfile , $eventData [ 'id' ], 'REJECTED' , PLUGIN_EVENT_COMMENTSPICE_REASON_REQUIRED_FIELD , $addData );
$eventData = array ( 'allow_comments' => false );
$serendipity [ 'messagestack' ][ 'comments' ][] = sprintf ( PLUGIN_EVENT_COMMENTSPICE_REASON_REQUIRED_FIELD , $required_field );
return false ;
}
}
}
}
// Check, if promoted URL is still valid (unmodified)
2012-01-18 23:13:28 +01:00
if ( isset ( $serendipity [ 'POST' ][ 'promorss' ]) && ! empty ( $serendipity [ 'POST' ][ 'promorss' ])) {
$promorss = $serendipity [ 'POST' ][ 'promorss' ];
$parts = explode ( " \n " , $promorss );
$promo_hash = trim ( $parts [ 0 ]);
$promo_name = trim ( $parts [ 1 ]);
$promo_url = trim ( $parts [ 2 ]);
if ( $this -> hashString ( $promo_name . $promo_url ) != $promo_hash ) {
$eventData = array ( 'allow_comments' => false );
$serendipity [ 'messagestack' ] [ 'comments' ] [] = PLUGIN_EVENT_COMMENTSPICE_PROMOTE_ARTICLE_CORRUPTED ;
return false ;
}
2012-01-11 14:55:43 +01:00
}
2012-02-03 02:05:50 +01:00
// Check, if an boo URL was set and if it seems to be valid:
if ( isset ( $serendipity [ 'POST' ][ 'boo' ]) && ! empty ( $serendipity [ 'POST' ][ 'boo' ])) {
$boourl = $serendipity [ 'POST' ][ 'boo' ];
$isBoo = preg_match ( '@^https?://(audio)?boo.fm/boos/@' , $boourl );
//$isBoo = (strpos($boourl, 'http://audioboo.fm/boos/') === 0 || (strpos($boourl, 'https://audioboo.fm/boos/') === 0));
if ( $isBoo ) {
$test = str_ireplace ( 'https;//' , 'http://' , $boourl );
$test = str_replace ( 'http://audioboo.fm/boos/' , '' , $test );
$test = str_replace ( 'http://boo.fm/boos/' , '' , $test );
$testfields = explode ( '/' , $test );
$isBoo = count ( $testfields ) == 1 ;
if ( $isBoo ) {
$testfields = explode ( '-' , $test );
$isBoo = is_numeric ( $testfields [ 0 ]);
}
}
if ( ! $isBoo ) {
$eventData = array ( 'allow_comments' => false );
$serendipity [ 'messagestack' ] [ 'comments' ] [] = PLUGIN_EVENT_COMMENTSPICE_BOO_WRONG ;
return false ;
}
if ( serendipity_db_bool ( $this -> get_config ( 'moderate_boo' , true ))) {
$eventData [ 'moderate_comments' ] = true ;
$serendipity [ 'csuccess' ] = 'moderate' ;
$serendipity [ 'moderate_reason' ] = sprintf ( PLUGIN_EVENT_COMMENTSPICE_BOO_MODERATED );
}
}
2012-01-11 14:55:43 +01:00
}
2012-01-18 23:13:28 +01:00
return true ;
2012-01-11 14:55:43 +01:00
}
function readRss () {
2012-01-18 23:13:28 +01:00
global $serendipity ;
2012-01-11 14:55:43 +01:00
$comment_url = $_REQUEST [ 'coment_url' ];
2012-01-18 23:13:28 +01:00
$this -> log ( " readRss for $comment_url " );
2012-01-29 23:59:11 +01:00
$comment_email = $_REQUEST [ 'coment_email' ];
$this -> log ( " email= $comment_email " );
$result = array ( " url " => $comment_url , " email " => $comment_email , " articles " => array ());
if ( empty ( $comment_url )) {
echo json_encode ( $result );
return ;
}
$allow = $this -> checkRules ( $comment_email , null , false );
if ( ! $allow [ 'allow_announce' ]) {
$this -> log ( " Announce not allowed by email. result: " . print_r ( $result , TRUE ));
echo json_encode ( $result );
return ;
}
2012-01-21 17:29:25 +01:00
// First try to read from cache
2012-01-25 14:42:14 +01:00
$result = $this -> cacheReadRss ( $comment_url );
2012-01-21 17:29:25 +01:00
if ( empty ( $result )) {
$result = $this -> readRssRemote ( $comment_url );
$this -> log ( " Fetched array: " . print_r ( $result , true ));
2012-01-25 14:42:14 +01:00
if ( ! empty ( $result ) && $result [ 'articles' ]) $this -> cacheWriteRss ( $comment_url , $result );
2012-01-21 17:29:25 +01:00
}
2012-01-29 23:59:11 +01:00
$result [ 'email' ] = $comment_email ;
if ( empty ( $result ) || ! $result [ 'articles' ] || count ( $result [ 'articles' ]) == 0 ) {
echo json_encode ( $result );
return ;
}
2012-01-21 17:29:25 +01:00
echo json_encode ( $result );
}
function readRssRemote ( $url ) {
$this -> log ( " Fetchig remote rss from: " . $url );
2012-01-17 20:39:02 +01:00
require_once ( defined ( 'S9Y_PEAR_PATH' ) ? S9Y_PEAR_PATH : S9Y_INCLUDE_PATH . 'bundled-libs/' ) . 'HTTP/Request.php' ;
2012-01-21 17:29:25 +01:00
$req = new HTTP_Request ( $url , array ( 'allowRedirects' => true , 'maxRedirects' => 3 ));
2012-01-17 20:39:02 +01:00
if ( PEAR :: isError ( $req -> sendRequest ()) || $req -> getResponseCode () != '200' ) {
2012-01-21 17:29:25 +01:00
$this -> log ( " Error reading $url " );
2012-01-17 20:39:02 +01:00
return ;
}
# Fetch html content:
$data = $req -> getResponseBody ();
2012-01-18 23:13:28 +01:00
$this -> log ( " Have data! " );
// Check if page defines a RSS link
2012-01-17 20:39:02 +01:00
$matches = array ();
2012-01-18 23:13:28 +01:00
if ( preg_match ( '@<link[^>]*? type="application/rss\+xml"[^>]*? href="([^"]*?)"@Usi' , $data , $matches )) {
$this -> log ( " rss link found, matches: " . print_r ( $matches [ 1 ], TRUE ));
2012-01-17 20:39:02 +01:00
$rssUrl = $matches [ 1 ];
}
2012-01-18 23:13:28 +01:00
else {
$this -> log ( " rss link not found " );
return ;
}
// Now fetch the RSS feed:
require_once ( defined ( 'S9Y_PEAR_PATH' ) ? S9Y_PEAR_PATH : S9Y_INCLUDE_PATH . 'bundled-libs/' ) . 'Onyx/RSS.php' ;
2012-01-21 17:29:25 +01:00
# test multiple likely charsets
2012-01-18 23:13:28 +01:00
$charsets = array ( " utf-8 " , " ISO-8859-1 " );
$retry = false ;
foreach ( $charsets as $ch ) {
if ( $retry ) $this -> log ( " Retrying charset $ch " );
$retry = true ;
$rss = new Onyx_RSS ( $ch );
# does it parse? if so, all is fine...
if ( $rss -> parse ( $rssUrl ))
break ;
}
2012-01-21 17:29:25 +01:00
2012-01-11 14:55:43 +01:00
$articles = array ();
2012-01-18 23:13:28 +01:00
$article = array ();
$article [ 'title' ] = PLUGIN_EVENT_COMMENTSPICE_PROMOTE_ARTICLE_CHOOSE ;
$article [ 'url' ] = " " ;
$articles [] = $article ;
$itemCount = 0 ;
2012-01-21 16:10:06 +01:00
$maxItems = $announcerssmax = $this -> get_config ( 'announcerssmax' , 3 );
2012-01-18 23:13:28 +01:00
// Iterate the items
while ( $item = $rss -> getNextItem ()) {
if ( $itemCount >= $maxItems ) break ;
2012-01-11 14:55:43 +01:00
$article = array ();
2012-01-18 23:13:28 +01:00
$article [ 'title' ] = $item [ 'title' ];
$hash = $this -> hashString ( $item [ 'title' ] . $item [ 'link' ]);
$article [ 'url' ] = $hash . " \n " . $item [ 'title' ] . " \n " . $item [ 'link' ];
2012-01-11 14:55:43 +01:00
$articles [] = $article ;
2012-01-18 23:13:28 +01:00
$itemCount ++ ;
2012-01-11 14:55:43 +01:00
}
2012-01-21 16:10:06 +01:00
$result [ 'articles' ] = $articles ;
2012-01-21 17:29:25 +01:00
$result [ 'url' ] = $url ;
return $result ;
}
function cacheReadRss ( $url ) {
$filename = $this -> cacheRssFilename ( $url );
$cachemin = $this -> get_config ( 'announcersscachemin' , 90 );
if ( $cachemin == 0 ) return null ;
$this -> log ( " Reading " . $filename );
if ( file_exists ( $filename ) && ( time () - filemtime ( $filename )) < $cachemin * 60 ) {
$fp = fopen ( $filename , 'rb' );
$result = unserialize ( fread ( $fp , filesize ( $filename )));
fclose ( $fp );
return $result ;
}
return null ;
}
function cacheWriteRss ( $url , $array_struct ) {
$cachemin = $this -> get_config ( 'announcersscachemin' , 90 );
if ( $cachemin == 0 ) return ; // cache switched off
$filename = $this -> cacheRssFilename ( $url );
$cache_dir = dirname ( $filename );
@ mkdir ( $cache_dir );
$this -> log ( " Writing " . $filename );
$fp = fopen ( $filename , 'wb' );
fwrite ( $fp , serialize ( $array_struct ));
fclose ( $fp );
}
function cacheRssFilename ( $url ) {
global $serendipity ;
$url_md5 = md5 ( $url );
return $serendipity [ 'serendipityPath' ] . '/' . PATH_SMARTY_COMPILE . '/commentspice/rss_' . $url_md5 ;
2012-01-11 14:55:43 +01:00
}
function commentDeleted ( $eventData , $addData ) {
2012-01-21 17:29:25 +01:00
$result = DbSpice :: deleteCommentSpice ( $addData [ 'cid' ]);
2012-01-11 14:55:43 +01:00
}
2012-01-28 15:37:19 +01:00
function spiceComment ( & $eventData , $addData ) {
2012-01-06 02:44:46 +01:00
global $serendipity ;
2012-01-21 18:46:54 +01:00
if ( ! isset ( $eventData [ 'comment' ])) {
2012-01-06 02:44:46 +01:00
return true ;
}
2012-06-22 19:29:14 +02:00
// Called from sidebar:
2012-01-06 02:44:46 +01:00
if ( $addData [ 'from' ] == 'serendipity_plugin_comments:generate_content' ) {
return true ;
}
2012-01-11 14:55:43 +01:00
$spice = DbSpice :: loadCommentSpice ( $eventData [ 'id' ]);
if ( ! is_array ( $spice )) {
return true ;
2012-01-06 02:44:46 +01:00
}
2012-01-29 23:59:11 +01:00
$allow = $this -> checkRules ( $eventData [ 'email' ], $eventData [ 'comment' ], true , true );
if ( $allow [ 'allow_twitter' ]) {
2012-01-21 18:46:54 +01:00
$smartify = serendipity_db_bool ( $this -> get_config ( 'smartifytwitter' , false ));
$twittername = $spice [ 'twittername' ];
2012-01-27 15:16:36 +01:00
if ( ! empty ( $twittername )) {
2012-03-11 04:02:15 +01:00
$twitternameparts = explode ( '@' , $twittername );
$statusnet = is_array ( $twitternameparts ) && count ( $twitternameparts ) == 2 ;
if ( $statusnet ) {
$twittername = $twitternameparts [ 0 ];
$timeline_url = " http:// " . $twitternameparts [ 1 ] . " / " . $twittername ;
$twitter_icon_html = '<img src="' . $serendipity [ 'baseURL' ] . 'index.php?/plugin/spiceicoidentica.png" alt="' . PLUGIN_EVENT_COMMENTSPICE_PROMOTE_TWITTER . ': ">' ;
$followme_widget = '' ;
}
else {
$timeline_url = 'https://twitter.com/#!/' . $twittername ;
$twitter_icon_html = '<img src="' . $serendipity [ 'baseURL' ] . 'index.php?/plugin/spiceicotwitter.png" alt="' . PLUGIN_EVENT_COMMENTSPICE_PROMOTE_TWITTER . ': ">' ;
$followme_widget = $this -> createFollowMeWidget ( $twittername , $timeline_url_nofollow );
}
2012-01-29 23:59:11 +01:00
$timeline_url_nofollow = $allow [ 'nofollow_twitter' ];
2012-01-27 15:16:36 +01:00
if ( $smartify ) {
$eventData [ 'spice_twitter_name' ] = $twittername ;
$eventData [ 'spice_twitter_url' ] = $timeline_url ;
$eventData [ 'spice_twitter_nofollow' ] = $timeline_url_nofollow ;
$eventData [ 'spice_twitter_icon_html' ] = $twitter_icon_html ;
$eventData [ 'spice_twitter_followme' ] = $followme_widget ;
2012-01-24 01:49:44 +01:00
}
else {
2012-01-27 15:16:36 +01:00
if ( serendipity_db_bool ( $this -> get_config ( 'followme_widget' , false ))) {
$eventData [ 'comment' ] = $followme_widget . '<br/>' . $eventData [ 'comment' ];
}
else {
$eventData [ 'comment' ] = '<a href="' . $timeline_url . '" class="commentspice_twitterlink" target="_blank"' . ( $timeline_url_nofollow ? ' rel="nofollow"' : '' ) . '>' . $twitter_icon_html . ' ' . $twittername . '</a>' . '<br/>' . $eventData [ 'comment' ];
}
2012-01-24 01:49:44 +01:00
}
2012-01-21 18:46:54 +01:00
}
}
2012-02-03 02:05:50 +01:00
if ( $allow [ 'allow_boo' ] && $spice [ 'boo' ]) {
$booPlayer = '<iframe class="commentspice_booplayer" allowtransparency="allowtransparency" cellspacing="0" frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" vspace="0" src="' . $spice [ 'boo' ] . '/embed" title="Audioboo player"></iframe>' ;
$eventData [ 'comment' ] .= $booPlayer ;
}
2012-01-29 23:59:11 +01:00
if ( $allow [ 'allow_announce' ] && $spice [ 'promo_name' ] && $spice [ 'promo_url' ]) {
2012-02-27 14:30:55 +01:00
$spice_article_prefix = sprintf ( PLUGIN_EVENT_COMMENTSPICE_PROMOTE_ARTICLE_RECENT , $eventData [ 'author' ]);
2012-01-21 18:46:54 +01:00
$spice_article_name = $spice [ 'promo_name' ];
$spice_article_url = $spice [ 'promo_url' ];
2012-01-29 23:59:11 +01:00
$spice_article_nofollow = $allow [ 'nofollow_announce' ];
2012-01-21 18:46:54 +01:00
$smartify = serendipity_db_bool ( $this -> get_config ( 'smartifyannouncerss' , false ));
if ( $smartify ) {
$eventData [ 'spice_article_prefix' ] = $spice_article_prefix ;
$eventData [ 'spice_article_name' ] = $spice_article_name ;
$eventData [ 'spice_article_url' ] = $spice_article_url ;
$eventData [ 'spice_article_nofollow' ] = $spice_article_nofollow ;
}
else {
$eventData [ 'comment' ] .= " <p class= \" commentspice_announce_article \" > " . $spice_article_prefix . " : <a href= \" $spice_article_url\ " target = \ " _blank \" " . ( $spice_article_nofollow ? ' rel="nofollow"' : '' ) . " > $spice_article_name </a></p> " ;
}
2012-01-18 23:13:28 +01:00
}
2012-01-06 02:44:46 +01:00
}
2012-01-28 15:37:19 +01:00
function spiceEntry ( & $eventData , $addData ) {
global $serendipity ;
if ( ! $addData [ 'extended' ]) return ; // Only single articles
$patched_input_twitter = serendipity_db_bool ( $this -> get_config ( 'inputpatched_twitter' , false ));
$patched_input_rss = serendipity_db_bool ( $this -> get_config ( 'inputpatched_rss' , false ));
if ( ! $patched_input_twitter && ! $patched_input_rss ) return ;
if ( isset ( $eventData ) && is_array ( $eventData )) {
// Get the first entry an add stuff
foreach ( $eventData as $event ) {
$smarty_spice = array ();
if ( $patched_input_twitter ) {
if ( isset ( $serendipity [ 'COOKIE' ][ 'twitter' ])) $twittername = $serendipity [ 'COOKIE' ][ 'twitter' ];
else $twittername = '' ;
2012-01-29 23:59:11 +01:00
$smarty_spice [ 'inputtwitter' ] = $this -> get_config ( 'twitterinput' , 'disabled' ) != 'disabled' ;
2012-01-28 15:37:19 +01:00
$smarty_spice [ 'inputtwitterlabel' ] = 'Twitter' ;
$smarty_spice [ 'inputtwittervalue' ] = $twittername ;
$smarty_spice [ 'inputtwitterplaceholder' ] = PLUGIN_EVENT_COMMENTSPICE_PROMOTE_TWITTER_PLACEHOLDER ;
}
if ( $patched_input_rss ) {
2012-01-29 23:59:11 +01:00
$smarty_spice [ 'inputarticle' ] = $this -> get_config ( 'announcerss' , 'disabled' ) != 'disabled' ;
2012-01-28 15:37:19 +01:00
}
if ( count ( $smarty_spice )) {
$serendipity [ 'smarty' ] -> assign ( 'spice' , $smarty_spice );
}
break ;
}
}
}
2012-01-24 01:49:44 +01:00
function createFollowMeWidget ( $wittername , $timeline_url_nofollow ) {
if ( serendipity_db_bool ( $this -> get_config ( 'followme_widget' , false ))) {
$extra_style = '' ;
if ( serendipity_db_bool ( $this -> get_config ( 'followme_widget_dark' , false ))) {
$extra_style .= ' data-button="grey" data-text-color="#FFFFFF" data-link-color="#00AEFF"' ;
}
if ( ! serendipity_db_bool ( $this -> get_config ( 'followme_widget_counter' , false ))) {
$extra_style .= ' data-show-count="false"' ;
}
2012-01-24 11:53:47 +01:00
return '<a href="https://twitter.com/' . $wittername . '" class="twitter-follow-button"' . $extra_style . ( $timeline_url_nofollow ? ' rel="nofollow"' : '' ) . '>Follow @' . $wittername . '</a>' ;
2012-01-24 01:49:44 +01:00
}
return " " ;
}
2012-01-28 15:37:19 +01:00
2012-01-22 23:39:20 +01:00
function handleAvatar ( & $eventData , & $addData ) {
$this -> log ( " avatar_hook. " . print_r ( $eventData , true ) . " \n " . print_r ( $addData , true ));
// We support twitter only
2012-02-02 15:34:20 +01:00
if ( ! is_array ( $addData ) || ! $addData [ 'type' ] == 'twitter' ) return ;
2012-01-22 23:39:20 +01:00
// Check for valid input
if ( ! is_array ( $eventData ) || ! $eventData [ 'cid' ]) return ;
// Add twitter infos to metadata. Twitter is detected by URL, so produce an URL
$spice = DbSpice :: loadCommentSpice ( $eventData [ 'cid' ]);
if ( ! is_array ( $spice )) return ;
if ( ! empty ( $spice [ 'twittername' ])) {
$eventData [ 'url' ] = 'http://twitter.com/' . $spice [ 'twittername' ];
$this -> log ( " avatar_hook filled. " . print_r ( $eventData , true ) . " \n " . print_r ( $addData , true ));
}
}
2012-01-11 14:55:43 +01:00
function printCommentEditExtras ( & $eventData , & $addData ) {
2012-01-06 02:44:46 +01:00
global $serendipity ;
2012-01-29 23:59:11 +01:00
$config_twitter = $this -> get_config ( 'twitterinput' , 'enabled' );
$config_announce = $this -> get_config ( 'announcerss' , 'disabled' );
$do_twitter = $config_twitter != 'disabled' ;
$do_announce = $config_announce != 'disabled' ;
2012-02-03 02:05:50 +01:00
$do_boo = serendipity_db_bool ( $this -> get_config ( 'allow_boo' , false ));
2012-06-23 15:35:49 +02:00
// Honeypot
if ( serendipity_db_bool ( $this -> get_config ( 'do_honeypot' , true ))) {
echo '<div id="serendipity_commentspice_phone" class="serendipity_commentDirection commentspice_phone_input" >' . " \n " ;
echo '<img src="' . $serendipity [ 'baseURL' ] . 'index.php?/plugin/commentspice.png" class="commentspice_ico" title="' . PLUGIN_EVENT_COMMENTSPICE_TITLE . '">' . " \n " ;
echo '<label for="serendipity_commentform_phone">Phone</label>' . " \n " ;
echo '<input class="commentspice_phone_input" type="text" id="serendipity_commentform_phone" name="serendipity[phone]" value="" placeholder="You don\'t want to give me your number, do you? ;)"/>' . " \n " ;
echo " </div> \n " ;
}
2012-01-29 23:59:11 +01:00
if ( $do_twitter ) {
2012-01-11 14:55:43 +01:00
if ( isset ( $serendipity [ 'COOKIE' ][ 'twitter' ])) $twittername = $serendipity [ 'COOKIE' ][ 'twitter' ];
else $twittername = '' ;
2012-01-28 15:37:19 +01:00
if ( ! serendipity_db_bool ( $this -> get_config ( 'inputpatched_twitter' , false ))) {
2012-06-23 15:35:49 +02:00
echo '<div id="serendipity_commentspice_twitter">' . " \n " ;
echo '<input class="commentspice_twitter_input" type="text" id="serendipity_commentform_twitter" name="serendipity[twitter]" placeholder="' . PLUGIN_EVENT_COMMENTSPICE_PROMOTE_TWITTER_PLACEHOLDER . '" value="' . $twittername . '"/>' . " \n " ;
echo '</div>' . " \n " ;
2012-01-28 15:37:19 +01:00
}
2012-01-11 14:55:43 +01:00
}
2012-01-29 23:59:11 +01:00
if ( $do_announce && ! serendipity_db_bool ( $this -> get_config ( 'inputpatched_rss' , false ))) {
2012-06-23 15:35:49 +02:00
echo '<div id="serendipity_commentspice_rss" style="display:none;">' . " \n " ;
echo '<select class="commentspice_rss_input" id="serendipity_commentform_rss" name="serendipity[promorss]"></select>' . " \n " ; // style="max-width: 20em; width: 100%"
echo '</div>' . " \n " ;
2012-01-11 14:55:43 +01:00
}
2012-02-03 02:05:50 +01:00
if ( $do_boo ) {
2012-06-23 15:35:49 +02:00
echo '<div id="serendipity_commentspice_boo_desc" class="serendipity_commentDirection serendipity_comment_spice">' . " \n " ;
echo '<a href="http://audioboo.fm/profile" target="_blank"><img src="' . $serendipity [ 'baseURL' ] . 'index.php?/plugin/audioboo.png" class="commentspice_ico" title="Audioboo.com"></a>' . " \n " ;
echo PLUGIN_EVENT_COMMENTSPICE_BOO_FOOTER . '<br/>' . " \n " ;
2012-02-03 02:05:50 +01:00
2012-06-23 15:35:49 +02:00
echo '<a href="http://audioboo.fm/boos/new" target="_blank"><img src="' . $serendipity [ 'baseURL' ] . 'index.php?/plugin/spiceicorecord.png" class="commentspice_ico" title="create a boo" alt="record" onClick="window.open(\'http://audioboo.fm/boos/new\',\'recordboo\',\'width=600,height=300\');return false;"></a>' . " \n " ;
echo '<input class="commentspice_boo_input" type="url" id="serendipity_commentform_boo" name="serendipity[boo]" placeholder="' . PLUGIN_EVENT_COMMENTSPICE_BOO_PLACEHOLDER . '" value=""/>' . " \n " ;
echo '</div>' . " \n " ;
2012-02-03 02:05:50 +01:00
}
2012-01-29 23:59:11 +01:00
if ( $do_twitter ) {
2012-06-23 15:35:49 +02:00
echo '<div id="serendipity_commentspice_twitter_desc" class="serendipity_commentDirection serendipity_comment_spice">' . " \n " ;
echo '<img src="' . $serendipity [ 'baseURL' ] . 'index.php?/plugin/commentspice.png" class="commentspice_ico" title="' . PLUGIN_EVENT_COMMENTSPICE_TITLE . '">' . " \n " ;
2012-01-21 16:10:06 +01:00
echo PLUGIN_EVENT_COMMENTSPICE_PROMOTE_TWITTER_FOOTER ;
2012-01-29 23:59:11 +01:00
$requirements = $this -> createRequirementsString ( $config_twitter );
if ( ! empty ( $requirements )) echo " <br/> $requirements " ;
2012-06-23 15:35:49 +02:00
echo '</div>' . " \n " ;
2012-01-11 14:55:43 +01:00
}
2012-01-29 23:59:11 +01:00
if ( $do_announce ) {
2012-06-23 15:35:49 +02:00
echo '<div id="serendipity_commentspice_rss_desc" class="serendipity_commentDirection serendipity_comment_spice">' . " \n " ;
echo '<img src="' . $serendipity [ 'baseURL' ] . 'index.php?/plugin/commentspice.png" class="commentspice_ico" title="' . PLUGIN_EVENT_COMMENTSPICE_TITLE . '">' . " \n " ;
2012-01-21 16:10:06 +01:00
echo PLUGIN_EVENT_COMMENTSPICE_PROMOTE_ARTICLE_FOOTER ;
2012-01-29 23:59:11 +01:00
$requirements = $this -> createRequirementsString ( $config_announce );
if ( ! empty ( $requirements )) echo " <br/> $requirements " ;
2012-06-23 15:35:49 +02:00
echo '</div>' . " \n " ;
2012-01-06 02:44:46 +01:00
}
2012-06-23 15:35:49 +02:00
2012-01-06 02:44:46 +01:00
}
2012-01-11 14:55:43 +01:00
2012-01-29 23:59:11 +01:00
function createRequirementsString ( $rule_config_value ) {
$requirements = '' ;
if ( 'rules' == $rule_config_value ) {
$rule_commentlenght = ( int ) $this -> get_config ( 'rule_extras_commentlength' , 0 );
$rule_commentcount = ( int ) $this -> get_config ( 'rule_extras_commentcount' , 0 );
$requirements = " <em>( " . PLUGIN_EVENT_COMMENTSPICE_REQUIREMENTS . " : " ;
if ( $rule_commentcount ) {
$requirements .= sprintf ( PLUGIN_EVENT_COMMENTSPICE_REQUIREMENTS_COMMENTCOUNT , $rule_commentcount );
}
if ( $rule_commentlenght && $rule_commentcount ) {
$requirements .= " , " ;
}
if ( $rule_commentlenght ) {
$requirements .= sprintf ( PLUGIN_EVENT_COMMENTSPICE_REQUIREMENTS_COMMENTLEN , $rule_commentlenght );
}
$requirements .= " )</em> " ;
}
return $requirements ;
}
2012-06-23 15:35:49 +02:00
function printCss ( & $eventData , & $addData ) {
2012-02-03 02:05:50 +01:00
// $booPlayer = '<iframe class="space_booplayer" style="" allowtransparency="allowtransparency" cellspacing="0" frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" vspace="0" src="http://audioboo.fm/boos/649785-ein-erster-testboo/embed" title="Audioboo player"></iframe>';
2012-01-21 16:10:06 +01:00
global $serendipity ;
2012-02-03 02:05:50 +01:00
if ( ! ( strpos ( $eventData , '.commentspice_booplayer' ))) {
?>
. commentspice_booplayer {
margin : 0 px ; padding : 0 px ; border : none ; display : block ; max - width : 100 % ; width : 1000 px ; height : 145 px ;
}
< ? php
}
if ( ! ( strpos ( $eventData , '.commentspice_ico_boo' ))) {
?>
. commentspice_ico_boo {
float : right ;
margin - right : 0 px ;
margin - left : 10 px ;
}
< ? php
}
2012-01-21 16:10:06 +01:00
if ( ! ( strpos ( $eventData , '.commentspice_ico' ))) {
?>
. commentspice_ico {
float : right ;
margin - right : 0 px ;
margin - left : 10 px ;
}
2012-02-03 02:05:50 +01:00
< ? php
}
if ( ! ( strpos ( $eventData , '.commentspice_boo_input' ))) {
?>
. commentspice_boo_input {
max - width : 100 % ;
}
2012-06-23 15:35:49 +02:00
< ? php
}
if ( ! ( strpos ( $eventData , '.commentspice_phone_input' ))) {
?>
. commentspice_phone_input {
max - width : 100 % ;
display : none ;
visibility : hidden ;
}
2012-01-21 16:10:06 +01:00
< ? php
}
if ( ! ( strpos ( $eventData , '.commentspice_twitter_input' ))) {
?>
. commentspice_twitter_input {
background : url ( '<?php echo $serendipity[' baseURL ']; ?>index.php?/plugin/spiceicotwitter.png' ) left no - repeat ;
padding - left : 1.5 em ;
max - width : 18.5 em ;
margin - bottom : 1 em ;
}
< ? php
}
if ( ! ( strpos ( $eventData , '.commentspice_rss_input' ))) {
?>
2012-01-28 15:37:19 +01:00
#serendipity_commentspice_rss {
max - width : 100 % ;
}
2012-01-21 16:10:06 +01:00
. commentspice_rss_input {
2012-01-28 15:37:19 +01:00
max - width : 100 % ;
min - width : 30.6 em ;
2012-01-21 16:10:06 +01:00
background : url ( '<?php echo $serendipity[' baseURL ']; ?>index.php?/plugin/spiceicorss.png' ) no - repeat left #444444;
overflow : hidden ;
border : 0.1 em solid #000000;
border - radius : 3 px 3 px 3 px 3 px ;
color : #FFFFFF;
padding - left : 1.5 em ;
2012-01-28 15:37:19 +01:00
< ? php if ( ! serendipity_db_bool ( $this -> get_config ( 'inputpatched_rss' , false ))) { ?>
2012-01-21 16:10:06 +01:00
margin - bottom : 1 em ;
2012-01-28 15:37:19 +01:00
< ? php } ?>
2012-01-21 16:10:06 +01:00
}
2012-01-30 13:05:40 +01:00
select . commentspice_rss_input option {
background : #444444;
padding - left : 1.5 em ;
}
2012-01-21 18:46:54 +01:00
< ? php
}
if ( ! ( strpos ( $eventData , '.commentspice_announce_article' ))) {
?>
. commentspice_announce_article {
padding - top : 1 em ;
margin - bottom : 0 em ;
font - size : smaller ;
text - align : center ;
}
2012-01-21 16:10:06 +01:00
< ? php
}
}
2012-01-18 23:13:28 +01:00
function hashString ( $what ) {
$installation_secret = $this -> get_config ( 'installation_secret' );
if ( empty ( $installation_secret )) {
$installation_secret = md5 ( date ( 'l jS \of F Y h:i:s A' ));
$this -> set_config ( 'installation_secret' , $installation_secret );
}
return md5 ( $installation_secret . ':' . $what );
}
2012-01-26 13:50:43 +01:00
function saveFetchPingbackDataConfig ( $fetchPingback ) {
global $serendipity ;
if ( is_writeable ( $serendipity [ 'serendipityPath' ] . 'serendipity_config_local.inc.php' )) {
$privateVariables = array ( 'pingbackFetchPage' => $fetchPingback );
serendipity_updateLocalConfig ( $serendipity [ 'dbName' ], $serendipity [ 'dbPrefix' ], $serendipity [ 'dbHost' ], $serendipity [ 'dbUser' ], $serendipity [ 'dbPass' ], $serendipity [ 'dbType' ], $serendipity [ 'dbPersistent' ], $privateVariables );
}
else {
echo " serendipity_config_local.inc.php is not writeable for plugins " ;
}
}
function isLocalConfigWritable () {
global $serendipity ;
$file = $serendipity [ 'serendipityPath' ] . 'serendipity_config_local.inc.php' ;
return ! file_exists ( $file ) || is_writeable ( $file );
}
function set_config ( $name , $value , $implodekey = '^' ) {
global $serendipity ;
if ( $name == 'fetchPingback' ) {
if ( 'none' != $value ) {
// This will be updated later, so save it in memory, too:
$serendipity [ 'pingbackFetchPage' ] = serendipity_db_bool ( $value );
// now make the config persistant.
$this -> saveFetchPingbackDataConfig ( $serendipity [ 'pingbackFetchPage' ]);
}
}
else {
parent :: set_config ( $name , $value , $implodekey );
}
}
2012-01-11 14:55:43 +01:00
function log ( $message ){
if ( ! PLUGIN_EVENT_COMMENTSPICE_DEBUG ) return ;
$fp = fopen ( dirname ( __FILE__ ) . '/spice.log' , 'a' );
fwrite ( $fp , date ( 'Y.m.d H:i:s' ) . " - " . $message . " \n " );
fflush ( $fp );
fclose ( $fp );
}
2012-06-23 15:35:49 +02:00
function spamlog ( $logfile , $id , $switch , $reason , $addData ) {
global $serendipity ;
$method = $this -> get_config ( 'spamlogtype' , 'none' );
if ( empty ( $logfile )) $logfile = dirname ( __FILE__ ) . '/spice_honeypot.log' ;
switch ( $method ) {
case 'file' :
$reason = " CommentSpice Honeypot: " + $reason ;
if ( empty ( $logfile )) {
return ;
}
if ( strpos ( $logfile , '%' ) !== false ) {
$logfile = strftime ( $logfile );
}
$fp = @ fopen ( $logfile , 'a+' );
if ( ! is_resource ( $fp )) {
return ;
}
fwrite ( $fp , sprintf (
'[%s] - [%s: %s] - [#%s, Name "%s", E-Mail "%s", URL "%s", User-Agent "%s", IP %s] - [%s]' . " \n " ,
date ( 'Y-m-d H:i:s' , serendipity_serverOffsetHour ()),
$switch ,
$reason ,
$id ,
str_replace ( " \n " , ' ' , $addData [ 'name' ]),
str_replace ( " \n " , ' ' , $addData [ 'email' ]),
str_replace ( " \n " , ' ' , $addData [ 'url' ]),
str_replace ( " \n " , ' ' , $_SERVER [ 'HTTP_USER_AGENT' ]),
$_SERVER [ 'REMOTE_ADDR' ],
str_replace ( " \n " , ' ' , $addData [ 'comment' ])
));
fclose ( $fp );
break ;
case 'none' :
return ;
break ;
case 'db' :
default :
$reason = " CommentSpice Honeypot: " . serendipity_db_escape_string ( $reason );
$q = sprintf ( " INSERT INTO { $serendipity [ 'dbPrefix' ] } spamblocklog
( timestamp , type , reason , entry_id , author , email , url , useragent , ip , referer , body )
VALUES ( % d , '%s' , '%s' , '%s' , '%s' , '%s' , '%s' , '%s' , '%s' , '%s' , '%s' ) " ,
serendipity_serverOffsetHour (),
serendipity_db_escape_string ( $switch ),
serendipity_db_escape_string ( $reason ),
serendipity_db_escape_string ( $id ),
serendipity_db_escape_string ( $addData [ 'name' ]),
serendipity_db_escape_string ( $addData [ 'email' ]),
serendipity_db_escape_string ( $addData [ 'url' ]),
substr ( serendipity_db_escape_string ( $_SERVER [ 'HTTP_USER_AGENT' ]), 0 , 255 ),
serendipity_db_escape_string ( $_SERVER [ 'REMOTE_ADDR' ]),
substr ( serendipity_db_escape_string ( isset ( $_SESSION [ 'HTTP_REFERER' ]) ? $_SESSION [ 'HTTP_REFERER' ] : $_SERVER [ 'HTTP_REFERER' ]), 0 , 255 ),
serendipity_db_escape_string ( $addData [ 'comment' ])
);
serendipity_db_schema_import ( $q );
break ;
}
}
2012-01-22 23:39:20 +01:00
}