/**
  * find elements
  *
  * @param Charcoal_String|string $selector
  * @param Charcoal_Integer|integer $index
  */
 public function find($selector, $index = NULL)
 {
     Charcoal_ParamTrait::validateString(1, $selector);
     Charcoal_ParamTrait::validateInteger(2, $index, TRUE);
     if (!$this->simple_html_dom) {
         _throw(new SimpleHtmlDomComponentException("SimpleHtmlDom object is not created"));
     }
     $selector = us($selector);
     log_debug("debug", "index:{$index}");
     if ($index !== NULL) {
         // returns single element
         $index = ui($index);
         log_debug("debug", "returns single element");
         $result = $this->simple_html_dom->find($selector, $index);
         log_debug("debug", "result: " . print_r($result, true));
         return $result ? new Charcoal_SimpleHtmlDomElement($result) : NULL;
     }
     // returns all elements
     log_debug("debug", "selector:" . print_r($selector, true));
     $result = $this->simple_html_dom->find($selector);
     log_debug("debug", "result: " . print_r($result, true));
     $elements = array();
     foreach ($result as $e) {
         $elements[] = new Charcoal_SimpleHtmlDomElement($e);
     }
     return $result ? $elements : array();
 }
 /**
  *    Returns table name
  *
  * @return string
  */
 public function getTableName()
 {
     if (!property_exists($this, '___table_name')) {
         _throw(new Charcoal_TableModelException($this, s('___table_name property is not set')));
     }
     return $this->___table_name;
 }
Exemple #3
0
 /**
  * @param $pay_type          支付方式
  * @param $month_fee         每月电费量
  * @param $package_data_id   套餐id
  * @param $ticket_id         绿电券id
  */
 static function confirm($pay_type, $month_fee, $package_data_id, $ticket_id)
 {
     $ticket_price = 0;
     if (empty($package_data_id)) {
         _throw("请选择绿电套餐");
     }
     //套餐
     $packageData = self::get_pkg_data($package_data_id);
     if (empty($packageData)) {
         _throw('未检索到绿电套餐');
     }
     if (empty($month_fee) || !is_numeric($month_fee)) {
         _throw('请填写每月预计电费金额');
     }
     if ($packageData['period'] == 3) {
         if ($month_fee < 200) {
             $month_fee = 200;
         }
     } else {
         if ($month_fee < C('PKG_PAGE_COMBO_NUM_INIT')) {
             $month_fee = C('PKG_PAGE_COMBO_NUM_INIT');
         }
     }
     //根据套餐配置的"是否允许使用优惠券"列来动态判断
     if (!$packageData['allow_coupon']) {
         $ticket_id = 0;
     }
 }
Exemple #4
0
 static function getPorderSaveRow($_row)
 {
     if (empty($_row['client_id'])) {
         _throw("没有选择客户!");
     }
     return array("designer_uid" => empty($_row['designer_uid']) ? null : $_row['designer_uid'], "client_id" => empty($_row['client_id']) ? null : $_row['client_id'], "nutri" => empty($_row['nutri']) ? null : $_row['nutri'], "blood" => empty($_row['blood']) ? null : $_row['blood'], "parts" => empty($_row['parts']) ? null : $_row['parts'], "material" => empty($_row['material']) ? null : $_row['material'], "item" => empty($_row['item']) ? null : $_row['item'], "allergies" => empty($_row['allergies']) ? null : $_row['allergies'], "years" => empty($_row['years']) ? null : $_row['years'], "blood_pressure" => empty($_row['blood_pressure']) ? null : $_row['blood_pressure'], "medical_history" => empty($_row['medical_history']) ? null : $_row['medical_history'], "medicine" => empty($_row['medicine']) ? null : $_row['medicine'], "solution1" => empty($_row['solution1']) ? null : $_row['solution1'], "solution2" => empty($_row['solution2']) ? null : $_row['solution2'], "request" => empty($_row['request']) ? null : $_row['request']);
 }
