function processTweet($tweet) { // who wrote the tweet? $contents = strtolower($tweet->text); // if we're testing, only allow test tweets through // (if we're not testing, don't allow test tweets through!) global $testing; if ($testing == true && strpos($contents, "#test") === false || $testing != true && strpos($contents, "#test") !== false) { return $tweet->id_str; } loginfo("Processing tweet " . $tweet->id_str . " from user " . $tweet->user->screen_name . "\n" . $contents); // Or we can adjust it, which basically just performs a delete // followed by a new insert $tweet->information = getTweetInformation($tweet); // If we're registering a new challenger! $processed = false; $register = strpos($contents, "#register"); if ($register !== false) { processRegistration($tweet); $processed = true; } // We can "delete" a tweet with the undo tag $undo = strposa($contents, array("#undo", "#delete")); if (!$processed && $undo !== false) { // basically change the 'inc_' to 'del_' processUndo($tweet); $processed = true; } // We can edit an existing tweet $edit = strposa($contents, array("#edit", "#update")); if (!$processed && $edit !== false) { processEdit($tweet); $processed = true; } // filter now for ID/Events - we can only run the following on single events if (!$processed && findEntryId($tweet) < 0) { // we count errors as processing, because we've replied replyEntryErrorTweet($tweet); $processed = true; } // If we're removing an entry $giveup = strpos($contents, "#giveup"); if (!$processed && $giveup !== false) { processGiveup($tweet); $processed = true; } // If we're processing content if (!$processed && $tweet->information->contenttype) { processContent($tweet); $processed = true; } // If we got this far and still didn't process it, there's something wrong if (!$processed) { } // After processing, return the ID if (!$testing) { return $tweet->id_str; } }
public function createAction() { global $tpl; set_time_limit(100); //删除data/chache目录 $path = DATA_DIR . 'cache/'; //缓存目录 if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { //$files[] = $file; @unlink($path . $file); } } closedir($handle); } //删除首页 del_cache(); //文章 $total = Cache::getTotal(); $start = 0; $limit = 20; $start_id = 0; $i = 0; $tablename_content = Record::tableFromClass('Article'); $tablename_contentpart = Record::tableFromClass('ContentPart'); $previous = null; while ($i < $total) { $sql = "select * from {$tablename_content} where type='post' and id > {$start_id} order by id asc limit {$limit}"; Record::$__CONN__->query($sql); $articles = array(); $articles = Record::$__CONN__->last_result; if (is_array($articles) && count($articles) > 0) { foreach ($articles as $k => $data) { $article = new Article(get_object_vars($data)); //上一页 $previous = isset($previous) ? $previous : ''; $tpl->assign('previous', $previous); $previous = $article; //下一页 if (isset($articles[$k + 1])) { //$next = new Article(get_object_vars($articles[$k+1])); $next = $articles[$k + 1]; } else { $next = $article->next(); } $tpl->assign('next', $next); $content_part = ContentPart::findById($article->id); $article->content = processContent($content_part->content); $article->tags = isset($this->cahce_tags[$article->id]) ? $this->cahce_tags[$article->id] : array(); $article->category = isset($this->cahce_categories[$article->cid]) ? $this->cahce_categories[$article->cid]['name'] : '无分类'; $article->category_slug = isset($this->cahce_categories[$article->cid]) ? $this->cahce_categories[$article->cid]['slug'] : 'uncategory'; $this->createHtml($article); if ($k == $limit - 1) { $start_id = $article->id; } } } $i += $limit; } //while flush(); echo 'create cache over!'; echo '<a href="index.php">Index</a>'; }
public function createPostHtml($obj = null) { global $tpl; if (is_object($obj) && DEBUG === false) { $post = clone $obj; $post->content = processContent($post->content); //上一篇文章 $previous = $obj->previous(); //下一篇文章 $next = $obj->next(); //首页最近文章 $recent_post = Article::getPost(5, false); //侧栏分类 $categories = Category::findAll(); //Tags $hot_tags = Tag::findAll(30); //mprint_r($hot_tags, '$hot_tags'); if (count($hot_tags) > 0) { $first = current($hot_tags); $last = end($hot_tags); foreach ($hot_tags as $k => $v) { $tags_list[$k]['word'] = $v->name; $tags_list[$k]['size'] = tagClouds($v->count, $first->count, $last->count); } } //smarty $tpl->assign('post', $post); $tpl->assign('next', $next); $tpl->assign('previous', $previous); $tpl->assign('recent_post', $recent_post); $tpl->assign('categories', $categories); $tpl->assign('tag_list', $tags_list); $filetpl = SYSTEM_ROOT . 'templates/' . DEFAULT_TEMPLATE . '/post.html'; $path = SYSTEM_ROOT . 'post/'; //$filename = !empty($obj->slug) ? str_replace(' ', '-', trim($obj->slug)) : $obj->id; $filename = $obj->id; $file = $path . $filename . '.html'; file_put_contents($file, $tpl->fetch($filetpl)); @chmod($file, 0777); } }
function checkNode($rootDOM, $rootXpath, $lastHighest) { $paragraphCounts = countParagraphs($rootDOM, $rootXpath); // if more than 50% less paragraphs, send parentNode to be output if (max($paragraphCounts) < 0.5 * $lastHighest) { // WE HAVE FOUND THE ELEMENT CONTAINING CONTENT processContent($rootDOM); } else { $lastHighest = max($paragraphCounts); if (isset($GLOBALS["debug"]) && $GLOBALS["debug"] == 1) { echo "<p>From Above. The highest no of p were found in index no:" . (findHighestIndex($paragraphCounts) + 1) . ". With a total of " . $lastHighest . " paragraphs.</p>"; echo "<p>Paragraph counts: "; foreach ($paragraphCounts as $pCount) { echo $pCount, ', '; } echo "</p><br></br>"; } $index_highest_pcount = findHighestIndex($paragraphCounts); removeJunk($rootDOM->childNodes->item($index_highest_pcount)); if ($rootDOM->childNodes->item($index_highest_pcount)->hasChildNodes()) { checkNode($rootDOM->childNodes->item($index_highest_pcount), $rootXpath, $lastHighest); } } }
public function showAction($args = null) { global $tpl, $app; $id = isset($args['id']) ? (int) $args['id'] : ''; //如果为空 提示出错 try { $article = new Article('id', $id); if (!$article->id) { throw new Exception('文章不存在'); } $content_part = ContentPart::findById($id); //语法加亮处理 $article->content = processContent($content_part->content); $article->tags = $article->getTags(); $article->category = $this->categories[$article->cid]->name; $article->category_slug = $this->categories[$article->cid]->slug; //上一篇文章 $previous = $article->previous(); //下一篇文章 $next = $article->next(); //首页最近文章 //$recent_post = Article::getPost(5, true); } catch (Exception $e) { //die($e->getMessage()); $app->error($e->getMessage(), SITE_URL); } $tpl->assign('post', $article); $tpl->assign('next', $next); $tpl->assign('previous', $previous); //首页post静态页 if (DEBUG === false) { $fp = fopen(SYSTEM_ROOT . "post/{$id}.html", 'w'); fputs($fp, $tpl->fetch(DEFAULT_TEMPLATE . '/post.html')); fclose($fp); } $tpl->display(DEFAULT_TEMPLATE . '/post.html'); }