[pLog-svn] r1665 - in plugins/trunk: . shoutbox shoutbox/plugins
shoutbox/plugins/shoutbox shoutbox/plugins/shoutbox/class
shoutbox/plugins/shoutbox/class/action
shoutbox/plugins/shoutbox/class/dao
shoutbox/plugins/shoutbox/templates shoutbox/templates
shoutbox/templates/grey
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Thu Mar 31 15:28:42 GMT 2005
Author: oscar
Date: 2005-03-31 15:28:42 +0000 (Thu, 31 Mar 2005)
New Revision: 1665
Added:
plugins/trunk/shoutbox/
plugins/trunk/shoutbox/README.txt
plugins/trunk/shoutbox/plugins/
plugins/trunk/shoutbox/plugins/shoutbox/
plugins/trunk/shoutbox/plugins/shoutbox/class/
plugins/trunk/shoutbox/plugins/shoutbox/class/action/
plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxaction.class.php
plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxconfigaction.class.php
plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxdeleteshoutsaction.class.php
plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxsetupaction.class.php
plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxupdateconfigaction.class.php
plugins/trunk/shoutbox/plugins/shoutbox/class/dao/
plugins/trunk/shoutbox/plugins/shoutbox/class/dao/shoutbox.class.php
plugins/trunk/shoutbox/plugins/shoutbox/pluginshoutbox.class.php
plugins/trunk/shoutbox/plugins/shoutbox/templates/
plugins/trunk/shoutbox/plugins/shoutbox/templates/shoutbox.template
plugins/trunk/shoutbox/plugins/shoutbox/templates/shoutboxConfig.template
plugins/trunk/shoutbox/templates/
plugins/trunk/shoutbox/templates/grey/
plugins/trunk/shoutbox/templates/grey/footer.template
plugins/trunk/shoutbox/templates/grey/shoutbox.template
Log:
palantir's shoutbox plugin ported to plog 1.0 just in time :)
Added: plugins/trunk/shoutbox/README.txt
===================================================================
--- plugins/trunk/shoutbox/README.txt 2005-03-31 14:08:02 UTC (rev 1664)
+++ plugins/trunk/shoutbox/README.txt 2005-03-31 15:28:42 UTC (rev 1665)
@@ -0,0 +1,82 @@
+++++++++++++++++++++++++++++++++++++++++++++++++
+Readme for the "Shoutbox Plugin"
+version 0.12
+a plugin for pLog (v1.0)
+Developed by Palantir, radar at netpalantir.it
+
+See the plugin in action at my blog:
+http://www.netpalantir.it
+
+This plugin is released under the terms of the LGPL
+
+++++++++++++++++++++++++++++++++++++++++++++++++
+Warning: This is a 0.x version. It may work, but
+it may also nuke your blog. BACK UP FIRST!!
+++++++++++++++++++++++++++++++++++++++++++++++++
+
+HOW TO INSTALL (from scratch)
+1. Unpack the archive
+2. Locate the installation directory of your plog
+3. Copy the whole "shoutbox" directory into the plugin directory
+4. Change the permissions/ownership of all the files, according to your setup.
+ If you transfer files via FTP this could be unneccessary. All the files must
+ be readable by the web server.
+5. Point your browser to your blog administration page, log in, click on:
+ Control Center > Plugin center. The shoutbox plugin should be on your
+ list. If it is not, try updating the page a few times, it seems to help ;)
+6. The first time you run it, the plugin should autodetect if any change has to
+ be done to the database and apply them, so to make it ready to use.
+
+HOW TO MAKE IT WORK
+First, integrate the plugin into the template.
+I am using the grey template, so this example refers to it. The easiest way is
+to modify the footer template to add the shoutbox on the right column. Just copy
+the enclosed footer.template to <path-to-plog>/templates/grey/footer.template
+(remember to back-up your old one!). Also, copy the shoutbox.template to your
+templates directory.
+
+HOW TO USE IT
+After the first setup, customize the options at the bottom of the page. Then,
+wait for people to leave messages. If you have enabled email notifications,
+you will receive the shouts directly into your mailbox. You can delete shouts
+by selecting them and clicking the delete button.
+You can protect one or more nicknames, by adding them into the protected nicks
+box. Separate them using spaces. Then, when you want to use them, simply enter
+the nickname followed by : and the password. Password is case sensitive.
+
+HOW TO UPGRADE - Admin Side
+Enter the plugins directory, and delete the file called pluginShoutbox.class.php,
+then delete the whole directory called pluginShoutbox. Then follow all the steps
+in the section HOW TO INSTALL (from scratch)
+
+HOW TO UPGRADE - User Side
+Open the template where you have your shoutbox (for example, shoutbox.template
+and replace every occurrence of $shoutboxPlugin to $shoutbox
+
+DOESN'T WORK? BUGS? WISHES? WHO TO CONTACT
+Please, use the pLog's bug reporting system. It's located at:
+http://bugs.plogworld.net
+
++++++++++++++++++++++++++++++++++++++++++++++++
+
+TODO:
+- It would be nice to put the shoutbox into an iframe
+- Restore the validation of the fields in the admin interface
+
++++++++++++++++++++++++++++++++++++++++++++++++
+
+CHANGELOG:
+
+v0.12
+- Porting of the whole tinng to the new pLog 1 framework. Costed A LOT of work
+so it's not such a _minor_ release ;-)
+
+v0.11x
+- Nickname password protection
+- Admin section: shout list divided in pages
+
+v0.1
+Initial release
+
+
+
Added: plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxaction.class.php
===================================================================
--- plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxaction.class.php 2005-03-31 14:08:02 UTC (rev 1664)
+++ plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxaction.class.php 2005-03-31 15:28:42 UTC (rev 1665)
@@ -0,0 +1,55 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+
+ include_once( PLOG_CLASS_PATH."plugins/shoutbox/class/dao/shoutbox.class.php" );
+
+ /**
+ * shows a form with the current configuration
+ */
+ class PluginShoutboxAction extends AdminAction {
+
+ function PluginShoutboxAction( $actionInfo, $request ) {
+ $this->AdminAction( $actionInfo, $request );
+ }
+
+ function perform() {
+
+ // load some configuration settings
+ $blogSettings = $this->_blogInfo->getSettings();
+
+ if(!$blogSettings->getValue("plugin_shoutbox_dbok") || $blogSettings->getValue( "plugin_shoutbox_version") != '0.12') {
+ header('Location: admin.php?op=setupShoutbox');
+ exit();
+ }
+
+ // Get the shoutbox entries
+ $s = new Shoutbox($this->_blogInfo->getId(), $blogSettings);
+
+ // create a view and export the settings to the template
+ $this->_view = new AdminPluginTemplatedView( $this->_blogInfo, "shoutbox", "shoutbox", true );
+ $this->_view->setValue( "pluginEnabled", $pluginEnabled );
+ //$this->_view->setValue( "Shoutboxet", $Shoutboxet );
+
+ $this->_view->setValue( "shouts", $s->getShoutsArray());
+
+ if($s->mail_alert)
+ $mail_alert_checked = "checked";
+
+ $this->_view->setValue( "mail_alert_checked", $mail_alert_checked);
+ $this->_view->setValue( "max_length", $s->max_length);
+ $this->_view->setValue( "shouts_per_view", $s->shouts_per_view);
+ $this->_view->setValue( "default_nick", $s->default_nick);
+ $this->_view->setValue( "default_shout", $s->default_shout);
+ $this->_view->setValue( "protected_nicks", $s->protected_nicks);
+ $this->_view->setValue( "protection_password", $s->protection_password);
+ $this->_view->setValue( "current_page", $s->current_page);
+
+
+ $this->setCommonData();
+
+ return true;
+ }
+}
+?>
\ No newline at end of file
Added: plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxconfigaction.class.php
===================================================================
--- plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxconfigaction.class.php 2005-03-31 14:08:02 UTC (rev 1664)
+++ plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxconfigaction.class.php 2005-03-31 15:28:42 UTC (rev 1665)
@@ -0,0 +1,45 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+
+ include_once( PLOG_CLASS_PATH."plugins/shoutbox/class/dao/shoutbox.class.php" );
+
+ /**
+ * shows a form with the current configuration
+ */
+ class PluginShoutboxConfigAction extends AdminAction {
+
+ function PluginShoutboxConfigAction( $actionInfo, $request ) {
+ $this->AdminAction( $actionInfo, $request );
+ }
+
+ function perform() {
+
+ // load some configuration settings
+ $blogSettings = $this->_blogInfo->getSettings();
+
+ // Get the shoutbox entries
+ $s = new Shoutbox($this->_blogInfo->getId(), $blogSettings);
+
+ // create a view and export the settings to the template
+ $this->_view = new AdminPluginTemplatedView( $this->_blogInfo, "shoutbox", "shoutboxConfig" );
+
+ if($s->mail_alert)
+ $mail_alert_checked = "checked";
+
+ $this->_view->setValue( "mail_alert_checked", $mail_alert_checked);
+ $this->_view->setValue( "max_length", $s->max_length);
+ $this->_view->setValue( "shouts_per_view", $s->shouts_per_view);
+ $this->_view->setValue( "default_nick", $s->default_nick);
+ $this->_view->setValue( "default_shout", $s->default_shout);
+ $this->_view->setValue( "protected_nicks", $s->protected_nicks);
+ $this->_view->setValue( "protection_password", $s->protection_password);
+ $this->_view->setValue( "current_page", $s->current_page);
+
+ $this->setCommonData();
+
+ return true;
+ }
+}
+?>
\ No newline at end of file
Added: plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxdeleteshoutsaction.class.php
===================================================================
--- plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxdeleteshoutsaction.class.php 2005-03-31 14:08:02 UTC (rev 1664)
+++ plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxdeleteshoutsaction.class.php 2005-03-31 15:28:42 UTC (rev 1665)
@@ -0,0 +1,49 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminmessageview.class.php" );
+
+ include_once( PLOG_CLASS_PATH."plugins/shoutbox/class/dao/shoutbox.class.php" );
+
+ /**
+ * updates the plugin configuration
+ */
+ class PluginShoutboxDeleteShoutsAction extends AdminAction
+ {
+
+ var $_pluginEnabled;
+ var $_Shoutboxet;
+
+ function PluginShoutboxDeleteShoutsAction( $actionInfo, $request )
+ {
+ $this->AdminAction( $actionInfo, $request );
+ }
+
+
+ function perform()
+ {
+ $backLink = "<br><br><a href='admin.php?op=shoutbox'>Back to the shoutbox</a>";
+
+ // and check which smiley set we should be using, or if none, then the default one
+ $blogSettings = $this->_blogInfo->getSettings();
+
+ if(is_array($this->_request->getValue('del')) ) {
+ $endMessage = "Shouts successfully deleted.";
+ $s = new Shoutbox($this->_blogInfo->getId(), $blogSettings);
+ foreach($this->_request->getValue('del') as $k => $v) {
+ //echo("Delete $k<br>");
+ $s->deleteShout($k);
+ }
+ }
+ else
+ $endMessage = "Nothing to do (no shouts selected).";
+
+ $this->_view = new AdminMessageView( $this->_blogInfo );
+ $this->_view->setMessage($endMessage . $backLink);
+ $this->setCommonData();
+
+ return true;
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxsetupaction.class.php
===================================================================
--- plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxsetupaction.class.php 2005-03-31 14:08:02 UTC (rev 1664)
+++ plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxsetupaction.class.php 2005-03-31 15:28:42 UTC (rev 1665)
@@ -0,0 +1,114 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminmessageview.class.php" );
+
+ include_once( PLOG_CLASS_PATH."plugins/shoutbox/class/dao/shoutbox.class.php" );
+
+ /**
+ * creates or upgrades the shoutbox
+ */
+ class PluginShoutboxSetupAction extends AdminAction
+ {
+
+ var $_pluginEnabled;
+
+ function PluginShoutboxSetupAction( $actionInfo, $request )
+ {
+ $this->AdminAction( $actionInfo, $request );
+ }
+
+ function perform()
+ {
+ $blogSettings = $this->_blogInfo->getSettings();
+
+ $dbOk = $blogSettings->getValue("plugin_shoutbox_dbok");
+ $version = $blogSettings->getValue( "plugin_shoutbox_version");
+
+ if($dbOk && $version == '0.2')
+ return true;
+ else if($dbOk && $version < 0.2) {
+ $this->confirmSetup();
+ $this->finalSaveSettings();
+ $this->_view = new AdminMessageView( $this->_blogInfo );
+ $this->_view->setMessage("Shoutbox successfully upgraded from previous version");
+ $this->setCommonData();
+ }
+ else if($dbOk && $version > 0.2) {
+ $this->_view = new AdminErrorView( $this->_blogInfo );
+ $this->_view->setValue( "message", "It seems that you are downgrading the shoutbox from version $version. Operation not supported. Maybe you have hit a bug?");
+ $this->setCommonData();
+ }
+ else {
+ $s = new Shoutbox($this->_blogInfo->getId(), $blogSettings);
+
+ $tableExists = $s->checkTableExists();
+ if(!$tableExists)
+ $s->createTable();
+ $this->setDefaults();
+ $this->confirmSetup();
+ $this->finalSaveSettings();
+
+ if($tableExists) {
+ $this->_view = new AdminErrorView( $this->_blogInfo );
+ $this->_view->setValue( "message", "You have hit a (known) bug. Your shouts are intact, but the configuration options are gone. You will have to set them again :( Sorry for the inconvenience");
+ $this->setCommonData();
+ }
+ else {
+ $this->_view = new AdminMessageView( $this->_blogInfo );
+ $this->_view->setMessage("Shoutbox options successfully updated");
+ $this->setCommonData();
+ }
+ }
+
+ return true;
+ }
+
+
+ function setDefaults() {
+ $blogSettings = $this->_blogInfo->getSettings();
+
+ $blogSettings->setValue( "plugin_shoutbox_mail_alert", true);
+ $blogSettings->setValue( "plugin_shoutbox_max_length", 400);
+ $blogSettings->setValue( "plugin_shoutbox_shouts_per_view", 15);
+
+ $blogSettings->setValue( "plugin_shoutbox_protected_nicks", "ExampleNick");
+ $blogSettings->setValue( "plugin_shoutbox_protection_password", "");
+
+ $blogSettings->setValue( "plugin_shoutbox_default_nickname", "Your nickname");
+ $blogSettings->setValue( "plugin_shoutbox_default_shout", "Your shout here");
+
+ $this->_blogInfo->setSettings( $blogSettings );
+ }
+
+ function confirmSetup() {
+ $blogSettings = $this->_blogInfo->getSettings();
+
+ $blogSettings->setValue( "plugin_shoutbox_dbok", true);
+ $blogSettings->setValue( "plugin_shoutbox_version", '0.12');
+
+ $this->_blogInfo->setSettings( $blogSettings );
+ }
+
+ function finalSaveSettings() {
+ $blogSettings = $this->_blogInfo->getSettings();
+
+ // save the blogs settings
+ $blogs = new Blogs();
+ if( !$blogs->updateBlog( $this->_blogInfo->getId(), $this->_blogInfo )) {
+ $this->_view = new AdminErrorView( $this->_blogInfo );
+ $this->_view->setValue( "message", "An error occurred while saving the shoutbox options");
+ $this->setCommonData();
+
+ return false;
+ }
+
+ // if everything went ok...
+ $this->_blogInfo->setSettings( $blogSettings );
+ $this->_session->setValue( "blogInfo", $this->_blogInfo );
+ $this->saveSession();
+ }
+
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxupdateconfigaction.class.php
===================================================================
--- plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxupdateconfigaction.class.php 2005-03-31 14:08:02 UTC (rev 1664)
+++ plugins/trunk/shoutbox/plugins/shoutbox/class/action/pluginshoutboxupdateconfigaction.class.php 2005-03-31 15:28:42 UTC (rev 1665)
@@ -0,0 +1,83 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminmessageview.class.php" );
+
+ include_once( PLOG_CLASS_PATH."plugins/shoutbox/class/dao/shoutbox.class.php" );
+
+ /**
+ * updates the plugin configuration
+ */
+ class PluginShoutboxUpdateConfigAction extends AdminAction
+ {
+
+ var $_pluginEnabled;
+ var $_Shoutboxet;
+
+ function PluginShoutboxUpdateConfigAction( $actionInfo, $request )
+ {
+ $this->AdminAction( $actionInfo, $request );
+ }
+
+ function validate()
+ {
+ $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
+ $this->_pluginEnabled = ($this->_pluginEnabled != "" );
+ $this->_Shoutboxet = $this->_request->getValue( "setId" );
+ if( $Shoutboxet == "" )
+ $Shoutboxet = DEFAULT_SMILEY_SET;
+
+ return true;
+ }
+
+
+ function perform()
+ {
+ $endMessage = "Configuration successfully updated.";
+ $backLink = "<br><br><a href='admin.php?op=shoutbox'>Back to the shoutbox</a><br>" .
+ "<a href='admin.php?op=shoutboxConfig'>Back to the shoutbox config page</a><br>";
+
+ // and check which smiley set we should be using, or if none, then the default one
+ $blogSettings = $this->_blogInfo->getSettings();
+
+
+ if(strlen($this->_request->getValue('mail_alert')) > 0)
+ $blogSettings->setValue( "plugin_shoutbox_mail_alert", 1);
+ else
+ $blogSettings->setValue( "plugin_shoutbox_mail_alert", 0);
+
+ $blogSettings->setValue( "plugin_shoutbox_max_length", $this->_request->getValue('max_length'));
+ $blogSettings->setValue( "plugin_shoutbox_shouts_per_view", $this->_request->getValue('shouts_per_view'));
+
+ $blogSettings->setValue( "plugin_shoutbox_default_nick", $this->_request->getValue('default_nick'));
+ $blogSettings->setValue( "plugin_shoutbox_default_shout", $this->_request->getValue('default_shout'));
+
+ $blogSettings->setValue( "plugin_shoutbox_protected_nicks", $this->_request->getValue('protected_nicks'));
+ $blogSettings->setValue( "plugin_shoutbox_protection_password", $this->_request->getValue('protection_password'));
+
+ $this->_blogInfo->setSettings( $blogSettings );
+
+ // save the blogs settings
+ $blogs = new Blogs();
+ if( !$blogs->updateBlog( $this->_blogInfo->getId(), $this->_blogInfo )) {
+ $this->_view = new AdminErrorView( $this->_blogInfo );
+ $this->_view->setValue( "message", "An error occurred! " . $backLink);
+ $this->setCommonData();
+
+ return false;
+ }
+
+ // if everything went ok...
+ $this->_blogInfo->setSettings( $blogSettings );
+ $this->_session->setValue( "blogInfo", $this->_blogInfo );
+ $this->saveSession();
+
+ $this->_view = new AdminMessageView( $this->_blogInfo );
+ $this->_view->setMessage($endMessage . $backLink);
+ $this->setCommonData();
+
+ return true;
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/shoutbox/plugins/shoutbox/class/dao/shoutbox.class.php
===================================================================
--- plugins/trunk/shoutbox/plugins/shoutbox/class/dao/shoutbox.class.php 2005-03-31 14:08:02 UTC (rev 1664)
+++ plugins/trunk/shoutbox/plugins/shoutbox/class/dao/shoutbox.class.php 2005-03-31 15:28:42 UTC (rev 1665)
@@ -0,0 +1,321 @@
+<?php
+
+include_once( PLOG_CLASS_PATH."class/dao/model.class.php" );
+
+/**
+* schema of the table, so that we can tell ADOdb to create it
+* automatically for us
+*/
+/*
+define( ATOM_PASSWORDS_DB_SCHEMA,
+ "user_id I(10) NOTNULL,
+ password C(32) NOTNULL DEFAULT ''" );
+*/
+
+
+class Shoutbox extends Model {
+
+ var $blogId;
+ var $shoutsResult;
+ var $resultCounter;
+ var $config;
+ var $mail_alert;
+ var $max_length;
+ var $shouts_per_view;
+ var $default_nick;
+ var $default_shout;
+ var $protected_nicks;
+ var $protection_password;
+ var $current_page;
+
+ var $blogSettings;
+
+ function Shoutbox($blogId, $blogSettings) {
+ $this->blogSettings = $blogSettings;
+
+ /* Modelize it! */
+ $this->Model();
+
+ /* Check Setup */
+ $this->checkTables();
+
+ /* Initialization */
+ $this->blogId = $blogId;
+
+ $this->mail_alert = $blogSettings->getValue("plugin_shoutbox_mail_alert");
+ $this->max_length = $blogSettings->getValue( "plugin_shoutbox_max_length");
+ $this->shouts_per_view = $blogSettings->getValue( "plugin_shoutbox_shouts_per_view");
+
+ $this->default_nick = $blogSettings->getValue( "plugin_shoutbox_default_nick");
+ $this->default_shout = $blogSettings->getValue( "plugin_shoutbox_default_shout");
+
+ $this->protected_nicks = $blogSettings->getValue( "plugin_shoutbox_protected_nicks");
+ $this->protection_password = $blogSettings->getValue( "plugin_shoutbox_protection_password");
+
+ //Connections and blog data
+ //$this->connectDb();
+ //$this->blogSettings = new Config();
+ //$this->dbPrefix = $this->blogSettings->getValue( "db_prefix" );
+ //$this->blogId = $this->blogInfo->getId();
+ }
+
+
+ ###########################################################
+ # Database setup section. To be migrated to ADODB, but for the moment I can't get
+ # it working :(
+ /**
+ * @private
+ * Makes sure that the plog_atom_password table is there
+ */
+ function checkTables()
+ {
+ /* Maybe some day :(
+ $schema = "shout_id I(11) AUTOINCREMENT, blog_id I(11) NOTNULL, nickname C(255) NOTNULL, shout_text C(255) NOTNULL, shout_date T NOTNULL";
+
+ $tableName = $this->getPrefix() . "shoutbox_shouts";
+
+ $dict = NewDataDictionary( $this->_db );
+ $sqlArray = $dict->ChangeTableSQL( $tableName, $schema);
+ $result = $dict->ExecuteSQLArray( $sqlArray );
+ if(!$result)
+ die("No result :(" . $schema);
+ else
+ echo("Seems ok ". print_r($result) . " $schema<br>");
+ */
+ }
+
+ function checkTableExists() {
+ $dbPrefix = $this->getPrefix();
+ $sql = "SELECT * FROM {$dbPrefix}shoutbox_shouts";
+ if( !$this->_db->Execute($sql) ) {
+ return false;
+ }
+ return true;
+ }
+
+ function createTable() {
+ $dbPrefix = $this->getPrefix();
+
+ $sql = "SELECT * FROM {$dbPrefix}shoutbox_shouts";
+ if( !$this->_db->Execute($sql) ) {
+ // Make new setup
+ $sql = "
+CREATE TABLE {$dbPrefix}shoutbox_shouts (
+ shout_id INT(11) NOT NULL auto_increment,
+ blog_id INT(11) NOT NULL,
+ nickname TEXT NOT NULL,
+ shout_text TEXT NOT NULL,
+ shout_date DATETIME NOT NULL,
+ UNIQUE KEY cashout_id (shout_id)
+)
+";
+ if( !$this->_db->Execute($sql) ) {
+ die("The database setup failed!<br> <pre>". $sql . '</pre>');
+ }
+ }
+ }
+
+
+ function nextShout() {
+ if(!$this->shoutsResult) {
+ $sql = "SELECT * FROM " . $this->getPrefix() . "shoutbox_shouts ";
+ $sql .= "WHERE blog_id = {$this->blogId} ORDER BY shout_date DESC ";
+ if(!$this->current_page)
+ $this->current_page = 0;
+ $offset = $this->current_page * 15;
+ $maxShouts = 15;
+ $sql .= "LIMIT $offset, $maxShouts";
+ $this->shoutsResult = $this->Execute($sql);
+ if(!$this->shoutsResult)
+ return false;
+ }
+
+ $shout = $this->shoutsResult->FetchRow();
+ if(!$shout) {
+ $this->resultCounter = 0;
+ $this->shoutsResult = false;
+ return false;
+ }
+ $this->resultCounter++;
+
+ $shout['shout_date'] = Date("d/m/Y G:i", strtotime($shout['shout_date']));
+
+ return $shout;
+ }
+
+ function getShoutsArray($maxShouts = false) {
+ $shouts = array();
+ while($shout = $this->nextShout($maxShouts))
+ $shouts[] = $shout;
+
+ return $shouts;
+ }
+
+ function addShout($nickname, $shoutText) {
+ $nickname = strip_tags($nickname);
+
+ $protected_nicks = $this->protected_nicks;
+ $protection_password = $this->protection_password;
+
+ //echo("Controllo :$protection_password contro $nickname<br>");
+ $usesProtectedNick = false;
+ $parts = explode(' ', $protected_nicks);
+ //echo("PN: $protected_nicks <pre>" . print_r($parts) ."</pre>");
+
+ foreach($parts as $part) {
+ //echo("Controllo $part contro $nickname<br>");
+ if(preg_match("/$part/i", $nickname)) {
+ $usesProtectedNick = true;
+ continue;
+ }
+ }
+
+ if($usesProtectedNick) {
+ if(!preg_match("/:$protection_password\$/", $nickname)) {
+ echo('<font color="red"><b>');
+ echo('Nonononono! Questo nickname e` MIO, capito? :P<br/>');
+ echo("Pass: $protection_password nick: $nickname<br>");
+ echo('</b></font>');
+ if($this->mail_alert) {
+ $this->notifyUser($nickname, $shoutText, "alert");
+ }
+ return false;
+ }
+ else {
+ $nickname = preg_replace("/:$protection_password\$/", "", $nickname);
+ }
+ }
+
+ $shoutText = strip_tags($shoutText, '<a><br><b><i><strong>');
+ if (!get_magic_quotes_gpc()) {
+ $nickname = addslashes($nickname);
+ $shoutText = addslashes($shoutText);
+ }
+ if(strlen($nickname) == 0 || strlen($shoutText) == 0) {
+ echo('<font color="red"><b>');
+ echo('You need to insert a nickname and a message.</br>');
+ echo('</b></font>');
+ return false;
+ }
+ else if($nickname == $this->default_nick || $shoutText == $this->default_shout) {
+ echo('<font color="red"><b>');
+ echo('Shout something more original ;-)<br/>');
+ echo('</b></font>');
+ return false;
+ }
+ else if(strlen($shoutText) > $this->max_length) {
+ echo('<font color="red"><b>');
+ echo("Your shout is too long! It can be at most {$this->max_length} characters long<br/>");
+ echo('</b></font>');
+ return false;
+ }
+ else if(strlen($nickname) > 20) {
+ echo('<font color="red"><b>');
+ echo("Your nickname is too long! It can be at most 20 characters long<br/>");
+ echo('</b></font>');
+ return false;
+ }
+
+ $sql = "INSERT INTO " . $this->getPrefix() . "shoutbox_shouts (nickname, shout_text, blog_id, shout_date) VALUES" .
+ "('$nickname', '$shoutText', {$this->blogId}, '".Date('Y-m-d H:i:s')."')";
+ $result = $this->Execute($sql);
+
+ if($this->mail_alert) {
+ $this->notifyUser($nickname, $shoutText);
+ }
+
+ //die("<pre>$sql</pre>");
+
+ if(!$result) {
+ echo('Sorry, coud not add your shout.');
+ return false;
+ }
+ return true;
+ }
+
+ function deleteShout($id) {
+ $sql = "DELETE FROM " . $this->getPrefix() . "shoutbox_shouts WHERE shout_id = $id";
+ $result = $this->Execute($sql);
+ if(!$result) {
+ die('Could not delete the shouts!');
+ return false;
+ }
+ return true;
+ }
+
+ function alterShout($id, $nickname, $shoutText) {
+ $sql = "UPDATE " . $this->getPrefix() . "shoutbox_shouts SET nickname = '$nickname' , shout_text = '$shoutText' WHERE shout_id = $id";
+ $result = $this->Execute($sql);
+ if(!$result) {
+ die('Could not slter the shout!');
+ return false;
+ }
+ return true;
+ }
+
+ function getLastPage() {
+ $sql = "SELECT COUNT(*) as cnt FROM " . $this->getPrefix() . "shoutbox_shouts ";
+ $res = $this->Execute($sql);
+ if(!$res)
+ return 0;
+ $cnt = $res->FetchRow();
+ if($cnt['cnt'] > 0)
+ $cnt = floor($cnt['cnt'] / 15);
+ return $cnt;
+ }
+
+ ####################################################
+ # Extra functions
+ function notifyUser($nickname, $shout_text, $whichMail = "new") {
+ $users = new Users();
+ $userInfos = $users->getBlogUsers($this->blogId);
+
+ foreach($userInfos as $userInfo) {
+ $message = new EmailMessage();
+ $message->setFrom("Plog Shoutbox Plugin");
+ $message->addTo( $userInfo->getEmail());
+
+ if($whichMail == "new") {
+ $message->setSubject( "pLog Notification system: new shout in shoutbox" );
+ $body = <<<END
+There is a new shout in your shoutbox.
+From: $nickname
+Text: $shout_text
+END;
+ }
+ else if($whichMail == "alert") {
+ $message->setSubject( "pLog Notification system: shoutbox nickname protection alert" );
+ $body = <<<END
+Someone has tried to use your nickname in the shoutbox. The following message has been discarded:
+Text: $shout_text
+END;
+ }
+
+ $message->setBody($body);
+
+ $service = new EmailService();
+ $service->sendMessage( $message );
+ //echo('Sent mail to ' . $userInfo->getEmail() . '<br>');
+ }
+ }
+
+ ####################################################
+ # Public section. This is more a hack than anything, because things should be
+ # done using user actions and such... well... maybe next release...
+ function thinkAndDo() {
+ if(isset($_POST['shoutbox_submit'])) {
+ $this->addShout($_POST['shoutbox_nickname'], $_POST['shoutbox_text']);
+ //TODO: reload to discard used post
+ }
+ return $this->getShoutsArray($this->shouts_per_view);
+ }
+
+ function defaultNick() {
+ return $this->default_nick;
+ }
+
+ function defaultShout() {
+ return $this->default_shout;
+ }
+}
+?>
Added: plugins/trunk/shoutbox/plugins/shoutbox/pluginshoutbox.class.php
===================================================================
--- plugins/trunk/shoutbox/plugins/shoutbox/pluginshoutbox.class.php 2005-03-31 14:08:02 UTC (rev 1664)
+++ plugins/trunk/shoutbox/plugins/shoutbox/pluginshoutbox.class.php 2005-03-31 15:28:42 UTC (rev 1665)
@@ -0,0 +1,68 @@
+<?php
+
+// -- plugin manager stuff
+include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+include_once( PLOG_CLASS_PATH."class/plugin/eventpluginbase.class.php" );
+include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+
+// -- for the public side action
+include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
+include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
+
+// -- for the admin side action
+include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
+
+include_once( PLOG_CLASS_PATH."plugins/shoutbox/class/dao/shoutbox.class.php" );
+
+class PluginShoutbox extends PluginBase {
+ var $s;
+
+ function PluginShoutbox()
+ {
+ $this->PluginBase();
+
+ $this->desc = "Shoutbox plugin: unleash your visitors";
+ $this->author = "Palantir (radar at netpalantir.it)";
+ $this->id = "shoutbox";
+ $this->locales = Array();
+
+ $this->registerAdminAction("shoutbox", "PluginShoutboxAction" );
+ $this->registerAdminAction("shoutboxConfig", "PluginShoutboxConfigAction" );
+ $this->registerAdminAction( "updateShoutboxConfig", "PluginShoutboxUpdateConfigAction" );
+ $this->registerAdminAction( "deleteShouts", "PluginShoutboxDeleteShoutsAction" );
+ $this->registerAdminAction( "setupShoutbox", "PluginShoutboxSetupAction" );
+
+ $this->addMenuEntry( "/menu/controlCenter/manageSettings", "Shoutbox", "?op=shoutbox", "" );
+ }
+
+ function process( $eventType, $params )
+ {
+ // return the content as it came, as the caller class probably expected us to do
+ // something with it...
+ return $params;
+ }
+
+ function sayHello()
+ {
+ return( "Hello, world!" );
+ }
+
+ function thinkAndDo() {
+ if(!$this->s)
+ $this->s = new Shoutbox($this->blogInfo->getId(), $this->blogSettings, $this->config);
+ return $this->s->thinkAndDo();
+ }
+
+ function getDefaultNick() {
+ if(!$this->s)
+ $this->s = new Shoutbox($this->blogInfo->getId(), $this->blogSettings, $this->config);
+ return $this->s->default_nick;
+ }
+
+ function getDefaultShout() {
+ if(!$this->s)
+ $this->s = new Shoutbox($this->blogInfo->getId(), $this->blogSettings, $this->config);
+ return $this->s->default_shout;
+ }
+}
\ No newline at end of file
Added: plugins/trunk/shoutbox/plugins/shoutbox/templates/shoutbox.template
===================================================================
--- plugins/trunk/shoutbox/plugins/shoutbox/templates/shoutbox.template 2005-03-31 14:08:02 UTC (rev 1664)
+++ plugins/trunk/shoutbox/plugins/shoutbox/templates/shoutbox.template 2005-03-31 15:28:42 UTC (rev 1665)
@@ -0,0 +1,53 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=Shoutbox title=$locale->tr("Shoutbox")}
+
+{literal}
+<SCRIPT>
+var submitUsed = '';
+function doConfirm() {
+ if(submitUsed == 'del')
+ if(!confirm('Are you sure to delete? There is NO undo!'))
+ return false;
+ return true;
+}
+</SCRIPT>
+{/literal}
+
+<FORM method="POST" onSubmit="return doConfirm()">
+ <input type="hidden" name="op" value="deleteShouts" />
+
+
+ <input type="hidden" name="currentPage" value="{$this->current_page}" />
+
+<table class="info">
+ <thead>
+ <tr>
+ <!-- 775 -->
+ <th style="width:140px;">Nickname</th>
+ <th>Text</th>
+ <th style="width:10px;">Select</th>
+ </tr>
+ </thead>
+
+ <tbody>
+
+{foreach from=$shouts item=shout key=shoutId}
+ <tr>
+ <td>{$shout.nickname}</td>
+ <td>{$shout.shout_text}</td>
+ <td><INPUT type='checkbox' name=del[{$shout.shout_id}]/></td>
+ </tr>
+{/foreach}
+
+</table>
+
+<br/>
+<INPUT type="submit" name="delShouts" value="Delete selected" onFocus="submitUsed = 'del'"/>
+</FORM>
+
+<br/>
+
+<a href="admin.php?op=shoutboxConfig">Configure the shoutbox</a>
+
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file
Added: plugins/trunk/shoutbox/plugins/shoutbox/templates/shoutboxConfig.template
===================================================================
--- plugins/trunk/shoutbox/plugins/shoutbox/templates/shoutboxConfig.template 2005-03-31 14:08:02 UTC (rev 1664)
+++ plugins/trunk/shoutbox/plugins/shoutbox/templates/shoutboxConfig.template 2005-03-31 15:28:42 UTC (rev 1665)
@@ -0,0 +1,76 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=Shoutbox title=$locale->tr("Shoutbox")}
+
+<FORM method="POST">
+
+<fieldset class="inputField">
+ <input type="hidden" name="op" value="updateShoutboxConfig" />
+ <input type="hidden" name="pluginId" value="shoutboxPlugin" />
+
+ <legend>Shoutbox Settings</legend>
+
+ <div class="field">
+ <label for="mail_alert">Mail Alert</label>
+ <div class="formHelp">
+ <input type="checkbox" id="mail_alert" name="mail_alert" checked="{$mail_alert_checked}" />
+ Alert me when a new shout is added
+ </div>
+ </div>
+
+ <div class="field">
+ <label for="max_length">Maximum length</label>
+ <div class="formHelp">
+ <input type="input" size="3" name="max_length" value="{$max_length}">
+ Maximum lenght of a shout (number of characters)
+ </div>
+ </div>
+
+ <div class="field">
+ <label for="max_length">Visible Shouts</label>
+ <div class="formHelp">
+ <input type="input" size="3" name="shouts_per_view" value="{$shouts_per_view}">
+ Number of shouts to be shown on the page
+ </div>
+ </div>
+
+ <div class="field">
+ <label for="max_length">Default Shout</label>
+ <div class="formHelp">
+ <input type="input" size="20" name="default_shout" value="{$default_shout}">
+ Text to be written in the shout field, like: "Your shout here"
+ </div>
+ </div>
+
+ <div class="field">
+ <label for="max_length">Default Nickname</label>
+ <div class="formHelp">
+ <input type="input" size="20" name="default_nick" value="{$default_nick}">
+ Text to be written in the nickname field, like: "Your nickname here"
+ </div>
+ </div>
+
+ <div class="field">
+ <label for="max_length">Protected Nicknames</label>
+ <div class="formHelp">
+ <input type="input" size="20" name="protected_nicks" value="{$protected_nicks}">
+ Nicks to be password protected. Separate them by spaces. They are case insensitive
+ </div>
+ </div>
+
+ <div class="field">
+ <label for="max_length">Protection password</label>
+ <div class="formHelp">
+ <input type="input" size="20" name="protection_password" value="{$protection_password}">
+ Password for using nicks. To use a protected nick, write it like this: Palantir:MySecretPassword
+ </div>
+ </div>
+</fieldset>
+
+
+ <INPUT type="submit" name="updateOptions" value="Save options"/>
+</FORM>
+<br/>
+
+
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file
Added: plugins/trunk/shoutbox/templates/grey/footer.template
===================================================================
--- plugins/trunk/shoutbox/templates/grey/footer.template 2005-03-31 14:08:02 UTC (rev 1664)
+++ plugins/trunk/shoutbox/templates/grey/footer.template 2005-03-31 15:28:42 UTC (rev 1665)
@@ -0,0 +1,73 @@
+ </div>
+ <div id="Sidebar-r">
+
+ <div class="Sidetitle">
+ <h4>{$locale->tr("search")}</h4>
+ </div>
+ <p>
+ <form name="search_form" method="post" action="{$url->getIndexUrl()}">
+ <input type="text" name="searchTerms" value="" size="14" /><br/>
+ <input type="hidden" name="op" value="Search" />
+ <input type="hidden" name="blogId" value="{$blog->getId()}"/>
+ <input type="submit" name="Search" value="{$locale->tr("search")|capitalize}" />
+ </form>
+ </p>
+
+ <div class="Sidetitle">
+ <h4>{$locale->tr("archives")}</h4>
+ </div>
+ <p>
+ {foreach from=$archives item=month}
+ <a href="{$month->getUrl()}">{$month->getName()}</a><br/>
+ {/foreach}
+ </p>
+ <div class="Sidetitle">
+ <h4>{$locale->tr("categories")}</h4>
+ </div>
+ <p>
+ {foreach from=$articlecategories item=articleCategory}
+ <a href="{$url->categoryLink($articleCategory)}">{$articleCategory->getName()}</a> [{$articleCategory->getNumArticles()}]
+ <a class="nodecoration" href="{$url->categoryRssLink($articleCategory)}"><img src="{$url->getUrl("/imgs/rss_logo_small.gif")}" style="border:0px;" alt="RSS 0.90" /></a><br/>
+ {/foreach}
+ </p>
+ <div class="Sidetitle">
+ <h4>{$locale->tr("my_links")}</h4>
+ </div>
+ <p>
+ {foreach from=$mylinkscategories item=linkcategory}
+ <b>{$linkcategory->getName()}</b><br/>
+ {foreach from=$linkcategory->getLinks() item=link}
+ <a href="{$link->getUrl()}" title="{$link->getDescription()}">{$link->getName()}</a><br/>
+ {/foreach}
+ {/foreach}
+ </p>
+ <div class="Sidetitle">
+ <h4>{$locale->tr("syndicate")}</h4>
+ </div>
+ <p>
+ <a class="nodecoration" title="Link to the RSS 0.90 feed." href="{$url->rssLink("rss090")}"><img src="{$url->getUrl("/imgs/rss090_logo.gif")}" style="border:0px;" alt="RSS 0.90" /></a><br/>
+ <a class="nodecoration" title="Link to the RSS 1.0 feed." href="{$url->rssLink("rss10")}"><img src="{$url->getUrl("/imgs/rss10_logo.gif")}" style="border:0px;" alt="RSS 1.0" /></a><br/>
+ <a class="nodecoration" title="Link to the RSS 2.0 feed." href="{$url->rssLink("rss20")}"><img src="{$url->getUrl("/imgs/rss20_logo.gif")}" style="border:0px;" alt="RSS 2.0" /></a><br/>
+ <a class="nodecoration" title="Link to the Atom 0.3 feed." href="{$url->rssLink("atom")}"><img src="{$url->getUrl("/imgs/atom_logo.png")}" style="border:0px;" alt="Atom 0.3" /></a><br/>
+ </p>
+
+ <div class="Sidetitle">
+ <h4>Shoutbox</h4>
+ </div>
+ <p>
+ {include file="$blogtemplate/shoutbox.template"}
+ </p>
+
+ </div>
+ </div>
+ <div id="Bottommenu">
+ Valid <a href="http://validator.w3.org/check/referer">XHTML 1.0 Strict</a> and <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>.
+ </div>
+<!-- Please leave the credit intact. Thank you. -->
+<div id="Bottom">
+Powered by <a href="http://www.plogworld.org">pLog</a><br/>
+Design by <a href="http://www.bookofstyles.org/">Book of Styles</a><br/>
+</div>
+</div>
+</body>
+</html>
Added: plugins/trunk/shoutbox/templates/grey/shoutbox.template
===================================================================
--- plugins/trunk/shoutbox/templates/grey/shoutbox.template 2005-03-31 14:08:02 UTC (rev 1664)
+++ plugins/trunk/shoutbox/templates/grey/shoutbox.template 2005-03-31 15:28:42 UTC (rev 1665)
@@ -0,0 +1,37 @@
+{assign var="deafultNick" value=$shoutbox->getDefaultNick()}
+{assign var="defaultShout" value=$shoutbox->getDefaultShout()}
+
+{assign var="shouts" value=$shoutbox->thinkAndDo()}
+{foreach from=$shouts item=shout}
+ <<b>{$shout.nickname}</B>>
+ {$shout.shout_text}<br/>
+ ({$shout.shout_date})<br/>
+{/foreach}
+
+{literal}
+<SCRIPT>
+function shoutbox_clearField(el) {
+ if(el.name == 'shoutbox_text' && el.value == '{/literal}{$defaultShout}{literal}')
+ el.value = '';
+ else if(el.name == 'shoutbox_nickname' && el.value == '{/literal}{$deafultNick}{literal}')
+ el.value = '';
+}
+
+function shoutbox_resetField(el) {
+ var x = el.value;
+ if(el.name == 'shoutbox_text' && x.length == 0) {
+ el.value = '{/literal}{$defaultShout}{literal}';
+ }
+ else if(el.name == 'shoutbox_nickname' && el.value == '')
+ el.value = '{/literal}{$deafultNick}{literal}';
+}
+</SCRIPT>
+{/literal}
+
+<FORM method="POST">
+ <TEXTAREA name="shoutbox_text" cols="15" rows="2" onFocus="shoutbox_clearField(this)" onBlur="shoutbox_resetField(this)">{$defaultShout}</TEXTAREA>
+ <br>
+ <INPUT type="text" name="shoutbox_nickname" value="{$deafultNick}" size="15" onFocus="shoutbox_clearField(this)" onBlur="shoutbox_resetField(this)"/>
+ <br>
+ <INPUT type="submit" name="shoutbox_submit" value="Shout!"/>
+</FORM>
More information about the pLog-svn
mailing list