[pLog-svn] r3957 - in nonfree/plugins/trunk/ads: . class/action
class/view locale templates
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Tue Sep 12 16:25:00 GMT 2006
Author: oscar
Date: 2006-09-12 16:24:59 +0000 (Tue, 12 Sep 2006)
New Revision: 3957
Modified:
nonfree/plugins/trunk/ads/class/action/pluginadsupdatesettingsaction.class.php
nonfree/plugins/trunk/ads/class/view/adminpluginadssettingsview.class.php
nonfree/plugins/trunk/ads/locale/locale_en_UK.php
nonfree/plugins/trunk/ads/pluginads.class.php
nonfree/plugins/trunk/ads/templates/settings.template
Log:
added support for selecting which blogs need to be shown ads and which don't. There are three posibilities:
- all blogs (default)
- only the blogs in a list
- all blogs except the ones in a list
This should cover most of the cases, let me know if there should be any other option...
Modified: nonfree/plugins/trunk/ads/class/action/pluginadsupdatesettingsaction.class.php
===================================================================
--- nonfree/plugins/trunk/ads/class/action/pluginadsupdatesettingsaction.class.php 2006-09-11 21:22:20 UTC (rev 3956)
+++ nonfree/plugins/trunk/ads/class/action/pluginadsupdatesettingsaction.class.php 2006-09-12 16:24:59 UTC (rev 3957)
@@ -16,11 +16,16 @@
$pluginEnabled = (bool)$this->_request->getValue( "pluginEnabled" );
$pluginAdsCode = $this->_request->getValue( "adCode" );
$pluginAdsPosition = $this->_request->getValue( "adPosition", PLUGIN_ADS_POSITION_TOP );
+ $pluginAdsBlogs = $this->_request->getValue( "adBlogs", PLUGIN_ADS_BLOGS_SHOW_ALL );
+ $pluginAdsBlogsList = $this->_request->getValue( "adBlogsList", Array());
+ // save the plugin settings
$config =& Config::getConfig();
$config->setValue( "plugin_ads_enabled", (bool)$pluginEnabled );
$config->setValue( "plugin_ads_code", $pluginAdsCode );
$config->setValue( "plugin_ads_position", $pluginAdsPosition );
+ $config->setValue( "plugin_ads_blogs", $pluginAdsBlogs );
+ $config->setValue( "plugin_ads_blogs_list", $pluginAdsBlogsList );
$config->save();
$this->_view = new AdminPluginAdsSettingsView( $this->_blogInfo );
Modified: nonfree/plugins/trunk/ads/class/view/adminpluginadssettingsview.class.php
===================================================================
--- nonfree/plugins/trunk/ads/class/view/adminpluginadssettingsview.class.php 2006-09-11 21:22:20 UTC (rev 3956)
+++ nonfree/plugins/trunk/ads/class/view/adminpluginadssettingsview.class.php 2006-09-12 16:24:59 UTC (rev 3957)
@@ -2,6 +2,7 @@
include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
class AdminPluginAdsSettingsView extends AdminPluginTemplatedView
{
@@ -16,7 +17,22 @@
$this->setValue( "pluginEnabled", $config->getValue( "plugin_ads_enabled" ));
$this->setValue( "adCode", $config->getValue( "plugin_ads_code" ));
$this->setValue( "adPosition", $config->getValue( "plugin_ads_position" ));
+ $this->setValue( "adBlogs", $config->getValue( "plugin_ads_blogs" ));
+ // ge the list of blogs and load them
+ $blogList = $config->getValue( "plugin_ads_blogs_list" );
+ if( !is_array( $blogList ))
+ $blogInfo = Array();
+ else {
+ $blogs = new Blogs();
+ foreach( $blogList as $blogId ) {
+ $blog = $blogs->getBlogInfo( $blogId );
+ if( $blog )
+ $blogInfo[] = $blog;
+ }
+ }
+ $this->setValue( "blogs", $blogInfo );
+
return( parent::render());
}
}
Modified: nonfree/plugins/trunk/ads/locale/locale_en_UK.php
===================================================================
--- nonfree/plugins/trunk/ads/locale/locale_en_UK.php 2006-09-11 21:22:20 UTC (rev 3956)
+++ nonfree/plugins/trunk/ads/locale/locale_en_UK.php 2006-09-12 16:24:59 UTC (rev 3957)
@@ -9,5 +9,12 @@
$messages['ad_position_help'] = 'Where to show the ads. If using \'custom\', please make sure to implement your custom logic in method PluginAds::customAdPosition()';
$messages['ad_position_top'] = 'Top';
$messages['ad_position_bottom'] = 'Bottom';
-$messages['ad_position_custom'] = 'Custom'
+$messages['ad_position_custom'] = 'Custom';
+$messages['ad_blogs'] = 'Target blogs';
+$messages['ad_blogs_help'] = 'Which blogs should see ads?';
+$messages['ad_blogs_all'] = 'All';
+$messages['ad_blogs_include_list'] = 'Only blogs in the list below';
+$messages['ad_blogs_exclude_list'] = 'All blogs except the ones in the list below';
+$messages['ad_blogs_list'] = 'Blogs';
+$messages['ad_blogs_list_help'] = 'List of blogs that should see/not see ads depending on the value of the parameter above';
?>
\ No newline at end of file
Modified: nonfree/plugins/trunk/ads/pluginads.class.php
===================================================================
--- nonfree/plugins/trunk/ads/pluginads.class.php 2006-09-11 21:22:20 UTC (rev 3956)
+++ nonfree/plugins/trunk/ads/pluginads.class.php 2006-09-12 16:24:59 UTC (rev 3957)
@@ -3,10 +3,20 @@
include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+ /**
+ * Where to show ads
+ */
define( "PLUGIN_ADS_POSITION_TOP", 1 );
define( "PLUGIN_ADS_POSITION_BOTTOM", 2 );
define( "PLUGIN_ADS_POSITION_CUSTOM", 3 );
+ /**
+ * mode of operation (i.e. which blogs get to see ads?)
+ */
+ define( "PLUGIN_ADS_BLOGS_SHOW_ALL", 1 );
+ define( "PLUGIN_ADS_BLOGS_INCLUDE_LIST", 2 );
+ define( "PLUGIN_ADS_BLOGS_EXCLUDE_LIST", 3 );
+
class PluginAds extends PluginBase
{
function PluginAds()
@@ -27,15 +37,33 @@
}
/**
- * Please implement this method with your custom logic to determine whether to show
- * or not show ads for this blog
- *
- * @param
- * @return
+ * whether the current blog should be shown ads or not
*/
function blogShowAds( $blog )
{
- return( true );
+ // get the mode
+ $config =& Config::getConfig();
+ $mode = $config->getValue( "plugin_ads_blogs", PLUGIN_ADS_BLOGS_SHOW_ALL );
+
+ $show = true;
+
+ // based on the mode, check whether the blog needs ads
+ if( $mode == PLUGIN_ADS_BLOGS_SHOW_ALL ) {
+ // ads for everyone!
+ $show = true;
+ }
+ elseif( $mode == PLUGIN_ADS_BLOGS_INCLUDE_LIST ) {
+ // load the list of blogs and see if this one is in the list
+ $blogList = $config->getValue( "plugin_ads_blogs_list" );
+ $show = (is_integer(array_search( $blog->getId(), $blogList )));
+ }
+ elseif( $mode == PLUGIN_ADS_BLOGS_EXCLUDE_LIST ) {
+ // load the list of blogs and see if this one is *not* in the list
+ $blogList = $config->getValue( "plugin_ads_blogs_list" );
+ $show = (array_search( $blog->getId(), $blogList ) === FALSE );
+ }
+
+ return( $show );
}
/**
@@ -66,26 +94,28 @@
if( !$config->getValue( "plugin_ads_enabled" ))
return( true );
- // otherwise get the content and process them
- $content = $params['content'];
+ if( $this->blogShowAds( $this->blogInfo )) {
+ // otherwise get the content and process them
+ $content = $params['content'];
- // get the configured ad code
- $code = $config->getValue( "plugin_ads_code" );
- $pos = $config->getValue( "plugin_ads_position", PLUGIN_ADS_POSITION_TOP );
+ // get the configured ad code
+ $code = $config->getValue( "plugin_ads_code" );
+ $pos = $config->getValue( "plugin_ads_position", PLUGIN_ADS_POSITION_TOP );
- // put the ad in place
- if( $pos == PLUGIN_ADS_POSITION_TOP ) {
- $content = str_replace( "<body>", "<body>$code", $content );
+ // put the ad in place
+ if( $pos == PLUGIN_ADS_POSITION_TOP ) {
+ $content = str_replace( "<body>", "<body>$code", $content );
+ }
+ elseif( $pos == PLUGIN_ADS_POSITION_BOTTOM ) {
+ $content = str_replace( "</body>", "$code</body>", $content );
+ }
+ else {
+ $content = $this->customAdPosition( $content );
+ }
+
+ $params['content'] = $content;
}
- elseif( $pos == PLUGIN_ADS_POSITION_BOTTOM ) {
- $content = str_replace( "</body>", "$code</body>", $content );
- }
- else {
- $content = $this->customAdPosition( $content );
- }
- $params['content'] = $content;
-
return( true );
}
}
Modified: nonfree/plugins/trunk/ads/templates/settings.template
===================================================================
--- nonfree/plugins/trunk/ads/templates/settings.template 2006-09-11 21:22:20 UTC (rev 3956)
+++ nonfree/plugins/trunk/ads/templates/settings.template 2006-09-12 16:24:59 UTC (rev 3957)
@@ -1,6 +1,6 @@
{include file="$admintemplatepath/header.template"}
{include file="$admintemplatepath/navigation.template" showOpt=configureAds title=$locale->tr("configureAds")}
-<form name="configureAds" method="post" action="admin.php">
+<form name="configureAds" method="post" action="admin.php" onSubmit="listSelectAll('blogList');return true">
<fieldset class="inputField">
<legend>{$locale->tr("configureAds")}</legend>
{include file="$admintemplatepath/successmessage.template"}
@@ -14,6 +14,31 @@
</div>
<div class="field">
+ <label for="adBlogs">{$locale->tr("ad_blogs")}</label>
+ <div class="formHelp">{$locale->tr("ad_blogs_help")}</div>
+ <select name="adBlogs" {literal}onChange="elem=document.getElementById('blogListBlock');if(this.selectedIndex!=0){elem.style.display='block';}else{elem.style.display='none';}"{/literal}>
+ <option value="1" {if $adBlogs==1}selected="selected"{/if}>{$locale->tr("ad_blogs_all")}</option>
+ <option value="2" {if $adBlogs==2}selected="selected"{/if}>{$locale->tr("ad_blogs_include_list")}</option>
+ <option value="3" {if $adBlogs==3}selected="selected"{/if}>{$locale->tr("ad_blogs_exclude_list")}</option>
+ </select>
+ </div>
+
+ <div class="field" id="blogListBlock" {if $adBlogs == 1}style="display:none"{/if}>
+ <label for="adBlogList">{$locale->tr("ad_blogs_list")}</label>
+ <span class="required">*</span>
+ <div class="formHelp">{$locale->tr("ad_blogs_list_help")}</div>
+ <select name="adBlogsList[]" id="blogList" multiple="multiple" style="width:40%" size="5">
+ {foreach from=$blogs item=blog}
+ <option value="{$blog->getId()}">{$blog->getBlog()}</option>
+ {/foreach}
+ </select>
+ <br />
+ <input type="button" class="button" onClick="window.open('?op=siteBlogsChooser&mode=2','BlogChooser','scrollbars=yes,resizable=yes,toolbar=no,height=450,width=600');" value="{$locale->tr("add")}" />
+ <input type="button" class="button" onClick="removeSelectedItemsFromList(document.getElementById('adBlogList'))" value="{$locale->tr("remove_selected")}" />
+ </div>
+
+
+ <div class="field">
<label for="adPosition">{$locale->tr("ad_position")}</label>
<div class="formHelp">{$locale->tr("ad_position_help")}</div>
<select name="adPosition">
More information about the pLog-svn
mailing list