Ejemplo n.º 1
0
 /**
  * Triggers an individual event.
  *
  * NOTE: The payload sent to the event method is a pointer to the actual data.
  * This means that any operations on the data will affect the original data.
  * Use with care.
  *
  * @param string $event_name A string with the name of the event to trigger. Case sensitive.
  * @param mixed  $payload    (optional) A variable pointer to send to the event method.
  *
  * @return void
  */
 public static function trigger($event_name = null, &$payload = null)
 {
     if (empty($event_name) || !is_string($event_name)) {
         return;
     }
     if (!array_key_exists($event_name, self::$events)) {
         return;
     }
     if (!function_exists('module_file_path')) {
         $ci =& get_instance();
         $ci->load->helper('application');
     }
     $subscribers = self::$events[$event_name];
     foreach ($subscribers as $subscriber) {
         if (strpos($subscriber['filename'], '.php') == false) {
             $subscriber['filename'] .= '.php';
         }
         $file_path = module_file_path($subscriber['module'], $subscriber['filepath'], $subscriber['filename']);
         if (!file_exists($file_path)) {
             continue;
         }
         @(include_once $file_path);
         if (!class_exists($subscriber['class'])) {
             // if class doesn't exist check that the function is callable
             // could be just a helper function
             if (is_callable($subscriber['method'])) {
                 call_user_func($subscriber['method'], $payload);
             }
             continue;
         }
         $class = new $subscriber['class']();
         if (!is_callable(array($class, $subscriber['method']))) {
             unset($class);
             continue;
         }
         $class->{$subscriber['method']}($payload);
         unset($class);
     }
     //end foreach
 }
