public function save($conn = null)
 {
     $return = parent::save($conn);
     if ($this->getObject()->getPath() != '') {
         $uploadDir = sfConfig::get('sf_upload_dir') . '/photo/';
         $image = explode('.', $this->getObject()->getPath());
         $img = new sfImage($uploadDir . $image[0] . '.' . $image[1], swImageTransform::mime_content_type($uploadDir . $image[0] . '.' . $image[1]));
         if ($img->getWidth() > $img->getHeight()) {
             $img->resize(780, 518);
         } else {
             $img->resize(344, 518);
         }
         $img->setQuality(95);
         $img->overlay(new sfImage(sfConfig::get('sf_web_dir') . '/images/marcadagua.png', 'image/png'), 'bottom-right');
         $img->saveAs($uploadDir . $this->getObject()->getSlug() . '.' . $image[1]);
         if ($img->getWidth() > $img->getHeight()) {
             $img->resize(130, 86);
         } else {
             $img->resize(130, 196);
             $img->crop(0, 55, 130, 86);
         }
         $img->saveAs($uploadDir . 'thumb_' . $this->getObject()->getSlug() . '.' . $image[1]);
         unlink($uploadDir . $image[0] . '.' . $image[1]);
         $this->getObject()->setPath($this->getObject()->getSlug() . '.' . $image[1]);
         $this->getObject()->save();
     }
     return $return;
 }
Beispiel #2
0
 public function save($conn = null)
 {
     parent::save();
     $BASE = sfConfig::get('sf_web_dir') . '/' . $this->WEB_IMAGE;
     $OC = $this->getObject();
     if ($OC instanceof Cicles) {
         $I = $OC->getImatge();
         if (!empty($I) && file_exists($BASE . $I)) {
             $img = new sfImage($BASE . $I, 'image/jpg');
             $img->resize(100, 100);
             $nom = $OC->getCicleid() . '.jpg';
             $img->saveAs($BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $I);
             }
             $OC->setImatge($nom)->save();
         }
         $P = $OC->getPdf();
         if (!empty($P) && file_exists($BASE . $P)) {
             $nom = $OC->getCicleid() . '.pdf';
             rename($BASE . $P, $BASE . $nom);
             if ($P != $nom) {
                 unlink($BASE . $P);
             }
             $OC->setPdf($nom)->save();
         }
     }
 }
 public function save($conn = null)
 {
     parent::save();
     $OR = $this->getObject();
     if (!is_null($this['Categories']->getValue())) {
         $OR->setCategories(implode('@', $this['Categories']->getValue()));
     }
     $BASE = sfConfig::get('sf_web_dir') . '/' . $this->WEB_IMATGE;
     if ($OR instanceof Activitats) {
         $I = $OR->getImatge();
         if (!empty($I) && file_exists($BASE . $I)) {
             $img = new sfImage($BASE . $I, 'image/jpg');
             $img->resize(150, 150);
             $nom = $OR->getActivitatid() . '.jpg';
             $img->saveAs($BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $I);
             }
             $OR->setImatge($nom);
         }
         $P = $OR->getPdf();
         if (!empty($P) && file_exists($BASE . $P)) {
             $nom = $OR->getActivitatid() . '.pdf';
             rename($BASE . $P, $BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $P);
             }
             $OR->setPdf($nom);
         }
     }
     $OR->save();
 }
Beispiel #4
0
 public function save($conn = null)
 {
     parent::save();
     $BASE = $this->URL_IMAGE;
     $ON = $this->getObject();
     if ($ON instanceof Noticies) {
         $I = $ON->getImatge();
         if (!empty($I) && file_exists($BASE . $I)) {
             $img = new sfImage($BASE . $I, 'image/jpg');
             $img->resize(100, 100);
             $nom = $ON->getIdnoticia() . '.jpg';
             $img->saveAs($BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $I);
             }
             $ON->setImatge($nom)->save();
         }
         $P = $ON->getAdjunt();
         if (!empty($P) && file_exists($BASE . $P)) {
             $nom = $ON->getIdnoticia() . '.pdf';
             rename($BASE . $P, $BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $P);
             }
             $ON->setAdjunt($nom)->save();
         }
     }
 }
