source: trunk/news_admin/inc/class.bonews.inc.php @ 45

Revision 45, 8.5 KB checked in by niltonneto, 17 years ago (diff)

Implementação do FCKEDITOR na edição de artigos no news_admin, para permitir texto rico.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * eGroupWare - News                                                        *
4        * http://www.egroupware.org                                                *
5        * --------------------------------------------                             *
6        *  This program is free software; you can redistribute it and/or modify it *
7        *  under the terms of the GNU General Public License as published by the   *
8        *  Free Software Foundation; either version 2 of the License, or (at your  *
9        *  option) any later version.                                              *
10        * --------------------------------------------                             *
11        * This program was sponsered by Golden Glair productions                   *
12        * http://www.goldenglair.com                                               *
13        \**************************************************************************/
14
15        /* $Id$ */
16
17        class bonews
18        {
19                var $sonews;
20                var $acl;
21                var $start = 0;
22                var $query = '';
23                var $sort  = '';
24                var $cat_id;
25                var $total = 0;
26                var $debug;
27                var $use_session = False;
28                var $unixtimestampmax;
29                var $dateformat;
30                var $cats = array();
31
32                function bonews($session=False)
33                {
34                        $this->acl = CreateObject('news_admin.boacl');
35                        $this->sonews = CreateObject('news_admin.sonews');
36                        $this->accounts = $GLOBALS['phpgw']->accounts->get_list('groups');
37                        $this->debug = False;
38                        if($session)
39                        {
40                                $this->read_sessiondata();
41                                $this->use_session = True;
42                                foreach(array('start','query','sort','order','cat_id') as $var)
43                                {
44                                        $this->$var = get_var($var, array('POST', 'GET'), '');
45                                }
46
47                                $this->cat_id = $this->cat_id ? $this->cat_id : 'all';
48                                $this->save_sessiondata();
49                        }
50                        $this->catbo = createobject('phpgwapi.categories','','news_admin');
51                        $this->cats = $this->catbo->return_array('all',0,False,'','','cat_name',True);
52                        settype($this->cats,'array');
53                        //change this around 19 Jan 2038 03:14:07 GMT
54                        $this->unixtimestampmax = 2147483647;
55                        $this->dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
56                }
57
58                function save_sessiondata()
59                {
60                        $data = array(
61                                'start' => $this->start,
62                                'query' => $this->query,
63                                'sort'  => $this->sort,
64                                'order' => $this->order,
65                                'cat_id' => $this->cat_id,
66                        );
67                        if($this->debug) { echo '<br>Save:'; _debug_array($data); }
68                        $GLOBALS['phpgw']->session->appsession('session_data','news_admin',$data);
69                }
70
71                function read_sessiondata()
72                {
73                        $data = $GLOBALS['phpgw']->session->appsession('session_data','news_admin');
74                        if($this->debug) { echo '<br>Read:'; _debug_array($data); }
75
76                        $this->start  = $data['start'];
77                        $this->query  = $data['query'];
78                        $this->sort   = $data['sort'];
79                        $this->order  = $data['order'];
80                        $this->cat_id = $data['cat_id'];
81                }
82
83                function get_newslist($cat_id, $start=0, $order='',$sort='',$limit=0,$activeonly=False)
84                {
85                        $charset = $GLOBALS['phpgw']->translation->charset();
86                       
87                        $cats = False;
88                        if ($cat_id == 'all')
89                        {
90                                foreach($this->cats as $cat)
91                                {
92                                   if ($this->acl->is_readable($cat['id']))
93                                   {
94                                                $cats[] = $cat['id'];
95                                   }
96                           }
97                        }
98                        elseif($this->acl->is_readable($cat_id))
99                        {
100                                $cats = $cat_id;
101                        }
102                       
103                        if($cats)
104                        {
105                                $news = $this->sonews->get_newslist($cats, $start,$order,$sort,$limit,$activeonly,$this->total);
106                                foreach($news as $id => $item)
107                                {
108                                        $news[$id]['content'] = ($item['is_html'] ?
109                                                                        $item['content'] :
110                                                                        nl2br(@htmlspecialchars($item['content'],ENT_COMPAT,$charset)
111                                                                ));
112                                }
113                                return $news;
114                        }
115                        else
116                        {
117                                return array();
118                        }
119                }
120
121                function get_all_public_news($limit = 5)
122                {
123                        $charset = $GLOBALS['phpgw']->translation->charset();
124                       
125                        $news = $this->sonews->get_all_public_news($limit);
126                        foreach($news as $id => $item)
127                        {
128                                $news[$id]['content'] = ($item['is_html'] ?
129                                                                $item['content'] :
130                                                                nl2br(@htmlspecialchars($item['content'],ENT_COMPAT,$charset)
131                                                        ));
132                        }
133                        return $news;
134                }
135
136                function delete($news_id)
137                {
138                        $this->sonews->delete($news_id);
139                }
140
141                function add($news)
142                {
143                        $enc = preg_replace('!\015\012|\015|\012!','',$news['content']);
144                        $news['content'] = $enc;
145                        return $this->acl->is_writeable($news['category']) ?
146                                $this->sonews->add($news) :
147                                false;
148                }
149
150                function edit($news)
151                {
152                        $enc = preg_replace('!\015\012|\015|\012!','',$news['content']);
153                        $news['content'] = $enc;
154                        $oldnews = $this->sonews->get_news($news['id']);
155                        return ($this->acl->is_writeable($oldnews['category']) &&
156                                        $this->acl->is_writeable($news['category'])) ?
157                                $this->sonews->edit($news) :
158                                False;
159                }
160
161                function get_visibility(&$news)
162                {
163                        $now = time();
164
165                        if ($news['end'] < $now)
166                        {
167                                return lang('Never');
168                        }
169                        else
170                        {
171                                if ($news['begin'] < $now)
172                                {
173                                        if ($news['end'] == $this->unixtimestampmax)
174                                        {
175                                                return lang('Always');
176                                        }
177                                        else
178                                        {
179                                                return lang('until') . date($this->dateformat,$news['end']);
180                                        }
181                                }
182                                else
183                                {
184                                        if ($news['end'] == $this->unixtimestampmax)
185                                        {
186                                                return lang('from') . date($this->dateformat,$news['begin']);
187
188                                        }
189                                        else
190                                        {
191                                                return lang('from') . ' ' . date($this->dateformat,$news['begin']) . ' ' .
192                                                        lang('until') . ' ' . date($this->dateformat,$news['end']);
193                                        }
194                                }
195                        }
196                }
197
198                //return the selectboxes with calculated defaults, and change begin and end by sideaffect
199                function get_options(&$news)
200                {
201                        $now = time();
202                        //always is default
203                        if (!isset($news['begin']))
204                        {
205                                //these are only displayed values not necessarily the ones that will get stored
206                                $news['begin'] = $now;
207                                $news['end'] = $now;
208                                $from = 1;
209                                $until = 1;
210                        }
211                        //if enddate is in the past set option to never
212                        elseif ($news['end'] < $now)
213                        {
214                                $news['begin'] = $now;
215                                $news['end'] = $now;
216                                $from = 0;
217                                $until = 1;
218                        }
219                        else
220                        {
221                                if ($news['begin'] < $now)
222                                {
223                                        $news['begin'] = $now;
224                                        if ($news['end'] == $this->unixtimestampmax)
225                                        {
226                                                $news['end'] = $now;
227                                                $from = 1;
228                                                $until = 1;
229                                        }
230                                        else
231                                        {
232                                                $from = 0.5;
233                                                $until = 0.5;
234                                        }
235                                }
236                                else
237                                {
238                                        if ($news['end'] == $this->unixtimestampmax)
239                                        {
240                                                $news['end'] = $now;
241                                                $from = 0.5;
242                                                $until = 1;
243                                        }
244                                        else
245                                        {
246                                                $from = 0.5;
247                                                $until = 0.5;
248                                        }
249                                }
250                        }
251                        $options['from'] = '<option value="1"' . (($from == 1) ? ' selected="selected"' : '') . '>' . lang('Always') . '</option>';
252                        $options['from'] .= '<option value="0"' . (($from == 0) ? ' selected="selected"' : '') . '>' . lang('Never') . '</option>';
253                        $options['from'] .= '<option value="0.5"' . (($from == 0.5) ? ' selected="selected"' : '') . '>' . lang('From') . '</option>';
254                        $options['until'] = '<option value="1"' . (($until == 1) ? ' selected="selected"' : '') . '>' . lang('Always') . '</option>';
255                        $options['until'] .= '<option value="0.5"' . (($until == 0.5) ? ' selected="selected"' : '') . '>' . lang('until') . '</option>';
256                        return $options;
257                }
258
259                //set the begin and end dates
260                function set_dates($from,$until,&$news)
261                {
262                        switch($from)
263                        {
264                                //always
265                                case 1:
266                                        $news['begin'] = $news['date'];
267                                        $news['end'] = $this->unixtimestampmax;
268                                        break;
269                                //never
270                                case 0:
271                                        $news['begin'] = 0;
272                                        $news['end'] = 0;
273                                        break;
274                                default:
275                                        $news['begin'] = mktime(0,0,0,(int)$news['begin_m'], (int)$news['begin_d'], (int)$news['begin_y']);
276                                        switch($until)
277                                        {
278                                                case 1:
279                                                        $news['end'] = $this->unixtimestampmax;
280                                                        break;
281                                                default:
282                                                        $news['end'] = mktime(0,0,0,(int)$news['end_m'], (int)$news['end_d'], (int)$news['end_y']);
283                                        }
284                        }
285                }
286
287//              function format_fields($fields)
288//              {
289//                      $cat = createobject('phpgwapi.categories','news_admin');
290
291//                      $item = array(
292//                              'id'          => $fields['id'],
293//                              'date'        => $GLOBALS['phpgw']->common->show_date($fields['date']),
294//                              'subject'     => $GLOBALS['phpgw']->strip_html($fields['subject']),
295//                              'submittedby' => $fields['submittedby'],
296//                              'content'     => $fields['content'],
297//                              'status'      => lang($fields['status']),
298//                              'cat'         => $cat->id2name($fields['cat'])
299//                      );
300//                      return $item;
301//              }
302
303                function get_news($news_id)
304                {
305                        $news = $this->sonews->get_news($news_id);
306                       
307                        if ($this->acl->is_readable($news['category']))
308                        {
309                                $this->total = 1;
310                                $news['content'] = ($news['is_html'] ?
311                                                        $news['content']:
312                                                        nl2br(htmlspecialchars($news['content'],ENT_COMPAT,$GLOBALS['phpgw']->translation->charset())
313                                                ));
314                                return $news;
315                        }
316                        else
317                        {
318                                 return False;
319                        }
320                }
321        }
322?>
Note: See TracBrowser for help on using the repository browser.