-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpintrest.php
91 lines (65 loc) · 1.97 KB
/
pintrest.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
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
82
83
84
85
86
87
88
89
90
91
<?php
// Grab pintrest RSS feed and add images to CouchDB
require_once (dirname(__FILE__) . '/config.inc.php');
require_once (dirname(__FILE__) . '/couchsimple.php');
require_once (dirname(__FILE__) . '/lib.php');
$url = 'http://pinterest.com/rdmpage/feed.rss';
$xml = get($url);
$dom= new DOMDocument;
$dom->loadXML($xml);
$xpath = new DOMXPath($dom);
$itemCollection = $xpath->query ('//item');
foreach ($itemCollection as $item)
{
$obj = new stdclass;
$nodeCollection = $xpath->query ('title', $item);
foreach ($nodeCollection as $node)
{
$obj->title = $node->firstChild->nodeValue;
}
$nodeCollection = $xpath->query ('link', $item);
foreach ($nodeCollection as $node)
{
$obj->link = $node->firstChild->nodeValue;
$html = get($obj->link);
$html = str_replace("\n", "", $html);
$html = str_replace("\r", "", $html);
if (preg_match('/<meta property="og:see_also"\s+name="og:see_also"\s+content="http:\/\/biostor.org\/reference\/(biostor\/)?(?<id>\d+)(\/page\/\d+)?"/Uu', $html, $m))
{
$obj->biostor = $m['id'];
}
}
$nodeCollection = $xpath->query ('description', $item);
foreach ($nodeCollection as $node)
{
$obj->description = $node->firstChild->nodeValue;
if (preg_match('/src="(?<image>https:\/\/(.*).jpg)"/Uu', $obj->description, $m))
{
$obj->image = $m['image'];
// grab
$image = get($obj->image);
if ($image != '')
{
$mime_type = 'image/jpg';
$base64 = chunk_split(base64_encode($image));
$obj->thumbnail = 'data:' . $mime_type . ';base64,' . $base64;
}
}
}
$nodeCollection = $xpath->query ('pubDate', $item);
foreach ($nodeCollection as $node)
{
$obj->pubDate = $node->firstChild->nodeValue;
// Date as array
$obj->date = explode("-", date("Y-n-j", strtotime($obj->pubDate)));
}
$obj->_id = $obj->link;
$obj->type = "pintrest";
print_r($obj);
// only grab pins from BioStor
if (isset($obj->biostor))
{
$couch->add_update_or_delete_document($obj, $obj->_id);
}
}
?>