Merge branch 'maint/7.0'
[ninja.git] / application / helpers / ninja.php
blob598f71832e1e6de509638d3d489b59200c2c607f
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
3 /**
4 * Helper for basic ninja stuff
6 * Basically, stuff that could be in the ninja controller, if not other helpers
7 * had needed it.
8 */
9 class ninja {
10 private static $loaded_modules = array();
11 /**
12 * Given a file name that is relative to the views directory, find it and
13 * return the full path.
15 * @return string
17 public static function add_path($rel_path, $module_name=false) {
18 static $url_base = false;
19 if (!$url_base)
20 $url_base = url::base();
21 $rel_path = trim($rel_path);
22 if (empty($rel_path)) {
23 return false;
25 if($module_name === false ) {
26 $path = 'application/views/'.$rel_path;
27 } else {
28 $path = 'modules/'.$module_name.'/views/'.$rel_path;
30 # make sure we didn't mix up start/end slashes
31 $path = str_replace('//', '/', $path);
32 return self::add_version_to_uri($url_base.$path);
35 /**
36 * Return array of all installed skins
38 public static function get_skins() {
39 $available_skins = array();
40 $required_css = array('common.css');
41 $skins = glob(APPPATH.'views/css/*', GLOB_ONLYDIR);
42 if (count($skins) > 1) {
43 foreach ($skins as $skin) {
45 # make sure we have all requred css
46 $missing_css = false;
47 foreach ($required_css as $css) {
48 if (glob($skin.'/'.$css) == false) {
49 $missing_css = true;
50 continue;
53 if ($missing_css !== false) {
54 continue;
57 # all required css files seems to be exist
58 $skinparts = explode('/', $skin);
59 if (is_array($skinparts) && !empty($skinparts)) {
60 $available_skins[$skinparts[sizeof($skinparts)-1].'/'] = $skinparts[sizeof($skinparts)-1];
64 return $available_skins;
67 /**
68 * @param $name string
69 * @return boolean
71 static function has_module($name)
73 $name = (string) $name;
74 if(!isset(self::$loaded_modules[$name])) {
75 self::$loaded_modules[$name] = is_readable(MODPATH.$name);
77 return self::$loaded_modules[$name];
80 /**
81 * Add "?v=3.0.0" (or such) to the parameter, makes for solid
82 * cache busting.
84 * @param $uri string
85 * @return string
87 static function add_version_to_uri($uri) {
88 return $uri .= "?v=".config::get_version_info();