/** * * Return URI instance * * @access public * * @return object * */ public static function getInstance() { if (is_null(self::$instance)) { self::$instance = new uri(); } return self::$instance; }
function __construct($config = array()) { parent::__construct(); $name = Uri::instance()->segment(1, Kohana::config('controls.default_controller')); $setup = Kohana::config('controls.' . $name); if ($setup != false) { $this->setup = $setup; } else { $this->setup = array(); $this->setup['name'] = $name; $this->setup['model'] = inflector::singular($name); $this->setup['table'] = $name; $this->setup['view'] = 'standard'; } $this->name = $this->setup['name']; $this->set_listeners(); }
public function get_page() { $c = URI::instance()->segment(1, 'page'); if ($c != 'page' and $c != 'auth') { return $c; } $p = Uri::instance()->segment(2, 'home'); $pos = strrpos($p, '.'); if ($pos !== false) { $p = substr($p, 0, $pos); } return $p; }
/** * Loads URI and Input objects into the controller. * Check if the requested environment supports by the system. * @throws Exception_Exido */ public function __construct() { // Check environment if (!in_array(EXIDO_ENVIRONMENT_NAME, $this->_envs)) { throw new Exception_Exido('The requested environment %s does not supported by the system', array(EXIDO_ENVIRONMENT_NAME)); } // URI should always be available $this->uri = Uri::instance(); // Input should always be available $this->input = Input::instance(); // Init a model loader object $this->_model = Registry::factory('Model'); // Input should always be available $this->view = View::instance(); // Session object $this->session = Registry::factory('Session'); // Init layout view object $this->_viewLayout = Registry::factory('View_Layout'); // Init action view object $this->_viewAction = Registry::factory('View_Action'); // Get active components $this->_components = $this->model('Model_Component')->getActiveComponents(); // Get session data $_user_key = $this->_getCurrentUser(); // If current user is unknown so we should start guest session if (empty($_user_key)) { // Guest session id $_user_key = '5627a272bf2563cee5877539bd906e7cc3eb33afcefe2b570a08906f9a34ae48'; } if ($r = $this->model('Model_User')->getUserByUniqueKey($_user_key)) { $this->_system_user = array('user_id' => $r->getUser_id(), 'user_name' => $r->getUser_name(), 'password' => $r->getPassword(), 'user_email' => $r->getUser_email(), 'owner_id' => $r->getOwner_id(), 'owner_name' => $r->getOwner_name(), 'group_id' => $r->getGroup_id(), 'group_name' => $r->getGroup_name(), 'role_name' => $r->getRole_key(), 'permissions' => array('owner' => $r->getPermissions_owner(), 'group' => $r->getPermissions_group(), 'other' => $r->getPermissions_other()), 'is_enabled' => $r->getIs_enabled(), 'is_dropped' => $r->getIs_dropped(), 'is_system' => $r->getIs_system()); // User constants define('@SU.GROUP_ID', $r->getGroup_id()); define('@SU.GROUP_NAME', $r->getGroup_name()); define('@SU.USER_ID', $r->getUser_id()); define('@SU.USER_NAME', $r->getUser_name()); $this->_system_user_access = $this->model('Model_User')->getUserAccess($r->getUser_id(), EXIDO_ENVIRONMENT_NAME); $this->session->set('system_user', $_user_key); } }
/** * render an image from a title * * @return void * @author Andy Bennett */ function render() { $c = Uri::instance()->segment(2, 'default'); $config = Kohana::config('image_title.' . $c); if (!is_array($config)) { die('config error'); } $using_ie6 = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.') !== FALSE; $id = md5(serialize($_GET)); $path = APPPATH . 'cache/images/titles/' . $id . '-' . ($using_ie6 ? '8b' : '24b') . '.png'; if (!file_exists($path) or !Kohana::config('image_title.cache')) { $image_width = Kohana::instance()->input->get('width', false); $font_size = Kohana::instance()->input->get('size', false); if ($image_width == false) { $image_width = $config['width']; } if ($font_size == false) { $font_size = $config['size']; } $title = Kohana::instance()->input->get('title'); $font_size = $font_size * 4; if ($title == false) { $title = 'Hello World!'; } if ($image_width == false) { $image_width = strlen($title) * $font_size; } else { $image_width = $image_width * 4; } $fw = $font_size * 0.6; $w = floor($image_width / $fw); $title = wordwrap($title, $w, "\n"); $c = count(explode("\n", $title)); $image_height = $font_size * 1.5 * $c; $font_path = Kohana::find_file('fonts', $config['font'], TRUE, $config['format']); // Check GD lib support $freetype = FALSE; if (function_exists('gd_info')) { $libspecs = gd_info(); $gif_create = $libspecs['GIF Create Support']; $jpg_support = (isset($libspecs['JPEG Support']) && $libspecs['JPEG Support'] or isset($libspecs['JPG Support']) && $libspecs['JPG Support']); $png_support = $libspecs['PNG Support']; $freetype = $libspecs['FreeType Support']; } $jpg_support = $jpg_support ? $jpg_support : imagetypes() & IMG_JPG; $png_support = $png_support ? $png_support : imagetypes() & IMG_PNG; if (!$jpg_support and !$png_support or !function_exists('imagetypes')) { Kohana::log('error', 'GD library is not installed'); exit; } $w = $image_width / 4; $h = $image_height / 4; // Creates the image if (function_exists('imagecreatetruecolor') and !$using_ie6) { $new_image = imageCreateTrueColor($image_width, $image_height); $final_image = imageCreateTrueColor($w, $h); } else { $final_image = imageCreate($w, $h); $new_image = imageCreate($image_width, $image_height); } imageSaveAlpha($new_image, true); ImageAlphaBlending($new_image, false); imageSaveAlpha($final_image, true); ImageAlphaBlending($final_image, false); $transparentColor = imagecolorallocatealpha($new_image, 200, 200, 200, 127); imagefill($new_image, 0, 0, $transparentColor); $transparentColor = imagecolorallocatealpha($final_image, 200, 200, 200, 127); imagefill($final_image, 0, 0, $transparentColor); $r = $config['r']; $r = is_numeric($r) ? $r : 80; $g = $config['g']; $b = is_numeric($g) ? $g : 100; $b = $config['b']; $b = is_numeric($b) ? $b : 149; $black = imagecolorallocate($new_image, $r, $g, $b); imagettftext($new_image, $font_size, $angle = 0, $x = 0, $font_size, $black, $font_path, $title); imagecopyresampled($final_image, $new_image, 0, 0, 0, 0, $w, $h, $image_width, $image_height); imageDestroy($new_image); if (!file_exists(dirname($path))) { mkdir(dirname($path), 0777, true); } imagePNG($final_image, $path); imageDestroy($final_image); } // Outputs the image header('Expires: Tue, 1 Jan 1980 00:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header('Content-type: image/png'); header('Content-Disposition: inline; filename=title.png'); readfile($path); }