Ejemplo n.º 2
0
 private function find_files($files = array(), $type = 'css', $bypass_inheritance = false)
 {
     // Grab the theme paths from the template library.
     $paths = Template::get('theme_paths');
     $site_path = Template::get('site_path');
     $active_theme = Template::get('active_theme');
     $default_theme = Template::get('default_theme');
     $new_files = array();
     $clean_type = $type;
     $type = '.' . $type;
     if (self::$debug) {
         echo "Active Theme = {$active_theme}<br/>";
         echo "Default Theme = {$default_theme}<br/>";
         echo 'Site Path = ' . $site_path . '<br/>';
         echo 'File(s) to find: ';
         print_r($files);
     }
     foreach ($files as $file) {
         // If it's an array, we're dealing with css and it has both
         // a file and media keys. Store them for later use.
         if ($type == '.css' && is_array($file)) {
             $media = $file['media'];
             $module = isset($file['module']) ? $file['module'] : '';
             $file = $file['file'];
         } else {
             if ($type == '.js' && is_array($file)) {
                 $module = isset($file['module']) ? $file['module'] : '';
                 $file = $file['file'];
             }
         }
         // Strip out the file type for consistency
         $file = str_replace($type, '', $file);
         // If it contains an external URL, we're all done here.
         if (strpos((string) $file, 'http', 0) !== false) {
             $new_files[] = $file;
             continue;
         }
         $found = false;
         // Is it a module file?
         if (!empty($module)) {
             $path = module_file_path($module, 'assets', $file);
             if (!empty($path)) {
                 $file_path = '';
                 $file = array('file' => $file_path, 'server_path' => $path);
                 if (isset($media)) {
                     $file['media'] = $media;
                 }
                 $new_files[] = $file;
             }
             continue;
         } else {
             // We need to check all of the possible theme_paths
             foreach ($paths as $path) {
                 if (self::$debug) {
                     echo '[Assets] Looking in: <ul><li>' . $site_path . $path . '/' . $default_theme . $file . "{$type}</li>";
                     echo '<li>' . $site_path . $path . '/' . $default_theme . $type . '/' . $file . $type . "</li>";
                     if (!empty($active_theme)) {
                         echo '<li>' . $site_path . $path . '/' . $active_theme . $file . "{$type}</li>";
                         echo '<li>' . $site_path . $path . '/' . $active_theme . $type . '/' . $file . "{$type}</li>";
                     }
                     echo '<li>' . $site_path . self::$asset_base . '/' . $type . '/' . $file . "{$type}</li>";
                     echo '</ul>';
                 }
                 if (!$bypass_inheritance) {
                     /*
                     	DEFAULT THEME
                     
                     	First, check the default theme. Add it to the array. We check here first so that it
                     	will get overwritten by anything in the active theme.
                     */
                     if (is_file($site_path . $path . '/' . $default_theme . $file . "{$type}")) {
                         $file_path = base_url() . $path . '/' . $default_theme . $file . "{$type}";
                         $server_path = $site_path . $path . '/' . $default_theme . $file . "{$type}";
                         $new_files[] = isset($media) ? array('file' => $file_path, 'media' => $media, 'server_path' => $server_path) : $file_path;
                         $found = true;
                         if (self::$debug) {
                             echo '[Assets] Found file at: <b>' . $site_path . $path . '/' . $default_theme . $file . "{$type}" . "</b><br/>";
                         }
                     } else {
                         if (is_file($site_path . $path . '/' . $default_theme . $clean_type . '/' . $file . "{$type}")) {
                             $file_path = base_url() . $path . '/' . $default_theme . $clean_type . '/' . $file . ".{$type}";
                             $server_path = $site_path . $path . '/' . $default_theme . $clean_type . '/' . $file . "{$type}";
                             $new_files[] = isset($media) ? array('file' => $file_path, 'media' => $media, 'server_path' => $server_path) : $file_path;
                             $found = true;
                             if (self::$debug) {
                                 echo '[Assets] Found file at: <b>' . $site_path . $path . '/' . $default_theme . $type . '/' . $file . "{$type}" . "</b><br/>";
                             }
                         }
                     }
                 }
                 /*
                 	ACTIVE THEME
                 	
                 	By grabbing a copy from both the default theme and the active theme, we can
                 	handle simple CSS-only overrides for a theme, completely changing it's appearance
                 	through a simple child css file.
                 */
                 if (!empty($active_theme) && is_file($site_path . $path . '/' . $active_theme . $file . "{$type}")) {
                     $file_path = base_url() . $path . '/' . $active_theme . $file . "{$type}";
                     $server_path = $site_path . $path . '/' . $active_theme . $file . "{$type}";
                     $new_files[] = isset($media) ? array('file' => $file_path, 'media' => $media, 'server_path' => $server_path) : $file_path;
                     $found = true;
                     if (self::$debug) {
                         echo '[Assets] Found file at: <b>' . $site_path . $path . '/' . $active_theme . $file . "{$type}" . "</b><br/>";
                     }
                 } else {
                     if (is_file($site_path . $path . '/' . $active_theme . $clean_type . '/' . $file . "{$type}")) {
                         $file_path = base_url() . $path . '/' . $active_theme . $clean_type . '/' . $file . "{$type}";
                         $server_path = $site_path . $path . '/' . $active_theme . $clean_type . '/' . $file . "{$type}";
                         $new_files[] = isset($media) ? array('file' => $file_path, 'media' => $media, 'server_path' => $server_path) : $file_path;
                         $found = true;
                         if (self::$debug) {
                             echo '[Assets] Found file at: <b>' . $site_path . $path . '/' . $active_theme . $type . '/' . $file . "{$type}" . "</b><br/>";
                         }
                     }
                 }
                 /*
                 	ASSET BASE
                 	
                 	If the file hasn't been found, yet, we have one more place to look for it: 
                 	in the folder specified by 'assets.base_folder', and under the $type sub-folder.
                 */
                 if (!$found) {
                     // Assets/type folder
                     if (is_file($site_path . self::$asset_base . '/' . $clean_type . '/' . $file . "{$type}")) {
                         $file_path = base_url() . self::$asset_base . '/' . $clean_type . '/' . $file . "{$type}";
                         $server_path = $site_path . self::$asset_base . '/' . $clean_type . '/' . $file . "{$type}";
                         $new_files[] = isset($media) ? array('file' => $file_path, 'media' => $media, 'server_path' => $server_path) : $file_path;
                         if (self::$debug) {
                             echo '[Assets] Found file at: <b>' . $site_path . self::$asset_base . '/' . $type . '/' . $file . "{$type}" . "</b><br/>";
                         }
                     } else {
                         if (is_file($site_path . self::$asset_base . '/' . $file . "{$type}")) {
                             $file_path = base_url() . self::$asset_base . '/' . $file . "{$type}";
                             $server_path = $site_path . self::$asset_base . '/' . $file . "{$type}";
                             $new_files[] = isset($media) ? array('file' => $file_path, 'media' => $media, 'server_path' => $server_path) : $file_path;
                             if (self::$debug) {
                                 echo '[Assets] Found file at: <b>' . $site_path . self::$asset_base . '/' . $file . "{$type}" . "</b><br/>";
                             }
                         }
                     }
                 }
                 // if (!$found)
             }
             // foreach ($paths as $path)
         }
         // else
     }
     return $new_files;
 }
