Beispiel #1
0
 public function authenticateRemoteUser($remoteUser)
 {
     $app = \App::getInstance();
     $authorized = f('auth.remoteAuthorize', $remoteUser);
     if ($authorized) {
         $users = \Norm\Norm::factory('User');
         $user = $users->findOne(array('username' => $remoteUser['username']));
         if (is_null($user)) {
             $user = $users->newInstance();
             $user['username'] = $remoteUser['username'];
             $user['first_name'] = $remoteUser['first_name'];
             $user['last_name'] = $remoteUser['last_name'];
             $user['birth_date'] = $remoteUser['birth_date'];
             $user['birth_place'] = $remoteUser['birth_place'];
         }
         if (!empty($remoteUser['normalized_username'])) {
             $user['normalized_username'] = $remoteUser['normalized_username'];
         }
         $user['email'] = $remoteUser['email'];
         $user['sso_account_id'] = $remoteUser['$id'];
         $user->save();
     } else {
         throw new \Exception('You are unauthorized to access this application. Please contact administrator.');
     }
     return $user->toArray();
 }
Beispiel #2
0
 public function doError($exception = null)
 {
     function setError($code, $msg)
     {
         http_response_code($code);
         return sprintf("%s%s", is_numeric($code) ? "<span style=\"color: red;\">{$code}</span> " : '', $msg);
     }
     function f($e)
     {
         if ($e instanceof ForbiddenException) {
             return setError(403, 'FORBIDDEN');
         } else {
             if ($e instanceof WrongMethodException) {
                 return setError(405, 'WRONG METHOD');
             } else {
                 if ($e instanceof BadRequestException) {
                     return setError(400, 'BAD REQUEST');
                 } else {
                     if ($e instanceof NotFoundException) {
                         return setError(404, 'NOT FOUND');
                     } else {
                         return setError(500, 'INTERNAL SERVER ERROR');
                     }
                 }
             }
         }
     }
     return '<div style="text-align: center; padding-top: 20px;">' . f($exception) . '</div>';
 }
