1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of zoneclearFeedServer, a plugin for Dotclear 2. |
---|
4 | # |
---|
5 | # Copyright (c) 2009-2011 JC Denis, BG 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 | |
---|
13 | if (!defined('DC_CONTEXT_ADMIN')){return;} |
---|
14 | |
---|
15 | # Namespace for settings |
---|
16 | $core->blog->settings->addNamespace('zoneclearFeedServer'); |
---|
17 | |
---|
18 | # Widgets |
---|
19 | require_once dirname(__FILE__).'/_widgets.php'; |
---|
20 | |
---|
21 | # Admin menu |
---|
22 | $_menu['Plugins']->addItem( |
---|
23 | __('Feeds server'), |
---|
24 | 'plugin.php?p=zoneclearFeedServer','index.php?pf=zoneclearFeedServer/icon.png', |
---|
25 | preg_match('/plugin.php\?p=zoneclearFeedServer(&.*)?$/',$_SERVER['REQUEST_URI']), |
---|
26 | $core->auth->check('admin',$core->blog->id) |
---|
27 | ); |
---|
28 | |
---|
29 | if ($core->auth->check('admin',$core->blog->id)) |
---|
30 | { |
---|
31 | # Dashboard icon |
---|
32 | $core->addBehavior('adminDashboardIcons',array('zoneclearFeedServerAdminBehaviors','adminDashboardIcons')); |
---|
33 | # Add info about feed on post page sidebar |
---|
34 | $core->addBehavior('adminPostHeaders',array('zoneclearFeedServerAdminBehaviors','adminPostHeaders')); |
---|
35 | $core->addBehavior('adminPostFormSidebar',array('zoneclearFeedServerAdminBehaviors','adminPostFormSidebar')); |
---|
36 | } |
---|
37 | # Delete related info about feed post in meta table |
---|
38 | $core->addBehavior('adminBeforePostDelete',array('zoneclearFeedServerAdminBehaviors','adminBeforePostDelete')); |
---|
39 | |
---|
40 | # Take care about tweakurls (thanks Mathieu M.) |
---|
41 | if (version_compare($core->plugins->moduleInfo('tweakurls','version'),'0.8','>=')) { |
---|
42 | $core->addbehavior('zoneclearFeedServerAfterPostCreate',array('zoneclearFeedServer','tweakurlsAfterPostCreate')); |
---|
43 | } |
---|
44 | |
---|
45 | class zoneclearFeedServerAdminBehaviors |
---|
46 | { |
---|
47 | # Add icon on dashboard if there are disabled feeds |
---|
48 | public static function adminDashboardIcons($core,$icons) |
---|
49 | { |
---|
50 | $zcfs = new zoneclearFeedServer($core); |
---|
51 | $count = $zcfs->getFeeds(array('feed_status'=>'0'),true)->f(0); |
---|
52 | if (!$count) return; |
---|
53 | |
---|
54 | $str = ($count > 1) ? __('%s disabled feeds') : __('one disable feed'); |
---|
55 | |
---|
56 | $icons['zcfs'] = new ArrayObject(array( |
---|
57 | sprintf($str,$count), |
---|
58 | 'plugin.php?p=zoneclearFeedServer&part=feeds&sortby=feed_status&order=asc', |
---|
59 | 'index.php?pf=zoneclearFeedServer/icon-b.png' |
---|
60 | )); |
---|
61 | } |
---|
62 | |
---|
63 | # Load javascript for toggle menu |
---|
64 | public static function adminPostHeaders() |
---|
65 | { |
---|
66 | return |
---|
67 | '<script type="text/javascript">$(function() { '. |
---|
68 | "$('#zcfs-form-title').toggleWithLegend($('#zcfs-form-content'),{cookie:'dcx_zcfs_admin_form_sidebar'}); ". |
---|
69 | '});</script>'; |
---|
70 | } |
---|
71 | |
---|
72 | # Add info about feed on post page sidebar |
---|
73 | public static function adminPostFormSidebar($post) |
---|
74 | { |
---|
75 | global $core; |
---|
76 | |
---|
77 | if (null === $post || $post->post_type != 'post') return; |
---|
78 | |
---|
79 | $url = $core->meta->getMetadata(array('post_id'=>$post->post_id,'meta_type'=>'zoneclearfeed_url','limit'=>1)); |
---|
80 | $url = $url->isEmpty() ? '' : $url->meta_id; |
---|
81 | |
---|
82 | if (!$url) return; |
---|
83 | |
---|
84 | $author = $core->meta->getMetadata(array('post_id'=>$post->post_id,'meta_type'=>'zoneclearfeed_author','limit'=>1)); |
---|
85 | $author = $author->isEmpty() ? '' : $author->meta_id; |
---|
86 | |
---|
87 | $site = $core->meta->getMetadata(array('post_id'=>$post->post_id,'meta_type'=>'zoneclearfeed_site','limit'=>1)); |
---|
88 | $site = $site->isEmpty() ? '' : $site->meta_id; |
---|
89 | |
---|
90 | $sitename = $core->meta->getMetadata(array('post_id'=>$post->post_id,'meta_type'=>'zoneclearfeed_sitename','limit'=>1)); |
---|
91 | $sitename = $sitename->isEmpty() ? '' : $sitename->meta_id; |
---|
92 | |
---|
93 | echo |
---|
94 | '<div id="zoneclear-feed">'. |
---|
95 | '<h3 id="zcfs-form-title" class="clear">'.__('Feed source').'</h3>'. |
---|
96 | '<div id="zcfs-form-content">'. |
---|
97 | '<p>'. |
---|
98 | '<a href="'.$url.'" title="'.$author.' - '.$url.'">'.__('feed URL').'</a> - '. |
---|
99 | '<a href="'.$site.'" title="'.$sitename.' - '.$site.'">'.__('site URL').'</a>'. |
---|
100 | '</p>'; |
---|
101 | |
---|
102 | if ($core->auth->check('admin',$core->blog->id)) |
---|
103 | { |
---|
104 | $fid = $core->meta->getMetadata(array('post_id'=>$post->post_id,'meta_type'=>'zoneclearfeed_id','limit'=>1)); |
---|
105 | if (!$fid->isEmpty()) |
---|
106 | { |
---|
107 | echo '<p><a class="button" href="plugin.php?p=zoneclearFeedServer&part=feed&feed_id='.$fid->meta_id.'">'.__('Edit this feed').'</a></p>'; |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | echo |
---|
112 | '</div></div>'; |
---|
113 | } |
---|
114 | |
---|
115 | # Delete related info about feed post in meta table |
---|
116 | public static function adminBeforePostDelete($post_id) |
---|
117 | { |
---|
118 | global $core; |
---|
119 | |
---|
120 | $post_id = (integer) $post_id; |
---|
121 | $types = array( |
---|
122 | 'zoneclearfeed_url', |
---|
123 | 'zoneclearfeed_author', |
---|
124 | 'zoneclearfeed_site', |
---|
125 | 'zoneclearfeed_sitename', |
---|
126 | 'zoneclearfeed_id' |
---|
127 | ); |
---|
128 | |
---|
129 | $core->con->execute( |
---|
130 | 'DELETE FROM '.$core->prefix.'meta '. |
---|
131 | 'WHERE post_id = '.$post_id.' '. |
---|
132 | 'AND meta_type '.$core->con->in($types).' ' |
---|
133 | ); |
---|
134 | } |
---|
135 | } |
---|
136 | ?> |
---|