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->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":"