WordPress.org

Plugin Directory

Changeset 182189


Ignore:
Timestamp:
12/12/09 21:37:29 (8 years ago)
Author:
freshlabs
Message:

Renamed timeline-db.inc.php to WPSimileTimelineDatabase.class.php

File:
1 copied

Legend:

Unmodified
Added
Removed
  • wp-simile-timeline/trunk/inc/WPSimileTimelineDatabase.class.php

    r181989 r182189  
    11<?php 
    2 /* 
    3  * timeline-db.php 
     2/** 
     3 * WPSimileTimelineDatabase.class.php 
    44 * Description: Database functions for the SIMILE Timline Plugin 
    5  * Plugin URI: http://www.freshlabs.de/journal/archives/2006/10/wordpress-plugin-simile-timeline/ 
     5 * Plugin URI: http://wordpress.org/extend/plugins/wp-simile-timeline/ 
    66 * Author: Tim Isenheim 
    77 *  
    88    =========================================================================== 
    99    SIMILE Timeline for WordPress 
    10     Copyright (C) 2006 Tim Isenheim 
     10    Copyright (C) 2009 Tim Isenheim 
    1111     
    1212    This program is free software: you can redistribute it and/or modify 
     
    2424    =========================================================================== 
    2525*/ 
     26class WPSimileTimelineDatabase{ 
     27    function WPSimileTimelineDatabase(){ 
     28         
     29    } 
     30     
     31    /* --------------------------------------------------------------------------------- 
     32     * checks if a given column exists in a database table 
     33     * --------------------------------------------------------------------------------*/ 
     34    function columnExists($col_name){ 
     35        global $wpdb; 
     36        $column_exists = false; 
     37        $q = $wpdb->query($wpdb->prepare("SHOW COLUMNS FROM $wpdb->posts LIKE '$col_name'")); 
     38        if($q == 1){ 
     39            $column_exists = true; 
     40        } 
     41        return $column_exists; 
     42    } 
     43     
     44    /* ------------------------------------------------------------------------- 
     45     * Functions to ADD tables and columns 
     46     * ----------------------------------------------------------------------*/ 
     47     
     48    /* 
     49     * Adds extra column in posts table for start and end dates 
     50     */ 
     51    function addEventColumn($column_name){ 
     52        global $wpdb; 
     53        if(!WPSimileTimelineDatabase::columnExists($column_name)) { 
     54            $wpdb->query($wpdb->prepare("ALTER TABLE $wpdb->posts ADD COLUMN " . $column_name . " datetime NOT NULL DEFAULT '0000-00-00 00:00:00'")); 
     55        } 
     56    } 
     57     
     58    /* ------------------------------------------------------------------------- 
     59     * Functions to DELETE tables and columns 
     60     * ----------------------------------------------------------------------*/ 
    2661 
    27 /* --------------------------------------------------------------------------------- 
    28  * adds extra column in posts table for start and end dates 
    29  * --------------------------------------------------------------------------------*/ 
    30 function stl_timeline_add_eventcolumn($column_name){ 
    31     global $wpdb; 
    32     if(!stl_timeline_column_exists($column_name)) { 
    33         $wpdb->query($wpdb->prepare("ALTER TABLE $wpdb->posts ADD COLUMN " . $column_name . " datetime NOT NULL DEFAULT '0000-00-00 00:00:00'")); 
     62    /* 
     63     * Delete a table 
     64     */ 
     65    function deleteTable($tn){       
     66        global $wpdb; 
     67        $table_name = $wpdb->prefix . $tn; 
     68        $wpdb->query($wpdb->prepare("DROP TABLE " . $table_name)); 
     69    } 
     70 
     71    /* 
     72     * removes the database column on uninstalling 
     73     * This deletes all event dates set for posts 
     74     */ 
     75    function removeEventColumn($column_name) { 
     76        global $wpdb; 
     77        if(WPSimileTimelineDatabase::columnExists($column_name)) { 
     78            $wpdb->query($wpdb->prepare("ALTER TABLE $wpdb->posts DROP COLUMN $column_name")); 
     79        } 
     80    } 
     81     
     82    /* 
     83     * Save start and end dates of an event(post) to the database 
     84     */ 
     85    function updateEventDates($post_id){ 
     86        WPSimileTimelineDatabase::saveEventDate($post_id, $_POST, 'start'); 
     87        WPSimileTimelineDatabase::saveEventDate($post_id, $_POST, 'latest_start'); 
     88        WPSimileTimelineDatabase::saveEventDate($post_id, $_POST, 'end'); 
     89        WPSimileTimelineDatabase::saveEventDate($post_id, $_POST, 'earliest_end'); 
     90    } 
     91     
     92    /* 
     93     * Save time value of an event(post) to the database 
     94     * used by both, start and end update functions 
     95     */ 
     96    function saveEventDate($pID, $p, $type='start'){ 
     97        global $wpdb; 
     98        $column = "stl_timeline_event_".$type; 
     99        $edit = $p['stl_timeline_'.$type]['edit']; 
     100        $reset = $p['stl_timeline_'.$type]['reset']; 
     101        // if "Edit timestamp" is selected 
     102        if (isset($edit) && !isset($reset)) { 
     103            $stl_aa = $p['stl_timeline_'.$type]['year']; 
     104            $stl_mm = $p['stl_timeline_'.$type]['month']; 
     105            $stl_jj = $p['stl_timeline_'.$type]['day']; 
     106            $stl_hh = $p['stl_timeline_'.$type]['hour']; 
     107            $stl_mn = $p['stl_timeline_'.$type]['minute']; 
     108            $stl_ss = $p['stl_timeline_'.$type]['second']; 
     109            $stl_jj = ($stl_jj > 31) ? 31 : $stl_jj; 
     110            $stl_hh = ($stl_hh > 23) ? $stl_hh -24 : $stl_hh; 
     111            $stl_mn = ($stl_mn > 59) ? $stl_mn -60 : $stl_mn; 
     112            $stl_ss = ($stl_ss > 59) ? $stl_ss -60 : $stl_ss; 
     113            $postdata = "$stl_aa-$stl_mm-$stl_jj $stl_hh:$stl_mn:$stl_ss"; 
     114            $stl_tee = $postdata; 
     115            $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET $column = '%s' WHERE ID = %d", $stl_tee, $pID)); 
     116        } 
     117        // Reset timestamp to 0 
     118        if (isset ($reset)) { 
     119            $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET $column = '0000-00-00 00:00:00' WHERE ID = $pID")); 
     120        } 
     121    } 
     122     
     123    /** 
     124     * Get the minimum or maximum date of wpdb->posts.$column in $categories 
     125     */ 
     126    function queryEventDate($minmax, $column, $categories){ 
     127        global $wpdb; 
     128         
     129        $relation = "SELECT object_id FROM $wpdb->term_relationships " . 
     130                    "INNER JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND  $wpdb->term_taxonomy.term_id IN ($categories) )"; 
     131                     
     132        $query =    "SELECT $minmax($wpdb->posts.$column) from $wpdb->posts INNER JOIN ($relation) t1 ON (t1.object_id=$wpdb->posts.ID) " . 
     133                    "WHERE $column != '0000-00-00 00:00:00' AND post_status='publish' AND post_type!='revision'"; 
     134     
     135        return $wpdb->get_var($query); 
     136    } 
     137     
     138    /* --------------------------------------------------------------------------------- 
     139     * stl_get_extreme_event_date 
     140     * Get the date of the very first or last post dependant from the start date 
     141     * --------------------------------------------------------------------------------*/ 
     142    function getMinMaxEventDate($minmax, $type, $format='r', $categories){ 
     143        global $wpdb; 
     144         
     145        $column = 'stl_timeline_event_' . $type; 
     146         
     147        // try to get the extreme post date from stl-columns 
     148        $date = WPSimileTimelineDatabase::queryEventDate($minmax, $column, $categories); 
     149         
     150        if(empty($date)){ 
     151            $column = 'post_date'; 
     152            // get usual post date when start or end date isn't set 
     153            $date = WPSimileTimelineDatabase::queryEventDate($minmax, $column, $categories); 
     154        } 
     155        if($format != null){ 
     156            $date = adodb_date2($format, $date); 
     157        } 
     158        return $date; 
    34159    } 
    35160} 
    36  
    37 /* --------------------------------------------------------------------------------- 
    38  * removes the database column on uninstalling 
    39  * WARNING: This deletes all end dates set for posts 
    40  * --------------------------------------------------------------------------------*/ 
    41 function stl_timeline_remove_eventcolumn($column_name) { 
    42     global $wpdb; 
    43     if(stl_timeline_column_exists($column_name)) { 
    44         $wpdb->query($wpdb->prepare("ALTER TABLE $wpdb->posts DROP COLUMN $column_name")); 
    45     } 
    46 } 
    47  
    48 /* --------------------------------------------------------------------------------- 
    49  * Save the start date of an event(post) to the database 
    50  * --------------------------------------------------------------------------------*/ 
    51 function stl_timeline_update_eventstart_box($pID){ 
    52     __stl_timeline_update_event_date($pID, $_POST, 'start'); 
    53     __stl_timeline_update_event_date($pID, $_POST, 'latest_start'); 
    54 } 
    55  
    56 /* --------------------------------------------------------------------------------- 
    57  * Save the end date of an event(post) to the database 
    58  * --------------------------------------------------------------------------------*/ 
    59 function stl_timeline_update_eventend_box($pID){ 
    60     __stl_timeline_update_event_date($pID, $_POST, 'end'); 
    61     __stl_timeline_update_event_date($pID, $_POST, 'earliest_end'); 
    62 } 
    63  
    64 /* --------------------------------------------------------------------------------- 
    65  * Save time value of an event(post) to the database 
    66  * used by both, start and end update functions 
    67  * --------------------------------------------------------------------------------*/ 
    68 function __stl_timeline_update_event_date($pID, $p, $type='start'){ 
    69     global $wpdb; 
    70     $column = "stl_timeline_event_".$type; 
    71     $edit = $p['stl_timeline_'.$type]['edit']; 
    72     $reset = $p['stl_timeline_'.$type]['reset']; 
    73     // if "Edit timestamp" is selected 
    74     if (isset($edit) && !isset($reset)) { 
    75         $stl_aa = $p['stl_timeline_'.$type]['year']; 
    76         $stl_mm = $p['stl_timeline_'.$type]['month']; 
    77         $stl_jj = $p['stl_timeline_'.$type]['day']; 
    78         $stl_hh = $p['stl_timeline_'.$type]['hour']; 
    79         $stl_mn = $p['stl_timeline_'.$type]['minute']; 
    80         $stl_ss = $p['stl_timeline_'.$type]['second']; 
    81         $stl_jj = ($stl_jj > 31) ? 31 : $stl_jj; 
    82         $stl_hh = ($stl_hh > 23) ? $stl_hh -24 : $stl_hh; 
    83         $stl_mn = ($stl_mn > 59) ? $stl_mn -60 : $stl_mn; 
    84         $stl_ss = ($stl_ss > 59) ? $stl_ss -60 : $stl_ss; 
    85         $postdata = "$stl_aa-$stl_mm-$stl_jj $stl_hh:$stl_mn:$stl_ss"; 
    86         $stl_tee = $postdata; 
    87         $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET $column = '%s' WHERE ID = %d", $stl_tee, $pID)); 
    88     } 
    89     // Reset timestamp to 0 
    90     if (isset ($reset)) { 
    91         $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET $column = '0000-00-00 00:00:00' WHERE ID = $pID")); 
    92     } 
    93 } 
    94  
    95 /* --------------------------------------------------------------------------------- 
    96  * stl_get_extreme_event_date 
    97  * Get the date of the very first or last post dependant from the start date 
    98  * --------------------------------------------------------------------------------*/ 
    99 function stl_get_extreme_event_date($minmax, $type, $format='r', $categories){ 
    100     global $wpdb; 
    101      
    102     $column = 'stl_timeline_event_' . $type; 
    103      
    104     // try to get the extreme post date from stl-columns 
    105     $date = stl_timeline_query_postdate($minmax, $column, $categories); 
    106      
    107     if(empty($date)){ 
    108         $column = 'post_date'; 
    109         // get usual post date when start or end date isn't set 
    110         $date = stl_timeline_query_postdate($minmax, $column, $categories); 
    111     } 
    112     if($format != null){ 
    113         $date = adodb_date2($format, $date); 
    114     } 
    115     return $date; 
    116 } 
    117  
    118 /* --------------------------------------------------------------------------------- 
    119  * stl_timeline_query_postdate 
    120  * Get the minimum or maximum date of wpdb->posts.$column in $categories 
    121  * --------------------------------------------------------------------------------*/ 
    122 function stl_timeline_query_postdate($minmax, $column, $categories){ 
    123     global $wpdb; 
    124      
    125     $relation = "SELECT object_id FROM $wpdb->term_relationships " . 
    126                 "INNER JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND  $wpdb->term_taxonomy.term_id IN ($categories) )"; 
    127                  
    128     $query =    "SELECT $minmax($wpdb->posts.$column) from $wpdb->posts INNER JOIN ($relation) t1 ON (t1.object_id=$wpdb->posts.ID) " . 
    129                 "WHERE $column != '0000-00-00 00:00:00' AND post_status='publish' AND post_type!='revision'"; 
    130  
    131     return $wpdb->get_var($query); 
    132 } 
    133  
    134 /* --------------------------------------------------------------------------------- 
    135  * stl_getdate 
    136  * PHP getdate pendant...the dirty way 
    137  * --------------------------------------------------------------------------------*/ 
    138 function stl_getdate($date){ 
    139     $d = explode(' ', $date); 
    140     $date = explode('-', $d[0]); 
    141     $time = explode(':', $d[1]); 
    142     $arr['year'] = $date[0]; 
    143     $arr['month'] = $date[1]; 
    144     $arr['day'] = $date[2]; 
    145     $arr['hour'] = $time[0]; 
    146     $arr['minute'] = $time[1]; 
    147     $arr['second'] = $time[2]; 
    148     return $arr; 
    149 } 
    150  
    151 /* --------------------------------------------------------------------------------- 
    152  * install STL table for Timeline category attributes 
    153  * --------------------------------------------------------------------------------*/ 
    154 function stl_timeline_add_relationship_table(){ 
    155          
    156     global $wpdb; 
    157  
    158     $table_name = $wpdb->prefix . "stl_timeline_terms"; 
    159     if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { 
    160  
    161         $sql = "CREATE TABLE " . $table_name . " ( 
    162               id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
    163               term_id INT NOT NULL, 
    164               color VARCHAR( 7 ) NOT NULL DEFAULT '#58A0DC', 
    165               active INT NOT NULL DEFAULT 0 
    166             );"; 
    167  
    168         require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
    169         dbDelta($sql); 
    170          
    171         // copy all category-terms to the new table 
    172         $sql2 = "SELECT * FROM $wpdb->term_taxonomy WHERE taxonomy = 'category' OR taxonomy = 'link_category'"; 
    173  
    174         $res = $wpdb->get_results($sql2); 
    175  
    176         foreach($res as $term){ 
    177             stl_add_term_to_db($term->term_id); 
    178         } 
    179    } 
    180 } 
    181  
    182 /* --------------------------------------------------------------------------------- 
    183  * Delete STL table 
    184  * --------------------------------------------------------------------------------*/ 
    185 function stl_timeline_remove_table($tn){ 
    186          
    187     global $wpdb; 
    188  
    189     $table_name = $wpdb->prefix . $tn; 
    190     $wpdb->query($wpdb->prepare("DROP TABLE " . $table_name)); 
    191 } 
    192  
    193 /* --------------------------------------------------------------------------------- 
    194  * update STL table for Timeline categories 
    195  * --------------------------------------------------------------------------------*/ 
    196 function stl_timeline_update_relationship_table(){ 
    197      
    198     global $wpdb; 
    199     require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
    200          
    201     // copy diff of term table to timeline-terms 
    202     $table = $wpdb->prefix . "stl_timeline_terms"; 
    203     $sql = "SELECT term_id FROM $table "; 
    204     $res = $wpdb->get_results($sql, ARRAY_A); 
    205  
    206     $terms = get_terms(array('category', 'link_category')); 
    207      
    208     $cmp = array(); 
    209     // copy categories to stl_timeline term relationship table 
    210     foreach($res as $stl_term){ 
    211         array_push($cmp, $stl_term['term_id']); 
    212     } 
    213     // loop all available valid terms 
    214     foreach($terms as $term){        
    215         // add to database if not already exist in the timeline terms  
    216         if(!in_array($term->term_id, $cmp)){ 
    217             stl_add_term_to_db($term->term_id); 
    218         } 
    219         else{ 
    220             // already exists.. do nothing 
    221         } 
    222     } 
    223 } 
    224  
    225 /* --------------------------------------------------------------------------------- 
    226  * remove term from options if the whole category is deleted 
    227  * --------------------------------------------------------------------------------*/ 
    228 function stl_delete_term_from_db($term_id) { 
    229     global $wpdb; 
    230  
    231     $table_name = $wpdb->prefix . "stl_timeline_terms"; 
    232      
    233     $insert = "DELETE FROM " . $table_name . " WHERE term_id= " . $term_id . ""; 
    234     $results = $wpdb->query($wpdb->prepare($insert)); 
    235 } 
    236  
    237 /* --------------------------------------------------------------------------------- 
    238  * add single term to timeline relationship table 
    239  * --------------------------------------------------------------------------------*/ 
    240 function stl_add_term_to_db($term_id) { 
    241     global $wpdb; 
    242  
    243     require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
    244      
    245     $table_name = $wpdb->prefix . "stl_timeline_terms"; 
    246  
    247     $insert = "INSERT INTO $table_name (term_id, color) VALUES ($term_id, '#58A0DC')"; 
    248  
    249     $wpdb->query($insert); 
    250 } 
    251  
    252 /* --------------------------------------------------------------------------------- 
    253  * get term from timeline relationship table for specific post ID 
    254  * --------------------------------------------------------------------------------*/ 
    255 function stl_get_timeline_term_for_post($post_id) { 
    256     global $wpdb; 
    257      
    258     $table_name = $wpdb->prefix . "stl_timeline_terms"; 
    259      
    260     $term_id = $wpdb->get_var("SELECT term_id FROM $wpdb->term_taxonomy " . 
    261             "INNER JOIN $wpdb->term_relationships ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id AND 
    262             $wpdb->term_relationships.object_id = $post_id)"); 
    263  
    264     return stl_get_term($term_id); 
    265 } 
    266  
    267 /* --------------------------------------------------------------------------------- 
    268  * get term from timeline relationship table for specific post ID 
    269  * --------------------------------------------------------------------------------*/ 
    270 function stl_get_term($term_id) { 
    271     global $wpdb; 
    272      
    273     $table_name = $wpdb->prefix . "stl_timeline_terms"; 
    274  
    275     $get = "SELECT * FROM " . $table_name . " WHERE term_id = $term_id"; 
    276     $row = $wpdb->get_row($get); 
    277     return $row; 
    278 } 
    279  
    280 /* --------------------------------------------------------------------------------- 
    281  * install table for Timeline bandds 
    282  * --------------------------------------------------------------------------------*/ 
    283 function stl_timeline_add_bands_table(){ 
    284          
    285     global $wpdb; 
    286  
    287     $table_name = $wpdb->prefix . "stl_timeline_bands"; 
    288     if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { 
    289  
    290         $sql = "CREATE TABLE " . $table_name . " ( 
    291               `id` int(11) NOT NULL auto_increment, 
    292               `name` varchar(210) NOT NULL, 
    293               `height` varchar(10) NOT NULL, 
    294               `unit` int(11) NOT NULL, 
    295               `interval_size` int(11) NOT NULL, 
    296               `bg_color` varchar(7) NOT NULL, 
    297               `interval_color` varchar(7) NOT NULL, 
    298               `ether_highlight_color` varchar(7) NOT NULL, 
    299               `highlight_label_color` varchar(7) NOT NULL, 
    300               `show_labels` int(11) NOT NULL, 
    301               PRIMARY KEY  (`id`) 
    302             );"; 
    303  
    304         require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
    305         dbDelta($sql); 
    306          
    307         // fill with standard timeline bands 
    308         $insert = "INSERT INTO " . $table_name . " (name, height, unit, interval_size, bg_color, interval_color, ether_highlight_color, highlight_label_color, show_labels) " . 
    309                   "VALUES (%s, %s, %d, %d, %s, %s, %s, %s, %d)"; 
    310         $wpdb->query($wpdb->prepare($insert, 'Band 1', '70%', 4, 200, '#eee', '#aaa', '#aaa', '#444', 1)); 
    311         $wpdb->query($wpdb->prepare($insert, 'Band 2', '30%', 6, 100, '#ddd', '#aaa', '#aaa', '#444', 0)); 
    312    } 
    313 } 
    314  
    315 /* --------------------------------------------------------------------------------- 
    316  * install table for Timeline hotzones 
    317  * --------------------------------------------------------------------------------*/ 
    318 function stl_timeline_add_hotzones_table(){ 
    319          
    320     global $wpdb; 
    321      
    322     $hotzone_object = new WPSimileTimelineHotzone(); 
    323     $table_name = $wpdb->prefix . $hotzone_object->table_name; 
    324     if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { 
    325  
    326         $sql = "CREATE TABLE " . $table_name . " ( 
    327               `id` int(11) NOT NULL auto_increment, 
    328               `name` varchar(210) NOT NULL, 
    329               `stl_timeline_band_id` int(11) NOT NULL, 
    330               `start_date` datetime NOT NULL, 
    331               `end_date` datetime NOT NULL, 
    332               `magnify` int(11) NOT NULL, 
    333               `multiple` int(11) NOT NULL, 
    334               `unit` int(11) NOT NULL, 
    335               PRIMARY KEY  (`id`) 
    336             );"; 
    337  
    338         require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
    339         dbDelta($sql); 
    340    } 
    341 } 
    342  
    343 /* --------------------------------------------------------------------------------- 
    344  * install table for Highlight decorators 
    345  * --------------------------------------------------------------------------------*/ 
    346 function stl_timeline_add_decorators_table(){ 
    347          
    348     global $wpdb; 
    349  
    350     $decorator_object = new WPSimileTimelineDecorator(); 
    351     $table_name = $wpdb->prefix . $decorator_object->table_name; 
    352     if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { 
    353  
    354         $sql = "CREATE TABLE " . $table_name . " ( 
    355               `id` int(11) NOT NULL auto_increment, 
    356               `name` varchar(210) NOT NULL, 
    357               `stl_timeline_band_id` int(11) NOT NULL, 
    358               `type` int(11) NOT NULL, 
    359               `start_date` datetime NOT NULL, 
    360               `end_date` datetime NOT NULL, 
    361               `start_label` varchar(50) NOT NULL, 
    362               `end_label` varchar(50) NOT NULL, 
    363               `color` varchar(7) NOT NULL, 
    364               `css_class` varchar(50) NOT NULL, 
    365               `opacity` int(11) NOT NULL, 
    366               PRIMARY KEY  (`id`) 
    367             );"; 
    368  
    369         require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
    370         dbDelta($sql); 
    371    } 
    372 } 
    373  
    374 /* --------------------------------------------------------------------------------- 
    375  * Save the category active attribute into database 
    376  * --------------------------------------------------------------------------------*/ 
    377 function stl_timeline_update_catactive($cID, $status){ 
    378     global $wpdb; 
    379     //extract($_POST); 
    380     $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->prefix."stl_timeline_terms SET active = '$status' WHERE term_id = $cID")); 
    381 } 
    382  
    383 /* --------------------------------------------------------------------------------- 
    384  * Save the category color into database 
    385  * --------------------------------------------------------------------------------*/ 
    386 function stl_timeline_update_catcolor($cID, $color){ 
    387     global $wpdb; 
    388     //extract($_POST); 
    389     // TODO: Escape query with $wpdb->escape or $wpdb->prepare (messes up color value with #!) 
    390     $wpdb->query("UPDATE ".$wpdb->prefix."stl_timeline_terms SET color = '$color' WHERE term_id = $cID"); 
    391 } 
    392  
    393 /* --------------------------------------------------------------------------------- 
    394  * checks if a given column exists in a database table 
    395  * --------------------------------------------------------------------------------*/ 
    396 function stl_timeline_column_exists($col_name){ 
    397     global $wpdb; 
    398     $column_exists = false; 
    399     $q = $wpdb->query($wpdb->prepare("SHOW COLUMNS FROM $wpdb->posts LIKE '$col_name'")); 
    400     if($q == 1){ 
    401         $column_exists = true; 
    402     } 
    403     return $column_exists; 
    404 } 
    405161?> 
Note: See TracChangeset for help on using the changeset viewer.