Ejemplo n.º 3
0
 public function run()
 {
     if ($this->input->post('submit') && !$this->input->post('tests')) {
         Template::set_message('Please select one or more modules to run tests on.', 'attention');
         redirect(SITE_AREA . '/developer/tester');
     }
     $this->load->library('unit_test');
     $this->load->library('Unit_tester');
     $this->unit->set_test_items(array('test_name', 'result', 'notes'));
     $vars = array();
     $vars['results'] = array();
     // Someplace to store the results of all of our tests.
     $modules = is_array($this->input->post('tests')) ? $this->input->post('tests') : array($this->input->post('tests'));
     // Send to view for reload
     Template::set('test_names', $modules);
     Template::set_block('sub_nav', 'developer/_sub_nav');
     // Run through each module, running their tests.
     foreach ($modules as $module) {
         $tests = module_files($module, 'tests');
         $tests = $tests[$module]['tests'];
         // Run all of the tests.
         foreach ($tests as $test) {
             // We need to make sure it's not a sql file!
             if (strpos($test, '.sql') === false) {
                 // Grab our test class
                 $test_class = str_replace(EXT, '', end(explode('/', $test)));
                 $module_file_path = module_file_path($module, 'tests', $test);
                 require $module_file_path;
                 $class = new $test_class();
                 // Tell it what module it's running.
                 // (Saves us from manually doing it for every test class)
                 $class->set_module_path(dirname($module_file_path));
                 // Clear previous unit results
                 $this->unit->reset();
                 // Run the tests
                 $class->run_all();
                 // Store our results for processing later.
                 $vars['results'][$module . ' : <b>' . ucwords(str_replace('_', ' ', $test_class)) . '</b>'] = array('report' => $this->unit->report(), 'raw' => $this->unit->result(), 'passed' => 0, 'failed' => 0);
             }
         }
     }
     // Find our totals
     $vars['total_passed'] = 0;
     $vars['total_failed'] = 0;
     if (count($vars['results'])) {
         foreach ($vars['results'] as $key => $result) {
             foreach ($result['raw'] as $k => $v) {
                 // We're not using the results so strip it.
                 unset($vars['results'][$key]['report']);
                 if (isset($v['Result'])) {
                     if (strtolower($v['Result']) == 'passed') {
                         $vars['total_passed']++;
                         $vars['results'][$key]['passed']++;
                         //print_r($vars['results'][$key]);
                     } else {
                         $vars['total_failed']++;
                         $vars['results'][$key]['failed']++;
                     }
                 }
             }
         }
     }
     Template::set($vars);
     // display the results
     Template::render();
 }
Ejemplo n.º 4
0
 /**
  * Returns the 'module_config' array from a modules config/config.php
  * file. The 'module_config' contains more information about a module,
  * and even provide enhanced features within the UI. All fields are optional
  *
  * @author Liam Rutherford (http://www.liamr.com)
  *
  * <code>
  * $config['module_config'] = array(
  * 	'name'			=> 'Blog', 			// The name that is displayed in the UI
  *	'description'	=> 'Simple Blog',	// May appear at various places within the UI
  *	'author'		=> 'Your Name',		// The name of the module's author
  *	'homepage'		=> 'http://...',	// The module's home on the web
  *	'version'		=> '1.0.1',			// Currently installed version
  *	'menu'			=> array(			// A view file containing an <ul> that will be the sub-menu in the main nav.
  *		'context'	=> 'path/to/view'
  *	)
  * );
  * </code>
  *
  * @param $module_name string The name of the module.
  * @param $return_full boolean If true, will return the entire config array. If false, will return only the 'module_config' portion.
  *
  * @return array An array of config settings, or an empty array if empty/not found.
  */
 function module_config($module_name = null, $return_full = false)
 {
     $config_param = array();
     $config_file = module_file_path($module_name, 'config', 'config.php');
     if (file_exists($config_file)) {
         include $config_file;
         /* Check for the optional module_config and serialize if exists*/
         if (isset($config['module_config'])) {
             $config_param = $config['module_config'];
         } else {
             if ($return_full === true && isset($config) && is_array($config)) {
                 $config_param = $config;
             }
         }
     }
     return $config_param;
 }
