Esempio n. 1
0
 function select()
 {
     $args = func_get_args() ? implode(',', func_get_args()) : false;
     $select = $this->read($args);
     $select or debug::error('没有查询到数据', 116002);
     return $select->fetchAll(PDO::FETCH_ASSOC);
 }
Esempio n. 2
0
 static function buildModel($model)
 {
     $modelFile = _APP_ . 'core/model/' . $model . '.php';
     $modelBase = _APP_ . 'model/' . $model . '.model.php';
     if (file_exists($modelBase)) {
         if (file_exists($modelFile) || filemtime($modelBase) > filemtime($modelFile)) {
             include _APP_ . 'model/' . $model . '.model.php';
             $fields = array_combine(str_replace('@', C('DB_FIX'), array_keys($fields)), array_values($fields));
             $links = array_combine(str_replace('@', C('DB_FIX'), array_keys($links)), str_replace('@', C('DB_FIX'), array_values($links)));
             //在数据中解析出表名
             $tables = array();
             foreach (array_keys($fields) as $v) {
                 array_push($tables, array_shift(explode('.', $v)));
             }
             $tables = array_unique($tables);
             //获取关联关系
             $arr = array();
             foreach ($links as $k => $v) {
                 array_push($arr, $k . '=' . $v);
             }
             $links = $arr;
             $table['tables'] = $tables;
             $table['fields'] = $fields;
             $table['links'] = $links;
             file_put_contents($modelFile, "<?php\nreturn " . var_export($table, true) . "\n?>");
         }
     } else {
         file_exists($modelFile) and unlink($modelFile);
         debug::error('模型' . $model . '文件不存在.', 11004);
     }
 }
Esempio n. 3
0
 function output()
 {
     //set all template variables
     foreach ($this->vars as $var => $val) {
         ${$var} = $val;
     }
     if ($this->parent_view) {
         foreach ($this->parent_view->vars as $var => $val) {
             ${$var} = $val;
         }
     }
     // TODO: Check extract() for an alternative method
     $path = Kennel::cascade("{$this->view}", 'views');
     if (!$path) {
         return debug::error("View <strong>{$this->view}</strong> not found.");
     }
     //begin intercepting the output buffer
     ob_start();
     if ($path) {
         require $path;
     }
     //return the output and close the buffer
     return ob_get_clean();
     //unset all template variables
     foreach ($this->vars as $var => $val) {
         unset(${$var});
     }
 }
Esempio n. 4
0
 function __construct($image)
 {
     if (is_string($image)) {
         if (!is_file($image)) {
             return debug::error("Image <strong>{$image}</strong> not found at");
         }
         $this->path = pathinfo($image);
         $imageSize = getimagesize($image);
         $this->width = $imageSize[0];
         $this->height = $imageSize[1];
         $this->mime = $imageSize['mime'];
         switch ($this->mime) {
             case 'image/jpeg':
                 $this->image = imagecreatefromjpeg($image);
                 break;
             case 'image/png':
                 $this->image = imagecreatefrompng($image);
                 break;
             case 'image/gif':
                 $this->image = imagecreatefromgif($image);
                 break;
         }
     } else {
         $this->width = imagesx($image);
         $this->height = imagesy($image);
         $this->image = $image;
     }
 }
Esempio n. 5
0
 function _empty($fun)
 {
     if (file_exists(_APP_ . 'template/' . C('TEMPLATE_STYLE') . '/' . $_GET['m'] . '/' . $_GET['a'] . '.' . C('TEMPLATE_SUFFIX'))) {
         $this->display();
     } else {
         debug::error('没有找到该操作!', 20202);
     }
 }
Esempio n. 6
0
 function getInstance()
 {
     if (self::$INSTANCE) {
         return self::$INSTANCE;
     } else {
         return debug::error('Template::getInstance() error: there is no instance created yet');
     }
 }
/**
 * Autoload function
 * Whenever an unknown class/function is invoked, this function is called to include correct file(s)
 * Outputs an error if resource not found
 * 
 * @param String $class class or function name to invoke
 * @return void
 */
