Compare commits

...

25 Commits
master ... phar

Author SHA1 Message Date
Christian Weiske
f36c79cb7b phar + clean urls work fully now 2014-03-26 21:54:55 +01:00
Christian Weiske
995dbef2a1 map clean urls to .php files in phar 2014-03-26 21:54:51 +01:00
Christian Weiske
fb4d822f31 make "php dist/SemanticScuttle-0.98.X.phar r scripts/avahi-export.php" work 2014-03-26 21:54:46 +01:00
Christian Weiske
9a57269b23 introduce global $cfg variable that one day will get rid of all the $GLOBALS pollution 2014-03-26 21:54:41 +01:00
Christian Weiske
524b1056a6 troubleshooting 2014-03-26 21:54:36 +01:00
Christian Weiske
6f5cd7c6e4 phar installation instructions 2014-03-26 21:54:22 +01:00
Christian Weiske
7947dad6a5 implement extracting files and running scripts 2014-03-26 21:53:00 +01:00
Christian Weiske
897bc4f7dc use console_commandline to handle cli arguments 2014-03-26 21:52:56 +01:00
Christian Weiske
d49a9e684b map calls to phar without anything 2014-03-26 21:52:51 +01:00
Christian Weiske
75156bfd20 first version of phar cli interface; currently lists files only 2014-03-26 21:52:47 +01:00
Christian Weiske
afe1fbd4b4 phar setup 2014-03-26 21:52:42 +01:00
Christian Weiske
557467b2b4 properly detect path info when running in the phar without /www/ 2014-03-26 21:51:35 +01:00
Christian Weiske
2333ebf0e7 fix config tests 2014-03-26 21:50:20 +01:00
Christian Weiske
e991f209bc get rid of www/ in phar 2014-03-26 21:50:13 +01:00
Christian Weiske
3070f234b6 fix file inclusion with phar 2014-03-26 21:49:38 +01:00
Christian Weiske
e6d66690d2 fix PATH_INFO in phar mode
Conflicts:
	src/SemanticScuttle/Environment.php
	src/SemanticScuttle/constants.php
	tests/SemanticScuttle/EnvironmentTest.php
2014-03-26 21:47:33 +01:00
Christian Weiske
aed211c5b2 provide mapping for /www/ 2014-03-26 21:43:42 +01:00
Christian Weiske
64923095e6 detect correct root path when run from the phar 2014-03-26 21:43:37 +01:00
Christian Weiske
f93c3bbe76 test configurable root 2014-03-26 21:43:32 +01:00
Christian Weiske
b0e4b4390b move root directory detection into SemanticScuttle_Environment to make it testable
Conflicts:
	tests/SemanticScuttle/EnvironmentTest.php
2014-03-26 17:19:05 +01:00
Christian Weiske
bbe708ce17 delete phar file before generating it 2014-03-26 17:16:18 +01:00
Christian Weiske
160ef2d631 own stub for the phar to disallow access to anything but www/ 2014-03-26 17:16:11 +01:00
Christian Weiske
b73d18af88 load configuration for phar files
Conflicts:
	src/SemanticScuttle/Config.php
2014-03-26 17:15:54 +01:00
Christian Weiske
ddcf7cd2a3 we have no hostname on cli (phar) 2014-03-26 17:11:53 +01:00
Christian Weiske
72db833930 phar generation task
Conflicts:
	build.xml
2014-03-26 17:11:37 +01:00
27 changed files with 793 additions and 73 deletions

View File

@ -22,8 +22,10 @@
" /> " />
<property name="zipfile" value="${phing.project.name}-${version}.zip" /> <property name="zipfile" value="${phing.project.name}-${version}.zip" />
<property name="pkgfile" value="${phing.project.name}-${version}.tgz" /> <property name="pkgfile" value="${phing.project.name}-${version}.tgz" />
<property name="pharfile" value="${phing.project.name}-${version}.phar" />
<property name="distfile" value="dist/${zipfile}" /> <property name="distfile" value="dist/${zipfile}" />
<property name="distpkgfile" value="dist/pear/${pkgfile}" /> <property name="distpkgfile" value="dist/pear/${pkgfile}" />
<property name="pharfilepath" value="dist/${pharfile}" />
<property name="sfproject" value="SemanticScuttle" /> <property name="sfproject" value="SemanticScuttle" />
<property name="sffilepath" value="s/se/semanticscuttle/" /> <property name="sffilepath" value="s/se/semanticscuttle/" />
<property name="svnpath" value="https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/" /> <property name="svnpath" value="https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/" />
@ -305,6 +307,30 @@
</target> </target>
<target name="phar" depends="check"
description="Create .phar file for release"
>
<echo msg="Creating .phar for SemanticScuttle ${version}"/>
<delete file="${pharfilepath}" quiet="yes"/>
<pharpackage basedir="." destfile="${pharfilepath}"
alias="SemanticScuttle.phar"
stub="res/phar-stub.php"
>
<metadata>
<element name="version" value="${version}" />
<element name="authors">
<element name="Christian Weiske">
<element name="e-mail" value="cweiske@cweiske.de" />
</element>
</element>
</metadata>
<fileset refid="fs.zip"/>
</pharpackage>
</target>
<target name="build-docs" description="render documentation"> <target name="build-docs" description="render documentation">
<rST format="html" uptodate="true" <rST format="html" uptodate="true"
toolparam="--stylesheet=res/docs/style.css" toolparam="--stylesheet=res/docs/style.css"

View File

