Beispiel #1
0
 public function index()
 {
     $users = $this->users()->map(function ($user) {
         return api::user($user);
     });
     return response::json(array_values($users->toArray()));
 }
Beispiel #2
0
 /**
  * compile and send the json response.
  */
 public function afterRoute($f3, $params)
 {
     $version = (int) $f3->get('GET.version');
     if (empty($version)) {
         $version = $this->version;
     }
     if ($version !== $this->version) {
         $this->failure(4999, 'Unknown API version requested.', 400);
     }
     if (empty($this->data['href'])) {
         $data['href'] = $this->href();
     }
     $data = array('service' => 'API', 'api' => $version, 'time' => time()) + $this->data;
     // if an OAuthError is set, return that instead of errors array
     if (!empty($this->OAuthError)) {
         $data['error'] = $this->OAuthError;
     } else {
         if (count($this->errors)) {
             ksort($this->errors);
             $data['errors'] = $this->errors;
         }
     }
     $return = $f3->get('GET.return');
     switch ($return) {
         case 'xml':
             $this->response->xml($data, $this->params);
             break;
         default:
         case 'json':
             $this->response->json($data, $this->params);
     }
 }
Beispiel #3
0
 public function ajaxCouponData()
 {
     $filter = input::get();
     if (!$filter['pages']) {
         $filter['pages'] = 1;
     }
     $pageSize = 10;
     $params = array('page_no' => $pageSize * ($filter['pages'] - 1), 'page_size' => $pageSize, 'fields' => '*', 'user_id' => userAuth::id());
     $couponListData = app::get('topm')->rpcCall('user.coupon.list', $params, 'buyer');
     $count = $couponListData['count'];
     $couponList = $couponListData['coupons'];
     //处理翻页数据
     $current = $filter['pages'] ? $filter['pages'] : 1;
     $filter['pages'] = time();
     if ($count > 0) {
         $total = ceil($count / $pageSize);
     }
     $pagedata['pagers'] = array('link' => url::action('topm_ctl_member_coupon@couponList', $filter), 'current' => $current, 'total' => $total, 'token' => $filter['pages']);
     $pagedata['couponList'] = $couponList;
     $pagedata['count'] = $count;
     $pagedata['action'] = 'topm_ctl_member_coupon@couponList';
     if (input::get('json')) {
         $data['html'] = view::make('topm/member/coupon/list.html', $pagedata)->render();
         $data['pagers'] = $pagedata['pagers'];
         $data['success'] = true;
         return response::json($data);
         exit;
     }
     return view::make('topm/member/coupon/list.html', $pagedata);
 }
Beispiel #4
0
 public function getProp()
 {
     $postCartId = input::get('catId');
     try {
         $userMdlProp = app::get("syscategory")->model('cat_rel_prop');
         $propList = $userMdlProp->getList("*", array('cat_id' => $postCartId));
         $pagedata = array();
         foreach ($propList as $prop) {
             // code...
             $propId = $prop["prop_id"];
             $propModel = app::get("syscategory")->model('prop_values');
             $propValueList = $propModel->getList("*", array('prop_id' => $propId));
             foreach ($propValueList as $propvalue) {
                 $pagedata[] = array("prop_value_id" => $propvalue["prop_value_id"], "prop_value" => $propvalue["prop_value"]);
             }
             $a = 1;
         }
     } catch (Exception $e) {
         $msg = $e->getMessage();
         return $this->splash('error', null, $msg);
     } catch (\LogicException $e) {
         $msg = $e->getMessage();
         return $this->splash('error', null, $msg);
     }
     $ajaxdata = array('datas' => $pagedata);
     return response::json($ajaxdata);
 }
Beispiel #5
0
 /**
  * 异步获取数据  图表用
  * @param null
  * @return array
  */
 public function ajaxTrade()
 {
     $postData = input::get();
     //api的参数
     $all = $this->__getParams('graphall', $postData, 'trade');
     $datas = app::get('topshop')->rpcCall('sysstat.data.get', $all, 'seller');
     return response::json($datas);
 }
