public function getValue($key) { switch ($key) { // We can put specific keys which do something other than get the value of selectors // But of course this stops us from using those keys as XML Nodes in the code // This isn't really a problem, since I can't see them overlapping right now case "filename": return Amslib_File::absolute($this->location . "/" . $this->packageName); break; } return false; }
function TestOfabsolute() { $this->caseTitle('absolute'); $test = 'http://www.crm-test.local/vendor/amstudios/amslib/file/index.php'; $this->log($test); $result = Amslib_File::absolute($test); $this->log($result); $this->assertTrue(strpos($result, 'http://www.crm-test.local') === 0); $test = 'C:\\Sites\\crm-test\\vendor\\amstudios\\amslib\\file\\index.php'; $this->log($test); $result = Amslib_File::absolute($test); $this->log($result); $this->assertTrue(strpos($result, '/Sites/crm-test') === 0); $test = 'vendor\\amstudios\\amslib\\file\\index.php'; $this->log($test); $result = Amslib_File::absolute($test); $this->log($result); $this->assertEqual($result, '/Sites/crm-test/vendor/amstudios/amslib/file/index.php'); }
/** * method: setLocation * * todo: write documentation */ public function setLocation($location) { $this->location = Amslib_File::absolute($location); // NOTE: (08/03/2015) I don't think the below setPaths will work the way expected // as each plugin will keep resetting them with whatever location they are // given, hence there is no "plugin" location, it could diff and current plugin // will obviously change depending on the plugin being loaded, so this is // way off for a start. // NOTE: (05/05/2014) why the duplicated name....or more or less // duplicated, obviously I have old code to fix Amslib_Website::setPath("plugin", $this->location); Amslib_Website::setPath("current_plugin", $this->location); }
/** * method: getJavascript * * todo: write documentation */ public static function getJavascript() { $output = ""; $content = ""; foreach (self::$js as $file) { $content .= file_get_contents(Amslib_File::absolute($file)); } $output .= "<script type='text/javascript'>{$content}</script>"; foreach (self::$jsc as $condition => $list) { $content = ""; foreach ($list as $file) { $content .= file_get_contents(Amslib_File::absolute($file)); } $output .= "<!--[{$conditional}]><script type='text/javascript'>{$content}</script><![endif]-->"; } foreach (self::$jsi as $file) { $output .= "<script type='text/javascript' src='{$file}'></script>"; } return $output; }
/** * method: file_exists * * todo: write documentation */ protected function validate_file_exists($name, $value, $required, $options) { if ($options["absolute"] == true) { $value = Amslib_File::absolute($value); } if (is_file($value)) { $this->setValid("{$options["key"]}{$name}", $value); return true; } if ($required == false) { return true; } return "FILE_EXISTS_FAILED"; }
/** * method: absolute * * Return an absolute url for the file to the root directory * FIXME: if you pass an absolute filename into this method, it won't return the correct filename back */ public static function absolute($url = "", $resolve = false) { //self::set(); if (!is_string($url)) { Amslib_Debug::log("stack_trace", $url); return false; } /* // When we have a string with this protocol token, it's already an absolute url if(strpos($url,"://") !== false){ return $url; } $url = Amslib_File::absolute(self::$location.$url); return $resolve ? Amslib_File::resolvePath($url) : $url; */ return Amslib_File::absolute(self::$location . $url); }
/** * method: addLocation * * todo: write documentation */ public static function addLocation($location) { self::$location[] = Amslib_File::absolute($location); }