Ejemplo n.º 1
0
 /**
  * 内容列表,内容管理
  * @param $cid
  */
 public function showManage($cid)
 {
     $cid = intval($cid);
     $category = model('category')->where('cid', $cid)->getOne();
     $category['is_page'] = model('model')->where('modelid', $category['cat_modelid'])->getOne('is_page');
     $category['is_page'] = $category['is_page'][0];
     if ($category['is_page'] == 1) {
         header('Location:' . Router::$router->url('Content/page/edit', array('cid' => $cid)));
     } else {
         $page = isset($_GET['page']) ? $_GET['page'] : 1;
         if ($page < 1) {
             $page = 1;
         }
         $num = 10;
         //页面显示的结果数量
         $categoryDet = model($category['catetable'])->where('id', $category['catid'])->getOne('catname');
         $data['catname'] = $categoryDet['catname'];
         $count = model($category['contable'])->where('cid', $cid)->count();
         $pageO = Loader::plugin('page');
         $pageO->init($count, Router::$router->url('content/content/manage', array('page' => '%page%', 'cid' => $cid)), $page, $num);
         $pages = $pageO->p();
         $content = model($category['contable'])->where('cid', $cid)->orderby($category['contable'] . '.listorder desc')->limit($pages['min'], $num)->query();
         $data['cid'] = $cid;
         $data['content'] = model()->stripslashes($content);
         $data['pages'] = $pages['html'];
         $data['pageNum'] = $pages['pageNum'];
         view('Content/content_manage', $data);
     }
     //var_dump($category);
 }
Ejemplo n.º 2
0
/**
 * 图片等比缩放,优先宽度
 * @param $imgUrl           图片地址
 * @param bool $width       宽度
 * @param bool $height      高度
 */
function thumb($imgUrl, $width = 'auto', $height = 'auto')
{
    if ($width == false && $height == false) {
        echo $imgUrl;
        return;
    } else {
        if ($width == 'auto' && $height == 'auto') {
            echo $imgUrl;
            return;
        }
        $img = Loader::plugin('image');
        $info = pathinfo($imgUrl);
        $dir = explode('/', $info['dirname']);
        $dir = $dir[3];
        $picPath = __ROOT__ . 'runtime/thumb/' . $dir . '/' . $info['filename'] . '/' . $width . 'X' . $height . '.png';
        $urlpath = '/runtime/thumb/' . $dir . '/' . $info['filename'] . '/' . $width . 'X' . $height . '.png';
        $info = pathinfo($picPath);
        if (!is_dir($info['dirname'])) {
            mkdir($info['dirname'], 0777, 1);
        }
        //var_dump($info);exit;
        if (file_exists($picPath)) {
            echo $urlpath;
            return;
        }
        $image = $img->CreateThumbnail(__ROOT__ . $imgUrl, $width == 'auto' ? false : $width, $height == 'auto' ? false : $height, $picPath);
        echo $urlpath;
    }
}
Ejemplo n.º 3
0
 function checkcode()
 {
     $checkcode = Loader::plugin('checkcode');
     if (isset($_GET['code_len']) && intval($_GET['code_len'])) {
         $checkcode->code_len = intval($_GET['code_len']);
     }
     if ($checkcode->code_len > 8 || $checkcode->code_len < 2) {
         $checkcode->code_len = 4;
     }
     if (isset($_GET['font_size']) && intval($_GET['font_size'])) {
         $checkcode->font_size = intval($_GET['font_size']);
     }
     if (isset($_GET['width']) && intval($_GET['width'])) {
         $checkcode->width = intval($_GET['width']);
     }
     if ($checkcode->width <= 0) {
         $checkcode->width = 130;
     }
     if (isset($_GET['height']) && intval($_GET['height'])) {
         $checkcode->height = intval($_GET['height']);
     }
     if ($checkcode->height <= 0) {
         $checkcode->height = 50;
     }
     $max_width = $checkcode->code_len * 28;
     $max_height = $checkcode->font_size * 2;
     if ($checkcode->width > $max_width) {
         $checkcode->width = $max_width;
     }
     if ($checkcode->height > $max_height) {
         $checkcode->height = $max_height;
     }
     if (isset($_GET['font_color']) && trim(urldecode($_GET['font_color'])) && preg_match('/(^#[a-z0-9]{6}$)/im', trim(urldecode($_GET['font_color'])))) {
         $checkcode->font_color = trim(urldecode($_GET['font_color']));
     }
     if (isset($_GET['background']) && trim(urldecode($_GET['background'])) && preg_match('/(^#[a-z0-9]{6}$)/im', trim(urldecode($_GET['background'])))) {
         $checkcode->background = trim(urldecode($_GET['background']));
     }
     $checkcode->doimage();
     $_SESSION['code'] = $checkcode->get_code();
     exit;
 }
