diff --git a/init.php b/init.php index a3cb8dd3..350e4828 100644 --- a/init.php +++ b/init.php @@ -1,8 +1,8 @@ main->mediaPath . DS . 'fonts' . DS; -$libPath = $config->main->mediaPath . DS . 'lib' . DS; +$fontsPath = TextHelper::absolutePath($config->main->mediaPath . DS . 'fonts'); +$libPath = TextHelper::absolutePath($config->main->mediaPath . DS . 'lib'); @@ -29,10 +29,10 @@ function download($source, $destination = null) //jQuery -download('http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', $libPath . 'jquery' . DS . 'jquery.min.js'); +download('http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', $libPath . DS . 'jquery' . DS . 'jquery.min.js'); //jQuery UI -download('http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js', $libPath . 'jquery-ui' . DS . 'jquery-ui.min.js'); +download('http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js', $libPath . DS . 'jquery-ui' . DS . 'jquery-ui.min.js'); $manifest = download('http://ajax.googleapis.com/ajax/libs/jqueryui/1/MANIFEST'); $lines = explode("\n", str_replace("\r", '', $manifest)); foreach ($lines as $line) @@ -40,21 +40,21 @@ foreach ($lines as $line) if (preg_match('/themes\/flick\/(.*?) /', $line, $matches)) { $srcUrl = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1/' . $matches[0]; - $dstUrl = $libPath . 'jquery-ui' . DS . $matches[1]; + $dstUrl = $libPath . DS . 'jquery-ui' . DS . $matches[1]; download($srcUrl, $dstUrl); } } //jQuery Tag-it! -download('http://raw.github.com/aehlke/tag-it/master/css/jquery.tagit.css', $libPath . 'tagit' . DS . 'jquery.tagit.css'); -download('http://raw.github.com/aehlke/tag-it/master/js/tag-it.min.js', $libPath . 'tagit' . DS . 'jquery.tagit.js'); +download('http://raw.github.com/aehlke/tag-it/master/css/jquery.tagit.css', $libPath . DS . 'tagit' . DS . 'jquery.tagit.css'); +download('http://raw.github.com/aehlke/tag-it/master/js/tag-it.min.js', $libPath . DS . 'tagit' . DS . 'jquery.tagit.js'); //Mousetrap -download('http://raw.github.com/ccampbell/mousetrap/master/mousetrap.min.js', $libPath . 'mousetrap' . DS . 'mousetrap.min.js'); +download('http://raw.github.com/ccampbell/mousetrap/master/mousetrap.min.js', $libPath . DS . 'mousetrap' . DS . 'mousetrap.min.js'); //fonts -download('http://googlefontdirectory.googlecode.com/hg/apache/droidsans/DroidSans.ttf', $fontsPath . 'DroidSans.ttf'); -download('http://googlefontdirectory.googlecode.com/hg/apache/droidsans/DroidSans-Bold.ttf', $fontsPath . 'DroidSans-Bold.ttf'); +download('http://googlefontdirectory.googlecode.com/hg/apache/droidsans/DroidSans.ttf', $fontsPath . DS . 'DroidSans.ttf'); +download('http://googlefontdirectory.googlecode.com/hg/apache/droidsans/DroidSans-Bold.ttf', $fontsPath . DS . 'DroidSans-Bold.ttf'); diff --git a/public_html/dispatch.php b/public_html/dispatch.php index 40413c81..ea08b316 100644 --- a/public_html/dispatch.php +++ b/public_html/dispatch.php @@ -1,6 +1,5 @@ main->filesPath, DS); $query = array_shift($argv); $posts = Model_Post::getEntities($query, null, null); foreach ($posts as $post) @@ -21,7 +20,7 @@ foreach ($posts as $post) [ $post->id, $post->name, - $filesPath . DS . $post->name, + Model_Post::getFullPath($post->name), $post->mimeType, ]). PHP_EOL; } diff --git a/scripts/process-detached-files.php b/scripts/process-detached-files.php index 652ff148..382ca7c7 100644 --- a/scripts/process-detached-files.php +++ b/scripts/process-detached-files.php @@ -1,6 +1,5 @@ main->filesPath; - rename($filesPath . DS . $name, $dir . DS . $name); + $srcPath = Model_Post::getFullPath($name); + $dstPath = $dir . DS . $name; + rename($srcPath, $dstPath); }; break; case '-purge': - $func = function($name) use ($dir, $config) + $func = function($name) { echo $name . PHP_EOL; - static $filesPath = null; - if ($filesPath == null) - $filesPath = $config->main->filesPath; - unlink($filesPath . DS . $name); + $srcPath = Model_Post::getFullPath($name); + unlink($srcPath); }; break; @@ -63,8 +59,8 @@ foreach (R::findAll('post') as $post) } $names = array_flip($names); -$filesPath = $config->main->filesPath; -foreach (glob($filesPath . DS . '*') as $name) +$config = \Chibi\Registry::getConfig(); +foreach (glob(TextHelper::absolutePath($config->main->filesPath) . DS . '*') as $name) { $name = basename($name); if (!isset($names[$name])) diff --git a/scripts/process-old-users.php b/scripts/process-old-users.php index 2c2b08a4..7bb227ea 100644 --- a/scripts/process-old-users.php +++ b/scripts/process-old-users.php @@ -32,7 +32,7 @@ switch ($action) $func = function($user) { printUser($user); - R::trash($user); + Model_User::remove($user); }; break; diff --git a/src/Controllers/IndexController.php b/src/Controllers/IndexController.php index c0c21e5e..cfafa486 100644 --- a/src/Controllers/IndexController.php +++ b/src/Controllers/IndexController.php @@ -32,7 +32,7 @@ class IndexController $tab = $tab ?: array_keys($this->config->help->subTitles)[0]; if (!isset($this->config->help->paths[$tab])) throw new SimpleException('Invalid tab'); - $this->context->path = $this->config->help->paths[$tab]; + $this->context->path = TextHelper::absolutePath($this->config->help->paths[$tab]); $this->context->stylesheets []= 'index-help.css'; $this->context->stylesheets []= 'tabs.css'; $this->context->subTitle = 'help'; diff --git a/src/Controllers/LogController.php b/src/Controllers/LogController.php index 31d9d0a4..9d91e0e9 100644 --- a/src/Controllers/LogController.php +++ b/src/Controllers/LogController.php @@ -9,8 +9,7 @@ class LogController $this->context->subTitle = 'latest logs'; PrivilegesHelper::confirmWithException(Privilege::ListLogs); - $path = $this->context->rootDir . DS . $this->config->main->logsPath; - $path = TextHelper::cleanPath($path); + $path = TextHelper::absolutePath($this->config->main->logsPath); $logs = []; foreach (glob($path . DS . '*.log') as $log) @@ -36,8 +35,7 @@ class LogController PrivilegesHelper::confirmWithException(Privilege::ViewLog); $name = str_replace(['/', '\\'], '', $name); //paranoia mode - $path = $this->context->rootDir . DS . $this->config->main->logsPath . DS . $name; - $path = TextHelper::cleanPath($path); + $path = TextHelper::absolutePath($this->config->main->logsPath . DS . $name); if (!file_exists($path)) throw new SimpleException('Specified log doesn\'t exist'); diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 5f8a416a..c541a6da 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -514,7 +514,7 @@ class PostController PrivilegesHelper::confirmWithException(Privilege::ListPosts, PostSafety::toString($post->safety)); $post->makeThumb($width, $height); if (!file_exists($path)) - $path = $this->config->main->mediaPath . DS . 'img' . DS . 'thumb.jpg'; + $path = TextHelper::absolutePath($this->config->main->mediaPath . DS . 'img' . DS . 'thumb.jpg'); } } @@ -542,7 +542,7 @@ class PostController PrivilegesHelper::confirmWithException(Privilege::RetrievePost); PrivilegesHelper::confirmWithException(Privilege::RetrievePost, PostSafety::toString($post->safety)); - $path = $this->config->main->filesPath . DS . $post->name; + $path = TextHelper::absolutePath($this->config->main->filesPath . DS . $post->name); if (!file_exists($path)) throw new SimpleException('Post file does not exist'); if (!is_readable($path)) diff --git a/src/Helpers/LogHelper.php b/src/Helpers/LogHelper.php index 4fb02179..f4b1f295 100644 --- a/src/Helpers/LogHelper.php +++ b/src/Helpers/LogHelper.php @@ -1,7 +1,6 @@ main->logsPath . date('Y-m') . '.log'; self::$autoFlush = true; - self::$buffer = []; } @@ -39,7 +36,8 @@ class LogHelper public static function getLogPath() { - return self::$path; + return TextHelper::absolutePath( + \Chibi\Registry::getConfig()->main->logsPath . DS . date('Y-m') . '.log'); } public static function log($text, array $tokens = []) diff --git a/src/Helpers/TextHelper.php b/src/Helpers/TextHelper.php index 2a453523..1f063f94 100644 --- a/src/Helpers/TextHelper.php +++ b/src/Helpers/TextHelper.php @@ -224,4 +224,13 @@ class TextHelper $path = rtrim($path, DS); return $path; } + + public static function absolutePath($path) + { + if ($path{0} != DS) + $path = \Chibi\Registry::getContext()->rootDir . DS . $path; + + $path = self::cleanPath($path); + return $path; + } } diff --git a/src/Models/Model_Post.php b/src/Models/Model_Post.php index d3b9fc42..ccb81845 100644 --- a/src/Models/Model_Post.php +++ b/src/Models/Model_Post.php @@ -130,10 +130,10 @@ class Model_Post extends AbstractModel { list ($width, $height) = self::validateThumbSize($width, $height); - return TextHelper::replaceTokens($text, [ + return TextHelper::absolutePath(TextHelper::replaceTokens($text, [ 'fullpath' => self::$config->main->thumbsPath . DS . $name, 'width' => $width, - 'height' => $height]); + 'height' => $height])); } public static function getThumbCustomPath($name, $width = null, $height = null) @@ -148,7 +148,7 @@ class Model_Post extends AbstractModel public static function getFullPath($name) { - return self::$config->main->filesPath . DS . $name; + return TextHelper::absolutePath(self::$config->main->filesPath . DS . $name); } public function isTaggedWith($tagName) diff --git a/src/core.php b/src/core.php index 7d497dd6..1ff7eec2 100644 --- a/src/core.php +++ b/src/core.php @@ -41,7 +41,7 @@ $context->startTime = $startTime; $context->rootDir = $rootDir; //load database -R::setup('sqlite:' . $config->main->dbPath); +R::setup('sqlite:' . TextHelper::absolutePath($config->main->dbPath)); R::freeze(true); R::dependencies(['tag' => ['post'], 'favoritee' => ['post', 'user'], 'comment' => ['post', 'user']]); diff --git a/upgrade.php b/upgrade.php index c3700db3..5a1e855d 100644 --- a/upgrade.php +++ b/upgrade.php @@ -5,7 +5,8 @@ $config = \Chibi\Registry::getConfig(); $dbVersion = Model_Property::get(Model_Property::DbVersion); printf('DB version = %d' . PHP_EOL, $dbVersion); -$upgrades = glob('src/Upgrades/*.sql'); +$upgradesPath = TextHelper::absolutePath(\Chibi\Registry::getContext()->rootDir . DS . 'src' . DS . 'Upgrades'); +$upgrades = glob($upgradesPath . DS . '*.sql'); natcasesort($upgrades); foreach ($upgrades as $upgradePath)