示例#1
0
 /**
  * 给图片添加水水印
  * @param	string	$groundName		背景图片,需要添加水印的背景图片,暂时只支持jpg,gif.png格式
  * @param	string	$waterName		图片水印,作为水印的图片,暂时只支持jpg,gif.png格式
  * @param	int		$waterPos		水印的位置,有10中模式,默认0为随机模式
  * @param	string	$qz				加完水印后新图片的前缀
  * @param	mixed	生成水印后的图面的名称,失败返回假
  */
 public function waterMark($groundName, $waterName, $waterPos = 0, $qz = 'wa_')
 {
     $curpath = rtrim($this->path, '/') . '/';
     $dir = dirname($waterName);
     if ($dir == '.') {
         $wpath = $curpath;
     } else {
         $wpath = $dir . '/';
         $waterName = basename($waterName);
     }
     //如果都存在
     if (file_exists($curpath . $groundName) && file_exists($wpath . $waterName)) {
         $groundInfo = $this->getInfo($groundName);
         //获取背景图片信息
         $waterInfo = $this->getInfo($waterName, $dir);
         //获取水印图片信息
         if (!($pos = $this->position($groundInfo, $waterInfo, $waterPos))) {
             Debug::addmsg('<font color="red">图片的大小不应该比水印小</font>');
             return false;
         }
         $groundImg = $this->getImg($groundName, $groundInfo);
         //获取背景图片资源
         $waterImg = $this->getImg($waterName, $waterInfo, $dir);
         $groundImg = $this->copyImage($groundImg, $waterImg, $pos, $waterInfo);
         //拷贝图像
         return $this->createNewImage($groundImg, $qz . $groundName, $groundInfo);
     } else {
         Debug::addmsg('<font color="red">图片或水印图片不存在</font>');
         return false;
     }
 }
示例#2
0
/**
 *	输出各种类型的数据、适用于调试模式和开发阶段 
 *	@param	mixed	参数可以是一个或者多个任意变量或值
 */
function p()
{
    $args = func_get_args();
    //获取多个参数
    if (count($args) < 1) {
        Debug::addmsg('<font color="red">函数p()一定要提供一个以上的参数</font>');
        return;
    }
    echo '<div style="width:100%" text-align:"left"><pre>';
    //多个参数循环输出
    foreach ($args as $arg) {
        if (is_array($arg)) {
            print_r($arg);
            echo '<br />';
        } else {
            if (is_string($arg)) {
                echo $arg;
                echo '<br />';
            } else {
                var_dump($arg);
                echo '<br />';
            }
        }
    }
    echo '</pre></div>';
}
示例#3
0
 public static function run()
 {
     //安全性检测
     if (!preg_match('/^[A-Za-z_0-9]+$/', CONTROLLER_NAME)) {
         $controller = false;
     } else {
         $controller = ucfirst(CONTROLLER_NAME) . 'Controller';
         //判断控制器是否存在
         $srccontrolerfile = CONTROLLER_PATH . $controller . '.class.php';
         if (!file_exists($srccontrolerfile) && APP_DEBUG) {
             Debug::addmsg("该控制器不存在,你应该创建一个{$srccontrolerfile}的控制器!");
             return;
         }
     }
     if (!preg_match('/^[A-Za-z_0-9]+$/', ACTION_NAME)) {
         $action = false;
     } else {
         $action = ACTION_NAME;
     }
     if (!$controller || !$action && APP_DEBUG) {
         Debug::addmsg("非法操作!");
         return;
     }
     //如果存在_initialize 则优先执行这个初始化接口
     if (method_exists($controller, 'init')) {
         call_user_func(array(new $controller(), 'init'));
     }
     //执行当前操作
     if (method_exists($controller, $action)) {
         call_user_func(array(new $controller(), $action));
         Debug::addmsg("当前访问的控制器是<b>" . CONTROLLER_PATH . $controller . '.class.php</b>');
     } elseif (APP_DEBUG) {
         Debug::addmsg("非法操作{$action}");
     }
 }
