Unnamed Fossil Project

Check-in [da1cb101a4]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Funkcni import...
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:da1cb101a4e066946af5d812ddf488bc2e99bce1
User & Date: root 2013-04-03 00:57:18
Context
2013-04-03
00:57
Funkcni import... Leaf check-in: da1cb101a4 user: root tags: trunk
2013-04-01
21:29
first import... check-in: 24768f2ba3 user: root tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Name change from index.php to import.php.

5
6
7
8
9
10
11
12
13
14
15

16
17

require $libPath . '/brickyard.php';

$fw = new brickyard();
$fw->init();
$fw->inDevelMode = true;

$db = new fDatabase('sqlite', $rootPath . '/db/zupy.db3');
echo 'DB';
$import = new zupy_mirror_soup($db);
echo 'IMPORT';

$import->importFeed($rootPath . '/soup_severak.rss', 1);
echo 'OK';







|



>
|

5
6
7
8
9
10
11
12
13
14
15
16
17
18

require $libPath . '/brickyard.php';

$fw = new brickyard();
$fw->init();
$fw->inDevelMode = true;

$db = new fDatabase('sqlite', '/srv/www/db/zupy.db3');
echo 'DB';
$import = new zupy_mirror_soup($db);
echo 'IMPORT';
date_default_timezone_set('Europe/Prague');
$import->importFeed($rootPath . '/soup_ruzovy_2013-03-28.rss', 2);
echo 'OK';

Changes to lib/brick/saxofon.php.

37
38
39
40
41
42
43
44
45
46
47
48

49
50
51
52
				}
			} elseif ($reader->nodeType == XMLReader::TEXT) {
				$n = join('/', $stack);
				if (isset($this->_textCallbacks[$n])) {
					call_user_func($this->_textCallbacks[$n], $reader->value);
				}
			} elseif ($reader->nodeType == XMLReader::END_ELEMENT) {
				array_pop($stack);
				$n = join('/', $stack);
				if (isset($this->_closeCallbacks[$n])) {
					call_user_func($this->_closeCallbacks[$n]);
				}

			}
		}
	}
}







<




>




37
38
39
40
41
42
43

44
45
46
47
48
49
50
51
52
				}
			} elseif ($reader->nodeType == XMLReader::TEXT) {
				$n = join('/', $stack);
				if (isset($this->_textCallbacks[$n])) {
					call_user_func($this->_textCallbacks[$n], $reader->value);
				}
			} elseif ($reader->nodeType == XMLReader::END_ELEMENT) {

				$n = join('/', $stack);
				if (isset($this->_closeCallbacks[$n])) {
					call_user_func($this->_closeCallbacks[$n]);
				}
				array_pop($stack);
			}
		}
	}
}

Changes to lib/zupy/mirror/soup.php.

1
2
3
4
5

6
7
8
9
10
11
12
13

14
15
16

17
18


19

20
21
22
23
24










25
26
27
28
29
30
31
32
33
34














35
36
37
38









39

40
41
<?php
class zupy_mirror_soup
{
	private $_db = null;
	private $_post = null;

	
	function __construct(fDatabase $db)
	{
		$this->_db = $db;
	}
	
	function importFeed($file, $destinationUser)
	{

		$saxofon= new brick_saxofon;
		$saxofon->registerOpen("rss/channel/item", array($this, 'openItem'));
		$saxofon->registerText("rss/channel/item/guid", array($this, 'setGuid'));

		$saxofon->registerText("rss/channel/item/soup:attributes", array($this, 'setSoup'));
		$saxofon->registerClose("rss/channel/item", array($this, 'closeItem'));


		$saxofon->readFile($file);

	}
	
	function openItem()
	{
		$this->_post = new stdClass;










	}
	
	function setGuid($text)
	{
		$this->_post->guid = $text;
	}
	
	function setSoup($text)
	{
		echo $text . '<br>';














	}
	
	function closeItem()
	{









		//var_dump($this->_post);

	}
} 





>








>



>


>
>

>




|
>
>
>
>
>
>
>
>
>
>




|




|
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
>
>
>
>
>
>
>
>
|
>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
class zupy_mirror_soup
{
	private $_db = null;
	private $_post = null;
	private $_destination = null;
	
	function __construct(fDatabase $db)
	{
		$this->_db = $db;
	}
	
	function importFeed($file, $destinationUser)
	{
		$this->_destination = $destinationUser;
		$saxofon= new brick_saxofon;
		$saxofon->registerOpen("rss/channel/item", array($this, 'openItem'));
		$saxofon->registerText("rss/channel/item/guid", array($this, 'setGuid'));
		$saxofon->registerText("rss/channel/item/pubDate", array($this, 'setPubDate'));
		$saxofon->registerText("rss/channel/item/soup:attributes", array($this, 'setSoup'));
		$saxofon->registerClose("rss/channel/item", array($this, 'closeItem'));
		
		$this->_db->query('BEGIN');
		$saxofon->readFile($file);
		$this->_db->query('COMMIT');
	}
	
	function openItem()
	{
		$this->_post = array(
			'wall_id'=>$this->_destination,
			'date'=>0,
			'author_id'=>$this->_destination,
			'type'=>0,
			'title'=>'',
			'text'=>'',
			'source'=>'',
			'data_url'=>'',
			'guid'=>''
		);
	}
	
	function setGuid($text)
	{
		$this->_post['guid'] = $text;
	}
	
	function setSoup($text)
	{
		$def = json_decode($text, true);
		if (isset($def['title'])) {
			$this->_post['title'] = $def['title'];
		}
		if (isset($def['body'])) {
			$this->_post['text'] = $def['body'];
		}
		if ($def['type']=='image') {
			$this->_post['data_url'] = $def['url'];
		}
	}
	
	function setPubDate($date)
	{
		$this->_post['date'] = $date;
	}
	
	function closeItem()
	{
		$this->_db->query(
			'INSERT INTO post(wall_id, author_id, date, title, text, source, data_url, guid) VALUES (%i, %i, %d, %s, %s, %s, %s, %s)',
			$this->_post['wall_id'],
			$this->_post['author_id'],
			$this->_post['date'],
			$this->_post['title'],
			$this->_post['text'],
			$this->_post['source'],
			$this->_post['data_url'],
			$this->_post['guid']
		);
	}
} 

Added schema.sql.





























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-- Adminer 3.6.3 SQLite 3 dump

CREATE TABLE "wall" (
  "id" integer NULL PRIMARY KEY AUTOINCREMENT,
  "name" text NULL,
  "is_group" numeric NULL,
  "title" text NULL,
  "description" text NULL,
  "picture" text NULL
);


CREATE TABLE sqlite_sequence(name,seq);


CREATE TABLE "post" (
  "id" integer NULL PRIMARY KEY AUTOINCREMENT,
  "wall_id" numeric NULL,
  "author_id" numeric NULL,
  "date" text NULL,
  "type" numeric NULL,
  "title" text NULL,
  "text" text NULL,
  "source" text NULL,
  "data_url" text NULL,
  "guid" text NULL,
  "repost_id" numeric NULL
);