Permalink
Browse files

Add favorite loadouts.

  • Loading branch information...
1 parent 3958273 commit 017a0e7030ec68707ca9204b17d80662a525fe3f @Artefact2 Artefact2 committed Jun 9, 2012
View
@@ -9,6 +9,7 @@ RewriteRule ^/?new$ src/new_fitting.php [L,QSA]
RewriteRule ^/?loadout/([1-9][0-9]*)$ src/view_fit.php?loadoutid=$1 [L,QSA]
RewriteRule ^/?edit/([1-9][0-9]*)$ src/edit_fit.php?loadoutid=$1 [L,QSA]
RewriteRule ^/?delete/([1-9][0-9]*)$ src/delete_fit.php?loadoutid=$1 [L,QSA]
+RewriteRule ^/?favorite/([1-9][0-9]*)$ src/toggle_favorite.php?loadoutid=$1 [L,QSA]
RewriteRule ^/?search$ src/search.php [L,QSA]
RewriteRule ^/?import$ src/import_loadouts.php [L,QSA]
View
@@ -87,7 +87,7 @@ function return_json($data, $flags = 0) {
die(json_encode($data, $flags));
}
-function print_loadout_title($name, $viewpermission, $visibility, $author, $relative = '.') {
+function print_loadout_title($name, $viewpermission, $visibility, $author, $relative = '.', $loadoutid = null) {
$pic = '';
if($viewpermission == \Osmium\Fit\VIEW_PASSWORD_PROTECTED) {
$pic = "<img src='$relative/static/icons/private.png' alt='(password-protected)' title='Password-protected fit' />";
@@ -103,6 +103,22 @@ function print_loadout_title($name, $viewpermission, $visibility, $author, $rela
if($visibility == \Osmium\Fit\VISIBILITY_PRIVATE) {
$pic .= "<img src='$relative/static/icons/hidden.png' alt='(hidden)' title='This loadout will never appear on search results, and will never be indexed by search engines.' />";
}
+
+ if($loadoutid !== null && ($a = \Osmium\State\get_state('a', null)) !== null) {
+ $fav = \Osmium\Db\fetch_row(\Osmium\Db\query_params('SELECT loadoutid FROM osmium.accountfavorites WHERE accountid = $1 AND loadoutid = $2', array($a['accountid'], $loadoutid)));
+ $fav = ($fav !== false);
+
+ if($fav) {
+ $title = 'On of your favorite loadouts; click to un-favorite';
+ $favimg = '';
+ } else {
+ $title = 'Add to your favorite loadouts';
+ $favimg = '_ds';
+ }
+
+ $tok = \Osmium\State\get_token();
+ $pic .= "<a href='$relative/favorite/$loadoutid?tok=$tok' title='$title'><img src='$relative/static/icons/favorited$favimg.png' alt='Favorite status' /></a>";
+ }
echo "<span class='fitname'>".htmlentities($name).$pic."</span>";
}
View
Binary file not shown.
View
@@ -34,6 +34,7 @@
$loadoutid = $_GET['loadoutid'];
\Osmium\Db\query('BEGIN;');
+\Osmium\Db\query_params('DELETE FROM osmium.accountfavorites WHERE loadoutid = $1', array($loadoutid));
\Osmium\Db\query_params('DELETE FROM osmium.loadouthistory WHERE loadoutid = $1', array($loadoutid));
\Osmium\Db\query_params('DELETE FROM osmium.loadouts WHERE loadoutid = $1', array($loadoutid));
\Osmium\Db\query('COMMIT;');
View
@@ -0,0 +1,52 @@
+<?php
+/* Osmium
+ * Copyright (C) 2012 Romain "Artefact2" Dalmaso <artefact2@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Osmium\ToggleFavorite;
+
+require __DIR__.'/../inc/root.php';
+
+if(!\Osmium\State\is_logged_in()) {
+ \Osmium\fatal(403, 'Not logged in.');
+}
+
+$loadoutid = intval($_GET['loadoutid']);
+
+if(!isset($_GET['tok']) || $_GET['tok'] != \Osmium\State\get_token()) {
+ \Osmium\fatal(403, 'Invalid token.');
+}
+
+$accountid = \Osmium\State\get_state('a')['accountid'];
+
+$row = \Osmium\Db\fetch_row(\Osmium\Db\query_params('SELECT loadoutid FROM osmium.allowedloadoutsbyaccount WHERE accountid = $1 AND loadoutid = $2', array($accountid, $loadoutid)));
+
+if($row === false) {
+ \Osmium\fatal(404, 'No such loadout.');
+}
+
+$fav = \Osmium\Db\fetch_row(\Osmium\Db\query_params('SELECT loadoutid FROM osmium.accountfavorites WHERE accountid = $1 AND loadoutid = $2', array($accountid, $loadoutid)));
+
+if($fav === false) {
+ \Osmium\Db\query_params('INSERT INTO osmium.accountfavorites (accountid, loadoutid) VALUES ($1, $2)',
+ array($accountid, $loadoutid));
+} else {
+ \Osmium\Db\query_params('DELETE FROM osmium.accountfavorites WHERE accountid = $1 AND loadoutid = $2',
+ array($accountid, $loadoutid));
+}
+
+header('Location: ../loadout/'.$loadoutid);
+die();
View
@@ -158,7 +158,7 @@
echo "<img src='http://image.eveonline.com/Render/".$fit['ship']['typeid']."_256.png' alt='".$fit['ship']['typename']."' id='fittypepic' />\n";
echo "<h2>".$fit['ship']['typename']." loadout</h2>\n";
echo "<h1 id='fitname' class='has_spinner'>";
-echo \Osmium\Chrome\print_loadout_title($fit['metadata']['name'], $fit['metadata']['view_permission'], $fit['metadata']['visibility'], $author, '..');
+echo \Osmium\Chrome\print_loadout_title($fit['metadata']['name'], $fit['metadata']['view_permission'], $fit['metadata']['visibility'], $author, '..', $fit['metadata']['loadoutid']);
echo "<img src='../static/icons/spinner.gif' id='vloadoutbox_spinner' class='spinner' alt='' /></h1>\n";
echo "<div id='fittags'>\n<h2>Tags:</h2>\n";
if(count($fit['metadata']['tags']) > 0) {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 017a0e7

Please sign in to comment.