/** * Returns class instance * * @return PHOTO_BOL_PhotoTemporaryService */ public static function getInstance() { if (null === self::$classInstance) { self::$classInstance = new self(); } return self::$classInstance; }
public function __construct($albumId = NULL, $albumName = NULL, $albumDescription = null, $url = NULL) { if (!OW::getUser()->isAuthorized('photo', 'upload')) { $this->setVisible(FALSE); return; } $userId = OW::getUser()->getId(); $document = OW::getDocument(); PHOTO_BOL_PhotoTemporaryService::getInstance()->deleteUserTemporaryPhotos($userId); $plugin = OW::getPluginManager()->getPlugin('photo'); $document->addStyleSheet($plugin->getStaticCssUrl() . 'photo_upload.css'); $document->addScript($plugin->getStaticJsUrl() . 'jQueryRotate.min.js'); $document->addScript($plugin->getStaticJsUrl() . 'codemirror.min.js'); $document->addScript($plugin->getStaticJsUrl() . 'upload.js'); $document->addScriptDeclarationBeforeIncludes(UTIL_JsGenerator::composeJsString(';window.ajaxPhotoUploadParams = {}; Object.defineProperties(ajaxPhotoUploadParams, { actionUrl: { value: {$url}, writable: false, enumerable: true }, maxFileSize: { value: {$size}, writable: false, enumerable: true }, deleteAction: { value: {$deleteAction}, writable: false, enumerable: true } });', array('url' => OW::getRouter()->urlForRoute('photo.ajax_upload'), 'size' => PHOTO_BOL_PhotoService::getInstance()->getMaxUploadFileSize(), 'deleteAction' => OW::getRouter()->urlForRoute('photo.ajax_upload_delete')))); $document->addOnloadScript(';window.ajaxPhotoUploader.init();'); $this->addForm(new PHOTO_CLASS_AjaxUploadForm('user', $userId, $albumId, $albumName, $albumDescription, $url)); $newsfeedAlbum = PHOTO_BOL_PhotoAlbumService::getInstance()->getNewsfeedAlbum($userId); $this->assign('albumNameList', PHOTO_BOL_PhotoAlbumService::getInstance()->findAlbumNameListByUserId($userId, !empty($newsfeedAlbum) ? array($newsfeedAlbum->id) : array())); $language = OW::getLanguage(); $language->addKeyForJs('photo', 'not_all_photos_uploaded'); $language->addKeyForJs('photo', 'size_limit'); $language->addKeyForJs('photo', 'type_error'); $language->addKeyForJs('photo', 'dnd_support'); $language->addKeyForJs('photo', 'dnd_not_support'); $language->addKeyForJs('photo', 'drop_here'); $language->addKeyForJs('photo', 'please_wait'); $language->addKeyForJs('photo', 'create_album'); $language->addKeyForJs('photo', 'album_name'); $language->addKeyForJs('photo', 'album_desc'); $language->addKeyForJs('photo', 'describe_photo'); $language->addKeyForJs('photo', 'photo_upload_error'); }
public function __construct($albumId = null, $albumName = null, $albumDescription = null, $url = null, $data = null) { parent::__construct(); if (!OW::getUser()->isAuthorized('photo', 'upload')) { $this->setVisible(false); return; } $userId = OW::getUser()->getId(); $document = OW::getDocument(); PHOTO_BOL_PhotoTemporaryService::getInstance()->deleteUserTemporaryPhotos($userId); $plugin = OW::getPluginManager()->getPlugin('photo'); $document->addStyleSheet($plugin->getStaticCssUrl() . 'photo_upload.css'); $document->addScript($plugin->getStaticJsUrl() . 'codemirror.min.js'); $document->addScript($plugin->getStaticJsUrl() . 'upload.js'); $document->addScriptDeclarationBeforeIncludes(UTIL_JsGenerator::composeJsString(';window.ajaxPhotoUploadParams = Object.freeze({$params});', array('params' => array('actionUrl' => OW::getRouter()->urlForRoute('photo.ajax_upload'), 'maxFileSize' => PHOTO_BOL_PhotoService::getInstance()->getMaxUploadFileSize(), 'deleteAction' => OW::getRouter()->urlForRoute('photo.ajax_upload_delete'))))); $document->addOnloadScript(';window.ajaxPhotoUploader.init();'); $form = new PHOTO_CLASS_AjaxUploadForm('user', $userId, $albumId, $albumName, $albumDescription, $url, $data); $this->addForm($form); $this->assign('extendInputs', $form->getExtendedElements()); $this->assign('albumId', $albumId); $this->assign('userId', $userId); $newsfeedAlbum = PHOTO_BOL_PhotoAlbumService::getInstance()->getNewsfeedAlbum($userId); $exclude = !empty($newsfeedAlbum) ? array($newsfeedAlbum->id) : array(); $this->addComponent('albumNames', OW::getClassInstance('PHOTO_CMP_AlbumNameList', $userId, $exclude)); $language = OW::getLanguage(); $language->addKeyForJs('photo', 'not_all_photos_uploaded'); $language->addKeyForJs('photo', 'size_limit'); $language->addKeyForJs('photo', 'type_error'); $language->addKeyForJs('photo', 'dnd_support'); $language->addKeyForJs('photo', 'dnd_not_support'); $language->addKeyForJs('photo', 'drop_here'); $language->addKeyForJs('photo', 'please_wait'); $language->addKeyForJs('photo', 'create_album'); $language->addKeyForJs('photo', 'album_name'); $language->addKeyForJs('photo', 'album_desc'); $language->addKeyForJs('photo', 'describe_photo'); $language->addKeyForJs('photo', 'photo_upload_error'); }
* * */ //$app = new \Slim\Slim(); $app = new \Slim\Slim(); //$baseJsDir = OW::getPluginManager()->getPlugin("base")->getStaticJsUrl(); $BOL_UserDao = BOL_UserDao::getInstance(); $ow_user = OW::getUser(); $OW_Auth_inst = OW_Auth::getInstance(); $Userservice = BOL_UserService::getInstance(); $EmailVerifyService = BOL_EmailVerifyService::getInstance(); $BOL_AvatarService_inst = BOL_AvatarService::getInstance(); $SKAPI_BOL_Service_inst = SKAPI_BOL_Service::getInstance(); $PHOTO_BOL_PhotoService_inst = PHOTO_BOL_PhotoService::getInstance(); $PHOTO_BOL_PhotoAlbumService = PHOTO_BOL_PhotoAlbumService::getInstance(); $PHOTO_BOL_PhotoTemporaryService = PHOTO_BOL_PhotoTemporaryService::getInstance(); $UserResetPassword = BOL_UserResetPasswordDao::getInstance(); $QuestionService = BOL_QuestionService::getInstance(); $AccountTypeToGenderService = SKADATE_BOL_AccountTypeToGenderService::getInstance(); $BOL_AuthorizationService = BOL_AuthorizationService::getInstance(); $BOL_UserOnlineDao = BOL_UserOnlineDao::getInstance(); $USEARCH_BOL_Service = USEARCH_BOL_Service::getInstance(); $BOL_SearchService = BOL_SearchService::getInstance(); $getPluginManager = OW::getPluginManager(); $CONTACTUS_BOL_Service = CONTACTUS_BOL_Service::getInstance(); $PHOTO_BOL_PhotoService = PHOTO_BOL_PhotoService::getInstance(); $PHOTO_BOL_PhotoAlbumCoverDao = PHOTO_BOL_PhotoAlbumCoverDao::getInstance(); $PHOTO_BOL_PhotoDao = PHOTO_BOL_PhotoDao::getInstance(); $getRouter = OW::getRouter(); $language = OW::getLanguage(); $getMailer = OW::getMailer();
public function delete(array $params = array()) { if (!empty($_POST['id'])) { PHOTO_BOL_PhotoTemporaryService::getInstance()->deleteTemporaryPhoto((int) $_POST['id']); } exit; }
public function deleteLimitedPhotos() { PHOTO_BOL_PhotoTemporaryService::getInstance()->deleteLimitedPhotos(); }
public function feedBeforeStatusUpdate(OW_Event $e) { $params = $e->getParams(); if ($params['type'] == 'photo') { $status = BOL_AuthorizationService::getInstance()->getActionStatus('photo', 'upload'); if ($status['status'] != BOL_AuthorizationService::STATUS_AVAILABLE) { return; } $userId = OW::getUser()->getId(); $url = $params['data']['url']; $tmpFile = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . md5($userId . time()) . basename($url); copy($url, $tmpFile); if (!file_exists($tmpFile)) { return; } $albumName = OW::getLanguage()->text('photo', 'newsfeed_album'); $event = new OW_Event(self::EVENT_CREATE_USER_ALBUM, array('userId' => $userId, 'name' => $albumName)); OW::getEventManager()->trigger($event); $p = $event->getData(); if (empty($p['ablumId'])) { @unlink($tmpFile); return; } PHOTO_BOL_PhotoTemporaryService::getInstance()->deleteUserTemporaryPhotos($userId); $album = PHOTO_BOL_PhotoAlbumService::getInstance()->findAlbumById($p['ablumId']); $desc = $params['status']; if ($tmpId = PHOTO_BOL_PhotoTemporaryService::getInstance()->addTemporaryPhoto($tmpFile, $userId)) { $photo = PHOTO_BOL_PhotoTemporaryService::getInstance()->moveTemporaryPhoto($tmpId, $album->id, $desc); PHOTO_BOL_PhotoTemporaryService::getInstance()->deleteTemporaryPhoto($tmpId); BOL_AuthorizationService::getInstance()->trackAction('photo', 'upload', NULL, array('checkInterval' => FALSE)); $this->photoService->createAlbumCover($album->id, array($photo)); $albumUrl = OW::getRouter()->urlForRoute('photo_user_album', array('user' => BOL_UserService::getInstance()->getUserName($album->userId), 'album' => $album->id)); $data = array('photoIdList' => array($photo->id), 'string' => array('key' => 'photo+feed_single_description', 'vars' => array('number' => 1, 'albumUrl' => $albumUrl, 'albumName' => $album->name))); if (!empty($photo->description)) { $data['status'] = $photo->description; } $eventParams = array('pluginKey' => 'photo', 'entityType' => 'photo_comments', 'entityId' => $photo->id, 'userId' => $album->userId, 'postOnUserFeed' => false, 'feedType' => $params['feedType'], 'feedId' => $params['feedId']); if (!empty($params['visibility'])) { $eventParams['visibility'] = $params['visibility']; } OW::getEventManager()->trigger(new OW_Event('feed.action', $eventParams, $data)); $movedArray = array(array('addTimestamp' => time(), 'photoId' => $photo->id, 'description' => $photo->description)); OW::getEventManager()->trigger(new OW_Event(PHOTO_CLASS_EventHandler::EVENT_ON_PHOTO_ADD, $movedArray)); $status = $this->photoService->findPhotoById($photo->id)->status; if ($status == PHOTO_BOL_PhotoDao::STATUS_APPROVAL) { $e->setData(array('message' => OW::getLanguage()->text('photo', 'photo_uploaded_pending_approval'))); } else { $e->setData(array('entityType' => 'photo_comments', 'entityId' => $photo->id)); } } @unlink($tmpFile); } }
public function photo(array $params = null) { if (!OW::getUser()->isAuthenticated()) { throw new AuthenticateException(); } $language = OW::getLanguage(); if (!OW::getUser()->isAuthorized('photo', 'upload')) { $status = BOL_AuthorizationService::getInstance()->getActionStatus('photo', 'upload'); $this->assign('auth_msg', $status['msg']); return; } $config = OW::getConfig(); $userQuota = (int) $config->getValue('photo', 'user_quota'); $userId = OW::getUser()->getId(); if (!($this->photoService->countUserPhotos($userId) <= $userQuota)) { $this->assign('auth_msg', $language->text('photo', 'quota_exceeded', array('limit' => $userQuota))); } else { $accepted = floatval($config->getValue('photo', 'accepted_filesize') * 1024 * 1024); $this->assign('auth_msg', null); $form = new PHOTO_MCLASS_UploadForm(); $this->addForm($form); $photoAlbumService = PHOTO_BOL_PhotoAlbumService::getInstance(); $albums = $photoAlbumService->findUserAlbumList($userId, 1, 100); $this->assign('albums', $albums); if (!empty($params['album']) && (int) $params['album']) { $albumId = (int) $params['album']; $uploadToAlbum = $photoAlbumService->findAlbumById($albumId); if (!$uploadToAlbum || $uploadToAlbum->userId != $userId) { $this->redirect(OW::getRouter()->urlForRoute('photo_upload')); } $form->getElement('album')->setValue($uploadToAlbum->name); } if ($albums) { $script = '$("#album_select").change(function(event){ $("#album_input").val($(this).val()); });'; OW::getDocument()->addOnloadScript($script); } $script = '$("#upload-file-field").change(function(){ var img = $("#photo-file-prevew"); var name = $(".owm_upload_img_name_label span"); img.hide(); name.text(""); if (!this.files || !this.files[0]) return; if ( window.FileReader ) { var reader = new FileReader(); reader.onload = function (e) { img.show().attr("src", e.target.result); } reader.readAsDataURL(this.files[0]); } else { name.text(this.files[0].name); } $(".owm_upload_photo_browse_wrap").addClass("owm_upload_photo_attach_wrap"); });'; OW::getDocument()->addOnloadScript($script); if (OW::getRequest()->isPost()) { $form->isValid($_POST); $values = $form->getValues(); // Delete old temporary photos $tmpPhotoService = PHOTO_BOL_PhotoTemporaryService::getInstance(); $photoService = PHOTO_BOL_PhotoService::getInstance(); $file = $_FILES['photo']; $tmpPhotoService->deleteUserTemporaryPhotos($userId); if (strlen($file['tmp_name'])) { if (!UTIL_File::validateImage($file['name']) || $file['size'] > $accepted) { OW::getFeedback()->warning($language->text('photo', 'no_photo_uploaded')); $this->redirect(); } $tmpPhotoService->addTemporaryPhoto($file['tmp_name'], $userId, 1); $tmpList = $tmpPhotoService->findUserTemporaryPhotos($userId, 'order'); $tmpList = array_reverse($tmpList); // check album exists if (!($album = $photoAlbumService->findAlbumByName($values['album'], $userId))) { $album = new PHOTO_BOL_PhotoAlbum(); $album->name = $values['album']; $album->userId = $userId; $album->createDatetime = time(); $photoAlbumService->addAlbum($album); } foreach ($tmpList as $tmpPhoto) { $photo = $tmpPhotoService->moveTemporaryPhoto($tmpPhoto['dto']->id, $album->id, $values['description']); if ($photo) { BOL_AuthorizationService::getInstance()->trackAction('photo', 'upload'); $photoService->createAlbumCover($album->id, array($photo)); $photoService->triggerNewsfeedEventOnSinglePhotoAdd($album, $photo); $photoParams = array('addTimestamp' => $photo->addDatetime, 'photoId' => $photo->id, 'hash' => $photo->hash, 'description' => $photo->description); $event = new OW_Event(PHOTO_CLASS_EventHandler::EVENT_ON_PHOTO_ADD, array($photoParams)); OW::getEventManager()->trigger($event); $photo = $this->photoService->findPhotoById($photo->id); if ($photo->status != PHOTO_BOL_PhotoDao::STATUS_APPROVED) { OW::getFeedback()->info(OW::getLanguage()->text('photo', 'photo_uploaded_pending_approval')); if (PHOTO_BOL_PhotoAlbumService::getInstance()->countAlbumPhotos($photo->albumId)) { $this->redirect(OW::getRouter()->urlForRoute('photo_user_album', array('user' => BOL_UserService::getInstance()->getUserName($userId), 'album' => $album->id))); } else { $this->redirect(OW::getRouter()->urlForRoute('photo_user_albums', array('user' => BOL_UserService::getInstance()->getUserName($userId)))); } } else { OW::getFeedback()->info($language->text('photo', 'photos_uploaded', array('count' => 1))); $this->redirect(OW::getRouter()->urlForRoute('view_photo', array('id' => $photo->id))); } } } } else { OW::getFeedback()->warning($language->text('photo', 'no_photo_uploaded')); $this->redirect(); } } } OW::getDocument()->setHeading($language->text('photo', 'upload_photos')); OW::getDocument()->setTitle($language->text('photo', 'meta_title_photo_upload')); }
public static function __savePhoto($photo, $source, $userId) { $photoTmpService = PHOTO_BOL_PhotoTemporaryService::getInstance(); $photoTmpService->deleteUserTemporaryPhotos($userId); self::addTemporaryPhoto($source, $userId, '0'); $tmpList = $photoTmpService->findUserTemporaryPhotos($userId, 'order'); if (!$tmpList) { $resp = array('result' => false, 'msg' => OW::getLanguage()->text('photo', 'photo_upload_error')); exit(json_encode($resp)); } $tmpPhoto = end($tmpList); $tmpId = $tmpPhoto['dto']->id; if ($tmpId) { $eventParams = array('pluginKey' => 'photo', 'action' => 'add_photo'); $credits = OW::getEventManager()->call('usercredits.check_balance', $eventParams); if ($credits === false) { $resp = array('result' => false, 'msg' => OW::getEventManager()->call('usercredits.error_message', $eventParams)); exit(json_encode($resp)); } $photo = $photoTmpService->moveTemporaryPhoto($tmpId, $photo->albumId, '', ''); if ($credits === true) { OW::getEventManager()->call('usercredits.track_action', $eventParams); } } return $photo; }
public function photoAdd(OW_Event $e) { $params = $e->getParams(); $data = $e->getData(); if (empty($params['albumId'])) { return false; } $addToFeed = !isset($params["addToFeed"]) || $params["addToFeed"]; $album = $this->albumService->findAlbumById($params['albumId']); if (!$album) { return false; } if (empty($params['path']) || !file_exists($params['path'])) { return false; } $description = !empty($params['description']) ? $params['description'] : null; $tags = !empty($params['tags']) ? $params['tags'] : null; $tmpPhotoService = PHOTO_BOL_PhotoTemporaryService::getInstance(); if ($tmpId = $tmpPhotoService->addTemporaryPhoto($params['path'], $album->userId, 1)) { $photo = $tmpPhotoService->moveTemporaryPhoto($tmpId, $album->id, $description, $tags); if ($photo) { $data['photoId'] = $photo->id; if ($album->userId && $addToFeed) { //Newsfeed $event = new OW_Event('feed.action', array('pluginKey' => 'photo', 'entityType' => 'photo_comments', 'entityId' => $photo->id, 'userId' => $album->userId)); OW::getEventManager()->trigger($event); } $movedArray[] = array('addTimestamp' => time(), 'photoId' => $photo->id); $event = new OW_Event(PHOTO_CLASS_EventHandler::EVENT_ON_PHOTO_ADD, $movedArray); OW::getEventManager()->trigger($event); } } $e->setData($data); return $data; }
public function ajaxDeletePhoto($params) { list($entityType, $entityId) = $this->getEntity($params); if (empty($_POST['photoId']) || !$_POST['photoId']) { $resp = array('result' => false); exit(json_encode($resp)); } $service = PHOTO_BOL_PhotoTemporaryService::getInstance(); if ($service->deleteTemporaryPhoto($_POST['photoId'])) { $resp = array('result' => true); exit(json_encode($resp)); } }
function addphoto() { //$script = "$(window).bind('beforeunload', function(){return 'Processing your request...';});"; //OW::getDocument()->addOnloadScript($script); OW::getDocument()->addStyleSheet(OW::getPluginManager()->getPlugin('ynmediaimporter')->getStaticCssUrl() . 'ynmediaimporter.css'); $this->setPageTitle(OW::getLanguage()->text("ynmediaimporter", "adding_photo")); $this->setPageHeading(OW::getLanguage()->text("ynmediaimporter", "index_page_heading")); if (!OW::getRequest()->isPost()) { $url = OW::getRouter()->urlForRoute('ynmediaimporter.index'); $this->redirect($url); exit; } $lang = OW::getLanguage(); if (!strlen($albumName = htmlspecialchars(trim($_POST['album'])))) { $resp = array('result' => false, 'msg' => $lang->text('photo', 'photo_upload_error')); exit(json_encode($resp)); } $photoService = PHOTO_BOL_PhotoService::getInstance(); $tagService = BOL_TagService::getInstance(); $photoAlbumService = PHOTO_BOL_PhotoAlbumService::getInstance(); $photoTmpService = PHOTO_BOL_PhotoTemporaryService::getInstance(); $userId = OW::getUser()->getId(); // check album exists if (!($album = $photoAlbumService->findAlbumByName($albumName, $userId))) { $album = new PHOTO_BOL_PhotoAlbum(); $album->name = $albumName; $album->userId = $userId; $album->createDatetime = time(); $albumId = $photoAlbumService->addAlbum($album); $newAlbum = true; } else { $albumId = $album->id; } $data = str_replace("'", "\"", $_POST['json_data']); $data = json_decode($data); if (!empty($data->albums)) { $schedulerId = Ynmediaimporter::setupScheduler($data->photos, $data->albums, $albumId, array()); } else { $schedulerId = Ynmediaimporter::setupScheduler($data->photos, null, $albumId, array()); } $schedulerUrl = OW::getRouter()->urlForRoute('ynmediaimporter.scheduler', array('scheduler_id' => $schedulerId)); $this->assign('callback_url', OW::getRouter()->urlForRoute("ynmediaimporter.index") . "/" . $data->provider); $this->assign('scheduler_id', $schedulerId); $this->assign('scheduler_url', $schedulerUrl); }