Example #1
0
 public function addMenuItem($fileName, $menuItem, $baseDir)
 {
     $absolutePath = $baseDir . '/../../../../web/uploads/images/menu/' . $menuItem->getId() . '/' . $fileName;
     $image = new Image();
     $image->setPath($fileName);
     $filename = $baseDir . '/../../Resources/public/images/' . $fileName;
     $this->createPath($baseDir . '/../../../../web/uploads/images/menu/' . $menuItem->getId());
     $this->createPath($baseDir . '/../../../../web/uploads/images/menu/' . $menuItem->getId() . '/thumbnail');
     copy($filename, $absolutePath);
     $menuItem->setImage($image);
     $this->getManager()->persist($image);
     $arr = array();
     if (preg_match('/\\.jpeg/', $fileName)) {
         $arr = explode('.jpeg', $fileName);
     }
     if (preg_match('/\\.jpg/', $fileName)) {
         $arr = explode('.jpg', $fileName);
     }
     $img_name = $arr[0];
     $this->resizeImage($absolutePath, $img_name . '_380', 380, 180, __DIR__ . '/../../../../../web/uploads/images/menu/' . $menuItem->getId() . '/');
     $this->resizeImage($absolutePath, $img_name . '_260', 260, 123, __DIR__ . '/../../../../../web/uploads/images/menu/' . $menuItem->getId() . '/');
     $this->resizeImage($absolutePath, $img_name . '_142', 142, 88, __DIR__ . '/../../../../../web/uploads/images/menu/' . $menuItem->getId() . '/');
     $this->resizeImage($absolutePath, $img_name . '_150', 150, 150, __DIR__ . '/../../../../../web/uploads/images/menu/' . $menuItem->getId() . '/');
 }
Example #2
0
 public function updateOAuthData($user, $oauthData)
 {
     $profileImage = null;
     if (isset($oauthData['profileImage']) && $oauthData['owner'] == 'twitter' && strpos($oauthData['profileImage'], '_normal') > 0) {
         $profileImage = str_replace('_normal', '', $oauthData['profileImage']);
     }
     if ($oauthData['owner'] == 'facebook') {
         $profileImage = $this->getFacebookImage($oauthData['id']);
     }
     if (isset($oauthData['profileImage']) && $oauthData['owner'] == 'google') {
         $profileImage = $oauthData['profileImage'];
     }
     if (!is_null($profileImage)) {
         //save image
         $arr = explode('/', $profileImage);
         $ext = explode('.', parse_url($arr[count($arr) - 1], PHP_URL_PATH));
         @mkdir(__DIR__ . '/../../../../../web/uploads/images/profile/' . $user->getId());
         $imageName = md5(uniqid()) . '.' . $ext[1];
         $img = __DIR__ . '/../../../../../web/uploads/images/profile/' . $user->getId() . '/' . $imageName;
         file_put_contents($img, file_get_contents($profileImage));
         $image = new Image();
         $image->setPath($imageName);
         $user->setImage($image);
         $this->em->persist($image);
     }
     if (isset($oauthData['name'])) {
         $user->setName($oauthData['name']);
     }
     $this->em->flush();
     return true;
 }
