/**
  * Get all objects and their related variants for a section
  * @param $where
  * @param array $selectedColumns
  * @return mixed
  * @throws Exception
  * @since 08-01-2016
  * @author Dinanath Thakur <*****@*****.**>
  */
 public function getAllObjectsAndVariantsOfASectionWhere($where, $selectedColumns = ['*'])
 {
     if (func_num_args() > 0) {
         $where = func_get_arg(0);
         $cacheKey = $this->table . "::" . implode('-', array_flatten($where));
         if (cacheGet($cacheKey)) {
             return cacheGet($cacheKey);
         }
         //            die("no cache");
         DB::statement('SET SESSION group_concat_max_len = 10000');
         $result = DB::table($this->table)->join('settings_sections', 'settings_sections.section_id', '=', 'settings_objects.section_id')->join('settings_descriptions', 'settings_descriptions.object_id', '=', 'settings_objects.object_id')->leftJoin('settings_variants', 'settings_variants.object_id', '=', 'settings_objects.object_id')->leftJoin('settings_descriptions as sd', function ($join) {
             $join->on('sd.object_id', '=', 'settings_variants.variant_id');
         })->whereRaw($where['rawQuery'], isset($where['bindParams']) ? $where['bindParams'] : array())->select(DB::raw('settings_objects.object_id ,
             settings_objects.*,
             settings_sections.name AS section_name,
             settings_descriptions.value AS setting_name,
             settings_descriptions.tooltip,
             GROUP_CONCAT(DISTINCT(settings_variants.variant_id) ORDER BY settings_variants.position) AS variant_ids,
             GROUP_CONCAT(DISTINCT(BINARY settings_variants.name)  ORDER BY settings_variants.position  SEPARATOR "____") AS variant_names,
             GROUP_CONCAT(CASE sd.object_type WHEN "V" THEN sd.value END  ORDER BY settings_variants.position SEPARATOR "____") AS var_names'))->orderBy('settings_objects.position')->groupBy('settings_objects.object_id')->get();
         cachePut($cacheKey, $result, $this->minutes);
         return $result;
     } else {
         throw new Exception('Argument Not Passed');
     }
 }
 /**
  * Get all variant details
  * @param $where
  * @param array $selectedColumns
  * @return array|bool|object
  * @throws Exception
  * @since 06-01-2016
  * @author Dinanath Thakur <*****@*****.**>
  */
 public function getAllVariantWhere($where, $selectedColumns = ['*'])
 {
     if (func_num_args() > 0) {
         $where = func_get_arg(0);
         $cacheKey = $this->table . "::" . implode('-', array_flatten($where));
         if (cacheGet($cacheKey)) {
             return cacheGet($cacheKey);
         }
         $result = DB::table($this->table)->whereRaw($where['rawQuery'], isset($where['bindParams']) ? $where['bindParams'] : array())->select($selectedColumns)->get();
         cachePut($cacheKey, $result, $this->minutes);
         return $result;
     } else {
         throw new Exception('Argument Not Passed');
     }
 }
Exemplo n.º 3
0
function sqlGet($query)
{
    $result = cacheGet($query);
    if ($result !== false) {
        #echo "<b>Попадание в кеш:</b> $query<br>";
        #echo $result;
        return $result;
    } else {
        #echo "<b>Кеш не сработал:</b> $query<br>";
        $resource = sqlQuery($query);
        #$result = array();
        while ($row = mysql_fetch_assoc($resource)) {
            $result[] = $row;
        }
        cacheSet($query, $result, 3600);
        #echo $resource;
        return $result;
    }
}
Exemplo n.º 4
0
    echo "100 ERROR\n";
    dbgt("DATABASE ERROR: " . $db->ErrorMsg() . ": SQL=" . $sql);
    exit;
}
function dbExec($db, $sql)
{
    $rs = $db->Execute($sql);
    if (!$rs) {
        p_sqlfail($db, $sql);
    }
    return $rs;
}
if (false) {
    // xxx avoid the select id from call
    $uk = "{$username}-{$password}";
    $uid = cacheGet($uk);
    if (!$uid) {
        $uid = $db->GetOne("select id from users where username=\"{$username}\" and password=\"{$password}\"");
        cacheSet($uk, $uid, 3600);
    }
} else {
    $uid = $db->GetOne("select id from users where username=\"{$username}\" and password=\"{$password}\"");
}
if ($uid == "") {
    echo __LINE__ . " ERROR\n";
    dbgt("username/password lookup failed");
    exit;
}
if (false) {
    // xxx avoid the $db->MetaColumns call
} else {
Exemplo n.º 5
0
 private function doTb($tid, $cid = 0)
 {
     if ($tid == 2610) {
         //彩票部分
         $cacheId = 'doTb_' . $tid;
         $fcurl = cacheGet($cacheId);
         if (empty($fcurl)) {
             $url = 'http://www.114la.com/icai.json';
             $fcurl = XUtils::fcurl($url);
             cacheSet($cacheId, $fcurl, 3600);
         }
         $fcurl = substr($fcurl, 17, -1);
         $data_arr = json_decode($fcurl, TRUE);
         if (!empty($data_arr)) {
             //对应关系
             $dy = array('ssq' => array(220, 221, 222), 'dlt' => array(223, 224, 225), 'fc3d' => array(226, 227, 228), 'jx_11x5' => array(229, 230, 231));
             foreach ($data_arr as $tp => $v) {
                 $va = $v[0];
                 $fdata[$dy[$tp][0]] = array(0 => array('title' => '上期开奖号码', 'link' => $va['url'][0], 'opt_a' => implode(',', $va['result']), 'opt_b' => $va['phase'], 'opt_c' => $va['date']));
                 $fdata[$dy[$tp][1]] = array(0 => array('title' => '立即投注', 'link' => $va['url'][1]), 1 => array('title' => $va['chain'][0], 'link' => $va['chain'][1]));
                 foreach ($va['link'] as $vl => $tu) {
                     $tu['link'] = $tu['url'];
                     unset($tu['url']);
                     $va['link'][$vl] = $tu;
                 }
                 $fdata[$dy[$tp][2]] = $va['link'];
             }
         }
         if (!empty($fdata)) {
             foreach ($fdata as $cid => $cinfo) {
                 Links::model()->deleteAll("catalog_id=:cid", array(':cid' => $cid));
                 foreach ($cinfo as $info) {
                     try {
                         $model = new Links();
                         $info['catalog_id'] = $cid;
                         $info['title'] = empty($info['title']) ? '待定' : $info['title'];
                         $info['link'] = empty($info['link']) || $info['link'] == '#' ? 'http://www.114la.com/' : $info['link'];
                         $info['mix'] = empty($info['mix']) ? null : base64_decode($info['mix']);
                         $info = array_filter($info);
                         $model->attributes = $this->_form($info);
                         //                        ppr($model->attributes);
                         $model->save();
                     } catch (Exception $exc) {
                         return 'error1caipiao';
                     }
                 }
             }
         }
         return 'ok';
         //            ppr($fdata,1);
     } elseif ($tid == 1114) {
         //实时热点部分
         $cacheId = 'doTb_' . $tid;
         $fcurl = cacheGet($cacheId);
         if (empty($fcurl)) {
             $url = 'http://api4.114la.com/1114_2.json';
             $fcurl = XUtils::fcurl($url);
             cacheSet($cacheId, $fcurl, 3600);
         }
         $fcurl = substr($fcurl, 20, -1);
         //            ppr($fcurl,1);
         if (!empty($fcurl) && ($fcurl = json_decode($fcurl, 1))) {
             //先将对应的旧数据处理
             $old = reqPost('old');
             if (empty($old)) {
                 Links::model()->updateAll(array('status_is' => 'N'), "`catalog_id`='{$cid}'");
             } else {
                 Links::model()->deleteAll("catalog_id=:cid", array(':cid' => $cid));
             }
             //                ppr(Links::model()->findAll("`catalog_id`='$cid'"));
             foreach ($fcurl as $info) {
                 try {
                     $model = new Links();
                     $info['catalog_id'] = $cid;
                     $info['title'] = empty($info['title']) ? '待定' : $info['title'];
                     $info['link'] = empty($info['url']) || $info['url'] == '#' ? 'http://www.114la.com/' : $info['url'];
                     unset($info['url']);
                     $info = array_filter($info);
                     $model->attributes = $this->_form($info);
                     //                        ppr($model->attributes);
                     $model->save();
                 } catch (Exception $exc) {
                     return 'error1';
                 }
             }
             $cacheId = '_catalogAllNum';
             $catalogAllNum = XXcache::refresh($cacheId);
             return empty($catalogAllNum[$cid]) ? 0 : $catalogAllNum[$cid] . ' ok';
         } else {
             return 'error2';
         }
         ppr($data_arr, 1);
     } elseif ($tid > 1000 && $tid < 10000) {
         $tid = (int) $tid;
         $data = $re = 0;
         $cacheId = 'doTb_' . $tid;
         $fcurl = cacheGet($cacheId);
         if (empty($fcurl)) {
             $url = 'http://www.114la.com/api/ky.php?id=' . $tid . '&' . time();
             //                $url = 'http://www.114la.com/api/ky.php?id='.$tid;
             $fcurl = XUtils::fcurl($url);
             cacheSet($cacheId, $fcurl, 3600);
         }
         if (!empty($fcurl) && ($fcurl = json_decode($fcurl, 1))) {
             //先将对应的旧数据处理
             $old = reqPost('old');
             if (empty($old)) {
                 Links::model()->updateAll(array('status_is' => 'N'), "`catalog_id`='{$cid}'");
             } else {
                 Links::model()->deleteAll("catalog_id=:cid", array(':cid' => $cid));
             }
             //                ppr(Links::model()->findAll("`catalog_id`='$cid'"));
             foreach ($fcurl as $info) {
                 try {
                     $model = new Links();
                     $info['catalog_id'] = $cid;
                     $info['title'] = empty($info['title']) ? '待定' : $info['title'];
                     $info['link'] = empty($info['link']) || $info['link'] == '#' ? 'http://www.114la.com/' : $info['link'];
                     $info['mix'] = empty($info['mix']) ? null : base64_decode($info['mix']);
                     $info = array_filter($info);
                     $model->attributes = $this->_form($info);
                     //                        ppr($model->attributes);
                     $model->save();
                 } catch (Exception $exc) {
                     return 'error1';
                 }
             }
             $cacheId = '_catalogAllNum';
             $catalogAllNum = XXcache::refresh($cacheId);
             return empty($catalogAllNum[$cid]) ? 0 : $catalogAllNum[$cid] . ' ok';
         } else {
             return 'error2';
         }
     } else {
         return 'error3';
     }
 }
Exemplo n.º 6
0
/**
 * Renvoie la dernière version de WordPress
 */
function getWordPressVersion()
{
    $fileCache = 'wordpress';
    if (cacheState($fileCache, gCACHE_TIME_WORDPRESS) === FALSE) {
        $urlAPI = gWORDPRESS_API_CORE;
        $json = join('', file($urlAPI));
        $infos = json_decode($json, TRUE);
        cacheSet($fileCache, $infos);
    } else {
        $infos = cacheGet($fileCache);
    }
    return $infos;
}
 /**
  * Get setting value and cache the value for a day
  * @param string $settingObject
  * @return mixed
  * @throws Exception
  * @since 19-01-2016
  * @author Dinanath Thakur <*****@*****.**>
  */
 function getSetting($settingObject)
 {
     switch ($settingObject) {
         case 'price_symbol':
             $objCurrencyModel = \FlashSale\Http\Modules\Admin\Models\Currency::getInstance();
             $whereForPrice = ['rawQuery' => 'is_primary=? AND status=?', 'bindParams' => ['Y', 1]];
             $selectedColumns = ['symbol'];
             $cacheKey = "settings_objects::" . implode('-', array_flatten($whereForPrice));
             if (cacheGet($cacheKey)) {
                 $priceSymbol = cacheGet($cacheKey);
             } else {
                 $priceSymbol = $objCurrencyModel->getCurrencyWhere($whereForPrice, $selectedColumns);
                 cachePut($cacheKey, $priceSymbol, 86400);
             }
             $settingValue = $priceSymbol->symbol;
             break;
         default:
             $objSettingObject = \FlashSale\Http\Modules\Admin\Models\SettingsObject::getInstance();
             $whereForSettingObject = ['rawQuery' => 'name=?', 'bindParams' => [$settingObject]];
             $selectedColumns = ['value'];
             $cacheKey = "settings_objects::" . implode('-', array_flatten($whereForSettingObject));
             if (cacheGet($cacheKey)) {
                 $settingValue = cacheGet($cacheKey);
             } else {
                 $settingValue = $objSettingObject->getSettingObjectWhere($whereForSettingObject, $selectedColumns);
                 cachePut($cacheKey, $settingValue, 86400);
             }
             $settingValue = $settingValue->value;
             break;
     }
     return $settingValue;
 }
Exemplo n.º 8
0
function getconfig()
{
    global $config, $dbg;
    if (false) {
        $o = cacheGet("vtc.config");
        if (!$o) {
            //dbg("fetching config ...");
            $config = array();
            $rs = dbExec("select * from config");
            while ($o = $rs->FetchNextObj()) {
                $config[$o->tag] = $o->val;
            }
            cacheSet("vtc.config", $config, 10);
        } else {
            //dbg("returning cached config ...");
            $config = array();
            foreach ($o as $k => $v) {
                $config[$k] = $v;
            }
        }
    } else {
        $config = array();
        $rs = dbExec("select * from config");
        while ($o = $rs->FetchNextObj()) {
            $config[$o->tag] = $o->val;
        }
    }
    //dbg($config);
}
Exemplo n.º 9
0
        dbg("ERROR: {$o->error}");
        return null;
    }
    return $o->value;
}
function cacheSet($k, $o, $ttl = 0)
{
    global $cacheHost;
    $v = obj2json($o);
    $r = cache($cacheHost, array('act' => 'set', 'key' => $k, 'val' => $v, 'ttl' => (int) $ttl));
    //echo "(cacheSet($k, $v) returning $r)\n";
    return $r;
}
function cacheGet($k)
{
    global $cacheHost;
    $v = cache($cacheHost, array('act' => 'get', 'key' => $k));
    //echo "(cacheGet($k) returning ".($v === null ? "null" : $v).")\n";
    return $v;
}
if (false) {
    // test code
    $cc = "(from cache)";
    $v = cacheGet("foo");
    if ($v == null) {
        $v = 15;
        $cc = "";
        cacheSet("foo", $v, 10);
    }
    echo "v is {$v} {$cc}\n";
}