/** * 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; } }
/** * Checks if the $post is the one specified in the $unreadLink. If the $unreadLink is * empty or there is no post id in the link, true will be return asap. * Please note that for the entire request, this method only return true once. * * Usage: {xen:helper wf_unreadLinkPost, $unreadLink, $post, $posts} * Recommended position: hook:message_below * * @param string $unreadLink * @param array $post * @param array $posts * @return bool */ public function unreadLinkPost($unreadLink, $post, $posts) { static $found = false; static $postFragment = '#post-'; if ($found) { // return true once return false; } if (!is_array($post) || !isset($post['post_id']) || !is_array($posts)) { // incorrect usage... if (XenForo_Application::debugMode()) { XenForo_Error::logError('{xen:helper wf_unreadLinkPost} requires (string $unreadLink),' . ' (array $post), (array $posts)'); } $found = true; } else { $postPos = strpos($unreadLink, $postFragment); if ($postPos === false) { // wait for the last post and return true $postIds = array_keys($posts); $lastPostId = array_pop($postIds); $found = $lastPostId == $post['post_id']; } else { // return true for the specified unread post $unreadLinkPostId = substr($unreadLink, $postPos + strlen($postFragment)); $found = $unreadLinkPostId == $post['post_id']; } } return $found; }
public function extraPrepareTitle(array $widget) { if (!empty($widget['title'])) { if (is_string($widget['title']) && preg_match('/^{xen:phrase ([^}]+)}$/i', $widget['title'], $matches)) { // {xen:phrase title} as widget title, use the specified phrase if (XenForo_Application::debugMode()) { // this kind of usage is deprecated, log server error entry if debug mode is on XenForo_Error::logError(sprintf('Widget title support for {xen:phrase title} has been deprecated. ' . 'Please update widget #%d.', $widget['widget_id'])); } return new XenForo_Phrase($matches[1]); } else { if (!empty($widget['options'][WidgetFramework_DataWriter_Widget::WIDGET_OPTION_ADDON_VERSION_ID]) && $widget['widget_id'] > 0) { // since 2.6.0 // use self-managed phrase for widget title /** @var WidgetFramework_Model_Widget $widgetModel */ $widgetModel = WidgetFramework_Core::getInstance()->getModelFromCache('WidgetFramework_Model_Widget'); return new XenForo_Phrase($widgetModel->getWidgetTitlePhrase($widget['widget_id'])); } else { // legacy support return $widget['title']; } } } else { return $this->getName(); } }