File/PHPmyBrowser/functions.php

Description

This file contains all functions used by PHPmyBrowser.

See all the print_... functions that are used in templates.

If you want to add functions, create a functions.php in your custom folder.

Constants
UTF8 = true,true (line 1729)

A constant used by entities(String, boolean)

ISO = false,true (line 1735)

A constant used by entities(String, boolean)

RETURNS = true (line 1974)

For print_xxx functions, the last parameter set to true don't echo to HTML flow but returns the content to be echo()ed.

  1. $a = print_xxx(..., true)
returns in $a var.

You can replace true by RETURNS, that's easier :)

  1. $a = print_xxx(..., RETURNS);

This parameter is optional for all print_xxx functions, it's turned to false by default.

IMG_WIDTH = (line 3058)

For getimagesize() function, the array contains image width at index 0, and height at index 1.

IMG_HEIGHT = 1 (line 3059)

For getimagesize() function, the array contains image width at index 0, and height at index 1.

Functions
makeURL (line 306)

Create a correct URL to browse a given directory / Crée l'URL appropriée pour parcourir un répertoire donné.

Just a little trick : add a '|' at first char of $wpath if you want to automatically add path to current folder.

string makeURL ([string $wpath = ' '], [string $wsort = ' '], [string $ordre = ' '])
  • string $wpath: path to browse
  • string $wsort: sort criteria
  • string $ordre: sort order
makeFields (line 326)

Return hidden fields for forms / Renvoie les champs cachés utiles pour les formulaires

string makeFields ([string $wpath = ' '], [string $wsort = ' '], [string $ordre = ' '])
  • string $wpath: path to browse
  • string $wsort: sort criteria
  • string $ordre: sort order
write_hits (line 792)

Save hits (number of downloads) in the count file.

If your plug-in need to store the number of download/view of a file, write :

  1. $hits[$filename]++;
  2. write_hits();
or see in download.php how I add a little test to avoid warnings.

void write_hits ()
file_is_type (line 1147)

Returns true if $filename is $type type or $type extension.

void file_is_type (string $filename, string $type)
  • string $filename
  • string $type
utf8entities (line 1477)

takes a string of utf-8 encoded characters and converts it to a string of unicode entities

each unicode entitiy has the form &#nnnnn; n={0..9} and can be displayed by utf-8 supporting browsers

string utf8entities (mixed $str, string $source)
  • string $source: Encoded using UTF-8
entities (line 1718)

Return $source in choosen or default entities : call htmlentities or utf8entities.

The 2nd parameter is a boolean, false return htmlentities()ed $source, true return utf8entities()ed $source string. Instead of true or false, you can use the constants UTF8 and ISO.

string entities (string $source, [boolean $isUTF8 = false])
  • string $source
  • boolean $isUTF8: can be UTF8 or ISO (without quotes, these are constants)
isUTF8 (line 1754)

Returns true if the string or array of string is encoded in UTF8.

Example of use. If you want to know if a file is saved in UTF8 format :

  1. $array = file('one file.txt');
  2. $isUTF8 = isUTF8($array);
  3. foreach($array as $key=>$val)
  4. {
  5. echo $isUTF8?utf8entities($val)
  6. :htmlentities($val);
  7. //or echo entities($val, $isUTF8);
  8. }

boolean isUTF8 (mixed $string)
  • mixed $string: A string, or an array from a file() function.
get_files (line 1794)

Returns an array with only files

If you want to list all files, use :

  1. foreach(get_files() as $index=>$v)
  2. //$index is really important, $v is not...
  3. {
  4. //do what you want here, for example print_name()
  5. print_name();
  6. echo '<br/>';
  7. }

You can add a parameter : the type of file or extension you want.
If you only want jpg, gif... call :

  1. foreach(get_files('webimage') as $index=>$v)
  2. {
  3. //here you have only jpg, gif... images :-)
  4. }

  • todo: Accept multiple type/extension, separated by a |
array get_files ([string $type = ''])
  • string $type: The type or extension of files you want (e.g. 'webimage', 'txt'...), an empty value return all files.
get_folders (line 1821)

Returns an array with only folders.

If you want to list all folders, use :

  1. foreach(get_folders() as $index=>$v)
  2. //$index is really important, $v is not...
  3. {
  4. //do what you want here, for example print_name()
  5. }

