| [ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 function commentsToPreorderTreeHelper(&$tP, $left, $indent = 0) 4 { 5 global $_TABLES; 6 7 // start with the right terminal value = left terminal value + 1 8 $right = $left + 1; 9 10 //foreach child (if any) run the recursive function 11 if ( isset( $tP['children'] )) 12 { 13 while( list( $k, $A ) = each( $tP['children'] ) ) 14 { 15 //DEBUG: print("calling recurisive($k, $right)\n"); 16 $right = commentsToPreorderTreeHelper($A, $right, $indent + 1); 17 $right++; 18 } 19 } 20 21 //Update the comment, set lft = $left and rht = return value + 1 22 $q = "UPDATE {$_TABLES['comments']} SET lft = $left, rht = $right, " 23 . "indent = $indent WHERE cid = " . $tP['cid']; 24 DB_query($q); 25 26 //DEBUG: print $q."<br>"; 27 28 //return right 29 return $right; 30 } 31 32 function commentsToPreorderTree() 33 { 34 global $_TABLES; 35 36 // Get all the unique sid's from the database 37 $q = "SELECT sid FROM {$_TABLES['comments']} group by sid"; 38 $result = DB_query($q); 39 40 // Loop through every sid supplementing comments with new rows 41 // 'lft', 'rht', and 'indent' 42 while ( $A = DB_fetchArray($result) ) 43 { 44 // build a tree 45 $aP = array(); 46 $tP = array(); 47 48 // grab comments associated with the current 'sid' 49 $qC = "SELECT cid,pid FROM {$_TABLES['comments']} " 50 . "WHERE sid = '{$A['sid']}' ORDER BY cid ASC"; 51 $rC = DB_query( $qC ); 52 53 // put the comments in a usefull array 54 while ( $dC = DB_fetchArray( $rC ) ) 55 { 56 if ( $dC['pid'] == 0 ) 57 { 58 // Root comment 59 $tP[$dC['cid']] = $dC; 60 $aP[$dC['cid']] =& $tP[$dC['cid']]; 61 } 62 else 63 { 64 // Child comment 65 $aP[$dC['pid']]['children'][$dC['cid']] = $dC; 66 $aP[$dC['cid']] =& $aP[$dC['pid']]['children'][$dC['cid']]; 67 } 68 } 69 70 unset ($aP); 71 72 // initialize left terminal value, this starts with 1 for every 73 // set of comments associated with a 'sid' 74 $left = 1; 75 76 // Foreach toplevel comment run the recursive funtion 77 while( list( $k, $B ) = each( $tP ) ) 78 { 79 //DEBUG: print("calling recurisive({$B['cid']}, $left)\n"); 80 $left = commentsToPreorderTreeHelper($B, $left); 81 $left++; 82 } 83 84 /* Print results to error log for DEBUGing 85 * $left = ($left-1)/2; 86 * COM_errorLog("$left comments in story {$A['sid']} converted"); 87 */ 88 } 89 } 90 91 92 // Note: this is the exact same function as STORY_extractLinks 93 function UPDATE_extractLinks( $fulltext, $maxlength = 26 ) 94 { 95 $rel = array(); 96 97 /* Only match anchor tags that contain 'href="<something>"' 98 */ 99 preg_match_all( "/<a[^>]*href=[\"']([^\"']*)[\"'][^>]*>(.*?)<\/a>/i", $fulltext, $matches ); 100 for ( $i=0; $i< count( $matches[0] ); $i++ ) 101 { 102 $matches[2][$i] = strip_tags( $matches[2][$i] ); 103 if ( !strlen( trim( $matches[2][$i] ) ) ) { 104 $matches[2][$i] = strip_tags( $matches[1][$i] ); 105 } 106 107 // if link is too long, shorten it and add ... at the end 108 if ( ( $maxlength > 0 ) && ( strlen( $matches[2][$i] ) > $maxlength ) ) 109 { 110 $matches[2][$i] = substr( $matches[2][$i], 0, $maxlength - 3 ) . '...'; 111 } 112 113 $rel[] = '<a href="' . $matches[1][$i] . '">' 114 . str_replace ("/(\015\012)|(\015)|(\012)/", '', $matches[2][$i]) 115 . '</a>'; 116 } 117 118 return( $rel ); 119 } 120 121 122 // modify the comments table to speed things up 123 $_SQL[] = "ALTER TABLE {$_TABLES['comments']} ADD lft mediumint(10) unsigned NOT NULL default '0' AFTER pid"; 124 $_SQL[] = "ALTER TABLE {$_TABLES['comments']} ADD rht mediumint(10) unsigned NOT NULL default '0' AFTER lft"; 125 $_SQL[] = "ALTER TABLE {$_TABLES['comments']} ADD indent mediumint(10) unsigned NOT NULL default '0' AFTER rht"; 126 $_SQL[] = "ALTER TABLE {$_TABLES['comments']} ADD ipaddress varchar(15) NOT NULL default '' AFTER uid"; 127 $_SQL[] = "ALTER TABLE {$_TABLES['comments']} ADD INDEX comments_lft(lft)"; 128 $_SQL[] = "ALTER TABLE {$_TABLES['comments']} ADD INDEX comments_rht(rht)"; 129 130 // make sure the older_stories block is of type "gldefault" 131 $_SQL[] = "UPDATE {$_TABLES['blocks']} SET type = 'gldefault' WHERE name = 'older_stories'"; 132 133 // remove obsolete "layout" blocks from _very_ old databases ... 134 $_SQL[] = "DELETE FROM {$_TABLES['blocks']} WHERE type = 'layout'"; 135 136 // add an index on the 'topic' field of the syndication table 137 $_SQL[] = "ALTER TABLE {$_TABLES['syndication']} ADD INDEX syndication_topic(topic)"; 138 139 // make sure old links have a proper owner (user "anonymous") 140 $_SQL[] = "UPDATE {$_TABLES['links']} SET owner_id = 1 WHERE owner_id = 0"; 141 142 // Add new fields for Story Archive feature 143 $_SQL[] = "ALTER TABLE {$_TABLES['stories']} ADD expire DATETIME NOT NULL AFTER statuscode"; 144 $_SQL[] = "ALTER TABLE {$_TABLES['topics']} ADD archive_flag tinyint(1) unsigned NOT NULL DEFAULT '0' AFTER is_default"; 145 146 // add index for 'onleft' and 'name' to speed up themes with different left and right block templates 147 $_SQL[] = "ALTER TABLE {$_TABLES['blocks']} ADD INDEX blocks_onleft(onleft)"; 148 $_SQL[] = "ALTER TABLE {$_TABLES['blocks']} ADD INDEX blocks_name(name)"; 149 150 // remove unused entry (moved to 'syndication' table) 151 // (this is obsolete since 1.3.9 but was still present in fresh 1.3.9 installs) 152 $_SQL[] = "DELETE FROM {$_TABLES['vars']} WHERE name = 'rdf_sids'"; 153 154 // add index on the 'statuscode' and 'expire' fields of the stories table 155 $_SQL[] = "ALTER TABLE {$_TABLES['stories']} ADD INDEX stories_statuscode(statuscode)"; 156 $_SQL[] = "ALTER TABLE {$_TABLES['stories']} ADD INDEX stories_expire(expire)"; 157 158 // extend max. length of static page IDs to 40 characters (again) 159 // (fresh installs of 1.3.9 were still using 20 characters) 160 $_SQL[] = "ALTER TABLE {$_TABLES['staticpage']} CHANGE sp_id sp_id varchar(40) NOT NULL"; 161 162 // allow up to 40 characters for the story IDs, as they are editable now 163 $_SQL[] = "ALTER TABLE {$_TABLES['stories']} CHANGE sid sid varchar(40) NOT NULL"; 164 $_SQL[] = "ALTER TABLE {$_TABLES['article_images']} CHANGE ai_sid ai_sid varchar(40) NOT NULL"; 165 166 // Add new location fields to the userinfo table 167 $_SQL[] = "ALTER TABLE {$_TABLES['userinfo']} ADD location VARCHAR(96) NOT NULL AFTER about"; 168 169 /** 170 * Install SpamX plugin (also handled updates from version 1.0) 171 * 172 */ 173 function install_spamx_plugin () 174 { 175 global $_TABLES; 176 177 $_SPX_TABLE = "CREATE TABLE {$_TABLES['spamx']} (" 178 . " name varchar(20) NOT NULL default ''," 179 . " value varchar(255) NOT NULL default ''," 180 . " INDEX spamx_name (name)" 181 . ") TYPE=MyISAM"; 182 183 // SpamX plugin information, 'spamx.admin' feature, SpamX Admin group 184 $_SPX_PLUGIN = "INSERT INTO {$_TABLES['plugins']} (pi_name, pi_version, pi_gl_version, pi_enabled, pi_homepage) VALUES ('spamx', '1.0.1','1.3.10',1,'http://www.pigstye.net/gplugs/staticpages/index.php/spamx') "; 185 $_SPX_FEAT = "INSERT INTO {$_TABLES['features']} (ft_name, ft_descr, ft_gl_core) VALUES ('spamx.admin', 'spamx Admin', 0) "; 186 $_SPX_ADMIN = "INSERT INTO {$_TABLES['groups']} (grp_name, grp_descr, grp_gl_core) VALUES ('spamx Admin', 'Users in this group can administer the spamx plugin',0) "; 187 188 $group_id = DB_getItem ($_TABLES['groups'], 'grp_id', 189 "grp_name = 'spamx Admin'"); 190 if ($group_id <= 0) { 191 DB_query ($_SPX_ADMIN); // add SpamX Admin group 192 $group_id = DB_insertId (); 193 } 194 $feat_id = DB_getItem ($_TABLES['features'], 'ft_id', 195 "ft_name = 'spamx.admin'"); 196 if ($feat_id <= 0) { 197 DB_query ($_SPX_FEAT); // add 'spamx.admin' feature 198 $feat_id = DB_insertId (); 199 } 200 if (DB_getItem ($_TABLES['access'], 'acc_grp_id', "acc_ft_id = $feat_id") 201 != $group_id) { 202 // add feature to spamx admin group 203 DB_query ("INSERT INTO {$_TABLES['access']} (acc_ft_id, acc_grp_id) VALUES ($feat_id, $group_id)"); 204 } 205 if (DB_getItem ($_TABLES['group_assignments'], 'ug_main_grp_id', "ug_uid = NULL AND ug_grp_id = 1") != $group_id) { 206 // make Root group a member of the SpamX Admin group 207 DB_query ("INSERT INTO {$_TABLES['group_assignments']} VALUES ($group_id, NULL, 1)"); 208 } 209 210 $spxversion = get_SPX_Ver (); 211 if (($spxversion == 0) || ($spxversion == 1)) { 212 // delete plugin entry so that we can update it below 213 DB_delete ($_TABLES['plugins'], 'pi_name', 'spamx'); 214 215 // create 'spamx' table 216 DB_query ($_SPX_TABLE); 217 218 DB_query ($_SPX_PLUGIN); // add entry to 'plugins' table 219 } 220 221 return true; 222 } 223 224 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
|