1 | <?php |
---|
2 | # ***** BEGIN LICENSE BLOCK ***** |
---|
3 | # |
---|
4 | # This file is part of Contribute, a plugin for Dotclear 2 |
---|
5 | # Copyright (C) 2008,2009,2010 Moe (http://gniark.net/) |
---|
6 | # |
---|
7 | # Contribute is free software; you can redistribute it and/or |
---|
8 | # modify it under the terms of the GNU General Public License v2.0 |
---|
9 | # as published by the Free Software Foundation. |
---|
10 | # |
---|
11 | # Contribute is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with this program; if not, see <http://www.gnu.org/licenses/>. |
---|
18 | # |
---|
19 | # Icon (icon.png) is from Silk Icons : |
---|
20 | # <http://www.famfamfam.com/lab/icons/silk/> |
---|
21 | # |
---|
22 | # ***** END LICENSE BLOCK ***** |
---|
23 | |
---|
24 | if (!defined('DC_RC_PATH')) {return;} |
---|
25 | |
---|
26 | /** |
---|
27 | @ingroup Contribute |
---|
28 | @brief General class |
---|
29 | */ |
---|
30 | class contribute |
---|
31 | { |
---|
32 | /** |
---|
33 | get Tags |
---|
34 | @return <b>array</b> Tags array |
---|
35 | \see /dotclear/plugins/metadata/class.dc.meta.php > getMeta() |
---|
36 | \note $meta->getMeta('tag') break the login when adding a post, we avoid it |
---|
37 | */ |
---|
38 | public static function getTags() |
---|
39 | { |
---|
40 | global $core; |
---|
41 | |
---|
42 | $strReq = 'SELECT meta_id, meta_type, COUNT(M.post_id) as count '. |
---|
43 | 'FROM '.$core->prefix.'meta M LEFT JOIN '.$core->prefix.'post P '. |
---|
44 | 'ON M.post_id = P.post_id '. |
---|
45 | "WHERE P.blog_id = '".$core->con->escape($core->blog->id)."' "; |
---|
46 | |
---|
47 | $strReq .= " AND meta_type = '".$core->con->escape('tag')."' "; |
---|
48 | |
---|
49 | $strReq .= 'AND ((post_status = 1) AND (post_password IS NULL)) '; |
---|
50 | |
---|
51 | $strReq .= |
---|
52 | 'GROUP BY meta_id,meta_type,P.blog_id '. |
---|
53 | 'ORDER BY count DESC'; |
---|
54 | |
---|
55 | $rs = $core->con->select($strReq); |
---|
56 | |
---|
57 | $tags = array(); |
---|
58 | |
---|
59 | while ($rs->fetch()) |
---|
60 | { |
---|
61 | $tags[] = $rs->meta_id; |
---|
62 | } |
---|
63 | |
---|
64 | return $tags; |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | get My Meta values |
---|
69 | @param mymeta <b>My Meta object</b> My Meta |
---|
70 | @param all <b>boolean</b> All the settings ? |
---|
71 | @return <b>recordset</b> Image metadata |
---|
72 | */ |
---|
73 | public static function getMyMeta($mymeta,$all=false) |
---|
74 | { |
---|
75 | global $core,$_ctx; |
---|
76 | |
---|
77 | $array = array(); |
---|
78 | |
---|
79 | if (($mymeta === false) || (!$mymeta->hasMeta())) |
---|
80 | { |
---|
81 | return(staticRecord::newFromArray($array)); |
---|
82 | } |
---|
83 | |
---|
84 | $mymeta_values = @unserialize(@base64_decode( |
---|
85 | $core->blog->settings->contribute_mymeta_values)); |
---|
86 | |
---|
87 | if (!is_array($mymeta_values)) {$mymeta_values = array();} |
---|
88 | |
---|
89 | foreach ($mymeta->getAll() as $k => $v) |
---|
90 | { |
---|
91 | if ($v->enabled) |
---|
92 | { |
---|
93 | $active = in_array($k,$mymeta_values); |
---|
94 | if ($all || $active) |
---|
95 | { |
---|
96 | $array[] = array( |
---|
97 | 'id' => $k, |
---|
98 | 'type' => $v->type, |
---|
99 | 'prompt' => $v->prompt, |
---|
100 | 'values' => $v->values, |
---|
101 | 'active' => $active |
---|
102 | ); |
---|
103 | } |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | return(staticRecord::newFromArray($array)); |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | get My Meta values |
---|
112 | @param values <b>array</b> Values |
---|
113 | @return <b>recordset</b> Values |
---|
114 | */ |
---|
115 | public static function getMyMetaValues($values) |
---|
116 | { |
---|
117 | global $core; |
---|
118 | |
---|
119 | if (!$core->blog->settings->contribute_allow_mymeta) {return;} |
---|
120 | |
---|
121 | $array = array(); |
---|
122 | |
---|
123 | if (empty($values)) |
---|
124 | { |
---|
125 | return(staticRecord::newFromArray($array)); |
---|
126 | } |
---|
127 | |
---|
128 | foreach ($values as $k => $v) |
---|
129 | { |
---|
130 | $array[] = array( |
---|
131 | 'id' => $v, |
---|
132 | 'description' => $k |
---|
133 | ); |
---|
134 | } |
---|
135 | |
---|
136 | return(staticRecord::newFromArray($array)); |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | ?> |
---|