Changeset 16400
- Timestamp:
- Jul 6, 2012, 4:40:28 PM (12 years ago)
- Location:
- extensions/BatchDownloader
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/BatchDownloader/admin/sets.php
r16379 r16400 1 1 <?php 2 2 if (!defined('BATCH_DOWNLOAD_PATH')) die('Hacking attempt!'); 3 4 // actions 5 if (isset($_GET['delete'])) 6 { 7 $BatchDownloader = new BatchDownloader($_GET['delete']); 8 $BatchDownloader->deleteLastArchive(); 9 $BatchDownloader->clearImages(); 10 pwg_query('DELETE FROM '.BATCH_DOWNLOAD_TSETS.' WHERE id = '.$_GET['delete'].';'); 11 } 12 if (isset($_GET['cancel'])) 13 { 14 $BatchDownloader = new BatchDownloader($_GET['cancel']); 15 $BatchDownloader->deleteLastArchive(); 16 $BatchDownloader->clearImages(); 17 $BatchDownloader->updateParam('status', 'done'); 18 } 19 20 21 // filter 22 $where_clauses = array('1=1'); 23 $order_by = 'date_creation DESC, status DESC'; 24 25 if (isset($_POST['filter'])) 26 { 27 if (!empty($_POST['username'])) 28 { 29 array_push($where_clauses, 'username LIKE "%'.$_POST['username'].'%"'); 30 } 31 32 if ($_POST['type'] != -1) 33 { 34 array_push($where_clauses, 'type = "'.$_POST['type'].'"'); 35 } 36 37 if ($_POST['status'] != -1) 38 { 39 array_push($where_clauses, 'status = "'.$_POST['status'].'"'); 40 } 41 42 $order_by = $_POST['order_by'].' '.$_POST['direction']; 43 } 44 45 46 // get sets 47 $query = ' 48 SELECT 49 s.id, 50 u.'.$conf['user_fields']['username'].' AS username 51 FROM '.BATCH_DOWNLOAD_TSETS.' AS s 52 INNER JOIN '.USERS_TABLE.' AS u 53 ON s.user_id = u.'.$conf['user_fields']['id'].' 54 WHERE 55 '.implode("\n AND ", $where_clauses).' 56 ORDER BY '.$order_by.' 57 ;'; 58 $sets = simple_hash_from_query($query, 'id', 'username'); 59 60 foreach ($sets as $set_id => $username) 61 { 62 $set = new BatchDownloader($set_id); 63 $template->append('sets', array_merge( 64 $set->getSetInfo(), 65 array( 66 'USERNAME' => $username, 67 'STATUS' => $set->getParam('status'), 68 'LAST_ZIP' => $set->getParam('last_zip'), 69 'U_DELETE' => BATCH_DOWNLOAD_ADMIN . '-sets&delete='.$set->getParam('set_id'), 70 'U_CANCEL' => BATCH_DOWNLOAD_ADMIN . '-sets&cancel='.$set->getParam('set_id'), 71 ) 72 )); 73 } 74 75 76 // filter options 77 $page['status_items'] = array( 78 -1 => '------------', 79 'new' => l10n('new'), 80 'download' => l10n('download'), 81 'done' => l10n('done'), 82 ); 83 84 $page['type_items'] = array( 85 -1 => '------------', 86 'calendar' => l10n('Calendar'), 87 'category' => l10n('Album'), 88 'flat' => l10n('Whole gallery'), 89 'tags' => l10n('Tags'), 90 'search' => l10n('Search'), 91 'favorites' => l10n('Favorites'), 92 'most_visited' => l10n('Most visited'), 93 'best_rated' => l10n('Best rated'), 94 'list' => l10n('Random'), 95 'recent_pics' => l10n('Recent photos'), 96 // 'selection' => l10n('Selection'), 97 ); 98 99 $page['order_by_items'] = array( 100 'date_creation' => l10n('Creation date'), 101 'total_size' => l10n('Total size'), 102 'nb_images' => l10n('Nb images'), 103 'nb_archives' => l10n('Nb archives'), 104 ); 105 106 $page['direction_items'] = array( 107 'DESC' => l10n('descending'), 108 'ASC' => l10n('ascending'), 109 ); 110 111 $template->assign('status_options', $page['status_items']); 112 $template->assign('status_selected', 113 isset($_POST['status']) ? $_POST['status'] : ''); 114 115 $template->assign('type_options', $page['type_items']); 116 $template->assign('type_selected', 117 isset($_POST['type']) ? $_POST['type'] : ''); 118 119 $template->assign('order_options', $page['order_by_items']); 120 $template->assign('order_selected', 121 isset($_POST['order_by']) ? $_POST['order_by'] : ''); 122 123 $template->assign('direction_options', $page['direction_items']); 124 $template->assign('direction_selected', 125 isset($_POST['direction']) ? $_POST['direction'] : ''); 126 127 128 $template->assign(array( 129 'F_USERNAME' => @htmlentities($_POST['username'], ENT_COMPAT, 'UTF-8'), 130 'F_FILTER_ACTION' => BATCH_DOWNLOAD_ADMIN . '-sets', 131 )); 3 132 4 133 -
extensions/BatchDownloader/admin/template/sets.tpl
r16392 r16400 5 5 </div> 6 6 7 <form method="post" action="" class="properties">7 <form class="filter" method="post" name="filter" action="{$F_FILTER_ACTION}"> 8 8 <fieldset> 9 <legend>{'TODO'|@translate}</legend> 9 <legend>{'Filter'|@translate}</legend> 10 <input type="hidden" name="page" value="user_list"> 11 12 <label>{'Username'|@translate} <input type="text" name="username" value="{$F_USERNAME}"></label> 13 14 <label> 15 {'Set type'|@translate} 16 {html_options name=type options=$type_options selected=$type_selected} 17 </label> 10 18 19 <label> 20 {'Status'|@translate} 21 {html_options name=status options=$status_options selected=$status_selected} 22 </label> 23 24 <label> 25 {'Sort by'|@translate} 26 {html_options name=order_by options=$order_options selected=$order_selected} 27 </label> 28 29 <label> 30 {'Sort order'|@translate} 31 {html_options name=direction options=$direction_options selected=$direction_selected} 32 </label> 33 34 <label> 35 36 <span><input class="submit" type="submit" name="filter" value="{'Submit'|@translate}"> <a href="{$F_FILTER_ACTION}">{'Reset'|@translate}</a></span> 37 </label> 38 11 39 </fieldset> 40 12 41 </form> 42 43 <table class="table2" width="97%"> 44 <thead> 45 <tr class="throw"> 46 <td class="user">{'Username'|@translate}</td> 47 <td class="type">{'Set type'|@translate}</td> 48 <td class="date">{'Creation date'|@translate}</td> 49 <td class="size">{'Total size'|@translate}</td> 50 <td class="images">{'Nb images'|@translate}</td> 51 <td class="archives">{'Nb archives'|@translate}</td> 52 <td class="status">{'Status'|@translate}</td> 53 <td class="action">{'Actions'|@translate}</td> 54 </tr> 55 </thead> 56 57 {foreach from=$sets item=set name=sets_loop} 58 <tr class="{if $smarty.foreach.sets_loop.index is odd}row1{else}row2{/if}"> 59 <td>{$set.USERNAME}</td> 60 <td>{$set.NAME}</td> 61 <td style="text-align:center;">{$set.DATE_CREATION}</td> 62 <td>{$set.TOTAL_SIZE} MB</td> 63 <td>{$set.NB_IMAGES}</td> 64 <td>{$set.NB_ARCHIVES}</td> 65 <td> 66 {$set.STATUS} 67 {if $set.STATUS == 'download'}({$set.LAST_ZIP}/{$set.NB_ARCHIVES}){/if} 68 </td> 69 <td style="padding-left:25px;"> 70 <a href="{$set.U_DELETE}" title="{'Delete this set'|@translate}" onClick="return confirm('{'Are your sure?'|@translate}');"><img src="admin/themes/default/icon/delete.png"></a> 71 {if $set.STATUS != 'done'}<a href="{$set.U_CANCEL}" title="{'Cancel this set'|@translate}" onClick="return confirm('{'Are your sure?'|@translate}');"><img src="admin/themes/default/icon/permissions.png"></a>{/if} 72 </td> 73 </tr> 74 {/foreach} 75 76 {if not $sets} 77 <tr class="row2"> 78 <td colspan="8" style="text-align:center;font-style:italic;">{'No result'|@translate}</td> 79 </tr> 80 {/if} 81 </table> -
extensions/BatchDownloader/admin/template/style.css
r16392 r16400 18 18 width:300px; 19 19 } 20 21 .table2 .action { 22 width:70px; 23 } 24 .table2 .user { 25 width:120px; 26 } 27 .table2 .date { 28 width:180px; 29 } 30 .table2 .size { 31 width:100px; 32 } 33 .table2 .images { 34 width:100px; 35 } 36 .table2 .archives { 37 width:110px; 38 } 39 .table2 .status { 40 width:100px; 41 } -
extensions/BatchDownloader/include/BatchDownloader.class.php
r16392 r16400 21 21 $this->conf = $conf['batch_download']; 22 22 $this->data = array( 23 'set_id' => 0, 23 24 'user_id' => $user['id'], 24 ' set_id' => 0,25 'date_creation' => '0000-00-00 00:00:00', 25 26 'type' => null, 26 27 'type_id' => null, … … 28 29 'last_zip' => 0, 29 30 'nb_images' => 0, 31 'total_size' => 0, 30 32 'status' => 'new', 31 33 ); … … 37 39 $query = ' 38 40 SELECT 41 date_creation, 39 42 type, 40 43 type_id, … … 42 45 last_zip, 43 46 nb_images, 47 total_size, 44 48 status 45 49 FROM '.BATCH_DOWNLOAD_TSETS.' 46 50 WHERE 47 user_id = '.$this->data['user_id'].'48 AND id = '.$set_id.'51 id = '.$set_id.' 52 '.(!is_admin() ? 'AND user_id = '.$this->data['user_id'] : null).' 49 53 ;'; 50 54 $result = pwg_query($query); … … 54 58 $this->data['set_id'] = $set_id; 55 59 list( 60 $this->data['date_creation'], 56 61 $this->data['type'], 57 62 $this->data['type_id'], … … 59 64 $this->data['last_zip'], 60 65 $this->data['nb_images'], 66 $this->data['total_size'], 61 67 $this->data['status'] 62 68 ) = pwg_db_fetch_row($result); … … 80 86 $this->images = simple_hash_from_query($query, 'image_id', 'zip'); 81 87 82 if ( count($this->images) != $this->data['nb_images'])88 if ( $this->data['status'] != 'done' and count($this->images) != $this->data['nb_images'] ) 83 89 { 84 90 $this->updateParam('nb_images', count($this->images)); … … 105 111 last_zip, 106 112 nb_images, 113 total_size, 107 114 status 108 115 ) … … 115 122 0, 116 123 0, 124 0, 117 125 "new" 118 126 ) … … 120 128 pwg_query($query); 121 129 $this->data['set_id'] = pwg_db_insert_id(); 130 131 $date = pwg_query('SELECT FROM_UNIXTIME(NOW());'); 132 list($this->data['date_creation']) = pwg_db_fetch_row($date); 122 133 123 134 if (!empty($images)) … … 225 236 226 237 /** 227 * clear 228 */ 229 function clear ($reset=true)238 * clearImages 239 */ 240 function clearImages() 230 241 { 231 242 $this->images = array(); … … 236 247 ;'; 237 248 pwg_query($query); 238 239 if ($reset)240 {241 $this->updateParam('nb_zip', 0);242 $this->updateParam('last_zip', 0);243 $this->updateParam('nb_images', 0);244 }245 249 } 246 250 … … 259 263 /** 260 264 * createNextArchive 265 * @param: bool force all elements in one archive 266 * @return: string zip path or false 261 267 */ 262 268 function createNextArchive($force_one_archive=false) … … 277 283 { 278 284 $images_ids = array_slice(array_keys($this->images), 0, $this->conf['max_elements']); 279 $this->clear (false);285 $this->clearImages(); 280 286 $this->addImages($images_ids); 281 287 } … … 283 289 $this->getEstimatedArchiveNumber(); 284 290 285 pwg_query('UPDATE '.BATCH_DOWNLOAD_TSETS.' SET date_creation = NOW() WHERE id = '.$this->data['set_id'].';');291 $this->updateParam('date_creation', date('Y-m-d H:i:s')); 286 292 } 287 293 … … 332 338 } 333 339 340 $this->updateParam('total_size', $this->data['total_size'] + $total_size); 341 334 342 // archive comment 335 343 global $conf; … … 358 366 { 359 367 $this->updateParam('status', 'done'); 360 $this->clear(false);361 368 } 362 369 … … 386 393 function getEstimatedTotalSize() 387 394 { 395 if ($this->data['status'] == 'done') return $this->data['total_size']; 388 396 if ($this->data['nb_images'] == 0) return 0; 389 397 … … 416 424 function getDownloadList($url='') 417 425 { 418 $nb_archives = $this->getEstimatedArchiveNumber();419 420 426 $out = ''; 421 /*if ($this->data['status'] == 'done') 422 { 423 $out.= '<li id="zip-1">Already downloaded</li>'; 424 }*/ 425 if (true) 426 { 427 for ($i=1; $i<=$this->data['nb_zip']; $i++) 428 { 429 $out.= '<li id="zip-'.$i.'">'; 430 431 if ($i < $this->data['last_zip']+1) 432 { 433 $out.= '<img src="'.BATCH_DOWNLOAD_PATH.'template/drive.png"> Archive #'.$i.' (already downloaded)'; 434 } 435 else if ($i == $this->data['last_zip']+1) 436 { 437 $out.= '<a href="'.add_url_params($url, array('set_id'=>$this->data['set_id'],'zip'=>$i)).'" rel="nofollow" style="font-weight:bold;"' 438 .($i!=1 ? 'onClick="return confirm(\'Starting download Archive #'.$i.' will destroy Archive #'.($i-1).', be sure you finish the download. Continue ?\');"' : null). 439 '><img src="'.BATCH_DOWNLOAD_PATH.'template/drive_go.png"> Archive #'.$i.' (ready)</a>'; 440 } 441 else 442 { 443 $out.= '<img src="'.BATCH_DOWNLOAD_PATH.'template/drive.png"> Archive #'.$i.' (pending)'; 444 } 445 446 $out.= '</li>'; 447 } 427 for ($i=1; $i<=$this->data['nb_zip']; $i++) 428 { 429 $out.= '<li id="zip-'.$i.'">'; 430 431 if ($i < $this->data['last_zip']+1) 432 { 433 $out.= '<img src="'.BATCH_DOWNLOAD_PATH.'template/drive.png"> Archive #'.$i.' (already downloaded)'; 434 } 435 else if ($i == $this->data['last_zip']+1) 436 { 437 $out.= '<a href="'.add_url_params($url, array('set_id'=>$this->data['set_id'],'zip'=>$i)).'" rel="nofollow" style="font-weight:bold;"' 438 .($i!=1 ? 'onClick="return confirm(\'Starting download Archive #'.$i.' will destroy Archive #'.($i-1).', be sure you finish the download. Continue ?\');"' : null). 439 '><img src="'.BATCH_DOWNLOAD_PATH.'template/drive_go.png"> Archive #'.$i.' (ready)</a>'; 440 } 441 else 442 { 443 $out.= '<img src="'.BATCH_DOWNLOAD_PATH.'template/drive.png"> Archive #'.$i.' (pending)'; 444 } 445 446 $out.= '</li>'; 448 447 } 449 448 … … 471 470 get_username($this->data['user_id']) .'_'. 472 471 $this->data['type'] .'-'. $this->data['type_id'] .'_'. 473 $this->data['user_id'] . $this->data['set_id'] . '_'.474 ($this->data['nb_zip']!=1 ? ' part'. $i : null).472 $this->data['user_id'] . $this->data['set_id'] . 473 ($this->data['nb_zip']!=1 ? '_part'. $i : null). 475 474 '.zip'; 476 475 } … … 487 486 'TOTAL_SIZE' => ceil($this->getEstimatedTotalSize()/1024), 488 487 'LINKS' => $this->getDownloadList(BATCH_DOWNLOAD_PUBLIC . 'init_zip'), 488 'DATE_CREATION' => format_date($this->data['date_creation'], true), 489 489 ); 490 490 … … 496 496 switch ($this->data['type']) 497 497 { 498 // calendar 498 499 case 'calendar': 499 500 { 500 $set['NAME'] = l10n('Calendar'); 501 $set['COMMENT'] = $this->data['type_id']; 502 break; 503 } 504 501 global $conf, $page; 502 $old_page = $page; 503 504 $fields = array( 505 'created' => l10n('Creation date'), 506 'posted' => l10n('Post date'), 507 ); 508 509 $chronology = explode('-', $this->data['type_id']); 510 $page['chronology_field'] = $chronology[0]; 511 $page['chronology_style'] = $chronology[1]; 512 $page['chronology_view'] = $chronology[2]; 513 $page['chronology_date'] = array_splice($chronology, 3); 514 515 if (!class_exists('Calendar')) 516 { 517 include_once(PHPWG_ROOT_PATH.'include/calendar_'. $page['chronology_style'] .'.class.php'); 518 } 519 $calendar = new Calendar(); 520 $calendar->initialize(''); 521 $display_name = strip_tags($calendar->get_display_name()); 522 523 $set['NAME'] = l10n('Calendar').': '.$fields[$page['chronology_field']].$display_name; 524 $set['sNAME'] = l10n('Calendar').': '.ltrim($display_name, $conf['level_separator']); 525 526 $page = $old_page; 527 break; 528 } 529 530 // category 505 531 case 'category': 506 532 { … … 512 538 } 513 539 540 // flat 514 541 case 'flat': 515 542 { … … 518 545 } 519 546 547 // tags 520 548 case 'tags': 521 549 { 522 550 $tags = find_tags(explode(',', $this->data['type_id'])); 523 $set['NAME'] = l10n('Tags') ;524 525 $ set['COMMENT'] = ''; $first = true;551 $set['NAME'] = l10n('Tags').': '; 552 553 $first = true; 526 554 foreach ($tags as $tag) 527 555 { 528 556 if ($first) $first = false; 529 else $set[' COMMENT'].= ', ';530 $set[' COMMENT'].=557 else $set['NAME'].= ', '; 558 $set['NAME'].= 531 559 '<a href="' . make_index_url(array('tags'=>array($tag))) . '">' 532 560 .trigger_event('render_tag_name', $tag['name']) 533 561 .'</a>'; 534 562 } 535 536 $set['sNAME'] = l10n('Tags').': '.strip_tags($set['COMMENT']); 537 break; 538 } 539 563 break; 564 } 565 566 // search 540 567 case 'search': 541 568 { … … 544 571 } 545 572 573 // favorites 546 574 case 'favorites': 547 575 { … … 550 578 } 551 579 580 // most_visited 552 581 case 'most_visited': 553 582 { … … 556 585 } 557 586 587 // best_rated 558 588 case 'best_rated': 559 589 { … … 562 592 } 563 593 594 // list 564 595 case 'list': 565 596 { … … 568 599 } 569 600 601 // recent_pics 570 602 case 'recent_pics': 571 603 { … … 574 606 } 575 607 608 // selection 576 609 // case 'selection': 577 610 // { … … 582 615 } 583 616 584 if (!isset($set['sNAME'])) $set['sNAME'] = $set['NAME'];617 if (!isset($set['sNAME'])) $set['sNAME'] = strip_tags($set['NAME']); 585 618 if (!isset($set['COMMENT'])) $set['COMMENT'] = null; 586 619 -
extensions/BatchDownloader/include/download.inc.php
r16392 r16400 18 18 { 19 19 $BatchDownloader->deleteLastArchive(); 20 $BatchDownloader->clear ();20 $BatchDownloader->clearImages(); 21 21 pwg_query('DELETE FROM '.BATCH_DOWNLOAD_TSETS.' WHERE id = '.$_GET['set_id'].';'); 22 22 $_SESSION['page_infos'][] = l10n('Download set deleted'); -
extensions/BatchDownloader/include/events.inc.php
r16392 r16400 73 73 $BatchDownloader->getEstimatedArchiveNumber(); 74 74 75 // if we plan only one zip with less elements than 'max_elements', the download starts immediately 75 76 if ( 76 77 $BatchDownloader->getParam('nb_images') <= $conf['batch_download']['max_elements'] … … 78 79 ) 79 80 { 80 $BatchDownloader->createNextArchive(true); 81 $BatchDownloader->createNextArchive(true); // make sure we have only one zip, even if 'max_size' is exceeded 81 82 82 83 $u_download = BATCH_DOWNLOAD_PATH . 'download.php?set_id='.$BatchDownloader->getParam('set_id').'&zip=1'; … … 87 88 array_push($page['infos'], sprintf(l10n('The archive is downloading, if the download doesn\'t start automatically please <a href="%s">click here</a>'), $u_download)); 88 89 } 90 // oterwise we go to summary page 89 91 else 90 92 { … … 190 192 $BatchDownloader = new BatchDownloader($set_id); 191 193 $BatchDownloader->deleteLastArchive(); 192 $BatchDownloader->clear (false);194 $BatchDownloader->clearImages(); 193 195 $BatchDownloader->updateParam('status', 'done'); 194 196 } -
extensions/BatchDownloader/include/functions.inc.php
r16379 r16400 73 73 global $user, $conf; 74 74 75 if (is_a_guest()) return false; 75 76 if (is_admin()) return true; 76 77 -
extensions/BatchDownloader/maintain.inc.php
r16379 r16400 28 28 `type` varchar(16) CHARACTER SET utf8 NOT NULL, 29 29 `type_id` varchar(64) CHARACTER SET utf8 NOT NULL, 30 `nb_zip` smallint( 2) NOT NULL DEFAULT 0,31 `last_zip` smallint( 2) NOT NULL DEFAULT 0,30 `nb_zip` smallint(3) NOT NULL DEFAULT 0, 31 `last_zip` smallint(3) NOT NULL DEFAULT 0, 32 32 `nb_images` mediumint(8) NOT NULL DEFAULT 0, 33 `total_size` int(10) NOT NULL DEFAULT 0, 33 34 `status` enum("new","download","done") CHARACTER SET utf8 NOT NULL DEFAULT "new", 34 35 PRIMARY KEY (`id`) -
extensions/BatchDownloader/template/init_zip.tpl
r16392 r16400 30 30 <li><b>{'Estimated size'|@translate}:</b> {$set.TOTAL_SIZE} MB</li> 31 31 <li><b>{'Estimated number of archives'|@translate}:</b> {$set.NB_ARCHIVES} <i>({'real number of archives can differ'|@translate})</i></li> 32 <li><b>{'Created on'|@translate}:</b> {$set.DATE_CREATION}</li> 32 33 </ul> 33 34
Note: See TracChangeset
for help on using the changeset viewer.