Call a droplet within php code

Stefek

Quote from: DarkViper on November 07, 2010, 06:41:27 PM
please try to refactoring this function to optimize the speed to a acceptable manner and reduce the CPU load!

Done  :-)
https://forum.websitebaker.org/index.php/topic,19820.msg134939.html#msg134939

Regards,
Stefek
[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

Stefek

Hello,

Quote from: PurpleEdge on November 08, 2010, 12:36:10 AM
Your idea is a good one though, and I wonder if there is a need for a WB Function_Store module where developers can create functions and store them in a central data file - similar to Droplets (and Snippets). The benefit of this idea is that functions developed for a module can be used by other modules, instead of re-inventing the wheel, or copying code, for every new module.

the OutputFilter Dashboard is exactly such a "Function Store Module" for Filters (and some more). ^^
You can assign the filter I created here to more than just one Module (as described here):

https://forum.websitebaker.org/index.php/topic,19820.msg133691.html#msg133691

Enjoy ;-)

Kind regards,
Stefek


[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

PurpleEdge

Thank you both very much!

Werner I have applied your changes and it works nicely. (There must be more bad words in German than in English, I can only think of 6!  :lol:)

Stefek, it appears this is an OUTPUT filter? which means it gets called on every page display - what I would prefer is an INPUT filter, which means it only gets called when the page is saved to the database.

Your idea is a good one though, and I wonder if there is a need for a WB Function_Store module where developers can create functions and store them in a central data file - similar to Droplets (and Snippets). The benefit of this idea is that functions developed for a module can be used by other modules, instead of re-inventing the wheel, or copying code, for every new module.

Therefore, I would have access to a single bad_words_filter() function in every module where I wanted to apply the code. It is similar to the module you have created, but it is designed for use within module php code.

Stefek

#13
Hello Werner,

thanks for response and I am sure you're right in this point.
The real reson for using the same code as user PurpleEdge did was to give him some similarity to his original code.
This way I hope he can see for himself how ease it is to create a filter on his own.

I think you get me here.

There are lots of similar approaches out there on the web.
I found also this nice one http://badwordfilter.com/
but... unfortunately there is no german library (but it's still interesting).

Thanks anyway.
I will adapt your code later tonight, if I find some time.

Regards,
Stefek

Quote[joke] I ask myself only what the pharmaceutical industry will pay for this excellent sedativum? [/joke]
As I always say: a beatiful Aquarium is better than Valium.  :wink:
[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

DarkViper

#12
@Stefek
the idea itself is really good.

[joke] I ask myself only what the pharmaceutical industry will pay for this excellent sedativum? [/joke] :wink:

please try to refactoring this function to optimize the speed to a acceptable manner and reduce the CPU load!

i.e. 1st: if you have 100 bad-words in your list and a page with around 2500 words in a wysiwyg-section, then the outer loop explode(" ",$content) statement 100 times will create an array with nearly 5000 entries (don't forget: the $content includes the whole html-markup, which also will be exploded). Then the inner loop must calculate 100*2*5000 (1000000) times a metaphone value( it's a complex algorithm). Also the replace-statement must be executed very often.  .... it's a loooooooong time to wait for the output.  :wink: (may be the server like to have a coffee to do that job.. :wink:)

2nd: eregi_replace() is a deprecated function and will throw a strict warning. Better to use simple str_replace().

3th: to prevent the design its better to replace each letter of a badword by # or *. How to do: <?php
$content 
str_replace$cstr_repeat'#'strlen($c)) , $content );
?>

Badword: 'Computer'  Result: '########'

or better:
<?php
$content 
str_replace$csubstr($c01).str_repeat'*'strlen($c)-2).substr($c, -1) , $content );
?>

Badword: 'Computer'  Result: 'C******r'