function autoload($class)
{
    if ($class == "smarty" || !preg_match("#smarty#i", $class)) {
        if (file_exists(PLUGIN . '/' . $class . '/plugin.' . $class . '.php')) {
            require_once PLUGIN . '/' . $class . '/plugin.' . $class . '.php';
        } elseif (file_exists(PLUGIN . '/' . strtolower($class) . '/plugin.' . strtolower($class) . '.php')) {
            require_once PLUGIN . '/' . strtolower($class) . '/plugin.' . strtolower($class) . '.php';
        } elseif (file_exists(SYSTEM . '/class/class.' . $class . '.php')) {
            require_once SYSTEM . '/class/class.' . $class . '.php';
        } else {
            debug::error("Plugin autoload", "Plugin could not be loaded", PLUGIN . '/' . $class . '/plugin.' . $class . '.php');
        }
    }
}
Esempio n. 8
0
 static function file($uri)
 {
     # Absolute paths
     if (substr($uri, 0, 7) === 'http://') {
         return $uri;
     }
     # Cascading Resource
     $path = Kennel::cascade($uri, 'file', true);
     if ($path) {
         return $path;
     } else {
         debug::error("assets helper: File <b>{$uri}</b> not found.", 1);
     }
 }
Esempio n. 9
0
 function show()
 {
     if (file_exists($this->templateFile)) {
         //开发模式下记录模板
         C('DEVE') and debug::$info['templaceFile'] = $this->templateFile;
         if (file_exists($this->cacheFile) && filemtime($this->cacheFile) > filemtime($this->templateFile)) {
             include $this->cacheFile;
         } else {
             $this->cache();
             include $this->cacheFile;
         }
     } else {
         debug::error('模版不存在:' . $this->templateFile, 202001);
     }
 }
Esempio n. 10
0
 function __construct($data, $num = 5)
 {
     if (isset($_GET['page'])) {
         $_GET['page'] == 1 and header("Location: {$_SERVER['SCRIPT_NAME']}/{$_GET['m']}/{$_GET['a']}");
         $this->thisPage = intval($_GET['page']);
     } else {
         $this->thisPage = 1;
     }
     $this->data = $data;
     $this->num = $num;
     $this->pageNum = $this->getPageNum();
     if ($this->thisPage != 1) {
         if ($this->thisPage < 1 or $this->thisPage > $this->pageNum) {
             debug::error('没有找到分页!', 219001);
         }
     }
     $this->offset = $this->getOffset();
     $this->pageHtml();
 }
Esempio n. 11
0
 function __construct($model_name)
 {
     if (!$model_name) {
         debug::error("Schema::__construct - undefined model name.");
     }
     $path = Kennel::cascade($model_name, 'schemas');
     if (!$path) {
         debug::error("Schema::__construct - model schema for \"{$model_name}\" not found.");
     }
     $doc = new DOMDocument();
     $doc->load(realpath($path));
     $root = $doc->getElementsByTagName('model')->item(0);
     if (Kennel::getSetting('database', 'prefix')) {
         $this->table = Kennel::getSetting('database', 'prefix') . '_' . $root->getAttribute('table');
     } else {
         $this->table = $root->getAttribute('table');
     }
     $fields = $doc->getElementsByTagName('field');
     foreach ($fields as $field) {
         $this->fields[] = new Field($this->table, $field);
     }
 }