Beispiel #3
0
 /**
  * 获取表字段信息
  *
  * @param string $table
  *
  * @return array|bool|void
  */
 public function getFields($table)
 {
     $name = c('database.database') . '.' . $table;
     //字段缓存
     if (!c('app.debug') && f($name, '[get]', 0, ROOT_PATH . '/storage/field')) {
         $data = f($name, '[get]', 0, ROOT_PATH . '/storage/cache/field');
     } else {
         $sql = "show columns from " . c('database.prefix') . $table;
         if (!($result = Db::query($sql))) {
             return [];
         }
         $data = [];
         foreach ((array) $result as $res) {
             $f['field'] = $res['Field'];
             $f['type'] = $res['Type'];
             $f['null'] = $res['Null'];
             $f['field'] = $res['Field'];
             $f['key'] = $res['Key'] == "PRI" && $res['Extra'] || $res['Key'] == "PRI";
             $f['default'] = $res['Default'];
             $f['extra'] = $res['Extra'];
             $data[$res['Field']] = $f;
         }
         f($name, $data, 0, ROOT_PATH . '/storage/field');
     }
     return $data;
 }
 /**
  * @role update
  */
 public function move()
 {
     $page = StaticPage::getInstanceById((int) $this->request->get('id'), StaticPage::LOAD_DATA);
     // update parent
     if ($this->request->get('parent')) {
         $parent = StaticPage::getInstanceById((int) $this->request->get('parent'), StaticPage::LOAD_DATA);
     } else {
         $parent = null;
     }
     $page->parent->set($parent);
     $page->save();
     // update order
     $f = new ARUpdateFilter();
     if ($parent) {
         $f->setCondition(eq(f('StaticPage.parentID'), $parent->getID()));
     } else {
         $f->setCondition(new IsNullCond(f('StaticPage.parentID')));
     }
     $f->addModifier('StaticPage.position', new ARExpressionHandle('position+2'));
     if ($this->request->get('previous')) {
         $previous = StaticPage::getInstanceById((int) $this->request->get('previous'), StaticPage::LOAD_DATA);
         $position = $previous->position->get();
         $f->mergeCondition(gt(f('StaticPage.position'), $position));
         $page->position->set($position + 1);
     } else {
         $previous = null;
         $page->position->set(1);
     }
     ActiveRecordModel::updateRecordSet('StaticPage', $f);
     $page->save();
     return new JSONResponse(array(), 'success', $this->translate('_pages_were_successfully_reordered'));
 }
 public function set(array $delete, array $cookies)
 {
     $pending = array();
     $f = function ($spec, $key, $val) use($pending) {
         if (!array_key_exists($spec, $pending)) {
             $pending[$spec] = array();
         }
         $pending[$spec][$key] = $val;
     };
     foreach ($delete as $key) {
         f(null, $key, '');
     }
     foreach ($cookies as $key => $data) {
         list($val, $spec) = $data;
         $f($spec, $key, $val);
     }
     $callback = $this->callback;
     foreach ($pending as $spec => $data) {
         if ($spec === null) {
             $spec = new CookieSpec();
         }
         $flags = $spec->secure ? extCookie::SECURE : 0;
         $flags += $spec->httponly ? extCookie::HTTPONLY : 0;
         $httpCookie = new extCookie(null, $flags);
         $httpCookie->setCookies($data);
         $httpCookie->setExpires($spec->expire);
         $httpCookie->setPath($spec->path);
         $httpCookie->setDomain($spec->domain);
         $callback($httpCookie->toString());
     }
     return true;
 }
 function rss()
 {
     $url = f('url');
     if (!$url) {
         $url = 'http://java5000.blogspot.com/feeds/posts/default?alt=rss';
     }
     require ROOT . 'lib/rss/lastRSS.php';
     $rss = new lastRSS();
     $str = $this->url2str($url, 1);
     if (!$str) {
         $data = $this->fmodel('rss')->peek(array('url' => $url));
         $data['valid'] = 2;
         $this->fmodel('rss')->save($data);
         $str = "";
     } else {
         cacheme($url, $str);
     }
     $result = $rss->ParseStr($str);
     if ($result["encoding"] && strcasecmp($result["encoding"], "utf-8") != 0) {
         $result = $rss->ParseStr(mb_convert_encoding($str, "UTF-8", $result["encoding"]));
     }
     foreach ($result["items"] as &$i) {
         $i["description"] = html_entity_decode($i["description"]);
         $i["description"] = preg_replace('/< *br *[\\/]?>/', "\n", $i["description"]);
         $i["description"] = preg_replace('|href=("?)|i', 'target=_blank href=${1}/self/out/rd?url=', $i["description"]);
         $i["link"] = preg_replace('/>$/', "", $i["link"]);
         if (!preg_match('/^https?\\:/', $i["link"])) {
             $i["link"] = "http://www.google.com/search?q=" . urlencode($i["title"]);
         }
     }
     $this->sv("rssresult", $result);
     $rsslist = $this->fmodel('rss')->peeks(array('valid' => 1));
     $this->sv("rssfeed", array_reverse($rsslist));
 }
Beispiel #7
0
 private function replaceFields($item)
 {
     // SEARCH {} IN TEMPLATE
     preg_match_all('`{([A-Za-z0-9\\._\\x7f-\\xff]+?)}`', $this->tpl, $results);
     if (!$results) {
         return;
     }
     $results[0] = array_unique($results[0]);
     $results[1] = array_unique($results[1]);
     foreach ($results[0] as $key => $value) {
         // ONLY FOR PHPTHUMB AND JCROP
         if ($results[1][$key] == 'phptParams') {
             if ($item['cropCords']) {
                 $this->copyTpl = preg_replace('/' . $value . '/', $this->phpt->getCropParams($item['cropCords']), $this->copyTpl);
             } else {
                 $this->copyTpl = preg_replace('/' . $value . '/', $this->phpt->getParams(), $this->copyTpl);
             }
         }
         // RETURN WIDTH AND HEIGHT ATTR OF IMG
         if ($results[1][$key] == 'imgSize') {
             $this->copyTpl = preg_replace('/' . $value . '/', $this->phpt->getImgDimentions(), $this->copyTpl);
         }
         // ITERATE ALL {} FOUND IN TEMPLATE
         $this->copyTpl = preg_replace('/' . $value . '/', f($item[$results[1][$key]]), $this->copyTpl);
     }
 }
