public function postWriteArticle($type)
 {
     $this->beforeAction($type);
     try {
         if (!isset($_POST['id'])) {
             throw new Exception("Error Processing Request [10]");
         }
         $id = (int) Arr::get($_POST, 'id', null);
         if (empty($id)) {
             $model = new ServiceFaq();
         } else {
             $model = ServiceFaq::find($id);
             if ($model == null) {
                 throw new Exception("Error Processing Request [11]");
             }
         }
         $labels = Input::get('labels', array());
         $lblList = array();
         foreach ($labels as $label) {
             $lblList[] = (int) $label;
         }
         $order = 0;
         $tabContents = Input::get('tabContents', array());
         $tabs = array();
         foreach (Input::get('tabName', array()) as $key => $tab) {
             if (!isset($tabContents[$key])) {
                 continue;
             }
             $tabs[] = array('title' => $tab, 'content' => $tabContents[$key], 'sort' => $order);
             $order++;
         }
         //$model             = new ServiceFaq;
         $model->type = $type;
         $model->title = Input::get('title');
         $model->image = Input::get('image_path');
         $model->content = Input::get('content');
         $model->labels = json_encode($lblList);
         $model->tabs = json_encode($tabs);
         $model->status = Input::get('status');
         $model->_parent = Input::get('category');
         $model->created_at = time();
         $model->updated_at = time();
         $model->save();
         # Handling Images
         $imgs = ServiceFaqImage::where('sid', '=', $model->id)->get();
         $delImages = Arr::get($_POST, 'deleteImages', array());
         if (sizeof($imgs) > 0) {
             $delLength = sizeof($delImages);
             foreach ($imgs as $img) {
                 if ($delLength > 0 && in_array($img->id, $delImages)) {
                     fps::getInstance()->delete($img->image);
                 }
                 $img->delete();
             }
         }
         $order = 1;
         $imagesDesc = Input::get('imageDesc', array());
         foreach (Input::get('images', array()) as $key => $image) {
             ServiceFaqImage::create(array('sid' => $model->id, 'image' => $image, 'text' => $imagesDesc[$key], 'sort' => $order));
             $order++;
         }
         return Redirect::route('admin.service_faq.article.list', array('type' => $model->type, 'category' => $model->_parent, 'afterAction' => 1));
     } catch (Exception $e) {
         return Redirect::back()->withInput()->withErrors($e->getMessage());
     }
 }
Пример #2
0
 public function postArticleAction()
 {
     try {
         if (!isset($_POST['id'])) {
             throw new Exception("Error Processing Request [10]");
         }
         $id = (int) Arr::get($_POST, 'id', null);
         if (empty($id)) {
             $model = new Wintness();
         } else {
             $model = Wintness::find($id);
             if ($model == null) {
                 throw new Exception("Error Processing Request [11]");
             }
         }
         // collect image uploader
         /*
          * (array) currentList
          * (string) competeKey
          * (array) newList
          * (string) deleteFieldName
          */
         $delImages = Arr::get($_POST, 'deleteImages', array());
         $delLength = sizeof($delImages);
         for ($i = 0; $i < $delLength; $i++) {
             $delLength[$i] = basename($delLength);
         }
         $imgUploaderList = array('cover' => array('fieldName' => 'cover', 'items' => null), 'before' => array('fieldName' => 'img_before', 'items' => null), 'after' => array('fieldName' => 'img_after', 'items' => null), 'gallery' => array('fieldName' => 'gallery', 'items' => null));
         foreach ($imgUploaderList as $key => $val) {
             $imgs = json_decode($model->{$val}['fieldName']);
             if (!empty($imgs) && sizeof($imgs) > 0) {
                 foreach ($imgs as $img) {
                     if ($delLength > 0 && in_array($img->id, $delImages)) {
                         fps::getInstance()->delete($img->image);
                     }
                 }
             }
             $list = array();
             $descFieldName = $val['fieldName'] . '_desc';
             $imagesDesc = Input::get($descFieldName, array());
             $images = Input::get($val['fieldName'], array());
             foreach ($images as $idx => $image) {
                 $list[] = array('id' => basename($image), 'image' => $image, 'text' => $imagesDesc[$idx]);
             }
             $imgUploaderList[$key]['items'] = $list;
         }
         $status = (int) Arr::get($_POST, 'status', 0);
         $isInSiderbar = (int) Arr::get($_POST, 'isInSiderbar', 0);
         $model->title = Input::get('title');
         $model->background_color = Input::get('background_color', '#ccc');
         $model->cover = json_encode($imgUploaderList['cover']['items']);
         $model->img_before = json_encode($imgUploaderList['before']['items']);
         $model->img_after = json_encode($imgUploaderList['after']['items']);
         $model->description = Input::get('description', '');
         $model->gallery = json_encode($imgUploaderList['gallery']['items']);
         $model->status = $status % 2;
         $model->isInSiderbar = $isInSiderbar % 2;
         $model->created_at = time();
         $model->updated_at = time();
         $model->save();
         WintnessLabels::where('wid', '=', $model->id)->delete();
         $types = array('service', 'faq');
         foreach ($types as $type) {
             $fieldName = 'label_' . $type;
             $labels = Input::get($fieldName, array());
             foreach ($labels as $label) {
                 WintnessLabels::create(array('wid' => (int) $model->id, 'label_id' => (int) $label));
             }
         }
         Tabs::where('type', '=', 'wintness')->where('item_id', '=', $model->id)->delete();
         // collect tabs
         $tabContents = Input::get('tabContents', array());
         $tabs = array();
         $tabName = Input::get('tabName', array());
         $order = 1;
         foreach ($tabName as $key => $tab) {
             if (!isset($tabContents[$key])) {
                 continue;
             } else {
                 Tabs::create(array('type' => 'wintness', 'item_id' => $model->id, 'title' => $tab, 'content' => $tabContents[$key], 'sort' => $order++));
             }
         }
         return Redirect::route('admin.wintness.article.list', array('page' => 1, 'message' => 'success'));
     } catch (Exception $e) {
         return Redirect::back()->withInput()->withErrors($e->getMessage());
     }
 }
