/** * Utility function to obtain PATH_INFO information. * * @return string The PATH_INFO string. */ public static function getPathInfo() { if (isset($_SERVER['PATH_INFO']) && strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') === false) { return $_SERVER['PATH_INFO']; } elseif (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['SCRIPT_NAME'])) { $search = Horde_String::common($_SERVER['SCRIPT_NAME'], $_SERVER['REQUEST_URI']); if (substr($search, -1) == '/') { $search = substr($search, 0, -1); } $search = array($search); if (!empty($_SERVER['QUERY_STRING'])) { // We can't use QUERY_STRING directly because URL rewriting // might add more parameters to the query string than those // from the request URI. $url = parse_url($_SERVER['REQUEST_URI']); if (!empty($url['query'])) { $search[] = '?' . $url['query']; } } $path = str_replace($search, '', $_SERVER['REQUEST_URI']); if ($path == '/') { $path = ''; } return $path; } return ''; }
/** * Constructs a standard page class to represent a wiki page. * * @param string $pagename The name of the page to represent. */ public function __construct($pagename) { if (is_array($pagename)) { $this->_page = $pagename; return; } $page = null; try { $page = $GLOBALS['wicked']->retrieveByName($pagename); } catch (Wicked_Exception $e) { // If we can't load $pagename, see if there's default data for it. // Protect against directory traversion. $pagepath = realpath(WICKED_BASE . '/data/' . $GLOBALS['conf']['wicked']['format']); $pagefile = realpath($pagepath . '/' . $pagename); if ($pagefile && Horde_String::common($pagefile, $pagepath) == $pagepath && substr($pagename, 0, 1) != '.' && file_exists($pagefile) && ($text = file_get_contents($pagefile))) { try { $GLOBALS['wicked']->newPage($pagename, $text); try { $page = $GLOBALS['wicked']->retrieveByName($pagename); } catch (Wicked_Exception $e) { $GLOBALS['notification']->push(sprintf(_("Unable to create %s"), $pagename), 'horde.error'); } } catch (Wicked_Exception $e) { } } } if ($page) { $this->_page = $page; } else { if ($pagename == 'Wiki/Home') { $GLOBALS['notification']->push(_("Unable to create Wiki/Home. The wiki is not configured."), 'horde.error'); } $this->_page = array(); } // Make sure 'wicked' permission exists. Set reasonable defaults if // necessary. $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); $corePerms = $GLOBALS['injector']->getInstance('Horde_Core_Perms'); if (!$perms->exists('wicked')) { $perm = $corePerms->newPermission('wicked'); $perm->addGuestPermission(Horde_Perms::SHOW | Horde_Perms::READ, false); $perm->addDefaultPermission(Horde_Perms::SHOW | Horde_Perms::READ | Horde_Perms::EDIT | Horde_Perms::DELETE, false); $perms->addPermission($perm); } // Make sure 'wicked:pages' exists. Copy from 'wicked' if it does not // exist. if (!$perms->exists('wicked:pages')) { $perm = $corePerms->newPermission('wicked:pages'); $copyFrom = $perms->getPermission('wicked'); $perm->addGuestPermission($copyFrom->getGuestPermissions(), false); $perm->addDefaultPermission($copyFrom->getDefaultPermissions(), false); $perm->addCreatorPermission($copyFrom->getCreatorPermissions(), false); foreach ($copyFrom->getUserPermissions() as $user => $uperm) { $perm->addUserPermission($user, $uperm, false); } foreach ($copyFrom->getGroupPermissions() as $group => $gperm) { $perm->addGroupPermission($group, $gperm, false); } $perms->addPermission($perm); } if ($GLOBALS['conf']['lock']['driver'] != 'none') { $this->supportedModes[Wicked::MODE_LOCKING] = $this->supportedModes[Wicked::MODE_UNLOCKING] = true; $this->_locks = $GLOBALS['injector']->getInstance('Horde_Lock'); $locks = $this->_locks->getLocks('wicked', $pagename, Horde_Lock::TYPE_EXCLUSIVE); if ($locks) { $this->_lock = reset($locks); } } }
/** * Returns a session-id-ified version of $SCRIPT_NAME resp. $PHP_SELF. * * @param boolean $script_params Include script parameters like * QUERY_STRING and PATH_INFO? * (Deprecated: use Horde::selfUrlParams() * instead.) * @param boolean $nocache Include a cache-buster parameter in the * URL? * @param boolean $full Return a full URL? * @param boolean $force_ssl Ignore $conf['use_ssl'] and force creation * of a SSL URL? * * @return Horde_Url The requested URL. */ public static function selfUrl($script_params = false, $nocache = true, $full = false, $force_ssl = false) { if (!strncmp(PHP_SAPI, 'cgi', 3)) { // When using CGI PHP, SCRIPT_NAME may contain the path to // the PHP binary instead of the script being run; use // PHP_SELF instead. $url = $_SERVER['PHP_SELF']; } else { $url = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : $_SERVER['PHP_SELF']; } if (isset($_SERVER['REQUEST_URI'])) { $url = Horde_String::common($_SERVER['REQUEST_URI'], $url); } if (substr($url, -9) == 'index.php') { $url = substr($url, 0, -9); } if ($script_params) { if ($pathInfo = Horde_Util::getPathInfo()) { if (substr($url, -1) == '/') { $pathInfo = substr($pathInfo, 1); } $url .= $pathInfo; } if (!empty($_SERVER['QUERY_STRING'])) { $url .= '?' . $_SERVER['QUERY_STRING']; } } $url = self::url($url, $full, array('force_ssl' => $force_ssl)); return $nocache && $GLOBALS['browser']->hasQuirk('cache_same_url') ? $url->unique() : $url; }