示例#4
0
 function display($resource_name = null, $cache_id = null, $compile_id = null)
 {
     if (is_null($resource_name)) {
         $resource_name = "{$_GET["m"]}/{$_GET["a"]}" . C('TPL_SUFFIX');
     } else {
         if (strstr($resource_name, "/")) {
             $resource_name = $resource_name . C('TPL_SUFFIX');
         } else {
             $resource_name = $_GET["m"] . "/" . $resource_name . C('TPL_SUFFIX');
         }
     }
     $tplpath = rtrim(C('TPL_DIR'), '/') . '/' . $resource_name;
     if (!file_exists($tplpath)) {
         if (C('DEBUG')) {
             Debug::addmsg("<font style='color:red'>当前访问的模板文件:  {$tplpath} 不存在</font>");
         } else {
             $this->error('抱歉, 访问的页面不存在!');
         }
     } else {
         if (C('DEBUG')) {
             Debug::addmsg("当前访问的模板文件: {$tplpath}");
         }
         //预定义目录
         $root = rtrim(substr(C('PRO_PATH'), strlen(rtrim($_SERVER["DOCUMENT_ROOT"], "/\\"))), '/\\');
         $resource = rtrim(dirname($_SERVER["SCRIPT_NAME"]), "/\\") . '/' . ltrim(C('APP_PATH'), './') . "/View/" . C('TPL_STYLE') . "/Resource/";
         $url = $_SERVER['SCRIPT_NAME'] . '/' . $_GET['m'];
         $this->assign('root', $root);
         $this->assign('public', $root . '/Public');
         $this->assign('res', $resource);
         $this->assign('url', $url);
         parent::display($resource_name, $cache_id, $compile_id);
     }
 }
 /**
  * display *$cache_id是变化的这样,smarty才可以动态缓存,缓存的ID 用URL来做!因为每一个URL是不相同的!$_SERVER['REQUEST_URI'];
  * 
  * @Param $resource_name 
  * @Param $cache_id 
  * @Param $compile_id 
  * @Access public
  * @Return void
  */
 function display($resource_name = '', $cache_id = NULL, $compile_id = NULL)
 {
     $this->assign('root', rtrim($GLOBALS['root'], '/'));
     $this->assign('app', $GLOBALS['app']);
     $this->assign('url', $GLOBALS['url']);
     $this->assign('res', $GLOBALS['res']);
     $this->assign('public', rtrim(MYPUBLIC, '/'));
     $this->assign('PUBLIC', $GLOBALS['public']);
     $this->assign('CSS', rtrim(__CSS__, '/'));
     $this->assign('IMAGES', rtrim(__IMAGES__, '/'));
     $this->assign('JS', rtrim(__JS__, '/'));
     $this->assign('UPLOAD', rtrim(__UPLOAD__, '/'));
     $this->assign('css', rtrim(CSS, '/'));
     $this->assign('js', rtrim(JS, '/'));
     $this->assign('images', rtrim(IMAGES, '/'));
     if (empty($resource_name)) {
         $resource_name = $_GET['m'] . '/' . $_GET['a'] . '.' . TPL_PREFIX;
         //这个就规定了必须新建一个控制器目录里面放模板文件
     } else {
         if (strstr($resource_name, '/')) {
             //如果有斜线的话就找指定的文件
             $resource_name = $resource_name . '.' . TPL_PREFIX;
             //这里的意思是传了  比如index/update
         } else {
             //这是只传方法名的情况,比如$this->display('display');
             $resource_name = $_GET['m'] . '/' . $resource_name . '.' . TPL_PREFIX;
         }
     }
     if (!file_exists($this->template_dir . $resource_name)) {
         Debug::addmsg('[<font color="red">模板错误</font>]:<font color="red">' . $this->template_dir . $resource_name . '模板不存在</font>');
     }
     parent::display($resource_name, $cache_id, $compile_id, TRUE);
 }
示例#6
0
/**
 * 输出各种类型的数据,调试程序时打印数据使用。
 * @param	mixed	参数:可以是一个或多个任意变量或值
 */
function p()
{
    $args = func_get_args();
    //获取多个参数
    if (count($args) < 1) {
        Debug::addmsg("<font color='red'>必须为p()函数提供参数!");
        return;
    }
    echo '<div style="width:100%;text-align:left"><pre>';
    //多个参数循环输出
    foreach ($args as $arg) {
        if (is_array($arg)) {
            print_r($arg);
            echo '<br>';
        } else {
            if (is_string($arg)) {
                echo $arg . '<br>';
            } else {
                var_dump($arg);
                echo '<br>';
            }
        }
    }
    echo '</pre></div>';
}
示例#7
0
 function run()
 {
     if (method_exists($this, 'init')) {
         $this->init();
     }
     $C = !isset($_GET['a']) ? 'index' : strtolower($_GET['a']);
     if (method_exists($this, $C)) {
         $this->{$C}();
     } else {
         Debug::addmsg('<font color="red">控制器' . ucfirst(strtolower($_GET['m'])) . 'Action中没有' . $C . '这个方法</font>');
     }
     parent::__construct();
 }
示例#8
0
 public function zoom($path, $background, $width, $height, $prefix = 'zo_')
 {
     if (!self::checkpath($background)) {
         Debug::addmsg('缩放图片路径不正确!');
     }
     $backInfo = self::getInfo($background);
     $backres = self::open_img($background, $backInfo['type']);
     $newsize = self::getNewSize($width, $height, $backInfo);
     $newres = self::kidOfImage($backres, $newsize, $backInfo);
     $newpath = self::getnewpath($path, $prefix, $backInfo, self::$randfix);
     $newPathName = self::saveImg($backInfo['type'], $newres, $newpath);
     imagedestroy($newres);
     return $newPathName;
 }