Beispiel #5
0
 public function transform(sfImage $img)
 {
     $this->directory = dirname($img->getFilename());
     $arr = array_reverse(explode("/", $img->getFilename()));
     $this->fileName = $arr[0];
     $arr2 = explode(".", $this->fileName);
     if (count($arr2) == 1) {
         $this->fileName .= '.png';
     }
     $destDir = '/tmp';
     $ccFile = $destDir . DIRECTORY_SEPARATOR . 'cc_' . $this->fileName;
     $bwFile = $destDir . DIRECTORY_SEPARATOR . 'bw_' . $this->fileName;
     $ccSmallFile = $destDir . DIRECTORY_SEPARATOR . 'cc_s_' . $this->fileName;
     $bwSmallFile = $destDir . DIRECTORY_SEPARATOR . 'bw_s_' . $this->fileName;
     if (!file_exists($destDir)) {
         mkdir($destDir);
     }
     if ($img->getWidth() > IMG_MAX_WIDTH || $img->getHeight() > IMG_MAX_HEIGHT) {
         if ($img->getWidth() > $img->getHeight() * IMG_RATIO) {
             $img->resize(IMG_MAX_WIDTH, null);
         } else {
             $img->resize(null, IMG_MAX_HEIGHT);
         }
     }
     $img->saveAs($ccFile);
     $img->greyscale()->saveAs($bwFile);
     $smallImg = new sfImage($ccFile);
     if ($smallImg->getWidth() > IMG_SMALL_WIDTH || $smallImg->getHeight() > IMG_SMALL_WIDTH) {
         if ($smallImg->getWidth() > $img->getHeight() * IMG_RATIO) {
             $smallImg->resize(null, IMG_MAX_HEIGHT);
         } else {
             $smallImg->resize(IMG_MAX_WIDTH, null);
         }
     }
     if ($smallImg->getWidth() > IMG_SMALL_WIDTH || $smallImg->getHeight() > IMG_SMALL_HEIGHT) {
         if ($smallImg->getWidth() > $smallImg->getHeight() * IMG_RATIO) {
             $smallImg->resize(null, IMG_SMALL_HEIGHT);
         } else {
             $smallImg->resize(IMG_SMALL_WIDTH, null);
         }
     }
     $x1 = ($smallImg->getWidth() - IMG_SMALL_WIDTH) / 2;
     $y1 = ($smallImg->getHeight() - IMG_SMALL_HEIGHT) / 3;
     $smallImg->crop($x1, $y1, IMG_SMALL_WIDTH, IMG_SMALL_HEIGHT)->saveAs($ccSmallFile);
     $smallImg->greyscale()->saveAs($bwSmallFile);
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $x = $resource->getImageWidth();
     $y = $resource->getImageHeight();
     $image->resize(round($x * $this->scale), round($y * $this->scale));
     return $image;
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $x = imagesx($resource);
     $y = imagesy($resource);
     $image->resize(round($x * $this->scale), round($y * $this->scale));
     return $image;
 }
Beispiel #8
0
 public function save($conn = null)
 {
     $return = parent::save($conn);
     if ($this->getObject()->getPicture() != '') {
         $uploadDir = sfConfig::get('sf_upload_dir') . '/news/';
         $image = $this->getObject()->getPicture();
         $img = new sfImage($uploadDir . $image, swImageTransform::mime_content_type($uploadDir . $image));
         if ($img->getWidth() > $img->getHeight()) {
             $img->resize(480, null);
         } else {
             $img->resize(null, 360);
         }
         $img->setQuality(95);
         $img->save();
         $img->resize(180, 128)->saveAs($uploadDir . 'thumb_' . $image);
     }
     return $return;
 }
