Beispiel #1
0
 public function actionIndex()
 {
     $attachmentId = $this->_input->filterSingle('attachment_id', XenForo_Input::UINT);
     $cache = XenForo_Application::getCache();
     $imageTypes = array('gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png');
     if ($cache) {
         $attachment = unserialize($cache->load('attachment_cache_' . md5($attachmentId)));
         if (!$attachment) {
             $attachment = $this->_getAttachmentOrError($attachmentId);
             $extension = XenForo_Helper_File::getFileExtension($attachment['filename']);
             if (isset($imageTypes[$extension])) {
                 $cache->save(serialize($attachment), 'attachment_cache_' . md5($attachmentId), array(), 3600);
             }
         }
     } else {
         $attachment = $this->_getAttachmentOrError($attachmentId);
     }
     $extension = XenForo_Helper_File::getFileExtension($attachment['filename']);
     if (!in_array($extension, array_keys($imageTypes))) {
         return parent::actionIndex();
     }
     $attachmentModel = $this->_getAttachmentModel();
     $filePath = $attachmentModel->getAttachmentDataFilePath($attachment);
     if (!file_exists($filePath) || !is_readable($filePath)) {
         return $this->responseError(new XenForo_Phrase('attachment_cannot_be_shown_at_this_time'));
     }
     $this->canonicalizeRequestUrl(XenForo_Link::buildPublicLink('attachments', $attachment));
     $eTag = $this->_request->getServer('HTTP_IF_NONE_MATCH');
     $this->_routeMatch->setResponseType('raw');
     if ($eTag && $eTag == $attachment['attach_date']) {
         return $this->responseView('XenForo_ViewPublic_Attachment_View304');
     }
     $viewParams = array('attachment' => $attachment, 'attachmentFile' => $filePath);
     return $this->responseView('XenForo_ViewPublic_Attachment_View', '', $viewParams);
 }
 public function renderCss()
 {
     // re-implement XenForo_CssOutput::renderCss() so we can change how caching works
     $cacheId = $this->getCacheId();
     if ($cacheObject = XenForo_Application::getCache()) {
         if ($cacheCss = $cacheObject->load($cacheId, true)) {
             return $cacheCss . "\n/* CSS returned from cache. */";
         }
     }
     $this->_prepareForOutput();
     if (XenForo_Application::isRegistered('bbCode')) {
         $bbCodeCache = XenForo_Application::get('bbCode');
     } else {
         $bbCodeCache = XenForo_Model::create('XenForo_Model_BbCode')->getBbCodeCache();
     }
     $params = array('displayStyles' => $this->_displayStyles, 'smilieSprites' => $this->_smilieSprites, 'customBbCodes' => !empty($bbCodeCache['bbCodes']) ? $bbCodeCache['bbCodes'] : array(), 'xenOptions' => XenForo_Application::get('options')->getOptions(), 'dir' => $this->_textDirection, 'pageIsRtl' => $this->_textDirection == 'RTL');
     $templates = array();
     foreach ($this->_cssRequested as $cssName) {
         $cssName = trim($cssName);
         if (!$cssName) {
             continue;
         }
         $templateName = $cssName . '.css';
         if (!isset($templates[$templateName])) {
             $templates[$templateName] = new XenForo_Template_Public($templateName, $params);
         }
     }
     $css = self::renderCssFromObjects($templates, XenForo_Application::debugMode());
     $css = self::prepareCssForOutput($css, $this->_textDirection, XenForo_Application::get('options')->minifyCss && $cacheObject);
     if ($cacheObject) {
         $cacheObject->save($css, $cacheId, array(), 86400);
     }
     return $css;
 }
