# Filter functions

Summary

Filter functions |
The Filter-Function itself | The Filter function must have an unique name, and should have a “opff_”-prefix
Functions |
opf_register_filter | Register a new Filter.
opf_move_up_before | Upon registration move a filter up to a position before another one.
opf_unregister_filter | Un-Register a Filter.
opf_register_frontend_files | Register JS- or CSS-files to be loaded into the page’s <head>-section.
opf_register_onload_event | Register an Javascript onload-function inside page’s <head>-section, using window.attachEvent() or window.addEventListener().
opf_register_onload | Register an Javascript script onload-function inside page’s <body>-section.
opf_register_document_ready | Register an Javascript onload-event inside page’s <head>-section, using jquery’s jQuery(document).ready()
opf_find_class | Check whether a class (or any other attribute) is present in content.
opf_add_class | Add a class to a present HTML-tag, i.e.
opf_add_class_to_class | Add a class to an already present class.
opf_add_class_to_attr | Add a class to all HTML-tags that has a given attribute.
opf_cut_extract | Cuts pieces out of content using a regular expression and replace them by placeholders.
opf_glue_extract | bool opf_glue_extract( string &$content, string $extracts )
opf_filter_get_data | Fetch data from filter.
opf_filter_get_rel_pos | Checks if a given filter was or will be executed.
opf_filter_exists | Checks whether a given filter exists
opf_is_childpage | Checks whether a page is a subpage of a given page (or the same page)
opf_filter_is_active | Checkes whether a given filter is active for the actual module and page_id
opf_filter_get_additional_values | Receive additional filter arguments
opf_filter_name_to_setting | For WBCE 1.2: This function converts the name of a filter to the settings string which is associated with the active/inactive state of the given filter name.

### The Filter-Function itself

The Filter function must have an unique name, and should have a “opff_”-prefix

#### Prototype

bool opff_unique_name( string &$content, int $page_id, int $section_id, string $module, object $wb )

#### Parameters

&$content | (string) The page’s or section’s Content, per reference!
$page_id | (int) Actual Page ID.
$section_id | (int) Actual Section ID. For Filters of type OPF_TYPE_PAGE_FIRST, OPF_TYPE_PAGE or OPF_TYPE_PAGE_LAST or OPF_TYPE_PAGE_FINAL this is always FALSE.
$module | (string) Name of actual module (== $module_directory ). For Filters of type OPF_TYPE_PAGE_FIRST, OPF_TYPE_PAGE or OPF_TYPE_PAGE_LAST or OPF_TYPE_PAGE_FINAL this is always FALSE.
$wb | (object) Instance of Class wb.

#### Returns

Should return always TRUE. Only in case the content may be damaged or undefined the function must return FALSE.

#### Examples

>     // simple filter which will convert all U to X in $content
>     function opff_x_as_u(&$content, $page_id, $section_id, $module, $wb) {
>         $content = str_replace('U', 'X', $content);
>         return(TRUE);
>     }

>     function opff_prettify(&$content, $page_id, $section_id, $module, $wb) {
>         $PATH = WB_URL.'/modules/opf_prettify/prettify';
>         if(opf_find_class($content, 'prettyprint', '(pre|code)')) {
>             opf_register_frontend_files($PATH.'/prettify.css','css');
>             opf_register_frontend_files($PATH.'/prettify.js','js');
>             if(opf_find_class($content, 'lang-sql', '(pre|code)'))
>                 opf_register_frontend_files($PATH.'/lang-sql.js','js');
>             opf_register_onload_event('prettyPrint');
>         }
>         return(TRUE);
>     }

### Functions

### opf_register_filter

> function opf_register_filter( | $filter, |  |
> | $serialized | = | FALSE | )

Register a new Filter.

This function is used for plugin- and module-filters to install the filter.

You don’t need this function for inline-filters!

#### Prototype

bool opf_register_filter( array $filter, bool $serialized=FALSE )

#### Parameters

$filter | (array) An array that contains all filter data.
$serialized | (bool) Whether the filter-data is passed serialized.

#### Returns

TRUE on success, FALSE otherwise. Additionaly it will emit an error-message (level: E_USER_WARNING) in case of failure.

#### Examples

>     $filter = array(
>         'name'       => 'PrettyPrint: Google-Code-Prettify',
>         'type'       => OPF_TYPE_SECTION,
>         'file'       => WB_PATH.'/modules/opf_prettify/filter.php',
>         'funcname'   => 'opff_prettify',
>         'csspath'    => WB_PATH.'/modules/opf_prettify/prettify/prettify.css',
>         'modules'     => 'download_gallery,manual,news,wysiwyg'
>     );
>     opf_register_filter($filter);

#### $filter-Array