Example #3
0
 public function importProducts(Import $entity, $output)
 {
     $sql = ' SELECT p.*, o.nombre as opticName, m.nombre as brand, mo.nombre as model, s.nombre as category FROM  `producto` AS p ' . ' LEFT JOIN optica AS o ON o.id = p.id_optica ' . ' LEFT JOIN servicio AS s ON s.id = p.id_servicio ' . ' LEFT JOIN marca AS m ON m.id_marca = p.id_marca ' . ' LEFT JOIN modelo AS mo ON mo.id_modelo = p.id_modelo ' . ' ORDER BY p.id ' . ' LIMIT ' . $entity->getLimitStart() . ', ' . $entity->getLimitEnd();
     $link = mysqli_connect($entity->getServer(), $entity->getUsername(), $entity->getPassword(), $entity->getDbname()) or die('No se pudo conectar: ' . mysqli_error($link));
     $resultado = $link->query($sql);
     $x = 0;
     if (mysqli_num_rows($resultado) > 0) {
         while ($fila = mysqli_fetch_assoc($resultado)) {
             $x++;
             print_r($x . '-' . utf8_encode($fila['nombre']));
             echo PHP_EOL;
             $em = $this->container->get('doctrine')->getManager();
             $optic = $em->getRepository('CoreBundle:Optic')->findOneByName(utf8_encode($fila['opticName']));
             $category = $em->getRepository('EcommerceBundle:Category')->findOneByName(utf8_encode($fila['category']));
             $brand = $em->getRepository('EcommerceBundle:Brand')->findOneByName(utf8_encode($fila['brand']));
             $model = $em->getRepository('EcommerceBundle:BrandModel')->findOneByName(utf8_encode($fila['model']));
             //Create Products
             if ($optic instanceof Optic && $fila['id'] != 746 && $fila['id'] != 747 && $fila['id'] != 748 && $fila['id'] != 749 && $fila['id'] != 750 && $fila['id'] != 751 && $fila['id'] != 752 && $fila['id'] != 753) {
                 $product = new Product();
                 $product->setName(utf8_encode($fila['nombre']));
                 $product->setDescription(utf8_encode($fila['descripcion']));
                 if ($fila['precio_original'] != '') {
                     $product->setInitPrice($fila['precio_original']);
                 } else {
                     $product->setInitPrice(0);
                 }
                 $product->setPrice($fila['precio']);
                 if ($fila['tipo_precio'] != '') {
                     $product->setPriceType($fila['tipo_precio']);
                 } else {
                     $product->setPriceType(0);
                 }
                 $product->setDiscount($fila['descuento']);
                 $product->setDiscountType($fila['tipo_descuento']);
                 if ($fila['stock'] != '') {
                     $product->setStock($fila['stock']);
                 } else {
                     $product->setStock(0);
                 }
                 $product->setWeight($fila['kilos']);
                 $product->setOutlet($fila['outlet']);
                 $product->setPublic($fila['publicado']);
                 if ($fila['recoger_tienda'] != '') {
                     $product->setStorePickup($fila['recoger_tienda']);
                 } else {
                     $product->setStorePickup(0);
                 }
                 $product->setMetaTitle(utf8_encode($fila['meta_titulo']));
                 $product->setMetaDescription(utf8_encode($fila['meta_descripcion']));
                 $product->setMetaTags(utf8_encode($fila['meta_keywords']));
                 $product->setOptic($optic);
                 $product->setBrand($brand);
                 $product->setModel($model);
                 $product->setCategory($category);
                 $product->setActive(true);
                 $product->setAvailable(true);
                 $product->setHighlighted(false);
                 $product->setFreeTransport(false);
                 $slug = $this->slugify(utf8_encode($fila['nombre'] . '-' . $optic->getCity()));
                 //                    $p = $em->getRepository('EcommerceBundle:Product')->findOneBySlug($slug);
                 //                    if($p instanceof Product) $slug = $slug.'_'.rand(1000,9999);
                 $product->setSlug($slug);
                 $em->persist($product);
                 $em->flush();
                 //image
                 if ($fila['imagen'] != '') {
                     $imagePath = '';
                     $dir = '/home/sebastian/www/src/Symfony/web/uploads/documents';
                     $absoluteImagePath = $dir . '/' . utf8_encode($fila['imagen']);
                     if (file_exists($absoluteImagePath . '.jpeg')) {
                         $imagePath = utf8_encode($fila['imagen']) . '.jpeg';
                     }
                     if (file_exists($absoluteImagePath . '.jpg')) {
                         $imagePath = utf8_encode($fila['imagen']) . '.jpg';
                     }
                     if (file_exists($absoluteImagePath . '.gif')) {
                         $imagePath = utf8_encode($fila['imagen']) . '.gif';
                     }
                     if (file_exists($absoluteImagePath . '.png')) {
                         $imagePath = utf8_encode($fila['imagen']) . '.png';
                     }
                     //Thumb
                     $imagePathThumb = '';
                     $absoluteImagePathThumb = $dir . '/' . utf8_encode($fila['imagen']) . '_260.jpg';
                     if (file_exists($absoluteImagePathThumb)) {
                         $imagePathThumb = utf8_encode($fila['imagen']) . '_260.jpg';
                     }
                     $imagePathThumb2 = '';
                     $absoluteImagePathThumb2 = $dir . '/' . utf8_encode($fila['imagen']) . '_142.jpg';
                     if (file_exists($absoluteImagePathThumb2)) {
                         $imagePathThumb2 = utf8_encode($fila['imagen']) . '_142.jpg';
                     }
                     if ($imagePath == '') {
                         $dir = 'http://web.com/uploads/documents/';
                         $imagePath = $fila['imagen'] . '.' . $fila['extension_img'];
                     }
                     print_r($dir . '/' . $imagePath);
                     echo PHP_EOL;
                     @mkdir(__DIR__ . '/../../../../../web/uploads/images/product');
                     @mkdir(__DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId());
                     @mkdir(__DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/thumbnail');
                     copy($dir . '/' . $imagePath, __DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/' . $imagePath);
                     if ($imagePathThumb != '') {
                         copy($dir . '/' . $imagePathThumb, __DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/thumbnail/' . $imagePathThumb);
                     }
                     if ($imagePathThumb2 != '') {
                         copy($dir . '/' . $imagePathThumb2, __DIR__ . '/../../../../../web/uploads/images/product/' . $product->getId() . '/thumbnail/' . $imagePathThumb2);
                     }
                     $image0 = new Image();
                     $image0->setPath($imagePath);
                     $product->addImage($image0);
                     $em->persist($image0);
                 }
                 $em->flush();
             }
         }
     }
 }
Example #4
0
 /**
  * Post method
  *
  * @param bool $printResponse
  *
  * @throws NotFoundHttpException
  * @return mixed
  */
 public function post($printResponse = true)
 {
     if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
         return $this->delete($printResponse);
     }
     $upload = isset($_FILES[$this->options['param_name']]) ? $_FILES[$this->options['param_name']] : null;
     // Parse the Content-Disposition header, if available:
     /*$fileName = $this->get_server_var('HTTP_CONTENT_DISPOSITION') ?
       rawurldecode(preg_replace(
           '/(^[^"]+")|("$)/',
           '',
           $this->get_server_var('HTTP_CONTENT_DISPOSITION')
       )) : null;*/
     $fileName = $this->options['entity_slug'] . '-' . md5(uniqid());
     // Parse the Content-Range header, which has the following form:
     // Content-Range: bytes 0-524287/2000000
     $contentRange = $this->get_server_var('HTTP_CONTENT_RANGE') ? preg_split('/[^0-9]+/', $this->get_server_var('HTTP_CONTENT_RANGE')) : null;
     $size = $contentRange ? $contentRange[3] : null;
     $files = array();
     if ($upload && is_array($upload['tmp_name'])) {
         /** @var Product $entity */
         $entity = $this->entityManager->getRepository($this->options['entity_path'])->find($this->options['entity_id']);
         if (!$entity) {
             throw new NotFoundHttpException('Unable to find entity.');
         }
         // param_name is an array identifier like "files[]",
         // $_FILES is a multi-dimensional array:
         foreach ($upload['tmp_name'] as $index => $value) {
             $files[] = $this->handle_file_upload($upload['tmp_name'][$index], $fileName ? $fileName : $upload['name'][$index], $size ? $size : $upload['size'][$index], $upload['type'][$index], $upload['error'][$index], $index, $contentRange);
             // save the file name in the database
             /** @var Image $image */
             if ($this->options['entity_path'] == 'BlogBundle:Post') {
                 $image = new PostImage();
             } elseif ($this->options['entity_path'] == 'EcommerceBundle:Product') {
                 $image = new ProductImage();
             }
             $image->setPath('/uploads/images/' . $this->options['type'] . '/' . $entity->getId() . '/' . $files[$index]->name);
             $this->entityManager->persist($image);
             $entity->addImage($image);
             //add crop center thumbmail image
             // '260'=>array('w'=>260,'h'=>123),
             // '160'=>array('w'=>160,'h'=>100),
             // '104'=>array('w'=>104,'h'=>56),
             // '142'=>array('w'=>142,'h'=>88)
             //create source image
             if (isset($upload['type'][0]) && isset($upload['name'][0])) {
                 $extension = $upload['type'][0];
                 $arr = array();
                 if ($extension == 'image/jpeg') {
                     $source = imagecreatefromjpeg($this->options['upload_dir'] . $files[$index]->name);
                     if (preg_match('/\\.jpeg/', $files[$index]->name)) {
                         $arr = explode('.jpeg', $files[$index]->name);
                     }
                     if (preg_match('/\\.jpg/', $files[$index]->name)) {
                         $arr = explode('.jpg', $files[$index]->name);
                     }
                     $img_name = $arr[0];
                 } else {
                     if ($extension == 'image/gif') {
                         $source = imagecreatefromgif($this->options['upload_dir'] . $files[$index]->name);
                         if (preg_match('/\\.gif/', $files[$index]->name)) {
                             $arr = explode('.gif', $files[$index]->name);
                         }
                         $img_name = $arr[0];
                     } else {
                         if ($extension == 'image/png') {
                             $source = imagecreatefrompng($this->options['upload_dir'] . $files[$index]->name);
                             if (preg_match('/\\.png/', $files[$index]->name)) {
                                 $arr = explode('.png', $files[$index]->name);
                             }
                             $img_name = $arr[0];
                         }
                     }
                 }
                 $this->resizeImage($source, $img_name . '_400', 400, 250);
                 $this->resizeImage($source, $img_name . '_380', 380, 180);
                 $this->resizeImage($source, $img_name . '_260', 260, 123);
                 $this->resizeImage($source, $img_name . '_142', 142, 88);
             }
         }
         $this->entityManager->persist($entity);
         $this->entityManager->flush();
     } else {
         // param_name is a single object identifier like "file",
         // $_FILES is a one-dimensional array:
         $files[] = $this->handle_file_upload(isset($upload['tmp_name']) ? $upload['tmp_name'] : null, $fileName ? $fileName : (isset($upload['name']) ? $upload['name'] : null), $size ? $size : (isset($upload['size']) ? $upload['size'] : $this->get_server_var('CONTENT_LENGTH')), isset($upload['type']) ? $upload['type'] : $this->get_server_var('CONTENT_TYPE'), isset($upload['error']) ? $upload['error'] : null, null, $contentRange);
     }
     return $this->generate_response(array($this->options['param_name'] => $files), $printResponse);
 }
Example #5
0
 /**
  * Upload profile image
  * @Route("/user/{id}/upload", name="upload_profile_image", defaults={"_format" = "json"})
  */
 public function uploadProfileImage(Request $request, $id)
 {
     if (!$id) {
         throw $this->createNotFoundException('Unable to upload.');
     }
     if ($id != $this->get('security.token_storage')->getToken()->getUser()->getId()) {
         throw $this->createNotFoundException('Can not upload anything to a profile that is not their own.');
     }
     $em = $this->container->get('doctrine')->getManager();
     $entity = $this->get('security.token_storage')->getToken()->getUser();
     if ($request->files->get('file') instanceof UploadedFile) {
         $imagePath = $this->get('core_manager')->uploadProfileImagePost($request->files->get('file'), $entity);
         $img = new Image();
         $img->setPath($imagePath);
         $em->persist($img);
         $entity->setImage($img);
         $em->flush();
     }
     return new JsonResponse($imagePath);
 }
Example #6
0
 public function createSliderFixtures()
 {
     $core = $this->container->getParameter('core');
     $server_base_url = $core['server_base_url'];
     //Create Item
     $slider = new Slider();
     //        $slider->setTitle('Proyecto Nº1 ciencia');
     //        $slider->setCaption('Quisque venenatis et orci non pretium. Nunc pellentesque suscipit lorem, non volutpat ex mattis id. Vivamus dictum dolor metus. Aliquam erat volutpat.');
     $slider->setActive(true);
     $slider->setOpenInNewWindow(true);
     $slider->setUrl('http://local.com');
     $slider->setOrder(0);
     $this->getManager()->persist($slider);
     $slider2 = new Slider();
     //        $slider2->setTitle('Proyecto Nº1 biologia');
     //        $slider2->setCaption(' Nunc pellentesque suscipit lorem, non volutpat ex mattis id. Vivamus dictum dolor metus. Aliquam erat volutpat. Nunc pellentesque suscipit lorem, non volutpat ex mattis id. Vivamus dictum dolor metus. Aliquam erat volutpat. ');
     $slider2->setActive(true);
     $slider2->setOpenInNewWindow(true);
     $slider2->setUrl('http://www.google.com');
     $slider2->setOrder(1);
     $this->getManager()->persist($slider2);
     //
     //
     //        $slider3  = new Slider();
     //        $slider3->setTitle('Proyecto Nº2 biologia');
     //        $slider3->setCaption(' Nunc pellentesque suscipit lorem, non volutpat ex mattis id. Vivamus dictum dolor metus. Aliquam erat volutpat. Nunc pellentesque suscipit lorem, non volutpat ex mattis id. Vivamus dictum dolor metus. Aliquam erat volutpat. ');
     //        $slider3->setActive(true);
     //        $slider3->setOpenInNewWindow(false);
     //        $slider3->setUrl($server_base_url.'/quienes-somos');
     //        $slider3->setOrder(2);
     //        $this->getManager()->persist($slider3);
     $this->getManager()->flush();
     //Brand
     $image = new Image();
     $image->setPath('slider3.jpg');
     $filename = __DIR__ . '/../../Resources/public/images/slider3.jpg';
     copy($filename, __DIR__ . '/../../../../../../web/uploads/images/slider3.jpg');
     $slider->setImage($image);
     $this->getManager()->persist($image);
     $image2 = new Image();
     $image2->setPath('slider1.png');
     $filename = __DIR__ . '/../../Resources/public/images/slider1.png';
     copy($filename, __DIR__ . '/../../../../../../web/uploads/images/slider1.png');
     $slider2->setImage($image2);
     $this->getManager()->persist($image2);
     //
     //        $image3 = new Image();
     //        $image3->setPath('slide4.jpg');
     //        $filename =  __DIR__ . '/../../Resources/public/images/slide4.jpg';
     //        copy($filename, __DIR__ . '/../../../../../../web/uploads/images/slide4.jpg' );
     //        $slider3->setImage($image3);
     //        $this->getManager()->persist($image3);
     $this->getManager()->flush();
 }