Exemple #5
0
 function index($ctx)
 {
     $ctx->title = '绑定微信账号';
     setcookie('no_subscribe_prj', '', time() + 3600);
     $user = UC::auth();
     if ($user) {
         $connect = WxConnect::get_by('user_id', $user['id']);
         if ($connect) {
             _redirect('/');
         }
     }
     if (!$this->openid) {
         if (!$_GET['redirect']) {
             // 避免循环跳转
             UC::logout();
             // 使用域名 axelahome.com, 避免因为跨域导致 session 获取不到问题
             $jump = _url('https://axelahome.com/weixin/bind', array('redirect' => 1));
             $url = _url('https://axelahome.com/weixin/oauth', array('jump' => $jump));
             _redirect($url);
         }
         _throw("链接已经过期, 请重新获取微信消息!", 200);
     } else {
         $connect = WxConnect::get_by('wx_openid', $this->openid);
         if ($connect) {
             _throw('此微信号已经绑定过懒投资账号, 请先解绑!');
         }
     }
 }
Exemple #6
0
 static function getSaveRow($_row)
 {
     if (empty($_row['client_id'])) {
         _throw("没有选择客户!");
     }
     return array("client_id" => $_row['client_id'], "type" => empty($_row['type']) ? null : $_row['type'], "content" => empty($_row['content']) ? null : $_row['content'], "dtime" => empty($_row['dtime']) ? null : $_row['dtime'], "ndtime" => empty($_row['ndtime']) ? null : $_row['ndtime']);
 }
 /**
  * イベントを処理する
  */
 public function processEvent($context)
 {
     $event = $context->getEvent();
     // パラメータを取得
     $app_name = $event->getAppName();
     $project_name = $event->getProjectName();
     $out_dir = $event->getTargetDir();
     //=======================================
     // Confirm input parameters
     //=======================================
     if (!preg_match('/^[0-9a-zA-Z_\\-]*$/', $app_name)) {
         _throw(new Charcoal_InvalidArgumentException($app_name));
     }
     if (!preg_match('/^[0-9a-zA-Z_\\-]*$/', $project_name)) {
         _throw(new Charcoal_InvalidArgumentException($project_name));
     }
     //=======================================
     // Make output directory
     //=======================================
     $out_dir = new Charcoal_File($out_dir);
     $out_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make web_app directory
     //=======================================
     $webapp_dir = new Charcoal_File('web_app', $out_dir);
     $webapp_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make project directory
     //=======================================
     $project_dir = new Charcoal_File($project_name, $webapp_dir);
     $project_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make project/app directory
     //=======================================
     $project_app_dir = new Charcoal_File('app', $project_dir);
     $project_app_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make application directory
     //=======================================
     $application_dir = new Charcoal_File($app_name, $project_app_dir);
     $application_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make application/class directory
     //=======================================
     $app_class_dir = new Charcoal_File('class', $application_dir);
     $app_class_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make application/config directory
     //=======================================
     $app_config_dir = new Charcoal_File('config', $application_dir);
     $app_config_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make application/module directory
     //=======================================
     $module_dir = new Charcoal_File('module', $application_dir);
     $module_dir->makeDirectory(self::DIR_MODE);
     echo "Application[{$app_name}] created at: " . $application_dir->getAbsolutePath() . PHP_EOL;
     return b(true);
 }
Exemple #8
0
 public function pop()
 {
     $tail = array_pop($this->values);
     if (!$tail) {
         _throw(new Charcoal_StackEmptyException($this));
     }
     return $tail;
 }
 /**
  *    score
  *
  *  @param integer $handle        handle of timer
  *  @param integer $precision     precision of timer value
  *
  *  @return integer      now score
  */
 public static function score($handle, $precision = self::DEFAULT_PRECISION)
 {
     $start_time = isset(self::$benchmarks[$handle]) ? self::$benchmarks[$handle] : NULL;
     $stop_time = microtime(true);
     if ($start_time === NULL) {
         _throw(new Charcoal_BenchmarkException('not started yet!'));
     }
     return round(($stop_time - $start_time) * 1000, $precision);
 }