Beispiel #3
0
 public static function runOften()
 {
     $feeds = XenForo_Model::create('DigitalPointSocialBar_Model_SocialBar')->getSlugsFromOptions();
     shuffle($feeds);
     // randomize order in case someone has absurd number of lists attached to forums (would need to be more than 180 unique) to work around Twitter API limits
     $cacheObject = XenForo_Application::getCache();
     $twitter = DigitalPointSocialBar_Helper_Twitter::getService(XenForo_Application::getOptions()->dpTwitterAccessToken, XenForo_Application::getOptions()->dpTwitterAccessTokenSecret, XenForo_Application::getOptions()->dpTwitterUsername);
     // forum specific feeds
     if ($feeds) {
         foreach ($feeds as $slug) {
             $tweets_array = array();
             $results = $twitter->listsStatuses(array('slug' => $slug, 'owner_screen_name' => XenForo_Application::getOptions()->dpTwitterUsername, 'count' => 250, 'include_rts' => 1, 'include_entities' => 1));
             if (count($results)) {
                 try {
                     for ($i = 0; $i < count($results); $i++) {
                         $tweet = $results[$i];
                         if (is_object($tweet->user)) {
                             $screen_name = $tweet->user->screen_name;
                             if (!@isset($tweets_array[$screen_name])) {
                                 $tweets_array[$screen_name] = DigitalPointSocialBar_Helper_Twitter::parseTweet($tweet);
                             }
                         }
                     }
                     $cacheObject->save(json_encode(array_values($tweets_array)), 'social_bar_' . str_replace('-', '_', $slug), array(), 604800);
                     // 7 day cache
                 } catch (Exception $e) {
                 }
             }
         }
     }
 }
Beispiel #4
0
 public static function getInstance()
 {
     $object = new self();
     if (!$object->_cache) {
         $object->_cache = XenForo_Application::getCache();
     }
     return $object;
 }
Beispiel #5
0
 public function __construct()
 {
     $this->options = XenForo_Application::get('options');
     $this->cache = XenForo_Application::getCache();
     if ($this->cache && $this->options->sonnb_LiveThread_Cache) {
         $this->enable = true;
     }
     $this->duration = $this->options->sonnb_LiveThread_CacheDuration;
 }
Beispiel #6
0
 public static function installCode()
 {
     if (XenForo_Application::$versionId < 1030070) {
         throw new XenForo_Exception('Digital Point Social Bar requires XenForo 1.3.0 or newer.', true);
     }
     if (!XenForo_Application::getCache()) {
         throw new XenForo_Exception('Digital Point Social Bar requires a valid caching mechanism defined within your XenForo config.php.', true);
     }
     $db = XenForo_Application::getDb();
     try {
         $db->query("\n\t\t\t\tALTER TABLE xf_forum\n\t\t\t\t\tADD dp_twitter_slug\n\t\t\t\t\t\tVARCHAR(25)\n\t\t\t\t\t\tCHARACTER SET utf8\n\t\t\t\t\t\tCOLLATE utf8_general_ci\n\t\t\t\t\t\tNOT NULL\n\t\t\t\t\t\tDEFAULT ''\n\t\t\t");
     } catch (Zend_Db_Exception $e) {
         return false;
     }
 }
Beispiel #7
0
 public function actionTweets()
 {
     if (!($slug = $this->_input->filterSingle('slug', XenForo_Input::STRING))) {
         $slug = XenForo_Application::getOptions()->dpTwitterDefaultList;
     }
     $tweets = json_decode(XenForo_Application::getCache()->load('social_bar_' . str_replace('-', '_', preg_replace('#[^a-z0-9\\_\\-]#', '', $slug)), true), true);
     if (!$tweets) {
         $tweets = array('d' => XenForo_Application::$time, 'n' => 'Error', 'u' => '', 'i' => '', 's' => '', 't' => 'Twitter List not found for "' . $slug . '".');
     }
     header('Content-Type: application/json; charset=UTF-8', true);
     header('Cache-Control: max-age=600', true);
     header('Last-Modified : ' . gmdate('D, d M Y H:i:s' . XenForo_Application::$time) . ' GMT', true);
     echo XenForo_ViewRenderer_Json::jsonEncodeForOutput(array('tweets' => $tweets));
     exit;
 }