Beispiel #6
0
 /**
  * 根据itemId获取图片
  */
 public function getItemPic()
 {
     $itemId = input::get('itemIds');
     $picData = kernel::single('sysitem_item_info')->getItemDefaultPic($itemId);
     if ($picData[$itemId]['image_default_id']) {
         $result['url'] = $picData[$itemId]['image_default_id'];
     }
     return response::json($result);
 }
Beispiel #7
0
 /**
  * 异步获取数据  图表用
  * @param null
  * @return array
  */
 public function ajaxTrade()
 {
     $postData = input::get();
     $orderBy = $postData['trade'] . ' ' . 'DESC';
     $postData['orderBy'] = $orderBy;
     $postData['limit'] = 10;
     $grapParams = $this->__getParams('itemgraphall', $postData, 'item');
     $datas = app::get('topshop')->rpcCall('sysstat.data.get', $grapParams, 'seller');
     $ajaxdata = array('dataInfo' => $data, 'datas' => $datas);
     return response::json($ajaxdata);
 }
 public function slideDelete($id)
 {
     $result = false;
     $slide = Slide::where('id', $id);
     if ($slide) {
         $slide->delete();
         SlideImage::where('slide_id', $id)->delete();
         $result = true;
     }
     return response::json(array('result' => $result));
 }
Beispiel #9
0
 public function autocomplete($mode)
 {
     switch ($mode) {
         case 'usernames':
             $result = site()->users()->map(function ($user) {
                 return $user->username();
             })->toArray();
             break;
         case 'emails':
             $result = site()->users()->map(function ($user) {
                 return $user->email();
             })->toArray();
             break;
         case 'uris':
             $result = site()->index()->map(function ($page) {
                 return $page->id();
             })->toArray();
             // sort results alphabetically
             sort($result);
             break;
         case 'field':
             $index = get('index', 'siblings');
             // siblings, children, template, all
             $id = get('uri');
             $page = page($id);
             switch ($index) {
                 case 'siblings':
                 case 'children':
                     $pages = $page->{$index}();
                     break;
                 case 'template':
                     $template = get('template', $page->template());
                     $pages = site()->index()->filterBy('template', $template);
                     break;
                 case 'pages':
                 case 'all':
                     $pages = site()->index();
                     break;
                 default:
                     if ($page = site()->page($index)) {
                         $pages = $page->children();
                     } else {
                         return response::json(array());
                     }
             }
             $result = $pages->pluck(get('field', 'tags'), get('separator', true), true);
             break;
         default:
             return response::error('Invalid autocomplete method');
     }
     return response::json(array_values($result));
 }
Beispiel #10
0
 /**
  * Handle an incomming request.
  */
 public static function handle($pageId, $lang)
 {
     if (r::data('token') != c::get('slack.verify')) {
         return response::error('Forbidden', 403);
     }
     $history = static::api('channels.history', ['channel' => r::data('channel_id')]);
     if (!empty($history['error'])) {
         // Something went wrong ... maybe:
         $msg = ['channel_not_found' => ':lock: Sorry, but this is a private channel'];
         $err = $history['error'];
         return response::json(isset($msg[$err]) ? $msg[$err] : $err);
     }
     $messages = $history['messages'];
     if (!empty(r::data('text'))) {
         $messages = array_values(array_filter($messages, function ($m) {
             return stristr($m['text'], r::data('text'));
         }));
     }
     if (empty($messages)) {
         return response::json(":mag: Sorry, I couldn't find the post you're looking for");
     }
     $m = $messages[0];
     $a = @$m['attachments'][0];
     $img = @$a['image_url'];
     if (empty($img)) {
         $img = @$a['thumb_url'];
     }
     if (empty($img)) {
         return response::json(":warning: I'll only publish posts with images");
     }
     $page = site()->visit($pageId, $lang);
     $dir = $page->root();
     $ext = preg_replace('/.+?(\\.\\w+)($|[#?].*)/', '$1', $img);
     $file = $dir . DS . $m['ts'] . $ext;
     // Output success message early because of short slackbot timeouts
     $msg = ':metal: *' . r::data('text', 'last') . '* post is now live' . ' on <' . $page->url() . '>';
     echo $msg;
     flush();
     error_log($msg);
     $user = static::api('users.info', ['user' => $m['user']]);
     $meta = ['title' => $a['title'], 'date' => date('d.m.Y', $m['ts']), 'description' => @$a['text'], 'linkurl' => $a['from_url'], 'author' => $user['user']['profile']['real_name'], 'avatar' => $m['user'] . '.jpg', 'comment' => static::format(@$m['text']), 'slack' => '1'];
     data::write($file . '.txt', $meta, 'kd');
     // Download the avatar image
     $avatar = $dir . DS . $meta['avatar'];
     static::download($user['user']['profile']['image_72'], $avatar);
     // Download the image
     static::download($img, $file);
     // Response has already been sent
     return false;
 }
