00001 <?php
00023 $modules_names[] = "Gallery2";
00024 $modules_versions[] = "0.1";
00025 $modules_descriptions[] = "A simple but powerful gallery";
00026
00027 $modules_setup[] = "modulesetup_gallery2";
00028
00029 $profilemodules[] = "profilemodule_gallery2";
00030 $modules_globalID[] = "globalID_gallery2";
00031
00032 $modules[] = "parse_gallery2";
00033
00034 $page_help["\gallery(txt1)"] = "This will show the gallery with the global ID txt1.";
00035 $page_help["\galleryimage(txt1,txt2,txt3)"] = "This will show the image thumbnail for the image with the global ID txt1. If txt2 is present the image will be floated to the alignment as described. Accepted values are left, center and right. If you write anything at all as txt3, the shown thumbnail will not be linked to the midsize view. If omitted, the image will be linked.";
00036 $page_help["\profilegallerylist(txt1)"] = "This will show a list of profiles where there is at least one image in the user's profile gallery. txt1 is optional, and is the style of listing. Defaults to three-up.";
00037
00038
00039 $gallery_options = array(
00040 "page_id" => 12,
00041 "title" => i18n("Travelsized Images"),
00042 "menu_id" => 100,
00043 "maxwidth" => 1600,
00044 "maxheight" => 1200,
00045 "midwidth" => 600,
00046 "midheight" => 480,
00047 "thumbwidth" => 120,
00048 "thumbheight" => 120,
00049 "viewType" => 0,
00050 "viewLevel" => 0,
00051 "commentLevel" => 1,
00052 "editLevel" => 4,
00053 "embedLevel" => 0,
00054 );
00055
00056
00057 if( file_exists( $module_folder . "/gallery/options.inc" ) )
00058 {
00059 $temp_options = $gallery_options;
00060
00061 include( $module_folder . "/gallery/options.inc" );
00062 $temp_options["maxwidth"] = $gallery_options["galleryoption_resize_width"];
00063 $temp_options["maxheight"] = $gallery_options["galleryoption_resize_height"];
00064 $temp_options["midwidth"] = $gallery_options["galleryoption_midsize_width"];
00065 $temp_options["midheight"] = $gallery_options["galleryoption_midsize_height"];
00066 $gallery_options = $temp_options;
00067
00068 file_put_contents( $module_folder . "/gallery/options.php", array_export( $gallery_options, "gallery_options" ) );
00069 unlink( $module_folder . "/gallery/options.inc" );
00070 }
00071
00072 if( file_exists( $module_folder . "/gallery/options.php" ) )
00073 include( $module_folder . "/gallery/options.php" );
00074
00076 class gallery2_image extends lockableClass
00077 {
00078 var $imagename;
00079 var $parentGallery;
00080 var $prevGlobalID;
00081 var $nextGlobalID;
00082
00084
00085 var $thumbURL;
00086 var $imageURL;
00087 var $midsizeURL;
00088 var $globalID;
00089 var $splitID;
00090
00091
00093
00094 var $descriptions;
00095 var $viewCount;
00096 var $commentCount;
00097 var $width;
00098 var $height;
00099 var $weight;
00100 var $comments;
00101
00102
00104 var $dataFile;
00105 var $commentFile;
00106
00108
00116 function gallery2_image( $parentGallery, $imagename )
00117 {
00118 global $languages;
00119
00120 $this->parentGallery = &$parentGallery;
00121 $this->imagename = $imagename;
00122
00123 $this->thumbURL = $this->parentGallery->baseurl . "/thumbs/" . $imagename;
00124 $this->midsizeURL = $this->parentGallery->baseurl . "/midsize/" . $imagename;
00125 $this->imageURL = $this->parentGallery->baseurl . "/images/" . $imagename;
00126 $this->globalID = $this->parentGallery->globalID . "/" . $imagename;
00127 $this->splitID = $this->parentGallery->splitID;
00128 $this->splitID[] = $imagename;
00129 $this->dataFile = $this->parentGallery->basedir . "/data/" . $imagename . ".php";
00130 $this->commentFile = $this->parentGallery->basedir . "/comments/" . $imagename . ".php";
00131 $this->lockfile = $this->parentGallery->basedir . "/comments/" . $imagename . ".lock";
00132
00133 if( file_exists( $this->dataFile ) )
00134 {
00135 include( $this->dataFile );
00136 $this->descriptions = $image["descriptions"];
00137 $this->viewCount = $image["viewCount"];
00138 $this->commentCount = $image["commentCount"];
00139 $this->width = $image["width"];
00140 $this->height = $image["height"];
00141 $this->weight = $image["weight"];
00142
00143 $comments = array();
00144 if( file_exists( $this->commentFile ) )
00145 include( $this->commentFile );
00146 $this->comments = $comments;
00147 }
00148 else
00149 {
00151
00152
00153 foreach( $languages as $key => $value )
00154 {
00155 if( file_exists( $this->parentgallery->basedir . "/data/" . $this->imagename . ".$value.txt" ) )
00156 {
00157 $theData = file_get_contents( $this->parentGallery->basedir . "/data/" . $this->imagename . ".$value.txt" );
00158 unlink( $this->parentgallery->basedir . "/data/" . $this->imagename . ".$value.txt" );
00159 }
00160 $this->descriptions[$value] = $theData;
00161 }
00162
00163 $this->viewCount = 0;
00164 list( $this->width, $this->height ) = getimagesize( $this->parentGallery->basedir . "/images/" . $this->imagename );
00165 $this->weight = fileweight( $this->parentGallery->basedir . "/images/" . $this->imagename );
00166
00167 $usercomments = array();
00168 if( file_exists( $this->parentGallery->basedir . "/comments/" . $this->imagename . ".inc" ) )
00169 include( $this->parentGallery->basedir . "/comments/" . $this->imagename . ".inc" );
00170 $this->comments = $usercomments;
00171 if( file_exists( $this->parentGallery->basedir . "/comments/" . $this->imagename . ".inc" ) )
00172 unlink( $this->parentGallery->basedir . "/comments/" . $this->imagename . ".inc" );
00173
00174 $commenthandler = new commentHandler($this->comments, $this->parentGallery->owner, $this->parentGallery->commentLevel, $this->parentGallery->editLevel);
00175 $this->commentCount = $commenthandler->numberOfComments();
00176
00177 $this->save();
00178 }
00179 }
00180
00189 function save($comment = null)
00190 {
00191 $image["descriptions"] = $this->descriptions;
00192 $image["viewCount"] = $this->viewCount;
00193 $image["commentCount"] = $this->commentCount;
00194 $image["width"] = $this->width;
00195 $image["height"] = $this->height;
00196 $image["weight"] = $this->weight;
00197 if( file_exists( $this->dataFile ) )
00198 unlink( $this->dataFile );
00199 file_put_contents( $this->dataFile, array_export( $image, "image" ) );
00200
00201 if( is_dir( $this->parentGallery->basedir ) && !is_dir( $this->parentGallery->basedir . "/comments" ) )
00202 mkdir( $this->parentGallery->basedir . "/comments" );
00203
00204 $comments = $this->comments;
00205 if( file_exists( $this->commentFile ) )
00206 unlink( $this->commentFile );
00207 file_put_contents( $this->commentFile, array_export( $comments, "comments" ) );
00208
00209
00210 global $subscriptions;
00211 if( $comment == null )
00212 {
00213 global $language;
00214 $subject = i18n( "The image ##0## in the gallery ##1## has a been changed", array( $this->imagename, $this->parentGallery->title ) );
00215 $message = i18n( "The image was edited. The description of the image is:" ) . "\n" . $this->descriptions[$language];
00216 }
00217 else if( $comment[0] != "" || $comment[1] != "" )
00218 {
00219 $subject = i18n( "The image ##0## in the gallery ##1## has a new comment", array( $this->imagename, $this->parentGallery->title ) );
00220 $message .= i18n( "Comment by ##0##:", array( $comment[0] ) ) . "\n" . $comment[1];
00221 }
00222 if( $subject != "" )
00223 $subscriptions->handle( $this->getGlobalID("view"), $this->parentGallery->owner, $this->parentGallery->viewLevel, $subject, $message );
00224 }
00225
00229 function getGlobalID( $editingFunction )
00230 {
00231 $tempSplitID = $this->splitID;
00232 if( $this->parentGallery->profileGallery )
00233 $tempSplitID[3] = "$editingFunction";
00234 else
00235 $tempSplitID[1] = "$editingFunction";
00236 return implode( "/", $tempSplitID );
00237 }
00238
00242 function render()
00243 {
00244
00245 global $language, $gallery_options;
00246
00247 $breadcrumbs = $this->parentGallery->getBreadcrumbs();
00248 $renderedTrail = $breadcrumbs->render();
00249
00250 if( $this->prevGlobalID != "" )
00251 $navigationControls = drawCommand( "«", i18n("Previous image"), globalIDtoURL( $this->prevGlobalID ) );
00252 else
00253 $navigationControls = "(«)";
00254
00255 $navigationControls .= " " . drawCommand( "Gallery", i18n("Return to the gallery"), globalIDtoURL($this->parentGallery->globalID) ) . " ";
00256
00257 if( $this->nextGlobalID != "" )
00258 $navigationControls .= drawCommand( "»", i18n("Next image"), globalIDtoURL( $this->nextGlobalID ) );
00259 else
00260 $navigationControls .= "(»)";
00261
00262 if( !is_dir( $this->parentGallery->basedir . "/midsize" ) )
00263 mkdir( $this->parentGallery->basedir . "/midsize" );
00264 if( !file_exists( $this->parentGallery->basedir . "/midsize/" . $this->imagename ) )
00265 {
00266 list($x, $y) = getimagesize( $this->parentGallery->basedir . "/images/" . $this->imagename );
00267 if( $x > $gallery_options["midwidth"] )
00268 {
00269 $resize_factor = $gallery_options["midwidth"] / $x;
00270 $x = $gallery_options["midwidth"];
00271 $y = $y * $resize_factor;
00272 }
00273 if( $y > $gallery_options["midheight"] )
00274 {
00275 $resize_factor = $gallery_options["midheight"] / $y;
00276 $x = $x * $resize_factor;
00277 $y = $gallery_options["midheight"];
00278 }
00279 scaleImage( $this->parentGallery->basedir . "/images/" . $this->imagename, $this->parentGallery->basedir . "/midsize/" . $this->imagename, $x, $y );
00280 }
00281
00282 $fullsizeCommand = drawCommand( "♦", i18n("Show full size"), $this->imageURL );
00283
00284
00285 if( userAllows( $this->parentGallery->owner, $this->parentGallery->embedLevel ) )
00286 {
00287 $embedLinks = array(
00288 "BBCode: " => "[url=" . globalIDtoURL( $this->getGlobalID( "view" ) ) . "][img]" . $this->thumbURL . "[/img][/url]",
00289 "Travelsized: " => "\galleryimage(" . $this->getGlobalID( "view" ) . ")",
00290 "HTML: " => htmlentities( "<a href=\"" . globalIDtoURL( $this->getGlobalID( "view" ) ) . "\"><img src=\"" . $this->thumbURL . "\" alt=\"" . $this->imagename . "\"></a>" ) );
00291
00292 $embedData = "";
00293 foreach( $embedLinks as $name => $text )
00294 $embedData .= "<div class=\"gallery-embed-item\"><span class=\"gallery-embed-name\">$name</span><input type=\"text\" class=\"gallery-embed-text\" value=\"" . $text . "\"/></div>";
00295 }
00296
00297 $comments = array();
00298 if( file_exists( $this->commentFile ) )
00299 include( $this->commentFile );
00300 $this->comments = $comments;
00301 $commenthandler = new commentHandler($this->comments, $this->parentGallery->owner, $this->parentGallery->commentLevel, $this->parentGallery->editLevel);
00302 $commenthandler->thisPageURL = globalIDtoURL( $this->getGlobalID( "view" ) );
00303 if( $commenthandler->commentsChanged )
00304 {
00305 if( $this->lock() )
00306 {
00307 $this->comments = $commenthandler->comments;
00308 $this->commentCount = $commenthandler->numberOfComments();
00309 $this->save( array( $commenthandler->lastCommenter, $commenthandler->lastComment ) );
00310 }
00311 else
00312 die( i18n("Too many people attempting to access the same image at the same time!") );
00313 $this->unlock();
00314 }
00315
00316
00317 global $subscriptions;
00318 $renderedSubscriptionControl = $subscriptions->renderSubscribeControl( $this->globalID, false, " discussSubscribeControl" );
00319
00320 $renderedImage .= "
00321 <div class=\"wikirightalign\">$renderedSubscriptionControl</div>
00322 <div class=\"gallery-midsize\">
00323 <div class=\"gallery-midsize-left\">" . $renderedTrail . "</div>
00324 <div class=\"gallery-midsize-right\">$navigationControls $fullsizeCommand</div>
00325 <div class=\"gallery-midsize-image\"><a href=\"" . $this->imageURL . "\"><img border=\"0\" alt=\"" . $this->imagename . "\" src=\"" . $this->midsizeURL . "\" /></a></div>
00326 <div class=\"gallery-midsize-description-title\">" . i18n("Description") . "</div>
00327 <div class=\"gallery-midsize-description\">" . parse_page_data( $this->descriptions[$language] ) . "</div>";
00328 if( userAllows( $this->parentGallery->owner, $this->parentGallery->embedLevel ) )
00329 $renderedImage .= "
00330 <div class=\"gallery-embed-title\">" . i18n("Embedding") . "</div>
00331 <div class=\"gallery-embed\">$embedData</div>";
00332 $renderedImage .= "
00333 </div>" . $commenthandler->renderComments() . $commenthandler->renderCommentsAdder();
00334 return $renderedImage;
00335 }
00336 }
00337
00339 class gallery2_gallery
00340 {
00342 var $globalID;
00343 var $splitID;
00344 var $title;
00345 var $description;
00346 var $viewType;
00347
00348 var $images;
00349 var $subgalleries;
00350
00351 var $owner;
00352 var $viewLevel;
00353 var $commentLevel;
00354 var $editLevel;
00355 var $embedLevel;
00356
00357 var $profileGallery = false;
00358 var $edit = false;
00359 var $editMode = "edit";
00360 var $displayImage = null;
00361 var $error = false;
00362
00363 var $basedir;
00364 var $baseurl;
00365
00366 var $imageOrder;
00367
00376 function gallery2_gallery( $globalID, $loadMore = true )
00377 {
00378 global $setup_folder, $userinfo_folder, $viewUser, $module_folder, $gallery_options;
00379
00380 $this->splitID = explode("/", $globalID);
00381 $this->subgalleries = array();
00382
00383 if( strpos( end($this->splitID), "." ) > 0 )
00384 {
00385 $this->displayImage = end( $this->splitID );
00386 $this->splitID = array_slice( $this->splitID, 0, -1 );
00387 $this->globalID = implode( "/", $this->splitID );
00388 }
00389 else
00390 $this->globalID = $globalID;
00391
00392 if( $this->splitID[0] == "user")
00393 {
00394
00395
00396 if(
00397 array_key_exists( 3, $this->splitID ) &&
00398 ( $this->splitID[3] == "edit" ||
00399 $this->splitID[3] == "thumbnail" ||
00400 $this->splitID[3] == "moveup" ||
00401 $this->splitID[3] == "movedown" ||
00402 $this->splitID[3] == "upload" ||
00403 $this->splitID[3] == "replace" ||
00404 $this->splitID[3] == "new" ||
00405 $this->splitID[3] == "rename" ||
00406 $this->splitID[3] == "details" ||
00407 $this->splitID[3] == "move" ||
00408 $this->splitID[3] == "delete"
00409 )
00410 )
00411 {
00412 $tempID = array_slice( $this->splitID, 4);
00413 $this->edit = true;
00414 $this->editMode = $this->splitID[3];
00415
00416 }
00417
00418 else if( array_key_exists( 3, $this->splitID ) && ( $this->splitID[3] == "view" || $this->splitID[3] == "gallery" ) )
00419 $tempID = array_slice( $this->splitID, 4);
00420 else
00421 {
00422
00423 $this->splitID[] = "view";
00424 $this->globalID = implode( "/", $this->splitID );
00425 $tempID = array();
00426 }
00427 $this->owner = $this->splitID[1];
00428 $this->basedir = $userinfo_folder . "/". $this->owner . "/gallery";
00429
00430 if( count($tempID) > 0 )
00431 {
00432 array_splice( $tempID, 0, 0, array("") );
00433 $this->basedir .= implode( "/galleries/", $tempID);
00434 }
00435 $this->profileGallery = true;
00436 }
00437 else
00438 {
00439 if( array_key_exists( 1, $this->splitID ) && (
00440 $this->splitID[1] == "edit" ||
00441 $this->splitID[1] == "thumbnail" ||
00442 $this->splitID[1] == "moveup" ||
00443 $this->splitID[1] == "movedown" ||
00444 $this->splitID[1] == "upload" ||
00445 $this->splitID[1] == "replace" ||
00446 $this->splitID[1] == "new" ||
00447 $this->splitID[1] == "rename" ||
00448 $this->splitID[1] == "details" ||
00449 $this->splitID[1] == "move" ||
00450 $this->splitID[1] == "delete"
00451 )
00452 )
00453 {
00454 $this->edit = true;
00455 $this->editMode = $this->splitID[1];
00456 }
00457 $tempID = array_slice( $this->splitID, 2 );
00458 $this->basedir = $module_folder . "/gallery/" . implode( "/galleries/", $tempID );
00459 }
00460
00461 if( $this->profileGallery )
00462 $this->baseurl .= $userinfo_folder . "/" . $this->owner . "/gallery/";
00463 else
00464 $this->baseurl .= $module_folder . "/gallery/";
00465 $this->baseurl .= implode( "/galleries/", $tempID );
00466 $this->baseurl = str_replace( "//", "/", $this->baseurl );
00467 $this->baseurl = siteURL( true ) . $this->baseurl;
00468
00469 if( is_dir( $this->basedir ) && file_exists( $this->basedir . "/gallery.php" ) )
00470 {
00471 include( $this->basedir . "/gallery.php" );
00472 $this->title = $gallery["title"];
00473 $this->description = $gallery["description"];
00474 $this->viewType = $gallery["viewType"];
00475 if( $this->viewType == "" )
00476 $this->viewType = "table";
00477 $this->viewLevel = $gallery["viewLevel"];
00478 $this->commentLevel = $gallery["commentLevel"];
00479 $this->editLevel = $gallery["editLevel"];
00480 $this->embedLevel = $gallery["embedLevel"];
00481 $this->imageOrder = $gallery["imageOrder"];
00482
00483
00484
00485 if( $this->profileGallery && count( $this->splitID ) == 4 )
00486 {
00487 if( !is_dir($this->basedir . "/images") )
00488 mkdir($this->basedir . "/images");
00489 if( !is_dir($this->basedir . "/data") )
00490 mkdir($this->basedir . "/data");
00491 if( !is_dir($this->basedir . "/comments") )
00492 mkdir($this->basedir . "/comments");
00493 if( !is_dir($this->basedir . "/thumbs") )
00494 mkdir($this->basedir . "/thumbs");
00495 if( !is_dir($this->basedir . "/galleries") )
00496 mkdir($this->basedir . "/galleries");
00497 }
00498 }
00499 else if( !( is_dir( $this->basedir ) && is_dir( $this->basedir . "/images" ) ) && $this->profileGallery && count($this->splitID) == 4 )
00500 {
00501
00502 mkdir( $this->basedir );
00503 mkdir( $this->basedir . "/images" );
00504 mkdir( $this->basedir . "/data" );
00505 mkdir( $this->basedir . "/comments" );
00506 mkdir( $this->basedir . "/thumbs" );
00507 mkdir( $this->basedir . "/galleries" );
00508
00509
00510 $this->title = i18n( "##0##'s gallery", array(getUserInfo( $this->owner, "name" )) );
00511 $this->description = i18n( "No description - change it by editing the gallery's details" );
00512 $this->viewType = $gallery_options["viewType"];
00513 $this->viewLevel = $gallery_options["viewLevel"];
00514 $this->commentLevel = $gallery_options["commentLevel"];
00515 $this->editLevel = $gallery_options["editLevel"];
00516 $this->embedLevel = $gallery_options["embedLevel"];
00517 $this->imageOrder = array();
00518 $this->images = array();
00519 $this->save();
00520 }
00521 else if( is_dir( $this->basedir ) )
00522 {
00524
00525
00526 if( file_exists( $this->basedir . "/gallery.$language.txt" ) )
00527 $filecontents = file_get_contents( $this->basedir . "/gallery.$language.txt" );
00528 else if( file_exists( $this->basedir . "/gallery.txt" ) )
00529 $filecontents = file_get_contents( $this->basedir . "/gallery.txt" );
00530 else
00531 $filecontents = "No title\nNo description file found";
00532
00533 $galleryinfobegpos = strpos( $filecontents, "\n" );
00534 $this->title = substr( $filecontents, 0, $galleryinfobegpos );
00535 $this->description = substr( $filecontents, $galleryinfobegpos );
00536
00537
00538
00539
00540 $this->viewType = $gallery_options["viewType"];
00541 $this->viewLevel = $gallery_options["viewLevel"];
00542 $this->commentLevel = $gallery_options["commentLevel"];
00543 $this->editLevel = $gallery_options["editLevel"];
00544 $this->embedLevel = $gallery_options["embedLevel"];
00545 $this->imageOrder = array();
00546 $this->images = array();
00547
00548
00549 if( file_exists( $this->basedir . "/images" ) )
00550 {
00551 $dir_handle = opendir( $this->basedir . "/images" );
00552 while( $file = readdir( $dir_handle ) )
00553 {
00554 if( substr($file, 0, 1) != "." )
00555 $this->imageOrder[] = $file;
00556 }
00557 closedir($dir_handle);
00558 }
00559
00560
00561 unlink_multiple( $this->basedir . "/gallery.*" );
00562 $this->save();
00563 }
00564 else
00565 {
00566
00567 $this->error = true;
00568 $loadMore = false;
00569 }
00570
00571 if( $loadMore )
00572 {
00573 $this->loadSubgalleries();
00574 $this->loadImages();
00575 }
00576
00577 if( $this->edit && !userAllows( $this->owner, $this->editLevel ) )
00578 $this->edit = false;
00579 }
00580
00584 function loadSubgalleries()
00585 {
00586 if( file_exists( $this->basedir . "/galleries" ) )
00587 {
00588 $fp = opendir( $this->basedir . "/galleries" );
00589 while ($file = readdir($fp)) {
00590 if( substr($file, 0, 1) != "." )
00591 $this->subgalleries[] = new gallery2_gallery( $this->globalID . "/" . $file, false );
00592 }
00593 closedir($fp);
00594 }
00595 }
00596
00600 function loadImages()
00601 {
00602
00603 $this->images = array();
00604 if( file_exists( $this->basedir . "/images" ) )
00605 {
00606 $dir_handle = opendir( $this->basedir . "/images" );
00607 while( $file = readdir( $dir_handle ) )
00608 {
00609 if( substr($file, 0, 1) != "." )
00610 $this->images[$file] = new gallery2_image( &$this, $file );
00611 }
00612 closedir($dir_handle);
00613 }
00614
00615
00616 foreach( $this->images as $key => $image )
00617 {
00618 if( ! in_array( $image->imagename, $this->imageOrder ) )
00619 $this->imageOrder[] = $image->imagename;
00620 }
00621
00622
00623
00624 $tempImageorder = array_reverse( $this->imageOrder, true );
00625 foreach( $tempImageorder as $key => $value )
00626 {
00627 $tempImage = $this->images[$value];
00628 unset( $this->images[$value] );
00629 array_splice( $this->images, 0, 0, array($tempImage) );
00630 }
00631
00633 $prevImage = null;
00634 $thisPrev = null;
00635 foreach( $this->images as $key => $image )
00636 {
00637 if( $prevImage != null )
00638 $this->images[$key]->prevGlobalID = $this->images[$prevImage]->globalID;
00639 $prevImage = $key;
00640 if( $thisPrev != null )
00641 $this->images[$thisPrev]->nextGlobalID = $this->images[$key]->globalID;
00642 $thisPrev = $key;
00643 }
00644
00645 if( count( $this->images ) > 1 )
00646 {
00647 $this->images[0]->nextGlobalID = $this->images[1]->globalID;
00648 $this->images[1]->prevGlobalID = $this->images[0]->globalID;
00649 }
00650 }
00651
00657 function save()
00658 {
00659 $gallery["title"] = $this->title;
00660 $gallery["description"] = $this->description;
00661 $gallery["viewType"] = $this->viewType;
00662 $gallery["viewLevel"] = $this->viewLevel;
00663 $gallery["commentLevel"] = $this->commentLevel;
00664 $gallery["editLevel"] = $this->editLevel;
00665 $gallery["embedLevel"] = $this->embedLevel;
00666 $gallery["imageOrder"] = $this->imageOrder;
00667
00668 if( file_put_contents( $this->basedir . "/gallery.php", array_export( $gallery, "gallery" ) ) )
00669 return true;
00670 else
00671 return "An error occured while saving the gallery settings!";
00672 }
00673
00677 function getGlobalID( $editingFunction )
00678 {
00679 $tempSplitID = $this->splitID;
00680 if( $this->profileGallery )
00681 $tempSplitID[3] = "$editingFunction";
00682 else
00683 $tempSplitID[1] = "$editingFunction";
00684 return implode( "/", $tempSplitID );
00685 }
00686
00692 function getBreadcrumbs()
00693 {
00694 $tempSplitID = $this->splitID;
00695
00696 if( $this->profileGallery )
00697 $tempSplitID[3] = $this->edit ? "edit" : "view";
00698 else
00699 $tempSplitID[1] = $this->edit ? "edit" : "view";
00700
00701 $i = 0;
00702 $firstGallery = true;
00703
00704 if( $this->profileGallery )
00705 $tempID = "user/" . $this->splitID[1] . "/gallery2";
00706 else
00707 $tempID = "gallery2/" . $tempSplitID[1];
00708 foreach( $tempSplitID as $key => $theID )
00709 {
00710
00711
00712
00713
00714 if( ( $this->profileGallery && $i < 3 ) || ( $i < 2 ) )
00715 $i++;
00716 else
00717 {
00718 $tempID .= "/$theID";
00719
00720 if( $tempSplitID[$key] == end( $tempSplitID ) )
00721 {
00722 $theTitle = $this->title;
00723 $imageCount = count($this->imageOrder);
00724 $thisClass = "-current";
00725 }
00726 else
00727 {
00728 $parentgallery = new gallery2_gallery( $tempID, false );
00729 $imageCount = count($parentgallery->imageOrder);
00730 $theTitle = $parentgallery->title;
00731
00732 }
00733
00734 if( $firstGallery )
00735 $trail = new breadcrumbs( "$theTitle ($imageCount)", globalIDtoURL($tempID) );
00736 else
00737 $trail->addCrumb( "$theTitle ($imageCount)", globalIDtoURL($tempID) );
00738
00739 $firstGallery = false;
00740 }
00741 }
00742
00743 if( $this->displayImage )
00744 $trail->addCrumb( $this->displayImage, globalIDtoURL( $tempID . "/" . $this->displayImage ) );
00745
00746 return $trail;
00747 }
00748
00749
00758 function optionSubgalleries( $currentGallery = "", $level )
00759 {
00760 if( $this->globalID == $currentGallery )
00761 {
00762 $itsHere = i18n(" ##0## Currently here", array("<--") );
00763 $itsHere2 = " selected";
00764 }
00765
00766 if( $this->profileGallery && $level == "" )
00767 $profileName = i18n( "##0##'s profile gallery: ", array( getUserInfo( $this->owner, "name" ) ) );
00768
00769
00770 $renderedList .= "
00771 <option$itsHere2 value=\"" . $this->globalID . "\">$level$profileName" . $this->title . " (" . count($this->imageOrder) . ")$itsHere</option>";
00772
00773 $this->loadSubgalleries();
00774
00775
00776 $level .= " ";
00777
00778
00779 foreach( $this->subgalleries as $key => $theGallery )
00780 $renderedList .= $theGallery->optionSubgalleries( $currentGallery, $level);
00781
00782 return $renderedList;
00783 }
00784
00790 function countSubImages()
00791 {
00792 if( count( $this->images ) == 0 )
00793 $this->loadImages();
00794
00795
00796 $count += count( $this->images );
00797
00798 if( count( $this->subgalleries ) == 0 )
00799 $this->loadSubgalleries();
00800
00801
00802 foreach( $this->subgalleries as $key => $theGallery )
00803 $count += $theGallery->countSubImages();
00804
00805 return $count;
00806 }
00807
00813 function userCanEdit()
00814 {
00815 if( $this->owner == currentUser() )
00816 return true;
00817
00818 if( userAllows(currentUser(), $this->editLevel ) )
00819 return true;
00820
00821 if( ! $this->profileGallery && isAllowed( currentUser(), "module_gallery_edit" ) )
00822 return true;
00823
00824
00825 if( isAllowed( currentUser(), "global_admin" ) )
00826 return true;
00827
00828
00829 return false;
00830 }
00831
00837 function userCanView()
00838 {
00839 if( $this->owner == currentUser() )
00840 return true;
00841
00842 if( userAllows(currentUser(), $this->viewLevel ) )
00843 return true;
00844
00845 if( ! $this->profileGallery && isAllowed( currentUser(), "module_gallery_view" ) )
00846 return true;
00847
00848
00849 if( isAllowed( currentUser(), "global_admin" ) )
00850 return true;
00851
00852
00853 return false;
00854 }
00855
00862 function renderEditor()
00863 {
00864 global $formatting_toolbar, $languages, $gallery_options;
00865 $tempSplitID = $this->splitID;
00866
00867 $uploadID = $this->getGlobalID( "upload" );
00868 $newID = $this->getGlobalID( "new" );
00869 $detailsID = $this->getGlobalID( "details" );
00870 $moveID = $this->getGlobalID( "move" );
00871 $deleteID = $this->getGlobalID( "delete" );
00872
00873 $renderedGallery = "<div class=\"wikirightalign\">";
00874
00875 if (!$this->profileGallery || ($this->profileGallery && endKey($this->splitID) > 3))
00876 $renderedGallery .= drawCommand( i18n("Rename"), i18n("Rename the gallery physically"), globalIDtoURL($moveID) ) . " ";
00877 else
00878 $renderedGallery .= "(" . i18n("Rename") . ") ";
00879 $renderedGallery .= drawCommand( i18n("Delete"), i18n("Delete this gallery"), globalIDtoURL($deleteID) ) . " ";
00880 $renderedGallery .= " | ";
00881 $renderedGallery .= drawCommand( i18n("New Subgallery"), i18n("Create new subgallery"), globalIDtoURL($newID) ) . " ";
00882 $renderedGallery .= drawCommand( i18n("Edit details"), i18n("Edit the gallery's title and description"), globalIDtoURL($detailsID) ) . " ";
00883 $renderedGallery .= drawCommand( i18n("Upload"), i18n("Upload a new image"), globalIDtoURL($uploadID) );
00884 $renderedGallery .= "</div>";
00885
00886 switch( $this->editMode )
00887 {
00888 case "thumbnail":
00889
00890 switch( $_REQUEST["thumbtype"] )
00891 {
00892 case "cropnresize":
00893 if (file_exists( $this->basedir . "/images/" . $this->displayImage )) {
00894 $image = $this->basedir . "/images/" . $this->displayImage;
00895 $image_url = $this->baseurl . "/images/" . $this->displayImage;
00896 $dest_image = $this->basedir . "/thumbs/" . $this->displayImage;
00897 $ext = checkImageMimetype( $image );
00898 }
00899
00901
00913 $url = globalIDtoURL( $this->globalID . "/" . $this->displayImage, array( "thumbtype" => "cropnresize", "theme" => "empty" ) );
00914 $margin = 10;
00915
00916 if(!isset($_POST['step'])) $title = '1';
00917 else $title = $_POST['step'];
00918
00919 $data = '
00920 <html>
00921 <head>
00922 <title>' . i18n("Cropping gallery image - step") . ' ' . $title . '</title>
00923 </head>
00924 <body style="margin: '.$margin.'px;">';
00925
00926 if(!isset($_POST['tx']) && !isset($_POST['fx']))
00927 {
00928 $data .= '
00929 <form method="post" action="'.$url.'">
00930 <input type="image" src="'.$image_url.'"><p>';
00931 if(!isset($_POST['x']))
00932 {
00933 $data .= '
00934 <input type="hidden" name="step" value="2">
00935 ' . i18n("Click to mark the first corner of the selection rectangle.") . " " . i18n("You will be able to review the result before cropping");
00936 }else{
00937 $data .= '
00938 <input type="hidden" name="step" value="3">
00939 <input type="hidden" name="fx" value="'.$_POST['x'].'">
00940 <input type="hidden" name="fy" value="'.$_POST['y'].'">
00941 ' . i18n("Click to mark the second corner of the selection rectangle.") . ' | <a href="'.$url.'">' . i18n("Start over") . '</a> ' . " " . i18n("You will be able to review the result before cropping");
00942 }
00943 $data .= '
00944 </form>
00945 ';
00946 }
00947
00948 if(isset($_POST['fx']))
00949 {
00950 $data .= '
00951 <form method="post" action="'.$url.'">
00952 <input type="hidden" name="step" value="4">
00953 <input type="image" src="'.$image_url.'">
00954 <input type="hidden" name="tx" value="'.$_POST['fx'].'">
00955 <input type="hidden" name="ty" value="'.$_POST['fy'].'">
00956 <input type="hidden" name="width" value="'.($_POST['x']-$_POST['fx']).'">
00957 <input type="hidden" name="height" value="'.($_POST['y']-$_POST['fy']).'"><p>
00958 <div style="position: absolute;
00959 left:'.($_POST['fx']+$margin).'px;
00960 top: '.($_POST['fy']+$margin).'px;
00961 width: '.($_POST['x']-$_POST['fx']).'px;
00962 height: '.($_POST['y']-$_POST['fy']).'px;
00963 border: 1px solid #fff;">
00964 </div>
00965 ' . i18n("Click the image to crop. The rectangle shown on the picture is the rectangle that will be cropped.") . '| <a href="'.$url.'">' . i18n("Start over") . '</a>
00966 </form>';
00967 }
00968
00969 if(isset($_POST['tx']))
00970 {
00971
00972 cropImage( $image, $dest_image, $_POST["tx"], $_POST["ty"], $_POST["width"], $_POST["height"] );
00973
00974
00975 scaleImage( $dest_image, $dest_image, 120, 120 );
00976
00977 header("Location: " . globalIDtoURL( $this->getGlobalID( "edit" ) ) );
00978 }
00979
00980
00981 return $data;
00982 break;
00983 case "fullsize":
00984
00985 scaleImage( $this->basedir . "/images/" . $this->displayImage, $this->basedir . "/thumbs/" . $this->displayImage, 120, 120 );
00986
00987 header("Location: " . globalIDtoURL( $this->getGlobalID( "edit" ) ) );
00988 break;
00989 }
00990 $renderedGallery = "";
00991 break;
00992 case "moveup":
00993
00994 foreach( $this->imageOrder as $key => $imagename )
00995 {
00996 if( $imagename == $this->displayImage )
00997 {
00998 $tempImage = $this->imageOrder[$key];
00999 unset( $this->imageOrder[$key] );
01000 array_splice( $this->imageOrder, $prevImage, 0, $tempImage );
01001 break;
01002 }
01003 else
01004 $prevImage = $key;
01005 }
01006 $this->save();
01007 header("Location: " . globalIDtoURL( $this->getGlobalID( "edit" ) ) );
01008 break;
01009 case "movedown":
01010
01012 $prevImage = null;
01013 foreach( $this->imageOrder as $key => $imagename )
01014 {
01015 if( $prevImage != null )
01016 {
01017 $tempImage = $this->imageOrder[$prevImage];
01018 unset( $this->imageOrder[$prevImage] );
01019 array_splice( $this->imageOrder, $key, 0, $tempImage );
01020 break;
01021 }
01022 else
01023 {
01024 if( $imagename == $this->displayImage )
01025 $prevImage = $key;
01026 }
01027 }
01028 $this->save();
01029
01030 header("Location: " . globalIDtoURL( $this->getGlobalID( "edit" ) ) );
01031 break;
01032 case "upload":
01033
01034 if( $_POST["saveOptions"] )
01035 {
01036
01037 global $subscriptions;
01038 $errorHandler = new errorHandler( $this->globalID );
01039 foreach ($_FILES["uploadedfile"]["name"] as $thekey => $thevalue) {
01040 $filename = suggestFilename( str_replace("&", "_", str_replace("'", "", stripslashes($_FILES['uploadedfile']['name'][$thekey]))), $this->basedir . "/images" );
01041 $uploadFile = $this->basedir . "/images/$filename";
01042
01043 if( checkImageMimetype( $_FILES['uploadedfile']['tmp_name'][$thekey] ) != false && move_uploaded_file( $_FILES['uploadedfile']['tmp_name'][$thekey], $uploadFile ) )
01044 {
01045 chmod($uploadFile, 0664);
01046
01047 list( $x, $y ) = getimagesize( $uploadFile );
01048
01049 if( is_array($gallery_options) && $x > $gallery_options["maxwidth"] )
01050 {
01051 $resize_factor = $gallery_options["maxwidth"] / $x;
01052 $resized_x = $gallery_options["maxwidth"];
01053 $resized_y = $y * $resize_factor;
01054
01055 if( $resized_y > $gallery_options["maxheight"] )
01056 {
01057 $resize_factor = $gallery_options["maxheight"] / $y;
01058 $resized_x = $x * $resize_factor;
01059 $resized_y = $gallery_options["maxheight"];
01060 }
01061
01062 $errorHandler->handle( i18n( "Resizing ##0##", array( $filename ) ), scaleImage( $uploadFile, $uploadFile, $resized_x, $resized_y ) );
01063 $x = $resized_x; $y = $resized_y;
01064 }
01065 else if( is_array($gallery_options) && $y > $gallery_options["maxheight"] )
01066 {
01067 $resize_factor = $gallery_options["maxheight"] / $y;
01068 $resized_x = $x * $resize_factor;
01069 $resized_y = $gallery_options["maxheight"];
01070 $errorHandler->handle( i18n( "Resizing ##0##", array( $filename ) ), scaleImage( $uploadFile, $uploadFile, $resized_x, $resized_y ) );
01071 $x = $resized_x; $y = $resized_y;
01072 }
01073
01074 $errorHandler->handle( i18n("Thumbnail ##0##", array( $filename) ) , scaleImage( $uploadFile, $this->basedir . "/thumbs/$filename", $gallery_options["thumbwidth"], $gallery_options["thumbheight"] ) );
01075
01076 foreach($languages as $key => $value)
01077 $image["descriptions"][$value] = stripslashes($_POST["picture_comment"]);
01078 $image["viewCount"] = 0;
01079 $image["commentCount"] = 0;
01080 $image["width"] = $x;
01081 $image["height"] = $y;
01082 $image["weight"] = fileweight($uploadFile);
01083
01084 file_put_contents( $this->basedir . "/data/$filename.php", array_export( $image, "image" ) );
01085 file_put_contents( $this->basedir . "/comments/$filename.php", array_export( array(), "comments" ) );
01086
01087 $this->imageOrder[] = $filename;
01088
01089
01090 $subject = i18n( "New image ##0## uploaded to ##1##", array( $filename, $this->title ) );
01091 $message = i18n( "A new image was uploaded to the gallery ##0## with the description:", array( $this->title ) ) . "\n" . stripslashes($_POST["picture_comment"]);
01092 $subscriptions->handle( $this->getGlobalID("view") . "/" . $filename, $this->owner, $this->viewLevel, $subject, $message );
01093 }
01094 else
01095 {
01096 switch ($_FILES['uploadedfile']['error'][$thekey]) {
01097 case 0:
01098 if( checkImageMimetype( $_FILES['uploadedfile']['tmp_name'][$thekey] ) == false )
01099 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), i18n("Image type not supported or not an image file! Only jpg, gif and png are supported image types") );
01100 else
01101 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), false );
01102 break;
01103 case 1:
01104 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), i18n("The uploaded file exceeds the upload_max_filesize directive in php.ini. Please contact your host and rectify this (or better yet, select a smaller file. Most often, this directive states 2MB as the maximum upload size, however as we have 1MB as the maxium here, they have obviously changed it).") );
01105 break;
01106 case 2:
01107 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), i18n("The uploaded file exceeds 1MB in size, and is too large to upload in this manner.") );
01108 break;
01109 case 3:
01110 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), i18n("The uploaded file was only partially uploaded.") );
01111 break;
01112 case 4:
01113
01114 break;
01115 default:
01116 if( checkImageMimetype( $_FILES['uploadedfile']['tmp_name'][$thekey] ) == false )
01117 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), i18n("Image type not supported or not an image file! Only jpg, gif and png are supported image types") );
01118 else
01119 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), false );
01120 }
01121 }
01122 }
01123
01124 $renderedGallery .= $errorHandler->render();
01125
01126 if( !$errorHandler->handled )
01127 {
01128 $this->save();
01129 header("Location: " . globalIDtoURL( $this->getGlobalID( "edit" ) ) );
01130 }
01131 }
01132 else
01133 {
01134 $panel = new optionsPanel("");
01135 $panel->saveTitle = i18n("Upload image");
01136 $panel->resetTitle = i18n("Reset");
01137 $panel->showHeader = false;
01138
01139 $panel->addOption( i18n("Select picture for upload:"), i18n("Please note, the system supports only images of the format JPG, PNG and GIF."), "", "uploadedfile[]", "file");
01140 $panel->addOption( i18n("Description:"), "", i18n("Enter a description of the picture here"), "picture_comment", "pagedata");
01141
01142 $theContent = $panel->render();
01143
01144 $furtherContent = "
01145 <div><input style=\"width: 100%\" id=\"uploadedfile2\" name=\"uploadedfile[]\" type=\"file\" /></div>
01146 <div><input style=\"width: 100%\" id=\"uploadedfile3\" name=\"uploadedfile[]\" type=\"file\" /></div>
01147 <div><input style=\"width: 100%\" id=\"uploadedfile4\" name=\"uploadedfile[]\" type=\"file\" /></div>
01148 <div><input style=\"width: 100%\" id=\"uploadedfile5\" name=\"uploadedfile[]\" type=\"file\" /></div>
01149 <div><input style=\"width: 100%\" id=\"uploadedfile6\" name=\"uploadedfile[]\" type=\"file\" /></div>
01150 <div><input style=\"width: 100%\" id=\"uploadedfile7\" name=\"uploadedfile[]\" type=\"file\" /></div>
01151 <div><input style=\"width: 100%\" id=\"uploadedfile8\" name=\"uploadedfile[]\" type=\"file\" /></div>
01152 <div><input style=\"width: 100%\" id=\"uploadedfile9\" name=\"uploadedfile[]\" type=\"file\" /></div>
01153 <div><input style=\"width: 100%\" id=\"uploadedfile0\" name=\"uploadedfile[]\" type=\"file\" /></div>";
01154
01155 $renderedGallery .= renderInformationBox( i18n("Upload a new image"), $theContent . generate_pagehelplink(), false ) . renderInformationBox( i18n("Additional pictures"), i18n("Select up to 9 additional pictures for upload. These pictures will be given the same description as the first picture. If you wish to assign a different description to one picture, do this afterwards.") . $furtherContent, false );
01156 }
01157 break;
01158 case "replace":
01159
01160
01161 if( $_POST["saveOptions"] )
01162 {
01163 $errorHandler = new errorHandler( $this->globalID );
01164 $filename = $this->displayImage;
01165 $uploadFile = $this->basedir . "/images/$filename";
01166 @unlink( $uploadFile );
01167 @unlink( $this->basedir . "/midsize/$filename" );
01168 @unlink( $this->basedir . "/thumbs/$filename" );
01169
01170
01171 if( checkImageMimetype( $_FILES['uploadedfile']['tmp_name'] ) != false && move_uploaded_file( $_FILES['uploadedfile']['tmp_name'], $uploadFile ) )
01172 {
01173 chmod($uploadFile, 0664);
01174
01175 list( $x, $y ) = getimagesize( $uploadFile );
01176
01177 if( is_array($gallery_options) && $x > $gallery_options["maxwidth"] )
01178 {
01179 $resize_factor = $gallery_options["maxwidth"] / $x;
01180 $resized_x = $gallery_options["maxwidth"];
01181 $resized_y = $y * $resize_factor;
01182
01183 if( $resized_y > $gallery_options["maxheight"] )
01184 {
01185 $resize_factor = $gallery_options["maxheight"] / $y;
01186 $resized_x = $x * $resize_factor;
01187 $resized_y = $gallery_options["maxheight"];
01188 }
01189
01190 $errorHandler->handle( i18n( "Resizing ##0##", array( $filename ) ), scaleImage( $uploadFile, $uploadFile, $resized_x, $resized_y ) );
01191 $x = $resized_x; $y = $resized_y;
01192 }
01193 else if( is_array($gallery_options) && $y > $gallery_options["maxheight"] )
01194 {
01195 $resize_factor = $gallery_options["maxheight"] / $y;
01196 $resized_x = $x * $resize_factor;
01197 $resized_y = $gallery_options["maxheight"];
01198 $errorHandler->handle( i18n( "Resizing ##0##", array( $filename ) ), scaleImage( $uploadFile, $uploadFile, $resized_x, $resized_y ) );
01199 $x = $resized_x; $y = $resized_y;
01200 }
01201
01202 $errorHandler->handle( i18n("Thumbnail ##0##", array( $filename) ) , scaleImage( $uploadFile, $this->basedir . "/thumbs/$filename", $gallery_options["thumbwidth"], $gallery_options["thumbheight"] ) );
01203
01204 include( $this->basedir . "/data/$filename.php" );
01205 foreach( $image["descriptions"] as $key => $description )
01206 $image["descriptions"][$key] = $description . "\n" . i18n("Edit by ##0## on ##1##", array("%%" . currentUser() . "%%", formatTime(time()))) . ": " . stripslashes($_POST["comment"]);
01207 $image["width"] = $x;
01208 $image["height"] = $y;
01209 $image["weight"] = fileweight($uploadFile);
01210
01211 file_put_contents( $this->basedir . "/data/$filename.php", array_export( $image, "image" ) );
01212 }
01213 else
01214 {
01215 switch ($_FILES['uploadedfile']['error']) {
01216 case 0:
01217 if( checkImageMimetype( $_FILES['uploadedfile']['tmp_name'] ) == false )
01218 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), i18n("Image type not supported or not an image file! Only jpg, gif and png are supported image types") );
01219 else
01220 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), false );
01221 break;
01222 case 1:
01223 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), i18n("The uploaded file exceeds the upload_max_filesize directive in php.ini. Please contact your host and rectify this (or better yet, select a smaller file. Most often, this directive states 2MB as the maximum upload size, however as we have 1MB as the maxium here, they have obviously changed it).") );
01224 break;
01225 case 2:
01226 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), i18n("The uploaded file exceeds 1MB in size, and is too large to upload in this manner.") );
01227 break;
01228 case 3:
01229 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), i18n("The uploaded file was only partially uploaded.") );
01230 break;
01231 case 4:
01232
01233 break;
01234 default:
01235 if( checkImageMimetype( $_FILES['uploadedfile']['tmp_name'] ) == false )
01236 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), i18n("Image type not supported or not an image file! Only jpg, gif and png are supported image types") );
01237 else
01238 $errorHandler->handle( i18n("Uploading image ##0##", array($filename) ), false );
01239 }
01240 }
01241
01242 $renderedGallery .= $errorHandler->render();
01243
01244 if( !$errorHandler->handled )
01245 header("Location: " . globalIDtoURL( $this->getGlobalID( "edit" ) ) );
01246 }
01247 else
01248 {
01249 $panel = new optionsPanel("");
01250 $panel->saveTitle = i18n("Upload image");
01251 $panel->resetTitle = i18n("Reset");
01252 $panel->showHeader = false;
01253
01254 $panel->addOption( i18n("Select picture for upload:"), i18n("Please note, the system supports only images of the format JPG, PNG and GIF."), "", "uploadedfile[]", "file");
01255 $panel->addOption( i18n("Description:"), "", i18n("Enter a description of the picture here"), "picture_comment", "pagedata");
01256
01257 $theContent = $panel->render();
01258
01259 $renderedGallery .= renderInformationBox( i18n("Replace ##0## with a new image", array($this->displayImage)), $theContent, false);
01260 }
01261 break;
01262 case "new":
01263 global $gallery2_viewTypes, $permissionlevels_array;
01264
01265 $panel = new optionsPanel("");
01266 $panel->saveTitle = i18n("Create subgallery");
01267 $panel->resetTitle = i18n("Reset");
01268 $panel->showHeader = false;
01269
01270 $values["physicalname"] = ( $_POST["physicalname"] != "" ) ? stripslashes($_POST["physicalname"]) : "gallery";
01271 $values["title"] = ( $_POST["title"] != "" ) ? stripslashes($_POST["title"]) : i18n("Untitled Gallery");
01272 $values["description"] = ( $_POST["description"] != "" ) ? stripslashes($_POST["description"]) : i18n("Enter the new gallery's description here");
01273 $values["viewType"] = ( $_POST["viewType"] != "" ) ? stripslashes($_POST["viewType"]) : $gallery_options["viewType"];
01274 $values["viewLevel"] = ( $_POST["viewLevel"] != "" ) ? stripslashes($_POST["viewLevel"]) : $gallery_options["viewLevel"];
01275 $values["commentLevel"] = ( $_POST["commentLevel"] != "" ) ? stripslashes($_POST["commentLevel"]) : $gallery_options["commentLevel"];
01276 $values["editLevel"] = ( $_POST["editLevel"] != "" ) ? stripslashes($_POST["editLevel"]) : $gallery_options["editLevel"];
01277
01278 $panel->addOption( i18n("Physical name:"), i18n("The filename you will find the gallery under (used for linking)"), $values["physicalname"], "physicalname", "text");
01279 $panel->addOption( i18n("Title:"), i18n("The gallery's human readable name"), $values["title"], "title", "text");
01280 $panel->addOption( i18n("View type"), i18n("How do you wish to present this gallery to the user by default?"), $values["viewType"], "viewType", "select", $gallery2_viewTypes);
01281 $panel->addOption( i18n("View Level:"), i18n("Who, except for yourself, is allowed to view the contents of this gallery?"), $values["viewLevel"], "viewLevel", "select", $permissionlevels_array);
01282 $panel->addOption( i18n("Comment Level:"), i18n("Who, except for yourself, is allowed to comment on the contents of this gallery?"), $values["commentLevel"], "commentLevel", "select", $permissionlevels_array);
01283 $panel->addOption( i18n("Edit Level:"), i18n("Who, except for yourself, is allowed to edit the contents of this gallery?"), $values["editLevel"], "editLevel", "select", $permissionlevels_array);
01284 $panel->addOption( i18n("Embedding Level:"), i18n("Who, except for yourself, is allowed to get embedding codes for the contents of this gallery?"), $values["embedLevel"], "embedLevel", "select", $permissionlevels_array);
01285 $panel->addOption( i18n("Description:"), "", $values["description"], "description", "pagedata");
01286
01287 $newbasedir = $this->basedir . "/galleries/" . str_replace( ".", "-", str_replace( " ", "_", $panel->options["physicalname"]["current"] ) );
01288
01289 if( $_POST["saveOptions"] && file_exists( $newbasedir ) )
01290 $panel->options["physicalname"]["error"] = i18n("A gallery already exists with this name!");
01291
01292 if( $_POST["saveOptions"] && $panel->options["physicalname"]["current"] != "" && ! file_exists( $newbasedir ) )
01293 {
01294 RecursiveMkdir( $newbasedir );
01295 mkdir( $newbasedir . "/comments" );
01296 mkdir( $newbasedir . "/data" );
01297 mkdir( $newbasedir . "/galleries" );
01298 mkdir( $newbasedir . "/images" );
01299 mkdir( $newbasedir . "/thumbs" );
01300
01301 $gallery["title"] = $panel->options["title"]["current"];
01302 $gallery["description"] = $panel->options["description"]["current"];
01303 $gallery["viewType"] = $gallery2_viewTypes[ $panel->options["viewType"]["current"] ];
01304 $gallery["viewLevel"] = $panel->options["viewLevel"]["current"];
01305 $gallery["commentLevel"] = $panel->options["commentLevel"]["current"];
01306 $gallery["editLevel"] = $panel->options["editLevel"]["current"];
01307 $gallery["embedLevel"] = $panel->options["embedLevel"]["current"];
01308 $gallery["imageOrder"] = array();
01309 if( file_put_contents( $newbasedir . "/gallery.php", array_export( $gallery, "gallery" ) ) )
01310 header("Location: " . globalIDtoURL( $this->getGlobalID( "edit" ) . "/" . str_replace(" ", "_", $panel->options["physicalname"]["current"]) ) );
01311 else
01312 $renderedGallery .= "An error occured while saving the gallery settings!";
01313 }
01314 else
01315 $renderedGallery .= renderInformationBox( i18n("Create a new subgallery under ##0##", array($this->title)), $panel->render(), false);
01316
01317 break;
01318 case "rename":
01319
01320 if( $this->displayImage == null )
01321 {
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351 }
01352
01353 else
01354 {
01355 $panel = new optionsPanel("");
01356 $panel->saveTitle = i18n("Rename the image");
01357 $panel->showHeader = false;
01358
01359 $theFiletitle = substr( $this->displayImage, 0, -4 );
01360 $theFilesuffix = substr( $this->displayImage, -4 );
01361
01362 $values["filename"] = $_POST["filename"] ? $_POST["filename"] : $theFiletitle;
01363
01364 $panel->addOption(
01365 i18n("New filename"),
01366 i18n("The new filename for this image - remember this is used for things like linking, so spaces and other interesting characters shold probably be avoided"),
01367 $values["filename"],
01368 "filename",
01369 "text");
01370
01371 if( $_POST["saveOptions"] && $values["filename"] != $theFiletitle )
01372 {
01373 $errorHandler = new errorHandler( globalIDtoURL($this->getGlobalID("rename") . "/" . $this->displayImage) );
01374
01375 $filenames["image file"] = $this->basedir . "/images/" . $this->displayImage;
01376 $filenames["thumbnail file"] = $this->basedir . "/thumbs/" . $this->displayImage;
01377 $filenames["midsize file"] = $this->basedir . "/midsize/" . $this->displayImage;
01378 $filenames["data file"] = $this->basedir . "/data/" . $this->displayImage . ".php";
01379 $filenames["comments file"] = $this->basedir . "/comments/" . $this->displayImage . ".php";
01380
01381 $newFilenames["image file"] = $this->basedir . "/images/" . $values["filename"] . $theFilesuffix;
01382 $newFilenames["thumbnail file"] = $this->basedir . "/thumbs/" . $values["filename"] . $theFilesuffix;
01383 $newFilenames["midsize file"] = $this->basedir . "/midsize/" . $values["filename"] . $theFilesuffix;
01384 $newFilenames["data file"] = $this->basedir . "/data/" . $values["filename"] . $theFilesuffix . ".php";
01385 $newFilenames["comments file"] = $this->basedir . "/comments/" . $values["filename"] . $theFilesuffix . ".php";
01386
01387
01388 if( !file_exists( $filenames["midsize file"] ) )
01389 unset( $filenames["midsize file"] );
01390
01391
01392 foreach( $filenames as $key => $value )
01393 $errorHandler->handle( i18n("Renaming ##0##", array(i18n($key))), rename($value, $newFilenames[$key]) );
01394
01395 if( !$errorHandler->handled )
01396 {
01397
01398 $theKey = array_search( $this->displayImage, $this->imageOrder );
01399 if( is_numeric($theKey) )
01400 {
01401
01402 $this->imageOrder[$theKey] = $values["filename"] . $theFilesuffix;
01403
01404 $this->save();
01405
01406 global $subscriptions;
01407 $subscriptions->renameGlobalID( $this->getGlobalID("view") . "/" . $this->displayImage, $this->getGlobalID("view") . "/" . $values["filename"] . $theFilesuffix );
01408 }
01409
01410 header("Location: " . globalIDtoURL( $this->getGlobalID("edit") ) );
01411 }
01412 else
01413 $renderedGallery = renderInformationBox( i18n("Image rename failed!"), $errorHandler->render() );
01414 }
01415 else if( $_POST["saveOptions"] && $values["filename"] == $theFiletitle )
01416 header("Location: " . globalIDtoURL( $this->getGlobalID("edit") ) );
01417 else
01418 $renderedGallery = renderInformationBox( i18n("Rename image physically?"), $panel->render(), false );
01419 }
01420 break;
01421 case "details":
01422 global $gallery2_viewTypes, $permissionlevels_array, $languages, $languages_names;
01423
01424 if( $this->displayImage == null )
01425 {
01426 $panel = new optionsPanel("");
01427 $panel->saveTitle = i18n("Save gallery details");
01428 $panel->resetTitle = i18n("Reset");
01429 $panel->showHeader = false;
01430
01431 $values["title"] = ( $_POST["title"] != "" ) ? stripslashes($_POST["title"]) : $this->title;
01432 $values["description"] = ( $_POST["description"] != "" ) ? stripslashes($_POST["description"]) : $this->description;
01433 $values["viewType"] = ( $_POST["viewType"] != "" ) ? stripslashes($_POST["viewType"]) : $this->viewType;
01434 $values["viewLevel"] = ( $_POST["viewLevel"] != "" ) ? stripslashes($_POST["viewLevel"]) : $this->viewLevel;
01435 $values["commentLevel"] = ( $_POST["commentLevel"] != "" ) ? stripslashes($_POST["commentLevel"]) : $this->commentLevel;
01436 $values["editLevel"] = ( $_POST["editLevel"] != "" ) ? stripslashes($_POST["editLevel"]) : $this->editLevel;
01437 $values["owner"] = ( $_POST["owner"] != "" ) ? stripslashes($_POST["owner"]) : $this->owner;
01438
01439 $panel->addOption( i18n("Title:"), i18n("The gallery's human readable name"), $values["title"], "title", "text");
01440 $panel->addOption( i18n("View type"), i18n("How do you wish to present this gallery to the user by default?"), $values["viewType"], "viewType", "select", $gallery2_viewTypes);
01441 $panel->addOption( i18n("View Level:"), i18n("Who, except for yourself, is allowed to view the contents of this gallery?"), $values["viewLevel"], "viewLevel", "select", $permissionlevels_array);
01442 $panel->addOption( i18n("Comment Level:"), i18n("Who, except for yourself, is allowed to comment on the contents of this gallery?"), $values["commentLevel"], "commentLevel", "select", $permissionlevels_array);
01443 $panel->addOption( i18n("Edit Level:"), i18n("Who, except for yourself, is allowed to edit the contents of this gallery?"), $values["editLevel"], "editLevel", "select", $permissionlevels_array);
01444 $panel->addOption( i18n("Embedding Level:"), i18n("Who, except for yourself, is allowed to get embedding codes for the contents of this gallery?"), $values["embedLevel"], "embedLevel", "select", $permissionlevels_array);
01445
01446 if( !$this->profileGallery )
01447 $panel->addOption( i18n("Owner:"), i18n("Who owns the gallery (all permissions are relative to this user)"), $values["owner"], "owner", "select", allUsersArray() );
01448 $panel->addOption( i18n("Description:"), "", $values["description"], "description", "pagedata");
01449
01450 if( $_POST["saveOptions"] )
01451 {
01452 $this->title = $panel->options["title"]["current"];
01453 $this->description = $panel->options["description"]["current"];
01454 $this->viewType = $gallery2_viewTypes[ $panel->options["viewType"]["current"] ];
01455 $this->viewLevel = $panel->options["viewLevel"]["current"];
01456 $this->commentLevel = $panel->options["commentLevel"]["current"];
01457 $this->editLevel = $panel->options["editLevel"]["current"];
01458 $this->embedLevel = $panel->options["embedLevel"]["current"];
01459 if( array_key_exists( "owner", $panel->options ) )
01460 $this->owner = $panel->options["owner"]["current"];
01461 $this->save();
01462 header( "Location: " . globalIDtoURL( $this->getGlobalID( "edit" ) ) );
01463 }
01464 else
01465 $renderedGallery .= renderInformationBox( i18n( "Edit gallery details", array( $this->getGlobalID( "view" ) ) ), $panel->render(), false );
01466 }
01467
01468 else
01469 {
01470
01471 foreach( $this->images as $key => $tmpimage )
01472 if( $tmpimage->imagename == $this->displayImage )
01473 $image = &$this->images[$key];
01474
01475 $editlanguage = $_REQUEST["editLanguage"];
01476
01477 $extraReqVars = "&editLanguage=" . $editlanguage;
01478 foreach( $languages as $key => $value )
01479 if( $editlanguage == $value )
01480 $languagename = $languages_names[$key];
01481
01482 $panel = new optionsPanel("");
01483 $panel->saveTitle = i18n("Save image details");
01484 $panel->resetTitle = i18n("Reset");
01485 $panel->showHeader = false;
01486
01487 $panel->addOption( i18n("Description:"), "", $image->descriptions[$editlanguage], "description", "pagedata");
01488
01489 if( $_POST["saveOptions"] )
01490 {
01491 $image->descriptions[$editlanguage] = $panel->options["description"]["current"];
01492 $image->save();
01493 header( "Location: " . globalIDtoURL( $this->getGlobalID( "edit" ) ) );
01494 }
01495 else
01496 $renderedGallery .= renderInformationBox( i18n("Edit ##0## description for the image ##1##", array( $languagename, $image->getGlobalID("view") ) ), $panel->render(), false );
01497 }
01498 break;
01499 case "move":
01500
01501 if( $this->displayImage == null )
01502 {
01503
01504 $oldName = substr($this->basedir, strrpos( $this->basedir, "/" ) + 1);
01505 if( $_POST["saveOptions"] && $_POST["newName"] != $oldName )
01506 {
01507 $theBase = substr($this->basedir, 0, strlen( $this->basedir ) - strlen( $oldName ) );
01508 rename( $this->basedir, $theBase . $_POST["newName"] );
01509 $this->basedir = $theBase . $_POST["newName"];
01510 $this->splitID[end(array_keys($this->splitID))] = $_POST["newName"];
01511 $this->globalID = implode( "/", $this->splitID );
01512 }
01513 else if( $_POST["saveOptions"] && $_POST["newName"] == $oldName )
01514 {
01515 header( "Location: " . globalIDtoURL( $this->getGlobalID("edit") ) );
01516 }
01517 else
01518 {
01519 $panel = new optionsPanel("");
01520 $panel->saveText = i18n("Rename");
01521 $panel->showHeader = false;
01522
01523 $panel->addOption(
01524 i18n("New physical name"),
01525 i18n("The gallery's new physical name - remember this is used for things like linking, so spaces and other interesting characters shold probably be avoided"),
01526 $oldName,
01527 "newName",
01528 "text");
01529
01530 $data = $panel->render();
01531 }
01532 $renderedGallery .= renderInformationBox( i18n("Rename gallery physically"), $data, false );
01533 }
01534
01535 else
01536 {
01537 if( $_POST["saveOptions"] && $this->getGlobalID("view") != $_POST["whatGallery"] )
01538 {
01539
01540 $moveto = new gallery2_gallery($_POST["whatGallery"], false);
01541
01542
01543 $imagefile = $this->basedir . "/images/" . $this->displayImage;
01544 $thumbfile = $this->basedir . "/thumbs/" . $this->displayImage;
01545 $midfile = $this->basedir . "/midsize/" . $this->displayImage;
01546 $datafile = $this->basedir . "/data/" . $this->displayImage . ".php";
01547 $commentsfile = $this->basedir . "/comments/" . $this->displayImage . ".php";
01548
01549
01550 rename( $imagefile, $moveto->basedir . "/images/" . $this->displayImage);
01551 if( file_exists( $midfile ) )
01552 {
01553 if( !is_dir( $moveto->basedir . "/midsize" ) )
01554 mkdir( $moveto->basedir . "/midsize" );
01555 rename( $midfile, $moveto->basedir . "/midsize/" . $this->displayImage);
01556 }
01557 rename( $thumbfile, $moveto->basedir . "/thumbs/" . $this->displayImage);
01558
01559
01560 foreach( $this->images as $key => $image )
01561 if( $image->imagename == $this->displayImage )
01562 {
01563 $image->parentGallery = &$moveto;
01564 break;
01565 }
01566
01567 $image->dataFile = $moveto->basedir . "/data/" . $this->displayImage . ".php";
01568 $image->commentFile = $moveto->basedir . "/comments/" . $this->displayImage . ".php";
01569 $image->save();
01570
01571
01572 unlink( $datafile );
01573 if( file_exists( $commentsfile ) )
01574 unlink( $commentsfile );
01575 foreach( $this->imageOrder as $key => $value )
01576 if( $value == $this->displayImage )
01577 unset( $this->imageOrder[$key] );
01578 $this->save();
01579
01580 global $subscriptions;
01581 $subscriptions->renameGlobalID( $this->getGlobalID("view") . "/" . $this->displayImage, $moveto->getGlobalID("view") . "/" . $this->displayImage );
01582
01583
01584 header( "Location: " . globalIDtoURL( $moveto->getGlobalID("edit") ) );
01585
01586 }
01587 else if( $_POST["saveOptions"] && $this->getGlobalID("view") == $_POST["whatGallery"] )
01588 {
01589 header( "Location: " . globalIDtoURL( $this->getGlobalID("edit") ) );
01590 }
01591 else
01592 {
01593 global $module_folder;
01594
01595 $galleries = array();
01596 $gallerybase = "$module_folder/gallery";
01597
01598 $dir_handle = opendir("$gallerybase");
01599 while ($folder = readdir($dir_handle)) {
01600 if( is_dir( "$gallerybase/$folder" ) && substr($folder, 0, 1) != "." ) {
01601 $theGallery = new gallery2_gallery( "gallery2/view/" . $folder, false );
01602 if( userAllows( $theGallery->owner, $theGallery->editLevel ) )
01603 $galleries[] = $theGallery;
01604 }
01605 }
01606 closedir($dir_handle);
01607
01608
01609 $allusers = allUsersArray();
01610 foreach( $allusers as $key => $username )
01611 {
01612 $theGallery = new gallery2_gallery( "user/$username/gallery", false );
01613 if( userAllows( $username, $theGallery->editLevel ) )
01614 $galleries[] = $theGallery;
01615 }
01616
01617
01618 foreach( $galleries as $key => $theGallery )
01619 $renderedList .= $theGallery->optionSubgalleries( $this->getGlobalID("view"), "");
01620
01621 $data = "
01622 <table class=\"options\">
01623 <tr class=\"options\">
01624 <td colspan=\"2\" class=\"options\">
01625 <p>" . i18n("Select the gallery you wish to move the image to from the drop-down list below") . "</p>
01626 <select style=\"width: 100%;\" name=\"whatGallery\">$renderedList</select>
01627 </td>
01628 <tr class=\"options\">
01629 <td width=\"50%\" class=\"options-bottomleft\"><input type=\"submit\" class=\"options_save\" name=\"saveOptions\" value=\"" . i18n("Move image") . "\" /></td>
01630 <td width=\"50%\" class=\"options-bottomright\"><input type=\"reset\" class=\"options_reset\" value=\"" . i18n("Reset") . "\" /></td>
01631 </tr>
01632 </table>";
01633 }
01634 $renderedGallery .= renderInformationBox( i18n("Move image to another gallery"), $data, false );
01635 }
01636 break;
01637 case "delete":
01638
01639 if( $this->displayImage == null )
01640 {
01641 if( $_REQUEST["deleteAccept"] == "true" )
01642 {
01643 $errorhandler = new errorHandler( $this->globalID );
01644 $errorhandler->handle( i18n("Deleting the gallery and all contents including subgalleries"), rmdirr( $this->basedir ) );
01645
01646 if( $errorhandler->handled )
01647 $renderedGallery .= $errorhandler->render();
01648 else
01649 {
01650 $tmpID = array_slice( $this->splitID, 0, -1 );
01651 if( $this->profileGallery )
01652 $tmpID[3] = "edit";
01653 else
01654 $tmpID[1] = "edit";
01655
01656 header( "Location: " . globalIDtoURL( implode( "/", $tmpID ) ) );
01657 }
01658 }
01659 else
01660 $renderedGallery .= renderInformationBox(
01661 i18n("Delete the gallery ##0##", array( $this->getGlobalID("view") ) ),
01662 "<p>" .
01663 i18n("Please confirm that you wish to delete the gallery by clicking on the Confirm Delete link below. If you do not wish to delete the image, click on Abort Delete in stead to return to the gallery overview") .
01664 "</p>
01665 <p> </p>
01666 <div class=\"wikicenteralign\">" .
01667 drawCommand( i18n("Confirm Delete"), i18n("Confirm that you wish to delete ##0##", array( $this->getGlobalID("view") ) ), globalIDtoURL( $this->globalID, array( "deleteAccept" => "true" ) ) ) .
01668 " " .
01669 drawCommand( i18n("Abort Delete"), i18n("Return to the gallery overview"), globalIDtoURL( $this->getGlobalID( "edit" ) ) ) .
01670 "<div>",
01671 false
01672 );
01673 }
01674
01675 else
01676 {
01677
01678 foreach( $this->images as $key => $tmpimage )
01679 if( $tmpimage->imagename == $this->displayImage )
01680 $image = &$this->images[$key];
01681
01682 if( $_REQUEST["deleteAccept"] == "true" )
01683 {
01684 $errorhandler = new errorHandler( $image->globalID );
01685
01686 $errorhandler->handle( i18n("Deleting image file"), unlink( $this->basedir . "/images/" . $image->imagename ) );
01687 if( file_exists( $this->basedir . "/midsize/" . $image->imagename ) )
01688 $errorhandler->handle( i18n("Deleting midsize file"), unlink( $this->basedir . "/midsize/" . $image->imagename ) );
01689 $errorhandler->handle( i18n("Deleting thumbnail file"), unlink( $this->basedir . "/thumbs/" . $image->imagename ) );
01690 $errorhandler->handle( i18n("Deleting comments"), unlink( $this->basedir . "/comments/" . $image->imagename . ".php" ) );
01691 $errorhandler->handle( i18n("Deleting data"), unlink( $this->basedir . "/data/" . $image->imagename . ".php" ) );
01692
01693 global $subscriptions;
01694 $subscriptions->removeGlobalID( $this->getGlobalID("view") . "/" . $image->imagename );
01695
01696
01697 foreach( $this->imageOrder as $key => $value )
01698 if( $value == $image->imagename )
01699 unset( $this->imageOrder[$key] );
01700 $errorhandler->handle( i18n("Saving new gallery image order"), $this->save() );
01701
01702 if( $errorhandler->handled )
01703 $renderedGallery .= $errorhandler->render();
01704 else
01705 header( "Location: " . globalIDtoURL( $this->getGlobalID( "edit" ) ) );
01706 }
01707 else
01708 $renderedGallery .= renderInformationBox(
01709 i18n("Delete the image ##0##", array( $image->getGlobalID("view") ) ),
01710 "<div class=\"wikicenteralign\"><img src=\"" . $image->thumbURL . "\" alt=\"" . $image->getGlobalID("view") . "\" /></div>
01711 <hr /><p>" .
01712 i18n("Please confirm that you wish to delete the image by clicking on the Confirm Delete link below. If you do not wish to delete the image, click on Abort Delete in stead to return to the gallery overview") .
01713 "</p>
01714 <p> </p>
01715 <div class=\"wikicenteralign\">" .
01716 drawCommand( i18n("Confirm Delete"), i18n("Confirm that you wish to delete ##0##", array( $image->getGlobalID("view") ) ), globalIDtoURL( $image->globalID, array( "deleteAccept" => "true" ) ) ) .
01717 " " .
01718 drawCommand( i18n("Abort Delete"), i18n("Return to the gallery overview"), globalIDtoURL( $this->getGlobalID( "edit" ) ) ) .
01719 "<div>",
01720 false
01721 );
01722 }
01723 break;
01724 case "edit":
01725 default:
01726
01727 if( count( $this->images ) < 1 )
01728 $renderedGallery .= renderInformationBox(
01729 i18n("No images"),
01730 i18n("There are no images in this gallery. ##0##Please click here to upload your first image##1##.", array( "<a href=\"" . globalIDtoURL($uploadID) . "\">", "</a>") )
01731 );
01732 else
01733 {
01734 if( $this->viewType == "0" )
01735 $viewType = "table";
01736 else
01737 $viewType = $this->viewType;
01738 $viewTypeRenderer = "gallery2_viewType_" . $viewType;
01739 $viewTypeRenderer = new $viewTypeRenderer( &$this );
01740 $renderedGallery .= $viewTypeRenderer->render();
01741 }
01742 }
01743
01744 $tempSplitID = $this->splitID;
01745 if( $this->profileGallery )
01746 $tempSplitID[3] = $this->editMode;
01747 else
01748 $tempSplitID[1] = $this->editMode;
01749
01750 if( $this->displayImage != null )
01751 $tempSplitID[] = $this->displayImage;
01752
01753 return "<form enctype=\"multipart/form-data\" action=\"" . globalIDtoURL( implode( "/", $tempSplitID ) ) . "$extraReqVars\" method=\"post\">" . $renderedGallery . "</form>";
01754 }
01755
01761 function render()
01762 {
01763 global $meta_headers, $module_folder, $permissionlevels_array;
01764 $meta_headers .= "
01765 <link rel=\"StyleSheet\" href=\"" . siteURL(true) . "$module_folder/gallery/gallery.css\" type=\"text/css\" />";
01766 if( $this->userCanView() )
01767 {
01768 if( $this->edit )
01769 {
01770 $renderedGallery = $this->renderEditor();
01771 if( $_REQUEST["theme"] == "empty" )
01772 return $renderedGallery;
01773 }
01774 else if( $this->error )
01775 {
01776 $renderedGallery = renderInformationBox( i18n("Not found"), i18n("You are attempting to view a gallery which does not exist. Please check the link you attempted to use and tell the person who gave the link to you about this error.") );
01777 }
01778 else
01779 {
01780
01781 if( $this->displayImage != null )
01782 {
01783 foreach( $this->images as $key => $image )
01784 if( $image->imagename == $this->displayImage )
01785 return $image->render();
01786 }
01787 else
01788 {
01789 if( count( $this->images ) < 1 )
01790 {
01791 if( count( $this->subgalleries ) > 0 )
01792 $renderedGallery = renderInformationBox(
01793 i18n("No images"),
01794 i18n("There are no images in this gallery, however there are subgalleries. Please go into one of them by clicking on their name in the list above.")
01795 );
01796 else
01797 $renderedGallery = renderInformationBox(
01798 i18n("No images"),
01799 i18n("There are no images in this gallery.")
01800 );
01801 }
01802 else
01803 {
01804 if( $this->viewType == "0" )
01805 $viewType = "table";
01806 else
01807 $viewType = $this->viewType;
01808 $viewTypeRenderer = "gallery2_viewType_" . $viewType;
01809 $viewTypeRenderer = new $viewTypeRenderer( &$this );
01810 $renderedGallery = $viewTypeRenderer->render();
01811 }
01812
01813 global $subscriptions;
01814 $renderedSubscriptionControl = "<div class=\"wikirightalign\">" . $subscriptions->renderSubscribeControl( $this->getGlobalID("view"), false ) . "</div>";
01815 }
01816 }
01817 }
01818 else
01819 {
01820 $renderedGallery = renderInformationBox( i18n("No access"), i18n("You are not allowed to view this gallery. The owner has decided that only users fitting the description **##0##** are allowed to view this.", array( $permissionlevels_array[$this->viewLevel] ) ) );
01821 }
01822
01823
01824 $trail = $this->getBreadcrumbs();
01825
01826
01827 foreach( $this->subgalleries as $key => $subgallery )
01828 $subgalleries .= "<div class=\"gallery-subgallery\"><a class=\"gallery-subgallery\" href=\"" . globalIDtoURL( $subgallery->globalID ) . "\">" . $subgallery->title . " (" . count( $subgallery->imageOrder ) . ")</a></div>";
01829
01830
01831 if( $subgalleries != "" )
01832 {
01833 $subgalleryTitle = "
01834 <th class=\"gallery-subgalleries\">" . i18n("Subgalleries") . "</th>";
01835 $subgalleries = "
01836 <td class=\"gallery-subgalleries\">" . $subgalleries . "</td>";
01837 $subgallerySpan = " colspan=\"2\"";
01838 }
01839
01840 $header = "
01841 <table class=\"gallery\">
01842 <tr class=\"gallery-title\">
01843 <th class=\"gallery-title\">" . $trail->render() . "</th>$subgalleryTitle
01844 </tr>
01845 <tr class=\"gallery-info\">
01846 <td class=\"gallery-description\">" . parse_page_data( $this->description ) . "</td>$subgalleries
01847 </tr>
01848 <tr class=\"gallery\">
01849 <td$subgallerySpan class=\"gallery\">";
01850
01851 $footer = "
01852 </td>
01853 </tr>
01854 </table>";
01855
01856 return $header . $renderedSubscriptionControl . $renderedGallery . $footer;
01857 }
01858 }
01859
01861 class gallery2_viewType_interface
01862 {
01863 var $gallery;
01864
01870 function gallery2_viewType_interface( $gallery )
01871 {
01872 $this->gallery = &$gallery;
01873 }
01874
01876
01883 function renderSingleImage( $image )
01884 {
01885 $renderedImage = "<img src=\"" . $image->imageURL . "\" />";
01886
01887 if( $this->gallery->edit )
01888 $renderedImage .= "Insert edit controls";
01889
01890 return $renderedImage;
01891 }
01892
01894
01899 function render()
01900 {
01901 foreach( $this->gallery->images as $key => $image )
01902 $renderedGallery .= $this->renderSingleImage( &$image );
01903
01904 return $renderedGallery;
01905 }
01906 }
01907
01908
01909 $gallery2_viewTypes[] = "table";
01910
01912 class gallery2_viewType_table
01913 {
01914 var $gallery;
01915
01917 var $picsPerRow = 3;
01918
01922 function gallery2_viewType_table( $gallery )
01923 {
01924 $this->gallery = &$gallery;
01925 }
01926
01928 function renderSingleImage( $key )
01929 {
01930 global $setup_folder, $languages, $languages_names;
01931 $image = &$this->gallery->images[$key];
01932
01933 if( $image->parentGallery->edit )
01934 {
01936 $rename = drawCommand( "<img src=\"" . siteURL(true) . "$setup_folder/images/edit.png\" border=\"0\" width=\"10\" height=\"10\" alt=\"move back\" />", i18n("Rename the image"), globalIDtoURL($image->getGlobalID( "rename" ) ) );
01937 $replace = drawCommand( "<img src=\"" . siteURL(true) . "$setup_folder/images/replace.png\" border=\"0\" width=\"10\" height=\"10\" alt=\"move back\" />", i18n("Replace the image with a new one, retaining all comments"), globalIDtoURL($image->getGlobalID( "replace" ) ) );
01938 $moveGallery = " | " . drawCommand( "<img src=\"" . siteURL(true) . "$setup_folder/images/folder.png\" border=\"0\" width=\"10\" height=\"10\" alt=\"move back\" />", i18n("Move the image to another gallery or subgallery"), globalIDtoURL($image->getGlobalID( "move" ) ) );
01939 $delete = drawCommand( "<img src=\"" . siteURL(true) . "$setup_folder/images/delete.png\" border=\"0\" width=\"10\" height=\"10\" alt=\"move back\" />", i18n("Delete the image and all associated comments"), globalIDtoURL($image->getGlobalID( "delete" ) ) );
01940 $moveUp = drawCommand( "<img src=\"" . siteURL(true) . "$setup_folder/images/nav-prev.png\" border=\"0\" width=\"10\" height=\"10\" alt=\"move back\" />", i18n("Move this image one position back in the gallery view order"), globalIDtoURL($image->getGlobalID( "moveup" ) ) );
01941 $moveDown = drawCommand( "<img src=\"" . siteURL(true) . "$setup_folder/images/nav-next.png\" border=\"0\" width=\"10\" height=\"10\" alt=\"move back\" />", i18n("Move this image one position forward in the gallery view order"), globalIDtoURL($image->getGlobalID( "movedown" ) ) );
01942
01943 $thumbEdit = i18n("Thumbnail:");
01944 $thumbEdit .= " " . drawCommand( "cr", i18n("Create a thumbnail by selecting a section of the image"), globalIDtoURL($image->getGlobalID( "thumbnail" ), array( "thumbtype" => "cropnresize", "theme" => "empty" ) ) );
01945 $thumbEdit .= " " . drawCommand( "fs", i18n("Create a thumbnail from the entire image"), globalIDtoURL($image->getGlobalID( "thumbnail" ), array("thumbtype" => "fullsize") ) );
01946
01947 $languageEdit = i18n("Description:");
01948 foreach ($languages as $key => $value)
01949 $languageEdit .= " " . drawCommand( i18n($value), i18n("Edit the description in: ##0##", array( $languages_names[$key] ) ), globalIDtoURL($image->getGlobalID( "details" ), array( "editLanguage" => $value ) ) );
01950 $languageEdit = "<div>$languageEdit</div>";
01951
01952 $break = "<br />";
01953 }
01954 else
01955 {
01956 $viewLinkTop = "
01957 <a class=\"gallery-view-table-tile\" href=\"" . globalIDtoURL( $image->globalID ) . "\">";
01958 $viewLinkBottom = "
01959 </a>";
01960 }
01961 return "
01962 <td class=\"gallery-view-table-tile\">
01963 <div class=\"gallery-view-table-tile\">$viewLinkTop
01964 $thumbEdit $break
01965 $moveUp<img src=\"" . $image->thumbURL . "\" border=\"0\" class=\"gallery-view-table-tile\" />$moveDown
01966 $break $rename $replace $moveGallery $delete
01967 <h6 class=\"gallery-view-table-tile\">" . $image->imagename . "</h6>$viewLinkBottom
01968 $languageEdit
01969 <span class=\"gallery-view-table-comments\">" . i18n("Comments") . ": " . $image->commentCount . "<br /></span>
01970 <span class=\"gallery-view-table-dimensions\">" . $image->width . "×" . $image->height . " " . $image->weight . "</span>
01971 </div>
01972 </td>";
01973 }
01974
01976 function render()
01977 {
01978 $header = "
01979 <table class=\"gallery-view-table\">";
01980 $footer = "
01981 </table>";
01982
01983 $firstinrow = true;
01984 $lastinrow = false;
01985
01986 foreach( $this->gallery->images as $key => $image )
01987 {
01988
01989 $renderedData .= $this->renderSingleImage( $key );
01990
01991
01992 if( $firstinrow )
01993 {
01994 $firstinrow = false;
01995 $renderedData = "
01996 <tr class=\"gallery\">" . $renderedData;
01997 }
01998
01999 else if( $lastinrow )
02000 {
02001 $lastinrow = false;
02002 $firstinrow = true;
02003 $renderedData .= "
02004 </tr>";
02005 }
02006
02007 else
02008 $lastinrow = true;
02009 }
02010
02011 if( $lastinrow )
02012 $renderedData .= "
02013 <td class=\"gallery-view-table-tile-none\"></td>
02014 </tr>";
02015 else if( $lastinrow == false && $firstinrow == false )
02016 $renderedData .= "
02017 <td class=\"gallery-view-table-tile-none\"></td>
02018 <td class=\"gallery-view-table-tile-none\"></td>
02019 </tr>";
02020
02021
02022 return $header . $renderedData . $footer;
02023 }
02024 }
02025
02026 $gallery2_viewTypes[] = "oldstyle";
02027
02029 class gallery2_viewType_oldstyle
02030 {
02031 var $gallery;
02032
02038 function gallery2_viewType_oldstyle( $gallery )
02039 {
02040 $this->gallery = &$gallery;
02041 }
02042
02044
02051 function renderSingleImage( $image )
02052 {
02053 global $language, $languages, $languages_names;
02054
02055 $renderedImage .= "
02056 <tr class=\"gallery-view-oldstyle\">
02057 <td class=\"gallery-view-oldstyle-image\">
02058 <div align=\"center\"><a class=\"gallery-view-oldstyle-image-link\" href=\"" . globalIDtoURL( $image->globalID ) . "\"><img src=\"" . $image->thumbURL . "\" border=\"0\" /><br />" . $image->imagename . "</a></div>
02059 </td>
02060 <td class=\"gallery-view-oldstyle-description\">";
02061 if( $this->gallery->edit )
02062 {
02063 foreach ($languages as $key => $value)
02064 $renderedImage .= parse_page_data( $image->descriptions[$value] ) . drawCommand( i18n($value), i18n("Edit the description in: ##0##", array( $languages_names[$key] ) ), globalIDtoURL($image->getGlobalID( "details" ), array( "editLanguage" => $value ) ) );
02065 }
02066 else
02067 $renderedImage .= parse_page_data( $image->descriptions[$language] );
02068
02069 $renderedImage .= "
02070 </td>";
02071
02072 if( $this->gallery->edit )
02073 {
02074 $renderedImage .= "
02075 <td class=\"gallery-view-oldstyle-commands\">
02076 <div align=\"right\">" .
02077 drawCommand( i18n("Rename"), i18n("Rename the image"), globalIDtoURL($image->getGlobalID( "rename" ) ) ) . " " .
02078 drawCommand( i18n("Replace"), i18n("Replace the image with a new one, retaining all comments"), globalIDtoURL($image->getGlobalID( "replace" ) ) ) . " " .
02079 drawCommand( i18n("Move"), i18n("Move the image to another gallery or subgallery"), globalIDtoURL($image->getGlobalID( "move" ) ) ) . " " .
02080 drawCommand( i18n("Delete"), i18n("Delete the image and all associated comments"), globalIDtoURL($image->getGlobalID( "delete" ) ) ) . "
02081 </div><hr class=\"gallery-edit-commands\" />
02082 <div align=\"right\">" .
02083 drawCommand( i18n("Move up"), i18n("Move this image one position up in the gallery view order"), globalIDtoURL($image->getGlobalID( "moveup" ) ) ) . " " .
02084 drawCommand( i18n("Move down"), i18n("Move this image one position down in the gallery view order"), globalIDtoURL($image->getGlobalID( "movedown" ) ) ) . "
02085 </div><hr class=\"gallery-edit-commands\" />
02086 <div align=\"right\">" . i18n("Redo thumbnail:") . "<br />" .
02087 drawCommand( i18n("Crop and Resize"), i18n("Create a thumbnail by selecting a section of the image"), globalIDtoURL($image->getGlobalID( "thumbnail" ), array( "thumbtype" => "cropnresize", "theme" => "empty" ) ) ) . " " .
02088 drawCommand( i18n("Full picture"), i18n("Create a thumbnail from the entire image"), globalIDtoURL($image->getGlobalID( "thumbnail" ), array("thumbtype" => "fullsize") ) ) . "
02089 </div>
02090 </td>";
02091 }
02092
02093 $renderedImage .= "
02094 </tr>";
02095
02096 return $renderedImage;
02097 }
02098
02100
02105 function render()
02106 {
02107 $renderedGallery .= "
02108 <table class=\"gallery-view-oldstyle\">";
02109
02110 foreach( $this->gallery->images as $key => $image )
02111 $renderedGallery .= $this->renderSingleImage( &$image );
02112
02113 $renderedGallery .= "
02114 </table>";
02115
02116 return $renderedGallery;
02117 }
02118 }
02119
02120 function parse_gallery2( $page_data )
02121 {
02122 global $userinfo_folder, $globalID;
02123
02124 $moduleCommandName = "gallery";
02125 while( $parameters = spotModuleCommand( $page_data, $moduleCommandName, &$loopcontrol ) )
02126 {
02127 $galleryid = $parameters;
02128 if( $parameters == " " )
02129 $parameters = "";
02130
02131
02132 $splitID = explode( "/", $galleryid );
02133 if( $splitID[0] != "gallery" && $splitID[0] != "gallery2" && $splitID[0] != "user" )
02134 $galleryid = "gallery2/view/$galleryid";
02135
02136 $splitID = explode( "/", $globalID );
02137 if( $splitID[0] == "gallery" || $splitID[0] == "gallery2" )
02138 $galleryid = $globalID;
02139
02140 $theGallery = new gallery2_gallery( $galleryid );
02141
02142 $replaceData = $theGallery->render();
02143
02144 $page_data = str_replace( "\\$moduleCommandName($parameters)", $replaceData, $page_data );
02145 }
02146
02147 $loopcontrol = 0;
02148 $moduleCommandName = "profilegallerylist";
02149 while( $parameters = spotModuleCommand( $page_data, $moduleCommandName, &$loopcontrol ) )
02150 {
02151 $viewtype = $parameters;
02152 if( $parameters == " " )
02153 $parameters = "";
02154
02155 $userlist = allUsersArray();
02156 $userswithgalleries = array();
02157 foreach( $userlist as $key => $value )
02158 {
02159 if( is_dir( "$userinfo_folder/$value/gallery" ) )
02160 {
02161 $theGallery = new gallery2_gallery("user/$value/gallery", false);
02162 $count = $theGallery->countSubImages();
02163 if( $count > 0 )
02164 {
02165 $userswithgalleries[] = $value;
02166 $gallerycounts[] = $count;
02167 }
02168 }
02169 }
02170 if( count($userswithgalleries) > 0 )
02171 {
02172 $replaceData = parse_userlists( "\userlist($viewtype)", false, $userswithgalleries, "gallery2" );
02173
02174 foreach($userswithgalleries as $key => $value)
02175 $replaceData = str_replace("($value)", "($value) " . $gallerycounts[$key], $replaceData);
02176 }
02177 else
02178 $replaceData = renderInformationBox( i18n("No gallery profiles"), i18n("Sorry, there were found no profiles with at least one picture in the profile gallery") );
02179
02180 $page_data = str_replace( "\\$moduleCommandName($parameters)", $replaceData, $page_data );
02181 }
02182
02183 $loopcontrol = 0;
02184 $moduleCommandName = "galleryimage";
02185 while( $parameters = spotModuleCommand( $page_data, $moduleCommandName, &$loopcontrol ) )
02186 {
02187 list( $galleryid, $float, $dontlink ) = explode( ",", $parameters );
02188
02189 $theGallery = new gallery2_gallery( $galleryid );
02190
02191 foreach( $theGallery->images as $key => $image )
02192 {
02193 if( $image->imagename == $theGallery->displayImage )
02194 {
02195 $theImage = $image;
02196 break;
02197 }
02198 }
02199
02200 if( $float == "right" )
02201 $floatit = " style=\"float: right;\"";
02202 else if( $float == "center" )
02203 $floatit = " style=\"float: center;\"";
02204 else if( $float == "left" )
02205 $floatit = " style=\"float: left;\"";
02206
02207 if( $dontlink == "" )
02208 {
02209 $link = "<a href=\"" . globalIDtoURL( $image->globalID ) . "\">";
02210 $link2 = "</a>";
02211 }
02212
02213 list( $x, $y ) = getimagesize( $image->parentGallery->basedir . "/thumbs/" . $image->imagename );
02214 $replaceData = "$link<img$floatit border=\"0\" src=\"" . $image->parentGallery->baseurl . "/thumbs/" . $image->imagename . "\" width=\"$x\" height=\"$y\" alt=\"" . $image->imagename . "\" />$link2";
02215
02216 $page_data = str_replace( "\\$moduleCommandName($parameters)", $replaceData, $page_data );
02217 }
02218
02219 return $page_data;
02220 }
02221
02222 function profilemodule_gallery2()
02223 {
02224 global $tabwidget, $viewUser, $globalID;
02225
02226 $gallery = $globalID;
02227
02228 $theGallery = new gallery2_gallery( $gallery );
02229
02230 if( userAllows( $theGallery->owner, $theGallery->editLevel) && $theGallery->edit )
02231 {
02232 $tabwidget->addCommand( i18n("Upload"), i18n("Upload an image to the gallery"), globalIDtoURL( $theGallery->getGlobalID( "upload" ) ) );
02233 $tabwidget->addCommand( i18n("View"), i18n("View the gallery"), globalIDtoURL( $theGallery->getGlobalID( "view" ) ) );
02234 }
02235 else if( userAllows( $theGallery->owner, $theGallery->editLevel) )
02236 {
02237 $tabwidget->addCommand( i18n("Upload"), i18n("Upload an image to the gallery"), globalIDtoURL( $theGallery->getGlobalID( "upload" ) ) );
02238 $tabwidget->addCommand( i18n("Edit"), i18n("Edit the gallery"), globalIDtoURL( $theGallery->getGlobalID( "edit" ) ) );
02239 }
02240 return $theGallery->render();
02241 }
02242
02243 function modulesetup_gallery2()
02244 {
02245 global $setup_folder, $module_folder, $page_folder, $menu_folder, $recent_file, $pagectl, $default_language, $language, $meta_headers, $theModuleSection, $theModuleSubsection, $theModuleAction, $gallery_options, $gallery2_viewTypes, $permissionlevels_array;
02246 $meta_headers .= "
02247 <link rel=\"StyleSheet\" href=\"" . siteURL(true) . "$module_folder/gallery/gallery.css\" type=\"text/css\" />";
02248
02249 $gallerySetup = new TabWidget;
02250 $gallerySetup->tabbar->addTab(i18n("Gallery Setup"), globalIDtoURL("setup/modulesetup/gallery2/setup"));
02251 $gallerySetup->tabbar->addTab(i18n("Options"), globalIDtoURL("setup/modulesetup/gallery2/options"));
02252
02253 switch( $theModuleSection )
02254 {
02255 case "options":
02256 if( $theModuleAction == "create_gallery_page" )
02257 {
02258
02259 $edit_page["id"] = $pagectl->getFreePageID($page_folder, $pagectl);
02260 $edit_page["title"] = $gallery_options["title"];
02261 $edit_page["menu"] = $gallery_options["menu_id"];
02262 $edit_page["language"] = $default_language;
02263 $edit_page["content"] = "\\\\gallery()";
02264 $edit_page["author"] = getUserInfo(currentUser(), "name");
02265 $edit_page["email"] = getUserInfo(currentUser(), "email");
02266
02267 unlink_multiple( "$page_folder/{$edit_page['id']}.*" );
02268
02269 if ($pagectl->savePageData($page_folder, $edit_page["id"], $edit_page["language"], $edit_page["author"], $edit_page["email"], $gallery_options["menu_id"], $edit_page["title"], $edit_page["content"])) {
02270 update_getpage_id($page_folder, $setup_folder, $pagectl);
02271 rotate_recent($edit_page["id"], $edit_page["title"], $edit_page["language"], date("j/n/y"), $recent_file);
02272
02273 $gallery_options["page_id"] = $edit_page["id"];
02274 if( file_exists( $module_folder . "/gallery/options.php" ) )
02275 unlink( $module_folder . "/gallery/options.php" );
02276 file_put_contents( $module_folder . "/gallery/options.php", array_export( $gallery_options, "gallery_options" ) );
02277
02278 header("Location: " . globalIDtoURL("setup/modulesetup/gallery2/options"));
02279 } else {
02280 $error_description = parse_page_data(i18n("The gallery page could not be saved!"));
02281 }
02282 }
02283 if( $_POST["saveOptions"] && $_POST["gallery"]["page_id"] != 12 && ( $gallery_options["page_id"] != $_POST["gallery"]["page_id"] || $gallery_options["menu_id"] != $_POST["gallery"]["menu_id"] || $gallery_options["title"] != $_POST["gallery"]["title"] ) )
02284 {
02285 $thePage = $pagectl->fetchPageData($_POST["page_id"]);
02286 unlink_multiple( "$page_folder/{$gallery_options['page_id']}.*" );
02287 if ($pagectl->savePageData($page_folder, $_POST["gallery"]["page_id"], $thePage["language"], $thePage["author"], $thePage["email"], $_POST["gallery"]["menu_id"], $_POST["gallery"]["title"], "\\\\gallery()"))
02288 {
02289 update_getpage_id($page_folder, $setup_folder, $pagectl);
02290 rotate_recent($gallery_options["page_id"], $gallery_options["title"], $thePage["language"], date("j/n/y"), $recent_file);
02291 }
02292 }
02293 $gallerySetup->tabbar->setCurrent( i18n( "Options" ) );
02294 $panel = new optionsPanel("gallery");
02295
02296 $values["page_id"] = $_POST["saveOptions"] ? $_POST["gallery"]["page_id"] : $gallery_options["page_id"] ;
02297 $values["title"] = $_POST["saveOptions"] ? $_POST["gallery"]["title"] : $gallery_options["title"] ;
02298 $values["menu_id"] = $_POST["saveOptions"] ? $_POST["gallery"]["menu_id"] : $gallery_options["menu_id"] ;
02299
02300 $values["maxwidth"] = $_POST["saveOptions"] ? $_POST["gallery"]["maxwidth"] : $gallery_options["maxwidth"] ;
02301 $values["maxheight"] = $_POST["saveOptions"] ? $_POST["gallery"]["maxheight"] : $gallery_options["maxheight"] ;
02302 $values["midwidth"] = $_POST["saveOptions"] ? $_POST["gallery"]["midwidth"] : $gallery_options["midwidth"] ;
02303 $values["midheight"] = $_POST["saveOptions"] ? $_POST["gallery"]["midheight"] : $gallery_options["midheight"] ;
02304 $values["thumbwidth"] = $_POST["saveOptions"] ? $_POST["gallery"]["thumbwidth"] : $gallery_options["thumbwidth"] ;
02305 $values["thumbheight"] = $_POST["saveOptions"] ? $_POST["gallery"]["thumbheight"] : $gallery_options["thumbheight"] ;
02306
02307 $values["viewType"] = $_POST["saveOptions"] ? $_POST["gallery"]["viewType"] : $gallery_options["viewType"] ;
02308 $values["viewLevel"] = $_POST["saveOptions"] ? $_POST["gallery"]["viewLevel"] : $gallery_options["viewLevel"] ;
02309 $values["commentLevel"] = $_POST["saveOptions"] ? $_POST["gallery"]["commentLevel"] : $gallery_options["commentLevel"] ;
02310 $values["editLevel"] = $_POST["saveOptions"] ? $_POST["gallery"]["editLevel"] : $gallery_options["editLevel"] ;
02311 $values["embedLevel"] = $_POST["saveOptions"] ? $_POST["gallery"]["embedLevel"] : $gallery_options["embedLevel"] ;
02312
02313 $panel->addHeader( i18n("Gallery page"), "thepage" );
02314
02315 $pagelist = $pagectl->fetchPageList($page_folder);
02316 $temp_pagelist[12] = i18n("Please select a page...");
02317 foreach( $pagelist as $key => $value )
02318 {
02319 $temp_pagelist[$key] = $value["title"][0];
02320 }
02321 $panel->addOption(
02322 i18n("Gallery page"),
02323 i18n("This is the page that will be used to show the gallery images on when linking. If you want to create a new page to put the information into, ##0##simply click here##1## and this will be done for you.", array("<a href=\"" . globalIDtoURL("setup/modulesetup/gallery2/options/na/create_gallery_page") . "\">", "</a>")),
02324 $values["page_id"],
02325 "page_id",
02326 "select",
02327 $temp_pagelist
02328 );
02329
02330 $panel->addOption(
02331 i18n("Title"),
02332 i18n("The title of the gallery page"),
02333 $values["title"],
02334 "title",
02335 "text"
02336 );
02337
02338 $menulist = $pagectl->fetchMenuMenuList($menu_folder);
02339 foreach( $menulist as $key => $value )
02340 {
02341 $temp_menulist[$value["id"]] = $value["title"][0];
02342 }
02343 $panel->addOption(
02344 i18n("Gallery menu"),
02345 i18n("This is the menu that will be shown on the gallery page"),
02346 $values["menu_id"],
02347 "menu_id",
02348 "select",
02349 $temp_menulist
02350 );
02351
02352 $panel->addHeader( i18n("Image resize sizes"), "sizes" );
02353 $panel->addOption(
02354 i18n("Resize width"),
02355 i18n("Images will be resized if they are larger than this width when uploading to galleries"),
02356 $values["maxwidth"],
02357 "maxwidth",
02358 "text");
02359 $panel->addOption(
02360 i18n("Resize height"),
02361 i18n("Images will be resized if they are larger than this height when uploading to galleries"),
02362 $values["maxheight"],
02363 "maxheight",
02364 "text");
02365 $panel->addOption(
02366 i18n("Midsize width"),
02367 i18n("When viewing gallery images, they will be resized to this width if required"),
02368 $values["midwidth"],
02369 "midwidth",
02370 "text");
02371 $panel->addOption(
02372 i18n("Midsize height"),
02373 i18n("When viewing gallery images, they will be resized to this height if required"),
02374 $values["midheight"],
02375 "midheight",
02376 "text");
02377 $panel->addOption(
02378 i18n("Thumbnail width"),
02379 i18n("The maximum width for thumbnails"),
02380 $values["thumbwidth"],
02381 "thumbwidth",
02382 "text");
02383 $panel->addOption(
02384 i18n("Thumbnail height"),
02385 i18n("The maximum height for thumbnails"),
02386 $values["thumbheight"],
02387 "thumbheight",
02388 "text");
02389
02390 $panel->addHeader( i18n("Default gallery options"), "defaults" );
02391
02392 $panel->addOption(
02393 i18n("View type"),
02394 i18n("The view type of newly created galleries"),
02395 $values["viewType"],
02396 "viewType",
02397 "select",
02398 $gallery2_viewTypes);
02399 $panel->addOption(
02400 i18n("View level"),
02401 i18n("Apart from the gallery owner, who is allowed to view the gallery's contents?"),
02402 $values["viewLevel"],
02403 "viewLevel",
02404 "select",
02405 $permissionlevels_array);
02406 $panel->addOption(
02407 i18n("Comment level"),
02408 i18n("Apart from the gallery owner, who is allowed to comment on the gallery's contents?"),
02409 $values["commentLevel"],
02410 "commentLevel",
02411 "select",
02412 $permissionlevels_array);
02413 $panel->addOption(
02414 i18n("Edit level"),
02415 i18n("Apart from the gallery owner, who is allowed to edit the gallery?"),
02416 $values["editLevel"],
02417 "editLevel",
02418 "select",
02419 $permissionlevels_array);
02420 $panel->addOption(
02421 i18n("Embedding level"),
02422 i18n("Apart from the gallery owner, who is allowed to get embedding codes for the contents of the gallery?"),
02423 $values["embedLevel"],
02424 "embedLevel",
02425 "select",
02426 $permissionlevels_array);
02427
02428 if( $_POST["saveOptions"] )
02429 {
02430 $gallery_options["page_id"] = $values["page_id"];
02431 $gallery_options["menu_id"] = $values["menu_id"];
02432 $gallery_options["title"] = $values["title"];
02433
02434 $gallery_options["maxwidth"] = $values["maxwidth"];
02435 $gallery_options["maxheight"] = $values["maxheight"];
02436 $gallery_options["midwidth"] = $values["midwidth"];
02437 $gallery_options["midheight"] = $values["midheight"];
02438 $gallery_options["thumbwidth"] = $values["thumbwidth"];
02439 $gallery_options["thumbheight"] = $values["thumbheight"];
02440 $gallery_options["viewType"] = $values["viewType"];
02441 $gallery_options["viewLevel"] = $values["viewLevel"];
02442 $gallery_options["commentLevel"] = $values["commentLevel"];
02443 $gallery_options["editLevel"] = $values["editLevel"];
02444 $gallery_options["embedLevel"] = $values["embedLevel"];
02445
02446 if( file_exists( $module_folder . "/gallery/options.php" ) )
02447 unlink( $module_folder . "/gallery/options.php" );
02448 file_put_contents( $module_folder . "/gallery/options.php", array_export( $gallery_options, "gallery_options" ) );
02449
02450 header( "Location: " . globalIDtoURL( "setup/modulesetup/gallery2/options" ) );
02451 }
02452 else
02453 $data = $panel->render();
02454
02455 $gallerySetup->contents = "<form action=\"" . globalIDtoURL("setup/modulesetup/gallery2/options") . "\" method=\"POST\">" . $data . "</form>";
02456 break;
02457 case "edit":
02458 case "thumbnail":
02459 case "moveup":
02460 case "movedown":
02461 case "upload":
02462 case "replace":
02463 case "new":
02464 case "rename":
02465 case "details":
02466 case "move":
02467 case "delete":
02468 global $gallery2_gallery;
02469 $theGallery = new gallery2_gallery( $gallery2_gallery );
02470 $gallerySetup->contents = $theGallery->render();
02471 break;
02472 case "setup":
02473 default:
02474 $gallerySetup->tabbar->setCurrent( i18n( "Gallery Setup" ) );
02475 $gallerySetup->addCommand( i18n("New gallery"), i18n("Create a new global gallery"), globalIDtoURL( "setup/modulesetup/gallery2/setup/new" ) );
02476
02477 switch( $theModuleSubsection )
02478 {
02479 case "new":
02480 $panel = new optionsPanel("");
02481 $panel->saveTitle = i18n("Create subgallery");
02482 $panel->resetTitle = i18n("Reset");
02483 $panel->showHeader = false;
02484
02485 $values["physicalname"] = ( $_POST["physicalname"] != "" ) ? stripslashes($_POST["physicalname"]) : "gallery";
02486 $values["title"] = ( $_POST["title"] != "" ) ? stripslashes($_POST["title"]) : i18n("Untitled Gallery");
02487 $values["description"] = ( $_POST["description"] != "" ) ? stripslashes($_POST["description"]) : i18n("Enter the new gallery's description here");
02488 $values["viewType"] = ( $_POST["viewType"] != "" ) ? stripslashes($_POST["viewType"]) : $gallery_options["viewType"];
02489 $values["viewLevel"] = ( $_POST["viewLevel"] != "" ) ? stripslashes($_POST["viewLevel"]) : $gallery_options["viewLevel"];
02490 $values["commentLevel"] = ( $_POST["commentLevel"] != "" ) ? stripslashes($_POST["commentLevel"]) : $gallery_options["commentLevel"];
02491 $values["editLevel"] = ( $_POST["editLevel"] != "" ) ? stripslashes($_POST["editLevel"]) : $gallery_options["editLevel"];
02492 $values["embedLevel"] = ( $_POST["embedLevel"] != "" ) ? stripslashes($_POST["embedLevel"]) : $gallery_options["embedLevel"];
02493
02494 $panel->addOption( i18n("Physical name:"), i18n("The filename you will find the gallery under (used for linking)"), $values["physicalname"], "physicalname", "text");
02495 $panel->addOption( i18n("Title:"), i18n("The gallery's human readable name"), $values["title"], "title", "text");
02496 $panel->addOption( i18n("View type"), i18n("How do you wish to present this gallery to the user by default?"), $values["viewType"], "viewType", "select", $gallery2_viewTypes);
02497 $panel->addOption( i18n("View Level:"), i18n("Who, except for yourself, is allowed to view the contents of this gallery?"), $values["viewLevel"], "viewLevel", "select", $permissionlevels_array);
02498 $panel->addOption( i18n("Comment Level:"), i18n("Who, except for yourself, is allowed to comment on the contents of this gallery?"), $values["commentLevel"], "commentLevel", "select", $permissionlevels_array);
02499 $panel->addOption( i18n("Edit Level:"), i18n("Who, except for yourself, is allowed to edit the contents of this gallery?"), $values["editLevel"], "editLevel", "select", $permissionlevels_array);
02500 $panel->addOption( i18n("Description:"), "", $values["description"], "description", "pagedata");
02501
02502 $newbasedir = $module_folder . "/gallery/" . str_replace( ".", "-", str_replace( " ", "_", $panel->options["physicalname"]["current"] ) ) ;
02503
02504 if( $_POST["saveOptions"] && file_exists( $newbasedir ) )
02505 $panel->options["physicalname"]["error"] = i18n("A gallery already exists with this name!");
02506
02507 if( $_POST["saveOptions"] && $panel->options["physicalname"]["current"] != "" && ! file_exists( $newbasedir ) )
02508 {
02509 RecursiveMkdir( $newbasedir );
02510 mkdir( $newbasedir . "/comments" );
02511 mkdir( $newbasedir . "/data" );
02512 mkdir( $newbasedir . "/galleries" );
02513 mkdir( $newbasedir . "/images" );
02514 mkdir( $newbasedir . "/thumbs" );
02515
02516 $gallery["title"] = $panel->options["title"]["current"];
02517 $gallery["description"] = $panel->options["description"]["current"];
02518 $gallery["viewType"] = $gallery2_viewTypes[ $panel->options["viewType"]["current"] ];
02519 $gallery["viewLevel"] = $panel->options["viewLevel"]["current"];
02520 $gallery["commentLevel"] = $panel->options["commentLevel"]["current"];
02521 $gallery["editLevel"] = $panel->options["editLevel"]["current"];
02522 $gallery["embedLevel"] = $panel->options["embedLevel"]["current"];
02523 $gallery["imageOrder"] = array();
02524 $gallery["owner"] = currentUser();
02525
02526 if( file_put_contents( $newbasedir . "/gallery.php", array_export( $gallery, "gallery" ) ) )
02527 header("Location: " . globalIDtoURL( "gallery2/edit/" . $panel->options["physicalname"]["current"] ) );
02528 else
02529 $renderedGallery .= "An error occured while saving the gallery settings!";
02530 }
02531 else
02532 $renderedGallery .= renderInformationBox( i18n("Create a new gallery"), $panel->render(), false);
02533
02534 $data = "<form action=\"" . globalIDtoURL("setup/modulesetup/gallery2/setup/new") . "\" method=\"POST\">" . $renderedGallery . "</form>";
02535 break;
02536 case "gallery_galleries":
02537 default:
02538 $galleries = array();
02539 $gallerybase = "$module_folder/gallery";
02540
02541 $dir_handle = opendir("$gallerybase");
02542 while ($folder = readdir($dir_handle)) {
02543 if( is_dir( "$gallerybase/$folder" ) && substr($folder, 0, 1) != "." ) {
02544 $galleries[] = new gallery2_gallery( "gallery2/edit/" . $folder, false );
02545 }
02546 }
02547 closedir($dir_handle);
02548
02549 if( count( $galleries ) == 0 )
02550 {
02551 $data = renderInformationBox( i18n("No galleries"), i18n("There are currently no galleries on the system. If you wish, you can create one by choosing the New gallery command link above.") );
02552 }
02553 else
02554 {
02555 foreach( $galleries as $key => $theGallery )
02556 {
02557 if( userAllows( $theGallery->owner, $theGallery->editLevel ) )
02558 $data .= "
02559 <div class=\"gallery-global-list\">
02560 <a class=\"gallery-global-header\" href=\"" . globalIDtoURL( $theGallery->getGlobalID("edit") ) . "\">
02561 <span class=\"gallery-global-go\">" . i18n("Edit ##0##", array( "»" ) ) . "</span>
02562 <h3 class=\"gallery-global-header\">" . $theGallery->title . " (" . $theGallery->countSubImages() . ")</h3>
02563 </a>
02564 <div class=\"gallery-global-description\">" . parse_page_data( $theGallery->description ) . "</div>
02565 </div>";
02566 else
02567 $data .= "
02568 <div class=\"gallery-global-list\">
02569 <span class=\"gallery-global-go\">" . i18n("Edit not allowed" ) . "</span>
02570 <h3 class=\"gallery-global-header\">" . $theGallery->title . " (" . $theGallery->countSubImages() . ")</h3>
02571 <div class=\"gallery-global-description\">" . parse_page_data( $theGallery->description ) . "</div>
02572 </div>";
02573 }
02574 }
02575 }
02576 $gallerySetup->contents = $data;
02577 }
02578 return $gallerySetup->renderTabWidget();
02579 }
02580
02588 function globalID_gallery2( $splitID )
02589 {
02590 global $gallery2_gallery, $gallery_options;
02591 $pageID = null;
02592
02593
02594
02595 if( $splitID[0] == "gallery2" || $splitID[0] == "gallery" )
02596 {
02597 if( $splitID[1] == "view" || $splitID[1] == "" )
02598 {
02599 $pageID = $gallery_options["page_id"];
02600 }
02601 else
02602 {
02603 $pageID = 12;
02604 global $theModule, $theModuleSection;
02605 $theModule = "gallery2";
02606 $theModuleSection = $splitID[1];
02607 $gallery2_gallery = implode( "/", $splitID );
02608 }
02609 }
02610
02611 else if( $splitID[0] == "user" && ( $splitID[2] == "gallery2" || $splitID[2] == "gallery" ))
02612 {
02613
02614 $_REQUEST["module"] = "profilemodule_gallery2";
02615
02616 $gallery2_gallery = implode( "/", $splitID );
02617
02618 $pageID = 13;
02619 }
02620 return $pageID;
02621 }
02622
02630 function globalIDThumbnail_gallery2( $splitID )
02631 {
02632 $theGallery = new gallery2_gallery( join( $splitID, "/" ) );
02633
02634 foreach( $theGallery->images as $key => $tmpimage )
02635 {
02636 if( $tmpimage->imagename == $theGallery->displayImage )
02637 {
02638 $image = &$theGallery->images[$key];
02639 break;
02640 }
02641 }
02642
02643 list( $width, $height ) = getimagesize($theGallery->basedir . "/thumbs/" . $tmpimage->imagename);
02644 $data = array( "uri" => $tmpimage->thumbURL, "width" => $width, "height" => $height );
02645 return $data;
02646 }
02647
02648 ?>