4images Modifications / Modifikationen > Mods & Plugins (Releases & Support)

[MOD] Search between specifyed date

(1/9) > >>

V@no:
Reqested several times mod, that will let visitors search between date they select. (uses dropdown options for day, month, year)


-------- Files to edit ------------
/search.php
/templates/<yourtemplate>/search_form.html
/lang/<yourlanguage>/main.php


-------- Installation -------------

Step 1.
Open /search.php
Find:
--- Code: ---include(ROOT_PATH.'includes/search_utils.php');
--- End code ---
Add after:
--- Code: ---$year_default = 2000;
$year_now = date("Y", time());
$year_start = (isset($HTTP_POST_VARS['year_start']) ) ? intval($HTTP_POST_VARS['year_start']) : ((isset($HTTP_GET_VARS['year_start'])) ? intval($HTTP_GET_VARS['year_start']) : $year_default);
$year_end = (isset($HTTP_POST_VARS['year_end']) ) ? intval($HTTP_POST_VARS['year_end']) : ((isset($HTTP_GET_VARS['year_end'])) ? intval($HTTP_GET_VARS['year_end']) : $year_now);
$month_start = (isset($HTTP_POST_VARS['month_start']) ) ? intval($HTTP_POST_VARS['month_start']) : ((isset($HTTP_GET_VARS['month_start'])) ? intval($HTTP_GET_VARS['month_start']) : 1);
$month_end = (isset($HTTP_POST_VARS['month_end']) ) ? intval($HTTP_POST_VARS['month_end']) : ((isset($HTTP_GET_VARS['month_end'])) ? intval($HTTP_GET_VARS['month_end']) : date("n", time()));
$day_start = (isset($HTTP_POST_VARS['day_start']) ) ? intval($HTTP_POST_VARS['day_start']) : ((isset($HTTP_GET_VARS['day_start'])) ? intval($HTTP_GET_VARS['day_start']) : 1);
$day_end = (isset($HTTP_POST_VARS['day_end']) ) ? intval($HTTP_POST_VARS['day_end']) : ((isset($HTTP_GET_VARS['day_end'])) ? intval($HTTP_GET_VARS['day_end']) : date("j", time()));
$date_start = mktime(0,0,0,$month_start,$day_start,$year_start);
$date_end = mktime(23,59,59,$month_end,$day_end,$year_end);
--- End code ---

Step 1.2.
Find:
--- Code: ---      $sql = "SELECT m.image_id
              FROM ".WORDLIST_TABLE." w, ".WORDMATCH_TABLE." m
              WHERE w.word_text LIKE '".addslashes(str_replace("*", "%", $split_words[$i]))."'
              AND m.word_id = w.word_id
              $match_field_sql";
--- End code ---
Replace with:
--- Code: ---      $sql = "SELECT m.image_id, i.image_date
              FROM ".WORDLIST_TABLE." w, ".WORDMATCH_TABLE." m
              LEFT JOIN ".IMAGES_TABLE." i ON (m.image_id = i.image_id)
              WHERE w.word_text LIKE '".addslashes(str_replace("*", "%", $split_words[$i]))."'
              AND m.word_id = w.word_id AND i.image_date >= ".$date_start." AND i.image_date <= ".$date_end."
              $match_field_sql";
--- End code ---

Step 1.3.
Find:
--- Code: ---  $site_template->register_vars(array(
    "search_keywords" => htmlspecialchars(stripslashes($org_search_keywords)),
--- End code ---
Replace with:
--- Code: ---  function date_select($start, $end, $now, $text_array = ""){
    $options = "";
    $start = ($start) ? $start : $start + 1;
    for ($i = $start; $i <= $end; $i++){
      $select = ($i == $now) ? " selected" : "";
      $options .= "<option value=\"".$i."\"".$select.">".(($text_array) ? $text_array[$i - 1] : $i)."</option>";
    }
    return $options;
  }

  $site_template->register_vars(array(
    "search_keywords" => stripslashes($org_search_keywords),
    "year_start" => date_select($year_default, $year_now, $year_start),
    "year_end" => date_select($year_default, $year_now, $year_end),
    "month_start" => date_select(1, 12, $month_start, $lang['month_array']),
    "month_end" => date_select(1, 12, $month_end, $lang['month_array']),
    "day_start" => date_select(1, 31, $day_start),
    "day_end" => date_select(1, 31, $day_end),
    "lang_search_date" => $lang['search_date'],
    "lang_search_date_start" => $lang['search_start'],
    "lang_search_date_end" => $lang['search_end'],
--- End code ---


Step 2.
Open /templates/<yourtemplate>/search_form.html
Add this:
--- Code: --- <tr class="row2">
<td><b>{lang_search_date}:</b></td>
<td>
{lang_search_date_start}<br />
<select name="day_start" class="select">{day_start}</select>
<select name="month_start" class="select">{month_start}</select>
<select name="year_start" class="select">{year_start}</select><br /><br />
{lang_search_date_end}<br />
<select name="day_end" class="select">{day_end}</select>
<select name="month_end" class="select">{month_end}</select>
<select name="year_end" class="select">{year_end}</select>
</td>
</tr>
--- End code ---


Step 3.
Open /lang/<yourlanguage>/main.php
Add at the end, just before closing ?>
--- Code: ---$lang['month_array'] = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$lang['search_date'] = "Search between";
$lang['search_start'] = "Start";
$lang['search_end'] = "End";
--- End code ---


NOTE:
- If u dont want display name for each month instead of number (1 to 12), then just comment $lang['month_array'] in Step 3.
- U can change minimum year in dropdown: $year_default = 2000; from Step 1.

P.S. I know, design and text - sux, and would really appretiate it if somebody help me with that ;) :D

Bomba:
hey v@no this is awesome :)
just what i needed

but i think there's some prob on it cause i went to your demo and tryed to do a search and no results were found, and i've tried many dates

is it me?

V@no:
what were u searching?

Bomba:
well i wanted to see all images that were submitted in a specified period of time, isn't that what this can do? or does this only search all images with specified keywords in the mentioned period?

if so, how can i put this working like the 1st way?
thanks

V@no:

--- Quote from: Bomba ---well i wanted to see all images that were submitted in a specified period of time, isn't that what this can do? or does this only search all images with specified keywords in the mentioned period?

if so, how can i put this working like the 1st way?
thanks
--- End quote ---
maybe I should have name it as "limit images by date" or something...
yes, it will search from keywords, but limit it by date.
use * to search all images (add as many * as set max keyword lenght)

Navigation

[0] Message Index

[#] Next page

Go to full version