Beispiel #8
0
function foo()
{
    $obj = new C();
    $obj->a = f();
    $obj->b = new C();
    $obj->b->a = f();
}
Beispiel #9
0
function foo($a)
{
    (yield 1);
    foreach ((array) f($a) as $x) {
        var_dump('i:' . $x);
    }
}
Beispiel #10
0
 function fetch($tpl = '')
 {
     // 模板文件
     T('POEM_COMPILE_TIME');
     $tpl = $this->parseTpl($tpl);
     $filekey = str_replace(APP_PATH, '', $tpl);
     // 文件名 Home/Index/index.html
     $c_w_v_tpl = f($filekey, '', 2);
     // 判断是否存在
     if (APP_DEBUG || $c_w_v_tpl === false) {
         $content = file_get_contents($tpl);
         // 开启页面布局
         if (($layfile = config('layout')) && config('layout_on') === true) {
             $layfile = $this->parseTpl($layfile);
             $content = str_replace('{__LAYOUT__}', $content, file_get_contents($layfile));
         }
         $content = $this->compiler($content);
         // 模板编译
         $c_w_v_tpl = f($filekey, $content);
         // F($filekey, php_strip_whitespace($c_w_v_tpl) ); // 去掉空格什么的
     }
     T('POEM_COMPILE_TIME', 0);
     // 模板变量
     if (!empty($this->html_vars)) {
         extract($this->html_vars);
     }
     $this->html_vars = array();
     // 清空
     // 缓冲区
     ob_start();
     ob_implicit_flush(0);
     include $c_w_v_tpl;
     // 获取并清空缓存
     return ob_get_clean();
 }
Beispiel #11
0
function get_aid_by_name($name)
{
    $s = q("SELECT * FROM aid WHERE name = '" . clean_query($name) . "' limit 1;");
    if (a() > 0) {
        return f($s);
    }
}
Beispiel #12
0
 public function __construct()
 {
     Language::read("common");
     Language::read("microshop");
     if (c("microshop_isuse") != "1") {
         header("location: " . SiteUrl);
         exit;
     }
     Tpl::setdir("default");
     self::cp();
     Tpl::setlayout("microshop_layout");
     if ($_GET['column'] && strtoupper(CHARSET) == "GBK") {
         $GLOBALS['_GET'] = Language::getgbk($_GET);
     }
     Tpl::output("nav_list", ($nav = f("nav")) ? $nav : h("nav", TRUE, "file"));
     $search_type = array();
     $search_type['goods'] = Language::get("nc_microshop_goods");
     $search_type['personal'] = Language::get("nc_microshop_personal");
     $search_type['store'] = Language::get("nc_microshop_store");
     Tpl::output("search_type", $search_type);
     if (!empty($_SESSION['member_id']) || 0 < intval($_SESSION['member_id'])) {
         self::get_member_avatar($_SESSION['member_id']);
     }
     if (!c("site_status")) {
         halt(c("closed_reason"));
     }
     Tpl::output("html_title", Language::get("nc_microshop") . "-" . c("site_name"));
     Tpl::output("seo_keywords", c("microshop_seo_keywords"));
     Tpl::output("seo_description", c("microshop_seo_description"));
     $this->queryCart();
 }
Beispiel #13
0
function f($a, $b)
{
    echo number_format($a, 0, '', '') . '<br>' . number_format($b, 0, '', '') . '<br>';
    $a = $a + $b;
    $b = $a + $b;
    f($a, $b);
}
Beispiel #14
0
function pr(...$args)
{
    return f(function ($a) {
        echo $a, "\n";
        return $a;
    }, ...$args);
}
Beispiel #15
0
 public function getSelectFilter($disableFilters = false)
 {
     $selectFilter = $this->category->getProductsFilter($this, false);
     $selectFilter->merge($this->productFilter);
     $cond = null;
     $list = array();
     // group filters by class
     foreach ($this->filters as $filter) {
         if ($disableFilters && !$filter instanceof SearchFilter) {
             continue;
         }
         $id = $filter instanceof SpecificationFilterInterface ? $filter->getFilterGroup()->getID() : '';
         $list[get_class($filter) . '_' . $id][] = $filter->getCondition();
         $filter->defineJoin($selectFilter);
     }
     // convert filter group to OrChainCondition
     foreach ($list as &$filterGroup) {
         $filterGroup = new OrChainCondition($filterGroup);
     }
     if ($fCond = $selectFilter->getCondition()) {
         $list[] = $fCond;
     }
     $selectFilter->setCondition(new AndChainCondition($list));
     // all merged with and
     $selectFilter->setOrder(f('Product.ID'), 'DESC');
     ActiveRecordModel::getApplication()->processInstancePlugins('finalProductFilter', $selectFilter);
     return $selectFilter;
 }
