Page MenuHomeDevCentral

No OneTemporary

diff --git a/workspaces/src/Engines/I18n/TextFileMessage.php b/workspaces/src/Engines/I18n/TextFileMessage.php
index 8672f92..e4e6bd3 100644
--- a/workspaces/src/Engines/I18n/TextFileMessage.php
+++ b/workspaces/src/Engines/I18n/TextFileMessage.php
@@ -1,81 +1,81 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Text file Message class
*
* @package ObsidianWorkspaces
* @subpackage I18n
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*/
namespace Waystone\Workspaces\Engines\I18n;
use Exception;
/**
* Represents a localizable message stored in a plain text file
*/
class TextFileMessage extends Message {
/**
* @var string The folder where the message is stored.
*/
public $folder;
/**
* @var string The message filename, without extension or language suffix.
*/
public $filename;
/**
* Initializes a new instance of the TextFileMessage class.
*
* @param string $folder The folder where the message is stored.
* @param string $filename The message filename, without extension or language suffix.
*/
public function __construct ($folder, $filename) {
$this->folder = $folder;
$this->folder = $filename;
//Finds relevant files
$files = scandir($folder);
foreach ($files as $file) {
- if (string_starts_with($file, $filename . '-') && get_extension($file) == 'txt') {
+ if (str_starts_with($file, $filename . '-') && get_extension($file) == 'txt') {
$lang = substr($file, strlen($filename) + 1, -4);
if (strpos($lang, '-') !== false) {
//The user have quux-lang.txt and quux-foo-lang.txt files
continue;
}
$file = $folder . DIRECTORY_SEPARATOR . $file;
$this->localizations[$lang] = file_get_contents($file);
}
}
//Fallback if only one file is offered
$file = $folder . DIRECTORY_SEPARATOR . $filename . '.txt';
if (file_exists($file)) {
if (count($this->localizations)) {
if (array_key_exists(MESSAGE_FALLBACK_LANG, $this->localizations)) {
trigger_error("Ignored file: $filename.txt, as $filename-" . MESSAGE_FALLBACK_LANG . ".txt already exists and is used for fallback purpose", E_USER_NOTICE);
return;
}
trigger_error("You have $filename.txt and $filename-<lang>.txt files; you should have one or the other, but not both", E_USER_NOTICE);
}
$this->localizations[MESSAGE_FALLBACK_LANG] = file_get_contents($file);
return;
}
if (!count($this->localizations)) {
throw new Exception("TextFileMessage not found: $filename");
}
}
}
diff --git a/workspaces/src/includes/GlobalFunctions.php b/workspaces/src/includes/GlobalFunctions.php
index a2004bd..e9fb639 100644
--- a/workspaces/src/includes/GlobalFunctions.php
+++ b/workspaces/src/includes/GlobalFunctions.php
@@ -1,156 +1,140 @@
<?php
use Waystone\Workspaces\Engines\Workspaces\Workspace;
////////////////////////////////////////////////////////////////////////////////
/// ///
/// Misc helper functions ///
/// ///
////////////////////////////////////////////////////////////////////////////////
//Plural management
/*
* Gets a "s" if the specified amount requests the plural
* @param mixed $amount the quantity (should be numeric)
* @return string 's' if the amount is greater or equal than 2 ; otherwise, ''
*/
function s ($amount) {
if ($amount >= 2 || $amount <= -2 ) return 's';
}
/**
* Gets file extension
* @param string $file the file to get the extension
* @return string the file extension
*/
function get_extension ($file) {
$dotPosition = strrpos($file, ".");
return substr($file, $dotPosition + 1);
}
/**
* Gets file name
* @param string $file the file to get the extension
* @return string the file name
*/
function get_filename ($file) {
//TODO: clear directory
$dotPosition = strrpos($file, ".");
return substr($file, 0, $dotPosition);
}
-/*
- * Determines if a string starts with specified substring
- * @param string $haystack the string to check
- * @param string $needle the substring to determines if it's the start
- * @param boolean $case_sensitive determines if the search must be case sensitive
- * @return boolean true if $haystack starts with $needle ; otherwise, false.
- */
-function string_starts_with ($haystack, $needle, $case_sensitive = true) {
- if (!$case_sensitive) {
- $haystack = strtoupper($haystack);
- $needle = strtoupper($needle);
- }
- if ($haystack == $needle) return true;
- return strpos($haystack, $needle) === 0;
-}
-
////////////////////////////////////////////////////////////////////////////////
/// ///
/// URL helpers functions ///
/// ///
////////////////////////////////////////////////////////////////////////////////
/*
* Gets URL
* @return string URL
*/
function get_url () {
global $Config;
if (func_num_args() > 0) {
$pieces = func_get_args();
return $Config['BaseURL'] . '/' . implode('/', $pieces);
} elseif ($Config['BaseURL'] == "" || $Config['BaseURL'] == "/index.php") {
return "/";
} else {
return $Config['BaseURL'];
}
}
/*
* Gets server URL
* @todo find a way to detect https:// on non standard port
* @return string the server URL
*/
function get_server_url () {
if (php_sapi_name() == 'cli') {
return '';
}
switch ($port = $_SERVER['SERVER_PORT']) {
case '80':
return "http://$_SERVER[SERVER_NAME]";
case '443':
return "https://$_SERVER[SERVER_NAME]";
default:
return "http://$_SERVER[SERVER_NAME]:$_SERVER[SERVER_PORT]";
}
}
/*
* Gets $_SERVER['PATH_INFO'] or computes the equivalent if not defined.
* @return string the relevant URL part
*/
function get_current_url () {
global $Config;
//Gets relevant URL part from relevant $_SERVER variables
if (array_key_exists('PATH_INFO', $_SERVER)) {
//Without mod_rewrite, and url like /index.php/controller
//we use PATH_INFO. It's the easiest case.
return $_SERVER["PATH_INFO"];
}
//In other cases, we'll need to get the relevant part of the URL
$current_url = get_server_url() . $_SERVER['REQUEST_URI'];
//Relevant URL part starts after the site URL
$len = strlen($Config['SiteURL']);
//We need to assert it's the correct site
if (substr($current_url, 0, $len) != $Config['SiteURL']) {
dieprint_r(GENERAL_ERROR, "Edit includes/config.php and specify the correct site URL<br /><strong>Current value:</strong> $Config[SiteURL]<br /><strong>Expected value:</strong> a string starting by " . get_server_url(), "Setup");
}
if (array_key_exists('REDIRECT_URL', $_SERVER)) {
//With mod_rewrite, we can use REDIRECT_URL
//We take the end of the URL, ie *FROM* $len position
return substr(get_server_url() . $_SERVER["REDIRECT_URL"], $len);
}
//Last possibility: use REQUEST_URI, but remove QUERY_STRING
//If you need to edit here, use $_SERVER['REQUEST_URI']
//but you need to discard $_SERVER['QUERY_STRING']
//We take the end of the URL, ie *FROM* $len position
$url = substr(get_server_url() . $_SERVER["REQUEST_URI"], $len);
//But if there are a query string (?action=... we need to discard it)
if ($_SERVER['QUERY_STRING']) {
return substr($url, 0, strlen($url) - strlen($_SERVER['QUERY_STRING']) - 1);
}
return $url;
}
/*
* Gets an array of url fragments to be processed by controller
* @return array an array containing URL fragments
*/
function get_current_url_fragments () {
$url_source = get_current_url();
if ($url_source == '/index.php') return array();
return explode('/', substr($url_source, 1));
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Nov 21, 16:28 (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3174520
Default Alt Text
(8 KB)

Event Timeline