فهرست منبع

pull in dev branch changes

not pulled: swiftmailer, gzip
raylu 14 سال پیش
والد
کامیت
05a2b26d90

+ 1 - 1
config/bootstrap.php

@@ -82,6 +82,6 @@ require __DIR__ . '/bootstrap/media.php';
  */
  */
 // require __DIR__ . '/bootstrap/console.php';
 // require __DIR__ . '/bootstrap/console.php';
 
 
-// require __DIR__ . '/bootstrap/permissions.php';
+require __DIR__ . '/bootstrap/permissions.php';
 
 
 ?>
 ?>

+ 35 - 0
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;
+});
+*/
+?>

+ 0 - 4
config/routes.php

@@ -53,10 +53,6 @@ if (!Environment::is('production')) {
 Router::connect('/login',  array('controller' => 'users', 'action' => 'login'));
 Router::connect('/login',  array('controller' => 'users', 'action' => 'login'));
 Router::connect('/logout', array('controller' => 'users', 'action' => 'logout'));
 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
 //Pagination route
 Router::connect('/{:controller}/{:action}/page:{:page:[0-9]+}');
 Router::connect('/{:controller}/{:action}/page:{:page:[0-9]+}');
 
 

+ 1 - 8
controllers/AnimelistController.php

@@ -94,17 +94,10 @@ class AnimeListController extends \lithium\action\Controller {
 				$entry->my_tags = explode(',', $this->request->data['tags']);
 				$entry->my_tags = explode(',', $this->request->data['tags']);
 				unset($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))
 			if($entry->add($username))
 			{
 			{
+
 				//Redirect the user to their anime list
 				//Redirect the user to their anime list
 				return $this->redirect("/animelist/view/$username");	
 				return $this->redirect("/animelist/view/$username");	
 			}
 			}

+ 13 - 0
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']);
+		}
+	}
+} 

+ 11 - 0
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'));
+		
+	}
+}

+ 5 - 21
controllers/UsersController.php

@@ -11,7 +11,7 @@ use lithium\security\Auth;
 use lithium\util\String;
 use lithium\util\String;
 use \MongoDate;
 use \MongoDate;
 use li3_flash_message\extensions\storage\FlashMessage;
 use li3_flash_message\extensions\storage\FlashMessage;
