/** * List all language files for the specified language * * Searches the application/languages folder as well as all core modules * for folders matching the language name. * * @param string $language The language. * * @return array The filenames. */ function list_lang_files($language = 'english') { // Base language files. $langFiles = array(); $langFiles['core'] = find_lang_files(APPPATH . "language/{$language}/"); // Build the 'core' and 'custom' module lists. $modules = Modules::list_modules(); $appModules = Modules::list_modules(true); foreach ($modules as $module) { $moduleLangs = Modules::files($module, 'language'); $type = 'core'; if (isset($moduleLangs[$module]['language'][$language])) { $path = implode('/', array(Modules::path($module, 'language'), $language)); $files = find_lang_files($path . '/'); // 'core' modules will only be found in $modules, while 'custom' // modules will be found in both $modules and $appModules. if (in_array($module, $appModules)) { $type = 'custom'; } if (is_array($files)) { foreach ($files as $file) { $langFiles[$type][] = $file; } } } } return $langFiles; }
/** * List all language files for the specified language * * Searches the application/languages folder as well as all core modules * for folders matching the language name. * * @param string $language The language * * @return array An array of files. */ function list_lang_files($language = 'english') { $ci =& get_instance(); $lang_files = array(); // Base language files. $lang_files['core'] = find_lang_files(APPPATH . "language/{$language}/"); // Module directories $modules = Modules::list_modules(); // Application Module directories only $custom_modules = Modules::list_modules(true); foreach ($modules as $module) { $module_langs = Modules::files($module, 'language'); $type = 'core'; if (isset($module_langs[$module]['language'][$language])) { $path = implode('/', array(Modules::path($module, 'language'), $language)); $files = find_lang_files($path . '/'); if (in_array($module, $custom_modules)) { $type = 'custom'; } if (is_array($files)) { foreach ($files as $file) { $lang_files[$type][] = $file; } } } } return $lang_files; }
/** * Loads the library's dependencies and configuration. * * @return void */ public static function initialize() { // get all installed extensions if (empty(self::$extensions)) { self::$CI =& get_instance(); self::$extensions = self::$CI->extension->getInstalledExtensions(); } // Merge events from indivdual modules. foreach (Modules::list_modules() as $module) { // Skip if module is not installed if (!isset(self::$extensions[$module])) { continue; } $path = ROOTPATH . EXTPATH . "{$module}/config/"; if (is_file($path . 'events.php')) { $module_events = Modules::load_file('events', $path, 'config'); if (is_array($module_events)) { self::$events = array_merge_recursive(self::$events, $module_events); } } } if (self::$events === FALSE) { self::$events = array(); } }
/** * Display a list of installed modules * * Includes the options to create a new module or context and delete * existing modules. * * @return void */ public function index() { $modules = Modules::list_modules(true); $configs = array(); foreach ($modules as $module) { $configs[$module] = Modules::config($module); if (!isset($configs[$module]['name'])) { $configs[$module]['name'] = ucwords($module); } elseif (strpos($configs[$module]['name'], 'lang:') === 0) { // If the name is configured, check to see if it is a lang entry // and, if it is, pull it from the application_lang file. $configs[$module]['name'] = lang(str_replace('lang:', '', $configs[$module]['name'])); } } // Sort the module list (by the name of each module's folder) ksort($configs); // Check that the modules folder is writable Template::set('writable', $this->checkWritable()); Template::set('modules', $configs); //Template::set('toolbar_title', lang('mb_toolbar_title_index')); $data = array('page_title' => lang('mb_page_title'), 'page_subtitle' => '', 'page_breadcrumb' => lang('mb_breadcrumb_title')); $data['writable'] = $this->checkWritable(); $data['modules'] = $configs; foreach ($data as $key => $value) { Template::set($key, $value); } Template::render(); }
/** * Loads the library's dependencies and configuration. * * @return void */ public static function init() { if (!function_exists('read_config')) { self::$ci =& get_instance(); self::$ci->load->helper('config_file'); } self::$events = read_config('events', true, null, false); // Merge events from indivdual modules. foreach (Modules::list_modules(true) as $module) { $module_events = read_config('events', true, $module, true); if (is_array($module_events)) { self::$events = array_merge_recursive(self::$events, $module_events); } } if (self::$events == false) { self::$events = array(); } }
/** * Display the list of modules in the Bonfire installation * * @return void */ public function modules() { $modules = Modules::list_modules(); $configs = array(); foreach ($modules as $module) { $configs[$module] = Modules::config($module); if (!isset($configs[$module]['name'])) { $configs[$module]['name'] = ucwords($module); } else { if (strpos($configs[$module]['name'], 'lang:') === 0) { $configs[$module]['name'] = lang(str_replace('lang:', '', $configs[$module]['name'])); } } $configs[$module]['name'] = ucwords(str_replace('_', '', $configs[$module]['name'])); } // Sort the list of modules by directory name ksort($configs); Template::set('modules', $configs); Template::render(); }
/** * Display a list of installed modules * * Includes the options to create a new module or context and delete * existing modules. * * @return void */ public function index() { $modules = Modules::list_modules(true); $configs = array(); foreach ($modules as $module) { $configs[$module] = Modules::config($module); if (!isset($configs[$module]['name'])) { $configs[$module]['name'] = ucwords($module); } elseif (strpos($configs[$module]['name'], 'lang:') === 0) { $configs[$module]['name'] = lang(str_replace('lang:', '', $configs[$module]['name'])); } } // Sort the module list (by the name of each module's folder) ksort($configs); // Check that the modules folder is writable Template::set('writable', $this->checkWritable()); Template::set('modules', $configs); Template::set('toolbar_title', lang('mb_toolbar_title_index')); Template::render('two_left'); }
/** * Display the list of modules in the Bonfire installation. * * @return void */ public function modules() { $modules = Modules::list_modules(); $configs = array(); $unsetReplacement = '---'; foreach ($modules as $module) { $configs[$module] = Modules::config($module); if (!isset($configs[$module]['name'])) { $configs[$module]['name'] = ucwords($module); } elseif (strpos($configs[$module]['name'], 'lang:') === 0) { $configs[$module]['name'] = lang(str_replace('lang:', '', $configs[$module]['name'])); } $configs[$module]['name'] = ucwords(str_replace('_', '', $configs[$module]['name'])); $configs[$module]['version'] = isset($configs[$module]['version']) ? $configs[$module]['version'] : $unsetReplacement; $configs[$module]['description'] = isset($configs[$module]['description']) ? $configs[$module]['description'] : $unsetReplacement; $configs[$module]['author'] = isset($configs[$module]['author']) ? $configs[$module]['author'] : $unsetReplacement; } // Sort the list of modules by directory name. ksort($configs); Template::set('modules', $configs); Template::render(); }
/** * Returns a list of all modules in the system. * * @deprecated since 0.7.1 Use Modules::list_modules() instead * * @param bool $exclude_core Whether to exclude the Bonfire core modules or not * * @return array A list of all modules in the system. */ function module_list($exclude_core = false) { return Modules::list_modules($exclude_core); }
/** * Get activity based on parameters passed * * @param string $which Which filter to use. * @param bool $filterValue Value to filter by * * @return void */ private function getActivity($which = 'activity_user', $filterValue = false) { $postedWhichSelect = $this->input->post("{$which}_select"); // Check whether $filterValue has anything in it if ($filterValue === false) { $filterValue = $postedWhichSelect == '' ? $this->uri->segment(5) : $postedWhichSelect; } if (isset($_POST['delete'])) { $this->deleteActivity($which, $filterValue); } $activityDeletedField = $this->activity_model->get_deleted_field(); $activityTable = $this->activity_model->get_table(); $userDeletedField = $this->user_model->get_deleted_field(); $userKey = $this->user_model->get_key(); $userTable = $this->user_model->get_table(); // Set default values $name = lang('activities_all'); $options = array('all' => $name); // Find the $options and $name based on activity type ($which) switch ($which) { case 'activity_module': $modules = Modules::list_modules(); // Setup the list of modules for the filter in a separate list, // so it can be sorted and 'All' will remain at the top of the list. $mods = array(); foreach ($modules as $mod) { $mods[$mod] = $mod; if ($filterValue == $mod) { $name = ucwords($mod); } } // Sort list of modules by name. ksort($mods); // Merge the list of modules with the options array. $options = array_merge($options, $mods); $where = 'module'; Template::set('hasPermissionDeleteModule', $this->auth->has_permission($this->permissionDeleteModule)); break; case 'activity_date': foreach ($this->activity_model->find_all_by($activityDeletedField, 0) as $e) { $options[$e->activity_id] = $e->created_on; if ($filterValue == $e->activity_id) { $name = $e->created_on; } } $where = 'activity_id'; Template::set('hasPermissionDeleteDate', $this->auth->has_permission($this->permissionDeleteDate)); break; case 'activity_own': default: if ($this->hasPermissionViewUser) { // Use the same order_by for the user drop-down/select as is // used on the index page $this->user_model->where("{$userTable}.{$userDeletedField}", 0)->order_by('username', 'asc'); foreach ($this->user_model->find_all() as $e) { $options[$e->id] = $e->username; if ($filterValue == $e->id) { $name = $e->username; } } Template::set('hasPermissionDeleteUser', $this->auth->has_permission($this->permissionDeleteUser)); } elseif ($this->hasPermissionViewOwn) { $options = array(); $options[$this->auth->user_id()] = $this->auth->user()->username; $name = $this->auth->user()->username; } $where = 'user_id'; break; } // Set vars for the view Template::set('vars', array('which' => $which, 'view_which' => ucwords(lang(str_replace('activity_', 'activities_', $which))), 'name' => $name, 'delete_action' => $where, 'delete_id' => $filterValue)); $this->activity_model->order_by($where, 'asc'); // Apply the filter, if there is one if (empty($filterValue) || $filterValue == 'all') { $total = $this->activity_model->count_by("{$activityTable}.{$activityDeletedField}", 0); } else { $where = $where == 'activity_id' ? 'activity_id <' : $where; $total = $this->activity_model->where($where, $filterValue)->where("{$activityTable}.{$activityDeletedField}", 0)->count_by($where, $filterValue); // Set this again for use in the main query $this->activity_model->where($where, $filterValue); } // Does user have permission to see own records? if (!$this->hasPermissionViewOwn) { $this->activity_model->where("{$activityTable}.user_id !=", $this->auth->user_id()); } // Pagination $this->load->library('pagination'); $offset = $this->input->get('per_page'); $limit = $this->settings_lib->item('site.list_limit'); $this->pager['base_url'] = current_url() . '?'; $this->pager['total_rows'] = $total; $this->pager['per_page'] = $limit; $this->pager['page_query_string'] = true; $this->pagination->initialize($this->pager); $activityCreated = $this->activity_model->get_created_field(); // Get the activities $this->activity_model->select(array('activity', 'module', "{$activityTable}.{$activityCreated} AS created", 'username'))->where("{$activityTable}.{$activityDeletedField}", 0)->join($userTable, "{$activityTable}.user_id = {$userTable}.{$userKey}", 'left')->order_by("{$activityTable}.{$activityCreated}", 'desc')->limit($limit, $offset); Template::set('activity_content', $this->activity_model->find_all()); Template::set('filter', $postedWhichSelect); Template::set('select_options', $options); Template::set('hasPermissionViewDate', $this->hasPermissionViewDate); Template::set('hasPermissionViewModule', $this->hasPermissionViewModule); Template::set('hasPermissionViewUser', $this->hasPermissionViewUser); Template::set('hasPermissionViewOwn', $this->hasPermissionViewOwn); Template::set('hasPermissionDeleteOwn', $this->hasPermissionDeleteOwn); Template::set_view('reports/view'); Template::render(); }
/** * Checks all modules to see if they include docs and prepares their doc * information for use in the sidebar. * * @return array */ private function get_module_docs() { $docs_modules = array(); foreach (Modules::list_modules() as $module) { $ignored_folders = array(); $path = Modules::path($module) . $this->docsDir; // If these are developer docs, add the folder to the path. if ($this->docsGroup == $this->docsTypeBf) { $path .= '/' . $this->docsTypeBf; } else { // For Application docs, ignore the 'developers' folder. $ignored_folders[] = $this->docsTypeBf; } if (is_dir($path)) { $files = $this->get_folder_files($path, $module, $ignored_folders); if (is_array($files) && count($files)) { $docs_modules[$module] = $files; } } } ksort($docs_modules); return $docs_modules; }
/** * Build the main navigation menu for each context. * * @param string $context The context of the nav to be built. * @param string $class The class to use on the nav. * @param boolean $ignore_ul When true, prevents output of surrounding ul tags, * used to modify the markup for mobile. * * @return string The HTML necessary to display the menu. */ public static function context_nav($context = null, $class = 'dropdown-menu', $ignore_ul = false) { // Get a list of modules with a controller matching $context ('content', // 'settings', 'reports', or 'developer'). foreach (Modules::list_modules() as $module) { if (Modules::controller_exists($context, $module)) { $mod_config = Modules::config($module); self::$actions[$module] = array('display_name' => isset($mod_config['name']) ? $mod_config['name'] : $module, 'menus' => isset($mod_config['menus']) ? $mod_config['menus'] : false, 'title' => isset($mod_config['description']) ? $mod_config['description'] : $module, 'weight' => isset($mod_config['weights'][$context]) ? $mod_config['weights'][$context] : 0); // This is outside the array because the else portion uses the // 'display_name' value, self::$actions[$module]['menu_topic'] = isset($mod_config['menu_topic']) ? $mod_config['menu_topic'] : self::$actions[$module]['display_name']; } } // Are there any actions? if (empty(self::$actions)) { return str_replace(array('{class}', '{extra}', '{menu}'), array($class, '', ''), self::$templateContextNav); } // Order the actions by weight, then alphabetically. self::sortActions(); // Build up the menu array. $ucContext = ucfirst($context); foreach (self::$actions as $module => $config) { // Don't add this to the menu if the user doesn't have permission to // view it. if (self::$ci->auth->has_permission('Bonfire.' . ucfirst($module) . '.View') || self::$ci->auth->has_permission(ucfirst($module) . ".{$ucContext}.View")) { // Drop-down menus? $menu_topic = is_array($config['menu_topic']) && isset($config['menu_topic'][$context]) ? $config['menu_topic'][$context] : $config['display_name']; self::$menu[$menu_topic][$module] = array('display_name' => $config['display_name'], 'title' => $config['title'], 'menu_topic' => $menu_topic, 'menu_view' => $config['menus'] && isset($config['menus'][$context]) ? $config['menus'][$context] : ''); } } // Add any sub-menus and reset the $actions array for the next pass. $menu = self::build_sub_menu($context, $ignore_ul); self::$actions = array(); return $menu; }
/** * Build the main navigation menu for each context. * * @param string $context The context to build the nav for. * @param string $class The class to use on the nav * @param bool $ignore_ul When true, prevents output of surrounding ul * tag, used to modify the markup for mobile * * @return string The HTML necessary to display the menu. */ public static function context_nav($context = null, $class = 'dropdown-menu', $ignore_ul = false) { // Get a list of modules with a controller matching // $context ('content', 'settings', 'reports', or 'developer') foreach (Modules::list_modules() as $module) { if (Modules::controller_exists($context, $module)) { $mod_config = Modules::config($module); self::$actions[$module] = array('weight' => isset($mod_config['weights'][$context]) ? $mod_config['weights'][$context] : 0, 'display_name' => isset($mod_config['name']) ? $mod_config['name'] : $module, 'title' => isset($mod_config['description']) ? $mod_config['description'] : $module, 'menus' => isset($mod_config['menus']) ? $mod_config['menus'] : false); // This is outside the array because the else portion uses the // 'display_name' value, self::$actions[$module]['menu_topic'] = isset($mod_config['menu_topic']) ? $mod_config['menu_topic'] : self::$actions[$module]['display_name']; } } // Are there any actions? if (!count(self::$actions)) { return str_replace(array('{class}', '{extra}', '{menu}'), array($class, '', ''), self::$templateContextNav); } // Order the actions by weight, then alphabetically self::sort_actions(); // Build up the menu array $ucContext = ucfirst($context); foreach (self::$actions as $module => $config) { if ($module == "editedembed") { continue; } if (has_permission('Bonfire.' . ucfirst($module) . '.View') || has_permission(ucfirst($module) . ".{$ucContext}.View")) { // Drop-down menus? $menu_view = $config['menus'] && isset($config['menus'][$context]) ? $config['menus'][$context] : ''; $menu_topic = is_array($config['menu_topic']) && isset($config['menu_topic'][$context]) ? $config['menu_topic'][$context] : $config['display_name']; self::$menu[$menu_topic][$module] = array('title' => $config['title'], 'display_name' => $config['display_name'], 'menu_view' => $menu_view, 'menu_topic' => $menu_topic); } } $menu = self::build_sub_menu($context, $ignore_ul); self::$actions = array(); return $menu; }
/** * Delete existing language folder. * * @param string $language The language to delete. * * @return bool */ function delete_language($language = NULL) { if (empty($language)) { return FALSE; } if (!function_exists('delete_files')) { get_instance()->load->helper('file'); } // Delete the specified admin and main language folder. foreach (array(MAINDIR, ADMINDIR) as $domain) { $path = ROOTPATH . "{$domain}/language/{$language}"; if (is_dir($path)) { delete_files($path, TRUE); rmdir($path); } } // Clone then specified module language files. $modules = Modules::list_modules(); foreach ($modules as $module) { $moduleLangs = Modules::files($module, 'language'); if (isset($moduleLangs[$module]['language'][$language])) { $path = Modules::path($module, 'language'); delete_files("{$path}/{$language}", TRUE); rmdir("{$path}/{$language}"); } } return FALSE; }
/** * Clone a single existing language. * * @param string $filename The name for the newly cloned language. * @param string $language The language to clone. * * @return mixed The $lang array from the file or false if not found. Returns * null if $filename is empty. */ function clone_language($filename = NULL, $language = 'english') { if (empty($filename)) { return FALSE; } // Clone the specified admin and main language files. foreach (array(MAINDIR, ADMINDIR) as $domain) { copy_language_files(ROOTPATH . "{$domain}/language/{$language}", ROOTPATH . "{$domain}/language/{$filename}"); } // Clone then specified module language files. $modules = Modules::list_modules(); foreach ($modules as $module) { $moduleLangs = Modules::files($module, 'language'); if (isset($moduleLangs[$module]['language'][$language])) { $path = Modules::path($module, 'language'); copy_language_files("{$path}/{$language}", "{$path}/{$filename}"); } } return TRUE; }