Beispiel #16
0
 private static function parse_conf(&$setting_config)
 {
     $nc_config = $GLOBALS['config'];
     if (is_array($nc_config['db']['slave']) && !empty($nc_config['db']['slave'])) {
         $dbslave = $nc_config['db']['slave'];
         $sid = array_rand($dbslave);
         $nc_config['db']['read'] = $dbslave[$sid];
     } else {
         $nc_config['db']['read'] = $nc_config['db'][1];
     }
     $nc_config['db']['write'] = $nc_config['db'][1];
     $setting_config = $nc_config;
     $setting = ($setting = f("setting")) ? $setting : h("setting", TRUE, "file");
     if ($nc_config['thumb']['save_type'] == 1) {
         $nc_config['thumb_url'] = SiteUrl;
     } else {
         if ($nc_config['thumb']['save_type'] == 2 && preg_match("/^http:\\/\\/[\\.\\-\\w]+/", $nc_config['thumb']['url'])) {
             $nc_config['thumb_url'] = $nc_config['thumb']['url'];
         } else {
             if ($nc_config['thumb']['save_type'] == 3 && $setting['ftp_open']) {
                 $nc_config['thumb_url'] = $setting['ftp_access_url'];
             } else {
                 $nc_config['thumb_url'] = SiteUrl;
             }
         }
     }
     $setting_config = array_merge_recursive($setting, $nc_config);
 }
Beispiel #17
0
 public function getExtraFilteringMapping()
 {
     if (count($this->extraFilteringMapping) == 0) {
         $this->extraFilteringMapping = array('id' => array(self::AR_FIELD_HANDLE => f('User.ID'), self::AR_CONDITION => 'EqualsCond'), 'name' => array(self::AR_FIELD_HANDLE => new ARExpressionHandle("CONCAT(User.firstName,' ',User.lastName)"), self::AR_CONDITION => 'LikeCond'), 'created' => array(self::AR_FIELD_HANDLE => f('User.dateCreated'), self::AR_CONDITION => 'EqualsCond'), 'enabled' => array(self::AR_FIELD_HANDLE => f('User.isEnabled'), self::AR_CONDITION => 'EqualsCond'));
     }
     return $this->extraFilteringMapping;
 }
Beispiel #18
0
 public function process()
 {
     if (!$this->response instanceof ActionResponse) {
         return;
     }
     $products = $this->response->get('products');
     $ids = array();
     foreach ($products as $key => $product) {
         $ids[$product['ID']] = !empty($product['parentID']) ? $product['parentID'] : $product['ID'];
     }
     if (!$ids) {
         return;
     }
     $f = select(in(f('ProductImage.productID'), array_values($ids)), new LikeCond(f('ProductImage.title'), '%Virtual Mirror%'));
     $hasMirror = array();
     foreach (ActiveRecordModel::getRecordSetArray('ProductImage', $f) as $mirror) {
         $hasMirror[$mirror['productID']] = true;
     }
     foreach ($ids as $realID => $parentID) {
         if (!empty($hasMirror[$parentID])) {
             $hasMirror[$realID] = true;
         }
     }
     foreach ($products as $key => $product) {
         if ($hasMirror[$product['ID']]) {
             $products[$key]['hasMirror'] = true;
         }
     }
     $this->response->set('hasMirror', $hasMirror);
     $this->response->set('products', $products);
 }
Beispiel #19
0
    public function home()
    {
        global $user;
        $v = $this->__(w('alias filename ext'));
        if (!f($v['alias']) || !f($v['filename'])) {
            _fatal();
        }
        $sql = 'SELECT tree_id
			FROM _tree
			WHERE tree_alias = ?';
        if (!($tree = _fieldrow(sql_filter($sql, $v['alias'])))) {
            _fatal();
        }
        $sql = 'SELECT *
			FROM _downloads
			WHERE download_alias = ?
				AND download_tree = ?';
        if (!($download = _fieldrow(sql_filter($sql, $v['filename'], $tree['tree_id'])))) {
            _fatal();
        }
        if ($download['download_login']) {
            _login();
        }
        $sql = 'UPDATE _downloads SET download_count = download_count + 1
			WHERE download_id = ?';
        _sql(sql_filter($sql, $download['download_id']));
        $filepath = LIB . 'fetch/' . _filename($download['download_id'], $download['download_extension']);
        return;
    }
