| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Crawler.php |
|---|
| 4 | * |
|---|
| 5 | * @author halt feits <halt.feits at gmail.com> |
|---|
| 6 | * @package Delphinus |
|---|
| 7 | * @version $Id: skel.action.php,v 1.4 2005/01/04 12:53:26 fujimoto Exp $ |
|---|
| 8 | */ |
|---|
| 9 | |
|---|
| 10 | /** |
|---|
| 11 | * Crawler����若����茖� * |
|---|
| 12 | * @author halt feits <halt.feits at gmail.com> |
|---|
| 13 | * @access public |
|---|
| 14 | * @package Delphinus |
|---|
| 15 | */ |
|---|
| 16 | class Delphinus_CLI_Form_Crawler extends Ethna_ActionForm |
|---|
| 17 | { |
|---|
| 18 | /** |
|---|
| 19 | * @access private |
|---|
| 20 | * @var array ����若��ゅ�臂� */ |
|---|
| 21 | var $form = array( |
|---|
| 22 | /* |
|---|
| 23 | 'sample' => array( |
|---|
| 24 | 'name' => '�泣����', // 茵�ず�� 'required' => true, // 綽������激���true/false) |
|---|
| 25 | 'min' => null, // ����� 'max' => null, // ��ぇ�� 'regexp' => null, // ���腮��絎�罩h�茵�� |
|---|
| 26 | 'custom' => null, // �<�����������с��� 'filter' => null, // �ュ��ゅ�����c��帥�����с� |
|---|
| 27 | 'form_type' => FORM_TYPE_TEXT // ����若��� 'type' => VAR_TYPE_INT, // �ュ��ゅ� |
|---|
| 28 | ), |
|---|
| 29 | */ |
|---|
| 30 | ); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | /** |
|---|
| 34 | * Crawler�≪��激��潟�絎�� |
|---|
| 35 | * |
|---|
| 36 | * @author halt feits <halt.feits at gmail.com> |
|---|
| 37 | * @access public |
|---|
| 38 | * @package Delphinus |
|---|
| 39 | */ |
|---|
| 40 | class Delphinus_CLI_Action_Crawler extends Ethna_ActionClass |
|---|
| 41 | { |
|---|
| 42 | /** |
|---|
| 43 | * Crawler�≪��激��潟������ * |
|---|
| 44 | * @access public |
|---|
| 45 | * @return string �欠Щ��罩e幻腟�����null, ���腟�����false) |
|---|
| 46 | */ |
|---|
| 47 | function prepare() |
|---|
| 48 | { |
|---|
| 49 | $Controller = $this->backend->getController(); |
|---|
| 50 | if ( $Controller->getCLI() ) { |
|---|
| 51 | return null; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | return false; |
|---|
| 55 | |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | /** |
|---|
| 59 | * Crawler�≪��激��潟�絎�� |
|---|
| 60 | * |
|---|
| 61 | * @access public |
|---|
| 62 | * @return string �欠Щ�� */ |
|---|
| 63 | function perform() |
|---|
| 64 | { |
|---|
| 65 | $cache =& $this->backend->plugin->getPlugin('Cachemanager', 'Localfile'); |
|---|
| 66 | $cache->clear('index'); |
|---|
| 67 | |
|---|
| 68 | print("Start Crawl Feeds<br>\n"); |
|---|
| 69 | $this->crawlRSS(); |
|---|
| 70 | $Controller = $this->backend->getController(); |
|---|
| 71 | $path_bin = $Controller->getDirectory('bin'); |
|---|
| 72 | exec("php {$path_bin}/rss_rebuild.php"); |
|---|
| 73 | return null; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | /** |
|---|
| 77 | * crawlRSS |
|---|
| 78 | * |
|---|
| 79 | * @access protected |
|---|
| 80 | * @param void |
|---|
| 81 | */ |
|---|
| 82 | function crawlRSS() |
|---|
| 83 | { |
|---|
| 84 | require_once 'XML/Feed/Parser.php'; |
|---|
| 85 | |
|---|
| 86 | $DB = $this->backend->getDB(); |
|---|
| 87 | $rss_list = $DB->getRssList(); |
|---|
| 88 | $allow_category = $this->config->get('allow_category'); |
|---|
| 89 | |
|---|
| 90 | foreach( $rss_list as $rss){ |
|---|
| 91 | |
|---|
| 92 | print("Fetch:{$rss['url']}<br>\n"); |
|---|
| 93 | |
|---|
| 94 | try { |
|---|
| 95 | $feed = new XML_Feed_Parser(file_get_contents($rss['rss_url'])); |
|---|
| 96 | } catch(XML_Feed_Parser_Exception $e) { |
|---|
| 97 | print('Feed invalid: ' . $e->getMessage()); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | foreach($feed as $entry){ |
|---|
| 101 | |
|---|
| 102 | if (is_string($allow_category) && ($entry->category !== false) && (strtoupper($entry->category) != $allow_category)) { |
|---|
| 103 | print("Parge:{$entry->category}\n"); |
|---|
| 104 | continue; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | $item['title'] = $entry->title; |
|---|
| 108 | if ($entry->date !== false) { |
|---|
| 109 | $item['date'] = date('Y-m-d H:i:s', $entry->date); |
|---|
| 110 | } else { |
|---|
| 111 | $item['date'] = date('Y-m-d H:i:s', $entry->pubdate); |
|---|
| 112 | } |
|---|
| 113 | $item['link'] = $entry->link; |
|---|
| 114 | if ($entry->description !== false) { |
|---|
| 115 | $item['description'] = $entry->description; |
|---|
| 116 | } else { |
|---|
| 117 | $item['description'] = $entry->content; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | if ( !$DB->existsEntryFromLink($item['link']) ) { |
|---|
| 121 | $DB->setEntry($rss['id'], $item); |
|---|
| 122 | } else { |
|---|
| 123 | print('Delete Entry' . "\n"); |
|---|
| 124 | $DB->deleteEntry($item['link']); |
|---|
| 125 | $DB->setEntry($rss['id'], $item); |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | return true; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | } |
|---|
| 134 | ?> |
|---|