@ -208,6 +208,8 @@ $tableprefix = 'sc_';
*/ */
$dbneedssetnames = true; $dbneedssetnames = true;
$dbpersist = false;
/*************************************************** /***************************************************
* Users * Users

View File

@ -14,6 +14,11 @@ To run SemanticScuttle, you need:
Standard installation instructions Standard installation instructions
================================== ==================================
If you downloaded the ``.phar`` file, follow the `Phar setup instructions`__.
Otherwise continue here:
__ install-phar.html
If you've downloaded a ``SemanticScuttle-x.y.z.zip`` file from SourceForge, If you've downloaded a ``SemanticScuttle-x.y.z.zip`` file from SourceForge,
then this instructions are for you. then this instructions are for you.

View File

@ -59,9 +59,6 @@ __ https://sourceforge.net/mailarchive/forum.php?forum_name=semanticscuttle-deve
Known issues Known issues
============ ============
See `troubleshooting.rst`_ for a list of known problems and their solution.
Number of bookmarks always 0: "0 bookmark(s)" .. _troubleshooting.rst: troubleshooting.html
---------------------------------------------
This issue occurs when debug mode is enabled.
Technically, this is because the database layers ``DEBUG_EXTRA`` gets
enabled through debug mode.

84
doc/install-phar.rst Normal file
View File

@ -0,0 +1,84 @@
==================================
SemanticScuttle .phar installation
==================================
How to install the `.phar` version of SemanticScuttle.
Note: The ``.phar`` file can be used from the browser and
via command line. Use ``--help`` to find out what you can do.
.. contents::
Server setup
============
Apache or any other web server is by default not configured to let PHP handle
``.phar`` files, so we need to add it.
The default apache configuration on Debian contains the following lines::
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
which matches ``.php``, ``.php3`` and ``.phtml`` files.
Adding ``.phar`` is trivial::
<FilesMatch "\.ph(ar|p3?|tml)$">
Restart your server after this configuration change.
Database setup
==============
Extract the database schema from the ``.phar`` file::
$ php SemanticScuttle-0.98.3.phar x data/tables.sql tables.sql
Import the schema into you MySQL server::
$ mysql -umyusername mydatabase < tables.sql
Database upgrades
-----------------
If you are upgrading from an earlier version of SemanticScuttle, you might need
to upgrade your database schema.
See the `upgrade instructions`_ for more information.
Get a list of all schema files with ::
$ php SemanticScuttle-0.98.3.phar list | grep schema
and then extract the relevant ones with ::
$ php SemanticScuttle-0.98.3.phar x data/schema/6.sql
.. _upgrade instructions: UPGRADE.html
Configuration
=============
Extract the configuration file from the ``.phar`` file::
$ php SemanticScuttle-0.98.3.phar x data/config.php.dist SemanticScuttle-0.98.3.phar.config.php
Note that the file name must be exactly the name of the ``.phar``
plus ``.config.php`` - otherwise the configuration file is not detected.
After extracting it, modify it according to your needs.
Caching
-------
If you want to enable caching, make sure you use a ``$dir_cache`` that is
_outside_ the phar file.
Visit SemanticScuttle
=====================
Open your browser and navigate to the ``.phar`` file.
Happy bookmarking!

33
doc/troubleshooting.rst Normal file
View File

@ -0,0 +1,33 @@
===============================
SemanticScuttle Troubleshooting
===============================
Godaddy error: "No input file specified."
=========================================
Opening personalized URLs like ``bookmarks.php/username`` on a godaddy
hosted server leads to the error ::
No input file specified.
We do not have a real solution yet, but changing the PHP handler from
`CGI` to `mod_php` in the control center makes it work:
- Hosting Control Center
- Settings
- File extensions
- Change ``.php`` from `FastCGI` to `PHP 5.x`
Thanks to CESgeekbook__ for the hint.
__ http://www.cesgeekbook.com/2010/07/php-no-input-file-specified-godaddy.html
Number of bookmarks always 0: "0 bookmark(s)"
=============================================
This issue occurs when debug mode is enabled.
Technically, this is because the database layers ``DEBUG_EXTRA`` gets
enabled through debug mode.

54
res/phar-stub.php Normal file
View File

@ -0,0 +1,54 @@
<?php
if (!in_array('phar', stream_get_wrappers())
|| !class_exists('Phar', 0)
) {
echo 'PHP Phar extension required';
exit;
}
Phar::interceptFileFuncs();
if (php_sapi_name() == 'cli') {
require_once dirname(__FILE__) . '/../src/SemanticScuttle/Phar/Cli.php';
$cli = new SemanticScuttle_Phar_Cli();
$cli->run();
exit;
}
function mapUrls($path)
{
$arMap = array(
'' => '/www/index.php',
'/' => '/www/index.php',
'/gsearch/' => '/www/gsearch/index.php',
);
if (isset($arMap[$path])) {
return $arMap[$path];
}
$parts = explode('/', $path);
$partPos = 1;
if (in_array($parts[$partPos], array('js', 'player', 'themes'))) {
return '/www' . $path;
}
if (in_array($parts[$partPos], array('ajax', 'api', 'gsearch'))) {
$partPos = 2;
}
$pos = strrpos($parts[$partPos], '.');
if ($pos === false) {
$parts[$partPos] .= '.php';
$_SERVER['PATH_INFO'] = '/' . implode(
'/', array_slice($parts, $partPos + 1)
);
}
return '/www' . implode('/', $parts);
}
Phar::webPhar(
null,
'www/index.php',
null,
array(),
'mapUrls'
);
__HALT_COMPILER(); ?>

View File

@ -20,7 +20,7 @@
* @license AGPL http://www.gnu.org/licenses/agpl.html * @license AGPL http://www.gnu.org/licenses/agpl.html
* @link http://sourceforge.net/projects/semanticscuttle * @link http://sourceforge.net/projects/semanticscuttle
*/ */
class SemanticScuttle_Config class SemanticScuttle_Config implements ArrayAccess
{ {
/** /**
* Prefix for configuration files. * Prefix for configuration files.
@ -30,6 +30,121 @@ class SemanticScuttle_Config
*/ */
public $filePrefix = ''; public $filePrefix = '';
/**
* Array with all configuration data
*/
protected $configData = array();
/**
* Loads the variables from the given configuration file
* into $GLOBALS
*
* @param string $file Configuration file path to load
*
* @return void
*/
public function load($file)
{
// ack \\$ data/config.default.php |sed 's/ .*$//'|grep -v ^$|sort
//this here is required because setting $GLOBALS doesnt'
// automatically set "global" :/
global
$adminemail,
$adminsAreAdvisedTagsFromOtherAdmins,
$adminsCanModifyBookmarksFromOtherUsers,
$admin_users,
$allowedProtocols,
$allowUnittestMode,
$antispamAnswer,
$antispamQuestion,
$authDebug,
$authEmailSuffix,
$authOptions,
$authType,
$avahiServiceFilePath,
$avahiServiceFilePrefix,
$avahiTagName,
$blankDescription,
$bottom_include,
$cleanurls,
$dateOrderField,
$dbhost,
$dbname,
$dbneedssetnames,
$dbpass,
$dbpersist,
$dbport,
$dbtype,
$dbuser,
$debugMode,
$defaultOrderBy,
$defaultPerPage,
$defaultPerPageForAdmins,
$defaultRecentDays,
$defaultRssEntries,
$defaults,
$descriptionAnchors,
$dir_cache,
$enableAdminColors,
$enableCommonBookmarkDescription,
$enableCommonTagDescription,
$enableCommonTagDescriptionEditedByAll,
$enableGoogleCustomSearch,
$enableRegistration,
$enableVoting,
$enableWebsiteThumbnails,
$filetypes,
$footerMessage,
$googleAnalyticsCode,
$hideBelowVoting,
$index_sidebar_blocks,
$locale,
$longdate,
$maxRssEntries,
$maxSizeMenuBlock,
$menu2Tags,
$menuTag,
$nofollow,
$reservedusers,
$root,
$serviceoverrides,
$shortdate,
$shorturl,
$sidebarBottomMessage,
$sidebarTopMessage,
$sitename,
$sizeSearchHistory,
$tableprefix,
$TEMPLATES_DIR,
$theme,
$thumbnailsKey,
$thumbnailsUserId,
$top_include,
$unittestUrl,
$url_redir,
$usecache,
$useredir,
$votingMode,
$welcomeMessage;
require_once $file;
//make them global
//does not really work because many parts still access the variables
// without $cfg/$GLOBALS
//unset($file);
//$GLOBALS = get_defined_vars() + $GLOBALS;
}
/**
* Assigns GLOBALS to configData
*/
public function __construct()
{
$this->configData =& $GLOBALS;
}
/** /**
@ -50,30 +165,29 @@ class SemanticScuttle_Config
return $datadir; return $datadir;
} }
/** /**
* Tries to find a configuration file by looking in different * Creates an array with file paths where the configuration
* places: * file may be located.
* - pear data_dir/SemanticScuttle/config-$hostname.php
* - pear data_dir/SemanticScuttle/config.php
* - /etc/semanticscuttle/config-$hostname.php
* - /etc/semanticscuttle/config.php
*
* Paths with host name have priority.
* *
* When open_basedir restrictions are in effect and /etc is not part of * When open_basedir restrictions are in effect and /etc is not part of
* the setting, /etc/semanticscuttle/ is not checked for config files. * the setting, /etc/semanticscuttle/ is not checked for config files.
* *
* @return array Array with config file path as first value * @return array Array of possible configuration file paths.
* and default config file path as second value.
* Any may be NULL if not found
*/ */
public function findFiles() public function getPossibleConfigFiles()
{ {
if (isset($_SERVER['HTTP_HOST'])) {
//use basename to prevent path injection //use basename to prevent path injection
$host = basename($_SERVER['HTTP_HOST']); $host = basename($_SERVER['HTTP_HOST']);
} else {
$host = 'cli';
}
$datadir = $this->getDataDir(); $datadir = $this->getDataDir();
$arFiles = array();
if (class_exists('Phar') && Phar::running(false) != '') {
$arFiles[] = Phar::running(false) . '.config.php';
}
$openbase = ini_get('open_basedir'); $openbase = ini_get('open_basedir');
if ($openbase && strpos($openbase, '/etc') === false) { if ($openbase && strpos($openbase, '/etc') === false) {
@ -93,6 +207,30 @@ class SemanticScuttle_Config
); );
} }
return $arFiles;
}
/**
* Tries to find a configuration file by looking in different
* places:
* - pear data_dir/SemanticScuttle/config-$hostname.php
* - pear data_dir/SemanticScuttle/config.php
* - /etc/semanticscuttle/config-$hostname.php
* - /etc/semanticscuttle/config.php
*
* Paths with host name have priority.
*
* @return array Array with config file path as first value
* and default config file path as second value.
* Any may be NULL if not found
*/
public function findFiles()
{
$datadir = $this->getDataDir();
$arFiles = $this->getPossibleConfigFiles();
$configfile = null; $configfile = null;
foreach ($arFiles as $file) { foreach ($arFiles as $file) {
if (file_exists($this->filePrefix . $file)) { if (file_exists($this->filePrefix . $file)) {
@ -118,6 +256,32 @@ class SemanticScuttle_Config
} }
return array($configfile, $defaultfile); return array($configfile, $defaultfile);
} }
public function offsetExists($offset)
{
return isset($this->configData[$offset]);
}
public function offsetGet($offset)
{
return $this->configData[$offset];
}
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
$this->configData[] = $value;
} else {
$this->configData[$offset] = $value;
}
}
public function offsetUnset($offset)
{
unset($this->configData[$offset]);
}
} }
?> ?>