Beispiel #8
0
 public function actionTestSetup()
 {
     $checks['hasCache'] = XenForo_Application::getCache() ? true : false;
     if (DigitalPointBetterAnalytics_Helper_Reporting::checkAccessToken(false)) {
         $checks['profiles'] = DigitalPointBetterAnalytics_Helper_Reporting::getProfiles();
         $checks['matchingProfile'] = DigitalPointBetterAnalytics_Helper_Reporting::getProfileByPropertyId(XenForo_Application::getOptions()->googleAnalyticsWebPropertyId);
         $checks['siteSearchSetup'] = @$checks['matchingProfile']['siteSearchQueryParameters'] == 'q';
         $checks['ecommerceTracking'] = @$checks['matchingProfile']['eCommerceTracking'];
         $checks['enhancedEcommerceTracking'] = @$checks['matchingProfile']['enhancedECommerceTracking'];
         $property = DigitalPointBetterAnalytics_Helper_Reporting::getPropertyByPropertyId(@$checks['matchingProfile']['accountId'], XenForo_Application::getOptions()->googleAnalyticsWebPropertyId);
         $checks['level'] = @$property['level'];
         $checks['industryVertical'] = @$property['industryVertical'];
         $checks['dimensions'] = DigitalPointBetterAnalytics_Helper_Reporting::getDimensionsByPropertyId(@$checks['matchingProfile']['accountId'], XenForo_Application::getOptions()->googleAnalyticsWebPropertyId, array('User', 'Forum'));
     }
     $checks['licensed'] = DigitalPointBetterAnalytics_Helper_Api::check(true);
     $checks['user_dimension_set'] = XenForo_Application::getOptions()->dpBetterAnalyticsDimensionIndexUser > 0 && @$checks['dimensions']['User']['index'] == XenForo_Application::getOptions()->dpBetterAnalyticsDimensionIndexUser;
     $checks['forum_dimension_set'] = XenForo_Application::getOptions()->dpBetterAnalyticsDimentionIndex > 0 && @$checks['dimensions']['Forum']['index'] == XenForo_Application::getOptions()->dpBetterAnalyticsDimentionIndex;
     $checks['hasCurl'] = function_exists('curl_multi_init');
     return $this->responseView('DigitalPointBetterAnalytics_ViewAdmin_Tools_CheckAnalytics', 'tools_test_analytics', array('checks' => $checks));
 }
Beispiel #9
0
 public function renderTagAttach(array $tag, array $rendererStates)
 {
     $imageTypes = array('gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png');
     if (empty($rendererStates['viewAttachments'])) {
         $rendererStates['viewAttachments'] = true;
     }
     $attachmentId = intval($this->stringifyTree($tag['children']));
     if (!empty($rendererStates['attachments'][$attachmentId])) {
         $extension = XenForo_Helper_File::getFileExtension($rendererStates['attachments'][$attachmentId]['filename']);
         if (!empty($rendererStates['attachments'][$attachmentId]['temp_hash'])) {
             $rendererStates['attachments'][$attachmentId]['temp_hash'] = '';
         }
         if (in_array($extension, array_keys($imageTypes))) {
             $rendererStates['viewAttachments'] = true;
         }
     } else {
         if ($tag['option'] == 'full' && $tag['children'] && $rendererStates['viewAttachments'] && $rendererStates['lightBox'] && $attachmentId) {
             $cache = XenForo_Application::getCache();
             if ($cache) {
                 $attachment_check = unserialize($cache->load('attachment_cache_' . md5($attachmentId)));
                 if (!$attachment_check) {
                     $attachment_check = $this->_getAttachmentModel()->getAttachmentById($attachmentId);
                     $cache->save(serialize($attachment_check), 'attachment_cache_' . md5($attachmentId), array(), 3600);
                 }
             } else {
                 $attachment_check = $this->_getAttachmentModel()->getAttachmentById($attachmentId);
             }
             if ($attachment_check && in_array(XenForo_Helper_File::getFileExtension($attachment_check['filename']), array_keys($imageTypes))) {
                 $attachment = $this->_getAttachmentModel()->prepareAttachment($attachment_check);
                 if (!empty($attachment['temp_hash'])) {
                     $attachment['temp_hash'] = '';
                 }
                 $rendererStates['canView'] = true;
                 $rendererStates['validAttachment'] = true;
                 $rendererStates['viewAttachments'] = true;
                 $rendererStates['attachments'][$attachment['attachment_id']] = $attachment;
             }
         }
     }
     return parent::renderTagAttach($tag, $rendererStates);
 }