Ejemplo n.º 5
0
 /**
  * Locates file by looping through the active and default themes, and
  * then the assets folder (as specified in the config file).
  *
  * Files are searched for in this order...
  *     1 - active_theme/
  *     2 - active_theme/type/
  *     3 - default_theme/
  *     4 - default_theme/type/
  *     5 - asset_base/type
  *
  * Where 'type' is either 'css' or 'js'.
  *
  * If the file is not found, it is removed from the array. If the file
  * is found, a full url is created, using base_path(), unless the path
  * already includes 'http' at the beginning of the filename, in which case
  * it is simply included in the return files.
  *
  * For CSS files, if a script of the same name is found in both the
  * default_theme and the active_theme folders (or their type sub-folder),
  * they are both returned, with the default_theme linked to first, so that
  * active_theme styles can override those in the default_theme without
  * having to recreate the entire stylesheet.
  *
  * @access private
  *
  * @param array  $files              An array of file names to search for.
  * @param string $type               Either 'css' or 'js'.
  * @param bool   $bypass_inheritance
  *
  * @return array The complete list of files with url paths.
  */
 private function find_files($files = array(), $type = 'css', $bypass_inheritance = FALSE)
 {
     // Grab the theme paths from the template library.
     $paths = Template::get('theme_paths');
     $site_path = Template::get('site_path');
     $active_theme = Template::get('active_theme');
     $default_theme = Template::get('default_theme');
     $new_files = array();
     $clean_type = $type;
     $type = '.' . $type;
     if (self::$debug) {
         echo "Active Theme = {$active_theme}<br/>";
         echo "Default Theme = {$default_theme}<br/>";
         echo "Site Path = {$site_path}<br/>";
         echo 'File(s) to find: ';
         print_r($files);
     }
     foreach ($files as $file) {
         // If it's an array, we're dealing with css and it has both
         // a file and media keys. Store them for later use.
         if (is_array($file)) {
             if ($type == '.css') {
                 $media = $file['media'];
             }
             $module = isset($file['module']) ? $file['module'] : '';
             $file = $file['file'];
         }
         // Strip out the file type for consistency
         $file = str_replace($type, '', $file);
         $rtl = 'rtl';
         //Check for HTTPS or HTTP connection
         if (isset($_SERVER['HTTPS'])) {
             $http_protocol = "https";
         } else {
             $http_protocol = "http";
         }
         // If it contains an external URL, we're all done here.
         if (strpos((string) $file, $http_protocol, 0) !== FALSE) {
             $new_files[] = !empty($media) ? array('file' => $file, 'media' => $media) : $file;
             continue;
         }
         $found = FALSE;
         // Is it a module file?
         if (!empty($module)) {
             $file_path_name = $file;
             $path = module_file_path($module, 'assets', $file_path_name . $type);
             if (empty($path)) {
                 $file_path_name = $clean_type . '/' . $file;
                 // Try assets/type folder
                 $path = module_file_path($module, 'assets', $file_path_name . $type);
             }
             if (!empty($path) && lang('bf_language_direction') == $rtl) {
                 $path_rtl = module_file_path($module, 'assets', $file_path_name . '-' . $rtl . $type);
                 if (!empty($path_rtl)) {
                     $path = $path_rtl;
                 }
             }
             if (self::$debug) {
                 echo "[Assets] Lookin for MODULE asset at: {$path}<br/>" . PHP_EOL;
             }
             if (!empty($path)) {
                 $file_path = '';
                 $file = array('file' => $file_path, 'server_path' => $path);
                 if (isset($media)) {
                     $file['media'] = $media;
                 }
                 $new_files[] = $file;
             }
             continue;
         } else {
             $media = empty($media) ? '' : $media;
             // We need to check all of the possible theme_paths
             foreach ($paths as $path) {
                 if (self::$debug) {
                     echo "[Assets] Looking in: <ul><li>{$site_path}{$path}/{$default_theme}{$file}{$type}</li>" . PHP_EOL;
                     echo "<li>{$site_path}{$path}/{$default_theme}{$type}/{$file}{$type}</li>" . PHP_EOL;
                     if (!empty($active_theme)) {
                         echo "<li>{$site_path}{$path}/{$active_theme}{$file}{$type}</li>" . PHP_EOL;
                         echo "<li>{$site_path}{$path}/{$active_theme}{$type}/{$file}{$type}</li>" . PHP_EOL;
                     }
                     echo '<li>' . $site_path . self::$asset_base . "/{$type}/{$file}{$type}</li>" . PHP_EOL;
                     echo '</ul>' . PHP_EOL;
                 }
                 /*
                  * If default_theme and active_theme are the same,
                  * checking the default_theme would just repeat the
                  * active_theme section below, resulting in duplicates
                  */
                 if (!$bypass_inheritance && $default_theme !== $active_theme) {
                     /*
                     	DEFAULT THEME
                     
                     	First, check the default theme. Add it to the array. We check here first so that it
                     	will get overwritten by anything in the active theme.
                     */
                     if ($file_array = self::get_file_array($site_path, $path . '/' . $default_theme, $file, $type, $media)) {
                         $new_files[] = $file_array;
                         $found = TRUE;
                     } else {
                         if ($file_array = self::get_file_array($site_path, $path . '/' . $default_theme . $clean_type . '/', $file, $type, $media)) {
                             $new_files[] = $file_array;
                             $found = TRUE;
                         }
                     }
                 }
                 /*
                 	ACTIVE THEME
                 
                 	By grabbing a copy from both the default theme and the active theme, we can
                 	handle simple CSS-only overrides for a theme, completely changing it's appearance
                 	through a simple child css file.
                 */
                 if (!empty($active_theme)) {
                     if ($file_array = self::get_file_array($site_path, $path . '/' . $active_theme, $file, $type, $media)) {
                         $new_files[] = $file_array;
                         $found = TRUE;
                     } else {
                         if ($file_array = self::get_file_array($site_path, $path . '/' . $active_theme . $clean_type . '/', $file, $type, $media)) {
                             $new_files[] = $file_array;
                             $found = TRUE;
                         }
                     }
                 }
                 /*
                 	ASSET BASE
                 
                 	If the file hasn't been found, yet, we have one more place to look for it:
                 	in the folder specified by 'assets.base_folder', and under the $type sub-folder.
                 */
                 if (!$found) {
                     // Assets/type folder
                     if ($file_array = self::get_file_array($site_path, self::$asset_base . '/' . $clean_type . '/', $file, $type, $media)) {
                         $new_files[] = $file_array;
                     } else {
                         if ($file_array = self::get_file_array($site_path, self::$asset_base . '/', $file, $type, $media)) {
                             $new_files[] = $file_array;
                         }
                     }
                 }
                 // if (!$found)
             }
             // foreach ($paths as $path)
         }
         // else
     }
     //end foreach
     return $new_files;
 }
