backup de julho
[h2N7SspZmY.git] / lib / plugins / tag / action.php
blob80c173516dcd4fd43f3c95c21b307caa2a2944ed
1 <?php
2 /**
3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author Esther Brunner <wikidesign@gmail.com>
5 */
7 // must be run within Dokuwiki
8 if(!defined('DOKU_INC')) die();
10 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11 require_once(DOKU_PLUGIN.'action.php');
13 class action_plugin_tag extends DokuWiki_Action_Plugin {
15 /**
16 * return some info
18 function getInfo() {
19 return array(
20 'author' => 'Gina Häußge, Michael Klier, Esther Brunner',
21 'email' => 'dokuwiki@chimeric.de',
22 'date' => @file_get_contents(DOKU_PLUGIN.'tag/VERSION'),
23 'name' => 'Tag Plugin (ping component)',
24 'desc' => 'Ping technorati when a new page is created',
25 'url' => 'http://www.dokuwiki.org/plugin:tag',
29 /**
30 * register the eventhandlers
32 function register(&$contr) {
33 $contr->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'ping', array());
34 $contr->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, '_handle_act', array());
35 $contr->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, '_handle_tpl_act', array());
38 /**
39 * Ping Technorati
41 * @author Rui Carmo <http://the.taoofmac.com/space/blog/2005-08-07>
42 * @author Esther Brunner <wikidesign@gmail.com>
44 function ping(&$event, $param) {
45 if (!$this->getConf('pingtechnorati')) return false; // config: don't ping
46 if ($event->data[3]) return false; // old revision saved
47 if (@file_exists($event->data[0][0])) return false; // file not new
48 if (!$event->data[0][1]) return false; // file is empty
50 // okay, then let's do it!
51 global $conf;
53 $request = '<?xml version="1.0"?><methodCall>'.
54 '<methodName>weblogUpdates.ping</methodName>'.
55 '<params>'.
56 '<param><value>'.$conf['title'].'</value></param>'.
57 '<param><value>'.DOKU_URL.'</value></param>'.
58 '</params>'.
59 '</methodCall>';
60 $url = 'http://rpc.technorati.com:80/rpc/ping';
61 $header[] = 'Host: rpc.technorati.com';
62 $header[] = 'Content-type: text/xml';
63 $header[] = 'Content-length: '.strlen($request);
65 $http = new DokuHTTPClient();
66 // $http->headers = $header;
67 return $http->post($url, $request);
70 /**
71 * catch tag action
73 * @author Michael Klier <chi@chimeric.de>
75 function _handle_act(&$event, $param) {
76 if($event->data != 'showtag') return;
77 $event->preventDefault();
80 function _handle_tpl_act(&$event, $param) {
81 global $lang;
83 if($event->data != 'showtag') return;
84 $event->preventDefault();
86 $tagns = $this->getConf('namespace');
87 $flags = explode(',', trim($this->getConf('pagelist_flags')));
89 $tag = trim(str_replace($this->getConf('namespace').':', '', $_REQUEST['tag']));
90 $ns = trim($_REQUEST['ns']);
92 if ($helper =& plugin_load('helper', 'tag')) $pages = $helper->getTopic($ns, '', $tag);
94 if(!empty($pages)) {
96 // let Pagelist Plugin do the work for us
97 if (plugin_isdisabled('pagelist') || (!$pagelist = plugin_load('helper', 'pagelist'))) {
98 msg($this->getLang('missing_pagelistplugin'), -1);
99 return false;
102 $pagelist->setFlags($flags);
103 $pagelist->startList();
104 foreach ($pages as $page) {
105 $pagelist->addPage($page);
108 print '<h1>TAG: ' . $tag . '</h1>' . DOKU_LF;
109 print '<div class="level1">' . DOKU_LF;
110 print $pagelist->finishList();
111 print '</div>' . DOKU_LF;
113 } else {
114 print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
118 // vim:ts=4:sw=4:et:enc=utf-8: