[pLog-svn] r5951 - in plog/branches/lifetype-1.2/class: file net test/tests/file
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Sat Sep 29 02:46:35 EDT 2007
Author: oscar
Date: 2007-09-29 02:46:34 -0400 (Sat, 29 Sep 2007)
New Revision: 5951
Modified:
plog/branches/lifetype-1.2/class/file/file.class.php
plog/branches/lifetype-1.2/class/net/baserequestgenerator.class.php
plog/branches/lifetype-1.2/class/test/tests/file/file_test.class.php
Log:
Removed a hardcoded occurence of ./templates, rather than using the Config class to retrieve the value from the database.
Modified: plog/branches/lifetype-1.2/class/file/file.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/file/file.class.php 2007-09-24 19:04:36 UTC (rev 5950)
+++ plog/branches/lifetype-1.2/class/file/file.class.php 2007-09-29 06:46:34 UTC (rev 5951)
@@ -494,6 +494,31 @@
$basename = preg_replace( '/^.+[\\\\\/]/', '', $fileName );
return $basename;
- }
+ }
+
+ /**
+ * "Cleans" up a path by removing all references to relative paths. It works in a way similar to
+ * PHP's own realpath() but it does not perform any kind of check to make sure that the path
+ * really exists in disk
+ *
+ * @param path
+ * @return String
+ * @static
+ */
+ function expandPath($path)
+ {
+ $oldP = "";
+ $newP = $path;
+ while( $newP != $oldP) {
+ $oldP = $newP;
+ $newP = preg_replace("/([^\/]+\/)([^\/]+\/)(\.\.\/)/ms","$1",$newP);
+ }
+ $result = str_replace("//","",str_replace("./","",$newP));
+
+ if($result[strlen($result)-1] == "/" )
+ $result = substr( $result, 0, strlen($result)-1);
+
+ return( $result );
+ }
}
?>
Modified: plog/branches/lifetype-1.2/class/net/baserequestgenerator.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/net/baserequestgenerator.class.php 2007-09-24 19:04:36 UTC (rev 5950)
+++ plog/branches/lifetype-1.2/class/net/baserequestgenerator.class.php 2007-09-29 06:46:34 UTC (rev 5951)
@@ -695,13 +695,16 @@
*/
function getTemplateFile( $file )
{
+ lt_include( PLOG_CLASS_PATH."class/file/file.class.php" );
+
// get the current template set
$blogSettings = $this->_blogInfo->getSettings();
$template = $blogSettings->getValue( "template" );
// define this couple of things
$baseUrl = $this->getBaseUrl();
- $url = "$baseUrl/templates/";
+ $config =& Config::getConfig();
+ $url = "$baseUrl/".File::expandPath( $config->getValue( "template_folder" ))."/";
// is it a blog template?
$blogTemplates = $blogSettings->getValue( "blog_templates" );
@@ -714,7 +717,7 @@
else
$url .= "$template/$file";
}
-
+
return $url;
}
Modified: plog/branches/lifetype-1.2/class/test/tests/file/file_test.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/tests/file/file_test.class.php 2007-09-24 19:04:36 UTC (rev 5950)
+++ plog/branches/lifetype-1.2/class/test/tests/file/file_test.class.php 2007-09-29 06:46:34 UTC (rev 5951)
@@ -27,5 +27,13 @@
$this->assertEquals("中文 name.jpg", File::basename( "\.\\\\\gallery\\\\\1\中文 name.jpg"));
$this->assertEquals("中文 name.jpg", File::basename( "\.\\\\\gallery\\\\\1\\中文 name.jpg"));
}
+
+ function testExpandPath()
+ {
+ $this->assertEquals( "path", File::expandPath( "./path" ));
+ $this->assertEquals( "a", File::expandPath( "./path/../a" ));
+ $this->assertEquals( "/path", File::expandPath( "/path" ));
+ $this->assertEquals( "/path", File::expandPath( "/path/././././" ));
+ }
}
?>
\ No newline at end of file
More information about the pLog-svn
mailing list