function __construct(Dao_Factory $daoFactory, Services_Settings_Container $settings) { $this->_daoFactory = $daoFactory; $this->_settings = $settings; $this->_nntp_post = new Services_Nntp_SpotPosting(Services_Nntp_EnginePool::pool($settings, 'post')); $this->_nntp_hdr = new Services_Nntp_SpotReading(Services_Nntp_EnginePool::pool($settings, 'hdr')); }
function render() { # Check users' permissions $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spotimage, ''); $settings_nntp_hdr = $this->_settings->get('nntp_hdr'); # Did the user request an SpeedDial image? if (isset($this->_image['type']) && $this->_image['type'] == 'speeddial') { $svcActn_SpeedDial = new Services_Actions_SpeedDial($this->_daoFactory, $this->_spotSec, $this->_tplHelper); $data = $svcActn_SpeedDial->createSpeedDialImage($this->_currentSession['user']['userid'], $settings_nntp_hdr['host']); } elseif (isset($this->_image['type']) && $this->_image['type'] == 'statistics') { /* Check whether the user has view statistics permissions */ $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_statistics, ''); $graph = isset($this->_image['graph']) ? $this->_image['graph'] : false; $limit = isset($this->_image['limit']) ? $this->_image['limit'] : false; # init $svcPrv_Stats = new Services_Providers_Statistics($this->_daoFactory->getSpotDao(), $this->_daoFactory->getCacheDao(), $this->_daoFactory->getUsenetStateDao()->getLastUpdate(Dao_UsenetState::State_Spots)); $data = $svcPrv_Stats->renderStatImage($graph, $limit); } elseif (isset($this->_image['type']) && $this->_image['type'] == 'avatar') { # Check users' permissions $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spotimage, 'avatar'); $providerSpotImage = new Services_Providers_CommentImage(new Services_Providers_Http($this->_daoFactory->getCacheDao())); $data = $providerSpotImage->fetchGravatarImage($this->_image); } else { $svc_nntpnzb_engine = Services_Nntp_EnginePool::pool($this->_settings, 'bin'); /* * Retrieve the full spot, we need it to be able to retrieve the image */ $svcActn_GetSpot = new Services_Actions_GetSpot($this->_settings, $this->_daoFactory, $this->_spotSec); $fullSpot = $svcActn_GetSpot->getFullSpot($this->_currentSession, $this->_messageid, false); /* * Actually retrieve the image */ $providerSpotImage = new Services_Providers_SpotImage(new Services_Providers_Http($this->_daoFactory->getCacheDao()), new Services_Nntp_SpotReading($svc_nntpnzb_engine), $this->_daoFactory->getCacheDao()); $data = $providerSpotImage->fetchSpotImage($fullSpot); } # else # Images are allowed to be cached on the client unless the provider explicitly told us not to if (isset($data['ttl']) && $data['ttl'] > 0) { $this->sendExpireHeaders(true); } else { $this->sendExpireHeaders(false); } # else header("Content-Type: " . image_type_to_mime_type($data['metadata']['imagetype'])); header("Content-Length: " . strlen($data['content'])); echo $data['content']; }
function render() { # Check the users' basic rights $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_retrieve_nzb, ''); /* * If the user has configured download integration, make sure the user has * permission for this specific download integration */ if ($this->_action != 'display') { $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_download_integration, $this->_action); } # if /* * Create the different NNTP components */ $svcBinSpotReading = new Services_Nntp_SpotReading(Services_Nntp_EnginePool::pool($this->_settings, 'bin')); $svcTextSpotReading = new Services_Nntp_SpotReading(Services_Nntp_EnginePool::pool($this->_settings, 'hdr')); $svcProvNzb = new Services_Providers_Nzb($this->_daoFactory->getCacheDao(), $svcBinSpotReading); $svcProvSpot = new Services_Providers_FullSpot($this->_daoFactory, $svcTextSpotReading); # We do not want NZB files to be cached on the client $this->sendExpireHeaders(true); try { if ($this->_action == 'display') { $this->sendContentTypeHeader("nzb"); } # if $svcActnNzb = new Services_Actions_DownloadNzb($this->_settings, $this->_daoFactory); $svcActnNzb->handleNzbAction($this->_messageid, $this->_currentSession, $this->_action, $svcProvSpot, $svcProvNzb); if ($this->_action != 'display') { $this->sendContentTypeHeader("json"); $result = new Dto_FormResult('success'); $this->template('jsonresult', array('result' => $result)); } # if } catch (Exception $x) { $this->sendContentTypeHeader("json"); $result = new Dto_FormResult('notsubmitted'); $result->addError($x->getMessage()); $this->template('jsonresult', array('result' => $result)); } # catch }
function __construct(Dao_Factory $daoFactory, Services_Settings_Container $settings, $force, $retro) { $this->_daoFactory = $daoFactory; $this->_settings = $settings; $this->_retro = $retro; $this->_force = $force; $this->_textServer = $settings->get('nntp_hdr'); $this->_binServer = $settings->get('nntp_nzb'); /* * Create the specific DAO objects */ $this->_usenetStateDao = $daoFactory->getUsenetStateDao(); $this->_usenetStateDao->initialize(); /* * Create the service objects for both the NNTP binary group and the * textnews group. We only create a basic NNTP_Engine object, but we * don't create any higher level objects */ $this->_svcNntpText = Services_Nntp_EnginePool::pool($this->_settings, 'hdr'); $this->_svcNntpBin = Services_Nntp_EnginePool::pool($this->_settings, 'bin'); }
function getFullSpot(array $currentSession, $msgId, $markAsRead) { # Make sure user has access to the spot $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spotdetail, ''); $svcNntpSpotReading = new Services_Nntp_SpotReading(Services_Nntp_EnginePool::pool($this->_settings, 'hdr')); $svcProvFullSpot = new Services_Providers_FullSpot($this->_daoFactory->getSpotDao(), $svcNntpSpotReading); $fullSpot = $svcProvFullSpot->fetchFullSpot($msgId, $currentSession['user']['userid']); # seen list if ($markAsRead) { if ($this->_spotSec->allowed(SpotSecurity::spotsec_keep_own_seenlist, '')) { if ($currentSession['user']['prefs']['keep_seenlist']) { /* * Always update the seen stamp, this is used for viewing new comments * and the likes */ $this->_daoFactory->getSpotStateListDao()->addtoSeenList($msgId, $currentSession['user']['userid']); } # if } # if allowed } # if return $fullSpot; }
$cacheDao = $daoFactory->getCacheDao(); if (!is_dir('./cache')) { mkdir('./cache', 0777); } # if /* * Now try to get all current cache items */ $dbConnection = $daoFactory->getConnection(); /* * Initialize the NZB retrieval provider */ $svcFullSpot = new Services_Providers_FullSpot($daoFactory->getSpotDao(), new Services_Nntp_SpotReading(Services_Nntp_EnginePool::pool($settings, 'hdr'))); $svcNzb = new Services_Providers_Nzb($cacheDao, new Services_Nntp_SpotReading(Services_Nntp_EnginePool::pool($settings, 'bin'))); $svcPrvHttp = new Services_Providers_Http($cacheDao); $svcImage = new Services_Providers_SpotImage($svcPrvHttp, new Services_Nntp_SpotReading(Services_Nntp_EnginePool::pool($settings, 'bin')), $cacheDao); $counter = 0; while (true) { $counter++; echo "Validating cache content, items " . ($counter - 1) * 1000 . ' to ' . $counter * 1000; $results = $dbConnection->arrayQuery("SELECT * FROM cache LIMIT 1001 OFFSET " . ($counter - 1) * 1000); foreach ($results as $cacheItem) { $cacheItem['metadata'] = unserialize($cacheItem['metadata']); try { $cacheDao->getCacheContent($cacheItem['id'], $cacheItem['cachetype'], $cacheItem['metadata']); } catch (CacheIsCorruptException $x) { echo PHP_EOL . ' Trying to fetch #' . $cacheItem['id'] . ' for ' . $cacheItem['resourceid'] . ' again, '; switch ($cacheItem['cachetype']) { case Dao_Cache::SpotNzb: try { $fullSpot = $svcFullSpot->fetchFullSpot($cacheItem['resourceid'], 1);
public function getSpotComments($msgId, $userId, $start, $length, $language) { # Check users' permissions $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_comments, ''); $svcNntpSpotReading = new Services_Nntp_SpotReading(Services_Nntp_EnginePool::pool($this->_settings, 'hdr')); $svcProvComments = new Services_Providers_Comments($this->_daoFactory->getCommentDao(), $svcNntpSpotReading); $tryTranslate = Services_Actions_GetComments::nativeLanguage !== $language; /* * Basically we are retrieving the comments from the database, for them to be translated * if necessary */ $comments = $svcProvComments->fetchSpotComments($msgId, $userId, $start, $length); if (!$tryTranslate) { return $comments; } # if /* * In our cache, we store an key => value pair with the original string and * the translation, so we can do very quick lookups. */ $toBeTranslated = array(); $translated = $this->_cacheDao->getCachedTranslatedComments($msgId, $language); if ($translated === false) { $translated = array(); } # if foreach ($comments as &$comment) { $tmpBody = $comment['body']; if (isset($translated[$tmpBody])) { $comment['body_translated'] = $translated[$tmpBody]; } else { $toBeTranslated[] = $comment; } # else } # foreach /* * Actually translate our list of comments, and merge * them with the actual comments */ if (!empty($toBeTranslated)) { $svcTranslate = new Services_Translation_Microsoft($this->_settings, $this->_cacheDao); if (!$svcTranslate->isAvailable()) { return $comments; } # if $translations = $svcTranslate->translateMultiple($language, $toBeTranslated, 'body'); /* * copy the translations into the cache */ if (!empty($translations)) { foreach ($translations as $v) { $tmpBody = $v['body']; $translated[$tmpBody] = $v['body_translated']; } # foreach /* * Convert the comments once again */ foreach ($comments as &$comment) { $tmpBody = $comment['body']; if (isset($translated[$tmpBody])) { $comment['body_translated'] = $translated[$tmpBody]; } # else } # foreach } # if /* * and save the translated bodies into the cache */ $this->_cacheDao->saveTranslatedCommentCache($msgId, $language, $translated); } # if return $comments; }