Beispiel #20
0
    public function home()
    {
        $v = $this->__(array('category' => '', 'faq' => 0));
        if (f($v['category'])) {
            $sql = 'SELECT *
				FROM _faq_categories
				ORDER BY cat_order';
            $category = _rowset($sql);
            if (!count($category)) {
                _fatal();
            }
            foreach ($category as $i => $row) {
                if (!$i) {
                    _style('category');
                }
                _style('category.row', array('CAT_SUBJECT' => $row['cat_subject'], 'CAT_ALIAS' => _link('help', $row['help_alias'])));
            }
        }
        if ($v['faq']) {
            $sql = 'SELECT *
				FROM _help_faq
				WHERE faq_id = ?';
            if (!($faq = _fieldrow(sql_filter($sql, $v['faq'])))) {
                _fatal();
            }
        }
        return;
    }
Beispiel #21
0
 public function getCondition()
 {
     // analyze search query
     // find exact phrases first
     $query = $this->query;
     preg_match_all('/"(.*)"/sU', $query, $matches);
     $phrases = array();
     if ($matches[1]) {
         $phrases = $matches[1];
     }
     $query = $this->getCleanedQuery($query);
     $phrases = array_merge($phrases, explode(' ', $query));
     $searchFields = array('name', 'keywords', 'shortDescription', 'longDescription', 'sku');
     $conditions = array();
     foreach ($phrases as $phrase) {
         $searchCond = null;
         foreach ($searchFields as $field) {
             $cond = new LikeCond(new ARFieldHandle('Product', $field), '%' . $phrase . '%');
             if (!$searchCond) {
                 $searchCond = $cond;
             } else {
                 $searchCond->addOr($cond);
             }
         }
         $conditions[] = $searchCond;
     }
     $condition = new AndChainCondition($conditions);
     $vc = new IsNotNullCond(f('Product.parentID'));
     $vc->addAND(new LikeCond(new ARExpressionHandle('(SELECT name FROM Product as searchvar WHERE Product.parentID=searchvar.ID)'), '%' . $phrase . '%'));
     ActiveRecordModel::getApplication()->variationCond = $vc;
     ActiveRecordModel::getApplication()->processInstancePlugins('searchFilter', $condition);
     return $condition;
 }
Beispiel #22
0
function test()
{
    global $a;
    $a[f(0)]->{f(1)}[f(2)] = $a[f(3)][f(4)][f(5)]->foo;
    var_dump($a[f(6)]['fuz'] . f(7));
    ref($a[f(10)][f(11)][f(12)], $a[f(20)][f(21)][f(22)], $a[f(30)][f(31)][f(32)]);
    $a->{f(0)}[f(1)]->{f(2)} = $a->{f(3)}->{f(4)}->bar;
}
Beispiel #23
0
function main()
{
    try {
        f(1);
    } catch (Exception $e) {
    }
    echo "Done\n";
}
Beispiel #24
0
function raund($arrayOFchisla, $n, $loe, $key)
{
    $b = array();
    for ($i = 1; $i < n; $i++) {
        $b[i] = f($i, $arrayOFchisla, $n, $loe, $key);
    }
    return $b[i];
}
Beispiel #25
0
function get_product_by_name($name)
{
    $s = q("select * from product where name = '" . clean_query($name) . "' limit 1;");
    if (a($s) > 0) {
        return f($s);
    }
    return false;
}
Beispiel #26
0
 function foo()
 {
     try {
         f();
     } catch (Exception $this) {
         return $this;
     }
 }
Beispiel #27
0
function get_family_by_id($clientid)
{
    $s = q("select * from family, client where client.clientid = family.clientid and family.clientid = '" . clean_query($clientid) . "';");
    if (n($s) > 0) {
        return f($s);
    }
    return null;
}
Beispiel #28
0
function get_user_by_username($username)
{
    $s = q("select * from user where user.username = '******' limit 1;");
    if (n($s) > 0) {
        return f($s);
    }
    return null;
}
Beispiel #29
0
 public static function getRecordCount($locale = null)
 {
     $filter = new ARSelectFilter();
     if ($locale) {
         $filter->mergeCondition(eq(f(__CLASS__ . '.locale'), $locale));
     }
     return ActiveRecordModel::getRecordCount(__CLASS__, $filter);
 }
 function webproxy()
 {
     if (f('pass') == "fsidl734gjdf9230742o423hlfs890") {
         echo $this->url2str(f('url'));
         exit;
     }
     $this->do404();
 }