array get_folders ([boolean $addParentFolder = true])
  • boolean $addParentFolder: By default this list include the parent folder '..'. If you don't want it, add a false parameter.
get_files_and_folders (line 1855)

Returns an array with all files and folders.

When you want to list all content of the current folder, use :

  1. foreach(get_files_and_folders() as $index=>$v)
  2. //$index is really important, $v is not...
  3. {
  4. //do what you want here, for example print_name()
  5. }

array get_files_and_folders ([boolean $addParentFolder = true])
  • boolean $addParentFolder: By default this list include the parent folder '..'. If you don't want it, add a false parameter.
is_a_directory (line 1884)

Return true if the current entry in the list is a directory, else return false

Example of use :

  1. foreach(get_files_and_folders() as $index=>$v)
  2. //$index is really important, $v is not...
  3. {
  4. print_name();
  5. if (is_a_directory()) echo ' is a folder';
  6. else echo ' is a file';
  7. echo '<br/>';
  8. }

boolean is_a_directory ([int $idx = null])
  • int $idx: If null (recommanded), take the current index
is_parent_folder (line 1905)

Return a boolean that tells if the current entry is the '..' parent folder or not.

  1. foreach(get_files_and_folders() as $index=>$v)
  2. {
  3. if (is_parent_folder())
  4. //special stuff for this special folder
  5. else
  6. {
  7. //
  8. }
  9. }

boolean is_parent_folder ([int $idx = null])
  • int $idx: If null (recommanded), take the current index
get_parent_folder (line 1927)

Return true if parent directory '..' is in the list, and set the current entry to '..'.

Example of use : you want to display a conditional link, display it only if we can browse to '..'.

  1. if (get_parent_folder())
  2. {
  3. print_icon_name_link();
  4. //...what you want for this very special folder
  5. }
get_parent_folder is used in some templates when we want to display it first.

boolean get_parent_folder ()
file_is (line 1956)

Return true if the current file, is $type type, or $type extension.

For example :

  1. while(get_files)
  2. {
  3. if (file_is('webimage'))
  4. { ... }
  5. else if (file_is{'mp3'})
  6. ...
  7. }
Note that get_files($type) returns only files of $type type...

boolean file_is (string $type)
  • string $type
print_css_file (line 1988)

Echo the CSS file for the template.

If your template is called mytemplate, the php is templates/mytemplate.php, the css must be templates/mytemplate.css.

If your template doesn't have css, it returns default.css.

  • return: A string if $return is true, nothing else.
string print_css_file ([boolean $return = false])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
print_path (line 2020)

Print the current path

Return the current path /path/to/dir, for example :

  1. <title>PHPmyBrowser -
  2. <?php echo print_path(); ?></title>

2 optionals parameters / 2 paramètres optionnels

  • a separator of the dir namss withouth slashes /
    séparateur des noms de répertoires, qui sont alors affichés sans le slash /
    print_path_with_links(' > ') ==> / > path > to > dir
  • a first word which replace the root displayed as '/'. You can set 'Home'
    le premier mot qui remplace le '/' initial symbolisant la racine. On peut mettre 'Accueil'
    print_path_with_links(' > ', 'Home') ==> Home > path > to > dir

  • return: A string if $return is true, nothing else.
string print_path ([string $sep = ''], [string $home = '/'], [boolean $return = false])
  • string $sep
  • string $home
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
print_path_with_links (line 2080)

Print the current path with links

Print the current path with links /path/to/dir is cutted in /<kbd>, <kbd>/path, /to and /dir which are links to browse /, /path, /path/to and /path/to/dir.

Affiche le chemin courant avec des liens /le/long/chemin est découpé en /, /le, /long et /chemin qui sont des liens pour parcourir directement /, /le, /le/long ou /le/long/chemin.

  1. <h2><?php echo print_path_with_links(); ?></h2>

