Dotclear

source: plugins/contribute/inc/lib.contribute.php @ 2940

Revision 2940, 4.3 KB checked in by Moe, 13 years ago (diff)

Contribute 1.0-alpha31:

  • added IP address in notification email (closes #646)
  • switched to Dotclear 2.2 settings (closes #636)
  • switched to PHP 5.3 arguments (closes #636)
Line 
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
24if (!defined('DC_RC_PATH')) {return;}
25
26/**
27@ingroup Contribute
28@brief General class
29*/
30class 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->contribute_mymeta_values));
86         
87          if (!is_array($mymeta_values)) {$mymeta_values = array();}
88         
89          if (version_compare(DC_VERSION,'2.2-alpha1','>='))
90          {
91               foreach ($mymeta->getAll() as $meta)
92               {
93                    # section
94                    if ($meta instanceof myMetaSection)
95                    {
96                         $active = in_array($meta->id,$mymeta_values);
97                         
98                         $array[] = array(
99                              'id' => $meta->id,
100                              'type' => 'section',
101                              'prompt' => $meta->prompt,
102                              'active' => $active
103                         );
104                    }
105                    elseif ($meta->enabled)
106                    {
107                         $active = in_array($meta->id,$mymeta_values);
108                         
109                         if ($meta->getMetaTypeId() == 'list')
110                         {
111                              $values = $meta->values;
112                         }
113                         else
114                         {
115                              $values = '';
116                         }
117                         
118                         if ($all || $active)
119                         {
120                              $array[] = array(
121                                   'id' => $meta->id,
122                                   'type' => $meta->getMetaTypeId(),
123                                   'prompt' => $meta->prompt,
124                                   'default' => $meta->default,
125                                   'values' => $values,
126                                   'active' => $active
127                              );
128                         }
129                    }
130               }
131          }
132          else
133          {
134               foreach ($mymeta->getAll() as $k => $v)
135               {
136                    if ($v->enabled)
137                    {
138                         $active = in_array($k,$mymeta_values);
139                         if ($all || $active)
140                         {
141                              $array[] = array(
142                                   'id' => $k,
143                                   'type' => $v->type,
144                                   'prompt' => $v->prompt,
145                                   'values' => $v->values,
146                                   'active' => $active
147                              );
148                         }
149                    }
150               }
151          }
152         
153          return(staticRecord::newFromArray($array));
154     }
155     
156     /**
157     get My Meta values
158     @param    values    <b>array</b>   Values
159     @return   <b>recordset</b> Values
160     */
161     public static function getMyMetaValues($values)
162     {
163          global $core;
164         
165          if (!$core->blog->settings->contribute->contribute_allow_mymeta) {return;}
166         
167          $array = array();
168         
169          if (empty($values))
170          {
171               return(staticRecord::newFromArray($array));
172          }
173                   
174          foreach ($values as $k => $v)
175          {
176               $array[] = array(
177                    'id' => $v,
178                    'description' => $k
179               );
180          }
181         
182          return(staticRecord::newFromArray($array));
183     }
184     
185     /**
186     filter HTML
187     @param    str  <b>string</b>  String to filter
188     @return   <b>string</b> Filtered string
189     \see /dotclear/inc/core/class.dc.core.php
190     */
191     public static function HTMLfilter($str)
192     {
193          $filter = new htmlFilter;
194          $str = trim($filter->apply($str));
195          return $str;
196     }
197}
198
199?>
Note: See TracBrowser for help on using the repository browser.

Sites map