Avail feature updated
[ninja.git] / application / helpers / customlogo.php
blobc14c95d581381cbc258e09da4b361549d875818d
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Help class to ease the customization of the Ninja GUI Logo
4 */
5 class customlogo {
6 /**
7 * Display the div with the logo if it's all enabled
8 */
9 public static function Render()
11 if (!Kohana::Config('customlogo.enable'))
12 return;
14 $logo = customlogo::imageExists($image = customlogo::getImage());
16 if ($logo) {
17 $height = 42;
18 echo html::image(array(
19 'src' => $image,
20 'height' => $height,
22 array(
23 'alt' => '',
24 'style' => '',
29 return;
32 /**
33 * Function to check if the image actually exists, else we won't display the logo
35 function imageExists($logo)
37 if (is_file($logo))
38 return is_readable($logo);
40 return false;
43 /**
44 * Get the logo we should use based on some nifty logic
46 function getImage()
48 $path = 'application/views/icons/';
49 $icon = $path . Kohana::config('customlogo.path') . Kohana::config('customlogo.default_icon');
51 /**
52 * Get list of icons found in the custom_logo dir and
53 * try to match it towards your pattern defined in config
55 $images = customlogo::getCustomImageList();
56 if (!$images) {
57 return $icon;
60 if (!preg_match(Kohana::config('customlogo.pattern'), user::session('username'), $custom)) {
61 return $icon;
64 foreach ($images as $image) {
65 if (($image == $custom[1] . '.png') || ($image == $custom[1] . '.jpg')) {
66 return $path . Kohana::config('customlogo.path') . $image;
70 return $icon;
74 /**
75 * Read the custom dir defined in customlogo config file
76 * return an array of the names.
78 function getCustomImageList()
80 $images = false;
81 if ($fh = opendir(APPPATH.'views/icons/'.Kohana::Config('customlogo.path'))) {
82 while (false !== ($file = readdir($fh))) {
83 if ((substr($file, -4) == '.png') || (substr($file, -4) == '.jpg')) {
84 $images[] = $file;
89 return $images;