Ejemplo n.º 6
0
 public static function trigger($event_name = null, &$payload = null)
 {
     if (empty($event_name) || !is_string($event_name)) {
         return;
     }
     if (!array_key_exists($event_name, self::$events)) {
         return;
     }
     if (!function_exists('module_file_path')) {
         $ci =& get_instance();
         $ci->load->helper('application');
     }
     $subscribers = self::$events[$event_name];
     foreach ($subscribers as $subscriber) {
         $file_path = module_file_path($subscriber['module'], $subscriber['filepath'], $subscriber['filename']);
         if (!file_exists($file_path)) {
             continue;
         }
         @(include $file_path);
         if (!class_exists($subscriber['class'])) {
             continue;
         }
         $class = new $subscriber['class']();
         if (!is_callable(array($class, $subscriber['method']))) {
             unset($class);
             continue;
         }
         $class->{$subscriber['method']}($payload);
         unset($class);
     }
 }
Ejemplo n.º 7
0
 /**
  * Save a language file
  *
  * @param string $filename The name of the file to locate. The file will be found by looking in all modules.
  * @param string $language The language to retrieve.
  * @param array  $settings An array of the language settings
  * @param bool   $return   TRUE to return the contents or FALSE to write to file
  *
  * @return mixed A string when the $return setting is TRUE
  */
 function save_lang_file($filename = NULL, $language = 'english', $settings = NULL, $return = FALSE)
 {
     if (empty($filename) || !is_array($settings)) {
         return FALSE;
     }
     // Is it the application_lang file?
     if ($filename == 'application_lang.php' || $filename == 'datatable_lang.php') {
         $path = APPPATH . 'language/' . $language . '/' . $filename;
     } else {
         $module = str_replace('_lang.php', '', $filename);
         $path = module_file_path($module, 'language', $language . '/' . $filename);
         // If it's empty still, just grab the module path
         if (empty($path)) {
             $path = module_path($module, 'language');
         }
     }
     // Load the file so we can loop through the lines
     if (is_file($path)) {
         $contents = file_get_contents($path);
         $empty = FALSE;
     } else {
         // Create the folder...
         $folder = basename($path) == 'language' ? $path . '/' . $language : dirname($path);
         if (!is_dir($folder)) {
             mkdir($folder);
             $path = basename($path) == 'language' ? $folder . '/' . $module . '_lang.php' : $path;
         }
         $contents = '';
         $empty = TRUE;
     }
     // Save the file.
     foreach ($settings as $name => $val) {
         // Is the config setting in the file?
         $start = strpos($contents, '$lang[\'' . $name . '\']');
         $end = strpos($contents, ';', $start);
         $search = substr($contents, $start, $end - $start + 1);
         //var_dump($search); die();
         if (is_array($val)) {
             $tval = 'array(\'';
             $tval .= implode("','", $val);
             $tval .= '\')';
             $val = $tval;
             unset($tval);
         } else {
             if (is_numeric($val)) {
                 $val = $val;
             } else {
                 $val = '\'' . str_replace("'", "\\'", $val) . '\'';
             }
         }
         if (!$empty) {
             $contents = str_replace($search, '$lang[\'' . $name . '\'] = ' . $val . ';', $contents);
         } else {
             $contents .= '$lang[\'' . $name . '\'] = ' . $val . ";\n";
         }
     }
     //end foreach
     // is the code we are producing OK?
     if (!is_null(eval(str_replace('<?php', '', $contents)))) {
         return FALSE;
     }
     // Make sure the file still has the php opening header in it...
     if (strpos($contents, '<?php') === FALSE) {
         $contents = '<?php if ( ! defined(\'BASEPATH\')) exit(\'No direct script access allowed\');' . "\n\n" . $contents;
     }
     // Write the changes out...
     if (!function_exists('write_file')) {
         $CI = get_instance();
         $CI->load->helper('file');
     }
     if ($return == FALSE) {
         $result = write_file($path, $contents);
     } else {
         return $contents;
     }
     if ($result === FALSE) {
         return FALSE;
     } else {
         return TRUE;
     }
 }