View File

@ -29,6 +29,17 @@ class SemanticScuttle_Environment
*/ */
public static function getServerPathInfo() public static function getServerPathInfo()
{ {
if (isset($_SERVER['PHAR_PATH_TRANSLATED'])) {
$fscript = '/' . $_SERVER['SCRIPT_NAME'];
if ($fscript == $_SERVER['PATH_INFO']
|| $fscript == $_SERVER['PATH_INFO'] . '.php'
) {
return null;
} else if (substr($_SERVER['PATH_INFO'], 0, strlen($fscript)) == $fscript) {
return substr($_SERVER['PATH_INFO'], strlen($fscript));
}
}
if (isset($_SERVER['PATH_INFO'])) { if (isset($_SERVER['PATH_INFO'])) {
return $_SERVER['PATH_INFO']; return $_SERVER['PATH_INFO'];
} }
@ -44,5 +55,51 @@ class SemanticScuttle_Environment
//fallback when no special path after the php file is given //fallback when no special path after the php file is given
return ''; return '';
} }
/**
* Determines the root directory from the server environment.
* The root directory is the path that needs to be prepended
* to relative links.
*
* Returns $GLOBALS['root'] if set.
*
* @return string Base URL with trailing slash
*/
public static function getRoot()
{
if (isset($GLOBALS['root'])) {
return $GLOBALS['root'];
}
$rootTmp = '/';
if (isset($_SERVER['PHAR_PATH_TRANSLATED'])) {
$rootTmp = $_SERVER['SCRIPT_NAME'] . '/';
$_SERVER['SCRIPT_NAME'] = substr(
$_SERVER['PATH_TRANSLATED'],
strpos($_SERVER['PATH_TRANSLATED'], $rootTmp)
+ strlen($rootTmp)
+ 4 /* strip "www/" */
);
}
$pieces = explode('/', $_SERVER['SCRIPT_NAME']);
foreach ($pieces as $piece) {
//we eliminate possible sscuttle subfolders (like gsearch for example)
if ($piece != '' && !strstr($piece, '.php')
&& $piece != 'gsearch' && $piece != 'ajax'
) {
$rootTmp .= $piece .'/';
}
}
if (($rootTmp != '/') && (substr($rootTmp, -1, 1) != '/')) {
$rootTmp .= '/';
}
//we do not prepend http since we also want to support https connections
// "http" is not required; it's automatically determined by the browser
// depending on the current connection.
return '//' . $_SERVER['HTTP_HOST'] . $rootTmp;
}
} }
?> ?>

