art-web r548 - in branches/art-hub: controllers models views
- From: thos svn gnome org
- To: svn-commits-list gnome org
- Subject: art-web r548 - in branches/art-hub: controllers models views
- Date: Sun, 7 Sep 2008 00:03:03 +0000 (UTC)
Author: thos
Date: Sun Sep 7 00:03:03 2008
New Revision: 548
URL: http://svn.gnome.org/viewvc/art-web?rev=548&view=rev
Log:
* Implement theme and background search
Modified:
branches/art-hub/controllers/backgrounds.php
branches/art-hub/controllers/themes.php
branches/art-hub/models/art.php
branches/art-hub/models/backgrounds.php
branches/art-hub/models/themes.php
branches/art-hub/views/backgrounds.php
branches/art-hub/views/themes.php
Modified: branches/art-hub/controllers/backgrounds.php
==============================================================================
--- branches/art-hub/controllers/backgrounds.php (original)
+++ branches/art-hub/controllers/backgrounds.php Sun Sep 7 00:03:03 2008
@@ -7,7 +7,7 @@
$bg = new BackgroundsModel();
-preg_match ('/^\/backgrounds\/(abstract|gnome|nature|other)\/?$/', $_SERVER['PHP_SELF'], $params);
+preg_match ('/^\/backgrounds\/(abstract|gnome|nature|other|search)\/?$/', $_SERVER['PHP_SELF'], $params);
$category = $params[1];
$page = $_GET['page'];
@@ -21,7 +21,20 @@
$start = ($page - 1) * $limit;
if ($category)
- $view_data = $bg->get_items ($category, $start, $limit, "name");
+ if ($category == "search")
+ {
+ $search = mysql_escape_string ($_GET['text']);
+ $search = "background.name LIKE '%".$search."%'";
+ $search_text = htmlspecialchars ($_GET['text']);
+
+ $view_data = $bg->search_items ($search, $start, $limit, "name");
+ $total_backgrounds = $bg->search_total ($search);
+ }
+ else
+ {
+ $view_data = $bg->get_items ($category, $start, $limit, "name");
+ $total_backgrounds = $bg->get_total ($category);
+ }
else
$view_data = null;
@@ -34,8 +47,6 @@
}
}
-$total_backgrounds = $bg->get_total ($category);
-
/* load view */
require ("views/backgrounds.php");
Modified: branches/art-hub/controllers/themes.php
==============================================================================
--- branches/art-hub/controllers/themes.php (original)
+++ branches/art-hub/controllers/themes.php Sun Sep 7 00:03:03 2008
@@ -7,7 +7,7 @@
$themes = new ThemesModel();
-preg_match ('/^\/themes\/(gtk2|metacity|icon|gdm_greeter|splash_screens|gtk_engines)\/?$/',
+preg_match ('/^\/themes\/(gtk2|metacity|icon|gdm_greeter|splash_screens|gtk_engines|search)\/?$/',
$_SERVER['PHP_SELF'], $params);
$category = $params[1];
@@ -22,11 +22,23 @@
$start = ($page - 1) * $limit;
if ($category)
- $view_data = $themes->get_items ($category, $start, $limit, "name");
+ if ($category == 'search')
+ {
+ $search = mysql_escape_string ($_GET['text']);
+ $search = "theme.name LIKE '%".$search."%'";
+ $search_text = htmlspecialchars ($_GET['text']);
+
+ $view_data = $themes->search_items ($search, $start, $limit, "name");
+ $total_themes = $themes->search_total ($search);
+ }
+ else
+ {
+ $view_data = $themes->get_items ($category, $start, $limit, "name");
+ $total_themes = $themes->get_total ($category);
+ }
else
$view_data = null;
-$total_themes = $themes->get_total ($category);
/* load view */
require ("views/themes.php");
Modified: branches/art-hub/models/art.php
==============================================================================
--- branches/art-hub/models/art.php (original)
+++ branches/art-hub/models/art.php Sun Sep 7 00:03:03 2008
@@ -6,6 +6,43 @@
var $get_items_sql = '';
var $get_total_sql = '';
+ function search_items ($search, $start, $length, $order)
+ {
+ /* check that start and length values are numeric */
+ if (!is_numeric ($start) || !is_numeric ($length))
+ return;
+
+ $sql = sprintf ($this->search_items_sql, $search, $order, $start, $length);
+
+ if ($sql === '')
+ return;
+
+ $bg_select_result = mysql_query ($sql);
+ if (!$bg_select_result)
+ printf ("Database error: %s", mysql_error());
+
+ $table = Array ();
+ while ($row = mysql_fetch_assoc ($bg_select_result))
+ {
+ $table[] = $row;
+ }
+
+ return $table;
+ }
+
+ function search_total ($search)
+ {
+ $sql = sprintf ($this->search_total_sql, $search);
+ $r = mysql_query ($sql);
+ if (!$r)
+ printf ("Database error: %s", mysql_error());
+
+
+ $total = mysql_fetch_row ($r);
+
+ return $total[0];
+ }
+
function get_items ($category, $start, $length, $order)
{
/* check that start and length values are numeric */
Modified: branches/art-hub/models/backgrounds.php
==============================================================================
--- branches/art-hub/models/backgrounds.php (original)
+++ branches/art-hub/models/backgrounds.php Sun Sep 7 00:03:03 2008
@@ -11,6 +11,15 @@
var $get_total_sql = "SELECT COUNT(name) FROM background
WHERE category = '%s' AND status='active'";
+ var $search_items_sql = "SELECT * FROM background,user
+ WHERE status='active'
+ AND background.userID = user.userID
+ AND (%s)
+ ORDER BY %s LIMIT %s,%s";
+
+ var $search_total_sql = "SELECT COUNT(*) FROM background
+ WHERE status='active' AND (%s)";
+
function get_resolutions ($backgroundID)
{
if (!is_numeric ($backgroundID))
Modified: branches/art-hub/models/themes.php
==============================================================================
--- branches/art-hub/models/themes.php (original)
+++ branches/art-hub/models/themes.php Sun Sep 7 00:03:03 2008
@@ -10,6 +10,14 @@
var $get_total_sql = "SELECT COUNT(name) FROM theme
WHERE category = '%s' AND status='active'";
+
+ var $search_items_sql = "SELECT * FROM theme,user
+ WHERE status='active' AND (%s)
+ AND theme.userID = user.userID
+ ORDER BY %s LIMIT %s,%s";
+
+ var $search_total_sql = "SELECT COUNT(name) FROM theme
+ WHERE (%s) AND status='active'";
}
?>
Modified: branches/art-hub/views/backgrounds.php
==============================================================================
--- branches/art-hub/views/backgrounds.php (original)
+++ branches/art-hub/views/backgrounds.php Sun Sep 7 00:03:03 2008
@@ -21,6 +21,13 @@
<li><a href="/backgrounds/abstract">Abstract</a></li>
<li><a href="/backgrounds/other">Other</a></li>
</ul>
+ Search for backgrounds:
+ <?php if ($total_backgrounds < 1 && $search_text) echo "<p>No search results for "$search_text"</p>" ?>
+ <ul>
+ <form method="get" action="/backgrounds/search">
+ <input name="text" type="text" value="<?php echo $search_text?>"><input type="submit" value="Search">
+ </form>
+ </ul>
<?php
$t->print_footer ();
exit (0);
@@ -35,6 +42,8 @@
if ($category == "gnome")
$d_category = "GNOME";
+elseif ($category == 'search')
+ $d_category = 'Search Results';
else
$d_category = ucwords ($category);
Modified: branches/art-hub/views/themes.php
==============================================================================
--- branches/art-hub/views/themes.php (original)
+++ branches/art-hub/views/themes.php Sun Sep 7 00:03:03 2008
@@ -22,6 +22,13 @@
<li><a href="/themes/splash_screens">Splash Screens</a></li>
<li><a href="/themes/gdm_greeter">Login Window</a></li>
</ul>
+ Search for themes:
+ <?php if ($total_themes < 1 && $search_text) echo "<p>No search results for "$search_text"</p>" ?>
+ <ul>
+ <form method="get" action="/themes/search">
+ <input name="text" type="text" value="<?php echo $search_text?>"><input type="submit" value="Search">
+ </form>
+ </ul>
<?php
$t->print_footer ();
exit (0);
@@ -42,7 +49,10 @@
"splash_screens" => "Splash Screens"
);
- $d_category = $display_cat [$category];
+ if ($category == 'search')
+ $d_category = 'Search Results';
+ else
+ $d_category = $display_cat [$category];
?>
<a href="/">GNOME Art</a> > <a href="/themes">Themes</a>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]