Beispiel #10
0
 public function renderHtml()
 {
     parent::renderHtml();
     if (isset($this->_params['editorTemplate']) && $this->_params['editorTemplate']->getParam('showWysiwyg')) {
         $attachPattern = '/\\[ATTACH(.*?)\\](.*?)\\[\\/ATTACH\\]/si';
         $count = @preg_match_all($attachPattern, $this->_params['post']['message'], $matches);
         if ($count) {
             $cache = XenForo_Application::getCache();
             $imageTypes = array('gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png');
             foreach ($matches[0] as $position => $match) {
                 if ($match && intval($matches[2][$position]) > 0) {
                     $attachmentId = intval($matches[2][$position]);
                     if ($cache) {
                         $attachment = unserialize($cache->load('attachment_cache_' . md5($attachmentId)));
                         if (!$attachment) {
                             $attachment = $this->_getAttachment($attachmentId);
                             $extension = XenForo_Helper_File::getFileExtension($attachment['filename']);
                             if (isset($imageTypes[$extension])) {
                                 $cache->save(serialize($attachment), 'attachment_cache_' . md5($attachmentId), array(), 3600);
                             }
                         }
                     } else {
                         $attachment = $this->_getAttachment($attachmentId);
                     }
                     if ($attachment && $attachment['thumbnail_width']) {
                         $attachment = $this->_getAttachmentModel()->prepareAttachment($attachment);
                         if ($matches[1][$position]) {
                             $replace = '<img class="attachFull bbCodeImage" src="' . XenForo_Link::buildPublicLink('attachments', array('attachment_id' => $attachment['attachment_id'])) . '" alt="attachFull' . $attachment['attachment_id'] . '" data-mce-src="' . XenForo_Link::buildPublicLink('attachments', array('attachment_id' => $attachment['attachment_id'])) . '" />';
                         } else {
                             $replace = '<img class="attachThumb bbCodeImage" src="' . $attachment['thumbnailUrl'] . '" alt="attachThumb' . $attachment['attachment_id'] . '" data-mce-src="' . $attachment['thumbnailUrl'] . '" />';
                         }
                     }
                     if (!empty($replace)) {
                         $htmlMessage = str_replace($match, $replace, $this->_params['editorTemplate']->getParam('messageHtml'));
                         $this->_params['editorTemplate']->setParam('messageHtml', $htmlMessage);
                     }
                 }
             }
         }
     }
 }
