public function save_image($page_id, $image) { $dir = DOCROOT . 'public' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'page_preview' . DIRECTORY_SEPARATOR; create_dir($dir); $file = $dir . $page_id . '.jpg'; $this->base64_to_jpeg($image, $file); }
public function upload_image($dir = 'images') { $options = array('upload_dir' => FCPATH . config_item('site_attachments_dir') . $dir . '/', 'upload_url' => '/' . config_item('site_attachments_dir') . $dir . '/', 'script_url' => '/admin/upload/index/upload_image/' . $dir); $this->load->library('UploadHandler', $options); create_dir($this->uploadhandler->get_option('upload_dir')); $this->uploadhandler->initialize(); }
/** * 拷贝目录及下面所有文件 * * @param string $from 原路径 * @param string $to 目标路径 * * @return bool true拷贝成功,否则false */ function copy_dir($from, $to) { $from = dir_path($from); $to = dir_path($to); if (!is_dir($from)) { return false; } if ($from == $to) { return true; } !is_dir($to) && create_dir($to); $list = glob($from . '*'); if (!empty($list)) { foreach ($list as $v) { $path = $to . basename($v); if (is_dir($v)) { copy_dir($v, $path); } else { copy($v, $path); chmod($path, 0755); } } } return true; }
public function __construct() { parent::__construct(); $this->_curruid = (int) $this->auth->user('uid'); $this->_attach_dir = config_item('site_attach_dir') . DIRECTORY_SEPARATOR; if (@is_dir($this->_attach_dir) === FALSE) { create_dir($this->_attach_dir); } }
function create_dirs($dirs) { $rtn = 1; foreach ($dirs as $dir) { if (!create_dir($dir)) { $rtn = 0; } } return $rtn; }
function install() { global $_plugin; global $success; global $error; global $errors; !plugin_is_installed($_plugin['name']) or $error = $errors['installed']; create_dir($_plugin['dir']['definitions']) or $error = $errors['create_dir']; copy_example('example', $_plugin['dir']['definitions']) or $error = $errors['example']; set_as_installed() or $error = $errors['installing']; $success = $_plugin['name'] . ' was successfully installed'; }
/** * Functions Plugin * * this plugin bla bla bla * * @author Joshua Morse <*****@*****.**> */ function install() { global $_plugin; global $success; global $error; global $errors; !plugin_is_installed($_plugin['name']) or $error = $errors['installed']; create_dir($_plugin['dir']['user']) or $error = $errors['create_dir']; create_dir($_plugin['dir']['base']) or $error = $errors['create_dir']; set_as_installed() or $error = $errors['installing']; $success = $_plugin['name'] . ' was successfully installed'; }
function create_dirs_recursively($dirs) { $dirs = str_replace('\\', '', $dirs); $dirs_array = explode('/', $dirs); $dir = $dirs_array[0]; unset($dirs_array[0]); create_dir($dir); foreach ($dirs_array as $d) { $dir .= '/' . $d; create_dir($dir); } }
function register_uploaded_file($file, $to_folder, $creator_id, $type, $access_policy = 'public') { $md5_hash = md5_file($file['tmp_name']); if ($md5_hash === false) { return false; } create_dir(DATA_PATH . $to_folder); $newName = getAvailableName(DATA_PATH . $to_folder, $file['name']); if (move_uploaded_file($file['tmp_name'], DATA_PATH . $to_folder . $newName) === false) { return false; } $file_record = array('creator' => $creator_id, 'creation_date' => now(), 'filepath' => $to_folder . $newName, 'filesize' => filesize(DATA_PATH . $to_folder . $newName), 'filename_original' => $file['name'], 'extension' => pathinfo($file['name'], PATHINFO_EXTENSION), 'mime_type' => $file['type'], 'md5_hash' => $md5_hash, 'type' => $type, 'access_policy' => $access_policy); $file_id = $this->insert($file_record); return $file_id; }
/** * 创建html生成文件 * @param string $html * @param string $content * @return boolean */ function create_html($html, $content) { //分析dir $dirname = dirname($html); $path = str_replace('\\', '/', FCPATH) . 'html/'; if (!create_dir('html/' . $dirname)) { return false; } $fp = fopen($path . $html, 'w'); if (!$fp) { return false; } fwrite($fp, $content); fclose($fp); return true; }
public function action_upload_files() { $files = array(); if (isset($_FILES)) { foreach ($_FILES as $name => $file) { if (Upload::not_empty($file)) { $filename = uniqid() . '_' . $file['name']; $filename = preg_replace('/\\s+/u', '_', $filename); $dir = 'public' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'page_media'; create_dir($dir); Upload::save($file, $filename, DOCROOT . $dir); $files[] = array('url' => URL::site($dir . '/' . $filename), 'file' => $file, 'dir' => $dir, 'filename' => $filename); } } } $this->response->json(array('files' => $files)); }
/** * 生成语言包js * * @author mrmsl <*****@*****.**> * @date 2012-07-04 08:35:38 * @lastmodify 2013-01-27 14:14:23 by mrmsl * * @return void 无返回值 */ public function createAction() { require CORE_PATH . 'functions/dir.php'; create_dir(WEB_JS_LANG_PATH); $loop_arr = array('admin' => LANG_PATH, str_replace('modules/admin/', 'modules/' . FRONT_MODULE_NAME . '/', LANG_PATH)); foreach ($loop_arr as $key => $item) { $lang_arr = scand_dir($item); //语言包 foreach ($lang_arr as $k => $v) { $lang = is_file($filename = SYS_LANG_PATH . $k . '.php') ? include $filename : array(); foreach ($v as $file) { $lang = array_merge($lang, array_change_key_case(include $file, CASE_UPPER)); } array2js($lang, 'L', WEB_JS_LANG_PATH . (is_string($key) ? $key . '.' : '') . $k . '.js'); } } }
/** * 检查目录可读、可写权限 * @param array $directories * @return array */ private function getDirctoriesState(array $directories) { $dirStates = array(); foreach ($directories as $key => $dir) { $fullDirPath = WEB_ROOT . $dir; create_dir($fullDirPath); $dirStates[$key]['dir_name'] = $dir; // 测试可写 if (is_writable($fullDirPath)) { $dirStates[$key]['writable'] = current_state_support('可写'); } else { $dirStates[$key]['writable'] = current_state_unsupport('不可写'); } // 测试可读 if (is_readable($fullDirPath)) { $dirStates[$key]['readable'] = current_state_support('可读'); } else { $dirStates[$key]['readable'] = current_state_unsupport('不可读'); } } return $dirStates; }
echo '<font color="blue">正在进行代码预处理CODE_ADV2..</font><br>'; include GAME_ROOT . './include/modulemng.codeadv2.func.php'; for ($i = 1; $i <= $n; $i++) { /* if (strtoupper($modn[$i])=='INPUT') { echo '跳过模块input。<br>'; continue; } */ echo '开始处理模块' . $modn[$i] . '...<br>'; ob_end_flush(); flush(); $srcdir = GAME_ROOT . './include/modules/' . $modp[$i]; $tpldir = GAME_ROOT . './gamedata/run/' . $modp[$i]; create_dir($tpldir); clear_dir($tpldir); copy_dir($srcdir, $tpldir); foreach ($codelist[$i] as $key) { echo ' 正在处理代码' . $key . '.. '; ob_end_flush(); flush(); $src = GAME_ROOT . './include/modules/' . $modp[$i] . $key; $objfile = GAME_ROOT . './gamedata/run/' . $modp[$i] . $key; $objfile = substr($objfile, 0, -4) . '.adv' . substr($objfile, strlen($objfile) - 4); $delfile = GAME_ROOT . './gamedata/run/' . $modp[$i] . $key; preparse($modn[$i], $i, $src); parse($modn[$i], $src, $objfile); unlink($delfile); echo '完成。<br>'; ob_end_flush();
public static function form($appid, $list) { global $_G; $sql = "SELECT * FROM `mod:form_form` WHERE appid='" . $appid . "' "; //读取表单信息 $list && ($sql .= " and id in(" . $list . ")"); //创建子文件夹 $folder = create_dir(self::direct($appid)); $result = System::$db->getAll($sql); foreach ($result as $form) { $file = $folder . "/form." . $form['id'] . ".php"; $part = array('form' => array(), 'group' => array(), 'option' => array()); //表单主体 foreach ($form as $key => $val) { if ($key == 'config') { $form[$key] = fix_json($val); } } $part['form'] = $form; //////////////// //选项组 $sql = "SELECT * FROM `mod:form_group` WHERE fid=" . $form['id'] . " and `state`>0 order BY sort ASC,id ASC"; $res = System::$db->getAll($sql, 'id'); foreach ($res as $gid => $group) { foreach ($group as $key => $val) { if ($key == 'config') { $group[$key] = fix_json($val); } if ($key == 'selected') { $group[$key] = explode(',', $val); } } $part['group'][$gid] = $group; } //////////////// //子选项 $sql = "SELECT * FROM `mod:form_option` WHERE fid=" . $form['id'] . " and `state`>0 order BY sort ASC,id ASC"; $res = System::$db->getAll($sql, 'id'); foreach ($res as $oid => $option) { foreach ($option as $key => $val) { if ($key == 'config') { $option[$key] = fix_json($val); } } $part['option'][$option['gid']][$oid] = $option; } //////////////// //写入缓存 create_file($file, '<?php /*' . date("Y-m-d H:i:s") . '*/ $_CACHE[\'' . $appid . '\'] = ' . var_export($part, true) . ';'); } }
public static function moved_file($tmpdir, $newdir, $pack) { //return rename( $tmpdir, $newdir ); $list = rglob($tmpdir . '*', GLOB_BRACE); //var_dump( $list ); //exit; //批量迁移文件 foreach ($list as $file) { $newd = str_replace($tmpdir, $newdir, $file); //var_dump( $file ); //var_dump( $newd ); //echo '<hr />'; if (file_exists($file) && is_writable($file) == FALSE) { //记录在案 self::$lastfile = str_replace($tmpdir, '', $file); return -10007; } //////////////////////////// if (file_exists($newd) && is_writable($newd) == FALSE) { //记录在案 self::$lastfile = str_replace($newdir, '', $newd); return -10007; } //////////////////////////// //创建文件夹 if (is_dir($file)) { create_dir($newd, TRUE, 0777); } else { //删除旧文件(winodws 环境需要) if (file_exists($newd)) { unlink($newd); } //生成新文件 $test = @rename($file, $newd); //记录在案 self::$lastfile = str_replace($tmpdir, '', $file); } //////////////////////////// //移动文件出错 if ($test === FALSE) { return -10005; } } //删除临时目录 delete_dir($tmpdir); //删除文件包 unlink(self::get_pack_file($pack)); return count($list); }
function create_basedir($file) { $dir = dirname($file); return create_dir($dir); }
public function getOnlineOperatorsFromFiles($operatorIdToSkip = null, $departmentkey = null, $locale = null) { $dir_name = OPERATOR_ONLINE_FILES_DIR; create_dir($dir_name); $dh = opendir($dir_name); $time = time(); $result = array(); if (!$dh) { return $result; } while (($file = readdir($dh)) !== false) { if (!empty($locale) && $file != $locale || $file == '.' || $file == '..' || !is_dir($dir_name . DIRECTORY_SEPARATOR . $file)) { continue; } $ldir_name = $dir_name . DIRECTORY_SEPARATOR . $file; $ldh = opendir($ldir_name); if (!$ldh) { continue; } while (($lfile = readdir($ldh)) !== false) { if (!empty($departmentkey) && $lfile != $departmentkey || $lfile == '.' || $lfile == '..') { continue; } if (!is_dir($ldir_name . DIRECTORY_SEPARATOR . $lfile)) { $id = $this->processOnlineFile($time, $operatorIdToSkip, $ldir_name, $lfile); if ($id !== false) { $result[] = $id; } } elseif ($departmentkey !== false) { $ddir_name = $ldir_name . DIRECTORY_SEPARATOR . $lfile; $ddh = opendir($ddir_name); if (!$ddh) { continue; } while (($dfile = readdir($ddh)) !== false) { $id = $this->processOnlineFile($time, $operatorIdToSkip, $ddir_name, $dfile); if ($id !== false) { $result[] = $id; } } closedir($ddh); } } closedir($ldh); } closedir($dh); return array_unique($result); }
$iteration = array(PHPT_ACL_READ => false, PHPT_ACL_NONE => false, PHPT_ACL_WRITE => true, PHPT_ACL_WRITE | PHPT_ACL_READ => true); echo "Testing file:\n"; $i = 1; $path = __DIR__ . '/a.txt'; foreach ($iteration as $perms => $exp) { create_file($path, $perms); clearstatcache(true, $path); echo 'Iteration #' . $i++ . ': '; if (is_writable($path) == $exp) { echo "passed.\n"; } else { var_dump(is_writable($path), $exp); echo "failed.\n"; } delete_file($path); } echo "Testing directory:\n"; $path = __DIR__ . '/adir'; $i = 1; foreach ($iteration as $perms => $exp) { create_dir($path, $perms); clearstatcache(true, $path); echo 'Iteration #' . $i++ . ': '; if (is_writable($path) == $exp) { echo "passed.\n"; } else { var_dump(is_writable($path), $exp); echo "failed.\n"; } delete_dir($path); }
protected function save() { $this->model->values($this->request->post()); // clean null values foreach ($this->model->table_columns() as $field => $values) { $is_boolean = Arr::get($values, 'data_type') === 'tinyint' and Arr::get($values, 'display') == 1; $is_nullable = Arr::get($values, 'is_nullable'); $has_value = (bool) $this->model->{$field} and $this->model->{$field} !== NULL; if ($is_nullable and !$is_boolean and !$has_value) { $this->model->{$field} = NULL; } } try { if (isset($_FILES)) { foreach ($_FILES as $name => $file) { if (Upload::not_empty($file)) { $filename = uniqid() . '_' . $file['name']; $filename = preg_replace('/\\s+/u', '_', $filename); $dir = DOCROOT . 'public' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . strtolower($this->model_name); create_dir($dir); Upload::save($file, $filename, $dir); $this->model->{$name} = $filename; } } } if ($this->parent_id) { $this->model->{$this->parent . '_id'} = $this->parent_id; } $this->has_many = Arr::merge($this->has_many, $this->model->has_many()); $this->save_before(); $this->model->save(); $this->save_after(); // ignore external relations $has_many_through = array_filter($this->has_many, function ($item) { return strpos(Arr::get($item, 'through'), $this->model->table_name() . '_') === 0; }); // add has many foreach ($has_many_through as $name => $values) { $ids = $this->request->post($name); $this->model->remove($name); if (!$ids) { continue; } $this->model->add($name, $ids); } $this->flush(); if ($this->request->is_ajax()) { $this->response->json($this->model->all_as_array()); return; } Session::instance()->set('success', 'Registro salvo com sucesso!'); if ($this->redirect === NULL) { HTTP::redirect($this->url()); } else { HTTP::redirect($this->redirect); } } catch (ORM_Validation_Exception $e) { $errors = $e->errors('models'); if (!$errors) { $errors = array($e->getMessage()); } View::set_global('errors', $errors); if ($this->request->is_ajax()) { $this->response->json(array('errors' => $errors)); } } }
function icopy($path, $dir) { if (!file_exists($path)) { return false; } $tmpPath = parse_path($path); if (!is_dir($path)) { create_dir($dir); if (!copy($path, $dir . '/' . $tmpPath['filename'])) { return false; } } else { create_dir($dir); foreach ((array) list_dir($path) as $lineArray) { if ($lineArray['type'] == 'dir') { icopy($lineArray['path'], $dir . '/' . $lineArray['filename']); } else { icopy($lineArray['path'], $dir); } } } return true; }
/** * generate a thumbnail * @param str $sub_path upload path * @param str $file filename * @param str $out_file outfile name, can be null if show is true * @param int $w desired width * @param int $h desired max height, optional, will limit height and adjust width accordingly * @param int $quality quality of image jpg and png * @param bool $show output to browser if true * @param str $output_format optional output format, if not determining from out_file can be excusivly set (1|'GIF', 2|'JPG,'' 3|'PNG') * @param boolean $upscale true, allows image to scale up/zoom to fit thumbnail * @return bool success */ function generate_thumbnail($file, $sub_path = '', $out_file = null, $w = null, $h = null, $crop = null, $quality = null, $show = false, $output_format = null, $upscale = false) { //gd check, do nothing if no gd $php_modules = get_loaded_extensions(); if (!in_arrayi('gd', $php_modules)) { return false; } $sub_path = tsl($sub_path); $upload_folder = GSDATAUPLOADPATH . $sub_path; $thumb_folder = GSTHUMBNAILPATH . $sub_path; $thumb_file = isset($out_file) && !empty($out_file) ? $thumb_folder . $out_file : ''; create_dir($thumb_folder); require_once 'imagemanipulation.php'; $objImage = new ImageManipulation($upload_folder . $file); if ($objImage->imageok) { if ($upscale) { $objImage->setUpscale(); } // allow magnification if ($quality) { $objImage->setQuality($quality); } // set quality for jpg or png if (isset($output_format)) { $objImage->setOutputFormat($output_format); } // setoutput format, ignored if out_file specifies extension if (isset($w) && isset($h)) { $objImage->setImageWidth($w, $h); } elseif (isset($w)) { $objImage->setImageWidth($w); // if only specifiying width, scale to width only // $objImage->resize($w); // constrains both dimensions to $size, same as setImageWidth($w,$w); } elseif (isset($h)) { $objImage->setImageHeight($h); // if only specifiying width, scale to width only } if (isset($crop)) { $objImage->setAutoCrop($crop); } // die(print_r($objImage)); $objImage->save($thumb_file, $show); return $objImage; } else { return false; } }
private function get_upload_config($ID) { $dir = BASE_PATH . 'users/' . $this->id_users . '/media/module_' . $this->segment . '/m_catalogue_album/' . $ID; if (!is_dir($dir)) { $this->load->helper('agfiles_helper'); create_dir($dir, 2); } $config['upload_path'] = $dir . '/'; $config['allowed_types'] = 'jpg|jpeg'; $config['max_size'] = '4092'; $config['encrypt_name'] = TRUE; return $config; }
function excel_file($file_name, $file_type = "xls") { $date_path = create_dir() . "/"; $filename = iconv("utf-8", "gb2312", $file_name); $filename = $filename . date("YmdHis") . "." . $file_type; $file_path = $date_path . $filename; $file_arr = array($filename, $date_path, $file_path); return $file_arr; }
function create_dirs($base, $dirs) { foreach ($dirs as $dir) { create_dir("{$base}/{$dir}"); } }
//模块安装 case 'install': //通信已关闭 if ($connect == 'off') { exit(serialize(array('return' => 'connect', 'connect' => $connect))); } //缺少必要参数 if (!$command['appid'] || !$command['package']) { exit(serialize(array('return' => 'argument', 'appid' => $command['appid'], 'package' => $command['package']))); } //模块已存在 if (Module::exists($command['appid'])) { exit(serialize(array('return' => 'exist', 'appid' => $command['appid']))); } //创建模块目录 $dir = create_dir($module, TRUE, 0777); if ($dir === FALSE) { exit(serialize(array('return' => 'permission', 'catalog' => array('./module/')))); } //测试读写权限 $status = Cloud::valid_perm($module); if (count($status)) { exit(serialize(array('return' => 'permission', 'catalog' => $status))); } //安装模块 $status = Cloud::install_module($command['package'], $command['hash'], $command['appid'], $command['option']['install']['ignore']); //安装成功 if ($status > 0) { //执行安装脚本 Module::install($command['appid']); //更新模块缓存
// tmp-404.xml used as temporary write tester // removed afterwards foreach ($dirsArray as $dir) { $tmpfile = GSADMININCPATH . 'tmp/tmp-404.xml'; if (file_exists($dir)) { gs_chmod($dir, 0755); $result_755 = copy_file($tmpfile, $dir . 'tmp.tmp'); if (!$result_755) { gs_chmod($dir, 0777); $result_777 = copy_file($tmpfile, $dir . 'tmp.tmp'); if (!$result_777) { $kill = i18n_r('CHMOD_ERROR'); } } } else { create_dir($dir, 0755); $result_755 = copy_file($tmpfile, $dir . 'tmp.tmp'); if (!$result_755) { gs_chmod($dir, 0777); $result_777 = copy_file($tmpfile, $dir . 'tmp.tmp'); if (!$result_777) { $kill = i18n_r('CHMOD_ERROR'); } } } if (file_exists($dir . 'tmp.tmp')) { delete_file($dir . 'tmp.tmp'); } } // get available language files $filenames = getFiles(GSLANGPATH);
public function files() { if (isset($_FILES)) { foreach ($_FILES as $name => $file) { if (Upload::not_empty($file)) { $filename = uniqid() . '_' . $file['name']; $filename = preg_replace('/\\s+/u', '_', $filename); $dir = DOCROOT . 'public' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . strtolower($this->model_name); create_dir($dir); Upload::save($file, $filename, $dir); $this->model->{$name} = $filename; } } } }
// check for invalid chars $cleanname = clean_url(to7bit(strippath($newfolder), "UTF-8")); $cleanname = basename($cleanname); if (file_exists($path . $cleanname) || $cleanname == '') { $error = i18n_r('ERROR_FOLDER_EXISTS'); } else { if (getDef('GSCHMOD')) { $chmod_value = GSCHMOD; } else { $chmod_value = 0755; } if (create_dir($path . $cleanname, $chmod_value)) { //create folder for thumbnails $thumbFolder = GSTHUMBNAILPATH . $subFolder . $cleanname; if (!file_exists($thumbFolder)) { create_dir($thumbFolder, $chmod_value); } $success = sprintf(i18n_r('FOLDER_CREATED'), $cleanname); } else { $error = i18n_r('ERROR_CREATING_FOLDER'); } } } $pagetitle = i18n_r('FILE_MANAGEMENT'); get_template('header'); // check if host uses Linux (used for displaying permissions $isUnixHost = !hostIsWindows(); function getUploadIcon($type) { if ($type == '.') { $class = 'folder';
public static function generate_model($model, $force = FALSE) { $class_name = 'Model_' . $model; $file = str_replace('_', DIRECTORY_SEPARATOR, $model); $base_dir = 'Base'; $model_dir = APPPATH . 'classes' . DIRECTORY_SEPARATOR . 'Model' . DIRECTORY_SEPARATOR; $model_base = $model_dir . $base_dir . DIRECTORY_SEPARATOR; $file_name = Kohana::find_file('classes/model', $file); $file_base_name = Kohana::find_file('classes/model/base', $file); $table_name = strtolower(Inflector::plural($model)); $table_id = strtolower($model) . '_id'; $rules = array(); $labels = array(); $has_many = array(); $belongs_to = array(); $columns = Database::instance()->list_columns($table_name); foreach ($columns as $field) { $name = Arr::get($field, 'column_name'); $key = Arr::get($field, 'key'); $type = Arr::get($field, 'type'); $low_name = str_replace('_id', '', $name); $maximum_length = Arr::get($field, 'character_maximum_length', Arr::get($field, 'display')); $title = ucfirst($name); // ignore id and _at$ if ($name === 'id' or preg_match('@_at$@', $name)) { continue; } $field_rules = array(); // unique if ($key === 'UNI') { $field_rules[] = "array(array(\$this, 'unique'), array(':field', ':value')),"; } // unique if ($type === 'int') { $field_rules[] = "array('numeric'),"; } // not null if (Arr::get($field, 'is_nullable') === FALSE) { $field_rules[] = "array('not_empty'),"; } // max length if ($maximum_length) { $field_rules[] = "array('max_length', array(':value', {$maximum_length})),"; } // cpf if ($name === 'cpf') { $field_rules[] = "array('cpf', array(':value')),"; } // email if (preg_match('@email@', $name)) { $field_rules[] = "array('email', array(':value')),"; } // rules if (!empty($field_rules)) { $rules[$name] = $field_rules; } // labels if (!preg_match('@_id$@', $name)) { $labels[$name] = $title; } // belongs to if (preg_match('@_id$@', $name)) { $model_name = ORM::get_model_name($low_name); $belongs_to[$low_name] = "array(" . "'model' => '" . $model_name . "'" . "),"; $labels[$low_name] = ucfirst($low_name); } } foreach (Database::instance()->list_tables() as $name) { $_columns = array_keys(Database::instance()->list_columns($name)); // has many through if (preg_match('/(^' . $table_name . '_(.*)|(.*)_' . $table_name . '$)/', $name, $matchs)) { $related = $matchs[count($matchs) - 1]; $has_many[$related] = "array(" . "'model' => '" . ORM::get_model_name($related) . "', " . "'through' => '" . $name . "'" . "),"; $labels[$related] = ucfirst($related); } // has many if (in_array('id', $_columns) and in_array($table_id, $_columns)) { $related = Inflector::singular($name); $field_name = Inflector::singular($table_name); $model_name = ORM::get_model_name($related); $has_many[str_replace($field_name . '_', '', $name)] = "array(" . "'model' => '" . $model_name . "'" . "),"; } } $class_extends = 'Model_App'; $columns = self::format_columns($columns); $full_class_name = 'Model_' . $base_dir . '_' . $model; $view = View::factory('huia/orm/base'); $view->set('class_name', $full_class_name); $view->set('class_extends', $class_extends); $view->set('table_name', $class_name); $view->set('rules', $rules); $view->set('labels', $labels); $view->set('has_many', $has_many); $view->set('belongs_to', $belongs_to); $view->set('columns', $columns); $render_view = $view->render(); $hash_current = $file_base_name ? preg_replace("/[^A-Za-z0-9]/", "", @file_get_contents($file_base_name)) : NULL; $hash_new = preg_replace("/[^A-Za-z0-9]/", "", $render_view); if ($hash_current !== $hash_new) { $file_base_name = $model_base . $file . EXT; create_dir(dirname($file_base_name)); file_put_contents($file_base_name, $view->render()); } // Create if dont exists if (!$file_name) { $view = View::factory('huia/orm'); $view->set('class_name', $class_name); $view->set('class_extends', 'Model_' . $base_dir . '_' . $model); $file_name = $model_dir . $file . EXT; create_dir(dirname($file_name)); file_put_contents($file_name, $view->render()); } }