diff options
author | raylu <raylu@mixpanel.com> | 2011-07-02 17:02:07 -0700 |
---|---|---|
committer | raylu <raylu@mixpanel.com> | 2011-07-02 17:02:07 -0700 |
commit | 05a2b26d9038752a40348a3f226e44710833c49b (patch) | |
tree | 9bc3e49ac2e84b33ca5ff6e44eb7e5f2c02d13bf | |
parent | 83483a1826d1d05e2f9733746f35fef1939b8c0a (diff) | |
download | otakuhub-05a2b26d9038752a40348a3f226e44710833c49b.tar.xz |
pull in dev branch changes
not pulled: swiftmailer, gzip
-rw-r--r-- | config/bootstrap.php | 2 | ||||
-rw-r--r-- | config/bootstrap/permissions.php | 35 | ||||
-rw-r--r-- | config/routes.php | 4 | ||||
-rw-r--r-- | controllers/AnimelistController.php | 9 | ||||
-rw-r--r-- | controllers/ImportController.php | 13 | ||||
-rw-r--r-- | controllers/MangalistController.php | 11 | ||||
-rw-r--r-- | controllers/UsersController.php | 26 | ||||
-rw-r--r-- | models/Anime.php | 2 | ||||
-rw-r--r-- | models/Entry.php | 26 | ||||
-rw-r--r-- | models/Kdrama.php | 41 | ||||
-rw-r--r-- | models/Post.php | 4 | ||||
-rw-r--r-- | models/Profile.php | 1 | ||||
-rw-r--r-- | models/contentList.php | 87 | ||||
-rw-r--r-- | table.php | 27 | ||||
-rw-r--r-- | views/anime_list/add.html.php | 8 | ||||
-rw-r--r-- | views/elements/animesearch.html.php | 4 | ||||
-rw-r--r-- | views/elements/authnav.html.php | 2 | ||||
-rw-r--r-- | views/import/index.html.php | 5 | ||||
-rw-r--r-- | views/search/anime.html.php | 27 |
19 files changed, 282 insertions, 52 deletions
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 @@ +<?php + +//Permissions stuff +/* +Access::config(array( + 'permissions' => 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 @@ +<?php + +namespace app\controllers; + +class ImportController extends \lithium\action\Controller { + public function index($source, $type = 'all') { + if ($this->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 @@ +<?php + +namespace app\controllers; + +class MangalistController extends \lithium\action\Controller { + public function view($username) + { + $user = User::first('conditions' => 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 @@ +<?php + +namespace app\models; + +class Kdrama extends \lithium\data\Model { + protected $_meta = array('key' => '_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 @@ <?php namespace app\models; +use \lithium\util\Validator; class Profile extends \lithium\data\Model { public static function __init() diff --git a/models/contentList.php b/models/contentList.php index 017e261..ed890ef 100644 --- a/models/contentList.php +++ b/models/contentList.php @@ -2,6 +2,10 @@ 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() { @@ -14,4 +18,87 @@ class contentList extends \lithium\data\Model { $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)); + + }*/ }
\ 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 @@ +<?php + +//table helper + +public function table($data, array $headers = array(), array $options = array()) { + //Create the table + echo '<table>\n'; + echo '<tr>'; + foreach ($headers as $k => $v) + { + echo "<th>$v</th>" + } + echo "</tr>\n" + + + foreach ($data as $item) + { + echo '<tr>' + foreach($header as $key => $value) + { + echo "<td>$data->$key</td>\n" + } + echo "</tr>\n" + } + echo "</table>" +} +?>
\ 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 @@ <?php if (empty($anime)): ?> <h2 class="ribbon full">Find an Anime:</h2> <div class="triangle-ribbon"></div> -<br class="clear" /> +<br class="cl" /> <?php else: ?> <h2 class="ribbon full"><?= $anime->title ?></h2> <div class="triangle-ribbon"></div> -<br class="clear" /> +<br class="cl" /> <?php endif; ?> <script type="text/javascript"> @@ -30,6 +30,7 @@ } echo $this->form->field('my_watched_episodes', array('label' => 'Watched Episodes')); + echo "Start date"; echo $this->form->field('my_start_date', array('label' => 'Start Date')); echo $this->form->field('my_finish_date', array('label' => 'Finish Date')); echo $this->form->field('my_score', array('label' => 'Score')); @@ -46,4 +47,5 @@ echo $this->form->field('tags', array('type' => 'textarea', 'id' => 'tags')); echo $this->form->checkbox('rewatching', array('label' =>'Rewatching?', 'value' => false)); echo $this->form->submit('Save!'); -?>
\ No newline at end of file + echo $this->form->end(); +?> diff --git a/views/elements/animesearch.html.php b/views/elements/animesearch.html.php new file mode 100644 index 0000000..370ff1a --- /dev/null +++ b/views/elements/animesearch.html.php @@ -0,0 +1,4 @@ +<tr><th>img</th><th>Name</th><th>Episodes</th><th>Type</th><th>Score</th></tr> + <?php foreach($content as $item): ?> + <tr><td>"image"</td><td><a href="/anime/view/<?= $item->special_id ?>"><?= $item->title ?></a></td> <td><?= $item->episode_count ?></td><td><?= $item->view_type ?></td><td><?= $item->mal_score ?></td></tr> +<?php endforeach; ?>
\ No newline at end of file diff --git a/views/elements/authnav.html.php b/views/elements/authnav.html.php index b961c39..e2f3d99 100644 --- a/views/elements/authnav.html.php +++ b/views/elements/authnav.html.php @@ -1,7 +1,7 @@ <nav> <ul id="nav"> <li class="current"><a href="/users/feed">Home</a></li> - <li><a href="about.html">Anime</a></li> + <li><a href="about.html">Anime</a> <ul> <li><a href="about.html">Top Anime</a> <li><a href="#">Recomendations</a></li> diff --git a/views/import/index.html.php b/views/import/index.html.php new file mode 100644 index 0000000..da0d396 --- /dev/null +++ b/views/import/index.html.php @@ -0,0 +1,5 @@ +<?php + echo $this->form->create(); + echo $this->form->field(array('type' => 'file')); + echo $this->form->end(); +?>
\ No newline at end of file diff --git a/views/search/anime.html.php b/views/search/anime.html.php new file mode 100644 index 0000000..70a6315 --- /dev/null +++ b/views/search/anime.html.php @@ -0,0 +1,27 @@ + +<div class="container_12"> +<div class="grid_4"> +<h2> Search options </h2> +<hr /> +<?= $this->form->create(null, array('method' => 'get')); ?> + <?= $this->form->field('search', array('type' => 'textbox', 'class' => 'sidebar-search', 'style' => 'width:200px')); ?> + <?= $this->form->label('type', 'For:'); ?> + <?= $this->form->select('type', array('Anime' => 'Anime', + 'Manga' => 'Manga', + 'Kdrama' => 'Kdrama')); ?> + <?= $this->form->submit('Search', array('style' => 'width: 100px')); ?> +<?= $this->form->end(); ?> +</div> +<div class="grid_8"> +<h2>Search Results</h2> +<hr /> + <table class="table"> + <tr><th>img</th><th>Name</th><th>Episodes</th><th>Type</th><th>Score</th></tr> + <?php foreach($content as $item): ?> + <tr><td>"image"</td><td><a href="/anime/view/<?= $item->special_id ?>"><?= $item->title ?></a></td> <td><?= $item->episode_count ?></td><td><?= $item->view_type ?></td><td><?= $item->mal_score ?></td></tr> + <?php endforeach; ?> + </table> +<?=$this->Paginator->paginate(array('separator' => '', 'action' => 'index/anime')); ?> +</div> +<br class="cl"> +</div>
\ No newline at end of file |