function ubb2html($content, $attach = 0, $type) { $content = preg_replace(array("/\\[div\\]/i", "/\\[\\/div\\]/i", "/\n|\r|\r\n/", "/\\[code\\](.+?)\\[\\/code\\]/i", "/\\[quote\\](.+?)\\[\\/quote\\]/i", "/\\[h3\\](.+?)\\[\\/h3\\]/i", "/\\[url=([^\\]]+?)\\](.+?)\\[\\/url\\]/i", "/\\[(b|i|u|kbd)\\](.+?)\\[\\/\\1\\]/i", "/\\[hr\\]/i", "/\\[img=([^\\]]+?)\\]/i"), array('<div>', '</div>', '<br>', '<pre>$1</pre>', '<blockquote>$1</blockquote>', '<h3>$1</h3>', '<a href="$1" target="_blank">$2</a>', '<$1>$2</$1>', '<hr>', '<img src="$1" width="600px">'), $content); if ($attach) { $resattachs = J::t('image')->fetch_all('id,path,thumbH', "aid={$attach} AND type='article'"); if ($resattachs) { $find = $replace = array(); foreach ($resattachs as $k => $v) { $find[] = "/\\[attach\\]" . $v['id'] . "\\[\\/attach\\]/i"; $width = $suff = ''; if ($v['thumbH']) { $width = 'width="600px"'; $suff = '.thumb.jpg'; } $imgurl = $_B['siteurl'] . $v['path'] . $suff; if ($type == 'update') { $replace[] = '<img src="' . $imgurl . '" ' . $width . '>'; } else { $replace[] = '<img src="' . IMGDIR . 'l.gif" class="lazy" data-original="' . $imgurl . '" ' . $width . '>'; } } $content = preg_replace($find, $replace, $content); } } //<img src="{IMGDIR}l.gif" class="lazy" data-original="{$imgids[$v['aid']]}"> return $content; }
private function _init_setting() { $cachepath = BLOG_ROOT . '/' . CACHEDIR . '/setting.txt'; if ($cache = cache($cachepath)) { $this->b['setting'] = $cache; } else { $setting = J::t('setting')->fetch_all(); foreach ($setting as $k => $v) { $this->b['setting'][$k] = json_decode($v['svalue'], true); } cache($cachepath, $this->b['setting']); } }
$group[$v['pid']][] = $v; } } foreach (multi_array_sort($pinfos, 'displayorder') as $k => $v) { $sortpinfos[$v['id']] = $v; } foreach ($group as $k => $v) { $sortpinfos[$k]['downnav'] = multi_array_sort($v, 'displayorder'); } J::t('setting')->replace('nav', $sortpinfos); jsonOutput($return); } exit; } else { if (empty($_B['setting']['nav'])) { $navinfos = J::t('nav')->fetch_all(); foreach ($navinfos as $k => $v) { if ($v['pid'] == 0) { $pinfos[$v['id']] = $v; } else { $group[$v['pid']][] = $v; } } foreach (multi_array_sort($pinfos, 'displayorder') as $k => $v) { $sortpinfos[$v['id']] = $v; } foreach ($group as $k => $v) { $sortpinfos[$k]['downnav'] = multi_array_sort($v, 'displayorder'); } $nav = $sortpinfos; } else {
function getUser($uid) { static $users = array(); if (empty($users[$uid])) { $users[$uid] = J::t('users')->find_by_pk($uid); } return $users[$uid]; }
if ($errorcode < 0) { $data = $upload->errormsg(); @unlink($file['target']); jsonOutput(2, $data); } //判断是否开启了exif,并获取照片的exif信息 $my_exif = array(); if (extension_loaded('exif') && extension_loaded('mbstring')) { $my_exif = exif_read_data($file['target'], "EXIF"); } $image = new class_image($file['target']); $image->exif = $my_exif; $status = $image->Thumb(); if ($status <= 0) { $data = $image->errormsg($status); @unlink($file['target']); jsonOutput(2, $data); } $insert = array('uid' => $_B['uid'], 'aid' => 0, 'path' => $file['imgurl'], 'type' => 'article', 'size' => $image->imginfo['size'], 'width' => $image->imginfo['width'], 'height' => $image->imginfo['height'], 'thumbH' => $image->imginfo['thumbH'], 'status' => 0, 'dateline' => TIMESTAMP); $aid = J::t('image')->insert($insert, true); if (!is_numeric($aid) || $aid <= 0) { @unlink($file['target']); jsonOutput(2, '上传失败 0071'); } $data['url'] = $_B['siteurl'] . $file['imgurl'] . '.thumb.jpg'; $data['aid'] = $aid; jsonOutput(1, $data); break; case 'view': case 'new': }
jsonOutput(2, '不允许的操作'); } } elseif ($do == 'get') { if (!$_B['ajax']) { jsonOutput(2, '不允许的操作'); } if (!is_numeric($_B['page'])) { jsonOutput(2, '数据出错,请刷新重试'); } if (!is_numeric($_GET['aid']) || $_GET['aid'] <= 0) { jsonOutput(2, '数据出错,请刷新重试'); } $aid = $_GET['aid']; $comlimit = 30; $start = ($_B['page'] - 1) * $comlimit; $comlist = J::t('comment')->fetch_list('*', "classify='article' AND aid={$aid} AND `status`=1", $start, $comlimit); $next = ''; if ($comlist) { require_once libfile('article'); foreach ($comlist as $k => $v) { $comlist[$k]['formattime'] = btime($v['dateline'], 1); $comlist[$k]['time'] = btime($v['dateline']); $comlist[$k]['avatar'] = IMGDIR . 'jam.png'; $comlist[$k]['content'] = ubb2html($v['content']); } if (count($comlist) >= $comlimit) { $next = 'index.php?m=comment&do=get&aid=' . $aid . '&page=' . ($_B['page'] + 1); } } $data['content'] = display('_comment', 0, true, array('comlist' => $comlist)); $data['next'] = $next;
$limit = 5; $start = ($_B['page'] - 1) * $limit; if ($do == 'list') { $count = J::t('tag')->fetch_count(); $taginfo = J::t('tag')->fetch_all($start, $limit); $pagehtml = page($count, $_B['page'], $limit, 'admin.php?action=tag&do=list'); } elseif ($do == 'add') { if ($_B['ajax']) { $return['status'] = 1; $return['data'] = ''; $tagname = $_GET['tagname']; if (J::t('tag')->find_by_tagname($tagname)) { $return['status'] = 2; $return['data'] = '已存在该标签'; } else { $tagid = J::t('tag')->insert(array('tagname' => $tagname, 'dateline' => TIMESTAMP)); if ($tagid > 0) { $return['data'] = $tagid; } else { $return['status'] = 2; $return['data'] = '插入失败'; } } jsonOutput($return); } exit; } //$articles=J::t('article')->fetch_all($start,$limit); $menu_active[$action] = 'class="myactive"'; $side_active[$do] = 'class="myactive"'; include display('header', 1);
} } jsonOutput($status, $data); } if (!$_B['uid']) { shownotice('请先登录', array('referer' => $_B['referer'])); } $navtitle = $_B['setting']['blog']['blogName'] . ' - 写文章'; $defaultcontent = ''; break; case 'update': if ($_B['ajax'] && $_GET['type'] == 'update') { } $aid = $_GET['aid'] ?: 0; if (!$aid || !is_numeric($aid)) { shownotice('该文章不存在', array('referer' => $_B['referer'])); } $article = J::t('article')->find_by_pk($aid); if (!$article) { shownotice('该文章不存在', array('referer' => $_B['referer'])); } if ($_B['uid'] != $article['authorid'] || $article['status'] != 1 && !$_B['admin']) { shownotice('无权编辑该文章', array('referer' => $_B['referer'])); } $navtitle = '编辑文章 - ' . $article['subject']; $aidattach = $article['image'] ? $article['aid'] : 0; $defaultcontent = ubb2html($article['content'], $aidattach, 'update'); $do = 'new'; break; } include display('article_' . $do);