Ejemplo n.º 8
0
 /**
  * Deletes a module and all of its files.
  *
  * @access public
  *
  * @return void
  */
 public function delete()
 {
     $module_name = $this->input->post('module');
     if (!empty($module_name)) {
         $this->auth->restrict('Bonfire.Modules.Delete');
         $prefix = $this->db->dbprefix;
         $this->db->trans_begin();
         // check if there is a model to drop (non-table modules will have no model)
         $model_name = $module_name . "_model";
         if (module_file_path($module_name, 'models', $model_name . '.php')) {
             // drop the table
             $this->load->model($module_name . '/' . $model_name, 'mt');
             $this->dbforge->drop_table($this->mt->get_table());
         }
         // get any permission ids
         $query = $this->db->query('SELECT permission_id FROM ' . $prefix . 'permissions WHERE name LIKE "' . $module_name . '.%.%"');
         if ($query->num_rows() > 0) {
             foreach ($query->result_array() as $row) {
                 // undo any permissions that exist
                 $this->db->where('permission_id', $row['permission_id']);
                 $this->db->delete('permissions');
                 // and fron the roles as well.
                 $this->db->where('permission_id', $row['permission_id']);
                 $this->db->delete('role_permissions');
             }
         }
         // drop the schema - old Migration schema method
         $module_name_lower = preg_replace("/[ -]/", "_", strtolower($module_name));
         if ($this->db->field_exists($module_name_lower . '_version', 'schema_version')) {
             $this->dbforge->drop_column('schema_version', $module_name_lower . '_version');
         }
         // drop the Migration record - new Migration schema method
         $module_name_lower = preg_replace("/[ -]/", "_", strtolower($module_name));
         if ($this->db->field_exists('version', 'schema_version')) {
             $this->db->delete('schema_version', array('type' => $module_name_lower . '_'));
         }
         if ($this->db->trans_status() === FALSE) {
             $this->db->trans_rollback();
             Template::set_message('We could not delete this module.', $this->db->error, 'error');
         } else {
             $this->db->trans_commit();
             // database was successful in deleting everything. Now try to get rid of the files.
             if (delete_files(module_path($module_name), true)) {
                 @rmdir(module_path($module_name . '/'));
                 // Log the activity
                 $this->activity_model->log_activity((int) $this->current_user->id, lang('mb_act_delete') . ': ' . $module_name . ' : ' . $this->input->ip_address(), 'builder');
                 Template::set_message('The module and associated database entries were successfully deleted.', 'success');
             } else {
                 Template::set_message('The module and associated database entries were successfully deleted, HOWEVER, the module folder and files were not removed. They must be removed manually.', 'info');
             }
         }
         //end if
     }
     //end if
     Template::redirect(SITE_AREA . '/developer/builder');
 }
