/** * @usage Zend_Debug::dump($this->getUrl('front/image/crop', array( 'image' => base64_encode('http://www.mobistadium.com/wp-content/uploads/2012/11/fitness.jpg'), 'width' => 640, 'height' => 400 ))); */ public function cropAction() { $datas = $this->getRequest()->getParams(); $default_url = ''; try { if (!empty($datas['image'])) { $default_url = $datas['image']; } else { die; } if (empty($datas['width']) or empty($datas['height'])) { throw new Exception(''); } $image = base64_decode($datas['image']); $expected_width = $datas['width']; $expected_height = $datas['height']; $this->_setFileType($image); $image_id = 'wordpress_image_' . sha1($image) . '-' . $expected_width . 'x' . $expected_height; $tmp_file = Core_Model_Directory::getTmpDirectory(true) . '/' . $image_id . '.' . $this->_image_ext; if (!is_dir(Core_Model_Directory::getImageCacheDirectory(true))) { mkdir(Core_Model_Directory::getImageCacheDirectory(true), 0777); } $dest_file = Core_Model_Directory::getImageCacheDirectory(true) . '/' . $image_id . '.' . $this->_image_ext; // if(file_exists($dest_file)) unlink($dest_file); if (!file_exists($dest_file) or !@getimagesize($dest_file)) { $image_url = $datas['image']; $new_img = imagecreatefromstring(file_get_contents($image)); $this->_saveImage($new_img, $tmp_file); imagedestroy($new_img); list($width, $height) = getimagesize($tmp_file); $new_width = $width; $new_height = $height; $ratio_width = $expected_width / $width; $ratio_height = $expected_height / $height; if ($ratio_height > $ratio_width) { $new_width *= $ratio_height; $new_height *= $ratio_height; } else { $new_width *= $ratio_width; $new_height *= $ratio_width; } Thumbnailer_CreateThumb::createThumbnail($tmp_file, $dest_file, $new_width, $new_height, $this->_image_ext, false, array('resizeUp' => true)); Thumbnailer_CreateThumb::crop($dest_file, $dest_file, 0, 0, $expected_width, $expected_height, true); if (!file_exists($dest_file) or !@getimagesize($dest_file)) { throw new Exception(''); } } $image_url = $dest_file; } catch (Exception $e) { $image_url = ''; } if (!empty($image_url)) { $this->_showImage($image_url); } die; }
public function loginwithfacebookAction() { if ($access_token = $this->getRequest()->getParam('token')) { try { // Réinitialise la connexion $this->getSession()->resetInstance(); // Récupération des données du compte Facebook $graph_url = "https://graph.facebook.com/v2.0/me?access_token=" . $access_token; $user = json_decode(file_get_contents($graph_url)); if (!$user instanceof stdClass or !$user->id) { throw new Exception($this->_('An error occurred while connecting to your Facebook account. Please try again later')); } // Récupère le user_id $user_id = $user->id; // Charge le client à partir du user_id $customer = new Customer_Model_Customer(); $customer->findBySocialId($user_id, 'facebook'); // Si le client n'a pas de compte if (!$customer->getId()) { // Charge le client à partir de l'adresse email afin d'associer les 2 comptes ensemble if ($user->email) { $customer->find(array('email' => $user->email)); } // Si l'email n'existe pas en base, on crée le client if (!$customer->getId()) { // Préparation des données du client $customer->setData(array('civility' => $user->gender == 'male' ? 'm' : 'mme', 'firstname' => $user->first_name, 'lastname' => $user->last_name, 'email' => $user->email)); // Ajoute un mot de passe par défaut $customer->setPassword(uniqid()); // Récupèration de l'image de Facebook $social_image = @file_get_contents("http://graph.facebook.com/v2.0/{$user_id}/picture?type=large"); if ($social_image) { $formated_name = Core_Model_Lib_String::format($customer->getName(), true); $image_path = $customer->getBaseImagePath() . '/' . $formated_name; // Créer le dossier du client s'il n'existe pas if (!is_dir($customer->getBaseImagePath())) { mkdir($image_path, 0777); } // Créer l'image sur le serveur $image_name = uniqid() . '.jpg'; $image = fopen($image_path . '/' . $image_name, 'w'); fputs($image, $social_image); fclose($image); // Redimensionne l'image Thumbnailer_CreateThumb::createThumbnail($image_path . '/' . $image_name, $image_path . '/' . $image_name, 150, 150, 'jpg', true); // Affecte l'image au client $customer->setImage('/' . $formated_name . '/' . $image_name); } } } // Affecte les données du réseau social au client $customer->setSocialData('facebook', array('id' => $user_id, 'datas' => $access_token)); // Sauvegarde du nouveau client $customer->save(); // Connexion du client $this->getSession()->setCustomer($customer); $html = array('success' => 1, 'customer_id' => $customer->getId()); } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }
/** * @usage Zend_Debug::dump($this->getUrl('front/image/crop', array( 'image' => base64_encode('http://www.mobistadium.com/wp-content/uploads/2012/11/fitness.jpg'), 'width' => 640, 'height' => 400 ))); */ public function cropAction() { // Zend_Debug::dump(base64_encode('http://www.mobistadium.com/wp-content/uploads/2012/09/fitness1.jpg')); // die; // aHR0cDovL3d3dy5tb2Jpc3RhZGl1bS5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMTIvMDkvZml0bmVzczEuanBn // aHR0cDovL3d3dy5tb2Jpc3RhZGl1bS5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMTIvMDkvZml0bmVzcy1oZi5qcGc // aHR0cDovL3d3dy5tb2Jpc3RhZGl1bS5jb20vd3AtY29udGVudC91cGxvYWRzLzIwMTIvMDkvQnJhZC1QaXR0LUZpZ2h0LUNsdWItMy5qcGc $datas = $this->getRequest()->getParams(); $default_url = ''; try { if (!empty($datas['image'])) { $default_url = $datas['image']; } else { die; } if (empty($datas['width']) or empty($datas['height'])) { throw new Exception(''); } $image = base64_decode($datas['image']); $expected_width = $datas['width']; $expected_height = $datas['height']; $this->_setFileType($image); $image_id = 'wordpress_image_' . sha1($image) . '-' . $expected_width . 'x' . $expected_height; $tmp_file = Core_Model_Directory::getTmpDirectory(true) . '/' . $image_id . '.' . $this->_image_ext; if (!is_dir(Core_Model_Directory::getImageCacheDirectory(true))) { mkdir(Core_Model_Directory::getImageCacheDirectory(true), 0777); } $image_path = Core_Model_Directory::getImageCacheDirectory(true) . '/' . $image_id . '.' . $this->_image_ext; $dest_file = Core_Model_Directory::getBasePathTo($image_path); // if(file_exists($dest_file)) unlink($dest_file); if (!file_exists($dest_file) or !@getimagesize($dest_file)) { $image_url = $datas['image']; $new_img = imagecreatefromstring(file_get_contents($image)); $this->_saveImage($new_img, $tmp_file); imagedestroy($new_img); list($width, $height) = getimagesize($tmp_file); $new_width = $width; $new_height = $height; $ratio_width = $expected_width / $width; $ratio_height = $expected_height / $height; if ($ratio_height > $ratio_width) { $new_width *= $ratio_height; $new_height *= $ratio_height; } else { $new_width *= $ratio_width; $new_height *= $ratio_width; } Thumbnailer_CreateThumb::createThumbnail($tmp_file, $dest_file, $new_width, $new_height, $this->_image_ext, false, array('resizeUp' => true)); Thumbnailer_CreateThumb::crop($dest_file, $dest_file, 0, 0, $expected_width, $expected_height, true); if (!file_exists($dest_file) or !@getimagesize($dest_file)) { throw new Exception(''); } } $image_url = $dest_file; } catch (Exception $e) { $image_url = ''; } if (!empty($image_url)) { $this->_showImage($image_url); } die; }
public function loginwithfacebookAction() { if ($access_token = $this->getRequest()->getParam('token')) { try { // Reset session $this->getSession()->resetInstance(); // Fetch data from Facebook $graph_url = "https://graph.facebook.com/me?fields=id,name,email,first_name,last_name&access_token=" . $access_token; $user = json_decode(file_get_contents($graph_url)); if (!$user instanceof stdClass or !$user->id) { throw new Exception($this->_('An error occurred while connecting to your Facebook account. Please try again later')); } // Retrieve the user_id $user_id = $user->id; // Retrieve the current app ID $app_id = $this->getApplication()->getId(); // Load the customer from the user_id $customer = new Customer_Model_Customer(); $customer->findBySocialId($user_id, 'facebook', $app_id); // If the customer doesn't exist if (!$customer->getId()) { // Load the customer based on the email address in order to link the 2 accounts together if ($user->email) { $customer->find(array("email" => $user->email, "app_id" => $app_id)); } // If the email doesn't exist, create the account if (!$customer->getId()) { // Préparation des données du client $customer->setData(array("app_id" => $app_id, "firstname" => $user->first_name, "lastname" => $user->last_name, "email" => $user->email)); // Add a default password $customer->setPassword(uniqid()); // Retrieve its picture from Facebook $social_image = @file_get_contents("http://graph.facebook.com/{$user_id}/picture?type=large"); if ($social_image) { $formated_name = Core_Model_Lib_String::format($customer->getName(), true); $image_path = $customer->getBaseImagePath() . '/' . $formated_name; // Create customer's folder if (!is_dir($customer->getBaseImagePath())) { mkdir($image_path, 0777); } // Store the picture on the server $image_name = uniqid() . '.jpg'; $image = fopen($image_path . '/' . $image_name, 'w'); fputs($image, $social_image); fclose($image); // Resize the image Thumbnailer_CreateThumb::createThumbnail($image_path . '/' . $image_name, $image_path . '/' . $image_name, 150, 150, 'jpg', true); // Set the image to the customer $customer->setImage('/' . $formated_name . '/' . $image_name); } } } // Set the social data to the customer $customer->setSocialData('facebook', array('id' => $user_id, 'datas' => $access_token)); // Save the customer $customer->save(); // Log-in the customer $this->getSession()->setCustomer($customer); $html = array('success' => 1, 'customer_id' => $customer->getId(), 'can_access_locked_features' => $customer->canAccessLockedFeatures()); } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }