Changeset 12865 for trunk/include
- Timestamp:
- Jan 8, 2012, 8:25:52 PM (12 years ago)
- Location:
- trunk/include
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/derivative.inc.php
r12855 r12865 220 220 } 221 221 222 function get_path() 223 { 224 return PHPWG_ROOT_PATH.$this->rel_path; 225 } 226 222 227 function get_url() 223 228 { -
trunk/include/ws_functions.inc.php
r12855 r12865 93 93 $clauses[] = $tbl_name.'width/'.$tbl_name.'height<='.$params['f_max_ratio']; 94 94 } 95 if ( $params['f_with_thumbnail'])96 { 97 $clauses[] = $tbl_name.' tn_ext IS NOT NULL';95 if (is_numeric($params['f_max_level']) ) 96 { 97 $clauses[] = $tbl_name.'level <= '.$params['f_max_level']; 98 98 } 99 99 return $clauses; … … 148 148 { 149 149 $ret = array(); 150 150 151 151 $src_image = new SrcImage($image_row); 152 152 … … 156 156 $ret['element_url'] = get_element_url($image_row); 157 157 } 158 158 159 159 $derivatives = DerivativeImage::get_all($src_image); 160 160 $derivatives_arr = array(); … … 178 178 'id','element_url', 'file','width','height','hit','date_available','date_creation' 179 179 ); 180 } 181 182 function ws_getMissingDerivatives($params, &$service) 183 { 184 if (!is_admin()) 185 { 186 return new PwgError(403, 'Forbidden'); 187 } 188 189 if ( empty($params['types']) ) 190 { 191 $types = array_keys(ImageStdParams::get_defined_type_map()); 192 } 193 else 194 { 195 $types = array_intersect(array_keys(ImageStdParams::get_defined_type_map()), $params['types']); 196 if (count($types)==0) 197 { 198 return new PwgError(WS_ERR_INVALID_PARAM, "Invalid types"); 199 } 200 } 201 202 if ( ($max_urls = intval($params['max_urls'])) <= 0) 203 { 204 return new PwgError(WS_ERR_INVALID_PARAM, "Invalid max_urls"); 205 } 206 207 list($max_id, $image_count) = pwg_db_fetch_row( pwg_query('SELECT MAX(id)+1, COUNT(*) FROM '.IMAGES_TABLE) ); 208 $start_id = intval($params['prev_page']); 209 if ($start_id<=0) 210 { 211 $start_id = $max_id; 212 } 213 214 $uid = '&b='.time(); 215 global $conf; 216 $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true; 217 $conf['derivative_url_style']=2; //script 218 219 $qlimit = min(5000, ceil(max($image_count/500, $max_urls/count($types)))); 220 $where_clauses = ws_std_image_sql_filter( $params, '' ); 221 $where_clauses[] = 'id<start_id'; 222 223 $query_model = 'SELECT id, path, representative_ext, width, height 224 FROM '.IMAGES_TABLE.' 225 WHERE '.implode(' AND ', $where_clauses).' 226 ORDER BY id DESC 227 LIMIT '.$qlimit; 228 229 $urls=array(); 230 do 231 { 232 $result = pwg_query( str_replace('start_id', $start_id, $query_model)); 233 $is_last = pwg_db_num_rows($result) < $qlimit; 234 while ($row=pwg_db_fetch_assoc($result)) 235 { 236 $start_id = $row['id']; 237 $src_image = new SrcImage($row); 238 if ($src_image->is_mimetype()) 239 continue; 240 foreach($types as $type) 241 { 242 $derivative = new DerivativeImage($type, $src_image); 243 if ($type != $derivative->get_type()) 244 continue; 245 if (@filemtime($derivative->get_path())===false) 246 { 247 $urls[] = $derivative->get_url().$uid; 248 } 249 } 250 if (count($urls)>=$max_urls && !$is_last) 251 break; 252 } 253 if ($is_last) 254 { 255 $start_id = 0; 256 } 257 }while (count($urls)<$max_urls && $start_id); 258 259 $ret = array(); 260 if ($start_id) 261 { 262 $ret['next_page']=$start_id; 263 } 264 $ret['urls']=$urls; 265 return $ret; 180 266 } 181 267 … … 515 601 $user_representative_updates_for = array(); 516 602 // management of the album thumbnail -- stops here 517 603 518 604 $cats = array(); 519 605 while ($row = pwg_db_fetch_assoc($result)) … … 553 639 554 640 // management of the album thumbnail -- starts here 555 // 641 // 556 642 // on branch 2.3, the algorithm is duplicated from 557 643 // include/category_cats, but we should use a common code for Piwigo 2.4 … … 604 690 } 605 691 } 606 692 607 693 if (isset($image_id)) 608 694 { … … 611 697 $user_representative_updates_for[ $user['id'].'#'.$row['id'] ] = $image_id; 612 698 } 613 699 614 700 $row['representative_picture_id'] = $image_id; 615 701 array_push($image_ids, $image_id); … … 651 737 // * register it at user_representative_picture_id 652 738 // * set it as the representative_picture_id for the category 653 739 654 740 foreach ($categories as &$category) 655 741 { … … 658 744 // searching a random representant among elements in sub-categories 659 745 $image_id = get_random_image_in_category($category); 660 746 661 747 if (isset($image_id) and !in_array($image_id, $image_ids)) 662 748 { 663 749 array_push($new_image_ids, $image_id); 664 750 } 665 751 666 752 if ($conf['representative_cache_on_level']) 667 753 { 668 754 $user_representative_updates_for[ $user['id'].'#'.$category['id'] ] = $image_id; 669 755 } 670 756 671 757 $category['representative_picture_id'] = $image_id; 672 758 } … … 675 761 } 676 762 } 677 763 678 764 if (count($new_image_ids) > 0) 679 765 { … … 697 783 { 698 784 $updates = array(); 699 785 700 786 foreach ($user_representative_updates_for as $user_cat => $image_id) 701 787 { 702 788 list($user_id, $cat_id) = explode('#', $user_cat); 703 789 704 790 array_push( 705 791 $updates, … … 736 822 unset($cat['count_categories']); 737 823 } 738 unset($cat); 824 unset($cat); 739 825 // management of the album thumbnail -- stops here 740 826 … … 1531 1617 // check dumped thumbnail md5 1532 1618 $dumped_md5 = md5_file($file_path); 1533 if ($dumped_md5 != $file_sum) 1619 if ($dumped_md5 != $file_sum) 1534 1620 { 1535 1621 return new PwgError(500, '[add_file] '.$type.' transfer failed'); … … 1666 1752 { 1667 1753 ws_logfile('[pwg.images.add] resize activated'); 1668 1754 1669 1755 // temporary file path 1670 1756 $type = 'file'; 1671 1757 $file_path = $conf['upload_dir'].'/buffer/'.$params['original_sum'].'-'.$type; 1672 1758 1673 1759 merge_chunks($file_path, $params['original_sum'], $type); 1674 1760 chmod($file_path, 0644); 1675 1761 1676 1762 include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); 1677 1763 1678 1764 $image_id = add_uploaded_file( 1679 1765 $file_path, … … 1704 1790 $filename_wo_ext = $date_string.'-'.$random_string; 1705 1791 $file_path = $upload_dir.'/'.$filename_wo_ext.'.jpg'; 1706 1792 1707 1793 // add files 1708 1794 $file_infos = add_file($file_path, 'file', $params['original_sum'], $params['file_sum']); 1709 1795 $thumb_infos = add_file($file_path, 'thumb', $params['original_sum'], $params['thumbnail_sum']); 1710 1796 1711 1797 if (isset($params['high_sum'])) 1712 1798 { … … 1763 1849 } 1764 1850 } 1765 1851 1766 1852 if (count(array_keys($update)) > 0) 1767 1853 { … … 1774 1860 1775 1861 $url_params = array('image_id' => $image_id); 1776 1862 1777 1863 // let's add links between the image and the categories 1778 1864 if (isset($params['categories'])) … … 1782 1868 if (preg_match('/^\d+/', $params['categories'], $matches)) { 1783 1869 $category_id = $matches[0]; 1784 1870 1785 1871 $query = ' 1786 1872 SELECT id, name, permalink … … 1790 1876 $result = pwg_query($query); 1791 1877 $category = pwg_db_fetch_assoc($result); 1792 1878 1793 1879 $url_params['section'] = 'categories'; 1794 1880 $url_params['category'] = $category; … … 1958 2044 return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid user_id'); 1959 2045 } 1960 2046 1961 2047 $query = ' 1962 2048 DELETE FROM '.RATE_TABLE.' 1963 2049 WHERE user_id='.$user_id; 1964 2050 1965 2051 if (!empty($params['anonymous_id'])) 1966 2052 { 1967 2053 $query .= ' AND anonymous_id=\''.$params['anonymous_id'].'\''; 1968 2054 } 1969 2055 1970 2056 $changes = pwg_db_changes(pwg_query($query)); 1971 2057 if ($changes) … … 3275 3361 return new PwgError(403, "image can't be resized"); 3276 3362 } 3277 3363 3278 3364 $hd_path = get_high_path($image); 3279 3365 … … 3285 3371 $hd_dir = dirname($hd_path); 3286 3372 prepare_directory($hd_dir); 3287 3373 3288 3374 rename($image_path, $hd_path); 3289 3375 $hd_infos = pwg_image_infos($hd_path);
Note: See TracChangeset
for help on using the changeset viewer.