View File

@ -0,0 +1,150 @@
<?php
/**
* SemanticScuttle - your social bookmark manager.
*
* PHP version 5.
*
* @category Bookmarking
* @package SemanticScuttle
* @author Christian Weiske <cweiske@cweiske.de>
* @license AGPL http://www.gnu.org/licenses/agpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
require_once 'Console/CommandLine.php';
/**
* Command line interface for the SemanticScuttle.phar file.
* Can be used to extract parts of the phar file and to run
* scripts in it.
*
* @category Bookmarking
* @package SemanticScuttle
* @author Christian Weiske <cweiske@cweiske.de>
* @license AGPL http://www.gnu.org/licenses/agpl.html
* @link http://sourceforge.net/projects/semanticscuttle
*/
class SemanticScuttle_Phar_Cli
{
public function run()
{
$ccl = new Console_CommandLine();
$ccl->name = 'SemanticScuttle';
$ccl->description = 'Command line interface to SemanticScuttle .phar files';
$ccl->version = '0.98.3';
$ccl->add_help_option = true;
$ccl->add_version_option = true;
$ccl->force_posix = true;
$ccl->addCommand('list', array('aliases' => array('l')));
$extract = $ccl->addCommand('extract', array('aliases' => array('x')));
$extract->addArgument(
'file', array('description' => 'Path of file to extract')
);
$extract->addArgument(
'target', array(
'description' => 'Path to store file contents. Defaults to stdout',
'optional' => true,
)
);
$run = $ccl->addCommand('run', array('aliases' => array('r')));
$run->addArgument(
'file', array('description' => 'Path of file to extract')
);
try {
$result = $ccl->parse();
if ($result->command_name == '') {
$ccl->displayUsage();
}
$method = $result->command_name . 'Action';
$this->$method($result->command->args, $result->command->options);
} catch (Exception $ex) {
$ccl->displayError($ex->getMessage());
}
}
/**
* Lists the contents of this phar archive and echos the output
*
* @return void
*/
public function listAction()
{
$excludes = array(
'data/locales',
'data/templates',
'src',
'www',
);
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
'phar://SemanticScuttle.phar/'
)
);
while($it->valid()) {
if (!$it->isDot()) {
$name = $it->getSubPathName();
$excluded = false;
foreach ($excludes as $exclude) {
if (substr($name, 0, strlen($exclude)) == $exclude) {
$excluded = true;
break;
}
}
if (!$excluded) {
echo $name . "\n";
}
}
$it->next();
}
}
/**
* Extract the file given in $args['file'] to stdout
*
* @param array $args Array of commandline arguments
* @param array $options Array of commandline options
*
* @return void
* @throws Exception When the file does not exist in the .phar
*/
public function extractAction($args, $options)
{
$file = 'phar://SemanticScuttle.phar/' . $args['file'];
if (!file_exists($file)) {
echo 'File "' . $args['file'] . '" does not exist in phar.' . "\n";
exit(1);
}
if (isset($args['target'])) {
copy($file, $args['target']);
} else {
readfile($file);
}
}
/**
* Runs a script inside the .phar
*
* @param array $args Array of commandline arguments
* @param array $options Array of commandline options
*
* @return void
* @throws Exception When the file does not exist in the .phar
*/
public function runAction($args, $options)
{
$file = 'phar://SemanticScuttle.phar/' . $args['file'];
if (!file_exists($file)) {
echo 'File "' . $args['file'] . '" does not exist in phar.' . "\n";
exit(1);
}
//FIXME: shift off options
include $file;
}
}
?>

View File

@ -113,16 +113,14 @@ class SemanticScuttle_Service_Factory
*/ */
protected static function loadDb() protected static function loadDb()
{ {
global $dbhost, $dbuser, $dbpass, $dbname,
$dbport, $dbpersist, $dbtype, $dbneedssetnames;
if (self::$db !== null) { if (self::$db !== null) {
return; return;
} }
include_once 'SemanticScuttle/db/'. $dbtype .'.php'; include_once 'SemanticScuttle/db/'. $GLOBALS['dbtype'] .'.php';
$db = new sql_db(); $db = new sql_db();
$db->sql_connect( $db->sql_connect(
$dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist $GLOBALS['dbhost'], $GLOBALS['dbuser'], $GLOBALS['dbpass'],
$GLOBALS['dbname'], $GLOBALS['dbport'], $GLOBALS['dbpersist']
); );
if (!$db->db_connect_id) { if (!$db->db_connect_id) {
message_die( message_die(
@ -132,7 +130,7 @@ class SemanticScuttle_Service_Factory
); );
} }
$dbneedssetnames && $db->sql_query('SET NAMES UTF8'); $GLOBALS['dbneedssetnames'] && $db->sql_query('SET NAMES UTF8');
self::$db = $db; self::$db = $db;
} }

View File

@ -25,29 +25,7 @@ if (isset($GLOBALS['debugMode'])) {
} }
// Determine the base URL as ROOT // Determine the base URL as ROOT
if (!isset($GLOBALS['root'])) { define('ROOT', SemanticScuttle_Environment::getRoot());
$pieces = explode('/', $_SERVER['SCRIPT_NAME']);
$rootTmp = '/';
foreach ($pieces as $piece) {
//we eliminate possible sscuttle subfolders (like gsearch for example)
if ($piece != '' && !strstr($piece, '.php')
&& $piece != 'gsearch' && $piece != 'ajax'
) {
$rootTmp .= $piece .'/';
}
}
if (($rootTmp != '/') && (substr($rootTmp, -1, 1) != '/')) {
$rootTmp .= '/';
}
//we do not prepend http since we also want to support https connections
// "http" is not required; it's automatically determined by the browser
// depending on the current connection.
define('ROOT', '//'. $_SERVER['HTTP_HOST'] . $rootTmp);
} else {
define('ROOT', $GLOBALS['root']);
}
define('ROOT_JS', ROOT . 'js/jstree-1.0-rc2/'); define('ROOT_JS', ROOT . 'js/jstree-1.0-rc2/');
// Error codes // Error codes

View File

