Dotclear

source: plugins/shareOn/_widgets.php @ 1941

Revision 1941, 2.0 KB checked in by JcDenis, 14 years ago (diff)

shareOn 0.1:

  • First lab release (closes #260)
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of shareOn, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009 JC Denis and contributors
6# jcdenis@gdwd.com
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11# -- END LICENSE BLOCK ------------------------------------
12
13if (!defined('DC_RC_PATH')){return;}
14
15$core->addBehavior('initWidgets',array('shareOnWidget','adminShareOn'));
16
17class shareOnWidget
18{
19     public static function adminShareOn($w)
20     {
21          global $core;
22
23          require_once dirname(__FILE__).'/inc/class.shareon.php';
24
25          $w->create('shareon',
26               __('Share on'),array('shareOnWidget','publicShareOn')
27          );
28          $w->shareon->setting('title',
29               __('Title:'),__('Share on'),'text'
30          );
31          $w->shareon->setting('small',
32               __('Use small buttons'),1,'check'
33          );
34          foreach($core->shareOnButtons as $button_id => $button)
35          {
36               $o = new $button($core);
37
38               $w->shareon->setting('use_'.$button_id,
39                    sprintf(__('Add %s'),$o->name),1,'check'
40               );
41          }
42     }
43
44     public static function publicShareOn($w)
45     {
46          global $core, $_ctx;
47
48          # Disable
49          if (!$core->blog->settings->shareOn_active) return;
50          # No button
51          if (empty($core->shareOnButtons)) return;
52          # Not in post context
53          if ('post.html' != $_ctx->current_tpl) return;
54
55          require_once dirname(__FILE__).'/inc/class.shareon.php';
56
57          $li = ''; 
58          foreach($core->shareOnButtons as $button_id => $button)
59          {
60               $n = 'use_'.$button_id;
61               if (!$w->{$n}) continue;
62
63               $o = new $button($core);
64               $o->_active = true;
65               $o->_small = (boolean) $w->small;
66               $res = $o->generateHTMLButton($_ctx->posts->getURL(),$_ctx->posts->post_title);
67
68               if (!empty($res)) $li .= '<li>'.$res.'</li>';
69          }
70
71          if (empty($li)) return;
72
73          return
74          '<div class="shareonwidget">'.
75          ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '').
76          '<ul>'.$li.'</ul>'.
77          '</div>';
78     }
79}
80?>
Note: See TracBrowser for help on using the repository browser.

Sites map