XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/include/sitemap.plugin.php @ 762

Last change on this file since 762 was 749, checked in by toemon, 13 years ago

Database::getInstance()を使わずに、global $xoopsDB を使用する。(xoops3対策)

File size: 5.4 KB
RevLine 
[29]1<?php
2// $Id: xpress.php
3// FILE         ::      xpress.php
4// AUTHOR       ::      toemon
5//
6// WordPress 2.0+
7
8if( ! defined( 'XOOPS_ROOT_PATH' ) ) exit ;
9$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
10
11eval( '
12function b_sitemap_' . $mydirname . '(){       
13        return _sitemap_xpress("'.$mydirname.'");
14}
15') ;
16
17if(!function_exists('_sitemap_xpress')){
18        function _sitemap_xpress($mydirname){
[423]19                global $sitemap_configs , $xoopsDB;
[29]20
21                if (!file_exists(XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/wp-includes/version.php')){
22                        return '';
23                }
[423]24                include (XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/wp-includes/version.php');
25                if ($wp_db_version < 6124) {  // UNDER WP2.3
26                            $block = sitemap_get_categoires_map($xoopsDB->prefix("wp_categories"), "cat_ID", "category_parent", "cat_name", "index.php?cat=", "cat_name");
27                        return $block;
28                }
[29]29               
[423]30                $disp_sub =@$sitemap_configs["show_subcategoris"];
[29]31               
[583]32                $prefix = preg_replace('/wordpress/','wp',$mydirname);
[423]33                $prefix = $xoopsDB->prefix($prefix);
34                require_once (XOOPS_ROOT_PATH . '/modules/'.$mydirname . '/include/general_functions.php');
35                $options_tables = get_table_list($prefix,'options');
[29]36               
[423]37                $index = 0;
38                $blogs =array();
39                foreach( $options_tables as $options_table){
40                        $blog_url = get_blog_option($options_table , 'siteurl');
41                        $blog_sub_url = preg_replace('/.*\/' . $mydirname . '/' , '' , $blog_url);
42                        $blog_sub_url = preg_replace('/\//' , '' , $blog_sub_url);
43                        if (!empty($blog_sub_url)) {
44                                $blog_sub_url = $blog_sub_url . '/';
45                        }
46                        $blog_name = get_blog_option($options_table , 'blogname');
47                        $db_prefix = get_multi_prefix($options_table , 'options');
48
49                        $data = array(
50                                'blog_name' => $blog_name ,
51                                'blog_sub_url' => $blog_sub_url ,
52                                'term_taxonomy' => $db_prefix. 'term_taxonomy' ,
53                                'terms' => $db_prefix . 'terms'
54                        );
55                        $blogs[$index] = $data;
56                        $index++;
[29]57                }
[423]58                return xpress_get_categoires_map($blogs,$disp_sub);
59        }
60}
61
62if(!function_exists('xpress_get_categoires_map')){
63        function xpress_get_categoires_map($blogs ,$disp_sub){
[749]64                global $sitemap_configs,$xoopsDB;
[423]65               
66                $sitemap = array();
67                $myts =& MyTextSanitizer::getInstance();
68               
69                $blogs_count = count($blogs);
70                $i = 0;
71                $blog = array();
72                for ($b_no = 0 ; $b_no < $blogs_count ; $b_no++){
73                        $blog = $blogs[$b_no];
74                        $terms = $blog['terms'];
75                        $term_taxonomy = $blog['term_taxonomy'];
76                        $blog_sub_url = $blog['blog_sub_url'];
77                        $cat_url = $blog['blog_sub_url'] . '?cat=';
78                        $blog_name = $blog['blog_name'];
79                       
80                        $sql  = "SELECT term_id , name FROM $terms";
81                        $result = $xoopsDB->query($sql);
82                        $cat_name = array();
83                        while (list($id, $name) = $xoopsDB->fetchRow($result)){
84                                $cat_name["'ID" . $id . "'"] = $name;
85                        }
86                        if ($blogs_count > 1){
87                                        $sitemap['parent'][$i]['id'] = 0;
88                                        $sitemap['parent'][$i]['title'] = $blog_name ;
89                                        $sitemap['parent'][$i]['image'] = 1 ;
90                                        $sitemap['parent'][$i]['url'] = $blog_sub_url;
91                                        $blog_index = $i;
92                                        $i++;
93                        }
94
95                        $mytree = new XoopsTree($term_taxonomy, 'term_id' , 'parent');
96                        $sql  = "SELECT term_id  FROM $term_taxonomy WHERE parent = 0 AND taxonomy = 'category'";
97                        $result = $xoopsDB->query($sql);
98                        while (list($catid) = $xoopsDB->fetchRow($result)){
99                                if ($blogs_count <= 1){
100                                        $dipth = 1;
101                                        $sitemap['parent'][$i]['id'] = $catid;
102                                        $sitemap['parent'][$i]['title'] = $cat_name["'ID" . $catid . "'"] ; ;
103                                        $sitemap['parent'][$i]['image'] = $dipth ;
104                                        $sitemap['parent'][$i]['url'] = $cat_url.$catid;
105
106                                        if($disp_sub){
107                                                $j = 0;
108                                                $child_ary = $mytree->getChildTreeArray($catid, '');
109                                                foreach ($child_ary as $child)
110                                                {
111                                                        $count = strlen($child['prefix']) + $dipth;
112                                                        $sitemap['parent'][$i]['child'][$j]['id'] = $child['term_id'];
113                                                        $sitemap['parent'][$i]['child'][$j]['title'] = $cat_name["'ID" .$child['term_id'] . "'"];
114                                                        $sitemap['parent'][$i]['child'][$j]['image'] = (($count > 3) ? 4 : $count);
115                                                        $sitemap['parent'][$i]['child'][$j]['url'] = $cat_url.$child['term_id'];
116                                                        $j++;
117                                                }
[29]118                                        }
[423]119                                        $i++;
[29]120                                } else {
[423]121                                        $dipth = 2;
122                                        $sitemap['parent'][$blog_index]['child'][$i]['id'] = $catid;
123                                        $sitemap['parent'][$blog_index]['child'][$i]['title'] = $cat_name["'ID" . $catid . "'"];
124                                        $sitemap['parent'][$blog_index]['child'][$i]['image'] = $dipth;
125                                        $sitemap['parent'][$blog_index]['child'][$i]['url'] = $cat_url.$catid;
126                                        $i++;
127                                        $parent_id = $blog_index;
128                                        if($disp_sub){
129                                                $child_ary = $mytree->getChildTreeArray($catid, '');
130                                                foreach ($child_ary as $child)
131                                                {
132                                                        $count = strlen($child['prefix']) + $dipth;
133                                                        $sitemap['parent'][$blog_index]['child'][$i]['id'] = $child['term_id'];
134                                                        $sitemap['parent'][$blog_index]['child'][$i]['title'] = $cat_name["'ID" .$child['term_id'] . "'"];
135                                                        $sitemap['parent'][$blog_index]['child'][$i]['image'] = (($count > 3) ? 4 : $count);
136                                                        $sitemap['parent'][$blog_index]['child'][$i]['url'] = $cat_url.$child['term_id'];
137                                                        $i++;
138                                                }
139                                        }
[29]140                                }
[423]141                        $i++;
[29]142                        }
[423]143                }
144                return $sitemap;
[29]145        }
146}
147
[423]148if( ! function_exists( 'get_blog_option' ) ) {
149        function get_blog_option($option_table,$option_name){
[749]150                global $xoopsDB;
[423]151
152                $sql = "SELECT option_value FROM $option_table WHERE option_name = '" . $option_name . "'";
153               
154                $result =  $xoopsDB->query($sql, 0, 0);
155                if ($xoopsDB->getRowsNum($result)  > 0){
156                        $row = $xoopsDB->fetchArray($result);
157                        return $row['option_value'];
158                }
159                return 0;
160        }
161}
162
163
[29]164?>
Note: See TracBrowser for help on using the repository browser.