4 optionals parameters / 4 paramètres optionnels :

  • a separator of the dir namss withouth slashes /
    séparateur des noms de répertoires, qui sont alors affichés sans le slash /
    print_path_with_links(' > ') ==> / > path > to > dir
  • a first word which replace the root displayed as '/'. You can set 'Home'
    le premier mot qui remplace le '/' initial symbolisant la racine. On peut mettre 'Accueil'
    print_path_with_links(' > ', 'Home') ==> Home > path > to > dir
  • "brothers" folders of current dir can be displayed in a select list to browse them quickly
    Les répertoires "frères" du répertoire courrant peuvent être affiché dans une liste déroulante.
    true => enable/active
    false => disable/désactive
  • Image for the submit button if there is a select. If '' then it'll be a 'OK' button.
    The image (e.g. 'go.gif') must be in templates/.../images.
    Image pour valider le choix dans le select. Si '' alors ça sera un bouton 'OK' tout simple.
    L'image (par ex: 'go.gif') doit être placée dans templates/.../images.
If the 3rd parameter is true, you can add this optionals parameters to custom the <select> list.
Si le 3e parameter est true, voici d'autres paramètres optionels pour personnaliser la liste déroulante <select>.
  • $color1 = '#123456' or $color1 = 'cssclass' for each options
  • $color2 = '#654321' or $color2 = 'anothercssclass', used if you select gradient or alternate in next parameter.
  • $style = 'gradient' => a gradient from $color1 to $color2 if they are #xxxxxx
    $style = 'alternate' => alternate between $color1 and $color2 (they can be colors #xxxxxx or css styles).

  • return: A string if $return is true, nothing else.
string print_path_with_links ([string $sep = ''], [string $home = ''], [bool $brother = false], [string $button = ''], [string $color1 = ''], [string $color2 = ''], [string $style = ''], [boolean $return = false])
  • string $sep: Separator
  • string $home: If separator != '/', name of the "Home" directory
  • bool $brother: true display "brother" folders in a <select> list
  • string $button: '' (OK) or name of an image in templates/.../images for submit button
  • string $color1: Color '#rrggbb' or 'cssclass'
  • string $color2: Color '#rrggbb' or 'cssclass'
  • string $style: 'gradient' or 'alternate'
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
print_text (line 2250)

Print one of the admin texts stored in the XML file.

The "reference" can be 'Header1', 'Header2', 'Footer1', 'Copyright_Notice', 'Before_Upload', 'News'... or what you want.
For example, insert

  1. print_text('Header1');
in top of the page.

If a text exists (in xml file $COMMENT_file), it'll be displayed. Administrator will have a link to Add/Edit the text.
So you place as many texts as you want. PHPmyBrowser, more flexible and powerful ! ;-)

La "référence" est un mot du genre 'En-tete1', 'Pied1', 'Copyright', 'Avant_Upload', 'Annonce'.... ce que vous voulez.
Par exemple mettez

  1. print_text('En-tete1');
en haut de page.

Si un texte existe (stocké dans le fichier $COMMENT_file) il sera affiché. L'administrateur verra un lien "Ajouter/Modifier le texte".
Ainsi vous placez autant de textes que vous voulez sur la page. Plus de souplesse et de possibilités avec PHPmyBrowser ! ;-)

  • return: A string if $return is true, nothing else.
string print_text (string $reference, [boolean $return = false])
  • string $reference
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
print_flags (line 2301)

Print flags to choose language / Affiche les drapeaux pour le choix de la langue

If there is only one language allowed in $language var => no flags S'il n'y a qu'une langue autorisée (variable $language) => aucun drapeau

First parameter can be 'flag' or 'list'. Display flags, or a select list. By default (''), it's 'list'.

  • return: A string if $return is true, nothing else.
  • todo: Add gif flag images
string print_flags ([string $type = ''], [boolean $return = false])
  • string $type
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
print_sort_link (line 2361)

Print link to change sort criteria and order.

The sort parameter must be / le paramètre sort doit être :

  • 'n' => by file Names / par Nom de fichier
  • 't' => by file Type / par Type de fichier
  • 's' => by file Size / par taille de fichier (size=taille)
  • 'd' => by file Date / par Date de fichier
Return a default text, or the specified text with link to sort the list by 'sort'

Retourne un texte par défaut, ou le texte spécifié, sous forme de lien pour trier selon le critère 'sort'

string print_sort_link (mixed $wsort, [string $text = ''], [boolean $return = false], string $sort)
  • string $sort: 'n', 't', 's' or 'd'
  • string $text: If empty, it uses the predefined texts in language file.
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
print_icon_name_link (line 2406)

Print icon + a little blank + folder/file name as a link.

Affiche icone + petit blanc + nom du répertoire ou fichier en lien.

  • return: A string if $return is true, nothing else.
