From 05a2b26d9038752a40348a3f226e44710833c49b Mon Sep 17 00:00:00 2001 From: raylu Date: Sat, 2 Jul 2011 17:02:07 -0700 Subject: pull in dev branch changes not pulled: swiftmailer, gzip --- models/Anime.php | 2 +- models/Entry.php | 26 ++++++++------- models/Kdrama.php | 41 ++++++++++++++++++++++++ models/Post.php | 4 ++- models/Profile.php | 1 + models/contentList.php | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 147 insertions(+), 14 deletions(-) create mode 100644 models/Kdrama.php (limited to 'models') diff --git a/models/Anime.php b/models/Anime.php index 34b999e..2798a43 100644 --- a/models/Anime.php +++ b/models/Anime.php @@ -23,7 +23,7 @@ class Anime extends \lithium\data\Model { - $total = Anime::count(array($by => $query)); + $total = self::count(array($by => $query)); break; default: diff --git a/models/Entry.php b/models/Entry.php index e84d438..12a3035 100644 --- a/models/Entry.php +++ b/models/Entry.php @@ -10,9 +10,9 @@ Class entry extends \lithium\data\Model { public static function __init() { parent::__init(); - //Validators go here } + public $_schema = array('_id' => array('type' => 'id')); public $validates = array( 'my_watched_episodes' => array('numeric', 'message' => 'please enter a number'), 'my_start_date' => array('date', 'message' => 'Please enter a valid date'), @@ -20,7 +20,7 @@ Class entry extends \lithium\data\Model { 'my_score' => array(array('inRange' => array('min' => 0, 'max' => '10'), 'message' => 'Enter a valid score'), array('numeric', 'message' => 'Please enter a number')), //'my_status' => array('isValidStatus', 'message' => 'please enter valid status'), - 'my_times_watched' => array('numeric', 'message' => 'This must be a number') + 'my_times_watched' => array('numeric', 'message' => 'This must be a number'), ); //Add timestamping to entries. :TODO: @@ -29,36 +29,38 @@ Class entry extends \lithium\data\Model { - /* public function add($entity, $username) { - var_dump($entity->_data); - exit(); - $updateData = array('$push' => array('animelist' => $entity)); - $conditions = array('username' => $username); + $updateData = array('$push' => array('animelist' => $entity->data())); + $conditions = compact('username'); $result = Entry::update($updateData, $conditions, array('atomic' => false)); return $result; } - */ + /* //Got lazy, the proper way to do it is above, but needs a bit of fiddling. - //The below code works, but forces mongo to resave the entire record, which tags + //The below code works, but forces mongo to resave the entire record, which takes //longer than just updating what has chaged. public function add($entity, $username) { $user = User::find('first', array('conditions' => compact('username'))); $entity->created_on = new MongoDate(); $entity->updated_on = new MongoDate(); + $user->animelist[] = $entity; - if (Validator::check($entity->data(), $this->validates, array('skipEmpty' => 'true'))) { - return $user->save(null, array('validate' => false)); - } + //if (Validator::check($entity->data(), $this->validates, array('skipEmpty' => 'true'))) { + $return = $user->save(null, array('validate' => false)); + var_dump($entity); + exit(); + /* else { return false; } + } + */ public function edit($entity, $username) { diff --git a/models/Kdrama.php b/models/Kdrama.php new file mode 100644 index 0000000..9d3ddf7 --- /dev/null +++ b/models/Kdrama.php @@ -0,0 +1,41 @@ + '_id', 'source' => 'kdrama'); + + public static function search($query, $page = 1, $by = 'title') + { + $defaults = array('limit' => 20); + $limit = 20; + + switch($by) { + case 'special_id': + + $content = parent::find('first', + array('conditions' => array( + $by => $query + ), + 'limit' => $limit, + 'page' => $page + )); + + + + $total = parent::count(array($by => $query)); + break; + + default: + $content = parent::find('all', + array('conditions' => array( + $by => array('like' => $query) + ), + 'limit' => $limit, + 'page' => $page + )); + $total = parent::count(array($by => array('like' => $query))); + } + return compact('content', 'by', 'limit', 'total', 'page'); + } +} \ No newline at end of file diff --git a/models/Post.php b/models/Post.php index 58e2487..ec82ca2 100644 --- a/models/Post.php +++ b/models/Post.php @@ -67,7 +67,9 @@ class Post extends \lithium\data\Model { if ($user) { //Add the post to their feed, - return $post->store($user); + var_dump($entity->data()); + $entity->save(); + return $entity->store($user); } //If the user wasn't found return false; diff --git a/models/Profile.php b/models/Profile.php index 83f82ae..18d099f 100644 --- a/models/Profile.php +++ b/models/Profile.php @@ -1,6 +1,7 @@ $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
) + $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)); + + }*/ } \ No newline at end of file -- cgit v1.2.3