Пример #1
0
 /**
  * Finds all posts by given request settings directly from Flickr api
  *
  * @param array $settings settings The settings
  * @return Tx_Extbase_Persistence_QueryResultInterface The posts
  */
 public function requestAllBySettings($settings)
 {
     $result = array();
     $postIds = array();
     if (!$settings['offset']) {
         $settings['offset'] = 0;
     }
     $rawFeed = \TYPO3\MooxSocial\Controller\FlickrController::flickr($settings['api_user_id']);
     $posts = array();
     foreach ($rawFeed as $item) {
         if (!in_array($item['id'], $postIds)) {
             $postIds[] = $item['id'];
             $postId = $item['id'];
             $item['id'] = $postId;
             $item['userId'] = $userId;
             $item['pid'] = $storagePid;
             $post = \TYPO3\MooxSocial\Controller\FlickrController::flickrPost($item);
             if (is_array($post)) {
                 $posts[] = $post;
             }
         }
     }
     if (count($posts)) {
         foreach ($posts as $post) {
             $flickrPost = new \TYPO3\MooxSocial\Domain\Model\Flickr();
             $flickrPost->setPid($post['pid']);
             $flickrPost->setCreated($post['created']);
             $flickrPost->setUpdated($post['updated']);
             $flickrPost->setType($post['type']);
             $flickrPost->setStatusType($post['statusType']);
             $flickrPost->setPage($post['page']);
             $flickrPost->setAction($post['action']);
             $flickrPost->setTitle($post['title']);
             $flickrPost->setSummary($post['summary']);
             $flickrPost->setText($post['text']);
             $flickrPost->setAuthor($post['author']);
             $flickrPost->setAuthorId($post['authorId']);
             $flickrPost->setDescription($post['description']);
             $flickrPost->setCaption($post['caption']);
             $flickrPost->setUrl($post['url']);
             $flickrPost->setLinkName($post['linkName']);
             $flickrPost->setLinkUrl($post['linkUrl']);
             $flickrPost->setImageUrl($post['imageUrl']);
             $flickrPost->setImageEmbedcode($post['imageEmbedcode']);
             $flickrPost->setVideoUrl($post['videoUrl']);
             $flickrPost->setVideoEmbedcode($post['videoEmbedcode']);
             $flickrPost->setSharedUrl($post['sharedUrl']);
             $flickrPost->setSharedTitle($post['sharedTitle']);
             $flickrPost->setSharedDescription($post['sharedDescription']);
             $flickrPost->setSharedCaption($post['sharedCaption']);
             $flickrPost->setLikes($post['likes']);
             $flickrPost->setShares($post['shares']);
             $flickrPost->setComments($post['comments']);
             $flickrPost->setApiUid($post['apiUid']);
             $flickrPost->setApiHash($post['apiHash']);
             $result[] = $flickrPost;
         }
     }
     return $result;
 }
Пример #2
0
 /**
  * action reinit
  *
  * @param string $apiKey
  * @param string $apiSecretKey
  * @param string $userId
  * @param integer $storagePid
  * @return void
  */
 public function reinitAction($apiKey, $apiSecretKey, $userId, $storagePid)
 {
     if ($apiKey != "" && $apiSecretKey != "" && $userId != "") {
         $this->flickrRepository->removeByPageId($userId, $storagePid);
         $rawFeed = self::flickr($apiKey, $apiSecretKey, $userId, 'init');
         $posts = array();
         $postIds = array();
         foreach ($rawFeed as $item) {
             if (!in_array($item['id'], $postIds)) {
                 $postIds[] = $item['id'];
                 $postId = $item['id'];
                 $item['id'] = $postId;
                 $item['userId'] = $userId;
                 $item['pid'] = $storagePid;
                 $post = self::flickrPost($item);
                 if (is_array($post)) {
                     $posts[] = $post;
                 }
             }
         }
         if (count($posts)) {
             $insertCnt = 0;
             foreach ($posts as $post) {
                 $flickrPost = new \TYPO3\MooxSocial\Domain\Model\Flickr();
                 $flickrPost->setPid($post['pid']);
                 $flickrPost->setCreated($post['created']);
                 $flickrPost->setUpdated($post['updated']);
                 $flickrPost->setModel("flickr");
                 $flickrPost->setType($post['type']);
                 $flickrPost->setStatusType($post['statusType']);
                 $flickrPost->setPage($post['page']);
                 $flickrPost->setAction($post['action']);
                 $flickrPost->setTitle($post['title']);
                 $flickrPost->setSummary($post['summary']);
                 $flickrPost->setText($post['text']);
                 $flickrPost->setAuthor($post['author']);
                 $flickrPost->setAuthorId($post['authorId']);
                 $flickrPost->setDescription($post['description']);
                 $flickrPost->setCaption($post['caption']);
                 $flickrPost->setUrl($post['url']);
                 $flickrPost->setLinkName($post['linkName']);
                 $flickrPost->setLinkUrl($post['linkUrl']);
                 $flickrPost->setImageUrl($post['imageUrl']);
                 $flickrPost->setImageEmbedcode($post['imageEmbedcode']);
                 $flickrPost->setVideoUrl($post['videoUrl']);
                 $flickrPost->setVideoEmbedcode($post['videoEmbedcode']);
                 $flickrPost->setSharedUrl($post['sharedUrl']);
                 $flickrPost->setSharedTitle($post['sharedTitle']);
                 $flickrPost->setSharedDescription($post['sharedDescription']);
                 $flickrPost->setSharedCaption($post['sharedCaption']);
                 $flickrPost->setLikes($post['likes']);
                 $flickrPost->setShares($post['shares']);
                 $flickrPost->setComments($post['comments']);
                 $flickrPost->setApiUid($post['apiUid']);
                 $flickrPost->setApiHash($post['apiHash']);
                 $this->flickrRepository->add($flickrPost);
                 $insertCnt++;
             }
             $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
             $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface')->persistAll();
             $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $insertCnt . " neue Bilder geladen", '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE);
             \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message);
         }
     }
     $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('LLL:EXT:moox_social/Resources/Private/Language/locallang.xlf:overview.flickr.listing.reinit.success', $this->extensionName), '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE);
     \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message);
     $this->redirect('index');
 }