Exemple #10
0
 /**
  *    constructor
  */
 public function __construct(Charcoal_String $url)
 {
     parent::__construct();
     $this->original = $url;
     $this->url = parse_url($url);
     if ($this->url === FALSE) {
         _throw(new Charcoal_URLFormatException($url));
     }
 }
 public function __construct(Charcoal_String $address, Charcoal_String $label = NULL)
 {
     $this->address = $address;
     $this->label = $label;
     $valid = Charcoal_MailUtil::validateAddress(s($address));
     if (!$valid) {
         _throw(new Charcoal_InvalidMailAddressException($address));
     }
 }
Exemple #12
0
 static function getSaveRow($row, $is_add = true)
 {
     $row = json_decode($row, 1);
     if (empty($row['dep_name'])) {
         _throw("部门名不能为空");
     }
     $_row = array("dep_name" => empty($row['dep_name']) ? null : $row['dep_name'], "dep_pid" => empty($row['dep_pid']) ? 1 : $row['dep_pid']);
     return array("row" => $_row);
 }
Exemple #13
0
 static function getSaveRow()
 {
     $row = Utils::I("row");
     $row = json_decode($row, 1);
     if (empty($row['title'])) {
         _throw("title不能为空");
     }
     $_row = array("title" => empty($row['title']) ? "" : $row['title'], "pics" => empty($row['pics']) ? "" : $row['pics'], "name" => empty($row['name']) ? "" : $row['name']);
     return $_row;
 }
Exemple #14
0
 static function getSaveRow($_row)
 {
     if (empty($_row['com_name'])) {
         _throw("企业名不能为空!");
     }
     if (empty($_row['province_id'])) {
         _throw("所属省份不能为空!");
     }
     return array("com_name" => empty($_row['com_name']) ? null : $_row['com_name'], "com_charger" => empty($_row['com_charger']) ? null : $_row['com_charger'], "tel" => empty($_row['tel']) ? null : $_row['tel'], "sex" => empty($_row['sex']) ? 0 : 1, "addr" => empty($_row['addr']) ? null : $_row['addr'], "area_id" => empty($_row['area_id']) ? null : $_row['area_id'], "province_id" => empty($_row['province_id']) ? null : $_row['province_id'], "zxs_uid" => intval(empty($_row['zxs_uid']) ? null : $_row['zxs_uid']), "zxz_uid" => intval(empty($_row['zxz_uid']) ? null : $_row['zxz_uid']), "kf_uid" => intval(empty($_row['kf_uid']) ? null : $_row['kf_uid']));
 }