string print_icon_name_link ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_icon_name (line 2426)

Print icon + a little blank + folder/file name without link

Affiche icone + petit blanc + nom du répertoire ou fichier, sans lien

string print_icon_name ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_name_link (line 2444)

Print folder/file name as a link or $ClickAction1.

Affiche le nom du répertoire ou du fichier avec le lien ou $ClickAction1

string print_name_link ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_name (line 2461)

Print folder/file name without link

Affiche le nom du répertoire ou fichier sans lien

string print_name ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_link (line 2481)

Perform the $ClickAction1.

Execute le $ClickAction1

  • return: A string if $return is true, nothing else.
  • see: $ClickAction1
string print_link ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_link_end (line 2512)

Print the end of the link </a> or $ClickAction2.

Affiche la fin du lien </a> ou $ClickAction2.

  • return: A string if $return is true, nothing else.
  • see: $ClickAction2
string print_link_end ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_icon_link (line 2539)

Print icon as a link to browse/download/... perform the $ClickAction1.

Affiche icone en lien pour parcourir/downloader/... réaliser $ClickAction1.

  • return: A string if $return is true, nothing else.
  • see: $ClickAction1
string print_icon_link ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_icon (line 2555)

Print icon of the folder/file

Affiche l'icône du répertoire ou du fichier

  • return: A string if $return is true, nothing else.
string print_icon ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_new (line 2576)

Return a little picture that indicates that the file is new usually displayed with the name or with the date.

Renvoie une image qui indique que le fichier est récent de préférence afficher à côté du nom ou de la date.

  • return: A string if $return is true, nothing else.
string print_new ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_addon (line 2601)

Execute "on the fly" the add-ons. In most case returns an image to call a plug-in in a popup or new page.

Exécute "à la volée" les extensions (addon en anglais) qui retournent généralement des petites images pour appeler un plug-in.

string print_addon ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_type (line 2629)

Return the "type" label (Image GIF, Word...) of the file

Renvoie le libellé du "type" (Image GIF, Word...) du fichier

  • return: A string if $return is true, nothing else.
  • see: types.php
string print_type ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_size (line 2645)

Print the file size in correct format

Affiche la taille du fichier avec un formatage adapté

  • return: A string if $return is true, nothing else.
string print_size ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_hits (line 2665)

Print the number of download (hits) if enabled.

Affiche la nombre de téléchargements si activé.

  • return: A string if $return is true, nothing else.
string print_hits ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_date (line 2692)

Return the formated date of the folder or file

Renvoie la date formatée du répertoire ou du fichier

  • return: A string if $return is true, nothing else.
string print_date ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_nb_files (line 2708)

Print "12 folders and 5 files"...

Affiche "12 dossiers et 5 fichiers"...

  • return: A string if $return is true, nothing else.
string print_nb_files ([boolean $return = false])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
print_new_legend (line 2729)

Print "new" legend

If some files are new (and this features enabled...), display the new logo and a little text like "new file since X days" or "since <last visit date>"

Si certains fichiers sont récents (et l'option activée...), affiche le logo et un texte du genre "nouveaux fichiers depuis X jours" ou "depuis <date de dernière visite>".

  • return: A string if $return is true, nothing else.
string print_new_legend ([boolean $return = false])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
print_nb_file_per_type (line 2755)

Display the number of file of each type listed with an icon.

Affiche le nombre de fichiers de chaque type listé, avec une icône. Example :

  • 5 WinAmp
  • 3 archive WinZip
  • 1 texte
  • 4 image JPEG....

  • return: A string if $return is true, nothing else.
string print_nb_file_per_type ([boolean $return = false])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
print_total_size (line 2790)

Display the total dir size (sum of all file size)

Affiche la taille totale du répertoire (somme des tailles de fichiers)

  • return: A string if $return is true, nothing else.
string print_total_size ([boolean $return = false])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
print_total_hits (line 2807)

Display the total hits (sum of hits of all files in the browsed folder)

Affiche le nombre total de téléchargement (somme des nb de téléchargements des fichiers du répertoire parcouru).

  • return: A string if $return is true, nothing else.
string print_total_hits ([boolean $return = false])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
file_has_comment (line 2822)

Return true if the file have a comment / Retourne vrai si le fichier a un commentaire

boolean file_has_comment ([int $idx = null])
  • int $idx: If null (recommanded), take the current index
print_comment (line 2837)

Print comments of the file / Affiche les commentaires sur le fichier

  • return: A string if $return is true, nothing else.
string print_comment ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_add_comment (line 2866)

print a link to add a comment / Affiche un lien pour ajouter un commentaire

The parameter $icontext tells if it prints icon, icon and text ('Add a comment') or only text.

Le paramètre $icontext détermine ce qui sera affiché, une icône, le texte ('Ajouter un commentaire') ou les 2.

Values / Valeurs possibles :

  • 'icon' : icon only / uniquement l'icône
  • 'icon_text' : icon and text / icône et texte
  • 'text' : text only / uniquement le texte

  • return: A string if $return is true, nothing else.
string print_add_comment ([string $icontext = 'icon_text'], [boolean $return = false], [int $idx = null])
  • string $icontext
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_upload_form (line 2907)

Display the form for file upload

Display the upload form if $UPLOAD_enable is true the upload form contain one or more file input fields, an "Upload" button, and texts for accepted/forbidden formats, and $$UPLOAD_maxFileSize.

Affiche le formulaire d'upload si $UPLOAD_enable est activé.

Le formulaire contient un ou plusieurs champs pour choisir des fichiers, un bouton pour upload, des textes pour afficher les fichiers acceptés/refusés et la taille maximale.

string print_upload_form ([boolean $return = false])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
print_create_folder_form (line 2955)

Display the form to create a new folder, if enabled.

  • return: The form in a string if return = true, else it prints directly
  • todo: to be continued...
  • see: $CREATEFOLDER_enable
string print_create_folder_form ([boolean $return = false])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
print_admin_tasks (line 2989)

Print icons for admin tasks, like copy, delete, move, rename / Affiche des icônes pour les tâches d'administration (copier, déplacer, renommer, supprimer).

If $adminPHPmyBrowser is false, then print nothing ;-) Si $adminPHPmyBrowser vaut false, alors n'affiche rien ;-)

  • return: A string if $return is true, nothing else.
  • todo: Add admin task (rename, delete, copy/cut...)
string print_admin_tasks ([boolean $return = false], [int $idx = null])
  • boolean $return: false or no parameter prints the text on output, true returns it in a string
  • int $idx: If null (recommanded), take the current index
print_execution_time (line 3012)

Display the execution time of the script / Affiche le temps d'exécution de la page

string print_execution_time ([boolean $return = false])
  • boolean $return
print_logo (line 3029)

It's nice from you if you print PHPmyBrowser logo at the bottom of the pages.

Ça serait sympa de votre part de laisser le logo de PHPmyBrowser en bas de vos pages,

string print_logo ([boolean $return = false])
  • boolean $return
isGDSupported (line 3069)

Given the name of a file, this function returns true if this file seems to be supported by GD (test on extension).

boolean isGDSupported (string $filename)
  • string $filename
imagecreatefromextension (line 3090)

Open an image with the appropriate function, depending on the extension of the file, and return a resource GD can use.

It's a way to use easily GD functions imagecreatefrompng, imagecreatefromjpeg...

resource imagecreatefromextension (string $filename)
  • string $filename
imageextension (line 3110)

Save an image in the format specified by the extension of the filename.

It's a way to use easily GD functions imagecreatefrompng, imagecreatefromjpeg...

void imageextension (resource $resource, string $filename)
  • resource $resource: An GD image resource
  • string $filename: The name of the file to be saved
imageresize (line 3159)

Resize an image if GD support image source format.

It saves into image destination file, if possible in the format specified by its extension.

For example : source is 'image1.jpg', destination is 'imagedest.png', this function try to load the JPEG source, resize it, and save it in PNG format. If PNG is not supported, it'll be saved in source format (JPEG in this example).

About the destination size, the image keeps its proportions, and it's resized to fit the best the area.

If the destination format is not supported, the extension of the destination file is changed to extension of the source. The name of the destination file is returned.

void imageresize (string $img_src, string $img_dest, int $max_w, int $max_h)
  • string $img_src: Path to source image
  • string $img_dest: Path to destination image
  • int $max_w: Destination max width
  • int $max_h: Destination max height return string

Documentation generated on Sat, 28 Aug 2004 16:53:08 +0200 by phpDocumentor 1.3.0RC3