Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 01:24:00 PM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155538 Posts in 21712 Topics by 7737 Members
Latest Member: deanmacullam
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Search DirList filenames  (Read 300 times)
danville

Offline Offline

Posts: 6


« on: November 25, 2010, 11:30:59 AM »

I need to make a DirList directory FILENAMES searchable.
How can I include this in the WEBSITE BAKER search path?
Logged
CaptainRob

Offline Offline

Posts: 28



« Reply #1 on: April 03, 2012, 12:45:04 PM »

I have the same question, but I think I have a (partly) solution for it, but I need some help with coding.

I think the solution is:

  • Add in the DirList page a WYSIWYG section
  • Add a code section
  • Place in code section:

    If ($handle = opendir('../../media/blabla')) {
        while (false !== ($entry = readdir($handle))) {
            if ($entry != "." && $entry != "..") {
                echo "$entry\n";
            }
        }
        closedir($handle);
    }

From here I need some help to put the output (echo) in the database of the above created WYSIWYG module.
To prevent that you see the directory twice:
Make the whole output invisible with for example <span style="font-size: 0px;">.

I think on this way the DirList directory is seachable.

Thanks,
Rob

Logged
CaptainRob

Offline Offline

Posts: 28



« Reply #2 on: April 16, 2012, 10:38:40 AM »

Maybe someone can help me?

I have now this code:

Code:
// get data from directory
if ($handle = opendir("../../media/test")) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {

// write data to the database
$sql_query = "UPDATE `" .TABLE_PREFIX ."mod_wysiwyg` SET `content` = '$entry', `text` = '$entry' WHERE `section_id` = '36'";
$database->query($sql_query);

}
}
  closedir($handle);
}

It's working, but it's write only one file in the database.
How can I change the code so that it is writing all the files in the database?

And second:
How do I include <span style="font-size: 0px;"> '$entry' </span> to make the WYSIWYG section invisible to prevent that you see the files of the directory twice?

Thanks in advance,
Rob
Logged
DarkViper
Development Team
*****
Offline Offline

Posts: 1253


« Reply #3 on: April 16, 2012, 12:20:38 PM »

there are some functions available by the core.

if /framework/functions.php is loaded, you can choose. wink
Code:
<?php

function file_list($directory$skip = array(), $show_hidden false)

function 
scan_current_dir($root ''$search '/.*/')

function 
directory_list($directory$show_hidden false)

?>
each of this functions has a short description before.

for your requirements:
Code:
<?php

$aFoundFiles 
scan_current_dir(WB_PATH.'/media/test');
$sContent '<ul>\n\t<li>'.implode"</li>\n\t<li>"$aFoundFiles['path'])."</li>\n</ul>\n";
$sText implode(' '$aFoundFiles['path']);
$sql  'UPDATE `'.TABLE_PREFIX.'mod_wysiwyg` ';
$sql .= 'SET `content`=\''.mysql_real_escape_string($sContent).'\', ';
$sql .=     '`text`=\''.mysql_real_escape_string($sText).'\' ';
$sql .= 'WHERE `section_id`=36';
$database->query($sql);

?>
so you have a HTML-formated list in `content` and plain text for search in `text`
« Last Edit: April 16, 2012, 12:55:15 PM by DarkViper » Logged

Anleitungen lesen und selber nachdenken ist anstrengend...  Da lass ich doch lieber andere für mich denken...

In 1984:  Nineteen Eighty-Four is a unrealistic utopia!!
In 2012:  Nineteen Eighty-Four is a little piece only of our reality!!
CaptainRob

Offline Offline

Posts: 28



« Reply #4 on: April 16, 2012, 06:07:48 PM »

Sorry DarkViper, that's far beyond my knowledge.

Your code is not working on my system and I have no idea how to fix it.
Is it possible that /framework/functions.php is not loaded on my system?
And how do I get that file loaded, or how can I check if it is loaded?

Thanks,
Rob
Logged
DarkViper
Development Team
*****
Offline Offline

Posts: 1253


« Reply #5 on: April 16, 2012, 07:22:10 PM »

extend the code by the first line please.
So the file is loaded in any case.

Code:
<?php

include_once(WB_PATH.'/framework/functions.php');
$aFoundFiles scan_current_dir(WB_PATH.'/media/test');
...

?>
Logged

Anleitungen lesen und selber nachdenken ist anstrengend...  Da lass ich doch lieber andere für mich denken...

In 1984:  Nineteen Eighty-Four is a unrealistic utopia!!
In 2012:  Nineteen Eighty-Four is a little piece only of our reality!!
CaptainRob

Offline Offline

Posts: 28



« Reply #6 on: April 17, 2012, 12:48:58 PM »

I get only this error message:

Warning: implode() [function.implode]: Invalid arguments passed in /mnt/webg/e2/72/52917472/htdocs/test/modules/code/view.php(30) : eval()'d code on line 3

Warning: implode() [function.implode]: Invalid arguments passed in /mnt/webg/e2/72/52917472/htdocs/test/modules/code/view.php(30) : eval()'d code on line 4


This is now the code what I'm using:

Code:
include_once(WB_PATH.'/framework/functions.php');
$aFoundFiles = scan_current_dir(WB_PATH.'/media/test');
$sContent = '<ul>\n\t<li>'.implode( "</li>\n\t<li>", $aFoundFiles['path'])."</li>\n</ul>\n";
$sText = implode(' ', $aFoundFiles['path']);
$sql  = 'UPDATE `'.TABLE_PREFIX.'mod_wysiwyg` ';
$sql .= 'SET `content`=\''.mysql_real_escape_string($sContent).'\', ';
$sql .=     '`text`=\''.mysql_real_escape_string($sText).'\' ';
$sql .= 'WHERE `section_id`=36';
$database->query($sql);

In the content of the database is inserted:

<ul>\n\t<li></li>
</ul>


Thanks,
Rob
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!