Esempio n. 12
0
 function getSaveQuery($forceInsert = false)
 {
     $primaryKey = $this->schema->getPrimaryKey();
     $columns = array();
     $newValues = array();
     $syncedValues = array();
     // Add quotes for non-numeric field values, used to the SQL statement
     foreach ($this->schema as $field) {
         $columns[] = '`' . $field->name . '`';
         switch (strtolower($field->type)) {
             case 'varchar':
             case 'char':
             case 'text':
             case 'datetime':
             case 'date':
             case 'time':
                 if ($this->_data[$field->name] !== NULL) {
                     $newValues[] = '"' . MySQL::escape_string($this->_data[$field->name]) . '"';
                 } else {
                     $newValues[] = 'NULL';
                 }
                 if ($this->_synced_data[$field->name] !== NULL) {
                     $syncedValues[] = '"' . MySQL::escape_string($this->_synced_data[$field->name]) . '"';
                 } else {
                     $syncedValues[] = 'NULL';
                 }
                 break;
             case 'int':
             case 'tinyint':
             case 'bigint':
             case 'float':
             case 'double':
             case 'decimal':
                 if ($this->_data[$field->name] !== NULL && is_numeric($this->_data[$field->name])) {
                     $newValues[] = $this->_data[$field->name];
                 } else {
                     $newValues[] = 'NULL';
                 }
                 if ($this->_synced_data[$field->name] !== NULL && is_numeric($this->sunced_data[$field->name])) {
                     $syncedValues[] = $this->_synced_data[$field->name];
                 } else {
                     $syncedValues[] = 'NULL';
                 }
                 break;
             default:
                 debug::error("Model::save - Unsuported field type \"{$field->type}\" for field \"{$field->name}\" on model \"{$this->model_name}\"");
         }
     }
     // Check if it's an existing record, build SQL statement accordingly
     if (!$this->_synced_data[$primaryKey->name] || $forceInsert) {
         $sql = "INSERT INTO {$this->schema->table} (";
         $sql .= implode(', ', $columns);
         $sql .= ")\nVALUES (";
         $sql .= implode(', ', $newValues);
         $sql .= ");";
     } else {
         $dataList = array();
         foreach ($columns as $key => $column) {
             $dataList[] = "\n {$column} = {$newValues[$key]}";
         }
         $c = new Criteria($this->model_name);
         foreach ($this->schema as $field) {
             $c->add($field->name, $this->_synced_data[$field->name]);
         }
         $sql = "UPDATE {$this->schema->table} SET " . implode(', ', $dataList);
         $sql .= "\nWHERE " . ORM::getWhereString($c) . ';';
     }
     return $sql;
 }
	/**
	* Creates a node before a given node
	* <pre>
	* +-- root1
	* |
	* +-\ root2
	* | |
	* | |-- subnode2 [new]
	* | |-- subnode1 [target]
	* | |-- subnode3
	* |
	* +-- root3
	* </pre>
	* 
	* @param int $id Target node ID
	* @param array $values Hash with param => value pairs of the node (see $this->_params)
	* @param bool $returnID Tell the method to return a node id instead of an object.
	*                                 ATTENTION: That the method defaults to return an object instead of the node id
	*                                 has been overseen and is basically a bug. We have to keep this to maintain BC.
	*                                 You will have to set $returnID to true to make it behave like the other creation methods.
	*                                 This flaw will get fixed with the next major version.
	* @access public 
	* @return mixed The node id or false on error
	*/
	function create_left_node($id, $values)
	{
		$this->_verify_user_values($values); 
		// invalid target node, bail out
		if (!($this_node = $this->get_node($id)))
		{
    	debug :: error(TREE_ERROR_NODE_NOT_FOUND,
    		 __FILE__ . ' : ' . __LINE__ . ' : ' .  __FUNCTION__, 
    		array('id' => $id)
    	);
    	return false;
		} 

		// If the target node is a rootnode we virtually want to create a new root node
		if ($this_node['root_id'] == $this_node['id'])
		{
			return $this->create_root_node($values, $id, false, NESE_MOVE_BEFORE);
		} 

		$insert_data = array();
		$parent = $this->get_parent($id);
		$insert_data['parent_id'] = $parent['id'];

		$sql = array();
		$sql[] = sprintf('UPDATE %s SET ordr=ordr+1
                      WHERE root_id=%s AND ordr>=%s AND level=%s AND l BETWEEN %s AND %s',
											$this->_node_table,
											$this_node['root_id'],
											$this_node['ordr'],
											$this_node['level'],
											$parent['l'], $parent['r']); 
			
		// Update all nodes which have dependent left and right values
		$sql[] = sprintf('UPDATE %s SET
			                l=CASE WHEN l >= %s THEN l+2 ELSE l END,
			                r=CASE WHEN (r >= %s OR l >= %s) THEN r+2 ELSE r END
			                WHERE root_id=%s',
											$this->_node_table,
											$this_node['l'],
											$this_node['r'],
											$this_node['l'],
											$this_node['root_id']);

		$insert_data['ordr'] = $this_node['ordr'];
		$insert_data['l'] = $this_node['l'];
		$insert_data['r'] = $this_node['l'] + 1;
		$insert_data['root_id'] = $this_node['root_id'];
		$insert_data['level'] = $this_node['level'];

		if (!$this->_dumb_mode || !$node_id = isset($values['id']))
		{
			$node_id = $insert_data['id'] = $this->_db->get_max_column_value($this->_node_table, 'id') + 1;
		} 
		else
		{
			$node_id = $values['id'];
		} 

		if (!$qr = $this->_values2insert_query($values, $insert_data))
		{
			return false;
		} 
		// Insert the new node
		$sql[] = sprintf('INSERT INTO %s (%s) VALUES (%s)', $this->_node_table, implode(', ', array_keys($qr)), implode(', ', $qr));
		foreach ($sql as $qry)
		{
			$this->_db->sql_exec($qry);
		} 

		return $node_id;
	} 