Пример #3
0
 /**
  * Works through the indexing queue and indexes the queued items into Solr.
  *
  * @return	boolean	Returns TRUE on success, FALSE if no items were indexed or none were found.
  * @see	typo3/sysext/scheduler/tx_scheduler_Task#execute()
  */
 public function execute()
 {
     // Get the extensions's configuration
     $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['moox_social']);
     if ($extConf['debugEmailSenderName'] == "") {
         $extConf['debugEmailSenderName'] = $extConf['debugEmailSenderAddress'];
     }
     if ($this->email == "") {
         $this->email = $extConf['debugEmailReceiverAddress'];
     }
     $executionSucceeded = FALSE;
     if (!$this->pid) {
         $this->pid = 0;
     }
     if ($this->apiKey != "" && $this->apiSecretKey != "" && $this->userId != "") {
         $execution = $this->getExecution();
         $interval = $execution->getInterval();
         $time = time();
         $to = $time;
         $from = $time - $interval - $this->intervalBuffer;
         try {
             $rawFeed = \TYPO3\MooxSocial\Controller\FlickrController::flickr($this->apiKey, $this->apiSecretKey, $this->userId);
             /*print "<pre>";
                                           print_r($rawFeed);
                                           print "</pre>";
             		exit();*/
             $executionSucceeded = TRUE;
         } catch (\Exception $e) {
             $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_flickrgettask.api_execution_error') . " [" . $e->getMessage() . "]", '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, TRUE);
             \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message);
             if ($this->email && $extConf['debugEmailSenderAddress']) {
                 $lockfile = $_SERVER['DOCUMENT_ROOT'] . "/typo3temp/.lock-email-task-" . md5($this->apiKey . $this->apiSecretKey . $this->userId);
                 if (file_exists($lockfile)) {
                     $lockfiletime = filemtime($lockfile);
                     if ($lockfiletime < time() - 86400) {
                         unlink($lockfile);
                     }
                 }
                 if (!file_exists($lockfile)) {
                     $message = (new \TYPO3\CMS\Core\Mail\MailMessage())->setFrom(array($extConf['debugEmailSenderAddress'] => $extConf['debugEmailSenderName']))->setTo(array($this->email => $this->email))->setSubject($GLOBALS['LANG']->sL('LLL:EXT:moox_social/Resources/Private/Language/locallang_scheduler.xlf:tx_mooxsocial_tasks_flickrgettask.api_error_mailsubject'))->setBody('ERROR: while requesting [api key: ' . $this->apiKey . ' | api secret key: ' . $this->apiSecretKey . ' | user id: ' . $this->userId . "]");
                     $message->send();
                     touch($lockfile);
                 }
             }
         }
         $posts = array();
         $postIds = array();
         foreach ($rawFeed as $item) {
             if (!in_array($item['id'], $postIds)) {
                 $postIds[] = $item['id'];
                 $postId = $item['id'];
                 $item['id'] = $postId;
                 $item['userId'] = $this->userId;
                 $item['pid'] = $this->pid;
                 $post = \TYPO3\MooxSocial\Controller\FlickrController::flickrPost($item);
                 if (is_array($post)) {
                     $posts[] = $post;
                 }
             }
         }
         if (count($posts)) {
             $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
             $flickrRepository = $objectManager->get('\\TYPO3\\MooxSocial\\Domain\\Repository\\FlickrRepository');
             $insertCnt = 0;
             $updateCnt = 0;
             foreach ($posts as $post) {
                 $flickrPost = $flickrRepository->findOneByApiUid($post['apiUid'], $this->pid);
                 if (!$flickrPost instanceof \TYPO3\MooxSocial\Domain\Model\Flickr) {
                     $flickrPost = new \TYPO3\MooxSocial\Domain\Model\Flickr();
                     $action = "insert";
                 }
                 if ($action == "insert") {
                     $flickrPost->setPid($post['pid']);
                     $flickrPost->setCreated($post['created']);
                 }
                 $flickrPost->setUpdated($post['updated']);
                 $flickrPost->setType($post['type']);
                 $flickrPost->setStatusType($post['statusType']);
                 if ($action == "insert") {
                     $flickrPost->setPage($post['page']);
                     $flickrPost->setModel("flickr");
                 }
                 $flickrPost->setAction($post['action']);
                 $flickrPost->setTitle($post['title']);
                 $flickrPost->setSummary($post['summary']);
                 $flickrPost->setText($post['text']);
                 $flickrPost->setAuthor($post['author']);
                 $flickrPost->setAuthorId($post['authorId']);
                 $flickrPost->setDescription($post['description']);
                 $flickrPost->setCaption($post['caption']);
                 $flickrPost->setUrl($post['url']);
                 $flickrPost->setLinkName($post['linkName']);
                 $flickrPost->setLinkUrl($post['linkUrl']);
                 $flickrPost->setImageUrl($post['imageUrl']);
                 $flickrPost->setImageEmbedcode($post['imageEmbedcode']);
                 $flickrPost->setVideoUrl($post['videoUrl']);
                 $flickrPost->setVideoEmbedcode($post['videoEmbedcode']);
                 $flickrPost->setSharedUrl($post['sharedUrl']);
                 $flickrPost->setSharedTitle($post['sharedTitle']);
                 $flickrPost->setSharedDescription($post['sharedDescription']);
                 $flickrPost->setSharedCaption($post['sharedCaption']);
                 $flickrPost->setLikes($post['likes']);
                 $flickrPost->setShares($post['shares']);
                 $flickrPost->setComments($post['comments']);
                 if ($action == "insert") {
                     $flickrPost->setApiUid($post['apiUid']);
                 }
                 $flickrPost->setApiHash($post['apiHash']);
                 if ($action == "insert") {
                     $flickrRepository->add($flickrPost);
                     $insertCnt++;
                 } else {
                     $flickrRepository->update($flickrPost);
                     $updateCnt++;
                 }
             }
             $objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface')->persistAll();
             $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $insertCnt . " neue Bilder geladen | " . $updateCnt . " bestehende Bilder aktualisiert", '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE);
             \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message);
         } else {
             $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', "Keine neuen oder aktualisierten Bilder gefunden", '', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE);
             \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($message);
         }
     }
     return $executionSucceeded;
 }