Пример #3
0
 public function postAction()
 {
     $bid = Arr::get($_POST, 'bid');
     $image = Arr::get($_POST, 'image', null);
     $imgList = Arr::get($_POST, 'imglist', array());
     $size = Arr::get($_POST, 'size', 'small');
     $title = Arr::get($_POST, 'title', 'unknown');
     $link = Arr::get($_POST, 'link', '#');
     $target = Arr::get($_POST, 'target', '_self');
     $start = Arr::get($_POST, 'on_time', 0);
     $end = Arr::get($_POST, 'off_time', 0);
     $status = Arr::get($_POST, 'status', '1');
     if ($image == null) {
         return Redirect::route('admin.banners.list', array($size, 'message' => 'error'));
     }
     $m = $bid != 'null' ? $m = Banners::find($bid) : null;
     if ($m == null) {
         $m = new Banners();
         $m->created_at = date('Y-m-d H:i:s');
     }
     $start = empty($start) ? 0 : strtotime($start);
     $end = empty($end) ? 0 : strtotime($end);
     $m->title = $title;
     $m->image = $image;
     $m->size = $size;
     $m->link = $link;
     $m->target = $target;
     $m->on_time = $start;
     $m->off_time = $end;
     $m->status = $status;
     $m->updated_at = date('Y-m-d H:i:s');
     $bool = $m->save();
     $list = explode($imgList, '=sep=');
     foreach ($list as $item) {
         if (md5($item) != md5($image)) {
             fps::getInstance()->delete($item);
         }
     }
     return Redirect::route('admin.banners.list', array($size, 'message' => 'success'));
 }
 public function postAction()
 {
     try {
         if (!isset($_POST['id'])) {
             throw new Exception("Error Processing Request [10]");
         }
         $id = (int) Arr::get($_POST, 'id', null);
         if (empty($id)) {
             $model = new BeautyNews();
         } else {
             $model = BeautyNews::find($id);
             if ($model == null) {
                 throw new Exception("Error Processing Request [11]");
             }
         }
         // collect image uploader
         /*
          * (array) currentList
          * (string) competeKey
          * (array) newList
          * (string) deleteFieldName
          */
         $delImages = Arr::get($_POST, 'deleteImages', array());
         $delLength = sizeof($delImages);
         for ($i = 0; $i < $delLength; $i++) {
             $delLength[$i] = basename($delLength);
         }
         $imgUploaderList = array('cover' => array('fieldName' => 'cover', 'items' => null), 'fb' => array('fieldName' => 'fb', 'items' => null));
         foreach ($imgUploaderList as $key => $val) {
             $imgs = json_decode($model->{$val}['fieldName']);
             if (!empty($imgs) && sizeof($imgs) > 0) {
                 foreach ($imgs as $img) {
                     if ($delLength > 0 && in_array($img->id, $delImages)) {
                         fps::getInstance()->delete($img->image);
                     }
                 }
             }
             $list = array();
             $descFieldName = $val['fieldName'] . '_desc';
             $imagesDesc = Input::get($descFieldName, array());
             $images = Input::get($val['fieldName'], array());
             foreach ($images as $idx => $image) {
                 $list[] = array('id' => basename($image), 'image' => $image, 'text' => $imagesDesc[$idx]);
             }
             $imgUploaderList[$key]['items'] = $list;
         }
         $status = (int) Arr::get($_POST, 'status', 0);
         $model->title = Input::get('title');
         $model->style = Arr::get($_POST, 'style', 1);
         $model->cover = json_encode($imgUploaderList['cover']['items']);
         $model->fb = json_encode($imgUploaderList['fb']['items']);
         $model->link = Arr::get($_POST, 'link', '#');
         $model->target = Arr::get($_POST, 'target', '_self');
         $model->description = Arr::get($_POST, 'description', '');
         $model->status = $status % 2;
         $model->sort = (int) Arr::get($_POST, 'sort', 1);
         $model->created_at = time();
         $model->updated_at = time();
         $model->save();
         return Redirect::route('admin.beautynews.list', array('page' => 1, 'message' => 'success'));
     } catch (Exception $e) {
         return Redirect::back()->withInput()->withErrors($e->getMessage());
     }
 }