name | (string) - Unique name of Filter, e.g. Correct Date filter.
type | (string) - Type of Filter (see below).
funcname | (string) - Unique name of Filter-Function. This function is called to apply the filter. It has to be an unique name and should begin with “opff_”, e.g. opff_correct_date().
func | (string) - “Inline-Function” (see below).
file | (string) - Name and absolute path of file containing the Filter-Function. Use either func or file.
active | (int) - Set Filter active (1), or inactive (0) after installation. Defaults to 1.
allowedit | (int) - Set Filter-Settings editable (1), or not editable (0) (see below). Defaults to 0.
allowedittarget | (int) - Set additional Filter-Settings editable (see below). Defaults to 0.
desc | (string/array) - Description of Filter (see below).
configurl | (string) - URL to Filter-Settings (e.g. to an Admin-Tool). E.g.: ’configurl’ => ADMIN_URL.’/admintools/tool.php?tool=output_filter’. Default: “”.
csspath | (string) - Name and absolute path of CSS-file. E.g.: ’csspath’ => ‘{SYSVAR:WB_PATH}/modules/opf_prettify/prettify/prettify.css’. Default: “”.
helppath | (array) - Array of name and absolute path to Help-files. E.g.: ’helppath’ => array(‘DE’=>’{SYSVAR:WB_URL}/modules/opf_prettify/help_de.html’, ‘EN’=>’{SYSVAR:WB_URL}/modules/opf_prettify/help_en.html’). Default: “”.
modules | (string/array) - List of modules (see below).
pages | (string/array) - List of pages (see below).
pages_parent | (string/array) - List of pages (see below).
additional_fields | (array) - List of additional Settings-Fields (see below).

#### type

Determines on which type of content the filter is applied to.

OPF_TYPE_SECTION_FIRST | Apply filter on section-content, but before all filters of type OPF_TYPE_SECTION.
OPF_TYPE_SECTION | Apply filter on section-content.
OPF_TYPE_SECTION_LAST | Like OPF_TYPE_SECTION, but applied after all filters of type OPF_TYPE_SECTION.
OPF_TYPE_PAGE_FIRST | Like OPF_TYPE_PAGE, but applied before all filters of type OPF_TYPE_PAGE.
OPF_TYPE_PAGE | Apply filter on page-content, i.e. on all sections, snippets on that page, and the entire template, too.
OPF_TYPE_PAGE_LAST | Like OPF_TYPE_PAGE, but applied after all filters of type OPF_TYPE_PAGE.
OPF_TYPE_PAGE_FINAL | Like OPF_TYPE_PAGE_LAST, but applied even after all filters of type OPF_TYPE_PAGE_LAST.

Filter of type OPF_TYPE_SECTION are applied on section-content before the content gets inserted into the template.

Filter of type OPF_TYPE_PAGE are applied on the finished page just before the page is sent to the browser.

#### func

A string containing the filter-function. Convenient for very short functions. Use file for larger filter-functions.

>     $function = '
>         function opff_search_highlight(&$content, $page_id, $section_id, $module, $wb) {
>             if(isset($_GET["searchresult"]) && is_numeric($_GET["searchresult"])
>                  && !isset($_GET["nohighlight"]) && isset($_GET["sstring"])
>                  && !empty($_GET["sstring"])) {
>                 $arr_string = explode(" ", $_GET["sstring"]);
>                 if($_GET["searchresult"]==2) // exact match
>                     $arr_string[0] = str_replace("_", " ", $arr_string[0]);
>                 $content = search_highlight($content, $arr_string);
>             }
>             return(TRUE);
>         }
>     ';
>     $filter = array(
>         'name'       => 'Searchresult Highlighting',
>         'type'       => OPF_TYPE_SECTION_LAST,
>         'funcname'   => 'opff_search_highlight',
>         'func'       => $function,
>         'modules'     => 'all'
>     );
>     opf_register_filter($filter);

#### file

Name and absolute path of file containing the Filter-Function.

>     $filter = array(
>         'name'       => 'Searchresult Highlighting',
>         'type'       => OPF_TYPE_SECTION_LAST,
>         'funcname'   => 'opff_search_highlight',
>         'file'       => '{SYSVAR:WB_PATH}/modules/myfilter/filter.php',
>         'modules'    => 'all'
>     );
>     opf_register_filter($filter);

With filter.php

>     <?php
>     // content of filter.php
>     function opff_search_highlight(&$content, $page_id, $section_id, $module, $wb) {
>         if(isset($_GET["searchresult"]) && is_numeric($_GET["searchresult"])
>              && !isset($_GET["nohighlight"]) && isset($_GET["sstring"])
>              && !empty($_GET["sstring"])) {
>             $arr_string = explode(" ", $_GET["sstring"]);
>             if($_GET["searchresult"]==2) // exact match
>                 $arr_string[0] = str_replace("_", " ", $arr_string[0]);
>             $content = search_highlight($content, $arr_string);
>         }
>         return(TRUE);
>     }
>     ?>

#### allowedit

If set to 1 following settings are changeable through Admin-Tool

- Name of filter
- Type of Filter
- Name of filter-function
- Filter-function itself (in case it’s a “inline-filter”)
- List of modules, and
- List of pages the filter is applied to.

Suggestion: use ’allowedit’ => 0 always (default).