Beispiel #11
0
 public function setConf()
 {
     $shopId = $this->shopId;
     $confs = input::get();
     try {
         $requestParams = ['shop_id' => $shopId, 'developMode' => $confs['developer'] ? $confs['developer'] : 'PRODUCT'];
         app::get('topshop')->rpcCall('open.shop.develop.setConf', $requestParams);
         $ret = ['result' => '修改成功'];
     } catch (Exception $e) {
         $ret = ['result' => $e->getMessage()];
     }
     return response::json($ret);
     exit;
 }
Beispiel #12
0
 /**
  * 根据父类id获取子类列表
  * @return json
  */
 public function getChildrenCatList()
 {
     $catId = intval(input::get('cat_id'));
     if ($catId) {
         $catList = app::get('toputil')->rpcCall('category.cat.get.info', array('parent_id' => $catId, 'fields' => 'cat_id,cat_name,child_count'));
         foreach ($catList as $key => $value) {
             $newList[$key] = array('value' => $value['cat_id'], 'text' => $value['cat_name'], 'hasChild' => $value['child_count'] > 0 ? true : false);
         }
         $data['data']['options'] = $newList;
     } else {
         $data = array();
     }
     return response::json($data);
 }
Beispiel #13
0
 public function handle($request, Clousure $next)
 {
     $routeAs = route::currentRouteName();
     $currentPermission = shopAuth::getSellerPermission();
     //$currentPermission = false 表示为店主不用判断权限
     //获取当前用户的路由权限
     if ($currentPermission && !in_array($routeAs, $currentPermission)) {
         if (request::ajax()) {
             return response::json(array('error' => true, 'message' => '无操作权限'));
         } else {
             return redirect::action('topshop_ctl_index@nopermission');
         }
     }
     return $next($request);
 }
Beispiel #14
0
 public function splash($status = 'success', $url = null, $msg = null, $ajax = false)
 {
     $status = $status == 'failed' ? 'error' : $status;
     //如果需要返回则ajax
     if ($ajax == true || request::ajax()) {
         return response::json(array($status => true, 'message' => $msg, 'redirect' => $url));
     }
     if ($url && !$msg) {
         //如果有url地址但是没有信息输出则直接跳转
         return redirect::action($url);
     }
     $this->setLayoutFlag('splash');
     $pagedata['msg'] = $msg;
     return $this->page('topm/splash/error.html', $pagedata);
 }
Beispiel #15
0
 public function update()
 {
     $noticeid = $_POST["notice_id"];
     $noticemdl = app::get("sysshop")->model("shop_notice");
     $notice = $noticemdl->getRow("*", array("notice_id" => $noticeid));
     $notice["is_read"] = true;
     try {
         $noticemdl->save($notice);
         $ajaxdata["result"] = "success";
         return response::json($ajaxdata);
     } catch (Exception $e) {
         $ajaxdata["result"] = "error";
         return response::json($ajaxdata);
     }
 }