Exemple #15
0
 public function __construct($class_name)
 {
     //        Charcoal_ParamTrait::validateString( 1, $class_name );
     $class_name = us($class_name);
     parent::__construct();
     if (!class_exists($class_name)) {
         _throw(new Charcoal_ClassNotFoundException($class_name));
     }
     $this->class_name = us($class_name);
 }
 public function validateImplements($object)
 {
     $interface_name = $this->interface_name;
     if (!interface_exists($interface_name)) {
         _throw(new Charcoal_InterfaceNotFoundException($interface_name));
     }
     if (!$object instanceof $interface_name) {
         // Invoke Exception
         _throw(new Charcoal_InterfaceImplementException($object, $interface_name));
     }
 }
 /**
  * Save a value to cache
  *
  * @param string $key                The key under which to store the value.
  * @param Charcoal_Object $value     value to save
  * @param int $duration              specify expiration span which the cache will be removed.
  */
 public function set($key, Charcoal_Object $value, $duration = NULL)
 {
     //        Charcoal_ParamTrait::validateString( 1, $key );
     //        Charcoal_ParamTrait::validateInteger( 3, $duration, TRUE );
     $duration = $duration ? ui($duration) : ui($this->_default_duration);
     $res = $this->_memcached->set(us($key), $value, $duration);
     if (!$res) {
         $result_code = $this->_memcached->getResultCode();
         _throw(new Charcoal_CacheDriverException('memcached', "set failed. result code=[{$result_code}]"));
     }
 }
 /**
  *  Write file
  *
  * @param Charcoal_String $mode File access mode
  *
  * @return Charcoal_Integer Written size in bytes
  */
 public function write($data)
 {
     if (!$this->fp) {
         _throw(new Charcoal_FileOutputException($this->file->getPath()));
     }
     $ret = fwrite($this->fp, $data);
     if ($ret === FALSE) {
         _throw(new Charcoal_FileOutputException($this->file->getPath()));
     }
     return i($ret);
 }
 public static function getMime(Charcoal_File $image_file)
 {
     if (!$image_file->exists()) {
         return NULL;
     }
     $data = getimagesize(us($image_file->getPath()));
     if ($data === FALSE) {
         _throw(new Charcoal_ImageGetSizeException($image_file));
     }
     return $data['mime'];
 }
Exemple #20
0
 function action_my_task($status)
 {
     $user_id = Auth::get_user_id();
     if (!$user_id) {
         _throw("您还没有登陆", 9001);
     }
     $table = self::_table("user_mission");
     $table_mission = self::_table("mission");
     $rows = self::_db()->rows("select\n                      user_mission.*,mission.title,mission.thumb,mission.desc from {$table} as user_mission\n                      left join {$table_mission} as mission on mission.id = user_mission.mission_id\n                      where user_mission.user_id = ? order by user_mission.id desc ", $user_id);
     return array("missions" => $rows);
 }
 public function __construct($values = array())
 {
     parent::__construct();
     if ($values) {
         if (is_array($values)) {
             $this->values = $values;
         } else {
             _throw(new NonArrayException($values));
         }
     } else {
         $this->values = array();
     }
 }
Exemple #22
0
 static function create_encrypt_info()
 {
     $config = array("digest_alg" => "sha512", "private_key_bits" => 1024, "private_key_type" => OPENSSL_KEYTYPE_RSA);
     $res = openssl_pkey_new($config);
     $private_key = '';
     openssl_pkey_export($res, $private_key);
     $details = openssl_pkey_get_details($res);
     $public_key = $details["key"];
     if (!$private_key || !$public_key) {
         _throw("get_encrypt_keys failed");
     }
     return array('public_key' => $public_key, 'private_key' => $private_key);
 }
 public function __construct($path, $parent = NULL)
 {
     Charcoal_ParamTrait::validateString(1, $path);
     Charcoal_ParamTrait::validateIsA(2, 'Charcoal_File', $parent, TRUE);
     parent::__construct($path, $parent);
     if (!is_readable(parent::getPath())) {
         _throw(new Charcoal_FileNotFoundException($this));
     }
     $this->_data = getimagesize(parent::getPath());
     if ($this->_data === FALSE) {
         _throw(new Charcoal_ImageGetSizeException($this));
     }
 }