Beispiel #11
0
 public function getSlugsFromList()
 {
     $cache = XenForo_Application::getCache();
     if ($cache) {
         $cacheKey = 'social_ownership_list_slugs';
         if ($slugs = @unserialize($cache->load($cacheKey, true))) {
             return $slugs;
         }
     }
     $twitter = self::getTwitterService();
     $results = $twitter->listsOwnerships(array('count' => 100, 'screen_name' => XenForo_Application::getOptions()->dpTwitterUsername));
     $slugs = array();
     if (@$results->lists) {
         foreach ($results->lists as $list) {
             $slugs[$list->slug] = $list->name;
         }
     }
     if ($cache) {
         $cache->save(serialize($slugs), $cacheKey, array(), 90);
         // 90 second cache
     }
     return $slugs;
 }
 public static function getShareCounts()
 {
     // XenForo options
     $o = XenForo_Application::get('options');
     // Debug options
     self::$dCacheHit = $o->EHSS_CacheHitDebug;
     // XenForo variables
     $cache = XenForo_Application::getCache();
     $req = XenForo_Application::get('requestPaths');
     // Main options
     $cacheIdPrefix = $o->EHSS_CacheIdPrefix;
     $cacheTime = $o->EHSS_CacheTime;
     self::$mSiteUrl = $req['fullUri'];
     self::$mCacheId = ($cacheIdPrefix ?: '') . md5(self::$mSiteUrl);
     // Local variables
     $counts = array();
     $prevCache = false;
     if ($cacheTime === 0) {
         self::logExceptionByType('EHSS_DEBUG: Caching was effectively disabled because cache time was set to 0 (Session: ' . self::$mCacheId . ')', 1);
     }
     if ($cache && $cacheTime > 0) {
         $prevCache = $cache->load(self::$mCacheId);
         if ($prevCache) {
             $counts = json_decode($prevCache, true);
             foreach ($counts as $v) {
                 if ($v !== -1) {
                     self::logExceptionByType('EHSS_DEBUG: Share counters were loaded from cache and the data was valid (Session: ' . self::$mCacheId . ')', 1);
                     // Return counts if at least one count was valid
                     return json_encode($counts);
                 }
             }
         }
     }
     /** WILL ONLY GET TO THIS POINT IF THERE WAS NO CACHE **/
     // More debug options
     self::$dFetching = $o->EHSS_FetchingDebug;
     // More main options
     self::$mTimeout = $o->EHSS_Timeout;
     self::$mCurlSecure = $o->EHSS_CurlSecure;
     self::$mCurlLocalCert = $o->EHSS_CurlLocalCert;
     $oDisableCurl = $o->EHSS_DisableCurl;
     $oZeroFallback = $o->EHSS_ZeroFallback;
     // Define self::$mCurlUsable, self::$mCurlMilliSeconds and self::$mCurlSecurePeer
     if ($oDisableCurl || !function_exists('curl_version')) {
         self::$mCurlUsable = false;
         self::logExceptionByType('EHSS_DEBUG: Did not use cURL because either it was disabled or the module did not exist (Session: ' . self::$mCacheId . ')', 2);
     } else {
         $t = curl_version();
         self::$mCurlMilliSeconds = version_compare($t['version'], '7.16.2', '>=');
         if (!self::$mCurlMilliSeconds) {
             self::logExceptionByType('EHSS_DEBUG: Did not use milliseconds as timeout value because cURL version was older than version 7.16.2 (Your version: ' . $t['version'] . ', Session: ' . self::$mCacheId . ')', 2);
         }
         self::$mCurlSecurePeer = version_compare($t['version'], '7.10', '>=');
         if (!self::$mCurlSecurePeer) {
             self::logExceptionByType('EHSS_DEBUG: Did not use cURL option \'CURLOPT_SSL_VERIFYPEER\' because cURL version was older than version 7.10 (Your version: ' . $t['version'] . ', Session: ' . self::$mCacheId . ')', 2);
         }
         if (!self::$mCurlSecure) {
             self::logExceptionByType('EHSS_DEBUG: Did not use secure connection for cURL as instructed (Your version: ' . $t['version'] . ', Session: ' . self::$mCacheId . ')', 2);
         }
     }
     // More local variables
     $counters = $o->EHSS_ShareCounter;
     $services = array("facebook", "twitter", "googleplus", "linkedin", "pinterest", "vk");
     $tryAgain = $o->EHSS_TryAgain;
     // Temporarily mark the current session as 'total failure'
     $tFailure = true;
     // Get count for enabled services
     foreach ($services as $s) {
         if (!$counters[$s]) {
             continue;
         }
         $ts = $s;
         // Facebook v2 patch (use newer Graph API with access token if available)
         if ($s === 'facebook') {
             self::$mFacebookAppId = $o->facebookAppId;
             self::$mFacebookAppSecret = $o->facebookAppSecret;
             if (strlen(self::$mFacebookAppId) && strlen(self::$mFacebookAppSecret)) {
                 $ts = 'facebook_v2';
                 self::logExceptionByType('EHSS_DEBUG: Used an alternative API for Facebook since Facebook App ID and Secret were available in XenForo options.', 2);
             }
         }
         $counts[$s] = self::getCount($ts);
         self::logExceptionByType('EHSS_DEBUG: ' . $ts . ' service returned ' . $counts[$s] . ' (Session: ' . self::$mCacheId . ')', 2);
         // Disable the temporary 'total failure' mark if at least one site were fetched properly
         if ($counts[$s] >= 0) {
             $tFailure = false;
         } elseif ($oZeroFallback) {
             $counts[$s] = 0;
         }
     }
     $jsonCounts = json_encode($counts);
     if ($tFailure && $tryAgain) {
         self::logExceptionByType('EHSS_DEBUG: Did not save share counters because none were successfully fetched (Session: ' . self::$mCacheId . ')', 1);
     } elseif ($cache && $cacheTime > 0) {
         $cache->save($jsonCounts, self::$mCacheId, array(), $cacheTime);
         self::logExceptionByType('EHSS_DEBUG: Share counters were stored to cache (Session: ' . self::$mCacheId . ')', 1);
     } else {
         self::logExceptionByType('EHSS_DEBUG: Did not save share counters because of missing cache object or caching was disabled (Session: ' . self::$mCacheId . ')', 1);
     }
     return $jsonCounts;
 }