Beispiel #16
0
 public static function latest_post()
 {
     $cache = kirby()->cache()->get('facebook.latest.post');
     if (!is_null($cache)) {
         return response::json($cache);
     }
     $response = remote::get(url::build(array('scheme' => static::$graph_scheme, 'host' => static::$graph_host, 'fragments' => array(c::get('facebook.id'), 'posts'), 'query' => array('access_token' => c::get('facebook.accesstoken'), 'limit' => 1))));
     if ($response->content) {
         // parse json string
         $data = str::parse($response->content)['data'][0];
         $return = array('text' => $data['message'], 'picture' => $data['picture'], 'timestamp' => strtotime($data['updated_time']), 'time_formatted' => strftime('%d. %B %G', strtotime($data['updated_time'])), 'link' => $data['link']);
         // set cache for 10 minutes
         kirby()->cache()->set('facebook.latest.post', $return, 10);
     } else {
         return false;
     }
     return $return;
 }
 public function update_user(userUpdateRequest $request, $id)
 {
     $user_data = userRegister::findorfail($id);
     if ($user_data) {
         $user_data->fb_id = $request->get('fb_id');
         $user_data->full_name = $request->get('full_name');
         $user_data->mobile_no = $request->get('mobile_no');
         $user_data->email = $request->get('email');
         $user_data->dob = $request->get('dob');
         $user_data->gender = $request->get('gender');
         $user_data->zone = $request->get('zone');
         $user_data->district = $request->get('district');
         $user_data->location = $request->get('location');
         $user_data->save();
         $result = response::json(array('result' => 'success'))->header('Content-type', 'application/json');
     } else {
         $result = response::json(array('result' => 'Errors'))->header('Content-type', 'application/json');
     }
     return $result;
     die;
 }
Beispiel #18
0
 /**
  * 异步获取数据  图表用
  * @param null
  * @return array
  */
 public function ajaxTrade()
 {
     $postData = input::get();
     //api的参数
     $all = $this->__getParams('graphall', $postData, 'trade');
     /*	$tradetype= $postData['trade'];
     		$sendtype = $postData['sendtype'];
     		$compare = $postData['compare'];
     
     		if($sendtype=='selecttime')
     		{
     			$filter = array(
     				'starttime'=>$postData['starttime'],
     				'endtime'=>$postData['endtime']
     			);
     		}
     		if($sendtype=='select')
     		{
     			$filter = array(
     				'starttime' => $postData['starttime'],
     			);
     		}*/
     $datas = app::get('topshop')->rpcCall('sysstat.data.get', $all, 'seller');
     //echo '<pre>';print_r($datas);exit();
     return response::json($datas);
     /*if($sendtype == 'yesterday' || $sendtype == 'beforday')
     		{
     			$data = $dataInfo['commonday'];
     		}
     		else
     		{
     			$data = $dataInfo;
     		}
     
     
     		return response::json($datas);*/
 }
Beispiel #19
0
 /**
  * 根据父类id获取子类列表
  * @return json
  */
 public function getChildrenCatList()
 {
     $a = input::get();
     $catId = intval(input::get('cat_id'));
     $shopid = intval(input::get('shopid'));
     if ($catId) {
         $catPralist = app::get("syscategory")->model('cat')->getRow("*", array("cat_id" => $catId));
         if ($catPralist["cat_name"] == "其他") {
             $catList = app::get("syscategory")->model('cat')->getList("*", array("parent_id" => $catId, "belong" => $shopid));
             foreach ($catList as $key => $value) {
                 $newList[$key] = array('value' => $value['cat_id'], 'text' => $value['cat_name'], 'hasChild' => $value['child_count'] > 0 ? true : false);
             }
         } else {
             $catList = app::get('toputil')->rpcCall('category.cat.get.info', array('parent_id' => $catId, 'fields' => 'cat_id,cat_name,child_count'));
             foreach ($catList as $key => $value) {
                 $newList[$key] = array('value' => $value['cat_id'], 'text' => $value['cat_name'], 'hasChild' => $value['child_count'] > 0 ? true : false);
             }
         }
         $data['data']['options'] = $newList;
     } else {
         $data = array();
     }
     return response::json($data);
 }