示例#9
0
/**
 * 优化的require_once
 * @param $filename
 * @return mixed
 */
function require_cache($filename)
{
    static $_importFiles = array();
    if (!isset($_importFiles[$filename])) {
        if (is_file($filename)) {
            require $filename;
            Debug::addmsg("<b> {$filename} </b>", 1);
            //在debug中显示自动包含的类
            $_importFiles[$filename] = true;
        } else {
            $_importFiles[$filename] = false;
            Debug::addmsg("文件{$filename}不存在", 1);
        }
    }
    return $_importFiles[$filename];
}
示例#10
0
 /**
  * 该方法用来运行框架中的操制器,在brophp.php入口文件中调用
  */
 function run()
 {
     if ($this->left_delimiter != "<{") {
         parent::__construct();
     }
     //如果有子类Common,调用这个类的init()方法 做权限控制
     if (method_exists($this, "init")) {
         $this->init();
     }
     //根据动作去找对应的方法
     $method = $_GET["a"];
     if (method_exists($this, $method)) {
         $this->{$method}();
     } else {
         Debug::addmsg("<font color='red'>没有{$_GET["a"]}这个操作!</font>");
     }
 }
示例#11
0
 public function __construct($width = 60, $height = 60, $codeNum = 4, $codeType = 3, $shapeType = 1, $fontTextShow = FALSE, $fontType = './Reluctance/Classes/Fonts/heiti.ttf', $imgOutType = 'gif')
 {
     self::$width = $width;
     self::$height = $height;
     self::$codeNum = $codeNum;
     self::$codeType = $codeType;
     self::$shapeType = $shapeType;
     self::$imgOutType = $imgOutType;
     self::$fontTextShow = $fontTextShow;
     if (!file_exists($fontType)) {
         $GLOBALS['debug'] = 1;
         Debug::addmsg('<font color="red">验证码字体路径不存在</font>');
     } else {
         self::$fontType = $fontType;
     }
     self::$img = imagecreatetruecolor($width, $height);
     self::$codeStringArray = self::getCodeString($codeType);
 }
示例#12
0
 /**
  * 该方法用来运行框架中的控制器,在入口文件huphp.php文件中调用
  */
 public function run()
 {
     //如果子类中有Common类的init()方法,则自动调用(可做权限控制)
     if (method_exists($this, 'init')) {
         $this->init();
     }
     //根据动作($_GET['a']去找相应的方法)
     $method = $_GET['a'];
     if (method_exists($this, $method)) {
         $this->{$method}();
     } else {
         if (DEBUG) {
             Debug::addmsg('<font color="red">没有' . $_GET['a'] . '这个操作!</font>');
         } else {
             self::_404();
         }
     }
 }
示例#13
0
 /**
  * 连贯操作调用field() where() order() limit() group() having()方法,组合SQL语句
  */
 function __call($methodName, $args)
 {
     $methodName = strtolower($methodName);
     if (array_key_exists($methodName, $this->sql)) {
         if (empty($args[0]) || is_string($args[0]) && trim($args[0]) === '') {
             $this->sql[$methodName] = "";
         } else {
             $this->sql[$methodName] = $args;
         }
         if ($methodName == "limit") {
             if ($args[0] == "0") {
                 $this->sql[$methodName] = $args;
             }
         }
     } else {
         Debug::addmsg("<font color='red'>调用类" . get_class($this) . "中的方法{$methodName}()不存在!</font>");
     }
     return $this;
 }
示例#14
0
 function display($resource_name = null, $cache_id = null, $compile_id = null)
 {
     //将部分全局变量直接分配到模板中使用
     $this->assign("root", B_ROOT);
     $this->assign("app", B_APP);
     $this->assign("url", B_URL);
     $this->assign("public", B_PUBLIC);
     $this->assign("res", B_RES);
     if (is_null($resource_name)) {
         $resource_name = "{$_GET["m"]}/{$_GET["a"]}." . TPLPREFIX;
     } else {
         if (strstr($resource_name, "/")) {
             $resource_name = $resource_name . "." . TPLPREFIX;
         } else {
             $resource_name = $_GET["m"] . "/" . $resource_name . "." . TPLPREFIX;
         }
     }
     Debug::addmsg("使用模板 <b> {$resource_name} </b>");
     parent::display($resource_name, $cache_id, $compile_id);
 }