Beispiel #9
0
 public function save(Doctrine_Connection $conn = null)
 {
     $slug = Magic::slugify($this->getTitle());
     if ($this->isNew()) {
         $i = 0;
         do {
             $i++;
             $q = Doctrine::getTable('Event')->findOneBySlug($slug);
             if (!$q) {
                 break;
             } else {
                 $slug = Magic::slugify($this->getTitle());
                 $slug .= $i;
             }
         } while ($i);
         $this->setSlug($slug);
     } elseif ($slug != $this->getSlug()) {
         $i = 0;
         do {
             $i++;
             $q = Doctrine::getTable('Event')->findOneBySlug($slug);
             if (!$q) {
                 $this->setSlug($slug);
                 break;
             } else {
                 if ($slug == $this->getSlug()) {
                     break;
                 } else {
                     $slug = Magic::slugify($this->getTitle());
                     $slug .= $i;
                 }
             }
         } while ($i);
     }
     if ($this->get('sticky') == 'no') {
         $this->set('sticky', 1000);
     }
     parent::save($conn);
     $config = sfConfig::get('app_sfDoctrineJCroppablePlugin_models');
     $dir = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . $config['Events']['directory'];
     $image = $this->getImageSrc('mugshot', 'original');
     if ($this->getMugshot() != '') {
         $arr_filename = explode('.', $this->getMugshot());
         $filename = $arr_filename[0] . '_original.' . $arr_filename[1];
         $file = $dir . DIRECTORY_SEPARATOR . $filename;
         if (is_file($file)) {
             $dims = array(array('w' => 950, 'h' => 534), array('w' => 720, 'h' => 405), array('w' => 250, 'h' => 141));
             $size = getimagesize($file);
             $img = new sfImage($file, $size['mime']);
             foreach ($dims as $dim) {
                 $img->resize($dim['w'], $dim['h']);
                 $img->setQuality(90);
                 $img->saveAs($dir . '/' . $arr_filename[0] . '_' . $dim['w'] . 'x' . $dim['h'] . '.jpg');
             }
         }
     }
 }
Beispiel #10
0
 public function save($conn = null)
 {
     $return = parent::save($conn);
     if (!$this->isNew() and count($this->embeddedForms) != 0) {
         $uploadDir = sfConfig::get('sf_upload_dir') . '/gallery/';
         $image = $this->embeddedForms['photo']->getObject()->getPath();
         $img = new sfImage($uploadDir . $image, swImageTransform::mime_content_type($uploadDir . $image));
         if ($img->getWidth() > $img->getHeight()) {
             $img->resize(600, null);
         } else {
             $img->resize(null, 480);
         }
         $img->setQuality(95);
         $img->overlay(new sfImage(sfConfig::get('sf_web_dir') . '/images/marcadagua.png', 'image/png'), 'bottom-right');
         $img->save();
         $img->resize(null, 80)->saveAs($uploadDir . 'thumb_' . $image);
     }
     return $return;
 }
Beispiel #11
0
 public function save($conn = null)
 {
     $OPromocions = $this->getObject();
     PromocionsPeer::gestionaOrdre($this->getValue('Ordre'), $OPromocions->getOrdre(), $this->getOption('IDS'));
     parent::save();
     $nom = $OPromocions->getExtensio();
     if (!empty($nom)) {
         $img = new sfImage($this->URL . $nom, 'image/jpg');
         $img->resize(171, 63)->saveAs($this->URL . $nom);
     }
 }
 protected function saveFile($field, $filename = null, sfValidatedFile $file = null)
 {
     $file_saved = parent::saveFile($field, $filename = null, $file);
     // generate images ?
     if (sfConfig::get('app_sfMooDooGalleryPlugin_generate_images')) {
         $sizes = sfConfig::get('app_sfMooDooGalleryPlugin_image_size');
         $name = explode('.', $file_saved);
         foreach ($sizes as $size) {
             $image_name = sfConfig::get('app_sfMooDooGalleryPlugin_images_dir') . DIRECTORY_SEPARATOR . $name[0] . '_' . $size['width'] . 'x' . $size['height'] . $file->getExtension();
             $img = new sfImage($file, $file->getType());
             $img->resize($size['width'], $size['height']);
             $img->saveAs($image_name);
         }
     }
     return $file_saved;
 }