Beispiel #20
0
<?php

//return url of next test
echo response::json(['url' => $url]);
Beispiel #21
0
 public function ajaxGetBrand($cat_id)
 {
     $params['shop_id'] = $this->shopId;
     $params['cat_id'] = input::get('cat_id');
     $brand = app::get('topshop')->rpcCall('category.get.cat.rel.brand', $params);
     if (!$brand) {
         return $this->splash('error', null, '当前类目不支持产品发布,请联系平台开启此权限', true);
     }
     return response::json($brand);
     exit;
 }
Beispiel #22
0
 public function ajaxItemShow()
 {
     $postdata = input::get();
     $pagedata = $this->__getItems($postdata);
     if (!$pagedata) {
         $data['error'] = true;
         return response::json($data);
         exit;
     }
     $data['html'] = view::make('topm/list/itemlist/itemshow.html', $pagedata)->render();
     $data['pagers'] = $pagedata['pagers'];
     $data['success'] = true;
     return response::json($data);
     exit;
 }
Beispiel #23
0
 function splash($status = 'success', $url = null, $msg = null, $method = 'redirect', $params = array())
 {
     $default = array($status => $msg ? $msg : app::get('desktop')->_('操作成功'), $method => $url);
     $arr = array_merge($default, $params, array('splash' => true));
     response::json($arr)->send();
     exit;
 }
Beispiel #24
0
 public function searchItem()
 {
     $shopId = $this->shopId;
     $catId = input::get('catId');
     $brandId = input::get('brandId');
     $keywords = input::get('searchname');
     $couponId = input::get('couponId');
     if ($brandId) {
         $searchParams = array('shop_id' => $shopId, 'cat_id' => $catId, 'brand_id' => $brandId, 'search_keywords' => $keywords, 'page_size' => 1000);
     } else {
         $searchParams = array('shop_id' => $shopId, 'cat_id' => $catId, 'search_keywords' => $keywords, 'page_size' => 1000);
     }
     $searchParams['fields'] = 'item_id,title,image_default_id,price';
     $itemsList = app::get('topshop')->rpcCall('item.search', $searchParams);
     $pagedata['itemsList'] = $itemsList['list'];
     $pagedata['image_default_id'] = app::get('image')->getConf('image.set');
     if ($couponId) {
         $objMdlCouponItem = app::get('syspromotion')->model('coupon_item');
         $notEndItem = $objMdlCouponItem->getList('item_id', array('canuse_end_time|than' => time(), 'coupon_id' => $couponId));
         $pagedata['notEndItem'] = array_column($notEndItem, 'item_id');
     } else {
         $pagedata['notEndItem'] = array();
     }
     return response::json($pagedata);
 }
Beispiel #25
0
<?php