示例#15
0
 /**
  * 连贯操作调用field() where() order() limit() group() having()方法,作用是把你在程序里传的方法和参数打到全局的属性里,为了在下面个各种操作中调用,这些关键词都不能单独使用(这些都是需要传递参数的SQL语句)
  */
 public function __call($methodName, $args)
 {
     //$args 传进来以后变数组(自动加一维)
     $methodName = strtolower($methodName);
     if (array_key_exists($methodName, $this->sql)) {
         //如果$this->sql数组里面设置了传过来的连贯操作的方法
         if (empty($args[0]) || is_string($args[0]) && trim($args[0]) === '') {
             $this->sql[$methodName] = '';
         } else {
             $this->sql[$methodName] = $args;
         }
         if ($methodName == 'limit') {
             if ($args[0] == '0') {
                 $this->sql[$methodName] = $args;
             }
         }
     } else {
         Debug::addmsg('<font color="red">调用类' . get_class($this) . '中的方法' . $methodName . '()不存在</font>');
     }
     return $this;
 }
示例#16
0
 /**
  * 重载Smarty中的display方法
  * @param	string	$resource_name	模板的位置
  * @param	mixed	$cache_id		缓存的ID
  */
 public function display($resource_name = null, $cache_id = null, $compile_id = null)
 {
     //将部分全局变量直接分配到Smarty模板中
     $this->assign('root', H_ROOT);
     $this->assign('app', H_APP);
     $this->assign('url', H_URL);
     $this->assign('public', H_PUBLIC);
     $this->assign('res', H_RES);
     if (is_null($resource_name)) {
         $resource_name = $_GET['m'] . '/' . $_GET['a'] . '.' . TPLPREFIX;
     } else {
         $resource_name = trim($resource_name, '/');
         if (strstr($resource_name, '/')) {
             $resource_name = $resource_name . '.' . TPLPREFIX;
         } else {
             $resource_name = $_GET['m'] . '/' . $resource_name . '.' . TPLPREFIX;
         }
     }
     Debug::addmsg('使用模板<b>' . $resource_name . '</b>');
     parent::display($resource_name, $cache_id, $compile_id);
 }
示例#17
0
function __autoload($className)
{
    if ($className == 'Smarty') {
        include 'Smarty/Smarty.class.php';
    } else {
        if ($className == 'Memcache') {
            return TRUE;
        } else {
            if ($className == 'PHPExcel') {
                include $className . '.php';
            } else {
                if (strstr($className, '_')) {
                    $classPathArr = explode('_', $className);
                    include join('/', $classPathArr) . '.php';
                } else {
                    include $className . '.class.php';
                }
            }
        }
    }
    Debug::addmsg($className, 1);
}
示例#18
0
 public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
 {
     //将部分常量分配给模板
     $this->assign('__ROOT__', __ROOT__);
     $this->assign('__APP__', __APP__);
     $this->assign('__URL__', __URL__);
     $this->assign('__ACTION__', __ACTION__);
     $this->assign('__ROUTE__', CONTROLLER_NAME . '/' . ACTION_NAME);
     $this->assign('__SELF__', __SELF__);
     $this->assign('siteName', C('siteName'));
     if (is_null($template)) {
         $template = CONTROLLER_NAME . '/' . ACTION_NAME . C('view_suffix');
     } elseif (strstr($template, '.')) {
         //直接使用模板路径
     } elseif (strstr($template, '/')) {
         $template = strtolower($template);
         $template = $template . C('view_suffix');
     } else {
         $template = CONTROLLER_NAME . '/' . $template . C('view_suffix');
     }
     Debug::addmsg("使用模板 {$template} ");
     parent::display($template, $cache_id, $compile_id, $parent);
 }
示例#19
0
 /** 
  * 为图片添加水印
  * @param	string	$groundName	背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式; 
  * @param	string	$waterName	图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式; 
  * @param	int	$waterPos	水印位置,有10种状态,0为随机位置; 
  * 					1为顶端居左,2为顶端居中,3为顶端居右; 
  * 					4为中部居左,5为中部居中,6为中部居右; 
  *					7为底端居左,8为底端居中,9为底端居右; 
  * @param	string	$qz		加水印后的图片的文件名在原文件名前面加上这个前缀,。
  * @return	mixed			是生成水印后的图片名称,失败返回false;
  */
 function waterMark($groundName, $waterName, $waterPos = 0, $qz = "wa_")
 {
     $this->path = rtrim($this->path, "/") . "/";
     if (file_exists($this->path . $groundName) && file_exists($this->path . $waterName)) {
         $groundInfo = $this->getInfo($groundName);
         //获取背景信息
         $waterInfo = $this->getInfo($waterName);
         //获取水印图片信息
         if (!($pos = $this->position($groundInfo, $waterInfo, $waterPos))) {
             Debug::addmsg("<font color='red'>水印不应该比背景图片小!</font>");
             return false;
         }
         $groundImg = $this->getImg($groundName, $groundInfo);
         //获取背景图像资源
         $waterImg = $this->getImg($waterName, $waterInfo);
         //获取水印图片资源
         $groundImg = $this->copyImage($groundImg, $waterImg, $pos, $waterInfo);
         //拷贝图像
         return $this->createNewImage($groundImg, $qz . $groundName, $groundInfo);
     } else {
         Debug::addmsg("<font color='red'>图片或水印图片不存在!</font>");
         return false;
     }
 }
