/[drupal]/contributions/modules/xmlsitemap/xmlsitemap.install
ViewVC logotype

Contents of /contributions/modules/xmlsitemap/xmlsitemap.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Tue May 20 17:48:46 2008 UTC (18 months, 1 week ago) by darrenoh
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.4: +110 -36 lines
File MIME type: text/x-php
#157533 by Freso, DenRaf, hswong3i, chantra, wayland76: Updated to work with Drupal 6.
1 <?php
2 // $Id: xmlsitemap.install,v 1.1.2.3 2007/12/11 22:57:38 darrenoh Exp $
3
4 /**
5 * Implementation of hook_schema().
6 */
7 function xmlsitemap_schema() {
8 $schema['xmlsitemap_additional'] = array(
9 'description' => t('The base table for xmlsitemap.'),
10 'fields' => array(
11 'path' => array(
12 'description' => t('The path of this node.'),
13 'type' => 'varchar',
14 'length' => 128,
15 'not null' => TRUE,
16 'default' => '',
17 ),
18 'pid' => array(
19 'description' => t('The id of the path.'),
20 'type' => 'int',
21 'unsigned' => TRUE,
22 'default' => 0,
23 ),
24 'last_changed' => array(
25 'description' => t('Keeps track of new changes.'),
26 'type' => 'int',
27 'unsigned' => TRUE,
28 'not null' => TRUE,
29 'default' => 0,
30 ),
31 'previously_changed' => array(
32 'description' => t('Keeps track of old changes.'),
33 'type' => 'int',
34 'unsigned' => TRUE,
35 'not null' => TRUE,
36 'default' => 0,
37 ),
38 'priority' => array(
39 'description' => t('Stores the index value.'),
40 'type' => 'float',
41 'not null' => FALSE,
42 ),
43 ),
44 'indexes' => array(
45 'pid' => array('pid'),
46 ),
47 'primary key' => array('path'),
48 );
49
50 return $schema;
51 }
52
53 /**
54 * Implementation of hook_install().
55 */
56 function xmlsitemap_install() {
57 // Create my tables.
58 db_query("DELETE FROM {url_alias} WHERE dst LIKE 'sitemap%.xml'");
59 drupal_install_schema('xmlsitemap');
60 }
61
62 /**
63 * Implementation of hook_uninstall().
64 */
65 function xmlsitemap_uninstall() {
66 // Drop my tables.
67 $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'xmlsitemap\_%'");
68 while ($variable = db_fetch_object($settings)) {
69 variable_del($variable->name);
70 }
71 drupal_uninstall_schema('xmlsitemap');
72 }
73
74 /**
75 * Implementation of hook_enable().
76 */
77 function xmlsitemap_enable() {
78 global $base_path;
79 $xsl = file_get_contents(drupal_get_path('module', 'xmlsitemap') .'/gss/gss.xsl');
80
81 $css_start = strpos($xsl, '<link href="') + strlen('<link href="');
82 $css_length = strpos($xsl, '" type="text/css" rel="stylesheet"/>') - $css_start;
83 $xsl = substr_replace($xsl, $base_path . drupal_get_path('module', 'xmlsitemap') .'/gss/gss.css', $css_start, $css_length);
84
85 $js_start = strpos($xsl, '<script src="') + strlen('<script src="');
86 $js_length = strpos($xsl, '"></script>') - $js_start;
87 $xsl = substr_replace($xsl, $base_path . drupal_get_path('module', 'xmlsitemap') .'/gss/gss.js', $js_start, $js_length);
88
89 if (file_check_directory(($path = file_directory_path() .'/xmlsitemap'), FILE_CREATE_DIRECTORY)) {
90 file_save_data($xsl, "$path/gss.xsl", FILE_EXISTS_REPLACE);
91 }
92 _xmlsitemap_gsitemap_replace();
93 }
94
95 /**
96 * Replace Google Sitemap if it is installed.
97 */
98 function _xmlsitemap_gsitemap_replace() {
99 if (db_result(db_query("
100 SELECT 1 FROM {system}
101 WHERE type = 'module' AND name = 'gsitemap' AND (status = 1 OR schema_version >= 0)
102 "))) {
103 db_query("
104 INSERT INTO {xmlsitemap_additional} (path, pid, last_changed, previously_changed, priority)
105 SELECT path, pid, last_changed, previously_changed, priority FROM {gsitemap_additional}
106 ");
107 $modules = array('xmlsitemap_node', 'xmlsitemap_engines');
108 if (variable_get('gsitemap_showterms', FALSE)) {
109 $modules[] = 'xmlsitemap_term';
110 variable_del('gsitemap_showterms');
111 }
112 if (variable_get('gsitemap_showusers', FALSE)) {
113 $modules[] = 'xmlsitemap_user';
114 variable_del('gsitemap_showusers');
115 }
116 drupal_install_modules($modules);
117 $settings = db_query("SELECT * FROM {variable} WHERE name LIKE 'gsitemap\_%'");
118 while ($variable = db_fetch_object($settings)) {
119 switch ($variable->name) {
120 case 'gsitemap_frontpage':
121 $name = 'xmlsitemap_front_page_priority';
122 break;
123 case 'gsitemap_priority':
124 $name = 'xmlsitemap_additional_links_priority';
125 break;
126 case 'gsitemap_logacc':
127 $name = 'xmlsitemap_log_access';
128 break;
129 default:
130 $name = 'xmlsitemap'. strstr($variable->name, '_');
131 break;
132 }
133 variable_set($name, (float) unserialize($variable->value));
134 }
135 module_disable(array('gsitemap'));
136 drupal_uninstall_module('gsitemap');
137 }
138 }
139
140 /**
141 * Implementation of hook_disable().
142 */
143 function xmlsitemap_disable() {
144 $path = file_directory_path() .'/xmlsitemap';
145 if ($dir = @opendir($path)) {
146 while (($file = readdir($dir)) !== FALSE) {
147 if ($file != '.' && $file != '..') {
148 unlink("$path/$file");
149 }
150 }
151 closedir($dir);
152 rmdir($path);
153 }
154 }

  ViewVC Help
Powered by ViewVC 1.1.2