Пример #5
0
 private function handleImageRequest($filename)
 {
     $pKey = array('w' => null, 'h' => null, 'ar' => 'sl', 'gr' => false, 'bg' => 'ffffff', 'q' => 100);
     $p = array();
     foreach ($pKey as $k => $value) {
         $p[$k] = Input::get($k, $value);
     }
     $gr = $this->getGR($p['gr']);
     //$filename = $this->storePath . DIRECTORY_SEPARATOR . $filename;
     list($file, $ext) = explode('.', $filename);
     $cacheKey = md5(implode('_', $p));
     $ck = md5($filename . '/' . $cacheKey);
     $IM = null;
     $bool = Cache::has($ck);
     //if ($bool) $bool = false;
     if ($bool) {
         return $result = Cache::get($ck);
     } else {
         ob_start();
         $cacheFile = $p['w'] == null && $p['h'] == null ? $filename : fps::getInstance()->getRealFilePath($filename, 'cache') . DIRECTORY_SEPARATOR . sprintf('%s_%s', $cacheKey, basename($filename));
         if (!file_exists($cacheFile)) {
             $info = getimagesize($filename);
             $width = $info[0];
             $height = $info[1];
             $createFuncion = '';
             $q = (int) $p['q'];
             switch (strtolower($info['mime'])) {
                 case 'image/jpeg':
                 case 'image/jpg':
                     $im = imagecreatefromjpeg($filename);
                     $createFuncion = 'imagejpeg';
                     break;
                 case 'image/gif':
                     $im = imagecreatefromgif($filename);
                     $createFuncion = 'imagegif';
                     break;
                 case 'image/png':
                     $im = imagecreatefrompng($filename);
                     $createFuncion = 'imagepng';
                     $q = ceil(abs(100 - $q) / 10);
                     break;
                 case "image/bmp":
                     $im = imagecreatefromwbmp($filename);
                     $createFuncion = 'image2wbmp';
                     break;
             }
             $newCreateImage = $createFuncion == 'imagepng' || $createFuncion == 'imagegif' ? 'imagecreate' : 'imagecreatetruecolor';
             if ($p['w'] != null && $p['h'] != null) {
                 $ratio = round($p['w'] / $p['h'], 3);
                 if (($h = $width / $ratio) <= $height) {
                     $w = $width;
                 } else {
                     $w = $height * $ratio;
                     $h = $height;
                 }
                 $corpIm = $this->getCropImage($im, $gr, $width, $height, (int) $w, (int) $h, $newCreateImage);
                 $newIm = $newCreateImage($p['w'], $p['h']);
                 imagecopyresampled($newIm, $corpIm, 0, 0, 0, 0, $p['w'], $p['h'], $w, $h);
                 $createFuncion($newIm, $cacheFile, $q);
                 imagedestroy($corpIm);
             } else {
                 if (!empty($p['w'])) {
                     $p['h'] = (int) round($p['w'] * $height / $width);
                 } else {
                     $p['w'] = (int) round($p['h'] * $width / $height);
                 }
                 $newIm = $newCreateImage($p['w'], $p['h']);
                 imagecopyresampled($newIm, $im, 0, 0, 0, 0, $p['w'], $p['h'], $width, $height);
                 $createFuncion($newIm, $cacheFile, $q);
                 imagedestroy($im);
             }
             $createFuncion($newIm);
             imagedestroy($newIm);
         } else {
             $info = getimagesize($cacheFile);
             $createFuncion = '';
             $q = (int) $p['q'];
             switch (strtolower($info['mime'])) {
                 case 'image/jpeg':
                 case 'image/jpg':
                     $im = imagecreatefromjpeg($cacheFile);
                     $createFuncion = 'imagejpeg';
                     break;
                 case 'image/gif':
                     $im = imagecreatefromgif($cacheFile);
                     $createFuncion = 'imagegif';
                     break;
                 case 'image/png':
                     $im = imagecreatefrompng($cacheFile);
                     $createFuncion = 'imagepng';
                     $q = ceil(abs(100 - $q) / 10);
                     break;
                 case "image/bmp":
                     $im = imagecreatefromwbmp($cacheFile);
                     $createFuncion = 'image2wbmp';
                     break;
             }
             $createFuncion($im, null, $q);
             imagedestroy($im);
         }
         $result = ob_get_contents();
         Cache::put($ck, $result, 10);
         ob_end_clean();
         return $result;
     }
 }
Пример #6
0
 public function getIndex()
 {
     var_dump(fps::getInstance()->delete('http://eric.www.rebeauty.com.tw/image/5313ea80699a1.jpg'));
     return View::make('admin.test.index');
 }