示例#20
0
 /**
  * 自动获取表结构
  */
 function setTable($tabName)
 {
     $cachefile = C('RUN_PATH') . "/Data/" . $tabName . ".php";
     $this->tabName = C('DB_PREFIX') . $tabName;
     //加前缀的表名
     if (!file_exists($cachefile)) {
         try {
             $pdo = self::connect();
             $stmt = $pdo->prepare("desc {$this->tabName}");
             $stmt->execute();
             $auto = "yno";
             $fields = array();
             while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                 if ($row["Key"] == "PRI") {
                     $fields["pri"] = strtolower($row["Field"]);
                 } else {
                     $fields[] = strtolower($row["Field"]);
                 }
                 if ($row["Extra"] == "auto_increment") {
                     $auto = "yes";
                 }
             }
             //如果表中没有主键,则将第一列当作主键
             if (!array_key_exists("pri", $fields)) {
                 $fields["pri"] = array_shift($fields);
             }
             if (!C('DEBUG')) {
                 file_put_contents($cachefile, "<?php " . json_encode($fields) . $auto);
             }
             $this->fieldList = $fields;
             $this->auto = $auto;
         } catch (PDOException $e) {
             Debug::addmsg("<font color='red'>异常:" . $e->getMessage() . '</font>');
         }
     } else {
         $json = ltrim(file_get_contents($cachefile), "<?ph ");
         $this->auto = substr($json, -3);
         $json = substr($json, 0, -3);
         $this->fieldList = (array) json_decode($json, true);
     }
     Debug::addmsg("表<b>{$this->tabName}</b>结构:" . implode(",", $this->fieldList), 2);
     //debug
 }
示例#21
0
        } else {
            Debug::addmsg('开启Memcache');
        }
    } else {
        Debug::addmsg('<font color="red">PHP没有安装memcache扩展模块,请先安装!</font>');
    }
} else {
    Debug::addmsg('<span style="color:red;">[未使用Memcache]</span>');
}
if (IS_SESSION_TO_MEMCACHE && MEMCACHE) {
    SessionToMem::start(MyMemcache::getMemcache());
    Debug::addmsg('开启Session==>Memcache');
} else {
    session_start();
}
Debug::addmsg('SessionID: ' . session_id());
if (empty($_SESSION['configMtime'])) {
    $_SESSION['configMtime'] = filemtime('./Public/Config.inc.php');
}
if (filemtime('./Public/Config.inc.php') > $_SESSION['configMtime']) {
    Struct::init();
    //当修改配置文件,同样执行一次框架结构类
    //自动根据数据库驱动切换继承关系
    $_SESSION['configMtime'] = filemtime('./Public/Config.inc.php');
    $String = file_get_contents(RELUC_DIR . 'Kernel/Model.class.php');
    $replaceMent = 'extends Base' . ucfirst(strtolower(DB_DRIVER)) . "\n";
    $String = preg_replace('/extends\\s+\\w+\\s+/', $replaceMent, $String);
    file_put_contents(RELUC_DIR . 'Kernel/Model.class.php', $String);
}
$_GET['m'] = !isset($_GET['m']) ? 'index' : strtolower($_GET['m']);
$_GET['a'] = !isset($_GET['a']) ? 'index' : strtolower($_GET['a']);
示例#22
0
 /**
  * 自动换取表结构
  */
 public function setTable($tabName)
 {
     $cachefile = PROJECT_PATH . 'runtime/data/' . $tabName . '.php';
     $this->tabName = TABPREFIX . $tabName;
     if (!file_exists($cachefile)) {
         try {
             $pdo = self::connect();
             $stmt = $pdo->prepare('desc ' . $this->tabName);
             $stmt->execute();
             $auto = 'yno';
             $fields = array();
             while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                 if ($row['Key'] == 'PRI') {
                     $fields['pri'] = strtolower($row['Field']);
                 } else {
                     $fields[] = strtolower($row['Field']);
                 }
                 if ($row['Extra'] == 'auto_increment') {
                     $auto = 'yes';
                 }
             }
             //如果没有主键,则将第一列作为主件
             if (!array_key_exists('pri', $fields)) {
                 $fields['pri'] = array_shift($fields);
             }
             //如果关闭了Debug
             if (!DEBUG) {
                 file_put_contents($cachefile, '<?php ' . json_encode($fields) . $auto);
             }
             $this->fieldList = $fields;
             $this->auto = $auto;
         } catch (PDOException $e) {
             Debug::addmsg('<font color="red">异常:' . $e->getMessage() . '</font>');
         }
     } else {
         $json = ltrim(file_get_contents($cachefile), '<?ph ');
         $this->auto = substr($json, -3);
         $json = substr($json, 0, -3);
         $this->fieldList = (array) json_decode($json, true);
     }
     Debug::addmsg('表<b>' . $this->tabName . '</b>结构:' . implode(',', $this->fieldList), 2);
 }