Exemple #24
0
 function edit($ctx)
 {
     $id = intval($_GET['id']);
     $m = WxConnect::get($id);
     if (!$m) {
         _throw("ID: {$id} 不存在!");
     }
     if ($_POST) {
         $up = array('prj_subscribe' => intval($_POST['f']['prj_subscribe']), 'wx_subscribe' => intval($_POST['f']['wx_subscribe']));
         $m->update($up);
     }
     $ctx->m = $m;
 }
 /**
  *    score
  *
  *  @param integer $unit          unit of memory usage
  *  @param integer $precision     precision of memory usage
  *
  *  @return integer      now score
  */
 public static function score($handle, $unit = Charcoal_EnumMemoryUnit::UNIT_B, $precision = Charcoal_MemoryUtil::DEFAULT_PRECISION)
 {
     $start = isset(self::$benchmarks[$handle]) ? self::$benchmarks[$handle] : NULL;
     if ($start === NULL) {
         _throw(new Charcoal_BenchmarkException('not started yet!'));
     }
     list($start_usage_1, $start_usage_2) = $start;
     $score_1 = memory_get_usage(true) - $start_usage_1;
     $score_2 = memory_get_usage(false) - $start_usage_2;
     $score_1 = Charcoal_MemoryUtil::convertSize($score_1, $unit, $precision);
     $score_2 = Charcoal_MemoryUtil::convertSize($score_2, $unit, $precision);
     return array($score_1, $score_2);
 }
Exemple #26
0
 /**
  *    Constructor
  *
  *    @param mixed $value        boolean value to set
  */
 public function __construct($value = self::DEFAULT_VALUE)
 {
     parent::__construct();
     if ($value === TRUE || $value === FALSE) {
         $this->value = $value;
     } elseif ($value instanceof Charcoal_Boolean) {
         $this->value = $value->unbox();
     } elseif ($value === NULL) {
         $value = FALSE;
     } else {
         _throw(new Charcoal_NonBooleanException($value));
     }
 }
 /**
  * Initialize instance
  *
  * @param Charcoal_Config $config   configuration data
  */
 public function configure($config)
 {
     parent::configure($config);
     $this->file_name = $config->getString('file_name', '', TRUE);
     $this->logs_dir = $config->getString('logs_dir', '%APPLICATION_DIR%/logs', TRUE);
     $this->line_end = $config->getString('line_end', self::CRLF);
     // replace logs_dir with macro value
     $this->logs_dir = $this->fillMacroValue($this->logs_dir, true);
     // replace file_name with macro value
     $this->file_name = $this->fillMacroValue($this->file_name, true);
     if (empty($this->file_name)) {
         _throw(new Charcoal_ComponentConfigException('file_name', 'mandatory'));
     }
 }
 /**
  * Initialize instance
  *
  * @param Charcoal_Config $config   configuration data
  */
 public function configure($config)
 {
     parent::configure($config);
     $rules_section = $config->getSection('routing rules');
     $patterns = $rules_section->getKeys();
     foreach ($patterns as $pattern) {
         $proc_path = $rules_section->getString($pattern);
         if ($proc_path === NULL) {
             _throw(new Charcoal_RoutingRuleConfigException($pattern, 'can not be NULL'));
         }
         $this->proc_paths[$pattern] = us($proc_path);
     }
     log_info('system,debug,router', "proc_paths:" . print_r($this->proc_paths, true), self::TAG);
 }
 public static function onUnhandledError($errno, $errstr, $errfile, $errline)
 {
     $flags_handled = error_reporting();
     if (Charcoal_System::isBitSet($errno, $flags_handled, Charcoal_System::BITTEST_MODE_ANY)) {
         // create fake exception
         $e = new Charcoal_PHPErrorException($errno, $errstr, $errfile, $errline);
         // output error message to STDERR if CLI
         if (defined('STDERR')) {
             fputs(STDERR, $e);
         }
         _throw($e);
     }
     return TRUE;
     // Otherwise, ignore all errors
 }
 /**
  * Output file
  *
  * @param Charcoal_File $file       path to output
  * @param array $lines              each line of the file to output
  */
 public static function outputFile(Charcoal_File $file, array $lines)
 {
     $file_name = $file->getPath();
     $fp = fopen($file_name, "w");
     if ($fp === FALSE) {
         _throw(new Charcoal_FileOpenException($file));
     }
     foreach ($lines as $line) {
         $res = fwrite($fp, $line . PHP_EOL);
         if ($res === FALSE) {
             _throw(new Charcoal_FileOutputException($file));
         }
     }
     fclose($fp);
 }