#### allowedittarget

Extension for allowedit: If allowedit is set to 0 and allowedittarget set to 1 the user is allowed to change only

- List of modules, and
- List of pages the filter is applied to.

Suggestion: use ’allowedittarget’ => 1 always (default).

In case allowedit is set to 1 allowedittarget is meaningless.

#### desc

Description of filter. Use either

>     'desc' => "Description follows here.\nText..."

or

>     'desc' => array(
>       'EN' => "Description\n...",
>       'DE' => "Beschreibung\n..."
>     )

Using the latter form, there has to be at least an English ( ’EN’ ) entry.

#### modules

List of modules the filter (of type OPF_TYPE_SECTION_FIRST, OPF_TYPE_SECTION or OPF_TYPE_SECTION_LAST ) is applied to. In the following two examples, the filter will be applied to all WYSIWYG- and News-sections.

>     'modules' => 'wysiwyg,news'

or

>     'modules' => array('wysiwyg', 'news')

There are some aliases defined

’all’ | all installed modules
’all_page_types’ | all page-type modules: wysiwyg, news, guestbook, download_gallery, manual, mapbaker, newsarc
’all_form_types’ | form, formx, mpform, miniform
’all_gallery_types’ | Auto_Gallery, fancy_box, flickrgallery, foldergallery, gallery, gdpics, imageflow, imagegallery, lightbox2, lightbox, minigallery, minigal2, panoramic_image, pickle, picturebox, tiltviewer, smoothgallery, swift, slideshow
’all_wrapper_types’ | curl, inlinewrapper, wrapper
’all_calendar_types’ | calendar, concert, event, event_calendar, extcal, procalendar
’all_shop_types’ | bakery, gocart, anyitems, lastitems
’all_code_types’ | code, code2, show_code, show_code_geshi, color4code
’all_poll_types’ | doodler, polls
’all_listing_types’ | accordion, addressbok, aggregator, bookings_v2, bookmarks, cabin, dirlist, enhanced_aggregator, faqbaker, faqmaker, glossary, jqCollapse, members, mfz, sitemap
’all_various_types’ | audioplayer, feedback, forum, newsreader, shoutbox, simpleviewer, small_ads, wb-forum, zitate

See <opf_modules_categories> for the actual module -> category relation.

#### pages

List of pages (PAGE_IDs) the filter is applied to. Alias ‘all’ for all present pages.

>     // apply filter on page 12, 121 and 16 only
>     'pages' => '21,121,16' // written as list
>     'pages' => array('21', '121', '16') // written as array
>     // apply filter to all pages
>     'pages' => 'all'

#### pages_parent

List of pages (PAGE_IDs) the filter is applied to. Additionaly the filter is applied to all sub-pages, too. Alias ‘all’ for all present pages.

>     // apply filter on page 12 and 21, and all sub-pages of page 12 and 21
>     'pages_parent' => '12,21' // written as list
>     'pages_parent' => array('12', '21') // written as array

#### additional_fields

Arrays of additional configuration elements.

In case the filter needs some additional config-elements but it doesn’t have its own Settings-Page / Admin-Tool, you can add some fields using additional_fields. Possible field-types are

text | normal HTML text-field
textarea | normal HTML textarea
editarea | textarea with activated editarea (Editor)
radio | normal HTML radio-fields
checkbox | normal HTML checkbox-fields
select | normal HTML select-field
array | simple array broken up into several text-fields

allowedit has no affect on these fields.

See opf_filter_get_additional_values on how to retrieve values from these fields.

Example: Adding various fields

>     'additional_fields' => array(
>         array( // add text-field "Name"
>             'type' => 'text',    // type of field
>             'label' => 'Name',       // Label for the text-field
>             'variable' => 'name',    // name of variable
>             'name' => 'af_name',     // name for HTML name-attribute
>             'value' => '',       // default-value
>             'style' => 'width: 98%;' // style (only for text, textarea and editarea for width and height)
>         ),
>         array( // add textarea "Long-text"
>             'type' => 'textarea',
>             'label' => 'Long-Text',
>             'variable' => 'text',
>             'name' => 'af_long_text',
>             'value' => 'Default text',
>             'style' => 'width: 98%;'
>         ),
>         array( // add select-field "Colour"
>             'type' => 'select',
>             'label' => 'Colour',
>             'variable' => 'colour',
>             'name' => 'af_colour',
>             'value' => array(    // options
>                 'red'   => 'Red',
>                 'blue'  => 'Blue',
>                 'green' => 'Green'
>             ),
>             'checked'=> 'blue'       // selected option
>             )
>         ),
>         array( // add checkbox
>             'type' => 'checkbox',
>             'label' => 'Use ECMA-variant',
>             'variable' => 'use_ecma',
>             'name' => 'af_use_ecma',
>             'value' => 'use_ecma',
>             'checked' => 1
>         )
>     )

Example: Adding fields with language-support