Beispiel #13
0
 public function save($conn = null)
 {
     parent::save();
     $OS = $this->getObject();
     $BASE = $this->BASE . $this->WEB_IMATGE;
     if ($OS instanceof Sites) {
         $I = $OS->getLogourl();
         if (!empty($I) && file_exists($BASE . $I)) {
             $img = new sfImage($BASE . $I, 'image/jpg');
             $img->resize(150, 150);
             $nom = $OS->getSiteId() . '.jpg';
             $img->saveAs($BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $I);
             }
             $OS->setLogourl($nom);
         }
     }
     $OS->save();
 }
/**
 * fetch today's news regarding objects monitored by the user
 *
 * @param string $user - OppUser object
 * @return void
 * @author Guglielmo Celata
 */
function opp_sync_politician_image($pol)
{
    $start_time = microtime(true);
    $success = true;
    echo pakeColor::colorize(sprintf('Processing politician %s...', $pol), array('fg' => 'red', 'bold' => true));
    // invoke the remote getPolImage function to grab the images from op_openpolis
    $remote_img_url = sfConfig::get('app_remote_politicians_images_service_url') . '/' . sfConfig::get('app_remote_openpolis_api_key') . '/' . $pol->getId();
    /* debug
      echo pakeColor::colorize(sprintf('Url:  %s...', $remote_img_url), 
                              array('fg' => 'red', 'bold' => true));
      */
    $file = fopen($remote_img_url, "r");
    if (!$file) {
        $err = "unable to open remote file.";
        $success = false;
    }
    $remote_img_str = '';
    while (!feof($file)) {
        $remote_img_str .= fgets($file, 1024);
    }
    fclose($file);
    $images_root = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'web' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'parlamentari' . DIRECTORY_SEPARATOR;
    // resizes images and stores them in the FS
    $picture = new sfImage();
    $picture->setMimeType('image/jpeg');
    $picture->loadString($remote_img_str);
    $picture->resize(91, null);
    $picture->saveAs($images_root . 'picture/' . $pol->getId() . '.jpeg', 'image/jpeg');
    $thumb = new sfImage();
    $thumb->setMimeType('image/jpeg');
    $thumb->loadString($remote_img_str);
    $thumb->resize(40, null);
    $thumb->saveAs($images_root . 'thumb/' . $pol->getId() . '.jpeg', 'image/jpeg');
    $execution_time = microtime(true) - $start_time;
    if ($success) {
        echo " ok (";
    } else {
        echo " {$err} (";
    }
    echo pakeColor::colorize(sprintf("%f", $execution_time), array('fg' => 'cyan'));
    echo ")\n";
}
 /**
  * Apply the transformation to the image and returns the image thumbnail
  */
 protected function transform(sfImage $image)
 {
     $resource_w = $image->getWidth();
     $resource_h = $image->getHeight();
     $scale_w = $this->getWidth() / $resource_w;
     $scale_h = $this->getHeight() / $resource_h;
     $ratio_w = $resource_w / $this->getWidth();
     $ratio_h = $resource_w / $this->getHeight();
     switch ($this->getMethod()) {
         case 'deflate':
         case 'inflate':
             return $image->resize($this->getWidth(), $this->getHeight());
         case 'west':
             $image->scale(max($scale_w, $scale_h));
             return $image->crop($this->getWidth(), $this->getHeight(), 0, 0);
         case 'east':
             $image->scale(max($scale_w, $scale_h));
             return $image->crop($this->getWidth(), $this->getHeight(), (int) ($image->getWidth() - $this->getWidth()), 0);
         case 'north':
             $image->scale(max($scale_w, $scale_h));
             return $image->crop($this->getWidth(), $this->getHeight(), 0, 0);
         case 'south':
             $image->scale(max($scale_w, $scale_h));
             return $image->crop($this->getWidth(), $this->getHeight(), 0, $image->getHeight() - $this->getHeight());
         case 'center':
             $image->scale(max($scale_w, $scale_h));
             $left = (int) round(($image->getWidth() - $this->getWidth()) / 2);
             $top = (int) round(($image->getHeight() - $this->getHeight()) / 2);
             return $image->crop($this->getWidth(), $this->getHeight(), $left, $top);
         case 'scale':
         default:
             return $image->scale(min($scale_w, $scale_h));
     }
 }
