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

Revision 45, 5.9 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 sonews
18        {
19                var $db;
20
21                function sonews()
22                {
23                        copyobj($GLOBALS['phpgw']->db,$this->db);
24                }
25
26                function get_newslist($cat_id, $start, $order,$sort,$limit=0,$activeonly,&$total)
27                {
28                        if(!empty($order))
29                        {
30                                $ordermethod = ' ORDER BY ' . $this->db->db_addslashes($order) . ' ' . $this->db->db_addslashes($sort);
31                        }
32                        else
33                        {
34                                $ordermethod = ' ORDER BY news_date DESC';
35                        }
36
37                        if(is_array($cat_id))
38                        {
39                                $filter = 'IN (' . implode(',',$cat_id) . ')';
40                        }
41                        else
42                        {
43                                $filter = '=' . (int)$cat_id;
44                        }
45
46                        $sql = 'SELECT * FROM phpgw_news WHERE news_cat ' . $filter;
47                        if($activeonly)
48                        {
49                                $now = time();
50                                $sql .= " AND news_begin<=$now AND news_end>=$now";
51                        }
52                        $sql .= $ordermethod;
53
54                        $this->db->query($sql,__LINE__,__FILE__);
55                        $total = $this->db->num_rows();
56                        $this->db->limit_query($sql,$start,__LINE__,__FILE__,$limit);
57
58                        $news = array();
59
60                        while($this->db->next_record())
61                        {
62                                $news[$this->db->f('news_id')] = array(
63                                        'subject' => @htmlspecialchars($this->db->f('news_subject', True),ENT_COMPAT,$GLOBALS['phpgw']->translation->charset()),
64                                        'submittedby' => $this->db->f('news_submittedby'),
65                                        'date'    => $this->db->f('news_date'),
66                                        'id'      => $this->db->f('news_id'),
67                                        'begin'   => $this->db->f('news_begin'),
68                                        'end'     => $this->db->f('news_end'),
69                                        'teaser'  => @htmlspecialchars($this->db->f('news_teaser', True),ENT_COMPAT,$GLOBALS['phpgw']->translation->charset()),
70                                        'content' => $this->db->f('news_content',True),
71                                        'is_html' => ($this->db->f('is_html') ? True : False),
72                                );
73                        }
74                        return $news;
75                }
76
77                function get_all_public_news($limit=5)
78                {
79                        $now = time();
80                        $this->db->limit_query("SELECT * FROM phpgw_news WHERE news_begin<=$now AND news_end>=$now ORDER BY news_date DESC",0,__LINE__,__FILE__,$limit);
81
82                        $news = array();
83
84                        while ($this->db->next_record())
85                        {
86                                $news[$this->db->f('news_id')] = array(
87                                        'subject' => $this->db->f('news_subject', True),
88                                        'submittedby' => $this->db->f('news_submittedby'),
89                                        'date'    => $this->db->f('news_date'),
90                                        'id'      => $this->db->f('news_id'),
91                                        'teaser'  => $this->db->f('news_teaser', True),
92                                        'content' => $this->db->f('news_content', True),
93                                        'is_html' => ($this->db->f('is_html') ? True : False),
94                                );
95                        }
96                        return $news;
97                }
98
99                function add($news)
100                {
101                        $add_array = array(
102                                'news_date'                     => (int)$news['date'],
103                                'news_submittedby'      => $GLOBALS['phpgw_info']['user']['account_id'],
104                                'news_content'          => $news['content'],
105                                'news_subject'          => $news['subject'],
106                                'news_begin'            => (int)$news['begin'],
107                                'news_end'                      => (int)$news['end'],
108                                'news_teaser'           => $news['teaser'],
109                                'news_cat'                      => (int)$news['category'],
110                                'is_html'                       => (int)!!$news['is_html'],
111                        );
112                        $this->db->insert('phpgw_news', $add_array, '', __LINE__, __FILE__);
113
114                        return $this->db->get_last_insert_id('phpgw_news', 'news_id');
115                }
116
117                function edit($news)
118                {
119                        $update_array = array(
120                                'news_content'  => $news['content'],
121                                'news_subject'  => $news['subject'],
122                                'news_teaser'   => $news['teaser'],
123                                'news_begin'    => $news['begin'],
124                                'news_end'              => $news['end'],
125                                'news_cat'              => $news['category'],
126                                'is_html'               => $news['is_html'] ? 1 : 0,
127                        );
128                        $this->db->update('phpgw_news', $update_array, array('news_id' => (int)$news['id']), __LINE__, __FILE__);
129                }
130
131                function delete($news_id)
132                {
133                        $this->db->query('DELETE FROM phpgw_news WHERE news_id=' . (int)$news_id,__LINE__,__FILE__);
134                }
135
136                function get_news($news_id)
137                {
138                        $this->db->query('SELECT * FROM phpgw_news WHERE news_id=' . (int)$news_id,__LINE__,__FILE__);
139                        $this->db->next_record();
140
141                        $item = array(
142                                'id'       => $this->db->f('news_id'),
143                                'date'     => $this->db->f('news_date'),
144                                'subject'  => $this->db->f('news_subject', True),
145                                'submittedby' => $this->db->f('news_submittedby'),
146                                'teaser'   => $this->db->f('news_teaser', True),
147                                'content'  => $this->db->f('news_content', True),
148                                'begin'    => $this->db->f('news_begin'),
149                                'end'      => $this->db->f('news_end'),
150                                'category' => $this->db->f('news_cat'),
151                                'is_html'  => ($this->db->f('is_html') ? True : False),
152                        );
153                        return $item;
154                }
155
156//              function getlist($order,$sort,$cat_id)
157//              {
158//                      if ($order)
159//                      {
160//                              $ordermethod = ' ORDER BY ' . $this->db->db_addslashes($order) . ' ' . $this->db->db_addslashes($sort);
161//                      }
162//                      else
163//                      {
164//                              $ordermethod = ' ORDER BY news_date DESC';
165//                      }
166
167//                      $this->db->query('SELECT * FROM phpgw_news WHERE news_cat=' . (int)$cat_id . $ordermethod,__LINE__,__FILE__);
168//                      while ($this->db->next_record())
169//                      {
170//                              $items[] = array(
171//                                      'id'          => $this->db->f('news_id'),
172//                                      'date'        => $this->db->f('news_date'),
173//                                      'subject'     => $this->db->f('news_subject'),
174//                                      'submittedby' => $this->db->f('news_submittedby'),
175//                                      'content'     => $this->db->f('news_content'),
176//                                      'status'      => $this->db->f('news_status'),
177//                                      'cat'         => $this->db->f('news_cat')
178//                              );
179//                      }
180//                      return $items;
181//              }
182        }
Note: See TracBrowser for help on using the repository browser.