/** * Adds a file into the list to check for last modified date * * @param string $path */ public function addFile($path) { if (is_dir($path)) { $contents = \File::read_dir($path, 0, array('!^\\.', '!^private' => 'dir', '!^compiled' => 'dir', '\\.css$' => 'file', '\\.js$' => 'file', '\\.scss$' => 'file', '!^_')); $this->addFiles($contents, rtrim($path) . '/'); } else { if (file_exists($path)) { $this->files[] = str_replace(PROJECTROOT, '', $path); } } }
public static function get_options() { $options = array(); $stencil_dirs = File::read_dir(STENCILSPATH, 1); foreach ($stencil_dirs as $dir => $null) { if ($data = self::get($dir)) { $options[$dir] = $data['name']; } } return $options; }
/** * Portfolio page * * @access public */ public function action_portfolio() { $portfolio_pieces = array(); $portfolio_dir = File::read_dir(DOCROOT . 'assets/img/portfolio'); foreach ($portfolio_dir as $piece => $imgs) { $data = json_decode(file_get_contents(DOCROOT . 'assets/img/portfolio/' . $piece . 'data.json')); $object = array($data->name => (object) array('img' => $piece, 'url' => $data->url, 'total_imgs' => count($imgs) - 1)); $portfolio_pieces[$data->name] = $object[$data->name]; } $this->template->contact = View::forge('site/contact'); $this->template->content = View::forge('site/portfolio', array('portfolio_pieces' => $portfolio_pieces, 'primary_piece' => 'Texting Base')); }
/** * Get enabled payments * * @access public * @param string $get = Get payments that are: enabled | disabled | all * @param string $load_config = Load payments config * @param bool $allowed * @return array * */ public function action_get_payments($get = 'enabled', $load_config = true, $allowed = true) { if (!\Request::is_hmvc()) { die('Access is denied.'); } $user = \Sentry::user(); $out = array(); $path = APPPATH . "modules" . DS . "payment" . DS . "config" . DS; $config_files = \File::read_dir($path); if (!empty($config_files)) { foreach ($config_files as $file) { $file_parts = pathinfo($file); $payment_config = (include_once $path . $file); // Check allowed if ($allowed && isset($payment_config['allowed']) && is_array($payment_config['allowed'])) { foreach ($payment_config['allowed'] as $key => $value) { if (!isset($user['metadata'][$key]) || !in_array($user['metadata'][$key], $value)) { continue 2; } } } switch ($get) { case 'enabled': if ($payment_config['enabled']) { $out[$payment_config['code']] = $payment_config['name']; if ($load_config) { \Config::load('payment::' . $file_parts['filename'], $file_parts['filename']); } } break; case 'disabled': if (!$payment_config['enabled']) { $out[$payment_config['code']] = $payment_config['name']; if ($load_config) { \Config::load('payment::' . $file_parts['filename'], $file_parts['filename']); } } break; default: case 'all': $out[$payment_config['code']] = $payment_config['name']; if ($load_config) { \Config::load('payment::' . $file_parts['filename'], $file_parts['filename']); } } } } return $out; }
/** * Root * * @access public * @return Response */ public function action_index() { $data = array('dirs' => array()); try { /** * get documentation list */ $dirs = array_keys(File::read_dir(DOCROOT . 'dbdocs' . DS, 1)); foreach ($dirs as $dir) { $i = count($data['dirs']); $data['dirs'][$i]['name'] = rtrim($dir, DS) . '/'; $file_info = File::file_info(DOCROOT . 'dbdocs' . DS . $dir); $data['dirs'][$i]['time_ago'] = Date::time_ago($file_info['time_created']); } } catch (Fuel\Core\InvalidPathException $e) { //do nothing } $this->template->content = View::forge('index/index', array('data' => $data)); }
public function action_update_mca() { $mpath = APPPATH . 'modules'; try { $module = \File::read_dir($mpath, 2); foreach ($module as $k => $v) { if (is_string($k)) { if (preg_match('#[a-zA-Z]+#i', $k, $m)) { $mn = array_shift($m); $mid = \Model\VsvnListMca::field('id', array('where' => array('name' => $mn, 'type' => 'module'))); if (empty($mid)) { $mid = \Model\VsvnListMca::save(array('name' => $mn, 'type' => 'module', 'parent' => 0)); } $path = $mpath . DS . $mn . DS . 'classes' . DS . 'controller'; $files = \File::read_dir($path); foreach ($files as $file) { $cn = substr($file, 0, strpos($file, '.')); $cid = \Model\VsvnListMca::field('id', array('where' => array('name' => $cn, 'type' => 'controller'))); if (empty($cid)) { $cid = \Model\VsvnListMca::save(array('name' => $cn, 'type' => 'controller', 'parent' => $mid)); } $content = fopen($path . DS . $file, 'r'); while (!feof($content)) { $line = fgets($content); if (strpos($line, 'public')) { if (preg_match('/action_(.*)\\(.*\\)\\{/', $line, $matches)) { $aid = \Model\VsvnListMca::field('id', array('where' => array('name' => $matches[1], 'type' => 'action', 'parent' => $cid))); if (empty($aid)) { \Model\VsvnListMca::save(array('name' => $matches[1], 'type' => 'action', 'parent' => $cid)); } } } } fclose($content); } } } } } catch (\FileAccessException $e) { } return \Response::forge(); }
public static function autocomplete() { $path = COREPATH . 'classes/'; static::convert_filelist(\File::read_dir($path), $path); $path = PKGPATH . 'auth/classes/'; static::convert_filelist(\File::read_dir($path), $path); $path = PKGPATH . 'email/classes/'; static::convert_filelist(\File::read_dir($path), $path); $path = PKGPATH . 'parser/classes/'; $filelist = static::convert_filelist(\File::read_dir($path), $path); static::generate_class_definition($filelist); $output = '<?php' . "\n\n" . implode("", static::$class_definitions); $file = APPPATH . '_autocomplete.php'; $ret = file_put_contents($file, $output); if ($ret === false) { echo 'Can\'t write to ' . $file . PHP_EOL; } else { echo $file . ' was created.' . PHP_EOL; } }
/** * Index page * * @access public * @param $slug */ public function action_index($slug = false, $gallery_id = null) { // Get home page $home_page = \Config::get('details.locked_items.home_page'); $gallery_page = \Config::get('details.locked_items.gallery'); $item = false; if ($slug == 'referrals' && strtolower(\Sentry::user()->groups()[0]['name']) != 'club members') { \Messages::error('Only club members can access this page.'); \Response::redirect('/'); } //var_dump($slug);die(); // Find content by slug if ($slug !== false) { $item = \Page\Model_Page::get_by_slug($slug); } elseif ($slug === false) { $item = \Page\Model_Page::find_one_by_id($home_page); } if ($item) { // Home page is always without slug so we redirect if someone tries to access home page with slug if ($item->id == $home_page && $slug !== false) { \Response::redirect(\Uri::base(false)); } } else { // Send to 404 page throw new \HttpNotFoundException(); } $result = \Page\Model_Page::get_content_file($item->id); if ($result) { foreach ($result as $rs) { $item->content_file_pdf = $rs->file; //pdf file $item->content_file_title = $rs->title; //pdf title } } // Default view file $view_file = 'default'; // Fill in home page slug if none is supplied if ($slug === false && $item->id == $home_page) { $slug = $item->seo->slug; // Home page has its standard template $view_file = 'home'; } else { // Search for page specific template $files = \File::read_dir($this->theme_view_path); if (!empty($files)) { foreach ($files as $file) { $path_parts = pathinfo($file); if (strpos($path_parts['filename'], '_') === 0) { $file_id = substr($path_parts['filename'], strripos($path_parts['filename'], '_') + 1); if (is_numeric($file_id) && $item->id == $file_id) { $view_file = $path_parts['filename']; } } } } } $stock_options = \Config::load('stock-option.db'); // TODO delete this srand($item->id); $this->page_theme = \Theme::instance()->set_partial('content', $this->view_dir . $view_file); $this->page_theme->set('item', $item, false); $this->page_theme->set('manage_stock', $stock_options['manage_stock'], false); $this->page_theme->set('hide_out_of_stock', $stock_options['hide_out_of_stock'], false); $this->page_theme->set('allow_buy_out_of_stock', $stock_options['allow_buy_out_of_stock'], false); if ($item->id == $gallery_page) { if ($gallery_id && \Input::is_ajax()) { // This will return gallery images only if it is ajax call $this->returnGalleryImages($gallery_id); } } // Data for home page if ($view_file == 'home') { $featured_products = \Product\Model_Group::find_one_by_id(4); if ($featured_products) { $featured_products = $featured_products->products; } $this->page_theme->set('featured_products', $featured_products, false); $categories = \Product\Model_Category::find(array('where' => array('parent_id' => 0, 'status' => 1), 'order_by' => array('sort' => 'asc'), 'limit' => 8)); $this->page_theme->set('categories', $categories, false); $applications = \Application\Model_Application::find(array('where' => array('parent_id' => 0, 'status' => 1), 'order_by' => array('sort' => 'asc'), 'limit' => 8)); $this->page_theme->set('applications', $applications, false); // $this->page_theme->set('blog', $this->wp_blog(), false); } \View::set_global('title', $item->seo->meta_title ?: $item->title); \View::set_global('meta_description', $item->seo->meta_description ?: ''); \View::set_global('meta_keywords', $item->seo->meta_keywords ?: ''); $robots = array('meta_robots_index' => $item->seo->meta_robots_index == 1 ? 'index' : 'noindex', 'meta_robots_follow' => $item->seo->meta_robots_follow == 1 ? 'follow' : 'nofollow'); \View::set_global('robots', $robots); \View::set_global('canonical', $item->seo->canonical_links); \View::set_global('h1_tag', $item->seo->h1_tag); if ($item->seo->redirect_301) { \Response::redirect($item->seo->redirect_301); } }
/** * Purge all caches * * @param * limit purge to subsection * @return bool */ public function delete_all($section) { // get the cache root path and prep the requested section $path = rtrim(static::$path, '\\/') . DS; $section = $section === null ? '' : static::identifier_to_path($section) . DS; // if the path does not exist, bail out immediately if (!is_dir($path . $section)) { return true; } // get all files in this section $files = \File::read_dir($path . $section, -1, array('\\.cache$' => 'file')); // closure to recusively delete the files $delete = function ($folder, $files) use(&$delete, $path) { $folder = rtrim($folder, '\\/') . DS; foreach ($files as $dir => $file) { if (is_numeric($dir)) { if (!($result = \File::delete($folder . $file))) { return $result; } } else { if (!($result = $delete($folder . $dir, $file))) { return $result; } } } // if we're processing a sub directory if ($folder != $path) { // remove the folder if no more files are left $files = \File::read_dir($folder); empty($files) and rmdir($folder); } return true; }; return $delete($path . $section, $files); }
/** * Purge all caches * * @param limit purge to subsection * @return bool */ public function delete_all($section) { $path = rtrim(static::$path, '\\/') . DS; $section = static::identifier_to_path($section); $files = \File::read_dir($path . $section, -1, array('\\.cache$' => 'file')); $delete = function ($path, $files) use(&$delete) { foreach ($files as $dir => $file) { if (is_numeric($dir)) { if (!($result = \File::delete($path . $file))) { return $result; } } else { if (!($result = ($delete($path . $dir, $file) and rmdir($path . $dir)))) { return $result; } } } return true; }; return $delete($path . $section, $files); }
/** * @access public * @param string directory path * @return array list of full file paths */ public function get_files_in_dir($dir_path, $recursive = false) { # Add traling slash $folder = $this->fix_trailing_slash($dir_path); $types = array(); foreach ($this->accepted_file_types as $key => $value) { $type["\\." . $value . "\$"] = "file"; } $scan = array(); try { # Scan entire directory $scan = \File::read_dir($folder, $recursive == false ? 1 : 0, array_merge(array('!^\\.', '!^_'), $types)); } catch (\Exception $e) { throw new SprocketsFileException($e->getMessage(), 1); } $file_list = \Arr::flatten($this->dir_scan_iterator($scan, $folder)); # Remove duplicates return array_unique($file_list); }
public function read_dir($path, $depth = 0, $filter = null) { $content = \File::read_dir($path, $depth, $filter, $this); return $this->get_handler($path, array(), $content); }
<div id="body"> <h2>Uploadify demo using FuelPHP and SimpleAuth <span id="loader"><?php echo \Asset::img('loading.gif', array('alt' => 'Loading...')); ?> </span></h2> <div id="sidebar"> <!-- form to be replaced by uploadify --> <form id="mainftp" action="<?php echo $url; ?> " method="post" enctype="multipart/form-data"> <p><input type="file" name="userfile" id="file" /></p> <p><input type="submit" name="submit" value="Upload" /></p> </form> </div> <!-- whole div to be refreshed once uploadify is finished --> <div id="allfiles" > <ul> <?php $src_folder = "./uploads"; foreach (File::read_dir($src_folder) as $file) { echo "<li><a href='/uploads/{$file}'>{$file}</a></li>"; } ?> </ul> </div> <div class="clear"></div>
public static function delete_old_file($dir, $expire = '24 hours ago', $prefix = '') { $expire = strtotime($expire); // 取得ファイル分ループ $files = File::read_dir($dir); foreach ($files as $fileName) { $file = $dir . $fileName; if (!is_file($file)) { continue; } // 指定プレフィックス以外はスルー if (!empty($prefix) && !strstr($fileName, $prefix)) { continue; } $mod = filemtime($file); if ($mod < $expire) { File::delete($file); } } }
/** * Add directory files * * @param string|array $folders List directory * @param int $depth How deep the subdirectories are recurred: 0 for unlimited. * @param array|null $filter A filter for which files to read: array() for all or null for all but hidden. * @param string|null $localname Where will be added to the file in the zip * * @throws \InvalidPathException when the file does not exist. * @throws \FileAccessException when the file could not be opened for read. * * @return object Current instance */ public function addDir($folders, $depth = 0, $filter = null, $localname = null) { $files = []; if (is_array($folders)) { foreach ($folders as $folder) { if (is_dir($folder)) { $files[$folder] = \File::read_dir($folder, $depth, $filter); } } } else { if (is_dir($folders)) { $files[$folders] = \File::read_dir($folders, $depth, $filter); } } $this->getPath($files); foreach ($this->_list_files as $file) { $this->addFile($file, str_replace([APPPATH, COREPATH, DOCROOT, PKGPATH, VENDORPATH], '', pathinfo($file, PATHINFO_DIRNAME))); } return $this->_list_files; }
protected static function process_migration($scaffold, $module, $module_path) { /* * Migration files are a special case because the * original and destination file names are not * constant. Depending on the existing migrations * files, we could have to move the * 003_create_category.php migration file from the * application to the 002_create_category.php * migration file in the module. * Moreover, we don't need to do any replacements * here. */ $app_migrations_path = APPPATH . 'migrations'; $module_migrations_path = $module_path . 'migrations'; // Getting the list of migrations files in the // application. $app_migrations = \File::read_dir($app_migrations_path); // If the migration directory doesn't exists in the // module, we create it. if (!file_exists($module_migrations_path)) { mkdir($module_migrations_path, static::$folder_permissions, true); } $migration_filename_end = '_create_' . \Inflector::pluralize($scaffold) . '.php'; $module_migrations = \File::read_dir($module_migrations_path); // Searching if the migration file already exists $module_migration_filename = null; $already_exists = false; foreach ($module_migrations as $module_migration) { if (\Str::ends_with($module_migration, $migration_filename_end)) { $module_migration_filename = $module_migration; $already_exists = true; break; } } // If it doesn't, the migration file name generated if (is_null($module_migration_filename)) { // Finding the destination migration file name. $nb_module_migrations = count($module_migrations); $module_migration_number = str_pad($nb_module_migrations + 1, 3, '0', STR_PAD_LEFT); $module_migration_filename = $module_migration_number . $migration_filename_end; } // Finding the original migration file foreach ($app_migrations as $app_migration) { if (\Str::ends_with($app_migration, $migration_filename_end)) { // Moving it to the destination file. $migration_from = $app_migrations_path . DS . $app_migration; $migration_to = $module_migrations_path . DS . $module_migration_filename; /* * If it already exists, the migration is * not overriden except if the force option * is set. */ if (!$already_exists || static::$force) { \Cli::write("\tCreating migration: " . $migration_to, 'green'); file_put_contents($migration_to, file_get_contents($migration_from)); } \Cli::write("\tDeleting migration: " . $migration_from, 'green'); \File::delete($migration_from); break; } } }
public function action_getimages() { // find all images in said folder, encode as json. $folder = 'uploads/images'; $full_folder = DOCROOT . DS . $folder; if (!is_dir($folder)) { mkdir($folder); } if (is_dir($folder)) { $all_files = \File::read_dir($folder, 0, array('!^\\.', '!' => 'dir', '\\.png$' => 'file', '\\.jpg$' => 'file', '\\.gif$' => 'file', '!^_')); $image_array = array(); foreach ($all_files as $key => $file) { $image_array[] = array('thumb' => '/image/1/90/90/' . $folder . DS . $file, 'image' => DS . $folder . DS . $file); } $json = json_encode($image_array); echo $json; exit; } }
/** * Get enabled payments * * @access public * @param string $get = Get payments that are: enabled | disabled | all * @param string $load_config = Load payments config * @return array * */ public function get_payments($get = 'enabled', $load_config = false) { $out = array(); $path = APPPATH . "modules" . DS . "payment" . DS . "config" . DS; $config_files = \File::read_dir($path); if (!empty($config_files)) { foreach ($config_files as $file) { $file_parts = pathinfo($file); $payment_config = (include_once $path . $file); switch ($get) { case 'enabled': if ($payment_config['enabled']) { $out[$payment_config['code']] = $payment_config['name']; if ($load_config) { \Config::load($file_parts['filename'], true); } } break; case 'disabled': if (!$payment_config['enabled']) { $out[$payment_config['code']] = $payment_config['name']; if ($load_config) { \Config::load($file_parts['filename'], true); } } break; default: case 'all': $out[$payment_config['code']] = $payment_config['name']; if ($load_config) { \Config::load($file_parts['filename'], true); } } } } return $out; }
/** * list modules that has permission * * @return mixed */ public function listModulesWithPermission() { if (is_array($this->module_paths) && !empty($this->module_paths)) { $output = array(); $i = 0; // loop module paths foreach ($this->module_paths as $module_path) { $config['basedir'] = $module_path; $file_area = \File::forge($config); unset($config); $files = \File::read_dir($module_path, 1, array('!^\\.'), $file_area); unset($file_area); foreach ($files as $file => $subs) { // remove back slash trail. $file = mb_substr($file, 0, mb_strlen($file) - 1); if (is_dir($module_path . $file)) { if (file_exists($module_path . $file . DS . 'classes' . DS . $file . 'admin.php') && is_file($module_path . $file . DS . 'classes' . DS . $file . 'admin.php')) { $class_name_with_namespace = '\\' . ucfirst($file) . '\\' . ucfirst($file) . 'Admin'; // load module to check class exists, method exists. \Module::load($file); if (class_exists($class_name_with_namespace)) { if (method_exists($class_name_with_namespace, '_define_permission')) { // get module name. $info = $this->readModuleMetadata($module_path . $file . DS . $file . '_module.php'); if ($info['name'] == null) { $output[$i]['module_name'] = $file; $output[$i]['module_system_name'] = $file; } else { $output[$i]['module_name'] = $info['name']; $output[$i]['module_system_name'] = $file; } $i++; } } } // endif file exists. } // endif is dir } // endforaech; unset($class_name_with_namespace, $file, $files, $subs); } // endforaech; unset($module_path); return $output; } return false; }