Beispiel #16
0
 /**
  * myUser::resizeImage()
  * 
  * Funció estàtica que canvia la mida d'una imatge carregada amb un input file. 
  *  
  * @param mixed $x
  * @param mixed $y
  * @param mixed $BASE
  * @param mixed $imatge_actual
  * @param mixed $new_name
  * @param mixed $borrar
  * @return
  */
 public static function resizeImage($x, $y, $BASE, $imatge_actual, $new_name, $borrar)
 {
     if (!empty($imatge_actual) && file_exists($BASE . $imatge_actual)) {
         $img = new sfImage($BASE . $imatge_actual, 'image/jpg');
         $img->resize($x, $y);
         $nomf = $new_name . '.jpg';
         $img->saveAs($BASE . $nomf);
         if ($imatge_actual != $new_name && $borrar) {
             unlink($BASE . $imatge_actual);
         }
         return $nomf;
     }
     return false;
 }
Beispiel #17
0
/** 
 * -------------------------------------------- AVEC WATERMARK --------------------------------------------
 * 
 * Cette function utilise la précédente afin d'afficher directement l'image avec les balises et les options.
 * @param <string> $image_name : le nom de l’image donc généralement le $object->getImage(), pas de répertoire
 * @param <string> $folder : le nom du répertoire dans "uploads" où est stocké l’image 
 * @param <array> $options : les options contenus dans un array() : la taille de l’image (width et height) + la classe, l'id, le alt ... de l'image
 * @param <string> $resize : "scale" pour garder les proportions (deformation de l'image) OU "center" pour tronquer l’image sans la deformer)
 * @param <string> $default : l’image par défaut si $image_name n’existe pas
 * @param <string> $watermark : l'image représentant le watermark à placer dans le dossier "/images"
 * @param <string> $position : la position du watermark sur l'image (format : [de haut en bas]-[de gauche a droite]) : Pour [de haut en bas] : top, middle, bottom / Pour [de gauche à droite] : left, center, right
 * @return <image_path>
 */
