Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    NTT
    NTT is offline
    New Coder
    Join Date
    Jul 2006
    Posts
    13
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Exclamation Cut & Paste JSE internal seach engine v 1.0a

    Yeah, it's that internal search engine script again. But before you click away, I'd like to ask whether anyone can solve a problem I've come up against...

    I have minimally changed the script to present results with a clickable url (this is my attempt at creating an image search engine, hence having to use this method).

    The problem I have suddenly encountered however is that the urls, while they read complete, they only link one directory deep into my website. For example:

    Reads as:
    http://www.mysite.com/search/set1/doctor.jpg
    Link is:
    http://www.mysite.com/search


    As you will see, I've omitted using the numbering array and have rearranged the order in which the values for how the search results are called.

    Code:
    if (include_num == 1) {
    document.write(a + 1, '. <a href="', os[0], '">', os[1], '</a><br>', os[2], '<p>');
    } else {
    document.write('<a href="', os[0], '">', os[1], '</a><br>', os[2], '<p>');
    }
    It is with this second point that I fear I have caused the damage.


    Code:
    // ---------- script properties ----------
    
    var include_num = 0;
    var bold = 1;
    
    // ---------- sites ----------
    
    
    var s = new Array();
    
    s[0] = "^this will be added soon/form.html^Click to view image^";
    s[0] = "^this will be added soon/doc.txt^Click to view image^";
    s[0] = "^http://mysite.net/archive/Gliding/folderthumb.jpg^Click to view image^";
    s[0] = "^this will be added soon/doctor.txt^^";
    
    // ---------- end of script properties and sites ----------
    
    
    var cookies = document.cookie;
    var p = cookies.indexOf("d=");
    
    if (p != -1) {
    	var st = p + 2;
    	var en = cookies.indexOf(";", st);
    	if (en == -1) {
    		en = cookies.length;
    	}
    	var d = cookies.substring(st, en);
    	d = unescape(d);
    }
    var od = d;
    var m = 0;
    if (d.charAt(0) == '"' && d.charAt(d.length - 1) == '"') {
    	m = 1;
    }
    
    var r = new Array();
    var co = 0;
    
    if (m == 0) {
    	var woin = new Array();
    	var w = d.split(" ");
    	for (var a = 0; a < w.length; a++) {
    		woin[a] = 0;
    		if (w[a].charAt(0) == '-') {
    			woin[a] = 1;
    		}
    	}
    	for (var a = 0; a < w.length; a++) {
    		w[a] = w[a].replace(/^\-|^\+/gi, "");
    	}
    	a = 0;
    	for (var c = 0; c < s.length; c++) {
    		pa = 0;
    		nh = 0;
    		for (var i = 0; i < woin.length; i++) {
    			if (woin[i] == 0) {
    				nh++;
    				var pat = new RegExp(w[i], "i");
    				var rn = s[c].search(pat);
    				if (rn >= 0) {
    					pa++;
    				} else {
    					pa = 0;
    				}
    			}
    			if (woin[i] == 1) {
    				var pat = new RegExp(w[i], "i");
    				var rn = s[c].search(pat);
    				if (rn >= 0) {
    					pa = 0;
    				}
    			}
    		}
    		if (pa == nh) {
    			r[a] = s[c];
    			a++;
    		}
    	}
    	co = a;
    }
    
    if (m == 1) {
    	d = d.replace(/"/gi, "");
    	var a = 0;
    	var pat = new RegExp(d, "i");
    	for (var c = 0; c < s.length; c++) {
    		var rn = s[c].search(pat);
    		if (rn >= 0) {
    			r[a] = s[c];
    			a++;
    		}
    	}
    	co = a;
    
    }
    
    
    function return_query() {
    	document.jse_Form.d.value = od;
    }
    
    function num_jse() {
    	document.write(co);
    }
    
    function out_jse() {
    	if (co == 0) {
    		document.write('Your search did not match any images currently on file.<p>Make sure all keywords are spelt correctly.<br>Alternatively, view the Unknown Section of the Archive and help us put a name and date to your memories.');
    		return;
    	}
    	for (var a = 0; a < r.length; a++) {
    		var os = r[a].split("^");
    		if (bold == 1 && m == 1) {
    			var br = "<b>" + d + "</b>";
    			os[2] = os[2].replace(pat, br);
    		}
    		if (include_num == 1) {
    			document.write(a + 1, '. <a href="', os[0], '">', os[1], '</a><br>', os[2], '<p>');
    		} else {
    			document.write('<a href="', os[0], '">', os[1], '</a><br>', os[2], '<p>');
    		}
    	}
    
    }
    Because of the nature of the site (it will have over 600 images eventually), my level of understanding and the obviously limitations with this script, I'm looking for a solution that doesn't require a different edit for each entry.

    So far I have been able to simply drop a block of urls into this script (having planted a .php script to get the image directory listing) and then 'replace all' text that needs to be edited.

    In short, how do I ensure that the hyperlink for the url that is returned in the search query is full and not truncated to the first directory?


    ANY help in the matter would be really appreciated.

    Thank you in advance,


    Sam
    Last edited by VIPStephan; 12-16-2011 at 01:48 PM. Reason: replaced [quote] tags with [code] tags

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    Not to ask a really dumb question, but...

    Given that you "planted a .php script to get the image directory listing" why are you doing this, at all, in JavaScript instead of in PHP? Surely it would be just as easy to do the search in PHP and if you need to use PHP to get the list of images, why not then do it all in PHP?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    And this part of the code makes no sense at all:
    Code:
    var s = new Array();
    
    s[0] = "^this will be added soon/form.html^Click to view image^";
    s[0] = "^this will be added soon/doc.txt^Click to view image^";
    s[0] = "^http://45farchives.net16.net/archive/Gliding/folderthumb.jpg^Click to view image^";
    s[0] = "^this will be added soon/doctor.txt^^";
    Since you are assigning *ALL* those strings to s[0] that means that only the last assignment matters. The lines in red are an utter waste of code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,635 Times in 4,597 Posts
    In any case, your code is nearly impossible to follow because you use meaningless variable names. d. c. s. and so on. Heck, I'm not even sure where the list of names and/or the search term comes from.

    You have code that does
    Code:
        var rn = s[c].search(pat);
    but given that you only define s[0] and given that it contains only "^this will be added soon/doctor.txt^^" I don't see how you are searching for anything meaningful.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    NTT (12-16-2011)

  • #5
    NTT
    NTT is offline
    New Coder
    Join Date
    Jul 2006
    Posts
    13
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Clarrification on issue

    Hi Old Pedant

    Thank you for your reply. I know the whole thing is a mess, and in hindsight, after 8 hours of trying all combinations I think you get how I was feeling by that point

    I have since found a partial solution to my problem but again with issues that I still need help on. I know my initial request of help with this script appeared odd considering that I had managed to use .php to index a directory, but I copied that script from a site, and I have very little knowledge on how to manipulate it. I would of course use php to do what I originally asked, but again my knowledge is nowehere good enough.

    Since last posting I have tweaked the php script as best I can to search my directory and produce the following:

    Code:
    s[1] = /home/a2100544/public_html/archive/Gliding/folderthumb.jpg 
    s[2] = /home/a2100544/public_html/archive/Gliding/album.rss 
    s[3] = /home/a2100544/public_html/archive/Gliding/index.html 
    s[1] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5280030.JPG 
    s[2] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5270005.JPG 
    s[3] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5280033.JPG 
    s[4] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5280024.JPG 
    s[5] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5270012.JPG 
    s[6] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5280031.JPG 
    s[7] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/folderthumb.jpg 
    s[8] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5280020.JPG 
    s[9] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5270014.JPG 
    s[10] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5280022.JPG 
    s[11] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5280025.JPG 
    s[12] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5280023.JPG 
    s[13] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5270010.JPG 
    s[14] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/album.rss 
    s[15] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5280019.JPG 
    s[16] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5280018.JPG 
    s[17] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/index.html 
    s[18] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5270013.JPG 
    s[19] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5280021.JPG 
    s[20] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/P5280029.JPG 
    s[1] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/hi-res/P5280030.JPG 
    s[2] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/hi-res/P5270005.JPG 
    s[3] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/hi-res/P5280033.JPG 
    s[4] = /home/a2100544/public_html/archive/Gliding/RAF Kenley - October 2005/hi-res/P5280024.JPG
    The problem is that I cannot make it index just .jpg and .JPG files. Plus, it starts at s[1] again when in a new subdirectory.

    The format, as I'm sure you have realised is to fit into the Javascript search engine. But if you think I can do the same thing with php (I'm assuming you mean create a search engine only for image files) then I would very much like to hear from you.

    The php script I have been playing with is as follows:

    PHP Code:
    <?php 
    function listDirectory($path)
    {    
    $handle = @opendir($path);     while (false !== ($file readdir($handle))) 
    {        if (
    $file == '.' || $file == '..') continue;         
    if ( 
    is_dir("$path/$file")) 
    {
    ?>
    <?php
             listDirectory
    ("$path/$file");?>
    <br>
    <?php    } else {   echo "s[" . ++$x "] = ";    echo "$path/$file\n";?>
    <br>
    <?php        }    }     closedir($handle);} listDirectory("/home/a2100544/public_html/archive");
    ?>
    I do realise that most likely puts work onto you, but I wouldn't be asking if I didn't think it was wholly worth while. This whole thing is for my Squadron: http://45f.co.uk I want to keep the memory alive for all the old Cadets by making the history and hundreds of photos we have available.

    Thank you in advance,

    Sam
    Last edited by VIPStephan; 12-16-2011 at 01:49 PM.

  • #6
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,919
    Thanks
    6
    Thanked 1,040 Times in 1,013 Posts
    NTT, unrelated to the subject of the thread: there is a difference between a quote and code. If you want to post code then click the small ‘#’ button or the PHP button in the reply window (or write the tags manually).


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •