Changeset 12865
- Timestamp:
- Jan 8, 2012, 8:25:52 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r12855 r12865 201 201 $files[] = get_element_path($row); 202 202 203 204 203 if (!empty($row['representative_ext'])) 205 204 { 206 $pi = pathinfo($row['path']);207 $file_wo_ext = get_filename_wo_extension($pi['basename']);208 205 $files[] = original_to_representative( $files[0], $row['representative_ext']); 209 206 } -
trunk/admin/include/image.class.php
r12851 r12865 705 705 imagecopy($cut, $ioverlay, 0, 0, 0, 0, $ow, $oh); 706 706 imagecopymerge($this->image, $cut, $x, $y, 0, 0, $ow, $oh, $opacity); 707 imagedestroy($cut); 707 708 return true; 708 709 } -
trunk/admin/themes/default/template/derivatives.tpl
r12851 r12865 23 23 {/literal}{/html_head} 24 24 25 <p><a href="admin.php?page=derivatives_build">Build missing derivatives</a></p> 25 26 <form method="post" id="derviativesForm"> 26 27 <fieldset> -
trunk/i.php
r12851 r12865 109 109 { 110 110 $req = $_SERVER["QUERY_STRING"]; 111 if ($pos=strpos($req, '&')) 112 { 113 $req = substr($req, 0, $pos); 114 } 111 115 /*foreach (array_keys($_GET) as $keynum => $key) 112 116 { … … 168 172 try 169 173 { 170 $pa ge['derivative_params'] = DerivativeParams::from_url_tokens($deriv);174 $params = $page['derivative_params'] = DerivativeParams::from_url_tokens($deriv); 171 175 } 172 176 catch (Exception $e) 173 177 { 174 178 ierror($e->getMessage(), 400); 179 } 180 if ($params->sizing->ideal_size[0] < 20 or $params->sizing->ideal_size[1] < 20) 181 { 182 ierror('Invalid size', 400); 183 } 184 if ($params->sizing->max_crop < 0 or $params->sizing->max_crop > 1) 185 { 186 ierror('Invalid crop', 400); 175 187 } 176 188 } … … 225 237 226 238 $params = $page['derivative_params']; 227 if ($params->sizing->ideal_size[0] < 20 or $params->sizing->ideal_size[1] < 20)228 {229 ierror('Invalid size', 400);230 }231 if ($params->sizing->max_crop < 0 or $params->sizing->max_crop > 1)232 {233 ierror('Invalid crop', 400);234 }235 239 236 240 $src_mtime = @filemtime($page['src_path']); … … 251 255 $expires=false; 252 256 $now = time(); 253 if ( $now > (max($src_mtime, $params->last_mod_time) + 24*3600) ) 257 if ( isset($_GET['b']) ) 258 { 259 $expires = $now + 100; 260 header("Cache-control: no-store, max-age=100"); 261 } 262 elseif ( $now > (max($src_mtime, $params->last_mod_time) + 24*3600) ) 254 263 {// somehow arbitrary - if derivative params or src didn't change for the last 24 hours, we send an expire header for several days 255 264 $expires = $now + 10*24*3600; … … 268 277 } 269 278 279 if (!mkgetdir(dirname($page['derivative_path']))) 280 { 281 ierror("dir create error", 500); 282 } 270 283 271 284 include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php'); … … 275 288 276 289 $image = new pwg_image($page['src_path']); 277 278 if (!mkgetdir(dirname($page['derivative_path'])))279 {280 ierror("dir create error", 500);281 }282 290 283 291 $changes = 0; … … 326 334 { 327 335 // todo 336 $pad = $wm_size[0] + max(30, round($wm_size[0]/4)); 337 for($i=-$wm->xrepeat; $i<=$wm->xrepeat; $i++) 338 { 339 if (!$i) continue; 340 $x2 = $x + $i * $pad; 341 if ($x2>=0 && $x2+$wm_size[0]<$d_size[0]) 342 if (!$image->compose($wm_image, $x2, $y, $wm->opacity)) 343 break; 344 } 328 345 } 329 346 } -
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); -
trunk/themes/default/template/picture_content.tpl
r12855 r12865 33 33 } 34 34 {/literal}{/footer_script} 35 <a id="derivativeSwitchLink" onclick="toggleDerivativeSwitchBox()" style="cursor:pointer">{$current.selected_derivative->get_type()|@translate}</a>35 <a id="derivativeSwitchLink" href="javascript:toggleDerivativeSwitchBox()">{$current.selected_derivative->get_type()|@translate}</a> 36 36 <div id="derivativeSwitchBox" onclick="toggleDerivativeSwitchBox()" style="display:none"> 37 37 {foreach from=$current.unique_derivatives item=derivative key=derivative_type} … … 39 39 {/foreach} 40 40 {if isset($U_ORIGINAL)} 41 <a 41 <a href="javascript:phpWGOpenWindow('{$U_ORIGINAL}','xxx','scrollbars=yes,toolbar=no,status=no,resizable=yes')" title="{'Click on the photo to see it in high definition'|@translate}">{'original'|@translate}</a> 42 42 {/if} 43 43 </div> -
trunk/ws.php
r12730 r12865 70 70 'f_min_ratio' => array( 'default'=> null ), 71 71 'f_max_ratio' => array( 'default'=> null ), 72 'f_ with_thumbnail' => array( 'default'=> false),72 'f_max_level' => array( 'default'=> null ), 73 73 ), 74 74 'Returns elements for the corresponding categories. … … 86 86 ), 87 87 'retrieves a list of categories (tree_output option only compatible with json/php output format' ); 88 89 $service->addMethod('pwg.getMissingDerivatives', 'ws_getMissingDerivatives', 90 array( 91 'types' => array( 'default'=>array(), 'flags'=>WS_PARAM_FORCE_ARRAY), 92 'max_urls' => array( 'default' => 200 ), 93 'prev_page' => array( 'default'=> null), 94 'f_min_rate' => array( 'default'=> null ), 95 'f_max_rate' => array( 'default'=> null ), 96 'f_min_hit' => array( 'default'=> null ), 97 'f_max_hit' => array( 'default'=> null ), 98 'f_min_date_available' => array( 'default'=> null ), 99 'f_max_date_available' => array( 'default'=> null ), 100 'f_min_date_created' => array( 'default'=> null ), 101 'f_max_date_created' => array( 'default'=> null ), 102 'f_min_ratio' => array( 'default'=> null ), 103 'f_max_ratio' => array( 'default'=> null ), 104 'f_max_level' => array( 'default'=> null ), 105 ), 106 'retrieves a list of derivatives to build' ); 88 107 89 108 $service->addMethod('pwg.images.addComment', 'ws_images_addComment', … … 130 149 'f_min_ratio' => array( 'default'=> null ), 131 150 'f_max_ratio' => array( 'default'=> null ), 132 'f_ with_thumbnail' => array( 'default'=> false),151 'f_max_level' => array( 'default'=> null ), 133 152 ), 134 153 'Returns elements for the corresponding query search.' … … 193 212 'f_min_ratio' => array( 'default'=> null ), 194 213 'f_max_ratio' => array( 'default'=> null ), 195 'f_ with_thumbnail' => array( 'default'=> false),214 'f_max_level' => array( 'default'=> null ), 196 215 ), 197 216 'Returns elements for the corresponding tags. Note that tag_id, tag_url_name, tag_name an be arrays. Fill at least one of them. '
Note: See TracChangeset
for help on using the changeset viewer.