/** * Get a Gravatar URL for a specified email address. * * @param string $email The email address * * @return String containing either just a URL or a complete image tag * * @source http://gravatar.com/site/implement/images/php/ */ private static function getGravatar($email) { $s = 80; // Size in pixels, defaults to 80px [ 1 - 2048 ] $d = 'mm'; // Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] $r = 'g'; // Maximum rating (inclusive) [ g | pg | r | x ] if ($helper = Xoops\Module\Helper::getHelper('gravatars')) { $v = $helper->getConfig('pixel_size'); $s = empty($v) ? $s : $v; $v = $helper->getConfig('default_imageset'); $d = empty($v) ? $d : $v; $d = $d == 'default' ? '' : $d; // preferences does not like empty string $v = $helper->getConfig('max_rating'); $r = empty($v) ? $r : $v; } $scheme = \Xoops\Core\HttpRequest::getInstance()->getScheme(); if ($scheme == 'https') { $url = 'https://secure.gravatar.com/avatar/'; } else { $url = 'http://www.gravatar.com/avatar/'; } $url .= md5(strtolower(trim($email))); $url .= "?s={$s}&d={$d}&r={$r}"; return $url; }
/** * establish access to other classes we will use */ public function __construct() { $this->xoops = \Xoops::getInstance(); $this->httpRequest = HttpRequest::getInstance(); $this->sessionUser = new SessionUser($this); $this->fingerprint = new Fingerprint(); }
/** * grab things from the http request we need to use. * * @return string[] array of fingerprint values */ protected function takePrint() { $clientFingerprint = array(); $httpRequest = HttpRequest::getInstance(); $clientFingerprint['clientIp'] = $httpRequest->getClientIp(); $clientFingerprint['userAgent'] = $httpRequest->getHeader('USER_AGENT'); $clientFingerprint['acceptLanguage'] = $httpRequest->getHeader('ACCEPT_LANGUAGE'); return $clientFingerprint; }
/** * Blocks functions * * @copyright XOOPS Project (http://xoops.org) * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) * @author Kazumi Ono (AKA onokazu) * @package system * @version $Id$ */ function b_system_user_show() { $xoops = Xoops::getInstance(); if (!$xoops->isUser()) { return false; } $block = array(); $block['modules'] = array(); $plugins = \Xoops\Module\Plugin::getPlugins('system'); $i = 0; /* @var $plugin SystemPluginInterface */ foreach ($plugins as $dirname => $plugin) { $menu = $plugin->userMenus(); if (is_array($menu) && !empty($menu)) { $block['modules'][$i]['name'] = $menu['name']; $block['modules'][$i]['link'] = $xoops->url('modules/' . $dirname . '/' . $menu['link']); $block['modules'][$i]['image'] = $menu['image']; $block['modules'][$i]['icon'] = 'icon-tags'; $block['modules'][$i]['dirname'] = $dirname; //todo, remove this hardcoded call if ($xoops->isModule() && $xoops->module->getVar('dirname') == $dirname && ($plugin = \Xoops\Module\Plugin::getPlugin($dirname, 'menus'))) { if (method_exists($plugin, 'subMenus')) { $sublinks = $plugin->subMenus(); foreach ($sublinks as $sublink) { $block['modules'][$i]['sublinks'][] = array('name' => $sublink['name'], 'url' => \XoopsBaseConfig::get('url') . '/modules/' . $dirname . '/' . $sublink['url']); } } } ++$i; } } // View Account array_unshift($block['modules'], array('name' => XoopsLocale::VIEW_ACCOUNT, 'link' => $xoops->url('userinfo.php?uid=' . $xoops->user->getVar('uid')), 'icon' => 'icon-user')); // Edit Account array_unshift($block['modules'], array('name' => XoopsLocale::EDIT_ACCOUNT, 'link' => $xoops->url('edituser.php'), 'icon' => 'icon-user')); // Administration Menu if ($xoops->isAdmin()) { array_unshift($block['modules'], array('name' => SystemLocale::ADMINISTRATION_MENU, 'link' => $xoops->url('admin.php'), 'rel' => 'external', 'icon' => 'icon-wrench')); } // Inbox $criteria = new CriteriaCompo(new Criteria('read_msg', 0)); $criteria->add(new Criteria('to_userid', $xoops->user->getVar('uid'))); $pm_handler = $xoops->getHandlerPrivateMessage(); $xoops->preload()->triggerEvent('system.blocks.system_blocks.usershow', array(&$pm_handler)); $name = XoopsLocale::INBOX; $class = ''; if ($pm_count = $pm_handler->getCount($criteria)) { $name = XoopsLocale::INBOX . ' <strong>' . $pm_count . '</strong>'; $class = 'highlight'; } array_push($block['modules'], array('name' => $name, 'link' => $xoops->url('viewpmsg.php'), 'icon' => 'icon-envelope', 'class' => $class)); // Logout array_push($block['modules'], array('name' => XoopsLocale::A_LOGOUT, 'link' => $xoops->url('user.php?op=logout'), 'icon' => 'icon-off')); $block['active_url'] = \Xoops\Core\HttpRequest::getInstance()->getUrl(); return $block; }
/** * Get Environment Value * * @param string $key key (name) in the environment * * @return string */ public function getEnv($key) { return HttpRequest::getInstance()->getEnv($key, ''); }
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ use Xoops\Core\Request; /** * @copyright XOOPS Project (http://xoops.org) * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) * @author trabis <*****@*****.**> * @version $Id$ */ include dirname(dirname(__DIR__)) . '/mainfile.php'; $xoops = Xoops::getInstance(); // Warning: code depending on Xoops\Core\HttpRequest may need to change $request = \Xoops\Core\HttpRequest::getInstance(); $xoops->header(); \Xoops\Utils::dumpVar(Request::get()); $result['id'] = Request::getInt('id', 13); $result['string'] = Request::getString('string', 'defaultValueHere'); $result['bool'] = Request::getBool('bool', false); $result['order'] = Request::getString('order', 'ASC'); $result['url'] = $request->getUrl(); $result['uri'] = $request->getUri(); $result['referer'] = $request->getReferer(); $result['phpsessid_cookie'] = Request::getString('PHPSESSID', '', 'cookie'); $result['ip'] = $request->getClientIp(); $result['isget'] = 'GET' === Request::getMethod(); $result['ispost'] = 'POST' === Request::getMethod(); $result['ismobile'] = $request->is('mobile'); $result['isrobot'] = $request->is('robot');
/** * @covers Xoops\Core\HttpRequest::getInstance */ public function testGetInstance() { $instance = HttpRequest::getInstance(); $this->assertInstanceOf($this->myClass, $instance); $this->assertSame($instance, $this->object); }
/** * Update cookie status for current session * * @param array|string $cookieData usercookie value * @param integer $expire seconds until usercookie expires * * @return void **/ protected function writeUserCookie($cookieData, $expire = 2592000) { $usercookie = $this->xoops->getConfig('usercookie'); if (empty($usercookie)) { return; // remember me is not configured } if (is_array($cookieData)) { $cookieData = implode('-', $cookieData); } $httpRequest = HttpRequest::getInstance(); $path = \XoopsBaseConfig::get('cookie-path'); $domain = \XoopsBaseConfig::get('cookie-domain'); $secure = $httpRequest->is('ssl'); setcookie($usercookie, $cookieData, $this->now + $expire, $path, $domain, $secure, true); }
/** * getUserLocales() * Returns the user locales * Normally it returns an array like this: * 1. Forced language * 2. Language in $_GET['lang'] * 3. Language in $_SESSION['lang'] * 4. HTTP_ACCEPT_LANGUAGE * 5. Fallback language * Note: duplicate values are deleted. * * @return array with the user locales sorted by priority. Highest is best. */ public static function getUserLocales() { if (empty(self::$userLocales)) { // reset user_lang array $userLocales = array(); // Highest priority: forced language //if ($this->forcedLang != NULL) { // $userLocales[] = $this->forcedLang; //} // 2nd highest priority: GET parameter 'lang' $requestLocale = self::normalizeLocale(Request::getString('lang', '')); if (!empty($requestLocale)) { $userLocales[] = $requestLocale; } // 3rd highest priority: SESSION parameter 'lang' if (isset($_SESSION['lang']) && is_string($_SESSION['lang'])) { $userLocales[] = self::normalizeLocale($_SESSION['lang']); } // 4th highest priority: HTTP_ACCEPT_LANGUAGE $browserLocales = HttpRequest::getInstance()->getAcceptedLanguages(); $browserLocales = array_keys($browserLocales); foreach ($browserLocales as $bloc) { $userLocales[] = self::normalizeLocale($bloc); } $configLocale = \Xoops::getInstance()->getConfig('locale'); if (!empty($configLocale)) { $userLocales[] = $configLocale; } // Lowest priority: fallback $userLocales[] = static::FALLBACK_LOCALE; static::$userLocales = array_unique($userLocales); } return static::$userLocales; }