Beispiel #13
0
 public static function getShareCounts()
 {
     // Load XenForo options - debug
     self::$debugCacheHit = XenForo_Application::get('options')->EHSS_CacheHitDebug;
     self::$debugCurl = XenForo_Application::get('options')->EHSS_CurlDebug;
     $services = array("facebook", "twitter", "googleplus", "linkedin", "pinterest", "vk");
     $counts = array();
     $tmp = XenForo_Application::get('requestPaths');
     $siteUrl = $tmp['fullUri'];
     $cacheIdSuffix = XenForo_Application::get('options')->EHSS_CacheIdSuffix;
     $cacheId = "ehss_" . sprintf('%u', crc32($siteUrl)) . ($cacheIdSuffix ? '_' . $cacheIdSuffix : '');
     // CRC32 hash of the page's URL (fastest built-in hash for non-crypto use) with 'ehss_' prefix and custom suffix if available
     $cacheObject = XenForo_Application::getCache();
     $cacheTime = XenForo_Application::get('options')->EHSS_CacheTime;
     $previousCache = false;
     if ($cacheObject) {
         $previousCache = $cacheObject->load($cacheId);
         if ($previousCache) {
             $counts = json_decode($previousCache, true);
             foreach ($counts as $value) {
                 if ($value !== -1) {
                     self::logExceptionByType('DEBUG: Share counters were loaded from cache and the data was valid (' . $cacheId . ')', 1);
                     return json_encode($counts);
                     // Immediately return counts if at least one count was valid
                 }
             }
         }
     }
     // Load XenForo options - etc.
     $keepTrying = XenForo_Application::get('options')->EHSS_KeepTrying;
     $completeFailure = true;
     // Mark current session as completely failed
     $curlTimeout = XenForo_Application::get('options')->EHSS_CurlTimeout;
     $curlDisabled = XenForo_Application::get('options')->EHSS_DisableCurl;
     $curlExist = function_exists('curl_version');
     $curlVerPassMS = false;
     $curlSslVerify = XenForo_Application::get('options')->EHSS_CurlSslVerify;
     $curlVerPassPeer = false;
     $curlCertInfo = XenForo_Application::get('options')->EHSS_CurlCertInfo;
     // Fetch share counts if there was no previous cache or the previous cache held no valid counts
     if ($curlExist) {
         $curlVerPassMS = self::doesComplyWithMinCurlVersion('7.16.2');
         $curlVerPassPeer = self::doesComplyWithMinCurlVersion('7.10');
         $tmp = curl_version();
         if (!$curlVerPassMS) {
             self::logExceptionByType('DEBUG: Did not use milliseconds as cURL timeout because cURL version was older than 7.16.2 (version: ' . $tmp['version'] . ')', 2);
         }
         if (!$curlVerPassPeer) {
             self::logExceptionByType('DEBUG: Did not use cURL option \'CURLOPT_SSL_VERIFYPEER\' because cURL version was older than 7.10 (version: ' . $tmp['version'] . ')', 2);
         }
     }
     foreach ($services as $service) {
         $extraInfo = array();
         $tmpService = $service;
         $counts[$service] = -1;
         // Facebook v2 patch (use newer Graph API with access token when available)
         if ($tmpService === 'facebook') {
             $facebookAppId = XenForo_Application::get('options')->facebookAppId;
             $facebookAppSecret = XenForo_Application::get('options')->facebookAppSecret;
             if (strlen($facebookAppId) && strlen($facebookAppSecret)) {
                 self::logExceptionByType('DEBUG: Facebook App ID and Secret were available on XenForo options, thus the add-on would use an alternative of the Facebook API', 2);
                 $tmpService = 'facebook_v2';
                 $extraInfo['facebookAppId'] = $facebookAppId;
                 $extraInfo['facebookAppSecret'] = $facebookAppSecret;
             }
         }
         $tmp = XenForo_Application::get('options')->EHSS_ShareCounter;
         if ($tmp[$service]) {
             $counts[$service] = self::getCount($tmpService, $siteUrl, $curlTimeout, !$curlDisabled && $curlExist ? true : false, $curlVerPassMS, $curlSslVerify, $curlVerPassPeer, $curlCertInfo, $extraInfo);
         }
         if ($counts[$service] !== -1) {
             $completeFailure = false;
             // If at least one service was fetched properly, mark current session as not completely failed, then store to cache
         }
     }
     if ($completeFailure && $keepTrying) {
         self::logExceptionByType('DEBUG: Did not save share counters because none were successfully fetched (' . $cacheId . ')', 1);
     } else {
         if ($cacheObject) {
             $cacheObject->save(json_encode($counts), $cacheId, array(), $cacheTime);
             self::logExceptionByType('DEBUG: Share counters were stored on cache (' . $cacheId . ')', 1);
         } else {
             self::logExceptionByType('DEBUG: Did not save share counters because of missing cache object (' . $cacheId . ')', 1);
         }
     }
     return json_encode($counts);
 }
 /**
  * Helper method to get the cache object.
  *
  * @return Zend_Cache_Core|Zend_Cache_Frontend|false
  */
 protected function _getCache()
 {
     if ($this->_cache === null) {
         $this->_cache = XenForo_Application::getCache();
     }
     return $this->_cache;
 }
