public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('position' => 0, 'queryKeys' => array('xengallery_media_drop', 'xengallery_media_add', 'xengallery_album', 'xengallery_comment', 'xengallery_user_tag', 'xf_user')), $data); if (!$data['queryKeys']) { return true; } $s = microtime(true); $db = XenForo_Application::getDb(); $status = sprintf('%s... %s %s', 'Adding', 'XFMG Table Indexes', str_repeat(' . ', $data['position'])); foreach ($data['queryKeys'] as $key => $name) { $data['position']++; $query = $this->_getQueryToExecute($name); if (!$query) { continue; } try { $db->query($query); unset($data['queryKeys'][$key]); } catch (Zend_Db_Exception $e) { if ($name != 'xengallery_media_drop') { XenForo_Error::logException($e, false, "XenForo Media Gallery: Error adding index(es) ({$name}): "); } unset($data['queryKeys'][$key]); continue; } if ($targetRunTime && microtime(true) - $s > $targetRunTime) { break; } } return $data; }
public function actionDiscordLink() { $this->_assertPostOnly(); $visitor = XenForo_Visitor::getInstance(); if (!$visitor->hasPermission('general', 'linkDiscord')) { return $this->responseNoPermission(); } $tokenModel = $this->_getTokenmodel(); $generate = $this->_input->filterSingle('create', XenForo_Input::STRING, array('default' => '')); if (strlen($generate)) { $dw = XenForo_DataWriter::create('DiscordAuth_DataWriter_Token'); $existing = $tokenModel->getTokenByUserId($visitor['user_id']); if ($existing === false || !$existing['valid']) { if ($existing !== false) { $dw->setExistingData($existing, true); } try { $dw->set('user_id', $visitor['user_id']); $dw->set('token', self::generateToken()); $dw->save(); // self::generateToken may throw Exception } catch (Exception $e) { XenForo_Error::logException($e, false); } } } $unlink = $this->_input->filterSingle('unlink', XenForo_Input::STRING, array('default' => '')); if (strlen($unlink)) { $dw = XenForo_DataWriter::create('XenForo_DataWriter_User'); $dw->setExistingData($visitor['user_id']); $dw->set('da_discord_id', null); $dw->save(); } return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(XenForo_Link::buildPublicLink('account/discord'))); }
/** * Determines if CAPTCHA is valid (passed). * * @see XenForo_Captcha_Abstract::isValid() */ public function isValid(array $input) { if (!$this->_keyUserId) { return true; // if not configured, always pass } if (empty($input['keycaptcha_code']) || !is_string($input['keycaptcha_code'])) { return false; } $parts = explode('|', $input['keycaptcha_code']); if (count($parts) < 4) { return false; } if ($parts[0] !== md5('accept' . $parts[1] . $this->_privateKey . $parts[2])) { return false; } if (substr($parts[2], 0, 7) !== 'http://') { return false; } try { $client = XenForo_Helper_Http::getClient($parts[2]); $contents = trim($client->request('GET')->getBody()); return $contents == '1'; } catch (Zend_Http_Client_Adapter_Exception $e) { // this is an exception with the underlying request, so let it go through XenForo_Error::logException($e, false, 'KeyCAPTCHA connection error:'); return true; } }
public function runMailQueue($targetRunTime) { $s = microtime(true); $transport = XenForo_Mail::getTransport(); $db = $this->_getDb(); do { $queue = $this->getMailQueue($targetRunTime ? 20 : 0); foreach ($queue as $id => $record) { if (!$db->delete('xf_mail_queue', 'mail_queue_id = ' . $db->quote($id))) { // already been deleted - run elsewhere continue; } $mailObj = @unserialize($record['mail_data']); if (!$mailObj instanceof Zend_Mail) { continue; } $thisTransport = XenForo_Mail::getFinalTransportForMail($mailObj, $transport); try { $mailObj->send($thisTransport); } catch (Exception $e) { $toEmails = implode(', ', $mailObj->getRecipients()); XenForo_Error::logException($e, false, "Email to {$toEmails} failed: "); // pipe may be messed up now, so let's be sure to get another one unset($transport); $transport = XenForo_Mail::getTransport(); } if ($targetRunTime && microtime(true) - $s > $targetRunTime) { $queue = false; break; } } } while ($queue); return $this->hasMailQueue(); }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $s = microtime(true); /* @var $cronModel XenForo_Model_Cron */ $cronModel = XenForo_Model::create('XenForo_Model_Cron'); XenForo_Application::defer('Cron', array(), 'cron', false, XenForo_Application::$time + 300); $entries = $cronModel->getCronEntriesToRun(); foreach ($entries as $entry) { if (!$cronModel->updateCronRunTimeAtomic($entry)) { continue; } try { $cronModel->runEntry($entry); } catch (Exception $e) { // suppress so we don't get stuck XenForo_Error::logException($e); } $runTime = microtime(true) - $s; if ($targetRunTime && $runTime > $targetRunTime) { break; } } $cronModel->updateMinimumNextRunTime(); return false; }
public function processUsers(XenForo_DataWriter_DiscussionMessage_Post $dw) { if ($this->_controller->getInput()->filterSingle('ImageRestrictionDataIsComing', XenForo_Input::UINT)) { $usernames = $this->_controller->getInput()->filterSingle('ImageRestrictionUsers', XenForo_Input::STRING, array('array' => true)); foreach (array_keys($usernames) as $i) { if (empty($usernames[$i])) { unset($usernames[$i]); } } if (!empty($usernames)) { $userModel = $this->_controller->getModelFromCache('XenForo_Model_User'); $fetchOptions = array(); $invalidNames = array(); $users = $userModel->getUsersByNames($usernames, $fetchOptions, $invalidNames); try { if (!empty($invalidNames)) { throw new XenForo_Exception(new XenForo_Phrase('th_imagerestriction_users_not_found_x_imagerestriction', array('users' => implode(', ', $invalidNames))), true); } } catch (Exception $e) { XenForo_Error::logException($e); } $dw->setImageRestrictionUsers($users); } else { $dw->setImageRestrictionUsers(array()); } } }
/** * Determines if CAPTCHA is valid (passed). * * @see XenForo_Captcha_Abstract::isValid() */ public function isValid(array $input) { if (!$this->_cKey) { return true; // if not configured, always pass } if (empty($input['adcopy_challenge']) || empty($input['adcopy_response'])) { return false; } try { $client = XenForo_Helper_Http::getClient('http://verify.solvemedia.com/papi/verify'); $client->setParameterPost(array('privatekey' => $this->_vKey, 'challenge' => $input['adcopy_challenge'], 'response' => $input['adcopy_response'], 'remoteip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '')); $contents = trim($client->request('POST')->getBody()); $parts = explode("\n", $contents, 3); $result = trim($parts[0]); $error = isset($parts[1]) ? trim($parts[1]) : null; if ($result == 'true') { return true; } switch ($error) { case 'wrong answer': case 'invalid remoteip': // generally end user mistakes return false; default: // this is likely a configuration error, log and let it through XenForo_Error::logError("Solve Media CAPTCHA error: {$error}"); return true; } } catch (Zend_Http_Client_Adapter_Exception $e) { // this is an exception with the underlying request, so let it go through XenForo_Error::logException($e, false, "Solve Media connection error: "); return true; } }
/** DEBUG FUNCTION **/ private static function logExceptionByType($m, $t) { if ($m && ($t === 1 && self::$dCacheHit || $t === 2 && self::$dFetching)) { return XenForo_Error::logException(new XenForo_Exception($m)); } else { return false; } }
private static function logExceptionByType($message, $type) { if ($type === 1 && self::$debugCacheHit || $type === 2 && self::$debugCurl) { return XenForo_Error::logException(new XenForo_Exception($message)); } else { return false; } }
public static function createUser(array $data, array $provider, array $externalToken, array $externalVisitor, XenForo_Model_UserExternal $userExternalModel) { $user = null; /** @var bdApiConsumer_XenForo_Model_UserExternal $userExternalModel */ $options = XenForo_Application::get('options'); /** @var XenForo_DataWriter_User $writer */ $writer = XenForo_DataWriter::create('XenForo_DataWriter_User'); if ($options->registrationDefaults) { $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true)); } if (!isset($data['timezone']) and isset($externalVisitor['user_timezone_offset'])) { $tzOffset = $externalVisitor['user_timezone_offset']; $tzName = timezone_name_from_abbr('', $tzOffset, 1); if ($tzName !== false) { $data['timezone'] = $tzName; } } if (!empty($data['user_id'])) { $writer->setImportMode(true); } $writer->bulkSet($data); if (!empty($data['user_id'])) { $writer->setImportMode(false); } $writer->set('email', $externalVisitor['user_email']); if (!empty($externalVisitor['user_gender'])) { $writer->set('gender', $externalVisitor['user_gender']); } if (!empty($externalVisitor['user_dob_day']) && !empty($externalVisitor['user_dob_month']) && !empty($externalVisitor['user_dob_year'])) { $writer->set('dob_day', $externalVisitor['user_dob_day']); $writer->set('dob_month', $externalVisitor['user_dob_month']); $writer->set('dob_year', $externalVisitor['user_dob_year']); } if (!empty($externalVisitor['user_register_date'])) { $writer->set('register_date', $externalVisitor['user_register_date']); } $userExternalModel->bdApiConsumer_syncUpOnRegistration($writer, $externalToken, $externalVisitor); $auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword'); $writer->set('scheme_class', $auth->getClassName()); $writer->set('data', $auth->generate(''), 'xf_user_authenticate'); $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId); $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id')); $writer->advanceRegistrationUserState(false); // TODO: option for extra user group $writer->preSave(); if ($writer->hasErrors()) { return $user; } try { $writer->save(); $user = $writer->getMergedData(); $userExternalModel->bdApiConsumer_updateExternalAuthAssociation($provider, $externalVisitor['user_id'], $user['user_id'], array_merge($externalVisitor, array('token' => $externalToken))); XenForo_Model_Ip::log($user['user_id'], 'user', $user['user_id'], 'register_api_consumer'); } catch (XenForo_Exception $e) { XenForo_Error::logException($e, false); } return $user; }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { $data = array_merge(array('batch' => 100, 'position' => 0), $data); /* @var $attachmentModel XenForo_Model_Attachment */ $attachmentModel = XenForo_Model::create('XenForo_Model_Attachment'); $s = microtime(true); $dataIds = $attachmentModel->getAttachmentDataIdsInRange($data['position'], $data['batch']); if (sizeof($dataIds) == 0) { return false; } foreach ($dataIds as $dataId) { $data['position'] = $dataId; $dw = XenForo_DataWriter::create('XenForo_DataWriter_AttachmentData', XenForo_DataWriter::ERROR_SILENT); if ($dw->setExistingData($dataId) && $dw->get('width') && XenForo_Image_Abstract::canResize($dw->get('width'), $dw->get('height'))) { $attach = $dw->getMergedData(); $attachFile = $attachmentModel->getAttachmentDataFilePath($attach); $imageInfo = @getimagesize($attachFile); if ($imageInfo) { try { $image = XenForo_Image_Abstract::createFromFile($attachFile, $imageInfo[2]); } catch (Exception $e) { XenForo_Error::logException($e, false, "Thumbnail rebuild error {$attachFile}: "); continue; } if ($image) { if ($image->thumbnail(XenForo_Application::get('options')->attachmentThumbnailDimensions)) { ob_start(); $image->output($imageInfo[2]); $thumbData = ob_get_contents(); ob_end_clean(); } else { // no resize necessary, use the original $thumbData = file_get_contents($attachFile); } $dw->set('thumbnail_width', $image->getWidth()); $dw->set('thumbnail_height', $image->getHeight()); $dw->setExtraData(XenForo_DataWriter_AttachmentData::DATA_THUMB_DATA, $thumbData); try { $dw->save(); } catch (Exception $e) { XenForo_Error::logException($e, false, "Thumb rebuild for #{$dataId}: "); } unset($image); } } } if ($targetRunTime && microtime(true) - $s > $targetRunTime) { break; } } $actionPhrase = new XenForo_Phrase('rebuilding'); $typePhrase = new XenForo_Phrase('attachment_thumbnails'); $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position'])); return $data; }
public function actionStaffShare() { $visitor = XenForo_Visitor::getInstance(); if (!$visitor->hasPermission('general', 'bdSocialShare_staffShare')) { return $this->responseNoPermission(); } $url = $this->_input->filterSingle('url', XenForo_Input::STRING); if (empty($url)) { return $this->responseView('bdSocialShare_ViewPublic_Misc_StaffShare_UrlForm', 'bdsocialshare_staff_share_url_form'); } $request = new Zend_Controller_Request_Http($url); $request->setParamSources(array()); $routeMatch = bdSocialShare_Listener::getDependencies()->route($request); $shareable = $this->getModelFromCache('bdSocialShare_Model_Publisher')->getShareableForRouteMatchAndRequest($routeMatch, $request); if (empty($shareable)) { return $this->responseMessage(new XenForo_Phrase('bdsocialshare_url_x_is_not_supported', array('url' => $url))); } $userModel = $this->getModelFromCache('XenForo_Model_User'); $viewingUserGuest = $userModel->getVisitingGuestUser(); $userModel->bdSocialShare_prepareViewingUser($viewingUserGuest); $shareable->setViewingUser($viewingUserGuest); $publisherModel = $this->getModelFromCache('bdSocialShare_Model_Publisher'); $facebookAccounts = false; if (bdSocialShare_Option::hasPermissionFacebook($viewingUserGuest)) { $facebookAccounts = $this->getModelFromCache('bdSocialShare_Model_Facebook')->getAccounts(); } $twitterAccounts = false; if (bdSocialShare_Option::hasPermissionTwitter($viewingUserGuest)) { $twitterAccounts = $this->getModelFromCache('bdSocialShare_Model_Twitter')->getAccounts(); } if ($this->isConfirmedPost()) { $target = $this->_input->filterSingle('target', XenForo_Input::STRING); $targetId = $this->_input->filterSingle('target_id', XenForo_Input::STRING); $data = $this->_input->filter(array('userText' => XenForo_Input::STRING, 'title' => XenForo_Input::STRING, 'description' => XenForo_Input::STRING, 'image' => XenForo_Input::STRING)); $data['link'] = $shareable->getLink($publisherModel); $staffShareSharable = new bdSocialShare_Shareable_StaffShare($data); $published = false; try { $published = $publisherModel->publish($target, $targetId, $staffShareSharable, $viewingUserGuest); } catch (XenForo_Exception $e) { XenForo_Error::logException($e); } if ($published) { XenForo_Model_Log::logModeratorAction('bdsocialshare_all', $data, $target, array('target_id' => $targetId)); return $this->responseMessage(new XenForo_Phrase('bdsocialshare_staff_share_published_successfully')); } else { return $this->responseError(new XenForo_Phrase('unexpected_error_occurred')); } } $viewParams = array('facebookAccounts' => $facebookAccounts, 'twitterAccounts' => $twitterAccounts, 'hasAdminPermissionOption' => $visitor->hasAdminPermission('option'), 'url' => $url, 'link' => $shareable->getLink($publisherModel), 'userText' => strval($shareable->getUserText($publisherModel)), 'title' => strval($shareable->getTitle($publisherModel)), 'description' => strval($shareable->getDescription($publisherModel)), 'image' => $shareable->getImage($publisherModel)); return $this->responseView('bdSocialShare_ViewPublic_Misc_StaffShare', 'bdsocialshare_staff_share', $viewParams); }
public function insertTranscodeQueue(array $data) { XenForo_Application::getDb()->insert('xengallery_transcode_queue', array('queue_data' => @serialize($data), 'queue_date' => XenForo_Application::$time)); if (!$this->isDeferredQueued()) { try { XenForo_Application::defer('XenGallery_Deferred_TranscodeQueue', array(), 'TranscodeQueue'); } catch (Exception $e) { // need to just ignore this and let it get picked up later XenForo_Error::logException($e, false); } } return true; }
protected function _postDelete() { parent::_postDelete(); $discordId = $this->getExisting('da_discord_id'); if ($discordId !== null) { XenForo_CodeEvent::addListener('controller_post_dispatch', function ($c, $r, $n, $a) use($discordId) { try { self::refreshDiscordId($discordId); } catch (Exception $e) { XenForo_Error::logException($e, false); } }); } }
/** * Gets Facebook user info from the specified place. * * @param string $accessToken FB access token (from code swap, or given by user); may be empty * @param string $path Path to access (defaults to "me") * * @return array Info; may be error */ public static function getUserInfo($accessToken, $path = 'me') { try { $client = XenForo_Helper_Http::getClient('https://graph.facebook.com/' . $path); if ($accessToken) { $client->setParameterGet('access_token', $accessToken); } $response = $client->request('GET'); return json_decode($response->getBody(), true); } catch (Zend_Http_Client_Exception $e) { XenForo_Error::logException($e, false); return false; } }
protected function _postSave() { if ($this->isInsert()) { $function = sprintf('_sendAlerts_%s', $this->get('comment_type')); $comment = $this->getMergedData(); $team = $this->_getTeamData(); try { $this->{$function}($comment, $team); } catch (Exception $e) { XenForo_Error::logException($e); } // should be update new feed! $this->_publishToNewsFeed(); $db = $this->_db; $db->update('xf_team', array('last_activity' => XenForo_Application::$time), 'team_id = ' . $db->quote($this->get('team_id'))); } }
/** * Run all (or as many as possible) outstanding cron entries. * Confirms via an atomic update that the entries are runnable first. */ public function run() { /* @var $cronModel XenForo_Model_Cron */ $cronModel = XenForo_Model::create('XenForo_Model_Cron'); $entries = $cronModel->getCronEntriesToRun(); foreach ($entries as $entry) { if (!$cronModel->updateCronRunTimeAtomic($entry)) { continue; } try { $cronModel->runEntry($entry); } catch (Exception $e) { // suppress so we don't get stuck XenForo_Error::logException($e); } } $cronModel->updateMinimumNextRunTime(); }
public function execute(array $deferred, array $data, $targetRunTime, &$status) { /* @var $emailModel XenForo_Model_EmailBounce */ $emailModel = XenForo_Model::create('XenForo_Model_EmailBounce'); if (!isset($data['start'])) { $data['start'] = time(); } $s = microtime(true); try { $connection = $emailModel->openBounceHandlerConnection(); if (!$connection) { return false; } } catch (Zend_Mail_Exception $e) { XenForo_Error::logException($e); return false; } $total = $connection->countMessages(); if (!$total) { return false; } $finished = true; for ($messageId = $total, $i = 0; $messageId > 0; $messageId--, $i++) { if ($i > 0 && $targetRunTime && microtime(true) - $s >= $targetRunTime) { $finished = false; break; } $headers = $connection->getRawHeader($messageId); $content = $connection->getRawContent($messageId); $connection->removeMessage($messageId); $rawMessage = trim($headers) . "\r\n\r\n" . trim($content); $emailModel->processBounceEmail($rawMessage); } $connection->close(); if ($finished) { return false; } else { if (time() - $data['start'] > 60 * 30) { // don't let a single run of this run for more than 30 minutes return false; } return $data; } }
public function deleteMulti($itemNamePattern) { $cache = $this->_getCache(true); if (empty($cache)) { if (empty(self::$loggedMissingRedis)) { self::$loggedMissingRedis = true; XenForo_Error::logException(new Exception("No Cache setup")); } return; } $credis = $this->getCredis($cache); if (empty($credis)) { if (empty(self::$loggedMissingRedis)) { self::$loggedMissingRedis = true; XenForo_Error::logException(new Exception("Redis Cache is not setup")); } return; } $prefix = Cm_Cache_Backend_Redis::PREFIX_KEY . $cache->getOption('cache_id_prefix'); $pattern = $prefix . $itemNamePattern; // indicate to the redis instance would like to process X items at a time. $count = 1000; // find indexes matching the pattern $cursor = null; $keys = array(); while (true) { $next_keys = $credis->scan($cursor, $pattern, $count); // scan can return an empty array if ($next_keys) { $keys += $next_keys; } if (empty($cursor) || $next_keys === false) { break; } } if ($keys) { // delete them, use pipelining $credis->pipeline()->multi(); foreach ($keys as $key) { $credis->del($key); } $credis->exec(); } }
/** * Determines if CAPTCHA is valid (passed). * * @see XenForo_Captcha_Abstract::isValid() */ public function isValid(array $input) { if (!$this->_config['privateKey'] || !$this->_config['publicKey']) { return true; // if not configured, always pass } if (empty($input['recaptcha_challenge_field']) || empty($input['recaptcha_response_field'])) { return false; } try { $recaptcha = new Zend_Service_ReCaptcha($this->_config['publicKey'], $this->_config['privateKey']); $result = $recaptcha->verify($input['recaptcha_challenge_field'], $input['recaptcha_response_field']); return $result->isValid(); } catch (Zend_Http_Client_Adapter_Exception $e) { // this is an exception with the underlying request, so let it go through XenForo_Error::logException($e, false); return true; } }
public static function getGroups($accessToken) { try { $client = XenForo_Helper_Http::getClient('https://graph.facebook.com/v2.0/me/groups'); $client->setParameterGet('access_token', $accessToken); $response = $client->request('GET'); $jsonDecoded = json_decode($response->getBody(), true); if (!empty($jsonDecoded['data'])) { $groups = array(); foreach ($jsonDecoded['data'] as $entry) { $groups[$entry['id']] = array('name' => $entry['name'], 'target_id' => bdSocialShare_Helper_Common::encryptTargetId($entry['name'], array('targetId' => $entry['id'], 'accessToken' => $accessToken, 'type' => 'group'))); } return $groups; } } catch (Zend_Http_Client_Exception $e) { if (XenForo_Application::debugMode()) { XenForo_Error::logException($e, false); } } return false; }
public function isValidTag($tag) { $length = utf8_strlen($tag); $lengthLimits = XenForo_Application::getOptions()->tagLength; $minLength = max($lengthLimits['min'], 1); $maxLength = $lengthLimits['max'] <= 0 ? 100 : min($lengthLimits['max'], 100); if ($length < $minLength) { return false; } if ($length > $maxLength) { return false; } $validation = XenForo_Application::getOptions()->tagValidation; $disallowed = preg_split('/\\r?\\n/', $validation['disallowedWords']); if ($disallowed) { foreach ($disallowed as $disallowedCheck) { $disallowedCheck = trim($disallowedCheck); if ($disallowedCheck === '') { continue; } if (stripos($tag, $disallowedCheck) !== false) { return false; } } } if ($validation['matchRegex'] && !preg_match('/\\W[\\s\\w]*e[\\s\\w]*$/', $validation['matchRegex'])) { try { if (!preg_match($validation['matchRegex'], $tag)) { return false; } } catch (Exception $e) { XenForo_Error::logException($e, false); } } $censored = XenForo_Helper_String::censorString($tag); if ($censored != $tag) { return false; } return true; }
/** * * @see XenForo_ControllerPublic_Account::actionPrivacySave() */ public function actionPrivacySave() { if (ThemeHouse_Listener_ControllerPreDispatch::isAddOnEnabled('xfa_blogs')) { try { $userId = XenForo_Visitor::getUserId(); $allowViewBlog = $this->_input->filterSingle('allow_view_blog', XenForo_Input::STRING); $allowViewBlogGroup = 0; if (is_numeric($allowViewBlog)) { $allowViewBlogGroup = $allowViewBlog; $this->_request->setParam('allow_view_blog', 'group'); } // save the privacy settings if ($userId) { $db = XenForo_Application::getDb(); $db->query("UPDATE xf_user_privacy SET allow_view_blog_group = ? WHERE user_id = ?", array($allowViewBlogGroup, $userId)); } } catch (Exception $ex) { XenForo_Error::logException($ex, false); } } return parent::actionPrivacySave(); }
public function parseSVG($filename) { $svgfile = null; try { if (method_exists('XenForo_Helper_DevelopmentXml', 'scanFile')) { $svgfile = XenForo_Helper_DevelopmentXml::scanFile($filename); } else { $svgfile = new SimpleXMLElement($filename, 0, true); } } catch (Exception $e) { XenForo_Error::logException($e, false); $svgfile = null; } if (empty($svgfile)) { return null; } // check for bad tags $options = XenForo_Application::getOptions(); $badTags = array_fill_keys(explode(',', strtolower($options->SV_AttachImpro_badTags)), true); $badAttributes = array_fill_keys(explode(',', strtolower($options->SV_AttachmentImprovements_badAttributes)), true); return $this->_scanSVG($svgfile, $badTags, $badAttributes); }
public function handle($addOnId) { try { $addOnId = strtolower($addOnId); $root = XenForo_Application::getInstance()->getRootDir() . '/styles'; if (!($root = realpath($root)) || !is_dir($root)) { return; } $source = $root . '/default/' . $addOnId; if (!($source = realpath($source)) || !is_dir($source)) { return; } $available = GFNCore_Helper_Directory::read($root, false); foreach ($available as $i => $path) { if (is_dir($path) && basename($path) != 'default') { $target = $path . '/' . $addOnId; GFNCore_Helper_Directory::copy($source, $target); } } } catch (Exception $e) { XenForo_Error::logException($e, false); } }
public function call($service, array $params = array()) { $client = $this->_getXmlRpcClient(); if (!$client) { return array(); } if ($service != 'DataService.getTemporaryKey') { $key = XenForo_Application::get('options')->th_infusionsoftApi_key; array_unshift($params, $key); } try { $result = $client->call($service, $params); } catch (Zend_XmlRpc_Client_FaultException $e) { $message = $e->getMessage(); preg_match('#^\\[([A-z]*)\\](.*)$#', $message, $matches); if ($matches) { return array('error' => array($matches[1] => $matches[2])); } XenForo_Error::logException($e, false); return array(); } return $result; }
public function recover($target, $recovery = false) { if ($recovery === false) { $recovery = $this->loadRecoveryData(); } // reset recovery asap, it will be updated later $this->_getPublisherModel()->saveRecoveryData(); $recovered = true; if (empty($recovery) or empty($recovery['shareable']) or empty($recovery['targets'])) { return false; } if (empty($recovery['targets'][$target])) { return false; } $targetId = $recovery['targets'][$target]; $shareable = bdSocialShare_Shareable_Abstract::createFromRecoveryData($recovery['shareable']); if (empty($shareable)) { return false; } try { $this->_getPublisherModel()->publish($target, $targetId, $shareable); $this->_getPublisherModel()->postPublish($shareable); $recovered = true; } catch (bdSocialShare_Exception_Abstract $e) { if (XenForo_Application::debugMode()) { XenForo_Error::logException($e, false); } } if ($recovered) { // remove the target from the queue unset($recovery['targets'][$target]); } if (!empty($recovery['targets'])) { // still have something in queue, set recovery... $this->_getPublisherModel()->saveRecoveryData($recovery['shareable'], $recovery['targets']); } }
/** * Get the data and determine if we need to change the response code to 410. * * @param XenForo_Controller $controller * @param XenForo_ControllerResponse_Abstract|false $controllerResponse * @param string $controllerName * @param string $action * * @throws XenForo_Exception */ public static final function controllerPostDispatch(XenForo_Controller $controller, $controllerResponse, $controllerName, $action) { if ($controller instanceof XenForo_ControllerPublic_Abstract && $controllerResponse instanceof XenForo_ControllerResponse_Error && $controllerResponse->responseCode == 404) { $data = array(); XenForo_CodeEvent::fire('410_gone_data', array(&$data, $controller, $controllerName, $action)); $table = $field = ''; foreach ($data as $_controllerName => $info) { if ($_controllerName == $controllerName) { list($table, $field) = $info; break; } } if (($id = $controller->getInput()->filterSingle($field, XenForo_Input::UINT)) && $table && $field) { $db = XenForo_Application::getDb(); try { if (!$db->fetchOne("SELECT {$field} FROM {$table} WHERE {$field} = ?", $id) && $db->fetchOne("SELECT COUNT(*) FROM {$table} WHERE {$field} > ?", $id) > 0) { $controllerResponse->responseCode = 410; } } catch (Throwable $e) { XenForo_Error::logException($e, false, "410 Query Failed (Field: {$field}, Table: {$table}): "); } } } }
/** * Determines if CAPTCHA is valid (passed). * * @see XenForo_Captcha_Abstract::isValid() */ public function isValid(array $input) { if (!$this->_siteKey || !$this->_secretKey) { return true; // if not configured, always pass } if (empty($input['g-recaptcha-response'])) { return false; } $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; try { $client = XenForo_Helper_Http::getClient('https://www.google.com/recaptcha/api/siteverify'); $client->setParameterGet(array('secret' => $this->_secretKey, 'response' => $input['g-recaptcha-response'], 'remoteip' => $ip)); $response = json_decode($client->request()->getBody(), true); if (isset($response['success'])) { return $response['success']; } return false; } catch (Zend_Http_Client_Adapter_Exception $e) { // this is an exception with the underlying request, so let it go through XenForo_Error::logException($e, false, "ReCAPTCHA (No CAPTCHA) connection error: "); return true; } }
public static function getViewObject(array $params, XenForo_Template_Abstract $templateObj) { if (isset($params[WidgetFramework_Core::PARAM_VIEW_OBJECT])) { return $params[WidgetFramework_Core::PARAM_VIEW_OBJECT]; } $viewObj = $templateObj->getParam(WidgetFramework_Core::PARAM_VIEW_OBJECT); if (!empty($viewObj)) { return $viewObj; } if (empty(self::$_pseudoViewObj)) { if (!empty(WidgetFramework_Listener::$fc) and !empty(WidgetFramework_Listener::$viewRenderer)) { if (WidgetFramework_Listener::$viewRenderer instanceof XenForo_ViewRenderer_HtmlPublic) { self::$_pseudoViewObj = new XenForo_ViewPublic_Base(WidgetFramework_Listener::$viewRenderer, WidgetFramework_Listener::$fc->getResponse()); } } } if (!empty(self::$_pseudoViewObj)) { return self::$_pseudoViewObj; } if (WidgetFramework_Core::debugMode()) { // log the exception for admin examination (in our debug mode only) XenForo_Error::logException(new XenForo_Exception(sprintf('Unable to get view object for %s', $templateObj->getTemplateName())), false, '[bd] Widget Framework'); } return null; }