happy workeling...  8-)   :wink:
[url=http://www.youtube.com/watch?v=tmzDAz6ZvFQ]Der blaue Planet[/url] - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen[br]
[i]"You have to take the men as they are... but you can not leave them like that !" :-P [/i]
[i]Das tägliche Stoßgebet: [b]Oh Herr, wirf Hirn vom Himmel ![/b][/i]

Stefek

#11
Hello PurpleEdge,
Quote from: PurpleEdge on November 07, 2010, 08:54:14 AM
It is a lazy programmers technique for saving some values in a table that is easy to get to, so I can edit the list whenever I like from the backend.

Yes, I know what it mens being lazy...
But in the most cases we are "lazy" to be more efficient, right?

So here is a solution (your laziness will feel flattered)...

To do this, you will need to install OutputFilter Dashboard.
This is a Admin Tool to handle filtering on the server.

After installation you can create a NEW INLINE FILTER.
Put the following code into it:

<?php 
function opff_bad_word_filter(&$content$page_id$section_id$module$wb) {

 
$values['badwords'] = "my, bad, words, string, comma, separated";
$iarray explode(",",$values['badwords']) ;
if(!empty($iarray)){
foreach($iarray as $i){
$checklist explode(" ",$content) ;
foreach($checklist as $c){
if(metaphone(trim($c))== metaphone(trim($i)))
$content eregi_replace($c,'###',$content);
}
}
foreach($iarray as $i)
$content eregi_replace(trim($i),'##',$content) ;

}
return(TRUE);
}
?>




Pretty similar to your Code, right?

I also created a (installable) Plugin.
Look here:
https://forum.websitebaker.org/index.php/topic,19820.msg133691.html#msg133691

Please comment on this in the linked thread. Thank you.

Regards,
Stefek
[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

PurpleEdge

Hi Stefek, yes, go to bed!

That is the complete code.

The sql select statement just looks up the value in the "code" field for a record in the "droplet" table. IOW, I just created a droplet, named it bad_word_list and in the "code" section for the droplet I have a list of bad words...

bad, word, list, etc

It is a lazy programmers technique for saving some values in a table that is easy to get to, so I can edit the list whenever I like from the backend.

Stefek

Hello,

I will have a look tomorrow.
(its close to 6 am here.)
Code all night  :-P

One thing though.
Could you please post the code from the field `code`WHERE name = 'badwordlist' ?

Regards,
Sefek
[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

PurpleEdge

I'm just using this, not super efficient, but only called when saving a record...


function bad_word_filter(&$output){
    $database = new database();
    $badwords = $database->get_one("SELECT code FROM mod_droplets WHERE name = 'bad_word_list';");
    if($badwords == '') {
      $badwords = 'bad, word, list';
    }
    $iarray = explode(",",$badwords) ;
    foreach($iarray as $i){
        $checklist = explode(" ",$output) ;
        foreach($checklist as $c){
            if(metaphone(trim($c))== metaphone(trim($i))){
                $output = eregi_replace($c,'###',$output) ;
            }
        }
    }
    foreach($iarray as $i){
        $output = eregi_replace(trim($i),'##',$output) ;
    }
    return $output ;
}

Stefek

Hello,

could you point me a link to it?

I would like to create a ready to use FilterPlugin for the OutputFilterDashboard.

Regards,
Stefek
[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

PurpleEdge

Thanks again Stefek,

The filter I am using uses metaphone() as an additional filter, before the content is saved to the database, so I think I'll persevere with it.

Regards,

Geoff B

Stefek

Hello,
a good alternative could be the OutputFilter Dashboard.
You may create an array of all "bad" Words and it's replacement like:


$myBadWords = array(
'kacka' => '(badword!)',
'vucker' => '(don\'t use this word, man!)',
'bimber' => '(censored!)',
)


and then apply a str_replace on the whole array in this way.

$content = str_replace(array_keys($myBadWords), array_values($myBadWords), $content );

BTW. You may assign this code to be executed with selected Modules only (e.g. Guestbook, News (for comments) etc.)
If you need any help, just let me know.
Best place to ask for help is the OutputFilter Dashboard thread.



Kind regards,
Stefek

[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

PurpleEdge

Thanks Stefek, I might give that a try!

I have a bad-words-filter for front-end input and I am using a droplet as a handy place to manage the list of bad words. It is easy enough to lookup the value contained in the droplet, I was just looking for alternative techniques.

Stefek

Quote from: PurpleEdge on November 05, 2010, 06:05:07 AM... I was wondering if there is an easy way to call them from within php, rather than html?
Hello, depending on where the script is run you may try:
echo '[[my_droplet_token]]';

At least it works in a regular Section of Type code.

Regards,
Stefek
[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

pcwacht

Droplets aren't made to be called from another php script.
Droplets are pieces of code wich you can use in your output, when the output is created the droplets are executed.
You can copy and paste the droplet code into your php.

John
[url="http://www.ictwacht.nl"]http://www.ictwacht.nl[/url] = Dutch ICT info
[url="http://www.pcwacht.nl"]http://www.pcwacht.nl[/url] = My first
both still work in progress, since years.....

PurpleEdge

I haven't looked at the magic behind dropletes, but they are such a handy way to use php functions I was wondering if there is an easy way to call them from within php, rather than html?