1<?php
2
3/**
4 * Google Ads for DokuWiki
5 *
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Terence J. Grant<tjgrant@tatewake.com>
8 */
9
10$gads_loaded = 0;
11
12function gads_load()
13{
14    global $gads_loaded, $gads_settings;
15
16    $gads_file = dirname(__FILE__) . '/local_pref.php';
17
18    if ($gads_loaded == 0) {
19        if (file_exists($gads_file)) {
20            include($gads_file);
21
22            $gads_loaded = 1;
23        }
24    }
25}
26
27function gads_write($fp, $name, $val)
28{
29    fwrite($fp, '$gads_settings[\'' . $name . '\'] = \'' . $val . '\';' . "\n");
30}
31
32function gads_save()
33{
34    global $gads_loaded, $gads_settings;
35
36    $gads_file = dirname(__FILE__) . '/local_pref.php';
37
38    if (is_writable($gads_file) || is_writable(dirname(__FILE__))) {
39        $fp = fopen($gads_file, "w");
40        fwrite($fp, '<?php' . "\n// This file is automatically generated\n");
41        gads_write($fp, 'code', $gads_settings['code']);
42        gads_write($fp, 'dontcountadmin', $gads_settings['dontcountadmin']);
43        gads_write($fp, 'dontcountmanager', $gads_settings['dontcountmanager']);
44        gads_write($fp, 'dontcountusers', $gads_settings['dontcountusers']);
45        fclose($fp);
46
47        ptln('<div class="success">' . 'Google AdSense preferences saved successfully.' . '</div>');
48    } else {
49        ptln('<div class="error">' . 'Google AdSense preferences is not writable by the server.' . '</div>');
50    }
51}
52
53function gads_code()
54{
55    global $gads_loaded, $gads_settings, $conf, $INFO;
56
57    if ($gads_settings['code']) {
58        if ($GLOBALS['ACT'] != 'show') {
59            return;
60        }
61        if ($gads_settings['dontcountusers'] and $INFO['client']) {
62            return;
63        }
64        if ($gads_settings['dontcountmanager'] and ($INFO['ismanager'] and not($INFO['isadmin']))) {
65            return;
66        }
67        if ($gads_settings['dontcountadmin'] and $INFO['isadmin']) {
68            return;
69        }
70        ptln(stripslashes($gads_settings['code']));
71    }
72}
73
74//Load settings
75gads_load();
76