Dotclear

source: plugins/shareOn/_public.php @ 1941

Revision 1941, 3.6 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
15require_once dirname(__FILE__).'/_widgets.php';
16
17$core->addBehavior('publicHeadContent',
18     array('shareOnPublicBehavior','publicHeadContent')
19);
20$core->addBehavior('publicEntryBeforeContent',
21     array('shareOnPublicBehavior','publicEntryBeforeContent')
22);
23$core->addBehavior('publicEntryAfterContent',
24     array('shareOnPublicBehavior','publicEntryAfterContent')
25);
26
27if (!$core->blog->settings->shareOn_active)
28{
29     $core->tpl->addValue('shareOnButton',array('tplShareOn','disable'));
30}
31else
32{
33     $core->tpl->addValue('shareOnButton',array('tplShareOn','button'));
34}
35
36class shareOnPublicBehavior
37{
38     public static function publicHeadContent($core)
39     {
40          $s = $core->blog->settings->shareOn_style;
41          if (!$s) return;
42
43          echo 
44          "\n<!-- CSS for shareOn --> \n".
45          "<style type=\"text/css\"> \n".
46          html::escapeHTML($s)."\n".
47          "</style>\n";
48     }
49
50     public static function publicEntryBeforeContent($core,$_ctx)
51     {
52          return self::publicEntryContent($core,$_ctx,'before');
53     }
54
55     public static function publicEntryAfterContent($core,$_ctx)
56     {
57          return self::publicEntryContent($core,$_ctx,'after');
58     }
59
60     protected static function publicEntryContent($core,$_ctx,$place)
61     {
62          if (!$core->blog->settings->shareOn_active
63           || empty($core->shareOnButtons)) return;
64
65          if ('home.html' == $_ctx->current_tpl && $place == $core->blog->settings->shareOn_home_place 
66           || 'category.html' == $_ctx->current_tpl && $place == $core->blog->settings->shareOn_cat_place 
67           || 'tag.html' == $_ctx->current_tpl && $place == $core->blog->settings->shareOn_tag_place 
68           || 'post.html' == $_ctx->current_tpl && $place == $core->blog->settings->shareOn_post_place 
69          ) {
70               require_once dirname(__FILE__).'/inc/class.shareon.php';
71
72               $li = ''; 
73               foreach($core->shareOnButtons as $button_id => $button)
74               {
75                    $o = new $button($core);
76                    $res = $o->generateHTMLButton($_ctx->posts->getURL(),$_ctx->posts->post_title);
77
78                    if (!empty($res)) $li .= '<li class="button-'.$button_id.'">'.$res.'</li>';
79               }
80
81               if (empty($li)) return;
82               
83               $title = !$core->blog->settings->shareOn_title ?
84                    '' : '<h3>'.$core->blog->settings->shareOn_title.'</h3>';
85
86               echo '<div class="shareonentry">'.$title.'<ul>'.$li.'</ul></div>';
87          }
88     }
89}
90
91class tplShareOn
92{
93     public static function disable($a,$b=null)
94     {
95          return '';
96     }
97
98     public static function button($attr)
99     {
100          global $core;
101
102          if (empty($attr['button'])) return;
103
104          $small = '';
105          if (isset($attr['small']) && $attr['small'] == 1) { $small = 'true'; }
106          if (isset($attr['small']) && $attr['small'] == 0) { $small = 'false'; }
107
108          require_once dirname(__FILE__).'/inc/class.shareon.php';
109
110          return 
111          "<?php \n".
112          "if (\$core->blog->settings->shareOn_active ".
113          " && !empty(\$core->shareOnButtons) ".
114          " && isset(\$core->shareOnButtons['".$attr['button']."']) ".
115          " && \$_ctx->exists('posts')) { \n".
116          \$shareOnButton = new \$core->shareOnButtons['".$attr['button']."'](\$core); \n".
117          (!empty($small) ? \$shareOnButton->_small = ".$small."; \n" : '').
118          "  echo \$shareOnButton->generateHTMLButton(\$_ctx->posts->getURL(),\$_ctx->posts->post_title); \n".
119          "} \n".
120          "?> \n";
121     }
122}
123?>
Note: See TracBrowser for help on using the repository browser.

Sites map