Quantcast
Channel: 快乐云の小屋 » PHP
Viewing all articles
Browse latest Browse all 10

写了一个status.net的Amazon Affiliate插件

$
0
0

原创代码,转载请注明出处:http://guyun.me/

创建文件:plugin/Amazon/AmazonPlugin.php

<?php
/*
 * @author    Gary <guyun1982@gmail.com>
 * @link      http://guyun.me/
 * @brief	  
 * Plugin to add Amazon Affiliate to StatusNet sites
 *
 * This plugin lets you add Amazon ad units to your StatusNet site.
 *
 * We support the 4 ad sizes for the Universal Ad Platform (UAP):
 *
 *     Medium Rectangle (300*250)
 *     (Small) Rectangle (180*150)
 *     Leaderboard (728*90)
 *     Wide Skyscraper (160*600)
 *
 * Add the plugin to config.php like so:
 *
 *     addPlugin('Amazon', array('rectangle' => 'iframe src'));
 *
 */
 
 
if (!defined('STATUSNET')) {
	exit(1);
}
class AmazonPlugin extends UAPPlugin
{
	function initialize()
	{
		parent::initialize();
 
		// A little bit of chicanery so we avoid overwriting values that
		// are passed in with the constructor
 
		foreach (array('mediumRectangle', 'rectangle', 'leaderboard', 'wideSkyscraper') as $setting) {
			$value = common_config('amazon', strtolower($setting));
			if (!empty($value)) { // not found
				$this->$setting = $value;
			}
		}
	}
 
 
	/**
	 * Show a medium rectangle 'ad'
	 *
	 * @param Action $action Action being shown
	 *
	 * @return void
	 */
 
	protected function showMediumRectangle($action)
	{
		$action->element('iframe',
				array('width' => 300,
					'height' => 250,
					'scrolling' => "no",
					'border' => 0,
					'marginwidth' => 0,
					'style' => "border:none;",
					'frameborder' => 0,
					'src' => $this->mediumRectangle
					),
				'');
	}
 
	/**
	 * Show a rectangle 'ad'
	 *
	 * @param Action $action Action being shown
	 *
	 * @return void
	 */
 
	protected function showRectangle($action)
	{
		$action->element('iframe',
				array('width' => 180,
					'height' => 150,
					'scrolling' => "no",
					'border' => 0,
					'marginwidth' => 0,
					'style' => "border:none;",
					'frameborder' => 0,
					'src' => $this->rectangle
					),
				'');
	}
 
	/**
	 * Show a wide skyscraper ad
	 *
	 * @param Action $action Action being shown
	 *
	 * @return void
	 */
 
	protected function showWideSkyscraper($action)
	{
		$action->element('iframe',
				array('width' => 160,
					'height' => 600,
					'scrolling' => "no",
					'border' => 0,
					'marginwidth' => 0,
					'style' => "border:none;",
					'frameborder' => 0,
					'src' => $this->wideSkyscraper
					),
				'');
	}
 
	/**
	 * Show a leaderboard ad
	 *
	 * @param Action $action Action being shown
	 *
	 * @return void
	 */
 
	protected function showLeaderboard($action)
	{
		$action->element('iframe',
				array('width' => 728,
					'height' => 90,
					'scrolling' => "no",
					'border' => 0,
					'marginwidth' => 0,
					'style' => "border:none;",
					'frameborder' => 0,
					'src' => $this->leaderboard
					),
				'');
	}
}

使用的时候,和Google Adsense差不多,在config.php中,加入如下代码:

addPlugin('Amazon', array(
            'leaderboard' => "http://rcm.amazon.com/e/cm?t=pinkfacebook-20&o=1&p=48&l=ur1&category=kindlerotating&f=ifr",
            'wideSkyscraper' => "http://rcm.amazon.com/e/cm?t=pinkfacebook-20&o=1&p=14&l=ur1&category=electronics&f=ifr"
            ));

Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images