Beispiel #15
0
 public static function _cacheDelete($cacheKey)
 {
     if ($cache = XenForo_Application::getCache()) {
         $cache->remove($cacheKey);
     }
 }
Beispiel #16
0
 public function setBbCodeTagCache($content_type, $post_id, array $tagMapCache)
 {
     if ($this->cacheObject === null) {
         $this->cacheObject = XenForo_Application::getCache();
     }
     if ($this->cacheObject) {
         $options = $this->_getTagMapCacheOptions();
         $cacheId = $content_type . $post_id . $options['bbCodeCacheVersion'] . ($options['GlobalMethod'] ? "1" : "0");
         if (!empty($tagMapCache) && $options['EnableCache']) {
             $data = implode(',', $tagMapCache);
             $this->cacheObject->save($data, $cacheId, array(), $options['Expiry']);
         } else {
             $data = false;
             $this->cacheObject->remove($data);
         }
     }
 }
Beispiel #17
0
 public function prepareRealtimeData($dataType = 'threads', $limit = 5)
 {
     if ($cache = XenForo_Application::getCache()) {
         if ($compiled = @json_decode($cache->load('analytics_realtime_data', true), true)) {
             //$forumModel = XenForo_Model::create('XenForo_Model_Forum');
             //$threadModel = XenForo_Model::create('XenForo_Model_Thread');
             if (!empty($compiled[$dataType])) {
                 $newGroup = $items = array();
                 $lastValue = 0;
                 foreach ($compiled[$dataType] as $url => $data) {
                     if ($lastValue > 0 && $lastValue != $data[1]) {
                         shuffle($items);
                         $newGroup = array_merge($newGroup, $items);
                         $items = array();
                     }
                     if ($dataType == 'forums' || $dataType == 'threads') {
                         // adds a whole lot of queries
                         //if (!$forumModel->canViewForum($data[0]))
                         //{
                         //	continue;
                         //}
                         //else
                         //{
                         $url = XenForo_Link::buildPublicLink('forums', $data[0]);
                         //}
                     }
                     if ($dataType == 'threads') {
                         //if (!$threadModel->canViewThread($data[0], $data[0]))
                         //{
                         //	continue;
                         //}
                         //else
                         //{
                         $url = XenForo_Link::buildPublicLink('threads', $data[0]);
                         //}
                     }
                     $items[] = $data[0];
                     $lastValue = $data[1];
                 }
                 shuffle($items);
                 return array_slice(array_merge($newGroup, $items), 0, $limit);
             }
         }
     }
     return false;
 }
Beispiel #18
0
 /**
  * Renders the SVG and returns it.
  *
  * @return string
  */
 public function renderSvg()
 {
     $cacheId = 'xfSvgCache_' . sha1('style=' . $this->_styleId . 'language=' . $this->_languageId . 'svg=' . $this->_svgRequested . 'd=' . $this->_inputModifiedDate . 'dir=' . $this->_textDirection);
     if ($cacheObject = XenForo_Application::getCache()) {
         if ($cacheObject->test($cacheId)) {
             return $cacheObject->load($cacheId, true);
         }
     }
     $this->_prepareForOutput();
     $params = array('xenOptions' => XenForo_Application::get('options')->getOptions(), 'dir' => $this->_textDirection, 'pageIsRtl' => $this->_textDirection == 'RTL');
     $svgName = trim($this->_svgRequested);
     if (!$svgName) {
         return;
     }
     $templateName = $svgName . '.svg';
     $template = new XenForo_Template_Public($templateName, $params);
     $svg = self::renderSvgFromObject($template);
     if ($cacheObject) {
         $cacheObject->save($svg, $cacheId);
     }
     return $svg;
 }
Beispiel #19
0
 /**
  * Constructor.
  *
  * @param array $config Config elements to override default.
  * @param Zend_Cache_Core|null $cache
  * @param Zend_Db_Adapter_Abstract|null $db
  */
 public function __construct(array $config = array(), Zend_Cache_Core $cache = null, Zend_Db_Adapter_Abstract $db = null)
 {
     if (empty($config['admin'])) {
         $defaultConfig = array('table' => 'xf_session', 'cacheName' => 'session', 'cookie' => 'session', 'lifetime' => 3600);
     } else {
         $defaultConfig = array('table' => 'xf_session_admin', 'cacheName' => 'session_admin', 'cookie' => 'session_admin', 'lifetime' => XenForo_Application::debugMode() ? 86400 : 3600);
         unset($config['admin']);
     }
     $defaultConfig['ipv4CidrMatch'] = 24;
     $defaultConfig['ipv6CidrMatch'] = 64;
     $this->_config = array_merge($defaultConfig, $config);
     if (!$cache) {
         if (XenForo_Application::get('config')->cache->cacheSessions) {
             $cache = XenForo_Application::getCache();
         }
     }
     if ($cache) {
         $this->_cache = $cache;
     }
     if (!$db) {
         $db = XenForo_Application::getDb();
     }
     $this->_db = $db;
 }
