XPressME Integration Kit

Trac

source: trunk/include/data.inc.php @ 135

Last change on this file since 135 was 37, checked in by toemon, 16 years ago

WhatsNewモジュール用プラグインの実装 #15

File size: 6.0 KB
Line 
1<?php
2if( ! defined( 'XOOPS_ROOT_PATH' ) ) exit ;
3$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
4
5eval( '
6
7function '.$mydirname.'_new($limit=0, $offset=0){
8        return _xpress_new("'.$mydirname.'" ,$limit, $offset ) ;
9}
10
11function '.$mydirname.'_num(){
12        return _xpress_num("'.$mydirname.'") ;
13}
14
15function '.$mydirname.'_data($limit=0, $offset=0){
16        return _xpress_data("'.$mydirname.'" ,$limit, $offset ) ;
17}
18' ) ;
19
20if (!function_exists('_xpress_new')) {
21//================================================================
22// What's New Module
23// get aritciles from module
24// xpress 0.20 <http://www.toemon.com>
25// 2007-07-17 toemon
26//================================================================
27
28// --- function start ---
29function _xpress_new($mydirname, $limit=0, $offset=0)
30{
31        global $xoopsDB;
32
33        if ($mydirname == 'wordpress'){
34                $wp_prefix = 'wp';
35        } else {
36                $wp_prefix = $mydirname;
37        }
38       
39        include(XOOPS_ROOT_PATH . '/modules/'.$mydirname . '/wp-includes/version.php');
40
41        $modules_table = $xoopsDB->prefix('modules');
42        $modSQL ="SELECT mid FROM " . $modules_table . " WHERE dirname LIKE '" . $mydirname . "'";
43        $modRes = $xoopsDB->query($modSQL, 0, 0);
44        $modRow = $xoopsDB->fetchArray($modRes);
45        $module_id = $modRow['mid'];   
46
47        $table_config = $xoopsDB->prefix('config');
48        $confSQL ="SELECT conf_value FROM " . $table_config . " WHERE (conf_modid = " . $module_id . ") AND (conf_name LIKE 'whatsnew_use_mod_date')";
49        $confRes = $xoopsDB->query($confSQL, 0, 0);
50        $confRow = $xoopsDB->fetchArray($confRes);
51        $use_modified_date = $confRow['conf_value'];
52
53        $url_mod = XOOPS_URL."/modules/".$mydirname;
54
55        $table_posts      = $xoopsDB->prefix($wp_prefix . "_posts");
56        $table_categories = $xoopsDB->prefix($wp_prefix . "_categories");
57        $table_post2cat   = $xoopsDB->prefix($wp_prefix . "_post2cat");
58        $table_views   = $xoopsDB->prefix($wp_prefix . "_views");
59        $table_term_relationships = $xoopsDB->prefix($wp_prefix . "_term_relationships");
60        $table_term_taxonomy = $xoopsDB->prefix($wp_prefix . "_term_taxonomy");
61        $table_terms = $xoopsDB->prefix($wp_prefix . "_terms");
62
63//      $sql = "SELECT ID, post_title, post_content, UNIX_TIMESTAMP(post_date) AS unix_post_date, post_status FROM ".$xoopsDB->prefix($wp_prefix . "_posts")." WHERE post_status='publish' ORDER BY post_date DESC";
64
65        $sql1 = "SELECT ID, post_author, post_title, post_content, post_type, comment_count, UNIX_TIMESTAMP(post_date) AS unix_post_date, UNIX_TIMESTAMP(post_modified) AS unix_post_modified, post_status FROM ".$table_posts." WHERE (post_status='publish') AND (UNIX_TIMESTAMP(post_date) <= UNIX_TIMESTAMP()) ORDER BY post_date DESC";
66
67       
68        $res1 = $xoopsDB->query($sql1, $limit, $offset);
69
70        $i = 0;
71        $ret = array();
72
73        while($row1 = $xoopsDB->fetchArray($res1))
74        {
75                $id = $row1['ID'];
76                if ($wp_db_version < 6124){
77                        $sql2 = "SELECT c.cat_ID, c.cat_name FROM ".$table_categories." c, ".$table_post2cat." p2c WHERE c.cat_ID = p2c.category_id AND p2c.post_id=".$id;
78                } else {
79                        $sql2  = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name ";
80                        $sql2 .= "FROM $table_term_relationships INNER JOIN ($table_term_taxonomy INNER JOIN $table_terms ON $table_term_taxonomy.term_id = $table_terms.term_id) ON $table_term_relationships.term_taxonomy_id = $table_term_taxonomy.term_taxonomy_id ";
81                        $sql2 .= "WHERE ($table_term_relationships.object_id =" . $id.") AND ($table_term_taxonomy.taxonomy='category')";               
82                }
83                $row2 = $xoopsDB->fetchArray( $xoopsDB->query($sql2) );
84                if ($row1['post_type'] == 'page'){
85                                $ret[$i]['link']     = $url_mod."/?page_id=".$id;
86                } else {
87                        $ret[$i]['link']     = $url_mod."/index.php?p=".$id;
88                }
89                $ret[$i]['cat_link'] = $url_mod."/index.php?cat=".$row2['cat_ID'];
90
91                $ret[$i]['title']    = $row1['post_title'];
92                $ret[$i]['cat_name'] = $row2['cat_name'];
93
94                $ret[$i]['uid'] = $row1['post_author'];
95                $ret[$i]['replies'] = $row1['comment_count'];
96
97
98                if(empty($use_modified_date)) {
99                        $time = $row1['unix_post_date'];
100                } else {
101
102                        if ($row1['unix_post_modified'] > $row1['unix_post_date']){
103                                $time = $row1['unix_post_modified'];
104                        } else {
105                                $time = $row1['unix_post_date'];
106                        }
107                }
108
109                $ret[$i]['time']     = $time;
110                $ret[$i]['modified'] = $time;
111                $ret[$i]['issued']   = $row1['unix_post_date'];
112                $content=$row1['post_content'];
113                $content = strip_tags($content);
114
115                $ret[$i]['description'] = $content;
116
117                $sql3 = "SELECT post_views FROM  " .  $table_views . " WHERE post_id = " . $id;
118                $row3 = $xoopsDB->fetchArray( $xoopsDB->query($sql3) );
119                $ret[$i]['hits']     = $row3['post_views'];
120
121
122
123                $i++;
124        }
125
126        return $ret;
127}
128
129function _xpress_num($mydirname)
130{
131        // get $mydirnumber
132        if( ! preg_match( '/^(\D+)(\d*)$/' , $mydirname , $regs ) ) echo ( "invalid dirname: " . htmlspecialchars( $mydirname ) ) ;
133
134        global $xoopsDB;
135
136        if ($mydirname == 'wordpress'){
137                $wp_prefix = 'wp';
138        } else {
139                $wp_prefix = $mydirname;
140        }
141
142        $sql = "SELECT count(*) FROM ".$xoopsDB->prefix($wp_prefix . "_posts")." ORDER BY ID";
143        $array = $xoopsDB->fetchRow( $xoopsDB->query($sql) );
144        $num = $array[0];
145        if (empty($num)) $num = 0;
146
147        return $num;
148}
149
150function _xpress_data($mydirname,$limit=0, $offset=0)
151{
152        // get $mydirnumber
153        if( ! preg_match( '/^(\D+)(\d*)$/' , $mydirname , $regs ) ) echo ( "invalid dirname: " . htmlspecialchars( $mydirname ) ) ;
154
155        global $xoopsDB;
156
157        if ($mydirname == 'wordpress'){
158                $wp_prefix = 'wp';
159        } else {
160                $wp_prefix = $mydirname;
161        }
162        $sql = "SELECT ID, post_title, UNIX_TIMESTAMP(post_date) AS unix_post_date, post_status FROM ".$xoopsDB->prefix($wp_prefix . "_posts")." WHERE post_status='publish' ORDER BY ID";
163        $result = $xoopsDB->query($sql,$limit,$offset);
164
165        $i = 0;
166        $ret = array();
167
168        while($row1 = $xoopsDB->fetchArray($result))
169        {
170                $id = $row1['ID'];
171                $ret[$i]['id'] = $id;
172                $ret[$i]['link'] = XOOPS_URL."/modules/xpress/index.php?p=".$id."";
173                $ret[$i]['title'] = $row1['post_title'];
174                $ret[$i]['time']  = $row1['unix_post_date'];
175                $i++;
176        }
177
178        return $ret;
179
180}
181
182// --- function end ---
183
184}
185
186?>
Note: See TracBrowser for help on using the repository browser.