Esempio n. 14
0
    deve::load(_FFPHP_ . 'source/core/view.class.php');
}
//加载核心文件
deve::load(array(_FFPHP_ . 'source/core/ffphp.class.php', _FFPHP_ . 'source/core/compile.class.php', _FFPHP_ . 'source/core/action.class.php'));
//检测数据连接类型
if (C('CONNECT_TYPE') == 1) {
    deve::load(_FFPHP_ . 'source/drive/mysqli.class.php');
} else {
    deve::load(_FFPHP_ . 'source/drive/pdo.class.php');
}
//URL路由
ffphp::pathUrl();
//类的自动加载
function __autoload($className)
{
    deve::load(_APP_ . 'behavior/' . $className . '.class.php');
}
//控制器的格式化创建
$actionfile = _APP_ . 'action/' . strtolower($_GET['m']) . '.class.php';
if (file_exists($actionfile)) {
    deve::buildAction($_GET['m']);
    $newAction = strtolower($_GET['m']) . 'Action';
    deve::load(_APP_ . 'core/action/' . $newAction . '.class.php');
    $action = new $newAction();
    $action->{$_GET}['a']();
} else {
    debug::error('控制器不存在!', 202102);
}
if (C('DEBUG')) {
    debug::$showed or debug::show();
}
Esempio n. 15
0
 protected function descTable()
 {
     $table = array();
     $tableInfo = $this->mysqli->query('desc ' . $this->tableName);
     $tableInfo or debug::error('数据表不存在!', 113006);
     while ($arr = $tableInfo->fetch_assoc()) {
         if (is_int(stripos($arr['Type'], 'int'))) {
             $FieldType = 'i';
         } elseif (is_int(stripos($arr['Type'], 'float')) || is_int(stripos($arr['Type'], 'double'))) {
             $FieldType = 'd';
         } elseif (is_int(stripos($arr['Type'], 'blob'))) {
             $FieldType = 'b';
         } else {
             $FieldType = 's';
         }
         $table['list'][$arr['Field']] = $FieldType;
         if ($arr['Key'] == 'PRI') {
             $table['pri'] = $arr['Field'];
         }
     }
     empty($table['pri']) and $table['pri'] = $table['list'][0];
     $this->tableInfo = $table;
     return $table;
 }
Esempio n. 16
0
 /**
  * Modify a line output
  *
  * @access public
  * @param mixed $field field to update
  * @param String $value[optional] new value - default: empty string
  * @return void
  */
 public function put($field, $value = '')
 {
     if (empty($this->result)) {
         debug::error("SQL", "PUT method can't be requested before SELECT and EXEC method.", __FILE__, __LINE__);
         $this->error = true;
     }
     if (empty($table)) {
         $table = $this->table['select'];
     }
     $this->line[$this->table['select'] . '_' . $field] = $value;
     return true;
 }
Esempio n. 17
0
 static function getSetting($category, $setting)
 {
     // Skip if no settings found
     if (!self::$_APP_SETTINGS) {
         return null;
     }
     if (!isset(self::$_APP_SETTINGS[$category][$setting])) {
         debug::error("Setting [{$category}][{$setting}] was not found");
     }
     return self::$_APP_SETTINGS[$category][$setting];
 }
