Эх сурвалжийг харах

Merge branch 'master' of git.raylu.net:otakuhub

Michael Francis 14 жил өмнө
parent
commit
c9994190d2

+ 24 - 5
controllers/AnimeController.php

@@ -5,7 +5,7 @@ namespace app\controllers;
 use app\models\Anime;
 
 class AnimeController extends \lithium\action\Controller {
-	public $publicActions = array('index', 'view');
+	public $publicActions = array('index', 'view', 'cast');
 
 	public function index()
 	{
@@ -16,12 +16,31 @@ class AnimeController extends \lithium\action\Controller {
 
 	public function view($id = null)
 	{
-		if (is_numeric($id)) {
-			return Anime::search($id, null, 'special_id');
+		if (is_numeric($id))
+		{
+			$data = Anime::search($id, null, 'special_id');
+			$related = $data['anime']->related;
+			$str = '';
+			for ($i = 0; $i < count($related); $i++)
+			{
+				if ($i > 0) $str .= ', ';
+				$ra = Anime::search($related[$i], null, 'special_id');
+				$str .= '<a href="' . $related[$i] . '">' . $ra['anime']->title .  '</a>';
+			}
+			$data['related'] = $str;
+			return $data;
 		}
-		else {
+		else
+		{
 			return $this->redirect(array('controller' => 'search','q' => array('search' => $id)));
 		}
-	
+	}
+
+	public function cast($id = null)
+	{
+		if (is_numeric($id))
+		{
+			return Anime::search($id, null, 'special_id');
+		}
 	}
 }

+ 16 - 2
controllers/SearchController.php

@@ -25,8 +25,22 @@ class SearchController extends \lithium\action\Controller {
 
 	public function anime($by = 'title')
 	{
-		$q = isset($this->request->query['q']) ?  '/' . $this->request->query['q'] . '/i' : '';
+		$q = isset($this->request->query['q']) ? $this->request->query['q'] : '';
 		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
-		return Anime::search($q, $page, 'title');
+		return Anime::search("/$q/i", $page, 'title');
+	}
+
+	public function manga($by = 'title')
+	{
+		$q = isset($this->request->query['q']) ? $this->request->query['q'] : '';
+		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
+		return Manga::search("/$q/i", $page, 'title');
+	}
+
+	public function kdrama($by = 'title')
+	{
+		$q = isset($this->request->query['q']) ? $this->request->query['q'] : '';
+		$page = isset($this->request->query['page']) ? $this->request->query['page'] : 1;
+		return Kdrama::search("/$q/i", $page, 'title');
 	}
 }

+ 4 - 6
models/Kdrama.php

@@ -13,7 +13,7 @@ class Kdrama extends \lithium\data\Model {
 		switch($by) {
 			case 'special_id':
 			
-			$content = parent::find('first',
+			$kdrama = parent::find('first',
 				array('conditions' => array(
 						$by => $query
 					),
@@ -21,13 +21,11 @@ class Kdrama extends \lithium\data\Model {
 					'page' => $page
 				));
 
-
-		
 			$total = parent::count(array($by => $query)); 
 			break;
 			
 			default:
-			$content = parent::find('all',
+			$kdrama = parent::find('all',
 				array('conditions' => array(
 						$by => array('like' => $query)
 					),
@@ -36,6 +34,6 @@ class Kdrama extends \lithium\data\Model {
 				));
 				$total = parent::count(array($by => array('like' => $query)));
 	}
-	return compact('content', 'by', 'limit', 'total', 'page');
+	return compact('kdrama', 'by', 'limit', 'total', 'page');
 	}
-}
+}

+ 32 - 2
models/Manga.php

@@ -5,5 +5,35 @@ namespace app\models;
 class Manga extends \lithium\data\Model {
 	protected $_meta = array('key' => '_id', 'source' => 'manga', 'connection' => 'mongo');
 
-	
-}
+	public static function search($query, $page = 1, $by = 'title') 
+	{
+		$defaults = array('limit' => 20);
+		$limit = 20;
+
+		switch($by) {
+			case 'special_id':
+			
+			$manga = parent::find('first',
+				array('conditions' => array(
+						$by => $query
+					),
+					'limit' => $limit,
+					'page' => $page
+				));
+
+			$total = parent::count(array($by => $query)); 
+			break;
+			
+			default:
+			$manga = parent::find('all',
+				array('conditions' => array(
+						$by => array('like' => $query)
+					),
+					'limit' => $limit,
+					'page' => $page
+				));
+				$total = parent::count(array($by => array('like' => $query)));
+	}
+	return compact('manga', 'by', 'limit', 'total', 'page');
+	}
+}

+ 86 - 56
views/anime/view.html.php

@@ -1,68 +1,98 @@
-<h2 class="ribbon full"><?= $content->title ?></h2>
+<?php
+$this->styles($this->html->style('view'));
+?>
+
+<h2 class="ribbon full"><?= $anime->title ?></h2>
 <div class="triangle-ribbon"></div>
-<br class="cl" />
+<br class="cl">
 
-<div class="container_12">
-<!-- Start Sidebar -->
-<div class="grid_4" id="sidebar">
-<img src="<?=$content->image ?>" >
+<aside id="img">
+<img src="<?=$anime->image ?>" alt="<?= $anime->title ?>">
+</aside>
 
-<h2 class="ribbon"> Alternative Titles </h2>
-<hr/>
-<p>
-<?php if(isset($content->alternative_titles)) : ?>
-<?php foreach($content->alternative_titles as $title): ?>
-	<?= $title ?>
-<?php endforeach; ?>
+<section id="info"><p>
+<?php if(isset($anime->foreign_titles)):
+	$str = 'Foreign titles:';
+	for ($i = 0; $i < count($anime->foreign_titles); $i++) {
+		if ($i > 0) $str .= '<b>,</b>';
+		$str .= ' ' . $anime->foreign_titles[$i];
+	}
+	$str .= '<br>';
+	?>
+	<?= $str ?>
+<?php endif; ?>
+<?php if(isset($anime->alternative_titles)):
+	$str = 'Alternative titles:';
+	for ($i = 0; $i < count($anime->alternative_titles); $i++) {
+		if ($i > 0) $str .= '<b>,</b>';
+		$str .= ' ' . $anime->alternative_titles[$i];
+	}
+	$str .= '<br>';
+	?>
+	<?= $str ?>
 <?php endif; ?>
+Type: <?= $anime->view_type ?><br>
+Episodes: <?= $anime->episode_count ?><br>
+Aired: <?= $anime->aired ?><br>
+Producers: <?php
+$str = '';
+for ($i = 0; $i < count($anime->producers); $i++) {
+	if ($i > 0) $str .= ',';
+	$str .= ' <a href="/producer/view/' . $anime->producers[$i] . '">' . $anime->producers[$i] . '</a>';
+} ?><?= $str ?><br>
+Genres: <?php
+$str = '';
+for ($i = 0; $i < count($anime->genres); $i++) {
+	if ($i > 0) $str .= ',';
+	$str .= ' <a href="/genre/view/' . $anime->genres[$i] . '">' . $anime->genres[$i] . '</a>';
+} ?><?= $str ?><br>
+Duration: <?= $anime->episode_duration ?><br>
+Rating: <?= $anime->rated ?><br>
+Related: <?= $related ?>
 </p>
-<h2> Information </h2>
-<span> Type: <?= $content->view_type ?> </span>
-Episodes: <?= $content->episode_count ?><br/>
-Status: <?= $content->status ?><br/>
-Aired: <?= $content->aired ?><br/>
-Producers: <?php foreach($content->producers as $producer): ?>
-<a href="/producer/view/<?= $producer ?>"><?= $producer ?></a>,
-<?php endforeach; ?><br/>
-Genres: <?php foreach($content->genres as $genres): ?>
-<a href="/genres/view/<?= $genres ?>"><?= $genres ?></a>,
-<?php endforeach ?><br/>
-Duration: <?= $content->episode_duration ?><br/>
-Rating: <?= $content->rating ?><br/>
+</section>
 
-<h2 class="ribbon">Statistics</h2>
-Score: <br/>
-Ranked: <br/>
-Popularity: <br/>
-Members:<br/>
-Favorited by: over 9000 Users<br/>
-
-<h2 class="ribbon">  My Info </h2>
-<hr/>
-<!-- End Sidebar -->
-</div>
-<div class="grid_8" id="content">
-<!-- Start Content -->
-<h2>Synopsis</h2>
-<hr/>
-<?= $content->synopsis ?>
-
-<h2>Related Animes</h2>
-<hr/>
+<aside id="malstats">
+<h2>MAL Stats</h2>
+<p>
+Score: <?= $anime->mal_score ?><br>
+Votes: <?= $anime->mal_score_voted ?><br>
+Ranked: <?= $anime->mal_rank ?><br>
+Popularity: <?= $anime->mal_popularity ?><br>
+Members: <?= $anime->mal_score ?>
+</p>
+</aside>
 
-<h2>Characters And VA's </h2>
-<hr/>
-<?php foreach($content->cast as $char): ?>
-<?= $char->character ?>
-<?= $char->role ?>
-Played by:
+<section id="cast">
+<p>
+<a href="/anime/cast/<?= $anime->special_id ?>" onclick="return toggleCast()">Cast &#x2193;</a>
+</p>
+<p><table>
+<?php foreach($anime->cast as $char): ?>
+	<tr>
+		<td colspan="3">
+			<?= $char->character ?>
+		</td>
+	</tr>
 	<?php if (isset($char->people)): ?>
 		<?php foreach($char->people as $actor): ?>
-		<?= $actor->name ?>
-		<?= $actor->language ?>
+			<tr>
+				<td></td>
+				<td><?= $actor->name ?></td>
+				<td><?= $actor->language ?></td>
+			</tr>
 		<?php endforeach; ?>
 	<?php endif; ?>
 <?php endforeach; ?>
-</div>
-<br class="cl"/>
-</div>
+</table></p>
+<p id="castlink">
+<a href="" onclick="return toggleCast()">Cast &#x2191;</a>
+</p>
+</section>
+
+<br class="cl">
+
+<h2 class="ribbon">Synopsis</h2>
+<div class="triangle-ribbon"></div>
+<br class="cl">
+<p><?= $anime->synopsis ?></p>

+ 3 - 3
views/elements/animetable.html.php

@@ -6,12 +6,12 @@
 	<tr>
 		<td>
 			<a href="/anime/view/<?= $a->special_id ?>"><?= $a->title ?></a>
-			<?php if ($a->foreign_titles || $a->alternative_titles): ?>
+			<?php if (isset($a->foreign_titles) || isset($a->alternative_titles)): ?>
 				<span class="alt_titles">
-				<?php if ($a->foreign_titles): ?>
+				<?php if (isset($a->foreign_titles)): ?>
 					<?= $a->foreign_titles[0] ?>
 				<?php endif ?>
-				<?php if ($a->alternative_titles): ?>
+				<?php if (isset($a->alternative_titles)): ?>
 					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 					<?= $a->alternative_titles[0] ?>
 				<?php endif ?>

+ 29 - 0
views/elements/mangatable.html.php

@@ -0,0 +1,29 @@
+<table>
+<th>Title</th>
+<th>Date</th>
+<th style="width: 200px">Type</th>
+<?php foreach ($manga as $m): ?>
+	<tr>
+		<td>
+			<a href="/manga/view/<?= $m->special_id ?>"><?= $m->title ?></a>
+			<?php if (isset($m->foreign_titles) || isset($m->alternative_titles)): ?>
+				<span class="alt_titles">
+				<?php if (isset($m->foreign_titles)): ?>
+					<?= $m->foreign_titles[0] ?>
+				<?php endif ?>
+				<?php if (isset($m->alternative_titles)): ?>
+					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+					<?= $m->alternative_titles[0] ?>
+				<?php endif ?>
+				</span>
+			<?php endif ?>
+		</td>
+		<td>
+			<?= $m->publish_period ?>
+		</td>
+		<td>
+			<?= $m->author ?>
+		</td>
+	</tr>
+<?php endforeach ?>
+</table>

+ 2 - 2
views/layouts/default.html.php

@@ -69,9 +69,9 @@ use \lithium\security\Auth;
 
 	<br class="cl" />
 </header>
-<div id="page">
+<article>
 	<?php echo $this->content() ?>
-</div>
+</article>
 <footer>
 	<p>Copyright ©2011, <a href="http://www.melenion.org">Melenion Dev Studios</a></p>
 	<br class="cl" />

+ 16 - 14
views/search/index.html.php

@@ -5,27 +5,29 @@ $this->styles($this->html->style('search'));
 
 <?= $this->_render('element', 'search') ?>
 
+<?php if(count($anime) > 0): ?>
 <h2 class="ribbon">Anime</h2>
 <div class="triangle-ribbon"></div>
-<?= $this->_render('element', 'animetable', compact('anime')) ?>
-<p class="more">
-<a href="/search/anime/?q=<?= $q ?>">More</a>
-</p>
+	<?= $this->_render('element', 'animetable') ?>
+	<p class="more">
+	<a href="/search/anime/?q=<?= $q ?>">More</a>
+	</p>
+<?php endif ?>
 
+<?php if(count($manga) > 0): ?>
 <h2 class="ribbon">Manga</h2>
 <div class="triangle-ribbon"></div>
-<p>results</p>
-<?php if(count($manga) > 0): ?>
-<p class="more">
-<a href="/search/manga/?q=<?= $q ?>">More</a>
-</p>
+	<?= $this->_render('element', 'mangatable') ?>
+	<p class="more">
+	<a href="/search/manga/?q=<?= $q ?>">More</a>
+	</p>
 <?php endif ?>
 
+<?php if(count($kdrama) > 0): ?>
 <h2 class="ribbon">K-Drama</h2>
 <div class="triangle-ribbon"></div>
-<?= $this->_render('element', 'kdramatable', compact('anime')) ?>
-<?php if(count($kdrama) > 0): ?>
-<p class="more">
-<a href="/search/kdrama/?q=<?= $q ?>">More</a>
-</p>
+	<?= $this->_render('element', 'kdramatable') ?>
+	<p class="more">
+	<a href="/search/kdrama/?q=<?= $q ?>">More</a>
+	</p>
 <?php endif ?>

+ 16 - 0
views/search/kdrama.html.php

@@ -0,0 +1,16 @@
+<?php
+$this->styles($this->html->style('pagination'));
+$this->styles($this->html->style('table'));
+$this->styles($this->html->style('search'));
+?>
+
+<?= $this->_render('element', 'search') ?>
+
+<h2>K-Drama Search Results</h2>
+(search instead for ...)
+
+<?= $this->Paginator->paginate(array('separator' => '')) ?>
+
+<?= $this->_render('element', 'kdramatable') ?>
+
+<?= $this->Paginator->paginate(array('separator' => '')) ?>

+ 16 - 0
views/search/manga.html.php

@@ -0,0 +1,16 @@
+<?php
+$this->styles($this->html->style('pagination'));
+$this->styles($this->html->style('table'));
+$this->styles($this->html->style('search'));
+?>
+
+<?= $this->_render('element', 'search') ?>
+
+<h2>Manga Search Results</h2>
+(search instead for ...)
+
+<?= $this->Paginator->paginate(array('separator' => '')) ?>
+
+<?= $this->_render('element', 'mangatable') ?>
+
+<?= $this->Paginator->paginate(array('separator' => '')) ?>

+ 8 - 15
webroot/css/base.css

@@ -24,6 +24,8 @@ h2.ribbon {
 	border-radius: 3px 3px 3px 0px;
 	-moz-border-radius: 3px 3px 3px 0px;
 	-webkit-border-radius: 3px 3px 3px 0px;
+}
+h2.full {
 	width: 890px;
 }
 .triangle-ribbon {
@@ -146,11 +148,11 @@ footer {
 	width: 980px;
 	margin: 25px auto 20px;
 }
-#page {
+article {
 	background: #fff;
 	color: #191919;
 	border: 1px solid #d9d9d9;
-	padding: 40px;
+	padding: 25px 40px 30px;
 	position: relative;
 	width: 898px;
 	margin: 0 auto;
@@ -243,13 +245,16 @@ body.ie7 form, body.ie8 {
 form p {
 	margin-bottom:15px;
 }
-form input, form textarea {
+form input, form textarea, form select {
 	padding: 7px 5px;
 	border: 1px solid #ccc;
 	border-radius: 3px;
 	-moz-border-radius: 3px;
 	-webkit-border-radius: 3px;
 }
+form select {
+	padding: 6px 5px;
+}
 input[type="button"], input[type="submit"], button {
 	padding: 6px 5px; /* looks high in FF at inherited 7 5 */
 	line-height: 18px; /* looks small in webkit at 6 5 */
@@ -257,24 +262,12 @@ input[type="button"], input[type="submit"], button {
 	display: inline-block;
 	font-weight: 700;
 	outline: none;
-	background: #ddd;
 	color: #444;
 	text-shadow: 0 -1px 0 #eee;
 	border-radius: 3px;
 	-moz-border-radius: 3px;
 	-webkit-border-radius: 3px;
 }
-input[type="button"]:hover, input[type="submit"]:hover, button:hover {
-	background: #eee;
-}
-form select {
-	padding: 6px 5px;
-	border: 1px solid #ccc;
-	border-radius: 3px;
-	-moz-border-radius: 3px;
-	-webkit-border-radius: 3px;
-	background-color: #eee;
-}
 
 div#login {
 	text-align: center;

+ 4 - 4
webroot/css/search.css

@@ -16,13 +16,13 @@ p.more a {
 	border-radius: 3px;
 	background: #ddd;
 	background: -moz-linear-gradient(top, #ddd, #bbb);
-	background: -webkit-linear-gradient(top, rgba(255,255,255,1), rgba(255,255,255,0));
-	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffffff00', GradientType=1);
+	background: -webkit-linear-gradient(top, #ddd, #bbb);
+	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#dddddd', endColorstr='#bbbbbb');
 	color: #111;
 }
 p.more a:hover {
 	background: #eee;
 	background: -moz-linear-gradient(top, #eee, #ccc);
-	background: -webkit-linear-gradient(top, rgba(255,255,255,1), rgba(255,255,255,0));
-	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffffff00', GradientType=1);
+	background: -webkit-linear-gradient(top, #eee, #ccc);
+	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#eeeeee', endColorstr='#cccccc');
 }

+ 22 - 0
webroot/css/themes/light.css

@@ -48,6 +48,28 @@ a.gradient:hover {
 	color: #fff;
 }
 
+form input, form textarea, form select {
+	background: #f7f7f7;
+	background: -moz-linear-gradient(top, #eee, #fff);
+	background: -webkit-linear-gradient(top, #eee, #fff);
+	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#eee', endColorstr='#fff');
+}
+input[type="button"], input[type="submit"], button {
+	background: #ddd;
+	background: -moz-linear-gradient(top, #ddd, #eee);
+	background: -webkit-linear-gradient(top, #ddd, #eee);
+	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ddd', endColorstr='#eee');
+}
+form input:focus, form textarea:focus, select:focus {
+	border-color: #88c;
+}
+input[type="button"]:hover, input[type="submit"]:hover, button:hover {
+	background: #eee;
+	background: -moz-linear-gradient(top, #e0e0e0, #f7f7f7);
+	background: -webkit-linear-gradient(top, #e0e0e0, #f7f7f7);
+	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#e0e0e0', endColorstr='#f7f7f7');
+}
+
 footer {
 	color: #666;
 }

+ 48 - 0
webroot/css/view.css

@@ -0,0 +1,48 @@
+/* for viewing individual anime/manga/kdrama, rather than table.css */
+
+aside#img {
+	float: left;
+	margin: 0 25px 25px 0;
+	width: 225px;
+}
+
+section#info {
+	float: left;
+	width: 470px;
+}
+
+section#cast {
+	float: left;
+	width: 620px;
+}
+section#cast p {
+	margin: 0;
+}
+section#cast table {
+	table-layout: fixed;
+	display: none;
+}
+section#cast td {
+	padding: 3px;
+}
+section#cast td:nth-child(1) {
+	width: 60px;
+}
+section#cast td:nth-child(2) {
+	width: 250px;
+}
+section#cast td:nth-child(3) {
+	width: 200px;
+}
+section#cast #castlink {
+	display: none;
+}
+
+aside#malstats {
+	float: right;
+	width: 150px;
+}
+
+p {
+	text-indent: 0;
+}

+ 16 - 2
webroot/js/functions.js

@@ -10,8 +10,22 @@ jQuery(document).ready(function($) {
 	$('form [title]').tipsy({fade: true, trigger: 'focus', gravity: 'w'});
 
 	setTimeout(function() {
-		$(".flash-message").fadeOut("slow", function () {
-			$(".flash-message").remove();
+		$('.flash-message').fadeOut('slow', function () {
+			$('.flash-message').remove();
 		});
 	}, 2000);
 });
+
+function toggleCast() {
+	var table = $('#cast table');
+	if (table.css('display') == 'inline') {
+		table.css('display', 'none');
+		$('#cast > p > a').text('Cast ↓');
+		$('#castlink').css('display', 'none');
+	} else {
+		table.css('display', 'inline');
+		$('#cast > p > a').text('Cast ↑');
+		$('#castlink').css('display', 'inline');
+	}
+	return false;
+}