/[drupal]/contributions/modules/photos/photos.page.inc
ViewVC logotype

Contents of /contributions/modules/photos/photos.page.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download) (as text)
Sat Dec 20 05:49:59 2008 UTC (11 months ago) by eastcn
Branch: MAIN
CVS Tags: DRUPAL-6--1-4-BETA3, HEAD
Changes since 1.9: +6 -7 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2 // $Id: photos.page.inc,v 1.9 2008/11/30 11:07:58 eastcn Exp $
3 function photos_quote() {
4 global $user;
5 $content = '<div id="quote_title"><div class="quote_title_left">'. t('From my gallery, select the image') .'</div><div class="quote_title_right">'.l(t('Upload new image'),'photos/quote',array('query'=> array('type' => 'upload')));
6 if($_GET['type'] == 'upload'){
7 if(!_photos_num('useralbum',$user->uid)){
8 $content .= '<p>'.l(t('Please create a new album'),'node/add/photos',array('query'=>drupal_get_destination())).'</p>';
9 }else {
10 $content .= l(t('Back to'),'photos/quote').'</div></div>'.drupal_get_form('photos_upload_form');
11 }
12 }else{
13 $content .= '</div></div>'._photos_teee($user->uid);
14 }
15 echo theme('photos_quote_page', $content);
16 exit();
17 }
18 function _photos_teee($uid) {
19 $x = '<div id="photos_opalbum_form">'.drupal_get_form('_photos_opalbum_form',$uid).'</div><div class="photo-msg">'.t('Please select checkbox to get photos quoted link.').'</div>';
20 if(is_numeric($_GET['type'])){
21 $pid = $_GET['type'];
22 }
23 if(!$pid){
24 $p = _photos_sql('allimage','WHERE uid = '.$uid,50);
25 }else{
26 $p = _photos_sql('allimage','WHERE uid = '.$uid.' AND pid = '.$pid,50);
27 }
28 if($p){
29 foreach ($p as $b) {
30 $t = _photos_get_path($b->fid);
31 $title = !empty($t['title']) ? $t['title']:$t['ptitle'];
32 $x .= '<div class="photos-quote">'.l('<img src="'._photos_file_create_url($t['p1']).'">','photos/image/'.$b->fid,array('html' => true)).'<div class="photo-input"><div><input class="photos-p" type="checkbox" value="'._photos_file_create_url($t['p1']).'&&&'.$title.'&&&'.$b->fid.'" name="photos-p[]"/>'.t('Thumbnails'). '</div><input class="photos-p" type="checkbox" value="'._photos_file_create_url($t['p2']).'&&&'.$title.'&&&'.$b->fid.'" name="photos-pp[]"/>' .t('Appropriate'). '</div></div>';
33 };
34 $x .= theme('pager', NULL, 50);
35 }
36 return $x;
37 }
38 function _photos_opalbum_form(&$form_state,$uid) {
39 $form['albumselect'] = array(
40 '#type' => 'select',
41 '#options' => _photos_useralbum($uid),
42 '#default_value' => $_GET['type'],
43 );
44 $form['albumsubmit'] = array(
45 '#type' => 'submit',
46 '#value' => t('Select Album'),
47 '#submit' => array('_photos_opalbum_form_submit'),
48 );
49 $form['insert'] = array('#type' => 'textarea','#cols' => 250, '#rows' => 6);
50 return $form;
51 }
52 function _photos_opalbum_form_submit($form, &$form_state) {
53 $u = $form_state['values']['albumselect'];
54 drupal_goto('photos/quote',array('type' => $u));
55 }
56 function photos_test_page() {
57 drupal_goto('photos/album');
58 }
59
60 function photos_image_flash($node){
61 if($node->album['count'] || $node->photos['count']){
62 $output = '<div class="album-a ">'.l(t('« Back to album'),"node/$node->nid").(variable_get('photos_flash', 0) ? l(t('Flash View image'),"node/$node->nid/photos/view/flash"):NULL).(node_access('update',$node) ? l(t('Organize images'),"node/$node->nid/photos"):NULL).'</div>';
63 if($node->album['count']){
64 $bmb = t('A total of %num images',array('%num' => $node->album['count']));
65 }else{
66 $bmb = t('A total of %num images',array('%num' => $node->photos['count']));
67 }
68 switch (arg(4)){
69 case 'flash':
70 if(variable_get('photos_flash', 0)){
71 $xml = url("node/$node->nid/photos/view/xml");
72 $output = _photos_flash_swf($xml);
73 $title = t('Flash View image: ').$node->title;
74 }
75 break;
76 case 'xml':
77 if(variable_get('photos_flash', 0)){
78 if($node->type == 'photos'){
79 $result = db_query('SELECT fid FROM {x_image} WHERE pid = %d ORDER BY fid DESC',$node->nid);
80 }else{
81 $result = db_query('SELECT fid FROM {x_image} WHERE nid = %d ORDER BY fid DESC',$node->nid);
82 }
83 $b['title'] = t('!name\'s album',array('!name' => $node->name));
84 while ($a = db_fetch_object($result)){
85 $fid[] = $a->fid;
86 }
87 if($fid){
88 $b['xml'] = _photos_flash_xml($fid, $node->title, $node->teaser);
89 }
90 echo theme('photos_flash', $b);
91 return;
92 }
93 break;
94 default:
95 drupal_goto("node/$node->nid/photos/view/flash");
96 break;
97 }
98 drupal_set_title($title);
99 drupal_set_breadcrumb(array(l(t('Home'),NULL),l($node->title,'node/'.$node->nid),$bmb));
100 }else{
101 drupal_not_found();
102 }
103 return $output;
104 }
105
106 function _photos_flash_swf($xml) {
107 $swf = base_path() . drupal_get_path('module', 'photos').'/flash_gallery/gallery.swf';
108 if(variable_get('photos_flash_zoom', '500x450')){
109 $t = split('x',variable_get('photos_flash_zoom', '500x450'));
110 $width = $t['0'];
111 $height = $t['1'];
112 }else{
113 $width = 500;
114 $height = 450;
115 }
116 $output .= <<<EOT
117 <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"
118 width="$width" height="$height">
119 <param name="allowFullScreen" value="true" />
120 <param name="movie" value="$swf" />
121 <param name="quality" value="best" />
122 <param name="FlashVars" value="xmlFile=$xml" />
123 <embed src="$swf" quality="best" scale="noscale" width="$width" height="$height" FlashVars="xmlFile=$xml" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
124 </object>
125 EOT;
126 return $output;
127 }
128
129 function _photos_flash_xml($fid = array(), $title, $description){
130 $b = '<album title="'.$title.'" description="'.drupal_substr(strip_tags($description), 0, 100).'">';
131 if($fid){
132 foreach ($fid as $a){
133 $x = _photos_get_path($a);
134 $it = image_get_info($x['p']);
135 if(variable_get('photos_flash_show', 0)){
136 $showurl = $x['p'];
137 }else{
138 $showurl = $x['p2'];
139 }
140 if($it['extension'] != 'png'){
141 $b .= '<image title="'.$x['ptitle'].'" date="'.$x['time'].'" thumbnail="'._photos_file_create_url($x['p1']).'" image="'._photos_file_create_url($showurl).'" link="'.url('photos/image/'.$a).'"><![CDATA['.$x['des'].']]> </image>';
142 }else {
143 $b .= '<image title="'.$x['ptitle'].'" date="'.$x['time'].'" thumbnail="'.$GLOBALS['base_url'].'/photos/tools/tojpg/'.$a.'/tt" image="'.$GLOBALS['base_url'].'/photos/tools/tojpg/'.$a.'/t" link="'.url('photos/image/'.$a).'"><![CDATA['.$x['des'].']]> </image>';
144 }
145 }
146 }
147 $b .= '</album>';
148 return $b;
149 }
150 //单张图片编辑表单
151 function photos_desedit(&$form_state,$edit){
152 $form['des'] = array('#type' => 'textarea','#default_value' => '','#cols' => 40, '#rows' => 3);
153 $form['uid'] = array('#type' => 'value','#value' => $edit['uid']);
154 $form['del'] = array(
155 '#title' => t('delete'),
156 '#type' => 'checkbox',
157 );
158 $form['wid'] = array(
159 '#title' => t('weight'),
160 '#type' => 'weight',
161 '#default_value' => $edit['wid'],
162 );
163 $form['fid'] = array(
164 '#type' => 'value',
165 '#default_value' => $edit['fid'],
166 );
167 $form['submit'] = array(
168 '#type' => 'submit',
169 '#value' => t('Confirm the change'),
170 '#submit' => array('photos_desedit_submit'),
171 );
172 $form['editnone'] = array(
173 '#type' => 'button',
174 '#value' => t('Cancel').$edit['pid'],
175 );
176 return $form;
177 }
178
179 //单张图片编辑提交处理
180 function photos_desedit_submit($form, &$form_state) {
181 global $user;
182 if (!empty($form_state['values']['del'])) {
183 _photos_file_del($$form_state['values']['fid']);
184 $t = db_query('DELETE FROM {x_image} WHERE fid = %d',$form_state['values']['fid']);
185 if($t){
186 $a = t('Delete success');
187 }else{
188 $a = t('Failure to delete');
189 }
190 drupal_set_message($a);
191 drupal_goto('photos/user/image/'.$form_state['values']['uid']);
192 }else{
193 $t = db_query("UPDATE {x_image} SET des = '%s', wid = %d WHERE fid = %d", $form_state['values']['des'], $form_state['values']['wid'], $form_state['values']['fid']);
194 if($t){
195 $a = t('Laws success');
196 }else{
197 $a = t('Laws failure');
198 }
199 drupal_set_message($a);
200 }
201 }
202
203 function photos_allimage_page($sql,$num){
204 $a = _photos_sql('allimage',$sql,$num);
205 if($a){
206 $output = '<div id="album-node" class="photos-a">';
207 foreach ($a as $b) {
208 $output .= photos_view_image($b->fid,'all');
209 };
210 $output .= '</div>'.theme('pager', NULL, $num);
211 }else{
212 $output .= '';
213 }
214 return $output;
215 }
216
217 function photos_image_pageone(){
218 global $user;
219 if(is_numeric(arg(2))){
220 $p = _photos_get_path(arg(2));
221 if($p){
222 if(arg(1)=='image'){
223 switch (arg(3)){
224 case 'vote':
225 if(user_access('allowed to vote')){
226 if(arg(4) == 'up'){
227 $value = 1;
228 }elseif (arg(4) == 'down'){
229 $value = -1;
230 }else {
231 return false;
232 }
233 $fid = arg(2);
234 $vote = array('content_type' => 'image', 'content_id' => $fid, 'tag' => 'vote', 'value_type' => 'points', 'uid' => $user->uid, 'value' => $value);
235 $t = votingapi_set_votes($vote);
236 $x = $t['image'][$fid]['2']['value'].','.$t['image'][$fid]['0']['value'];
237 if($_GET['destination']){
238 return drupal_goto();
239 }else {
240 echo $x;
241 exit();
242 }
243 }
244 return;
245 break;
246 default:
247 if(!variable_get('photos_image_count', 0)){
248 db_query('UPDATE {x_image} SET count = count + 1 WHERE fid = %d', arg(2));
249 }
250 $output = photos_view_image(arg(2),'');
251 break;
252 }
253 }else{
254 if($p['pid']) { $pid = l(t('Back to album'),'node/'.$p['pid']);}
255 $output = '<div class="photo-zoom">'.l(t('Original Size'),'photos/zoom/'.arg(2)).l(t('Moderate size'),'photos/zoom/'.arg(2).'/2').l(t('Thumbnails'),'photos/zoom/'.arg(2).'/1').(variable_get('photos_vote', 0) && user_access('view vote list') ? l(t('Vote list'),'photos/zoom/'.arg(2).'/vote'):NULL).(variable_get('photos_exif', 0) ? l(t('Show EXIF'),'photos/zoom/'.arg(2).'/exif'):NULL).$pid.l(t('Back to image'),'photos/image/'.arg(2)).'</div>';
256 $photolink = '<div class="photo-zoom">' .t('Photo html: '). '<input type="text" value=\'<a title="'.$p["des"].'" href="'._photos_file_create_url('photos/image/'.arg(2)).'"><img src="'._photos_file_create_url($p['p'.arg(3)]).'" /></a>\' size="100" class="image-quote-link"><p>' .t('Photo link: '). '<input type="text" value="'._photos_file_create_url($p['p'.arg(3)]).'" size="100" class="image-quote-link"></p></div>';
257 switch (arg(3)) {
258 case '1':
259 $output .= $photolink.'<img src="'._photos_file_create_url($p['p1']).'">';
260 break;
261 case '2':
262 $output .= $photolink.'<img src="'._photos_file_create_url($p['p2']).'">';
263 break;
264 case 'vote':
265 if(!user_access('view vote list')){
266 drupal_not_found();
267 }
268 $header = array(
269 array('data' => t('Vote user'),'align'=> 'center'),
270 array('data' => t('Vote result'),'align'=> 'center'),
271 array('data' => t('Vote time'),'align'=> 'center'),
272 );
273 $fid = arg(2);
274 $rows = array();
275 $result = pager_query('SELECT v.uid, u.name, v.value, v.timestamp, v.vote_source FROM {votingapi_vote} v LEFT JOIN {users} u ON u.uid = v.uid WHERE content_type = \'image\' AND content_id = '. $fid . tablesort_sql($header), 30, 0);
276 while ($a = db_fetch_object($result)){
277 if($a->uid != 0){
278 $name = theme('username', $a);
279 }else{
280 $name = $a->vote_source;
281 }
282 $rows[] = array(
283 $name,
284 $a->value,
285 format_date($a->timestamp,'small')
286 );
287 }
288 if (empty($rows)) {
289 $rows[] = array(array('data' => t('No vote available.'), 'colspan' => 3));
290 }
291 $output .= theme('table', $header, $rows);
292 $output .= theme('pager', NULL, 30, 0);
293 drupal_set_title(t('See a image vote'));
294 break;
295 case 'exif':
296 $output .= _photos_getexif(_photos_file_create_url($p['p']));
297 drupal_set_title(t('See a image exif'));
298 break;
299 default:
300 $output .= $photolink.'<img src="'._photos_file_create_url($p['p']).'">';
301 if (variable_get('photos_open_orig', 0)) {
302 echo theme('photos_quote_page', $output);
303 exit();
304 }
305 break;
306 }
307 }
308 }else{
309 return drupal_not_found();
310 }
311 }else{
312 return drupal_not_found();
313 }
314 return $output;
315 }
316
317 function _photos_image_tools() {
318 $p = _photos_get_path(arg(3));
319 if($p){
320 header("Content-type: image/jpeg");
321 if(arg(4)=='t'){
322 $im = @imagecreatefrompng($p['p2']);
323 }elseif(arg(4)=='tt'){
324 $im = @imagecreatefrompng($p['p1']);
325 }else{
326 $im = @imagecreatefrompng($p['p']);
327 }
328 echo imagejpeg($im, '', 100);
329 exit();
330 }else{
331 drupal_not_found();
332 }
333 }
334 function photos_user_image_page(){
335 $a = _photos_num('image');
336 if($a){
337 $output = '<div class="album-a">'.t('A total of !img image, !num albums',array('!num' => _photos_num('album'),'!img' => $a)) . l(t('View albums'),'photos/album').'</div>';
338 $output .= photos_allimage_page('',50);
339 }else{
340 $output .= t('No image').l(t('Create a album'),'node/add/photos').l(t('Upload a image'),'photos/upload');
341 }
342 return $output;
343 }
344
345 function photos_user_album_page($a = false) {
346 global $user;
347 if(arg(1)=='album'){
348 $b = _photos_sql('album','',10);
349 if($b){
350 $output = '<div class="album-a">'.t('A total of !num albums, !img image',array('!num' => _photos_num('album'),'!img' => _photos_num('image'))) . l(t('View images'),'photos/image').'</div>';
351 foreach ($b as $c){
352 $node = node_load($c->pid);
353 if(!$node->album['privacy'] || $user->uid == $node->uid){
354 $output .= photos_album_view($node);
355 }
356 };
357 $output .= theme('pager', NULL, 10);
358 }else{
359 $output .= t('No album').l(t('Create a album'),'node/add/photos').l(t('Upload a image'),'photos/upload');
360 }
361 }elseif($a->uid){
362 if($a){
363 $menu = '<div class="album-a">'.t('A total of !num albums, !img image',array('!num' => $a->photos['album'],'!img' => $a->photos['image'])). l(t('View albums'),'photos/user/album/'.$a->uid) . l(t('View images'),'photos/user/image/'.$a->uid) . (variable_get('photos_flash', 0) ? l(t('Flash View image'), 'photos/user/flash/'.$a->uid): NULL).'</div>';
364 $output = '';
365 switch (arg(2)) {
366 case 'image':
367 $bread = l(t('Image'),'photos/image');
368 if($user->uid == $a->uid){
369 $title = t('My image');
370 }else{
371 $title = t('!name\'s image',array('!name' => $a->name));
372 }
373 $x = photos_allimage_page('WHERE uid = '.$a->uid, 50);
374 if($x){
375 $output = $menu;
376 }else{
377 $output .= t('No image').l(t('Create a album'),'node/add/photos').l(t('Upload a image'),'photos/upload');
378 }
379 $output .= $x;
380 break;
381 case 'album':
382 $bread = l(t('Album'),'photos/album');
383 if($user->uid == $a->uid){
384 $title = t('My Album');
385 }else{
386 $title = t('!name\'s Album',array('!name' => $a->name));
387 }
388 $b = _photos_sql('album','WHERE uid = '.$a->uid,10);
389 if($b){
390 $output = $menu;
391 foreach ($b as $c){
392 $node = node_load($c->pid);
393 $output .= photos_album_view($node,'album');
394 };
395 $output .= theme('pager', NULL, 10);
396 }else{
397 $output = '<div class="album-a">'.t('No album').l(t('Create a album'),'node/add/photos').l(t('Upload a image'),'photos/upload').'</div>';
398 }
399
400 break;
401 case 'flash':
402 if(variable_get('photos_flash', 0)){
403 if(arg(4)=='xml'){
404 $result = db_query('SELECT pid FROM {x_album} WHERE uid = %d ORDER BY pid DESC',$a->uid);
405 $i = 0;
406 while ($n = db_fetch_object($result)){
407 $node = node_load($n->pid);
408 $result1 = db_query('SELECT fid FROM {x_image} WHERE pid = %d ORDER BY fid DESC',$n->pid);
409 while ($f = db_fetch_object($result1)){
410 $fid[$i][] = $f->fid;
411 }
412 if($fid[$i]){
413 $xml .= _photos_flash_xml($fid[$i], $node->title, $node->teaser);
414 }
415 $i++;
416 }
417 $b['xml'] = $xml;
418 $b['title'] = t('!name\'s album',array('!name' => $a->name));
419 echo theme('photos_flash', $b);
420 return;
421 }else{
422 $bread = l(t('Album'),'photos/album');
423 if($user->uid == $a->uid){
424 $title = t('My flash');
425 }else{
426 $title = t('!name\'s flash',array('!name' => $a->name));
427 }
428 $xml = url("photos/user/flash/$a->uid/xml");
429 $output .= $menu . _photos_flash_swf($xml);
430 }
431 }
432 break;
433 }
434 drupal_set_title($title);
435 drupal_set_breadcrumb(array(l(t('Home'),NULL),$bread,drupal_get_title()));
436 }
437 }else{
438 drupal_not_found();
439 }
440
441 return $output;
442 }
443
444 function photos_album_upload() {
445 global $user;
446 if(!_photos_num('useralbum',$user->uid)){
447 return '<h2>'.l(t('Please create a new album'),'node/add/photos',array('query'=>drupal_get_destination())).'</h2>';
448 }
449 $t = drupal_get_form('photos_upload_form');
450 return $t;
451 }
452 function photos_album_view($node) {
453 global $user;
454 $node->titlelink = l(check_plain($node->title),'node/'.$node->nid);
455 $node->time = format_date($node->created, 'small');
456 if(_photos_access('edit',$node->uid)){
457 $node->albumlink .= l(t('Organize images'),'node/'.$node->nid.'/photos').l(t('Edit album'),'node/'.$node->nid.'/edit',array('query'=>drupal_get_destination()));
458 }
459 $node->albumlink .= l(t('View album'),'node/'.$node->nid);
460 if(variable_get('photos_flash', 0) && $node->album['count']){
461 $node->albumlink .= l(t('Flash View album'),"node/$node->nid/photos/view/flash");
462 }
463 return theme('photos_albumview',$node);
464 }
465
466 //图片管理
467 function photos_node_edit($node){
468 if(arg(3) == 'setcover'){
469 $setfid = arg(4);
470 $u = _photos_get_path($setfid);
471 if($u['uid'] == $node->uid && node_access('update',$node)){
472 $fid = $node->album['fid'];
473 if($fid){
474 $del = db_result(db_query('SELECT fid FROM {x_image} WHERE fid = %d', $fid));
475 if(!$del){
476 _photos_file_del($fid,'album');
477 }
478 }
479 db_query("UPDATE {x_album} SET fid = %d WHERE pid = %d",$setfid, $node->nid);
480 drupal_set_message(t('Cover successfully set.'));
481 return drupal_goto();
482 }else{
483 return drupal_not_found();
484 }
485 }
486 $output = '<div class="album-a ">'.l(t('« Back to'),"node/$node->nid").(variable_get('photos_flash', 0) ? l(t('Flash View image'),"node/$node->nid/photos/view/flash"):NULL).(node_access('update',$node) ? l(t('Organize images'),"node/$node->nid/photos"):NULL).'</div>';
487 if (variable_get('photos_'.$node->type, false)){
488 $output .= t('You are in management article !title image. A total of !num images. ',array('!title' => $node->title, '!num' => $node->photos['count']));
489 }elseif($node->album['pid']){
490 $output .= t('You are in management album !title image. A total of !num images. ',array('!title' => $node->title, '!num' => $node->album['count']));
491 }else{
492 drupal_not_found();
493 return;
494 }
495 drupal_set_title(t('Organize images: ').$node->title);
496 drupal_set_breadcrumb(array(l(t('Home'), NULL),l($node->title,'node/'.$node->nid),drupal_get_title()));
497 $output .= '<div id="photos_upload_new">'.drupal_get_form('photos_upload_form',$node).'</div>';
498 if($node->album['count'] || $node->photos['count']){
499 $output .= drupal_get_form('photos_editlist');
500 }
501 return $output;
502
503 }
504 //站点图片管理
505 function photos_admin_edit(){
506 $output = '';
507 $output .= drupal_get_form('photos_editlist');
508 return $output;
509 }
510
511 function photos_admin_import(){
512 global $user;
513 $info = _photos_upload_info();
514 $form['new']['unzip'] = array(
515 '#title' => t('Import zip'),
516 '#type' => 'textfield',
517 '#description' => t('From the server directory into zip files, to extract. You can upload images to a directory server, enter here path, you can extract and add to the album phtos. Path such as: !zip/test.zip. Documents must be read and write, php can operate.',array('!zip'=>$info['p'])),
518 '#weight' => -3,
519 );
520
521 $form['new']['pid'] = array(
522 '#title' => t('Upload to album'),
523 '#type' => 'select',
524 '#options' => _photos_useralbum($user->uid),
525 '#default_value' => $_GET['pid'],
526 '#required' => TRUE,
527 '#description' => '<p><strong>'.l(t('You may create a new album'),'node/add/photos',array('query'=>drupal_get_destination())).'</strong></p>',
528 '#weight' => -5,
529 );
530
531 $form['new']['submit'] = array(
532 '#type' => 'submit',
533 '#value' => t('Confirm upload'),
534 '#weight' => -2,
535 '#submit' => array('photos_upload_form_submit'),
536 );
537 $n->uid = $user->uid;
538 $form['date'] = array('#type' => 'value','#value' => $n);
539 $form['#attributes']['enctype'] = 'multipart/form-data';
540
541 return $form;
542 }
543
544 function photos_editlist() {
545 $form['photos']['#theme'] = 'photos_editlist_x';
546 $form['photos']['#tree'] = true;
547 $paging = '';
548 if (isset($_GET['page'])) {
549 $paging = '&page=' . intval($_GET['page']);
550 }
551 $form['#action'] = url($_GET['q'], array('query' => drupal_get_destination(). $paging));
552 if(arg(1)=='admin'){
553 $a = _photos_sql('node','f.status = 1',10);
554 }else{
555 $node = node_load(arg(1));
556 if($node->type == 'photos'){
557 $a = _photos_sql('node','i.pid = '.$node->nid,10);
558 $albumfid = $node->album['fid'];
559 }else{
560 $a = _photos_sql('node','i.nid = '.$node->nid,10);
561 }
562 }
563 if($a){
564 foreach ($a as $img) {
565 $fid = $img->fid;
566 if($node->type == 'photos'){
567 if($img->nid){
568 $tn = node_load($img->nid);
569 $title = t('Uploaded to the article ').l($tn->title,'node/'.$tn->nid);
570 }
571 }elseif($img->pid){
572 $tn = node_load($img->pid);
573 $albumfid = $tn->album['fid'];
574 $title = t('Categories in the album ').l($tn->title,'node/'.$tn->nid);
575 }
576 if($fid != $albumfid){
577 $setcover = l(t('Is set to album cover. '),"node/$img->pid/photos/setcover/$fid", array('query' => drupal_get_destination()));
578 }else{
579 $setcover = false;
580 }
581 $p = _photos_get_path($fid);
582 $form['photos'][$fid]['del'] = array('#type' => 'checkbox');
583 $form['photos'][$fid]['path'] = array('#value' => l('<img src="'._photos_file_create_url($p['p1']).'">','photos/image/'.$fid,array('html'=>true)));
584 $form['photos'][$fid]['des'] = array('#type' => 'textarea','#default_value' => $img->des,'#cols' => 40, '#rows' => 4);
585 $form['photos'][$fid]['time'] = array('#value' => $setcover.t('Upload the images in ').format_date($img->timestamp, 'small').'。'.$title);
586 $form['photos'][$fid]['wid'] = array('#type' => 'weight','#default_value' => $img->wid,);
587 $form['photos'][$fid]['pid'] = array(
588 '#type' => 'select',
589 '#options' => _photos_useralbum($img->uid),
590 '#default_value' => $img->pid,
591 '#required' => TRUE,
592 );
593 $form['photos'][$fid]['oldpid'] = array('#type' => 'value', '#value' => $img->pid);
594 $form['photos'][$fid]['uid'] = array('#type' => 'value', '#value' => $img->uid);
595 };
596 }
597 $form['allck'] = array('#value' =>'<a class="allck" href="javascript:void(0)">'.t('Select All').'</a> | <a class="allnone" href="javascript:void(0)">' .t('Deselect'). '</a>');
598 $form['submit'] = array(
599 '#type' => 'submit',
600 '#value' => t('Confirm the change'),
601 '#submit' => array('photos_editlist_submit'),
602 );
603 return $form;
604 }
605
606 function photos_editlist_submit($form, &$form_state) {
607 global $user;
608 foreach($form_state['values']['photos'] as $fid => $key) {
609 if (!empty($key['del'])) {
610 _photos_file_del($fid);
611 db_query('DELETE FROM {x_image} WHERE fid = %d',$fid);
612 db_query('DELETE FROM {x_vote} WHERE fid = %d', $fid);
613 db_query('DELETE FROM {comments} WHERE cid IN (SELECT cid FROM {x_vote} WHERE fid = %d)', $fid);
614 _comment_update_node_statistics($key['pid']);
615 }else{
616 db_query("UPDATE {x_image} SET pid = %d, des = '%s', wid = %d WHERE fid = %d", $key['pid'],$key['des'], $key['wid'], $fid);
617 if ($key['pid'] != $key['oldpid']) {
618 db_query('UPDATE {comments} SET nid = %d WHERE cid IN (SELECT cid FROM {x_vote} WHERE fid = %d)', $key['pid'], $fid);
619 _comment_update_node_statistics($key['pid']);
620 _comment_update_node_statistics($key['oldpid']);
621 }
622 }
623 }
624 }
625
626 function theme_photos_editlist_x($form) {
627 $node = node_load(arg(1));
628 if($node->type == 'photos'){
629 $title = t('Move to the album');
630 }else{
631 $title = t('His album');
632 }
633 $header = array(
634 array('data' => t('Delete'),'align'=> 'center','width' => 60),
635 array('data' => t('Thumbnails'),'align'=> 'center','width' => 120),
636 array('data' => t('Description'),'align'=> 'center'),
637 array('data' => $title,'align'=> 'center'),
638 array('data' => t('Weight'),'align'=> 'center','width' => 60)
639 );
640 if(!empty($node->photos['count']) || !empty($node->album['count']) || _photos_num('album')){
641 foreach (element_children($form) as $key) {
642 $row = array();
643 $row[] = drupal_render($form[$key]['del']);
644 $row[] = drupal_render($form[$key]['path']);
645 $row[] = drupal_render($form[$key]['des']);
646 $row[] = drupal_render($form[$key]['pid']);
647 $row[] = drupal_render($form[$key]['wid']);
648 $rows[] = $row;
649 $rows[] = array(array('data' => drupal_render($form[$key]['time']), 'class'=> 'photos-des','colspan' => '5'));
650 }
651 }else {
652 $rows[] = array(array('data' => t('No image'), 'colspan' => '5'));
653 }
654
655 $output = theme('table', $header, $rows,array('id'=>'imagesedit'));
656 $output .= theme('pager', NULL, 10, 0);
657 $output .= drupal_render($form['allck']);
658 $output .= drupal_render($form['submit']);
659
660 return $output;
661 }
662 //comment
663 function photos_vote_comment($fid,$con = false){
664 global $user;
665 $t = db_result(db_query('SELECT count(fid) FROM {x_vote} WHERE fid = '.$fid));
666 if(!$t){ return false;}
667 $output = '';
668 if($con){
669 $output = $t;
670 }elseif(module_exists('comment')) {
671 if (user_access('access comments')) {
672 $node->type = 'photos';
673 $mode = _comment_get_display_setting('mode', $node);
674 $order = _comment_get_display_setting('sort', $node);
675 $comments_per_page = _comment_get_display_setting('comments_per_page', $node);
676 //$query_count = $t;
677 $query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.picture, u.data, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid INNER JOIN {x_vote} x ON c.cid = x.cid WHERE x.fid = %d';
678
679 $query_args = array($fid);
680 if (!user_access('administer comments')) {
681 $query .= ' AND c.status = %d';
682 //$query_count .= ' AND c.status = %d';
683 $query_args[] = COMMENT_PUBLISHED;
684 }
685
686 if ($order == COMMENT_ORDER_NEWEST_FIRST) {
687 if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
688 $query .= ' ORDER BY c.cid DESC';
689 }else {
690 $query .= ' ORDER BY c.thread DESC';
691 }
692 }else if ($order == COMMENT_ORDER_OLDEST_FIRST) {
693 if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
694 $query .= ' ORDER BY c.cid';
695 }else {
696 $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))';
697 }
698 }
699 $query = db_rewrite_sql($query, 'c', 'cid');
700 //$query_count = db_rewrite_sql($query_count, 'c', 'cid');
701
702 $result = pager_query($query, $comments_per_page, 0, NULL, $query_args);
703
704 $divs = 0;
705 $num_rows = FALSE;
706 $comments = '';
707 drupal_add_css(drupal_get_path('module', 'comment') .'/comment.css');
708 while ($comment = db_fetch_object($result)) {
709 $comment = drupal_unpack($comment);
710 $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
711 $comment->depth = count(explode('.', $comment->thread)) - 1;
712
713 if ($mode == COMMENT_MODE_THREADED_COLLAPSED || $mode == COMMENT_MODE_THREADED_EXPANDED) {
714 if ($comment->depth > $divs) {
715 $divs++;
716 $comments .= '<div class="indented">';
717 }
718 else {
719 while ($comment->depth < $divs) {
720 $divs--;
721 $comments .= '</div>';
722 }
723 }
724 }
725 if(user_access('administer comments')){
726 $links['comment_delete'] = array(
727 'title' => t('delete'),
728 'href' => "comment/delete/$comment->cid",
729 'query' => drupal_get_destination()
730 );
731 $links['comment_edit'] = array(
732 'title' => t('edit'),
733 'href' => "comment/edit/$comment->cid",
734 'query' => drupal_get_destination()
735 );
736 }
737 if(user_access('post comments')){
738 $links['comment_reply'] = array(
739 'title' => t('reply'),
740 'href' => "comment/reply/$comment->nid/$comment->cid",
741 'query' => array('fid' => $fid)
742 );
743 }
744
745 if ($mode == COMMENT_MODE_FLAT_COLLAPSED) {
746 $comments .= theme('comment_flat_collapsed', $comment, $node);
747 }else if ($mode == COMMENT_MODE_FLAT_EXPANDED) {
748 //$comments .= theme('comment_flat_expanded', $comment, $node);
749 $comments .= theme('comment_view', $comment, $node, $links);
750 }else if ($mode == COMMENT_MODE_THREADED_COLLAPSED) {
751 $comments .= theme('comment_thread_collapsed', $comment, $node);
752 }else if ($mode == COMMENT_MODE_THREADED_EXPANDED) {
753 //$comments .= theme('comment_thread_expanded', $comment, $node);
754 $comments .= theme('comment_view', $comment, $node, $links);
755 }
756 $num_rows = TRUE;
757 }
758 while ($divs-- > 0) {
759 $comments .= '</div>';
760 }
761
762 $comment_controls = variable_get('comment_controls_'. $node->type, COMMENT_CONTROLS_HIDDEN);
763 if ($num_rows && ($comment_controls == COMMENT_CONTROLS_ABOVE || $comment_controls == COMMENT_CONTROLS_ABOVE_BELOW)) {
764 $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
765 }
766
767 $output .= $comments;
768 $output .= theme('pager', NULL, $comments_per_page, 0);
769
770 if ($num_rows && ($comment_controls == COMMENT_CONTROLS_BELOW || $comment_controls == COMMENT_CONTROLS_ABOVE_BELOW)) {
771 $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
772 }
773 }
774 $output = theme('comment_wrapper', $output, $node);
775 }
776 return $output;
777 }
778 //
779 function _photos_getval($ImageInfo,$val_arr) {
780 $InfoVal = t('Unknown');
781 foreach($val_arr as $name=>$val) {
782 if ($name==$ImageInfo) {
783 $InfoVal = &$val;
784 break;
785 }
786 }
787 return $InfoVal;
788 }
789
790 function _photos_getexif($img, $type = false, $url = false) {
791 $imgtype = array('', 'GIF', 'JPG', 'PNG', 'SWF', 'PSD', 'BMP', 'TIFF(intel byte order)', 'TIFF(motorola byte order)', 'JPC', 'JP2', 'JPX', 'JB2', 'SWC', 'IFF', 'WBMP', 'XBM');
792 $Orientation = array('', t('top left side'), t('top right side'), t('bottom right side'), t('bottom left side'), t('left side top'), t('right side top'), t('right side bottom'), t('left side bottom'));
793 $ResolutionUnit = array('', '', t('inches'), t('centimeters'));
794 $YCbCrPositioning = array('', t('the center of pixel array'), t('the datum point'));
795 $ExposureProgram = array(t('Not defined'), t('Manual'), t('Normal program'), t('Aperture priority'), t('Shutter priority'), t('Creative program (biased toward depth of field)'), t('Action program (biased toward fast shutter speed)'), t('Portrait mode (for closeup photos with the background out of focus)'), t('Landscape mode (for landscape photos with the background in focus)'));
796 $MeteringMode_arr = array(
797 '0' => t('unknown'),
798 '1' => t('Average'),
799 '2' => t('CenterWeightedAverage'),
800 '3' => t('Spot'),
801 '4' => t('MultiSpot'),
802 '5' => t('Pattern'),
803 '6' => t('Partial'),
804 '255' => t('other')
805 );
806 $Lightsource_arr = array(
807 '0' => t('unknown'),
808 '1' => t('Daylight'),
809 '2' => t('Fluorescent'),
810 '3' => t('Tungsten (incandescent light)'),
811 '4' => t('Flash'),
812 '9' => t('Fine weather'),
813 '10' => t('Cloudy weather'),
814 '12' => t('Daylight fluorescent (D 5700 – 7100K)'),
815 '13' => t('Day white fluorescent (N 4600 – 5400K)'),
816 '14' => t('Cool white fluorescent (W 3900 – 4500K)'),
817 '15' => t('White fluorescent (WW 3200 – 3700K)'),
818 '17' => t('Standard light A'),
819 '18' => t('Standard light B'),
820 '19' => t('Standard light C'),
821 '20' => 'D55',
822 '21' => 'D65',
823 '22' => 'D75',
824 '23' => 'D50',
825 '24' => t('ISO studio tungsten'),
826 '255' => t('other light source')
827 );
828 $Flash_arr = array(
829 '0' => t('Flash did not fire.'),
830 '1' => t('Flash fired.'),
831 '5' => t('Strobe return light not detected.'),
832 '7' => t('Strobe return light detected.'),
833 '9' => t('Flash fired, compulsory flash mode'),
834 '13' => t('Flash fired, compulsory flash mode, return light not detected'),
835 '15' => t('Flash fired, compulsory flash mode, return light detected'),
836 '16' => t('Flash did not fire, compulsory flash mode'),
837 '24' => t('Flash did not fire, auto mode'),
838 '25' => t('Flash fired, auto mode'),
839 '29' => t('Flash fired, auto mode, return light not detected'),
840 '31' => t('Flash fired, auto mode, return light detected'),
841 '32' => t('No flash function'),
842 '65' => t('Flash fired, red-eye reduction mode'),
843 '69' => t('Flash fired, red-eye reduction mode, return light not detected'),
844 '71' => t('Flash fired, red-eye reduction mode, return light detected'),
845 '73' => t('Flash fired, compulsory flash mode, red-eye reduction mode'),
846 '77' => t('Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected'),
847 '79' => t('Flash fired, compulsory flash mode, red-eye reduction mode, return light detected'),
848 '89' => t('Flash fired, auto mode, red-eye reduction mode'),
849 '93' => t('Flash fired, auto mode, return light not detected, red-eye reduction mode'),
850 '95' => t('Flash fired, auto mode, return light detected, red-eye reduction mode')
851 );
852
853 $exif = @exif_read_data ($img,'IFD0');
854 if ($exif) {
855 $exif = @exif_read_data($img,0,true);
856 if($type == 't'){
857 $new_img_info = array (
858 'Artist' => $exif[IFD0][Artist],
859 'FileType' => $imgtype[$exif[FILE][FileType]],
860 'MimeType' => $exif[FILE][MimeType],
861 'FileSize' => (floor($exif[FILE][FileSize] / 1024 * 10 )/10).'KB',
862 'FileDateTime' => date('Y:m:d H:i:s',$exif[FILE][FileDateTime]),
863 'Make' => $exif[IFD0][Make],
864 'Model' => $exif[IFD0][Model],
865 'DateTime' => $exif[IFD0][DateTime],
866 'ExifVersion' => $exif[EXIF][ExifVersion],
867 'DateTimeOriginal' => $exif[EXIF][DateTimeOriginal],
868 'DateTimeDigitized' => $exif[EXIF][DateTimeDigitized],
869 'Height' => $exif[COMPUTED][Height].'px',
870 'Width' => $exif[COMPUTED][Width].'px',
871 'CompressedBitsPerPixel' => $exif[EXIF][CompressedBitsPerPixel].'Bits/Pixel',
872 'FocusDistance' => !empty($exif[COMPUTED][FocusDistance]) ? $exif[COMPUTED][FocusDistance].'m':NULL,
873 'FocalLength' => !empty($exif[EXIF][FocalLength]) ? $exif[EXIF][FocalLength].'mm':NULL,
874 'FocalLengthIn35mmFilm' => !empty($exif[EXIF][FocalLengthIn35mmFilm]) ? $exif[EXIF][FocalLengthIn35mmFilm].'mm':NULL,
875 'ColorSpace' => ($exif[EXIF][ColorSpace]==1?'sRGB':'Uncalibrated'),
876 );
877 $more = l(t('Show details'),$url);
878 }else{
879 $new_img_info = array (
880 'FileName' => $exif[FILE][FileName],
881 'FileType' => $imgtype[$exif[FILE][FileType]],
882 'MimeType' => $exif[FILE][MimeType],
883 'FileSize' => (floor($exif[FILE][FileSize] / 1024 * 10 )/10).'KB',
884 'FileDateTime' => date('Y-m-d H:i:s',$exif[FILE][FileDateTime]),
885 'ImageDescription' => $exif[IFD0][ImageDescription],
886 'Make' => $exif[IFD0][Make],
887 'Model' => $exif[IFD0][Model],
888 'Orientation' => $Orientation[$exif[IFD0][Orientation]],
889 'XResolution' => $exif[IFD0][XResolution].$ResolutionUnit[$exif[IFD0][ResolutionUnit]],
890 'YResolution' => $exif[IFD0][YResolution].$ResolutionUnit[$exif[IFD0][ResolutionUnit]],
891 'Software' => drupal_convert_to_utf8($exif[IFD0][Software],'gbk'),
892 'DateTime' => $exif[IFD0][DateTime],
893 'Artist' => $exif[IFD0][Artist],
894 'YCbCrPositioning' => $YCbCrPositioning[$exif[IFD0][YCbCrPositioning]],
895 'Copyright' => $exif[IFD0][Copyright],
896 'Photographer' => $exif[COMPUTED][Copyright.Photographer],
897 'Editor' => $exif[COMPUTE