logIt Log Around The Clock

MicroBlogger Add Search Feature (1)

This is mainly about view of custom search page (not about searching itself).

Adding “Search” To Main Link Tabs

Changes to file under

/app/omb/plugins/
  1. wp.php
  2. security.php

In wp.php:

Adding

$links['Search'] = $request->url_for('search');

between ‘Personal’ and ‘Profile’ would bring out the ‘Search’ tab in main link-tabs.

In security.php

Adding

function security_init() {
...
$request->connect( 'search' );
...

would give the URI link if tab is clicked or hovered, that is: http://base_url/?search.

Adding the search function would make the URI seek for the correlated viewing page

1
2
3
4
function search( $vars ) {
extract( $vars );
$_SESSION['requested_url'] = $request->base;
}

I create a viewing page then, under /app/omb/view/ by the name _search.html.

However, the main theme won’t appear correctly. So, what I do is: add a controller in /app/omb/controller/ with the name search_posts.php (an empty one for a start) and its view with the name _search_posts.html (inside /app/omb/view/). And then, add rendering to our previous search-function as in

1
2
3
4
5
function search( $vars ) {
extract( $vars );
$_SESSION['requested_url'] = $request->base;
render( 'action', '<strong>search_posts</strong>' );
}

As I’ll be incorporating databases issue later. The following search is adequate to show relevant results, plain with no links etc. It is the content of the current _search_posts.html.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php if (environment('authentication') == 'password') : ?>
 
<table cellpadding="0" cellspacing="0" border="0" width="770" align="center" style="margin-top: 30px;">
<tr>
  <td class="content">
<!-  <form name="search" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
  <form name="search" action="<?php url_for('search_posts'); ?>" method="post">
 
    <table cellpadding="5" cellspacing="0" border="0" align="center" width="500">
    <tr>
      <td height="40" align="center" colspan="2">Please enter search</td>
    </tr>
    <tr>
      <td height="10" colspan="2"></td>
    </tr>
    <tr>
      <td width="170" height="30" align="right">Search:</td>
      <td><input type="text" maxlength="30" name="search_" value="" style="width: 180px;" /></td>
    </tr>
    <tr height="30">
      <td>&nbsp;</td>
      <td><input type="submit" name="submit" value="Submit" style="width: 180px; font-size: 10px; text-transform: uppercase; color: #003366; border: 1px solid #336699; background-color: #DDDDDD; padding: 3px;" /></td>
    </tr>
    <tr>
      <td height="10" colspan="2"></td>
    </tr>
    </table>
  </form>
  </td>
</tr>
</table>
 
 
 
 
<?php endif; ?>
 
<?php if (isset($_POST['submit'])) : ?>
 
 
<?php
   $link1 = @mysql_connect("localhost","db_name","db_password")
                 or die("Could not connect to MySQL Server!");
 
   @mysql_select_db("omb_db")
                 or die("Could not select database!");
 
	$search_ = $_POST['search_'];
	$query = "SELECT `title` , `id` FROM `posts` WHERE `title` LIKE '%$search_%'";
	$result = mysql_query($query);
?>
 
  <?php while (list($title, $id_) = mysql_fetch_row($result)	) : ?>
	<br />
	<br />
	<br />
	<a href="<?php url_for(array('resource'=>'posts', 'id'=>$id_)); ?>"><?php print $title ?></a>;
	<br />
	<br />
	<br />
  <?php endwhile; ?>
<?php  mysql_close(); ?>
 
 
<?php endif; ?>

Leave a Reply