[10] | 1 | <?php |
---|
| 2 | /*************************************************************************** |
---|
| 3 | * update.php * |
---|
| 4 | * ------------------ * |
---|
[57] | 5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
| 6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
[10] | 7 | * * |
---|
[57] | 8 | * $Id: update.php 272 2004-01-11 00:05:10Z z0rglub $ |
---|
| 9 | * * |
---|
[10] | 10 | ***************************************************************************/ |
---|
| 11 | |
---|
| 12 | /*************************************************************************** |
---|
| 13 | * * |
---|
| 14 | * This program is free software; you can redistribute it and/or modify * |
---|
| 15 | * it under the terms of the GNU General Public License as published by * |
---|
| 16 | * the Free Software Foundation; * |
---|
| 17 | * * |
---|
| 18 | ***************************************************************************/ |
---|
| 19 | |
---|
| 20 | include_once( './include/isadmin.inc.php' ); |
---|
| 21 | //------------------------------------------------------------------- functions |
---|
[269] | 22 | function insert_local_category( $id_uppercat ) |
---|
[10] | 23 | { |
---|
[88] | 24 | global $conf, $page, $user, $lang; |
---|
[269] | 25 | |
---|
[259] | 26 | $uppercats = ''; |
---|
[10] | 27 | |
---|
| 28 | // 0. retrieving informations on the category to display |
---|
| 29 | $cat_directory = '../galleries'; |
---|
| 30 | |
---|
[269] | 31 | if ( is_numeric( $id_uppercat ) ) |
---|
[10] | 32 | { |
---|
[269] | 33 | $query = 'SELECT name,uppercats,dir'; |
---|
| 34 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
| 35 | $query.= ' WHERE id = '.$id_uppercat; |
---|
| 36 | $query.= ';'; |
---|
| 37 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
| 38 | $uppercats = $row['uppercats']; |
---|
| 39 | $name = $row['name']; |
---|
| 40 | $dir = $row['dir']; |
---|
| 41 | |
---|
| 42 | $upper_array = explode( ',', $uppercats ); |
---|
| 43 | |
---|
| 44 | $local_dir = ''; |
---|
| 45 | |
---|
| 46 | $database_dirs = array(); |
---|
| 47 | $query = 'SELECT id,dir'; |
---|
| 48 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
| 49 | $query.= ' WHERE id IN ('.$uppercats.')'; |
---|
| 50 | $query.= ';'; |
---|
| 51 | $result = mysql_query( $query ); |
---|
| 52 | while( $row = mysql_fetch_array( $result ) ) |
---|
| 53 | { |
---|
| 54 | $database_dirs[$row['id']] = $row['dir']; |
---|
| 55 | } |
---|
| 56 | foreach ( $upper_array as $id ) { |
---|
| 57 | $local_dir.= $database_dirs[$id].'/'; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | $cat_directory.= '/'.$local_dir; |
---|
| 61 | |
---|
[10] | 62 | // 1. display the category name to update |
---|
[29] | 63 | $src = '../template/'.$user['template'].'/admin/images/puce.gif'; |
---|
| 64 | $output = '<img src="'.$src.'" alt=">" />'; |
---|
[269] | 65 | $output.= '<span style="font-weight:bold;">'.$name.'</span>'; |
---|
| 66 | $output.= ' [ '.$dir.' ]'; |
---|
[10] | 67 | $output.= '<div class="retrait">'; |
---|
[61] | 68 | |
---|
[10] | 69 | // 2. we search pictures of the category only if the update is for all |
---|
| 70 | // or a cat_id is specified |
---|
| 71 | if ( isset( $page['cat'] ) or $_GET['update'] == 'all' ) |
---|
| 72 | { |
---|
[269] | 73 | $output.= insert_local_image( $cat_directory, $id_uppercat ); |
---|
[10] | 74 | } |
---|
| 75 | } |
---|
[61] | 76 | |
---|
[269] | 77 | $sub_dirs = get_category_directories( $cat_directory ); |
---|
| 78 | |
---|
| 79 | $sub_category_dirs = array(); |
---|
| 80 | $query = 'SELECT id,dir'; |
---|
[10] | 81 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
[259] | 82 | $query.= ' WHERE site_id = 1'; |
---|
[269] | 83 | if (!is_numeric($id_uppercat)) $query.= ' AND id_uppercat IS NULL'; |
---|
| 84 | else $query.= ' AND id_uppercat = '.$id_uppercat; |
---|
| 85 | $query.= ' AND dir IS NOT NULL'; // virtual categories not taken |
---|
[10] | 86 | $query.= ';'; |
---|
| 87 | $result = mysql_query( $query ); |
---|
| 88 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 89 | { |
---|
[269] | 90 | $id = intval($row['id']); |
---|
| 91 | $sub_category_dirs[$id] = $row['dir']; |
---|
[10] | 92 | } |
---|
[269] | 93 | |
---|
| 94 | // 3. we have to remove the categories of the database not present anymore |
---|
| 95 | foreach ( $sub_category_dirs as $id => $dir ) { |
---|
| 96 | if ( !in_array( $dir, $sub_dirs ) ) delete_category( $id ); |
---|
[10] | 97 | } |
---|
[269] | 98 | |
---|
[272] | 99 | // array of new categories to insert |
---|
| 100 | $inserts = array(); |
---|
| 101 | |
---|
[269] | 102 | foreach ( $sub_dirs as $sub_dir ) { |
---|
[10] | 103 | // 5. Is the category already existing ? we create a subcat if not |
---|
| 104 | // existing |
---|
[269] | 105 | $category_id = array_search( $sub_dir, $sub_category_dirs ); |
---|
| 106 | if ( !is_numeric( $category_id ) ) |
---|
[10] | 107 | { |
---|
[269] | 108 | if ( preg_match( '/^[a-zA-Z0-9-_.]+$/', $sub_dir ) ) |
---|
| 109 | { |
---|
[272] | 110 | $value = ''; |
---|
[269] | 111 | $name = str_replace( '_', ' ', $sub_dir ); |
---|
[272] | 112 | |
---|
| 113 | $value.= "('".$sub_dir."','".$name."',1"; |
---|
| 114 | if ( !is_numeric( $id_uppercat ) ) $value.= ',NULL'; |
---|
| 115 | else $value.= ','.$id_uppercat; |
---|
| 116 | $value.= ",'undef'"; |
---|
| 117 | $value.= ')'; |
---|
| 118 | array_push( $inserts, $value ); |
---|
[269] | 119 | } |
---|
| 120 | else |
---|
| 121 | { |
---|
| 122 | $output.= '<span style="color:red;">"'.$sub_dir.'" : '; |
---|
| 123 | $output.= $lang['update_wrong_dirname'].'</span><br />'; |
---|
| 124 | } |
---|
[10] | 125 | } |
---|
| 126 | } |
---|
[272] | 127 | |
---|
| 128 | // we have to create the category |
---|
| 129 | if ( count( $inserts ) > 0 ) |
---|
| 130 | { |
---|
| 131 | $query = 'INSERT INTO '.PREFIX_TABLE.'categories'; |
---|
| 132 | $query.= ' (dir,name,site_id,id_uppercat,uppercats) VALUES '; |
---|
| 133 | $query.= implode( ',', $inserts ); |
---|
| 134 | $query.= ';'; |
---|
| 135 | mysql_query( $query ); |
---|
| 136 | // updating uppercats field |
---|
| 137 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
| 138 | $query.= ' SET uppercats = '; |
---|
| 139 | if ( $uppercats != '' ) $query.= "CONCAT('".$uppercats."',',',id)"; |
---|
| 140 | else $query.= 'id'; |
---|
| 141 | $query.= ' WHERE id_uppercat '; |
---|
| 142 | if (!is_numeric($id_uppercat)) $query.= 'IS NULL'; |
---|
| 143 | else $query.= '= '.$id_uppercat; |
---|
| 144 | $query.= ';'; |
---|
| 145 | mysql_query( $query ); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | // Recursive call on the sub-categories (not virtual ones) |
---|
| 149 | $query = 'SELECT id'; |
---|
| 150 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
| 151 | $query.= ' WHERE site_id = 1'; |
---|
| 152 | if (!is_numeric($id_uppercat)) $query.= ' AND id_uppercat IS NULL'; |
---|
| 153 | else $query.= ' AND id_uppercat = '.$id_uppercat; |
---|
| 154 | $query.= ' AND dir IS NOT NULL'; // virtual categories not taken |
---|
| 155 | $query.= ';'; |
---|
| 156 | $result = mysql_query( $query ); |
---|
| 157 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 158 | { |
---|
| 159 | $output.= insert_local_category( $row['id'] ); |
---|
| 160 | } |
---|
| 161 | |
---|
[269] | 162 | if ( is_numeric( $id_uppercat ) ) |
---|
[10] | 163 | { |
---|
| 164 | $output.= '</div>'; |
---|
| 165 | } |
---|
| 166 | return $output; |
---|
| 167 | } |
---|
[259] | 168 | |
---|
[10] | 169 | function insert_local_image( $rep, $category_id ) |
---|
| 170 | { |
---|
| 171 | global $lang,$conf,$count_new; |
---|
| 172 | |
---|
| 173 | $output = ''; |
---|
| 174 | // we have to delete all the images from the database that : |
---|
| 175 | // - are not in the directory anymore |
---|
| 176 | // - don't have the associated thumbnail available anymore |
---|
| 177 | $query = 'SELECT id,file,tn_ext'; |
---|
| 178 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
[61] | 179 | $query.= ' WHERE storage_category_id = '.$category_id; |
---|
[10] | 180 | $query.= ';'; |
---|
| 181 | $result = mysql_query( $query ); |
---|
| 182 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 183 | { |
---|
| 184 | $lien_image = $rep.'/'.$row['file']; |
---|
[19] | 185 | $lien_thumbnail = $rep.'/thumbnail/'.$conf['prefix_thumbnail']; |
---|
[10] | 186 | $lien_thumbnail.= get_filename_wo_extension( $row['file'] ); |
---|
| 187 | $lien_thumbnail.= '.'.$row['tn_ext']; |
---|
| 188 | |
---|
| 189 | if ( !is_file ( $lien_image ) or !is_file ( $lien_thumbnail ) ) |
---|
| 190 | { |
---|
| 191 | if ( !is_file ( $lien_image ) ) |
---|
| 192 | { |
---|
| 193 | $output.= $row['file']; |
---|
| 194 | $output.= ' <span style="font-weight:bold;">'; |
---|
| 195 | $output.= $lang['update_disappeared'].'</span><br />'; |
---|
| 196 | } |
---|
| 197 | if ( !is_file ( $lien_thumbnail ) ) |
---|
| 198 | { |
---|
| 199 | $output.= $row['file']; |
---|
| 200 | $output.= ' : <span style="font-weight:bold;">'; |
---|
| 201 | $output.= $lang['update_disappeared_tn'].'</span><br />'; |
---|
| 202 | } |
---|
| 203 | // suppression de la base : |
---|
| 204 | delete_image( $row['id'] ); |
---|
| 205 | } |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | // searching the new images in the directory |
---|
| 209 | $pictures = array(); |
---|
| 210 | $tn_ext = ''; |
---|
[26] | 211 | if ( $opendir = opendir( $rep ) ) |
---|
[10] | 212 | { |
---|
[26] | 213 | while ( $file = readdir( $opendir ) ) |
---|
[10] | 214 | { |
---|
| 215 | if ( is_file( $rep.'/'.$file ) and is_image( $rep.'/'.$file ) ) |
---|
| 216 | { |
---|
| 217 | // is the picture waiting for validation by an administrator ? |
---|
[26] | 218 | $query = 'SELECT id,validated,infos'; |
---|
[10] | 219 | $query.= ' FROM '.PREFIX_TABLE.'waiting'; |
---|
[81] | 220 | $query.= ' WHERE storage_category_id = '.$category_id; |
---|
[10] | 221 | $query.= " AND file = '".$file."'"; |
---|
| 222 | $query.= ';'; |
---|
| 223 | $result = mysql_query( $query ); |
---|
[26] | 224 | $waiting = mysql_fetch_array( $result ); |
---|
| 225 | if (mysql_num_rows( $result ) == 0 or $waiting['validated'] == 'true') |
---|
[10] | 226 | { |
---|
| 227 | if ( $tn_ext = TN_exists( $rep, $file ) ) |
---|
| 228 | { |
---|
| 229 | // is the picture already in the database ? |
---|
| 230 | $query = 'SELECT id'; |
---|
| 231 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
[61] | 232 | $query.= ' WHERE storage_category_id = '.$category_id; |
---|
[10] | 233 | $query.= " AND file = '".$file."'"; |
---|
| 234 | $query.= ';'; |
---|
| 235 | $result = mysql_query( $query ); |
---|
| 236 | if ( mysql_num_rows( $result ) == 0 ) |
---|
| 237 | { |
---|
[160] | 238 | // the name of the file must not use acentuated characters or |
---|
| 239 | // blank space.. |
---|
| 240 | if ( preg_match( '/^[a-zA-Z0-9-_.]+$/', $file ) ) |
---|
[26] | 241 | { |
---|
[160] | 242 | $picture = array(); |
---|
| 243 | $picture['file'] = $file; |
---|
| 244 | $picture['tn_ext'] = $tn_ext; |
---|
| 245 | $picture['date'] = date( 'Y-m-d', filemtime($rep.'/'.$file) ); |
---|
| 246 | $picture['filesize'] = floor( filesize($rep.'/'.$file) / 1024); |
---|
| 247 | $image_size = @getimagesize( $rep.'/'.$file ); |
---|
| 248 | $picture['width'] = $image_size[0]; |
---|
| 249 | $picture['height'] = $image_size[1]; |
---|
| 250 | if ( $waiting['validated'] == 'true' ) |
---|
[26] | 251 | { |
---|
[160] | 252 | // retrieving infos from the XML description of |
---|
| 253 | // $waiting['infos'] |
---|
| 254 | $infos = nl2br( $waiting['infos'] ); |
---|
| 255 | $picture['author'] = getAttribute( $infos, 'author' ); |
---|
| 256 | $picture['comment'] = getAttribute( $infos, 'comment'); |
---|
| 257 | $unixtime = getAttribute( $infos, 'date_creation' ); |
---|
| 258 | $picture['date_creation'] = ''; |
---|
| 259 | if ( $unixtime != '' ) |
---|
| 260 | $picture['date_creation'] = date( 'Y-m-d', $unixtime ); |
---|
| 261 | $picture['name'] = getAttribute( $infos, 'name' ); |
---|
| 262 | // deleting the waiting element |
---|
| 263 | $query = 'DELETE FROM '.PREFIX_TABLE.'waiting'; |
---|
| 264 | $query.= ' WHERE id = '.$waiting['id']; |
---|
| 265 | $query.= ';'; |
---|
| 266 | mysql_query( $query ); |
---|
[26] | 267 | } |
---|
[160] | 268 | array_push( $pictures, $picture ); |
---|
[26] | 269 | } |
---|
[160] | 270 | else |
---|
| 271 | { |
---|
| 272 | $output.= '<span style="color:red;">"'.$file.'" : '; |
---|
| 273 | $output.= $lang['update_wrong_dirname'].'</span><br />'; |
---|
| 274 | } |
---|
| 275 | |
---|
[10] | 276 | } |
---|
| 277 | } |
---|
| 278 | else |
---|
| 279 | { |
---|
| 280 | $output.= '<span style="color:red;">'; |
---|
| 281 | $output.= $lang['update_missing_tn'].' : '.$file; |
---|
| 282 | $output.= ' (<span style="font-weight:bold;">'; |
---|
[19] | 283 | $output.= $conf['prefix_thumbnail']; |
---|
[10] | 284 | $output.= get_filename_wo_extension( $file ).'.XXX</span>'; |
---|
| 285 | $output.= ', XXX = '; |
---|
| 286 | $output.= implode( ', ', $conf['picture_ext'] ); |
---|
| 287 | $output.= ')</span><br />'; |
---|
| 288 | } |
---|
| 289 | } |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | // inserting the pictures found in the directory |
---|
| 294 | foreach ( $pictures as $picture ) { |
---|
| 295 | $query = 'INSERT INTO '.PREFIX_TABLE.'images'; |
---|
[61] | 296 | $query.= ' (file,storage_category_id,date_available,tn_ext'; |
---|
| 297 | $query.= ',filesize,width,height'; |
---|
[26] | 298 | $query.= ',name,author,comment,date_creation)'; |
---|
[10] | 299 | $query.= ' VALUES '; |
---|
| 300 | $query.= "('".$picture['file']."','".$category_id."'"; |
---|
| 301 | $query.= ",'".$picture['date']."','".$picture['tn_ext']."'"; |
---|
| 302 | $query.= ",'".$picture['filesize']."','".$picture['width']."'"; |
---|
[26] | 303 | $query.= ",'".$picture['height']."','".$picture['name']."'"; |
---|
| 304 | $query.= ",'".$picture['author']."','".$picture['comment']."'"; |
---|
| 305 | if ( $picture['date_creation'] != '' ) |
---|
| 306 | { |
---|
| 307 | $query.= ",'".$picture['date_creation']."'"; |
---|
| 308 | } |
---|
| 309 | else |
---|
| 310 | { |
---|
| 311 | $query.= ',NULL'; |
---|
| 312 | } |
---|
| 313 | $query.= ');'; |
---|
[10] | 314 | mysql_query( $query ); |
---|
| 315 | $count_new++; |
---|
[61] | 316 | // retrieving the id of newly inserted picture |
---|
| 317 | $query = 'SELECT id'; |
---|
| 318 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
| 319 | $query.= ' WHERE storage_category_id = '.$category_id; |
---|
| 320 | $query.= " AND file = '".$picture['file']."'"; |
---|
| 321 | $query.= ';'; |
---|
| 322 | list( $image_id ) = mysql_fetch_array( mysql_query( $query ) ); |
---|
| 323 | // adding the link between this picture and its storage category |
---|
| 324 | $query = 'INSERT INTO '.PREFIX_TABLE.'image_category'; |
---|
| 325 | $query.= ' (image_id,category_id) VALUES '; |
---|
| 326 | $query.= ' ('.$image_id.','.$category_id.')'; |
---|
| 327 | $query.= ';'; |
---|
| 328 | mysql_query( $query ); |
---|
| 329 | |
---|
[10] | 330 | $output.= $picture['file']; |
---|
| 331 | $output.= ' <span style="font-weight:bold;">'; |
---|
| 332 | $output.= $lang['update_research_added'].'</span>'; |
---|
| 333 | $output.= ' ('.$lang['update_research_tn_ext'].' '.$picture['tn_ext'].')'; |
---|
| 334 | $output.= '<br />'; |
---|
| 335 | } |
---|
| 336 | return $output; |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | // remote_images verifies if a file named "listing.xml" is present is the |
---|
| 340 | // admin directory. If it is the case, creation of a remote picture storage |
---|
| 341 | // site if it doesn't already exists. Then, the function calls |
---|
| 342 | // insert_remote_category for this remote site on the root category. |
---|
| 343 | function remote_images() |
---|
| 344 | { |
---|
| 345 | global $conf, $lang, $vtp, $sub; |
---|
| 346 | |
---|
| 347 | // 1. is there a file listing.xml ? |
---|
| 348 | if ( !( $xml_content = getXmlCode( 'listing.xml' ) ) ) |
---|
| 349 | { |
---|
| 350 | return false; |
---|
| 351 | } |
---|
| 352 | $url = getContent( getChild( $xml_content, 'url' ) ); |
---|
| 353 | $vtp->setVar( $sub, 'remote_update.url', $url ); |
---|
| 354 | |
---|
| 355 | // 2. is the site already existing ? |
---|
[61] | 356 | $query = 'SELECT id'; |
---|
| 357 | $query.= ' FROM '.PREFIX_TABLE.'sites'; |
---|
| 358 | $query.= " WHERE galleries_url = '".$url."'"; |
---|
[10] | 359 | $query.= ';'; |
---|
| 360 | $result = mysql_query( $query ); |
---|
| 361 | if ( mysql_num_rows($result ) == 0 ) |
---|
| 362 | { |
---|
| 363 | // we have to register this site in the database |
---|
[61] | 364 | $query = 'INSERT INTO '.PREFIX_TABLE.'sites'; |
---|
| 365 | $query.= " (galleries_url) VALUES ('".$url."')"; |
---|
[10] | 366 | $query.= ';'; |
---|
| 367 | mysql_query( $query ); |
---|
| 368 | $site_id = mysql_insert_id(); |
---|
| 369 | } |
---|
| 370 | else |
---|
| 371 | { |
---|
| 372 | // we get the already registered id |
---|
| 373 | $row = mysql_fetch_array( $result ); |
---|
| 374 | $site_id = $row['id']; |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | // 3. available dirs in the file |
---|
| 378 | $categories = insert_remote_category( $xml_content, $site_id, 'NULL', 0 ); |
---|
| 379 | $vtp->setVar( $sub, 'remote_update.categories', $categories ); |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | // insert_remote_category searchs the "dir" node of the xml_dir given and |
---|
| 383 | // insert the contained categories if the are not in the database yet. The |
---|
| 384 | // function also deletes the categories that are in the database and not in |
---|
| 385 | // the xml_file. |
---|
| 386 | function insert_remote_category( $xml_dir, $site_id, $id_uppercat, $level ) |
---|
| 387 | { |
---|
[29] | 388 | global $conf,$user; |
---|
[10] | 389 | |
---|
| 390 | $output = ''; |
---|
| 391 | $categories = array(); |
---|
| 392 | $list_dirs = getChildren( $xml_dir, 'dir'.$level ); |
---|
| 393 | for ( $i = 0; $i < sizeof( $list_dirs ); $i++ ) |
---|
| 394 | { |
---|
| 395 | // is the category already existing ? |
---|
| 396 | $category_id = ''; |
---|
[126] | 397 | $dir = getAttribute( $list_dirs[$i], 'name' ); |
---|
| 398 | $categories[$i] = $dir; |
---|
[10] | 399 | |
---|
[29] | 400 | $src = '../template/'.$user['template'].'/admin/images/puce.gif'; |
---|
| 401 | $output.= '<img src="'.$src.'" alt=">" />'; |
---|
[126] | 402 | $output.= '<span style="font-weight:bold;">'.$dir.'</span>'; |
---|
[10] | 403 | $output.= '<div class="retrait">'; |
---|
| 404 | |
---|
[61] | 405 | $query = 'SELECT id'; |
---|
| 406 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
| 407 | $query.= ' WHERE site_id = '.$site_id; |
---|
[126] | 408 | $query.= " AND dir = '".$dir."'"; |
---|
[10] | 409 | if ( $id_uppercat == 'NULL' ) |
---|
| 410 | { |
---|
[61] | 411 | $query.= ' AND id_uppercat IS NULL'; |
---|
[10] | 412 | } |
---|
| 413 | else |
---|
| 414 | { |
---|
[61] | 415 | $query.= ' AND id_uppercat = '.$id_uppercat; |
---|
[10] | 416 | } |
---|
| 417 | $query.= ';'; |
---|
| 418 | $result = mysql_query( $query ); |
---|
| 419 | if ( mysql_num_rows( $result ) == 0 ) |
---|
| 420 | { |
---|
[126] | 421 | $name = str_replace( '_', ' ', $dir ); |
---|
[10] | 422 | // we have to create the category |
---|
[61] | 423 | $query = 'INSERT INTO '.PREFIX_TABLE.'categories'; |
---|
[126] | 424 | $query.= ' (name,dir,site_id,id_uppercat) VALUES '; |
---|
| 425 | $query.= "('".$name."','".$dir."',".$site_id; |
---|
[10] | 426 | if ( !is_numeric( $id_uppercat ) ) |
---|
| 427 | { |
---|
| 428 | $query.= ',NULL'; |
---|
| 429 | } |
---|
| 430 | else |
---|
| 431 | { |
---|
| 432 | $query.= ','.$id_uppercat; |
---|
| 433 | } |
---|
| 434 | $query.= ');'; |
---|
| 435 | mysql_query( $query ); |
---|
| 436 | $category_id = mysql_insert_id(); |
---|
| 437 | } |
---|
| 438 | else |
---|
| 439 | { |
---|
| 440 | // we get the already registered id |
---|
| 441 | $row = mysql_fetch_array( $result ); |
---|
| 442 | $category_id = $row['id']; |
---|
| 443 | } |
---|
| 444 | $output.= insert_remote_image( $list_dirs[$i], $category_id ); |
---|
| 445 | $output.= insert_remote_category( $list_dirs[$i], $site_id, |
---|
| 446 | $category_id, $level+1 ); |
---|
| 447 | $output.= '</div>'; |
---|
| 448 | } |
---|
| 449 | // we have to remove the categories of the database not present in the xml |
---|
| 450 | // file (ie deleted from the picture storage server) |
---|
[61] | 451 | $query = 'SELECT dir,id'; |
---|
| 452 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
| 453 | $query.= ' WHERE site_id = '.$site_id; |
---|
[10] | 454 | if ( !is_numeric( $id_uppercat ) ) |
---|
| 455 | { |
---|
[61] | 456 | $query.= ' AND id_uppercat IS NULL'; |
---|
[10] | 457 | } |
---|
| 458 | else |
---|
| 459 | { |
---|
[61] | 460 | $query.= ' AND id_uppercat = '.$id_uppercat; |
---|
[10] | 461 | } |
---|
| 462 | $query.= ';'; |
---|
| 463 | $result = mysql_query( $query ); |
---|
| 464 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 465 | { |
---|
| 466 | // is the category in the xml file ? |
---|
| 467 | if ( !in_array( $row['dir'], $categories ) ) |
---|
| 468 | { |
---|
| 469 | delete_category( $row['id'] ); |
---|
| 470 | } |
---|
| 471 | } |
---|
| 472 | |
---|
| 473 | return $output; |
---|
| 474 | } |
---|
| 475 | |
---|
| 476 | // insert_remote_image searchs the "root" node of the xml_dir given and |
---|
| 477 | // insert the contained pictures if the are not in the database yet. |
---|
| 478 | function insert_remote_image( $xml_dir, $category_id ) |
---|
| 479 | { |
---|
| 480 | global $count_new,$lang; |
---|
| 481 | |
---|
| 482 | $output = ''; |
---|
| 483 | $root = getChild( $xml_dir, 'root' ); |
---|
| 484 | $pictures = array(); |
---|
| 485 | $xml_pictures = getChildren( $root, 'picture' ); |
---|
| 486 | for ( $j = 0; $j < sizeof( $xml_pictures ); $j++ ) |
---|
| 487 | { |
---|
| 488 | //<picture file="albatros.jpg" tn_ext="png" date="2002-04-14" |
---|
| 489 | // filesize="35" width="640" height="480" /> |
---|
| 490 | $file = getAttribute( $xml_pictures[$j], 'file' ); |
---|
| 491 | $tn_ext = getAttribute( $xml_pictures[$j], 'tn_ext' ); |
---|
| 492 | $date = getAttribute( $xml_pictures[$j], 'date' ); |
---|
| 493 | $filesize = getAttribute( $xml_pictures[$j], 'filesize' ); |
---|
| 494 | $width = getAttribute( $xml_pictures[$j], 'width' ); |
---|
| 495 | $height = getAttribute( $xml_pictures[$j], 'height' ); |
---|
| 496 | |
---|
| 497 | $pictures[$j] = $file; |
---|
| 498 | |
---|
| 499 | // is the picture already existing in the database ? |
---|
[61] | 500 | $query = 'SELECT id,tn_ext'; |
---|
| 501 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
| 502 | $query.= ' WHERE storage_category_id = '.$category_id; |
---|
| 503 | $query.= " AND file = '".$file."'"; |
---|
[10] | 504 | $query.= ';'; |
---|
| 505 | $result = mysql_query( $query ); |
---|
| 506 | $query = ''; |
---|
| 507 | if ( mysql_num_rows( $result ) == 0 ) |
---|
| 508 | { |
---|
[61] | 509 | $query = 'INSERT INTO '.PREFIX_TABLE.'images'; |
---|
| 510 | $query.= ' (file,storage_category_id,date_available,tn_ext'; |
---|
| 511 | $query.= ',filesize,width,height)'; |
---|
| 512 | $query.= ' VALUES ('; |
---|
[10] | 513 | $query.= "'".$file."'"; |
---|
| 514 | $query.= ",'".$category_id."'"; |
---|
| 515 | $query.= ",'".$date."'"; |
---|
| 516 | $query.= ",'".$tn_ext."'"; |
---|
| 517 | $query.= ",'".$filesize."'"; |
---|
| 518 | $query.= ",'".$width."'"; |
---|
| 519 | $query.= ",'".$height."'"; |
---|
| 520 | $query.= ')'; |
---|
| 521 | $query.= ';'; |
---|
[124] | 522 | mysql_query( $query ); |
---|
[61] | 523 | // retrieving the id of newly inserted picture |
---|
| 524 | $query = 'SELECT id'; |
---|
| 525 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
| 526 | $query.= ' WHERE storage_category_id = '.$category_id; |
---|
| 527 | $query.= " AND file = '".$file."'"; |
---|
| 528 | $query.= ';'; |
---|
| 529 | list( $image_id ) = mysql_fetch_array( mysql_query( $query ) ); |
---|
| 530 | // adding the link between this picture and its storage category |
---|
| 531 | $query = 'INSERT INTO '.PREFIX_TABLE.'image_category'; |
---|
| 532 | $query.= ' (image_id,category_id) VALUES '; |
---|
| 533 | $query.= ' ('.$image_id.','.$category_id.')'; |
---|
| 534 | $query.= ';'; |
---|
| 535 | mysql_query( $query ); |
---|
[10] | 536 | |
---|
| 537 | $output.= $file; |
---|
| 538 | $output.= ' <span style="font-weight:bold;">'; |
---|
| 539 | $output.= $lang['update_research_added'].'</span>'; |
---|
| 540 | $output.= ' ('.$lang['update_research_tn_ext'].' '.$tn_ext.')<br />'; |
---|
| 541 | |
---|
| 542 | $count_new++; |
---|
| 543 | } |
---|
| 544 | else |
---|
| 545 | { |
---|
| 546 | // is the tn_ext the same in the xml file and in the database ? |
---|
| 547 | $row = mysql_fetch_array( $result ); |
---|
| 548 | if ( $row['tn_ext'] != $tn_ext ) |
---|
| 549 | { |
---|
[61] | 550 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
| 551 | $query.= ' SET'; |
---|
[10] | 552 | $query.= " tn_ext = '".$tn_ext."'"; |
---|
[61] | 553 | $query.= ' WHERE storage_category_id = '.$category_id; |
---|
| 554 | $query.= " AND file = '".$file."'"; |
---|
[10] | 555 | $query.= ';'; |
---|
| 556 | } |
---|
| 557 | } |
---|
| 558 | // execution of the query |
---|
| 559 | if ( $query != '' ) |
---|
| 560 | { |
---|
| 561 | mysql_query( $query ); |
---|
| 562 | } |
---|
| 563 | } |
---|
| 564 | // we have to remove the pictures of the database not present in the xml file |
---|
| 565 | // (ie deleted from the picture storage server) |
---|
[61] | 566 | $query = 'SELECT id,file'; |
---|
| 567 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
| 568 | $query.= ' WHERE storage_category_id = '.$category_id; |
---|
[10] | 569 | $query.= ';'; |
---|
| 570 | $result = mysql_query( $query ); |
---|
| 571 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 572 | { |
---|
| 573 | // is the file in the xml file ? |
---|
| 574 | if ( !in_array( $row['file'], $pictures ) ) |
---|
| 575 | { |
---|
| 576 | delete_image( $row['id'] ); |
---|
| 577 | } |
---|
| 578 | } |
---|
| 579 | return $output; |
---|
| 580 | } |
---|
| 581 | //----------------------------------------------------- template initialization |
---|
| 582 | $sub = $vtp->Open( '../template/'.$user['template'].'/admin/update.vtp' ); |
---|
| 583 | $tpl = array( 'update_default_title', 'update_only_cat', 'update_all', |
---|
| 584 | 'update_research_conclusion', 'update_deletion_conclusion', |
---|
| 585 | 'remote_site', 'update_part_research' ); |
---|
| 586 | templatize_array( $tpl, 'lang', $sub ); |
---|
[29] | 587 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
[10] | 588 | //-------------------------------------------- introduction : choices of update |
---|
| 589 | // Display choice if "update" var is not specified |
---|
| 590 | check_cat_id( $_GET['update'] ); |
---|
| 591 | if ( !isset( $_GET['update'] ) |
---|
| 592 | and !( isset( $page['cat'] ) |
---|
| 593 | or $_GET['update'] == 'cats' |
---|
| 594 | or $_GET['update'] == 'all' ) ) |
---|
| 595 | { |
---|
| 596 | $vtp->addSession( $sub, 'introduction' ); |
---|
| 597 | // only update the categories, not the pictures. |
---|
| 598 | $url = add_session_id( './admin.php?page=update&update=cats' ); |
---|
| 599 | $vtp->setVar( $sub, 'introduction.only_cat:url', $url ); |
---|
| 600 | // update the entire tree folder |
---|
| 601 | $url = add_session_id( './admin.php?page=update&update=all' ); |
---|
| 602 | $vtp->setVar( $sub, 'introduction.all:url', $url ); |
---|
| 603 | $vtp->closeSession( $sub, 'introduction' ); |
---|
| 604 | } |
---|
| 605 | //------------------------------------------------- local update : ../galleries |
---|
| 606 | else |
---|
| 607 | { |
---|
[269] | 608 | $start = get_moment(); |
---|
[10] | 609 | $count_new = 0; |
---|
| 610 | $count_deleted = 0; |
---|
| 611 | $vtp->addSession( $sub, 'local_update' ); |
---|
| 612 | if ( isset( $page['cat'] ) ) |
---|
| 613 | { |
---|
| 614 | $categories = insert_local_category( $page['cat'] ); |
---|
| 615 | } |
---|
| 616 | else |
---|
| 617 | { |
---|
| 618 | $categories = insert_local_category( 'NULL' ); |
---|
| 619 | } |
---|
[269] | 620 | $end = get_moment(); |
---|
| 621 | echo get_elapsed_time( $start, $end ).' for update <br />'; |
---|
[10] | 622 | $vtp->setVar( $sub, 'local_update.categories', $categories ); |
---|
| 623 | $vtp->setVar( $sub, 'local_update.count_new', $count_new ); |
---|
| 624 | $vtp->setVar( $sub, 'local_update.count_deleted', $count_deleted ); |
---|
| 625 | $vtp->closeSession( $sub, 'local_update' ); |
---|
| 626 | } |
---|
| 627 | //------------------------------------------------- remote update : listing.xml |
---|
| 628 | if ( @is_file( './listing.xml' ) ) |
---|
| 629 | { |
---|
| 630 | $count_new = 0; |
---|
| 631 | $count_deleted = 0; |
---|
| 632 | $vtp->addSession( $sub, 'remote_update' ); |
---|
| 633 | |
---|
| 634 | remote_images(); |
---|
| 635 | $vtp->setVar( $sub, 'remote_update.count_new', $count_new ); |
---|
| 636 | $vtp->setVar( $sub, 'remote_update.count_deleted', $count_deleted ); |
---|
| 637 | |
---|
| 638 | $vtp->closeSession( $sub, 'remote_update' ); |
---|
| 639 | } |
---|
[130] | 640 | //---------------------------------------- update informations about categories |
---|
[259] | 641 | if ( isset( $_GET['update'] ) |
---|
| 642 | or isset( $page['cat'] ) |
---|
| 643 | or @is_file( './listing.xml' ) ) |
---|
| 644 | { |
---|
| 645 | update_category( 'all' ); |
---|
| 646 | synchronize_all_users(); |
---|
| 647 | } |
---|
[10] | 648 | //----------------------------------------------------------- sending html code |
---|
| 649 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
| 650 | ?> |
---|