public function mysave($img, $target = "articles") { if ($img != '') { DB::table($this->table)->insert(array('img' => $img, 'cus_id' => Auth::id(), 'target' => $target)); //===释放用户空间容量=== $customer = Auth::user()->name; $filepath = public_path('customers/' . $customer . '/images/l/' . $target . '/' . $img); if (is_file($filepath)) { $size = filesize($filepath); //===images/l不一定有,要推送后才有图片 } else { $size = 0; } $Capacity = new CapacityController(); $Capacity->change_capa($size, 'free'); //===end=== return $Capacity->format_bytes($size); // return DB::table($this->table)->insert(array('img' => $img, 'cus_id' => Auth::id(), 'target' => $target)); } }
public function articleAdd() { $org_imgs = array(); $del_imgs = array(); $id = Input::get('id'); if ($id) { //修改操作 $article = Articles::find($id); $data = MoreImg::where('a_id', $id)->get()->toArray(); foreach ((array) $data as $v) { $org_imgs[] = $v["img"]; } $org_imgs[] = $article->img; } else { //新增操作 $article = new Articles(); } $cus_id = Auth::id(); $article->title = trim(Input::get('title')); $article->c_id = Input::get('c_id'); $article->viewcount = Input::get('viewcount') ? Input::get('viewcount') : 0; $article->title_bold = Input::get('title_bold'); $article->title_color = Input::get('title_color'); $article->keywords = Input::get('keywords'); $article->introduction = Input::get('introduction'); $article->content = trim(Input::get('content')); $article->url = trim(Input::get('url')); $article->use_url = trim(Input::get('use_url')); if ($article->title == "") { return Response::json(array('err' => 3001, 'msg' => '标题不能为空')); } $img_arr = explode(',', Input::get('src')); foreach ((array) $org_imgs as $v) { if (!in_array($v, (array) $img_arr)) { $del_imgs[] = $v; } } if (count($img_arr)) { $article->img = $img_arr[0]; unset($img_arr[0]); } $is_show = empty(Input::get('is_show')) ? array() : explode(',', Input::get('is_show')); $article->pc_show = 0; $article->mobile_show = 0; $article->wechat_show = 0; if (count($is_show)) { foreach ($is_show as $val) { $article->{$val} = 1; } } $pubdate = Input::get('pubdate'); if ($pubdate) { $article->created_at = date('Y-m-d H:i:s', strtotime($pubdate)); } $article->cus_id = $cus_id; $article->pushed = 1; //===ueditor文件统计容量=== $Capacity = new CapacityController(); $Capacity->compare_filename($article->content, $article->file_array); $article->file_array = $Capacity->reg_ueditor_content($article->content); //===end=== $result = $article->save(); if ($result) { if ($id) { MoreImg::where('a_id', $id)->delete(); foreach ((array) $del_imgs as $v) { $imgdel = new ImgDel(); $imgdel->mysave($v, 'articles'); } } if (count($img_arr)) { foreach ($img_arr as $img) { $moreimg = new Moreimg(); $moreimg->title = ''; $moreimg->img = $img; $moreimg->url = ''; $moreimg->sort = ''; $moreimg->a_id = $article->id; $moreimg->save(); } } $return_msg = array('err' => 0, 'msg' => '', 'data' => array($article->id)); } else { $return_msg = array('err' => 3001, 'msg' => '文章添加失败'); } return Response::json($return_msg); }
/** * ===点击保存按钮后动作=== * @return type */ public function img_upload() { $customer = Auth::user()->name; $cus_id = Auth::id(); $target = Input::get('target'); $this->check_dir($target, $customer); $files = explode(',', ltrim(Input::get('files'), ',')); $dir = public_path('customers/' . $customer . '/cache_images/'); $img_size = Input::get('imgsize') ? Input::get('imgsize') : 400; $destinationPath = public_path('customers/' . $customer . '/images/'); $weburl = Customer::where('id', $cus_id)->pluck('weburl'); $suf_url = str_replace('http://c', '', $weburl); if ($files) { $data = array(); $i = 0; //同步到客户服务器 $customerinfo = Customer::find($cus_id); $ftp_array = explode(':', $customerinfo->ftp_address); $port = $customerinfo->ftp_port; $ftpdir = $customerinfo->ftp_dir; $ftp = $customerinfo->ftp; $ftp_array[1] = isset($ftp_array[1]) ? $ftp_array[1] : $port; $conn = ftp_connect($ftp_array[0], $ftp_array[1]); $filesize = 0; //===文件大小=== if (file_exists(public_path('customers/' . $customer . '/img.zip'))) { @unlink(public_path('customers/' . $customer . '/img.zip')); } if ($conn) { ftp_login($conn, $customerinfo->ftp_user, $customerinfo->ftp_pwd); ftp_pasv($conn, 1); $zip = new ZipArchive(); if ($zip->open(public_path('customers/' . $customer . '/img.zip'), ZipArchive::CREATE) === TRUE) { foreach ((array) $files as $fileName) { $filepath = public_path('customers/' . $customer . '/cache_images/' . $fileName); if (file_exists($filepath)) { $filesize += filesize($filepath); //===累加大小 $file = explode('.', $fileName); $type = end($file); $up_result = copy(public_path('customers/' . $customer . '/cache_images/' . $fileName), $destinationPath . '/l/' . $target . '/' . $fileName); if ($up_result) { $s_path = $destinationPath . '/s/' . $target . '/' . $fileName; $img_info = getimagesize($destinationPath . '/l/' . $target . '/' . $fileName); switch ($img_info[2]) { case 1: $type = 'gif'; break; case 2: $type = 'jpg'; break; case 3: $type = 'png'; break; } $this->resizeImage($destinationPath . '/l/' . $target . '/' . $fileName, $type, $s_path, $img_size, $img_size); copy($destinationPath . '/l/' . $target . '/' . $fileName, public_path('customers/' . $customer . '/mobile/images/l/' . $target . '/' . $fileName)); $mobile_s_path = public_path('customers/' . $customer . '/mobile/images/s/') . $target . '/' . $fileName; $this->resizeImage(public_path('customers/' . $customer . '/mobile/images/l/') . $target . '/' . $fileName, $type, $mobile_s_path, $img_size, $img_size); if (trim($ftp) == '1') { $zip->addFile($destinationPath . '/l/' . $target . '/' . $fileName, 'images/l/' . $target . '/' . $fileName); $zip->addFile($destinationPath . '/s/' . $target . '/' . $fileName, 'images/s/' . $target . '/' . $fileName); // $zip->addFile(public_path('customers/' . $customer . '/mobile/images/s/') . $target . '/' . $fileName,'mobile/images/l/' . $target . '/' . $fileName); // $zip->addFile(public_path('customers/' . $customer . '/mobile/images/l/') . $target . '/' . $fileName,'mobile/images/s/' . $target . '/' . $fileName); // ftp_put($conn, $customer . '/images/l/' . $target . '/' . $fileName, $destinationPath . '/l/' . $target . '/' . $fileName, FTP_BINARY); // ftp_put($conn, $customer . '/images/s/' . $target . '/' . $fileName, $destinationPath . '/s/' . $target . '/' . $fileName, FTP_BINARY); // ftp_put($conn, $customer . '/mobile/images/l/' . $target . '/' . $fileName, public_path('customers/' . $customer . '/mobile/images/l/') . $target . '/' . $fileName, FTP_BINARY); // ftp_put($conn, $customer . '/mobile/images/s/' . $target . '/' . $fileName, public_path('customers/' . $customer . '/mobile/images/s/') . $target . '/' . $fileName, FTP_BINARY); } else { ftp_put($conn, $ftpdir . '/' . 'images/l/' . $target . '/' . $fileName, $destinationPath . '/l/' . $target . '/' . $fileName, FTP_BINARY); ftp_put($conn, $ftpdir . '/' . 'images/s/' . $target . '/' . $fileName, $destinationPath . '/s/' . $target . '/' . $fileName, FTP_BINARY); ftp_put($conn, $ftpdir . '/' . 'mobile/images/l/' . $target . '/' . $fileName, public_path('customers/' . $customer . '/mobile/images/l/') . $target . '/' . $fileName, FTP_BINARY); ftp_put($conn, $ftpdir . '/' . 'mobile/images/s/' . $target . '/' . $fileName, public_path('customers/' . $customer . '/mobile/images/s/') . $target . '/' . $fileName, FTP_BINARY); } $data[$i]['name'] = $fileName; $data[$i]['url'] = asset('customers/' . $customer . '/images/l/' . $target . '/' . $fileName); $data[$i]['s_url'] = '/images/s/' . $target . '/' . $fileName; $i++; } } } $zip->close(); if ($conn) { if (trim($ftp) == '1') { $weburl = Customer::where('id', $cus_id)->pluck('weburl'); $suf_url = str_replace('http://c', '', $weburl); $cus_name = strtolower(Customer::where('id', $cus_id)->pluck('name')); if (trim($ftp) == '1') { $ftp_pcdomain = "http://" . $cus_name . $suf_url; } ftp_put($conn, $customer . '/img.zip', public_path('customers/' . $customer . '/img.zip'), FTP_BINARY); ftp_put($conn, $customer . '/img_unzip.php', public_path('packages/img_unzip.php'), FTP_ASCII); @file_get_contents("{$ftp_pcdomain}/img_unzip.php"); @unlink(public_path('customers/' . $customer . '/img.zip')); } } } //===扣除空间容量=== $Capacity = new CapacityController(); $Capacity->change_capa($filesize, 'use'); //===end=== @ftp_close($conn); return Response::json(['err' => 0, 'msg' => '保存成功', 'data' => $data]); } } else { return Response::json(['err' => 1001, 'msg' => '保存失败']); } }
/** * ===栏目批量添加=== */ public function classifyBatch() { $cus_id = Auth::id(); $c_imgs = ''; $is_forced = Input::get('force'); $is_passed = true; $id = Input::get('id'); $classify = new stdClass(); $batch_column_name = Input::get('batch_column_name') ? Input::get('batch_column_name') : ''; $batch_array = explode(',', $batch_column_name); $batch_flag = true; $maxsort = Classify::where('cus_id', $cus_id)->max('sort'); $classify->sort = $maxsort === NULL ? 0 : $maxsort + 1; $classify->cus_id = $cus_id; $page_id = false; $classify->p_id = Input::get('p_id') == "undefined" ? 0 : Input::get('p_id'); //===要改变的父类=== $classify->type = Input::get('type'); $classify->form_id = Input::get('form_id'); if ($classify->p_id > 0) { if ($this->checkClassifyLevel($classify->p_id, 1, $cus_id)) { $p_c_info = Classify::find($classify->p_id); //===父类信息=== if (in_array($p_c_info->type, array(5, 6, 7, 8, 9))) { $result = ['err' => 1001, 'msg' => '该类型不允许添加子栏目', 'data' => []]; $is_passed = false; } else { $c_c_ids = Classify::where('p_id', $p_c_info->id)->lists('id'); if (!count($c_c_ids)) { $a_ids = Articles::where('c_id', $p_c_info->id)->lists('id'); if (count($a_ids)) { $result = ['err' => 1001, 'msg' => '存在文章的栏目不允许批量添加栏目', 'data' => []]; $is_passed = false; } } } } else { $result = ['err' => 1001, 'msg' => '添加失败,超过最大限制层级', 'data' => []]; $is_passed = false; } } if ($is_passed) { $classify->en_name = trim(Input::get('en_name')); $images = Input::get('img'); //===新图片 $classify->img = $images; if (!empty($c_imgs) && $c_imgs != 'undefined') { if ($c_imgs != $images) { $del_img = $c_imgs; } } $icon = Input::get('icon'); if (!empty($icon) && $icon != 'undefined') { $classify->icon = $icon; } else { $classify->icon = ''; } $classify->article_type = Input::get('article_type') != "undefined" ? Input::get('article_type') : 1; $classify->meta_keywords = trim(Input::get('keywords')); $classify->meta_description = trim(Input::get('description')); $classify->url = trim(Input::get('url')); $classify->open_page = trim(Input::get('open_page')) ? trim(Input::get('open_page')) : 1; $classify->pushed = 1; $is_show = Input::get('is_show'); $shows = explode(',', $is_show); if (count($shows)) { $classify->pc_show = 0; $classify->mobile_show = 0; $classify->wechat_show = 0; $classify->footer_show = 0; foreach ($shows as $show) { if ($show != '') { $classify->{$show} = 1; } } } if (Input::has('page_content') && Input::get('page_content') != 'undefined') { $page_content = Input::get('page_content'); //===ueditor保存=== $page = Page::find($page_id); $Capacity = new CapacityController(); if (empty($page)) { $page_file_array = ''; } else { $page_file_array = $page->file_array; } $Capacity->compare_filename($page_content, $page_file_array); $file_array = $Capacity->reg_ueditor_content($page_content); //===end=== if ($page_id) { Page::where('id', $page_id)->update(array('content' => $page_content, 'file_array' => $file_array)); } else { $page = new Page(); $page->c_id = 0; $page->content = $page_content; $page->file_array = $file_array; if ($page->save()) { $classify->page_id = $page->id; } else { return Response::json(['err' => 10001, 'msg' => '页面内容无法保存']); } } } $size = 0; $classify_arr = (array) $classify; // $ids = ''; foreach ($batch_array as $key => $value) { $classify_obj[$key] = $classify_arr; $classify_obj[$key]["name"] = trim($value); $temp_flag = Classify::insertGetId($classify_obj[$key]); // $ids[] = $temp_flag; $batch_flag = $batch_flag && $temp_flag; } if ($batch_flag) { // $data['ids'] = $ids; // if (in_array($classify->type, array(1, 2, 3, 4, 9)) && $classify->p_id == 0) { // //===添加type:9万用表单=== // $mhomepage_config = new MobileHomepage(); // $mhomepage_config->c_id = $data['id']; // $mhomepage_config->index_show = 1; // $mhomepage_config->show_num = 0; // $mhomepage_config->star_only = 0; // $mhomepage_config->s_sort = 0; // $mhomepage_config->cus_id = $cus_id; // $mhomepage_config->save(); // } $result = ['err' => 0, 'msg' => '批量创建栏目成功', 'data' => '']; } else { $result = ['err' => 1001, 'msg' => '批量创建栏目失败', 'data' => []]; } } return Response::json($result); }