Ejemplo n.º 1
0
 /**
  * Fetch HTML
  *
  * @param string $tpl
  * @param string $dir
  */
 public function fetch($tpl = null, $dir = null)
 {
     try {
         if ($this->_cacheKey && empty($this->_cache)) {
             $this->initCache();
         }
         if ($this->_cacheKey && $this->_cache && ($data = $this->_cache->get($this->_cacheKey))) {
             return $data;
         }
         $this->_init($this->_arg);
         foreach ($this->_update as $key => $value) {
             $this->view->{$key} = $value;
         }
         if (empty($tpl)) {
             $tpl = $this->defaultTemplate();
         }
         if (empty($dir)) {
             $dir = Cola::config('_widgetsHome');
         }
         $data = $this->view->fetch($tpl, $dir);
         if ($this->_cacheKey && $this->_cache) {
             $this->_cache->set($this->_cacheKey, $data);
         }
     } catch (Exception $e) {
         $data = '';
     }
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * Singleton instance
  *
  * @return Cola
  */
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Ejemplo n.º 3
0
 /**
  * Match path
  *
  * @param string $path
  * @return boolean
  */
 public function match($pathInfo = null)
 {
     $pathInfo = trim($pathInfo, '/');
     foreach ($this->rules as $regex => $rule) {
         if (!preg_match($regex, $pathInfo, $matches)) {
             continue;
         }
         if (isset($rule['maps']) && is_array($rule['maps'])) {
             $params = array();
             foreach ($rule['maps'] as $pos => $key) {
                 if (isset($matches[$pos]) && '' !== $matches[$pos]) {
                     $params[$key] = urldecode($matches[$pos]);
                 }
             }
             if (isset($rule['defaults'])) {
                 $params += $rule['defaults'];
             }
             Cola::setReg('_params', $params);
         }
         return $rule;
     }
     if ($this->enableDynamicMatch) {
         return $this->dynamicMatch($pathInfo);
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * Retrieve a member of the pathinfo params
  *
  * @param string $key
  * @param mixed $default
  * @return mixed
  */
 public static function param($key = null, $default = array())
 {
     $params = (array) Cola::reg('_params');
     if (null === $key) {
         return $params;
     }
     return isset($params[$key]) ? $params[$key] : $default;
 }
Ejemplo n.º 5
0
 /**
  * Dynamic get helper
  *
  * @param string $key
  */
 public function __get($key)
 {
     $className = 'Cola_Helper_' . ucfirst($key);
     if (Cola::loadClass($className)) {
         return $this->{$key} = new $className();
     } else {
         throw new Exception("No helper like {$key} defined");
     }
 }
Ejemplo n.º 6
0
 /**
  * Dynamic get Component
  *
  * @param string $key
  */
 public function __get($key)
 {
     $className = 'Cola_Com_' . ucfirst($key);
     if (Cola::loadClass($className)) {
         return $this->{$key} = new $className();
     } else {
         throw new Cola_Exception("No component like {$key} defined");
     }
 }
Ejemplo n.º 7
0
 /**
  * Widget
  *
  * @param string $name
  * @param array $data
  * @return Cola_Com_Widget
  */
 public function widget($name, $data = null)
 {
     if (empty($this->_widgetsHome) && ($widgetsHome = Cola::config('_widgetsHome'))) {
         $this->_widgetsHome = $widgetsHome;
     }
     $class = ucfirst($name) . 'Widget';
     if (!Cola::loadClass($class, $this->_widgetsHome)) {
         throw new Cola_Exception("Can not find widget:{$class}");
     }
     $widget = new $class($data);
     return $widget;
 }
Ejemplo n.º 8
0
 /**
  * 删除订单
  */
 public function delAction()
 {
     if (ComTool::isAjax()) {
         if (!$this->isLogin()) {
             ComTool::ajax(Cola::getConfig('_error.mustlogin'), '请先登录,即将跳转至登录页面');
         }
         $currUser = $this->getCurrentUser();
         $orderId = $this->post('oid', '');
         if (!$orderId) {
             ComTool::ajax(100001, '未知订单');
         }
         $orderId = ComTool::escape($orderId);
         $updateTime = time();
         $sql = "update `order` set `status`=4,update_time='{$updateTime}' where id='{$orderId}' and user_id='{$currUser['id']}'";
         $res = OrderData::sql($sql);
         if ($res === false) {
             ComTool::ajax(100001, '服务器忙,请重试');
         }
         //暂时不删除订单详情(order_detail表)
         ComTool::ajax(100000, 'ok');
     }
 }
 /**
  * Get var
  *
  * @param sting $key
  * @param mixed $default
  */
 protected function getVar($key = null, $default = null)
 {
     if (null === $key) {
         return array_merge(Cola::reg('_params', null, array()), $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV);
     }
     $funcs = array('param', 'get', 'post', 'cookie', 'server', 'env');
     foreach ($funcs as $func) {
         if (null !== ($return = $this->request->{$func}($key))) {
             return $return;
         }
     }
     return $default;
 }
Ejemplo n.º 10
0
 /**
  * Dynamic get vars
  *
  * @param string $key
  */
 public function __get($key)
 {
     switch ($key) {
         case 'config':
             $this->config = Cola::getInstance()->config;
             return $this->config;
         default:
             return null;
     }
 }
Ejemplo n.º 11
0
 /**
  * Instantiated model
  *
  * @param string $name
  * @param string $dir
  * @return Cola_Model
  */
 protected function model($name, $dir = null)
 {
     null === $dir && ($dir = Cola::config('_modelsHome'));
     $class = ucfirst($name) . 'Model';
     if (Cola::loadClass($class, $dir)) {
         return new $class();
     }
     throw new exception("Can't load model '{$class}' from '{$dir}'");
 }
Ejemplo n.º 12
0
 /**
  * Dynamic get vars
  *
  * @param string $key
  */
 public function __get($key)
 {
     switch ($key) {
         case 'db':
             $this->db = $this->db();
             return $this->db;
         case 'cache':
             $this->cache = $this->cache();
             return $this->cache;
         case 'config':
             $this->config = Cola::getInstance()->config;
             return $this->config;
         default:
             throw new Cola_Exception('Undefined property: ' . get_class($this) . '::' . $key);
     }
 }
Ejemplo n.º 13
0
 public function generate(swoole_process $worker)
 {
     $job = $worker->sitemap_job;
     //先判断这个job是否为空;
     if (empty($job)) {
         exit(0);
     }
     //需要新的mysql连接
     $config = (array) Cola::config()->get('_db') + array('adapter' => 'Mysql', 'params' => array());
     $db = Cola_Com_Db::factory($config);
     $this->cola_db = $db;
     //取出keys
     $files = array_keys($job);
     foreach ($files as $file) {
         //open this file , w+;不存在就创建,并且truncate文件
         $fileHandler = fopen($file, 'w+');
         $this->writeHeader($fileHandler);
         $low_id = $job[$file]['low'];
         $high_id = $job[$file]['high'];
         // count,从low到high有多少条记录
         $count = $this->countPic($low_id, $high_id);
         $times = $count / self::BUFFER_ROW;
         //如果times为0,也会运行一次$offset=0,可以达到目的
         foreach (range(0, $times) as $index) {
             $offset = $index * self::BUFFER_ROW;
             $pics = $this->selectPics($offset, $low_id, $high_id);
             $buffer_string = $this->fetchView($pics);
             fwrite($fileHandler, $buffer_string);
         }
         $this->writeFooter($fileHandler);
         fflush($fileHandler);
         fclose($fileHandler);
     }
 }
Ejemplo n.º 14
0
<?php

require_once '../negocio/Cola.php';
require_once '../util/Funciones.clase.php';
$id_lugar = $_POST["id_lugar"];
$c_estado = $_POST["c_estado"];
$user_dni = $_POST["user_dni"];
if (isset($id_lugar) && isset($c_estado) && isset($user_dni)) {
    try {
        $obj = new Cola();
        $resultado = $obj->registrarEstadoCola($c_estado, $id_lugar, $user_dni);
        if ($resultado) {
            Funciones::imprimeJSON(200, "Registro estado correcto", $resultado);
        } else {
            Funciones::imprimeJSON(500, "Surgió un problema inténlo luego", $resultado);
        }
    } catch (Exception $exc) {
        Funciones::imprimeJSON(500, $exc->getMessage(), "");
    }
} else {
    $error = array('estado' => 500, 'mesaje' => "Error al Ingresar los Datos!", 'datos' => "");
    echo json_encode($error);
}
Ejemplo n.º 15
0
<?php

require_once '../negocio/Cola.php';
require_once '../util/Funciones.clase.php';
$id_lugar = $_POST["id_lugar"];
if (isset($id_lugar)) {
    try {
        $obj = new Cola();
        $resultado = $obj->listarEstadoCola($id_lugar);
        Funciones::imprimeJSON(200, "Listado Correcto", $resultado);
    } catch (Exception $exc) {
        Funciones::imprimeJSON(500, $exc->getMessage(), "");
    }
} else {
    $error = array('estado' => 500, 'mesaje' => "no ha ingresado un ID de un lugar", 'datos' => "");
    echo json_encode($error);
}
    public function push(swoole_process $worker){
        $job = null;
        if(isset($worker->sitemap_job)){
            $job = $worker->sitemap_job;
        }
        //先判断这个job是否为空;
        if(empty($job)){
            exit(0);
        }
        //需要新的mysql连接
        $config = (array)Cola::config()->get('_db') + array('adapter' => 'Mysql', 'params' => array());
        $db = Cola_Com_Db::factory($config);
        $this->cola_db = $db;

        //取出keys
        $files = array_keys($job);
        foreach($files as $file){
            $low_id = $job[$file]['low'];
            $high_id = $job[$file]['high'];
            // count,从low到high有多少条记录
            $count = $this->countPic($low_id, $high_id);
            $times = $count/self::BUFFER_ROW;
            //如果times为0,也会运行一次$offset=0,可以达到目的
            foreach(range(0, $times) as $index){
                $offset = $index*self::BUFFER_ROW;
                $pics = $this->selectPics($offset, $low_id, $high_id);
                $this->pushToBaidu($pics);
            }
        }

    }
Ejemplo n.º 17
0
 static function delete($name)
 {
     self::set($name, '', -3600);
     $prefix = Cola::getConfig("_cookie.COOKIE_PREFIX");
     unset($_COOKIE[$prefix . $name]);
 }
Ejemplo n.º 18
0
<?php

error_reporting(E_ALL);
define('APP_DIR', dirname(__FILE__));
require '../Cola/Cola.php';
require './config.inc.php';
$cola = Cola::getInstance();
// 获得类名
if (isset($_GET['c'])) {
    $className = ucfirst($_GET['c']) . 'Controller';
} else {
    $className = 'IndexController';
}
// 获得方法名
if (isset($_GET['a'])) {
    $actionName = $_GET['a'] . 'Action';
} else {
    $actionName = 'indexAction';
}
try {
    Cola::loadClass($className, './controllers');
    $dispatchInfo = array('controller' => $className, 'action' => $actionName);
    $cola->setDispatchInfo($dispatchInfo);
    $cola->dispatch();
} catch (Exception $e) {
    // 处理404
    header("HTTP/1.0 404 Not Found");
    header("Status: 404 Not Found");
    header('Location:404.html');
}
Ejemplo n.º 19
0
 public function runAction()
 {
     //get log id
     $pic_id = intval($this->getLogId());
     //die(var_dump($pic_id));
     //取得为标签图片(id, url)
     $workerNum = 5;
     $limit = 20;
     $totalCount = $this->countUntaggedPic($pic_id);
     $partTotalCount = $totalCount / $workerNum;
     $jobs = $this->calculateJob($totalCount, $workerNum, $pic_id);
     var_dump($jobs);
     if ($jobs) {
         foreach ($jobs as $index => $range) {
             $pid = pcntl_fork();
             if (!$pid) {
                 //子进程
                 $endId = $range['endId'];
                 if (file_exists(ROOT_DIR . "/sbin/child_pic_id_{$index}.log")) {
                     $pid_log_file = fopen("child_pic_id_{$index}.log", 'r+');
                     $startId = (int) file_get_contents(ROOT_DIR . "/sbin/child_pic_id_{$index}.log");
                 } else {
                     //log不存在
                     $pid_log_file = fopen("child_pic_id_{$index}.log", 'w+');
                     $startId = $range['startId'];
                 }
                 //新建一个mysql连接,抛弃原来的
                 $config = (array) Cola::config()->get('_db') + array('adapter' => 'Mysql', 'params' => array());
                 $db = Cola_Com_Db::factory($config);
                 $this->cola_db = $db;
                 //$this->dbs["DB_".$index] = $db;
                 $times = $partTotalCount / $limit + 1;
                 for ($i = 0; $i < $times; $i++) {
                     $offset = $i * $limit;
                     $pics = $this->getUntaggedPicWithEnd($startId, $endId, $offset, $limit);
                     foreach ($pics as $pic) {
                         $id = $pic['id'];
                         $pic_url = $this->getPicUrl($pic['orig_path']);
                         $this->handle($pic_url, $id);
                     }
                     //log pic_id
                     rewind($pid_log_file);
                     fwrite($pid_log_file, $id);
                     fflush($pid_log_file);
                 }
                 //子进程退出时需要关闭资源
                 $this->cola_db->close();
                 fclose($pid_log_file);
                 echo "Child runs to end";
             }
         }
         //父进程等待子进程结束
         while (pcntl_waitpid(0, $status) != -1) {
             $status = pcntl_wexitstatus($status);
             echo "Child {$status} completed\n";
         }
     } else {
         //没有jobs,不需要多进程
         $times = $totalCount / $limit + 1;
         for ($i = 0; $i < $times; $i++) {
             $offset = $i * $limit;
             $pics = $this->getUntaggedPic($pic_id, $offset, $limit);
             foreach ($pics as $pic) {
                 $id = $pic['id'];
                 $pic_url = $this->getPicUrl($pic['orig_path']);
                 $this->handle($pic_url, $id);
             }
             $this->logId($id);
         }
     }
 }
Ejemplo n.º 20
0
 /**
  * Dynamic get vars
  *
  * @param string $key
  */
 public function __get($key)
 {
     switch ($key) {
         case 'view':
             $this->view();
             return $this->view;
         case 'request':
             $this->request = new Cola_Request();
             return $this->request;
         case 'response':
             $this->response = new Cola_Response();
             return $this->response;
         case 'config':
             $this->config = Cola::getInstance()->config;
             return $this->config;
         default:
             throw new Cola_Exception('Undefined property: ' . get_class($this) . '::' . $key);
     }
 }
Ejemplo n.º 21
0
<?php

if (isset($_GET['debug'])) {
    xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
    // System Start Time
    define('START_TIME', microtime(true));
    // System Start Memory
    define('START_MEMORY_USAGE', memory_get_usage());
}
error_reporting(E_ALL);
ini_set('display_errors', 'on');
date_default_timezone_set('Asia/Shanghai');
require '../Cola/Cola.php';
$cola = Cola::getInstance();
//$benchmark = new Cola_Com_Benchmark();
$cola->boot()->dispatch();
//echo "<br />cost:", $benchmark->cost(), 's';
if (!isset($_GET['debug'])) {
    die;
}
$xhprof_data = xhprof_disable();
echo "Page rendered in <b>" . round(microtime(true) - START_TIME, 5) * 1000 . " ms</b>, taking <b>" . round((memory_get_usage() - START_MEMORY_USAGE) / 1024, 2) . " KB</b>";
$f = get_included_files();
echo ", include files: " . count($f);
$XHPROF_ROOT = realpath(dirname(__FILE__) . '/../..');
include_once $XHPROF_ROOT . "/xhprof/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof/xhprof_lib/utils/xhprof_runs.php";
// save raw data for this profiler run using default
// implementation of iXHProfRuns.
$xhprof_runs = new XHProfRuns_Default();
// save the run under a namespace "xhprof_foo"
Ejemplo n.º 22
0
 /**
  * 加入圈子
  */
 public function joingroupAction()
 {
     if (ComTool::isAjax()) {
         if (isset($_POST['captcha'])) {
             $captcha = trim($this->post('captcha'));
             if (!ComTool::checkCaptcha($captcha)) {
                 ComTool::ajax(100001, '验证码错误');
             }
         }
         $city = trim($this->post('city'));
         ComTool::checkEmpty($city, '请选择城市');
         $area = trim($this->post('area'));
         ComTool::checkEmpty($area, '请选择区域');
         $group = trim($this->post('group'));
         ComTool::checkEmpty($group, '请选择圈子');
         $addr_desc = trim($this->post('addr_desc'));
         ComTool::checkEmpty($addr_desc, '请填写详细位置');
         ComTool::checkMaxLen($addr_desc, 32, '详细位置最多32位');
         $currUser = $this->getCurrentUser();
         $groupsNumLimit = Cola::getConfig('_groupsNumLimit');
         $groups = UserGroupData::getGroupsByUid($currUser['id']);
         foreach ($groups as $v) {
             if ($group == $v['group_id']) {
                 ComTool::ajax(100001, '已加入该圈子');
             }
         }
         if (count($groups) > $groupsNumLimit) {
             ComTool::ajax(100001, '已加入圈子数超过限制');
         }
         $res = UserGroupData::add(array('user_id' => $currUser['id'], 'group_id' => $group, 'detail' => $addr_desc, 'status' => 1));
         ComTool::result($res, '操作失败,请刷新重试', '操作成功');
     }
 }