qa-basic-adsense.php 2.62 KB
Newer Older
Scott committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	File: qa-plugin/basic-adsense/qa-basic-adsense.php
	Description: Widget module class for AdSense widget plugin


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

Scott committed
23 24 25 26 27 28
class qa_basic_adsense
{
	public function allow_template($template)
	{
		return ($template!='admin');
	}
Scott committed
29 30


Scott committed
31 32 33 34
	public function allow_region($region)
	{
		return in_array($region, array('main', 'side', 'full'));
	}
Scott committed
35 36


Scott committed
37 38 39
	public function admin_form(&$qa_content)
	{
		$saved=false;
Scott committed
40

Scott committed
41 42 43 44 45
		if (qa_clicked('adsense_save_button')) {
			$trimchars="=;\"\' \t\r\n"; // prevent common errors by copying and pasting from Javascript
			qa_opt('adsense_publisher_id', trim(qa_post_text('adsense_publisher_id_field'), $trimchars));
			$saved=true;
		}
Scott committed
46

Scott committed
47 48
		return array(
			'ok' => $saved ? 'AdSense settings saved' : null,
Scott committed
49

Scott committed
50 51 52 53 54 55
			'fields' => array(
				array(
					'label' => 'AdSense Publisher ID:',
					'value' => qa_html(qa_opt('adsense_publisher_id')),
					'tags' => 'name="adsense_publisher_id_field"',
					'note' => 'Example: <i>pub-1234567890123456</i>',
Scott committed
56
				),
Scott committed
57
			),
Scott committed
58

Scott committed
59 60 61 62
			'buttons' => array(
				array(
					'label' => 'Save Changes',
					'tags' => 'name="adsense_save_button"',
Scott committed
63
				),
Scott committed
64 65 66
			),
		);
	}
Scott committed
67 68


Scott committed
69 70 71
	public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
	{
		$divstyle='';
Scott committed
72

Scott committed
73 74 75
		switch ($region) {
			case 'full': // Leaderboard
				$divstyle='width:728px; margin:0 auto;';
76
				// fall-through
Scott committed
77

Scott committed
78 79 80 81 82
			case 'main': // Leaderboard
				$width=728;
				$height=90;
				$format='728x90_as';
				break;
Scott committed
83

Scott committed
84 85 86 87 88 89
			case 'side': // Wide skyscraper
				$width=160;
				$height=600;
				$format='160x600_as';
				break;
		}
Scott committed
90 91 92

?>
<div style="<?php echo $divstyle?>">
Scott committed
93 94 95 96 97 98 99 100 101
	<script type="text/javascript">
	google_ad_client = <?php echo qa_js(qa_opt('adsense_publisher_id'))?>;
	google_ad_width = <?php echo qa_js($width)?>;
	google_ad_height = <?php echo qa_js($height)?>;
	google_ad_format = <?php echo qa_js($format)?>;
	google_ad_type = "text_image";
	google_ad_channel = "";
	</script>
	<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
Scott committed
102 103 104
</div>
<?php
	}
Scott committed
105
}