kirby()->routes([['pattern' => 'locations/json', 'action' => function () {
    $data = [];
    foreach (page('locations')->children()->visible() as $city) {
        $data['cities'][$city->uid()] = ['name' => $city->title()->toString(), 'state' => $city->state()->toString(), 'airports' => (new \collection($city->airports()->yaml()))->pluck('code'), 'lat' => (new \collection($city->location()->split(',')))->first(), 'lng' => (new \collection($city->location()->split(',')))->last(), 'rep' => $city->rep()->toString()];
        foreach ($city->airports()->toStructure() as $airport) {
            $data['locations'][] = ['title' => $airport->name()->toString(), 'airportCode' => $airport->code()->toString(), 'rep' => $city->rep()->toString()];
        }
    }
    foreach (page('reps')->children()->visible() as $rep) {
        $data['reps'][$rep->uid()] = ['name' => $rep->title()->toString(), 'email' => $rep->email()->toString(), 'phone' => $rep->phone()->toString()];
    }
    return response::json($data);
}]]);
Beispiel #26
0
/* Custom Panel Stylesheet
---------------------------------------
Define a custom stylesheet to load in to the panel. See:
getkirby.com/docs/cheatsheet/options/panel.stylesheet
*/
c::set('panel.stylesheet', 'assets/css/panel.css');
/* Kirby Configuration
---------------------------------------
By default you don't have to configure anything to
make Kirby work. For more fine-grained configuration
please check out getkirby.com/docs/advanced/options
and getkirby.com/blog/multi-environment-setup
*/
// Routes
//
c::set('routes', array(array('pattern' => '(:any)', 'method' => 'ALL', 'action' => function ($path) {
    if (!r::ajax()) {
        header::notfound();
        return site()->visit($path);
    }
    $page = page($path);
    $has_api_method = method_exists($page, 'api');
    return response::json(array('has_api_method' => $has_api_method));
}), array('pattern' => 'get/users.json', 'method' => 'ALL', 'action' => function () {
    // if(!r::ajax()) {
    // 	return header::forbidden();
    // }
    // $users = site()->users()->toArray();
    // $r = array_combine($users,site()->users()->toArray()); // format for kirby select field
    return response::json(array("first" => 'Rafe', "middle" => 'Jackson', "last" => 'Goldberg'));
})));
Beispiel #27
0
 public function ajaxTradeShow()
 {
     $postdata = input::get();
     $pagedata = $this->__getTrade($postdata);
     $data['html'] = view::make('topm/member/trade/listitem.html', $pagedata)->render();
     $data['pagers'] = $pagedata['pagers'];
     $data['success'] = true;
     return response::json($data);
     exit;
 }
 /**
  * Generate the controller response.
  *
  * @param   string  $msg   Optional message to send with the response.
  * @param   integer $code  Response code to send.
  * @param   array   $data  Data to return.
  *
  * @return  Response
  */
 protected function response($msg, $code, $data)
 {
     if (!r::is('ajax')) {
         return $this->redirect('back', $data);
     }
     $response = array('status' => 'error', 'data' => $data, 'code' => $code, 'message' => $msg);
     return response::json($response, $code);
 }
Beispiel #29
0
 /**
  * @brief 会员地址编辑
  *
  * @return html
  */
 public function ajaxAddrUpdate()
 {
     $params['addr_id'] = input::get('addr_id');
     $params['user_id'] = userAuth::id();
     $addrInfo = app::get('topc')->rpcCall('user.address.info', $params);
     list($regions, $region_id) = explode(':', $addrInfo['area']);
     $addrInfo['area'] = $regions;
     $addrInfo['region_id'] = str_replace('/', ',', $region_id);
     return response::json($addrInfo);
 }
kirby()->hook('panel.file.sort', function ($file) use($gitHelper) {
    $gitHelper->kirbyChange('sort(file): ' . $file->page()->uri() . '/' . $file->filename());
});
kirby()->hook('panel.file.delete', function ($file) use($gitHelper) {
    $gitHelper->kirbyChange('delete(file): ' . $file->page()->uri() . '/' . $file->filename());
});
if (c::get('gcapc-cron-hooks-enabled', true)) {
    kirby()->routes(array(array('pattern' => 'gcapc/(:any)', 'action' => function ($gitCommand) use($gitHelper) {
        switch ($gitCommand) {
            case "push":
                try {
                    $gitHelper->push();
                    echo response::json(array("status" => "success", "data" => null, "message" => "successfully pulled the content folder"));
                } catch (Exception $e) {
                    echo response::json(array("status" => "error", "data" => null, "message" => $e->getMessage()));
                }
                break;
            case "pull":
                try {
                    $gitHelper->pull();
                    echo response::json(array("status" => "success", "data" => null, "message" => "successfully pushed the content folder"));
                } catch (Exception $e) {
                    echo response::json(array("status" => "error", "data" => null, "message" => $e->getMessage()));
                }
                break;
        }
    })));
}
if (c::get('gcapc-panel-widget', true)) {
    $kirby->set('widget', 'git-commit-and-push-content', __DIR__ . DS . 'widgets' . DS . 'git-commit-and-push-content');
}