function doThumb_resize_watermark($image_name, $folder, $options = array(), $resize = 'center', $default = 'default.jpg', $watermark = 'images/watermark.png', $position = 'middle-center')
{
    $source_dir = 'uploads/' . $folder . '/';
    $thumb_dir = 'uploads/' . $folder . '/thumb/';
    $source = $source_dir . $image_name;
    $exist = sfConfig::get('sf_web_dir') . '/' . $source;
    if (!is_file($exist)) {
        $image_name = $default;
        $source = 'images/' . $image_name;
    }
    //$new_name = $options['width'].'x'.$options['height'].'_'.$image_name;
    $new_name = $options['width'] . '_' . $image_name;
    $new_img = $thumb_dir . $new_name;
    // si le thumb n'existe pas ou s'il est plus ancien que le fichier source, alors on regénére le thumb
    if (!is_file(sfConfig::get('sf_web_dir') . '/' . $new_img) or filemtime($source) > filemtime($new_img)) {
        $img = new sfImage($source);
        $img->setQuality(100);
        $img->resize($options['width'], $options['height'])->overlay(new sfImage($watermark), $position)->saveAs($new_img);
    }
    return image_path('/' . $new_img);
}
 /**
  * Apply the transformation to the image and returns the image thumbnail
  */
 protected function transform(sfImage $image)
 {
     $resource_w = $image->getWidth();
     $resource_h = $image->getHeight();
     $scale_w = $this->getWidth() / $resource_w;
     $scale_h = $this->getHeight() / $resource_h;
     switch ($this->getMethod()) {
         case 'deflate':
         case 'inflate':
             return $image->resize($this->getWidth(), $this->getHeight());
         case 'left':
             $image->scale(max($scale_w, $scale_h));
             return $image->crop(0, (int) round(($image->getHeight() - $this->getHeight()) / 2), $this->getWidth(), $this->getHeight());
         case 'right':
             $image->scale(max($scale_w, $scale_h));
             return $image->crop($image->getWidth() - $this->getWidth(), (int) round(($image->getHeight() - $this->getHeight()) / 2), $this->getWidth(), $this->getHeight());
         case 'top':
             $image->scale(max($scale_w, $scale_h));
             return $image->crop((int) round(($image->getWidth() - $this->getWidth()) / 2), 0, $this->getWidth(), $this->getHeight());
         case 'bottom':
             $image->scale(max($scale_w, $scale_h));
             return $image->crop((int) round(($image->getWidth() - $this->getWidth()) / 2), $image->getHeight() - $this->getHeight(), $this->getWidth(), $this->getHeight());
         case 'center':
             $image->scale(max($scale_w, $scale_h));
             $left = (int) round(($image->getWidth() - $this->getWidth()) / 2);
             $top = (int) round(($image->getHeight() - $this->getHeight()) / 2);
             return $image->crop($left, $top, $this->getWidth(), $this->getHeight());
         case 'scale':
             return $image->scale(min($scale_w, $scale_h));
         case 'fit':
         default:
             $img = clone $image;
             $image->create($this->getWidth(), $this->getHeight());
             // Set a background color if specified
             if (!is_null($this->getBackground()) && $this->getBackground() != '') {
                 $image->fill(0, 0, $this->getBackground());
             }
             $img->scale(min($this->getWidth() / $img->getWidth(), $this->getHeight() / $img->getHeight()));
             $image->overlay($img, 'center');
             return $image;
     }
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $image->resize($this->getWidth(), $this->getHeight());
     $resource->roundCorners($this->getRadius(), $this->getRadius());
     $shadow = $resource->clone();
     $shadow->setImageBackgroundColor(new ImagickPixel('black'));
     $shadow->shadowImage(80, 3, 5, 5);
     $shadow->compositeImage($resource, Imagick::COMPOSITE_OVER, 0, 0);
     return $image;
 }
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeNoticiesculturals(sfWebRequest $request)
 {
     $this->IDS = 1;
     $this->PAGE_ID_QUE_ESTA_PASSANT = 1;
     $this->PAGE_ID_QUE_PASSARA = 2;
     $this->PAGE_ID_QUE_HA_PASSAT = 3;
     $this->FORM_ID = 2;
     $this->BLOG_ID = 4;
     $this->setLayout('blank');
     $this->PAGE_ID = $this->ParReqSesForm($request, 'PAGE_ID', $this->PAGE_ID_QUE_ESTA_PASSANT);
     $this->NOTICIA_ID = $this->ParReqSesForm($request, 'NOTICIA_ID', -1);
     $this->PAGINA = $request->getParameter('PAGINA', 1);
     $this->MODE = $this->ParReqSesForm($request, 'MODE', 'CONTINGUT');
     $this->ERRORS = "";
     if ($this->MODE == 'CONTINGUT' && $request->hasParameter('NOTICIA_ID')) {
         $this->NOTICIA = AppBlogsEntriesPeer::retrieveByPK($request->getParameter('NOTICIA_ID'));
         $this->MODE = 'CONTINGUT';
     } elseif ($this->MODE == 'CONTINGUT') {
         $order = $this->PAGE_ID == $this->PAGE_ID_QUE_HA_PASSAT ? false : true;
         $this->NOTICIES = AppBlogsEntriesPeer::getEntries($this->PAGE_ID, $this->PAGINA, $order, $this->IDS);
         $this->MODE = 'CONTINGUT';
     } elseif ($this->MODE == 'FORM1') {
         $this->FORM1 = array('nom_entitat' => '', 'nom_cognoms' => '', 'lloc_ocupa' => '', 'nom_cognoms_contacte' => '', 'adreca' => '', 'codi_postal' => '', 'municipi' => '', 'comarca' => '', 'telefons' => '', 'email' => '');
     } elseif ($this->MODE == 'FORM2') {
         $this->DADES = $request->getParameter('dades');
         $this->getUser()->setAttribute('dades', $this->DADES);
         $this->FORM2 = array('titol' => '', 'subtitol1' => '', 'ciutat_acte' => '', 'dia_acte' => '', 'web' => '', 'imatge' => '', 'tipus' => '', 'resum' => '');
     } elseif ($this->MODE == 'ENVIA_FINALITZA') {
         if (!$this->getUser()->hasAttribute('dades')) {
             $this->redirect('@noticies_culturals?MODE=FORM1');
         }
         $this->getUser()->setAttribute('dades2', $request->getParameter('dades'));
         $this->DADES = $this->getUser()->getAttribute('dades');
         $this->DADES2 = $this->getUser()->getAttribute('dades2');
         foreach ($this->DADES2 as $K => $E) {
             $this->DADES[$K] = $E;
         }
         AppBlogsFormsPeer::save($this->FORM_ID, $this->DADES, $request->getFiles(), $this->IDS);
         $this->MODE = 'FORM_OK';
     } elseif ($this->MODE == 'ACTUALITZA') {
         $next_two_month = date('Y-m-d', mktime(0, 0, 0, date('m', time()) + 2, date('d', time()), date('Y', time())));
         $next_month = date('Y-m-d', mktime(0, 0, 0, date('m', time()) + 1, date('d', time()), date('Y', time())));
         $today = date('Y-m-d', time());
         $previous_month = date('Y-m-d', mktime(0, 0, 0, date('m', time()) - 1, date('d', time()), date('Y', time())));
         $previous_two_month = date('Y-m-d', mktime(0, 0, 0, date('m', time()) - 2, date('d', time()), date('Y', time())));
         //Captem els que s'han de migrar del formulari
         $C = new Criteria();
         $C = AppBlogsFormsEntriesPeer::getCriteriaActiu($C, $this->IDS);
         $C->add(AppBlogsFormsEntriesPeer::FORM_ID, $this->FORM_ID);
         $C->add(AppBlogsFormsEntriesPeer::ESTAT, AppBlogsFormsEntriesPeer::ESTAT_TRACTAT_MIGRAT_WAIT);
         //Treballem i migrem els camps que hem marcat com "Per publicar"
         foreach (AppBlogsFormsEntriesPeer::doSelect($C) as $OO) {
             $RET = array();
             foreach (explode("@@@", $OO->getDades()) as $E) {
                 $EX = explode("###", $E);
                 if (isset($EX[0]) && isset($EX[1])) {
                     list($EXCAMP, $TEXT) = explode("###", $E);
                     $RET[$EX[0]] = $EX[1];
                 }
             }
             try {
                 $ON = AppBlogsEntriesPeer::initialize(0, 'CA', 1, 1, $this->IDS)->getObject();
                 $ON->setTitle($RET['titol']);
                 $ON->setSubtitle1($RET['subtitol1']);
                 $ON->setSubtitle2($RET['ciutat_acte'] . ', ' . $this->dataText($RET['dia_acte']));
                 $ON->setBody($RET['text']);
                 $ON->setTags($RET['tipus']);
                 echo stripos($RET['web'], 'http://');
                 if (!stripos($RET['web'], 'http://')) {
                     $ON->setUrl('http://' . $RET['web']);
                 } else {
                     $ON->setUrl($RET['web']);
                 }
                 $ON->setDate($RET['dia_acte']);
                 $dia = $RET['dia_acte'];
                 if ($dia >= $today && $dia < $next_month) {
                     $ON->setPageId($this->PAGE_ID_QUE_ESTA_PASSANT);
                 } elseif ($dia < $today) {
                     $ON->setPageId($this->PAGE_ID_QUE_HA_PASSAT);
                 } elseif ($dia > $next_month) {
                     $ON->setPageId($this->PAGE_ID_QUE_PASSARA);
                 }
                 $ON->save();
                 //Guardem la notícia
                 //Guardem les imatges
                 if (isset($RET['file'])) {
                     $WEBSYSROOT = OptionsPeer::getString('SF_WEBSYSROOT', $this->IDS);
                     //Mirem l'extensió de l'arxiu
                     $path_info = pathinfo($WEBSYSROOT . 'uploads/formularis/' . $RET['file']);
                     //Si l'arxiu és una imatge, el tractem i el posem com a imatge
                     if (strtolower($path_info['extension']) == 'jpg' || strtolower($path_info['extension']) == 'png') {
                         try {
                             $img = new sfImage($WEBSYSROOT . 'uploads/formularis/' . $RET['file'], 'image/jpeg');
                             $img->resize(200, null);
                             $img->saveAs($WEBSYSROOT . 'images/blogs/' . $RET['file']);
                             $OM = AppBlogsMultimediaPeer::initialize(0, $this->IDS)->getObject();
                             $OM->setName($RET['file']);
                             $OM->setUrl($RET['file']);
                             $OM->save();
                             echo 'ONID:' . $ON->getId();
                             $OME = AppBlogMultimediaEntriesPeer::initialize($ON->getId(), $OM->getId(), $this->IDS)->getObject()->save();
                         } catch (Exception $e) {
                             echo 'hail';
                             echo $e->getMessage();
                             echo $e->getCode();
                         }
                     }
                 }
                 $OO->setEstat(AppBlogsFormsEntriesPeer::ESTAT_TRACTAT_MIGRAT);
                 $OO->save();
             } catch (Exception $e) {
                 echo 'fiodaf';
                 echo $e->getMessage();
                 echo $e->getCode();
             }
         }
         /**
          * Captem els valors que han estat marcats com "Per arxivar" i els passem a "arxivats"
          */
         $C = new Criteria();
         $C = AppBlogsEntriesPeer::getCriteriaActiu($C, $this->IDS);
         $C->add(AppBlogsFormsEntriesPeer::FORM_ID, $this->FORM_ID);
         $C->add(AppBlogsFormsEntriesPeer::ESTAT, AppBlogsFormsEntriesPeer::ESTAT_TRACTAT_EMMAGATZEMAT_WAIT);
         foreach (AppBlogsFormsEntriesPeer::doSelect($C) as $OO) {
             $OO->setEstat(AppBlogsFormsEntriesPeer::ESTAT_TRACTAT_EMMAGATZEMAT);
             $OO->save();
         }
         /**
          * Procès de canvi de lloc les notícies que ja han passat a una altra pàgina
          */
         //Captem les notícies que han de canviar de pàgina... (Actual->Passades)
         $C = new Criteria();
         $C = AppBlogsEntriesPeer::getCriteriaActiu($C, $this->IDS);
         $C->add(AppBlogsEntriesPeer::PAGE_ID, $this->PAGE_ID_QUE_ESTA_PASSANT);
         $C->add(AppBlogsEntriesPeer::DATE, $today, CRITERIA::LESS_THAN);
         foreach (AppBlogsEntriesPeer::doSelect($C) as $OO) {
             $OO->setPageid($this->PAGE_ID_QUE_HA_PASSAT);
             $OO->save();
         }
         //Captem les notícies que han de canviar de pàgina... (Futures->actual)
         $C = new Criteria();
         $C = AppBlogsEntriesPeer::getCriteriaActiu($C, $this->IDS);
         $C->add(AppBlogsEntriesPeer::PAGE_ID, $this->PAGE_ID_QUE_PASSARA);
         $C->add(AppBlogsEntriesPeer::DATE, $today, CRITERIA::GREATER_THAN);
         $C->add(AppBlogsEntriesPeer::DATE, $next_month, CRITERIA::LESS_THAN);
         foreach (AppBlogsEntriesPeer::doSelect($C) as $OO) {
             $OO->setPageid($this->PAGE_ID_QUE_ESTA_PASSANT);
             $OO->save();
         }
         //  		$this->redirect('blogs/noticiesculturals?MODE=CONTINGUT&PAGE_ID='.$this->PAGE_ID_QUE_ESTA_PASSANT);
     }
 }