| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: custom_breadcrumbs.install,v 1.2.2.2 2007/08/25 05:55:19 eaton Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_install(). |
* Implementation of hook_install(). |
| 6 |
*/ |
*/ |
| 7 |
function custom_breadcrumbs_install() { |
function custom_breadcrumbs_install() { |
| 8 |
|
drupal_install_schema('custom_breadcrumbs'); |
| 9 |
|
} |
| 10 |
|
|
| 11 |
|
function custom_breadcrumbs_schema() { |
| 12 |
|
$schema['custom_breadcrumb'] = array( |
| 13 |
|
'description' => t('Stores custom breadcrumb trail overrides.'), |
| 14 |
|
'fields' => array( |
| 15 |
|
'bid' => array( |
| 16 |
|
'type' => 'serial', |
| 17 |
|
'unsigned' => TRUE, |
| 18 |
|
'not null' => TRUE, |
| 19 |
|
'description' => t('Unique identifier for the {custom_breadcrumb}.'), |
| 20 |
|
), |
| 21 |
|
'titles' => array( |
| 22 |
|
'type' => 'varchar', |
| 23 |
|
'length' => 255, |
| 24 |
|
'not null' => TRUE, |
| 25 |
|
'default' => '', |
| 26 |
|
'description' => t("A return-delimited list of titles for the breadcrumb links.") |
| 27 |
|
), |
| 28 |
|
'paths' => array( |
| 29 |
|
'type' => 'varchar', |
| 30 |
|
'length' => 255, |
| 31 |
|
'not null' => FALSE, |
| 32 |
|
'description' => t("A return-delimited list of url paths for the breadcrumb links."), |
| 33 |
|
), |
| 34 |
|
'visibility_php' => array( |
| 35 |
|
'type' => 'text', |
| 36 |
|
'not null' => TRUE, |
| 37 |
|
'size' => 'medium', |
| 38 |
|
'default' => '', |
| 39 |
|
'description' => t('An optional PHP snippet to control the {custom_breadcrumb} visibility.'), |
| 40 |
|
), |
| 41 |
|
'node_type' => array( |
| 42 |
|
'type' => 'varchar', |
| 43 |
|
'length' => 64, |
| 44 |
|
'not null' => FALSE, |
| 45 |
|
'default' => 'AND', |
| 46 |
|
'description' => t("Node types the {custom_breadcrumb} should apply to."), |
| 47 |
|
), |
| 48 |
|
), |
| 49 |
|
'primary key' => array('bid'), |
| 50 |
|
); |
| 51 |
|
return $schema; |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
// Update old-style tokens from early versions of token.module. |
| 56 |
|
// Most users aren't using them, but we might as well handle them |
| 57 |
|
// properly. |
| 58 |
|
|
| 59 |
|
function custom_breadcrumbs_update_1() { |
| 60 |
|
$stuff = array( |
| 61 |
|
'%author_id' => '[author-uid]', |
| 62 |
|
'%author_name' => '[author-name]', |
| 63 |
|
'%user_id' => '[user-id]', |
| 64 |
|
'%user_name' => '[user-name]', |
| 65 |
|
'%node_id' => '[nid]', |
| 66 |
|
'%node_type' => '[type]', |
| 67 |
|
'%node_type_name' => '[type-name]', |
| 68 |
|
'%top_term' => '[term]', |
| 69 |
|
'%top_tname' => '[term-id]', |
| 70 |
|
'%created_d' => '[dd]', |
| 71 |
|
'%created_D' => '[ddd]', |
| 72 |
|
'%created_j' => '[d]', |
| 73 |
|
'%created_l' => '[day]', |
| 74 |
|
'%created_F' => '[month]', |
| 75 |
|
'%created_m' => '[mm]', |
| 76 |
|
'%created_M' => '[mon]', |
| 77 |
|
'%created_n' => '[m]', |
| 78 |
|
'%created_y' => '[yy]', |
| 79 |
|
'%created_Y' => '[yyyy]', |
| 80 |
|
); |
| 81 |
|
|
| 82 |
|
$search = array_keys($stuff); |
| 83 |
|
$replace = array_values($stuff); |
| 84 |
|
|
| 85 |
|
$result = db_query("SELECT * FROM {custom_breadcrumb} cb"); |
| 86 |
|
while ($crumb = db_fetch_object($result)) { |
| 87 |
|
$crumb->titles = str_replace($search, $replace, $crumb->titles); |
| 88 |
|
$crumb->paths = str_replace($search, $replace, $crumb->paths); |
| 89 |
|
custom_breadcrumbs_save_breadcrumb($crumb); |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
return array(t('Custom Breadcrumb replacement strings updated for use with Token module.')); |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
function custom_breadcrumbs_update_2() { |
| 96 |
|
$ret = array(); |
| 97 |
switch ($GLOBALS['db_type']) { |
switch ($GLOBALS['db_type']) { |
| 98 |
case 'mysql': |
case 'mysql': |
| 99 |
case 'mysqli': |
case 'mysqli': |
| 100 |
db_query("CREATE TABLE {custom_breadcrumb} ( |
$ret[] = update_sql("ALTER TABLE {custom_breadcrumb} ADD visibility_php text"); |
|
bid int unsigned NOT NULL auto_increment, |
|
|
titles varchar(255) NOT NULL default '', |
|
|
paths varchar(255) NOT NULL default '', |
|
|
node_type varchar(64) default '', |
|
|
PRIMARY KEY (bid) |
|
|
) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); |
|
| 101 |
break; |
break; |
| 102 |
case 'pgsql': |
case 'pgsql': |
| 103 |
db_query("CREATE TABLE {custom_breadcrumb} ( |
db_add_column($ret, 'custom_breadcrumb', 'visibility_php', 'text', array('default' => '')); |
|
bid serial CHECK (nid >= 0), |
|
|
titles varchar(255) NOT NULL default '', |
|
|
paths varchar(255) NOT NULL default '', |
|
|
node_type varchar(64) default '' |
|
|
)"); |
|
|
db_query("CREATE INDEX {custom_breadcrumb}_bid_idx ON {custom_breadcrumb} (bid)"); |
|
| 104 |
break; |
break; |
| 105 |
} |
} |
| 106 |
|
return $ret; |
| 107 |
} |
} |
| 108 |
|
|
| 109 |
function custom_breadcrumbs_uninstall() { |
function custom_breadcrumbs_uninstall() { |
| 110 |
db_query('DROP TABLE {custom_breadcrumb}'); |
drupal_uninstall_schema('custom_breadcrumbs'); |
| 111 |
} |
} |