Ejemplo n.º 9
0
 /**
  * Deletes a module and all of its files.
  *
  * @access public
  *
  * @return void
  */
 public function delete()
 {
     $module_name = $this->input->post('module');
     if (!empty($module_name)) {
         $this->auth->restrict('Bonfire.Modules.Delete');
         $this->db->trans_begin();
         // check if there is a model to drop (non-table modules will have no model)
         $model_name = $module_name . '_model';
         if (module_file_path($module_name, 'models', $model_name . '.php')) {
             // drop the table
             $this->load->model($module_name . '/' . $model_name, 'mt');
             $this->load->dbforge();
             $this->dbforge->drop_table($this->mt->get_table());
         }
         // get any permission ids
         $query = $this->db->select('permission_id')->like('name', $module_name . '.', 'after')->get('permissions');
         if ($query->num_rows() > 0) {
             foreach ($query->result_array() as $row) {
                 // undo any permissions that exist
                 $this->db->where('permission_id', $row['permission_id'])->delete('permissions');
                 // and from the roles as well.
                 $this->db->where('permission_id', $row['permission_id'])->delete('role_permissions');
             }
         }
         // drop the schema - old Migration schema method
         $module_name_lower = preg_replace("/[ -]/", "_", strtolower($module_name));
         if ($this->db->field_exists($module_name_lower . '_version', 'schema_version')) {
             $this->dbforge->drop_column('schema_version', $module_name_lower . '_version');
         }
         // drop the Migration record - new Migration schema method
         if ($this->db->field_exists('version', 'schema_version')) {
             $this->db->delete('schema_version', array('type' => $module_name_lower . '_'));
         }
         if ($this->db->trans_status() === FALSE) {
             $this->db->trans_rollback();
             Template::set_message(lang('mb_delete_trans_false'), $this->db->error, 'error');
         } else {
             $this->db->trans_commit();
             // database was successful in deleting everything. Now try to get rid of the files.
             if (delete_files(module_path($module_name), true)) {
                 @rmdir(module_path($module_name . '/'));
                 // Log the activity
                 log_activity((int) $this->current_user->id, lang('mb_act_delete') . ': ' . $module_name . ' : ' . $this->input->ip_address(), 'builder');
                 Template::set_message(lang('mb_delete_success'), 'success');
             } else {
                 Template::set_message(lang('mb_delete_success') . lang('mb_delete_success_db_only'), 'info');
             }
         }
         //end if
     }
     //end if
     redirect(SITE_AREA . '/developer/builder');
 }