示例#23
0
    public static function model($className, $app)
    {
        $driver = 'D' . DRIVER;
        //数据库扩展技术父类名
        $path = PROJECT_PATH . 'runtime/models/' . TMPPATH;
        //model在runtime文件夹里生成的文件夹
        //不跨域
        if ($app == '') {
            $src = APP_PATH . 'models/' . strtolower($className) . '.class.php';
            //本项目文件夹下的model文件
            $psrc = APP_PATH . 'models/___.class.php';
            //假设本项目文件夹下的model父类(带替换)
            $className = ucfirst($className) . 'Model';
            //Model类名
            $parentClass = '___model';
            //假设Model父类的文件名(带替换)
            $to = $path . strtolower($className) . '.class.php';
            //在runtime文件夹里生成的类路径名称
            $pto = $path . $parentClass . '.class.php';
            //在runtime文件夹里生成的父类路径名称
            //有传APP则跨域(跨项目应用)
        } else {
            $src = PROJECT_PATH . $app . '/models/' . strtolower($className) . '.class.php';
            //对过域下面的model文件
            $psrc = PROJECT_PATH . $app . '/models/___.class.php';
            //对过域下面的假设model父类文件(带替换)
            $className = ucfirst($app) . ucfirst($className) . 'Model';
            //对过域下面的model类名
            $parentClass = ucfirst($app) . '___model';
            //对过域下面的假设Model父类的文件名(带替换)
            $to = $path . strtolower($className) . '.class.php';
            //在runtime文件夹里生成的类路径名称
            $pto = $path . $parentClass . '.class.php';
            //在runtime文件夹里生成的父类路径名称
        }
        //如果项目model文件夹下里已有原model存在
        if (file_exists($src)) {
            $classContent = file_get_contents($src);
            $super = '/extends\\s+(.+?)\\s*{/i';
            //查看是否有父类,如果已有父类
            if (preg_match($super, $classContent, $arr)) {
                /**
                 * $psrc	如果已有父类,父类的在model文件夹下的路径文件名
                 * $pto		如果已有父类,父类的在runtime文件夹下的路径文件名
                 */
                $psrc = str_replace('___', strtolower($arr[1]), $psrc);
                $pto = str_replace('___', strtolower($arr[1]), $pto);
                //父类的在原model文件夹下在存在
                if (file_exists($psrc)) {
                    if (!file_exists($pto) || filemtime($psrc) > filemtime($pto)) {
                        $pclassContent = file_get_contents($psrc);
                        $preg = '/class\\s+(.+?)\\s*{/i';
                        $pclassContent = preg_replace($preg, 'class ' . $arr['1'] . 'Model extends ' . $driver . ' {', $pclassContent, 1);
                        //生成runtime文件夹下的model的父类的文件
                        file_put_contents($pto, $pclassContent);
                    }
                } else {
                    Debug::addmsg('<font color="red">文件' . $psrc . '不存在</font>');
                }
                //继承完数据库扩展类以后,将$driver重新赋值为父类的类名,以便子类使用
                $driver = $arr['1'] . 'Model';
                include_once $pto;
                Debug::addmsg('<b>' . $driver . '</b>类', 1);
            }
            //model生成处理(没有父类或者不是父类!)
            if (!file_exists($to) || filemtime($src) > filemtime($to)) {
                $preg = '/class\\s+(.+?)\\s*{/i';
                //$driver如有有父类则接受赋值,不然直接继承数据库扩展类
                $classContent = preg_replace($preg, 'class ' . $className . ' extends ' . $driver . ' {', $classContent, 1);
                //生成runtime文件夹下的model
                file_put_contents($to, $classContent);
            }
        } else {
            if (!file_exists($to)) {
                $classContent = <<<st
<?php
\tclass {$className} extends {$driver} {
\t\t\t\t
\t}\t\t\t\t
st;
                //生成runtime文件夹下的直接集成数据库扩展技术类的MODEL
                file_put_contents($to, $classContent);
            }
        }
        include_once $to;
        Debug::addmsg('<b>' . $className . '</b>类', 1);
        return $className;
    }