>     'additional_fields' => array(
>         array(
>             'type' => 'text',         // type of field
>             'label' => array(          // Language-dependent string
>                 'EN'=>'Locale',
>                 'DE'=>'Spracheinstellung'
>             ),
>             'variable' => 'locale',       // name of variable
>             'name' => 'af_locale',    // name for name-attribute
>             'value' => 'de_DE.utf-8',     // default-value
>             'style' => 'width: 98%;'      // style (only for text, textarea and editarea for width and height)
>         ),
>         array(
>             'type' => 'array',
>             'label' => array(
>                 'EN'=>'Date format',
>                 'DE'=>'Datumsformat'
>             ),
>             'variable' => 'date_formats',
>             'name' => 'af_date_formats',
>             'value' => array(
>                 'D M d, Y'  => 'a b d Y',
>                 'M d Y'     => 'b d. %Y',
>                 'd M Y'     => 'd. b %Y',
>                 'jS F, Y'   => 'e. B %Y',
>                 'l, jS F, Y'=> 'A, e. B Y')
>         ),
>         array(
>             'type' => 'select',
>             'label' => array('EN'=>'Colour','DE'=>'Farbe'),
>             'variable' => 'colour',
>             'name' => 'af_colour',
>             'value' => array(    // options
>                 'red'   => array('EN'=>'Red','DE'=>'Rot'),
>                 'blue'  => array('EN'=>'Blue','DE'=>'Blau'),
>                 'green' => array('EN'=>'Green','DE'=>'Grün')
>             ),
>             'checked'=> 'blue'       // selected option
>             )
>         )
>     )

label | Label of field. label can be an ordinary string “Enter Date”, or a language-specific array.
variable | Name of variable to be used for this field. Radio-buttons uses the same name.
type | Type of field: ‘text’, ‘textarea’, ‘editarea’, ‘radio’, ‘checkbox’, ‘select’ or ‘array’.
name | Value for the HTML name-attribute. Radio-buttons uses the same name.
value | Default-value. ‘select’ and ‘array’ requires an array.
checked | For ‘radio’ or ‘checkbox’: use ’checked’ => 1 to mark this field checked. For ‘select’: use ’checked’ => ‘value’ i.e. repeat the selected value.
style | (optional) For ‘text’, ‘textarea’, ‘editarea’: add width: and/or height: attributes.

### opf_move_up_before

> function opf_move_up_before( | $name, |  |
> | $ref_name | = | "" | )

Upon registration move a filter up to a position before another one. This function can be used after opf_register_filter() to adjust its position in the filter list. By default, freshly installed filters are appended to the end of the list of filters of the same type. Use this function inside the <install.php> to move the filter up to a target position denoted by the name of another filter. You can repeat this with different names of filters from which you know that they have to be applied after the one you are installing. Alternatively, if $ref_name is an array, the filter denoted by $name is moved upwards to the position of the upper-most entry of the whole list. If $ref_name is ommited, the filter $name is moved up to the top of the whole list. In this case the return value is the new position of the filter $name

#### Prototype

bool opf_move_up_before( string $name, string $ref_name )

array opf_move_up_before( string $name, array $ref_name )

int opf_move_up_before( string $name )

#### Parameters

$name | (string) the name of the filter to move up in the list
$ref_name | (string) name of the filter at the target position or
$ref_name | (array) names of the filters at the target positions

#### Returns

TRUE on success, FALSE if the types don’t match or the filters were not found or an array of bools, corresponding to the return values for each filter or the position of $name if $ref_name is ommitted

#### Example

>     opf_move_up_before('opf CSS to head', 'Searchengine Highlighter');

### opf_unregister_filter

> function opf_unregister_filter( | $name | )

Un-Register a Filter.

This function is used to remove a filter. Use this for Module-Filters in the module’s uninstall.php-file.

#### Prototype

bool opf_unregister_filter( string $name )

#### Parameters

$name | (string) Name of filter to un-register.

#### Returns

TRUE on success, FALSE otherwise.

#### Example

>     opf_unregister_filter('PrettyPrint: Google-Code-Prettify');

### opf_register_frontend_files

> function opf_register_frontend_files( | $file, |  |
> | $type, |  |
> | $target | = | 'head',
> | $media | = | 'screen',
> | $iehack | = | '' | )

Register JS- or CSS-files to be loaded into the page’s <head>-section.

#### Prototype

bool opf_register_frontend_files( string $file, string $type, string $target=’head’, string $media=’screen’, string $iehack )

#### Parameters

$file | (string) URL of file to register, or “inline” JS-script or CSS-style.
$type | (string) Type: ‘js’ or ‘css’.
$target | (string) Where to insert the file: ‘head’ or ‘body’.
$media | (string) media, for stylesheets only, e.g.: ‘screen’ or ‘screen,print’. Use ‘’ (empty string) otherwise.
$iehack | (string) Special IE-Hack (for type js only).

#### Returns

Always TRUE.

#### Examples

