示例#1
0
文件: Content.php 项目: speedwork/app
 public function index($content, $break = false)
 {
     if (!$this->enable) {
         return $content;
     }
     $pattern = '#src="uploads([^"]+)"#iU';
     if (preg_match_all($pattern, $content, $matches)) {
         foreach ($matches[0] as $key => $value) {
             $content = str_replace($value, 'src="' . _PUBLIC . 'uploads' . $matches[1][$key] . '"', $content);
         }
     }
     //replace gallery plugin tage with gallery
     //<!-- <speed:module name="banners.slider" id="1" /> -->
     $pattern = '#<speed:(module|component) name="([^"]+)" (.*)\\/>#iU';
     $matches = [];
     if (preg_match_all($pattern, $content, $matches)) {
         foreach ($matches[0] as $k => $v) {
             $type = $matches[1][$k];
             $m = $matches[2][$k];
             $attr = $matches[3][$k];
             $attribs = $attr;
             $return = '';
             if ($attr) {
                 $attr = Utility::parseXmlAttributes($attr);
             }
             $m1 = explode('.', $m);
             $name = $m1[0];
             $attr['view'] = $m1[1];
             if ($type == 'module' && $name) {
                 $return = $this->renderModule($name, $attr);
             }
             if ($type == 'component' && $name) {
                 $return = $this->renderComponent($name, $attr);
             }
             $match = '<!-- <speed:' . $type . ' name="' . $m . '" ' . trim($attribs) . ' /> -->';
             $content = str_replace($match, $return, $content);
         }
     }
     if ($break) {
         $pattern = '<!-- pagebreak -->';
         $content = explode($pattern, $content, 2);
         $content = $content[0];
     }
     return $content;
 }
示例#2
0
 public function ajax($url = null, $total = 0, $params = [])
 {
     $is_api = $this->get('is_api_request');
     if ($is_api) {
         return false;
     }
     if (is_array($total)) {
         $params = $total;
         $total = 0;
     }
     $is_ajax = $this->get('is_ajax_request');
     $ajax = [];
     $ajax['enable'] = $is_ajax === true ? false : true;
     $ajax['disable'] = $ajax['enable'];
     $form = [];
     $url = empty($url) ? Utility::currentUrl() : $this->link($url);
     $method = strtoupper($params['method']);
     $method = $method && in_array($method, ['POST', 'GET']) ? $method : 'POST';
     unset($params['method']);
     $start = '<form id="ajax_form" method="' . $method . '" action="' . $url . '">';
     $end = '</form>';
     $start .= '<input type="hidden" id="page" name="page" value="1" />';
     $start .= '<input type="hidden" id="total" name="total" value="' . $total . '" />';
     foreach ($params as $k => $v) {
         $mid .= '<input type="hidden" name="' . $k . '" value="' . $v . '" />';
     }
     $ajax['form'] = $start . $mid . $end;
     $ajax['start'] = $start . $mid;
     $ajax['end'] = $end;
     $class = 'render-' . uniqid();
     $params['class'] = '.' . $class;
     $start = '<form role="render" class="' . $class . '" method="' . $method . '" action="' . $url . '">';
     $form['start'] = $start . $mid;
     $form['params'] = $mid;
     $form['end'] = $end;
     $form['class'] = $params['class'];
     $ajax['fm'] = $form;
     $params['total'] = $total;
     $params['url'] = $url;
     $ajax['params'] = $params;
     $this->assign('ajax', $ajax);
 }
示例#3
0
 public function parseUrl($url)
 {
     $parts = Utility::parseQuery($url);
     $save['option'] = $parts['option'];
     $save['view'] = $parts['view'];
     $save['option'] = str_replace('com_', '', $save['option']);
     if (empty($save['uniqueid'])) {
         //get config
         $conf = config('view.metainfo.config');
         $k = $save['option'] . ':' . $save['view'];
         $key = $conf[$k];
         $uniqid = $key['uniqid'];
         if ($uniqid == '') {
             $key = $conf[$save['option'] . ':*'];
             $uniqid = $key['uniqid'];
         }
         $save['uniqueid'] = $parts[$uniqid];
     }
     if (empty($save['option'])) {
         return false;
     }
     return $save;
 }
示例#4
0
 /**
  * Convert time to proper format.
  *
  * @param string $time
  * @param bool   $date
  * @param string $format
  *
  * @return string
  */
 public function toTime($time, $date = false, $format = 'Y-m-d')
 {
     return Utility::strtotime($time, $date, $format);
 }
示例#5
0
 /**
  * Functions to validate request.
  *
  * @param array &$request Element array
  * @param bool  $sig      Flag to specify force authentication
  * @param bool  $useronly Flag to check user only
  *
  * @return bool response
  **/
 protected function validate()
 {
     $api_key = $this->input('api_key');
     if (!$api_key) {
         return ['A402' => trans('Api Key not found')];
     }
     $secret = $this->getSecret($api_key);
     if ($secret === false) {
         return ['A404' => trans('Your api account got suspended')];
     }
     if ($secret['signature']) {
         $signature = $this->input('signature');
         if (!$signature) {
             return ['A403' => trans('Api Signature not found')];
         }
     }
     if ($secret['signature'] && !$secret['api_secret']) {
         return ['A405' => trans('Api secret not found')];
     }
     $secret['api_key'] = $api_key;
     if ($secret['allowed_ip']) {
         $ipaddr = ip();
         $allowed = explode(',', $secret['allowed_ip']);
         $allowed = array_map('trim', $allowed);
         if (!in_array($ipaddr, $allowed)) {
             $result = Utility::ipMatch($allowed);
             if (!$result) {
                 return ['A406' => trans('Request is not allowed from this ip :0', [$ipaddr])];
             }
         }
     }
     if ($secret['header']) {
         if (env($secret['header']['custom_key']) != $secret['header']['custom_value']) {
             return ['A407' => trans('Header misconfigured')];
         }
     }
     if ($secret['protocol']) {
         if (env('HTTPS') && env('HTTPS') == 'off' || env('SERVER_PORT') != 443) {
             return ['A407A' => trans('Protocol not allowed')];
         }
     }
     return ['status' => 'OK', 'data' => $secret];
 }