function cooliris() { $cids = JRequest::getVar('cid', array(0), 'post', 'array'); $model = $this->getModel('phocagalleryc'); $message = ''; if (!$model->cooliris($cids, $message)) { $message = PhocaGalleryUtils::setMessage(JText::_($message), JText::_('COM_PHOCAGALLERY_ERROR_CREATING_COOLIRS_FILE')); } else { $message = PhocaGalleryUtils::setMessage(JText::_($message), JText::_('COM_PHOCAGALLERY_COOLIRIS_FILE_CREATED')); } $link = 'index.php?option=com_phocagallery&view=phocagallerycs'; $this->setRedirect($link, $message); }
function recreate() { $cid = JRequest::getVar('cid', array(), '', 'array'); JArrayHelper::toInteger($cid); if (count($cid) < 1) { JError::raiseError(500, JText::_('COM_PHOCAGALLERY_SELECT_ITEM_RECREATE')); } $message = ''; $model = $this->getModel('phocagalleryimg'); if (!$model->recreate($cid, $message)) { $message = PhocaGalleryUtils::setMessage($message, JText::_('COM_PHOCAGALLERY_ERROR_THUMBS_REGENERATING')); } else { $message = JText::_('COM_PHOCAGALLERY_SUCCESS_THUMBS_REGENERATING'); } $this->setRedirect('index.php?option=com_phocagallery&view=phocagalleryimgs', $message); }
public static function rotateImage($thumbName, $size, $angle = 90, &$errorMsg) { $params = JComponentHelper::getParams('com_phocagallery'); $jfile_thumbs = $params->get('jfile_thumbs', 1); $jpeg_quality = $params->get('jpeg_quality', 85); $jpeg_quality = PhocaGalleryImage::getJpegQuality($jpeg_quality); // Try to change the size $memory = 8; $memoryLimitChanged = 0; $memory = (int) ini_get('memory_limit'); if ($memory == 0) { $memory = 8; } $fileIn = $thumbName->abs; $fileOut = $thumbName->abs; if ($fileIn !== '' && file_exists($fileIn)) { //array of width, height, IMAGETYPE, "height=x width=x" (string) list($w, $h, $type) = GetImageSize($fileIn); // we got the info from GetImageSize if ($w > 0 && $h > 0 && $type != '') { // Change the $w against $h because of rotating $src = array(0, 0, $w, $h); $dst = array(0, 0, $h, $w); } else { $errorMsg = 'ErrorWorHorType'; return false; } // Try to increase memory if ($memory < 50) { ini_set('memory_limit', '50M'); $memoryLimitChanged = 1; } switch ($type) { case IMAGETYPE_JPEG: if (!function_exists('ImageCreateFromJPEG')) { $errorMsg = 'ErrorNoJPGFunction'; return false; } //$image1 = ImageCreateFromJPEG($fileIn); try { $image1 = ImageCreateFromJPEG($fileIn); } catch (\Exception $exception) { $errorMsg = 'ErrorJPGFunction'; return false; } break; case IMAGETYPE_PNG: if (!function_exists('ImageCreateFromPNG')) { $errorMsg = 'ErrorNoPNGFunction'; return false; } //$image1 = ImageCreateFromPNG($fileIn); try { $image1 = ImageCreateFromPNG($fileIn); } catch (\Exception $exception) { $errorMsg = 'ErrorPNGFunction'; return false; } break; case IMAGETYPE_GIF: if (!function_exists('ImageCreateFromGIF')) { $errorMsg = 'ErrorNoGIFFunction'; return false; } //$image1 = ImageCreateFromGIF($fileIn); try { $image1 = ImageCreateFromGIF($fileIn); } catch (\Exception $exception) { $errorMsg = 'ErrorGIFFunction'; return false; } break; case IMAGETYPE_WBMP: if (!function_exists('ImageCreateFromWBMP')) { $errorMsg = 'ErrorNoWBMPFunction'; return false; } //$image1 = ImageCreateFromWBMP($fileIn); try { $image1 = ImageCreateFromWBMP($fileIn); } catch (\Exception $exception) { $errorMsg = 'ErrorWBMPFunction'; return false; } break; default: $errorMsg = 'ErrorNotSupportedImage'; return false; break; } if ($image1) { // Building image for ROTATING /* $image2 = @ImageCreateTruecolor($dst[2], $dst[3]); if (!$image2) { return 'ErrorNoImageCreateTruecolor'; }*/ /* if(!function_exists("imagerotate")) { $errorMsg = 'ErrorNoImageRotate'; return false; }*/ switch ($type) { case IMAGETYPE_PNG: // imagealphablending($image1, false); // imagesavealpha($image1, true); if (!function_exists("imagecolorallocate")) { $errorMsg = 'ErrorNoImageColorAllocate'; return false; } if (!function_exists("imagefill")) { $errorMsg = 'ErrorNoImageFill'; return false; } if (!function_exists("imagecolortransparent")) { $errorMsg = 'ErrorNoImageColorTransparent'; return false; } $colBlack = imagecolorallocate($image1, 0, 0, 0); if (!function_exists("imagerotate")) { $image2 = PhocaGalleryImageRotate::imageRotate($image1, $angle, $colBlack); } else { $image2 = imagerotate($image1, $angle, $colBlack); } imagefill($image2, 0, 0, $colBlack); imagecolortransparent($image2, $colBlack); break; default: if (!function_exists("imagerotate")) { $image2 = PhocaGalleryImageRotate::imageRotate($image1, $angle, 0); } else { $image2 = imageRotate($image1, $angle, 0); } break; } // Get the image size and resize the rotated image if necessary $rotateWidth = imagesx($image2); // Get the size from rotated image $rotateHeight = imagesy($image2); // Get the size from rotated image $parameterSize = PhocaGalleryFileThumbnail::getThumbnailResize($size); $newWidth = $parameterSize['width']; // Get maximum sizes, they can be displayed $newHeight = $parameterSize['height']; // Get maximum sizes, they can be displayed $scale = $newWidth / $rotateWidth < $newHeight / $rotateHeight ? $newWidth / $rotateWidth : $newHeight / $rotateHeight; // smaller rate $src = array(0, 0, $rotateWidth, $rotateHeight); $dst = array(0, 0, floor($rotateWidth * $scale), floor($rotateHeight * $scale)); // If original is smaller than thumbnail size, don't resize it if ($src[2] > $dst[2] || $src[3] > $dst[3]) { // Building image for RESIZING THE ROTATED IMAGE $image3 = @ImageCreateTruecolor($dst[2], $dst[3]); if (!$image3) { $errorMsg = 'ErrorNoImageCreateTruecolor'; return false; } ImageCopyResampled($image3, $image2, $dst[0], $dst[1], $src[0], $src[1], $dst[2], $dst[3], $src[2], $src[3]); switch ($type) { case IMAGETYPE_PNG: // imagealphablending($image2, true); // imagesavealpha($image2, true); if (!function_exists("imagecolorallocate")) { $errorMsg = 'ErrorNoImageColorAllocate'; return false; } if (!function_exists("imagefill")) { $errorMsg = 'ErrorNoImageFill'; return false; } if (!function_exists("imagecolortransparent")) { $errorMsg = 'ErrorNoImageColorTransparent'; return false; } $colBlack = imagecolorallocate($image3, 0, 0, 0); imagefill($image3, 0, 0, $colBlack); imagecolortransparent($image3, $colBlack); break; } } else { $image3 = $image2; } switch ($type) { case IMAGETYPE_JPEG: if (!function_exists('ImageJPEG')) { $errorMsg = 'ErrorNoJPGFunction'; return false; } if ($jfile_thumbs == 1) { ob_start(); if (!@ImageJPEG($image3, NULL, $jpeg_quality)) { ob_end_clean(); $errorMsg = 'ErrorWriteFile'; return false; } $imgJPEGToWrite = ob_get_contents(); ob_end_clean(); if (!JFile::write($fileOut, $imgJPEGToWrite)) { $errorMsg = 'ErrorWriteFile'; return false; } } else { if (!@ImageJPEG($image3, $fileOut, $jpeg_quality)) { $errorMsg = 'ErrorWriteFile'; return false; } } break; case IMAGETYPE_PNG: if (!function_exists('ImagePNG')) { $errorMsg = 'ErrorNoPNGFunction'; return false; } if ($jfile_thumbs == 1) { ob_start(); if (!@ImagePNG($image3, NULL)) { ob_end_clean(); $errorMsg = 'ErrorWriteFile'; return false; } $imgPNGToWrite = ob_get_contents(); ob_end_clean(); if (!JFile::write($fileOut, $imgPNGToWrite)) { $errorMsg = 'ErrorWriteFile'; return false; } } else { if (!@ImagePNG($image3, $fileOut)) { $errorMsg = 'ErrorWriteFile'; return false; } } break; case IMAGETYPE_GIF: if (!function_exists('ImageGIF')) { $errorMsg = 'ErrorNoGIFFunction'; return false; } if ($jfile_thumbs == 1) { ob_start(); if (!@ImageGIF($image3, NULL)) { ob_end_clean(); $errorMsg = 'ErrorWriteFile'; return false; } $imgGIFToWrite = ob_get_contents(); ob_end_clean(); if (!JFile::write($fileOut, $imgGIFToWrite)) { $errorMsg = 'ErrorWriteFile'; return false; } } else { if (!@ImageGIF($image3, $fileOut)) { $errorMsg = 'ErrorWriteFile'; return false; } } break; default: $errorMsg = 'ErrorNotSupportedImage'; return false; break; } // free memory ImageDestroy($image1); // Original ImageDestroy($image2); // Rotated ImageDestroy($image3); // Resized if ($memoryLimitChanged == 1) { $memoryString = $memory . 'M'; ini_set('memory_limit', $memoryString); } return true; // Success } else { $errorMsg = PhocaGalleryUtils::setMessage($errorMsg, JText::_('COM_PHOCAGALLERY_ERROR_IMAGE_NOT_PROCESS')); return false; } if ($memoryLimitChanged == 1) { $memoryString = $memory . 'M'; ini_set('memory_limit', $memoryString); } } $errorMsg = JText::_('COM_PHOCAGALLERY_FILEORIGINAL_NOT_EXISTS'); return false; }
public function loadExtImages($idCat, $data, &$message) { $paramsC = JComponentHelper::getParams('com_phocagallery'); $picasa_load_pagination = $paramsC->get('picasa_load_pagination', 20); // First get Album ID from PICASA // Second - Get id (from saved category) OR from GET (if pagination is used) // Third save images with ID of category $errorMsgA = $errorMsgI = ''; //FIRST if (JRequest::getVar('picstart', 0, 'get', 'int') > 0) { // Category is saved - use this id and don't save it again $data['exta'] = JRequest::getVar('picalbum', '', 'get'); $data['extu'] = JRequest::getVar('picuser', '', 'get'); $data['extauth'] = JRequest::getVar('picauth', '', 'get'); $data['language'] = JRequest::getVar('piclang', '', 'get'); } $album = $this->picasaAlbum($data['extu'], $data['extauth'], $data['exta'], $errorMsgA); if (!$album) { $message = PhocaGalleryUtils::setMessage($errorMsgA, $message); return false; } else { $data['extid'] = $album['id']; } // SECOND if (JRequest::getVar('picstart', 0, 'get', 'int') > 0) { // Category is saved - use this id and don't save it again $id = JRequest::getVar('id', 0, 'get', 'int'); } else { $id = $idCat; //you get id and you store the table data } if ($id && $id > 0) { // THIRD if ($album && (int) $album['id'] > 0) { // PAGINATION $start = JRequest::getVar('picstart', 1, 'get', 'int'); $max = $picasa_load_pagination; $pagination = '&start-index=' . (int) $start . '&max-results=' . (int) $max; $picImg = $this->picasaImages($data['extu'], $data['extauth'], $album['id'], $id, $data['language'], $pagination, $errorMsgI); if (!$picImg) { $message = PhocaGalleryUtils::setMessage($errorMsgI, $message); return false; } else { if (isset($album['num']) && (int) $album['num'] > 0) { $newStart = (int) $start + (int) $max; $newStartIf = (int) $newStart - 1; // Sec - - - - $loop = (int) $album['num'] / (int) $max; $maxCount = (int) $max; // - - - - - - if ((int) $loop > 50 || $maxCount < 20) { $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_PICASA_IMAGE_NOT_ALL_LOADED'), $message); return false; } else { if ((int) $album['num'] > (int) $newStartIf) { $refreshUrl = 'index.php?option=com_phocagallery&task=phocagalleryc.loadextimgpgn&id=' . $id . '&picalbum=' . $data['exta'] . '&picuser='******'extu'] . '&picauth=' . $data['extauth'] . '&piclang=' . $data['language'] . '&picstart=' . (int) $newStart . '&' . JSession::getFormToken() . '=1'; $countImg = $newStartIf + $max; if ($countImg > $album['num']) { $countImg = $album['num']; } //$countInfo = '<div><b>'.$newStart. '</b> - <b>'. $countImg . '</b> ' .JText::_('COM_PHOCAGALLERY_FROM'). ' <b>' . $album['num'].'</b></div>'; $countInfo = '<div>' . JText::sprintf('COM_PHOCAGALLERY_FROM_ALBUM', '<b>' . $newStart . '</b>', '<b>' . $countImg . '</b> ', ' <b>' . $album['num'] . '</b>') . '</div>'; PhocaGalleryPicasa::renderProcessPage($id, $refreshUrl, $countInfo); exit; } } } // The extid is not a part of post data, so we must store it after $query = $this->_db->getQuery(true); $query->update('`#__phocagallery_categories`'); $query->set('`extid` = ' . $this->_db->quote($album['id'])); $query->where('`id` = ' . (int) $id); $this->_db->setQuery((string) $query); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_PICASA_IMAGE_LOADED'), $message); return true; } } } else { $message = PhocaGalleryUtils::setMessage(JText::_('COM_PHOCAGALLERY_ERROR_SAVING_CATEGORY'), $message); return true; } }