Ejemplo n.º 10
0
 /**
  * Performs the image processing based on the parameters provided in the GET request
  *
  * @param string $file The name of the image to return.
  */
 public function index($file = null)
 {
     if (empty($file) || !is_string($file)) {
         die('No image to process.');
     }
     $this->output->enable_profiler(false);
     // Get our params
     $assets = $this->input->get('assets') ? $this->input->get('assets') : 'assets/images';
     $size = $this->input->get('size');
     $height = $this->input->get('height');
     $width = $this->input->get('width');
     $ratio = $this->input->get('ratio');
     $force = $this->input->get('force');
     $module = $this->input->get('module');
     $ext = pathinfo($file, PATHINFO_EXTENSION);
     if (empty($ext)) {
         die('Filename does not include a file extension.');
     }
     // Is it a square?
     if (!empty($size)) {
         $height = (int) $size;
         $width = (int) $size;
         $ratio = 'no';
     }
     if (!empty($module)) {
         $img_file = module_file_path($module, $assets, $file);
     } else {
         $img_file = FCPATH . $assets . '/' . $file;
     }
     if (!is_file($img_file)) {
         die('Image could not be found.');
     }
     $new_file = FCPATH . 'assets/cache/' . str_replace('.' . $ext, '', $file) . "_{$width}x{$height}." . $ext;
     if (!is_file($new_file) || $force != 'yes') {
         $config = array('image_library' => 'gd2', 'source_image' => $img_file, 'new_image' => $new_file, 'create_thumb' => false, 'maintain_ratio' => $ratio == 'no' ? false : true, 'master_dim' => !empty($width) ? 'width' : 'height', 'width' => !empty($width) ? $width : $height, 'height' => !empty($height) ? $height : $width);
         $this->load->library('image_lib', $config);
         $this->image_lib->resize();
     }
     $this->output->set_content_type($ext)->set_output(file_get_contents($new_file));
 }
Ejemplo n.º 11
0
 /**
  * Save a language file
  *
  * @param string $filename The name of the file to locate. The file will be found by looking in all modules.
  * @param string $language The language to retrieve.
  * @param array  $settings An array of the language settings
  * @param bool   $return   TRUE to return the contents or FALSE to write to file
  *
  * @return mixed A string when the $return setting is TRUE
  */
 function save_lang_file($filename = NULL, $language = 'english', $settings = NULL, $return = FALSE)
 {
     if (empty($filename) || !is_array($settings)) {
         return FALSE;
     }
     // Is it the application_lang file?
     if ($filename == 'application_lang.php' || $filename == 'datatable_lang.php') {
         $orig_path = APPPATH . 'language/english/' . $filename;
         $path = APPPATH . 'language/' . $language . '/' . $filename;
     } else {
         $module = str_replace('_lang.php', '', $filename);
         $orig_path = module_file_path($module, 'language', 'english/' . $filename);
         $path = module_file_path($module, 'language', $language . '/' . $filename);
         // If it's empty still, just grab the module path
         if (empty($path)) {
             $path = module_path($module, 'language');
         }
     }
     // Load the file so we can loop through the lines
     if (!is_file($orig_path)) {
         return FALSE;
     }
     $contents = file_get_contents($orig_path);
     $contents = trim($contents) . "\n";
     if (!is_file($path)) {
         // Create the folder...
         $folder = basename($path) == 'language' ? $path . '/' . $language : dirname($path);
         if (!is_dir($folder)) {
             mkdir($folder);
             $path = basename($path) == 'language' ? $folder . '/' . $module . '_lang.php' : $path;
         }
     }
     // Save the file.
     foreach ($settings as $name => $val) {
         // Use strrpos() instead of strpos() so we don't lose data
         // when people have put duplicate keys in the english files
         $start = strrpos($contents, '$lang[\'' . $name . '\']');
         if ($start === FALSE) {
             // tried to add non-existent value?
             return FALSE;
         }
         $end = strpos($contents, "\n", $start) + strlen("\n");
         if ($val !== '') {
             $val = '\'' . addcslashes($val, '\'\\') . '\'';
             $replace = '$lang[\'' . $name . '\'] = ' . $val . ";\n";
         } else {
             $replace = '// ' . substr($contents, $start, $end - $start);
         }
         $contents = substr($contents, 0, $start) . $replace . substr($contents, $end);
     }
     //end foreach
     // is the code we are producing OK?
     if (!is_null(eval(str_replace('<?php', '', $contents)))) {
         return FALSE;
     }
     // Make sure the file still has the php opening header in it...
     if (strpos($contents, '<?php') === FALSE) {
         $contents = '<?php if ( ! defined(\'BASEPATH\')) exit(\'No direct script access allowed\');' . "\n\n" . $contents;
     }
     // Write the changes out...
     if (!function_exists('write_file')) {
         $CI = get_instance();
         $CI->load->helper('file');
     }
     if ($return == FALSE) {
         $result = write_file($path, $contents);
     } else {
         return $contents;
     }
     if ($result === FALSE) {
         return FALSE;
     } else {
         return TRUE;
     }
 }