<?php

    lt_include( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
    lt_include( PLOG_CLASS_PATH."plugins/moblog/class/security/moblogbatchfilter.class.php" );
    
    /**
     * implementation a plugin to give Lifetype moblogging features (posting via email)
     */
    class PluginMoblog extends PluginBase
    {
    
        function PluginMoblog( $source )
        {
            $this->id = "moblog";
            $this->author = "The Lifetype Project";
            $this->locales = Array();
			$this->version = "20090415";
            $this->desc = "
Send a message with the following format ('start' and 'end' messages not included!):<br/>
<br/>
--- start of moblog message format ---<br/>
USER: your-lifetype-username<br/>
PASS: your-lifetype-password<br/>
BLOG: your-lifetype-blog-name or BLOGID: id-of-your-blog<br/>
TOPIC: your-subject (optional)<br/>
--- end of moblog message format ---<br/>
<br/>
The subject of the mail will be used as the subject for the article as long as there is no TOPIC set.<br/>
The message must be sent as plain text, and it can include as many attachment as needed.";

            $this->init();
        }
        
		/**
		 * set some actions and menu options
		 * @private
		 */
		function init()
		{
			// register the filter
			if( $this->getSource() == "index" ) {
				$this->registerFilter( "MoblogBatchFilter" );
			}
			else {
				// register actions
				$this->registerAdminAction( "moblogSettings", "AdminMoblogPluginSettingsAction" );
				$this->registerAdminAction( "updateMoblogSettings", "AdminMoblogPluginUpdateSettingsAction" );
				$this->registerAdminAction( "moblogbatchSettings", "AdminMoblogBatchPluginSettingsAction" );
				$this->registerAdminAction( "updateMoblogBatchSettings", "AdminMoblogBatchPluginUpdateSettingsAction" );


				// register menu entries
				$this->addMenuEntry(    "/menu/controlCenter/manageSettings",   // menu path
	                                    "moblogSettings",                       // menu id
	                                    "admin.php?op=moblogSettings",          // url
	                                    "moblogSettings"                        // text to show
	                               );
				$this->addMenuEntry(    "/menu/adminSettings/GlobalSettings",   // menu path
				                        "moblogbatchSettings",                  // menu id
				                        "admin.php?op=moblogbatchSettings",     // url
				                        "moblogbatchSettings"                   // text to show
				                    );
			}
		}
		
		
		/**
		 * register the plugin
		 * @private
		 */
		function register()
		{
			// register our permissions
			// add our new permission if it doesn't exist yet
			lt_include( PLOG_CLASS_PATH."class/dao/permissions.class.php" );
			$perms = new Permissions();
			if( !$perms->getPermissionByName( "manage_moblogbatch" )) {
				$perm = new Permission( "manage_moblogbatch", "manage_moblogbatch_desc" );
				$perm->setAdminOnlyPermission( true );
				$perms->addPermission( $perm );
			}			
		}       

		function getPluginConfigurationKeys()
		{
			lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );

			return( Array(
				Array( "name" => "plugin_moblog_enabled", "type" => "boolean" ),
				Array( "name" => "plugin_moblog_resource_preview_type",
                       "validator" => new IntegerValidator(),
                       "type" => "integer",
                       "allowEmpty" => true),

                    // Note: this API doesn't allow multiple IDs to be set, ie. no nested validators, like:
                    //  new ArrayValidator(new IntegerValidator())
                Array( "name" => "plugin_moblog_article_category_ids",
                       "validator" => new IntegerValidator(),
                       "type" => "integer",
                       "allowEmpty" => true),
				Array( "name" => "plugin_moblog_gallery_resource_album_ids",
                       "validator" => new IntegerValidator(),
                       "type" => "integer",
                       "allowEmpty" => true),
			));
		}
    }
?>
