/** * Returns information to summarize an article with a snippet of text and a picture if applicable. */ public function blurb() { wfProfileIn(__METHOD__); $idStr = $this->request->getVal('ids'); $ids = explode(',', $idStr); $summary = array(); # Iterate through each title per wiki ID foreach ($ids as $id) { $title = Title::newFromID($id); if (empty($title)) { $summary[$this->wg->CityId]['error'][] = "Unable to find title for ID {$id}"; break; } $service = new ArticleService($id); $snippet = $service->getTextSnippet(); $imageServing = new ImageServing(array($id), 200, array('w' => 2, 'h' => 1)); $images = $imageServing->getImages(1); // get just one image per article $imageURL = ''; if (isset($images[$id])) { $imageURL = $images[$id][0]['url']; } $summary[$id] = array('wiki' => $this->wg->Sitename, 'wikiUrl' => $this->wg->Server, 'titleDBkey' => $title->getPrefixedDBkey(), 'titleText' => $title->getFullText(), 'articleId' => $title->getArticleID(), 'imageUrl' => $imageURL, 'url' => $title->getFullURL(), 'snippet' => $snippet); } wfProfileOut(__METHOD__); $this->summary = $summary; }
protected function getDetails() { $article = \Article::newFromTitle($this->commentTitle, \RequestContext::getMain()); $service = new \ArticleService($article); $snippet = $service->getTextSnippet(); return $snippet; }
public function renderShow($id) { $service = new TripService($this->entityManager); $trip = $service->find($id); $this->template->trip = $trip; try { $eventService = new EventService(); $config = Environment::getConfig('api'); $events = $eventService->getEvents($trip->arrival, new DateTime(), new EventfulMapper($config->eventfulUser, $config->eventfulPassword, $config->eventfulKey)); $this->template->events = $events; } catch (InvalidStateException $e) { $this->template->events = array(); } $articleService = new ArticleService($this->entityManager); $this->template->article = $articleService->buildArticle($trip->arrival, new ArticleWikipediaMapper()); try { $airportMapper = new AirportTravelMathMapper(); $airportService = new AirportService(); $locationService = new LocationService(); $coordinates = $locationService->getCoordinates($trip->getDeparture()); $from = $airportService->searchNearestAirport($airportMapper, $coordinates['latitude'], $coordinates['longitude']); $coordinates = $locationService->getCoordinates($trip->getArrival()); $to = $airportService->searchNearestAirport($airportMapper, $coordinates['latitude'], $coordinates['longitude']); $flightMapper = new FlightKayakMapper(); $flightService = new FlightService($this->entityManager); $depart_date = new DateTime('now'); $return_date = new DateTime('+1 week'); $this->template->flights = $flightService->buildFlights($flightMapper, $from, $to, $depart_date, $return_date, '1', 'e', 'n'); } catch (FlightException $e) { $this->template->flightsError = "Connection with search system <a href='http://kayak.com'>Kayak</a> failed."; } catch (AirportException $e) { $this->template->flightsError = $e->getMessage(); } }
public function getForMap() { $pageName = $this->request->getVal('title'); $oTitle = Title::newFromText($pageName); if (empty($oTitle) || !$oTitle->exists()) { return array(); } $pageId = $oTitle->getArticleId(); // TODO: getImages() are not cached $imageServing = new ImageServing(array($pageId), 100, array('w' => 1, 'h' => 1)); $images = $imageServing->getImages(1); if (!empty($images[$pageId][0]['url'])) { $imageUrl = $images[$pageId][0]['url']; } else { $imageUrl = ''; } $oArticleService = new ArticleService(); $oArticleService->setArticleById($pageId); $textSnippet = $oArticleService->getTextSnippet(120); $strPos = mb_strrpos($textSnippet, ' '); $textSnippet = mb_substr($textSnippet, 0, $strPos); $textSnippet .= ' ...'; $this->setVal('title', $oTitle->getText()); $this->setVal('imgUrl', $imageUrl); $this->setVal('articleUrl', $oTitle->getLocalUrl()); $this->setVal('textSnippet', $textSnippet); }
/** * @param OutputPage $out * @param string $text * @return bool */ function wfArticleMetaDescription(&$out, &$text) { global $wgTitle; wfProfileIn(__METHOD__); $sMessage = null; $sMainPage = wfMsgForContent('Mainpage'); if (strpos($sMainPage, ':') !== false) { $sTitle = $wgTitle->getFullText(); } else { $sTitle = $wgTitle->getText(); } if (strcmp($sTitle, $sMainPage) == 0) { // we're on Main Page, check MediaWiki:Description message $sMessage = wfMsg("Description"); } if ($sMessage == null || wfEmptyMsg("Description", $sMessage)) { $DESC_LENGTH = 100; $articleId = $wgTitle->getArticleID(); $articleService = new ArticleService($articleId); $description = $articleService->getTextSnippet($DESC_LENGTH); } else { // MediaWiki:Description message found, use it $description = $sMessage; } if (!empty($description)) { $out->addMeta('description', htmlspecialchars($description)); } wfProfileOut(__METHOD__); return true; }
protected function getDetails() { $article = \Article::newFromTitle($this->postTitle, \RequestContext::getMain()); $service = new \ArticleService($article); // Include +3 characters here for the ellipsis added when we have to truncate $snippet = $service->getTextSnippet($length = 303, $breakLimit = 500); return $snippet; }
function egOgmcParserOutputApplyValues($out, $parserOutput, $data) { global $wgTitle; $articleId = $wgTitle->getArticleID(); $titleImage = $titleDescription = null; wfRunHooks('OpenGraphMeta:beforeCustomFields', array($articleId, &$titleImage, &$titleDescription)); // Only use ImageServing if no main image is already specified. This lets people override the image with the parser function: [[File:{{#setmainimage:Whatever.png}}]]. if (!isset($out->mMainImage)) { if (is_null($titleImage)) { // Get image from ImageServing // TODO: Make sure we automatically respect these restrictions from Facebook: // "An image URL which should represent your object within the graph. // The image must be at least 50px by 50px and have a maximum aspect ratio of 3:1. // We support PNG, JPEG and GIF formats." $imageServing = F::build('ImageServing', array($articleId)); foreach ($imageServing->getImages(1) as $key => $value) { $titleImage = Title::newFromText($value[0]['name'], NS_FILE); } } // If ImageServing was not able to deliver a good match, fall back to the wiki's wordmark. if (empty($titleImage) && !is_object($titleImage) && F::app()->checkSkin('oasis')) { $themeSettings = new ThemeSettings(); $settings = $themeSettings->getSettings(); if ($settings["wordmark-type"] == "graphic") { $titleImage = Title::newFromText($settings['wordmark-image-name'], NS_FILE); } } // If we have a Title object for an image, convert it to an Image object and store it in mMainImage. if (!empty($titleImage) && is_object($titleImage)) { $mainImage = wfFindFile($titleImage); if ($mainImage !== false) { $parserOutput->setProperty('mainImage', $mainImage); $out->mMainImage = $parserOutput->getProperty('mainImage'); } } else { // Fall back to using a Wikia logo. There aren't any as "File:" pages, so we use a new config var for one that // is being added to skins/common. global $wgBigWikiaLogo; $logoUrl = wfReplaceImageServer($wgBigWikiaLogo); $parserOutput->setProperty('mainImage', $logoUrl); $out->mMainImage = $parserOutput->getProperty('mainImage'); } } // Get description from ArticleService if (is_null($titleDescription)) { $DESC_LENGTH = 100; $articleService = new ArticleService($articleId); $titleDescription = $articleService->getTextSnippet($DESC_LENGTH); } if (!empty($titleDescription)) { $parserOutput->setProperty('description', $titleDescription); $out->mDescription = $parserOutput->getProperty('description'); } if ($page_id = Wikia::getFacebookDomainId()) { $out->addMeta('property:fb:page_id', $page_id); } }
/** * Get article type (as in: games, tv series, etc) * of current page * * @param Title $title * @return string */ public static function getArticleType($title = null) { global $wgTitle; if (is_null($title)) { $title = $wgTitle; } $articleService = new ArticleService($title); return $articleService->getArticleType(); }
function getPIDs($articleMetadataServer, $articleDomain) { $articleServices = new ArticleService($articleMetadataServer, $articleDomain); $tmp =& $this->domLiteDocument->getElementsByPath("//similarlist/similar"); for ($i = 0; $i < $tmp->getLength(); $i++) { $item = $tmp->item($i); $pid = $item->getText(); $relevance = $this->getNodeAttribute($item, 's'); $articleServices->setParams($pid); $article = $articleServices->getArticle(); $article->setPID($pid); $article->setRelevance($relevance); $articles[] = $article; } return $articles; }
public static function get_instance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }
function egOgmcParserOutputApplyValues(OutputPage $out, ParserOutput $parserOutput, $data) { wfProfileIn(__METHOD__); global $wgTitle; $articleId = $wgTitle->getArticleID(); $titleImage = $titleDescription = null; wfRunHooks('OpenGraphMeta:beforeCustomFields', array($articleId, &$titleImage, &$titleDescription)); // Get description from ArticleService if (is_null($titleDescription)) { $DESC_LENGTH = 500; $articleService = new ArticleService($wgTitle); $titleDescription = $articleService->getTextSnippet($DESC_LENGTH); } if (!empty($titleDescription)) { $parserOutput->setProperty('description', $titleDescription); $out->mDescription = $parserOutput->getProperty('description'); } wfProfileOut(__METHOD__); }
/** * @param OutputPage $out * @param string $text * @return bool */ function wfArticleMetaDescription(&$out, &$text) { wfProfileIn(__METHOD__); $wg = F::app()->wg; // Whether the description has already been added static $addedToPage = false; // The OutputPage::addParserOutput method calls the OutputPageBeforeHTML hook which can happen // more than once in a request. Make sure we don't add two <meta> tags // https://wikia-inc.atlassian.net/browse/VID-2102 if ($addedToPage) { wfProfileOut(__METHOD__); return true; } $sMessage = null; $sMainPage = wfMessage('Mainpage')->inContentLanguage()->text(); if (strpos($sMainPage, ':') !== false) { $sTitle = $wg->Title->getFullText(); } else { $sTitle = $wg->Title->getText(); } if (strcmp($sTitle, $sMainPage) == 0) { // we're on Main Page, check MediaWiki:Description message $sMessage = wfMessage('Description')->text(); } if ($sMessage == null || wfEmptyMsg('Description', $sMessage)) { $DESC_LENGTH = 100; $article = new Article($wg->Title); $articleService = new ArticleService($article); $description = $articleService->getTextSnippet($DESC_LENGTH); } else { // MediaWiki:Description message found, use it $description = $sMessage; } if (!empty($description)) { $out->addMeta('description', htmlspecialchars($description)); $addedToPage = true; } wfProfileOut(__METHOD__); return true; }
/** * @desc Returns description for the article's meta tag. * * This is mostly copied from the ArticleMetaDescription extension. * * @param int $articleId * @param int $descLength * @return string * @throws WikiaException */ private function getArticleDescription($articleId, $descLength = 100) { $article = Article::newFromID($articleId); if (!$article instanceof Article) { throw new NotFoundApiException(); } $title = $article->getTitle(); $sMessage = null; if ($title->isMainPage()) { // we're on Main Page, check MediaWiki:Description message $sMessage = wfMessage('Description')->text(); } if ($sMessage == null || wfEmptyMsg('Description', $sMessage)) { $articleService = new ArticleService($article); $description = $articleService->getTextSnippet($descLength); } else { // MediaWiki:Description message found, use it $description = $sMessage; } return $description; }
<?php session_start(); require_once "../configure.php"; require_once DIR_WS_DB . "mysql_db.php"; require_once DIR_WS_SERVICES . "article_services.php"; $db = new MysqlDB(); $articles_service = new ArticleService(); $per_page = PAGESIZE; $page_num = $_GET["page"]; if (!isset($page_num)) { $page_num = 1; } $uid = $_GET["uid"]; if (!isset($uid)) { $uid = "u1"; } $start_page = ($page_num - 1) * $per_page; $end_page = $page_num * $per_page; //$user_articles_detail = $articles_service->getUserArticleDetail($uid, $start_page, $per_page); if (empty($_SESSION["user_uid"])) { $user_articles_detail = $articles_service->getAllArticles($start_page, $per_page); } else { if ($_SESSION["category_uid"] === "all") { $user_articles_detail = $articles_service->getUserArticleDetail($_SESSION["user_uid"], $start_page, $per_page); } else { $user_articles_detail = $articles_service->getUserArticleCategoryDetail($_SESSION["user_uid"], $_SESSION["category_uid"], $start_page, $per_page); } } $page_num = $_GET["page"]; ?>
<?php session_start(); require_once $_SERVER['DOCUMENT_ROOT'] . '/lavender/admin/common/checklogin.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/lavender/model/Paging.class.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/lavender/model/ArticleService.class.php'; //此处应当加是否来自可信站点获取数据 //以免造成数据泄露 //****** checklogin(); if (isset($_GET['pagenow'])) { $pagenow = $_GET['pagenow']; } $paging = new Paging(); $articleService = new ArticleService(); $paging->pagenow = $pagenow; $paging->pagesize = 12; $res_class = $articleService->getArticle_paging($paging); $arr = $res_class->res_arr; for ($i = 0; $i < count($arr); $i++) { $arr[$i]['content'] = mb_substr($arr[$i]['content'], 0, 27, 'UTF-8') . "..."; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <link rel="stylesheet" href="./css/manageArticle.css" /> <script type="text/javascript" src="./js/jquery-2.2.0.min.js"></script> <script type="text/javascript" src="./js/manageArticle.js"></script> <script type="text/javascript">
protected function getArticlesDetails($articleIds, $articleKeys = [], $width = 0, $height = 0, $abstract = 0, $strict = false) { $articles = is_array($articleIds) ? $articleIds : [$articleIds]; $ids = []; $collection = []; $resultingCollectionIds = []; $titles = []; foreach ($articles as $i) { //data is cached on a per-article basis //to avoid one article requiring purging //the whole collection $cache = $this->wg->Memc->get(self::getCacheKey($i, self::DETAILS_CACHE_ID)); if (!is_array($cache)) { $ids[] = $i; } else { $collection[$i] = $cache; $resultingCollectionIds[] = $i; } } if (count($ids) > 0) { $titles = Title::newFromIDs($ids); } if (!empty($articleKeys)) { foreach ($articleKeys as $titleKey) { $titleObj = Title::newFromDbKey($titleKey); if ($titleObj instanceof Title && $titleObj->exists()) { $titles[] = $titleObj; } } } if (!empty($titles)) { foreach ($titles as $t) { $fileData = []; if ($t->getNamespace() == NS_FILE) { $fileData = $this->getFromFile($t->getText()); } elseif ($t->getNamespace() == NS_MAIN) { $fileData = ['type' => static::ARTICLE_TYPE]; } elseif ($t->getNamespace() == NS_CATEGORY) { $fileData = ['type' => static::CATEGORY_TYPE]; } $id = $t->getArticleID(); $revId = $t->getLatestRevID(); $rev = Revision::newFromId($revId); if (!empty($rev)) { $collection[$id] = ['id' => $id, 'title' => $t->getText(), 'ns' => $t->getNamespace(), 'url' => $t->getLocalURL(), 'revision' => ['id' => $revId, 'user' => $rev->getUserText(Revision::FOR_PUBLIC), 'user_id' => $rev->getUser(Revision::FOR_PUBLIC), 'timestamp' => wfTimestamp(TS_UNIX, $rev->getTimestamp())]]; $collection[$id]['comments'] = class_exists('ArticleCommentList') ? ArticleCommentList::newFromTitle($t)->getCountAllNested() : false; //add file data $collection[$id] = array_merge($collection[$id], $fileData); $resultingCollectionIds[] = $id; $this->wg->Memc->set(self::getCacheKey($id, self::DETAILS_CACHE_ID), $collection[$id], 86400); } else { $dataLog = ['titleText' => $t->getText(), 'articleId' => $t->getArticleID(), 'revId' => $revId]; WikiaLogger::instance()->info('No revision found for article', $dataLog); } } $titles = null; } //ImageServing has separate caching //so processing it separately allows to //make the thumbnail's size parametrical without //invalidating the titles details' cache //or the need to duplicate it $thumbnails = $this->getArticlesThumbnails($resultingCollectionIds, $width, $height); $articles = null; //ArticleService has separate caching //so processing it separately allows to //make the length parametrical without //invalidating the titles details' cache //or the need to duplicate it foreach ($collection as $id => &$details) { if ($abstract > 0) { $as = new ArticleService($id); $snippet = $as->getTextSnippet($abstract); } else { $snippet = null; } $details['abstract'] = $snippet; if (isset($thumbnails[$id])) { $details = array_merge($details, $thumbnails[$id]); } } $collection = $this->appendMetadata($collection); $thumbnails = null; //The collection can be in random order (depends if item was found in memcache or not) //lets preserve original order even if we are not using strict mode: //to keep things consistent over time (some other APIs that are using sorted results are using //ArticleApi::getDetails to fetch info about articles) $orderedIdsFromTitles = array_diff(array_keys($collection), $articleIds); //typecasting to convert falsy values into empty array (array_merge require arrays only) $orderedIds = array_merge((array) $articleIds, (array) $orderedIdsFromTitles); $collection = $this->preserveOriginalOrder($orderedIds, $collection); //if strict - return array instead of associative array (dict) if ($strict) { return array_values($collection); } else { return $collection; } }
<?php include '..' . DIRECTORY_SEPARATOR . 'init.php'; include SROOT . 'articleService.class.php'; $article_service = new ArticleService(); $article_list = $article_service->getAll(ARTICLE_PUBLISH, v('cid') ? v('cid') : null, v('page') ? v('page') : null); if ($article_list) { send_result(1, $article_list); } else { send_result(0, 'empty data'); }
/* fazendo a consistencia de usuário logado/não logado */ if($_data['userID']){ /* a url do serviço que retorna os meta-dados do artigo é o domínio de onde o usuário esta vendo o artigo */ $domain = str_replace("http://","",$_data['url']); $domain = substr($domain,0,strpos($domain,"/")); /* chamando o serviço (ele devolve um objeto Article) */ $articleService = new ArticleService($domain); $articleService->setParams($_data['PID']); $article = $articleService->getArticle(); $article->setURL($domain); //die(var_dump($article->getPID())); $article->addArticle(); $shelf = new Shelf(); $shelf->setUserID($_data['userID']); $shelf->setPID($_data['PID']);
include_once '../../app/services/HttpService.php'; // Parse parameters from request $title = isset($_POST['title']) ? $_POST['title'] : null; $keywords = isset($_POST['keywords']) ? $_POST['keywords'] : null; $content = isset($_POST['content']) ? $_POST['content'] : null; $user = $_SESSION['username']; // Validate required parameters if (!isset($title, $content, $user)) { HttpService::return_bad_request(); } // Sanitize user input $title = SanitationService::convertHtml($title); $keywords = SanitationService::convertHtml($keywords); $content = SanitationService::convertHtml($content); // Save article $articles = ArticleService::get_instance(); $articles->add_article($user, $title, $keywords, $content); // Redirect to articles HttpService::redirect_to('/articles/'); } // GET - Show form if ($method == "GET") { $page_title = "New Article"; $form_action = '/articles/new'; $id = ''; $title = ''; $keywords = ''; $author = $_SESSION['username']; $content = ''; $date = date('F d, Y', time()); $page_content = '../../app/views/articles/edit.php';
private function buildArticle(Entity\Feed $feed) { return function (ArrayCollection $data) use($feed) { return $this->article_service->build($data, $feed); }; }
if (!AuthenticationService::can_delete_article($article)) { HttpService::return_unauthorized(); } // Delete article $articles->remove_article($id); HttpService::return_no_content(); } HttpService::return_bad_request(); } // GET - Show form if ($method == "GET") { if (!isset($_GET['id'])) { HttpService::return_bad_request(); } $id = $_GET['id']; $srv = ArticleService::get_instance(); $article = $srv->get_article($id); if (!isset($article)) { HttpService::return_not_found(); } $article_id = $article->get_id(); $title = $article->get_title(); $keywords = $article->get_keywords(); $author = $article->get_author(); $content = BulletBoardCodeParser::convertToHtml($article->get_text()); $creation_date = date('F d, Y', $article->get_creation_date()); $commentsSrv = new CommentService(); $comments = $commentsSrv->get_comments_from_article($article_id); $page_title = "Article {$id}"; $page_content = '../../app/views/articles/details.php'; include_once '../../app/views/_layout.php';
<?php /** * Created by PhpStorm. * User: 宏 * Date: 2016/2/1 * Time: 20:56 */ require_once $_SERVER['DOCUMENT_ROOT'] . '/lavender/model/ArticleService.class.php'; if (isset($_GET['id']) && isset($_GET['pagenow'])) { $id = $_GET['id']; $pagenow = $_GET['pagenow']; } else { echo "非法请求"; exit; } $articleService = new ArticleService(); $res = $articleService->deleteArticle($id); if ($res == 1) { echo "<script type='text/javascript'>alert('删除成功!');</script>"; echo "<script type='text/javascript'>location.href='../manageArticle.php?pagenow={$pagenow}';</script>"; exit; } else { echo "<script type='text/javascript'>alert('删除失败!');</script>"; echo "<script type='text/javascript'>location.href='../manageArticle.php?pagenow={$pagenow}';</script>"; }
<?php /** * Created by PhpStorm. * User: 宏 * Date: 2016/2/1 * Time: 21:21 */ require_once $_SERVER['DOCUMENT_ROOT'] . '/lavender/model/ArticleService.class.php'; if (isset($_GET['id']) && isset($_GET['pagenow']) && isset($_POST['title']) && isset($_POST['content']) && isset($_POST['img_url'])) { $id = $_GET['id']; $pagenow = $_GET['pagenow']; $title = $_POST['title']; $content = $_POST['content']; $img_url = $_POST['img_url']; } else { echo "非法请求"; exit; } $articleService = new ArticleService(); $res = $articleService->updateArticle($id, $title, $content, $img_url); if ($res == 1) { echo "<script type='text/javascript'>alert('修改成功!');</script>"; echo "<script type='text/javascript'>location.href='../manageArticle.php?pagenow={$pagenow}';</script>"; exit; } else { echo "<script type='text/javascript'>alert('修改失败!');</script>"; echo "<script type='text/javascript'>location.href='../manageArticle.php?pagenow={$pagenow}';</script>"; }
protected function getArticleData($pageId) { global $wgVideoHandlersVideosMigrated; $oTitle = Title::newFromID($pageId); if (!$oTitle instanceof Title) { return false; } $oMemCache = F::App()->wg->memc; $sKey = wfSharedMemcKey('category_exhibition_category_cache_1', $pageId, F::App()->wg->cityId, $this->isVerify(), $wgVideoHandlersVideosMigrated ? 1 : 0, $this->getTouched($oTitle)); $cachedResult = $oMemCache->get($sKey); if (!empty($cachedResult)) { return $cachedResult; } $snippetText = ''; $imageUrl = $this->getImageFromPageId($pageId); if (empty($imageUrl)) { $snippetService = new ArticleService($oTitle); $snippetText = $snippetService->getTextSnippet(); } $returnData = array('id' => $pageId, 'img' => $imageUrl, 'width' => $this->thumbWidth, 'height' => $this->thumbHeight, 'snippet' => $snippetText, 'title' => $this->getTitleForElement($oTitle), 'url' => $oTitle->getFullURL()); // will be purged elsewhere after edit $oMemCache->set($sKey, $returnData, 60 * 60 * 24); return $returnData; }
<?php require_once "../configure.php"; require_once DIR_WS_DB . "mysql_db.php"; require_once DIR_WS_SERVICES . "article_services.php"; $db = new MysqlDB(); $articles_service = new ArticleService(); $per_page = PAGESIZE; $aid = empty($_GET) ? "a1" : $_GET["article_uid"]; $article_detail = $articles_service->getArticleDetail($aid); $more = $_GET["more"]; if (empty($more)) { $more = "show"; } ?> <?php if ($more === "show") { ?> <div class="row-fluid" id="<?php echo $aid; ?> "> <div class="hero-unit"> <h3 ><?php echo $article_detail[0]['article_name']; ?> </h3> <p style="font-size:50%"><?php echo $article_detail[0]['article_moddate'] . "</br>";
/** * Fetches short textual snippet for given article * @param $articleId int Article id * @param $length int Desired snippet length * @return string */ protected function getArticleSnippet($articleId, $length = 150) { wfProfileIn(__METHOD__); $articleService = new ArticleService($articleId); $result = $articleService->getTextSnippet($length); wfProfileOut(__METHOD__); return $result; }
<?php /** * Created by PhpStorm. * User: 宏 * Date: 2016/1/28 * Time: 11:53 */ require_once $_SERVER['DOCUMENT_ROOT'] . '/lavender/model/ArticleService.class.php'; if (isset($_GET['id'])) { $id = $_GET['id']; } else { echo "请求非法"; } $articleService = new ArticleService(); $res = $articleService->AddPraise($id); echo $res;
/** * Returns image or snippet for the category on id basis. * Uses in modified getArticle * * @param $iCategoryId int category pageId * @return array */ protected function getCategoryImageOrSnippet($iCategoryId) { $title = Title::newFromID($iCategoryId); $sCategoryDBKey = $title->getDBKey(); // tries to get image from images in category $result = CategoryDataService::getAlphabetical($sCategoryDBKey, NS_FILE, 1); if (!empty($result)) { $counter = 0; foreach ($result as $item) { if ($counter > F::App()->wg->maxCategoryExhibitionSubcatChecks) { break; } $imageServing = new ImageServing(array($item['page_id']), $this->thumbWidth, array("w" => $this->thumbWidth, "h" => $this->thumbHeight)); $itemTitle = Title::newFromID($item['page_id']); $image = wfFindFile($itemTitle); if (!empty($image)) { $imageSrc = wfReplaceImageServer($image->getThumbUrl($imageServing->getCut($image->width, $image->height) . "-" . $image->getName())); return array('imageUrl' => (string) $imageSrc, 'snippetText' => ''); } $counter++; } } // if no images found, tries to get image or snippet from artice unset($result); $result = CategoryDataService::getAlphabetical($sCategoryDBKey, NS_MAIN, 10); if (!empty($result)) { $counter = 0; $snippetText = ''; $imageUrl = ''; foreach ($result as $item) { if ($counter > F::App()->wg->maxCategoryExhibitionSubcatChecks) { break; } $imageUrl = $this->getImageFromPageId($item['page_id']); if (!empty($imageUrl)) { break; } if (empty($snippetText)) { $snippetService = new ArticleService($item['page_id']); $snippetText = $snippetService->getTextSnippet(); } $counter++; } return array('imageUrl' => $imageUrl, 'snippetText' => $snippetText); } else { return array('imageUrl' => '', 'snippetText' => ''); } }
<?php include 'init.php'; require_once SROOT . 'articleService.class.php'; require_once SROOT . 'categoryService.class.php'; $method = v('method'); if (!$method) { send_result(0, "request does not have method parame"); } $service = new ArticleService(); $categoryService = new CategoryService(); if ($method == 'delete') { if (v('id') && isset($_REQUEST['status'])) { if ($_REQUEST['status'] == -1) { $flag = $service->delete(v('id')); } else { $flag = $service->trash(v('id')); } if ($flag) { // 静态化文章,及更新列表 $service->staticArticle($id); $category = $categoryService->findById(v('cid')); $service->staticArticleList($category); $service->staticIndex(); } forward('article_list.php?status=' . $_REQUEST['status']); } else { send_result(0, 'request does not have id ro status parame'); } } else { if ($method == 'draft') {
/** * get a snippet of article text * @param int $articleId Article ID * @param int $length snippet length (in characters) */ public function getArticleSnippet($articleId, $length = 100) { $service = new ArticleService($articleId); return $service->getTextSnippet(); }