public function DoUploadImg(LJL_Request $input, LJL_Response $output) { $upfile = $input->files('uppic'); //客户端传过来的文件 $pos = strpos($upfile['name'], '.') + 1; $ext = substr($upfile['name'], $pos); //获取后缀名 $typelist = array("gif", "jpg", "png"); //限制图片类型 $imgInfo = LJL_Api::run("Image.DFS.imgStorage", array('rootdir' => UPLOAD_IMG_PATH . 'blog_' . APP_BLOG_NAME . '/')); $path = $imgInfo[2]; //上传到该文件夹 $webPath = Helper_Blog::getImgWebPath($imgInfo[2]); if (!is_dir($path)) { LJL_File::mkdir($path); } //获取图片名 $picName = $imgInfo[0]; $result = $this->uploadFile($upfile, $path, $picName, $webPath, $typelist); //图片上传函数 if ($result['status']) { //图片表中插入数据 $imgid = Helper_Blog::insertPic(array('picName' => $picName, 'picExt' => $ext, 'time' => $imgInfo[1])); echo '<script language="javascript">window.parent.addPic("' . $result['info'] . '","' . $imgid . '");</script>'; } else { echo '<script language="javascript">window.parent.addPic("error","0");</script>'; } }
/** * 插入文章 */ private function insertArticle($url, $title, $content) { if (!$title || !$content) { return; } $db = Db_Blog::instance(null, $this->website); //已有该文章则退出 $title = htmlspecialchars(strip_tags(addslashes(str_replace("'", '"', $title)))); if (Helper_Blog::ishasArticle('', $title)) { return; } //echo $title;die; //对于有图片的文章进行搬运图片处理 preg_match_all("/<img src=\"(.*?)\"/", $content, $matches, PREG_SET_ORDER); $imgidArr = array(); if ($matches) { if (count($matches) > 10) { return; } foreach ((array) $matches as $imgsrc) { $imgInfo = $this->getImgNameDir(); if (!$imgsrc[1]) { continue; } //1、移动图片 exec('wget -q --tries=3 -O ' . rtrim($imgInfo[1], '/') . '/' . $imgInfo[0] . '.jpg ' . $imgsrc[1]); //2、向自己库中插入图片 $imgidArr[] = Helper_Blog::insertPic(array('picName' => $imgInfo[0], 'picExt' => 'jpg', 'time' => $imgInfo[3])); //3、图片地址字符串替换 $content = str_replace($imgsrc[1], $imgInfo[2] . '/' . $imgInfo[0] . '.jpg', $content); } } //插入文章 $firstImgId = $imgidArr ? $imgidArr[0] : 0; $desc = $firstImgId ? API_Item_Base_String::getShort(array('str' => strip_tags($content), 'length' => 120)) : API_Item_Base_String::getShort(array('str' => strip_tags($content), 'length' => 150)); $articleId = Helper_Blog::insertArticleInfo(array('insertData' => array('firstImgId' => $firstImgId, 'insertTime' => SYSTEM_TIME, 'isPublished' => 0, 'cate' => $this->cate, 'tags' => $this->tags, 'title' => $title, 'descript' => ' ' . strip_tags(addslashes(str_replace("'", '"', $desc))) . ' ', 'source' => $url, 'content' => ' ' . htmlspecialchars(addslashes(preg_replace("/<script[\\s]*.*?<\\/script>/si", '', $content))) . ' ', 'imgArr' => $imgidArr))); echo 'article ' . $articleId . ' is ok' . PHP_EOL; }