qa-basic-adsense.php 2.87 KB
Newer Older
Gideon Greenspan committed
1 2 3
<?php

/*
Gideon Greenspan committed
4
	Question2Answer by Gideon Greenspan and contributors
Gideon Greenspan committed
5 6 7

	http://www.question2answer.org/

8

Gideon Greenspan committed
9 10 11 12 13 14 15 16 17
	File: qa-plugin/basic-adsense/qa-basic-adsense.php
	Version: See define()s at top of qa-include/qa-base.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.
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27
	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
*/

	class qa_basic_adsense {
28

29
		public function allow_template($template)
Gideon Greenspan committed
30 31 32 33
		{
			return ($template!='admin');
		}

34

35
		public function allow_region($region)
Gideon Greenspan committed
36
		{
37
			return in_array($region, array('main', 'side', 'full'));
Gideon Greenspan committed
38 39
		}

40

41
		public function admin_form(&$qa_content)
Gideon Greenspan committed
42 43
		{
			$saved=false;
44 45

			if (qa_clicked('adsense_save_button')) {
Gideon Greenspan committed
46 47 48 49
				$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;
			}
50

Gideon Greenspan committed
51 52
			return array(
				'ok' => $saved ? 'AdSense settings saved' : null,
53

Gideon Greenspan committed
54 55 56 57
				'fields' => array(
					array(
						'label' => 'AdSense Publisher ID:',
						'value' => qa_html(qa_opt('adsense_publisher_id')),
Gideon Greenspan committed
58 59
						'tags' => 'name="adsense_publisher_id_field"',
						'note' => 'Example: <i>pub-1234567890123456</i>',
Gideon Greenspan committed
60 61
					),
				),
62

Gideon Greenspan committed
63 64 65
				'buttons' => array(
					array(
						'label' => 'Save Changes',
Gideon Greenspan committed
66
						'tags' => 'name="adsense_save_button"',
Gideon Greenspan committed
67 68 69 70 71 72
					),
				),
			);
		}


73
		public function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
Gideon Greenspan committed
74 75
		{
			$divstyle='';
76

Gideon Greenspan committed
77 78 79
			switch ($region) {
				case 'full': // Leaderboard
					$divstyle='width:728px; margin:0 auto;';
80

Gideon Greenspan committed
81 82 83 84 85
				case 'main': // Leaderboard
					$width=728;
					$height=90;
					$format='728x90_as';
					break;
86

Gideon Greenspan committed
87 88 89 90 91 92
				case 'side': // Wide skyscraper
					$width=160;
					$height=600;
					$format='160x600_as';
					break;
			}
93

Gideon Greenspan committed
94 95
?>
<div style="<?php echo $divstyle?>">
Gideon Greenspan committed
96
<script type="text/javascript">
Gideon Greenspan committed
97 98 99 100 101 102 103 104 105 106 107 108 109
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>
</div>
<?php
		}
110

Gideon Greenspan committed
111
	}
112

Gideon Greenspan committed
113 114 115 116

/*
	Omit PHP closing tag to help avoid accidental output
*/