sDisplay(); echo $s; } class WYGalleryElement extends WYElement { var $iTNWidth; var $iTNHeight; var $iCellWidth; var $iImageWidth; var $iImageHeight; var $iCols; // class functions // instance functions function WYGalleryElement($sN, $bG, $iTNw, $iTNh, $iC = 3, $iIw = 0, $iIh = 0, $iCellWidth = 0) { global $goApp; parent::WYElement($sN, $bG); $this->iTNWidth = $iTNw; $this->iTNHeight = $iTNh; $this->iImageWidth = $iIw; $this->iImageHeight = $iIh; $this->iCellWidth = $iCellWidth == 0 ? (int)round($iTNw * 1.2):$iCellWidth; $this->iCols = $iC; $this->sEditorPageName = "gallery.php"; $this->iEditorWidth = 430; $this->iEditorHeight = 400; $this->setVersion(WY_GALLERY_VERSION); if (!isset($this->dContent[WY_DK_GALLERY_ID_ARRAY])) $this->dContent[WY_DK_LOOPIDARRAY] = array(); if ($goApp->bEditMode) $this->dispatchEditAction(); } function oIPhoneEditURL() { return new WYURL("javascript:alert(\"" . WYTS('NoGalleryEditorOnIPhone') . "\")"); } function &_aItems() { return $this->dContent[WY_DK_GALLERY_ID_ARRAY]; } function bUseLoopID() { return true; } function sFieldNameForFile() { $s = parent::sFieldNameForFile(); $s = "gl-" . $s; return $s; } function deleteContent() { $aItems =& $this->_aItems(); $iCount = count($aItems); for ($i = 0; $i < $iCount; $i++) { $this->_deleteImageFilesForID($i); } parent::deleteContent(); } function newImageAfter($iID, $iTransactionID = 0) { // $iID can be -1 (when adding to empty gallery $aItems =& $this->_aItems(); $dNewItem = array(WY_DK_GALLERY_FILENAME => "", WY_DK_GALLERY_TEXT => ""); if ($iTransactionID != 0) $dNewItem[WY_DK_GALLERY_TRANSACTION_ID] = $iTransactionID; if ($iID < (count($aItems) - 1) && $iID >= 0) webyep_array_insert($aItems, $iID+1, $dNewItem); else $aItems[] = $dNewItem; } function iImageIDForTransactionID($iTransID) // returns -1 if no item for the given transaction ID can be found { $aItems =& $this->_aItems(); foreach (array_keys($aItems) as $i) { $dItem =& $aItems[$i]; if (isset($dItem[WY_DK_GALLERY_TRANSACTION_ID]) && $dItem[WY_DK_GALLERY_TRANSACTION_ID] == $iTransID) return $i; } return -1; } function _deleteImageFilesForID($iID) { global $goApp; $oFile = od_nil; $aItems =& $this->_aItems(); if (isset($aItems[$iID]) && isset($aItems[$iID][WY_DK_GALLERY_FILENAME]) && $sFN = $aItems[$iID][WY_DK_GALLERY_FILENAME]) { $oPath = od_clone($goApp->oDataPath); $oPath->addComponent($sFN); $oFile =& new WYFile($oPath); if ($oFile->bExists() && !$oFile->bDelete()) $goApp->log("could not delete image file " . $oPath->sPath); $oPath = od_clone($goApp->oDataPath); $oPath->addComponent($this->_sThumbnailName($sFN)); $oFile =& new WYFile($oPath); if ($oFile->bExists() && !$oFile->bDelete()) $goApp->log("could not delete thumbnail file " . $oPath->sPath); } } function _bCreateThumbNailFor($sImgFilename) { // ### // use WYImage's class method here instead! // ---------------------------------------- global $goApp; $bSuccess = false; $rInImage = $rOutImage = false; $iW = $iH = 0; $iTNW = $iTNH = 0; $oImgPath = od_clone($goApp->oDataPath); $oImgPath->addComponent($sImgFilename); $oTNPath = od_clone($goApp->oDataPath); $oTNPath->addComponent($this->_sThumbnailName($sImgFilename)); $oTNPath->setExtension("jpg"); if (!function_exists("imagejpeg")) return false; if (strtolower($oImgPath->sExtension()) == "jpg") { if (!function_exists("imagecreatefromjpeg")) return false; else $rInImage = @imagecreatefromjpeg($oImgPath->sPath); } if (strtolower($oImgPath->sExtension()) == "gif") { if (!function_exists("imagecreatefromgif")) return false; else $rInImage = @imagecreatefromgif($oImgPath->sPath); } if (!$rInImage) return false; // calc TN size $iW = imagesx($rInImage); $iH = imagesy($rInImage); $iTNW = $iW; $iTNH = $iH; WYImage::bLimitSize($iTNW, $iTNH, $this->iTNWidth, $this->iTNHeight); if (function_exists("imagecreatetruecolor")) $rOutImage = @imagecreatetruecolor($iTNW, $iTNH); else if (function_exists("imagecreate")) $rOutImage = @imagecreate($iTNW, $iTNH); if (!$rOutImage) return false; if (function_exists("imagecopyresampled")) $bSuccess = @imagecopyresampled($rOutImage, $rInImage, 0, 0, 0, 0, $iTNW, $iTNH, $iW, $iH); if (!$bSuccess && function_exists("imagecopyresized")) $bSuccess = @imagecopyresized($rOutImage, $rInImage, 0, 0, 0, 0, $iTNW, $iTNH, $iW, $iH); if (!$bSuccess) return false; $bSuccess = @imagejpeg($rOutImage, $oTNPath->sPath, 100); chmod($oTNPath->sPath, 0644); return $bSuccess; } function useUploadedImageFileForID(&$oFromPath, &$oOrgFilename, $iID) { global $goApp; $sNewFilename = ""; $sExt = strtolower($oOrgFilename->sExtension()); $aItems =& $this->_aItems(); $dItem = array(); $bSuccess = false; if ($oFromPath && isset($aItems[$iID])) { $oFromFile = new WYFile($oFromPath); $oToPath = od_clone($goApp->oDataPath); $sNewFilename = $this->sDataFileName(true) . "-" . mt_rand(1000, 9999) . "." . $sExt; $oToPath->addComponent($sNewFilename); $bOK = false; $a = WYImage::aGetImageSize($oFromPath); $iW = $a[0]; $iH = $a[1]; if (!WYImage::bLimitSize($iW, $iH, $this->iImageWidth, $this->iImageHeight)) { if ($oFromFile->bMoveTo($oToPath)) $bOK = true; else $goApp->log("WYGallery: could not move image file: " . $oFromPath->sPath . " to " . $oToPath->sPath); } else { $oTMPPath = od_clone($goApp->oDataPath); $oTMPPath->addComponent("WYGalleryUpload_" . mt_rand(1000, 9999) . "." . $sExt); if ($oFromFile->bMoveTo($oTMPPath)) { if (WYImage::bResizeImage($oTMPPath, $oToPath, $iW, $iH)) { $bOK = true; if (!@unlink($oTMPPath->sPath)) $goApp->log("WYGallery: could not unlink uploaded image file: " . $oTMPPath->sPath); } else $goApp->log("WYGallery: could not resize uploaded image file: " . $oFromPath->sPath); } else $goApp->log("WYGallery: could not move image file: " . $oFromPath->sPath . " to " . $oTMPPath->sPath); } if ($bOK) { $this->_deleteImageFilesForID($iID); $dItem =& $aItems[$iID]; $dItem[WY_DK_GALLERY_FILENAME] = $sNewFilename; chmod($oToPath->sPath, 0644); if (!$this->_bCreateThumbNailFor($sNewFilename)) // if creating the thumbnail doesn't work, we only can copy the original image...:-( { $oTNPath = od_clone($oToPath); $oTNPath->removeLastComponent(); $oTNPath->addComponent($this->_sThumbnailName($sNewFilename)); $oTNPath->setExtension($oToPath->sExtension()); $oFile =& new WYFile($oToPath); if (!$oFile->bCopyTo($oTNPath)) $goApp->log("could not copy image $sNewFilename to thumbnail"); else chmod($oTNPath->sPath, 0644); } } } } function _sEditButtons($iID) { global $goApp; $sHTML = ""; $oURL = od_clone(WYURL::oCurrentURL()); $oLink = od_nil; $oImg = od_nil; $oImgURL = od_clone($goApp->oImageURL); $dEditQuery = WYEditor::dQueryForElement($this); $aItems =& $this->_aItems(); $iCount = count($aItems); if ($goApp->bEditMode) { $dEditQuery[WY_QK_GALLERY_IMAGE_ID] = $iID; // $dEditQuery = array_merge($oURL->dQuery, array(WY_QK_GALLERY_IMAGE_ID => $iID)); $oURL->setQuery(array_merge($oURL->dQuery, $dEditQuery)); /* $goApp->setActionInQuery($dEditQuery, WY_QV_LOOP_ADD); $oURL->setQuery(array_merge($oURL->dQuery, $dEditQuery)); $oLink = new WYLink($oURL, WYTS("GalleryAddButton")); $oImgURL->addComponent("add-button.gif"); $oImg = new WYImage($oImgURL); $oLink->setInnerHTML($oImg->sDisplay()); $sHTML .= $oLink->sDisplay(); */ $sHTML .= "
"; $this->dEditorQuery[WY_QK_GALLERY_IMAGE_ID] = $iID; $this->dEditorQuery[WY_QK_THUMB_WIDTH] = $this->iTNWidth; $this->dEditorQuery[WY_QK_THUMB_HEIGHT] = $this->iTNHeight; $this->dEditorQuery[WY_QK_IMAGE_WIDTH] = $this->iImageWidth; $this->dEditorQuery[WY_QK_IMAGE_HEIGHT] = $this->iImageHeight; $this->dEditorQuery[WY_QK_GALLERY_IMAGE_ID] = $iID; $this->dEditorQuery[WY_QK_GALLERY_ADD] = "true"; $goApp->setActionInQuery($dEditQuery, WY_QV_GALLERY_UP); $oURL->setQuery($dEditQuery); $oLink = new WYLink($iCount > 1 ? $oURL:(new WYURL("javascript:void(0)")), WYTS("GalleryUpButton")); $oImgURL->addComponent("gallery-move-left-button.gif"); $oImg = new WYImage($oImgURL); $oImg->setAttribute("style", "border: none"); $oImgURL->removeLastComponent(); $oLink->setInnerHTML($oImg->sDisplay()); $oLink->setAttribute("class", "WebYepGalleryUpButton"); $sHTML .= $oLink->sDisplay(); $this->sEditButtonCSSClass = "WebYepGalleryAddButton"; $sHTML .= $this->sEditButtonHTML("gallery-add-button.gif", WYTS("GalleryAddButton"), $goApp->bIsiPhone ? $this->oIPhoneEditURL():od_nil); $dEditQuery = $oURL->dQuery; $goApp->setActionInQuery($dEditQuery, WY_QV_GALLERY_REMOVE); $oURL->setQuery($dEditQuery); $oLink = new WYLink($iCount > 0 ? $oURL:(new WYURL("javascript:void(0)")), WYTS("GalleryRemoveButton")); $oImgURL->addComponent("gallery-remove-button.gif"); $oImg = new WYImage($oImgURL); $oImg->setAttribute("style", "border: none"); $oImgURL->removeLastComponent(); $oLink->setInnerHTML($oImg->sDisplay()); $oLink->setAttribute("onclick", "return confirm(\"" . WYTS("GalleryRemoveConfirm") . "\");"); $oLink->setAttribute("class", "WebYepGalleryRemoveButton"); $sHTML .= $oLink->sDisplay(); $oLink->removeAttribute("onclick"); $goApp->setActionInQuery($dEditQuery, WY_QV_GALLERY_DOWN); $oURL->setQuery($dEditQuery); $oLink = new WYLink($iCount > 1 ? $oURL:(new WYURL("javascript:void(0)")), WYTS("GalleryDownButton")); $oImgURL->addComponent("gallery-move-right-button.gif"); $oImg = new WYImage($oImgURL); $oImg->setAttribute("style", "border: none"); $oImgURL->removeLastComponent(); $oLink->setInnerHTML($oImg->sDisplay()); $oLink->setAttribute("class", "WebYepGalleryDownButton"); $sHTML .= $oLink->sDisplay(); if ($iCount > 0) { $sHTML .= "
"; $this->dEditorQuery[WY_QK_GALLERY_ADD] = "false"; $this->sEditButtonCSSClass = "WebYepGalleryEditButton"; $sHTML .= $this->sEditButtonHTML("gallery-edit-button.gif", WYTS("GalleryEditButton"), $goApp->bIsiPhone ? $this->oIPhoneEditURL():od_nil); } $sHTML .= "
"; } return $sHTML; } function dispatchEditAction() { global $goApp; $sAction = $goApp->sCurrentAction(); $sFieldName = $goApp->sFormFieldValue(WY_QK_EDITOR_FIELDNAME, ""); $iImageID = $goApp->sFormFieldValue(WY_QK_GALLERY_IMAGE_ID, 0); $iLoopID = $goApp->sFormFieldValue(WY_QK_LOOP_ID, 0); $aItems =& $this->_aItems(); $aTempItems = array(); $dItem = array(); $iCount = count($aItems); $iNewIndex = 0; $iPos = 0; $bChanged = false; if ($sFieldName != $this->sName) return; if ($iLoopID != $goApp->oDocument->iLoopID()) return; if ($sAction == WY_QV_GALLERY_REMOVE) { if ($iCount > 0) { if ($iPos !== false) { $this->_deleteImageFilesForID($iImageID); array_splice($aItems, $iImageID, 1); } $bChanged = true; } } else if ($sAction == WY_QV_GALLERY_UP) { if ($iCount > 1 && $iImageID > 0) { $aTempItems = array_splice($aItems, $iImageID, 1); webyep_array_insert($aItems, $iImageID - 1, $aTempItems[0]); $bChanged = true; } } else if ($sAction == WY_QV_GALLERY_DOWN) { if ($iCount > 1 && $iImageID < ($iCount-1) ) { $aTempItems = array_splice($aItems, $iImageID, 1); webyep_array_insert($aItems, $iImageID + 1, $aTempItems[0]); $bChanged = true; } } if ($bChanged) { $this->save(); } } function _sThumbnailName($sFilename) { global $goApp; $oP = $oF = od_nil; $sOrgExt = ""; $sTN = ""; $oP = new WYPath($sFilename); $sOrgExt = $oP->sExtension(); $oP = od_clone($goApp->oDataPath); $iPos = strrpos($sFilename, "."); $sTN = substr($sFilename, 0, $iPos) . "-tn.jpg"; $oP->addComponent($sTN); $oF =& new WYFile($oP); if (!$oF->bExists()) { $oP->removeDemoSlotID(); // try again without demo slot ID unset($oF); $oF =& new WYFile($oP); if (!$oF->bExists()) { $oP->setExtension($sOrgExt); $sTN = $oP->sBasename(); } } return $sTN; } function &_oTNImage($sFilename) { global $goApp, $webyep_sLiveDemoSlotID; $oImg = od_nil; $oURL = od_nil; $sTNName = ""; $fFactor = 0.0; $iW = $iH = 0; $oURL = od_clone($goApp->oDataURL); $iPos = strrpos($sFilename, "."); $sTNName = $this->_sThumbnailName($sFilename); $oURL->addComponent($sTNName); $oImg =& new WYImage($oURL); if ($webyep_sLiveDemoSlotID && !$oImg->bExists()) { $oURL->removeDemoSlotID(); unset($oImg); $oImg =& new WYImage($oURL); } if (isset($oImg->dAttributes["width"]) && isset($oImg->dAttributes["height"])) { WYImage::bLimitSize($oImg->dAttributes["width"], $oImg->dAttributes["height"], $this->iTNWidth, $this->iTNHeight); } else { // if size can't be determined, set at least max width $goApp->log("could not determine image size of $sTNName"); $oImg->dAttributes["width"] = $this->iTNWidth; unset($oImg->dAttributes["height"]); } return $oImg; } function &dItemForID($iID) { $aItems =& $this->_aItems(); if (isset($aItems[$iID])) $dItem =& $aItems[$iID]; $dItem = od_nil; return $dItem; } function setTransactionIDforID($iItemID, $iTransID) { $aItems =& $this->_aItems(); if (isset($aItems[$iItemID])) { $dItem =& $aItems[$iItemID]; $dItem[WY_DK_GALLERY_TRANSACTION_ID] = $iTransID; } } function iTransactionIDforID($iItemID) { $dItem =& $this->dItemForID($iItemID); if ($dItem) return $dItem[WY_DK_GALLERY_TRANSACTION_ID]; else return 0; } function setTextForID($iID, $sText) { $aItems =& $this->_aItems(); $dItem = od_nil; if (isset($aItems[$iID])) $dItem =& $aItems[$iID]; if ($dItem) $dItem[WY_DK_GALLERY_TEXT] = $sText; } function sTextForID($iID) { $aItems =& $this->_aItems(); $dItem = isset($aItems[$iID]) ? $aItems[$iID]:od_nil; if ($dItem) return $dItem[WY_DK_GALLERY_TEXT]; else return ""; } function sFilenameForID($iID) { $aItems =& $this->_aItems(); $dItem = isset($aItems[$iID]) ? $aItems[$iID]:od_nil; if ($dItem) return $dItem[WY_DK_GALLERY_FILENAME]; else return ""; } function sStripFormatting($s) { $s = preg_replace('|]+)>|', '\1', $s); $s = preg_replace('|<[A-Z0-9]+ ([^>]+)>|', '\1', $s); $s = strip_tags($s); return $s; } function sDisplay() { global $goApp, $webyep_bUseTablesForGalleries, $webyep_bUseLightBox, $webyep_sLiveDemoSlotID; $sHTML = ""; $iCount = count($this->_aItems()); $i = 0; $iCols = $this->iCols; $bEditMode = $goApp->bEditMode; $sTNName = ""; $oTN = $oLink = $oDetailURL = od_nil; $sText = $sFilename = ""; $sBoxName = $this->sDataFileName(false); if ($iCount == 0 && !$bEditMode) return ""; if (!$webyep_bUseLightBox) { $oDetailURL = od_clone($goApp->oProgramURL); $oDetailURL->addComponent("image-detail.php"); } $sHTML .= $webyep_bUseTablesForGalleries ? sprintf("\n", WY_GALLERY_CSS_CONTAINER):sprintf("
\n", WY_GALLERY_CSS_CONTAINER); while ((($i < $iCount) || ($iCount == 0 && $i == 0 && $bEditMode)) || ($i % $iCols)) { // new row? if (!($i % $iCols)) $sHTML .= $webyep_bUseTablesForGalleries ? sprintf(" \n", $i < $iCols ? (" class=\"" . WY_GALLERY_CSS_FIRSTROW . "\""):""):sprintf("
\n", WY_GALLERY_CSS_ROW, $i < $iCols ? (" " . WY_GALLERY_CSS_FIRSTROW):""); $sHTML .= $webyep_bUseTablesForGalleries ? sprintf("
\n":"\n"; // /WY_GALLERY_CSS_CELL $i++; if (!($i % $iCols)) $sHTML .= $webyep_bUseTablesForGalleries ? " \n":" \n"; // WY_GALLERY_CSS_ROW } $sHTML .= $webyep_bUseTablesForGalleries ? "
", $this->iCellWidth, ($i % $iCols) == 0 ? (" class=\"" . WY_GALLERY_CSS_FIRSTCOLUMN . "\""):""):sprintf("
", $this->iCellWidth, WY_GALLERY_CSS_CELL, ($i % $iCols) == 0 ? (" " . WY_GALLERY_CSS_FIRSTCOLUMN):""); if ($i < $iCount) { $sHTML .= sprintf("
", WY_GALLERY_CSS_IMAGE); $sFilename = $this->sFilenameForID($i); $sText = $this->sTextForID($i); if ($sFilename) { $oTN =& $this->_oTNImage($sFilename); unset($oLink); if ($webyep_bUseLightBox) { unset($oImgURL); $oImgURL = od_clone($goApp->oDataURL); $oImgURL->addComponent($sFilename); if ($webyep_sLiveDemoSlotID) { $oImg = new WYImage($oImgURL); if (!$oImg->bExists()) $oImgURL->removeDemoSlotID(); } $oLink =& new WYLink($oImgURL, $sText ? $this->sStripFormatting($sText):" "); $oLink->setAttribute("rel", "lightbox[$sBoxName]"); $oLink->sInnerHTML = $oTN->sDisplay(); $sHTML .= $oLink->sDisplay(); } else { $oDetailURL->dQuery[WY_QK_IMAGE_DETAIL] = $sFilename; $oDetailURL->dQuery[WY_QK_IMAGE_ALTTEXT] = $this->sStripFormatting($sText); $oDetailURL->dQuery[WY_QK_IMAGE_DEMOCONTENT] = $this->bDemoContent; $oLink = new WYLink(new WYURL("javascript:void(0)")); $oLink->setAttribute("onclick", sprintf("wydw=window.open(\"%s\", \"WYDetail\", \"width=%d,height=%d,status=yes,scrollbars=no,resizable=yes\"); wydw.focus();", $oDetailURL->sEURL(true, true, true), $this->iImageWidth, $this->iImageHeight)); $oLink->setToolTip(WYTS("ClickToZoom")); $oLink->sInnerHTML = $oTN->sDisplay(); $sHTML .= $oLink->sDisplay(); } } else if ($bEditMode) { $sHTML .= WYTS("GalleryNoImage"); } $sHTML .= "
"; } if ($bEditMode && ( ($i < $iCount) || ($i == 0) ) ) { $sHTML .= "\n
"; $sHTML .= $this->_sEditButtons(($i < $iCount) ? $i:-1); $sHTML .= "
"; } if ($i < $iCount) { if ($sText) { $sHTML .= sprintf("
", WY_GALLERY_CSS_TEXT);; // $sHTML .= webyep_sHTMLEntities($sText); $sHTML .= WYLongTextElement::_sFormatContent($sText, true); $sHTML .= "
"; } } $sHTML .= $webyep_bUseTablesForGalleries ? "
\n":"\n"; // /WY_GALLERY_CSS_CONTAINER return $sHTML; } } ?>