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
92
93
94
95
96
97
98
99
100
101
102
103
104
|
<?php
namespace app\models;
use app\models\Entry;
use \phpQuery;
use \Archive\Tar
use app\utils\Gzip.php;
class contentList extends \lithium\data\Model {
public function update()
{
}
public function add($entity, $data)
{
$updateData = array('$push' => array(''
$conditions = array('_id' => $user['_id']);
$result = User::update($updateData, $conditions, array('atomic' => false));
}
public function importManga() {
}
public static function importAnimeXML{$user, $file}
{
$xml = ungzip($file);
$list = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
foreach ($list->animelist as $entry)
{
$user->animelist[] = Entry::create($entry);
}
return $user->save(null, array('validate' => false));
}
/* public function importAnime($user, $malun, $malpass) {
//This method assumes we are importing from mal at the moment.
//1. Parse Mal for the download link
//1.1 Login to MAL
$cmd = "curl -c cookie.txt -d \"username=$malun&password=$malpass\" http://myanimelist.net/login.php";
$result = shell_exec($cmd);
//If the request went ok
if (empty($result)) {
//1.2 Request a list export
$cmd_getList = "curl -b cookie.txt -d \"value=1&subexport=Export My List\" http://myanimelist.net/panel.php?go=export";
$malreturn = shell_exec($cmd_getList);
//Initate a new document for phpQuery.
$doc = phpQuery::newDocument($malreturn);
//Grab the div with the content in it, (should be goodresult actually <div class=goodresult>)
$mal = pq('#content');
//If everything goes to plan, the only link the the body will be the one we want,
$link = $mal->find('a')->attr('href');
$cmd = "curl -b cookie.txt $link";
$data = shell_exec($cmd);
$xml_source = gzdecode($data);
$list = simplexml_load_string($xml_source, 'SimpleXMLElement', LIBXML_NOCDATA);
foreach($list as $entry) {
print_r($entry);
}
}
//2. Download the linked file
//3. Extract and unzip it
//4. Take the XML and parse it
$xml_source; //<-- the XML code
$xml = simplexml_load_string($xml_source, 'SimpleXMLElement', LIBXML_NOCDATA);
if (!isset($user->animelist))
{
$user->animelist = array();
}
//Create entries
foreach($xml->anime as $entry)
{
$user->animelist[] = Entry::create($entry);
}
//Store the entries to the database
return $user->save(null, array('validate' => false));
}*/
}
|