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'
));
$propbag->add('version', '0.1');
$propbag->add('event_hooks', array(
// 'frontend_header' => true,
'frontend_footer' => true,
'frontend_comment' => true,
'frontend_display' => true,
'frontend_saveComment_finish' => true,
'backend_deletecomment' => true,
'external_plugin' => true,
));
$propbag->add('groups', array('FRONTEND_VIEWS'));
$propbag->add('configuration', array('twitterinput','announcerss','plugin_path'));
}
function generate_content(&$title) {
$title = PLUGIN_EVENT_EMOTICONCHOOSER_TITLE;
}
function introspect_config_item($name, &$propbag)
{
global $serendipity;
switch($name) {
case 'twitterinput':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_EVENT_COMMENTSPICE_TWITTERINPUT);
$propbag->add('description', '');
$propbag->add('default', true);
return true;
break;
case 'announcerss':
$propbag->add('type', 'boolean');
$propbag->add('name', PLUGIN_EVENT_COMMENTSPICE_ANNOUNCE_RSS);
$propbag->add('description', '');
$propbag->add('default', false);
return true;
break;
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/');
return true;
break;
}
return false;
}
function event_hook($event, &$bag, &$eventData, &$addData) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'external_plugin':
switch($eventData) {
case 'spicetwitter.png':
header('Content-Type: image/png');
echo file_get_contents(dirname(__FILE__). '/img/twitter.png');
break;
case 'spicetwittersmall.png':
header('Content-Type: image/png');
echo file_get_contents(dirname(__FILE__). '/img/twitter_small.png');
break;
case 'commentspicefrss':
if (!serendipity_db_bool($this->get_config('announcerss', false))) break;
$this->readRss();
break;
}
break;
case 'frontend_saveComment_finish' :
$this->commentSaved($eventData, $addData);
break;
//case 'frontend_header':
case 'frontend_footer':
$this->printHeader();
break;
case 'frontend_display':
$this->printTwitterLink($eventData, $addData);
break;
case 'frontend_comment':
$this->printCommentEditExtras($eventData, $addData);
break;
case 'backend_deletecomment' :
$this->commentDeleted($eventData, $addData);
break;
default:
return false;
break;
}
return true;
} else {
return false;
}
}
function install() {
DbSpice::install($this);
}
function cleanup() {
DbSpice::install($this);
}
function printHeader() {
global $serendipity;
if (serendipity_db_bool($this->get_config('announcerss',false)))
{
$path = $this->path = $this->get_config('plugin_path', $serendipity['serendipityHTTPPath'] . 'plugins/serendipity_event_commentspice/');
echo "
";
}
}
function commentSaved($eventData, $addData) {
global $serendipity;
if ("NORMAL" == $addData['type']) { // only supported for normal comments
$result = DbSpice::saveCommentSpice($addData['comment_cid'], $serendipity['POST']['twitter']);
// Remember twitter name value into cookie, if user ordered to, else clear cookie
if (isset($serendipity['POST']['remember'])) {
serendipity_rememberCommentDetails(array ('twitter' => $serendipity['POST']['twitter']));
}
else {
serendipity_forgetCommentDetails(array('twitter'));
}
}
}
function readRss() {
$comment_url = $_REQUEST ['coment_url'];
if (empty($comment_url)) return;
require_once (defined('S9Y_PEAR_PATH') ? S9Y_PEAR_PATH : S9Y_INCLUDE_PATH . 'bundled-libs/') . 'HTTP/Request.php';
$req = new HTTP_Request($comment_url);
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
return;
}
# Fetch html content:
$data = $req->getResponseBody();
$matches = array();
if (preg_match('@log('commentDeleted');
$this->log(print_r($eventData, true));
$this->log(print_r($addData, true));
$reult = DbSpice::deleteCommentSpice($addData['cid']);
$this->log("delete result: $reult");
}
function printTwitterLink(&$eventData, &$addData) {
global $serendipity;
if (!isset($eventData['comment']) || !serendipity_db_bool($this->get_config('twitterinput', true))) {
return true;
}
// Called from sidbar:
if ($addData['from'] == 'serendipity_plugin_comments:generate_content') {
return true;
}
$spice = DbSpice::loadCommentSpice($eventData['id']);
if (!is_array($spice)) {
return true;
}
$twittername = $spice['twittername'];
$eventData['comment'] = '
' . $eventData['comment'];
}
function printCommentEditExtras(&$eventData, &$addData) {
global $serendipity;
$tag_comment_spice = '
(comment spice experimental)';
if (serendipity_db_bool($this->get_config('twitterinput', true))) {
if (isset($serendipity['COOKIE']['twitter'])) $twittername = $serendipity['COOKIE']['twitter'];
else $twittername = '';
echo '';
}
if (serendipity_db_bool($this->get_config('announcerss', false))) {
echo '';
}
if (serendipity_db_bool($this->get_config('twitterinput', true))) {
echo '';
}
if (serendipity_db_bool($this->get_config('announcerss', true))) {
echo '';
}
}
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);
}
}