Changeset 16400


Ignore:
Timestamp:
Jul 6, 2012, 4:40:28 PM (8 years ago)
Author:
mistic100
Message:
  • display creation date
  • improve set titles for Tags and Calendar
  • add Download history admin page

TODO : User Selection, localization, change archive name to more user-friendly one in the Force-Download

Location:
extensions/BatchDownloader
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • extensions/BatchDownloader/admin/sets.php

    r16379 r16400  
    11<?php
    22if (!defined('BATCH_DOWNLOAD_PATH')) die('Hacking attempt!');
     3
     4// actions
     5if (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}
     12if (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
     25if (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 = '
     48SELECT
     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
     60foreach ($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&amp;delete='.$set->getParam('set_id'),
     70      'U_CANCEL' => BATCH_DOWNLOAD_ADMIN . '-sets&amp;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  ));
    3132
    4133
  • extensions/BatchDownloader/admin/template/sets.tpl

    r16392 r16400  
    55</div>
    66
    7 <form method="post" action="" class="properties">
     7<form class="filter" method="post" name="filter" action="{$F_FILTER_ACTION}">
    88<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>
    1018 
     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  &nbsp;
     36  <span><input class="submit" type="submit" name="filter" value="{'Submit'|@translate}"> <a href="{$F_FILTER_ACTION}">{'Reset'|@translate}</a></span>
     37  </label>
     38
    1139</fieldset>
     40
    1241</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  
    1818  width:300px;
    1919}
     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  
    2121    $this->conf = $conf['batch_download'];
    2222    $this->data = array(
     23      'set_id' => 0,
    2324      'user_id' => $user['id'],
    24       'set_id' => 0,
     25      'date_creation' => '0000-00-00 00:00:00',
    2526      'type' => null,
    2627      'type_id' => null,
     
    2829      'last_zip' => 0,
    2930      'nb_images' => 0,
     31      'total_size' => 0,
    3032      'status' => 'new',
    3133      );
     
    3739      $query = '
    3840SELECT
     41    date_creation,
    3942    type,
    4043    type_id,
     
    4245    last_zip,
    4346    nb_images,
     47    total_size,
    4448    status
    4549  FROM '.BATCH_DOWNLOAD_TSETS.'
    4650  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).'
    4953;';
    5054      $result = pwg_query($query);
     
    5458        $this->data['set_id'] = $set_id;
    5559        list(
     60          $this->data['date_creation'],
    5661          $this->data['type'],
    5762          $this->data['type_id'],
     
    5964          $this->data['last_zip'],
    6065          $this->data['nb_images'],
     66          $this->data['total_size'],
    6167          $this->data['status']
    6268          ) = pwg_db_fetch_row($result);
     
    8086        $this->images = simple_hash_from_query($query, 'image_id', 'zip');
    8187       
    82         if (count($this->images) != $this->data['nb_images'])
     88        if ( $this->data['status'] != 'done' and count($this->images) != $this->data['nb_images'] )
    8389        {
    8490          $this->updateParam('nb_images', count($this->images));
     
    105111    last_zip,
    106112    nb_images,
     113    total_size,
    107114    status
    108115  )
     
    115122    0,
    116123    0,
     124    0,
    117125    "new"
    118126  )
     
    120128      pwg_query($query);
    121129      $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);
    122133     
    123134      if (!empty($images))
     
    225236 
    226237  /**
    227    * clear
    228    */
    229   function clear($reset=true)
     238   * clearImages
     239   */
     240  function clearImages()
    230241  {
    231242    $this->images = array();
     
    236247;';
    237248    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     }
    245249  }
    246250 
     
    259263  /**
    260264   * createNextArchive
     265   * @param: bool force all elements in one archive
     266   * @return: string zip path or false
    261267   */
    262268  function createNextArchive($force_one_archive=false)
     
    277283      {
    278284        $images_ids = array_slice(array_keys($this->images), 0, $this->conf['max_elements']);
    279         $this->clear(false);
     285        $this->clearImages();
    280286        $this->addImages($images_ids);
    281287      }
     
    283289      $this->getEstimatedArchiveNumber();
    284290     
    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'));
    286292    }
    287293   
     
    332338      }
    333339     
     340      $this->updateParam('total_size', $this->data['total_size'] + $total_size);
     341     
    334342      // archive comment
    335343      global $conf;
     
    358366      {
    359367        $this->updateParam('status', 'done');
    360         $this->clear(false);
    361368      }
    362369     
     
    386393  function getEstimatedTotalSize()
    387394  {
     395    if ($this->data['status'] == 'done') return $this->data['total_size'];
    388396    if ($this->data['nb_images'] == 0) return 0;
    389397   
     
    416424  function getDownloadList($url='')
    417425  {
    418     $nb_archives = $this->getEstimatedArchiveNumber();
    419    
    420426    $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>';
    448447    }
    449448   
     
    471470          get_username($this->data['user_id']) .'_'.
    472471          $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).
    475474          '.zip';
    476475  }
     
    487486      'TOTAL_SIZE' => ceil($this->getEstimatedTotalSize()/1024),
    488487      'LINKS' => $this->getDownloadList(BATCH_DOWNLOAD_PUBLIC . 'init_zip'),
     488      'DATE_CREATION' => format_date($this->data['date_creation'], true),
    489489      );
    490490       
     
    496496    switch ($this->data['type'])
    497497    {
     498      // calendar
    498499      case 'calendar':
    499500      {
    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
    505531      case 'category':
    506532      {
     
    512538      }
    513539     
     540      // flat
    514541      case 'flat':
    515542      {
     
    518545      }
    519546     
     547      // tags
    520548      case 'tags':
    521549      {
    522550        $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;
    526554        foreach ($tags as $tag)
    527555        {
    528556          if ($first) $first = false;
    529           else $set['COMMENT'].= ', ';
    530           $set['COMMENT'].=
     557          else $set['NAME'].= ', ';
     558          $set['NAME'].=
    531559            '<a href="' . make_index_url(array('tags'=>array($tag))) . '">'
    532560            .trigger_event('render_tag_name', $tag['name'])
    533561            .'</a>';
    534562        }
    535        
    536         $set['sNAME'] = l10n('Tags').': '.strip_tags($set['COMMENT']);
    537         break;
    538       }
    539      
     563        break;
     564      }
     565     
     566      // search
    540567      case 'search':
    541568      {
     
    544571      }
    545572     
     573      // favorites
    546574      case 'favorites':
    547575      {
     
    550578      }
    551579     
     580      // most_visited
    552581      case 'most_visited':
    553582      {
     
    556585      }
    557586     
     587      // best_rated
    558588      case 'best_rated':
    559589      {
     
    562592      }
    563593     
     594      // list
    564595      case 'list':
    565596      {
     
    568599      }
    569600     
     601      // recent_pics
    570602      case 'recent_pics':
    571603      {
     
    574606      }
    575607     
     608      // selection
    576609      // case 'selection':
    577610      // {
     
    582615    }
    583616   
    584     if (!isset($set['sNAME'])) $set['sNAME'] = $set['NAME'];
     617    if (!isset($set['sNAME'])) $set['sNAME'] = strip_tags($set['NAME']);
    585618    if (!isset($set['COMMENT'])) $set['COMMENT'] = null;
    586619   
  • extensions/BatchDownloader/include/download.inc.php

    r16392 r16400  
    1818    {
    1919      $BatchDownloader->deleteLastArchive();
    20       $BatchDownloader->clear();
     20      $BatchDownloader->clearImages();
    2121      pwg_query('DELETE FROM '.BATCH_DOWNLOAD_TSETS.' WHERE id = '.$_GET['set_id'].';');
    2222      $_SESSION['page_infos'][] = l10n('Download set deleted');
  • extensions/BatchDownloader/include/events.inc.php

    r16392 r16400  
    7373      $BatchDownloader->getEstimatedArchiveNumber();
    7474     
     75      // if we plan only one zip with less elements than 'max_elements', the download starts immediately
    7576      if (
    7677        $BatchDownloader->getParam('nb_images') <= $conf['batch_download']['max_elements']
     
    7879      )
    7980      {
    80         $BatchDownloader->createNextArchive(true);
     81        $BatchDownloader->createNextArchive(true); // make sure we have only one zip, even if 'max_size' is exceeded
    8182       
    8283        $u_download = BATCH_DOWNLOAD_PATH . 'download.php?set_id='.$BatchDownloader->getParam('set_id').'&amp;zip=1';
     
    8788        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));
    8889      }
     90      // oterwise we go to summary page
    8991      else
    9092      {
     
    190192    $BatchDownloader = new BatchDownloader($set_id);
    191193    $BatchDownloader->deleteLastArchive();
    192     $BatchDownloader->clear(false);
     194    $BatchDownloader->clearImages();
    193195    $BatchDownloader->updateParam('status', 'done');
    194196  }
  • extensions/BatchDownloader/include/functions.inc.php

    r16379 r16400  
    7373  global $user, $conf;
    7474 
     75  if (is_a_guest()) return false;
    7576  if (is_admin()) return true;
    7677 
  • extensions/BatchDownloader/maintain.inc.php

    r16379 r16400  
    2828  `type` varchar(16) CHARACTER SET utf8 NOT NULL,
    2929  `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,
    3232  `nb_images` mediumint(8) NOT NULL DEFAULT 0,
     33  `total_size` int(10) NOT NULL DEFAULT 0,
    3334  `status` enum("new","download","done") CHARACTER SET utf8 NOT NULL DEFAULT "new",
    3435  PRIMARY KEY (`id`)
  • extensions/BatchDownloader/template/init_zip.tpl

    r16392 r16400  
    3030    <li><b>{'Estimated size'|@translate}:</b> {$set.TOTAL_SIZE} MB</li>
    3131    <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>
    3233  </ul>
    3334 
Note: See TracChangeset for help on using the changeset viewer.