path() public static method

Return the path to the module and its specified folder.
public static path ( $module = null, $folder = null ) : string
$module string The name of the module (must match the folder name).
$folder string The folder name to search for (Optional).
return string The path, relative to the front controller.
コード例 #1
0
 /**
  * Returns the path to the module and it's specified folder.
  *
  * @deprecated since 0.7.1 Use Modules::path() instead.
  *
  * @param $module string The name of the module (must match the folder name)
  * @param $folder string The folder name to search for. (Optional)
  *
  * @return string The path, relative to the front controller.
  */
 function module_path($module = null, $folder = null)
 {
     return Modules::path($module, $folder);
 }
コード例 #2
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
  * @param bool   $allowNewValues if true, new values can be added to the file
  *
  * @return mixed A string when the $return setting is true
  */
 function save_lang_file($filename = null, $language = 'english', $settings = null, $return = false, $allowNewValues = false)
 {
     if (empty($filename) || !is_array($settings)) {
         return false;
     }
     // Is it a application lang file? Use the English folder to determine.
     $arFiles = scandir(APPPATH . "language/english/");
     if ($filename == 'application_lang.php' || in_array($filename, $arFiles)) {
         $orig_path = APPPATH . "language/english/{$filename}";
         $path = APPPATH . "language/{$language}/{$filename}";
     } else {
         $module = str_replace('_lang.php', '', $filename);
         $orig_path = Modules::file_path($module, 'language', "english/{$filename}");
         $path = Modules::file_path($module, 'language', "{$language}/{$filename}");
         // If it's still empty, grab the module path
         if (empty($path)) {
             $path = Modules::path($module, 'language');
         }
     }
     // Load the file and 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) {
         if ($val !== '') {
             $val = '\'' . addcslashes($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?
             if ($allowNewValues && $val !== '') {
                 $contents .= "\n\$lang['{$name}'] = {$val};";
                 continue;
             } else {
                 return false;
             }
         }
         $end = strpos($contents, "\n", $start) + strlen("\n");
         if ($val !== '') {
             $replace = '$lang[\'' . $name . '\'] = ' . $val . ";\n";
         } else {
             $replace = '// ' . substr($contents, $start, $end - $start);
         }
         $contents = substr($contents, 0, $start) . $replace . substr($contents, $end);
     }
     // Is the produced code 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 defined('BASEPATH') || exit('No direct script access allowed');\n\n{$contents}";
     }
     if ($return) {
         return $contents;
     }
     // Write the changes out...
     if (!function_exists('write_file')) {
         $CI = get_instance();
         $CI->load->helper('file');
     }
     if (write_file($path, $contents)) {
         return true;
     }
     return false;
 }
コード例 #3
0
ファイル: buildablox.php プロジェクト: ci-blox/Ignition-Go
 /**
  * Delete a Blox and all of its files.
  *
  * @return void
  */
 public function delete()
 {
     // If there's no module to delete, redirect
     $module_name = $this->input->post('module');
     if (empty($module_name)) {
         redirect('/buildablox');
     }
     //$this->auth->restrict('Modules.Delete');
     // Remove the module's data and permissions from the database
     if ($this->deleteModuleData($module_name) === false) {
         // Something went wrong while trying to delete the data
         Template::set_message(lang('mb_delete_trans_false'), $this->db->error, 'error');
         redirect('/buildablox');
     }
     // Data deleted successfully, now try to remove the files.
     $this->load->helper('file');
     if (delete_files(Modules::path($module_name), true)) {
         @rmdir(Modules::path("{$module_name}/"));
         log_activity((int) $this->auth->user_id(), lang('mb_act_delete') . ": {$module_name} : " . $this->input->ip_address(), 'buildablox');
         Template::set_message(lang('mb_delete_success'), 'success');
     } else {
         // Database removal succeeded, but the files may still be present
         Template::set_message(lang('mb_delete_success') . lang('mb_delete_success_db_only'), 'info');
     }
     redirect('/buildablox');
 }
コード例 #4
0
ファイル: Docs.php プロジェクト: ivantcholakov/Bonfire
 /**
  * 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;
 }
コード例 #5
0
ファイル: Migrations.php プロジェクト: vamsi683/accept
 /**
  * Get the migrations path for a given migration type.
  *
  * @param string $type The name of the module for module migrations.
  * self::APP_MIGRATION_PREFIX for application migrations.
  * Empty for core migrations.
  *
  * @return string The migrations path for the given migration type.
  */
 protected function getMigrationsPath($type = '')
 {
     switch ($type) {
         // Core migrations
         case '':
         case self::CORE_MIGRATIONS:
             return $this->coreMigrationsPath;
             // Application migrations
         // Application migrations
         case self::APP_MIGRATION_PREFIX:
             return APPPATH . 'db/migrations/';
             // If it is not a core migration or application migration, it should
             // be the name of a module.
         // If it is not a core migration or application migration, it should
         // be the name of a module.
         default:
             return Modules::path(substr($type, 0, -1), 'migrations') . '/';
     }
 }
コード例 #6
0
 /**
  * Migrate to the latest version or drop all migrations
  * for a given module migration
  *
  * @param        $module
  * @param bool $downgrade
  *
  * @return bool
  */
 public function runMigration($module, $downgrade = FALSE)
 {
     $path = Modules::path($module, 'config/');
     if (!is_file($path . 'migration.php')) {
         return FALSE;
     }
     $migration = Modules::load_file('migration', $path, 'config');
     $migration['migration_enabled'] = TRUE;
     $this->CI->load->library('migration', $migration);
     if ($downgrade === TRUE) {
         $this->CI->migration->version('0', $module);
     } else {
         $this->CI->migration->current($module);
     }
 }
コード例 #7
0
 /**
  * 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;
 }
コード例 #8
0
 /**
  * Retrieves the migrations path for a given migration type
  *
  * @param string $type
  *
  * @return string migration path
  */
 public function get_migrations_path($type = '')
 {
     switch ($type) {
         // Core migrations
         case '':
         case 'core':
             return $this->_migration_path;
             // If it is not a core migration, it should be the name of a module.
         // If it is not a core migration, it should be the name of a module.
         default:
             return Modules::path($type, 'migrations/');
     }
 }
コード例 #9
0
 /**
  * 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;
 }