public function action_save() { if ($_POST && $_FILES) { $imageChanged = false; $data = (object) $this->sanitize($_POST); $update = false; if ($data->id == "") { $editorial = ORM::factory("editorial"); } else { $editorial = ORM::factory("editorial", $data->id); } if (in_array($_FILES['image']['type'], $this->allowed)) { Upload::$default_directory = Kohana::config('myshot.basePath'); if ($stage_path = Upload::save($_FILES['image'])) { $imageChanged = true; Library_Akamai::factory()->addToDir($stage_path, 'editorials'); } } $editorial->title = $data->title; $editorial->image = $imageChanged ? Kohana::config('myshot.cdn') . 'editorials/' . basename($stage_path) : $editorial->image; $editorial->image_alt = $data->image_alt; $editorial->link = $data->link; $editorial->link_text = $data->link_text; $editorial->text = $data->text; $editorial->save(); Message::set(Message::SUCCESS, $update ? "You have sucessfully updated the editorial." : "You have sucessfully added the editorial."); } Request::instance()->redirect('admin/editorials'); }
public function post_upload() { $file = $this->param('file', array(), TRUE); if (!is_dir(BACKUP_PLUGIN_FOLDER)) { throw HTTP_API_Exception::factory(API::ERROR_UNKNOWN, 'Folder (:folder) not exist!', array(':folder' => BACKUP_PLUGIN_FOLDER)); } if (!is_writable(BACKUP_PLUGIN_FOLDER)) { throw HTTP_API_Exception::factory(API::ERROR_UNKNOWN, 'Folder (:folder) must be writable!', array(':folder' => BACKUP_PLUGIN_FOLDER)); } # Проверяем на расширение if (!Upload::type($file, array('sql', 'zip'))) { throw HTTP_API_Exception::factory(API::ERROR_UNKNOWN, 'Bad format of file!'); } $ext = pathinfo($file['name'], PATHINFO_EXTENSION); # Имя файла $filename = 'uploaded-' . date('YmdHis') . '-' . $file['name']; Upload::$default_directory = BACKUP_PLUGIN_FOLDER; # Cохраняем оригинал и продолжаем работать, если ок: if ($file = Upload::save($file, $filename, NULL, 0777)) { $this->response(__('File :filename successfully uploaded', array(':filename' => $filename))); Kohana::$log->add(Log::ALERT, 'Backup file :filename uploaded by :user', array(':filename' => $filename))->write(); } }
private function editAward($award) { $data = Arr::merge($this->sanitize($_POST), $_FILES); $award->title = $data['name']; $award->desc = $data['description']; if (isset($data['photo']) && $data['photo']['name'] != "") { Upload::$default_directory = Kohana::config('myshot.basePath'); if ($stage_path = Upload::save($data['photo'])) { foreach ($award->_images as $image) { $name = (string) $image->type->name; if ($image->type->name == self::FULL) { $path_info = pathinfo($stage_path); $savedAt = $path_info['dirname'] . '/' . $path_info['filename'] . '.' . $path_info['extension']; Library_Akamai::factory()->addToDir($savedAt, Kohana::config('akamai.honordir')); $image->path = $this->webpath($stage_path); } else { $image->path = $this->webPath($this->resizeHonor($stage_path, ImageTypes::types()->{$name}->size)); } $image->save(); } } } $award->save(); }
*/ Kohana::modules(array('user' => MODPATH . 'user', 'database' => MODPATH . 'database', 'image' => MODPATH . 'image', 'captcha' => MODPATH . 'captcha', 'minion' => MODPATH . 'minion')); /** * Attach the file write to logging. * Multiple writers are supported. */ if (Kohana::$environment !== Kohana::DEVELOPMENT and Kohana::$environment !== Kohana::STAGING) { Kohana::$log->attach(new Log_File(APPPATH . 'logs'), LOG_INFO); } else { Kohana::$log->attach(new Log_File(APPPATH . 'logs')); } /** * Default path for uploads directory. * Path are referenced by a relative or absolute path. */ Upload::$default_directory = APPPATH . 'uploads'; /** * Set the routes * * Each route must have a minimum of a name, * a URI and a set of defaults for the URI. * * Example: * ~~~ * Route::set('frontend/page', 'page(/<action>)') * ->defaults(array( * 'controller' => 'page', * 'action' => 'view', * )); * ~~~ *
/** * Upload new file * @param array $file * @param string $name * @return string */ protected function upload($file, $name = NULL) { if (empty($file['name'])) { return $name; } Upload::$default_directory = 'media/data/' . $this->model->object_plural(); if (!file_exists('media/data/' . $this->model->object_plural())) { mkdir('media/data/' . $this->model->object_plural(), 0777); } return str_replace(DOCROOT . 'media/data/' . $this->model->object_plural() . '/', '', Upload::save($file, $name)); }
private function check_photo() { // Photo validation $data = Arr::merge($_POST, $_FILES); $photo = ORM::factory('photo'); $validate = $photo->validate_create($data); $tag_errors = $this->validate_tags(); // Check both! if ($validate->check() and empty($errors)) { Upload::$default_directory = Kohana::config('myshot.basePath'); if ($stage_path = Upload::save($data['photo'])) { $img = Image::factory($stage_path); $photo->user_id = $this->user->id; $photo->original = basename($stage_path); $photo->file_type = $data['photo']['type']; $photo->name = Arr::get($data, 'name'); $photo->caption = Arr::get($data, 'caption'); $photo->category_id = Arr::get($data, 'category'); $photo->width = $img->width; $photo->height = $img->height; $photo->save(); $large_image = $this->create_large($stage_path, $photo); $croppable = $this->create_medium($large_image, $photo); $crop = new Controller_Canvas_Photos(Request::instance()); $crop->crop_small($croppable); $crop->crop_thumbnail($croppable); $tags = new Controller_Tags(Request::instance()); $tags->add_tags($_POST, $photo); //log the photo upload action $tagstr = ""; foreach ($photo->tags->find_all() as $tag) { $tagstr .= $tag->name . ","; } $gameUser = Helper_Game::getUser($this->user->id); $gameItem = $gameUser->getItem($photo->id); $gameItem->addData('tags', $tagstr); $gameItem->addData('category', $photo->category->name); $gameItem->addData('type', 'image'); Helper_Game::logEvent(Helper_Game::IMG_UPLOAD, $this->user->id, $photo->id, array('photo' => $photo->id, 'tags' => $tagstr, 'category' => $photo->category->name)); Request::instance()->redirect('canvas/photos/' . $photo->id); } } else { Message::set(Message::ERROR, Arr::merge($validate->errors('photo'), $tag_errors)); } }
Kohana::init(array('base_url' => '/', 'index_file' => false)); /** * Attach the file write to logging. Multiple writers are supported. */ Kohana::$log->attach(new Log_File(APPPATH . 'logs')); /** * Attach a file reader to config. Multiple readers are supported. */ Kohana::$config->attach(new Config_File()); /** * Enable modules. Modules are referenced by a relative or absolute path. */ Kohana::modules(array('auth' => MODPATH . 'auth', 'cache' => MODPATH . 'cache', 'database' => MODPATH . 'database', 'image' => MODPATH . 'image', 'orm' => MODPATH . 'orm')); /** * Cookie Salt * @see http://kohanaframework.org/3.3/guide/kohana/cookies * * If you have not defined a cookie salt in your Cookie class then * uncomment the line below and define a preferrably long salt. */ Cookie::$salt = ''; /** * Directory for uploads */ Upload::$default_directory = DOCROOT . 'public' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR; /** * Set the routes. Each route must have a minimum of a name, a URI and a set of * defaults for the URI. */ Route::set('admin', 'admin(<controller>(/<action>(/<id>)))')->defaults(array('controller' => 'admin', 'action' => 'index')); Route::set('default', '(<controller>(/<action>(/<id>)))')->defaults(array('controller' => 'main', 'action' => 'index'));
private function check_avatar() { Upload::$default_directory = Kohana::config('myshot.basePath'); $files = Validate::factory($_FILES); $files->rules('photo', array('Upload::valid' => NULL, 'Upload::type' => array(array('jpg', 'png', 'gif')), 'Upload::size' => array('5M'), 'Upload::not_empty' => NULL)); if ($files->check()) { if ($stage_path = Upload::save($files['photo'])) { $this->remove_avatar(); $avatar = ORM::factory('avatar')->where('user_id', '=', $this->user->id); $avatar->user_id = $this->user->id; $avatar->original = basename($stage_path); $avatar->file_type = $files['photo']['type']; $avatar->save(); $croppable = $this->create_large($stage_path, $avatar); $crop = new Controller_Canvas_Avatar(Request::instance()); $crop->crop_medium($croppable); $crop->crop_thumbnail($croppable); $gameUser = Helper_Game::getUser($this->user->id); $gameItem = $gameUser->getItem($avatar->id); $gameItem->addData('type', 'avatar'); Helper_Game::logEvent(Helper_Game::ADD_AVATAR, $this->user->id, $avatar->id, array('avatar_id' => $avatar->id)); Request::instance()->redirect('canvas/avatar'); } } else { // Validation failed son! Message::set(Message::ERROR, $files->errors('avatar')); } }
public function action_upload() { $this->auto_render = FALSE; $errors = array(); # Проверяем файл if (!isset($_FILES['file'])) { $this->go_back(); } $file = $_FILES['file']; if (!is_dir(BACKUP_PLUGIN_FOLDER)) { $errors[] = __('Folder (:folder) not exist!', array(':folder' => BACKUP_PLUGIN_FOLDER)); } if (!is_writable(BACKUP_PLUGIN_FOLDER)) { $errors[] = __('Folder (:folder) must be writable!', array(':folder' => BACKUP_PLUGIN_FOLDER)); } # Проверяем на пустоту if (!Upload::not_empty($file)) { $errors[] = __('File is not attached!'); } # Проверяем на расширение if (!Upload::type($file, array('sql', 'zip'))) { $errors[] = __('Bad format of file!'); } if (!empty($errors)) { Messages::errors($errors); $this->go_back(); } $ext = pathinfo($file['name'], PATHINFO_EXTENSION); # Имя файла $filename = 'uploaded-' . date('YmdHis') . '-' . $file['name']; Upload::$default_directory = BACKUP_PLUGIN_FOLDER; # Cохраняем оригинал и продолжаем работать, если ок: if ($file = Upload::save($file, $filename, NULL, 0777)) { Messages::success(__('File :filename uploaded successfully', array(':filename' => $filename))); Kohana::$log->add(Log::ALERT, 'Backup file :filename uploaded by :user', array(':filename' => $filename))->write(); $this->go_back(); } }
private function editBadge($badge) { $data = Arr::merge($this->sanitize($_POST), $_FILES); $badge->title = $data['name']; $badge->desc = $data['description']; if (isset($data['startstop'])) { $badge->available = $data['startyear'] . "-" . $data['startmonth'] . "-" . $data['startday']; $badge->expiration = $data['endyear'] . "-" . $data['endmonth'] . "-" . $data['endday']; } else { $badge->data->available = null; $badge->data->expiration = null; } //Delete unused rules foreach ($badge->rules as $rule) { $stillHere = false; for ($i = 0; $i < count($data['rule_id']); ++$i) { if ($data['rule_id'][$i] == $rule->id) { $stillHere = true; break; } } if (!$stillHere) { $rule->delete(); } } //Add new ones and update existing for ($i = 0; $i < count($data['rule_name']); ++$i) { $event = ORM::factory('game_Event', $data['event'][$i]); if ($data['rule_id'][$i] == 0) { $rule = $badge->createRule($data['rule_name'][$i], $event, $data['event_amount'][$i]); } else { $rule = ORM::factory("game_Rule", $data['rule_id'][$i]); $rule->name = $data['rule_name'][$i]; $rule->event_id = $event->id; $rule->amount = $data['event_amount'][$i]; } if ($data['data_key'][$i] != '' && $data['data_key'][$i] != 'key name') { $rule->log_info_name = $data['data_key'][$i]; $rule->operator = $data['data_method'][$i]; $rule->contains_data = $data['data_content'][$i]; } $rule->save(); } if (isset($data['photo']) && $data['photo']['name'] != "") { Upload::$default_directory = Kohana::config('myshot.basePath'); if ($stage_path = Upload::save($data['photo'])) { foreach ($badge->_images as $image) { $name = (string) $image->type->name; if ($image->type->name == self::FULL) { $path_info = pathinfo($stage_path); $savedAt = $path_info['dirname'] . '/' . $path_info['filename'] . '.' . $path_info['extension']; Library_Akamai::factory()->addToDir($savedAt, Kohana::config('akamai.honordir')); $image->path = $this->webpath($stage_path); } else { $image->path = $this->webPath($this->resizeHonor($stage_path, ImageTypes::types()->{$name}->size)); } $image->save(); } } } $badge->save(); }
public function action_uploadmarkimg() { $dir = SLINEDATA . '/mark'; //水印图片存储目录 if (!is_dir($dir)) { mkdir($dir); } $path_info = pathinfo($_FILES['Filedata']['name']); $filename = 'mark.' . $path_info['extension']; Upload::$default_directory = $dir; //默认保存文件夹 Upload::$remove_spaces = true; //上传文件删除空格 $file = $_FILES['Filedata']; $arr = array(); if (Upload::valid($file) && Upload::size($file, "500KB") && Upload::type($file, array('jpg', 'png', 'gif'))) { if (Upload::save($file, $filename)) { $arr['success'] = 'true'; $arr['bigpic'] = $GLOBALS['$cfg_basehost'] . '/data/mark/' . $filename; } } else { $arr['success'] = 'false'; $arr['msg'] = '上传失败,请检查图片大小,图片格式.'; } echo json_encode($arr); }
public function action_destination() { $action = $this->params['action']; if (empty($action)) { $typeid = $this->params['typeid']; $typeid = empty($typeid) ? 0 : $typeid; if (!empty($typeid)) { $moduleinfo = Model_Model::getModuleInfo($typeid); //$product_dest_table='sline_'.$this->product_arr[$typeid].'_kindlist'; $product_dest_table = $moduleinfo['pinyin'] . '_kindlist'; } $addmodule = ORM::factory('model')->where("id>13")->get_all(); //扩展模型 $allmodule = Model_Model::getAllModule(); //$position = $typeid==0 ? '全局目的地':$this->name_arr[$typeid].'目的地'; $position = $typeid == 0 ? '全局目的地' : $moduleinfo['modulename'] . '目的地'; $this->assign('typeid', $typeid); $this->assign('position', $position); $this->assign('addmodule', $addmodule); $this->assign('allmodule', $allmodule); $this->display('stourtravel/destination/destination'); } else { if ($action == 'read') { $node = Arr::get($_GET, 'node'); $typeid = Arr::get($_GET, 'typeid'); $node_arr = explode('_', $node); if (!empty($typeid)) { $moduleinfo = Model_Model::getModuleInfo($typeid); //$product_dest_table='sline_'.$this->product_arr[$typeid].'_kindlist'; $product_dest_table = 'sline_' . $moduleinfo['pinyin'] . '_kindlist'; } $pid = $node_arr[1] == 'root' ? 0 : $node_arr[1]; if (empty($typeid)) { $sql = "select * from sline_destinations where pid={$pid}"; } else { $bfields = 'b.kindid,b.seotitle,b.keyword,b.description,b.tagword,b.jieshao,b.isfinishseo,b.isnav,b.ishot,b.displayorder'; $sql = "select a.id,a.kindname,if(find_in_set({$typeid},opentypeids),1,0) as isopen,a.pinyin,a.iswebsite,{$bfields} from sline_destinations a left join {$product_dest_table} b on a.id=b.kindid where a.pid={$pid}"; } $list = DB::query(Database::SELECT, $sql)->execute()->as_array(); if ($typeid == 0) { $list[] = array('leaf' => true, 'id' => $pid . 'add', 'kindname' => '<button class="dest-add-btn df-add-btn" onclick="addSub(' . $pid . ')">添加</button>', 'allowDrag' => false, 'allowDrop' => false, 'displayorder' => 'add', 'isopen' => 'add', 'iswebsite' => 'add', 'isnav' => 'add', 'istopnav' => 'add', 'ishot' => 'add', 'pinyin' => 'add'); } echo json_encode(array('success' => true, 'text' => '', 'children' => $list)); } else { if ($action == 'update') { $id = Arr::get($_POST, 'id'); $field = Arr::get($_POST, 'field'); $val = Arr::get($_POST, 'val'); $typeid = Arr::get($_POST, 'typeid'); if ($typeid == 0) { $model = ORM::factory('destinations', $id); $model->{$field} = $val; if ($field == 'weburl') { $ar = explode('.', $val); $py = str_replace('http://', '', $ar[0]); $m = ORM::factory('destinations')->where("webprefix='{$py}' and id!={$id}")->find(); if (!$m->loaded()) { $model->webprefix = $py; } else { echo 'py_repeat'; exit; } } $model->save(); if ($model->saved()) { echo 'ok'; } else { echo 'no'; } } else { if ($field == 'isopen') { $result = Model_Destinations::setTypeidOpen($id, $typeid, $val); if ($result) { echo 'ok'; } else { echo 'no'; } } else { $moduleinfo = Model_Model::getModuleInfo($typeid); //$product_dest_table='sline_'.$this->product_arr[$typeid].'_kindlist'; $product_dest_table = $moduleinfo['pinyin'] . '_kindlist'; //$model=ORM::factory($this->product_arr[$typeid].'_kindlist')->where("kindid=$id")->find(); $model = new Model_Tongyong($product_dest_table); $model = $model->where("kindid={$id}")->find(); if (!$model->loaded()) { //$model = ORM::factory($this->product_arr[$typeid].'_kindlist'); $model->kindid = $id; } $model->{$field} = $val; $model->save(); if ($model->saved()) { echo 'ok'; } else { echo 'no'; } } } } else { if ($action == 'save') { $rawdata = file_get_contents('php://input'); $field = Arr::get($_GET, 'field'); $typeid = Arr::get($_GET, 'typeid'); $current_pinyin = Arr::get($_GET, 'pinyin'); $data = json_decode($rawdata); $dest_id_arr = explode('_', $data->id); $dest_id = $dest_id_arr[1]; if (!empty($typeid)) { $moduleinfo = Model_Model::getModuleInfo($typeid); //$product_dest_table='sline_'.$this->product_arr[$typeid].'_kindlist'; $product_dest_table = $moduleinfo['pinyin'] . '_kindlist'; } if (!is_numeric($dest_id_arr[1])) { echo json_encode(array('success' => false)); } if ($typeid == 0) { $dest = ORM::factory('destinations', $dest_id_arr[1]); if ($field) { if ($field == 'kindname') { $dest->pinyin = empty($current_pinyin) ? Common::getPinYin($data->{$field}) : $current_pinyin; } $dest->{$field} = $data->{$field}; } else { unset($data->id); unset($data->parentId); unset($data->leaf); unset($data->issel); unset($data->shownum); foreach ($data as $k => $v) { $dest->{$k} = $v; } } } else { //$dest=ORM::factory($this->product_arr[$typeid].'_kindlist')->where("kindid=$dest_id")->find(); $dest = new Model_Tongyong($product_dest_table); $dest = $dest->where("kindid={$dest_id}")->find(); if (!$dest->loaded()) { $dest->kindid = $dest_id; $dest->displayorder = $data->displayorder; } else { unset($data->id); unset($data->parentId); unset($data->leaf); unset($data->kindname); unset($data->isopen); unset($data->iswebsite); unset($data->istopnav); unset($data->pinyin); unset($data->pid); unset($data->kindtype); unset($data->litpic); unset($data->piclist); unset($data->issel); unset($data->shownum); unset($data->templet); unset($data->weburl); foreach ($data as $k => $v) { $dest->{$k} = $v; } $dest->displayorder = $data->displayorder; } } $dest->displayorder = empty($dest->displayorder) ? 9999 : $dest->displayorder; $dest->save(); if ($dest->saved()) { echo json_encode(array('success' => true)); } else { echo json_encode(array('success' => false)); } } else { if ($action == 'uploadfile') { $file = $_FILES['Filedata']; $rootpath = realpath(DOCROOT . '../'); $dir = $rootpath . "/uploads/main/" . date('Ymd'); if (!file_exists($dir)) { mkdir($dir); } $path_info = pathinfo($_FILES['Filedata']['name']); $filename = date('His') . '.' . $path_info['extension']; Upload::$default_directory = $dir; //默认保存文件夹 Upload::$remove_spaces = true; //上传文件删除空格 if (Upload::valid($file)) { if (Upload::size($file, "1M")) { if (Upload::type($file, array('jpg', 'png', 'gif'))) { if (Upload::save($file, $filename)) { $newfile = $dir . '/' . $filename; Image::factory($newfile)->resize(600, 400, Image::AUTO)->save($newfile); echo substr(substr($newfile, strpos($dir, '/uploads') - 1), 1); } else { echo "error_no"; } } else { echo "error_type"; } } else { echo "error_size"; } } else { echo "error_null"; } } else { if ($action == 'addsub') { $pid = Arr::get($_POST, 'pid'); $dest = ORM::factory('destinations'); $dest->pid = $pid; $dest->kindname = "未命名"; $dest->save(); if ($dest->saved()) { $dest->reload(); $dest->updateSibling('add'); echo json_encode($dest->as_array()); } } else { if ($action == 'drag') { $moveid = Arr::get($_POST, 'moveid'); $overid = Arr::get($_POST, 'overid'); $position = Arr::get($_POST, 'position'); $moveDest = ORM::factory('destinations', $moveid); $overDest = ORM::factory('destinations', $overid); if ($position == 'append') { $moveDest->pid = $overid; } else { $moveDest->pid = $overDest->pid; } $moveDest->save(); if ($moveDest->saved()) { echo 'ok'; } else { echo 'no'; } } else { if ($action == 'search') { $keyword = trim(Arr::get($_POST, 'keyword')); $list = DB::query(Database::SELECT, "select id,pid from sline_destinations where kindname like '%{$keyword}%'")->execute()->as_array(); $new_arr = array(); foreach ($list as $k => $v) { $temp_arr = array(); if ($v['pid'] != 0) { $temp_id = $v['pid']; $temp_arr = array($v['pid'], $v['id']); while (true) { $temp_dest = ORM::factory('destinations', $temp_id)->as_array(); if ($temp_dest['pid'] != 0) { array_unshift($temp_arr, $temp_dest['pid']); $temp_id = $temp_dest['pid']; } else { break; } } $new_arr[] = $temp_arr; } else { $new_arr[] = array($v['id']); } } if (empty($new_arr)) { echo 'no'; } else { echo json_encode($new_arr); } } else { if ($action == 'delete') { $rawdata = file_get_contents('php://input'); $field = Arr::get($_GET, 'field'); $data = json_decode($rawdata); $dest_id_arr = explode('_', $data->id); if (!is_numeric($dest_id_arr[1])) { echo json_encode(array('success' => false)); exit; } $dest = ORM::factory('destinations', $dest_id_arr[1]); $dest->deleteClear(); } } } } } } } } } }