| 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 | ############################################################################### |
|---|
| 36 | /* |
|---|
| 37 | * Step 0: Stop here if you are not sure what you are doing, it's no fun at all |
|---|
| 38 | * Step 1: Clone this file and rename as rssfitj.[mod_dir].php |
|---|
| 39 | * Step 2: Replace the text "RssfitjSample" with "Rssfitj[mod_dir]" at line 47 and line 55, i.e. "RssfitjNews" for the module "News" |
|---|
| 40 | * Step 3: Modify the word in line 48 from 'sample' to [mod_dir] |
|---|
| 41 | * Step 4: Modify the function "grabEntries" to satisfy your needs |
|---|
| 42 | * Step 5: Move the new plug-in file to the plugins folder, i.e. your-xoops-root/modules/rss/plugins |
|---|
| 43 | * Step 6: Install your plug-in by pointing your browser to your-xoops-url/modules/rss/admin/index.php |
|---|
| 44 | * [mod_dir]: Name of the driectory of your module, i.e. 'news' |
|---|
| 45 | */ |
|---|
| 46 | |
|---|
| 47 | class RssfitjWordpress{ |
|---|
| 48 | var $dirname = 'wordpress'; |
|---|
| 49 | var $modname; |
|---|
| 50 | |
|---|
| 51 | /* |
|---|
| 52 | * private |
|---|
| 53 | * Nothing here so far |
|---|
| 54 | */ |
|---|
| 55 | function RssfitjWordpress(){ |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | /* |
|---|
| 59 | * private |
|---|
| 60 | * Load the module |
|---|
| 61 | */ |
|---|
| 62 | function loadModule(){ |
|---|
| 63 | global $module_handler; |
|---|
| 64 | $mod = $module_handler->getByDirname($this->dirname); |
|---|
| 65 | if( !$mod || !$mod->getVar('isactive') ){ |
|---|
| 66 | return false; |
|---|
| 67 | } |
|---|
| 68 | $this->modname = $mod->getVar('name'); |
|---|
| 69 | return $mod; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | /* |
|---|
| 73 | * public |
|---|
| 74 | * return module name |
|---|
| 75 | */ |
|---|
| 76 | function getDirName(){ |
|---|
| 77 | return $this->dirname; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | /* |
|---|
| 81 | * public |
|---|
| 82 | * Grab the entries of your module here |
|---|
| 83 | */ |
|---|
| 84 | function grabEntries(&$obj){ |
|---|
| 85 | global $xoopsDB,$module_handler; |
|---|
| 86 | $myts =& MyTextSanitizer::getInstance(); |
|---|
| 87 | $ret = array(); |
|---|
| 88 | $i = 0; |
|---|
| 89 | |
|---|
| 90 | if ($obj->getVar('rssfj_param')) { |
|---|
| 91 | $rcdId=explode(',',$obj->getVar('rssfj_param')); |
|---|
| 92 | $Carray=array(); |
|---|
| 93 | $carray=array(); |
|---|
| 94 | $Tarray=array(); |
|---|
| 95 | $tarray=array(); |
|---|
| 96 | foreach ($rcdId as $eachId) { |
|---|
| 97 | if (strpos($eachId,':')!==False) { |
|---|
| 98 | $words=explode(':',$eachId); |
|---|
| 99 | $word_cnt=0; |
|---|
| 100 | foreach($words as $word) { |
|---|
| 101 | if ($word_cnt > 0) { |
|---|
| 102 | if (strpos($word,'C')!==False) |
|---|
| 103 | $Carray[$words[0]][]=substr($word,1,strlen($word)-1); |
|---|
| 104 | if (strpos($word,'c')!==False) { |
|---|
| 105 | if (!isset($Carray[$words[0]])) |
|---|
| 106 | $Carray[$words[0]]=""; |
|---|
| 107 | $carray[$words[0]][]=substr($word,1,strlen($word)-1); |
|---|
| 108 | } |
|---|
| 109 | if (strpos($word,'T')!==False) { |
|---|
| 110 | if (!isset($Carray[$words[0]])) |
|---|
| 111 | $Carray[$words[0]]=""; |
|---|
| 112 | $Tarray[$words[0]][]=substr($word,1,strlen($word)-1); |
|---|
| 113 | } |
|---|
| 114 | if (strpos($word,'N')!==False) { |
|---|
| 115 | if (!isset($Carray[$words[0]])) |
|---|
| 116 | $Carray[$words[0]]=""; |
|---|
| 117 | $tarray[$words[0]][]=substr($word,1,strlen($word)-1); |
|---|
| 118 | } |
|---|
| 119 | if (strpos($word,'t')!==False) { |
|---|
| 120 | if (!isset($Carray[$words[0]])) |
|---|
| 121 | $Carray[$words[0]]=""; |
|---|
| 122 | $tarray[$words[0]][]=substr($word,1,strlen($word)-1); |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | $word_cnt++; |
|---|
| 126 | } |
|---|
| 127 | } else { |
|---|
| 128 | if (!in_array($eachId,array_keys($Carray))) |
|---|
| 129 | $Carray[$eachId]=""; |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | if (count($Carray)==0) |
|---|
| 133 | $Carray['wordpress']=""; |
|---|
| 134 | } else { |
|---|
| 135 | $Carray['wordpress']=""; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | // The following example code grabs the latest entries from the module MyLinks |
|---|
| 139 | foreach ($Carray as $key=>$val) { |
|---|
| 140 | $add_sql=""; |
|---|
| 141 | if (is_array($Carray[$key])) { |
|---|
| 142 | $add_sql.=" AND ("; |
|---|
| 143 | foreach($Carray[$key] as $eachId) { |
|---|
| 144 | $add_sql .= "c.cat_ID=".$eachId." OR "; |
|---|
| 145 | } |
|---|
| 146 | $add_sql = substr($add_sql,0,strlen($add_sql)-4); |
|---|
| 147 | $add_sql .= ")"; |
|---|
| 148 | } |
|---|
| 149 | if (isset($carray[$key])) { |
|---|
| 150 | $add_sql.=" AND NOT("; |
|---|
| 151 | foreach($carray[$key] as $eachId) { |
|---|
| 152 | $add_sql .= "c.cat_ID=".$eachId." OR "; |
|---|
| 153 | } |
|---|
| 154 | $add_sql = substr($add_sql,0,strlen($add_sql)-4); |
|---|
| 155 | $add_sql .= ")"; |
|---|
| 156 | } |
|---|
| 157 | if (isset($Tarray[$key])) { |
|---|
| 158 | $add_sql.=" AND ("; |
|---|
| 159 | foreach($Tarray[$key] as $eachId) { |
|---|
| 160 | $add_sql .= "p.ID=".$eachId." OR "; |
|---|
| 161 | } |
|---|
| 162 | $add_sql = substr($add_sql,0,strlen($add_sql)-4); |
|---|
| 163 | $add_sql .= ")"; |
|---|
| 164 | } |
|---|
| 165 | if (isset($tarray[$key])) { |
|---|
| 166 | $add_sql.=" AND NOT("; |
|---|
| 167 | foreach($tarray[$key] as $eachId) { |
|---|
| 168 | $add_sql .= "p.ID=".$eachId." OR "; |
|---|
| 169 | } |
|---|
| 170 | $add_sql = substr($add_sql,0,strlen($add_sql)-4); |
|---|
| 171 | $add_sql .= ")"; |
|---|
| 172 | } |
|---|
| 173 | if ($key=='wordpress') { |
|---|
| 174 | $sql = "SELECT p.ID, p.post_content, p.post_title, p.post_date, p.post_category, c.cat_name FROM ".$xoopsDB->prefix("wp_posts")." p, ".$xoopsDB->prefix("wp_categories")." c, ".$xoopsDB->prefix("wp_post2cat")." r WHERE p.ID=r.post_id AND r.category_id=c.cat_ID AND post_status='publish'".$add_sql." ORDER BY p.post_date DESC"; |
|---|
| 175 | } else { |
|---|
| 176 | $sql = "SELECT p.ID, p.post_content, p.post_title, p.post_date, p.post_category, c.cat_name FROM ".$xoopsDB->prefix("wp".substr($key,-1,1)."_posts")." p, ".$xoopsDB->prefix("wp".substr($key,-1,1)."_categories")." c, ".$xoopsDB->prefix("wp".substr($key,-1,1)."_post2cat")." r WHERE p.ID=r.post_id AND r.category_id=c.cat_ID AND post_status='publish'".$add_sql." ORDER BY p.post_date DESC"; |
|---|
| 177 | } |
|---|
| 178 | $result = $xoopsDB->query($sql, $obj->getVar('rssfj_grab'), 0); |
|---|
| 179 | while( $row = $xoopsDB->fetchArray($result) ){ |
|---|
| 180 | // required items |
|---|
| 181 | $mod = $module_handler->getByDirname($key); |
|---|
| 182 | if( !$mod || !$mod->getVar('isactive') ){ |
|---|
| 183 | return $ret; |
|---|
| 184 | } |
|---|
| 185 | $modname = $mod->getVar('name'); |
|---|
| 186 | |
|---|
| 187 | $link = XOOPS_URL.'/modules/'.$key.'/index.php?p='.$row['ID']; |
|---|
| 188 | // The title of the item |
|---|
| 189 | $desc=$modname." : ".$row['cat_name'].">>".$row['post_title']; |
|---|
| 190 | $ret[$i]['title'] = $myts->makeTareaData4Show($desc); |
|---|
| 191 | $ret[$i]['link'] = $link; // The URL of the item |
|---|
| 192 | $ret[$i]['guid'] = $link; // Unique identifier, usually url |
|---|
| 193 | // Item modification date |
|---|
| 194 | $date_sep=explode(' ',$row['post_date']); |
|---|
| 195 | $date_ymd=explode('-',$date_sep[0]); |
|---|
| 196 | $date_tms=explode(':',$date_sep[1]); |
|---|
| 197 | $ret[$i]['timestamp'] = mktime($date_tms[0],$date_tms[1],$date_tms[2],$date_ymd[1],$date_ymd[2],$date_ymd[0]); |
|---|
| 198 | // must be in Unix time format |
|---|
| 199 | $desc = $row['post_content']; // The item synopsis, or |
|---|
| 200 | // description, whatever |
|---|
| 201 | $ret[$i]['description'] = $myts->makeTareaData4Show($desc); |
|---|
| 202 | // optional items |
|---|
| 203 | $ret[$i]['category'] = $modname; |
|---|
| 204 | $ret[$i]['domain'] = XOOPS_URL.'/modules/'.$key.'/'; |
|---|
| 205 | |
|---|
| 206 | $i++; |
|---|
| 207 | } |
|---|
| 208 | } |
|---|
| 209 | return $ret; |
|---|
| 210 | } |
|---|
| 211 | } |
|---|
| 212 | ?> |
|---|