>     // register JS-script
>     opf_register_frontend_files(WB_URL.'modules/opf_prettify/prettify.js', 'js');
>     // register JS-script in <body>
>     opf_register_frontend_files(WB_URL.'modules/opf_prettify/prettify.js', 'js', 'body');
>     // register CSS-Stylesheet
>     opf_register_frontend_files(WB_URL.'/modules/opf_pcdtr/pcdtr/styles.css', 'css');
>     // IE-Hack
>     opf_register_frontend_files(WB_URL.'/modules/opf_fix_png_ie6/sl.js', 'js', 'head', '', '[if lte IE 6]');
>     // output: <!--[if lte IE 6]><script ...></script><![endif]-->

>     // usage of "inline"-script
>     opf_register_frontend_files('
>       <script type="text/javascript">function do_highlight() { highlighter.highlight(); }</script>
>       ','js');

### opf_register_onload_event

> function opf_register_onload_event( | $function_name | )

Register an Javascript onload-function inside page’s <head>-section, using window.attachEvent() or window.addEventListener().

#### Prototype

bool opf_register_onload_event( string $function_name )

#### Parameters

$function_name | (string) Name of JS-function to register.

#### Returns

Always TRUE.

#### Example

>     opf_register_onload_event('prettyPrint');

#### Notes

There is no way to supply arguments to the function, yet. Use opf_register_onload in case the function call needs arguments.

### opf_register_onload

> function opf_register_onload( | $script | )

Register an Javascript script onload-function inside page’s <body>-section.

#### Prototype

bool opf_register_onload( string $script )

#### Parameters

$script | (string) JS-script to register.

#### Returns

Always TRUE.

#### Example

>     opf_register_onload('prettyPrint();');
>     opf_register_onload("supersleight.run('".WB_URL."/modules/opf_fix_png_ie6/x.gif');");
>     opf_register_onload('$(\'#tagSphere\').tagSphere();');

### opf_register_document_ready

> function opf_register_document_ready( | $js | )

Register an Javascript onload-event inside page’s <head>-section, using jquery’s jQuery(document).ready() method.

#### Prototype

bool opf_register_document_ready( string $js )

#### Parameters

$js | (string) The Javascript-Code to use inside $(document).ready().

#### Returns

Always TRUE.

#### Requires

This function requires that jQuery is loaded in the page’s <head>-section.

#### Example

>     opf_register_document_ready('alert("OK!");');
>     opf_register_document_ready('$(\'#tagSphere\').tagSphere();');

### opf_find_class

> function opf_find_class( | $content, |  |
> | $match, |  |
> | $tag | = | '',
> | $attr | = | 'class' | )

Check whether a class (or any other attribute) is present in content.

#### Prototype

bool opf_find_class( string $content, string $match, string $tag=’’, string $attr=’class’ )

#### Parameters

$content | (string) Content.
$match | (string/regex) String to search for.
$tag | (string/regex) HTML-tag. Defaults to ‘’ (nothing).
$attr | (string/regex) Attribute to check. Defaults to ‘class’.

#### Returns

1 if $match is present, 0 otherwise. In case of error, this function returns FALSE.

#### Example

>     // apply filter only if class 'special_class' is present somewhere in $content
>     if(opf_find_class($content, 'special_class')) {
>         // ... apply filter
>         return(TRUE);
>     } else {
>         return(TRUE); // quit
>     }

>     // apply filter only if class 'php_highlighter' is present inside a <pre>-tag
>     // <pre class="class1 php_highlighter">...</pre>
>     if(opf_find_class($content, 'php_highlighter', 'pre')) {
>         // ... apply filter

>     // apply filter only if id 'tagSphere' is present inside a <div>-tag
>     // <div class="class2" id="tagSphere">...</div>
>     if(opf_find_class($content, 'tagSphere', 'div', 'id')) {
>         // ... apply filter

Regular expressions are allowed, too. Those regexs are performed ungreedy (PCRE_UNGREEDY).

>     // search for class "cpp", "c" or "c++" in HTML-tag <pre> or <textarea>
>     if(opf_find_class($content, '(cpp|c|c\+\+)', '(pre|textarea)')) {
>         // ... apply filter

### opf_add_class

> function opf_add_class( | & | $content,
> |  | $class,
> |  | $tag | )

Add a class to a present HTML-tag, i.e. <pre>. The class will be added to all appearance of the given HTML-tag.

#### Prototype

bool opf_add_class( string $content, string $class, string $tag )

#### Parameters

$content | (string) Content (by reference).
$class | (string) Name of class to add.
$tag | (string/regex) HTML-tag, e.g. ‘pre’.

#### Returns

TRUE if $class was added, FALSE otherwise.

#### Example

>     // adds class "prettyPrint" to all <pre> tags
>     opf_add_class($content, 'prettyPrint', 'pre');

>     // adds class "prettyPrint" to all <pre> and <code> tags
>     opf_add_class($content, 'prettyPrint', '(?:pre|code)');

#### Note

$tag can be a regular expression (PCRE), too. But keep in mind that no “capturing groups” are allowed, i.e. use always ?: e.g.: ‘(?:pre|code)’. Per default those regexs are performed ungreedy (PCRE_UNGREEDY).

### opf_add_class_to_class

> function opf_add_class_to_class( | & | $content, |  |
> |  | $class, |  |
> |  | $present_class, |  |
> |  | $tag | = | '' | )

Add a class to an already present class. The new class will be added to all appearance of the given class.

#### Prototype

bool opf_add_class_to_class( string $content, string $class, string $present_class, string $tag=’’ )

#### Parameters

$content | (string) Content (by reference).
$class | (string) Name of class to add.
$present_class | (string/regex) Name of class to add $class to.
$tag | (string/regex) HTML-tag. Defaults to ‘’.

#### Returns

TRUE if $class was added, FALSE otherwise.

#### Example

>     // add class "php" to present class "prettify"
>     opf_add_class_to_class($content, 'php', 'prettify')
>     // <pre class="prettify"> ... </pre>
>     // will become
>     // <pre class="prettify php"> ... </pre>

>     // add class "php" to present class "prettify" but only for <code>-tags
>     opf_add_class_to_class($content, 'php', 'prettify', 'code')
>     // <pre class="prettify"> ... </pre>
>     // <code class="prettify">...</code>
>     // will become
>     // <pre class="prettify"> ... </pre>
>     // <code class="prettify php">...</code>

#### Note

$present_class and $tag can be a regular expression (PCRE), too. But keep in mind that no “capturing groups” are allowed, i.e. use always ?: e.g.: ‘(?:pre|code)’. Per default those regexs are performed ungreedy (PCRE_UNGREEDY).

### opf_add_class_to_attr

> function opf_add_class_to_attr( | & | $content, |  |
> |  | $class, |  |
> |  | $attr, |  |
> |  | $value, |  |
> |  | $tag | = | '' | )

Add a class to all HTML-tags that has a given attribute.

#### Prototype

bool opf_add_class_to_attr( string $content, string $class, string $attr, string $value, string $tag=’’ )

#### Parameters

$content | (string) Content (by reference).
$class | (string) Name of class to add.
$attr | (string/regex) Name of attribute that has to be present.
$value | (string/regex) Content of that attribute.
$tag | (string/regex) HTML-tag. Defaults to ‘’.

#### Returns

TRUE if $class was added, FALSE otherwise.

#### Examples

#### Note

$attr, $value and $tag can be a regular expression (PCRE), too. But keep in mind that no “capturing groups” are allowed, i.e. use always ?: e.g.: ‘(?:pre|code)’. Per default those regexs are performed ungreedy (PCRE_UNGREEDY).

### opf_cut_extract

> function opf_cut_extract( | & | $content, |  |
> |  | $regex, |  |
> |  | $subpattern | = | 0,
> |  | $modifers | = | 'iU',
> |  | $delimiter | = | '~',
> |  | $extracts | = | '' | )

Cuts pieces out of content using a regular expression and replace them by placeholders.

#### Prototype

array opf_cut_extract( string &$content, string $regex, string $subpattern=0, string $modifers=’iU’, string $delimiter=’~’, string $extracts=’’ )

#### Parameters

$content | (string) Content (by reference).
$regex | (string) Regular expression (PCRE), without delimiters and modifers, e.g.: ‘<input[^>]+/>’. The regex is applied UNGREEDY per default.
$subpattern | (string) Use the #.subpattern. Defaults to 0.
$modifers | (string) PCRE-modifiers to use, Defaults to ‘iU’.
$delimiter | (string) Delimiter to use. Defaults to ‘~’.
$extracts | (array) An array returned by a former call to this function (optional).

#### Returns

Array containing the extracts. The array will be empty if $regex didn’t match.

In case of error, this function returns FALSE and emits a error-message (level: E_USER_WARNING)

#### Example

Assume this filter-function:

>     function opff_work_on_links(&$content, $page_id, $section_id, $module, $wb) {
>         $extracts = opf_cut_extract($content, '<a href=[^>]+>.*</a>'); // cut $extracts out of content
>         var_dump($extracts);
>         var_dump($content);
>         opf_glue_extract($content, $extracts); // put $extracts back into $content
>         return(TRUE);
>     }

Running this filter-function, $extracts may contain:

>     array
>         '@@@OPF_EXTRACT_494e430fc8cf1@@@' => string '<a href="http://localhost/wbtest" target="_top"  class="menu_current"> start#22 </a>' (length=84)
>         '@@@OPF_EXTRACT_494e430fc8d06@@@' => string '<a href="http://localhost/wbtest/pages/test-mit-umbruch.php" target="_top"  class="menu_default"> Test! mit! Umbruch </a>' (length=121)
>         '@@@OPF_EXTRACT_494e430fc8d15@@@' => string '<a href="http://localhost/wbtest/pages/news.php" target="_top"  class="menu_default"> News </a>' (length=95)
>         ...

and $content:

>     ...
>     <tr>
>         <td width="170">
>             <ul>
>             <li><span class="menu_current">@@@OPF_EXTRACT_494e430fc8cf1@@@</span></li>
>             <li><span class="menu_default">@@@OPF_EXTRACT_494e430fc8d06@@@</span></li>
>             <li><span class="menu_default">@@@OPF_EXTRACT_494e430fc8d15@@@</span></li>
>     ...

#### Example

>     // PAGE_LAST-Filter: all '#' in menu-title will be converted to '<br />',
>     // to achieve an explicitly line-break in menu.
>     // Use menu-title e.g.: "entry# with linebreak", which will be converted to entry<br /> with linebreak
>     // Notice the use of $subpattern to fetch the (.*)-subpattern only.
>     // This example assumes that all menu-links will have a class="menu..." set.
>     function opff_menu_linebreak(&$content, $page_id, $section_id, $module, $wb) {
>         // cut pieces out of $content
>         $extracts = opf_cut_extract($content, '<a href=[^>]*class="menu[^>]*>(.*)</a>', 1, 'iUs');
>         // check if opf_cut_extract() returned without error
>         if($extracts) {
>             foreach($extracts as $key => $str) {
>                 // modify
>                 $extracts[$key] = str_replace('#','<br />', $str);
>             }
>             // write $extracts back to $content
>             opf_glue_extract($content, $extracts);
>             return(TRUE);
>         } else {  // opf_cut_extract() failed. $content may be damaged, so return FALSE
>             return(FALSE);
>         }
>     }

### opf_glue_extract

> function opf_glue_extract( | & | $content,
> |  | $extracts | )

#### Prototype

bool opf_glue_extract( string &$content, string $extracts )

#### Parameters

$content | (string) Content (by reference).
$extracts | (array) An array returned by opf_cut_extract().

#### Notes

See opf_cut_extract().

#### Returns

TRUE.

### opf_filter_get_data

> function opf_filter_get_data( | $name | = | '' | )

Fetch data from filter.

#### Prototype

array opf_filter_get_data( string $name=’’ )

#### Parameters

$name | string Name of Filter. Use ‘’ (empty string) for current filter.

#### Returns

Data of current filter, or FALSE in case of error.

#### Example

>     $data = opf_filter_get_data();
>     var_dump($data);

will output:

>     array
>         'id' => string '12' (length=2)
>         'userfunc' => string '0' (length=1)
>         'position' => string '1' (length=1)
>         'active' => string '1' (length=1)
>         'allowedit' => string '0' (length=1)
>         'allowedittarget' => string '1' (length=1)
>         'name' => string 'PrettyPrint: Google-Code-Prettify' (length=33)
>         'func' => string '' (length=0)
>         'type' => string '3section' (length=8)
>         'file' => string '/var/www/wbtest/modules/opf_prettify/filter.php' (length=47)
>         'csspath' => string '/var/www/wbtest/modules/opf_prettify/prettify/prettify.css' (length=58)
>         'funcname' => string 'opff_prettify' (length=13)
>         'configurl' => string '' (length=0)
>         'modules' =>
>             array
>                 0 => string 'download_gallery' (length=16)
>                 1 => string 'manual' (length=6)
>                 2 => string 'news' (length=4)
>                 3 => string 'wysiwyg' (length=7)
>         'desc' => string 'Prettifies all &lt;pre class=&quot;prettyprint&quot;&gt; and ...' (length=455)
>         'pages' =>
>             array
>                 0 => string 'all' (length=3)
>                 1 => string '99' (length=2)
>                 2 => string '104' (length=3)
>                 3 ...
>         'pages_parent' =>
>             array
>                 0 => string 'all' (length=3)
>                 1 => string '99' (length=2)
>                 2 => string '104' (length=3)
>                 3 ...
>         'current' => boolean true
>         'activated' => boolean false
>         'failed' => boolean false

### opf_filter_get_rel_pos

> function opf_filter_get_rel_pos( | $name | )

Checks if a given filter was or will be executed.

#### Prototype

int opf_filter_get_rel_pos( string $name )

#### Parameters

$name | string Name of Filter to test.

#### Returns

-1 | Filter $name was executed before the current one
0 | Filter $name is the current one
1 | Filter $name will be executed later
FALSE | Filter $name is not active, or not installed. Or an error occurred.

#### Examples

>     if(opf_filter_get_rel_pos('Menu Linebreak')) {
>         // filter "Menu Linebreak" is installed and active (but not the currend one)
>     }

>     $pos = opf_filter_get_rel_pos('Menu Linebreak');
>     if($pos==1) {
>         // filter Menu Linebreak will be called after this one
>     } elseif($pos==-1) {
>         // filter Menu Linebreak was already called before this one
>     }

### opf_filter_exists

> function opf_filter_exists( | $name, |  |
> | $verbose | = | FALSE | )

Checks whether a given filter exists

#### Prototype

bool opf_filter_exists( string $name, bool $verbose )

#### Parameters

$name | string Name of Filter to test.
$verbose | bool Outout a Error message (E_USER_WARNING) if $filter doesn’t exists.

#### Returns

TRUE if $filter exists (i.e. is installed), FALSE otherwise.

#### Examples

>     if(opf_filter_exists('Menu Linebreak')) {
>         // filter "Menu Linebreak" is installed
>     }

### opf_is_childpage

> function opf_is_childpage( | $child,
> | $parent | )

Checks whether a page is a subpage of a given page (or the same page)

#### Prototype

bool opf_is_childpage( int $child, int $parent )

#### Parameters

$child | int Page-ID of the possible childpage
$parent | int Page-ID of page to test against

#### Returns

TRUE if $child is a childpage of $parent or if $child and $parent are the same pages. FALSE otherwise.

#### Examples

>     if(opf_is_childpage(101, 9)) {
>         // page-id 101 is a childpage of page-id 9
>     }

### opf_filter_is_active

> function opf_filter_is_active( | $name | )

Checkes whether a given filter is active for the actual module and page_id

#### Prototype

bool opf_filter_is_active( string $name )

#### Parameters

$name | string Name of Filter

#### Returns

TRUE if filter $name is active for actual module and page_id. FALSE otherwise.

#### Examples

>     if(opf_filter_is_active('Menu Linebreak')) {
>         // Filter 'Menu Linebreak' is active for actual module and page_id.
>     }

### opf_filter_get_additional_values

> function opf_filter_get_additional_values()

Receive additional filter arguments

#### Prototype

array opf_filter_get_additional_values( void )

This function fetches additional filter arguments from filter-settings. See opf_register_filter().

#### Returns

Array containing the additional arguments, or FALSE in case of error.

#### Examples

>     $values = opf_filter_get_additional_values();
>     $locale = $values['locale'];
>     $date_formats = $values['date_formats'];

### opf_filter_name_to_setting

> function opf_filter_name_to_setting( | $name | )

For WBCE 1.2: This function converts the name of a filter to the settings string which is associated with the active/inactive state of the given filter name.

#### Prototype

string opf_filter_name_to_setting( string )

#### Parameters

$name | string the name of the filter

#### Returns

the name of the corresponding setting (in lowercase letters)

#### Examples

>         if(Settings::Get(opf_filter_name_to_setting($name))){
>       // do something;
>     }

> function opf_register_filter( | $filter, |  |
> | $serialized | = | FALSE | )

Register a new Filter.

> function opf_move_up_before( | $name, |  |
> | $ref_name | = | "" | )

Upon registration move a filter up to a position before another one.

> function opf_unregister_filter( | $name | )

Un-Register a Filter.

> function opf_register_frontend_files( | $file, |  |
> | $type, |  |
> | $target | = | 'head',
> | $media | = | 'screen',
> | $iehack | = | '' | )

Register JS- or CSS-files to be loaded into the page’s head-section.

> function opf_register_onload_event( | $function_name | )

Register an Javascript onload-function inside page’s head-section, using window.attachEvent() or window.addEventListener().

> function opf_register_onload( | $script | )

Register an Javascript script onload-function inside page’s body-section.

> function opf_register_document_ready( | $js | )

Register an Javascript onload-event inside page’s head-section, using jquery’s jQuery(document).ready()

> function opf_find_class( | $content, |  |
> | $match, |  |
> | $tag | = | '',
> | $attr | = | 'class' | )

Check whether a class (or any other attribute) is present in content.

> function opf_add_class( | & | $content,
> |  | $class,
> |  | $tag | )

Add a class to a present HTML-tag, i.e.

> function opf_add_class_to_class( | & | $content, |  |
> |  | $class, |  |
> |  | $present_class, |  |
> |  | $tag | = | '' | )

Add a class to an already present class.

> function opf_add_class_to_attr( | & | $content, |  |
> |  | $class, |  |
> |  | $attr, |  |
> |  | $value, |  |
> |  | $tag | = | '' | )

Add a class to all HTML-tags that has a given attribute.

> function opf_cut_extract( | & | $content, |  |
> |  | $regex, |  |
> |  | $subpattern | = | 0,
> |  | $modifers | = | 'iU',
> |  | $delimiter | = | '~',
> |  | $extracts | = | '' | )

Cuts pieces out of content using a regular expression and replace them by placeholders.

> function opf_glue_extract( | & | $content,
> |  | $extracts | )

bool opf_glue_extract( string &$content, string $extracts )

> function opf_filter_get_data( | $name | = | '' | )

Fetch data from filter.

> function opf_filter_get_rel_pos( | $name | )

Checks if a given filter was or will be executed.

> function opf_filter_exists( | $name, |  |
> | $verbose | = | FALSE | )

Checks whether a given filter exists

> function opf_is_childpage( | $child,
> | $parent | )

Checks whether a page is a subpage of a given page (or the same page)

> function opf_filter_is_active( | $name | )

Checkes whether a given filter is active for the actual module and page_id

> function opf_filter_get_additional_values()

Receive additional filter arguments

> function opf_filter_name_to_setting( | $name | )

For WBCE 1.2: This function converts the name of a filter to the settings string which is associated with the active/inactive state of the given filter name.
Close