Ignore:
Timestamp:
Sep 14, 2012, 5:59:05 PM (12 years ago)
Author:
mistic100
Message:

improve a bit datas methods

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/BatchDownloader/include/BatchDownloader.class.php

    r17880 r17915  
    3030      'nb_images' => 0,
    3131      'total_size' => 0,
     32      'estimated_total_size' => 0,
    3233      'status' => 'new',
    3334      );
     
    314315      $this->updateParam('last_zip', $this->data['last_zip']+1);
    315316      $zip_path = $this->getArchivePath();
    316      
    317317      $zip = new myZip($zip_path, isset($conf['batch_download_force_pclzip']));
    318318     
     
    383383   * @return: int
    384384   */
    385   function getEstimatedTotalSize()
     385  function getEstimatedTotalSize($force=false)
    386386  {
    387387    if ($this->data['status'] == 'done') return $this->data['total_size'];
    388388    if ($this->data['nb_images'] == 0) return 0;
     389    if ( !empty($this->data['estimated_total_size']) and !$force ) return $this->data['estimated_total_size'];
    389390   
    390391    $image_ids = array_slice(array_keys($this->images), 0, $this->conf['max_elements']);
     
    396397;';
    397398    list($total) = pwg_db_fetch_row(pwg_query($query));
     399    $this->data['estimated_total_size'] = $total;
    398400    return $total;
    399401  }
     
    462464   
    463465    if ($i === null) $i = $this->data['last_zip'];
     466    $set = $this->getNames();
    464467   
    465468    include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
    466469   
    467     return BATCH_DOWNLOAD_LOCAL .'u-'. $this->data['user_id'] .'/'.
    468           (!empty($this->conf['archive_prefix']) ? $this->conf['archive_prefix'] .'_' : null).
    469           get_username($this->data['user_id']) .'_'.
    470           $this->data['type'] .'-'. $this->data['type_id'] .'_'.
    471           $this->data['user_id'] . $this->data['id'] .
    472           ($this->data['nb_zip']!=1 ? '_part'. $i : null).
    473           '.zip';
    474   }
    475  
    476   /**
    477    * getSetInfo
     470    $path = BATCH_DOWNLOAD_LOCAL . 'u-'. $this->data['user_id'] . '/';
     471    $path.= !empty($this->conf['archive_prefix']) ? $this->conf['archive_prefix'] . '_' : null;
     472    $path.= get_username($this->data['user_id']) . '_';
     473    $path.= $set['BASENAME'] . '_';
     474    $path.= $this->data['user_id'] . $this->data['id'];
     475    $path.= $this->data['nb_zip']!=1 ? '_part' . $i : null;
     476    $path.= '.zip';
     477   
     478    return $path;
     479  }
     480 
     481  /**
     482   * getNames
    478483   * @return: array
    479484   */
    480   function getSetInfo()
    481   {
    482     $set = array(
    483       'NB_IMAGES' => $this->data['nb_images'],
    484       'NB_ARCHIVES' => $this->data['nb_zip'],
    485       'TOTAL_SIZE' => ceil($this->getEstimatedTotalSize()/1024),
    486       'LINKS' => $this->getDownloadList(BATCH_DOWNLOAD_PUBLIC . 'init_zip'),
    487       'DATE_CREATION' => format_date($this->data['date_creation'], true),
    488       );
    489    
     485  function getNames()
     486  {   
    490487    switch ($this->data['type'])
    491488    {
     
    517514        $set['NAME'] = l10n('Calendar').': '.$fields[$page['chronology_field']].$display_name;
    518515        $set['sNAME'] = l10n('Calendar').': '.ltrim($display_name, $conf['level_separator']);
     516        $set['BASENAME'] = 'calendar-'.$page['chronology_field'].'-'.implode('-',$page['chronology_date']);
    519517       
    520518        $page = $old_page;
     
    529527        {
    530528          $set['NAME'] = l10n('Album').': #'.$this->data['type_id'].' (deleted)';
     529          $set['BASENAME'] = 'album'.$this->data['type_id'];
    531530        }
    532531        else
     
    535534          $set['sNAME'] = l10n('Album').': '.trigger_event('render_category_name', $category['name']);
    536535          $set['COMMENT'] = trigger_event('render_category_description', $category['comment']);
     536         
     537          if (!empty($category['permalink']))
     538          {
     539            $set['BASENAME'] = 'album-'.$category['permalink'];
     540          }
     541          else if ( ($name = str2url($category['name'])) != null )
     542          {
     543            $set['BASENAME'] = 'album-'.$name;
     544          }
     545          else
     546          {
     547            $set['BASENAME'] = 'album'.$this->data['type_id'];
     548          }
    537549        }
    538550        break;
     
    543555      {
    544556        $set['NAME'] = l10n('Whole gallery');
     557        $set['BASENAME'] = 'all-gallery';
    545558        break;
    546559      }
     
    551564        $tags = find_tags(explode(',', $this->data['type_id']));
    552565        $set['NAME'] = l10n('Tags').': ';
     566        $set['BASENAME'] = 'tags';
    553567       
    554568        $first = true;
     
    561575            .trigger_event('render_tag_name', $tag['name'])
    562576            .'</a>';
     577          $set['BASENAME'].= '-'.$tag['url_name'];
    563578        }
    564579        break;
     
    569584      {
    570585        $set['NAME'] = '<a href="'.make_index_url(array('section'=>'search', 'search'=>$this->data['type_id'])).'">'.l10n('Search').'</a>';
     586        $set['BASENAME'] = 'search'.$this->data['type_id'];
    571587        break;
    572588      }
     
    576592      {
    577593        $set['NAME'] = '<a href="'.make_index_url(array('section'=>'favorites')).'">'.l10n('Your favorites').'</a>';
     594        $set['BASENAME'] = 'favorites';
    578595        break;
    579596      }
     
    583600      {
    584601        $set['NAME'] = '<a href="'.make_index_url(array('section'=>'most_visited')).'">'.l10n('Most visited').'</a>';
     602        $set['BASENAME'] = 'most-visited';
    585603        break;
    586604      }
     
    590608      {
    591609        $set['NAME'] = '<a href="'.make_index_url(array('section'=>'best_rated')).'">'.l10n('Best rated').'</a>';
     610        $set['BASENAME'] = 'best-rated';
    592611        break;
    593612      }
     
    597616      {
    598617        $set['NAME'] = l10n('Random');
     618        $set['BASENAME'] = 'random';
    599619        break;
    600620      }
     
    604624      {
    605625        $set['NAME'] = '<a href="'.make_index_url(array('section'=>'recent_pics')).'">'.l10n('Recent photos').'</a>';
     626        $set['BASENAME'] = 'recent-pics';
    606627        break;
    607628      }
     
    616637          $infos = $UserCollection->getCollectionInfo();
    617638          $set['NAME'] = l10n('Collection').': <a href="'.$infos['U_PUBLIC'].'">'.$UserCollection->getParam('name').'</a>';
     639         
     640          if ( ($name = str2url($UserCollection->getParam('name'))) != null)
     641          {
     642            $set['BASENAME'] = 'collection-'.$name;
     643          }
     644          else
     645          {
     646            $set['BASENAME'] = 'collection'.$this->data['type_id'];
     647          }
    618648        }
    619649        catch (Exception $e)
    620650        {
    621651          $set['NAME'] = l10n('Collection').': #'.$this->data['type_id'].' (deleted)';
     652          $set['BASENAME'] = 'collection'.$this->data['type_id'];
    622653        }
    623654        break;
     
    625656    }
    626657   
    627     if (!isset($set['sNAME']))   $set['sNAME'] = strip_tags($set['NAME']);
    628     if (!isset($set['COMMENT'])) $set['COMMENT'] = null;
     658    if (!isset($set['sNAME']))    $set['sNAME'] = strip_tags($set['NAME']);
     659    if (!isset($set['COMMENT']))  $set['COMMENT'] = null;
     660    if (!isset($set['BASENAME'])) $set['BASENAME'] = $this->data['type'] . $this->data['type_id'];
    629661   
    630662    return $set;
     663  }
     664 
     665  /**
     666   * getSetInfo
     667   * @return: array
     668   */
     669  function getSetInfo()
     670  {   
     671    $set = array(
     672      'NB_IMAGES' =>     $this->data['nb_images'],
     673      'NB_ARCHIVES' =>   $this->data['nb_zip'],
     674      'STATUS' =>        $this->data['status'],
     675      'LAST_ZIP' =>      $this->data['last_zip'],
     676      'TOTAL_SIZE' =>    ceil($this->getEstimatedTotalSize()/1024),
     677      'LINKS' =>         $this->getDownloadList(BATCH_DOWNLOAD_PUBLIC . 'init_zip'),
     678      'DATE_CREATION' => format_date($this->data['date_creation'], true),
     679      );
     680   
     681    return array_merge($set, $this->getNames());
    631682  }
    632683}
Note: See TracChangeset for help on using the changeset viewer.