@ -14,6 +14,7 @@
* @license GPL http://www.gnu.org/licenses/gpl.html * @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle * @link http://sourceforge.net/projects/semanticscuttle
*/ */
global $wwwdir, $datadir;
if ('@data_dir@' == '@' . 'data_dir@') { if ('@data_dir@' == '@' . 'data_dir@') {
//non pear-install //non pear-install
@ -29,6 +30,8 @@ require_once dirname(__FILE__) . '/Environment.php';
require_once dirname(__FILE__) . '/Config.php'; require_once dirname(__FILE__) . '/Config.php';
$cfg = new SemanticScuttle_Config(); $cfg = new SemanticScuttle_Config();
$GLOBALS['cfg'] = $cfg;
list($configfile, $defaultfile) = $cfg->findFiles(); list($configfile, $defaultfile) = $cfg->findFiles();
if ($defaultfile === null) { if ($defaultfile === null) {
header('HTTP/1.0 500 Internal Server Error'); header('HTTP/1.0 500 Internal Server Error');
@ -48,8 +51,8 @@ set_include_path(
); );
// 1 // First requirements part (before debug management) // 1 // First requirements part (before debug management)
require_once $defaultfile; $cfg->load($defaultfile);
require_once $configfile; $cfg->load($configfile);
if (isset($_GET['unittestMode']) && $_GET['unittestMode'] == 1 if (isset($_GET['unittestMode']) && $_GET['unittestMode'] == 1
) { ) {
@ -106,11 +109,11 @@ require_once 'SemanticScuttle/Model/Bookmark.php';
require_once 'SemanticScuttle/Model/UserArray.php'; require_once 'SemanticScuttle/Model/UserArray.php';
require_once 'SemanticScuttle/Model/User/SslClientCert.php'; require_once 'SemanticScuttle/Model/User/SslClientCert.php';
if (count($GLOBALS['serviceoverrides']) > 0 if (count($cfg['serviceoverrides']) > 0
&& !defined('UNIT_TEST_MODE') && !defined('UNIT_TEST_MODE')
) { ) {
SemanticScuttle_Service_Factory::$serviceoverrides SemanticScuttle_Service_Factory::$serviceoverrides
= $GLOBALS['serviceoverrides']; = $cfg['serviceoverrides'];
} }
// 3 // Third requirements part which import functions from includes/ directory // 3 // Third requirements part which import functions from includes/ directory
@ -121,7 +124,7 @@ require_once 'SemanticScuttle/utf8.php';
// Translation // Translation
require_once 'php-gettext/gettext.inc'; require_once 'php-gettext/gettext.inc';
$domain = 'messages'; $domain = 'messages';
T_setlocale(LC_MESSAGES, $locale); T_setlocale(LC_MESSAGES, $cfg['locale']);
T_bindtextdomain($domain, realpath($datadir . 'locales/')); T_bindtextdomain($domain, realpath($datadir . 'locales/'));
T_bind_textdomain_codeset($domain, 'UTF-8'); T_bind_textdomain_codeset($domain, 'UTF-8');
T_textdomain($domain); T_textdomain($domain);
@ -129,15 +132,15 @@ T_textdomain($domain);
// 4 // Session // 4 // Session
if (isset($_SERVER['REMOTE_ADDR'])) { if (isset($_SERVER['REMOTE_ADDR'])) {
session_start(); session_start();
if ($GLOBALS['enableVoting']) { if ($cfg['enableVoting']) {
if (isset($_SESSION['lastUrl'])) { if (isset($_SESSION['lastUrl'])) {
$GLOBALS['lastUrl'] = $_SESSION['lastUrl']; $cfg['lastUrl'] = $_SESSION['lastUrl'];
} }
//this here is hacky, but currently the only way to //this here is hacky, but currently the only way to
// differentiate between css/js php files and normal // differentiate between css/js php files and normal
// http files // http files
if (!isset($GLOBALS['saveInLastUrl']) if (!isset($cfg['saveInLastUrl'])
|| $GLOBALS['saveInLastUrl'] || $cfg['saveInLastUrl']
) { ) {
$_SESSION['lastUrl'] = $_SERVER['REQUEST_URI']; $_SESSION['lastUrl'] = $_SERVER['REQUEST_URI'];
} }

View File

@ -42,7 +42,7 @@ class SemanticScuttle_ConfigTest extends PHPUnit_Framework_TestCase
'SemanticScuttle_Config', 'SemanticScuttle_Config',
array('getDataDir') array('getDataDir')
); );
$this->cfg->expects($this->once()) $this->cfg->expects($this->any())
->method('getDataDir') ->method('getDataDir')
->will($this->returnValue('/data-dir/')); ->will($this->returnValue('/data-dir/'));

View File

@ -229,6 +229,175 @@ class SemanticScuttle_EnvironmentTest extends PHPUnit_Framework_TestCase
'/dummy/foo', SemanticScuttle_Environment::getServerPathInfo() '/dummy/foo', SemanticScuttle_Environment::getServerPathInfo()
); );
} }
public function testGetServerPathInfoPharPurePhpFile()
{
$_SERVER = array(
'SERVER_NAME' => 'dist.bm.bogo',
'SERVER_ADDR' => '127.0.0.1',
'SERVER_PORT' => '80',
'DOCUMENT_ROOT' => '/etc/apache2/htdocs',
'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/SemanticScuttle-0.98.X.phar',
'QUERY_STRING' => '',
'REQUEST_URI' => '/SemanticScuttle-0.98.X.phar/www/populartags.php',
'SCRIPT_NAME' => 'www/populartags.php',
'PATH_INFO' => '/www/populartags.php',
'PATH_TRANSLATED' => 'phar:///home/cweiske/Dev/semanticscuttle/cwdev/dist/SemanticScuttle-0.98.X.phar/www/populartags.php',
'PHP_SELF' => '/SemanticScuttle-0.98.X.phar/www/populartags.php',
'PHAR_PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/www/populartags.php',
);
$this->assertNull(
SemanticScuttle_Environment::getServerPathInfo()
);
}
public function testGetServerPathInfoPharCleanUrl()
{
$_SERVER = array(
'HTTP_HOST' => 'dist.bm.bogo',
'SERVER_NAME' => 'dist.bm.bogo',
'SERVER_ADDR' => '127.0.0.1',
'SERVER_PORT' => '80',
'DOCUMENT_ROOT' => '/etc/apache2/htdocs' ,
'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/SemanticScuttle-0.98.X.phar' ,
'QUERY_STRING' => '',
'REQUEST_URI' => '/SemanticScuttle-0.98.X.phar/populartags',
'SCRIPT_NAME' => 'populartags.php',
'PATH_INFO' => '/populartags',
'PATH_TRANSLATED' => 'phar:///home/cweiske/Dev/semanticscuttle/cwdev/dist/SemanticScuttle-0.98.X.phar/www/populartags.php',
'PHP_SELF' => '/SemanticScuttle-0.98.X.phar/populartags',
'PHAR_PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/populartags',
);
$this->assertNull(
SemanticScuttle_Environment::getServerPathInfo()
);
}
public function testGetServerPathInfoPharWithInfo()
{
$_SERVER = array(
'PATH' => '/usr/local/bin:/usr/bin:/bin',
'SERVER_NAME' => 'dist.bm.bogo',
'DOCUMENT_ROOT' => '/etc/apache2/htdocs',
'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/SemanticScuttle-0.98.X.phar',
'QUERY_STRING' => '',
'REQUEST_URI' => '/SemanticScuttle-0.98.X.phar/www/populartags.php/foo/bar',
'SCRIPT_NAME' => 'www/populartags.php',
'PATH_INFO' => '/foo/bar',
'PATH_TRANSLATED' => 'phar:///home/cweiske/Dev/semanticscuttle/cwdev/dist/SemanticScuttle-0.98.X.phar/www/populartags.php',
'PHP_SELF' => '/SemanticScuttle-0.98.X.phar/www/populartags.php/foo/bar',
'PHAR_PATH_INFO' => '/www/populartags.php/foo/bar',
'PHAR_PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/www/populartags.php/foo/bar',
);
$this->assertEquals(
'/foo/bar', SemanticScuttle_Environment::getServerPathInfo()
);
}
public function testGetServerPathInfoPharWithInfoWithoutWww()
{
$_SERVER = array(
'PATH' => '/usr/local/bin:/usr/bin:/bin',
'SERVER_NAME' => 'dist.bm.bogo',
'DOCUMENT_ROOT' => '/etc/apache2/htdocs',
'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/SemanticScuttle-0.98.X.phar',
'QUERY_STRING' => '',
'REQUEST_URI' => '/SemanticScuttle-0.98.X.phar/tags.php/test',
'SCRIPT_NAME' => 'tags.php',
'PATH_INFO' => '/tags.php/test',
'PATH_TRANSLATED' => 'phar:///home/cweiske/Dev/semanticscuttle/cwdev/dist/SemanticScuttle-0.98.X.phar/www/tags.php',
'PHP_SELF' => '/SemanticScuttle-0.98.X.phar/tags.php/test',
'PHAR_PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/tags.php/test',
);
$this->assertEquals(
'/test', SemanticScuttle_Environment::getServerPathInfo()
);
}
public function testGetRootWithConfigPreset()
{
$GLOBALS['root'] = 'https://happy.penguin.example.org/walks/away/';
$this->assertEquals(
'https://happy.penguin.example.org/walks/away/',
SemanticScuttle_Environment::getRoot()
);
}
public function testGetRootInRootDir()
{
$_SERVER = array(
'HTTP_HOST' => 'bm.bogo',
'DOCUMENT_ROOT' => '/etc/apache2/htdocs',
'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/bm.bogo/index.php',
'QUERY_STRING' => '',
'REQUEST_URI' => '/',
'SCRIPT_NAME' => '/index.php',
'PHP_SELF' => '/index.php',
);
$this->assertEquals(
'//bm.bogo/',
SemanticScuttle_Environment::getRoot()
);
}
public function testGetRootInSubdir()
{
$_SERVER = array(
'HTTP_HOST' => 'bm-subdir.bogo',
'DOCUMENT_ROOT' => '/etc/apache2/htdocs',
'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/bm-subdir.bogo/tools/scuttle/index.php',
'QUERY_STRING' => '',
'REQUEST_URI' => '/tools/scuttle/',
'SCRIPT_NAME' => '/tools/scuttle/index.php',
'PHP_SELF' => '/tools/scuttle/index.php',
);
$this->assertEquals(
'//bm-subdir.bogo/tools/scuttle/',
SemanticScuttle_Environment::getRoot()
);
}
public function testGetRootFromPharIndex()
{
$_SERVER = array(
'HTTP_HOST' => 'dist.bm.bogo',
'DOCUMENT_ROOT' => '/etc/apache2/htdocs',
'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/SemanticScuttle-0.98.X.phar',
'QUERY_STRING' => '',
'REQUEST_URI' => '/SemanticScuttle-0.98.X.phar/www/index.php',
'SCRIPT_NAME' => '/SemanticScuttle-0.98.X.phar',
'PATH_INFO' => '/www/index.php',
'PATH_TRANSLATED' => 'phar:///home/cweiske/Dev/semanticscuttle/cwdev/dist/SemanticScuttle-0.98.X.phar/www/index.php',
'PHP_SELF' => '/SemanticScuttle-0.98.X.phar/www/index.php',
'PHAR_PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/www/index.php',
);
$this->assertEquals(
'//dist.bm.bogo/SemanticScuttle-0.98.X.phar/',
SemanticScuttle_Environment::getRoot()
);
}
public function testGetRootFromPharWithSubpath()
{
$_SERVER = array(
'HTTP_HOST' => 'dist.bm.bogo',
'DOCUMENT_ROOT' => '/etc/apache2/htdocs',
'SCRIPT_FILENAME' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/SemanticScuttle-0.98.X.phar',
'QUERY_STRING' => 'no value',
'REQUEST_URI' => '/SemanticScuttle-0.98.X.phar/www/index.php/foo/bar/',
'SCRIPT_NAME' => '/SemanticScuttle-0.98.X.phar',
'PATH_INFO' => '/foo/bar/',
'PATH_TRANSLATED' => 'phar:///home/cweiske/Dev/semanticscuttle/cwdev/dist/SemanticScuttle-0.98.X.phar/www/index.php',
'PHP_SELF' => '/SemanticScuttle-0.98.X.phar/www/index.php/foo/bar/',
'REQUEST_TIME' => '1313425297',
'PHAR_PATH_INFO' => '/www/index.php/foo/bar/',
'PHAR_PATH_TRANSLATED' => '/home/cweiske/Dev/html/hosts/dist.bm.bogo/www/index.php/foo/bar/',
);
$this->assertEquals(
'//dist.bm.bogo/SemanticScuttle-0.98.X.phar/',
SemanticScuttle_Environment::getRoot()
);
}
} }
?> ?>

View File

@ -20,7 +20,7 @@
*/ */
$httpContentType = 'application/json'; $httpContentType = 'application/json';
require_once '../www-header.php'; require_once __DIR__ . '/../www-header.php';
/** /**
* Creates and returns an array of tags for the jsTree ajax loader. * Creates and returns an array of tags for the jsTree ajax loader.

View File

@ -22,7 +22,7 @@
*/ */
$httpContentType = 'application/json'; $httpContentType = 'application/json';
require_once '../www-header.php'; require_once __DIR__ . '/../www-header.php';
$limit = 30; $limit = 30;
$beginsWith = null; $beginsWith = null;

View File

@ -22,7 +22,7 @@
*/ */
$httpContentType = 'application/json'; $httpContentType = 'application/json';
require_once '../www-header.php'; require_once __DIR__ . '/../www-header.php';
$limit = 30; $limit = 30;
$beginsWith = null; $beginsWith = null;

View File

@ -25,7 +25,7 @@
* @link http://sourceforge.net/projects/semanticscuttle * @link http://sourceforge.net/projects/semanticscuttle
*/ */
$httpContentType = 'application/json'; $httpContentType = 'application/json';
require_once '../www-header.php'; require_once __DIR__ . '/../www-header.php';
$tag = isset($_GET['tag']) ? $_GET['tag'] : null; $tag = isset($_GET['tag']) ? $_GET['tag'] : null;
$uId = isset($_GET['uId']) ? (int)$_GET['uId'] : 0; $uId = isset($_GET['uId']) ? (int)$_GET['uId'] : 0;

View File

@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/* Return a json file with list of tags according to current user and sort by popularity*/ /* Return a json file with list of tags according to current user and sort by popularity*/
$httpContentType = 'application/json'; $httpContentType = 'application/json';
require_once '../www-header.php'; require_once __DIR__ . '/../www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); $b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag');

