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 --- config/bootstrap.php | 2 +- config/bootstrap/permissions.php | 35 +++++++++++++++ config/routes.php | 4 -- controllers/AnimelistController.php | 9 +--- controllers/ImportController.php | 13 ++++++ controllers/MangalistController.php | 11 +++++ controllers/UsersController.php | 26 +++-------- models/Anime.php | 2 +- models/Entry.php | 26 ++++++----- models/Kdrama.php | 41 +++++++++++++++++ models/Post.php | 4 +- models/Profile.php | 1 + models/contentList.php | 87 +++++++++++++++++++++++++++++++++++++ table.php | 27 ++++++++++++ views/anime_list/add.html.php | 8 ++-- views/elements/animesearch.html.php | 4 ++ views/elements/authnav.html.php | 2 +- views/import/index.html.php | 5 +++ views/search/anime.html.php | 27 ++++++++++++ 19 files changed, 282 insertions(+), 52 deletions(-) create mode 100644 config/bootstrap/permissions.php create mode 100644 controllers/ImportController.php create mode 100644 controllers/MangalistController.php create mode 100644 models/Kdrama.php create mode 100644 table.php create mode 100644 views/elements/animesearch.html.php create mode 100644 views/import/index.html.php create mode 100644 views/search/anime.html.php diff --git a/config/bootstrap.php b/config/bootstrap.php index 2a46046..1ced565 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -82,6 +82,6 @@ require __DIR__ . '/bootstrap/media.php'; */ // require __DIR__ . '/bootstrap/console.php'; -// require __DIR__ . '/bootstrap/permissions.php'; +require __DIR__ . '/bootstrap/permissions.php'; ?> diff --git a/config/bootstrap/permissions.php b/config/bootstrap/permissions.php new file mode 100644 index 0000000..c4fe982 --- /dev/null +++ b/config/bootstrap/permissions.php @@ -0,0 +1,35 @@ + array( + 'adapter' => 'Permissions', + 'model' => 'app\models\Perms', + 'defaultNoUser' => array(), + 'defaultUser' => array( + 'route' => array( + 'users' => array( + 'logout', 'account' + ) + ) + ), + 'userIdentifier' => 'PrincipalID' + ) +)); + +Perms::applyFilter('find', function($self, $params, $chain) { + if($params['type'] != 'first') { + return $chain->next($self, $params, $chain); + } + $cacheKey = 'permissions_' . $params['options']['conditions']['id']; + $cache = Cache::read('default', $cacheKey); + if($cache) { + return $cache; + } + $result = $chain->next($self, $params, $chain); + Cache::write('default', $cacheKey, $result, '+1 day'); + return $result; +}); +*/ +?> \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 1da09b9..7ac2567 100644 --- a/config/routes.php +++ b/config/routes.php @@ -53,10 +53,6 @@ if (!Environment::is('production')) { Router::connect('/login', array('controller' => 'users', 'action' => 'login')); Router::connect('/logout', array('controller' => 'users', 'action' => 'logout')); -/* Content routes */ -//Router::connect('/anime', array('controller' => 'content', 'action' => 'anime')); -//Router::connect('/anime/{:args}', array('controller' => 'anime', 'action' => 'view')); - //Pagination route Router::connect('/{:controller}/{:action}/page:{:page:[0-9]+}'); diff --git a/controllers/AnimelistController.php b/controllers/AnimelistController.php index add8fb7..47e5de2 100644 --- a/controllers/AnimelistController.php +++ b/controllers/AnimelistController.php @@ -94,17 +94,10 @@ class AnimeListController extends \lithium\action\Controller { $entry->my_tags = explode(',', $this->request->data['tags']); unset($this->request->data['tags']); } - - /* - var_dump($entry->_validates); - //If the entry is valid - if (Validator::check($entry->data(),$entry->_validates, array('skipEmpty' => true))) { - //Store it, :TODO: make sure this passes at some point, silent failures suck - $entry->add($username); - */ if($entry->add($username)) { + //Redirect the user to their anime list return $this->redirect("/animelist/view/$username"); } diff --git a/controllers/ImportController.php b/controllers/ImportController.php new file mode 100644 index 0000000..af917fb --- /dev/null +++ b/controllers/ImportController.php @@ -0,0 +1,13 @@ +request->data) { + $user = Auth::check('default'); + $user = Users::find($user->id); + ContentList::ImportAnimeXML($user, $this->request->data['file']); + } + } +} \ No newline at end of file diff --git a/controllers/MangalistController.php b/controllers/MangalistController.php new file mode 100644 index 0000000..1f2bec6 --- /dev/null +++ b/controllers/MangalistController.php @@ -0,0 +1,11 @@ + compact('username')); + + } +} \ No newline at end of file diff --git a/controllers/UsersController.php b/controllers/UsersController.php index 3991738..d1b3193 100644 --- a/controllers/UsersController.php +++ b/controllers/UsersController.php @@ -11,7 +11,7 @@ use lithium\security\Auth; use lithium\util\String; use \MongoDate; use li3_flash_message\extensions\storage\FlashMessage; -use app\libraries\openID\LightOpenID; +use lithium\template\helper\Html; class UsersController extends \lithium\action\Controller { public $secret = "marshmellows"; //I don't know why either? @@ -223,21 +223,6 @@ class UsersController extends \lithium\action\Controller { } - public function openid() - { - if ($this->request->data) - { - if (!empty($this->request->query)) - { - var_dump($this->request->query); - } - else - { - $openid = new LightOpenID; - echo $openid->validates(); - } - } - } public function signup() { @@ -287,15 +272,14 @@ class UsersController extends \lithium\action\Controller { } } - public function login($location = null, $args = null) - { - //Put in a check to make sure the user has confirmed their account - //The check should probably happen below after the auth check. - /* + /* If the user is valid, but not confirmed, tell the user they haven't confirmed, offer to resend the confirmation email or changed their email address. */ + public function login($location = null, $args = null) + { + if (!empty($this->request->data)) { $user = Auth::check('default', $this->request); if ($user) 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 diff --git a/table.php b/table.php new file mode 100644 index 0000000..fd82c8b --- /dev/null +++ b/table.php @@ -0,0 +1,27 @@ +\n'; + echo ''; + foreach ($headers as $k => $v) + { + echo "$v" + } + echo "\n" + + + foreach ($data as $item) + { + echo '' + foreach($header as $key => $value) + { + echo "$data->$key\n" + } + echo "\n" + } + echo "" +} +?> \ No newline at end of file diff --git a/views/anime_list/add.html.php b/views/anime_list/add.html.php index 2e93ffd..de3da9c 100644 --- a/views/anime_list/add.html.php +++ b/views/anime_list/add.html.php @@ -3,11 +3,11 @@

Find an Anime:

-
+

title ?>

-
+