contentList.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\models;
  3. use app\models\Entry;
  4. use \phpQuery;
  5. use \Archive\Tar
  6. use app\utils\Gzip.php;
  7. class contentList extends \lithium\data\Model {
  8. public function update()
  9. {
  10. }
  11. public function add($entity, $data)
  12. {
  13. $updateData = array('$push' => array(''
  14. $conditions = array('_id' => $user['_id']);
  15. $result = User::update($updateData, $conditions, array('atomic' => false));
  16. }
  17. public function importManga() {
  18. }
  19. public static function importAnimeXML{$user, $file}
  20. {
  21. $xml = ungzip($file);
  22. $list = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  23. foreach ($list->animelist as $entry)
  24. {
  25. $user->animelist[] = Entry::create($entry);
  26. }
  27. return $user->save(null, array('validate' => false));
  28. }
  29. /* public function importAnime($user, $malun, $malpass) {
  30. //This method assumes we are importing from mal at the moment.
  31. //1. Parse Mal for the download link
  32. //1.1 Login to MAL
  33. $cmd = "curl -c cookie.txt -d \"username=$malun&password=$malpass\" http://myanimelist.net/login.php";
  34. $result = shell_exec($cmd);
  35. //If the request went ok
  36. if (empty($result)) {
  37. //1.2 Request a list export
  38. $cmd_getList = "curl -b cookie.txt -d \"value=1&subexport=Export My List\" http://myanimelist.net/panel.php?go=export";
  39. $malreturn = shell_exec($cmd_getList);
  40. //Initate a new document for phpQuery.
  41. $doc = phpQuery::newDocument($malreturn);
  42. //Grab the div with the content in it, (should be goodresult actually <div class=goodresult>)
  43. $mal = pq('#content');
  44. //If everything goes to plan, the only link the the body will be the one we want,
  45. $link = $mal->find('a')->attr('href');
  46. $cmd = "curl -b cookie.txt $link";
  47. $data = shell_exec($cmd);
  48. $xml_source = gzdecode($data);
  49. $list = simplexml_load_string($xml_source, 'SimpleXMLElement', LIBXML_NOCDATA);
  50. foreach($list as $entry) {
  51. print_r($entry);
  52. }
  53. }
  54. //2. Download the linked file
  55. //3. Extract and unzip it
  56. //4. Take the XML and parse it
  57. $xml_source; //<-- the XML code
  58. $xml = simplexml_load_string($xml_source, 'SimpleXMLElement', LIBXML_NOCDATA);
  59. if (!isset($user->animelist))
  60. {
  61. $user->animelist = array();
  62. }
  63. //Create entries
  64. foreach($xml->anime as $entry)
  65. {
  66. $user->animelist[] = Entry::create($entry);
  67. }
  68. //Store the entries to the database
  69. return $user->save(null, array('validate' => false));
  70. }*/
  71. }