source: temp/test-xoops.ec-cube.net/html/modules/rssj/class/rssfitj.php @ 405

Revision 405, 8.9 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2###############################################################################
3##                RSSFit - Extendable XML news feed generator                ##
4##                   Copyright (c) 2004 NS Tai (aka tuff)                    ##
5##                       <http://www.brandycoke.com/>                        ##
6##                      Modified By 2005 CACHE RSSfitJ                       ##
7##                       <http://gyakubiki.kir.jp/>                          ##
8###############################################################################
9##                    XOOPS - PHP Content Management System                  ##
10##                       Copyright (c) 2000 XOOPS.org                        ##
11##                          <http://www.xoops.org/>                          ##
12###############################################################################
13##  This program is free software; you can redistribute it and/or modify     ##
14##  it under the terms of the GNU General Public License as published by     ##
15##  the Free Software Foundation; either version 2 of the License, or        ##
16##  (at your option) any later version.                                      ##
17##                                                                           ##
18##  You may not change or alter any portion of this comment or credits       ##
19##  of supporting developers from this source code or any supporting         ##
20##  source code which is considered copyrighted (c) material of the          ##
21##  original comment or credit authors.                                      ##
22##                                                                           ##
23##  This program is distributed in the hope that it will be useful,          ##
24##  but WITHOUT ANY WARRANTY; without even the implied warranty of           ##
25##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            ##
26##  GNU General Public License for more details.                             ##
27##                                                                           ##
28##  You should have received a copy of the GNU General Public License        ##
29##  along with this program; if not, write to the Free Software              ##
30##  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA ##
31###############################################################################
32##  Author of this file: CACHE                                               ##
33##  URL: http://gyakubiki.kir.jp/                                            ##
34##  Project: RSSFitJ                                                         ##
35###############################################################################
36require_once XOOPS_ROOT_PATH.'/kernel/object.php';
37define('RSSFITJ_PLUGINS_TABLE', $GLOBALS['xoopsDB']->prefix("rssfitJ_plugins"));
38
39class RssjRssfitj extends XoopsObject{
40    function RssjRssfitj(){
41        $this->XoopsObject();
42    //  key, data_type, value, req, max, opt
43        $this->initVar("rssfj_conf_id", XOBJ_DTYPE_INT, NULL, false);
44        $this->initVar("rssfj_filename", XOBJ_DTYPE_TXTBOX, NULL, false);
45        $this->initVar("rssfj_activated", XOBJ_DTYPE_INT);
46        $this->initVar("rssfj_grab", XOBJ_DTYPE_INT, NULL, true);
47        $this->initVar("rssfj_order", XOBJ_DTYPE_INT, NULL);
48        $this->initVar("rssfj_param", XOBJ_DTYPE_TXTAREA, NULL, false);
49    }
50}
51
52class RssjRssfitjHandler{
53    var $db;
54    function RssjRssfitjHandler(&$db){
55        $this->db =& $db;
56    }
57    function &getInstance(&$db){
58        static $instance;
59        if( !isset($instance) ){
60            $instance = new RssjRssfitjHandler($db);
61        }
62        return $instance;
63    }
64    function &create(){
65        return new RssjRssfitj();
66    }
67
68    function &get($id){
69        $id = intval($id);
70        if( $id > 0 ){
71            $sql = "SELECT * FROM ".RSSFITJ_PLUGINS_TABLE." WHERE rssfj_conf_id=".$id;
72            if( !$result = $this->db->query($sql) ){
73                return false;
74            }
75            $numrows = $this->db->getRowsNum($result);
76            if( $numrows == 1 ){
77                $obj = new RssjRssfitj();
78                $obj->assignVars($this->db->fetchArray($result));
79                return $obj;
80            }
81        }
82        return false;
83    }
84
85    function insert(&$obj, $force=false){
86        if( strtolower(get_class($obj)) != 'rssjrssfitj'){
87            return false;
88        }
89        if( !$obj->isDirty() ){
90            return true;
91        }
92        if( !$obj->cleanVars() ){
93            return false;
94        }
95        foreach( $obj->cleanVars as $k=>$v ){
96            ${$k} = $v;
97        }
98       
99        if( $obj->isNew() || empty($rssfj_conf_id) ){
100            $rssfj_conf_id = $this->db->genId(RSSFITJ_PLUGINS_TABLE."_rssfj_conf_id_seq");
101            $sql = sprintf(
102                    "INSERT INTO %s (
103                    rssfj_conf_id,
104                    rssfj_filename,
105                    rssfj_activated,
106                    rssfj_grab,
107                    rssfj_order,
108                    rssfj_param
109                    ) VALUES (
110                    %u, %s, %u, %u, %u, %s
111                    )",
112                    RSSFITJ_PLUGINS_TABLE,
113                    $rssfj_conf_id,
114                    $this->db->quoteString($rssfj_filename),
115                    $rssfj_activated,
116                    $rssfj_grab,
117                    $rssfj_order,
118                    $this->db->quoteString($rssfj_param)
119                    );
120        }else{
121            $sql = sprintf(
122                    "UPDATE %s SET
123                    rssfj_filename = %s,
124                    rssfj_activated = %u,
125                    rssfj_grab = %u,
126                    rssfj_order = %u,
127                    rssfj_param = %s
128                    WHERE rssfj_conf_id = %u",
129                    RSSFITJ_PLUGINS_TABLE,
130                    $this->db->quoteString($rssfj_filename),
131                    $rssfj_activated,
132                    $rssfj_grab,
133                    $rssfj_order,
134                    $this->db->quoteString($rssfj_param),
135                    $rssfj_conf_id
136                    );
137        }
138        if( false != $force ){
139            $result = $this->db->queryF($sql);
140        }else{
141            $result = $this->db->query($sql);
142        }
143        if( !$result ){
144            $obj->setErrors("Could not store data in the database.<br />".$this->db->error().' ('.$this->db->errno().')<br />'.$sql);
145            return false;
146        }
147        if( empty($rssfj_conf_id) ){
148            return $this->db->getInsertId();
149        }
150        $obj->assignVar('rssfj_conf_id', $rssfj_conf_id);
151        return $rssfj_conf_id;
152    }
153   
154    function delete(&$obj, $force = false){
155        if( strtolower(get_class($obj)) != 'rssjrssfitj' ){
156            return false;
157        }
158        $sql = "DELETE FROM ".RSSFITJ_PLUGINS_TABLE." WHERE rssfj_conf_id=".$obj->getVar("rssfj_conf_id")."";
159        if( false != $force ){
160            $result = $this->db->queryF($sql);
161        }else{
162            $result = $this->db->query($sql);
163        }
164        return true;
165    }
166
167    function &getObjects($criteria = null, $id_as_key = false){
168        $ret = array();
169        $limit = $start = 0;
170        $sql = 'SELECT * FROM '.RSSFITJ_PLUGINS_TABLE;
171        if( isset($criteria) && is_subclass_of($criteria, 'criteriaelement') ){
172            $sql .= ' '.$criteria->renderWhere();
173            if( $criteria->getSort() != '' ){
174                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
175            }
176            $limit = $criteria->getLimit();
177            $start = $criteria->getStart();
178        }
179        $result = $this->db->query($sql, $limit, $start);
180        if( !$result ){
181            return false;
182        }
183        while( $myrow = $this->db->fetchArray($result) ){
184            $obj = new RssjRssfitj();
185            $obj->assignVars($myrow);
186            if( !$id_as_key ){
187                $ret[] =& $obj;
188            }else{
189                $ret[$myrow['rssfj_conf_id']] =& $obj;
190            }
191            unset($obj);
192        }
193        return $ret;
194    }
195   
196    function getCount($criteria = null){
197        $sql = 'SELECT COUNT(*) FROM '.RSSFITJ_PLUGINS_TABLE;
198        if( isset($criteria) && is_subclass_of($criteria, 'criteriaelement') ){
199            $sql .= ' '.$criteria->renderWhere();
200        }
201        $result = $this->db->query($sql);
202        if( !$result ){
203            return false;
204        }
205        list($count) = $this->db->fetchRow($result);
206        return $count;
207    }
208   
209    function deleteAll($criteria = null){
210        $sql = 'DELETE FROM '.RSSFITJ_PLUGINS_TABLE;
211        if( isset($criteria) && is_subclass_of($criteria, 'criteriaelement') ){
212            $sql .= ' '.$criteria->renderWhere();
213        }
214        if( !$result = $this->db->query($sql) ){
215            return false;
216        }
217        return true;
218    }
219   
220    function forceDeactivate(&$obj){
221        $sql = 'UPDATE '.RSSFITJ_PLUGINS_TABLE.' SET rssfj_activated = 0 WHERE rssfj_conf_id = '.$obj->getVar('rssfj_conf_id');
222        $this->db->queryF($sql);
223        return true;
224    }
225   
226    function getPluginFileList(){
227        $sql = 'SELECT rssfj_filename FROM '.RSSFITJ_PLUGINS_TABLE;
228        if( !$result = $this->db->query($sql) ){
229            return false;
230        }
231        $ret="";
232        while( list($filename) = $this->db->fetchRow($result) ){
233            $ret[] =& $filename;
234            unset($filename);
235        }
236        return $ret;
237    }
238   
239    function checkPlugin(&$obj){
240        global $module_handler;
241        $file = RSSFITJ_ROOT_PATH.'plugins/'.$obj->getVar('rssfj_filename');
242        if( file_exists($file) ){
243            $require = require_once $file;
244            $name = explode('.', $obj->getVar('rssfj_filename'));
245            $class = 'Rssfitj'.ucfirst($name[1]);
246            if( class_exists($class) ){
247                $handler = new $class;
248                if( !method_exists($handler, 'loadmodule') || !method_exists($handler, 'grabentries') ){
249                    $obj->setErrors(_AM_PLUGIN_FUNCNOTFOUND);
250                }else{
251                    $dirname = $handler->dirname;
252                    if( !empty($dirname) && is_dir(XOOPS_ROOT_PATH.'/modules/'.$dirname) ){
253                        if( !$handler->loadModule() ){
254                            $obj->setErrors(_AM_PLUGIN_MODNOTFOUND);
255                        }else{
256                            return $handler;
257                        }
258                    }else{
259                        $obj->setErrors(_AM_PLUGIN_MODNOTFOUND);
260                    }
261                }
262            }else{
263                $obj->setErrors(_AM_PLUGIN_CLASSNOTFOUND);
264            }
265        }else{
266            $obj->setErrors(_AM_PLUGIN_FILENOTFOUND);
267        }
268        return false;
269    }
270
271}
272
273?>
Note: See TracBrowser for help on using the repository browser.