public function setPhoto($photo) { if ($photo instanceof Zend_Form_Element_File) { $file = $photo->getFileName(); } else { if (is_array($photo) && !empty($photo['tmp_name'])) { $file = $photo['tmp_name']; } else { if (is_string($photo) && file_exists($photo)) { $file = $photo; } else { throw new Event_Model_Exception('invalid argument passed to setPhoto'); } } } $name = basename($file); $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; $params = array('parent_id' => $this->getIdentity(), 'parent_type' => 'ynfeed'); // Save $storage = Engine_Api::_()->storage(); // Resize image (icon) $image = Engine_Image::factory(); $image->open($file)->resize(16, 16)->write($path . '/ic_' . $name)->destroy(); // Store $iMain = $storage->create($path . '/ic_' . $name, $params); // Remove temp files @unlink($path . '/ic_' . $name); // Update row $this->photo_id = $iMain->file_id; $this->save(); return $this; }
public function savePhoto($photo, $height) { if ($photo instanceof Zend_Form_Element_File) { $file = $photo->getFileName(); } else { if (is_array($photo) && !empty($photo['tmp_name'])) { $file = $photo['tmp_name']; } else { if (is_string($photo) && file_exists($photo)) { $file = $photo; } else { return; } } } $name = basename($file); $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; // Save $storage = Engine_Api::_()->storage(); $image = Engine_Image::factory(); $image->open($file)->resize($height, $height)->write($path . '/m_' . $name)->destroy(); $thumbFileRow = Engine_Api::_()->storage()->create($path . '/m_' . $name, array('parent_type' => 'advsubscription', 'parent_id' => 1)); unlink($path . '/m_' . $name); return $thumbFileRow->storage_path; }
public function setPhoto($photo) { if ($photo instanceof Zend_Form_Element_File) { $file = $photo->getFileName(); } else { if (is_array($photo) && !empty($photo['tmp_name'])) { $file = $photo['tmp_name']; } else { if (is_string($photo) && file_exists($photo)) { $file = $photo; } else { throw new Event_Model_Exception('invalid argument passed to setPhoto'); } } } $name = basename($file); $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; $params = array('parent_id' => $this->getIdentity(), 'parent_type' => 'ynresponsive1_sponsor'); // Save $storage = Engine_Api::_()->storage(); $angle = 0; if (function_exists('exif_read_data')) { $exif = exif_read_data($file); if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 8: $angle = 90; break; case 3: $angle = 180; break; case 6: $angle = -90; break; } } } // Resize image (main) $image = Engine_Image::factory(); $image->open($file); if ($angle != 0) { $image->rotate($angle); } $image->resize(720, 720)->write($path . '/m_' . $name)->destroy(); // Resize image (normal) $image = Engine_Image::factory(); $image->open($file)->resize(140, 160)->write($path . '/in_' . $name)->destroy(); // Store $iMain = $storage->create($path . '/m_' . $name, $params); $iIconNormal = $storage->create($path . '/in_' . $name, $params); $iMain->bridge($iIconNormal, 'thumb.normal'); // Remove temp files @unlink($path . '/m_' . $name); @unlink($path . '/in_' . $name); // Update row $this->photo_id = $iMain->file_id; $this->save(); return $this; }
public function setPhoto($photo) { if ($photo instanceof Zend_Form_Element_File) { $file = $photo->getFileName(); } else { if (is_array($photo) && !empty($photo['tmp_name'])) { $file = $photo['tmp_name']; } else { if (is_string($photo) && file_exists($photo)) { $file = $photo; } else { throw new Event_Model_Exception('invalid argument passed to setPhoto'); } } } $name = basename($file); $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; $params = array('parent_id' => $this->getIdentity(), 'parent_type' => 'event_sponsor'); // Save $storage = Engine_Api::_()->storage(); // Resize image (main) $image = Engine_Image::factory(); $image->open($file)->resize(720, 720)->write($path . '/m_' . $name)->destroy(); // Resize image (profile) $image = Engine_Image::factory(); $image->open($file)->resize(200, 400)->write($path . '/p_' . $name)->destroy(); // Resize image (normal) $image = Engine_Image::factory(); $image->open($file)->resize(140, 160)->write($path . '/in_' . $name)->destroy(); // Resize image (icon) $image = Engine_Image::factory(); $image->open($file); $size = min($image->height, $image->width); $x = ($image->width - $size) / 2; $y = ($image->height - $size) / 2; $image->resample($x, $y, $size, $size, 48, 48)->write($path . '/is_' . $name)->destroy(); // Store $iMain = $storage->create($path . '/m_' . $name, $params); $iProfile = $storage->create($path . '/p_' . $name, $params); $iIconNormal = $storage->create($path . '/in_' . $name, $params); $iSquare = $storage->create($path . '/is_' . $name, $params); $iMain->bridge($iProfile, 'thumb.profile'); $iMain->bridge($iIconNormal, 'thumb.normal'); $iMain->bridge($iSquare, 'thumb.icon'); // Remove temp files @unlink($path . '/p_' . $name); @unlink($path . '/m_' . $name); @unlink($path . '/in_' . $name); @unlink($path . '/is_' . $name); // Update row $this->photo_id = $iMain->file_id; $this->save(); return $this; }
public function getVideoImage($video_id = 0) { if ($video_id) { $video = Engine_Api::_()->getItem('video', $video_id); if ($video instanceof Video_Model_Video) { $video->duration = $duration = $this->getVideoDuration($video_id); $thumb_splice = $duration / 2; $tmpDir = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary' . DIRECTORY_SEPARATOR . 'video'; $thumbPathLarge = $tmpDir . DIRECTORY_SEPARATOR . $video->getIdentity() . '_vthumb_large.jpg'; $thumbPath = $tmpDir . DIRECTORY_SEPARATOR . $video->getIdentity() . '_vthumb.jpg'; $ffmpeg_path = Engine_Api::_()->getApi('settings', 'core')->video_ffmpeg_path; if (!@file_exists($ffmpeg_path) || !@is_executable($ffmpeg_path)) { $output = null; $return = null; exec($ffmpeg_path . ' -version', $output, $return); if ($return > 0) { return 0; } } // Prepare output header $output = PHP_EOL; $output .= $video->code . PHP_EOL; $output .= $thumbPathLarge . PHP_EOL; $thumbCommand = $ffmpeg_path . ' ' . '-i ' . escapeshellarg($video->code) . ' ' . '-f image2' . ' ' . '-ss ' . $thumb_splice . ' ' . '-vframes ' . '1' . ' ' . '-v 2' . ' ' . '-y ' . escapeshellarg($thumbPathLarge) . ' ' . '2>&1'; // Process thumbnail $thumbOutput = $output . $thumbCommand . PHP_EOL . shell_exec($thumbCommand); // Check output message for success $thumbSuccess = true; if (preg_match('/video:0kB/i', $thumbOutput)) { $thumbSuccess = false; } // Resize thumbnail if ($thumbSuccess && is_file($thumbPathLarge)) { try { $image = Engine_Image::factory(); $image->open($thumbPathLarge)->resize(640, 360)->write($thumbPathLarge)->destroy(); $thumbFileRowLarge = Engine_Api::_()->storage()->create($thumbPathLarge, array('parent_id' => $video->getIdentity(), 'parent_type' => $video->getType(), 'user_id' => $video->owner_id)); $image->open($thumbPathLarge)->resize(120, 240)->write($thumbPath)->destroy(); $thumbFileRow = Engine_Api::_()->storage()->create($thumbPath, array('parent_id' => $video->getIdentity(), 'parent_type' => $video->getType(), 'user_id' => $video->owner_id)); $video->large_photo_id = $thumbFileRowLarge->file_id; $video->photo_id = $thumbFileRow->file_id; $video->save(); unlink($thumbPathLarge); unlink($thumbPath); return true; } catch (Exception $e) { throw $e; unlink($thumbPathLarge); unlink($thumbPath); } } } } }
protected function _resizeThumbnail($user) { $storage = Engine_Api::_()->storage(); $iProfile = $storage->get($user->photo_id, 'thumb.profile'); $iSquare = $storage->get($user->photo_id, 'thumb.icon'); // Read into tmp file $pName = $iProfile->getStorageService()->temporary($iProfile); $iName = dirname($pName) . '/nis_' . basename($pName); list($x, $y, $w, $h) = explode(':', $this->getSession()->coordinates); $image = Engine_Image::factory(); $image->open($pName)->resample((int) $x, (int) $y, (int) $w, (int) $h, 48, 48)->write($iName)->destroy(); $iSquare->store($iName); @unlink($iName); }
public function createLink(Core_Model_Item_Abstract $owner, $data) { $table = Engine_Api::_()->getDbtable('links', 'core'); if (empty($data['parent_type']) || empty($data['parent_id'])) { $data['parent_type'] = $owner->getType(); $data['parent_id'] = $owner->getIdentity(); } $link = $table->createRow(); $link->setFromArray($data); $link->owner_type = $owner->getType(); $link->owner_id = $owner->getIdentity(); $link->save(); // Now try to create thumbnail $thumbnail = (string) @$data['thumb']; $thumbnail_parsed = @parse_url($thumbnail); //$ext = @ltrim(strrchr($thumbnail_parsed['path'], '.'), '.'); //$link_parsed = @parse_url($link->uri); // Make sure to not allow thumbnails from domains other than the link (problems with subdomains, disabled for now) //if( $thumbnail && $thumbnail_parsed && $thumbnail_parsed['host'] === $link_parsed['host'] ) //if( $thumbnail && $ext && $thumbnail_parsed && in_array($ext, array('jpg', 'jpeg', 'gif', 'png')) ) if ($thumbnail && $thumbnail_parsed) { $tmp_path = APPLICATION_PATH . '/temporary/link'; $tmp_file = $tmp_path . '/' . md5($thumbnail); if (!is_dir($tmp_path) && !mkdir($tmp_path, 0777, true)) { throw new Core_Model_Exception('Unable to create tmp link folder : ' . $tmp_path); } $src_fh = fopen($thumbnail, 'r'); $tmp_fh = fopen($tmp_file, 'w'); stream_copy_to_stream($src_fh, $tmp_fh, 1024 * 1024 * 2); fclose($src_fh); fclose($tmp_fh); if (($info = getimagesize($tmp_file)) && !empty($info[2])) { $ext = image_type_to_extension($info[2]); $thumb_file = $tmp_path . '/thumb_' . md5($thumbnail) . '.' . $ext; $image = Engine_Image::factory(); $image->open($tmp_file)->resize(120, 240)->write($thumb_file)->destroy(); $thumbFileRow = Engine_Api::_()->storage()->create($thumb_file, array('parent_type' => $link->getType(), 'parent_id' => $link->getIdentity())); $link->photo_id = $thumbFileRow->file_id; $link->save(); @unlink($thumb_file); } @unlink($tmp_file); } return $link; }
public function createPhoto($params, $file) { if ($file instanceof Storage_Model_File) { $params['file_id'] = $file->getIdentity(); } else { // Get image info and resize $name = basename($file['tmp_name']); $path = dirname($file['tmp_name']); $extension = ltrim(strrchr($file['name'], '.'), '.'); $mainName = $path . '/m_' . $name . '.' . $extension; $thumbName = $path . '/t_' . $name . '.' . $extension; $image = Engine_Image::factory(); $image->open($file['tmp_name'])->resize(self::IMAGE_WIDTH, self::IMAGE_HEIGHT)->write($mainName)->destroy(); $image = Engine_Image::factory(); $image->open($file['tmp_name'])->resize(self::THUMB_WIDTH, self::THUMB_HEIGHT)->write($thumbName)->destroy(); // Store photos $photo_params = array('parent_id' => $params['owner_id'], 'parent_type' => $params['owner_type']); try { $photoFile = Engine_Api::_()->storage()->create($mainName, $photo_params); $thumbFile = Engine_Api::_()->storage()->create($thumbName, $photo_params); } catch (Exception $e) { if ($e->getCode() == Storage_Api_Storage::SPACE_LIMIT_REACHED_CODE) { echo $e->getMessage(); exit; } } $photoFile->bridge($thumbFile, 'thumb.normal'); // Remove temp files @unlink($mainName); @unlink($thumbName); $params['file_id'] = $photoFile->file_id; // This might be wrong $params['photo_id'] = $photoFile->file_id; } $row = Engine_Api::_()->getDbtable('photos', 'album')->createRow(); $row->setFromArray($params); $row->save(); return $row; }
public function setPhoto($photo) { if ($photo instanceof Zend_Form_Element_File) { $file = $photo->getFileName(); } else { if (is_array($photo) && !empty($photo['tmp_name'])) { $file = $photo['tmp_name']; } else { if (is_string($photo) && file_exists($photo)) { $file = $photo; } else { throw new User_Model_Exception('invalid argument passed to setPhoto'); } } } $name = basename($file); $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; $params = array('parent_type' => 'user_library', 'parent_id' => $this->getIdentity()); // Save $storage = Engine_Api::_()->storage(); // Resize image (main) $image = Engine_Image::factory(); $image->open($file)->resize(720, 720)->write($path . '/m_' . $name)->destroy(); // Resize image (profile) $image = Engine_Image::factory(); $image->open($file)->resize(200, 400)->write($path . '/p_' . $name)->destroy(); // Store $iMain = $storage->create($path . '/m_' . $name, $params); $iProfile = $storage->create($path . '/p_' . $name, $params); $iMain->bridge($iProfile, 'thumb.profile'); // Remove temp files @unlink($path . '/p_' . $name); @unlink($path . '/m_' . $name); // Update row $this->modified_date = date('Y-m-d H:i:s'); $this->photo_id = $iMain->file_id; $this->save(); return $this; }
public function uploadAction() { $this->_helper->layout->disableLayout(); if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name'])) { $this->view->status = false; $this->view->error = Zend_Registry::get('Zend_Translate')->_('Invalid Upload'); return; } $destination = "public/book/"; if (!is_dir($destination)) { mkdir($destination); } $upload = new Zend_File_Transfer_Adapter_Http(); $upload->setDestination($destination); $fullFilePath = $destination . time() . '_' . $upload->getFileName('Filedata', false); $image = Engine_Image::factory(); $image->open($_FILES['Filedata']['tmp_name'])->resize(720, 720)->write($fullFilePath); $this->view->status = true; $this->view->name = $_FILES['Filedata']['name']; $this->view->photo_url = Zend_Registry::get('StaticBaseUrl') . $fullFilePath; $this->view->photo_width = $image->getWidth(); $this->view->photo_height = $image->getHeight(); }
protected function _translateThumbnail($newData) { $file_id = 0; if (empty($newData['code'])) { return $file_id; } $thumbnail = $this->handleThumbnail($newData['type'], $newData['code']); if (!$thumbnail) { return $file_id; } $ext = ltrim(strrchr($thumbnail, '.'), '.'); if (!$ext || !in_array($ext, array('jpg', 'jpeg', 'gif', 'png'))) { return $file_id; } $thumbnail_parsed = @parse_url($thumbnail); if (!$thumbnail_parsed || !@GetImageSize($thumbnail)) { return $file_id; } $temporary_directory = $this->_sys_get_temp_dir(); $tmp_file = $temporary_directory . '/video_' . md5($thumbnail) . '.' . $ext; $thumb_file = $temporary_directory . '/video_thumb_' . md5($thumbnail) . '.' . $ext; $src_fh = fopen($thumbnail, 'r'); $tmp_fh = fopen($tmp_file, 'w'); stream_copy_to_stream($src_fh, $tmp_fh, 1024 * 1024 * 2); $image = Engine_Image::factory(); $image->open($tmp_file)->resize(120, 240)->write($thumb_file)->destroy(); $file_id = $this->_translateFile($thumb_file, array('parent_type' => 'video', 'parent_id' => $newData['video_id'], 'user_id' => $newData['owner_id']), false); @unlink($thumb_file); @unlink($tmp_file); return $file_id; }
protected function _process($video) { // Make sure FFMPEG path is set $ffmpeg_path = Engine_Api::_() -> getApi('settings', 'core') -> ynvideo_ffmpeg_path; if (!$ffmpeg_path) { throw new Ynvideo_Model_Exception('Ffmpeg not configured'); } // Make sure FFMPEG can be run if (!@file_exists($ffmpeg_path) || !@is_executable($ffmpeg_path)) { $output = null; $return = null; exec($ffmpeg_path . ' -version', $output, $return); if ($return > 0) { throw new Ynvideo_Model_Exception('Ffmpeg found, but is not executable'); } } // Check we can execute if (!function_exists('shell_exec')) { throw new Ynvideo_Model_Exception('Unable to execute shell commands using shell_exec(); the function is disabled.'); } // Check the video temporary directory $tmpDir = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary' . DIRECTORY_SEPARATOR . 'video'; if (!is_dir($tmpDir)) { if (!mkdir($tmpDir, 0777, true)) { throw new Ynvideo_Model_Exception('Video temporary directory did not exist and could not be created.'); } } if (!is_writable($tmpDir)) { throw new Ynvideo_Model_Exception('Video temporary directory is not writable.'); } // Get the video object if (is_numeric($video)) { $video = Engine_Api::_() -> getItem('video', $video_id); } if (!($video instanceof Ynvideo_Model_Video)) { throw new Ynvideo_Model_Exception('Argument was not a valid video'); } // Update to encoding status $video -> status = 2; $video -> type = Ynvideo_Plugin_Factory::getUploadedType(); $video -> save(); // Prepare information $owner = $video -> getOwner(); $filetype = $video -> code; // Pull video from storage system for encoding $storageObject = Engine_Api::_() -> getItem('storage_file', $video -> file_id); if (!$storageObject) { throw new Ynvideo_Model_Exception('Video storage file was missing'); } $originalPath = $storageObject -> temporary(); if (!file_exists($originalPath)) { throw new Ynvideo_Model_Exception('Could not pull to temporary file'); } $outputPath = $tmpDir . DIRECTORY_SEPARATOR . $video -> getIdentity() . '_vconverted.mp4'; $thumbPathLarge = $tmpDir . DIRECTORY_SEPARATOR . $video -> getIdentity() . '_vthumb_large.jpg'; $thumbPath = $tmpDir . DIRECTORY_SEPARATOR . $video -> getIdentity() . '_vthumb.jpg'; //Convert to Mp4 (h264 - HTML5, mpeg4 - IOS) $videoCommand = $ffmpeg_path . ' ' . '-i ' . escapeshellarg($originalPath) . ' ' . '-ab 64k' . ' ' . '-ar 44100' . ' ' . '-qscale 5' . ' ' . '-r 25' . ' '; $videoCommand .= '-vcodec libx264' . ' ' . '-acodec aac' . ' ' . '-strict experimental' . ' ' . '-preset veryfast' . ' ' . '-f mp4' . ' '; $videoCommand .= "-s 640x360" . ' '; $videoCommand .= '-y ' . escapeshellarg($outputPath) . ' ' . '2>&1'; // Prepare output header $output = PHP_EOL; $output .= $originalPath . PHP_EOL; $output .= $outputPath . PHP_EOL; $output .= $thumbPathLarge . PHP_EOL; // Execute video encode command $videoOutput = $output . $videoCommand . PHP_EOL . shell_exec($videoCommand); // Check for failure $success = true; // Unsupported format if (preg_match('/Unknown format/i', $videoOutput) || preg_match('/Unsupported codec/i', $videoOutput) || preg_match('/patch welcome/i', $videoOutput) || preg_match('/Audio encoding failed/i', $videoOutput) || !is_file($outputPath) || filesize($outputPath) <= 0) { $success = false; $video -> status = 3; } // This is for audio files else if (preg_match('/video:0kB/i', $videoOutput)) { $success = false; $video -> status = 5; } // Failure if (!$success) { $exceptionMessage = ''; $db = $video -> getTable() -> getAdapter(); $db -> beginTransaction(); try { $video -> save(); // notify the owner $translate = Zend_Registry::get('Zend_Translate'); $language = (!empty($owner -> language) && $owner -> language != 'auto' ? $owner -> language : null); $notificationMessage = ''; if ($video -> status == 3) { $exceptionMessage = 'Video format is not supported by FFMPEG.'; $notificationMessage = $translate -> translate(sprintf('Video conversion failed. Video format is not supported by FFMPEG. Please try %1$sagain%2$s.', '', ''), $language); } else if ($video -> status == 5) { $exceptionMessage = 'Audio-only files are not supported.'; $notificationMessage = $translate -> translate(sprintf('Video conversion failed. Audio files are not supported. Please try %1$sagain%2$s.', '', ''), $language); } else { $exceptionMessage = 'Unknown encoding error.'; } Engine_Api::_() -> getDbtable('notifications', 'activity') -> addNotification($owner, $owner, $video, 'ynvideo_processed_failed', array( 'message' => $notificationMessage, 'message_link' => Zend_Controller_Front::getInstance() -> getRouter() -> assemble(array('action' => 'manage'), 'video_general', true), )); $db -> commit(); } catch (Exception $e) { $videoOutput_mpeg4 .= PHP_EOL . $e -> __toString() . PHP_EOL; $db -> rollBack(); } // Write to additional log in dev if (APPLICATION_ENV == 'development') { file_put_contents($tmpDir . '/' . $video -> video_id . '.txt', $videoOutput); } throw new Ynvideo_Model_Exception($exceptionMessage); } // Success else { // Get duration of the video to caculate where to get the thumbnail if (preg_match('/Duration:\s+(.*?)[.]/i', $videoOutput, $matches)) { list($hours, $minutes, $seconds) = preg_split('[:]', $matches[1]); $duration = ceil($seconds + ($minutes * 60) + ($hours * 3600)); } else { $duration = 0; // Hmm } // Fetch where to take the thumbnail $thumb_splice = $duration / 2; // Thumbnail proccess command $thumbCommand = $ffmpeg_path . ' ' . '-i ' . escapeshellarg($outputPath) . ' ' . '-f image2' . ' ' . '-ss ' . $thumb_splice . ' ' . '-vframes ' . '1' . ' ' . '-v 2' . ' ' . '-y ' . escapeshellarg($thumbPath) . ' ' . '2>&1'; // Process thumbnail $thumbOutput = $output . $thumbCommand . PHP_EOL . shell_exec($thumbCommand); // Check output message for success $thumbSuccess = true; if (preg_match('/video:0kB/i', $thumbOutput)) { $thumbSuccess = false; } // Resize thumbnail if ($thumbSuccess) { try { $image = Engine_Image::factory(); $image -> open($thumbPath) -> resize(640, 360) -> write($thumbPathLarge) -> destroy(); $image -> open($thumbPath) -> resize(120, 240) -> write($thumbPath) -> destroy(); } catch (Exception $e) { $this -> _addMessage((string)$e -> __toString()); $thumbSuccess = false; } } // Save video and thumbnail to storage system $params = array( 'parent_id' => $video -> getIdentity(), 'parent_type' => $video -> getType(), 'user_id' => $video -> owner_id ); $db = $video -> getTable() -> getAdapter(); $db -> beginTransaction(); try { $storageObject -> setFromArray($params); $storageObject -> store($outputPath); if ($thumbSuccess) { $thumbFileRowLarge = Engine_Api::_() -> storage() -> create($thumbPathLarge, $params); $thumbFileRow = Engine_Api::_() -> storage() -> create($thumbPath, $params); } $db -> commit(); } catch (Exception $e) { $db -> rollBack(); // delete the files from temp dir unlink($originalPath); unlink($outputPath); if ($thumbSuccess) { unlink($thumbPathLarge); unlink($thumbPath); } $video -> status = 7; $video -> save(); // notify the owner $translate = Zend_Registry::get('Zend_Translate'); $notificationMessage = ''; $language = (!empty($owner -> language) && $owner -> language != 'auto' ? $owner -> language : null); if ($video -> status == 7) { $notificationMessage = $translate -> translate(sprintf('Video conversion failed. You may be over the site upload limit. Try %1$suploading%2$s a smaller file, or delete some files to free up space.', '', ''), $language); } Engine_Api::_() -> getDbtable('notifications', 'activity') -> addNotification($owner, $owner, $video, 'ynvideo_processed_failed', array( 'message' => $notificationMessage, 'message_link' => Zend_Controller_Front::getInstance() -> getRouter() -> assemble(array('action' => 'manage'), 'video_general', true), )); //throw $e; // throw } // Video processing was a success! // Save the information if ($thumbSuccess) { $video -> photo_id = $thumbFileRow -> file_id; $video -> large_photo_id = $thumbFileRowLarge -> file_id; } $video -> file1_id = $video -> file_id; $video -> duration = $duration; $video -> status = 1; $video -> save(); // notify the owner Engine_Api::_() -> getDbtable('notifications', 'activity') -> addNotification($owner, $owner, $video, 'ynvideo_processed'); // delete the files from temp dir unlink($originalPath); unlink($outputPath); unlink($thumbPathLarge); unlink($thumbPath); // insert action in a seperate transaction if video status is a success $actionsTable = Engine_Api::_() -> getDbtable('actions', 'activity'); $db = $actionsTable -> getAdapter(); $db -> beginTransaction(); try { // new action $item = Engine_Api::_() -> getItem($video -> parent_type, $video -> parent_id); if ($video -> parent_type == 'group') { $action = $actionsTable -> addActivity($owner, $item, 'advgroup_video_create'); } elseif ($video -> parent_type == 'event') { $action = $actionsTable -> addActivity($owner, $item, 'ynevent_video_create'); } else { $action = $actionsTable -> addActivity($owner, $video, 'video_new'); } if ($action) { $actionsTable -> attachActivity($action, $video); } $db -> commit(); } catch (Exception $e) { $db -> rollBack(); //throw $e; // throw } } }
public function setPhoto($photo) { if ($photo instanceof Zend_Form_Element_File) { $file = $photo->getFileName(); $fileName = $file; } else { if ($photo instanceof Storage_Model_File) { $file = $photo->temporary(); $fileName = $photo->name; } else { if ($photo instanceof Core_Model_Item_Abstract && !empty($photo->file_id)) { $tmpRow = Engine_Api::_()->getItem('storage_file', $photo->file_id); $file = $tmpRow->temporary(); $fileName = $tmpRow->name; } else { if (is_array($photo) && !empty($photo['tmp_name'])) { $file = $photo['tmp_name']; $fileName = $photo['name']; } else { if (is_string($photo) && file_exists($photo)) { $file = $photo; $fileName = $photo; } else { throw new User_Model_Exception('invalid argument passed to setPhoto'); } } } } } if (!$fileName) { $fileName = $file; } $name = basename($file); $extension = ltrim(strrchr(basename($fileName), '.'), '.'); $base = rtrim(substr(basename($fileName), 0, strrpos(basename($fileName), '.')), '.'); $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; $params = array('parent_type' => $this->getType(), 'parent_id' => $this->getIdentity(), 'user_id' => $this->getIdentity(), 'name' => basename($fileName)); // Save $filesTable = Engine_Api::_()->getDbtable('files', 'storage'); // Resize image (main) $mainPath = $path . DIRECTORY_SEPARATOR . $base . '_m.' . $extension; $image = Engine_Image::factory(); $image->open($file)->resize(720, 720)->write($mainPath)->destroy(); // Resize image (profile) $profilePath = $path . DIRECTORY_SEPARATOR . $base . '_p.' . $extension; $image = Engine_Image::factory(); $image->open($file)->resize(200, 400)->write($profilePath)->destroy(); // Resize image (normal) $normalPath = $path . DIRECTORY_SEPARATOR . $base . '_in.' . $extension; $image = Engine_Image::factory(); $image->open($file)->resize(140, 160)->write($normalPath)->destroy(); // Resize image (icon) $squarePath = $path . DIRECTORY_SEPARATOR . $base . '_is.' . $extension; $image = Engine_Image::factory(); $image->open($file); $size = min($image->height, $image->width); $x = ($image->width - $size) / 2; $y = ($image->height - $size) / 2; $image->resample($x, $y, $size, $size, 48, 48)->write($squarePath)->destroy(); // Store $iMain = $filesTable->createFile($mainPath, $params); $iProfile = $filesTable->createFile($profilePath, $params); $iIconNormal = $filesTable->createFile($normalPath, $params); $iSquare = $filesTable->createFile($squarePath, $params); $iMain->bridge($iProfile, 'thumb.profile'); $iMain->bridge($iIconNormal, 'thumb.normal'); $iMain->bridge($iSquare, 'thumb.icon'); // Remove temp files @unlink($mainPath); @unlink($profilePath); @unlink($normalPath); @unlink($squarePath); // Update row $this->modified_date = date('Y-m-d H:i:s'); $this->photo_id = $iMain->file_id; $this->save(); return $this; }
public function createPhoto($params, $photo_file, $photo = array()) { if ($photo_file instanceof Zend_Form_Element_File) { $file = $photo_file; $fileName = $photo_file->getFileName(); } else { if ($photo_file instanceof Storage_Model_File) { $file = $photo_file->temporary(); $fileName = $photo_file->name; } else { if ($photo_file instanceof Core_Model_Item_Abstract && !empty($photo_file->file_id)) { $tmpRow = Engine_Api::_()->getItem('storage_file', $photo_file->file_id); $file = $tmpRow->temporary(); $fileName = $tmpRow->name; } else { if (is_array($photo_file) && !empty($photo_file['tmp_name'])) { $file = $photo_file['tmp_name']; $fileName = $photo_file['name']; } else { if (is_string($photo_file) && file_exists($photo_file)) { $file = $photo_file; $fileName = $photo_file; } else { throw new User_Model_Exception('invalid argument passed to setPhoto'); } } } } } if (!$fileName) { $fileName = $file; } if (!$photo) { $photo = Engine_Api::_()->getDbtable('photos', 'advalbum')->createRow(); $photo->setFromArray($params); $photo->save(); } if ($file instanceof Storage_Model_File) { $photo->file_id = $file->getIdentity(); } else { // Get image info and resize $name = basename($file); $path = dirname($file); $extension = ltrim(strrchr($fileName, '.'), '.'); $mainName = $path . '/m_' . $name . '.' . $extension; $thumbName = $path . '/t_' . $name . '.' . $extension; $image = Engine_Image::factory(); $image->open($file); $angle = 0; if (function_exists('exif_read_data')) { $exif = exif_read_data($file); if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 8: $angle = 90; break; case 3: $angle = 180; break; case 6: $angle = -90; break; } } } if ($angle != 0) { $image->rotate($angle); } $image->resize(self::IMAGE_WIDTH, self::IMAGE_HEIGHT)->write($mainName)->destroy(); $settings = Engine_Api::_()->getApi('settings', 'core'); $thumbnailstyle = $settings->getSetting('album_thumbnailstyle', 'crop'); $image = new Advalbum_Api_Image(); $image->open($file); if ($angle != 0) { $image->rotate($angle); } if ($thumbnailstyle == 'resize') { $image->resize(self::THUMB_WIDTH, self::THUMB_HEIGHT); } else { $image->resize_crop(self::THUMB_WIDTH, self::THUMB_HEIGHT); } $image->write($thumbName); $image->destroy(); // Store photos $photo_params = array('parent_type' => $photo->getType(), 'parent_id' => $photo->getIdentity(), 'user_id' => $photo->owner_id, 'name' => $fileName); try { $photoFile = Engine_Api::_()->storage()->create($mainName, $photo_params); $thumbFile = Engine_Api::_()->storage()->create($thumbName, $photo_params); } catch (Exception $e) { if ($e->getCode() == Storage_Api_Storage::SPACE_LIMIT_REACHED_CODE) { echo $e->getMessage(); exit; } } $photoFile->bridge($thumbFile, 'thumb.normal'); // Remove temp files @unlink($mainName); @unlink($thumbName); $photo->file_id = $photoFile->file_id; } $photo->save(); return $photo; }
public function photoPopupAction() { // In smoothbox $this->_helper->layout->setLayout('default-simple'); $this->view->user = $user = Engine_Api::_()->core()->getSubject(); $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer(); // Get form $this->view->form = $form = new User_Form_Edit_PhotoPopup(); if (empty($user->photo_id)) { $form->removeElement('remove'); } if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return; } $values = $form->getValues(); $isClose = true; if (!empty($values['url'])) { $isClose = false; $filename = $this->copyImg($this->getImageURL($values['url']), md5($values['url'])); if ($filename) { $user->setPhoto($filename); @unlink($filename); $iMain = Engine_Api::_()->getItem('storage_file', $user->photo_id); // Insert activity $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($user, $user, 'profile_photo_update', '{item:$subject} added a new profile photo.'); // Hooks to enable albums to work if ($action) { $event = Engine_Hooks_Dispatcher::_()->callEvent('onUserProfilePhotoUpload', array('user' => $user, 'file' => $iMain)); $attachment = $event->getResponse(); if (!$attachment) { $attachment = $iMain; } // We have to attach the user himself w/o album plugin Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $attachment); } } } // Uploading a new photo if ($form->Filedata->getValue() !== null) { $isClose = false; $db = $user->getTable()->getAdapter(); $db->beginTransaction(); try { $fileElement = $form->Filedata; $user->setPhoto($fileElement); $iMain = Engine_Api::_()->getItem('storage_file', $user->photo_id); // Insert activity $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($user, $user, 'profile_photo_update', '{item:$subject} added a new profile photo.'); // Hooks to enable albums to work if ($action) { $event = Engine_Hooks_Dispatcher::_()->callEvent('onUserProfilePhotoUpload', array('user' => $user, 'file' => $iMain)); $attachment = $event->getResponse(); if (!$attachment) { $attachment = $iMain; } // We have to attach the user himself w/o album plugin Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $attachment); } $db->commit(); } catch (Engine_Image_Adapter_Exception $e) { $db->rollBack(); $form->addError(Zend_Registry::get('Zend_Translate')->_('The uploaded file is not supported or is corrupt.')); } catch (Exception $e) { $db->rollBack(); throw $e; } } else { if ($form->getValue('coordinates') !== '') { $storage = Engine_Api::_()->storage(); $iMain = $storage->get($user->photo_id, 'thumb.main'); $iProfile = $storage->get($user->photo_id, 'thumb.profile'); $iSquare = $storage->get($user->photo_id, 'thumb.icon'); // Read into tmp file $mName = $iMain->getStorageService()->temporary($iMain); $pName = dirname($mName) . '/p_' . basename($mName); $iName = dirname($mName) . '/nis_' . basename($mName); list($x, $y, $w, $h) = explode(':', $form->getValue('coordinates')); $image = Engine_Image::factory(); $image->open($mName)->resample($x + 0.1, $y + 0.1, $w - 0.1, $h - 0.1, 48, 48)->write($iName)->destroy(); $iSquare->store($iName); $image->open($mName)->resample($x + 0.1, $y + 0.1, $w - 0.1, $h - 0.1, 200, 200)->write($pName)->destroy(); $iProfile->store($pName); // Remove temp files @unlink($pName); @unlink($iName); } } $form->reset(); if ($isClose) { return $this->_forward('success', 'utility', 'core', array('messages' => array(Zend_Registry::get('Zend_Translate')->_('Closed!')), 'format' => 'smoothbox', 'smoothboxClose' => true, 'parentRefresh' => true)); } }
public function addPhoto($photo, $viewer) { $file = $photo->getFileName(); $name = basename($file); $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; $params = array('parent_id' => $viewer->getIdentity(), 'parent_type' => $viewer->getType()); // Save $storage = Engine_Api::_()->storage(); // Resize image (main) $image = Engine_Image::factory(); $image->open($file)->write($path . '/m_' . $name)->destroy(); // Store $iMain = $storage->create($path . '/m_' . $name, $params); // Remove temp files @unlink($path . '/m_' . $name); $photos = new Book_Model_DbTable_Photos(); $photo = $photos->createRow(array('parent_object_type' => $this->getType(), 'parent_object_id' => $this->getIdentity(), 'file_id' => $iMain->getIdentity(), 'user_id' => $viewer->getIdentity())); $photo->save(); return $photo; }
public function importRawBooks() { try { $bookTbl = new Book_Model_DbTable_Books(); $select = $bookTbl->select(); $select->from($bookTbl->info('name'), new Zend_Db_Expr('MAX(`rawbook_id`) as max_rawbook_id')); $data = $select->query()->fetch(); $maxRawbookId = (int) $data['max_rawbook_id']; $userTbl = new User_Model_DbTable_Users(); $rawBookTbl = new Book_Model_DbTable_Rawbooks(); $rawBookSelect = $rawBookTbl->select(); $rawBookSelect->where('rawbook_id > ?', $maxRawbookId); $rawBookSelect->order('rawbook_id ASC'); $rawBookSelect->limit(self::DEFAULT_LIMIT); $rawBooks = $rawBookTbl->fetchAll($rawBookSelect); foreach ($rawBooks as $rawBook) { if (!empty($rawBook['publisher'])) { $publisherSelect = $userTbl->select()->where('displayname LIKE ?', $rawBook['publisher']); $publisher = $userTbl->fetchRow($publisherSelect); } if (!empty($rawBook['book_company'])) { $bookCompanySelect = $userTbl->select()->where('displayname LIKE ?', $rawBook['book_company']); $bookCompany = $userTbl->fetchRow($bookCompanySelect); } $data = array('book_name' => $rawBook->book_name, 'published_date' => date('Y-m-d H:i:s', $rawBook->published_date), 'price' => $rawBook->price, 'num_page' => $rawBook->num_page, 'description' => $rawBook->description, 'rawbook_id' => $rawBook->getIdentity(), 'user_id' => 1); if (isset($publisher) && !empty($publisher)) { $data['publisher_id'] = $publisher->getIdentity(); } if (isset($bookCompany) && !empty($bookCompany)) { $data['book_company_id'] = $bookCompany->getIdentity(); } $book = $bookTbl->createRow($data); $book->save(); if (!empty($rawBook['photo'])) { $image = Engine_Image::factory(); $name = basename($rawBook['photo']); $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; $params = array('parent_id' => $book->getIdentity(), 'parent_type' => $book->getType(), 'user_id' => 1); // Save $storage = Engine_Api::_()->storage(); $image->open($rawBook['photo'])->write($path . '/m_' . $name)->destroy(); // Store $iMain = $storage->create($path . '/m_' . $name, $params); // Remove temp files @unlink($path . '/m_' . $name); $book->photo_id = $iMain->getIdentity(); $book->save(); $photoTbl = new Book_Model_DbTable_Photos(); $photo = $photoTbl->createRow(array('parent_object_type' => $book->getType(), 'parent_object_id' => $book->getIdentity(), 'file_id' => $iMain->getIdentity(), 'user_id' => 1, 'approved' => 1, 'default' => 1)); $photo->save(); } } return true; } catch (Exception $e) { throw $e; } }
public function externalPhotoAction() { if (!$this->_helper->requireSubject()->isValid()) { return; } $user = Engine_Api::_()->core()->getSubject(); // Get photo $photo = Engine_Api::_()->getItemByGuid($this->_getParam('photo')); if (!$photo || !$photo instanceof Core_Model_Item_Abstract || empty($photo->photo_id)) { $this->_forward('requiresubject', 'error', 'core'); return; } if (!$photo->authorization()->isAllowed(null, 'view')) { $this->_forward('requireauth', 'error', 'core'); return; } // Make form $this->view->form = $form = new User_Form_Edit_ExternalPhoto(); $this->view->photo = $photo; if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return; } // Process $db = $user->getTable()->getAdapter(); $db->beginTransaction(); try { // Get the owner of the photo $photoOwnerId = null; if (isset($photo->user_id)) { $photoOwnerId = $photo->user_id; } else { if (isset($photo->owner_id) && (!isset($photo->owner_type) || $photo->owner_type == 'user')) { $photoOwnerId = $photo->owner_id; } } // if it is from your own profile album do not make copies of the image if ($photo instanceof Album_Model_Photo && ($photoParent = $photo->getParent()) instanceof Album_Model_Album && $photoParent->owner_id == $photoOwnerId && $photoParent->type == 'profile') { // ensure thumb.icon and thumb.profile exist $newStorageFile = Engine_Api::_()->getItem('storage_file', $photo->file_id); $filesTable = Engine_Api::_()->getDbtable('files', 'storage'); if ($photo->file_id == $filesTable->lookupFile($photo->file_id, 'thumb.profile')) { try { $tmpFile = $newStorageFile->temporary(); $image = Engine_Image::factory(); $image->open($tmpFile)->resize(200, 400)->write($tmpFile)->destroy(); $iProfile = $filesTable->createFile($tmpFile, array('parent_type' => $user->getType(), 'parent_id' => $user->getIdentity(), 'user_id' => $user->getIdentity(), 'name' => basename($tmpFile))); $newStorageFile->bridge($iProfile, 'thumb.profile'); @unlink($tmpFile); } catch (Exception $e) { echo $e; die; } } if ($photo->file_id == $filesTable->lookupFile($photo->file_id, 'thumb.icon')) { try { $tmpFile = $newStorageFile->temporary(); $image = Engine_Image::factory(); $image->open($tmpFile); $size = min($image->height, $image->width); $x = ($image->width - $size) / 2; $y = ($image->height - $size) / 2; $image->resample($x, $y, $size, $size, 48, 48)->write($tmpFile)->destroy(); $iSquare = $filesTable->createFile($tmpFile, array('parent_type' => $user->getType(), 'parent_id' => $user->getIdentity(), 'user_id' => $user->getIdentity(), 'name' => basename($tmpFile))); $newStorageFile->bridge($iSquare, 'thumb.icon'); @unlink($tmpFile); } catch (Exception $e) { echo $e; die; } } // Set it $user->photo_id = $photo->file_id; $user->save(); // Insert activity // @todo maybe it should read "changed their profile photo" ? $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($user, $user, 'profile_photo_update', '{item:$subject} changed their profile photo.'); if ($action) { // We have to attach the user himself w/o album plugin Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $photo); } } else { $user->setPhoto($photo); // Insert activity $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($user, $user, 'profile_photo_update', '{item:$subject} added a new profile photo.'); // Hooks to enable albums to work $newStorageFile = Engine_Api::_()->getItem('storage_file', $user->photo_id); $event = Engine_Hooks_Dispatcher::_()->callEvent('onUserProfilePhotoUpload', array('user' => $user, 'file' => $newStorageFile)); $attachment = $event->getResponse(); if (!$attachment) { $attachment = $newStorageFile; } if ($action) { // We have to attach the user himself w/o album plugin Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $attachment); } } $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } return $this->_forward('success', 'utility', 'core', array('messages' => array(Zend_Registry::get('Zend_Translate')->_('Set as profile photo')), 'smoothboxClose' => true)); }
public function cropAction() { if (!$this->_helper->requireSubject('album_photo')->isValid()) { return; } if (!$this->_helper->requireAuth()->setAuthParams(null, null, 'edit')->isValid()) { return; } if (!$this->getRequest()->isPost()) { $this->view->status = false; $this->view->error = $this->view->translate('Invalid method'); return; } $viewer = Engine_Api::_()->user()->getViewer(); $photo = Engine_Api::_()->core()->getSubject('album_photo'); $x = (int) $this->_getParam('x', 0); $y = (int) $this->_getParam('y', 0); $w = (int) $this->_getParam('w', 0); $h = (int) $this->_getParam('h', 0); // Get file $file = Engine_Api::_()->getItem('storage_file', $photo->file_id); if (!$file instanceof Storage_Model_File) { $this->view->status = false; $this->view->error = $this->view->translate('Could not retrieve file'); return; } // Pull photo to a temporary file $tmpFile = $file->temporary(); // Open the file $image = Engine_Image::factory(); $image->open($tmpFile); $curH = $image->getHeight(); $curW = $image->getWidth(); // Check the parameters if ($x < 0 || $y < 0 || $w < 0 || $h < 0 || $x + $w > $curW || $y + $h > $curH) { $this->view->status = false; $this->view->error = $this->view->translate('Invalid size'); return; } $image->open($tmpFile)->crop($x, $y, $w, $h)->write()->destroy(); // Set the photo $db = $photo->getTable()->getAdapter(); $db->beginTransaction(); try { $photo->setPhoto($tmpFile); @unlink($tmpFile); $db->commit(); } catch (Exception $e) { @unlink($tmpFile); $db->rollBack(); throw $e; } $this->view->status = true; $this->view->href = $photo->getPhotoUrl(); }
public function setPhoto($photo, $params) { if ($photo instanceof Zend_Form_Element_File) { $file = $photo->getFileName(); $name = basename($file); } else { if (is_array($photo) && !empty($photo['tmp_name'])) { $file = $photo['tmp_name']; $name = $photo['name']; } else { if (is_string($photo) && file_exists($photo)) { $file = $photo; $name = basename($file); } else { throw new Ynfeedback_Model_Exception('Invalid argument passed to setPhoto: ' . print_r($photo, 1)); } } } $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; if (empty($params)) { $params = array('parent_type' => 'user', 'parent_id' => Engine_Api::_()->user()->getViewer()->getIdentity()); } // Save $storage = Engine_Api::_()->storage(); $angle = 0; if (function_exists('exif_read_data')) { $exif = exif_read_data($file); if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 8: $angle = 90; break; case 3: $angle = 180; break; case 6: $angle = -90; break; } } } // Resize image (main) $image = Engine_Image::factory(); $image->open($file); if ($angle != 0) { $image->rotate($angle); } $image->resize(720, 720)->write($path . '/m_' . $name)->destroy(); // Resize image (profile) $image = Engine_Image::factory(); $image->open($file); if ($angle != 0) { $image->rotate($angle); } $image->resize(200, 400)->write($path . '/p_' . $name)->destroy(); // Resize image (normal) $image = Engine_Image::factory(); @$image->open($file); if ($angle != 0) { $image->rotate($angle); } $image->resize(140, 105)->write($path . '/in_' . $name)->destroy(); // Resize image (icon) $image = Engine_Image::factory(); $image->open($file); $size = min($image->height, $image->width); $x = ($image->width - $size) / 2; $y = ($image->height - $size) / 2; $image->resample($x, $y, $size, $size, 48, 48)->write($path . '/is_' . $name)->destroy(); // Store $iMain = $storage->create($path . '/m_' . $name, $params); $iProfile = $storage->create($path . '/p_' . $name, $params); $iIconNormal = $storage->create($path . '/in_' . $name, $params); $iSquare = $storage->create($path . '/is_' . $name, $params); $iMain->bridge($iProfile, 'thumb.profile'); $iMain->bridge($iIconNormal, 'thumb.normal'); $iMain->bridge($iSquare, 'thumb.icon'); // Remove temp files @unlink($path . '/p_' . $name); @unlink($path . '/m_' . $name); @unlink($path . '/in_' . $name); @unlink($path . '/is_' . $name); // Update row return $iMain->getIdentity(); }
public function setPhoto($photo) { if ($photo instanceof Zend_Form_Element_File) { $file = $photo->getFileName(); $fileName = $file; } else { if ($photo instanceof Storage_Model_File) { $file = $photo->temporary(); $fileName = $photo->name; } else { if ($photo instanceof Core_Model_Item_Abstract && !empty($photo->file_id)) { $tmpRow = Engine_Api::_()->getItem('storage_file', $photo->file_id); $file = $tmpRow->temporary(); $fileName = $tmpRow->name; } else { if (is_array($photo) && !empty($photo['tmp_name'])) { $file = $photo['tmp_name']; $fileName = $photo['name']; } else { if (is_string($photo) && file_exists($photo)) { $file = $photo; $fileName = $photo; } else { throw new User_Model_Exception('invalid argument passed to setPhoto'); } } } } } if (!$fileName) { $fileName = $file; } $name = basename($file); $extension = ltrim(strrchr($fileName, '.'), '.'); $base = rtrim(substr(basename($fileName), 0, strrpos(basename($fileName), '.')), '.'); $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; $params = array('parent_type' => $this->getType(), 'parent_id' => $this->getIdentity(), 'user_id' => $this->owner_id, 'name' => $fileName); // Save $filesTable = Engine_Api::_()->getDbtable('files', 'storage'); // Resize image (main) $mainPath = $path . DIRECTORY_SEPARATOR . $base . '_m.' . $extension; $image = Engine_Image::factory(); $image->open($file)->resize(720, 720)->write($mainPath)->destroy(); // Resize image (normal) $normalPath = $path . DIRECTORY_SEPARATOR . $base . '_in.' . $extension; $image = Engine_Image::factory(); $image->open($file)->resize(140, 160)->write($normalPath)->destroy(); // Store try { $iMain = $filesTable->createFile($mainPath, $params); $iIconNormal = $filesTable->createFile($normalPath, $params); $iMain->bridge($iIconNormal, 'thumb.normal'); } catch (Exception $e) { // Remove temp files @unlink($mainPath); @unlink($normalPath); // Throw if ($e->getCode() == Storage_Model_DbTable_Files::SPACE_LIMIT_REACHED_CODE) { throw new Album_Model_Exception($e->getMessage(), $e->getCode()); } else { throw $e; } } // Remove temp files @unlink($mainPath); @unlink($normalPath); // Update row $this->modified_date = date('Y-m-d H:i:s'); $this->file_id = $iMain->file_id; $this->save(); // Delete the old file? if (!empty($tmpRow)) { $tmpRow->delete(); } return $this; }
public function photoAction() { $this->view->user = $user = Engine_Api::_()->core()->getSubject(); $this->view->viewer = $viewer = $this->_helper->api()->user()->getViewer(); // remove styles if users are not allowed to style page $style_perm = Engine_Api::_()->getDbtable('permissions', 'authorization')->getAllowed('user', $user->level_id, 'style'); if (!$style_perm) { $this->view->navigation->removePage(2); } // Get form $this->view->form = $form = new User_Form_Edit_Photo(); if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return; } // Uploading a new photo if ($form->Filedata->getValue() !== null) { $db = $user->getTable()->getAdapter(); $db->beginTransaction(); try { $fileElement = $form->Filedata; $user->setPhoto($fileElement); $iMain = Engine_Api::_()->getItem('storage_file', $user->photo_id); // Insert activity $action = Engine_Api::_()->getDbtable('actions', 'activity')->addActivity($user, $user, 'profile_photo_update', '{item:$subject} added a new profile photo.'); // Hooks to enable albums to work if ($action) { $event = Engine_Hooks_Dispatcher::_()->callEvent('onUserProfilePhotoUpload', array('user' => $user, 'file' => $iMain)); $attachment = $event->getResponse(); if (!$attachment) { $attachment = $iMain; } // We have to attach the user himself w/o album plugin Engine_Api::_()->getDbtable('actions', 'activity')->attachActivity($action, $attachment); } $db->commit(); } catch (Engine_Image_Adapter_Exception $e) { $db->rollBack(); $form->addError(Zend_Registry::get('Zend_Translate')->_('The uploaded file is not supported or is corrupt.')); } catch (Exception $e) { $db->rollBack(); throw $e; } } else { if ($form->getValue('coordinates') !== '') { $storage = Engine_Api::_()->storage(); $iProfile = $storage->get($user->photo_id, 'thumb.profile'); $iSquare = $storage->get($user->photo_id, 'thumb.icon'); // Read into tmp file $pName = $iProfile->getStorageService()->temporary($iProfile); $iName = dirname($pName) . '/nis_' . basename($pName); list($x, $y, $w, $h) = explode(':', $form->getValue('coordinates')); $image = Engine_Image::factory(); $image->open($pName)->resample($x + 0.1, $y + 0.1, $w - 0.1, $h - 0.1, 48, 48)->write($iName)->destroy(); $iSquare->store($iName); // Remove temp files @unlink($iName); } } }
public function cropPhotoAction() { $this->view->group = $group = Engine_Api::_()->core()->getSubject(); $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer(); // Get form $this->view->form = $form = new User_Form_Edit_CropPhoto(); if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return; } // Resizing a photo if ($form->getValue('coordinates') !== '') { $storage = Engine_Api::_()->storage(); $iMain = $storage->get($group->photo_id, 'thumb.main'); $iProfile = $storage->get($group->photo_id, 'thumb.profile'); // Read into tmp file $pName = $iMain->getStorageService()->temporary($iMain); $iName = dirname($pName) . '/nis_' . basename($pName); list($x, $y, $w, $h) = explode(':', $form->getValue('coordinates')); $image = Engine_Image::factory(); $image->open($pName)->resample($x + 0.1, $y + 0.1, $w - 0.1, $h - 0.1, 200, 200)->write($iName)->destroy(); $iProfile->store($iName); // Remove temp files @unlink($iName); } $this->_forward('success', 'utility', 'core', array('smoothboxClose' => true, 'parentRefresh' => true, 'messages' => array(Zend_Registry::get('Zend_Translate')->_('Your changes have been saved.')))); }
protected function _translatePhoto($file, array $params) { if (!file_exists($file)) { return false; } $name = basename($file); $temporaryDirectory = $this->_sys_get_temp_dir(); $mainFile = $temporaryDirectory . '/m_' . $name; $profileFile = $temporaryDirectory . '/p_' . $name; $normalFile = $temporaryDirectory . '/n_' . $name; $squareFile = $temporaryDirectory . '/s_' . $name; // Resize image (main) $image = Engine_Image::factory(); $image->open($file)->resize(720, 720)->write($mainFile)->destroy(); // Resize image (profile) $image = Engine_Image::factory(); $image->open($file)->resize(200, 400)->write($profileFile)->destroy(); // Resize image (normal) $image = Engine_Image::factory(); $image->open($file)->resize(140, 160)->write($normalFile)->destroy(); // Resize image (icon) $image = Engine_Image::factory(); $image->open($file); $size = min($image->height, $image->width); $x = ($image->width - $size) / 2; $y = ($image->height - $size) / 2; $image->resample($x, $y, $size, $size, 48, 48)->write($squareFile)->destroy(); // Store $file_id = $this->_translateFile($mainFile, $params, false); if (!$file_id) { return false; } $this->_translateFile($profileFile, array_merge($params, array('parent_file_id' => $file_id, 'type' => 'thumb.profile')), false); $this->_translateFile($normalFile, array_merge($params, array('parent_file_id' => $file_id, 'type' => 'thumb.normal')), false); $this->_translateFile($squareFile, array_merge($params, array('parent_file_id' => $file_id, 'type' => 'thumb.icon')), false); // Remove temp files @unlink($mainFile); @unlink($profileFile); @unlink($normalFile); @unlink(${$squareFile}); return $file_id; }
protected function _process($video) { // Make sure FFMPEG path is set $ffmpeg_path = Engine_Api::_()->getApi('settings', 'core')->video_ffmpeg_path; if (!$ffmpeg_path) { throw new Video_Model_Exception('Ffmpeg not configured'); } // Make sure FFMPEG can be run if (!@file_exists($ffmpeg_path) || !@is_executable($ffmpeg_path)) { $output = null; $return = null; exec($ffmpeg_path . ' -version', $output, $return); if ($return > 0) { throw new Video_Model_Exception('Ffmpeg found, but is not executable'); } } // Check we can execute if (!function_exists('shell_exec')) { throw new Video_Model_Exception('Unable to execute shell commands using shell_exec(); the function is disabled.'); } // Check the video temporary directory $tmpDir = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary' . DIRECTORY_SEPARATOR . 'video'; if (!is_dir($tmpDir)) { if (!mkdir($tmpDir, 0777, true)) { throw new Video_Model_Exception('Video temporary directory did not exist and could not be created.'); } } if (!is_writable($tmpDir)) { throw new Video_Model_Exception('Video temporary directory is not writable.'); } // Get the video object if (is_numeric($video)) { $video = Engine_Api::_()->getItem('video', $video_id); } if (!$video instanceof Video_Model_Video) { throw new Video_Model_Exception('Argument was not a valid video'); } // Update to encoding status $video->status = 2; $video->save(); // Prepare information $owner = $video->getOwner(); $filetype = $video->code; $originalPath = $tmpDir . DIRECTORY_SEPARATOR . $video->getIdentity() . '.' . $filetype; $outputPath = $tmpDir . DIRECTORY_SEPARATOR . $video->getIdentity() . '_vconverted.flv'; $thumbPath = $tmpDir . DIRECTORY_SEPARATOR . $video->getIdentity() . '_vthumb.jpg'; $videoCommand = $ffmpeg_path . ' ' . '-i ' . escapeshellarg($originalPath) . ' ' . '-ab 64k' . ' ' . '-ar 44100' . ' ' . '-qscale 5' . ' ' . '-vcodec flv' . ' ' . '-f flv' . ' ' . '-r 25' . ' ' . '-s 480x386' . ' ' . '-v 2' . ' ' . '-y ' . escapeshellarg($outputPath) . ' ' . '2>&1'; $thumbCommand = $ffmpeg_path . ' ' . '-i ' . escapeshellarg($outputPath) . ' ' . '-f image2' . ' ' . '-ss 4.00' . ' ' . '-v 2' . ' ' . '-y ' . escapeshellarg($thumbPath) . ' ' . '2>&1'; // Prepare output header $output = PHP_EOL; $output .= $originalPath . PHP_EOL; $output .= $outputPath . PHP_EOL; $output .= $thumbPath . PHP_EOL; // Prepare logger $log = null; //if( APPLICATION_ENV == 'development' ) { $log = new Zend_Log(); $log->addWriter(new Zend_Log_Writer_Stream(APPLICATION_PATH . '/temporary/log/video.log')); //} // Execute video encode command $videoOutput = $output . $videoCommand . PHP_EOL . shell_exec($videoCommand); // Log if ($log) { $log->log($videoOutput, Zend_Log::INFO); } // Check for failure $success = true; // Unsupported format if (preg_match('/Unknown format/i', $videoOutput) || preg_match('/Unsupported codec/i', $videoOutput) || preg_match('/patch welcome/i', $videoOutput) || !is_file($outputPath) || filesize($outputPath) <= 0) { $success = false; $video->status = 3; } else { if (preg_match('/video:0kB/i', $videoOutput)) { $success = false; $video->status = 5; } } // Failure if (!$success) { $db = $video->getTable()->getAdapter(); $db->beginTransaction(); try { $video->save(); // notify the owner $translate = Zend_Registry::get('Zend_Translate'); $language = !empty($owner->language) && $owner->language != 'auto' ? $owner->language : null; $notificationMessage = ''; if ($video->status == 3) { $notificationMessage = $translate->translate(sprintf('Video conversion failed. Video format is not supported by FFMPEG. Please try %1$sagain%2$s.', '', ''), $language); } else { if ($video->status == 5) { $notificationMessage = $translate->translate(sprintf('Video conversion failed. Audio files are not supported. Please try %1$sagain%2$s.', '', ''), $language); } } Engine_Api::_()->getDbtable('notifications', 'activity')->addNotification($owner, $owner, $video, 'video_processed_failed', array('message' => $notificationMessage, 'message_link' => Zend_Controller_Front::getInstance()->getRouter()->assemble(array('action' => 'manage'), 'video_general', true))); $db->commit(); } catch (Exception $e) { $videoOutput .= PHP_EOL . $e->__toString() . PHP_EOL; if ($log) { $log->write($e->__toString(), Zend_Log::ERR); } $db->rollBack(); } // Write to additional log in dev if (APPLICATION_ENV == 'development') { file_put_contents($tmpDir . '/' . $video->video_id . '.txt', $videoOutput); } } else { // Get duration of the video to caculate where to get the thumbnail if (preg_match('/Duration:\\s+(.*?)[.]/i', $videoOutput, $matches)) { list($hours, $minutes, $seconds) = preg_split('[:]', $matches[1]); $duration = ceil($seconds + $minutes * 60 + $hours * 3600); } else { $duration = 0; // Hmm } // Log duration if ($log) { $log->log('Duration: ' . $duration, Zend_Log::INFO); } // Process thumbnail $thumbOutput = $output . $thumbCommand . PHP_EOL . shell_exec($thumbCommand); // Log thumb output if ($log) { $log->log($thumbOutput, Zend_Log::INFO); } // Resize thumbnail $image = Engine_Image::factory(); $image->open($thumbPath)->resize(120, 240)->write($thumbPath)->destroy(); // Save video and thumbnail to storage system $params = array('parent_id' => $video->getIdentity(), 'parent_type' => $video->getType(), 'user_id' => $video->owner_id); $db = $video->getTable()->getAdapter(); $db->beginTransaction(); try { $videoFileRow = Engine_Api::_()->storage()->create($outputPath, $params); $thumbFileRow = Engine_Api::_()->storage()->create($thumbPath, $params); $db->commit(); } catch (Exception $e) { $db->rollBack(); // delete the files from temp dir unlink($originalPath); unlink($outputPath); unlink($thumbPath); $video->status = 7; $video->save(); // notify the owner $translate = Zend_Registry::get('Zend_Translate'); $notificationMessage = ''; $language = !empty($owner->language) && $owner->language != 'auto' ? $owner->language : null; if ($video->status == 7) { $notificationMessage = $translate->translate(sprintf('Video conversion failed. You may be over the site upload limit. Try %1$suploading%2$s a smaller file, or delete some files to free up space.', '', ''), $language); } Engine_Api::_()->getDbtable('notifications', 'activity')->addNotification($owner, $owner, $video, 'video_processed_failed', array('message' => $notificationMessage, 'message_link' => Zend_Controller_Front::getInstance()->getRouter()->assemble(array('action' => 'manage'), 'video_general', true))); throw $e; // throw } // Video processing was a success! // Save the information $video->file_id = $videoFileRow->file_id; $video->photo_id = $thumbFileRow->file_id; $video->duration = $duration; $video->status = 1; $video->save(); // delete the files from temp dir unlink($originalPath); unlink($outputPath); unlink($thumbPath); // insert action in a seperate transaction if video status is a success $actionsTable = Engine_Api::_()->getDbtable('actions', 'activity'); $db = $actionsTable->getAdapter(); $db->beginTransaction(); try { // new action $action = $actionsTable->addActivity($owner, $video, 'video_new'); if ($action) { $actionsTable->attachActivity($action, $video); } // notify the owner Engine_Api::_()->getDbtable('notifications', 'activity')->addNotification($owner, $owner, $video, 'video_processed'); $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; // throw } } }
public function flipAction() { $album_id = $this->_getParam('album_id', 0); $photo_id = $this->_getParam('photo_id', 0); $dest = $this->_getParam('dest', 'vertical'); $this->view->photo = $photo = Engine_Api::_()->core()->getSubject(); $can_edit = FALSE; if ($photo) { $this->view->album = $album = Engine_Api::_()->getItem('advalbum_album', $photo->album_id); $can_edit = $this->_helper->requireAuth()->setAuthParams($album, null, 'edit')->checkRequire(); } $is_login = $this->_helper->requireUser()->isValid(); $parentRefresh = false; $first_call = false; $session_AdvAlbumFlip = new Zend_Session_Namespace('AdvAlbumFlip'); if (!isset($session_AdvAlbumFlip->dest) || $session_AdvAlbumFlip->dest != $dest || !isset($session_AdvAlbumFlip->photo_id) || $session_AdvAlbumFlip->photo_id != $photo_id) { $parentRefresh = true; $first_call = true; $session_AdvAlbumFlip->dest = $dest; $session_AdvAlbumFlip->photo_id = $photo_id; } if (!$photo || !$is_login || !$can_edit || !$first_call) { $this->_forward('success', 'utility', 'core', array('smoothboxClose' => true, 'parentRefresh' => false, 'format' => 'smoothbox', 'messages' => array('No permission!'))); return; } if (!in_array($dest, array('vertical', 'horizontal'))) { $this->view->status = false; $this->view->error = $this->view->translate('Invalid direction'); return; } // Get file $file = Engine_Api::_()->getItem('storage_file', $photo->file_id); if (!$file instanceof Storage_Model_File) { $this->view->status = false; $this->view->error = $this->view->translate('Could not retrieve file'); return; } // Pull photo to a temporary file $tmpFile = $file->temporary(); // Operate on the file $image = Engine_Image::factory(); $image->open($tmpFile)->flip($dest != 'vertical')->write()->destroy(); // Set the photo $db = $photo->getTable()->getAdapter(); $db->beginTransaction(); try { $viewer = Engine_Api::_()->user()->getViewer(); $params = array('owner_type' => 'user', 'owner_id' => $viewer->getIdentity()); Engine_Api::_()->advalbum()->createPhoto($params, $tmpFile, $photo); @unlink($tmpFile); $db->commit(); } catch (Exception $e) { @unlink($tmpFile); $db->rollBack(); throw $e; } $this->_forward('success', 'utility', 'core', array('smoothboxClose' => true, 'parentRefresh' => $parentRefresh, 'format' => 'smoothbox', 'messages' => array('Your changes have been saved.'))); }
private function _getUploadedFile() { $fullFilePath = ''; $upload = new Zend_File_Transfer_Adapter_Http(); if ($upload->getFileName('photo')) { $destination = "public/ynvideo_category/"; if (!is_dir($destination)) { mkdir($destination); } $upload->setDestination($destination); $fullFilePath = $destination . time() . '_' . $upload->getFileName('photo', false); $image = Engine_Image::factory(); $image->open($_FILES['photo']['tmp_name']) ->resize(128, 128) ->write($fullFilePath); } return $fullFilePath; }
public function setPhoto($photo) { if ($photo instanceof Zend_Form_Element_File) { $file = $photo->getFileName(); } else { if (is_array($photo) && !empty($photo['tmp_name'])) { $file = $photo['tmp_name']; } else { if (is_string($photo) && file_exists($photo)) { $file = $photo; } else { throw new Group_Model_Exception('invalid argument passed to setPhoto'); } } } $name = basename($file); $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; $params = array('parent_type' => 'group', 'parent_id' => $this->getIdentity()); // Save $storage = Engine_Api::_()->storage(); // Resize image (main) $image = Engine_Image::factory(); $image->open($file)->resize(720, 720)->write($path . '/m_' . $name)->destroy(); // Resize image (profile) $image = Engine_Image::factory(); $image->open($file)->resize(200, 400)->write($path . '/p_' . $name)->destroy(); // Resize image (normal) $image = Engine_Image::factory(); $image->open($file)->resize(140, 160)->write($path . '/in_' . $name)->destroy(); // Resize image (icon) $image = Engine_Image::factory(); $image->open($file); $size = min($image->height, $image->width); $x = ($image->width - $size) / 2; $y = ($image->height - $size) / 2; $image->resample($x, $y, $size, $size, 48, 48)->write($path . '/is_' . $name)->destroy(); // Store $iMain = $storage->create($path . '/m_' . $name, $params); $iProfile = $storage->create($path . '/p_' . $name, $params); $iIconNormal = $storage->create($path . '/in_' . $name, $params); $iSquare = $storage->create($path . '/is_' . $name, $params); $iMain->bridge($iProfile, 'thumb.profile'); $iMain->bridge($iIconNormal, 'thumb.normal'); $iMain->bridge($iSquare, 'thumb.icon'); // Remove temp files @unlink($path . '/p_' . $name); @unlink($path . '/m_' . $name); @unlink($path . '/in_' . $name); @unlink($path . '/is_' . $name); // Update row $this->modified_date = date('Y-m-d H:i:s'); $this->photo_id = $iMain->file_id; $this->save(); // Add to album $viewer = Engine_Api::_()->user()->getViewer(); $photoTable = Engine_Api::_()->getItemTable('group_photo'); $groupAlbum = $this->getSingletonAlbum(); $photoItem = $photoTable->createRow(); $photoItem->setFromArray(array('group_id' => $this->getIdentity(), 'album_id' => $groupAlbum->getIdentity(), 'user_id' => $viewer->getIdentity(), 'file_id' => $iMain->getIdentity(), 'collection_id' => $groupAlbum->getIdentity())); $photoItem->save(); return $this; }
public function setPhoto($photo) { if ($photo instanceof Zend_Form_Element_File) { $file = $photo->getFileName(); $fileName = $file; } else { if ($photo instanceof Storage_Model_File) { $file = $photo->temporary(); $fileName = $photo->name; } else { if ($photo instanceof Core_Model_Item_Abstract && !empty($photo->file_id)) { $tmpRow = Engine_Api::_()->getItem('storage_file', $photo->file_id); $file = $tmpRow->temporary(); $fileName = $tmpRow->name; } else { if (is_array($photo) && !empty($photo['tmp_name'])) { $file = $photo['tmp_name']; $fileName = $photo['name']; } else { if (is_string($photo) && file_exists($photo)) { $file = $photo; $fileName = $photo; } else { throw new Classified_Model_Exception('invalid argument passed to setPhoto'); } } } } } if (!$fileName) { $fileName = basename($file); } $extension = ltrim(strrchr(basename($fileName), '.'), '.'); $base = rtrim(substr(basename($fileName), 0, strrpos(basename($fileName), '.')), '.'); $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary'; $params = array('parent_type' => $this->getType(), 'parent_id' => $this->getIdentity(), 'user_id' => $this->user_id, 'name' => $fileName); // Save $filesTable = Engine_Api::_()->getItemTable('storage_file'); // Resize image (main) $mainPath = $path . DIRECTORY_SEPARATOR . $base . '_m.' . $extension; $image = Engine_Image::factory(); $exif = exif_read_data($file); $angle = 0; if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 8: $angle = 90; break; case 3: $angle = 180; break; case 6: $angle = -90; break; } } $image->open($file); if ($angle != 0) { $image->rotate($angle); } $image->resize(720, 720)->write($mainPath)->destroy(); // Resize image (normal) $normalPath = $path . DIRECTORY_SEPARATOR . $base . '_in.' . $extension; $image = Engine_Image::factory(); $image->open($file); if ($angle != 0) { $image->rotate($angle); } $image->resize(140, 160)->write($normalPath)->destroy(); // Store $iMain = $filesTable->createFile($mainPath, $params); $iIconNormal = $filesTable->createFile($normalPath, $params); $iMain->bridge($iIconNormal, 'thumb.normal'); // Remove temp files @unlink($mainPath); @unlink($normalPath); // Update row $this->modified_date = date('Y-m-d H:i:s'); $this->file_id = $iMain->file_id; $this->save(); return $this; }
public function composeUploadAction() { $viewer = Engine_Api::_()->user()->getViewer(); if (!$viewer->getIdentity()) { $this->_redirect('login'); return; } if (!$this->getRequest()->isPost()) { $this->view->status = false; $this->view->error = Zend_Registry::get('Zend_Translate')->_('Invalid method'); return; } $video_title = $this->_getParam('title'); $video_url = $this->_getParam('uri'); $video_type = $this->_getParam('type'); $composer_type = $this->_getParam('c_type', 'wall'); // extract code //$code = $this->extractCode("http://www.youtube.com/watch?v=5osJ8-NttnU&feature=popt00us08", $video_type); //$code = parse_url("http://vimeo.com/3945157/asd243", PHP_URL_PATH); $code = $this->extractCode($video_url, $video_type); // check if code is valid // check which API should be used if ($video_type == 1) { $valid = $this->checkYouTube($code); } if ($video_type == 2) { $valid = $this->checkVimeo($code); } // check to make sure the user has not met their quota of # of allowed video uploads // set up data needed to check quota $values['user_id'] = $viewer->getIdentity(); $paginator = Engine_Api::_()->getApi('core', 'video')->getVideosPaginator($values); $quota = Engine_Api::_()->authorization()->getPermission($viewer->level_id, 'video', 'max'); $current_count = $paginator->getTotalItemCount(); if ($current_count >= $quota && !empty($quota)) { // return error message $this->view->message = Zend_Registry::get('Zend_Translate')->_('You have already uploaded the maximum number of videos allowed. If you would like to upload a new video, please delete an old one first.'); } else { if ($valid) { $db = Engine_Api::_()->getDbtable('videos', 'video')->getAdapter(); $db->beginTransaction(); try { $information = $this->handleInformation($video_type, $code); // create video $table = Engine_Api::_()->getDbtable('videos', 'video'); $video = $table->createRow(); $video->title = $information['title']; $video->description = $information['description']; $video->duration = $information['duration']; $video->owner_id = $viewer->getIdentity(); $video->code = $code; $video->type = $video_type; $video->save(); // Now try to create thumbnail $thumbnail = $this->handleThumbnail($video->type, $video->code); $ext = ltrim(strrchr($thumbnail, '.'), '.'); $thumbnail_parsed = @parse_url($thumbnail); $tmp_file = APPLICATION_PATH . '/temporary/link_' . md5($thumbnail) . '.' . $ext; $thumb_file = APPLICATION_PATH . '/temporary/link_thumb_' . md5($thumbnail) . '.' . $ext; $src_fh = fopen($thumbnail, 'r'); $tmp_fh = fopen($tmp_file, 'w'); stream_copy_to_stream($src_fh, $tmp_fh, 1024 * 1024 * 2); $image = Engine_Image::factory(); $image->open($tmp_file)->resize(120, 240)->write($thumb_file)->destroy(); $thumbFileRow = Engine_Api::_()->storage()->create($thumb_file, array('parent_type' => $video->getType(), 'parent_id' => $video->getIdentity())); // If video is from the composer, keep it hidden until the post is complete if ($composer_type) { $video->search = 0; } $video->photo_id = $thumbFileRow->file_id; $video->status = 1; $video->save(); $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } // make the video public if ($composer_type === 'wall') { // CREATE AUTH STUFF HERE $auth = Engine_Api::_()->authorization()->context; $roles = array('owner', 'owner_member', 'owner_member_member', 'owner_network', 'registered', 'everyone'); foreach ($roles as $i => $role) { $auth->setAllowed($video, $role, 'view', $i <= $roles); $auth->setAllowed($video, $role, 'comment', $i <= $roles); } } $this->view->status = true; $this->view->video_id = $video->video_id; $this->view->photo_id = $video->photo_id; $this->view->title = $video->title; $this->view->description = $video->description; $this->view->src = $video->getPhotoUrl(); $this->view->message = Zend_Registry::get('Zend_Translate')->_('Video posted successfully'); } else { $this->view->message = Zend_Registry::get('Zend_Translate')->_('We could not find a video there - please check the URL and try again.'); } } }