示例#24
0
 static function model($className, $app)
 {
     $driver = "D" . DRIVER;
     //父类名
     $path = PROJECT_PATH . "runtime/models/" . TMPPATH;
     if ($app == "") {
         $src = APP_PATH . "models/" . strtolower($className) . ".class.php";
         $psrc = APP_PATH . "models/___.class.php";
         $className = ucfirst($className) . 'Model';
         $parentClass = '___model';
         $to = $path . strtolower($className) . ".class.php";
         $pto = $path . $parentClass . ".class.php";
     } else {
         $src = PROJECT_PATH . $app . "/models/" . strtolower($className) . ".class.php";
         $psrc = PROJECT_PATH . $app . "/models/___.class.php";
         $className = ucfirst($app) . ucfirst($className) . 'Model';
         $parentClass = ucfirst($app) . '___model';
         $to = $path . strtolower($className) . ".class.php";
         $pto = $path . $parentClass . ".class.php";
     }
     //如果有原model存在
     if (file_exists($src)) {
         $classContent = file_get_contents($src);
         $super = '/extends\\s+(.+?)\\s*{/i';
         //如果已经有父类
         if (preg_match($super, $classContent, $arr)) {
             $psrc = str_replace("___", strtolower($arr[1]), $psrc);
             $pto = str_replace("___", strtolower($arr[1]), $pto);
             if (file_exists($psrc)) {
                 if (!file_exists($pto) || filemtime($psrc) > filemtime($pto)) {
                     $pclassContent = file_get_contents($psrc);
                     $pclassContent = preg_replace('/class\\s+(.+?)\\s*{/i', 'class ' . $arr[1] . 'Model extends ' . $driver . ' {', $pclassContent, 1);
                     file_put_contents($pto, $pclassContent);
                 }
             } else {
                 Debug::addmsg("<font color='red'>文件{$psrc}不存在!</font>");
             }
             $driver = $arr[1] . "Model";
             include_once $pto;
         }
         if (!file_exists($to) || filemtime($src) > filemtime($to)) {
             $classContent = preg_replace('/class\\s+(.+?)\\s*{/i', 'class ' . $className . ' extends ' . $driver . ' {', $classContent, 1);
             //生成model
             file_put_contents($to, $classContent);
         }
     } else {
         if (!file_exists($to)) {
             $classContent = "<?php\n\tclass {$className} extends {$driver}{\n\t}";
             //生成model
             file_put_contents($to, $classContent);
         }
     }
     include_once $to;
     return $className;
 }
示例#25
0
 /**
  * 自动获取表结构
  * @param	string	$tabName	表名
  */
 public function setTable($tabName)
 {
     //设置缓存表结构的文件的位置
     $cachefile = PROJECT_PATH . 'runtime/data/' . $tabName . '.php';
     $this->tabName = TABPREFIX . $tabName;
     //合成表名
     //如果缓存表结构存在
     if (file_exists($cachefile)) {
         $json = ltrim(file_get_contents($cachefile), '<?ph ');
         $this->auto = substr($json, -3);
         $json = substr($json, 0, -3);
         $this->fieldList = (array) json_decode($json, true);
     } else {
         $mysqli = self::connect();
         if ($mysqli) {
             $result = $mysqli->query('desc ' . $this->tabName);
         } else {
             return;
         }
         $fields = array();
         $auto = 'yno';
         while ($row = $result->fetch_assoc()) {
             if ($row['Key'] == 'PRI') {
                 $fields['pri'] = strtolower($row['Field']);
             } else {
                 $fields[] = strtolower($row['Field']);
             }
             if ($row['Extra'] == 'auto_increment') {
                 $auto = 'yes';
             }
         }
         //如果表没有主键,则用第一列当主键
         if (!array_key_exists('pri', $fields)) {
             $fields['pri'] = array_shift($fields);
         }
         //如果关闭Debug,则将缓存表结构
         if (!DEBUG) {
             file_put_contents($cachefile, '<?php ' . json_encode($fields) . $auto);
         }
         $this->fieldList = $fields;
         $this->auto = $auto;
     }
     Debug::addmsg('表<b>' . $this->tabName . '</b>结构:' . implode(',', $this->fieldList), 2);
 }
示例#26
0
 /**
 在一个大的背景图片中剪裁出指定区域的图片
 @param	string	$name	需要剪切的背景图片
 @param	int	$x	剪切图片左边开始的位置
 @param	int	$y	剪切图片顶部开始的位置
 @param	int	$width	图片剪裁的宽度
 @param	int	$height	图片剪裁的高度
 @param	string	$qz	是新图片的前缀
 @return	mixed		是裁剪后的图片名称,失败返回false;
 */
 function cut($name, $x, $y, $width, $height, $qz = "cu_")
 {
     $imgInfo = $this->getInfo($name);
     //获取图片信息
     if ($x + $width > $imgInfo['width'] || $y + $height > $imgInfo['height']) {
         Debug::addmsg("<font color='red'>裁剪的位置超出了图片范围!</font>");
         return false;
     }
     $back = $this->getImg($name, $imgInfo);
     //获取图片资源
     /* 创建一个可以保存裁剪后图片的资源 */
     $cutimg = imagecreatetruecolor($width, $height);
     /* 使用imagecopyresampled()函数对图片进行裁剪 */
     imagecopyresampled($cutimg, $back, 0, 0, $x, $y, $width, $height, $width, $height);
     imagedestroy($back);
     return $this->createNewImage($cutimg, $qz . $name, $imgInfo);
     //返回新生成的缩略图的名称,以"cu_"为前缀
 }