View File

@ -6,7 +6,7 @@
// Force HTTP authentication first! // Force HTTP authentication first!
//require_once('httpauth.inc.php'); //require_once('httpauth.inc.php');
$httpContentType = false; $httpContentType = false;
require_once '../www-header.php'; require_once __DIR__ . '/../www-header.php';
if($GLOBALS['enableGoogleCustomSearch'] == false) { if($GLOBALS['enableGoogleCustomSearch'] == false) {
echo "Google Custom Search disabled. You can enable it into the config.php file."; echo "Google Custom Search disabled. You can enable it into the config.php file.";

View File

@ -2,7 +2,7 @@
/* Export data with semantic format (SIOC: http://sioc-project.org/, FOAF, SKOS, Annotea Ontology) */ /* Export data with semantic format (SIOC: http://sioc-project.org/, FOAF, SKOS, Annotea Ontology) */
$httpContentType = 'text/xml'; $httpContentType = 'text/xml';
require_once '../www-header.php'; require_once __DIR__ . '/../www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$userservice =SemanticScuttle_Service_Factory::get('User'); $userservice =SemanticScuttle_Service_Factory::get('User');

View File

@ -17,7 +17,7 @@
* @license GPL http://www.gnu.org/licenses/gpl.html * @license GPL http://www.gnu.org/licenses/gpl.html
* @link http://sourceforge.net/projects/semanticscuttle * @link http://sourceforge.net/projects/semanticscuttle
*/ */
require_once '../www-header.php'; require_once __DIR__ . '/../www-header.php';
/** /**
* Sends HTTP auth headers to the browser * Sends HTTP auth headers to the browser

View File

@ -1,6 +1,6 @@
<?php <?php
$httpContentType = 'text/xml'; $httpContentType = 'text/xml';
require_once '../www-header.php'; require_once __DIR__ . '/../www-header.php';
echo '<' . '?xml version="1.0" encoding="utf-8" ?' . ">\n"; echo '<' . '?xml version="1.0" encoding="utf-8" ?' . ">\n";
?> ?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"> <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">

View File

@ -7,7 +7,7 @@
// Force HTTP authentication first! // Force HTTP authentication first!
//require_once('httpauth.inc.php'); //require_once('httpauth.inc.php');
$httpContentType = 'text/xml'; $httpContentType = 'text/xml';
require_once '../www-header.php'; require_once __DIR__ . '/../www-header.php';
/* Service creation: only useful services are created */ /* Service creation: only useful services are created */
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark'); $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');

View File

@ -16,7 +16,7 @@
* @link http://sourceforge.net/projects/semanticscuttle * @link http://sourceforge.net/projects/semanticscuttle
* @link http://www.google.com/cse/docs/cref.html * @link http://www.google.com/cse/docs/cref.html
*/ */
require_once '../www-header.php'; require_once __DIR__ . '/../www-header.php';
if ($GLOBALS['enableGoogleCustomSearch'] == false) { if ($GLOBALS['enableGoogleCustomSearch'] == false) {
header('HTTP/1.0 403 Forbidden'); header('HTTP/1.0 403 Forbidden');

View File

@ -17,7 +17,7 @@
* @link http://sourceforge.net/projects/semanticscuttle * @link http://sourceforge.net/projects/semanticscuttle
* @link http://www.google.com/cse/docs/cref.html * @link http://www.google.com/cse/docs/cref.html
*/ */
require_once '../www-header.php'; require_once __DIR__ . '/../www-header.php';
if ($GLOBALS['enableGoogleCustomSearch'] == false) { if ($GLOBALS['enableGoogleCustomSearch'] == false) {
header('HTTP/1.0 403 Forbidden'); header('HTTP/1.0 403 Forbidden');