Esempio n. 18
0
 static function retrieveByPrimaryKey($model_name, $primary_key_value)
 {
     $schema = self::getSchema($model_name);
     $primaryKey = $schema->getPrimaryKey();
     if (!$primaryKey) {
         debug::error("ORM::retrieveByPrimaryKey error: no primary key defined for model <strong>{$model_name}</strong>.");
     }
     $c = new Criteria($model_name);
     $c->add($primaryKey->name, $primary_key_value);
     $c->setLimit(1);
     $instancies = ORM::retrieve($c);
     if (isset($instancies[0])) {
         return $instancies[0];
     } else {
         return null;
     }
 }
Esempio n. 19
0
 public function error($error = null, $errno = null)
 {
     $reg = new dberror();
     $f = "{$errno}";
     $aError = $reg->{$f}($error);
     $this->error = $aError;
     if (isset($this->cls) && $this->error && isset($this->cls->table) && isset($this->cls->tables[$this->cls->table])) {
         $table = $this->cls->tables[$this->cls->table];
         $fieldName = $this->error['fieldname'];
         $errorName = isset($this->error['errorName']) ? $this->error['errorName'] : $this->error['errno'];
         if ($table->{$fieldName}->closure->validate) {
             $error = isset($table->{$fieldName}->closure->validate->sql->{$errorName}) ? $table->{$fieldName}->closure->validate->sql->{$errorName} : false;
             if (DEBUG) {
                 debug::error($error, $errorName, 'sql');
             } else {
                 debug::error(T_('Error'), false, 'sql');
             }
         }
     } else {
         if (DEBUG) {
             debug::error($error, $errno, 'sql');
         } else {
             debug::error(T_('Error'), false, 'sql');
         }
     }
     return $aError;
 }
Esempio n. 20
0
 protected function descTable()
 {
     $table = array();
     $table['list'] = array();
     $pdoing = $this->pdo->prepare('desc ' . $this->tableName);
     $pdoing or debug::error('数据表不存在!', 114005);
     $pdoing->execute();
     $info = $pdoing->fetchAll(PDO::FETCH_ASSOC);
     foreach ($info as $key => $value) {
         if (is_int(stripos($info[$key]['Type'], 'int'))) {
             $FieldType = 'i';
         } elseif (is_int(stripos($info[$key]['Type'], 'float')) || is_int(stripos($info[$key]['Type'], 'double'))) {
             $FieldType = 'd';
         } elseif (is_int(stripos($info[$key]['Type'], 'blob'))) {
             $FieldType = 'b';
         } else {
             $FieldType = 's';
         }
         //将所有的字段元素加入到数组中
         $table['list'][$info[$key]['Field']] = $FieldType;
         //将主键记录下来
         if ($info[$key]['Key'] == 'PRI') {
             $table['pri'] = $info[$key]['Field'];
         }
     }
     empty($table['pri']) and $table['pri'] = $info[0]['Field'];
     //缓存表单结构
     return $table;
 }
Esempio n. 21
0
 private function read($arg)
 {
     $sql = 'SELECT ';
     $fields = array();
     if ($arg == null) {
         $this->fields = array_values($this->modelInfo['fields']);
         foreach ($this->modelInfo['fields'] as $k => $v) {
             array_push($fields, $k . ' as ' . $v);
         }
     } else {
         $args = explode(',', $arg);
         $this->fields = $args;
         foreach ($args as $v) {
             array_push($fields, array_search($v, $this->modelInfo['fields']) . ' as ' . $v);
         }
     }
     $sql .= join(',', $fields);
     $sql .= ' FROM ' . join(',', $this->modelInfo['tables']);
     $sql .= ' WHERE ' . join(' and ', $this->modelInfo['links']);
     if ($this->where) {
         $sql .= ' and ' . $this->where;
     }
     if ($this->order) {
         $sql .= ' ORDER BY ' . $this->order;
     }
     if ($this->limit) {
         $sql .= ' LIMIT ' . $this->limit;
     }
     DEVE and debug::$sql[] = $sql;
     $mysqli = $this->mysqli->prepare($sql) or debug::error('没有查询到数据!', 113004);
     $mysqli->execute();
     $mysqli->store_result();
     return $mysqli;
 }
Esempio n. 22
0
 private function error($str)
 {
     debug::error($str, $str);
 }