Beispiel #20
0
 /**
  * Renders the CSS and returns it.
  *
  * @return string
  */
 public function renderCss()
 {
     $cacheId = 'xfCssCache_' . sha1('style=' . $this->_styleId . 'css=' . serialize($this->_cssRequested) . 'd=' . $this->_inputModifiedDate . 'dir=' . $this->_textDirection . 'minify=' . XenForo_Application::get('options')->minifyCss) . (XenForo_Application::debugMode() ? 'debug' : '');
     if ($cacheObject = XenForo_Application::getCache()) {
         if ($cacheCss = $cacheObject->load($cacheId, true)) {
             return $cacheCss . "\n/* CSS returned from cache. */";
         }
     }
     $this->_prepareForOutput();
     if (XenForo_Application::isRegistered('bbCode')) {
         $bbCodeCache = XenForo_Application::get('bbCode');
     } else {
         $bbCodeCache = XenForo_Model::create('XenForo_Model_BbCode')->getBbCodeCache();
     }
     $params = array('displayStyles' => $this->_displayStyles, 'smilieSprites' => $this->_smilieSprites, 'customBbCodes' => !empty($bbCodeCache['bbCodes']) ? $bbCodeCache['bbCodes'] : array(), 'xenOptions' => XenForo_Application::get('options')->getOptions(), 'dir' => $this->_textDirection, 'pageIsRtl' => $this->_textDirection == 'RTL');
     $templates = array();
     foreach ($this->_cssRequested as $cssName) {
         $cssName = trim($cssName);
         if (!$cssName) {
             continue;
         }
         $templateName = $cssName . '.css';
         if (!isset($templates[$templateName])) {
             $templates[$templateName] = new XenForo_Template_Public($templateName, $params);
         }
     }
     $css = self::renderCssFromObjects($templates, XenForo_Application::debugMode());
     $css = self::prepareCssForOutput($css, $this->_textDirection, XenForo_Application::get('options')->minifyCss && $cacheObject);
     if ($cacheObject) {
         $cacheObject->save($css, $cacheId, array(), 86400);
     }
     return $css;
 }
Beispiel #21
0
 /**
  * Helper method to get the cache object. If cache reads are disabled, this
  * will return false.
  *
  * @param boolean $forceCachedRead If true, the global "allow cached read" value is ignored
  *
  * @return Zend_Cache_Core|Zend_Cache_Frontend|false
  */
 protected function _getCache($forceCachedRead = false)
 {
     if (!$this->_allowCachedRead && !$forceCachedRead) {
         return false;
     }
     if ($this->_cache === null) {
         $this->_cache = XenForo_Application::getCache();
     }
     return $this->_cache;
 }
 private static function _setCache($apiUrl, array $thisData)
 {
     $cache = XenForo_Application::getCache();
     if (!empty($cache)) {
         $data = $cache->load(self::KEY);
         if (empty($data)) {
             $data = array();
         }
         $data[$apiUrl] = $thisData;
         return $cache->save($data, self::KEY);
     }
     /** @var XenForo_Model_DataRegistry $dataRegistryModel */
     $dataRegistryModel = XenForo_Model::create('XenForo_Model_DataRegistry');
     $data = $dataRegistryModel->get(self::KEY);
     if (empty($data)) {
         $data = array();
     }
     $data[$apiUrl] = $thisData;
     $dataRegistryModel->set(self::KEY, $data);
     return true;
 }
Beispiel #23
0
 /**
  * Tasks that should be run really often.
  */
 public static function runVeryOften()
 {
     if (XenForo_Application::getCache() && XenForo_Application::getOptions()->dpAnalyticsSidebar == 'above' || XenForo_Application::getOptions()->dpAnalyticsSidebar == 'below') {
         XenForo_Model::create('DigitalPointBetterAnalytics_Model_Analytics')->getRealtimeUsage();
     }
 }