示例#27
0
/**
 * 实例化一个没有模型文件的Model
 * @param string $name Model名称 支持指定基础模型 例如 MongoModel:User
 * @param string $tablePrefix 表前缀
 * @param mixed $connection 数据库连接信息
 * @return Model
 */
function M($name = '', $app = '')
{
    $db_class = "Db" . ucfirst(strtolower(C('DB_TYPE')));
    $name = ucfirst(strtolower($name));
    $controler_src = C('APP_PATH') . '/Model/' . $name . 'Model.class.php';
    $runfile = C('RUN_PATH') . '/Model/' . $name . 'Model.class.php';
    if (file_exists($controler_src)) {
        if (!file_exists($runfile) || C('DEBUG')) {
            file_put_contents($runfile, strip_whitespace(file_get_contents($controler_src)));
        }
        Debug::addmsg("当前操作的Model类: {$controler_src}");
        return $name . 'Model';
    } else {
        return $db_class;
    }
}
示例#28
0
文件: huphp.php 项目: BigMaster/Huphp
}
$GLOBALS['url'] = REWRITE ? '/' . $_GET['m'] . '/' : $GLOBALS['app'] . $_GET['m'] . '/';
//当前的模块
define('H_ROOT', rtrim($GLOBALS['root'], '/'));
define('H_PUBLIC', rtrim($GLOBALS['public'], '/'));
define('H_RES', rtrim($GLOBALS['res'], '/'));
define('H_APP', rtrim($GLOBALS['app'], '/'));
define('H_URL', rtrim($GLOBALS['url'], '/'));
//访问的当前的控制器所在的路径文件
$srccontrolerfile = APP_PATH . 'controls/' . strtolower($_GET['m']) . '.class.php';
Debug::addmsg('当前访问的控制器类在项目应用下的:<b>' . $srccontrolerfile . '</b>文件!');
//控制器类的创建
if (file_exists($srccontrolerfile)) {
    Structure::commoncontroler(APP_PATH . 'controls/', $controlerpath);
    Structure::controler($srccontrolerfile, $controlerpath, $_GET['m']);
    $className = ucfirst($_GET['m']) . 'Action';
    $controler = new $className();
    $controler->run();
} else {
    if (DEBUG) {
        Debug::addmsg('<font color="red">对不起,访问的模块不存在,应该在' . APP_PATH . 'controls目录创建文件名为' . strtolower($_GET['m']) . '.class.php的文件,声明一个类名为' . ucfirst($_GET['m']) . '的类!</font>');
    } else {
        //Debug关闭时转换为404模式
        Action::_404();
    }
}
//输出Debug模式的信息
if (defined('DEBUG') && DEBUG == 1 && $GLOBALS['debug'] == 1) {
    Debug::stop();
    Debug::message();
}
示例#29
0
 /**
  * 自动获取表结构
  * @param	string	$tabName	表名
  */
 function setTable($tabName)
 {
     $cachefile = C('RUN_PATH') . "/Data/" . $tabName . ".php";
     $this->tabName = C('DB_PREFIX') . $tabName;
     //加前缀的表名
     if (file_exists($cachefile)) {
         $json = ltrim(file_get_contents($cachefile), "<?ph ");
         $this->auto = substr($json, -3);
         $json = substr($json, 0, -3);
         $this->fieldList = (array) json_decode($json, true);
     } else {
         $mysqli = self::connect();
         if ($mysqli) {
             $result = $mysqli->query("desc {$this->tabName}");
         } else {
             return;
         }
         $fields = array();
         $auto = "yno";
         while ($row = $result->fetch_assoc()) {
             if ($row["Key"] == "PRI") {
                 $fields["pri"] = strtolower($row["Field"]);
             } else {
                 $fields[] = strtolower($row["Field"]);
             }
             if ($row["Extra"] == "auto_increment") {
                 $auto = "yes";
             }
         }
         //如果表中没有主键,则将第一列当作主键
         if (!array_key_exists("pri", $fields)) {
             $fields["pri"] = array_shift($fields);
         }
         if (!C('DEBUG')) {
             file_put_contents($cachefile, "<?php " . json_encode($fields) . $auto);
         }
         $this->fieldList = $fields;
         $this->auto = $auto;
     }
     Debug::addmsg("表<b>{$this->tabName}</b>结构:" . implode(",", $this->fieldList), 2);
     //debug
 }
示例#30
0
 /**
  * 事务回滚
  * @access public
  * @return boolen
  */
 public function rollback()
 {
     if ($this->transTimes > 0) {
         $result = $this->_db->rollback();
         $this->transTimes = 0;
         if (!$result) {
             Debug::addmsg($this->error());
         }
     }
     return true;
 }