/** * Executes ResizeImage action * * This action can be used into an ajax action to resize an image. This function requires * some parameters: * image : The name of the image to resize * imagePath : The full image path * imageWidth : The new image width * imageHeight : The new image height * imageType : The new image type. This parameter must be 1-GIF 2-JPG 3-PNG. Other * formats will be ignored * imageQuality : The new value for the image quality. Applies only to JPG images * * return A JSon header. */ public function executeResizeImage() { // Resizes the image $imagePath = w3sCommonFunctions::checkLastDirSeparator(sfConfig::get('app_images_path')); $imageEditor = new ImageEditor($this->getRequestParameter('image'), $imagePath); echo $this->getRequestParameter('imageWidth') . ' - ' . $this->getRequestParameter('imageHeight'); $imageEditor->resize($this->getRequestParameter('imageWidth'), $this->getRequestParameter('imageHeight')); // Retrieve the image type and verifies if the new image will be of the same type $imageAttributes = getimagesize($imagePath . $this->getRequestParameter('image')); $newType = $this->getRequestParameter('imageType') != $imageAttributes[2] ? $this->getRequestParameter('imageType') : 0; // Writes the new image and returns its name $newFileName = $imageEditor->outputFile($this->getRequestParameter('image'), $imagePath, $newType, $this->getRequestParameter('imageQuality')); // Produces the output header for ajax calling. $canvasImage = w3sClassImageManager::getImageAttributes($newFileName, $this->getRequestParameter('previewWidth'), $this->getRequestParameter('previewHeight'), $this->getRequestParameter('setCanvas')); //$output = '[["w3s_image_size", "' . $imageAttributes["size"] . '"],["w3s_image_preview", "' . $imageAttributes["htmlImage"] . '"], ["w3s_image_canvas", "' . $imageAttributes["canvasValue"] . '"],["w3s_start_width", "' . $imageAttributes["width"] . '"],["w3s_start_height", "' . $imageAttributes["height"] . '"]]'; $jsonImage = '[["w3s_image_preview", "' . $canvasImage["htmlImage"] . '"],'; $jsonImage .= '["w3s_editor_image_size", "' . $canvasImage["size"] . '"],'; $jsonImage .= '["w3s_editor_width", "' . $canvasImage["width"] . '"],'; $jsonImage .= '["w3s_editor_height", "' . $canvasImage["height"] . '"],'; $jsonImage .= '["w3s_editor_type_select", "' . $canvasImage["imageType"] . '"],'; $jsonImage .= '["w3s_editor_canvas", "' . $canvasImage["canvasValue"] . '"],'; $jsonImage .= '["w3s_editor_start_width", "' . $canvasImage["width"] . '"],'; $jsonImage .= '["w3s_editor_start_height", "' . $canvasImage["height"] . '"],'; $jsonImage .= '["w3s_ppt_htmlImage", "' . $canvasImage["htmlImage"] . '"],'; $jsonImage .= '["w3s_ppt_imageType", "' . $canvasImage["imageType"] . '"],'; $jsonImage .= '["w3s_ppt_size", "' . $canvasImage["size"] . '"],'; $jsonImage .= '["w3s_ppt_width", "' . $canvasImage["width"] . '"],'; $jsonImage .= '["w3s_ppt_height", "' . $canvasImage["height"] . '"]]'; $this->imagesList = w3sCommonFunctions::buildFilesList($imagePath, $newFileName, array('gif', 'jpg', 'jpeg', 'png')); /* if ($newFileName != $this->getRequestParameter('image')){ }*/ $this->getResponse()->setHttpHeader("X-JSON", '(' . $jsonImage . ')'); return sfView::HEADER_ONLY; }
/** * Generates an array similar to the one generated by the * getParameterHolder()->getAll() function. It needs a serialized string * similar to [Parameter Name][]=[Property name]=[Property value]&; * * @param string serialized string which must match the following rule: * [Parameter Name A][]=[Property name]=[Property value]&[Parameter Name A][]=[Property name]=[Property value]&[Parameter Name B][]=[Property name]=[Property value]&... * * @return array The array with contents formatted. */ protected function saveParams($params) { $params = w3sCommonFunctions::checkLastDirSeparator($params, '&'); preg_match_all('/([0-9]+)\\[\\]=(.*?)&/', $params, $res); $current = array(); $result = array(); $currentKey = 0; foreach ($res[1] as $key => $value) { if ($value != $currentKey) { if ($currentKey != 0) { $result[$currentKey] = $current; } $current = array(); $currentKey = $value; } $current[] = $res[2][$key]; } $result[$currentKey] = $current; return $result; }
/** * Sets the value of the imagesPath variable. * * @param string * */ public function setImagesPath($value) { $this->imagesPath = w3sCommonFunctions::checkLastDirSeparator($value); }
/** * Renders the button * * @return string * */ public function render() { // Disable the button if a reference to current user has been passed and // the user has not the required credentials to use that button $hasCredentials = true; if (isset($this->currentUser) && isset($this->requiredCredentials) && !$this->currentUser->hasCredential($this->requiredCredentials)) { $hasCredentials = false; $this->enabled = false; } // Sets the image $this->image = $this->enabled ? $this->image : ($this->imageDisabled != '' ? $this->imageDisabled : $this->image); if ($this->image != '') { $image = sprintf('<img src="%s" %s />', $this->image, _tag_options($this->imageParams)); } else { // No image specified, configuring a text button $image = ''; $this->imageTextRelation = 4; } // action if ($this->action != '') { if (!$this->enabled) { $this->action = 'alert(\'You don\\\'t have the require credentials for this function\')'; $this->actionParams = $this->actionDisabledParams; } $function = substr($this->action, 1, 2) != 'on' ? sprintf('onclick="%s return false;"', w3sCommonFunctions::checkLastDirSeparator($this->action, ';')) : $this->action; } else { $function = ''; } return sprintf($this->buttonSkeleton(), $this->linkedTo, $function, _tag_options($this->actionParams), $image, $this->caption); }
/** * Check current location and return: * - basename if standard location * - src if custom location * * @param string $fullPath The full path to file * @param string $baseDir Standard document(web) base dir * * @return string */ public static function getStdBasename($fullPath, $baseDir) { $basename = basename($fullPath); $stdPath = w3sCommonFunctions::checkLastDirSeparator(sfConfig::get('sf_web_dir') . $baseDir) . $basename; if ($stdPath == $fullPath) { return $basename; } return str_replace(sfConfig::get('sf_web_dir'), '', $fullPath); }