Parent Directory
|
Revision Log
|
Revision Graph
*** empty log message ***
| 1 | <?php |
| 2 | // $Id: photos.module,v 1.12 2008/10/09 06:49:14 eastcn Exp $ |
| 3 | |
| 4 | function photos_node_info() { |
| 5 | return array( |
| 6 | 'photos' => array( |
| 7 | 'name' => t('Album'), |
| 8 | 'module' => 'photos', |
| 9 | 'has_title' => true, |
| 10 | 'title_label' => t('Album name'), |
| 11 | 'has_body' => true, |
| 12 | 'body_label' => t('Album description'), |
| 13 | ) |
| 14 | ); |
| 15 | } |
| 16 | |
| 17 | function photos_perm() { |
| 18 | return array( |
| 19 | 'view photo', |
| 20 | 'create photo', |
| 21 | 'edit own photo', |
| 22 | 'edit any photo', |
| 23 | 'delete own photo', |
| 24 | 'delete any photo', |
| 25 | 'allowed to vote', |
| 26 | 'view vote list', |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | function photos_access($op, $node, $account) { |
| 31 | if ($op == 'create') { |
| 32 | return user_access('create photo', $account); |
| 33 | } |
| 34 | if ($op == 'update') { |
| 35 | if (user_access('edit any photo', $account) || (user_access('edit own photo', $account) && ($account->uid == $node->uid))) { |
| 36 | return TRUE; |
| 37 | } |
| 38 | } |
| 39 | if ($op == 'delete') { |
| 40 | if (user_access('delete any photo', $account) || (user_access('delete own photo', $account) && ($account->uid == $node->uid))) { |
| 41 | return TRUE; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | function photos_form(&$node) { |
| 47 | global $user; |
| 48 | $type = node_get_types('type', $node); |
| 49 | $ua = _photos_num('useralbum',$user->uid); |
| 50 | (int) $a = variable_get('photos_pnum', 20); |
| 51 | (int) $aa = $a - $ua; |
| 52 | $form['help'] = array('#value' => t('You may create %a albums, now you have created %b albums, you can still create %aa albums.', array('%a' => $a, '%b' => $ua, '%aa' => $aa)),'#weight' => -10); |
| 53 | if ($type->has_title) { |
| 54 | $form['title'] = array( |
| 55 | '#type' => 'textfield', |
| 56 | '#title' => check_plain($type->title_label), |
| 57 | '#required' => TRUE, |
| 58 | '#default_value' => $node->title, |
| 59 | '#weight' => -5 |
| 60 | ); |
| 61 | } |
| 62 | if ($type->has_body) { |
| 63 | $form['body'] = array( |
| 64 | '#type' => 'textarea', |
| 65 | '#title' => check_plain($type->body_label), |
| 66 | '#required' => TRUE, |
| 67 | '#default_value' => $node->body, |
| 68 | ); |
| 69 | } |
| 70 | $form['album'] = array( |
| 71 | '#type' => 'fieldset', |
| 72 | '#title' => t('album cover'), |
| 73 | '#collapsible' => TRUE, |
| 74 | '#collapsed' => FALSE, |
| 75 | '#weight' => -2, |
| 76 | '#attributes' => array('class' => 'menu-item-form'), |
| 77 | ); |
| 78 | $form['album']['image'] = array( |
| 79 | '#type' => 'file', |
| 80 | '#description' => t('the best size of the cover image is 120x90.'), |
| 81 | '#weight' => 1, |
| 82 | ); |
| 83 | $form['album']['url'] = array( |
| 84 | '#value' => !empty($node->album['url']) ? '<img src="'.$node->album['url'].'">': NULL, |
| 85 | '#prefix' => '<div class="photos-images" style="float:left; margin-right:10px;">', |
| 86 | '#suffix' => '</div>', |
| 87 | ); |
| 88 | |
| 89 | $form['album']['pid'] = array( |
| 90 | '#type' => 'value', |
| 91 | '#default_value' => $node->album['pid'], |
| 92 | ); |
| 93 | |
| 94 | $form['album']['fid'] = array( |
| 95 | '#type' => 'value', |
| 96 | '#default_value' => $node->album['fid'], |
| 97 | ); |
| 98 | return $form; |
| 99 | } |
| 100 | |
| 101 | function photos_nodeapi(&$node, $op, $teaser, $page) { |
| 102 | global $user; |
| 103 | switch ($op) { |
| 104 | case 'validate': |
| 105 | if($node->type == 'photos'){ |
| 106 | (int) $a = variable_get('photos_pnum', 20); |
| 107 | (int) $aa = _photos_num('useralbum',$user->uid); |
| 108 | if($a <= $aa && arg(2) != 'edit' && $user->uid != 1){ |
| 109 | form_set_error('title',t('You cannot create more albums.')); |
| 110 | } |
| 111 | } |
| 112 | break; |
| 113 | case 'load': |
| 114 | if($node->type == 'photos'){ |
| 115 | $a = db_fetch_object(db_query('SELECT * FROM {x_album} WHERE pid = %d', $node->nid)); |
| 116 | $p = _photos_get_path($a->fid,'album'); |
| 117 | $info['album']['fid'] = $a->fid; |
| 118 | if($p){ |
| 119 | $info['album']['url'] = _photos_file_create_url($p['p1']); |
| 120 | } |
| 121 | $info['album']['pid'] = $a->pid; |
| 122 | if($a->pid){ |
| 123 | $result = db_query('SELECT fid FROM {x_image} WHERE pid ='.$a->pid); |
| 124 | while ($a = db_fetch_object($result)) { |
| 125 | $info['album']['sfid'][] = $a->fid; |
| 126 | } |
| 127 | $info['album']['count'] = count($info['album']['sfid']); |
| 128 | } |
| 129 | }else{ |
| 130 | $result = db_query('SELECT fid FROM {x_image} WHERE nid = %d', $node->nid); |
| 131 | while ($a = db_fetch_object($result)) { |
| 132 | $info['photos']['fid'][] = $a->fid; |
| 133 | } |
| 134 | $info['photos']['count'] = count($info['photos']['fid']); |
| 135 | } |
| 136 | return $info; |
| 137 | break; |
| 138 | |
| 139 | case 'view': |
| 140 | if($node->album['pid']){ |
| 141 | $cover = variable_get('photos_cover_photos', 0); |
| 142 | if($cover){ |
| 143 | if($node->album['url']){ |
| 144 | $v = l('<img src="'.$node->album['url'].'">',"node/$node->nid",array('html'=>true)); |
| 145 | }else{ |
| 146 | $v = l('<img src="/'.drupal_get_path(module,photos).'/img/d.jpg">', 'node/'.$node->nid, array('attributes'=>array('title' => t('There\'s no cover uploaded for the album, this image is the default cover.')), 'html'=>true)); |
| 147 | } |
| 148 | switch ($cover){ |
| 149 | case '1': |
| 150 | if($teaser){ |
| 151 | $node->content['albumpage'] = array( |
| 152 | '#value' => '<div class="photos-albumpage">'.$v.'</div>', |
| 153 | '#weight' => -5, |
| 154 | ); |
| 155 | } |
| 156 | break; |
| 157 | case '2': |
| 158 | if($page){ |
| 159 | $node->content['albumpage'] = array( |
| 160 | '#value' => '<div class="photos-albumpage">'.$v.'</div>', |
| 161 | '#weight' => -5, |
| 162 | ); |
| 163 | } |
| 164 | break; |
| 165 | case '3': |
| 166 | $node->content['albumpage'] = array( |
| 167 | '#value' => '<div class="photos-albumpage">'.$v.'</div>', |
| 168 | '#weight' => -5, |
| 169 | ); |
| 170 | break; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | if(user_access('view photo') && ($node->photos['count'] || $node->album['count'])) { |
| 176 | if($node->type == 'photos'){ |
| 177 | $sql = 'WHERE pid = '.$node->nid; |
| 178 | }else{ |
| 179 | $sql = 'WHERE nid = '.$node->nid; |
| 180 | } |
| 181 | if($page){ |
| 182 | $num = variable_get('photos_page_'.$node->type, 10); |
| 183 | $p = _photos_sql('allimage',$sql, $num,10); |
| 184 | }else{ |
| 185 | $num = variable_get('photos_teaser_'.$node->type, 5); |
| 186 | $p = _photos_sql('numimage',$sql, $num); |
| 187 | } |
| 188 | if($p){ |
| 189 | if($page && !variable_get('photos_pager_photos', 0)){ |
| 190 | $pager = theme('pager', NULL, $num, 10); |
| 191 | } |
| 192 | $t .= $pager; |
| 193 | foreach ($p as $b) { |
| 194 | $t .= photos_view_image($b->fid,'all'); |
| 195 | } |
| 196 | $t .= $pager; |
| 197 | } |
| 198 | $node->content['photos'] = array( |
| 199 | '#value' => '<div class="photos-image">'.$t.'</div>', |
| 200 | '#weight' => 0, |
| 201 | ); |
| 202 | } |
| 203 | break; |
| 204 | |
| 205 | case 'insert': |
| 206 | case 'update': |
| 207 | if(variable_get('photos_'.$node->type, 0)){ |
| 208 | photos_upload_form_submit($form, $form_state, $node); |
| 209 | }elseif($node->type == 'photos'){ |
| 210 | photos_album_save($node); |
| 211 | } |
| 212 | break; |
| 213 | case 'delete': |
| 214 | if($node->photos['count']){ |
| 215 | foreach ($node->photos['fid'] as $fid){ |
| 216 | _photos_file_del($fid); |
| 217 | db_query('DELETE FROM {x_image} WHERE fid = %d',$fid); |
| 218 | } |
| 219 | drupal_set_message(t('%count images are deleted.', array('%count' => $node->photos['count']))); |
| 220 | } |
| 221 | if($node->album['pid']){ |
| 222 | db_query('DELETE FROM {x_album} WHERE pid = %d',$node->nid); |
| 223 | _photos_file_del($node->album['fid'],'album'); |
| 224 | } |
| 225 | if($node->album['count']){ |
| 226 | foreach ($node->album['sfid'] as $fid){ |
| 227 | _photos_file_del($fid); |
| 228 | db_query('DELETE FROM {x_image} WHERE fid = %d',$fid); |
| 229 | } |
| 230 | drupal_set_message(t('%count images are deleted.', array('%count' => $node->album['count']))); |
| 231 | } |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | function photos_album_save($node) { |
| 237 | $info = _photos_upload_info(); |
| 238 | if($_FILES['files']['name']['image']){ |
| 239 | $file = new stdClass(); |
| 240 | $file->filename = $_FILES['files']['name']['image']; |
| 241 | if(!file_validate_extensions($file,'png gif jpg jpeg')){ |
| 242 | _photos_rename(); |
| 243 | $file->filepath = file_destination(file_create_path($info['p'].'/album_'.$node->nid . '_' .trim(basename($_FILES['files']['name']['image']))),FILE_EXISTS_RENAME); |
| 244 | if (is_uploaded_file($_FILES['files']['tmp_name']['image'])) { |
| 245 | $data = $_FILES['files']['tmp_name']['image']; |
| 246 | $maxs = @getimagesize($data); |
| 247 | if($maxs['0'] > 120 || $maxs['1'] > 90 ){ |
| 248 | $t = image_scale($data, $file->filepath, 120, 90); |
| 249 | |
| 250 | }else{ |
| 251 | $t = image_scale($data, $file->filepath, $maxs['0'] - 1, $maxs['0'] - 1); |
| 252 | } |
| 253 | } |
| 254 | if($t){ |
| 255 | $files = image_get_info($file->filepath); |
| 256 | $file->filesize = $files['file_size']; |
| 257 | $file->filemime = $files['mime_type']; |
| 258 | $file->timestamp = time(); |
| 259 | $file->uid = $node->uid; |
| 260 | if(drupal_write_record('files', $file)){ |
| 261 | file_set_status($file, FILE_STATUS_PERMANENT); |
| 262 | } |
| 263 | if($node->fid) { |
| 264 | $del = db_result(db_query('SELECT fid FROM {x_image} WHERE fid = %d', $node->fid)); |
| 265 | if(!$del){ |
| 266 | _photos_file_del($node->fid,'album'); |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | if(!$node->pid) { |
| 273 | db_query("INSERT INTO {x_album} (pid, fid, uid) VALUES (%d, %d, %d)",$node->nid, $file->fid, $node->uid); |
| 274 | }elseif($file->fid){ |
| 275 | db_query("UPDATE {x_album} SET fid = %d WHERE pid = %d",$file->fid, $node->nid); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | function photos_user($op, &$edit, &$account) { |
| 280 | switch ($op){ |
| 281 | case 'view': |
| 282 | if (user_access('create photo', $account)) { |
| 283 | $x = !empty($account->photos['album']) ? l(t('There are !a albums in total', array('!a'=> $account->photos['album'])), 'photos/user/album/'.$account->uid) : t('No albums yet, ').l(t('Create album'),'node/add/photos').'。'; |
| 284 | $x .= !empty($account->photos['image']) ? l(t('There are !a images in total', array('!a'=> $account->photos['image'])), 'photos/user/image/'.$account->uid) : t('No images yet, ').l(t('Upload images'), 'photos/upload').'。'; |
| 285 | if(variable_get('photos_flash', 0) && !empty($account->photos['image'])){ |
| 286 | $x .= l(t('Flash View image'), 'photos/user/flash/'.$account->uid); |
| 287 | } |
| 288 | $account->content['summary']['photos'] = array( |
| 289 | '#type' => 'user_profile_item', |
| 290 | '#title' => t('Album image'), |
| 291 | '#value' => $x, |
| 292 | '#attributes' => array('class' => 'photos'), |
| 293 | ); |
| 294 | } |
| 295 | break; |
| 296 | case 'load': |
| 297 | $account->photos['album'] = _photos_num('useralbum',$account->uid); |
| 298 | $account->photos['image'] = _photos_num('userimage',$account->uid); |
| 299 | break; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | function _photos_access($type,$id){ |
| 304 | global $user; |
| 305 | switch ($type) { |
| 306 | case 'edit': |
| 307 | return user_access('edit any photo') || (user_access('edit own photo') && $user->uid == $id); |
| 308 | case 'nedit': |
| 309 | $node = node_load(arg(1)); |
| 310 | return ($node->type == 'photos' || variable_get('photos_'.$node->type, 0)) && (user_access('edit any photo') || node_access('update', $node)); |
| 311 | case 'del': |
| 312 | return user_access('delete any photo') || (user_access('delete own photo') && $user->uid == $id); |
| 313 | case 'ndel': |
| 314 | $nid = arg(1); |
| 315 | $nuid = db_result(db_query('SELECT uid FROM {node} WHERE nid = %d',$nid)); |
| 316 | return user_access('delete any photo') || (user_access('delete own photo') && $user->uid == $nuid); |
| 317 | } |
| 318 | } |
| 319 | function photos_menu() { |
| 320 | $items = array(); |
| 321 | |
| 322 | $items['admin/settings/photos'] = array( |
| 323 | 'title' => 'Photos upload', |
| 324 | 'page callback' => 'drupal_get_form', |
| 325 | 'page arguments' => array('photos_admin_settings'), |
| 326 | 'access arguments' => array('administer nodes'), |
| 327 | 'type' => MENU_NORMAL_ITEM, |
| 328 | 'file' => 'photos.admin.inc', |
| 329 | ); |
| 330 | |
| 331 | $items['admin/settings/photos/update'] = array( |
| 332 | 'title' => 'Batch update', |
| 333 | 'page callback' => 'drupal_get_form', |
| 334 | 'page arguments' => array('photos_admin_update'), |
| 335 | 'access arguments' => array('administer nodes'), |
| 336 | 'type' => MENU_NORMAL_ITEM, |
| 337 | 'file' => 'photos.admin.inc', |
| 338 | ); |
| 339 | |
| 340 | $items['node/%node/photos'] = array( |
| 341 | 'title' => 'Photos management', |
| 342 | 'page callback' => 'photos_node_edit', |
| 343 | 'page arguments' => array(1), |
| 344 | 'access callback' => '_photos_access', |
| 345 | 'access arguments' => array('nedit',1), |
| 346 | 'type' => MENU_LOCAL_TASK, |
| 347 | 'file' => 'photos.page.inc', |
| 348 | ); |
| 349 | $items['node/%node/photos/view'] = array( |
| 350 | 'page callback' => 'photos_image_flash', |
| 351 | 'page arguments' => array(1), |
| 352 | 'access callback' => 'user_access', |
| 353 | 'access arguments' => array('view photo'), |
| 354 | 'type' => MENU_CALLBACK, |
| 355 | 'file' => 'photos.page.inc', |
| 356 | ); |
| 357 | $items['photos'] = array( |
| 358 | 'title' => 'Album photos', |
| 359 | 'page callback' => 'photos_test_page', |
| 360 | 'access callback' => 'user_access', |
| 361 | 'access arguments' => array('view photo'), |
| 362 | 'type' =>MENU_NORMAL_ITEM, |
| 363 | 'file' => 'photos.page.inc', |
| 364 | ); |
| 365 | $items['photos/tools'] = array( |
| 366 | 'page callback' => '_photos_image_tools', |
| 367 | 'access callback' => 'user_access', |
| 368 | 'access arguments' => array('view photo'), |
| 369 | 'type' => MENU_CALLBACK, |
| 370 | 'file' => 'photos.page.inc', |
| 371 | ); |
| 372 | $items['photos/quote'] = array( |
| 373 | 'title' => 'Select picture', |
| 374 | 'page callback' => 'photos_quote', |
| 375 | 'access callback' => 'user_access', |
| 376 | 'access arguments' => array('create photo'), |
| 377 | 'type' => MENU_CALLBACK, |
| 378 | 'file' => 'photos.page.inc', |
| 379 | ); |
| 380 | $items['photos/image'] = array( |
| 381 | 'title' => 'Latest images', |
| 382 | 'page callback' => 'photos_user_image_page', |
| 383 | 'access callback' => 'user_access', |
| 384 | 'access arguments' => array('view photo'), |
| 385 | 'type' => MENU_NORMAL_ITEM, |
| 386 | 'file' => 'photos.page.inc', |
| 387 | ); |
| 388 | $items['photos/album'] = array( |
| 389 | 'title' => 'Latest albums', |
| 390 | 'page callback' => 'photos_user_album_page', |
| 391 | 'access callback' => 'user_access', |
| 392 | 'access arguments' => array('view photo'), |
| 393 | 'type' => MENU_NORMAL_ITEM, |
| 394 | 'file' => 'photos.page.inc', |
| 395 | ); |
| 396 | $items['photos/admin'] = array( |
| 397 | 'title' => 'Photos admin', |
| 398 | 'page callback' => 'photos_admin_edit', |
| 399 | 'access callback' => 'user_access', |
| 400 | 'access arguments' => array('administer nodes'), |
| 401 | 'type' => MENU_NORMAL_ITEM, |
| 402 | 'weight' => 10, |
| 403 | 'file' => 'photos.page.inc', |
| 404 | ); |
| 405 | $items['photos/import'] = array( |
| 406 | 'title' => 'Import ZIP', |
| 407 | 'page callback' => 'drupal_get_form', |
| 408 | 'page arguments' => array('photos_admin_import'), |
| 409 | 'access callback' => 'user_access', |
| 410 | 'access arguments' => array('administer nodes'), |
| 411 | 'type' => MENU_NORMAL_ITEM, |
| 412 | 'weight' => 9, |
| 413 | 'file' => 'photos.page.inc', |
| 414 | ); |
| 415 | $items['photos/zoom/%'] = array( |
| 416 | 'title' => 'Photos reference download', |
| 417 | 'page callback' => 'photos_image_pageone', |
| 418 | 'access callback' => 'user_access', |
| 419 | 'access arguments' => array('view photo'), |
| 420 | 'type' => MENU_CALLBACK, |
| 421 | 'file' => 'photos.page.inc', |
| 422 | ); |
| 423 | $items['photos/image/%'] = array( |
| 424 | 'page callback' => 'photos_image_pageone', |
| 425 | 'access callback' => 'user_access', |
| 426 | 'access arguments' => array('view photo'), |
| 427 | 'type' => MENU_CALLBACK, |
| 428 | 'file' => 'photos.page.inc', |
| 429 | ); |
| 430 | |
| 431 | $items['photos/user/album/%user'] = array( |
| 432 | 'title' => 'My albums', |
| 433 | 'page callback' => 'photos_user_album_page', |
| 434 | 'page arguments' => array(3), |
| 435 | 'access callback' => 'user_access', |
| 436 | 'access arguments' => array('create photo',3), |
| 437 | 'file' => 'photos.page.inc', |
| 438 | 'type' => MENU_NORMAL_ITEM |
| 439 | ); |
| 440 | $items['photos/user/image/%user'] = array( |
| 441 | 'title' => 'My images', |
| 442 | 'page callback' => 'photos_user_album_page', |
| 443 | 'page arguments' => array(3), |
| 444 | 'access callback' => 'user_access', |
| 445 | 'access arguments' => array('create photo',3), |
| 446 | 'file' => 'photos.page.inc', |
| 447 | 'type' =>MENU_NORMAL_ITEM, |
| 448 | ); |
| 449 | if(variable_get('photos_flash', 0)){ |
| 450 | $items['photos/user/flash/%user'] = array( |
| 451 | 'title' => 'My flash', |
| 452 | 'page callback' => 'photos_user_album_page', |
| 453 | 'page arguments' => array(3), |
| 454 | 'access callback' => 'user_access', |
| 455 | 'access arguments' => array('create photo',3), |
| 456 | 'file' => 'photos.page.inc', |
| 457 | 'type' =>MENU_NORMAL_ITEM, |
| 458 | ); |
| 459 | } |
| 460 | $items['photos/upload'] = array( |
| 461 | 'title' => 'Upload image', |
| 462 | 'page callback' => 'photos_album_upload', |
| 463 | 'access callback' => 'user_access', |
| 464 | 'access arguments' => array('edit own photo'), |
| 465 | 'file' => 'photos.page.inc', |
| 466 | 'weight' => 1, |
| 467 | 'type' => MENU_NORMAL_ITEM |
| 468 | ); |
| 469 | |
| 470 | return $items; |
| 471 | } |
| 472 | function photos_view_page() { |
| 473 | global $user; |
| 474 | $output = ''; |
| 475 | $result = db_query("SELECT f.*,p.wid,p.des FROM {files} f INNER JOIN {x_image} p ON f.fid = p.fid ORDER BY p.wid ASC,f.fid DESC"); |
| 476 | while ($a = db_fetch_object($result)) { |
| 477 | $p = _photos_get_path($a->fid); |
| 478 | $d = !empty($a->des) ? check_plain($a->des) : $alt; |
| 479 | $t[]= array($a->filepath,$d,_photos_file_create_url($p['p']),_photos_file_create_url($p['p2']),$a->fid,$a->wid,$a->uid); |
| 480 | }; |
| 481 | $output .= count($t); |
| 482 | return $output; |
| 483 | } |
| 484 | |
| 485 | function _photos_image_pager($fid, $pid) { |
| 486 | $sql = 'SELECT fid FROM {x_image} WHERE pid =%d ORDER BY fid DESC'; |
| 487 | $result = db_query($sql, $pid); |
| 488 | $stop = $t['prev'] = $t['next'] = 0; |
| 489 | while ($pager = db_fetch_object($result)) { |
| 490 | if ($stop == 1) { |
| 491 | $t['next'] = $pager->fid; |
| 492 | $t['next_url'] = url("photos/image/$pager->fid"); |
| 493 | break; |
| 494 | } |
| 495 | if ($pager->fid == $fid) { |
| 496 | $t['current'] = $pager->fid; |
| 497 | $t['current_url'] = url("photos/image/$pager->fid"); |
| 498 | $stop = 1; |
| 499 | } else { |
| 500 | $t['prev'] = $pager->fid; |
| 501 | $t['prev_url'] = url("photos/image/$pager->fid"); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | return $t; |
| 506 | } |
| 507 | |
| 508 | function photos_view_image($fid, $type) { |
| 509 | global $user; |
| 510 | $t = _photos_get_path($fid); |
| 511 | if($t){ |
| 512 | if($t['nid']) { $mynode = node_load($t['nid']); } |
| 513 | if($t['pid']) { $myalbum = node_load($t['pid']); } |
| 514 | if($t['uid']) { $myuser = user_load($t['uid']); } |
| 515 | switch ($type) { |
| 516 | case 'all': |
| 517 | $output = l('<img alt="'.$t['title'].'" title="'.$t['des'].'" src="'._photos_file_create_url($t['p1']).'">','photos/image/'.$fid,array('class'=> 'imageview','html'=>true)); |
| 518 | break; |
| 519 | case 'url': |
| 520 | $output = _photos_file_create_url($t['p1']); |
| 521 | break; |
| 522 | case 'blocknext': |
| 523 | $image['album'] = $t; |
| 524 | if($t['uid'] == $node->uid){ |
| 525 | $image['user_name'] = theme('username', $n); |
| 526 | }else{ |
| 527 | $iu = user_load($t['uid']); |
| 528 | $image['user_name'] = theme('username', $iu); |
| 529 | } |
| 530 | $image['user_url'] = url('photos/user/image/'.$t['uid']); |
| 531 | $image['album']['albumurl'] = url('node/'.$t['pid']); |
| 532 | $image['album']['albumnum'] = $myalbum->album['count']; |
| 533 | if($t['nid']){ |
| 534 | $image['album']['nodeurl'] = url('node/'.$t['nid']); |
| 535 | $image['album']['nodenum'] = $mynode->photos['count']; |
| 536 | } |
| 537 | if(variable_get('photos_flash', 0)){ |
| 538 | $image['album']['flash'] = url('node/'.$t['pid'].'/photos/view/flash'); |
| 539 | } |
| 540 | $image['pager'] = _photos_image_pager($fid, $myalbum->nid); |
| 541 | $image['pager']['next_view'] = photos_view_image($image['pager']['next'],'url'); |
| 542 | $image['pager']['prev_view'] = photos_view_image($image['pager']['prev'],'url'); |
| 543 | $image['pager']['current_view'] = photos_view_image($image['pager']['current'],'url'); |
| 544 | if(!variable_get('photos_block_num_2_1', 0)){ |
| 545 | $image['link']['href'] = _photos_file_create_url('photos/image/'.arg(2)); |
| 546 | $image['link']['src'] = _photos_file_create_url($t['p2']); |
| 547 | |
| 548 | } |
| 549 | if(variable_get('photos_exif', 0) && variable_get('photos_block_num_2', 0)){ |
| 550 | $image['exif'] = _photos_getexif(_photos_file_create_url($t['p']),'t','photos/zoom/'.$fid.'/exif'); |
| 551 | } |
| 552 | $output = theme('photos_imageblock', $image); |
| 553 | break; |
| 554 | default: |
| 555 | $title = t('Browse images: ').$myalbum->title; |
| 556 | $bmbtitle = t('A total of %num albums under the image',array('%num' => $myalbum->album['count'])); |
| 557 | $breadcrumb = array(l(t('Home'), NULL),l($myalbum->title,'node/'.$myalbum->nid),$bmbtitle); |
| 558 | $sql = 'pid = '.$myalbum->nid.' AND'; |
| 559 | $edit = array('fid'=>$fid,'wid'=>$t['wid'],'uid'=>$t['uid']); |
| 560 | $image = new stdClass(); |
| 561 | $image->title = $title; |
| 562 | $image->description = !empty($t['des']) ? '<div class="desbody">'.$t['des'].'</div>':NULL; |
| 563 | if(_photos_access('edit',$t['uid'])){ |
| 564 | $image->editform = '<div id="imgedit">'.drupal_get_form('photos_desedit',$edit).'</div>'; |
| 565 | } |
| 566 | |
| 567 | if(_photos_access('edit',$t['uid'])){ |
| 568 | $image->links['edit'] = '<a class="click-des" href="javascript:void(0)">' .t('Click to change description'). '</a>'; |
| 569 | } |
| 570 | if(variable_get('photos_vote', 0)){ |
| 571 | $sum = votingapi_recalculate_results('image', $fid); |
| 572 | if($sum['0']['value']){ |
| 573 | $count = $sum['2']['value']; |
| 574 | $ren = $sum['0']['value']; |
| 575 | }else{ |
| 576 | $count = 0; |
| 577 | $ren = 0; |
| 578 | } |
| 579 | $x = votingapi_select_votes(array('uid' => $user->uid, 'content_type' => 'image', 'content_id' => $fid)); |
| 580 | if(!user_access('allowed to vote')){ |
| 581 | $image->links['vote']['up'] = l('',"user/login",array('query' => drupal_get_destination(), 'attributes' => array('class' => 'photos-vote-u photos-vote-up-u', 'title' => t('Login to vote')), 'html' => true)); |
| 582 | $image->links['vote']['down'] = l('',"user/login",array('query' => drupal_get_destination(), 'attributes' => array('class' => 'photos-vote-u photos-vote-down-u', 'title' => t('Login to vote')), 'html' => true)); |
| 583 | }else{ |
| 584 | $image->links['vote']['up'] = l('',"photos/image/$fid/vote/up",array('query' => drupal_get_destination(), 'attributes' => array('class' => 'photos-vote photos-vote-up', 'title' => t('I like this image')), 'html' => true)); |
| 585 | $image->links['vote']['down'] = l('',"photos/image/$fid/vote/down",array('query' => drupal_get_destination(), 'attributes' => array('class' => 'photos-vote photos-vote-down', 'title' => t('I do not like this image')), 'html' => true)); |
| 586 | if($x['0']['value'] == 1) { |
| 587 | $image->links['vote']['up'] = '<span class="photos-vote photos-vote-up photos-vote-up-x" title = "'.t('I like this image').'"></span>'; |
| 588 | }elseif($x['0']['value'] == -1){ |
| 589 | $image->links['vote']['down'] = '<span class="photos-vote photos-vote-down photos-vote-down-x" title = "'.t('I do not like this image').'"></span>'; |
| 590 | } |
| 591 | } |
| 592 | if(!user_access('view vote list')){ |
| 593 | $image->links['vote']['count'] = '<span class="photos-vote-sum">'.$count.'/'.$ren.'</span>'; |
| 594 | }else{ |
| 595 | $image->links['vote']['count'] = l('<span class="photos-vote-sum">'.$count.'/'.$ren.'</span>',"photos/zoom/$fid/vote",array('html' => true)); |
| 596 | } |
| 597 | } |
| 598 | if(variable_get('photos_comment', 0)){ |
| 599 | $commnetcon = photos_vote_comment($fid,1); |
| 600 | if(!$commnetcon){ |
| 601 | if (!user_access('post comments')) { |
| 602 | $image->links['comment'] = t('<a href="@login">Login</a> to post comments', array('@login' => url('user/login', array('query' => drupal_get_destination())))); |
| 603 | }else{ |
| 604 | $image->links['comment'] .= '<a href="#comment-form">' .t('Add new comment'). '</a>'; |
| 605 | } |
| 606 | }elseif($commnetcon > 1){ |
| 607 | $image->links['comment'] .= '<a href="#comments">' .t('!con comments',array('!con' => $commnetcon)). '</a>'; |
| 608 | }elseif($commnetcon == 1){ |
| 609 | $image->links['comment'] .= '<a href="#comments">' .t('!con comment',array('!con' => $commnetcon)). '</a>'; |
| 610 | } |
| 611 | } |
| 612 | $options = array(); |
| 613 | if (variable_get('photos_open_orig', 0)) { |
| 614 | $options['attributes']['target'] = '_blank'; |
| 615 | } |
| 616 | $image->links['more'] = l(t('View original image'), 'photos/zoom/'.$fid, $options); |
| 617 | $image->links['pager'] = _photos_image_pager($fid, $myalbum->nid); |
| 618 | $image->view = '<img alt="'.$t['title'].'" title="'.$t['des'].'" src="'._photos_file_create_url($t['p2']).'">'; |
| 619 | $image->comment['view'] = photos_vote_comment($fid); |
| 620 | if (variable_get('photos_comment', 0) && user_access('post comments')) { |
| 621 | $image->comment['box'] = comment_form_box(array('nid' => $myalbum->nid), t('Post new comment')); |
| 622 | } |
| 623 | $output = theme('photos_imageview',$image, $t); |
| 624 | drupal_set_title($title); |
| 625 | drupal_set_breadcrumb($breadcrumb); |
| 626 | break; |
| 627 | } |
| 628 | }else{ |
| 629 | $output = t('The image does not exist.'); |
| 630 | } |
| 631 | return $output; |
| 632 | } |
| 633 | |
| 634 | function photos_comment(&$comment, $op) { |
| 635 | switch ($op) { |
| 636 | case 'insert': |
| 637 | if((arg(0)=='photos' && arg(1)=='image') || (arg(0) == 'comment' && $_GET['fid'])){ |
| 638 | $cid = $comment['cid']; |
| 639 | if(arg(0) == 'comment'){ |
| 640 | $fid = $_GET['fid']; |
| 641 | }else{ |
| 642 | $fid = arg(2); |
| 643 | } |
| 644 | db_query("INSERT INTO {x_vote} (fid, cid) VALUES (%d, %d)",$fid, $cid); |
| 645 | } |
| 646 | break; |
| 647 | case 'delete': |
| 648 | $t = db_query('SELECT cid FROM {x_vote} WHERE cid = %d',$comment->cid); |
| 649 | if($t){ |
| 650 | db_query('DELETE FROM {x_vote} WHERE cid = %d',$comment->cid); |
| 651 | } |
| 652 | break; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | //å›¾ç‰‡ä¸Šä¼ |
| 657 | function photos_upload_form(& $form_state,$n = false, $edit = array()) { |
| 658 | global $user; |
| 659 | if(variable_get('photos_num',true)){ |
| 660 | $a = variable_get('photos_num',5); |
| 661 | }else{ |
| 662 | $a = 5; |
| 663 | } |
| 664 | if(variable_get('photos_upzip',0)){ $description = ' zip';} |
| 665 | $form['new'] = array( |
| 666 | '#title' => t('Image upload'), |
| 667 | '#weight' => -4, |
| 668 | '#type' => 'fieldset', |
| 669 | '#description' => t('Allow the type:').' jpg gif png jpeg '.$description, |
| 670 | '#collapsible' => TRUE, |
| 671 | ); |
| 672 | if(_photos_num('useralbum',$user->uid)){ |
| 673 | for($i =0;$i < $a; ++$i){ |
| 674 | $form['new']['images_'.$i] = array( |
| 675 | '#type' => 'file', |
| 676 | '#size' => 50, |
| 677 | ); |
| 678 | $form['new']['des_'.$i] = array( |
| 679 | '#type'=> 'textarea', |
| 680 | '#title' => t('description'), |
| 681 | '#default_value' => '', |
| 682 | '#cols' => 40, |
| 683 | '#rows' => 3, |
| 684 | ); |
| 685 | } |
| 686 | }else{ |
| 687 | $form['new']['images'] = array( |
| 688 | '#value' => '<p><strong>' . t('You must first !create an album to upload images.',array('!create' => l(t('create'),'node/add/photos',array('query'=>drupal_get_destination())))) . '</strong></p>', |
| 689 | '#weight' => -4, |
| 690 | ); |
| 691 | return $form; |
| 692 | } |
| 693 | if($n->type == 'photos'){ |
| 694 | $form['new']['pid'] = array( |
| 695 | '#type' => 'value', |
| 696 | '#value' => $n->nid |
| 697 | ); |
| 698 | $n->nid = 0; |
| 699 | }else{ |
| 700 | $form['new']['pid'] = array( |
| 701 | '#title' => t('Upload to album'), |
| 702 | '#type' => 'select', |
| 703 | '#options' => _photos_useralbum($user->uid), |
| 704 | '#default_value' => $_GET['pid'], |
| 705 | '#required' => TRUE, |
| 706 | '#description' => '<p><strong>'.l(t('You may create a new album'),'node/add/photos',array('query'=>drupal_get_destination())).'</strong></p>', |
| 707 | '#weight' => -5, |
| 708 | ); |
| 709 | } |
| 710 | if(arg(1) != 'add' && arg(2) != 'edit'){ |
| 711 | $form['new']['submit'] = array( |
| 712 | '#type' => 'submit', |
| 713 | '#value' => t('Confirm upload'), |
| 714 | '#weight' => 10, |
| 715 | '#submit' => array('photos_upload_form_submit'), |
| 716 | ); |
| 717 | if(arg(1)=='upload' || arg(1) == 'quote'){ $n->uid = $user->uid; } |
| 718 | $form['date'] = array('#type' => 'value','#value' => $n); |
| 719 | $form['#attributes']['enctype'] = 'multipart/form-data'; |
| 720 | } |
| 721 | return $form; |
| 722 | } |
| 723 | |
| 724 | function photos_upload_form_submit($form, & $form_state,$node = false) { |
| 725 | global $user; |
| 726 | $info = _photos_upload_info(); |
| 727 | $zip = new stdClass(); |
| 728 | if($node){ |
| 729 | $n = $node; |
| 730 | $zip->title = $node->title; |
| 731 | $zip->nid = $node->nid; |
| 732 | $zip->pid = $pid = $node->pid; |
| 733 | }else{ |
| 734 | $n = $form_state['values']['date']; |
| 735 | $zip->title = $n->title; |
| 736 | $zip->nid = $n->nid; |
| 737 | $zip->pid = $form_state['values']['pid']; |
| 738 | } |
| 739 | if(variable_get('photos_num',true)){ |
| 740 | $a = variable_get('photos_num',5); |
| 741 | }else{ |
| 742 | $a = 5; |
| 743 | } |
| 744 | if($user->uid == '1' && $form_state['values']['unzip']){ |
| 745 | if(!$t = _photos_unzip(trim($form_state['values']['unzip']), $info['p'],$zip)){ |
| 746 | $t = t('Failed to upload'); |
| 747 | } |
| 748 | return drupal_set_message($t); |
| 749 | } |
| 750 | |
| 751 | $limits = _upload_file_limits($user); |
| 752 | $validators = array( |
| 753 | 'file_validate_extensions' => array('zip png gif jpg jpeg'), |
| 754 | 'file_validate_image_resolution' => array($limits['resolution']), |
| 755 | 'file_validate_size' => array($limits['file_size'], $limits['user_size']) |
| 756 | ); |
| 757 | |
| 758 | for ($i = 0;$i < $a; ++$i){ |
| 759 | $zip->title = $form_state['values']['des_'.$i]; |
| 760 | $myfilename = urlencode($_FILES['files']['name']['images_'.$i]); |
| 761 | _photos_rename(); |
| 762 | if($_FILES['files']['name']['images_'.$i]){ |
| 763 | $extt = end(explode('.',$_FILES['files']['name']['images_'.$i])); |
| 764 | if($extt == 'zip' || $extt == 'ZIP'){ |
| 765 | if(!variable_get('photos_upzip',0)){ |
| 766 | return form_set_error('errer',t('Please Album photos set to open zip upload')); |
| 767 | } |
| 768 | $zipfile = new stdClass(); |
| 769 | $zipfile->filesize = $_FILES['files']['size']['images_'.$i]; |
| 770 | $zipurl = file_destination(file_create_path($info['p'] .'/'.trim(basename($_FILES['files']['name']['images_'.$i]))),FILE_EXISTS_RENAME); |
| 771 | if (move_uploaded_file($_FILES['files']['tmp_name']['images_'.$i], $zipurl)) { |
| 772 | if(!$ttt = _photos_unzip($zipurl, $info['p'],$zip)){ |
| 773 | $ttt = t('Failed to upload'); |
| 774 | } |
| 775 | } |
| 776 | }else{ |
| 777 | if ($file = file_save_upload('images_'.$i, $validators,$info['p'])) { |
| 778 | $file->title = ($zip->title ? $zip->title:urldecode($myfilename)); |
| 779 | $file->pid = $zip->pid; |
| 780 | $file->nid = $zip->nid; |
| 781 | if($ok = _photos_image_date($file)){ |
| 782 | $msg[] = $ok; |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | if(count($msg) != 0){ |
| 789 | $me = t('%count image(s) uploaded successfully.', array('%count'=>count($msg))); |
| 790 | }else{ |
| 791 | $me = $ttt; |
| 792 | } |
| 793 | drupal_set_message($me); |
| 794 | } |
| 795 | |
| 796 | function _photos_image_date($file, $path = false){ |
| 797 | $num = _photos_image_crop($file->filepath, $path); |
| 798 | if(db_query("INSERT INTO {x_image} (fid, pid, nid, uid, des, wid, num, count) VALUES (%d, %d, %d, %d, '%s', 0, %d, 0)",$file->fid, $file->pid, $file->nid, $file->uid, $file->title, $num)){ |
| 799 | file_set_status($file, FILE_STATUS_PERMANENT); |
| 800 | return true; |
| 801 | }else{ |
| 802 | return false; |
| 803 | } |
| 804 | } |
| 805 | function photos_link($type, $node = NULL, $teaser = FALSE) { |
| 806 | global $user; |
| 807 | $links = array(); |
| 808 | if(_photos_access('edit',$node->uid) && ($node->type == 'photos' || variable_get('photos_'.$node->type, 0)) && $node->album['pid']){ |
| 809 | $links['photos_edit'] = array( |
| 810 | 'title' => t('Organize images'), |
| 811 | 'href' => 'node/'.$node->nid.'/photos', |
| 812 | 'attributes' => array('title' => t('Organize images of !title', array('!title' => $node->title))), |
| 813 | ); |
| 814 | } |
| 815 | if(user_access('view photo') && variable_get('photos_flash', 0) && ($node->photos['count'] || $node->album['count'])){ |
| 816 | $title = !empty($node->photos['count']) ? $node->photos['count']:$node->album['count']; |
| 817 | $links['photos_flash'] = array( |
| 818 | 'title' => t('Flash View image'), |
| 819 | 'href' => 'node/'.$node->nid.'/photos/view/flash', |
| 820 | 'attributes' => array('title' => t('A total of !title images', array('!title'=> $title))), |
| 821 | ); |
| 822 | } |
| 823 | if ($type == 'comment') { |
| 824 | if (!(arg(0) == 'comment' && arg(1) == $node->cid)) { |
| 825 | $t = db_result(db_query('SELECT fid FROM {x_vote} WHERE cid = %d',$node->cid)); |
| 826 | if($t){ |
| 827 | $links['link_photo'] = array( |
| 828 | 'title' => t('View image'), |
| 829 | 'href' => 'photos/image/'.$t, |
| 830 | 'fragment' => 'comment-'.$node->cid |
| 831 | ); |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | return $links; |
| 836 | } |
| 837 | |
| 838 | function photos_form_alter(&$form, $form_state, $form_id) { |
| 839 | if ($form_id == 'node_type_form' && isset($form['identity']['type'])) { |
| 840 | $form['photos'] = array( |
| 841 | '#type' => 'fieldset', |
| 842 | '#title' => t('Image upload'), |
| 843 | '#collapsible' => TRUE, |
| 844 | '#collapsed' =>true, |
| 845 | ); |
| 846 | if(arg(3) != 'photos'){ |
| 847 | $form['photos']['photos'] = array( |
| 848 | '#type' => 'radios', |
| 849 | '#title' => t('Upload'), |
| 850 | '#default_value' => variable_get('photos_'. $form['#node_type']->type, 0), |
| 851 | '#options' => array(t('Disabled'), t('Enabled')), |
| 852 | '#description' => t('You can upload images to nodes after enable this.'), |
| 853 | ); |
| 854 | $form['photos']['photos_quote'] = array( |
| 855 | '#type' => 'radios', |
| 856 | '#title' => t('Reference'), |
| 857 | '#default_value' => variable_get('photos_quote_'. $form['#node_type']->type, 0), |
| 858 | '#options' => array(t('Disabled'), t('Enabled')), |
| 859 | '#description' => t('After enable this, you can insert a reference of images from other albums to the node, but do not attach the image to the node.'), |
| 860 | ); |
| 861 | }else { |
| 862 | $form['photos']['photos_cover'] = array( |
| 863 | '#type' => 'select', |
| 864 | '#title' => t('display album cover'), |
| 865 | '#default_value' => variable_get('photos_cover_'. $form['#node_type']->type, 0), |
| 866 | '#options' => array(t('none display'),t('the teaser'),t('the page'), t('teaser and page')), |
| 867 | ); |
| 868 | } |
| 869 | $form['photos']['photos_teaser'] = array( |
| 870 | '#type' => 'textfield', |
| 871 | '#title' => t('Number of images displayed in a teaser'), |
| 872 | '#default_value' => variable_get('photos_teaser_'. $form['#node_type']->type, 5), |
| 873 | ); |
| 874 | $form['photos']['photos_page'] = array( |
| 875 | '#type' => 'textfield', |
| 876 | '#title' => t('Number of images displayed in a page'), |
| 877 | '#default_value' => variable_get('photos_page_'. $form['#node_type']->type, 10), |
| 878 | ); |
| 879 | $form['photos']['photos_pager'] = array( |
| 880 | '#type' => 'radios', |
| 881 | '#title' => t('display pager'), |
| 882 | '#default_value' => variable_get('photos_pager_'. $form['#node_type']->type, 0), |
| 883 | '#options' => array( t('Enabled'), t('Disabled')), |
| 884 | ); |
| 885 | } |
| 886 | if($form_id == 'comment_form' && (arg(1) == 'image' || (arg(0) == 'comment' && $_GET['fid']))){ |
| 887 | if(arg(1) == 'image'){ |
| 888 | $form['#action'] = url('photos/image/'.arg(2)); |
| 889 | } |
| 890 | $form['#submit'] = array('photos_comment_form_submit'); |
| 891 | } |
| 892 | |
| 893 | if (isset($form['type']) && isset($form['#node']) && user_access('create photo')) { |
| 894 | $node = $form['#node']; |
| 895 | if ($form['type']['#value'] .'_node_form' == $form_id){ |
| 896 | if(variable_get('photos_'.$node->type, 0)) { |
| 897 | $form += photos_upload_form($form_state); |
| 898 | } |
| 899 | if(variable_get('photos_quote_'.$node->type, 0) && !variable_get('photos_'.$node->type, 0)){ |
| 900 | $form['new'] = array( |
| 901 | '#title' => t('Image'), |
| 902 | '#weight' => -4, |
| 903 | '#type' => 'fieldset', |
| 904 | '#collapsible' => TRUE, |
| 905 | ); |
| 906 | } |
| 907 | if(variable_get('photos_quote_'.$node->type, 0)){ |
| 908 | $form['new']['quote'] = array( |
| 909 | '#value'=>'<div id="potos-thickbox">'.l(t('Insert an existing image'),'photos/quote',array('attributes'=>array('title' => t('Choose an image from my albums to insert into the node'),'target' => '_blank'))).'</div>', |
| 910 | ); |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | function photos_comment_form_submit($form, &$form_state) { |
| 917 | _comment_form_submit($form_state['values']); |
| 918 | if(arg(0) == 'comment'){ |
| 919 | $arg = |