-use app\libraries\openID\LightOpenID;
+use lithium\template\helper\Html;
 
 
 class UsersController extends \lithium\action\Controller {
 class UsersController extends \lithium\action\Controller {
 	public $secret = "marshmellows"; //I don't know why either?
 	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()
 	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,
 			If the user is valid, but not confirmed,
 				tell the user they haven't confirmed,
 				tell the user they haven't confirmed,
 				offer to resend the confirmation email or changed their email address. 
 				offer to resend the confirmation email or changed their email address. 
 		*/
 		*/
+	public function login($location = null, $args = null)
+	{
+		
 		if (!empty($this->request->data)) {
 		if (!empty($this->request->data)) {
 			$user = Auth::check('default', $this->request);
 			$user = Auth::check('default', $this->request);
 			if ($user)
 			if ($user)

+ 1 - 1
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;
 			break;
 			
 			
 			default:
 			default:

+ 14 - 12
models/Entry.php

@@ -10,9 +10,9 @@ Class entry extends \lithium\data\Model {
 	public static function __init() {
 	public static function __init() {
 		parent::__init();
 		parent::__init();
 
 
-		//Validators go here
 	}
 	}
 
 
+	public $_schema = array('_id' => array('type' => 'id'));
 	public $validates = array(
 	public $validates = array(
 		    'my_watched_episodes' => array('numeric', 'message' => 'please enter a number'),
 		    'my_watched_episodes' => array('numeric', 'message' => 'please enter a number'),
 			'my_start_date' => array('date', 'message' => 'Please enter a valid date'),
 			'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'),
 			'my_score' => array(array('inRange' => array('min' => 0, 'max' => '10'), 'message' => 'Enter a valid score'),
 								array('numeric', 'message' => 'Please enter a number')),
 								array('numeric', 'message' => 'Please enter a number')),
 			//'my_status' => array('isValidStatus', 'message' => 'please enter valid status'),
 			//'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:
 	//Add timestamping to entries. :TODO:
@@ -29,36 +29,38 @@ Class entry extends \lithium\data\Model {
 
 
 
 
 
 
-	/*
 	public function add($entity, $username)
 	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));
 		$result = Entry::update($updateData, $conditions, array('atomic' => false));
 		return $result; 
 		return $result; 
 	}
 	}
-	*/
 
 
+	/*
 	//Got lazy, the proper way to do it is above, but needs a bit of fiddling. 
 	//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. 
 	//longer than just updating what has chaged. 
 	public function add($entity, $username)
 	public function add($entity, $username)
 	{
 	{
 		$user = User::find('first', array('conditions' => compact('username')));
 		$user = User::find('first', array('conditions' => compact('username')));
 		$entity->created_on = new MongoDate();
 		$entity->created_on = new MongoDate();
 		$entity->updated_on = new MongoDate();
 		$entity->updated_on = new MongoDate();
+
 		$user->animelist[] = $entity;
 		$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 
 		else 
 		{
 		{
 			return false;
 			return false;
 		}
 		}
+		
 	}
 	}
+	*/
 
 
 	public function edit($entity, $username)
 	public function edit($entity, $username)
 	{
 	{

+ 41 - 0
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');
+	}
+}

+ 3 - 1
models/Post.php

@@ -67,7 +67,9 @@ class Post extends \lithium\data\Model {
 		if ($user)
 		if ($user)
 		{
 		{
 			//Add the post to their feed,
 			//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
 		//If the user wasn't found
 		return false;
 		return false;

+ 1 - 0
models/Profile.php

@@ -1,6 +1,7 @@
 <?php
 <?php
 
 
 namespace app\models;
 namespace app\models;
+use \lithium\util\Validator;
 
 
 class Profile extends \lithium\data\Model {
 class Profile extends \lithium\data\Model {
 	public static function __init() 
 	public static function __init() 

+ 87 - 0
models/contentList.php

@@ -2,6 +2,10 @@
 
 
 namespace app\models;
 namespace app\models;
 
 
+use app\models\Entry; 
+use \phpQuery;
+use \Archive\Tar
+use app\utils\Gzip.php;
 class contentList extends \lithium\data\Model {
 class contentList extends \lithium\data\Model {
 		public function update()
 		public function update()
 		{
 		{
@@ -14,4 +18,87 @@ class contentList extends \lithium\data\Model {
 			$conditions =  array('_id' => $user['_id']);
 			$conditions =  array('_id' => $user['_id']);
 			$result = User::update($updateData, $conditions, array('atomic' => false));
 			$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));
+
+		}*/
 }
 }

+ 27 - 0
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>"
+}
+?>

+ 5 - 3
views/anime_list/add.html.php

@@ -3,11 +3,11 @@
 <?php if (empty($anime)): ?>
 <?php if (empty($anime)): ?>
 <h2 class="ribbon full">Find an Anime:</h2>
 <h2 class="ribbon full">Find an Anime:</h2>
 <div class="triangle-ribbon"></div>
 <div class="triangle-ribbon"></div>
-<br class="clear" />
+<br class="cl" />
 <?php else: ?>
 <?php else: ?>
 <h2 class="ribbon full"><?= $anime->title ?></h2>
 <h2 class="ribbon full"><?= $anime->title ?></h2>
 <div class="triangle-ribbon"></div>
 <div class="triangle-ribbon"></div>
-<br class="clear" />
+<br class="cl" />
 <?php endif; ?>
 <?php endif; ?>
 
 
 <script type="text/javascript">		
 <script type="text/javascript">		
@@ -30,6 +30,7 @@
 	}
 	}
 
 
 	echo $this->form->field('my_watched_episodes', array('label' => 'Watched Episodes'));
 	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_start_date', array('label' => 'Start Date'));
 	echo $this->form->field('my_finish_date', array('label' => 'Finish Date'));
 	echo $this->form->field('my_finish_date', array('label' => 'Finish Date'));
 	echo $this->form->field('my_score', array('label' => 'Score'));
 	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->field('tags', array('type' => 'textarea', 'id' => 'tags'));
 	echo $this->form->checkbox('rewatching', array('label' =>'Rewatching?', 'value' => false));
 	echo $this->form->checkbox('rewatching', array('label' =>'Rewatching?', 'value' => false));
 	echo $this->form->submit('Save!');
 	echo $this->form->submit('Save!');
-?>
+	echo $this->form->end();
+?>

+ 4 - 0
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; ?>

+ 1 - 1
views/elements/authnav.html.php

@@ -1,7 +1,7 @@
 <nav>
 <nav>
 <ul id="nav">
 <ul id="nav">
 	<li class="current"><a href="/users/feed">Home</a></li>
 	<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>
     <ul>
       <li><a href="about.html">Top Anime</a>
       <li><a href="about.html">Top Anime</a>
       <li><a href="#">Recomendations</a></li>
       <li><a href="#">Recomendations</a></li>

+ 5 - 0
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();
+?>

+ 27 - 0
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>