Ejemplo n.º 4
0
 /**
  * @param $user          要修改的用户信息
  * @param $userid        用户ID
  * @return bool OR int   状态或者错误码
  */
 public function edit_profile($user, $userid)
 {
     $user = $this->addslashes($user);
     $validate = Loader::plugin('validate');
     ######### 会删除掉无用的字段 ########
     foreach ($user as $field => $v) {
         if (!in_array($field, $this->allowField)) {
             unset($user[$field]);
         }
     }
     if (isset($user['nickername'])) {
         if (!$validate->check($user['nickername'], 'nickername')) {
             return 1;
         }
     }
     //昵称不合法
     if (isset($user['email'])) {
         if (!$validate->check($user['email'], 'email')) {
             return 2;
         }
     }
     //邮箱不合法
     if (isset($user['qq'])) {
         if (!$validate->check($user['qq'], 'qq')) {
             return 3;
         }
     }
     //qq号码不合法
     if (isset($user['mobile'])) {
         if (!$validate->check($user['mobile'], 'mobile')) {
             return 4;
         }
     }
     //手机号码不正确
     if ($this->where('userid', $userid)->update($user)) {
         return 0;
     } else {
         return -1;
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * @param string $action
  * @param string $type
  * @param int $page
  */
 public function attach($action = 'manage', $type = 'all', $page = 1)
 {
     if ($action == 'manage') {
         $page = intval($page);
         $listNum = 10;
         //列表数量
         if ($type == 'all') {
             $atm = model('attaches');
         } elseif ($type == 'image') {
             $atm = model('attaches')->where('attachtype', 'image');
         } elseif ($type == 'file') {
             $atm = model('attaches')->where('attachtype', 'file');
         } elseif ($type == 'flash') {
             $atm = model('attaches')->where('attachtype', 'flash');
         } elseif ($type == 'media') {
             $atm = model('attaches')->where('attachtype', 'media');
         } else {
             $atm = model('attaches')->where('attachtype', 'image');
         }
         $select = array('admin.realname', 'admin.username', 'attaches.*');
         $atm->leftJoin('admin', 'admin.userid', 'attaches.userid')->select($select);
         $atm1 = clone $atm;
         //克隆模型
         $count = $atm->count();
         $pager = Loader::plugin('page');
         $pager->init($count, Router::$router->url('Content/attach/manage/' . $type . '/%page%'), $page, $listNum);
         $pres = $pager->p();
         $data = array();
         $data['attaches'] = $atm1->limit($pres['min'], $listNum)->query();
         $data['pager'] = $pres['html'];
         $this->assign($data);
         $this->display('Content/attach');
     } elseif ($action == 'del') {
         $status = array('status' => 'error', 'msg' => '您没有选择附件!');
         if (!isset($_POST['attacheid'])) {
             echo json_encode($status);
             exit;
         } else {
             $attacheid = explode(',', $_POST['attacheid']);
             $root = substr(__ROOT__, 0, strlen(__ROOT__) - 1);
             foreach ($attacheid as $id) {
                 if ($id != '') {
                     $id = intval($id);
                 } else {
                     continue;
                 }
                 $attach = model('attaches')->where('attachid', $id)->getOne('attachpath,attachname');
                 //var_dump($attach);
                 if (unlink($root . $attach['attachpath'])) {
                     if (model('attaches')->where('attachid', $id)->delete()) {
                         $status = array('status' => 'info', 'msg' => '附件' . $attach['attachname'] . '删除成功!');
                         //echo json_encode($status);exit;
                     } else {
                         $status = array('status' => 'error', 'msg' => '附件' . $attach['attachname'] . '数据库删除失败!');
                         echo json_encode($status);
                         exit;
                     }
                 } else {
                     $status = array('status' => 'error', 'msg' => '附件从磁盘中' . $attach['attachname'] . '删除失败!');
                     echo json_encode($status);
                     exit;
                 }
             }
             if (count($attacheid) > 1) {
                 $status['msg'] = '您选中的附件删除成功了!';
             }
             $path = __ROOT__ . Config::cms('upload_path');
             /**
              * 清除空文件夹
              * @param $path
              */
             function rm_empty_dir($path)
             {
                 if (is_dir($path) && ($handle = opendir($path)) !== false) {
                     while (($file = readdir($handle)) !== false) {
                         // 遍历文件夹
                         if ($file != '.' && $file != '..') {
                             $curfile = $path . '/' . $file;
                             // 当前目录
                             if (is_dir($curfile)) {
                                 // 目录
                                 rm_empty_dir($curfile);
                                 // 如果是目录则继续遍历
                                 if (count(scandir($curfile)) == 2) {
                                     // 目录为空,=2是因为. 和 ..存在
                                     rmdir($curfile);
                                     // 删除空目录
                                 }
                             }
                         }
                     }
                     closedir($handle);
                 }
             }
             rm_empty_dir($path);
             echo json_encode($status);
             exit;
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * 获取模型表下的内容
  * @param $mid
  * @param $num
  * @param int $page
  */
 public function ContentListByModel($mid, $num = 10, $page = 1, $reutrnpage = false)
 {
     //
     $table = model('category')->where('con_modelid', intval($mid))->getOne('contable');
     if (empty($table) || is_null($table['contable'])) {
         return array();
     }
     $table = $table['contable'];
     $count = model($table)->count();
     //获取内容总数量
     Loader::$load->template()->assign(array('resnum' => $count));
     $pageclass = Loader::plugin('cmspage');
     if (!isset($_GET)) {
         $_GET = array();
     }
     $_GET['page'] = '%page%';
     $action = Router::$router->routers['controller'] . '/' . Router::$router->routers['method'];
     if (Router::$router->routers['var'] != false) {
         $action .= '/' . implode('/', Router::$router->routers['var']);
     }
     $url = Router::$router->url($action, $_GET);
     $pageclass->init($count, $url, $page, $num);
     if ($reutrnpage != false) {
         if (method_exists($pageclass, $reutrnpage)) {
             $pageclass->{$reutrnpage}();
         }
     }
     $rpage = $pageclass->output();
     $min = $rpage['min'];
     Loader::$load->template()->assign(array('pages' => $rpage['html'], 'allpages' => $rpage['allpages']));
     $ncontent = array();
     $num = intval($num);
     $content = model($table)->orderBy($table . '.listorder ' . $this->ContentOrder)->limit("{$min},{$num}")->query();
     foreach ($content as $con) {
         $inputtime = $con['inputtime'];
         $updatetime = $con['updatetime'];
         $ncon = model('model_field')->parse($mid, $con);
         $ncon['cid'] = $con['cid'];
         $ncon['id'] = $con['id'];
         $ncon['url'] = $this->getContentUrl($con['cid'], $con['id']);
         $ncon['inputtime'] = $inputtime;
         $ncon['updatetime'] = $updatetime;
         unset($con);
         $ncontent[] = $ncon;
     }
     return $ncontent;
 }
Ejemplo n.º 7
0
/**
 * 发送邮件
 * @param $address      邮件地址 如果为数组,则为多个
 * @param $Subject      邮件主题
 * @param $body         内容
 * @param $is_html      是否为HTML
 */
function send_mail($address, $Subject, $body, $is_html = false)
{
    $Mailer = Loader::plugin('Mailer');
    $Mailer = $Mailer->init();
    if (is_array($address)) {
        foreach ($address as $adr) {
            $Mailer->addAddress($adr);
        }
    } else {
        $Mailer->addAddress($address);
    }
    $Mailer->isHTML($is_html);
    $Mailer->Subject = $Subject;
    $Mailer->Body = $body;
    return $Mailer->send();
}
Ejemplo n.º 8
0
 public function manage($act = 'manage', $id = 0)
 {
     if ($act == 'manage') {
         $fid = isset($_GET['formid']) ? intval($_GET['formid']) : false;
         if (!$fid) {
             $var = array('error', '参数不完整,禁止非法进入!', '禁止非法进入。。。');
             controller('Admin', 'show_message', $var);
             exit;
         }
         $form = model('form')->where('formid', $fid)->getOne();
         $count = model('form_content')->where('fid', $fid)->count();
         //echo $count;
         $num = 10;
         //页面显示的结果数量
         $page = isset($_GET['page']) ? $_GET['page'] : 1;
         if ($page < 1) {
             $page = 1;
         }
         $pageO = Loader::plugin('page');
         $pageO->init($count, Router::$router->url('Form/manage', array('page' => '%page%', 'formid' => $fid)), $page, $num);
         $pages = $pageO->p();
         $content = model('form_content')->where('fid', $fid)->orderby('form_content.formid desc')->limit($pages['min'], $num)->query();
         //var_dump($content);
         $data['fid'] = $fid;
         $fcontent = array();
         foreach ($content as $value) {
             $formcon = unserialize($value['value']);
             $formcon['ip'] = $value['ip'];
             $formcon['id'] = $value['formid'];
             $formcon['time'] = date("Y-m-d H:i:s", $value['time']);
             $fcontent[] = $formcon;
         }
         $data['fcontent'] = $fcontent;
         $data['pages'] = $pages['html'];
         $data['pageNum'] = $pages['pageNum'];
         $formField = unserialize($form['formsetting']);
         $data['name'] = $form['formname'];
         $data['formField'] = $formField;
         view('Form/manage', $data);
     } elseif ($act == 'show') {
         $this->show($id);
     } elseif ($act == 'del') {
         $this->del();
     }
 }
Ejemplo n.º 9
0
 /**
  * 创建支付流水号并去支付
  */
 public function do_pay($method = "", $order_id = '')
 {
     // 加载订单模型
     // 创建支付插件实例
     $payobj = Loader::plugin('payment.' . $this->payment['type'] . '.' . $this->payment['type']);
     $pay_vars = get_object_vars($payobj);
     // 创建支付实例
     if ($this->to_create()) {
         $html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n                \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n                <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-US\" lang=\"en-US\" dir=\"ltr\">\n                <head>\n</header><body><div>Redirecting...</div>";
         $payObj->_payment = $this->payment['payment'];
         $toSubmit = $payobj->toSubmit($this->get_payment_info($method));
         if ("utf8" != strtolower($payobj->charset)) {
             $toSubmit = array_iconv($toSubmit, CHARSET, $payobj->charset);
         }
         $html .= "<form id=\"payment\" action=\"" . $payobj->submitUrl . "\" method=\"" . $payobj->method . "\">";
         $buffer = '';
         foreach ($toSubmit as $k => $v) {
             if ($k != "ikey") {
                 $html .= "<input name=\"" . urldecode($k) . "\" type=\"hidden\" value=\"" . htmlspecialchars($v) . "\" />";
                 if ($v) {
                     $buffer .= urldecode($k) . "=" . $v . "&";
                 }
             }
         }
         if (strtoupper($this->payment['type']) == "TENPAYTRAD") {
             $buffer = substr($buffer, 0, strlen($buffer) - 1);
             $md5_sign = strtoupper(md5($buffer . "&key=" . $toSubmit['ikey']));
             $url = $payObj->submitUrl . "?" . $buffer . "&sign=" . $md5_sign;
             echo "<script language='javascript'>";
             echo "window.location.href='" . $url . "';";
             echo "</script>";
         }
         $html .= "\n</form>\n<script language=\"javascript\">\ndocument.getElementById('payment').submit();\n</script>\n</html>";
     } else {
         $html = "<html>\n<meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\"/>\n<script language=\"javascript\">\nalert('创建支付流水号错误!');\n//location.href=document.referrer;\n</script>\n</html>";
     }
     echo $html;
 }