Compare commits

..

No commits in common. "b25e0b12c67e2faaec4d773f97257948bc45be43" and "e3bbb94f466e17a7fc8b66aeda4ef64a6e6e0cc5" have entirely different histories.

1273 changed files with 31905 additions and 137148 deletions

View file

@ -93,7 +93,8 @@ ErrorDocument 404 /index.php
<IfModule mod_headers.c>
# prevent site from being loaded in an iframe on another site
# you will need to remove this one if you want to allow external iframes
Header always append X-Frame-Options SAMEORIGIN
# Header always append X-Frame-Options SAMEORIGIN
Header always set X-Frame-Options SAMEORIGIN
# To prevent cross site scripting (IE8+ proprietary)
Header set X-XSS-Protection "1; mode=block"
@ -390,7 +391,7 @@ DirectoryIndex index.php index.html index.htm
RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/modules/.*\.(php|inc|tpl|module|info\.json)$ [NC,OR]
# Block access to any software identifying txt, markdown or textile files
RewriteCond %{REQUEST_URI} (^|/)(COPYRIGHT|INSTALL|README|htaccess)\.(txt|md|textile)$ [NC,OR]
RewriteCond %{REQUEST_URI} (^|/)(COPYRIGHT|INSTALL|README|LICENSE|htaccess)\.(txt|md|textile)$ [NC,OR]
# Block potential arbitrary backup files within site directories for things like config
RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/(config[^/]*/?|[^/]+\.php.*)$ [NC,OR]
@ -448,7 +449,7 @@ DirectoryIndex index.php index.html index.htm
RewriteCond %{REQUEST_FILENAME} !(favicon\.ico|robots\.txt)
# -----------------------------------------------------------------------------------------------
# 18. Optionally (O) prevent PW from serving some file types, or anything in /site/assets/.
# 18. Optionally (O) prevent PW from attempting to serve images or anything in /site/assets/.
# Both of these lines are optional, but can help to reduce server load. However, they
# are not compatible with the $config->pagefileSecure option (if enabled) and they
# may produce an Apache 404 rather than your regular 404. You may uncomment the two lines
@ -458,7 +459,7 @@ DirectoryIndex index.php index.html index.htm
# section #2 above that makes ProcessWire the 404 handler.
# -----------------------------------------------------------------------------------------------
# RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|gif|png|ico|webp|svg|js|css)$ [NC]
# RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|gif|png|ico|webp|svg)$ [NC]
# RewriteCond %{REQUEST_FILENAME} !(^|/)site/assets/
# -----------------------------------------------------------------------------------------------
@ -478,4 +479,5 @@ DirectoryIndex index.php index.html index.htm
#################################################################################################
# END PROCESSWIRE HTACCESS DIRECTIVES
#################################################################################################
#################################################################################################

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,18 @@
{
"file": "site\/templates\/_foot.php",
"textdomain": "site--templates--_foot-php",
"translations": {
"0c7c073ba4d9912cd6a408247a71d95a": {
"text": "Pie"
},
"d63d94f43418f66bd27ee27a62ec88ef": {
"text": "Todos los derechos reservados"
},
"4e72c9aec0195278fac9b0abfa52bc45": {
"text": "Dise\u00f1ado y desarrollado por"
},
"0ab28f00ad391c481fe4faab23d0d2fb": {
"text": "P\u00e1gina creada en %.6f segundos."
}
}
}

View file

@ -1,15 +1,18 @@
{
"file": "site\/templates\/layout\/func.php",
"textdomain": "site--templates--layout--func-php",
"file": "site\/templates\/_func.php",
"textdomain": "site--templates--_func-php",
"translations": {
"2d582d5d1db1446ef1b3f8d1ea1bfc90": {
"text": "P\u00e1gina actual"
},
"887552568b44443872f57a4d92697085": {
"text": "Editar"
},
"27cd58c2dab7be2c233dcc429d1517d6": {
"text": "Ver detalles"
"0aef62c2fab347cd350a3eb4263cd85c": {
"text": "Autor"
},
"82a3fdfb69baf6fb0be4dae7be23c8d1": {
"text": "Leer m\u00e1s."
"text": "Leer m\u00e1s"
},
"d42d3a059f66d7c7922c501182602073": {
"text": "%d publicaci\u00f3n"

View file

@ -1,6 +1,6 @@
{
"file": "site\/templates\/layout\/partial\/main_head.php",
"textdomain": "site--templates--layout--partial--main_head-php",
"file": "site\/templates\/_head.php",
"textdomain": "site--templates--_head-php",
"translations": {
"7679c0bdbd87c1984bd611c24b3cd0cb": {
"text": "es"
@ -8,6 +8,15 @@
"01bea08b9a838113ed66226778ce6108": {
"text": "Saltar al contenido"
},
"9a59fd41dc60086c1ba0b5ef77e05d4e": {
"text": "Logotipo de Praia de Seselle Apartamentos Tur\u00edsticos"
},
"4da98e72b078f4590386d08a0a363404": {
"text": "Abrir\/Cerrar el men\u00fa"
},
"6772cbe29a38577eeabce0d6ca81817d": {
"text": "Men\u00fa"
},
"dd8edfa3a268c9edb7199ed7da21551c": {
"text": "Cerrar sesi\u00f3n"
},
@ -16,12 +25,6 @@
},
"daf881397f6fa569bf059c21131e3690": {
"text": "Iniciar sesi\u00f3n"
},
"9a59fd41dc60086c1ba0b5ef77e05d4e": {
"text": "Logotipo de Praia de Seselle Apartamentos Tur\u00edsticos"
},
"c0dcc3911178249b82de663d603e5bf8": {
"text": "Buscar"
}
}
}

View file

@ -1,6 +1,6 @@
{
"file": "site\/templates\/layout\/partial\/xes-foot.php",
"textdomain": "site--templates--layout--partial--xes-foot-php",
"file": "site\/templates\/_xes-foot.php",
"textdomain": "site--templates--_xes-foot-php",
"translations": {
"0c7c073ba4d9912cd6a408247a71d95a": {
"text": "Pie"

View file

@ -1,6 +1,6 @@
{
"file": "site\/templates\/layout\/partial\/xes-head.php",
"textdomain": "site--templates--layout--partial--xes-head-php",
"file": "site\/templates\/_xes-head.php",
"textdomain": "site--templates--_xes-head-php",
"translations": {
"7679c0bdbd87c1984bd611c24b3cd0cb": {
"text": "es"

View file

@ -1,21 +0,0 @@
{
"file": "site\/templates\/atopar.php",
"textdomain": "site--templates--atopar-php",
"translations": {
"00ea1c0095523d1c335c9cdffa5a15c3": {
"text": "Se encontr\u00f3 %d p\u00e1gina"
},
"b171905a249dce55e10c9ae749a227bf": {
"text": "Se encontraron %d p\u00e1ginas"
},
"c1389106a2604e0d368b3a26331c46d2": {
"text": "Resultados de la b\u00fasqueda"
},
"73b96a0aa64d9eabb0a1ed94da6f2326": {
"text": "Mapa del sitio"
},
"098e98d0a4f789855fabd8cc3b7c00c7": {
"text": "Lo sentimos, no se encontraron resultados"
}
}
}

View file

@ -1,27 +0,0 @@
{
"file": "site\/templates\/contacto.php",
"textdomain": "site--templates--contacto-php",
"translations": {
"c1caa1b411f1ff3e16584f9b176f26ca": {
"text": "Nombre"
},
"d48ce9ca3048973f9ae971b29829f855": {
"text": "Correo electr\u00f3nico"
},
"32196b9fdb128ed308a43011d824ad3b": {
"text": "Asunto"
},
"32426539888e5940060745c267c2bcfb": {
"text": "Mensaje"
},
"1b59395f058b6f30f307923e80c54d36": {
"text": "Enviar mensaje"
},
"3d36827d9ee8154da6c95b3794ebc5e5": {
"text": "Direcci\u00f3n"
},
"aad5e1f90361aacf2af5aa8b887ce602": {
"text": "Tel\u00e9fono"
}
}
}

View file

@ -1,15 +0,0 @@
{
"file": "site\/templates\/layout\/partial\/main_foot.php",
"textdomain": "site--templates--layout--partial--main_foot-php",
"translations": {
"9a59fd41dc60086c1ba0b5ef77e05d4e": {
"text": "Logotipo de Praia de Seselle Apartamentos Tur\u00edsticos"
},
"4e72c9aec0195278fac9b0abfa52bc45": {
"text": "Dise\u00f1ado y desarrollado por"
},
"0ab28f00ad391c481fe4faab23d0d2fb": {
"text": "P\u00e1gina creada en %.6f segundos."
}
}
}

View file

@ -0,0 +1,18 @@
{
"file": "site\/templates\/_foot.php",
"textdomain": "site--templates--_foot-php",
"translations": {
"0c7c073ba4d9912cd6a408247a71d95a": {
"text": "P\u00e9"
},
"d63d94f43418f66bd27ee27a62ec88ef": {
"text": "Todos os dereitos reservados"
},
"4e72c9aec0195278fac9b0abfa52bc45": {
"text": "Dese\u00f1ada e desenvolvida por"
},
"0ab28f00ad391c481fe4faab23d0d2fb": {
"text": "P\u00e1xina creada en %.6f segundos."
}
}
}

View file

@ -0,0 +1,24 @@
{
"file": "site\/templates\/_func.php",
"textdomain": "site--templates--_func-php",
"translations": {
"2d582d5d1db1446ef1b3f8d1ea1bfc90": {
"text": "P\u00e1xina actual"
},
"887552568b44443872f57a4d92697085": {
"text": "Editar"
},
"0aef62c2fab347cd350a3eb4263cd85c": {
"text": "Autor"
},
"82a3fdfb69baf6fb0be4dae7be23c8d1": {
"text": "Ler m\u00e1is"
},
"d42d3a059f66d7c7922c501182602073": {
"text": "%d publicaci\u00f3n"
},
"96d2fb5e7d8d946eaad05f309ae96e7c": {
"text": "%d publicaci\u00f3ns"
}
}
}

View file

@ -1,6 +1,6 @@
{
"file": "site\/templates\/layout\/partial\/main_head.php",
"textdomain": "site--templates--layout--partial--main_head-php",
"file": "site\/templates\/_head.php",
"textdomain": "site--templates--_head-php",
"translations": {
"7679c0bdbd87c1984bd611c24b3cd0cb": {
"text": "gl"
@ -8,6 +8,15 @@
"01bea08b9a838113ed66226778ce6108": {
"text": "Ir ao contido"
},
"9a59fd41dc60086c1ba0b5ef77e05d4e": {
"text": "Logotipo de Praia de Seselle Apartamentos Tur\u00edsticos"
},
"4da98e72b078f4590386d08a0a363404": {
"text": "Abrir\/Pechar o men\u00fa"
},
"6772cbe29a38577eeabce0d6ca81817d": {
"text": "Men\u00fa"
},
"dd8edfa3a268c9edb7199ed7da21551c": {
"text": "Pechar sesi\u00f3n"
},
@ -16,12 +25,6 @@
},
"daf881397f6fa569bf059c21131e3690": {
"text": "Iniciar sesi\u00f3n"
},
"9a59fd41dc60086c1ba0b5ef77e05d4e": {
"text": "Logotipo de Praia de Seselle Apartamentos Tur\u00edsticos"
},
"c0dcc3911178249b82de663d603e5bf8": {
"text": "Atopar"
}
}
}

View file

@ -1,6 +1,6 @@
{
"file": "site\/templates\/layout\/partial\/xes-foot.php",
"textdomain": "site--templates--layout--partial--xes-foot-php",
"file": "site\/templates\/_xes-foot.php",
"textdomain": "site--templates--_xes-foot-php",
"translations": {
"0c7c073ba4d9912cd6a408247a71d95a": {
"text": "P\u00e9"

View file

@ -1,6 +1,6 @@
{
"file": "site\/templates\/layout\/partial\/xes-head.php",
"textdomain": "site--templates--layout--partial--xes-head-php",
"file": "site\/templates\/_xes-head.php",
"textdomain": "site--templates--_xes-head-php",
"translations": {
"7679c0bdbd87c1984bd611c24b3cd0cb": {
"text": "gl"

View file

@ -1,21 +0,0 @@
{
"file": "site\/templates\/atopar.php",
"textdomain": "site--templates--atopar-php",
"translations": {
"00ea1c0095523d1c335c9cdffa5a15c3": {
"text": "Atopouse %d p\u00e1xina."
},
"b171905a249dce55e10c9ae749a227bf": {
"text": "Atop\u00e1ronse %d p\u00e1xinas."
},
"c1389106a2604e0d368b3a26331c46d2": {
"text": "Resultados da busca"
},
"73b96a0aa64d9eabb0a1ed94da6f2326": {
"text": "Mapa do sitio"
},
"098e98d0a4f789855fabd8cc3b7c00c7": {
"text": "Sent\u00edmolo, non se atoparon resultados"
}
}
}

View file

@ -1,27 +0,0 @@
{
"file": "site\/templates\/contacto.php",
"textdomain": "site--templates--contacto-php",
"translations": {
"c1caa1b411f1ff3e16584f9b176f26ca": {
"text": "Nome"
},
"d48ce9ca3048973f9ae971b29829f855": {
"text": "Correo electr\u00f3nico"
},
"32196b9fdb128ed308a43011d824ad3b": {
"text": "Asunto"
},
"32426539888e5940060745c267c2bcfb": {
"text": "Mensaxe"
},
"1b59395f058b6f30f307923e80c54d36": {
"text": "Enviar mensaxe"
},
"3d36827d9ee8154da6c95b3794ebc5e5": {
"text": "Enderezo"
},
"aad5e1f90361aacf2af5aa8b887ce602": {
"text": "Tel\u00e9fono"
}
}
}

View file

@ -1,21 +0,0 @@
{
"file": "site\/templates\/layout\/func.php",
"textdomain": "site--templates--layout--func-php",
"translations": {
"887552568b44443872f57a4d92697085": {
"text": "Editar."
},
"27cd58c2dab7be2c233dcc429d1517d6": {
"text": "Ver detalles."
},
"82a3fdfb69baf6fb0be4dae7be23c8d1": {
"text": "Ler m\u00e1is."
},
"d42d3a059f66d7c7922c501182602073": {
"text": "%d publicaci\u00f3n."
},
"96d2fb5e7d8d946eaad05f309ae96e7c": {
"text": "%d publicaci\u00f3ns"
}
}
}

View file

@ -1,15 +0,0 @@
{
"file": "site\/templates\/layout\/partial\/main_foot.php",
"textdomain": "site--templates--layout--partial--main_foot-php",
"translations": {
"9a59fd41dc60086c1ba0b5ef77e05d4e": {
"text": "Logotipo de Praia de Seselle Apartamentos Tur\u00edsticos"
},
"4e72c9aec0195278fac9b0abfa52bc45": {
"text": "Dese\u00f1ada e desenvolvida por"
},
"0ab28f00ad391c481fe4faab23d0d2fb": {
"text": "P\u00e1xina creada en %.6f segundos."
}
}
}

View file

@ -1,8 +1,11 @@
{
"file": "site\/templates\/layout\/partial\/main_foot.php",
"textdomain": "site--templates--layout--partial--main_foot-php",
"file": "site\/templates\/_foot.php",
"textdomain": "site--templates--_foot-php",
"translations": {
"9a59fd41dc60086c1ba0b5ef77e05d4e": {
"0c7c073ba4d9912cd6a408247a71d95a": {
"text": "="
},
"d63d94f43418f66bd27ee27a62ec88ef": {
"text": "="
},
"4e72c9aec0195278fac9b0abfa52bc45": {

View file

@ -1,11 +1,14 @@
{
"file": "site\/templates\/layout\/func.php",
"textdomain": "site--templates--layout--func-php",
"file": "site\/templates\/_func.php",
"textdomain": "site--templates--_func-php",
"translations": {
"887552568b44443872f57a4d92697085": {
"text": "="
},
"27cd58c2dab7be2c233dcc429d1517d6": {
"2d582d5d1db1446ef1b3f8d1ea1bfc90": {
"text": "="
},
"0aef62c2fab347cd350a3eb4263cd85c": {
"text": "="
},
"82a3fdfb69baf6fb0be4dae7be23c8d1": {

View file

@ -1,6 +1,6 @@
{
"file": "site\/templates\/layout\/partial\/main_head.php",
"textdomain": "site--templates--layout--partial--main_head-php",
"file": "site\/templates\/_head.php",
"textdomain": "site--templates--_head-php",
"translations": {
"7679c0bdbd87c1984bd611c24b3cd0cb": {
"text": "="
@ -8,6 +8,15 @@
"01bea08b9a838113ed66226778ce6108": {
"text": "="
},
"9a59fd41dc60086c1ba0b5ef77e05d4e": {
"text": "="
},
"4da98e72b078f4590386d08a0a363404": {
"text": "="
},
"6772cbe29a38577eeabce0d6ca81817d": {
"text": "="
},
"dd8edfa3a268c9edb7199ed7da21551c": {
"text": "="
},
@ -16,12 +25,6 @@
},
"daf881397f6fa569bf059c21131e3690": {
"text": "="
},
"9a59fd41dc60086c1ba0b5ef77e05d4e": {
"text": "="
},
"c0dcc3911178249b82de663d603e5bf8": {
"text": "="
}
}
}

View file

@ -1,6 +1,6 @@
{
"file": "site\/templates\/layout\/partial\/xes-foot.php",
"textdomain": "site--templates--layout--partial--xes-foot-php",
"file": "site\/templates\/_xes-foot.php",
"textdomain": "site--templates--_xes-foot-php",
"translations": {
"0c7c073ba4d9912cd6a408247a71d95a": {
"text": "="

View file

@ -1,6 +1,6 @@
{
"file": "site\/templates\/layout\/partial\/xes-head.php",
"textdomain": "site--templates--layout--partial--xes-head-php",
"file": "site\/templates\/_xes-head.php",
"textdomain": "site--templates--_xes-head-php",
"translations": {
"7679c0bdbd87c1984bd611c24b3cd0cb": {
"text": "="
@ -17,10 +17,10 @@
"6772cbe29a38577eeabce0d6ca81817d": {
"text": "="
},
"dd8edfa3a268c9edb7199ed7da21551c": {
"636ca6b95f5129da8b6de675e1793b9b": {
"text": "="
},
"636ca6b95f5129da8b6de675e1793b9b": {
"dd8edfa3a268c9edb7199ed7da21551c": {
"text": "="
}
}

View file

@ -1,21 +0,0 @@
{
"file": "site\/templates\/atopar.php",
"textdomain": "site--templates--atopar-php",
"translations": {
"00ea1c0095523d1c335c9cdffa5a15c3": {
"text": "="
},
"b171905a249dce55e10c9ae749a227bf": {
"text": "="
},
"c1389106a2604e0d368b3a26331c46d2": {
"text": "="
},
"73b96a0aa64d9eabb0a1ed94da6f2326": {
"text": "="
},
"098e98d0a4f789855fabd8cc3b7c00c7": {
"text": "="
}
}
}

View file

@ -1,27 +0,0 @@
{
"file": "site\/templates\/contacto.php",
"textdomain": "site--templates--contacto-php",
"translations": {
"c1caa1b411f1ff3e16584f9b176f26ca": {
"text": "="
},
"d48ce9ca3048973f9ae971b29829f855": {
"text": "="
},
"32196b9fdb128ed308a43011d824ad3b": {
"text": "="
},
"32426539888e5940060745c267c2bcfb": {
"text": "="
},
"1b59395f058b6f30f307923e80c54d36": {
"text": "="
},
"3d36827d9ee8154da6c95b3794ebc5e5": {
"text": "="
},
"aad5e1f90361aacf2af5aa8b887ce602": {
"text": "="
}
}
}

View file

@ -1,4 +0,0 @@
# Auto detect text files and perform LF normalization
* text=auto
# Show correct language for ProcessWire .module
*.module linguist-language=PHP

View file

@ -1,5 +0,0 @@
dematte/*
jscolor-2.0.4/*
colorpicker/*
InputfieldColor.js
.DS_Store

View file

@ -1,336 +0,0 @@
<?php namespace ProcessWire;
/**
* ProcessWire Color Fieldtype
* Field that stores an 32Bit unsigned integer value to hold RGB colors and Alpha channel
*
* @author Christoph Thelen aka @kixe 2017/07/03
* @copyright © 2017 Christoph Thelen
* @license Licensed under GNU/GPL v3
* @link https://processwire.com/talk/topic/...
* @version 1.1.8
*
*
* @since 1.0.1 2017/07/05 - better validation, spectrum options modifiable
* @since 1.0.2 2017/07/09 - added default value option
* @since 1.0.3 2017/07/09 - added option for custom javascript
* @since 1.0.4 2017/08/18 - made # optional for input (pattern attribute)
* @since 1.0.5 2017/08/28 - optimized default color handling, added output format option array()
* @since 1.0.6 2017/10/07 - changed dec to hex conversion in function wakeupValue() from dechex() to base_convert() to be safe on 32bit systems
* @since 1.0.7 2017/10/08 - changed dec to hex conversion in function wakeupValue() from dechex() to custom function to be safe on 32bit systems
* @since 1.0.8 2018/09/08 - Installation error if PHP is running on 32-bit system and BCMath extension is not installed
* @since 1.0.9 2019/01/12 - fixed number format bug for rgba() and hsla() alpha channel if comma is forced as decimal separator by locale settings
* @since 1.1.0 2019/08/12 - better input check formatColorString()
* @since 1.1.1 2019/09/01 - fixed bug missing opacity if 0
* @since 1.1.2 2019/09/04 - fixed bug #5 FieldtypeColor index typo in var in function RGB2HSL() thanks to @junoforno
* @since 1.1.3 2019/10/10 - fixed bug #1 InputfieldColor - remove pattern attribute if spectrum color picker is used to prevent error in Chrome
* @since 1.1.4 2020/03/21 - fixed number format bug for hsl() output: use dot instead of comma as decimal separator independent from language setup
* @since 1.1.5 2020/05/15 switched to ProcessWire namespace
* @since 1.1.6 2021/10/04 added comparison functions getClosestColorName(), getColorDistance(), getLuminanceDistance()
* @since 1.1.7 2021/10/10 added output format option: array([0,255], [0,255], [0,255]) indexed array: R,G,B
* @since 1.1.8 2023/07/17 added output format option: array([0,255], [0,255], [0,255]) indexed array: H,S,L
*
* made for ProcessWire 3.x by Ryan Cramer
* https://processwire.com
*
*/
class FieldtypeColor extends Fieldtype {
public static function getModuleInfo() {
return array(
'title' => 'Color',
'version' => 118,
'summary' => 'Field that stores a color value as 32bit integer reflecting a RGBA value. Many options for Input (HTML5 Inputfield Color, Textfield with changing background, various jQuery/JS ColorPickers, custom jQuery/JS/CSS) and Output (RGB, RGBA, HSL, HSLA, HEX, Array).',
'installs' => 'InputfieldColor',
'href' => 'https://processwire.com/talk/topic/16679-fieldtypecolor/'
);
}
public function ___getCompatibleFieldtypes(Field $field) {
$fieldtypes = $this->wire(new Fieldtypes());
foreach($this->wire('fieldtypes') as $fieldtype) {
if(!$fieldtype instanceof FieldtypeInteger &&
!$fieldtype instanceof FieldtypeColor &&
$fieldtype != 'FieldtypeText') {
$fieldtypes->remove($fieldtype);
}
}
return $fieldtypes;
}
public function getInputfield(Page $page, Field $field) {
$inputfield = $this->modules->get('InputfieldColor');
$inputfield->initValue = $this->sanitizeValue($page, $field, $field->defaultValue);
$inputfield->class = $this->className();
return $inputfield;
}
public function sanitizeValue(Page $page, Field $field, $value) {
if (!$value) return $value;
$value = ltrim($value, '#');
if (strlen($value) == 8) return $value;
else if (strlen($value) == 6) return 'ff'.$value; // add alpha channel
else throw New WireException('Expecting Hex color string (length 6 or 8 digits) with optional leading \'#\'');
}
public function sleepValue(Page $page, Field $field, $value) {
return hexdec($value);
}
public function wakeupValue(Page $page, Field $field, $value) {
if (!$value) return $value;
if (function_exists("bcmod")) return str_pad(self::bcdechex($value), 8, '0', STR_PAD_LEFT); // BCMath extension required
return str_pad(dechex($value), 8, '0', STR_PAD_LEFT); // 64-bit system required
}
/**
* Converts a number from decimal to hex (BCMath extension required)
* returns precice result even if number is bigger than PHP_INT_MAX (safe for 32bit systems)
*
* @param int/string/float number
* @return string
*
* @see http://php.net/manual/en/ref.bc.php#99130
*/
public static function bcdechex($dec) {
$last = bcmod("$dec", 16);
$remain = bcdiv(bcsub("$dec", $last), 16);
if($remain == 0) return dechex($last);
else return self::bcdechex($remain).dechex($last);
}
/**
* Converts a RGB color value to HSL. Conversion formula
* @param array of 3 color values R, G, and B [0, 255]
* @return array The HSL representation
*
* @see https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion/9493060#9493060
* @see http://en.wikipedia.org/wiki/HSL_color_space
*/
public function RGB2HSL(array $rgb) {
$rgb = array_map(function($v) { return $v/ 255; }, $rgb);
$max = max($rgb);
$min = min($rgb);
$hue = $sat = $light = ($max + $min) / 2;
if($max == $min) {
$hue = $sat = 0; // achromatic
} else {
$d = $max - $min;
$sat = $light > 0.5 ? $d / (2 - $max - $min) : $d / ($max + $min);
switch($max) {
case $rgb[0]:
$hue = ($rgb[1] - $rgb[2]) / $d + ($rgb[1] < $rgb[1] ? 6 : 0);
break;
case $rgb[1]:
$hue = ($rgb[2] - $rgb[0]) / $d + 2;
break;
case $rgb[2]:
$hue = ($rgb[0] - $rgb[1]) / $d + 4;
break;
}
$hue = $hue / 6;
}
// round and convert float to string with dot as decimal separator in any language
$hue = str_replace(',', '.', round($hue * 360));
$sat = str_replace(',', '.', round($sat * 100, 1));
$light = str_replace(',', '.', round($light * 100, 1));
return [$hue, $sat, $light];
}
/**
* Find the "naive" difference between two colors.
* @see https://php.tutorialink.com/finding-nearest-match-rgb-color-from-array-of-colors/
* @param int[] $color_a Three-element array with R,G,B color values 0-255.
* @param int[] $color_b Three-element array with R,G,B color values 0-255.
* @return int
*/
public function getColorDistance(array $color_a, array $color_b): int {
return
abs($color_a[0] - $color_b[0]) +
abs($color_a[1] - $color_b[1]) +
abs($color_a[2] - $color_b[2]);
}
/**
* Find the difference between two colors' luminance values.
* @see https://php.tutorialink.com/finding-nearest-match-rgb-color-from-array-of-colors/
* @param int[] $color_a Three-element array with R,G,B color values 0-255.
* @param int[] $color_b Three-element array with R,G,B color values 0-255.
* @return int
*/
public function getLuminanceDistance(array $color_a, array $color_b): int {
$luminance_f = function ($red, $green, $blue): int {
// Source: https://en.wikipedia.org/wiki/Relative_luminance
$luminance = (int) (0.2126 * $red + 0.7152 * $green + 0.0722 * $blue);
return $luminance;
};
return abs(
$luminance_f($color_a[0], $color_a[1], $color_a[2]) -
$luminance_f($color_b[0], $color_b[1], $color_b[2])
);
}
/**
* Find the closest named color
* @param hexcolor
* @return string
*/
public function getClosestColorName(string $color) {
$color = ltrim($color, '#');
if (strlen($color) == 6) $color = "ff$color";
if (strlen($color) != 8) throw new WireException("Invalid parameter. Expected hex string of 6 or 8 digits length with or without leading '#'.");
$color = $this->formatColorString($color, 9);
$palette = json_decode(file_get_contents(__DIR__ . '/colornames.json'), true);
$min = 765;
$match = null;
foreach ($palette as $name => $pcolor) {
$pcolor = $this->formatColorString("ff$pcolor", 9);
if ($pcolor === $color) return $name; // quick exit if full match
$distance = $this->getColorDistance($pcolor, $color);
if ($distance >= $min) continue;
$min = $distance;
$match = $name;
}
return $match;
}
/**
* Format value for output
*
*/
public function ___formatValue(Page $page, Field $field, $value) {
if (!$value) return null;
if ($field->outputFormat === 7) return $this->sleepValue($page, $field, $value);
return $this->formatColorString($value, $field->outputFormat);
}
/**
* Format color string
*
* @param $value string - hex string of 8 chiffres, first 2 is the alpha channel
* @param $of int - output format
* @return string formatted color string
* @throws object WireException - if input doesn't match (check for length, detailed check in debug mode)
*
*/
public function formatColorString($value, $of = 0) {
// simple length check or preg_match in debug mode
if (strlen($value) != 8 || ($this->wire('config')->debug && !preg_match('/[A-Fa-f0-9]{8}/', $value))) {
throw new WireException("Invalid input: $value. Expected hex string of 8 digits length.");
}
if ($of === 6) return $value;
if ($of === 0) return "#".substr($value,2);
if ($of === 1) return "#".$value;
$hexVals = str_split($value, 2);
$value = array_map('hexdec', $hexVals);
// opacity
$opacity = '0';
if ($value[0] > 1 && in_array($of ,array(3,5,8,10,12))) {
$opacity = round($value[0] / 255, 2); // float
$opacity = rtrim(number_format($opacity, 2, '.', ''),'.0'); // convert float to string with dot as decimal separator
}
if ($of === 9) return [$value[1], $value[2], $value[3]];
if ($of === 10) return [$value[1], $value[2], $value[3], $opacity];
if ($of === 8) {
$assocArray = array(
'o' => $opacity,
'r' => $value[1],
'g' => $value[2],
'b' => $value[3],
'ox' => $hexVals[0],
'rx' => $hexVals[1],
'gx' => $hexVals[2],
'bx' => $hexVals[3],
);
return array_merge($value, $assocArray);
}
if ($of === 2) return "rgb($value[1], $value[2], $value[3])";
if ($of === 3) return "rgba($value[1], $value[2], $value[3], $opacity)";
$hsl = $this->RGB2HSL(array_slice($value,1,3));
if ($of === 11) return $hsl;
if ($of === 12) {
$hsla = $hsl;
$hsla[] = $opacity;
return $hsla;
}
if ($of === 4) return "hsl($hsl[0], $hsl[1]%, $hsl[2]%)";
if ($of === 5) return "hsla($hsl[0], $hsl[1]%, $hsl[2]%, $opacity)";
}
public function getDatabaseSchema(Field $field) {
$schema = parent::getDatabaseSchema($field);
$schema['data'] = "int UNSIGNED NOT NULL";
return $schema;
}
public function ___getConfigInputfields(Field $field) {
$inputfields = $this->wire(new InputfieldWrapper());
$f = $this->wire('modules')->get('InputfieldRadios');
$f->attr('name', 'outputFormat');
$f->label = $this->_('Output Format');
$f->description = $this->_('Choose your preferred output format.');
$f->addOption(0, $this->_('string 6-digit hex color *#4496dd*'));
$f->addOption(1, $this->_('string 8-digit hex color *#fa4496dd* (limited browser support)'));
$f->addOption(2, $this->_('string *rgb(68, 100, 221)*'));
$f->addOption(3, $this->_('string *rgba(68, 100, 221, 0.98)*'));
$f->addOption(4, $this->_('string *hsl(227, 69.2%, 56.7%)*'));
$f->addOption(5, $this->_('string *hsla(227, 69.2%, 56.7%, 0.98)*'));
$f->addOption(6, $this->_('string 8-digit raw hex *fa4496dd* (unformatted)'));
$f->addOption(7, $this->_('int 32bit (storage)'));
$f->addOption(8, $this->_('array(r[0,255], g[0,255], b[0,255], o[0,1], rx[00,ff], gx[00,ff], bx[00,ff], ox[00,ff])'));
$f->addOption(9, $this->_('array([0,255], [0,255], [0,255]) indexed array: R,G,B'));
$f->addOption(10, $this->_('array([0,255], [0,255], [0,255], [0,1]) indexed array: R,G,B,Alpha'));
$f->addOption(11, $this->_('array([0,360], [69.2%], [56.7%]) indexed array: H,S,L'));
$f->addOption(12, $this->_('array([0,360], [69.2%], [56.7%], [0,1]) indexed array: H,S,L,Alpha'));
$f->attr('value', (int) $field->outputFormat);
$inputfields->add($f);
$f = $this->wire('modules')->get('InputfieldColor');
$f->attr('name', 'defaultValue');
$f->label = $this->_('Default value');
$f->inputType = $field->inputType;
$f->spectrum = $field->spectrum;
$f->initJS = $field->initJS;
$f->fileJS = $field->fileJS;
$f->fileCSS = $field->fileCSS;
$f->jqueryCore = $field->jqueryCore;
$f->jqueryUI = $field->jqueryUI;
$f->alpha = $field->alpha;
$f->description = $this->_('This value is assigned as the default for blank fields and on newly created pages.');
$f->collapsed = Inputfield::collapsedBlank;
$f->attr('value', strlen($field->defaultValue) ? $this->sanitizeValue($this->wire('page'), $field, $field->defaultValue) : null);
$inputfields->add($f);
return $inputfields;
}
public function ___install() {
if (function_exists("bcmod") === false && PHP_INT_SIZE < 8) {
throw new WireException($this->_('The BCMath extension is required if your system can not handle 64-bit integer values.'));
}
parent::___install();
}
}

View file

@ -1,9 +0,0 @@
.InputfieldColor input[type=color], input[type=color].FieldtypeColor, input[type=color]#Inputfield_defaultValue {
height:2em;
padding:0;
}
.AdminThemeUikit .InputfieldColor input[type=color], .AdminThemeUikit input[type=color].FieldtypeColor, .AdminThemeUikit input[type=color]#Inputfield_defaultValue {
height:40px;
width: 100% !important;
}

View file

@ -1,354 +0,0 @@
<?php namespace ProcessWire;
/**
* ProcessWire Color Inputfield
*
* @author Christoph Thelen aka @kixe 2017/07/03
* @copyright © 2017 Christoph Thelen
* @license Licensed under GNU/GPL v3
* @link https://processwire.com/talk/topic/...
* @version 1.1.6
*
* @since 1.0.1 2017/07/05 - better validation, spectrum options modifiable
* @since 1.0.2 2017/07/09 - added default value option
* @since 1.0.3 2017/07/09 - added option for custom javascript
* @since 1.0.4 2017/08/18 - made # optional for input (pattern attribute)
* @since 1.0.5 2017/08/28 - optimized default color handling, added output format option array()
* @since 1.0.6 2017/12/17 - modified render() for usage in modules config
* @since 1.0.7 2017/12/17 - sync version number to fieldtype
* @since 1.0.8 2018/08/31 - added functions getTextColor() convertColorName()
* @since 1.0.9 2019/01/12 - fixed number format bug for rgba() and hsla() alpha channel if comma is forced as decimal separator by locale settings, added data-input-type attribute for better JS handling
* @since 1.1.0 2019/08/12 - better input check formatColorString()
* @since 1.1.1 2019/09/01 - fixed bug missing opacity if 0
* @since 1.1.2 2019/09/04 - fixed bug #5 FieldtypeColor index typo in var in function RGB2HSL() thanks to @junoforno
* @since 1.1.3 2019/10/10 - fixed bug #1 InputfieldColor - remove pattern attribute if spectrum color picker is used to prevent error in Chrome
* @since 1.1.4 2020/05/15 switched to ProcessWire namespace
* @since 1.1.5 2021/10/10 set field value to 0 if the color parameter is null as a result of showEmpty option enabled on spectrum, bugfix (workaround): something went wrong in javascript spectrum
* @since 1.1.6 added option to disable alpha channel for spectrum color picker
*
* made for ProcessWire 3.x by Ryan Cramer
* https://processwire.com
*
* @todo
* - include i18n support provided by spectrum color picker
*
*/
class InputfieldColor extends Inputfield {
public static function getModuleInfo() {
return array(
'title' => __('Color', __FILE__), // Module Title
'summary' => __('Inputfield for colors', __FILE__), // Module Summary
'version' => 116,
'href' => 'https://processwire.com/talk/topic/16679-fieldtypecolor/'
);
}
/**
* Construct
*
* @throws WireException
*
*/
public function __construct() {
parent::__construct();
$this->set('icon', 'paint-brush');
$this->setAttribute('type', 'text');
$this->setAttribute('size', 10);
$this->setAttribute('placeholder', '#000000');
$this->setAttribute('pattern', '(#?[a-fA-F\d]{6})?');
}
public function init() {
$this->inputType = 0;
$this->spectrum = '';
$this->initJS = '';
$this->fileJS = '';
$this->fileCSS = '';
$this->jqueryCore = 0;
$this->jqueryUI = 0;
$this->alpha = 0; // int 0, 1 will be set dependend on inputType. To disable explicitly for inputType = 3 (spectrum color picker) set bool false
parent::init();
}
/**
* Called before the render method
* checking for SpectrumColorPicker
*
* @param Inputfield $parent
* @param bool $renderValueMode
* @return $this
*
*/
public function renderReady(Inputfield $parent = null, $renderValueMode = false) {
$url = $this->config->urls->get('InputfieldColor');
switch ($this->inputType) {
case 3:
$this->wire('modules')->get('JqueryCore');
$this->config->scripts->add($url . 'spectrum/spectrum.js');
$this->config->styles->add($url . 'spectrum/spectrum.css');
break;
case 4:
if ($this->jqueryCore) $this->wire('modules')->get('JqueryCore');
if ($this->jqueryUI) $this->wire('modules')->get('JqueryUI');
if ($this->fileJS) $this->config->scripts->add($url . $this->fileJS);
if ($this->fileCSS) $this->config->styles->add($url . $this->fileCSS);
break;
}
parent::renderReady($parent, $renderValueMode);
}
/**
* get textcolor (light or dark) corresponding to the background for better contrast
*
* @param int/string $bgColor expecting string or int with 6 (24bit) or 8 (32bit) digits with or without leading '#'
* @param int/string $textColorLight default: '#fff' (white)
* @param int/string $textColorDark default: '#000' (black)
* @return string $color light or dark
*
*/
public function getTextColor($bgColor, $textColorLight = '#fff', $textColorDark = '#000') {
if (!is_string($bgColor)) return $textColorDark;
else if (!ctype_xdigit(ltrim($bgColor, '#'))) {
$bgColor = $this->convertColorName($bgColor);
if (false === $bgColor) return $textColorDark;
}
$bgColor = ltrim($bgColor, '#');
$bgColor = str_pad($bgColor,8,'f',STR_PAD_LEFT);
$ARGB = array_map('hexdec', str_split($bgColor, 2));
$opacity = round($ARGB[0] / 255, 2);
if ($opacity < 0.45) return $textColorDark;
return ($ARGB[1]+6*$ARGB[2]+$ARGB[3])*3/8 > 460? $textColorDark : $textColorLight;
}
/**
* convert color name (hex -> html, html -> hex)
*
* @param $color
* @param $to convert to 'hex' or 'html'
* @return bool/ string
*
*/
public function convertColorName($color, $to = 'hex') {
$colorArray = $this->getX11ColorArray();
if ($to = 'hex') {
$key = array_search($color, array_column($colorArray, 0));
return empty($colorArray[$key][1])? false : $colorArray[$key][1];
}
else if ($to = 'html') {
$key = array_search($color, array_column($colorArray, 1));
return empty($colorArray[$key][0])? false : $colorArray[$key][0];
}
return false;
}
/**
* get multiple array with html color names and corresponding hex codes and rgb values
*
* @param $domain
* @param $path file path
* @return boolean
*
*/
protected function getX11ColorArray() {
$path = __DIR__ .'/x11color.txt';
if (!file_exists($path)) throw new WireException("Missing file " . $path);
$array = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if ($array === false) throw new WireException("Failed to open file: $path");
return array_map(function($e) {
return explode("\t", $e);
}, $array);
}
public function ___render() {
if ($this->value === "" && strlen($this->initValue)) $this->value = $this->initValue;
if (!$this->value) $this->value = null;
if ($this->value) {
$this->value = str_pad(ltrim($this->value, '#'),8,'f',STR_PAD_LEFT);
$color32 = "#".$this->value;
$color24 = $bgColor = "#".substr($this->value,2,6);
$value = array_map('hexdec', str_split($this->value, 2));
} else {
$color32 = $color24 = null;
$value = array(255,255,255,255);
$bgColor = '#fff';
}
$opacity = round($value[0] / 255, 2);
$opacity = $opacity? rtrim(number_format($opacity, 2, '.', ''),'.0') : '0';
$textColor = $this->getTextColor($this->value);
$rgba = "rgba($value[1], $value[2], $value[3], $opacity)";
$this->attr('value', $color24);
$this->attr('data-input-type', $this->inputType);
switch ($this->inputType) {
case 0:
$this->attr('type', 'color');
break;
case 1:
$this->attr('style', "color: $textColor; background: $bgColor;");
break;
case 2:
$this->alpha = 1;
$this->attr('value', $color32);
$this->attr('style', "color: $textColor; background: $bgColor; background-image: linear-gradient($rgba, $rgba), url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAIAAADZF8uwAAAAGUlEQVQYV2M4gwH+YwCGIasIUwhT25BVBADtzYNYrHvv4gAAAABJRU5ErkJggg==');");
$this->attr('placeholder', '#ff000000');
$this->attr('pattern', '(#?[a-fA-F\d]{8})?');
break;
case 3:
if ($this->alpha !== false) $this->alpha = 1;
if (!$color32) $color32 = '#00000000';
$this->attr('value', $color32);
$this->attr('placeholder', '#ff000000');
$this->removeAttr('pattern');
break;
case 4:
if ($this->alpha) $this->attr('value', $color32);
else $this->attr('value', $color24);
}
$attrs = $this->getAttributes();
$out = "<input " . $this->getAttributesString($attrs) . " />";
if( $this->inputType == 3) {
$options = $this->spectrum? str_replace(array(",\n","\n"),", ", trim($this->spectrum,",\t\n\r\0\x0B")).',' : '';
$value = $color32? $color32 : null;
$format = $this->alpha? 'toHex8String' : 'toHexString';
$out .= "<script>
$(\"#$this->id\").spectrum({
$options
color: \"$value\",
change: function(color) {
if (color === null) {
this.value = 0;
} else {
this.value = color.$format();
}
}
});
</script>
";
}
if( $this->inputType == 4) {
$value = $color32? $color32 : null;
if ($this->initJS) {
$initJS = str_replace(array("{value}","{id}"), array($color24, $this->id), $this->initJS);
$out .= "<script>
$initJS
</script>
";
}
}
return $out;
}
public function ___processInput(WireInputData $input) {
parent::___processInput($input);
$value = $this->attr('value');
if (!$value) return $this;
// bugfix (workaround): something went wrong in javascript spectrum
if (is_string($value) && in_array($value, ['hsva(0, 0%, 0%, 0)','hsla(0, 0%, 0%, 0)','rgba(0, 0, 0, 0)'])) {
$this->attr('value', '00000000');
return $this;
}
$pattern = $this->alpha? '/#?[a-fA-F\d]{8}/' : '/#?[a-fA-F\d]{6}/';
if(!preg_match($pattern, $value)) $this->error("Submitted value: $value does not match required pattern: $pattern.");
return $this;
}
public function getConfigInputfields() {
$inputfields = parent::getConfigInputfields();
$f = $this->wire('modules')->get('InputfieldRadios');
$f->attr('name', 'inputType');
$f->label = $this->_('Inputfieldtype');
$f->addOption(0, $this->_('Inputfield type=\'color\' (HTML5 - limited browser support)'));
$f->addOption(1, $this->_('Inputfield type=\'text\' expects 24bit hexcode strings'));
$f->addOption(2, $this->_('Inputfield type=\'text\' expects 32bit hexcode strings (alpha channel)'));
$f->addOption(3, $this->_('Inputfield with Spectrum Color Picker (JavaScript)'));
$f->addOption(4, $this->_('Inputfield type=\'text\' with custom JavaScript and/or CSS'));
$f->attr('value', $this->inputType);
$f->description = $this->_('');
$f->columnWidth = 50;
$inputfields->add($f);
$f = $this->wire('modules')->get('InputfieldTextarea');
$f->attr('name', 'spectrum');
$f->attr('rows', 10);
$f->label = $this->_('Color Picker Options');
$f->attr('value', $this->spectrum);
$f->description = $this->_('Set or modify options for the **Spectrum Color Picker**. [Read more ...](https://bgrins.github.io/spectrum/#options)');
$f->notes = $this->_("One option per line in the format: 'option: value'. The options: 'color' and 'change' are used by the system and not modifiable.");
$f->columnWidth = 50;
$f->showIf = "inputType=3";
$inputfields->add($f);
$f = $this->wire('modules')->get('InputfieldTextarea');
$f->attr('name', 'initJS');
$f->attr('rows', 3);
$f->label = $this->_('Initial JS');
$f->attr('value', $this->initJS);
$f->description = $this->_('JavaScript code initiating your custom JS color picker. Use {id} and {value} as placeholders for the related field attributes in your selector');
$f->notes = sprintf($this->_('{id} will be replaced by the string "%s"'), $this->id);
$f->columnWidth = 33;
$f->showIf = "inputType=4";
$f->requiredIf = "inputType=4";
$inputfields->add($f);
$rootUrl = $this->config->urls->get('InputfieldColor');
$f = $this->wire('modules')->get('InputfieldURL');
$f->attr('name', 'fileJS');
$f->label = $this->_('Include JS File');
$f->attr('value', $this->fileJS);
$f->description = $this->_('Set the path to your custom JavaScript file.');
$f->notes = sprintf($this->_('URL string relative to "%s"'), $rootUrl);
$f->columnWidth = 34;
$f->showIf = "inputType=4";
$f->requiredIf = "inputType=4";
$inputfields->add($f);
$f = $this->wire('modules')->get('InputfieldURL');
$f->attr('name', 'fileCSS');
$f->label = $this->_('Include CSS File');
$f->attr('value', $this->fileCSS);
$f->description = $this->_('Set the path to your custom stylesheet file.');
$f->notes = sprintf($this->_('URL string relative to "%s"'), $rootUrl);
$f->columnWidth = 33;
$f->showIf = "inputType=4";
$f->requiredIf = "inputType=4";
$inputfields->add($f);
$f = $this->modules->get('InputfieldCheckbox');
$f->attr('name', 'jqueryCore');
$f->label = __('Enable JqueryCore');
$f->attr('checked', $this->jqueryCore ? 'checked' : '' );
$f->columnWidth = 33;
$f->showIf = "inputType=4";
$inputfields->append($f);
$f = $this->modules->get('InputfieldCheckbox');
$f->attr('name', 'jqueryUI');
$f->label = __('Enable JqueryUI');
$f->attr('checked', $this->jqueryUI ? 'checked' : '' );
$f->columnWidth = 34;
$f->showIf = "inputType=4";
$inputfields->append($f);
$f = $this->modules->get('InputfieldRadios');
$f->attr('name', 'alpha');
$f->addOption(0, $this->_('6 digits "#ff0000"'));
$f->addOption(1, $this->_('8 digits "#ffff0000" (leading alpha channel)'));
$f->label = __('Select value type');
$f->attr('value', $this->alpha);
$f->columnWidth = 33;
$f->showIf = "inputType=4";
$inputfields->append($f);
return $inputfields;
}
}

View file

@ -1,107 +0,0 @@
FieldtypeColor
==============
## Fieldtype/Inputfield for ProcessWire 3.0
Field that stores colors. Many options for Input (HTML5 Inputfield Color, Textfield with changing background, various jQuery/JS ColorPickers, custom jQuery/JS/CSS) and Output (RGB, RGBA, HSL, HSLA, HEX). Package includes Fieldtype Color Select.
## Inputfield
Select between **5 types of Inputfields**
+ Html5 Inputfield of type='color' (if supported by browser)
+ Inputfield type='text' expecting a 24bit hexcode string (RGB). Input format: *'#4496dd'*
The background color of the input fields shows selected color
+ Inputfield of type='text' expecting 32bit hexcode strings (RGB + alpha channel) Input format: *'#fa4496dd'*
+ Inputfield with **Spectrum Color Picker** (JavaScript)
Options modifiable
+ Inputfield type='text' with **custom JavaScript** and/or CSS
## Output
Define output format under **Details** - Tab in field settings. Select from the following options:
+ *string* 6-digit hex color. Example: **'#4496dd'**
+ *string* 8-digit hex color with leading Alpha channel (limited browser support). Example: **'#fa4496dd'**
+ *string* CSS color value **RGB**. Example: **'rgb(68, 100, 221)'**
+ *string* CSS color value **RGBA**. Example: **'rgba(68, 100, 221, 0.98)'**
+ *string* CSS color value **HSL**. Example: **'hsl(227, 69.2%, 56.7%)'**
+ *string* CSS color value **HSLA**. Example: **'hsla(227, 69.2%, 56.7%, 0.98)'**
+ *string* 32bit raw hex value. Example: **'fa4496dd'** (unformatted output value)
+ *int 32bit*. Example: **'4198799069'** (storage value)
+ *array(R,G,B)*
+ *array(R,G,B,Alpha)*
+ *array(H,S,L)*
+ *array(H,S,L,Alpha)*
```
array(
[0] => 0-255, // opacity
[1],['r'] => 0-255,
[2],['g'] => 0-255,
[3],['b'] => 0-255,
['rx'] => 00-ff,
['gx'] => 00-ff,
['bx'] => 00-ff,
['ox'] => 00-ff, // opacity
['o'] => 0-1 // opacity
)
```
## Templates & API
You can always modify values or output format via ProcessWire API.
**Modify output format**
```
$f = $page->fields->get('myColorField');
$f->outputFormat = 8;
echo $page->color['rx'];
```
**Modify values**
+ Delete the page field value by setting empty string or *NULL*.
+ The values (int) 0, (string) '0', '00000000' and '#00000000' are similar and stored as (int) 0 (black, full transparent).
```
$page->of(false);
$page->myColorField = 'ff0000'; // red
$page->save('myColorField');
```
## Notes
**Deleting values** is only possible with inputfields of type='text' and via API.
If a **default value** is set, the field is filled with it if the field is empty (for example on newly created pages).
If Inputfield of type='text' 32bit is selected you can set the value to '#00000000' and the default value will be ignored.
The Fieldtype includes
[**Spectrum Color Picker** by Brian Grinstead](https://github.com/bgrins/spectrum)
Any custom Javascript based Inputfield can be used.
If the **Inputfield** is **used as is** e.g. for Module Settings, the following properties are provided:
```
$f->wire('modules')->get('InputfieldColor);
$f->inputType = 0; // int 0 - 4
$f->alpha = 0; // int 0 or 1, will be set automatically dependend on inputType. To disable explicitly for inputType = 3 (spectrum color picker) set to bool false
$f->spectrum = ''; // options for spectrum Color Picker if inputType = 3 @see https://bgrins.github.io/spectrum/
// properties for inputType = 4 only
$f->initJS = ''; // initial JS
$f->fileJS = ''; // path to JS file
$f->fileCSS = ''; // path to CSS file
$f->jqueryCore = 0; // enable jqueryCore
$f->jqueryUI = 0; // enable jqueryUI
```
---
Fieldtype Select Color Options
==============================
This fieldtype is included in the package. The module is an extension of the Core **FieldtypeOptions** module and offers colors as predefined selectable options via 4 different input field types (Select, SelectMultiple, Checkboxes and Radios).

View file

@ -1,143 +0,0 @@
{
"AliceBlue": "f0f8ff",
"AntiqueWhite": "faebd7",
"Aqua": "00ffff",
"AquaMarine": "7fffd4",
"Azure": "f0ffff",
"Beige": "f5f5dc",
"Bisque": "ffe4c4",
"Black": "000000",
"BlanchedAlmond": "ffebcd",
"Blue": "0000ff",
"BlueViolet": "8a2be2",
"Brown": "a52a2a",
"BurlyWood": "deb887",
"CadetBlue": "5f9ea0",
"Chartreuse": "7fff00",
"Chocolate": "d2691e",
"Coral": "ff7f50",
"CornFlowerBlue": "6495ed",
"Cornsilk": "fff8dc",
"Crimson": "dc143c",
"Cyan": "00ffff",
"DarkBlue": "00008b",
"DarkCyan": "008b8b",
"DarkGoldenRod": "b8860b",
"DarkGray": "a9a9a9",
"DarkGreen": "006400",
"DarkKhaki": "bdb76b",
"DarkMagenta": "8b008b",
"DarkOliveGreen": "556b2f",
"DarkOrange": "ff8c00",
"DarkOrchid": "9932cc",
"DarkRed": "8b0000",
"DarkSalmon": "e9967a",
"DarkSeaGreen": "8fbc8f",
"DarkSlateBlue": "483d8b",
"DarkSlateGray": "2f4f4f",
"DarkTurquoise": "00ced1",
"DarkViolet": "9400d3",
"DeepPink": "ff1493",
"DeepSkyBlue": "00bfff",
"DimGray": "696969",
"DodgerBlue": "1e90ff",
"FireBrick": "b22222",
"FloralWhite": "fffaf0",
"ForestGreen": "228b22",
"Fuchsia": "ff00ff",
"Gainsboro": "dcdcdc",
"GhostWhite": "f8f8ff",
"Gold": "ffd700",
"GoldenRod": "daa520",
"Gray": "808080",
"Green": "008000",
"GreenYellow": "adff2f",
"HoneyDew": "f0fff0",
"HotPink": "ff69b4",
"IndianRed": "cd5c5c",
"Indigo": "4b0082",
"Ivory": "fffff0",
"Khaki": "f0e68c",
"Lavender": "e6e6fa",
"LavenderBlush": "fff0f5",
"LawnGreen": "7cfc00",
"LemonChiffon": "fffacd",
"LightBlue": "add8e6",
"LightCoral": "f08080",
"LightCyan": "e0ffff",
"LightGoldenrodYellow": "fafad2",
"LightGray": "d3d3d3",
"LightGreen": "90ee90",
"LightPink": "ffb6c1",
"LightSalmon": "ffa07a",
"LightSeaGreen": "20b2aa",
"LightSkyBlue": "87cefa",
"LightSlateGray": "778899",
"LightSteelBlue": "b0c4de",
"LightYellow": "ffffe0",
"Lime": "00ff00",
"LimeGreen": "32cd32",
"Linen": "faf0e6",
"Magenta": "ff00ff",
"Maroon": "800000",
"MediumAquaMarine": "66cdaa",
"MediumBlue": "0000cd",
"MediumOrchid": "ba55d3",
"MediumPurple": "9370d8",
"MediumSeaGreen": "3cb371",
"MediumSlateBlue": "7b68ee",
"MediumSpringGreen": "00fa9a",
"MediumTurquoise": "48d1cc",
"MediumVioletRed": "c71585",
"MidnightBlue": "191970",
"MintCream": "f5fffa",
"MistyRose": "ffe4e1",
"Moccasin": "ffe4b5",
"NavajoWhite": "ffdead",
"Navy": "000080",
"OldLace": "fdf5e6",
"Olive": "808000",
"OliveDrab": "6b8e23",
"Orange": "ffa500",
"OrangeRed": "ff4500",
"Orchid": "da70d6",
"PaleGoldenRod": "eee8aa",
"PaleGreen": "98fb98",
"PaleTurquoise": "afeeee",
"PaleVioletRed": "db7093",
"PapayaWhip": "ffefd5",
"PeachPuff": "ffdab9",
"Peru": "cd853f",
"Pink": "ffc0cb",
"Plum": "dda0dd",
"PowderBlue": "b0e0e6",
"Purple": "800080",
"RebeccaPurple":"663399",
"Red": "ff0000",
"RosyBrown": "bc8f8f",
"RoyalBlue": "4169e1",
"SaddleBrown": "8b4513",
"Salmon": "fa8072",
"SandyBrown": "f4a460",
"SeaGreen": "2e8b57",
"SeaShell": "fff5ee",
"Sienna": "a0522d",
"Silver": "c0c0c0",
"SkyBlue": "87ceeb",
"SlateBlue": "6a5acd",
"SlateGray": "708090",
"Snow": "fffafa",
"SpringGreen": "00ff7f",
"SteelBlue": "4682b4",
"Tan": "d2b48c",
"Teal": "008080",
"Thistle": "d8bfd8",
"Tomato": "ff6347",
"Turquoise": "40e0d0",
"Violet": "ee82ee",
"Wheat": "f5deb3",
"White": "ffffff",
"WhiteSmoke": "f5f5f5",
"Yellow": "ffff00",
"YellowGreen": "9acd32"
}

View file

@ -1,507 +0,0 @@
/***
Spectrum Colorpicker v1.8.1
https://github.com/bgrins/spectrum
Author: Brian Grinstead
License: MIT
***/
.sp-container {
position:absolute;
top:0;
left:0;
display:inline-block;
*display: inline;
*zoom: 1;
/* https://github.com/bgrins/spectrum/issues/40 */
z-index: 9999994;
overflow: hidden;
}
.sp-container.sp-flat {
position: relative;
}
/* Fix for * { box-sizing: border-box; } */
.sp-container,
.sp-container * {
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
/* http://ansciath.tumblr.com/post/7347495869/css-aspect-ratio */
.sp-top {
position:relative;
width: 100%;
display:inline-block;
}
.sp-top-inner {
position:absolute;
top:0;
left:0;
bottom:0;
right:0;
}
.sp-color {
position: absolute;
top:0;
left:0;
bottom:0;
right:20%;
}
.sp-hue {
position: absolute;
top:0;
right:0;
bottom:0;
left:84%;
height: 100%;
}
.sp-clear-enabled .sp-hue {
top:33px;
height: 77.5%;
}
.sp-fill {
padding-top: 80%;
}
.sp-sat, .sp-val {
position: absolute;
top:0;
left:0;
right:0;
bottom:0;
}
.sp-alpha-enabled .sp-top {
margin-bottom: 18px;
}
.sp-alpha-enabled .sp-alpha {
display: block;
}
.sp-alpha-handle {
position:absolute;
top:-4px;
bottom: -4px;
width: 6px;
left: 50%;
cursor: pointer;
border: 1px solid black;
background: white;
opacity: .8;
}
.sp-alpha {
display: none;
position: absolute;
bottom: -14px;
right: 0;
left: 0;
height: 8px;
}
.sp-alpha-inner {
border: solid 1px #333;
}
.sp-clear {
display: none;
}
.sp-clear.sp-clear-display {
background-position: center;
}
.sp-clear-enabled .sp-clear {
display: block;
position:absolute;
top:0px;
right:0;
bottom:0;
left:84%;
height: 28px;
}
/* Don't allow text selection */
.sp-container, .sp-replacer, .sp-preview, .sp-dragger, .sp-slider, .sp-alpha, .sp-clear, .sp-alpha-handle, .sp-container.sp-dragging .sp-input, .sp-container button {
-webkit-user-select:none;
-moz-user-select: -moz-none;
-o-user-select:none;
user-select: none;
}
.sp-container.sp-input-disabled .sp-input-container {
display: none;
}
.sp-container.sp-buttons-disabled .sp-button-container {
display: none;
}
.sp-container.sp-palette-buttons-disabled .sp-palette-button-container {
display: none;
}
.sp-palette-only .sp-picker-container {
display: none;
}
.sp-palette-disabled .sp-palette-container {
display: none;
}
.sp-initial-disabled .sp-initial {
display: none;
}
/* Gradients for hue, saturation and value instead of images. Not pretty... but it works */
.sp-sat {
background-image: -webkit-gradient(linear, 0 0, 100% 0, from(#FFF), to(rgba(204, 154, 129, 0)));
background-image: -webkit-linear-gradient(left, #FFF, rgba(204, 154, 129, 0));
background-image: -moz-linear-gradient(left, #fff, rgba(204, 154, 129, 0));
background-image: -o-linear-gradient(left, #fff, rgba(204, 154, 129, 0));
background-image: -ms-linear-gradient(left, #fff, rgba(204, 154, 129, 0));
background-image: linear-gradient(to right, #fff, rgba(204, 154, 129, 0));
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType = 1, startColorstr=#FFFFFFFF, endColorstr=#00CC9A81)";
filter : progid:DXImageTransform.Microsoft.gradient(GradientType = 1, startColorstr='#FFFFFFFF', endColorstr='#00CC9A81');
}
.sp-val {
background-image: -webkit-gradient(linear, 0 100%, 0 0, from(#000000), to(rgba(204, 154, 129, 0)));
background-image: -webkit-linear-gradient(bottom, #000000, rgba(204, 154, 129, 0));
background-image: -moz-linear-gradient(bottom, #000, rgba(204, 154, 129, 0));
background-image: -o-linear-gradient(bottom, #000, rgba(204, 154, 129, 0));
background-image: -ms-linear-gradient(bottom, #000, rgba(204, 154, 129, 0));
background-image: linear-gradient(to top, #000, rgba(204, 154, 129, 0));
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00CC9A81, endColorstr=#FF000000)";
filter : progid:DXImageTransform.Microsoft.gradient(startColorstr='#00CC9A81', endColorstr='#FF000000');
}
.sp-hue {
background: -moz-linear-gradient(top, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
background: -ms-linear-gradient(top, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
background: -o-linear-gradient(top, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
background: -webkit-gradient(linear, left top, left bottom, from(#ff0000), color-stop(0.17, #ffff00), color-stop(0.33, #00ff00), color-stop(0.5, #00ffff), color-stop(0.67, #0000ff), color-stop(0.83, #ff00ff), to(#ff0000));
background: -webkit-linear-gradient(top, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
background: linear-gradient(to bottom, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
}
/* IE filters do not support multiple color stops.
Generate 6 divs, line them up, and do two color gradients for each.
Yes, really.
*/
.sp-1 {
height:17%;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0000', endColorstr='#ffff00');
}
.sp-2 {
height:16%;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffff00', endColorstr='#00ff00');
}
.sp-3 {
height:17%;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00ff00', endColorstr='#00ffff');
}
.sp-4 {
height:17%;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00ffff', endColorstr='#0000ff');
}
.sp-5 {
height:16%;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0000ff', endColorstr='#ff00ff');
}
.sp-6 {
height:17%;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff00ff', endColorstr='#ff0000');
}
.sp-hidden {
display: none !important;
}
/* Clearfix hack */
.sp-cf:before, .sp-cf:after { content: ""; display: table; }
.sp-cf:after { clear: both; }
.sp-cf { *zoom: 1; }
/* Mobile devices, make hue slider bigger so it is easier to slide */
@media (max-device-width: 480px) {
.sp-color { right: 40%; }
.sp-hue { left: 63%; }
.sp-fill { padding-top: 60%; }
}
.sp-dragger {
border-radius: 5px;
height: 5px;
width: 5px;
border: 1px solid #fff;
background: #000;
cursor: pointer;
position:absolute;
top:0;
left: 0;
}
.sp-slider {
position: absolute;
top:0;
cursor:pointer;
height: 3px;
left: -1px;
right: -1px;
border: 1px solid #000;
background: white;
opacity: .8;
}
/*
Theme authors:
Here are the basic themeable display options (colors, fonts, global widths).
See http://bgrins.github.io/spectrum/themes/ for instructions.
*/
.sp-container {
border-radius: 0;
background-color: #ECECEC;
border: solid 1px #f0c49B;
padding: 0;
}
.sp-container, .sp-container button, .sp-container input, .sp-color, .sp-hue, .sp-clear {
font: normal 12px "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
.sp-top {
margin-bottom: 3px;
}
.sp-color, .sp-hue, .sp-clear {
border: solid 1px #666;
}
/* Input */
.sp-input-container {
float:right;
width: 100px;
margin-bottom: 4px;
}
.sp-initial-disabled .sp-input-container {
width: 100%;
}
.sp-input {
font-size: 12px !important;
border: 1px inset;
padding: 4px 5px;
margin: 0;
width: 100%;
background:transparent;
border-radius: 3px;
color: #222;
}
.sp-input:focus {
border: 1px solid orange;
}
.sp-input.sp-validation-error {
border: 1px solid red;
background: #fdd;
}
.sp-picker-container , .sp-palette-container {
float:left;
position: relative;
padding: 10px;
padding-bottom: 300px;
margin-bottom: -290px;
}
.sp-picker-container {
width: 172px;
border-left: solid 1px #fff;
}
/* Palettes */
.sp-palette-container {
border-right: solid 1px #ccc;
}
.sp-palette-only .sp-palette-container {
border: 0;
}
.sp-palette .sp-thumb-el {
display: block;
position:relative;
float:left;
width: 24px;
height: 15px;
margin: 3px;
cursor: pointer;
border:solid 2px transparent;
}
.sp-palette .sp-thumb-el:hover, .sp-palette .sp-thumb-el.sp-thumb-active {
border-color: orange;
}
.sp-thumb-el {
position:relative;
}
/* Initial */
.sp-initial {
float: left;
border: solid 1px #333;
}
.sp-initial span {
width: 30px;
height: 25px;
border:none;
display:block;
float:left;
margin:0;
}
.sp-initial .sp-clear-display {
background-position: center;
}
/* Buttons */
.sp-palette-button-container,
.sp-button-container {
float: right;
}
/* Replacer (the little preview div that shows up instead of the <input>) */
.sp-replacer {
margin:0;
overflow:hidden;
cursor:pointer;
padding: 4px;
display:inline-block;
*zoom: 1;
*display: inline;
border: solid 1px #91765d;
background: #eee;
color: #333;
vertical-align: middle;
}
.sp-replacer:hover, .sp-replacer.sp-active {
border-color: #F0C49B;
color: #111;
}
.sp-replacer.sp-disabled {
cursor:default;
border-color: silver;
color: silver;
}
.sp-dd {
padding: 2px 0;
height: 16px;
line-height: 16px;
float:left;
font-size:10px;
}
.sp-preview {
position:relative;
width:25px;
height: 20px;
border: solid 1px #222;
margin-right: 5px;
float:left;
z-index: 0;
}
.sp-palette {
*width: 220px;
max-width: 220px;
}
.sp-palette .sp-thumb-el {
width:16px;
height: 16px;
margin:2px 1px;
border: solid 1px #d0d0d0;
}
.sp-container {
padding-bottom:0;
}
/* Buttons: http://hellohappy.org/css3-buttons/ */
.sp-container button {
background-color: #eeeeee;
background-image: -webkit-linear-gradient(top, #eeeeee, #cccccc);
background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);
background-image: -ms-linear-gradient(top, #eeeeee, #cccccc);
background-image: -o-linear-gradient(top, #eeeeee, #cccccc);
background-image: linear-gradient(to bottom, #eeeeee, #cccccc);
border: 1px solid #ccc;
border-bottom: 1px solid #bbb;
border-radius: 3px;
color: #333;
font-size: 14px;
line-height: 1;
padding: 5px 4px;
text-align: center;
text-shadow: 0 1px 0 #eee;
vertical-align: middle;
}
.sp-container button:hover {
background-color: #dddddd;
background-image: -webkit-linear-gradient(top, #dddddd, #bbbbbb);
background-image: -moz-linear-gradient(top, #dddddd, #bbbbbb);
background-image: -ms-linear-gradient(top, #dddddd, #bbbbbb);
background-image: -o-linear-gradient(top, #dddddd, #bbbbbb);
background-image: linear-gradient(to bottom, #dddddd, #bbbbbb);
border: 1px solid #bbb;
border-bottom: 1px solid #999;
cursor: pointer;
text-shadow: 0 1px 0 #ddd;
}
.sp-container button:active {
border: 1px solid #aaa;
border-bottom: 1px solid #888;
-webkit-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
-moz-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
-ms-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
-o-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
}
.sp-cancel {
font-size: 11px;
color: #d93f3f !important;
margin:0;
padding:2px;
margin-right: 5px;
vertical-align: middle;
text-decoration:none;
}
.sp-cancel:hover {
color: #d93f3f !important;
text-decoration: underline;
}
.sp-palette span:hover, .sp-palette span.sp-thumb-active {
border-color: #000;
}
.sp-preview, .sp-alpha, .sp-thumb-el {
position:relative;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAIAAADZF8uwAAAAGUlEQVQYV2M4gwH+YwCGIasIUwhT25BVBADtzYNYrHvv4gAAAABJRU5ErkJggg==);
}
.sp-preview-inner, .sp-alpha-inner, .sp-thumb-inner {
display:block;
position:absolute;
top:0;left:0;bottom:0;right:0;
}
.sp-palette .sp-thumb-inner {
background-position: 50% 50%;
background-repeat: no-repeat;
}
.sp-palette .sp-thumb-light.sp-thumb-active .sp-thumb-inner {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAIVJREFUeNpiYBhsgJFMffxAXABlN5JruT4Q3wfi/0DsT64h8UD8HmpIPCWG/KemIfOJCUB+Aoacx6EGBZyHBqI+WsDCwuQ9mhxeg2A210Ntfo8klk9sOMijaURm7yc1UP2RNCMbKE9ODK1HM6iegYLkfx8pligC9lCD7KmRof0ZhjQACDAAceovrtpVBRkAAAAASUVORK5CYII=);
}
.sp-palette .sp-thumb-dark.sp-thumb-active .sp-thumb-inner {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAMdJREFUOE+tkgsNwzAMRMugEAahEAahEAZhEAqlEAZhEAohEAYh81X2dIm8fKpEspLGvudPOsUYpxE2BIJCroJmEW9qJ+MKaBFhEMNabSy9oIcIPwrB+afvAUFoK4H0tMaQ3XtlrggDhOVVMuT4E5MMG0FBbCEYzjYT7OxLEvIHQLY2zWwQ3D+9luyOQTfKDiFD3iUIfPk8VqrKjgAiSfGFPecrg6HN6m/iBcwiDAo7WiBeawa+Kwh7tZoSCGLMqwlSAzVDhoK+6vH4G0P5wdkAAAAASUVORK5CYII=);
}
.sp-clear-display {
background-repeat:no-repeat;
background-position: center;
background-image: url(data:image/gif;base64,R0lGODlhFAAUAPcAAAAAAJmZmZ2dnZ6enqKioqOjo6SkpKWlpaampqenp6ioqKmpqaqqqqurq/Hx8fLy8vT09PX19ff39/j4+Pn5+fr6+vv7+wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAP8ALAAAAAAUABQAAAihAP9FoPCvoMGDBy08+EdhQAIJCCMybCDAAYUEARBAlFiQQoMABQhKUJBxY0SPICEYHBnggEmDKAuoPMjS5cGYMxHW3IiT478JJA8M/CjTZ0GgLRekNGpwAsYABHIypcAgQMsITDtWJYBR6NSqMico9cqR6tKfY7GeBCuVwlipDNmefAtTrkSzB1RaIAoXodsABiZAEFB06gIBWC1mLVgBa0AAOw==);
}

File diff suppressed because it is too large Load diff

View file

@ -1,143 +0,0 @@
indianred #CD5C5C 205,92,92
lightcoral #F08080 240,128,128
salmon #FA8072 250,128,114
darksalmon #E9967A 233,150,122
lightsalmon #FFA07A 255,160,122
crimson #DC143C 220,20,60
red #FF0000 255,0,0
firebrick #B22222 178,34,34
darkred #8B0000 139,0,0
pink #FFC0CB 255,192,203
lightpink #FFB6C1 255,182,193
hotpink #FF69B4 255,105,180
deeppink #FF1493 255,20,147
mediumvioletred #C71585 199,21,133
palevioletred #DB7093 219,112,147
lightsalmon #FFA07A 255,160,122
coral #FF7F50 255,127,80
tomato #FF6347 255,99,71
orangered #FF4500 255,69,0
darkorange #FF8C00 255,140,0
orange #FFA500 255,165,0
gold #FFD700 255,215,0
yellow #FFFF00 255,255,0
lightyellow #FFFFE0 255,255,224
lemonchiffon #FFFACD 255,250,205
lightgoldenrodyellow #FAFAD2 250,250,210
papayawhip #FFEFD5 255,239,213
moccasin #FFE4B5 255,228,181
peachpuff #FFDAB9 255,218,185
palegoldenrod #EEE8AA 238,232,170
khaki #F0E68C 240,230,140
darkkhaki #BDB76B 189,183,107
lavender #E6E6FA 230,230,250
thistle #D8BFD8 216,191,216
plum #DDA0DD 221,160,221
violet #EE82EE 238,130,238
orchid #DA70D6 218,112,214
fuchsia #FF00FF 255,0,255
magenta #FF00FF 255,0,255
mediumorchid #BA55D3 186,85,211
mediumpurple #9370DB 147,112,219
blueviolet #8A2BE2 138,43,226
darkviolet #9400D3 148,0,211
darkorchid #9932CC 153,50,204
darkmagenta #8B008B 139,0,139
purple #800080 128,0,128
indigo #4B0082 75,0,130
slateblue #6A5ACD 106,90,205
darkslateblue #483D8B 72,61,139
mediumslateblue #7B68EE 123,104,238
greenyellow #ADFF2F 173,255,47
chartreuse #7FFF00 127,255,0
lawngreen #7CFC00 124,252,0
lime #00FF00 0,255,0
limegreen #32CD32 50,205,50
palegreen #98FB98 152,251,152
lightgreen #90EE90 144,238,144
mediumspringgreen #00FA9A 0,250,154
springgreen #00FF7F 0,255,127
mediumseagreen #3CB371 60,179,113
seagreen #2E8B57 46,139,87
forestgreen #228B22 34,139,34
green #008000 0,128,0
darkgreen #006400 0,100,0
yellowgreen #9ACD32 154,205,50
olivedrab #6B8E23 107,142,35
olive #808000 128,128,0
darkolivegreen #556B2F 85,107,47
mediumaquamarine #66CDAA 102,205,170
darkseagreen #8FBC8F 143,188,143
lightseagreen #20B2AA 32,178,170
darkcyan #008B8B 0,139,139
teal #008080 0,128,128
aqua #00FFFF 0,255,255
cyan #00FFFF 0,255,255
lightcyan #E0FFFF 224,255,255
paleturquoise #AFEEEE 175,238,238
aquamarine #7FFFD4 127,255,212
turquoise #40E0D0 64,224,208
mediumturquoise #48D1CC 72,209,204
darkturquoise #00CED1 0,206,209
cadetblue #5F9EA0 95,158,160
steelblue #4682B4 70,130,180
lightsteelblue #B0C4DE 176,196,222
powderblue #B0E0E6 176,224,230
lightblue #ADD8E6 173,216,230
skyblue #87CEEB 135,206,235
lightskyblue #87CEFA 135,206,250
deepskyblue #00BFFF 0,191,255
dodgerblue #1E90FF 30,144,255
cornflowerblue #6495ED 100,149,237
mediumslateblue #7B68EE 123,104,238
royalblue #4169E1 65,105,225
blue #0000FF 0,0,255
mediumblue #0000CD 0,0,205
darkblue #00008B 0,0,139
navy #000080 0,0,128
midnightblue #191970 25,25,112
cornsilk #FFF8DC 255,248,220
blanchedalmond #FFEBCD 255,235,205
bisque #FFE4C4 255,228,196
navajowhite #FFDEAD 255,222,173
wheat #F5DEB3 245,222,179
burlywood #DEB887 222,184,135
tan #D2B48C 210,180,140
rosybrown #BC8F8F 188,143,143
sandybrown #F4A460 244,164,96
goldenrod #DAA520 218,165,32
darkgoldenrod #B8860B 184,134,11
peru #CD853F 205,133,63
chocolate #D2691E 210,105,30
saddlebrown #8B4513 139,69,19
sienna #A0522D 160,82,45
brown #A52A2A 165,42,42
maroon #800000 128,0,0
white #FFFFFF 255,255,255
snow #FFFAFA 255,250,250
honeydew #F0FFF0 240,255,240
mintcream #F5FFFA 245,255,250
azure #F0FFFF 240,255,255
aliceblue #F0F8FF 240,248,255
ghostwhite #F8F8FF 248,248,255
whitesmoke #F5F5F5 245,245,245
seashell #FFF5EE 255,245,238
beige #F5F5DC 245,245,220
oldlace #FDF5E6 253,245,230
floralwhite #FFFAF0 255,250,240
ivory #FFFFF0 255,255,240
antiquewhite #FAEBD7 250,235,215
linen #FAF0E6 250,240,230
lavenderblush #FFF0F5 255,240,245
mistyrose #FFE4E1 255,228,225
gainsboro #DCDCDC 220,220,220
lightgrey #D3D3D3 211,211,211
silver #C0C0C0 192,192,192
darkgray #A9A9A9 169,169,169
gray #808080 128,128,128
dimgray #696969 105,105,105
lightslategray #778899 119,136,153
slategray #708090 112,128,144
darkslategray #2F4F4F 47,79,79
black #000000 0,0,0
rebeccapurple #663399 102,51,153

View file

@ -1,6 +0,0 @@
[*.{php,module}]
end_of_line = LF
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

View file

@ -1 +0,0 @@
+.module linguist-language=PHP

View file

@ -1,96 +0,0 @@
# Changelog
### 0.6.0 - 2021-04-15
- PHP 8 support
### 0.5.2 - 2020-05-25
- changed Manuel Lemos smtp-class to new version 1.52, as he added a new token feature
### 0.5.1 - 2020-05-11
- minor fix to testconnection in the configpage
### 0.5.0 - 2020-05-04
- added a verbose debug testconnection into the configpage
### 0.4.2 - 2019-05-02
- added support for connections without authentication: allow_without_authentication
### 0.4.1 - 2019-04-19
- added support for verbose debug of the connection and sending process via a new method: $mail->debugSend()
### 0.4.0 - 2019-04-19
- added support for manual selection of a crypto method for TLS per this request: https://processwire.com/talk/topic/5704-wiremailsmtp/page/12/?tab=comments#comment-184229
### 0.3.1 - 2019-03-27
- enhanced the module to get overridden by site/config settings per this request: https://processwire.com/talk/topic/5704-wiremailsmtp/page/12/?tab=comments#comment-182735
### 0.3.0 - 2017-12-08
- fixed code that broke backward compatibility for PW 2.4 and 2.5, brought in with the config cosmetics (0.2.6)
### 0.2.7 - 2017-10-19
- @abdus fixed smtp password not saving
### 0.2.6 - 2017-10-17
- module config cosmetics by @abdus, many thanks! [See this forum post](https://processwire.com/talk/topic/5704-wiremailsmtp/?page=9&tab=comments#comment-153329)
### 0.2.5 - 2017-09-12
- fixed adding HTML-signatures into HTML-messages without body-end-tag
### 0.2.4 - 2017-09-03
- updated the attachment function to silence a PHP-Strict notice
### 0.2.3 - 2016-10-08
- updated the attachment function to be conform with the new integrated function in core WireMail class (introduced with PW 3.0.36)
### 0.2.2 - 2016-05-26
- fixed date string to follow strict RFC2822, See [Issue 5](https://github.com/horst-n/WireMailSmtp/issues/5) - Many thanks to @selsermedia!
### 0.2.0 - 2016-02-15
- added support for Selfsigned Certificates, a contribution from @flydev, [See this post](https://processwire.com/talk/topic/5704-wiremailsmtp/page-5#entry113290) - Many thanks!
### 0.1.14
- changed smtp class to new version 1.50 to solve a bug with two debug messages echoed out, even if debug was set to false
### 0.1.13 - 2015-06-14
- changed default setting for wrapText from true to false.
### 0.1.12
- fixed not sending to all CC-recipients when in sendSingle mode. See [issue 3](https://github.com/horst-n/WireMailSmtp/issues/3)
### 0.1.11
- changed smtp class to new version to solve problems with mixed usage of IP and hostname, found by @k07n. See [this post](https://processwire.com/talk/topic/5704-wiremailsmtp/page-3#entry95880)
### 0.1.10
- made wrapText configurable by Jan Romero [Commit abc0ac0b](https://github.com/horst-n/WireMailSmtp/commit/abc0ac0b4a3edd0fcbbb8b4695f00a362705ad5b)
### 0.1.9
- disabling connecting without authentication in the smtp base class
### 0.1.8
- added a separate inputfield for a HTML signature into config page
### 0.1.7
- set status from alpha to beta
### 0.0.7
- added new sentLog methods for permanent logging, intended for usage with third party modules, e.g. newsletter modules
### 0.0.6
- corrected addSignature to check and respect the config screen setting
### 0.0.5
- added multiple emails sending and bulkmail sending
### 0.0.4
- changed the functions "to" "cc" "bcc" to be compatible with Ryans changes
### 0.0.3
- added GMT Timezone to the Dateheader to reflect local timezones and show DateTime correct in Mailclients
### 0.0.2
- added sanitization to recipient names in email addresses (in file: WireMailSmtp.module)
### 0.0.1
- initial release
More information and code examples, please visit the [WireMailSmtp ProcessWire forum thread.](http://processwire.com/talk/topic/5704-module-wiremailsmtp/)

View file

@ -1,84 +0,0 @@
WireMailSmtp
============
### ProcessWire: a extension to the WireMail base class that uses SMTP-transport ###
### Only functional with ProcessWire Version 2.4.1 or greater ###
This module integrates EmailMessage, SMTP and SASL php-libraries from [Manuel Lemos](http://www.phpclasses.org/browse/author/1.html) into ProcessWire.
[More information and code examples](http://processwire.com/talk/topic/5704-module-wiremailsmtp/)
---
### Current Version 0.6.0 ###
### List of all options and features ###
**testConnection** () *- returns true on success, false on failures*
**debugSend** () *- send the mail(s) and output or return verbose messages of the complete connection and sending process*
**sendSingle** ( true | false ) *- default is false*
**sendBulk** ( true | false ) *- default is false, Set this to true if you have lots of recipients (50+)*
**to** ($recipients) *- one emailaddress or array with multiple emailaddresses*
**cc** ($recipients) *- only available with mode sendSingle, one emailaddress or array with multiple emailaddresses*
**bcc** ($recipients) *- one emailaddress or array with multiple emailaddresses*
**from** = 'person@example.com' *- can be set in module config (called Sender Emailaddress) but it can be overwritten here*
**fromName =** 'Name Surname' *- optional, can be set in module config (called Sender Name) but it can be overwritten here*
**priority** (3) *- 1 = Highest | 2 = High | 3 = Normal | 4 = Low | 5 = Lowest*
**dispositionNotification** () or **notification** () *- request a Disposition Notification*
**subject** ($subject) *- subject of the message*
**body** ($textBody) *- use this one alone to create and send plainText emailmessages*
**bodyHTML** ($htmlBody) *- use this to create a Multipart Alternative Emailmessage (containing a HTML-Part and a Plaintext-Part as fallback)*
**addSignature** ( true | false ) *- the default-behave is selectable in config screen, this can be overridden here. (only available if a signature is defined in the config screen)*
**attachment** ($filename, $alternativeBasename = '') *- add attachment file*
**send** () *- send the mail(s) and return number of successful send messages*
**getResult** () *- returns a dump (array) with all recipients (to, cc, bcc) and settings you have selected with the message, the message subject and body, and lists of successfull addresses and failed addresses,*
**logActivity** ($logmessage) *- you may log success if you want*
**logError** ($logmessage) *- you may log errors, too. - Errors are also logged automaticaly*
**useSentLog** (true | false) *- intended for usage with e.g. third party newsletter modules - tells the send() method to make usage of the sentLog-methods*
**sentLogReset** () *- starts a new Session. Best usage would be interactively once when setting up a new Newsletter*
**sentLogGet** () *- returns an array containing all previously used emailaddresses*
**sentLogAdd** ($emailaddress) *- is called automaticly within the send() method*
**wrapText** (true|false) *- default is true*
[More information and code examples](http://processwire.com/talk/topic/5704-module-wiremailsmtp/)

File diff suppressed because it is too large Load diff

View file

@ -1,448 +0,0 @@
<?php
/*******************************************************************************
* WireMailSmtp | hnsmtp
*
* @version - '0.6.0'
* @date - 2021/04/15
* @author - Horst Nogajski
* @licence - GNU GPL v2 - http://www.gnu.org/licenses/gpl-2.0.html
* @licence - MIT - https://processwire.com/about/license/mit/
********************************************************************************/
require_once( dirname(__FILE__) . '/smtp_classes/email_message.php' );
require_once( dirname(__FILE__) . '/smtp_classes/smtp_message.php' );
require_once( dirname(__FILE__) . '/smtp_classes/smtp.php' );
require_once( dirname(__FILE__) . '/smtp_classes/sasl.php' );
class hnsmtp {
private $default_charset = 'UTF-8';
private $smtp_host = ''; /* SMTP server host name */
private $smtp_port = 25; /* SMTP server host port,
usually 25 but for use with SSL or TLS 587 */
private $smtp_ssl = 0; /* Establish secure connections using SSL */
private $smtp_ssl_crypto_method = ''; /* Define the crypto method to use with SSL */
private $smtp_start_tls = 0; /* Establish secure connections using START_TLS */
private $smtp_tls_crypto_method = ''; /* Define the crypto method to use with TLS */
private $localhost = ''; /* this computers address */
private $realm = ''; /* Authentication realm or domain */
private $workstation = ''; /* Workstation for NTLM authentication */
private $authentication_mechanism = ''; /* SASL authentication mechanism */
private $allow_without_authentication = 0; /* Server allows connection without authentication */
private $smtp_user = ''; /* Authentication user name */
private $smtp_password = ''; /* Authentication password */
private $smtp_debug = 0; /* Output debug information */
private $smtp_html_debug = 0; /* Debug information is in HTML */
private $sender_name = ''; // From: the senders name
private $sender_email = ''; // From: the senders email address
private $sender_reply = ''; // Reply-To: optional email address
private $sender_errors_to = ''; // Errors-To: optional email address
private $sender_signature = ''; // a Signature Text, like Contact Data and / or Confidentiality Notices
private $sender_signature_html = ''; // a Signature Text in HTML, like Contact Data and / or Confidentiality Notices
private $send_sender_signature = 1; // when the signature should be send: with every mail | only when the default Email is the sender | only when explicitly called via the API
private $extra_headers = array(); // optional Custom-Meta-Headers
private $valid_recipients = array(); /* SenderEmailAddresses wich are allowed to
receive Messages */
private $smtp_certificate = false; // @flydev: https://processwire.com/talk/topic/5704-wiremailsmtp/page-5#entry113290
private $aValidVars = null;
private $emailMessage = null;
private $connected = null;
private $errors = array();
private $from = '';
private $fromName = '';
public function testConnection($debug = false) {
$res = $this->connect($debug);
$this->close();
return $res;
}
public function connect($debug = false) {
$this->connected = (($this->errors[] = $this->emailMessage->StartSendingMessage()) == '') ? true : false;
return $this->connected;
}
public function close() {
if(!isset($this->emailMessage)) {
return null;
}
$res = $this->emailMessage->ResetConnection('') == '' ? true : false;
$this->connected = false;
return $res;
}
public function getErrors() {
$a = array();
foreach( $this->errors as $e ) {
if($e=='') {
continue;
}
$a[] = $e;
}
$this->errors = $a;
return $this->errors;
}
protected function set_var_val( $k, $v ) {
if(!isset($this->aValidVars[$k])) {
return;
}
switch($k) {
case 'send_sender_signature':
case 'smtp_port':
$this->$k = intval($v);
break;
case 'smtp_certificate':
case 'smtp_ssl':
case 'smtp_start_tls':
case 'smtp_debug':
case 'smtp_html_debug':
case 'allow_without_authentication':
if(is_bool($v)) {
$this->$k = $v==true ? 1 : 0;
}
elseif(is_int($v)) {
$this->$k = $v==1 ? 1 : 0;
}
elseif(is_string($v) && in_array($v, array('1','on','On','ON','true','TRUE'))) {
$this->$k = 1;
}
elseif(is_string($v) && in_array($v, array('0','off','Off','OFF','false','FALSE'))) {
$this->$k = 0;
}
else {
$this->$k = 0;
}
break;
case 'smtp_tls_crypto_method':
$availableTLSmethods = WireMailSmtp::getCryptoMethodsTLS();
if(is_string($v) && isset($v, $availableTLSmethods)) {
$this->$k = $v;
}
break;
case 'smtp_ssl_crypto_method':
$availableSSLmethods = WireMailSmtp::getCryptoMethodsSSL();
if(is_string($v) && isset($v, $availableSSLmethods)) {
$this->$k = $v;
}
break;
case 'authentication_mechanism':
$this->authentication_mechanism = $v;
break;
case 'valid_recipients':
case 'extra_headers';
$this->$k = is_array($v) || is_string($v) ? (array)$v : array();
break;
default:
if(in_array($k, array('smtp_host', 'smtp_user', 'smtp_password',
'localhost', 'workstation', 'realm',
'sender_name', 'sender_email', 'sender_reply',
'sender_errors_to', 'sender_signature', 'sender_signature_html',
'default_charset'
))
) {
$this->$k = strval($v);
}
}
}
public function __construct($aConfig = null) {
if(!is_array($aConfig)) {
return;
}
$this->aValidVars = get_class_vars(__CLASS__);
foreach($aConfig as $k => $v) {
$this->set_var_val($k, $v);
}
foreach($this->valid_recipients as $k=>$v) {
$this->valid_recipients[$k] = str_replace(array('<','>'), '', strtolower(trim($v)));
}
// start SMTP-Mail
$this->emailMessage = new smtp_message_class();
// SMTP Server Authentication
$this->emailMessage->default_charset = $this->default_charset;
$this->emailMessage->localhost = $this->localhost;
$this->emailMessage->smtp_host = $this->smtp_host;
$this->emailMessage->smtp_port = $this->smtp_port;
$this->emailMessage->smtp_ssl = $this->smtp_ssl;
$this->emailMessage->smtp_ssl_crypto_method = $this->smtp_ssl_crypto_method;
$this->emailMessage->smtp_start_tls = $this->smtp_start_tls;
$this->emailMessage->smtp_tls_crypto_method = $this->smtp_tls_crypto_method;
$this->emailMessage->smtp_user = $this->smtp_user;
$this->emailMessage->smtp_password = $this->smtp_password;
$this->emailMessage->allow_without_authentication = $this->allow_without_authentication;
$this->emailMessage->smtp_certificate = $this->smtp_certificate;
// advanced SMTP Server Settings
$this->emailMessage->realm = $this->realm;
$this->emailMessage->workstation = $this->workstation;
$this->emailMessage->authentication_mechanism = $this->authentication_mechanism;
// Debug on / off
$this->emailMessage->smtp_debug = $this->smtp_debug;
$this->emailMessage->smtp_html_debug = $this->smtp_html_debug;
}
public function __destruct() {
if( $this->connected ) {
$this->close();
}
unset($this->emailMessage);
}
protected function logError($msg) {
if(!isset($this->module)) $this->module = wire('modules')->get('WireMailSmtp');
$this->module->logError($msg);
}
protected function logActivity($msg) {
if(!isset($this->module)) $this->module = wire('modules')->get('WireMailSmtp');
$this->module->logActivity($msg);
}
public function setSender($from='', $fromName='') {
$genericEmail = isset($this->localhost) ? 'processwire@' . $this->localhost : false;
$sender = strlen($from)>0 ? $from : $this->sender_email;
if(empty($sender) && false!==$genericEmail) {
$sender = $genericEmail; // fallback to a generic email address
}
$this->isValidEmailadress($sender); // if it is not a valid Emailaddress a Error is thrown
$senderName = strlen($fromName)>0 ? $fromName : $this->sender_name;
$this->from = $sender;
$this->fromName = $senderName;
if($sender==$this->sender_email) {
// we use the defaults from module config
$replyTo = isset($this->sender_reply) && strlen($this->sender_reply)>0 ? $this->sender_reply : $this->sender_email;
$errorsTo = isset($this->sender_errors_to) && strlen($this->sender_errors_to)>0 ? $this->sender_errors_to : $this->sender_email;
}
else {
$replyTo = $genericEmail!=$sender ? $sender : ''; // we don't want get replys to the generic emailaddress
$errorsTo = '';
}
$this->setEmailHeader('from', $sender, $senderName);
if(''!=$replyTo) $this->setEmailHeader('reply', $replyTo);
if(''!=$errorsTo) $this->setEmailHeader('errors', $errorsTo);
}
public function setCustomHeader($header) {
$extra_headers = (isset($this->extra_headers) && is_array($this->extra_headers) && 0<count($this->extra_headers)) ? $this->extra_headers : array();
$headers = array_merge($extra_headers, $header);
foreach($headers as $k=>$v) {
$this->setHeader($k, $v);
}
}
public function setTextBody($text, $addSignature, $wrapText, &$maildata) {
if($addSignature===true && isset($this->sender_signature) && is_string($this->sender_signature) && strlen(trim($this->sender_signature))>0) {
$text .= "\r\n\r\n" . $this->sender_signature;
}
$text = $wrapText ? $this->emailMessage->WrapText($text) : (string)$text;
$maildata = $text;
$ret = $this->emailMessage->AddQuotedPrintableTextPart($text);
if($ret=='') {
return true;
}
$this->logError('Error in '.__CLASS__.'::'.__FUNCTION__.' : ' . $ret);
return false;
}
public function setTextAndHtmlBody($text, $html, $addSignature, $wrapText, &$maildata1, &$maildata2) {
if($addSignature===true && isset($this->sender_signature) && is_string($this->sender_signature) && strlen(trim($this->sender_signature))>0) {
$text .= "\r\n\r\n--\r\n" . $this->sender_signature;
}
if($addSignature===true && isset($this->sender_signature_html) && is_string($this->sender_signature_html) && strlen(trim($this->sender_signature_html))>0) {
// we first need to check if there is a </body> end tag in the html-markup
if(preg_match('</body>', $html)) {
$html = str_replace("</body>", "\r\n\r\n" . $this->sender_signature_html . "\r\n</body>", $html);
} else {
$html .= "\r\n\r\n" . $this->sender_signature_html . "\r\n";
}
}
$maildata1 = $text = $wrapText ? $this->emailMessage->WrapText($text) : (string)$text;
$maildata2 = $html = $wrapText ? $this->emailMessage->WrapText($html) : (string)$html;
// create Alternative-Multipart
$html_part = $text_part = $alternative_part = 0;
$this->emailMessage->CreateQuotedPrintableTextPart($text, 'UTF-8', $text_part);
$this->emailMessage->CreateQuotedPrintableHTMLPart($html, 'UTF-8', $html_part);
$alternative_parts = array( $text_part, $html_part );
#$this->emailMessage->CreateAlternativeMultipart($alternative_parts, $alternative_part);
$ret = $this->emailMessage->AddAlternativeMultipart($alternative_parts);
if($ret=='') {
return true;
}
$this->logError('Error in '.__CLASS__.'::'.__FUNCTION__.' : ' . $ret);
return false;
}
public function addAttachment($attachment) {
$ret = $this->emailMessage->AddFilePart($attachment);
if($ret=='') {
return true;
}
$this->logError('Error in '.__CLASS__.'::'.__FUNCTION__.' : ' . $ret);
return false;
}
public function setNotification(&$maildata) {
if(!isset($this->from) || strlen(trim($this->from))==0) {
return false;
}
$email = $this->bundleEmailAndName($this->from, $this->fromName);
$maildata = $email;
return $this->setHeader('Disposition-Notification-To', $email);
}
public function setPriority($priority=3) {
$priority = intval($priority);
if(!in_array($priority, array(1, 2, 3, 4, 5))) {
$this->logError('Error in '.__CLASS__.'::'.__FUNCTION__.' : ' . "($priority)");
return false;
}
$priorities = array(
5 => array('5 (Lowest)', 'Low', 'Low'),
4 => array('4 (Low)', 'Low', 'Low'),
3 => array('3 (Normal)', 'Normal', 'Normal'),
2 => array('2 (High)', 'High', 'High'),
1 => array('1 (Highest)', 'High', 'High')
);
$ret = 0;
$ret += $this->setHeader('X-Priority', $priorities[$priority][0]) ? 1 : 0;
$ret += $this->setHeader('X-MSMail-Priority', $priorities[$priority][1]) ? 1 : 0;
$ret += $this->setHeader('Importance', $priorities[$priority][2]) ? 1 : 0;
return 3==$ret ? true : false;
}
public function send($debugServer=false, $htmlDebug=false, &$maildata='') {
if($debugServer) $this->emailMessage->smtp_debug = 1;
if($htmlDebug) $this->emailMessage->smtp_html_debug = 1;
if(!$this->connect()) {
$this->logError('Error in '.__CLASS__.'::'.__FUNCTION__.' : cannot connect to smtp-server!');
return false;
}
$this->emailMessage->SetHeader("Date", gmdate("D, j M Y H:i:s \G\M\T"));
$ret = $this->emailMessage->Send();
if($ret=='') {
$maildata = 'success';
return true;
}
$this->logError('Error in '.__CLASS__.'::'.__FUNCTION__.' : ' . $ret);
$maildata = (string)$ret;
return false;
}
public function setEmailHeader($type, $address, $name='') {
$address = str_replace(array('<','>'), '', $address);
if(!$this->isValidEmailadress($address)) {
$this->logError('Error in '.__CLASS__.'::'.__FUNCTION__.' : No valid E-mailadress: '.$address);
return false;
}
$type = strtolower($type);
$valid_types = array('to'=>'To','from'=>'From','cc'=>'CC','bcc'=>'BCC','reply-to'=>'Reply-To','reply'=>'Reply-To','errors-to'=>'Errors-To','errors'=>'Errors-To','error'=>'Errors-To');
if(!in_array($type,array_keys($valid_types))) {
$this->logError('Error in '.__CLASS__.'::'.__FUNCTION__.' : No valid Headertype: '.$type);
return false;
}
if(strpos($type,'reply')!==false) {
$this->emailMessage->SetHeader('Return-Path',$address);
}
$ret = $this->emailMessage->SetEncodedEmailHeader($valid_types[$type], $address, $name);
if($ret!='') {
$this->logError('Error in '.__CLASS__.'::'.__FUNCTION__.' : ' . $ret);
return false;
}
return true;
}
public function setHeader($headername,$content) {
$ret = $this->emailMessage->SetEncodedHeader($headername,$content);
if($ret!='') {
$this->logError('Error in '.__CLASS__.'::'.__FUNCTION__.' : ' . $ret);
return false;
}
return true;
}
public function isValidEmailadress($email) {
$email = strtolower(trim($email));
$clean = wire('sanitizer')->email($email);
if($email != $clean) throw new WireException("Invalid email address");
return true;
}
protected function bundleEmailAndName($email, $name) {
$email = strtolower(trim($email));
$clean = wire('sanitizer')->email($email);
if(!strlen($name)) return $email;
$name = wire('sanitizer')->emailHeader($name);
if(strpos($name, ',') !== false) {
// name contains a comma, so quote the value
$name = str_replace('"', '', $name); // remove existing quotes
$name = '"' . $name . '"'; // surround w/quotes
}
return "$name <$email>";
}
public function setBulkMail($bulk) {
return $this->emailMessage->setBulkMail($bulk);
}
} // END class hnsmtp

View file

@ -1,641 +0,0 @@
<?php
/*******************************************************************************
* WireMailSmtp | WireMailSmtpConfig
* ---------------------------------------------------------------------------
* @version - '0.6.0'
* @author - Horst Nogajski
* @licence - GNU GPL v2 - http://www.gnu.org/licenses/gpl-2.0.html
*******************************************************************************/
class WireMailSmtpConfig extends Wire {
public function getConfig(array $data) {
// check that they have the required PW version
if(version_compare(wire('config')->version, '2.4.1', '<')) {
$this->error(' requires ProcessWire 2.4.1 or newer. Please update.');
}
$siteconfig = is_array(wire('config')->wiremailsmtp) ? wire('config')->wiremailsmtp : array();
$modules = wire('modules');
$form = new InputfieldWrapper();
// LOCALHOST
$field = $modules->get('InputfieldText');
$field->attr('name', 'localhost');
$field->attr('value', $data['localhost']);
$field->label = $this->_('Local Hostname');
$field->description = $this->_('Hostname of this computer');
if(isset($siteconfig['localhost'])) {
$field->notes = $this->attentionMessage($siteconfig['localhost']);
$field->attr('tabindex', '-1');
} else {
$field->required = true;
}
$field->icon = 'desktop';
$form->add($field);
// WRAPPER SMTP SERVER
$fieldset = $modules->get('InputfieldFieldset');
$fieldset->label = $this->_('SMTP Server');
$fieldset->attr('name', '_smtp');
$fieldset->collapsed = Inputfield::collapsedNo;
$fieldset->icon = 'server';
// SMTP HOST
$field = $modules->get('InputfieldText');
$field->attr('name', 'smtp_host');
$field->attr('value', $data['smtp_host']);
$field->label = $this->_('SMTP Hostname');
$field->description = $this->_('Set to the host name of the SMTP server to which you want to relay the messages');
$field->columnWidth = 50;
if(isset($siteconfig['smtp_host'])) {
$field->notes = $this->attentionMessage($siteconfig['smtp_host']);
$field->attr('tabindex', '-1');
} else {
$field->required = true;
}
$field->icon = 'server';
$fieldset->add($field);
// SMTP PORT
$field = $modules->get('InputfieldInteger');
$field->attr('name', 'smtp_port');
$field->attr('value', $data['smtp_port']);
$field->label = $this->_('SMTP Port');
$field->description = $this->_('Set to the TCP port of the SMTP server host to connect');
if(isset($siteconfig['smtp_port'])) {
$field->notes = $this->attentionMessage($siteconfig['smtp_port']);
$field->attr('tabindex', '-1');
} else {
$field->notes = $this->_("default: 25\ndefault for TLS / SSL: 587 or 465");
$field->required = true;
}
$field->columnWidth = 50;
$field->icon = 'sign-out';
$fieldset->add($field);
// ALLOW WITHOUT ANY AUTHENTICATION
$field = $modules->get('InputfieldCheckbox');
$field->attr('name', 'allow_without_authentication');
$field->attr('id', 'allow_without_authentication');
$field->attr('value', 1);
$field->attr('checked', $data['allow_without_authentication'] ? 'checked' : '');
$field->label = $this->_('Allow Connection without Authentication');
$field->description = $this->_('Server allows connecting without Authentication Credentials');
if(isset($siteconfig['allow_without_authentication'])) {
$field->notes = $this->attentionMessage($siteconfig['allow_without_authentication']);
$field->attr('tabindex', '-1');
} else {
$field->notes = $this->_('Default: unchecked');
}
$field->columnWidth = 33;
$field->icon = 'unlock';
$fieldset->add($field);
// SMTP USER
$field = $modules->get('InputfieldText');
$field->attr('name', 'smtp_user');
$field->attr('value', $data['smtp_user']);
$field->label = $this->_('SMTP User');
$field->description = $this->_('Set this variable to the user name when the SMTP server requires authentication');
if(isset($siteconfig['smtp_user'])) {
$field->notes = $this->attentionMessage($siteconfig['smtp_user']);
$field->attr('tabindex', '-1');
}
$field->columnWidth = 34;
$field->icon = 'user';
$fieldset->add($field);
// SMTP PASSWORD
$field = $modules->get('InputfieldText');
$field->attr('name', 'smtp_password');
$field->attr('value', $data['smtp_password']);
$field->attr('type', 'password');
$field->label = $this->_('SMTP Password');
$field->description = $this->_('Set this variable to the user password when the SMTP server requires authentication');
if(isset($siteconfig['smtp_password'])) {
$field->notes = $this->attentionMessage('*******');
$field->attr('tabindex', '-1');
} else {
$field->notes = $this->_('**Note**: Password is stored as plain text in database.');
}
$field->columnWidth = 33;
$field->icon = 'asterisk';
$fieldset->add($field);
// SMTP STARTTLS
$field = $modules->get('InputfieldCheckbox');
$field->attr('name', 'smtp_start_tls');
$field->attr('id', 'smtp_start_tls');
$field->attr('value', 1);
$field->attr('checked', $data['smtp_start_tls'] ? 'checked' : '');
$field->columnWidth = 50;
$field->label = $this->_('Use START-TLS');
$field->description = $this->_('Check if the connection to the SMTP server should use encryption after the connection is established using TLS protocol');
if(isset($siteconfig['smtp_start_tls'])) {
$field->notes = $this->attentionMessage($siteconfig['smtp_start_tls']);
$field->attr('tabindex', '-1');
}
$field->icon = 'lock';
//$field->showIf = 'smtp_ssl=0';
$fieldset->add($field);
// TLS crypto method
$field = $modules->get('InputfieldSelect');
$field->attr('name', 'smtp_tls_crypto_method');
$field->attr('value', $data['smtp_tls_crypto_method']);
$field->label = $this->_('Select a crypto method for TLS');
$availableTLSmethods = WireMailSmtp::getCryptoMethodsTLS();
array_unshift($availableTLSmethods, array(''));
$field->addOptions($availableTLSmethods);
$field->description = $this->_("Select the crypto method that should be used for TLS connections. If you don't know what to select, try with the highest and strongest entry first!");
if(isset($siteconfig['smtp_tls_crypto_method'])) {
$field->notes = $this->attentionMessage($siteconfig['smtp_tls_crypto_method']);
$field->attr('tabindex', '-1');
}
$field->columnWidth = 50;
$field->icon = 'lock';
//$field->showIf = 'smtp_start_tls=1';
$fieldset->add($field);
// SMTP SSL
$field = $modules->get('InputfieldCheckbox');
$field->attr('name', 'smtp_ssl');
$field->attr('id', 'smtp_ssl');
$field->attr('value', 1);
$field->attr('checked', $data['smtp_ssl'] ? 'checked' : '');
$field->columnWidth = 100;
$field->label = $this->_('Use SSL');
$field->description = $this->_('Check if the SMTP server requires secure connections using SSL protocol');
if(isset($siteconfig['smtp_ssl'])) {
$field->notes = $this->attentionMessage($siteconfig['smtp_ssl']);
$field->attr('tabindex', '-1');
}
$field->icon = 'lock';
//$field->showIf = 'smtp_start_tls=0';
$fieldset->add($field);
// SSL crypto method
// $field = $modules->get('InputfieldSelect');
// $field->attr('name', 'smtp_ssl_crypto_method');
// $field->attr('value', $data['smtp_ssl_crypto_method']);
// $field->label = $this->_('Select a crypto method for SSL');
// $availableSSLmethods = WireMailSmtp::getCryptoMethodsSSL();
// array_unshift($availableSSLmethods, array(''));
// $field->addOptions($availableSSLmethods);
// $field->description = $this->_("Select the crypto method that should be used for SSL connections. If you don't know what to select, try with the highest and strongest entry first!");
// if(isset($siteconfig['smtp_ssl_crypto_method'])) {
// $field->notes = $this->attentionMessage($siteconfig['smtp_ssl_crypto_method']);
// $field->attr('tabindex', '-1');
// }
// $field->columnWidth = 50;
// $field->icon = 'lock';
// $fieldset->add($field);
// SMTP CERTIFICATE
// @flydev: https://processwire.com/talk/topic/5704-wiremailsmtp/page-5#entry113290
if(version_compare(phpversion(), '5.6.0', '>=')) {
$field = $modules->get('InputfieldCheckbox');
$field->attr('name', 'smtp_certificate');
$field->label = $this->_('PHP >= 5.6 - Allow self signed certificate');
$field->attr('value', $data['smtp_certificate']);
$field->attr('checked', $data['smtp_certificate'] ? 'checked' : '');
$field->columnWidth = 100;
$field->icon = 'certificate';
$fieldset->add($field);
}
// WRAPPER ADVANCED SMTP SETTINGS
$fieldset2 = $modules->get('InputfieldFieldset');
$fieldset2->label = $this->_('Advanced SMTP');
$fieldset2->attr('name', '_advanced_SMTP');
$fieldset2->collapsed = Inputfield::collapsedYes;
$fieldset2->icon = 'cogs';
// AUTHENTICATION MECHANISM
$field = $modules->get('InputfieldText');
$field->attr('name', 'authentication_mechanism');
$field->attr('value', $data['authentication_mechanism']);
$field->label = $this->_('Authentication Mechanism');
$field->description = $this->_('Force the use of a specific authentication mechanism.');
if(isset($siteconfig['authentication_mechanism'])) {
$field->notes = $this->attentionMessage($siteconfig['authentication_mechanism']);
$field->attr('tabindex', '-1');
} else {
$field->notes = $this->_('Default: empty');
}
$field->columnWidth = 33;
$field->icon = 'unlock';
$fieldset2->add($field);
// REALM
$field = $modules->get('InputfieldText');
$field->attr('name', 'realm');
$field->attr('value', $data['realm']);
$field->label = $this->_('Realm');
$field->description = $this->_('Set this variable when the SMTP server requires authentication and if more than one authentication realm is supported');
if(isset($siteconfig['realm'])) {
$field->notes = $this->attentionMessage($siteconfig['realm']);
$field->attr('tabindex', '-1');
} else {
$field->notes = $this->_('Default: empty');
}
$field->columnWidth = 34;
$field->icon = 'map-signs';
$fieldset2->add($field);
// WORKSTATION
$field = $modules->get('InputfieldText');
$field->attr('name', 'workstation');
$field->attr('value', $data['workstation']);
$field->label = $this->_('Workstation');
$field->description = $this->_('Set this variable to the client workstation when the SMTP server requires authentication identifiying the origin workstation name');
if(isset($siteconfig['workstation'])) {
$field->notes = $this->attentionMessage($siteconfig['workstation']);
$field->attr('tabindex', '-1');
} else {
$field->notes = $this->_('Default: empty');
}
$field->columnWidth = 33;
$field->icon = 'building';
$fieldset2->add($field);
$fieldset->add($fieldset2);
$form->add($fieldset);
// WRAPPER SENDER
$fieldset = $modules->get('InputfieldFieldset');
$fieldset->label = $this->_('Sender');
$fieldset->attr('name', '_sender');
$fieldset->collapsed = Inputfield::collapsedNo;
$fieldset->icon = 'address-book';
// SENDER EMAIL
$field = $modules->get('InputfieldText');
$field->attr('name', 'sender_email');
$field->attr('value', $data['sender_email']);
$field->label = $this->_('Sender Email Address');
if(isset($siteconfig['sender_email'])) {
$field->notes = $this->attentionMessage($siteconfig['sender_email']);
$field->attr('tabindex', '-1');
}
$field->columnWidth = 50;
$field->icon = 'at';
$fieldset->add($field);
// SENDER NAME
$field = $modules->get('InputfieldText');
$field->attr('name', 'sender_name');
$field->attr('value', $data['sender_name']);
$field->label = $this->_('Sender Name');
if(isset($siteconfig['sender_name'])) {
$field->notes = $this->attentionMessage($siteconfig['sender_name']);
$field->attr('tabindex', '-1');
}
$field->columnWidth = 50;
$field->icon = 'user';
$fieldset->add($field);
// SENDER REPLY EMAIL
$field = $modules->get('InputfieldText');
$field->attr('name', 'sender_reply');
$field->attr('value', $data['sender_reply']);
$field->label = $this->_('Reply Email Address');
$field->description = $this->_('if is empty, Sender Emailaddress is used');
if(isset($siteconfig['sender_reply'])) {
$field->notes = $this->attentionMessage($siteconfig['sender_reply']);
$field->attr('tabindex', '-1');
}
$field->columnWidth = 50;
$field->collapsed = Inputfield::collapsedYes;
$field->icon = 'mail-reply';
$fieldset->add($field);
// SENDER ERROR EMAIL
$field = $modules->get('InputfieldText');
$field->attr('name', 'sender_errors_to');
$field->attr('value', $data['sender_errors_to']);
$field->label = $this->_('Errors Email Address');
if(isset($siteconfig['sender_errors_to'])) {
$field->notes = $this->attentionMessage($siteconfig['sender_errors_to']);
$field->attr('tabindex', '-1');
} else {
$field->notes = $this->_('Default: empty');
}
$field->columnWidth = 50;
$field->collapsed = Inputfield::collapsedYes;
$field->icon = 'remove';
$fieldset->add($field);
// SENDER SIGNATURE (TEXT)
$field = $modules->get('InputfieldTextarea');
$field->attr('name', 'sender_signature');
$field->attr('value', $data['sender_signature']);
$field->label = $this->_('Sender Signature (Plain Text)');
$field->description = $this->_('Like Contact Data and / or Confidentiality Notices');
if(isset($siteconfig['sender_signature'])) {
$field->notes = $this->attentionMessage('***');
$field->attr('tabindex', '-1');
}
$field->columnWidth = 33;
$field->icon = 'pencil';
$fieldset->add($field);
// SENDER SIGNATURE (HTML)
$field = $modules->get('InputfieldTextarea');
$field->attr('name', 'sender_signature_html');
$field->attr('value', $data['sender_signature_html']);
$field->label = $this->_('Sender Signature (HTML)');
$field->description = $this->_('Like Contact Data and / or Confidentiality Notices');
if(isset($siteconfig['sender_signature_html'])) {
$field->notes = $this->attentionMessage('***');
$field->attr('tabindex', '-1');
}
$field->columnWidth = 33;
$field->icon = 'code';
$fieldset->add($field);
// SENDER SEND SIGNATURE
$field = $modules->get('InputfieldSelect');
$field->attr('name', 'send_sender_signature');
$field->attr('value', $data['send_sender_signature']);
$field->label = $this->_('Send Sender Signature');
$field->addOptions(array(
'1' => 'only when explicitly called via API',
'2' => 'automaticaly when FROM = Sender Emailaddress',
'3' => 'automaticaly with _every_ Message'
));
$field->description = $this->_('When the Signature should be send by default, (could be overriden by the API)');
$field->columnWidth = 34;
$field->icon = 'question';
$fieldset->add($field);
$form->add($fieldset);
// WRAPPER ADVANCED SETTINGS
$fieldset = $modules->get('InputfieldFieldset');
$fieldset->label = $this->_('Advanced');
$fieldset->attr('name', '_advanced');
$fieldset->collapsed = Inputfield::collapsedYes;
$fieldset->icon = 'gear';
// VALID RECIPIENTS
$field = $modules->get('InputfieldTextarea');
$field->attr('name', 'valid_recipients');
$field->attr('value', $data['valid_recipients']);
$field->label = $this->_('Valid Recipients');
$field->description = $this->_('List of email addresses that can receive messages.');
if(isset($siteconfig['valid_recipients'])) {
$aTemp = array();
foreach($siteconfig['valid_recipients'] as $k => $v) $aTemp[] = "{$k} : {$v}";
$field->notes = $this->attentionMessage("\n" . implode("\n", $aTemp) . "\n");
$field->attr('tabindex', '-1');
unset($k, $v, $aTemp);
} else {
$field->notes = $this->_('One email per line');
}
$field->columnWidth = 50;
$field->icon = 'users';
$fieldset->add($field);
// EXTRA HEADERS
$field = $modules->get('InputfieldTextarea');
$field->attr('name', 'extra_headers');
$field->attr('value', $data['extra_headers']);
$field->label = $this->_('Extra Headers');
$field->description = $this->_('Optionally define custom meta headers.');
if(isset($siteconfig['extra_headers'])) {
$aTemp = array();
foreach($siteconfig['extra_headers'] as $k => $v) $aTemp[] = "{$k} : {$v}";
$field->notes = $this->attentionMessage("\n" . implode("\n", $aTemp) . "\n");
$field->attr('tabindex', '-1');
unset($k, $v, $aTemp);
} else {
$field->notes = $this->_('One email per line');
}
$field->columnWidth = 50;
$field->icon = 'align-left';
$fieldset->add($field);
$form->add($fieldset);
// DISPLAY FINAL MERGED SETTINGS
$field = $modules->get('InputfieldMarkup');
$field->attr('name', '_final_settings');
$field->label = 'Final Merged Settings';
$field->icon = 'filter';
$field->columnWidth = 100;
$field->collapsed = Inputfield::collapsedNo;
$field->attr('value', $this->finalSettingsMessage($siteconfig));
$form->add($field);
// TEST SETTINGS
$field = $modules->get('InputfieldCheckbox');
$field->attr('name', '_test_settings');
$field->label = $this->_('Test settings');
$field->description = $this->_('Test settings now.');
$field->attr('value', 1);
$field->attr('checked', '');
$field->icon = 'heartbeat';
$form->add($field);
// OPTIONAL VERBOSE DEBUGGING
$fieldset = $modules->get('InputfieldFieldset');
$fieldset->label = $this->_('Verbose Debug settings');
$fieldset->attr('name', '_verbosedebug');
$fieldset->collapsed = Inputfield::collapsedNo;
$fieldset->showIf = '_test_settings=1';
$fieldset->icon = 'heartbeat';
$field = $modules->get('InputfieldText');
$field->attr('name', 'debug_senderemail');
$field->attr('value', $data['sender_email']);
$field->label = $this->_('Sender Email Address');
// if(isset($siteconfig['sender_email'])) {
// $field->notes = $this->attentionMessage($siteconfig['sender_email']);
// $field->attr('tabindex', '-1');
// }
$field->columnWidth = 50;
$field->icon = 'at';
$fieldset->add($field);
$field = $modules->get('InputfieldText');
$field->attr('name', 'debug_recipientemail');
$field->attr('value', '');
$field->label = $this->_('Recipient Email Address');
$field->columnWidth = 50;
$field->icon = 'at';
$fieldset->add($field);
$field = $modules->get('InputfieldText');
$field->attr('name', 'debug_subjectline');
$field->attr('value', '');
$field->label = $this->_('Subjectline');
$field->columnWidth = 50;
$field->icon = 'pencil';
$fieldset->add($field);
$field = $modules->get('InputfieldTextarea');
$field->attr('name', 'debug_bodycontent');
$field->attr('value', 'This is a test message. ÄÖÜ äöüß');
$field->label = $this->_('Bodycontent');
$field->columnWidth = 50;
$field->icon = 'envelope-o';
$fieldset->add($field);
$form->add($fieldset);
if(wire('session')->test_settings) {
// EXECUTE DEBUG CONNECTION AND DISPLAY LOG
$field = $modules->get('InputfieldMarkup');
$field->attr('name', '_debug_log');
$field->label = 'Debug Log';
$field->icon = 'heartbeat';
$field->columnWidth = 100;
$field->collapsed = Inputfield::collapsedNo;
$field->attr('value', $this->testSettings());
$form->add($field);
} else if(wire('input')->post->_test_settings) {
// PREPARE SESSION FOR DEBUGGING
$session = wire('session');
$session->set('test_settings', 1);
$post = wire('input')->post;
$session->set('debug_senderemail', $post->debug_senderemail);
$session->set('debug_recipientemail', $post->debug_recipientemail);
$session->set('debug_subjectline', $post->debug_subjectline);
$session->set('debug_bodycontent', $post->debug_bodycontent);
}
return $form;
}
public function testSettings() {
try {
$session = wire('session');
$from = $session->get('debug_senderemail');
$to = array($session->get('debug_recipientemail'));
$subject = $session->get('debug_subjectline');
$body = $session->get('debug_bodycontent');
$session->remove('test_settings');
$session->remove('debug_senderemail');
$session->remove('debug_recipientemail');
$session->remove('debug_subjectline');
$session->remove('debug_bodycontent');
if($from && $to) {
// do a verbose debugging
if(!$subject) $subject = 'Debug Testmail';
if(!$body) $body = 'Debug Testmail, äöüß';
$mail = wireMail();
if($mail->className != 'WireMailSmtp') {
$dump = "<p>Couldn't get the right WireMail-Module (WireMailSmtp). found: {$mail->className}</p>";
} else {
$mail->from = $from;
$mail->to($to);
$mail->subject($subject);
$mail->sendSingle(true);
$mail->body($body);
$dump = $mail->debugSend(3);
}
} else {
// only try a testconnection
$module = wire('modules')->get('WireMailSmtp');
$a = $module->getAdaptor();
if($a->testConnection()) {
$dump = $this->_("SUCCESS! SMTP settings appear to work correctly.");
} else {
$dump = $this->_("FAILURE! SMTP settings doesn't appear to work.");
}
}
} catch(Exception $e) {
$dump = $e->getMessage();
}
$outputTemplate = "<pre style=\"overflow:scroll !important; margin:15px auto; padding:10px; background-color:#ffeedd; color:#000; border:1px solid #AAA; font-family:'Hack', 'Source Code Pro', 'Lucida Console', 'Courier', monospace; font-size:12px; line-height:15px;\">".str_replace(array('<br>', '<br/>', '<br />'), '', $dump) ."</pre>";
return $outputTemplate;
}
private function attentionMessage($value) {
return sprintf($this->_("ATTENTION: Value is overwritten by an entry in your site/config.php:\n -[ %s ]- "), $value);
}
private function finalSettingsMessage($siteconfig) {
$outputTemplate = "<pre style=\"overflow:scroll !important; margin:15px auto; padding:10px; background-color:#ffffdd; color:#555; border:1px solid #AAA; font-family:'Hack', 'Source Code Pro', 'Lucida Console', 'Courier', monospace; font-size:12px; line-height:15px;\">[__CONTENT__]</pre>";
if(!count($siteconfig)) {
$content = 'There are no overriding settings defined in your site/config.php';
return str_replace('[__CONTENT__]', $content, $outputTemplate);
}
$validKeys = array(
'localhost',
'smtp_host',
'smtp_port',
'smtp_ssl',
'smtp_ssl_crypto_method',
'smtp_start_tls',
'smtp_tls_crypto_method',
'smtp_user',
'smtp_password',
'allow_without_authentication',
'smtp_certificate',
'realm',
'workstation',
'authentication_mechanism',
'sender_name',
'sender_email',
'sender_reply',
'sender_errors_to',
'sender_signature',
'sender_signature_html',
'extra_headers',
'valid_recipients',
#'smtp_debug',
#'smtp_html_debug',
);
$module = wire('modules')->get('WireMailSmtp');
$dump = $module->getSettings();
$v = array();
foreach($validKeys as $k) {
if(isset($dump[$k])) {
$v[$k] = 'smtp_password' == $k ? '********' : $dump[$k];
}
}
ob_start();
var_dump($v);
$content = ob_get_contents();
ob_end_clean();
$m = 0;
preg_match_all('#^(.*)=>#mU', $content, $stack);
$lines = $stack[1];
$indents = array_map('strlen', $lines);
if($indents) $m = max($indents) + 1;
$content = preg_replace_callback(
'#^(.*)=>\\n\s+(\S)#Um',
function($match) use ($m) {
return $match[1] . str_repeat(' ', ($m - strlen($match[1]) > 1 ? $m - strlen($match[1]) : 1)) . $match[2];
},
$content
);
$content = preg_replace('#^((\s*).*){$#m', "\\1\n\\2{", $content);
$content = str_replace(array('<pre>', '</pre>'), '', $content);
return str_replace('[__CONTENT__]', $content, $outputTemplate);
}
}

View file

@ -1,61 +0,0 @@
<?php
/*
* basic_sasl_client.php
*
* @(#) $Id: basic_sasl_client.php,v 1.1 2004/11/17 08:01:23 mlemos Exp $
*
*/
define("SASL_BASIC_STATE_START", 0);
define("SASL_BASIC_STATE_DONE", 1);
class basic_sasl_client_class
{
var $credentials=array();
var $state=SASL_BASIC_STATE_START;
Function Initialize(&$client)
{
return(1);
}
Function Start(&$client, &$message, &$interactions)
{
if($this->state!=SASL_BASIC_STATE_START)
{
$client->error="Basic authentication state is not at the start";
return(SASL_FAIL);
}
$this->credentials=array(
"user"=>"",
"password"=>""
);
$defaults=array(
);
$status=$client->GetCredentials($this->credentials,$defaults,$interactions);
if($status==SASL_CONTINUE)
{
$message=$this->credentials["user"].":".$this->credentials["password"];
$this->state=SASL_BASIC_STATE_DONE;
}
else
Unset($message);
return($status);
}
Function Step(&$client, $response, &$message, &$interactions)
{
switch($this->state)
{
case SASL_BASIC_STATE_DONE:
$client->error="Basic authentication was finished without success";
return(SASL_FAIL);
default:
$client->error="invalid Basic authentication step state";
return(SASL_FAIL);
}
return(SASL_CONTINUE);
}
};
?>

View file

@ -1,67 +0,0 @@
<?php
/*
* cram_md5_sasl_client.php
*
* @(#) $Id: cram_md5_sasl_client.php,v 1.3 2004/11/17 08:00:37 mlemos Exp $
*
*/
define("SASL_CRAM_MD5_STATE_START", 0);
define("SASL_CRAM_MD5_STATE_RESPOND_CHALLENGE", 1);
define("SASL_CRAM_MD5_STATE_DONE", 2);
class cram_md5_sasl_client_class
{
var $credentials=array();
var $state=SASL_CRAM_MD5_STATE_START;
Function Initialize(&$client)
{
return(1);
}
Function HMACMD5($key,$text)
{
$key=(strlen($key)<64 ? str_pad($key,64,"\0") : substr($key,0,64));
return(md5((str_repeat("\x5c", 64)^$key).pack("H32", md5((str_repeat("\x36", 64)^$key).$text))));
}
Function Start(&$client, &$message, &$interactions)
{
if($this->state!=SASL_CRAM_MD5_STATE_START)
{
$client->error="CRAM-MD5 authentication state is not at the start";
return(SASL_FAIL);
}
$this->credentials=array(
"user"=>"",
"password"=>""
);
$defaults=array();
$status=$client->GetCredentials($this->credentials,$defaults,$interactions);
if($status==SASL_CONTINUE)
$this->state=SASL_CRAM_MD5_STATE_RESPOND_CHALLENGE;
Unset($message);
return($status);
}
Function Step(&$client, $response, &$message, &$interactions)
{
switch($this->state)
{
case SASL_CRAM_MD5_STATE_RESPOND_CHALLENGE:
$message=$this->credentials["user"]." ".$this->HMACMD5($this->credentials["password"], $response);
$this->state=SASL_CRAM_MD5_STATE_DONE;
break;
case SASL_CRAM_MD5_STATE_DONE:
$client->error="CRAM-MD5 authentication was finished without success";
return(SASL_FAIL);
default:
$client->error="invalid CRAM-MD5 authentication step state";
return(SASL_FAIL);
}
return(SASL_CONTINUE);
}
};
?>

View file

@ -1,135 +0,0 @@
<?php
/*
* digest_sasl_client.php
*
* @(#) $Id: digest_sasl_client.php,v 1.1 2005/10/27 05:24:15 mlemos Exp $
*
*/
define('SASL_DIGEST_STATE_START', 0);
define('SASL_DIGEST_STATE_RESPOND_CHALLENGE', 1);
define('SASL_DIGEST_STATE_DONE', 2);
class digest_sasl_client_class
{
var $credentials=array();
var $state=SASL_DIGEST_STATE_START;
Function unq($string)
{
return(($string[0]=='"' && $string[strlen($string)-1]=='"') ? substr($string, 1, strlen($string)-2) : $string);
}
Function H($data)
{
return md5($data);
}
Function KD($secret, $data)
{
return $this->H($secret.':'.$data);
}
Function Initialize(&$client)
{
return(1);
}
Function Start(&$client, &$message, &$interactions)
{
if($this->state!=SASL_DIGEST_STATE_START)
{
$client->error='Digest authentication state is not at the start';
return(SASL_FAIL);
}
$this->credentials=array(
'user'=>'',
'password'=>'',
'uri'=>'',
'method'=>'',
'session'=>''
);
$defaults=array();
$status=$client->GetCredentials($this->credentials,$defaults,$interactions);
if($status==SASL_CONTINUE)
$this->state=SASL_DIGEST_STATE_RESPOND_CHALLENGE;
Unset($message);
return($status);
}
Function Step(&$client, $response, &$message, &$interactions)
{
switch($this->state)
{
case SASL_DIGEST_STATE_RESPOND_CHALLENGE:
$values=explode(',',$response);
$parameters=array();
for($v=0; $v<count($values); $v++)
$parameters[strtok(trim($values[$v]), '=')]=strtok('');
$message='username="'.$this->credentials['user'].'"';
if(!IsSet($parameters[$p='realm'])
&& !IsSet($parameters[$p='nonce']))
{
$client->error='Digest authentication parameter '.$p.' is missing from the server response';
return(SASL_FAIL);
}
$message.=', realm='.$parameters['realm'];
$message.=', nonce='.$parameters['nonce'];
$message.=', uri="'.$this->credentials['uri'].'"';
if(IsSet($parameters['algorithm']))
{
$algorithm=$this->unq($parameters['algorithm']);
$message.=', algorithm='.$parameters['algorithm'];
}
else
$algorithm='';
$realm=$this->unq($parameters['realm']);
$nonce=$this->unq($parameters['nonce']);
if(IsSet($parameters['qop']))
{
switch($qop=$this->unq($parameters['qop']))
{
case "auth":
$cnonce=$this->credentials['session'];
break;
default:
$client->error='Digest authentication quality of protection '.$qop.' is not yet supported';
return(SASL_FAIL);
}
}
$nc_value='00000001';
if(IsSet($parameters['qop'])
&& !strcmp($algorithm, 'MD5-sess'))
$A1=$this->H($this->credentials['user'].':'. $realm.':'. $this->credentials['password']).':'.$nonce.':'.$cnonce;
else
$A1=$this->credentials['user'].':'. $realm.':'. $this->credentials['password'];
$A2=$this->credentials['method'].':'.$this->credentials['uri'];
if(IsSet($parameters['qop']))
$response=$this->KD($this->H($A1), $nonce.':'. $nc_value.':'. $cnonce.':'. $qop.':'. $this->H($A2));
else
$response=$this->KD($this->H($A1), $nonce.':'. $this->H($A2));
$message.=', response="'.$response.'"';
if(IsSet($parameters['opaque']))
$message.=', opaque='.$parameters['opaque'];
if(IsSet($parameters['qop']))
$message.=', qop="'.$qop.'"';
$message.=', nc='.$nc_value;
if(IsSet($parameters['qop']))
$message.=', cnonce="'.$cnonce.'"';
$client->encode_response=0;
$this->state=SASL_DIGEST_STATE_DONE;
break;
case SASL_DIGEST_STATE_DONE:
$client->error='Digest authentication was finished without success';
return(SASL_FAIL);
default:
$client->error='invalid Digest authentication step state';
return(SASL_FAIL);
}
return(SASL_CONTINUE);
}
};
?>

View file

@ -1,193 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Class: Simple Authentication and Security Layer client</title>
</head>
<body>
<center><h1>Class: Simple Authentication and Security Layer client</h1></center>
<hr />
<ul>
<p><b>Version:</b> <tt>@(#) $Id: sasl_class.html,v 1.1 2014/03/03 12:28:31 horst Exp $</tt></p>
<h2><a name="table_of_contents">Contents</a></h2>
<ul>
<li><a href="#2.1.1">Summary</a></li>
<ul>
<li><a href="#3.2.0">Name</a></li>
<li><a href="#3.2.0.0">Author</a></li>
<li><a href="#3.2.0.1">Copyright</a></li>
<li><a href="#3.2.0.2">Version</a></li>
<li><a href="#3.2.0.3">Purpose</a></li>
<li><a href="#3.2.0.4">Usage</a></li>
</ul>
<li><a href="#4.1.1">Variables</a></li>
<ul>
<li><a href="#5.2.4">error</a></li>
<li><a href="#5.2.5">mechanism</a></li>
<li><a href="#5.2.6">encode_response</a></li>
</ul>
<li><a href="#6.1.1">Functions</a></li>
<ul>
<li><a href="#7.2.5">SetCredential</a></li>
<li><a href="#9.2.6">GetCredentials</a></li>
<li><a href="#11.2.7">Start</a></li>
<li><a href="#13.2.8">Step</a></li>
</ul>
</ul>
<p><a href="#table_of_contents">Top of the table of contents</a></p>
</ul>
<hr />
<ul>
<h2><li><a name="2.1.1">Summary</a></li></h2>
<ul>
<h3><a name="3.2.0">Name</a></h3>
<p>Simple Authentication and Security Layer client</p>
<h3><a name="3.2.0.0">Author</a></h3>
<p>Manuel Lemos (<a href="mailto:mlemos-at-acm.org">mlemos-at-acm.org</a>)</p>
<h3><a name="3.2.0.1">Copyright</a></h3>
<p>Copyright &copy; (C) Manuel Lemos 2004</p>
<h3><a name="3.2.0.2">Version</a></h3>
<p>@(#) $Id: sasl_class.html,v 1.1 2014/03/03 12:28:31 horst Exp $</p>
<h3><a name="3.2.0.3">Purpose</a></h3>
<p>Provide a common interface to plug-in driver classes that implement different mechanisms for authentication used by clients of standard protocols like SMTP, POP3, IMAP, HTTP, etc.. Currently the supported authentication mechanisms are: <tt>PLAIN</tt>, <tt>LOGIN</tt>, <tt>CRAM-MD5</tt>, <tt>Digest</tt> and <tt>NTML</tt> (Windows or Samba).</p>
<h3><a name="3.2.0.4">Usage</a></h3>
<p>.</p>
<p><a href="#table_of_contents">Table of contents</a></p>
</ul>
</ul>
<hr />
<ul>
<h2><li><a name="variables"></a><a name="4.1.1">Variables</a></li></h2>
<ul>
<li><tt><a href="#variable_error">error</a></tt></li><br />
<li><tt><a href="#variable_mechanism">mechanism</a></tt></li><br />
<li><tt><a href="#variable_encode_response">encode_response</a></tt></li><br />
<p><a href="#table_of_contents">Table of contents</a></p>
<h3><a name="variable_error"></a><li><a name="5.2.4">error</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Store the message that is returned when an error occurs.</p>
<h3>Usage</h3>
<p>Check this variable to understand what happened when a call to any of the class functions has failed.</p>
<p> This class uses cumulative error handling. This means that if one class functions that may fail is called and this variable was already set to an error message due to a failure in a previous call to the same or other function, the function will also fail and does not do anything.</p>
<p> This allows programs using this class to safely call several functions that may fail and only check the failure condition after the last function call.</p>
<p> Just set this variable to an empty string to clear the error condition.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_mechanism"></a><li><a name="5.2.5">mechanism</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Store the name of the mechanism that was selected during the call to the <tt><a href="#function_Start">Start</a></tt> function.</p>
<h3>Usage</h3>
<p>You can access this variable but do not change it.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_encode_response"></a><li><a name="5.2.6">encode_response</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>1</tt></p>
<h3>Purpose</h3>
<p>Let the drivers inform the applications whether responses need to be encoded.</p>
<h3>Usage</h3>
<p>Applications should check this variable before sending authentication responses to the server to determine if the responses need to be encoded, eventually with base64 algorithm.</p>
<p><a href="#variables">Variables</a></p>
<p><a href="#table_of_contents">Table of contents</a></p>
</ul>
</ul>
<hr />
<ul>
<h2><li><a name="functions"></a><a name="6.1.1">Functions</a></li></h2>
<ul>
<li><tt><a href="#function_SetCredential">SetCredential</a></tt></li><br />
<li><tt><a href="#function_GetCredentials">GetCredentials</a></tt></li><br />
<li><tt><a href="#function_Start">Start</a></tt></li><br />
<li><tt><a href="#function_Step">Step</a></tt></li><br />
<p><a href="#table_of_contents">Table of contents</a></p>
<h3><a name="function_SetCredential"></a><li><a name="7.2.5">SetCredential</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i></i> SetCredential(</tt><ul>
<tt><i>string</i> </tt><tt><a href="#argument_SetCredential_key">key</a></tt><tt>,</tt><br />
<tt><i>string</i> </tt><tt><a href="#argument_SetCredential_value">value</a></tt></ul>
<tt>)</tt></p>
<h3>Purpose</h3>
<p>Store the value of a credential that may be used by any of the supported mechanisms to process the authentication messages and responses.</p>
<h3>Usage</h3>
<p>Call this function before starting the authentication dialog to pass all the credential values that be needed to use the type of authentication that the applications may need.</p>
<h3>Arguments</h3>
<ul>
<p><tt><b><a name="argument_SetCredential_key">key</a></b></tt> - Specify the name of the credential key.</p>
<p><tt><b><a name="argument_SetCredential_value">value</a></b></tt> - Specify the value for the credential.</p>
</ul>
<p><a href="#functions">Functions</a></p>
<h3><a name="function_GetCredentials"></a><li><a name="9.2.6">GetCredentials</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>int</i> GetCredentials(</tt><ul>
<tt>(input and output) <i>array</i> </tt><tt><a href="#argument_GetCredentials_credentials">credentials</a></tt><tt>,</tt><br />
<tt>(input and output) <i>array</i> </tt><tt><a href="#argument_GetCredentials_defaults">defaults</a></tt><tt>,</tt><br />
<tt>(input and output) <i>array</i> </tt><tt><a href="#argument_GetCredentials_interactions">interactions</a></tt></ul>
<tt>)</tt></p>
<h3>Purpose</h3>
<p>Retrieve the values of one or more credentials to be used by the authentication mechanism classes.</p>
<h3>Usage</h3>
<p>This is meant to be used by authentication mechanism driver classes to retrieve the credentials that may be neede.</p>
<h3>Arguments</h3>
<ul>
<p><tt><b><a name="argument_GetCredentials_credentials">credentials</a></b></tt> - Reference to an associative array variable with all the credentials that are being requested. The function initializes this associative array values.</p>
<p><tt><b><a name="argument_GetCredentials_defaults">defaults</a></b></tt> - Associative arrays with default values for credentials that may have not been defined.</p>
<p><tt><b><a name="argument_GetCredentials_interactions">interactions</a></b></tt> - Not yet in use. It is meant to provide context information to retrieve credentials that may be obtained interacting with the user.</p>
</ul>
<h3>Return value</h3>
<p>The function may return <tt>SASL_CONTINUE</tt> if it succeeded, or <tt>SASL_NOMECH</tt> if it was not possible to retrieve one of the requested credentials.</p>
<p><a href="#functions">Functions</a></p>
<h3><a name="function_Start"></a><li><a name="11.2.7">Start</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>int</i> Start(</tt><ul>
<tt>(input and output) <i>array</i> </tt><tt><a href="#argument_Start_mechanisms">mechanisms</a></tt><tt>,</tt><br />
<tt>(output) <i>string &amp;</i> </tt><tt><a href="#argument_Start_message">message</a></tt><tt>,</tt><br />
<tt>(input and output) <i>array</i> </tt><tt><a href="#argument_Start_interactions">interactions</a></tt></ul>
<tt>)</tt></p>
<h3>Purpose</h3>
<p>Process the initial authentication step initializing the driver class that implements the first of the list of requested mechanisms that is supported by this SASL client library implementation.</p>
<h3>Usage</h3>
<p>Call this function specifying a list of mechanisms that the server supports. If the <tt><a href="#argument_Start_message">message</a></tt> argument returns a string, it should be sent to the server as initial message. Check the <tt><a href="#variable_encode_response">encode_response</a></tt> variable to determine whether the initial message needs to be encoded, eventually with base64 algorithm, before it is sent to the server.</p>
<h3>Arguments</h3>
<ul>
<p><tt><b><a name="argument_Start_mechanisms">mechanisms</a></b></tt> - Define the list of names of authentication mechanisms supported by the that should be tried.</p>
<p><tt><b><a name="argument_Start_message">message</a></b></tt> - Return the initial message that should be sent to the server to start the authentication dialog. If this value is undefined, no message should be sent to the server.</p>
<p><tt><b><a name="argument_Start_interactions">interactions</a></b></tt> - Not yet in use. It is meant to provide context information to interact with the end user.</p>
</ul>
<h3>Return value</h3>
<p>The function may return <tt>SASL_CONTINUE</tt> if it could start one of the requested authentication mechanisms. It may return <tt>SASL_NOMECH</tt> if it was not possible to start any of the requested mechanisms. It returns <tt>SASL_FAIL</tt> or other value in case of error.</p>
<p><a href="#functions">Functions</a></p>
<h3><a name="function_Step"></a><li><a name="13.2.8">Step</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>int</i> Step(</tt><ul>
<tt><i>string</i> </tt><tt><a href="#argument_Step_response">response</a></tt><tt>,</tt><br />
<tt>(output) <i>string &amp;</i> </tt><tt><a href="#argument_Step_message">message</a></tt><tt>,</tt><br />
<tt>(input and output) <i>array</i> </tt><tt><a href="#argument_Step_interactions">interactions</a></tt></ul>
<tt>)</tt></p>
<h3>Purpose</h3>
<p>Process the authentication steps after the initial step, until the authetication iteration dialog is complete.</p>
<h3>Usage</h3>
<p>Call this function iteratively after a successful initial step calling the <tt><a href="#function_Start">Start</a></tt> function.</p>
<h3>Arguments</h3>
<ul>
<p><tt><b><a name="argument_Step_response">response</a></b></tt> - Pass the response returned by the server to the previous step.</p>
<p><tt><b><a name="argument_Step_message">message</a></b></tt> - Return the message that should be sent to the server to continue the authentication dialog. If this value is undefined, no message should be sent to the server.</p>
<p><tt><b><a name="argument_Step_interactions">interactions</a></b></tt> - Not yet in use. It is meant to provide context information to interact with the end user.</p>
</ul>
<h3>Return value</h3>
<p>The function returns <tt>SASL_CONTINUE</tt> if step was processed successfully, or returns <tt>SASL_FAIL</tt> in case of error.</p>
<p><a href="#functions">Functions</a></p>
<p><a href="#table_of_contents">Table of contents</a></p>
</ul>
</ul>
<hr />
<address>Manuel Lemos (<a href="mailto:mlemos-at-acm.org">mlemos-at-acm.org</a>)</address>
</body>
</html>

View file

@ -1,584 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Class: Sending e-mail messages via SMTP protocol</title>
</head>
<body>
<center><h1>Class: Sending e-mail messages via SMTP protocol</h1></center>
<hr />
<ul>
<p><b>Version:</b> <tt>@(#) $Id: smtp_class.html,v 1.1 2014/03/03 12:28:31 horst Exp $</tt></p>
<h2><a name="table_of_contents">Contents</a></h2>
<ul>
<li><a href="#2.1.1">Summary</a></li>
<ul>
<li><a href="#3.2.0">Name</a></li>
<li><a href="#3.2.0.0">Author</a></li>
<li><a href="#3.2.0.1">Copyright</a></li>
<li><a href="#3.2.0.2">Version</a></li>
<li><a href="#3.2.0.3">Purpose</a></li>
<li><a href="#3.2.0.4">Translation</a></li>
<li><a href="#3.2.0.5">Support</a></li>
<li><a href="#3.2.0.6">Usage</a></li>
</ul>
<li><a href="#4.1.1">Variables</a></li>
<ul>
<li><a href="#5.2.29">user</a></li>
<li><a href="#5.2.30">realm</a></li>
<li><a href="#5.2.31">password</a></li>
<li><a href="#5.2.32">workstation</a></li>
<li><a href="#5.2.33">authentication_mechanism</a></li>
<li><a href="#5.2.34">host_name</a></li>
<li><a href="#5.2.35">host_port</a></li>
<li><a href="#5.2.36">socks_host_name</a></li>
<li><a href="#5.2.37">socks_host_port</a></li>
<li><a href="#5.2.38">socks_version</a></li>
<li><a href="#5.2.39">http_proxy_host_name</a></li>
<li><a href="#5.2.40">http_proxy_host_port</a></li>
<li><a href="#5.2.41">user_agent</a></li>
<li><a href="#5.2.42">ssl</a></li>
<li><a href="#5.2.43">start_tls</a></li>
<li><a href="#5.2.44">localhost</a></li>
<li><a href="#5.2.45">timeout</a></li>
<li><a href="#5.2.46">data_timeout</a></li>
<li><a href="#5.2.47">direct_delivery</a></li>
<li><a href="#5.2.48">error</a></li>
<li><a href="#5.2.49">debug</a></li>
<li><a href="#5.2.50">html_debug</a></li>
<li><a href="#5.2.51">esmtp</a></li>
<li><a href="#5.2.52">esmtp_extensions</a></li>
<li><a href="#5.2.53">exclude_address</a></li>
<li><a href="#5.2.54">getmxrr</a></li>
<li><a href="#5.2.55">pop3_auth_host</a></li>
<li><a href="#5.2.56">pop3_auth_port</a></li>
</ul>
<li><a href="#6.1.1">Functions</a></li>
<ul>
<li><a href="#7.2.11">Connect</a></li>
<li><a href="#9.2.12">MailFrom</a></li>
<li><a href="#11.2.13">SetRecipient</a></li>
<li><a href="#13.2.14">StartData</a></li>
<li><a href="#13.2.15">PrepareData</a></li>
<li><a href="#15.2.16">SendData</a></li>
<li><a href="#17.2.17">EndSendingData</a></li>
<li><a href="#17.2.18">ResetConnection</a></li>
<li><a href="#17.2.19">Disconnect</a></li>
<li><a href="#19.2.20">SendMessage</a></li>
</ul>
</ul>
<p><a href="#table_of_contents">Top of the table of contents</a></p>
</ul>
<hr />
<ul>
<h2><li><a name="2.1.1">Summary</a></li></h2>
<ul>
<h3><a name="3.2.0">Name</a></h3>
<p>Sending e-mail messages via SMTP protocol</p>
<h3><a name="3.2.0.0">Author</a></h3>
<p>Manuel Lemos (<a href="mailto:mlemos-at-acm.org">mlemos-at-acm.org</a>)</p>
<h3><a name="3.2.0.1">Copyright</a></h3>
<p>Copyright (C) Manuel Lemos 1999-2011</p>
<h3><a name="3.2.0.2">Version</a></h3>
<p>@(#) $Id: smtp_class.html,v 1.1 2014/03/03 12:28:31 horst Exp $</p>
<h3><a name="3.2.0.3">Purpose</a></h3>
<p>Sending e-mail messages via SMTP protocol</p>
<h3><a name="3.2.0.4">Translation</a></h3>
<p>If you are interested in translating the documentation of this class to your own idiom, please <a href="mailto:mlemos-at-acm.org">contact the author</a>.</p>
<h3><a name="3.2.0.5">Support</a></h3>
<p>Technical support for using this class may be obtained in the <tt>smtpclass</tt> support forum. Just go to the support forum pages page to browse the forum archives and post support request messages:</p>
<p> <a href="http://www.phpclasses.org/discuss/package/14/">http://www.phpclasses.org/discuss/package/14/</a></p>
<h3><a name="3.2.0.6">Usage</a></h3>
<p>To use this class just create a new object, set any variables to configure its options and call the <tt><a href="#function_SendMessage">SendMessage</a></tt> function to send a message.</p>
<p>It is not recommended that you use this class alone unless you have deep understanding of Internet mail standards on how to compose compliant e-mail messages. Instead, use the <a href="http://www.phpclasses.org/mimemessage">MIME message composing and sending class</a> and its sub-class SMTP message together with this SMTP class to properly compose e-mail messages, so your messages are not discarded for not being correctly composed.</p>
<p><a href="#table_of_contents">Table of contents</a></p>
</ul>
</ul>
<hr />
<ul>
<h2><li><a name="variables"></a><a name="4.1.1">Variables</a></li></h2>
<ul>
<li><tt><a href="#variable_user">user</a></tt></li><br />
<li><tt><a href="#variable_realm">realm</a></tt></li><br />
<li><tt><a href="#variable_password">password</a></tt></li><br />
<li><tt><a href="#variable_workstation">workstation</a></tt></li><br />
<li><tt><a href="#variable_authentication_mechanism">authentication_mechanism</a></tt></li><br />
<li><tt><a href="#variable_host_name">host_name</a></tt></li><br />
<li><tt><a href="#variable_host_port">host_port</a></tt></li><br />
<li><tt><a href="#variable_socks_host_name">socks_host_name</a></tt></li><br />
<li><tt><a href="#variable_socks_host_port">socks_host_port</a></tt></li><br />
<li><tt><a href="#variable_socks_version">socks_version</a></tt></li><br />
<li><tt><a href="#variable_http_proxy_host_name">http_proxy_host_name</a></tt></li><br />
<li><tt><a href="#variable_http_proxy_host_port">http_proxy_host_port</a></tt></li><br />
<li><tt><a href="#variable_user_agent">user_agent</a></tt></li><br />
<li><tt><a href="#variable_ssl">ssl</a></tt></li><br />
<li><tt><a href="#variable_start_tls">start_tls</a></tt></li><br />
<li><tt><a href="#variable_localhost">localhost</a></tt></li><br />
<li><tt><a href="#variable_timeout">timeout</a></tt></li><br />
<li><tt><a href="#variable_data_timeout">data_timeout</a></tt></li><br />
<li><tt><a href="#variable_direct_delivery">direct_delivery</a></tt></li><br />
<li><tt><a href="#variable_error">error</a></tt></li><br />
<li><tt><a href="#variable_debug">debug</a></tt></li><br />
<li><tt><a href="#variable_html_debug">html_debug</a></tt></li><br />
<li><tt><a href="#variable_esmtp">esmtp</a></tt></li><br />
<li><tt><a href="#variable_esmtp_extensions">esmtp_extensions</a></tt></li><br />
<li><tt><a href="#variable_exclude_address">exclude_address</a></tt></li><br />
<li><tt><a href="#variable_getmxrr">getmxrr</a></tt></li><br />
<li><tt><a href="#variable_pop3_auth_host">pop3_auth_host</a></tt></li><br />
<li><tt><a href="#variable_pop3_auth_port">pop3_auth_port</a></tt></li><br />
<p><a href="#table_of_contents">Table of contents</a></p>
<h3><a name="variable_user"></a><li><a name="5.2.29">user</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Define the authorized user when sending messages to a SMTP server.</p>
<h3>Usage</h3>
<p>Set this variable to the user name when the SMTP server requires authentication.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_realm"></a><li><a name="5.2.30">realm</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Define the authentication realm when sending messages to a SMTP server.</p>
<h3>Usage</h3>
<p>Set this variable when the SMTP server requires authentication and if more than one authentication realm is supported.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_password"></a><li><a name="5.2.31">password</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Define the authorized user password when sending messages to a SMTP server.</p>
<h3>Usage</h3>
<p>Set this variable to the user password when the SMTP server requires authentication.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_workstation"></a><li><a name="5.2.32">workstation</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Define the client workstation name when sending messages to a SMTP server.</p>
<h3>Usage</h3>
<p>Set this variable to the client workstation when the SMTP server requires authentication identifiying the origin workstation name.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_authentication_mechanism"></a><li><a name="5.2.33">authentication_mechanism</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Force the use of a specific authentication mechanism.</p>
<h3>Usage</h3>
<p>Set it to an empty string to let the class determine the authentication mechanism to use automatically based on the supported mechanisms by the server and by the SASL client library classes.</p>
<p> Set this variable to a specific mechanism name if you want to override the automatic authentication mechanism selection.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_host_name"></a><li><a name="5.2.34">host_name</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Define the SMTP server host name.</p>
<h3>Usage</h3>
<p>Set to the host name of the SMTP server to which you want to relay the messages.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_host_port"></a><li><a name="5.2.35">host_port</a></li></h3>
<h3>Type</h3>
<p><tt><i>int</i></tt></p>
<h3>Default value</h3>
<p><tt>25</tt></p>
<h3>Purpose</h3>
<p>Define the SMTP server host port.</p>
<h3>Usage</h3>
<p>Set to the TCP port of the SMTP server host to connect.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_socks_host_name"></a><li><a name="5.2.36">socks_host_name</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Define the SOCKS server host name.</p>
<h3>Usage</h3>
<p>Set to the SOCKS server host name through which the SMTP connection should be routed. Leave it empty if you do not want the connections to be established through a SOCKS server.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_socks_host_port"></a><li><a name="5.2.37">socks_host_port</a></li></h3>
<h3>Type</h3>
<p><tt><i>int</i></tt></p>
<h3>Default value</h3>
<p><tt>1080</tt></p>
<h3>Purpose</h3>
<p>Define the SOCKS server host port.</p>
<h3>Usage</h3>
<p>Set to the port of the SOCKS server host through which the the SMTP connection should be routed.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_socks_version"></a><li><a name="5.2.38">socks_version</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>'5'</tt></p>
<h3>Purpose</h3>
<p>Set the SOCKS protocol version.</p>
<h3>Usage</h3>
<p>Change this value if SOCKS server you want to use is listening to a different port.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_http_proxy_host_name"></a><li><a name="5.2.39">http_proxy_host_name</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Define the HTTP proxy server host name.</p>
<h3>Usage</h3>
<p>Set to the HTTP proxy server host name through which the SMTP connection should be routed. Leave it empty if you do not want the connections to be established through an HTTP proxy.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_http_proxy_host_port"></a><li><a name="5.2.40">http_proxy_host_port</a></li></h3>
<h3>Type</h3>
<p><tt><i>int</i></tt></p>
<h3>Default value</h3>
<p><tt>80</tt></p>
<h3>Purpose</h3>
<p>Define the HTTP proxy server host port.</p>
<h3>Usage</h3>
<p>Set to the port of the HTTP proxy server host through which the SMTP connection should be routed.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_user_agent"></a><li><a name="5.2.41">user_agent</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>'SMTP Class (http://www.phpclasses.org/smtpclass $Revision: 1.1 $)'</tt></p>
<h3>Purpose</h3>
<p>Set the user agent used when connecting via an HTTP proxy.</p>
<h3>Usage</h3>
<p>Change this value only if for some reason you want emulate a certain e-mail client.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_ssl"></a><li><a name="5.2.42">ssl</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>0</tt></p>
<h3>Purpose</h3>
<p>Define whether the connection to the SMTP server should be established securely using SSL protocol.</p>
<h3>Usage</h3>
<p>Set to 1 if the SMTP server requires secure connections using SSL protocol.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_start_tls"></a><li><a name="5.2.43">start_tls</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>0</tt></p>
<h3>Purpose</h3>
<p>Define whether the connection to the SMTP server should use encryption after the connection is established using TLS protocol.</p>
<h3>Usage</h3>
<p>Set to 1 if the SMTP server requires that authentication be done securely starting the TLS protocol after the connection is established.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_localhost"></a><li><a name="5.2.44">localhost</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Name of the local host computer</p>
<h3>Usage</h3>
<p>Set to the name of the computer connecting to the SMTP server from the local network.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_timeout"></a><li><a name="5.2.45">timeout</a></li></h3>
<h3>Type</h3>
<p><tt><i>int</i></tt></p>
<h3>Default value</h3>
<p><tt>0</tt></p>
<h3>Purpose</h3>
<p>Specify the connection timeout period in seconds.</p>
<h3>Usage</h3>
<p>Leave it set to 0 if you want the connection attempts to wait forever. Change this value if for some reason the timeout period seems insufficient or otherwise it seems too long.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_data_timeout"></a><li><a name="5.2.46">data_timeout</a></li></h3>
<h3>Type</h3>
<p><tt><i>int</i></tt></p>
<h3>Default value</h3>
<p><tt>0</tt></p>
<h3>Purpose</h3>
<p>Specify the timeout period in seconds to wait for data from the server.</p>
<h3>Usage</h3>
<p>Leave it set to 0 if you want to use the same value defined in the <tt><a href="#variable_timeout">timeout</a></tt> variable. Change this value if for some reason the default data timeout period seems insufficient or otherwise it seems too long.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_direct_delivery"></a><li><a name="5.2.47">direct_delivery</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>0</tt></p>
<h3>Purpose</h3>
<p>Boolean flag that indicates whether the message should be sent in direct delivery mode, i.e. the message is sent to the SMTP server associated to the domain of the recipient instead of relaying to the server specified by the <tt><a href="#variable_host_name">host_name</a></tt> variable.</p>
<h3>Usage</h3>
<p>Set this to <tt>1</tt> if you want to send urgent messages directly to the recipient domain SMTP server.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_error"></a><li><a name="5.2.48">error</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Message that describes the error when a call to a class function fails.</p>
<h3>Usage</h3>
<p>Check this variable when an error occurs to understand what happened.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_debug"></a><li><a name="5.2.49">debug</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>0</tt></p>
<h3>Purpose</h3>
<p>Specify whether it is necessary to output SMTP connection debug information.</p>
<h3>Usage</h3>
<p>Set this variable to <tt>1</tt> if you need to see the progress of the SMTP connection and protocol dialog when you need to understand the reason for delivery problems.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_html_debug"></a><li><a name="5.2.50">html_debug</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>0</tt></p>
<h3>Purpose</h3>
<p>Specify whether the debug information should be outputted in HTML format.</p>
<h3>Usage</h3>
<p>Set this variable to <tt>1</tt> if you need to see the debug output in a Web page.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_esmtp"></a><li><a name="5.2.51">esmtp</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>1</tt></p>
<h3>Purpose</h3>
<p>Specify whether the class should attempt to use ESMTP extensions supported by the server.</p>
<h3>Usage</h3>
<p>Set this variable to <tt>0</tt> if for some reason you want to avoid benefitting from ESMTP extensions.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_esmtp_extensions"></a><li><a name="5.2.52">esmtp_extensions</a></li></h3>
<h3>Type</h3>
<p><tt><i>array</i></tt></p>
<h3>Default value</h3>
<p><tt>array()</tt></p>
<h3>Purpose</h3>
<p>Associative array with the list of ESMTP extensions supported by the SMTP server.</p>
<h3>Usage</h3>
<p>Check this variable after connecting to the SMTP server to determine which ESMTP extensions are supported.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_exclude_address"></a><li><a name="5.2.53">exclude_address</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify an address that should be considered invalid when resolving host name addresses.</p>
<h3>Usage</h3>
<p>In some networks any domain name that does not exist is resolved as a sub-domain of the default local domain. If the DNS is configured in such way that it always resolves any sub-domain of the default local domain to a given address, it is hard to determine whether a given domain does not exist.</p>
<p> If your network is configured this way, you may set this variable to the address that all sub-domains of the default local domain resolves, so the class can assume that such address is invalid.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_getmxrr"></a><li><a name="5.2.54">getmxrr</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>'getmxrr'</tt></p>
<h3>Purpose</h3>
<p>Specify the name of the function that is called to determine the SMTP server address of a given domain.</p>
<h3>Usage</h3>
<p>Change this to a working replacement of the PHP <tt>getmxrr()</tt> function if this is not working in your system and you want to send messages in direct delivery mode.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_pop3_auth_host"></a><li><a name="5.2.55">pop3_auth_host</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify the server address for POP3 based authentication.</p>
<h3>Usage</h3>
<p>Set this variable to the address of the POP3 server if the SMTP server requires POP3 based authentication.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_pop3_auth_port"></a><li><a name="5.2.56">pop3_auth_port</a></li></h3>
<h3>Type</h3>
<p><tt><i>int</i></tt></p>
<h3>Default value</h3>
<p><tt>110</tt></p>
<h3>Purpose</h3>
<p>Specify the server port for POP3 based authentication.</p>
<h3>Usage</h3>
<p>Set this variable to the port of the POP3 server if the SMTP server requires POP3 based authentication.</p>
<p><a href="#variables">Variables</a></p>
<p><a href="#table_of_contents">Table of contents</a></p>
</ul>
</ul>
<hr />
<ul>
<h2><li><a name="functions"></a><a name="6.1.1">Functions</a></li></h2>
<ul>
<li><tt><a href="#function_Connect">Connect</a></tt></li><br />
<li><tt><a href="#function_MailFrom">MailFrom</a></tt></li><br />
<li><tt><a href="#function_SetRecipient">SetRecipient</a></tt></li><br />
<li><tt><a href="#function_StartData">StartData</a></tt></li><br />
<li><tt><a href="#function_PrepareData">PrepareData</a></tt></li><br />
<li><tt><a href="#function_SendData">SendData</a></tt></li><br />
<li><tt><a href="#function_EndSendingData">EndSendingData</a></tt></li><br />
<li><tt><a href="#function_ResetConnection">ResetConnection</a></tt></li><br />
<li><tt><a href="#function_Disconnect">Disconnect</a></tt></li><br />
<li><tt><a href="#function_SendMessage">SendMessage</a></tt></li><br />
<p><a href="#table_of_contents">Table of contents</a></p>
<h3><a name="function_Connect"></a><li><a name="7.2.11">Connect</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>bool</i> Connect(</tt><ul>
<tt><i>string</i> </tt><tt><a href="#argument_Connect_domain">domain</a></tt> [default '']</ul>
<tt>)</tt></p>
<h3>Purpose</h3>
<p>Connect to an SMTP server.</p>
<h3>Usage</h3>
<p>Call this function as first step to send e-mail messages.</p>
<h3>Arguments</h3>
<ul>
<p><tt><b><a name="argument_Connect_domain">domain</a></b></tt> - Specify the domain of the recipient when using the direct delivery mode.</p>
</ul>
<h3>Return value</h3>
<p>The function returns <tt>1</tt> if the connection is successfully established.</p>
<p><a href="#functions">Functions</a></p>
<h3><a name="function_MailFrom"></a><li><a name="9.2.12">MailFrom</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>bool</i> MailFrom(</tt><ul>
<tt><i>string</i> </tt><tt><a href="#argument_MailFrom_sender">sender</a></tt></ul>
<tt>)</tt></p>
<h3>Purpose</h3>
<p>Set the address of the message sender.</p>
<h3>Usage</h3>
<p>Call this function right after establishing a connection with the <tt><a href="#function_Connect">Connect</a></tt> function.</p>
<h3>Arguments</h3>
<ul>
<p><tt><b><a name="argument_MailFrom_sender">sender</a></b></tt> - E-mail address of the sender.</p>
</ul>
<h3>Return value</h3>
<p>The function returns <tt>1</tt> if the sender address is successfully set.</p>
<p><a href="#functions">Functions</a></p>
<h3><a name="function_SetRecipient"></a><li><a name="11.2.13">SetRecipient</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>bool</i> SetRecipient(</tt><ul>
<tt><i>string</i> </tt><tt><a href="#argument_SetRecipient_recipient">recipient</a></tt></ul>
<tt>)</tt></p>
<h3>Purpose</h3>
<p>Set the address of a message recipient.</p>
<h3>Usage</h3>
<p>Call this function repeatedly for each recipient right after setting the message sender with the <tt><a href="#function_MailFrom">MailFrom</a></tt> function.</p>
<h3>Arguments</h3>
<ul>
<p><tt><b><a name="argument_SetRecipient_recipient">recipient</a></b></tt> - E-mail address of a recipient.</p>
</ul>
<h3>Return value</h3>
<p>The function returns <tt>1</tt> if the recipient address is successfully set.</p>
<p><a href="#functions">Functions</a></p>
<h3><a name="function_StartData"></a><li><a name="13.2.14">StartData</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>bool</i> StartData(</tt><tt>)</tt></p>
<h3>Purpose</h3>
<p>Tell the SMTP server that the message data will start being sent.</p>
<h3>Usage</h3>
<p>Call this function right after you are done setting all the message recipients with the <tt><a href="#function_SetRecipient">SetRecipient</a></tt> function.</p>
<h3>Return value</h3>
<p>The function returns <tt>1</tt> if the server is ready to start receiving the message data.</p>
<p><a href="#functions">Functions</a></p>
<h3><a name="function_PrepareData"></a><li><a name="13.2.15">PrepareData</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>string</i> PrepareData(</tt><ul>
<tt><i>string</i> </tt><tt><a href="#argument_PrepareData_data">data</a></tt></ul>
<tt>)</tt></p>
<h3>Purpose</h3>
<p>Prepare message data to normalize line breaks and escaping lines that contain single dots.</p>
<h3>Usage</h3>
<p>Call this function if the message data you want to send may contain line breaks that are not the &quot;\r\n&quot; sequence or it may contain lines that just have a single dot.</p>
<h3>Arguments</h3>
<ul>
<p><tt><b><a name="argument_PrepareData_data">data</a></b></tt> - Message data to be prepared.</p>
</ul>
<h3>Return value</h3>
<p>Resulting normalized messages data.</p>
<p><a href="#functions">Functions</a></p>
<h3><a name="function_SendData"></a><li><a name="15.2.16">SendData</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>bool</i> SendData(</tt><ul>
<tt><i>string</i> </tt><tt><a href="#argument_SendData_data">data</a></tt></ul>
<tt>)</tt></p>
<h3>Purpose</h3>
<p>Send message data.</p>
<h3>Usage</h3>
<p>Call this function repeatedly for all message data blocks to be sent right after start sending message data with the <tt><a href="#function_StartData">StartData</a></tt> function.</p>
<h3>Arguments</h3>
<ul>
<p><tt><b><a name="argument_SendData_data">data</a></b></tt> - Message data to be sent.</p>
</ul>
<h3>Return value</h3>
<p>The function returns <tt>1</tt> if the message data was sent to the SMTP server successfully.</p>
<p><a href="#functions">Functions</a></p>
<h3><a name="function_EndSendingData"></a><li><a name="17.2.17">EndSendingData</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>bool</i> EndSendingData(</tt><tt>)</tt></p>
<h3>Purpose</h3>
<p>Tell the server that all the message data was sent.</p>
<h3>Usage</h3>
<p>Call this function when you are done with sending the message data with the <tt><a href="#function_SendData">SendData</a></tt> function.</p>
<h3>Return value</h3>
<p>The function returns <tt>1</tt> if the server accepted the message.</p>
<p><a href="#functions">Functions</a></p>
<h3><a name="function_ResetConnection"></a><li><a name="17.2.18">ResetConnection</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>bool</i> ResetConnection(</tt><tt>)</tt></p>
<h3>Purpose</h3>
<p>Reset an already established SMTP connection to the initial state.</p>
<h3>Usage</h3>
<p>Call this function when there was an error sending a message and you need to skip to sending another message without disconnecting.</p>
<h3>Return value</h3>
<p>The function returns <tt>1</tt> if the connection was resetted successfully.</p>
<p><a href="#functions">Functions</a></p>
<h3><a name="function_Disconnect"></a><li><a name="17.2.19">Disconnect</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>bool</i> Disconnect(</tt><ul>
<tt><i>bool</i> </tt><tt><a href="#argument_Disconnect_quit">quit</a></tt> [default 1]</ul>
<tt>)</tt></p>
<h3>Purpose</h3>
<p>Terminate a previously opened connection.</p>
<h3>Usage</h3>
<p>Call this function after you are done sending your messages.</p>
<h3>Arguments</h3>
<ul>
<p><tt><b><a name="argument_Disconnect_quit">quit</a></b></tt> - Boolean option that tells whether the class should perform the final connection quit handshake, or just close the connection without waiting.</p>
</ul>
<h3>Return value</h3>
<p>The function returns <tt>1</tt> if the connection was successfully closed.</p>
<p><a href="#functions">Functions</a></p>
<h3><a name="function_SendMessage"></a><li><a name="19.2.20">SendMessage</a></li></h3>
<h3>Synopsis</h3>
<p><tt><i>bool</i> SendMessage(</tt><ul>
<tt><i>string</i> </tt><tt><a href="#argument_SendMessage_sender">sender</a></tt><tt>,</tt><br />
<tt><i>string</i> </tt><tt><a href="#argument_SendMessage_recipients">recipients</a></tt><tt>,</tt><br />
<tt>(input and output) <i>array</i> </tt><tt><a href="#argument_SendMessage_headers">headers</a></tt><tt>,</tt><br />
<tt><i>string</i> </tt><tt><a href="#argument_SendMessage_body">body</a></tt></ul>
<tt>)</tt></p>
<h3>Purpose</h3>
<p>Send a message in a single call.</p>
<h3>Usage</h3>
<p>Call this function if you want to send a single messages to a small number of recipients in a single call.</p>
<h3>Arguments</h3>
<ul>
<p><tt><b><a name="argument_SendMessage_sender">sender</a></b></tt> - E-mail address of the sender.</p>
<p><tt><b><a name="argument_SendMessage_recipients">recipients</a></b></tt> - Array with a list of the e-mail addresses of the recipients of the message.</p>
<p><tt><b><a name="argument_SendMessage_headers">headers</a></b></tt> - Array with a list of the header lines of the message.</p>
<p><tt><b><a name="argument_SendMessage_body">body</a></b></tt> - Body data of the message.</p>
</ul>
<h3>Return value</h3>
<p>The function returns <tt>1</tt> if the message was sent successfully.</p>
<p><a href="#functions">Functions</a></p>
<p><a href="#table_of_contents">Table of contents</a></p>
</ul>
</ul>
<hr />
<address>Manuel Lemos (<a href="mailto:mlemos-at-acm.org">mlemos-at-acm.org</a>)</address>
</body>
</html>

View file

@ -1,477 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Class: MIME E-mail message composing and sending via SMTP</title>
</head>
<body>
<center><h1>Class: MIME E-mail message composing and sending via SMTP</h1></center>
<hr />
<ul>
<p><b>Version:</b> <tt>@(#) $Id: smtp_message_class.html,v 1.1 2014/03/03 12:28:32 horst Exp $</tt></p>
<h2><a name="table_of_contents">Contents</a></h2>
<ul>
<li><a href="#2.1.1">Summary</a></li>
<ul>
<li><a href="#3.2.0">Name</a></li>
<li><a href="#3.2.0.0">Author</a></li>
<li><a href="#3.2.0.1">Copyright</a></li>
<li><a href="#3.2.0.2">Version</a></li>
<li><a href="#3.2.0.3">Parent classes</a></li>
<li><a href="#4.2.0">Purpose</a></li>
<li><a href="#4.2.0.0">Usage</a></li>
</ul>
<li><a href="#5.1.1">Variables</a></li>
<ul>
<li><a href="#6.2.27">localhost</a></li>
<li><a href="#6.2.28">smtp_host</a></li>
<li><a href="#6.2.29">smtp_port</a></li>
<li><a href="#6.2.30">smtp_ssl</a></li>
<li><a href="#6.2.31">smtp_start_tls</a></li>
<li><a href="#6.2.32">smtp_http_proxy_host_name</a></li>
<li><a href="#6.2.33">smtp_http_proxy_host_port</a></li>
<li><a href="#6.2.34">smtp_socks_host_name</a></li>
<li><a href="#6.2.35">smtp_socks_host_port</a></li>
<li><a href="#6.2.36">smtp_socks_version</a></li>
<li><a href="#6.2.37">smtp_direct_delivery</a></li>
<li><a href="#6.2.38">smtp_getmxrr</a></li>
<li><a href="#6.2.39">smtp_exclude_address</a></li>
<li><a href="#6.2.40">smtp_user</a></li>
<li><a href="#6.2.41">smtp_realm</a></li>
<li><a href="#6.2.42">smtp_workstation</a></li>
<li><a href="#6.2.43">smtp_authentication_mechanism</a></li>
<li><a href="#6.2.44">smtp_password</a></li>
<li><a href="#6.2.45">smtp_pop3_auth_host</a></li>
<li><a href="#6.2.46">smtp_debug</a></li>
<li><a href="#6.2.47">smtp_html_debug</a></li>
<li><a href="#6.2.48">esmtp</a></li>
<li><a href="#6.2.49">timeout</a></li>
<li><a href="#6.2.50">invalid_recipients</a></li>
<li><a href="#6.2.51">mailer_delivery</a></li>
<li><a href="#6.2.52">maximum_bulk_deliveries</a></li>
</ul>
<li><a href="#7.1.1">Inherited variables</a></li>
<li><a href="#9.1.1">Functions</a></li>
<li><a href="#11.1.1">Inherited functions</a></li>
</ul>
<p><a href="#table_of_contents">Top of the table of contents</a></p>
</ul>
<hr />
<ul>
<h2><li><a name="2.1.1">Summary</a></li></h2>
<ul>
<h3><a name="3.2.0">Name</a></h3>
<p>MIME E-mail message composing and sending via SMTP</p>
<h3><a name="3.2.0.0">Author</a></h3>
<p>Manuel Lemos (<a href="mailto:mlemos-at-acm.org">mlemos-at-acm.org</a>)</p>
<h3><a name="3.2.0.1">Copyright</a></h3>
<p>Copyright &copy; (C) Manuel Lemos 1999-2004</p>
<h3><a name="3.2.0.2">Version</a></h3>
<p>@(#) $Id: smtp_message_class.html,v 1.1 2014/03/03 12:28:32 horst Exp $</p>
<h3><a name="3.2.0.3">Parent classes</a></h3>
<ul>
<p><li>MIME E-mail message composing and sending</li></p>
<p><b>Version:</b> <tt>@(#) $Id: smtp_message_class.html,v 1.1 2014/03/03 12:28:32 horst Exp $</tt></p>
</ul>
<h3><a name="4.2.0">Purpose</a></h3>
<p>Implement an alternative message delivery method via SMTP protocol, overriding the method of using the PHP <tt>mail()</tt> function implemented by the base class.</p>
<h3><a name="4.2.0.0">Usage</a></h3>
<p>This class should be used exactly the same way as the base class for composing and sending messages. Just create a new object of this class as follows and set only the necessary variables to configure details of the SMTP delivery.</p>
<p> <tt>require('email_message.php');<br />
require('smtp.php');<br />
require('smtp_message.php');<br />
<br />
$message_object = new smtp_message_class;<br />
</tt></p>
<p> <b>- Requirements</b></p>
<p> You need the <a href="http://freshmeat.net/projects/smtpclass/">SMTP E-mail sending class</a> to perform the actual message delivery via the SMTP protocol.</p>
<p> <b>- SMTP connection</b></p>
<p> Before sending a message by relaying it to a given SMTP server you need set the <tt><a href="#variable_smtp_host">smtp_host</a></tt> variable to that server address. The <tt><a href="#variable_localhost">localhost</a></tt> variable needs to be set to the sending computer address.</p>
<p> You may also adjust the time the class will wait for establishing a connection by changing the <tt><a href="#variable_timeout">timeout</a></tt> variable.</p>
<p> <b>- Secure SMTP connections with SSL</b></p>
<p> Some SMTP servers, like for instance Gmail, require secure connections via SSL. In that case it is necessary to set the <tt><a href="#variable_smtp_ssl">smtp_ssl</a></tt> variable to 1. In the case of Gmail, it is also necessary to set the connection port changing the <tt><a href="#variable_smtp_port">smtp_port</a></tt> variable to 465.</p>
<p> SSL support requires at least PHP 4.3.0 with OpenSSL extension enabled.</p>
<p> <b>- Secure SMTP connections starting TLS after connections is established</b></p>
<p> Some SMTP servers, like for instance Hotmail, require starting the TLS protocol after the connection is already established to exchange data securely. In that case it is necessary to set the <tt><a href="#variable_smtp_start_tls">smtp_start_tls</a></tt> variable to 1.</p>
<p> Starting TLS protocol on an already established connection requires at least PHP 5.1.0 with OpenSSL extension enabled.</p>
<p> <b>- Authentication</b></p>
<p> Most servers only allow relaying messages sent by authorized users. If the SMTP server that you want to use requires authentication, you need to set the variables <tt><a href="#variable_smtp_user">smtp_user</a></tt>, <tt><a href="#variable_smtp_realm">smtp_realm</a></tt> and <tt><a href="#variable_smtp_password">smtp_password</a></tt>.</p>
<p> The way these values need to be set depends on the server. Usually the realm value is empty and only the user and password need to be set. If the server requires authentication via <tt>NTLM</tt> mechanism (Windows or Samba), you need to set the <tt><a href="#variable_smtp_realm">smtp_realm</a></tt> to the Windows domain name and also set the variable <tt><a href="#variable_smtp_workstation">smtp_workstation</a></tt> to the user workstation name.</p>
<p> Some servers require that the authentication be done on a separate server using the POP3 protocol before connecting to the SMTP server. In this case you need to specify the address of the POP3 server setting the <tt><a href="#variable_smtp_pop3_auth_host">smtp_pop3_auth_host</a></tt> variable.</p>
<p> <b>- Sending urgent messages with direct delivery</b></p>
<p> If you need to send urgent messages or obtain immediate confirmation that a message is accepted by the recipient SMTP server, you can use the direct delivery mode setting the <tt><a href="#variable_direct_delivery">direct_delivery</a></tt> variable to <tt>1</tt>. This mode can be used to send a message to only one recipient.</p>
<p> To use this mode, it is necessary to have a way to determine the recipient domain SMTP server address. The class uses the PHP <tt>getmxrr()</tt> function, but on some systems like for instance under Windows, this function does not work. In this case you may specify an equivalent alternative by setting the <tt><a href="#variable_smtp_getmxrr">smtp_getmxrr</a></tt> variable. See the SMTP class page for available alternatives.</p>
<p> <b>- Troubleshooting and debugging</b></p>
<p> If for some reason the delivery via SMTP is not working and the error messages are not self-explanatory, you may set the <tt><a href="#variable_smtp_debug">smtp_debug</a></tt> to <tt>1</tt> to make the class output the SMTP protocol dialog with the server. If you want to display this dialog properly formatted in an HTML page, also set the <tt><a href="#variable_smtp_debug">smtp_debug</a></tt> to <tt>1</tt>.</p>
<p> <b>- Optimizing the delivery of messages to many recipients</b></p>
<p> When sending messages to many recipients, this class can hinted to optimize its behavior by using the <tt><a href="#function_SetBulkMail">SetBulkMail</a></tt> function. After calling this function passing 1 to the <tt><a href="#argument_SetBulkMail_on">on</a></tt> argument, when the message is sent this class opens a TCP connection to the SMTP server but will not close it. This avoids the overhead of opening and closing connections.</p>
<p> When the delivery of the messages to all recipients is done, the connection may be closed implicitly by calling the <tt><a href="#function_SetBulkMail">SetBulkMail</a></tt> function again passing 0 to the <tt><a href="#argument_SetBulkMail_on">on</a></tt> argument.</p>
<p><a href="#table_of_contents">Table of contents</a></p>
</ul>
</ul>
<hr />
<ul>
<h2><li><a name="variables"></a><a name="5.1.1">Variables</a></li></h2>
<ul>
<li><tt><a href="#variable_localhost">localhost</a></tt></li><br />
<li><tt><a href="#variable_smtp_host">smtp_host</a></tt></li><br />
<li><tt><a href="#variable_smtp_port">smtp_port</a></tt></li><br />
<li><tt><a href="#variable_smtp_ssl">smtp_ssl</a></tt></li><br />
<li><tt><a href="#variable_smtp_start_tls">smtp_start_tls</a></tt></li><br />
<li><tt><a href="#variable_smtp_http_proxy_host_name">smtp_http_proxy_host_name</a></tt></li><br />
<li><tt><a href="#variable_smtp_http_proxy_host_port">smtp_http_proxy_host_port</a></tt></li><br />
<li><tt><a href="#variable_smtp_socks_host_name">smtp_socks_host_name</a></tt></li><br />
<li><tt><a href="#variable_smtp_socks_host_port">smtp_socks_host_port</a></tt></li><br />
<li><tt><a href="#variable_smtp_socks_version">smtp_socks_version</a></tt></li><br />
<li><tt><a href="#variable_smtp_direct_delivery">smtp_direct_delivery</a></tt></li><br />
<li><tt><a href="#variable_smtp_getmxrr">smtp_getmxrr</a></tt></li><br />
<li><tt><a href="#variable_smtp_exclude_address">smtp_exclude_address</a></tt></li><br />
<li><tt><a href="#variable_smtp_user">smtp_user</a></tt></li><br />
<li><tt><a href="#variable_smtp_realm">smtp_realm</a></tt></li><br />
<li><tt><a href="#variable_smtp_workstation">smtp_workstation</a></tt></li><br />
<li><tt><a href="#variable_smtp_authentication_mechanism">smtp_authentication_mechanism</a></tt></li><br />
<li><tt><a href="#variable_smtp_password">smtp_password</a></tt></li><br />
<li><tt><a href="#variable_smtp_pop3_auth_host">smtp_pop3_auth_host</a></tt></li><br />
<li><tt><a href="#variable_smtp_debug">smtp_debug</a></tt></li><br />
<li><tt><a href="#variable_smtp_html_debug">smtp_html_debug</a></tt></li><br />
<li><tt><a href="#variable_esmtp">esmtp</a></tt></li><br />
<li><tt><a href="#variable_timeout">timeout</a></tt></li><br />
<li><tt><a href="#variable_invalid_recipients">invalid_recipients</a></tt></li><br />
<li><tt><a href="#variable_mailer_delivery">mailer_delivery</a></tt></li><br />
<li><tt><a href="#variable_maximum_bulk_deliveries">maximum_bulk_deliveries</a></tt></li><br />
<p><a href="#table_of_contents">Table of contents</a></p>
<h3><a name="variable_localhost"></a><li><a name="6.2.27">localhost</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify the domain name of the computer sending the message.</p>
<h3>Usage</h3>
<p>This value is used to identify the sending machine to the SMTP server. When using the direct delivery mode, if this variable is set to a non-empty string it used to generate the <tt>Recieved</tt> header to show that the message passed by the specified host address. To prevent confusing directly delivered messages with spam, it is strongly recommended that you set this variable to you server host name.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_host"></a><li><a name="6.2.28">smtp_host</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify the address of the SMTP server.</p>
<h3>Usage</h3>
<p>Set to the address of the SMTP server that will relay the messages. This variable is not used in direct delivery mode.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_port"></a><li><a name="6.2.29">smtp_port</a></li></h3>
<h3>Type</h3>
<p><tt><i>int</i></tt></p>
<h3>Default value</h3>
<p><tt>25</tt></p>
<h3>Purpose</h3>
<p>Specify the TCP/IP port of SMTP server to connect.</p>
<h3>Usage</h3>
<p>Most servers work on port 25 . Certain e-mail services use alternative ports to avoid firewall blocking. Gmail uses port 465.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_ssl"></a><li><a name="6.2.30">smtp_ssl</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>0</tt></p>
<h3>Purpose</h3>
<p>Specify whether it should use secure connections with SSL to connect to the SMTP server.</p>
<h3>Usage</h3>
<p>Certain e-mail services like Gmail require SSL connections.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_start_tls"></a><li><a name="6.2.31">smtp_start_tls</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>0</tt></p>
<h3>Purpose</h3>
<p>Specify whether it should use secure connections starting TLS protocol after connecting to the SMTP server.</p>
<h3>Usage</h3>
<p>Certain e-mail services like Hotmail require starting TLS protocol after the connection to the SMTP server is already established.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_http_proxy_host_name"></a><li><a name="6.2.32">smtp_http_proxy_host_name</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify name of the host when the connection should be routed via an HTTP proxy.</p>
<h3>Usage</h3>
<p>Leave empty if no proxy should be used.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_http_proxy_host_port"></a><li><a name="6.2.33">smtp_http_proxy_host_port</a></li></h3>
<h3>Type</h3>
<p><tt><i>int</i></tt></p>
<h3>Default value</h3>
<p><tt>3128</tt></p>
<h3>Purpose</h3>
<p>Specify proxy port when the connection should be routed via an HTTP proxy.</p>
<h3>Usage</h3>
<p>Change this variable if you need to use a proxy with a specific port.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_socks_host_name"></a><li><a name="6.2.34">smtp_socks_host_name</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify name of the host when the connection should be routed via a SOCKS protocol proxy.</p>
<h3>Usage</h3>
<p>Leave empty if no proxy should be used.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_socks_host_port"></a><li><a name="6.2.35">smtp_socks_host_port</a></li></h3>
<h3>Type</h3>
<p><tt><i>int</i></tt></p>
<h3>Default value</h3>
<p><tt>1080</tt></p>
<h3>Purpose</h3>
<p>Specify proxy port when the connection should be routed via a SOCKS protocol proxy.</p>
<h3>Usage</h3>
<p>Change this variable if you need to use a proxy with a specific port.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_socks_version"></a><li><a name="6.2.36">smtp_socks_version</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify protocol version when the connection should be routed via a SOCKS protocol proxy.</p>
<h3>Usage</h3>
<p>Change this variable if you need to use a proxy with a specific SOCKS protocol version.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_direct_delivery"></a><li><a name="6.2.37">smtp_direct_delivery</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>0</tt></p>
<h3>Purpose</h3>
<p>Boolean flag that indicates whether the message should be sent in direct delivery mode.</p>
<h3>Usage</h3>
<p>Set this to <tt>1</tt> if you want to send urgent messages directly to the recipient domain SMTP server.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_getmxrr"></a><li><a name="6.2.38">smtp_getmxrr</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>'getmxrr'</tt></p>
<h3>Purpose</h3>
<p>Specify the name of the function that is called to determine the SMTP server address of a given domain.</p>
<h3>Usage</h3>
<p>Change this to a working replacement of the PHP <tt>getmxrr()</tt> function if this is not working in your system and you want to send messages in direct delivery mode.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_exclude_address"></a><li><a name="6.2.39">smtp_exclude_address</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify an address that should be considered invalid when resolving host name addresses.</p>
<h3>Usage</h3>
<p>In some networks any domain name that does not exist is resolved as a sub-domain of the default local domain. If the DNS is configured in such way that it always resolves any sub-domain of the default local domain to a given address, it is hard to determine whether a given domain does not exist.</p>
<p> If your network is configured this way, you may set this variable to the address that all sub-domains of the default local domain resolves, so the class can assume that such address is invalid.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_user"></a><li><a name="6.2.40">smtp_user</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify the user name for authentication.</p>
<h3>Usage</h3>
<p>Set this variable if you need to authenticate before sending a message.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_realm"></a><li><a name="6.2.41">smtp_realm</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify the user authentication realm.</p>
<h3>Usage</h3>
<p>Set this variable if you need to authenticate before sending a message.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_workstation"></a><li><a name="6.2.42">smtp_workstation</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify the user authentication workstation needed when using the <tt>NTLM</tt> authentication (Windows or Samba).</p>
<h3>Usage</h3>
<p>Set this variable if you need to authenticate before sending a message.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_authentication_mechanism"></a><li><a name="6.2.43">smtp_authentication_mechanism</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify the user authentication mechanism that should be used when authenticating with the SMTP server.</p>
<h3>Usage</h3>
<p>Set this variable if you need to force the SMTP connection to authenticate with a specific authentication mechanism. Leave this variable with an empty string if you want the authentication mechanism be determined automatically from the list of mechanisms supported by the server.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_password"></a><li><a name="6.2.44">smtp_password</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify the user authentication password.</p>
<h3>Usage</h3>
<p>Set this variable if you need to authenticate before sending a message.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_pop3_auth_host"></a><li><a name="6.2.45">smtp_pop3_auth_host</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>''</tt></p>
<h3>Purpose</h3>
<p>Specify the server address for POP3 based authentication.</p>
<h3>Usage</h3>
<p>Set this variable to the address of the POP3 server if the SMTP server requires POP3 based authentication.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_debug"></a><li><a name="6.2.46">smtp_debug</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>0</tt></p>
<h3>Purpose</h3>
<p>Specify whether it is necessary to output SMTP connection debug information.</p>
<h3>Usage</h3>
<p>Set this variable to <tt>1</tt> if you need to see the progress of the SMTP connection and protocol dialog when you need to understand the reason for delivery problems.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_smtp_html_debug"></a><li><a name="6.2.47">smtp_html_debug</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>0</tt></p>
<h3>Purpose</h3>
<p>Specify whether the debug information should be outputted in HTML format.</p>
<h3>Usage</h3>
<p>Set this variable to <tt>1</tt> if you need to see the debug output in a Web page.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_esmtp"></a><li><a name="6.2.48">esmtp</a></li></h3>
<h3>Type</h3>
<p><tt><i>bool</i></tt></p>
<h3>Default value</h3>
<p><tt>1</tt></p>
<h3>Purpose</h3>
<p>Specify whether the class should try to use Enhanced SMTP protocol features.</p>
<h3>Usage</h3>
<p>It is recommended to leave this variable set to <tt>1</tt> so the class can take advantage of Enhanced SMTP protocol features.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_timeout"></a><li><a name="6.2.49">timeout</a></li></h3>
<h3>Type</h3>
<p><tt><i>int</i></tt></p>
<h3>Default value</h3>
<p><tt>25</tt></p>
<h3>Purpose</h3>
<p>Specify the connection timeout period in seconds.</p>
<h3>Usage</h3>
<p>Change this value if for some reason the timeout period seems insufficient or otherwise it seems too long.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_invalid_recipients"></a><li><a name="6.2.50">invalid_recipients</a></li></h3>
<h3>Type</h3>
<p><tt><i>array</i></tt></p>
<h3>Default value</h3>
<p><tt>array()</tt></p>
<h3>Purpose</h3>
<p>Return the list of recipient addresses that were not accepted by the SMTP server.</p>
<h3>Usage</h3>
<p>Check this variable after attempting to send a message to figure whether there were any recipients that were rejected by the SMTP server.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_mailer_delivery"></a><li><a name="6.2.51">mailer_delivery</a></li></h3>
<h3>Type</h3>
<p><tt><i>string</i></tt></p>
<h3>Default value</h3>
<p><tt>'smtp $Revision: 1.1 $'</tt></p>
<h3>Purpose</h3>
<p>Specify the text that is used to identify the mail delivery class or sub-class. This text is appended to the <tt>X-Mailer</tt> header text defined by the mailer variable.</p>
<h3>Usage</h3>
<p>Do not change this variable.</p>
<p><a href="#variables">Variables</a></p>
<h3><a name="variable_maximum_bulk_deliveries"></a><li><a name="6.2.52">maximum_bulk_deliveries</a></li></h3>
<h3>Type</h3>
<p><tt><i>int</i></tt></p>
<h3>Default value</h3>
<p><tt>100</tt></p>
<h3>Purpose</h3>
<p>Specify the number of consecutive bulk mail deliveries without disconnecting.</p>
<h3>Usage</h3>
<p>Lower this value if you have enabled the bulk mail mode but the SMTP server does not accept sending more than a number of messages within the same SMTP connection.</p>
<p> Set this value to 0 to never disconnect during bulk mail mode unless an error occurs.</p>
<p><a href="#variables">Variables</a></p>
<p><a href="#table_of_contents">Table of contents</a></p>
</ul>
</ul>
<ul>
<h2><li><a name="functions"></a><a name="7.1.1">Inherited variables</a></li></h2>
<ul>
<li>email_regular_expression</li><br />
<li>mailer</li><br />
<li>default_charset</li><br />
<li>line_quote_prefix</li><br />
<li>break_long_lines</li><br />
<li>file_buffer_length</li><br />
<li>debug</li><br />
<li>cache_body</li><br />
<li>error</li><br />
<p><a href="#table_of_contents">Table of contents</a></p>
</ul>
</ul>
<hr />
<ul>
<h2><li><a name="functions"></a><a name="9.1.1">Functions</a></li></h2>
<ul>
<p><a href="#table_of_contents">Table of contents</a></p>
<p><a href="#table_of_contents">Table of contents</a></p>
</ul>
</ul>
<ul>
<h2><li><a name="functions"></a><a name="11.1.1">Inherited functions</a></li></h2>
<ul>
<li>ValidateEmailAddress</li><br />
<li>WrapText</li><br />
<li>CenterText</li><br />
<li>Ruler</li><br />
<li>QuoteText</li><br />
<li>SetHeader</li><br />
<li>SetEncodedHeader</li><br />
<li>SetEncodedEmailHeader</li><br />
<li>SetMultipleEncodedEmailHeader</li><br />
<li>ResetMessage</li><br />
<li>AddPart</li><br />
<li>ReplacePart</li><br />
<li>CreatePlainTextPart</li><br />
<li>AddPlainTextPart</li><br />
<li>CreateQuotedPrintableTextPart</li><br />
<li>AddQuotedPrintableTextPart</li><br />
<li>CreateHTMLPart</li><br />
<li>AddHTMLPart</li><br />
<li>CreateQuotedPrintableHTMLPart</li><br />
<li>AddQuotedPrintableHTMLPart</li><br />
<li>CreateFilePart</li><br />
<li>AddFilePart</li><br />
<li>CreateMessagePart</li><br />
<li>AddMessagePart</li><br />
<li>CreateAlternativeMultipart</li><br />
<li>AddAlternativeMultipart</li><br />
<li>CreateRelatedMultipart</li><br />
<li>AddRelatedMultipart</li><br />
<li>CreateMixedMultipart</li><br />
<li>AddMixedMultipart</li><br />
<li>GetPartContentID</li><br />
<li>GetDataURL</li><br />
<li>Send</li><br />
<li>GetMessage</li><br />
<li>GetMessageSize</li><br />
<li>Mail</li><br />
<li>SetBulkMail</li><br />
<p><a href="#table_of_contents">Table of contents</a></p>
</ul>
</ul>
<hr />
<address>Manuel Lemos (<a href="mailto:mlemos-at-acm.org">mlemos-at-acm.org</a>)</address>
</body>
</html>

File diff suppressed because it is too large Load diff

View file

@ -1,69 +0,0 @@
<?php
/*
* login_sasl_client.php
*
* @(#) $Id: login_sasl_client.php,v 1.2 2004/11/17 08:00:37 mlemos Exp $
*
*/
define("SASL_LOGIN_STATE_START", 0);
define("SASL_LOGIN_STATE_IDENTIFY_USER", 1);
define("SASL_LOGIN_STATE_IDENTIFY_PASSWORD", 2);
define("SASL_LOGIN_STATE_DONE", 3);
class login_sasl_client_class
{
var $credentials=array();
var $state=SASL_LOGIN_STATE_START;
Function Initialize(&$client)
{
return(1);
}
Function Start(&$client, &$message, &$interactions)
{
if($this->state!=SASL_LOGIN_STATE_START)
{
$client->error="LOGIN authentication state is not at the start";
return(SASL_FAIL);
}
$this->credentials=array(
"user"=>"",
"password"=>"",
"realm"=>""
);
$defaults=array(
"realm"=>""
);
$status=$client->GetCredentials($this->credentials,$defaults,$interactions);
if($status==SASL_CONTINUE)
$this->state=SASL_LOGIN_STATE_IDENTIFY_USER;
Unset($message);
return($status);
}
Function Step(&$client, $response, &$message, &$interactions)
{
switch($this->state)
{
case SASL_LOGIN_STATE_IDENTIFY_USER:
$message=$this->credentials["user"].(strlen($this->credentials["realm"]) ? "@".$this->credentials["realm"] : "");
$this->state=SASL_LOGIN_STATE_IDENTIFY_PASSWORD;
break;
case SASL_LOGIN_STATE_IDENTIFY_PASSWORD:
$message=$this->credentials["password"];
$this->state=SASL_LOGIN_STATE_DONE;
break;
case SASL_LOGIN_STATE_DONE:
$client->error="LOGIN authentication was finished without success";
break;
default:
$client->error="invalid LOGIN authentication step state";
return(SASL_FAIL);
}
return(SASL_CONTINUE);
}
};
?>

View file

@ -1,180 +0,0 @@
<?php
/*
* ntlm_sasl_client.php
*
* @(#) $Id: ntlm_sasl_client.php,v 1.3 2004/11/17 08:00:37 mlemos Exp $
*
*/
define("SASL_NTLM_STATE_START", 0);
define("SASL_NTLM_STATE_IDENTIFY_DOMAIN", 1);
define("SASL_NTLM_STATE_RESPOND_CHALLENGE", 2);
define("SASL_NTLM_STATE_DONE", 3);
class ntlm_sasl_client_class
{
var $credentials=array();
var $state=SASL_NTLM_STATE_START;
Function Initialize(&$client)
{
if(!function_exists($function="mcrypt_encrypt")
|| !function_exists($function="mhash"))
{
$extensions=array(
"mcrypt_encrypt"=>"mcrypt",
"mhash"=>"mhash"
);
$client->error="the extension ".$extensions[$function]." required by the NTLM SASL client class is not available in this PHP configuration";
return(0);
}
return(1);
}
Function ASCIIToUnicode($ascii)
{
for($unicode="",$a=0;$a<strlen($ascii);$a++)
$unicode.=substr($ascii,$a,1).chr(0);
return($unicode);
}
Function TypeMsg1($domain,$workstation)
{
$domain_length=strlen($domain);
$workstation_length=strlen($workstation);
$workstation_offset=32;
$domain_offset=$workstation_offset+$workstation_length;
return(
"NTLMSSP\0".
"\x01\x00\x00\x00".
"\x07\x32\x00\x00".
pack("v",$domain_length).
pack("v",$domain_length).
pack("V",$domain_offset).
pack("v",$workstation_length).
pack("v",$workstation_length).
pack("V",$workstation_offset).
$workstation.
$domain
);
}
Function NTLMResponse($challenge,$password)
{
$unicode=$this->ASCIIToUnicode($password);
$md4=mhash(MHASH_MD4,$unicode);
$padded=$md4.str_repeat(chr(0),21-strlen($md4));
$iv_size=mcrypt_get_iv_size(MCRYPT_DES,MCRYPT_MODE_ECB);
$iv=mcrypt_create_iv($iv_size,MCRYPT_RAND);
for($response="",$third=0;$third<21;$third+=7)
{
for($packed="",$p=$third;$p<$third+7;$p++)
$packed.=str_pad(decbin(ord(substr($padded,$p,1))),8,"0",STR_PAD_LEFT);
for($key="",$p=0;$p<strlen($packed);$p+=7)
{
$s=substr($packed,$p,7);
$b=$s.((substr_count($s,"1") % 2) ? "0" : "1");
$key.=chr(bindec($b));
}
$ciphertext=mcrypt_encrypt(MCRYPT_DES,$key,$challenge,MCRYPT_MODE_ECB,$iv);
$response.=$ciphertext;
}
return $response;
}
Function TypeMsg3($ntlm_response,$user,$domain,$workstation)
{
$domain_unicode=$this->ASCIIToUnicode($domain);
$domain_length=strlen($domain_unicode);
$domain_offset=64;
$user_unicode=$this->ASCIIToUnicode($user);
$user_length=strlen($user_unicode);
$user_offset=$domain_offset+$domain_length;
$workstation_unicode=$this->ASCIIToUnicode($workstation);
$workstation_length=strlen($workstation_unicode);
$workstation_offset=$user_offset+$user_length;
$lm="";
$lm_length=strlen($lm);
$lm_offset=$workstation_offset+$workstation_length;
$ntlm=$ntlm_response;
$ntlm_length=strlen($ntlm);
$ntlm_offset=$lm_offset+$lm_length;
$session="";
$session_length=strlen($session);
$session_offset=$ntlm_offset+$ntlm_length;
return(
"NTLMSSP\0".
"\x03\x00\x00\x00".
pack("v",$lm_length).
pack("v",$lm_length).
pack("V",$lm_offset).
pack("v",$ntlm_length).
pack("v",$ntlm_length).
pack("V",$ntlm_offset).
pack("v",$domain_length).
pack("v",$domain_length).
pack("V",$domain_offset).
pack("v",$user_length).
pack("v",$user_length).
pack("V",$user_offset).
pack("v",$workstation_length).
pack("v",$workstation_length).
pack("V",$workstation_offset).
pack("v",$session_length).
pack("v",$session_length).
pack("V",$session_offset).
"\x01\x02\x00\x00".
$domain_unicode.
$user_unicode.
$workstation_unicode.
$lm.
$ntlm
);
}
Function Start(&$client, &$message, &$interactions)
{
if($this->state!=SASL_NTLM_STATE_START)
{
$client->error="NTLM authentication state is not at the start";
return(SASL_FAIL);
}
$this->credentials=array(
"user"=>"",
"password"=>"",
"realm"=>"",
"workstation"=>""
);
$defaults=array();
$status=$client->GetCredentials($this->credentials,$defaults,$interactions);
if($status==SASL_CONTINUE)
$this->state=SASL_NTLM_STATE_IDENTIFY_DOMAIN;
Unset($message);
return($status);
}
Function Step(&$client, $response, &$message, &$interactions)
{
switch($this->state)
{
case SASL_NTLM_STATE_IDENTIFY_DOMAIN:
$message=$this->TypeMsg1($this->credentials["realm"],$this->credentials["workstation"]);
$this->state=SASL_NTLM_STATE_RESPOND_CHALLENGE;
break;
case SASL_NTLM_STATE_RESPOND_CHALLENGE:
$ntlm_response=$this->NTLMResponse(substr($response,24,8),$this->credentials["password"]);
$message=$this->TypeMsg3($ntlm_response,$this->credentials["user"],$this->credentials["realm"],$this->credentials["workstation"]);
$this->state=SASL_NTLM_STATE_DONE;
break;
case SASL_NTLM_STATE_DONE:
$client->error="NTLM authentication was finished without success";
return(SASL_FAIL);
default:
$client->error="invalid NTLM authentication step state";
return(SASL_FAIL);
}
return(SASL_CONTINUE);
}
};
?>

View file

@ -1,99 +0,0 @@
<?php
/*
* plain_sasl_client.php
*
* @(#) $Id: plain_sasl_client.php,v 1.2 2004/11/17 08:00:37 mlemos Exp $
*
*/
define("SASL_PLAIN_STATE_START", 0);
define("SASL_PLAIN_STATE_IDENTIFY", 1);
define("SASL_PLAIN_STATE_DONE", 2);
define("SASL_PLAIN_DEFAULT_MODE", 0);
define("SASL_PLAIN_EXIM_MODE", 1);
define("SASL_PLAIN_EXIM_DOCUMENTATION_MODE", 2);
class plain_sasl_client_class
{
var $credentials=array();
var $state=SASL_PLAIN_STATE_START;
Function Initialize(&$client)
{
return(1);
}
Function Start(&$client, &$message, &$interactions)
{
if($this->state!=SASL_PLAIN_STATE_START)
{
$client->error="PLAIN authentication state is not at the start";
return(SASL_FAIL);
}
$this->credentials=array(
"user"=>"",
"password"=>"",
"realm"=>"",
"mode"=>""
);
$defaults=array(
"realm"=>"",
"mode"=>""
);
$status=$client->GetCredentials($this->credentials,$defaults,$interactions);
if($status==SASL_CONTINUE)
{
switch($this->credentials["mode"])
{
case SASL_PLAIN_EXIM_MODE:
$message=$this->credentials["user"]."\0".$this->credentials["password"]."\0";
break;
case SASL_PLAIN_EXIM_DOCUMENTATION_MODE:
$message="\0".$this->credentials["user"]."\0".$this->credentials["password"];
break;
default:
$message=$this->credentials["user"]."\0".$this->credentials["user"].(strlen($this->credentials["realm"]) ? "@".$this->credentials["realm"] : "")."\0".$this->credentials["password"];
break;
}
$this->state=SASL_PLAIN_STATE_DONE;
}
else
Unset($message);
return($status);
}
Function Step(&$client, $response, &$message, &$interactions)
{
switch($this->state)
{
/*
case SASL_PLAIN_STATE_IDENTIFY:
switch($this->credentials["mode"])
{
case SASL_PLAIN_EXIM_MODE:
$message=$this->credentials["user"]."\0".$this->credentials["password"]."\0";
break;
case SASL_PLAIN_EXIM_DOCUMENTATION_MODE:
$message="\0".$this->credentials["user"]."\0".$this->credentials["password"];
break;
default:
$message=$this->credentials["user"]."\0".$this->credentials["user"].(strlen($this->credentials["realm"]) ? "@".$this->credentials["realm"] : "")."\0".$this->credentials["password"];
break;
}
var_dump($message);
$this->state=SASL_PLAIN_STATE_DONE;
break;
*/
case SASL_PLAIN_STATE_DONE:
$client->error="PLAIN authentication was finished without success";
return(SASL_FAIL);
default:
$client->error="invalid PLAIN authentication step state";
return(SASL_FAIL);
}
return(SASL_CONTINUE);
}
};
?>

View file

@ -1,422 +0,0 @@
<?php
/*
* sasl.php
*
* @(#) $Id: sasl.php,v 1.11 2005/10/31 18:43:27 mlemos Exp $
*
*/
define("SASL_INTERACT", 2);
define("SASL_CONTINUE", 1);
define("SASL_OK", 0);
define("SASL_FAIL", -1);
define("SASL_NOMECH", -4);
class sasl_interact_class
{
var $id;
var $challenge;
var $prompt;
var $default_result;
var $result;
};
/*
{metadocument}<?xml version="1.0" encoding="ISO-8859-1" ?>
<class>
<package>net.manuellemos.sasl</package>
<version>@(#) $Id: sasl.php,v 1.11 2005/10/31 18:43:27 mlemos Exp $</version>
<copyright>Copyright © (C) Manuel Lemos 2004</copyright>
<title>Simple Authentication and Security Layer client</title>
<author>Manuel Lemos</author>
<authoraddress>mlemos-at-acm.org</authoraddress>
<documentation>
<idiom>en</idiom>
<purpose>Provide a common interface to plug-in driver classes that
implement different mechanisms for authentication used by clients of
standard protocols like SMTP, POP3, IMAP, HTTP, etc.. Currently the
supported authentication mechanisms are: <tt>PLAIN</tt>,
<tt>LOGIN</tt>, <tt>CRAM-MD5</tt>, <tt>Digest</tt> and <tt>NTML</tt>
(Windows or Samba).</purpose>
<usage>.</usage>
</documentation>
{/metadocument}
*/
class sasl_client_class
{
/* Public variables */
/*
{metadocument}
<variable>
<name>error</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Store the message that is returned when an error
occurs.</purpose>
<usage>Check this variable to understand what happened when a call to
any of the class functions has failed.<paragraphbreak />
This class uses cumulative error handling. This means that if one
class functions that may fail is called and this variable was
already set to an error message due to a failure in a previous call
to the same or other function, the function will also fail and does
not do anything.<paragraphbreak />
This allows programs using this class to safely call several
functions that may fail and only check the failure condition after
the last function call.<paragraphbreak />
Just set this variable to an empty string to clear the error
condition.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $error='';
/*
{metadocument}
<variable>
<name>mechanism</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Store the name of the mechanism that was selected during the
call to the <functionlink>Start</functionlink> function.</purpose>
<usage>You can access this variable but do not change it.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $mechanism='';
/*
{metadocument}
<variable>
<name>encode_response</name>
<type>BOOLEAN</type>
<value>1</value>
<documentation>
<purpose>Let the drivers inform the applications whether responses
need to be encoded.</purpose>
<usage>Applications should check this variable before sending
authentication responses to the server to determine if the
responses need to be encoded, eventually with base64 algorithm.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $encode_response=1;
/* Private variables */
var $driver;
var $drivers=array(
"Digest" => array("digest_sasl_client_class", "digest_sasl_client.php" ),
"CRAM-MD5" => array("cram_md5_sasl_client_class", "cram_md5_sasl_client.php" ),
"LOGIN" => array("login_sasl_client_class", "login_sasl_client.php" ),
"NTLM" => array("ntlm_sasl_client_class", "ntlm_sasl_client.php" ),
"PLAIN" => array("plain_sasl_client_class", "plain_sasl_client.php" ),
"Basic" => array("basic_sasl_client_class", "basic_sasl_client.php" )
);
var $credentials=array();
/* Public functions */
/*
{metadocument}
<function>
<name>SetCredential</name>
<type>VOID</type>
<documentation>
<purpose>Store the value of a credential that may be used by any of
the supported mechanisms to process the authentication messages and
responses.</purpose>
<usage>Call this function before starting the authentication dialog
to pass all the credential values that be needed to use the type
of authentication that the applications may need.</usage>
<returnvalue>.</returnvalue>
</documentation>
<argument>
<name>key</name>
<type>STRING</type>
<documentation>
<purpose>Specify the name of the credential key.</purpose>
</documentation>
</argument>
<argument>
<name>value</name>
<type>STRING</type>
<documentation>
<purpose>Specify the value for the credential.</purpose>
</documentation>
</argument>
<do>
{/metadocument}
*/
Function SetCredential($key,$value)
{
$this->credentials[$key]=$value;
}
/*
{metadocument}
</do>
</function>
{/metadocument}
*/
/*
{metadocument}
<function>
<name>GetCredentials</name>
<type>INTEGER</type>
<documentation>
<purpose>Retrieve the values of one or more credentials to be used by
the authentication mechanism classes.</purpose>
<usage>This is meant to be used by authentication mechanism driver
classes to retrieve the credentials that may be neede.</usage>
<returnvalue>The function may return <tt>SASL_CONTINUE</tt> if it
succeeded, or <tt>SASL_NOMECH</tt> if it was not possible to
retrieve one of the requested credentials.</returnvalue>
</documentation>
<argument>
<name>credentials</name>
<type>HASH</type>
<documentation>
<purpose>Reference to an associative array variable with all the
credentials that are being requested. The function initializes
this associative array values.</purpose>
</documentation>
</argument>
<argument>
<name>defaults</name>
<type>HASH</type>
<documentation>
<purpose>Associative arrays with default values for credentials
that may have not been defined.</purpose>
</documentation>
</argument>
<argument>
<name>interactions</name>
<type>ARRAY</type>
<documentation>
<purpose>Not yet in use. It is meant to provide context
information to retrieve credentials that may be obtained
interacting with the user.</purpose>
</documentation>
</argument>
<do>
{/metadocument}
*/
Function GetCredentials(&$credentials,$defaults,&$interactions)
{
Reset($credentials);
$end=(GetType($key=Key($credentials))!="string");
for(;!$end;)
{
if(!IsSet($this->credentials[$key]))
{
if(IsSet($defaults[$key]))
$credentials[$key]=$defaults[$key];
else
{
$this->error="the requested credential ".$key." is not defined";
return(SASL_NOMECH);
}
}
else
$credentials[$key]=$this->credentials[$key];
Next($credentials);
$end=(GetType($key=Key($credentials))!="string");
}
return(SASL_CONTINUE);
}
/*
{metadocument}
</do>
</function>
{/metadocument}
*/
/*
{metadocument}
<function>
<name>Start</name>
<type>INTEGER</type>
<documentation>
<purpose>Process the initial authentication step initializing the
driver class that implements the first of the list of requested
mechanisms that is supported by this SASL client library
implementation.</purpose>
<usage>Call this function specifying a list of mechanisms that the
server supports. If the <argumentlink>
<argument>message</argument>
<function>Start</function>
</argumentlink> argument returns a string, it should be sent to
the server as initial message. Check the
<variablelink>encode_response</variablelink> variable to determine
whether the initial message needs to be encoded, eventually with
base64 algorithm, before it is sent to the server.</usage>
<returnvalue>The function may return <tt>SASL_CONTINUE</tt> if it
could start one of the requested authentication mechanisms. It
may return <tt>SASL_NOMECH</tt> if it was not possible to start
any of the requested mechanisms. It returns <tt>SASL_FAIL</tt> or
other value in case of error.</returnvalue>
</documentation>
<argument>
<name>mechanisms</name>
<type>ARRAY</type>
<inout />
<documentation>
<purpose>Define the list of names of authentication mechanisms
supported by the that should be tried.</purpose>
</documentation>
</argument>
<argument>
<name>message</name>
<type>STRING</type>
<out />
<documentation>
<purpose>Return the initial message that should be sent to the
server to start the authentication dialog. If this value is
undefined, no message should be sent to the server.</purpose>
</documentation>
</argument>
<argument>
<name>interactions</name>
<type>ARRAY</type>
<documentation>
<purpose>Not yet in use. It is meant to provide context
information to interact with the end user.</purpose>
</documentation>
</argument>
<do>
{/metadocument}
*/
Function Start($mechanisms, &$message, &$interactions)
{
if(strlen($this->error))
return(SASL_FAIL);
if(IsSet($this->driver))
return($this->driver->Start($this,$message,$interactions));
$no_mechanism_error="";
for($m=0;$m<count($mechanisms);$m++)
{
$mechanism=$mechanisms[$m];
if(IsSet($this->drivers[$mechanism]))
{
if(!class_exists($this->drivers[$mechanism][0]))
require(dirname(__FILE__)."/".$this->drivers[$mechanism][1]);
$this->driver=new $this->drivers[$mechanism][0];
if($this->driver->Initialize($this))
{
$this->encode_response=1;
$status=$this->driver->Start($this,$message,$interactions);
switch($status)
{
case SASL_NOMECH:
Unset($this->driver);
if(strlen($no_mechanism_error)==0)
$no_mechanism_error=$this->error;
$this->error="";
break;
case SASL_CONTINUE:
$this->mechanism=$mechanism;
return($status);
default:
Unset($this->driver);
$this->error="";
return($status);
}
}
else
{
Unset($this->driver);
if(strlen($no_mechanism_error)==0)
$no_mechanism_error=$this->error;
$this->error="";
}
}
}
$this->error=(strlen($no_mechanism_error) ? $no_mechanism_error : "it was not requested any of the authentication mechanisms that are supported");
return(SASL_NOMECH);
}
/*
{metadocument}
</do>
</function>
{/metadocument}
*/
/*
{metadocument}
<function>
<name>Step</name>
<type>INTEGER</type>
<documentation>
<purpose>Process the authentication steps after the initial step,
until the authetication iteration dialog is complete.</purpose>
<usage>Call this function iteratively after a successful initial
step calling the <functionlink>Start</functionlink> function.</usage>
<returnvalue>The function returns <tt>SASL_CONTINUE</tt> if step was
processed successfully, or returns <tt>SASL_FAIL</tt> in case of
error.</returnvalue>
</documentation>
<argument>
<name>response</name>
<type>STRING</type>
<in />
<documentation>
<purpose>Pass the response returned by the server to the previous
step.</purpose>
</documentation>
</argument>
<argument>
<name>message</name>
<type>STRING</type>
<out />
<documentation>
<purpose>Return the message that should be sent to the server to
continue the authentication dialog. If this value is undefined,
no message should be sent to the server.</purpose>
</documentation>
</argument>
<argument>
<name>interactions</name>
<type>ARRAY</type>
<documentation>
<purpose>Not yet in use. It is meant to provide context
information to interact with the end user.</purpose>
</documentation>
</argument>
<do>
{/metadocument}
*/
Function Step($response, &$message, &$interactions)
{
if(strlen($this->error))
return(SASL_FAIL);
return($this->driver->Step($this,$response,$message,$interactions));
}
/*
{metadocument}
</do>
</function>
{/metadocument}
*/
};
/*
{metadocument}
</class>
{/metadocument}
*/
?>

File diff suppressed because it is too large Load diff

View file

@ -1,803 +0,0 @@
<?php
/*
* smtp_message.php
*
* @(#) $Header: /opt2/ena/metal/mimemessage/smtp_message.php,v 1.36 2011/03/09 07:48:52 mlemos Exp $
*
*
*/
/**
* @horst, 19.04.2019:
* added support for: smtp_tls_crypto_method
*
*
*/
/*
{metadocument}<?xml version="1.0" encoding="ISO-8859-1"?>
<class>
<package>net.manuellemos.mimemessage</package>
<name>smtp_message_class</name>
<version>@(#) $Id: smtp_message.php,v 1.36 2011/03/09 07:48:52 mlemos Exp $</version>
<copyright>Copyright © (C) Manuel Lemos 1999-2004</copyright>
<title>MIME E-mail message composing and sending via SMTP</title>
<author>Manuel Lemos</author>
<authoraddress>mlemos-at-acm.org</authoraddress>
<documentation>
<idiom>en</idiom>
<purpose>Implement an alternative message delivery method via SMTP
protocol, overriding the method of using the PHP <tt>mail()</tt>
function implemented by the base class.</purpose>
<usage>This class should be used exactly the same way as the base
class for composing and sending messages. Just create a new object of
this class as follows and set only the necessary variables to
configure details of the SMTP delivery.<paragraphbreak />
<tt>require('email_message.php');<br />
require('smtp.php');<br />
require('smtp_message.php');<br />
<br />
$message_object = new smtp_message_class;<br /></tt><paragraphbreak />
<b>- Requirements</b><paragraphbreak />
You need the <link>
<data>SMTP E-mail sending class</data>
<url>http://freshmeat.net/projects/smtpclass/</url>
</link> to perform the actual message delivery via the SMTP
protocol.<paragraphbreak />
<b>- SMTP connection</b><paragraphbreak />
Before sending a message by relaying it to a given SMTP server you
need set the <variablelink>smtp_host</variablelink> variable to that
server address. The <variablelink>localhost</variablelink> variable
needs to be set to the sending computer address.<paragraphbreak />
You may also adjust the time the class will wait for establishing
a connection by changing the <variablelink>timeout</variablelink>
variable.<paragraphbreak />
<b>- Secure SMTP connections with SSL</b><paragraphbreak />
Some SMTP servers, like for instance Gmail, require secure
connections via SSL. In that case it is necessary to set the
<variablelink>smtp_ssl</variablelink> variable to
<booleanvalue>1</booleanvalue>. In the case of Gmail, it is also
necessary to set the connection port changing the
<variablelink>smtp_port</variablelink> variable to
<integervalue>465</integervalue>.<paragraphbreak />
SSL support requires at least PHP 4.3.0 with OpenSSL extension
enabled.<paragraphbreak />
<b>- Secure SMTP connections starting TLS after connections is established</b><paragraphbreak />
Some SMTP servers, like for instance Hotmail, require starting the
TLS protocol after the connection is already established to exchange
data securely. In that case it is necessary to set the
<variablelink>smtp_start_tls</variablelink> variable to
<booleanvalue>1</booleanvalue>.<paragraphbreak />
Starting TLS protocol on an already established connection requires
at least PHP 5.1.0 with OpenSSL extension enabled.<paragraphbreak />
<b>- Authentication</b><paragraphbreak />
Most servers only allow relaying messages sent by authorized
users. If the SMTP server that you want to use requires
authentication, you need to set the variables
<variablelink>smtp_user</variablelink>,
<variablelink>smtp_realm</variablelink> and
<variablelink>smtp_password</variablelink>.<paragraphbreak />
The way these values need to be set depends on the server. Usually
the realm value is empty and only the user and password need to be
set. If the server requires authentication via <tt>NTLM</tt>
mechanism (Windows or Samba), you need to set the
<variablelink>smtp_realm</variablelink> to the Windows domain name
and also set the variable
<variablelink>smtp_workstation</variablelink> to the user workstation
name.<paragraphbreak />
Some servers require that the authentication be done on a separate
server using the POP3 protocol before connecting to the SMTP server.
In this case you need to specify the address of the POP3 server
setting the <variablelink>smtp_pop3_auth_host</variablelink>
variable.<paragraphbreak />
<b>- Sending urgent messages with direct delivery</b><paragraphbreak />
If you need to send urgent messages or obtain immediate confirmation
that a message is accepted by the recipient SMTP server, you can use
the direct delivery mode setting the
<variablelink>direct_delivery</variablelink> variable to
<tt><booleanvalue>1</booleanvalue></tt>. This mode can be used to
send a message to only one recipient.<paragraphbreak />
To use this mode, it is necessary to have a way to determine the
recipient domain SMTP server address. The class uses the PHP
<tt>getmxrr()</tt> function, but on some systems like for instance
under Windows, this function does not work. In this case you may
specify an equivalent alternative by setting the
<variablelink>smtp_getmxrr</variablelink> variable. See the SMTP
class page for available alternatives.<paragraphbreak />
<b>- Troubleshooting and debugging</b><paragraphbreak />
If for some reason the delivery via SMTP is not working and the error
messages are not self-explanatory, you may set the
<variablelink>smtp_debug</variablelink> to
<tt><booleanvalue>1</booleanvalue></tt> to make the class output the
SMTP protocol dialog with the server. If you want to display this
dialog properly formatted in an HTML page, also set the
<variablelink>smtp_debug</variablelink> to
<tt><booleanvalue>1</booleanvalue></tt>.<paragraphbreak />
<b>- Optimizing the delivery of messages to many recipients</b><paragraphbreak />
When sending messages to many recipients, this class can hinted to
optimize its behavior by using the
<functionlink>SetBulkMail</functionlink> function. After calling this
function passing <booleanvalue>1</booleanvalue> to the <argumentlink>
<function>SetBulkMail</function>
<argument>on</argument>
</argumentlink> argument, when the message is sent this class opens
a TCP connection to the SMTP server but will not close it. This
avoids the overhead of opening and closing connections.<paragraphbreak />
When the delivery of the messages to all recipients is done, the
connection may be closed implicitly by calling the
<functionlink>SetBulkMail</functionlink> function again passing
<booleanvalue>0</booleanvalue> to the <argumentlink>
<function>SetBulkMail</function>
<argument>on</argument>
</argumentlink> argument.</usage>
</documentation>
{/metadocument}
*/
class smtp_message_class extends email_message_class
{
/* Private variables */
var $smtp;
var $line_break="\r\n";
var $delivery = 0;
/* Public variables */
/* Allow Self Signed Certificate */
var $smtp_certificate = 0; // @flydev: https://processwire.com/talk/topic/5704-wiremailsmtp/page-5#entry113290
/* @horst: Allow Connections without Authentication */
var $allow_without_authentication = 0;
/* @horst: Allow to define the crypto method for TLS connections */
var $smtp_tls_crypto_method = '';
/* @horst: Allow to define the crypto method for SSL connections */
var $smtp_ssl_crypto_method = '';
/*
{metadocument}
<variable>
<name>localhost</name>
<value></value>
<documentation>
<purpose>Specify the domain name of the computer sending the
message.</purpose>
<usage>This value is used to identify the sending machine to the
SMTP server. When using the direct delivery mode, if this variable
is set to a non-empty string it used to generate the
<tt>Recieved</tt> header to show that the message passed by the
specified host address. To prevent confusing directly delivered
messages with spam, it is strongly recommended that you set this
variable to you server host name.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $localhost="";
/*
{metadocument}
<variable>
<name>smtp_host</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Specify the address of the SMTP server.</purpose>
<usage>Set to the address of the SMTP server that will relay the
messages. This variable is not used in direct delivery mode.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_host="localhost";
/*
{metadocument}
<variable>
<name>smtp_port</name>
<type>INTEGER</type>
<value>25</value>
<documentation>
<purpose>Specify the TCP/IP port of SMTP server to connect.</purpose>
<usage>Most servers work on port 25 . Certain e-mail services use
alternative ports to avoid firewall blocking. Gmail uses port
<integervalue>465</integervalue>.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_port=25;
/*
{metadocument}
<variable>
<name>smtp_ssl</name>
<type>BOOLEAN</type>
<value>0</value>
<documentation>
<purpose>Specify whether it should use secure connections with SSL
to connect to the SMTP server.</purpose>
<usage>Certain e-mail services like Gmail require SSL connections.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_ssl=0;
/*
{metadocument}
<variable>
<name>smtp_start_tls</name>
<type>BOOLEAN</type>
<value>0</value>
<documentation>
<purpose>Specify whether it should use secure connections starting
TLS protocol after connecting to the SMTP server.</purpose>
<usage>Certain e-mail services like Hotmail require starting TLS
protocol after the connection to the SMTP server is already
established.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_start_tls=0;
/*
{metadocument}
<variable>
<name>smtp_http_proxy_host_name</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Specify name of the host when the connection should be
routed via an HTTP proxy.</purpose>
<usage>Leave empty if no proxy should be used.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_http_proxy_host_name='';
/*
{metadocument}
<variable>
<name>smtp_http_proxy_host_port</name>
<type>INTEGER</type>
<value>3128</value>
<documentation>
<purpose>Specify proxy port when the connection should be routed via
an HTTP proxy.</purpose>
<usage>Change this variable if you need to use a proxy with a
specific port.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_http_proxy_host_port=3128;
/*
{metadocument}
<variable>
<name>smtp_socks_host_name</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Specify name of the host when the connection should be
routed via a SOCKS protocol proxy.</purpose>
<usage>Leave empty if no proxy should be used.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_socks_host_name = '';
/*
{metadocument}
<variable>
<name>smtp_socks_host_port</name>
<type>INTEGER</type>
<value>1080</value>
<documentation>
<purpose>Specify proxy port when the connection should be routed via
a SOCKS protocol proxy.</purpose>
<usage>Change this variable if you need to use a proxy with a
specific port.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_socks_host_port = 1080;
/*
{metadocument}
<variable>
<name>smtp_socks_version</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Specify protocol version when the connection should be
routed via a SOCKS protocol proxy.</purpose>
<usage>Change this variable if you need to use a proxy with a
specific SOCKS protocol version.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_socks_version = '5';
/*
{metadocument}
<variable>
<name>smtp_direct_delivery</name>
<type>BOOLEAN</type>
<value>0</value>
<documentation>
<purpose>Boolean flag that indicates whether the message should be
sent in direct delivery mode.</purpose>
<usage>Set this to <tt><booleanvalue>1</booleanvalue></tt> if you
want to send urgent messages directly to the recipient domain SMTP
server.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_direct_delivery=0;
/*
{metadocument}
<variable>
<name>smtp_getmxrr</name>
<type>STRING</type>
<value>getmxrr</value>
<documentation>
<purpose>Specify the name of the function that is called to determine
the SMTP server address of a given domain.</purpose>
<usage>Change this to a working replacement of the PHP
<tt>getmxrr()</tt> function if this is not working in your system
and you want to send messages in direct delivery mode.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_getmxrr="getmxrr";
/*
{metadocument}
<variable>
<name>smtp_exclude_address</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Specify an address that should be considered invalid
when resolving host name addresses.</purpose>
<usage>In some networks any domain name that does not exist is
resolved as a sub-domain of the default local domain. If the DNS is
configured in such way that it always resolves any sub-domain of
the default local domain to a given address, it is hard to
determine whether a given domain does not exist.<paragraphbreak />
If your network is configured this way, you may set this variable
to the address that all sub-domains of the default local domain
resolves, so the class can assume that such address is invalid.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_exclude_address="";
/*
{metadocument}
<variable>
<name>smtp_user</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Specify the user name for authentication.</purpose>
<usage>Set this variable if you need to authenticate before sending
a message.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_user="";
/*
{metadocument}
<variable>
<name>smtp_realm</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Specify the user authentication realm.</purpose>
<usage>Set this variable if you need to authenticate before sending
a message.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_realm="";
/*
{metadocument}
<variable>
<name>smtp_workstation</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Specify the user authentication workstation needed when
using the <tt>NTLM</tt> authentication (Windows or Samba).</purpose>
<usage>Set this variable if you need to authenticate before sending
a message.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_workstation="";
/*
{metadocument}
<variable>
<name>smtp_authentication_mechanism</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Specify the user authentication mechanism that should be
used when authenticating with the SMTP server.</purpose>
<usage>Set this variable if you need to force the SMTP connection to
authenticate with a specific authentication mechanism. Leave this
variable with an empty string if you want the authentication
mechanism be determined automatically from the list of mechanisms
supported by the server.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_authentication_mechanism="";
/*
{metadocument}
<variable>
<name>smtp_password</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Specify the user authentication password.</purpose>
<usage>Set this variable if you need to authenticate before sending
a message.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_password="";
/*
{metadocument}
<variable>
<name>smtp_pop3_auth_host</name>
<type>STRING</type>
<value></value>
<documentation>
<purpose>Specify the server address for POP3 based authentication.</purpose>
<usage>Set this variable to the address of the POP3 server if the
SMTP server requires POP3 based authentication.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_pop3_auth_host="";
/*
{metadocument}
<variable>
<name>smtp_debug</name>
<type>BOOLEAN</type>
<value>0</value>
<documentation>
<purpose>Specify whether it is necessary to output SMTP connection
debug information.</purpose>
<usage>Set this variable to
<tt><booleanvalue>1</booleanvalue></tt> if you need to see
the progress of the SMTP connection and protocol dialog when you
need to understand the reason for delivery problems.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_debug=0;
/*
{metadocument}
<variable>
<name>smtp_html_debug</name>
<type>BOOLEAN</type>
<value>0</value>
<documentation>
<purpose>Specify whether the debug information should be outputted in
HTML format.</purpose>
<usage>Set this variable to
<tt><booleanvalue>1</booleanvalue></tt> if you need to see
the debug output in a Web page.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $smtp_html_debug=0;
/*
{metadocument}
<variable>
<name>esmtp</name>
<type>BOOLEAN</type>
<value>1</value>
<documentation>
<purpose>Specify whether the class should try to use Enhanced SMTP
protocol features.</purpose>
<usage>It is recommended to leave this variable set to
<tt><booleanvalue>1</booleanvalue></tt> so the class can take
advantage of Enhanced SMTP protocol features.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $esmtp=1;
/*
{metadocument}
<variable>
<name>timeout</name>
<type>INTEGER</type>
<value>25</value>
<documentation>
<purpose>Specify the connection timeout period in seconds.</purpose>
<usage>Change this value if for some reason the timeout period seems
insufficient or otherwise it seems too long.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $timeout=25;
/*
{metadocument}
<variable>
<name>invalid_recipients</name>
<type>ARRAY</type>
<value></value>
<documentation>
<purpose>Return the list of recipient addresses that were not
accepted by the SMTP server.</purpose>
<usage>Check this variable after attempting to send a message to
figure whether there were any recipients that were rejected by the
SMTP server.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $invalid_recipients=array();
/*
{metadocument}
<variable>
<name>mailer_delivery</name>
<value>smtp $Revision: 1.36 $</value>
<documentation>
<purpose>Specify the text that is used to identify the mail
delivery class or sub-class. This text is appended to the
<tt>X-Mailer</tt> header text defined by the
mailer variable.</purpose>
<usage>Do not change this variable.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $mailer_delivery='smtp $Revision: 1.36 $';
/*
{metadocument}
<variable>
<name>maximum_bulk_deliveries</name>
<type>INTEGER</type>
<value>100</value>
<documentation>
<purpose>Specify the number of consecutive bulk mail deliveries
without disconnecting.</purpose>
<usage>Lower this value if you have enabled the bulk mail mode but
the SMTP server does not accept sending more than a number of
messages within the same SMTP connection.<paragraphbreak />
Set this value to <integervalue>0</integervalue> to never
disconnect during bulk mail mode unless an error occurs.</usage>
</documentation>
</variable>
{/metadocument}
*/
var $maximum_bulk_deliveries=100;
Function SetRecipients(&$recipients,&$valid_recipients)
{
for($valid_recipients=$recipient=0,Reset($recipients);$recipient<count($recipients);Next($recipients),$recipient++)
{
$address=Key($recipients);
if($this->smtp->SetRecipient($address))
$valid_recipients++;
else
$this->invalid_recipients[$address]=$this->smtp->error;
}
return(1);
}
Function ResetConnection($error)
{
if(IsSet($this->smtp))
{
if(!$this->smtp->Disconnect()
&& strlen($error) == 0)
$error = $this->smtp->error;
UnSet($this->smtp);
}
if(strlen($error))
$this->OutputError($error);
return($error);
}
Function StartSendingMessage()
{
if(function_exists("class_exists")
&& !class_exists("smtp_class"))
return("the smtp_class class was not included");
if(IsSet($this->smtp))
return("");
$this->smtp=new smtp_class;
$this->smtp->localhost=$this->localhost;
$this->smtp->host_name=$this->smtp_host;
$this->smtp->host_port=$this->smtp_port;
$this->smtp->ssl=$this->smtp_ssl;
$this->smtp->smtp_ssl_crypto_method=$this->smtp_ssl_crypto_method; // @horst
$this->smtp->start_tls=$this->smtp_start_tls;
$this->smtp->smtp_tls_crypto_method=$this->smtp_tls_crypto_method; // @horst
$this->smtp->http_proxy_host_name=$this->smtp_http_proxy_host_name;
$this->smtp->http_proxy_host_port=$this->smtp_http_proxy_host_port;
$this->smtp->socks_host_name=$this->smtp_socks_host_name;
$this->smtp->socks_host_port=$this->smtp_socks_host_port;
$this->smtp->socks_version=$this->smtp_socks_version;
$this->smtp->timeout=$this->timeout;
$this->smtp->debug=$this->smtp_debug;
$this->smtp->html_debug=$this->smtp_html_debug;
$this->smtp->direct_delivery=$this->smtp_direct_delivery;
$this->smtp->getmxrr=$this->smtp_getmxrr;
$this->smtp->exclude_address=$this->smtp_exclude_address;
$this->smtp->pop3_auth_host=$this->smtp_pop3_auth_host;
$this->smtp->user=$this->smtp_user;
$this->smtp->realm=$this->smtp_realm;
$this->smtp->workstation=$this->smtp_workstation;
$this->smtp->authentication_mechanism=$this->smtp_authentication_mechanism;
$this->smtp->password=$this->smtp_password;
$this->smtp->esmtp=$this->esmtp;
$this->smtp->smtp_certificate = $this->smtp_certificate; // @flydev: https://processwire.com/talk/topic/5704-wiremailsmtp/page-5#entry113290
$this->smtp->allow_without_authentication = $this->allow_without_authentication; // @horst
if($this->smtp->Connect())
{
$this->delivery = 0;
return("");
}
return($this->ResetConnection($this->smtp->error));
}
Function SendMessageHeaders($headers)
{
$header_data="";
$date=date("D, d M Y H:i:s T");
if($this->smtp_direct_delivery
&& strlen($this->localhost))
{
$local_ip=gethostbyname($this->localhost);
$header_data.=$this->FormatHeader("Received","FROM ".$this->localhost." ([".$local_ip."]) BY ".$this->localhost." ([".$local_ip."]) WITH SMTP; ".$date)."\r\n";
}
for($message_id_set=$date_set=0,$header=0,$return_path=$from=$to=$recipients=array(),Reset($headers);$header<count($headers);$header++,Next($headers))
{
$header_name=Key($headers);
switch(strtolower($header_name))
{
case "return-path":
$return_path[$headers[$header_name]]=1;
break;
case "from":
$error=$this->GetRFC822Addresses($headers[$header_name],$from);
break;
case "to":
$error=$this->GetRFC822Addresses($headers[$header_name],$to);
break;
case "cc":
case "bcc":
$this->GetRFC822Addresses($headers[$header_name],$recipients);
break;
case "date":
$date_set=1;
break;
case "message-id":
$message_id_set=1;
break;
}
if(strcmp($error,""))
return($this->ResetConnection($error));
if(strtolower($header_name)=="bcc")
continue;
$header_data.=$this->FormatHeader($header_name,$headers[$header_name])."\r\n";
}
if(count($from)==0)
return($this->ResetConnection("it was not specified a valid From header"));
Reset($return_path);
Reset($from);
$this->invalid_recipients=array();
if(!$this->smtp->MailFrom(count($return_path) ? Key($return_path) : Key($from)))
return($this->ResetConnection($this->smtp->error));
$r = 0;
if(count($to))
{
if(!$this->SetRecipients($to,$valid_recipients))
return($this->ResetConnection($this->smtp->error));
$r += $valid_recipients;
}
if(!$date_set)
$header_data.="Date: ".$date."\r\n";
if(!$message_id_set
&& $this->auto_message_id)
{
$sender=(count($return_path) ? Key($return_path) : Key($from));
$header_data.=$this->GenerateMessageID($sender)."\r\n";
}
if(count($recipients))
{
if(!$this->SetRecipients($recipients,$valid_recipients))
return($this->ResetConnection($this->smtp->error));
$r += $valid_recipients;
}
if($r==0)
return($this->ResetConnection("it were not specified any valid recipients"));
if(!$this->smtp->StartData()
|| !$this->smtp->SendData($header_data."\r\n"))
return($this->ResetConnection($this->smtp->error));
return("");
}
Function SendMessageBody($data)
{
return($this->smtp->SendData($this->smtp->PrepareData($data)) ? "" : $this->ResetConnection($this->smtp->error));
}
Function EndSendingMessage()
{
return($this->smtp->EndSendingData() ? "" : $this->ResetConnection($this->smtp->error));
}
Function StopSendingMessage()
{
++$this->delivery;
if($this->bulk_mail
&& !$this->smtp_direct_delivery
&& ($this->maximum_bulk_deliveries == 0
|| $this->delivery < $this->maximum_bulk_deliveries))
return("");
return($this->ResetConnection(''));
}
Function ChangeBulkMail($on)
{
if($on
|| !IsSet($this->smtp))
return(1);
return($this->smtp->Disconnect() ? "" : $this->ResetConnection($this->smtp->error));
}
};
/*
{metadocument}
</class>
{/metadocument}
*/
?>

View file

@ -0,0 +1,135 @@
<?php
/**
* ProcessWire ColorPicker Fieldtype
*
* created by Philipp "Soma" Urlich
* ColorPicker jQuery Plugin by http://www.eyecon.ro/colorpicker/
*
* additions (swatches) by @Rayden
*
* Licensed under LGPL3 http://www.gnu.org/licenses/lgpl-3.0.txt
*
*/
class FieldtypeColorPicker extends Fieldtype {
const TRANSPARENT = "transparent";
const HEX_PREFIX = "#";
public static function getModuleInfo() {
return array(
'title' => 'ColorPicker',
'version' => 203,
'summary' => 'Fieldtype that stores a HEX color or the value transp. Color can be picked using a jQuery ColorPicker Plugin by http://www.eyecon.ro/colorpicker/ or from a configurable color swatch.',
'href' => 'http://processwire.com/talk/topic/865-module-colorpicker/page__gopid__7340#entry7340',
'installs' => 'InputfieldColorPicker'
);
}
/**
* Return the default or if not set a blank value
*
*/
public function getBlankValue(Page $page, Field $field) {
if($field->default == "0") $field->default = "000000";
return $field->default ? $field->default : '';
}
/**
* Return the associated InputfieldColorPicker
*
*/
public function getInputfield(Page $page, Field $field) {
$inputField = $this->modules->get('InputfieldColorPicker');
$inputField->set('default', $field->default);
$inputField->set('swatch', $field->swatch);
return $inputField;
}
/**
* Format the value for output
* @param Page $page
* @param Field $field
* @param mixed $value
* @return string
*/
public function ___formatValue(Page $page, Field $field, $value){
if(!$value) $value = trim($field->default);
if(!strlen($value)) return $value;
if(!$field->formatting) return $value;
if("transp" == strtolower($value)) return self::TRANSPARENT;
if($value == "0") $value = "000000";
return self::HEX_PREFIX . $value;
}
/**
* Render formatted markup for use in Admin ie. Lister
*/
public function ___markupValue(Page $page, Field $field, $value = null, $property = '') {
$m = "";
if($value) {
$m = "<span class='Markup_{$this->className}' style='width: 1em; height: 1em; display: inline-block; background-color:#" . $value . "'></span>";
}
return $m;
}
/**
* sanitize the HEX value and cut off characters if longer than 6
*/
public function sanitizeValue(Page $page, Field $field, $value) {
$value = $value == "transp" ? $value : strtoupper(substr($value, 0, 6));
return $value;
}
/**
* Return the database schema in specified format
*
*/
public function getDatabaseSchema(Field $field) {
$schema = parent::getDatabaseSchema($field);
$schema['data'] = 'CHAR(6) NOT NULL'; // i.e. FFFFFF or 333333 (hex color codes) or transp
return $schema;
}
/**
* set the config option fields for this field
*
*/
public function ___getConfigInputfields(Field $field) {
$inputfields = parent::___getConfigInputfields($field);
$f = $this->modules->get("InputfieldText");
$f->attr('name', 'default');
$f->attr('size', 6);
$f->attr('value', $field->default);
$f->label = $this->_('Default Value');
$f->description = $this->_('Set the default HEX value or "transp" (transparent) for the field.');
$f->notes = $this->_('For example "EAEAEA". To have a blank value leave this field empty.');
$inputfields->append($f);
/* additions (swatches) by @Rayden */
$f = $this->modules->get("InputfieldTextarea");
$f->attr('name', 'swatch');
$f->attr('value', $field->swatch);
$f->label = $this->_('Color Swatch');
$f->description = $this->_('Comma seperated HEX values or "transp" (transparent) to add color swatches for each.');
$f->notes = $this->_('For example "transp,FFFFFF,000000". Leave this field empty if you do not want to use the color swatch.');
$inputfields->append($f);
$f = $this->modules->get("InputfieldCheckbox");
$f->attr('name', 'formatting');
$f->attr('value', $field->formatting);
$f->attr('checked', $field->formatting ? 'checked' : '');
$f->label = $this->_('Turn on output formatting');
$f->description = $this->_('Enabling this turns on output formatting for this field. This will return the HEX value of the field already prefixed with "#" for convenience i.e "#FFAADD" and "transp" will be output as "transparent".');;
$inputfields->append($f);
return $inputfields;
}
}

View file

@ -0,0 +1,96 @@
/**
* An Inputfieldtype for handling Colors
* used by the FieldtypeColorPicker/InputfieldColorPicker
*
* created by Philipp "Soma" Urlich
* ColorPicker jQuery Plugin by http://www.eyecon.ro/colorpicker/
*
* Licensed under LGPL3 http://www.gnu.org/licenses/lgpl-3.0.txt
*
*/
;
(function(document, $){
var InputfieldColorPicker = {
init: function() {
$('div[id^=ColorPicker_]:not(.colorpicker_loaded)').each(function(){
var $colorpicker = $(this);
console.log("init colorpicker" + $colorpicker);
$colorpicker.ColorPicker({
color: $(this).data('color').toString(),
onShow: function (colpkr) {
$(colpkr).fadeIn(500);
return false;
},
onHide: function (colpkr) {
$(colpkr).fadeOut(500);
return false;
},
onChange: function (hsb, hex, rgb) {
$colorpicker.css('backgroundColor', '#' + hex);
$colorpicker.css('background-image', 'none');
$colorpicker.next('input').val(hex).trigger('change');
}
});
$colorpicker.addClass("colorpicker_loaded");
});
},
attachEvents: function() {
$(document).on('click', 'a.ColorPickerReset', function(e){
e.preventDefault();
var color = $(this).data('default') && $(this).data('default') != 'transp' ? '#' + $(this).data('default').toString() : 'transparent';
$(this).parent().find('input').val($(this).data('default')).trigger('change');
$(this).parent().find('div[id^=ColorPicker_]').ColorPickerSetColor($(this).data('default').toString());
$(this).parent().find('div[id^=ColorPicker_]')
.css('backgroundColor', color)
.css('background-image', 'none')
.attr('data-color', $(this).data('default').toString());
if(color == 'transparent') {
var modurl = $(this).data('modurl');
$(this).parent().find('div[id^=ColorPicker_]')
.css('background-image', 'url(' + modurl + 'transparent.gif)');
}
});
/* additions (swatches) by @Rayden */
$(document).on('click', 'div.ColorPickerSwatch',function(e){
e.preventDefault();
var color = $(this).data('color') && $(this).data('color') != 'transp' ? '#' + $(this).data('color').toString() : 'transparent';
$(this).closest('.ui-widget-content, .InputfieldContent').find('input').val($(this).data('color')).trigger('change');
$(this).closest('.ui-widget-content, .InputfieldContent').find('div[id^=ColorPicker_]').ColorPickerSetColor($(this).data('color').toString());
$(this).closest('.ui-widget-content, .InputfieldContent').find('div[id^=ColorPicker_]')
.css('backgroundColor', color)
.css('background-image', 'none')
.attr('data-color', $(this).data('color').toString());
if(color == 'transparent') {
var modurl = $(this).closest('.ui-widget-content, .InputfieldContent').find('.ColorPickerReset').data('modurl');
$(this).closest('.ui-widget-content, .InputfieldContent').find('div[id^=ColorPicker_]')
.css('background-image', 'url(' + modurl + 'transparent.gif)');
}
});
}
};
// document ready
$(function(){
InputfieldColorPicker.init();
InputfieldColorPicker.attachEvents();
$(".Inputfield").on("repeateradd", ".InputfieldRepeater", InputfieldColorPicker.init);
$(".Inputfield").on("reloaded", ".InputfieldRepeater", function(){
InputfieldColorPicker.init();
});
});
}(document, jQuery));

View file

@ -0,0 +1,93 @@
<?php
/**
* An Inputfieldtype for handling Colors
* used by the FieldtypeColorPicker
*
* created by Philipp "Soma" Urlich
* ColorPicker jQuery Plugin by http://www.eyecon.ro/colorpicker/
*
* additions (swatches) by @Rayden
*
* Licensed under LGPL3 http://www.gnu.org/licenses/lgpl-3.0.txt
*
*/
class InputfieldColorPicker extends Inputfield {
public static function getModuleInfo() {
return array(
'title' => 'ColorPicker',
'version' => 203,
'summary' => 'Choose your colors the easy way.',
'href' => 'http://processwire.com/talk/topic/865-module-colorpicker/page__gopid__7340#entry7340',
'requires' => array("FieldtypeColorPicker")
);
}
public function __construct() {
parent::__construct();
$this->setAttribute('type', 'hidden');
}
/**
* inputfield is loaded
*/
public function init() {
parent::init();
$conf = $this->getModuleInfo();
$version = (int) $conf['version'];
// append script needed for the inputfield
$this->config->styles->add($this->config->urls->InputfieldColorPicker . "colorpicker/css/colorpicker.css?v={$version}");
$this->config->scripts->add($this->config->urls->InputfieldColorPicker . "colorpicker/js/colorpicker.min.js?v={$version}");
}
/**
* render the markup for this iputfield
* @return string html markup
*/
public function ___render() {
$out = "\n<div id='ColorPicker_$this->name' style='border:2px solid #444; display:block;";
$out .= "width:40px; height:40px; background-color:";
$out .= $this->value == "transp"
? $this->value . "; background-image:url({$this->config->urls->InputfieldColorPicker}transparent.gif);"
: "#" . $this->value . "; background-image:none";
$out .= "' data-color='" . $this->value . "'></div>";
$out .= "<input " . $this->getAttributesString() . " />";
if($this->default == "0") $this->default = "000000";
$out .= "<a class='ColorPickerReset' href='#' data-default='{$this->default}' ";
$out .= "data-modurl='{$this->config->urls->InputfieldColorPicker}'>" . $this->_('reset color') . "</a>";
/**
* add swatches for predefined color values | @Rayden
*/
$swatch = trim($this->swatch);
if(strlen($swatch)) {
$csvalues = explode(",", trim($swatch));
if(count($csvalues)) {
$out .= "<ul style='list-style-type: none; margin: 1em 0 0; padding: 0; overflow: hidden'>";
foreach($csvalues as $csvalue) {
$csvalue = trim($csvalue);
if($csvalue == "0") $csvalue = "000000";
$out .= "<li style='display: inline-block; float:left; margin:0 4px 4px 0; border:1px solid #444; width:24px; height:24px; background-color:";
$out .= $csvalue == "transp"
? $csvalue . ";background-image:url({$this->config->urls->InputfieldColorPicker}transparent.gif);"
: "#" . $csvalue;
$out .= "'><div class='ColorPickerSwatch' href='#' data-color='{$csvalue}' style='width:24px;height:24px;display:block;cursor:pointer;' title='{$csvalue}'></div></li>";
}
$out .= "</ul>";
}
}
return $out;
}
}

View file

@ -0,0 +1,101 @@
ColorPicker
=====================
**Custom Fieldtype/Inputfield for ProcessWire 2.+/3.+**
This module gives you a new custom Fieldtype. Let's you select a color using a Colorpicker jQuery Plugin. The color selected will be stored in HEX format uppercase: "EAEAEA";
When creating a new field in the admin, you can set a default value. The default value will be set when creating a new page, and it will also be used for empty fields.
The field supports a transparent value. In the field setting you can use the name "transp" to define it. When output formatting (2.0.0) of the field is enabled, the field will return "transparent" in template code.
The field supports a "reset" button to be able to set it back to the default value.
### How to use it
To use it in your template as a background HEX color, you'd simple output the value and prefix it with a #:
```
echo "background-color: #" . $page->color;
```
Since of 2.0.0 you can enable output formatting of the field in the details settings. When enabled it will format value directly from AADDEE to "#AADDEE" and "transp" to "transparent".
```
echo "background-color: " . $page->color;
```
The colorpicker used:
[ColorPicker jQuery Plugin by Eyecon](http://www.eyecon.ro/colorpicker/)
### Changelog
**2.0.2**
- fixed issue when field is in a Repeater or RepeaterMatrix
- added support for ___markupValue() used in Lister
**2.0.1**
- Fixed default "000000" value issue in Fieldtype
**2.0.0**
- Added output formatting option to format values with prefix "#" when output in template code.
- Added checks for "0" values and returning them as "000000", just in case ProcessWire converts them to 0.
**1.0.8**
- some maintenance, remove <p> not needed
- remove overflow: auto
_ colorpicker css fix input with box sizing coming from new admin theme
**1.0.7**
- fixed typecasting bug: when a color value is numeric it should be
typecasted to string. This prevents the color picker window from not
being launched. @Rayden
- fixed small visualisation issue with the color swatch preventing a
box collapse with css. @Rayden
**1.0.6**
- added support for color swatches for easy predefining and selecting color values @Rayden
- added "transp" support for a transparent value (empty)
**1.0.5**
- fix bug with default value
**1.0.4**
- fix bug when used in repeaters
**1.0.3**
- added support for default value
- added reset link to set back to default color
**1.0.2**
- Fixed issue with colorpicker not working when used in tabs
**1.0.1**
- Remove lots of code not needed. Cleanup.
**1.0.0**
- Initial Stable Release.
### How to install:
- Download the contents of this repository and put the folder renamed as "ColorPicker" into your site/modules/ folder
- Login to processwire and got to Modules page and click "Check for new modules". You should see a note that two new modules were found. Install the FieldtypeColorPicker module under "Field" section. This will also install the required InputfieldColorPicker at the same time.
- Done
- You can now create a new field with the "ColorPicker" Fieldtype.

Binary file not shown.

View file

@ -0,0 +1,164 @@
.colorpicker {
width: 356px;
height: 176px;
overflow: hidden;
position: absolute;
background: url(../images/colorpicker_background.png);
font-family: Arial, Helvetica, sans-serif;
display: none;
z-index:1;
}
.colorpicker_color {
width: 150px;
height: 150px;
left: 14px;
top: 13px;
position: absolute;
background: #f00;
overflow: hidden;
cursor: crosshair;
}
.colorpicker_color div {
position: absolute;
top: 0;
left: 0;
width: 150px;
height: 150px;
background: url(../images/colorpicker_overlay.png);
}
.colorpicker_color div div {
position: absolute;
top: 0;
left: 0;
width: 11px;
height: 11px;
overflow: hidden;
background: url(../images/colorpicker_select.gif);
margin: -5px 0 0 -5px;
}
.colorpicker_hue {
position: absolute;
top: 13px;
left: 171px;
width: 35px;
height: 150px;
cursor: n-resize;
}
.colorpicker_hue div {
position: absolute;
width: 35px;
height: 9px;
overflow: hidden;
background: url(../images/colorpicker_indic.gif) left top;
margin: -4px 0 0 0;
left: 0px;
}
.colorpicker_new_color {
position: absolute;
width: 60px;
height: 30px;
left: 213px;
top: 13px;
background: #f00;
}
.colorpicker_current_color {
position: absolute;
width: 60px;
height: 30px;
left: 283px;
top: 13px;
background: #f00;
}
.colorpicker input {
background-color: transparent;
border: 1px solid transparent;
position: absolute;
font-size: 10px;
font-family: Arial, Helvetica, sans-serif;
color: #898989;
top: 4px;
right: 11px;
text-align: right;
margin: 0;
padding: 0;
height: 15px;
}
.colorpicker_hex {
position: absolute;
width: 72px;
height: 22px;
background: url(../images/colorpicker_hex.png) top;
left: 212px;
top: 142px;
}
.colorpicker_hex input {
right: 6px;
}
.colorpicker_field {
height: 22px;
width: 62px;
background-position: top;
position: absolute;
}
.colorpicker_field span {
position: absolute;
width: 12px;
height: 22px;
overflow: hidden;
top: 0;
right: 0;
cursor: n-resize;
}
.colorpicker_rgb_r {
background-image: url(../images/colorpicker_rgb_r.png);
top: 52px;
left: 212px;
}
.colorpicker_rgb_g {
background-image: url(../images/colorpicker_rgb_g.png);
top: 82px;
left: 212px;
}
.colorpicker_rgb_b {
background-image: url(../images/colorpicker_rgb_b.png);
top: 112px;
left: 212px;
}
.colorpicker_hsb_h {
background-image: url(../images/colorpicker_hsb_h.png);
top: 52px;
left: 282px;
}
.colorpicker_hsb_s {
background-image: url(../images/colorpicker_hsb_s.png);
top: 82px;
left: 282px;
}
.colorpicker_hsb_b {
background-image: url(../images/colorpicker_hsb_b.png);
top: 112px;
left: 282px;
}
.colorpicker_submit {
position: absolute;
width: 22px;
height: 22px;
background: url(../images/colorpicker_submit.png) top;
left: 322px;
top: 142px;
overflow: hidden;
}
.colorpicker_focus {
background-position: center;
}
.colorpicker_hex.colorpicker_focus {
background-position: bottom;
}
.colorpicker_submit.colorpicker_focus {
background-position: bottom;
}
.colorpicker_slider {
background-position: bottom;
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 532 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 970 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,012 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 970 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 984 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 970 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,008 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,018 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 997 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

View file

@ -0,0 +1,484 @@
/**
*
* Color picker
* Author: Stefan Petre www.eyecon.ro
*
* Dual licensed under the MIT and GPL licenses
*
*/
(function ($) {
var ColorPicker = function () {
var
ids = {},
inAction,
charMin = 65,
visible,
tpl = '<div class="colorpicker"><div class="colorpicker_color"><div><div></div></div></div><div class="colorpicker_hue"><div></div></div><div class="colorpicker_new_color"></div><div class="colorpicker_current_color"></div><div class="colorpicker_hex"><input type="text" maxlength="6" size="6" /></div><div class="colorpicker_rgb_r colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_g colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_h colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_s colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_submit"></div></div>',
defaults = {
eventName: 'click',
onShow: function () {},
onBeforeShow: function(){},
onHide: function () {},
onChange: function () {},
onSubmit: function () {},
color: 'ff0000',
livePreview: true,
flat: false
},
fillRGBFields = function (hsb, cal) {
var rgb = HSBToRGB(hsb);
$(cal).data('colorpicker').fields
.eq(1).val(rgb.r).end()
.eq(2).val(rgb.g).end()
.eq(3).val(rgb.b).end();
},
fillHSBFields = function (hsb, cal) {
$(cal).data('colorpicker').fields
.eq(4).val(hsb.h).end()
.eq(5).val(hsb.s).end()
.eq(6).val(hsb.b).end();
},
fillHexFields = function (hsb, cal) {
$(cal).data('colorpicker').fields
.eq(0).val(HSBToHex(hsb)).end();
},
setSelector = function (hsb, cal) {
$(cal).data('colorpicker').selector.css('backgroundColor', '#' + HSBToHex({h: hsb.h, s: 100, b: 100}));
$(cal).data('colorpicker').selectorIndic.css({
left: parseInt(150 * hsb.s/100, 10),
top: parseInt(150 * (100-hsb.b)/100, 10)
});
},
setHue = function (hsb, cal) {
$(cal).data('colorpicker').hue.css('top', parseInt(150 - 150 * hsb.h/360, 10));
},
setCurrentColor = function (hsb, cal) {
$(cal).data('colorpicker').currentColor.css('backgroundColor', '#' + HSBToHex(hsb));
},
setNewColor = function (hsb, cal) {
$(cal).data('colorpicker').newColor.css('backgroundColor', '#' + HSBToHex(hsb));
},
keyDown = function (ev) {
var pressedKey = ev.charCode || ev.keyCode || -1;
if ((pressedKey > charMin && pressedKey <= 90) || pressedKey == 32) {
return false;
}
var cal = $(this).parent().parent();
if (cal.data('colorpicker').livePreview === true) {
change.apply(this);
}
},
change = function (ev) {
var cal = $(this).parent().parent(), col;
if (this.parentNode.className.indexOf('_hex') > 0) {
cal.data('colorpicker').color = col = HexToHSB(fixHex(this.value));
} else if (this.parentNode.className.indexOf('_hsb') > 0) {
cal.data('colorpicker').color = col = fixHSB({
h: parseInt(cal.data('colorpicker').fields.eq(4).val(), 10),
s: parseInt(cal.data('colorpicker').fields.eq(5).val(), 10),
b: parseInt(cal.data('colorpicker').fields.eq(6).val(), 10)
});
} else {
cal.data('colorpicker').color = col = RGBToHSB(fixRGB({
r: parseInt(cal.data('colorpicker').fields.eq(1).val(), 10),
g: parseInt(cal.data('colorpicker').fields.eq(2).val(), 10),
b: parseInt(cal.data('colorpicker').fields.eq(3).val(), 10)
}));
}
if (ev) {
fillRGBFields(col, cal.get(0));
fillHexFields(col, cal.get(0));
fillHSBFields(col, cal.get(0));
}
setSelector(col, cal.get(0));
setHue(col, cal.get(0));
setNewColor(col, cal.get(0));
cal.data('colorpicker').onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col)]);
},
blur = function (ev) {
var cal = $(this).parent().parent();
cal.data('colorpicker').fields.parent().removeClass('colorpicker_focus');
},
focus = function () {
charMin = this.parentNode.className.indexOf('_hex') > 0 ? 70 : 65;
$(this).parent().parent().data('colorpicker').fields.parent().removeClass('colorpicker_focus');
$(this).parent().addClass('colorpicker_focus');
},
downIncrement = function (ev) {
var field = $(this).parent().find('input').focus();
var current = {
el: $(this).parent().addClass('colorpicker_slider'),
max: this.parentNode.className.indexOf('_hsb_h') > 0 ? 360 : (this.parentNode.className.indexOf('_hsb') > 0 ? 100 : 255),
y: ev.pageY,
field: field,
val: parseInt(field.val(), 10),
preview: $(this).parent().parent().data('colorpicker').livePreview
};
$(document).bind('mouseup', current, upIncrement);
$(document).bind('mousemove', current, moveIncrement);
},
moveIncrement = function (ev) {
ev.data.field.val(Math.max(0, Math.min(ev.data.max, parseInt(ev.data.val + ev.pageY - ev.data.y, 10))));
if (ev.data.preview) {
change.apply(ev.data.field.get(0), [true]);
}
return false;
},
upIncrement = function (ev) {
change.apply(ev.data.field.get(0), [true]);
ev.data.el.removeClass('colorpicker_slider').find('input').focus();
$(document).unbind('mouseup', upIncrement);
$(document).unbind('mousemove', moveIncrement);
return false;
},
downHue = function (ev) {
var current = {
cal: $(this).parent(),
y: $(this).offset().top
};
current.preview = current.cal.data('colorpicker').livePreview;
$(document).bind('mouseup', current, upHue);
$(document).bind('mousemove', current, moveHue);
},
moveHue = function (ev) {
change.apply(
ev.data.cal.data('colorpicker')
.fields
.eq(4)
.val(parseInt(360*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.y))))/150, 10))
.get(0),
[ev.data.preview]
);
return false;
},
upHue = function (ev) {
fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
$(document).unbind('mouseup', upHue);
$(document).unbind('mousemove', moveHue);
return false;
},
downSelector = function (ev) {
var current = {
cal: $(this).parent(),
pos: $(this).offset()
};
current.preview = current.cal.data('colorpicker').livePreview;
$(document).bind('mouseup', current, upSelector);
$(document).bind('mousemove', current, moveSelector);
},
moveSelector = function (ev) {
change.apply(
ev.data.cal.data('colorpicker')
.fields
.eq(6)
.val(parseInt(100*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.pos.top))))/150, 10))
.end()
.eq(5)
.val(parseInt(100*(Math.max(0,Math.min(150,(ev.pageX - ev.data.pos.left))))/150, 10))
.get(0),
[ev.data.preview]
);
return false;
},
upSelector = function (ev) {
fillRGBFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
fillHexFields(ev.data.cal.data('colorpicker').color, ev.data.cal.get(0));
$(document).unbind('mouseup', upSelector);
$(document).unbind('mousemove', moveSelector);
return false;
},
enterSubmit = function (ev) {
$(this).addClass('colorpicker_focus');
},
leaveSubmit = function (ev) {
$(this).removeClass('colorpicker_focus');
},
clickSubmit = function (ev) {
var cal = $(this).parent();
var col = cal.data('colorpicker').color;
cal.data('colorpicker').origColor = col;
setCurrentColor(col, cal.get(0));
cal.data('colorpicker').onSubmit(col, HSBToHex(col), HSBToRGB(col), cal.data('colorpicker').el);
},
show = function (ev) {
var cal = $('#' + $(this).data('colorpickerId'));
cal.data('colorpicker').onBeforeShow.apply(this, [cal.get(0)]);
var pos = $(this).offset();
var viewPort = getViewport();
var top = pos.top + this.offsetHeight;
var left = pos.left;
if (top + 176 > viewPort.t + viewPort.h) {
top -= this.offsetHeight + 176;
}
if (left + 356 > viewPort.l + viewPort.w) {
left -= 356;
}
cal.css({left: left + 'px', top: top + 'px'});
if (cal.data('colorpicker').onShow.apply(this, [cal.get(0)]) != false) {
cal.show();
}
$(document).bind('mousedown', {cal: cal}, hide);
return false;
},
hide = function (ev) {
if (!isChildOf(ev.data.cal.get(0), ev.target, ev.data.cal.get(0))) {
if (ev.data.cal.data('colorpicker').onHide.apply(this, [ev.data.cal.get(0)]) != false) {
ev.data.cal.hide();
}
$(document).unbind('mousedown', hide);
}
},
isChildOf = function(parentEl, el, container) {
if (parentEl == el) {
return true;
}
if (parentEl.contains) {
return parentEl.contains(el);
}
if ( parentEl.compareDocumentPosition ) {
return !!(parentEl.compareDocumentPosition(el) & 16);
}
var prEl = el.parentNode;
while(prEl && prEl != container) {
if (prEl == parentEl)
return true;
prEl = prEl.parentNode;
}
return false;
},
getViewport = function () {
var m = document.compatMode == 'CSS1Compat';
return {
l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft),
t : window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop),
w : window.innerWidth || (m ? document.documentElement.clientWidth : document.body.clientWidth),
h : window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight)
};
},
fixHSB = function (hsb) {
return {
h: Math.min(360, Math.max(0, hsb.h)),
s: Math.min(100, Math.max(0, hsb.s)),
b: Math.min(100, Math.max(0, hsb.b))
};
},
fixRGB = function (rgb) {
return {
r: Math.min(255, Math.max(0, rgb.r)),
g: Math.min(255, Math.max(0, rgb.g)),
b: Math.min(255, Math.max(0, rgb.b))
};
},
fixHex = function (hex) {
var len = 6 - hex.length;
if (len > 0) {
var o = [];
for (var i=0; i<len; i++) {
o.push('0');
}
o.push(hex);
hex = o.join('');
}
return hex;
},
HexToRGB = function (hex) {
var hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
},
HexToHSB = function (hex) {
return RGBToHSB(HexToRGB(hex));
},
RGBToHSB = function (rgb) {
var hsb = {
h: 0,
s: 0,
b: 0
};
var min = Math.min(rgb.r, rgb.g, rgb.b);
var max = Math.max(rgb.r, rgb.g, rgb.b);
var delta = max - min;
hsb.b = max;
if (max != 0) {
}
hsb.s = max != 0 ? 255 * delta / max : 0;
if (hsb.s != 0) {
if (rgb.r == max) {
hsb.h = (rgb.g - rgb.b) / delta;
} else if (rgb.g == max) {
hsb.h = 2 + (rgb.b - rgb.r) / delta;
} else {
hsb.h = 4 + (rgb.r - rgb.g) / delta;
}
} else {
hsb.h = -1;
}
hsb.h *= 60;
if (hsb.h < 0) {
hsb.h += 360;
}
hsb.s *= 100/255;
hsb.b *= 100/255;
return hsb;
},
HSBToRGB = function (hsb) {
var rgb = {};
var h = Math.round(hsb.h);
var s = Math.round(hsb.s*255/100);
var v = Math.round(hsb.b*255/100);
if(s == 0) {
rgb.r = rgb.g = rgb.b = v;
} else {
var t1 = v;
var t2 = (255-s)*v/255;
var t3 = (t1-t2)*(h%60)/60;
if(h==360) h = 0;
if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3}
else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3}
else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3}
else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3}
else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3}
else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3}
else {rgb.r=0; rgb.g=0; rgb.b=0}
}
return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)};
},
RGBToHex = function (rgb) {
var hex = [
rgb.r.toString(16),
rgb.g.toString(16),
rgb.b.toString(16)
];
$.each(hex, function (nr, val) {
if (val.length == 1) {
hex[nr] = '0' + val;
}
});
return hex.join('');
},
HSBToHex = function (hsb) {
return RGBToHex(HSBToRGB(hsb));
},
restoreOriginal = function () {
var cal = $(this).parent();
var col = cal.data('colorpicker').origColor;
cal.data('colorpicker').color = col;
fillRGBFields(col, cal.get(0));
fillHexFields(col, cal.get(0));
fillHSBFields(col, cal.get(0));
setSelector(col, cal.get(0));
setHue(col, cal.get(0));
setNewColor(col, cal.get(0));
};
return {
init: function (opt) {
opt = $.extend({}, defaults, opt||{});
if (typeof opt.color == 'string') {
opt.color = HexToHSB(opt.color);
} else if (opt.color.r != undefined && opt.color.g != undefined && opt.color.b != undefined) {
opt.color = RGBToHSB(opt.color);
} else if (opt.color.h != undefined && opt.color.s != undefined && opt.color.b != undefined) {
opt.color = fixHSB(opt.color);
} else {
return this;
}
return this.each(function () {
if (!$(this).data('colorpickerId')) {
var options = $.extend({}, opt);
options.origColor = opt.color;
var id = 'collorpicker_' + parseInt(Math.random() * 1000);
$(this).data('colorpickerId', id);
var cal = $(tpl).attr('id', id);
if (options.flat) {
cal.appendTo(this).show();
} else {
cal.appendTo(document.body);
}
options.fields = cal
.find('input')
.bind('keyup', keyDown)
.bind('change', change)
.bind('blur', blur)
.bind('focus', focus);
cal
.find('span').bind('mousedown', downIncrement).end()
.find('>div.colorpicker_current_color').bind('click', restoreOriginal);
options.selector = cal.find('div.colorpicker_color').bind('mousedown', downSelector);
options.selectorIndic = options.selector.find('div div');
options.el = this;
options.hue = cal.find('div.colorpicker_hue div');
cal.find('div.colorpicker_hue').bind('mousedown', downHue);
options.newColor = cal.find('div.colorpicker_new_color');
options.currentColor = cal.find('div.colorpicker_current_color');
cal.data('colorpicker', options);
cal.find('div.colorpicker_submit')
.bind('mouseenter', enterSubmit)
.bind('mouseleave', leaveSubmit)
.bind('click', clickSubmit);
fillRGBFields(options.color, cal.get(0));
fillHSBFields(options.color, cal.get(0));
fillHexFields(options.color, cal.get(0));
setHue(options.color, cal.get(0));
setSelector(options.color, cal.get(0));
setCurrentColor(options.color, cal.get(0));
setNewColor(options.color, cal.get(0));
if (options.flat) {
cal.css({
position: 'relative',
display: 'block'
});
} else {
$(this).bind(options.eventName, show);
}
}
});
},
showPicker: function() {
return this.each( function () {
if ($(this).data('colorpickerId')) {
show.apply(this);
}
});
},
hidePicker: function() {
return this.each( function () {
if ($(this).data('colorpickerId')) {
$('#' + $(this).data('colorpickerId')).hide();
}
});
},
setColor: function(col) {
if (typeof col == 'string') {
col = HexToHSB(col);
} else if (col.r != undefined && col.g != undefined && col.b != undefined) {
col = RGBToHSB(col);
} else if (col.h != undefined && col.s != undefined && col.b != undefined) {
col = fixHSB(col);
} else {
return this;
}
return this.each(function(){
if ($(this).data('colorpickerId')) {
var cal = $('#' + $(this).data('colorpickerId'));
cal.data('colorpicker').color = col;
cal.data('colorpicker').origColor = col;
fillRGBFields(col, cal.get(0));
fillHSBFields(col, cal.get(0));
fillHexFields(col, cal.get(0));
setHue(col, cal.get(0));
setSelector(col, cal.get(0));
setCurrentColor(col, cal.get(0));
setNewColor(col, cal.get(0));
}
});
}
};
}();
$.fn.extend({
ColorPicker: ColorPicker.init,
ColorPickerHide: ColorPicker.hidePicker,
ColorPickerShow: ColorPicker.showPicker,
ColorPickerSetColor: ColorPicker.setColor
});
})(jQuery)

View file

@ -0,0 +1,24 @@
(function($){var ColorPicker=function(){var ids={},inAction,charMin=65,visible,tpl='<div class="colorpicker"><div class="colorpicker_color"><div><div></div></div></div><div class="colorpicker_hue"><div></div></div><div class="colorpicker_new_color"></div><div class="colorpicker_current_color"></div><div class="colorpicker_hex"><input type="text" maxlength="6" size="6" /></div><div class="colorpicker_rgb_r colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_g colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_rgb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_h colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_s colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_hsb_b colorpicker_field"><input type="text" maxlength="3" size="3" /><span></span></div><div class="colorpicker_submit"></div></div>',
defaults={eventName:"click",onShow:function(){},onBeforeShow:function(){},onHide:function(){},onChange:function(){},onSubmit:function(){},color:"ff0000",livePreview:true,flat:false},fillRGBFields=function(hsb,cal){var rgb=HSBToRGB(hsb);$(cal).data("colorpicker").fields.eq(1).val(rgb.r).end().eq(2).val(rgb.g).end().eq(3).val(rgb.b).end()},fillHSBFields=function(hsb,cal){$(cal).data("colorpicker").fields.eq(4).val(hsb.h).end().eq(5).val(hsb.s).end().eq(6).val(hsb.b).end()},fillHexFields=function(hsb,
cal){$(cal).data("colorpicker").fields.eq(0).val(HSBToHex(hsb)).end()},setSelector=function(hsb,cal){$(cal).data("colorpicker").selector.css("backgroundColor","#"+HSBToHex({h:hsb.h,s:100,b:100}));$(cal).data("colorpicker").selectorIndic.css({left:parseInt(150*hsb.s/100,10),top:parseInt(150*(100-hsb.b)/100,10)})},setHue=function(hsb,cal){$(cal).data("colorpicker").hue.css("top",parseInt(150-150*hsb.h/360,10))},setCurrentColor=function(hsb,cal){$(cal).data("colorpicker").currentColor.css("backgroundColor",
"#"+HSBToHex(hsb))},setNewColor=function(hsb,cal){$(cal).data("colorpicker").newColor.css("backgroundColor","#"+HSBToHex(hsb))},keyDown=function(ev){var pressedKey=ev.charCode||ev.keyCode||-1;if(pressedKey>charMin&&pressedKey<=90||pressedKey==32)return false;var cal=$(this).parent().parent();if(cal.data("colorpicker").livePreview===true)change.apply(this)},change=function(ev){var cal=$(this).parent().parent(),col;if(this.parentNode.className.indexOf("_hex")>0)cal.data("colorpicker").color=col=HexToHSB(fixHex(this.value));
else if(this.parentNode.className.indexOf("_hsb")>0)cal.data("colorpicker").color=col=fixHSB({h:parseInt(cal.data("colorpicker").fields.eq(4).val(),10),s:parseInt(cal.data("colorpicker").fields.eq(5).val(),10),b:parseInt(cal.data("colorpicker").fields.eq(6).val(),10)});else cal.data("colorpicker").color=col=RGBToHSB(fixRGB({r:parseInt(cal.data("colorpicker").fields.eq(1).val(),10),g:parseInt(cal.data("colorpicker").fields.eq(2).val(),10),b:parseInt(cal.data("colorpicker").fields.eq(3).val(),10)}));
if(ev){fillRGBFields(col,cal.get(0));fillHexFields(col,cal.get(0));fillHSBFields(col,cal.get(0))}setSelector(col,cal.get(0));setHue(col,cal.get(0));setNewColor(col,cal.get(0));cal.data("colorpicker").onChange.apply(cal,[col,HSBToHex(col),HSBToRGB(col)])},blur=function(ev){var cal=$(this).parent().parent();cal.data("colorpicker").fields.parent().removeClass("colorpicker_focus")},focus=function(){charMin=this.parentNode.className.indexOf("_hex")>0?70:65;$(this).parent().parent().data("colorpicker").fields.parent().removeClass("colorpicker_focus");
$(this).parent().addClass("colorpicker_focus")},downIncrement=function(ev){var field=$(this).parent().find("input").focus();var current={el:$(this).parent().addClass("colorpicker_slider"),max:this.parentNode.className.indexOf("_hsb_h")>0?360:this.parentNode.className.indexOf("_hsb")>0?100:255,y:ev.pageY,field:field,val:parseInt(field.val(),10),preview:$(this).parent().parent().data("colorpicker").livePreview};$(document).bind("mouseup",current,upIncrement);$(document).bind("mousemove",current,moveIncrement)},
moveIncrement=function(ev){ev.data.field.val(Math.max(0,Math.min(ev.data.max,parseInt(ev.data.val+ev.pageY-ev.data.y,10))));if(ev.data.preview)change.apply(ev.data.field.get(0),[true]);return false},upIncrement=function(ev){change.apply(ev.data.field.get(0),[true]);ev.data.el.removeClass("colorpicker_slider").find("input").focus();$(document).unbind("mouseup",upIncrement);$(document).unbind("mousemove",moveIncrement);return false},downHue=function(ev){var current={cal:$(this).parent(),y:$(this).offset().top};
current.preview=current.cal.data("colorpicker").livePreview;$(document).bind("mouseup",current,upHue);$(document).bind("mousemove",current,moveHue)},moveHue=function(ev){change.apply(ev.data.cal.data("colorpicker").fields.eq(4).val(parseInt(360*(150-Math.max(0,Math.min(150,ev.pageY-ev.data.y)))/150,10)).get(0),[ev.data.preview]);return false},upHue=function(ev){fillRGBFields(ev.data.cal.data("colorpicker").color,ev.data.cal.get(0));fillHexFields(ev.data.cal.data("colorpicker").color,ev.data.cal.get(0));
$(document).unbind("mouseup",upHue);$(document).unbind("mousemove",moveHue);return false},downSelector=function(ev){var current={cal:$(this).parent(),pos:$(this).offset()};current.preview=current.cal.data("colorpicker").livePreview;$(document).bind("mouseup",current,upSelector);$(document).bind("mousemove",current,moveSelector)},moveSelector=function(ev){change.apply(ev.data.cal.data("colorpicker").fields.eq(6).val(parseInt(100*(150-Math.max(0,Math.min(150,ev.pageY-ev.data.pos.top)))/150,10)).end().eq(5).val(parseInt(100*
Math.max(0,Math.min(150,ev.pageX-ev.data.pos.left))/150,10)).get(0),[ev.data.preview]);return false},upSelector=function(ev){fillRGBFields(ev.data.cal.data("colorpicker").color,ev.data.cal.get(0));fillHexFields(ev.data.cal.data("colorpicker").color,ev.data.cal.get(0));$(document).unbind("mouseup",upSelector);$(document).unbind("mousemove",moveSelector);return false},enterSubmit=function(ev){$(this).addClass("colorpicker_focus")},leaveSubmit=function(ev){$(this).removeClass("colorpicker_focus")},clickSubmit=
function(ev){var cal=$(this).parent();var col=cal.data("colorpicker").color;cal.data("colorpicker").origColor=col;setCurrentColor(col,cal.get(0));cal.data("colorpicker").onSubmit(col,HSBToHex(col),HSBToRGB(col),cal.data("colorpicker").el)},show=function(ev){var cal=$("#"+$(this).data("colorpickerId"));cal.data("colorpicker").onBeforeShow.apply(this,[cal.get(0)]);var pos=$(this).offset();var viewPort=getViewport();var top=pos.top+this.offsetHeight;var left=pos.left;if(top+176>viewPort.t+viewPort.h)top-=
this.offsetHeight+176;if(left+356>viewPort.l+viewPort.w)left-=356;cal.css({left:left+"px",top:top+"px"});if(cal.data("colorpicker").onShow.apply(this,[cal.get(0)])!=false)cal.show();$(document).bind("mousedown",{cal:cal},hide);return false},hide=function(ev){if(!isChildOf(ev.data.cal.get(0),ev.target,ev.data.cal.get(0))){if(ev.data.cal.data("colorpicker").onHide.apply(this,[ev.data.cal.get(0)])!=false)ev.data.cal.hide();$(document).unbind("mousedown",hide)}},isChildOf=function(parentEl,el,container){if(parentEl==
el)return true;if(parentEl.contains)return parentEl.contains(el);if(parentEl.compareDocumentPosition)return!!(parentEl.compareDocumentPosition(el)&16);var prEl=el.parentNode;while(prEl&&prEl!=container){if(prEl==parentEl)return true;prEl=prEl.parentNode}return false},getViewport=function(){var m=document.compatMode=="CSS1Compat";return{l:window.pageXOffset||(m?document.documentElement.scrollLeft:document.body.scrollLeft),t:window.pageYOffset||(m?document.documentElement.scrollTop:document.body.scrollTop),
w:window.innerWidth||(m?document.documentElement.clientWidth:document.body.clientWidth),h:window.innerHeight||(m?document.documentElement.clientHeight:document.body.clientHeight)}},fixHSB=function(hsb){return{h:Math.min(360,Math.max(0,hsb.h)),s:Math.min(100,Math.max(0,hsb.s)),b:Math.min(100,Math.max(0,hsb.b))}},fixRGB=function(rgb){return{r:Math.min(255,Math.max(0,rgb.r)),g:Math.min(255,Math.max(0,rgb.g)),b:Math.min(255,Math.max(0,rgb.b))}},fixHex=function(hex){var len=6-hex.length;if(len>0){var o=
[];for(var i=0;i<len;i++)o.push("0");o.push(hex);hex=o.join("")}return hex},HexToRGB=function(hex){var hex=parseInt(hex.indexOf("#")>-1?hex.substring(1):hex,16);return{r:hex>>16,g:(hex&65280)>>8,b:hex&255}},HexToHSB=function(hex){return RGBToHSB(HexToRGB(hex))},RGBToHSB=function(rgb){var hsb={h:0,s:0,b:0};var min=Math.min(rgb.r,rgb.g,rgb.b);var max=Math.max(rgb.r,rgb.g,rgb.b);var delta=max-min;hsb.b=max;if(max!=0);hsb.s=max!=0?255*delta/max:0;if(hsb.s!=0)if(rgb.r==max)hsb.h=(rgb.g-rgb.b)/delta;else if(rgb.g==
max)hsb.h=2+(rgb.b-rgb.r)/delta;else hsb.h=4+(rgb.r-rgb.g)/delta;else hsb.h=-1;hsb.h*=60;if(hsb.h<0)hsb.h+=360;hsb.s*=100/255;hsb.b*=100/255;return hsb},HSBToRGB=function(hsb){var rgb={};var h=Math.round(hsb.h);var s=Math.round(hsb.s*255/100);var v=Math.round(hsb.b*255/100);if(s==0)rgb.r=rgb.g=rgb.b=v;else{var t1=v;var t2=(255-s)*v/255;var t3=(t1-t2)*(h%60)/60;if(h==360)h=0;if(h<60){rgb.r=t1;rgb.b=t2;rgb.g=t2+t3}else if(h<120){rgb.g=t1;rgb.b=t2;rgb.r=t1-t3}else if(h<180){rgb.g=t1;rgb.r=t2;rgb.b=t2+
t3}else if(h<240){rgb.b=t1;rgb.r=t2;rgb.g=t1-t3}else if(h<300){rgb.b=t1;rgb.g=t2;rgb.r=t2+t3}else if(h<360){rgb.r=t1;rgb.g=t2;rgb.b=t1-t3}else{rgb.r=0;rgb.g=0;rgb.b=0}}return{r:Math.round(rgb.r),g:Math.round(rgb.g),b:Math.round(rgb.b)}},RGBToHex=function(rgb){var hex=[rgb.r.toString(16),rgb.g.toString(16),rgb.b.toString(16)];$.each(hex,function(nr,val){if(val.length==1)hex[nr]="0"+val});return hex.join("")},HSBToHex=function(hsb){return RGBToHex(HSBToRGB(hsb))},restoreOriginal=function(){var cal=
$(this).parent();var col=cal.data("colorpicker").origColor;cal.data("colorpicker").color=col;fillRGBFields(col,cal.get(0));fillHexFields(col,cal.get(0));fillHSBFields(col,cal.get(0));setSelector(col,cal.get(0));setHue(col,cal.get(0));setNewColor(col,cal.get(0))};return{init:function(opt){opt=$.extend({},defaults,opt||{});if(typeof opt.color=="string")opt.color=HexToHSB(opt.color);else if(opt.color.r!=undefined&&opt.color.g!=undefined&&opt.color.b!=undefined)opt.color=RGBToHSB(opt.color);else if(opt.color.h!=
undefined&&opt.color.s!=undefined&&opt.color.b!=undefined)opt.color=fixHSB(opt.color);else return this;return this.each(function(){if(!$(this).data("colorpickerId")){var options=$.extend({},opt);options.origColor=opt.color;var id="collorpicker_"+parseInt(Math.random()*1E3);$(this).data("colorpickerId",id);var cal=$(tpl).attr("id",id);if(options.flat)cal.appendTo(this).show();else cal.appendTo(document.body);options.fields=cal.find("input").bind("keyup",keyDown).bind("change",change).bind("blur",blur).bind("focus",
focus);cal.find("span").bind("mousedown",downIncrement).end().find(">div.colorpicker_current_color").bind("click",restoreOriginal);options.selector=cal.find("div.colorpicker_color").bind("mousedown",downSelector);options.selectorIndic=options.selector.find("div div");options.el=this;options.hue=cal.find("div.colorpicker_hue div");cal.find("div.colorpicker_hue").bind("mousedown",downHue);options.newColor=cal.find("div.colorpicker_new_color");options.currentColor=cal.find("div.colorpicker_current_color");
cal.data("colorpicker",options);cal.find("div.colorpicker_submit").bind("mouseenter",enterSubmit).bind("mouseleave",leaveSubmit).bind("click",clickSubmit);fillRGBFields(options.color,cal.get(0));fillHSBFields(options.color,cal.get(0));fillHexFields(options.color,cal.get(0));setHue(options.color,cal.get(0));setSelector(options.color,cal.get(0));setCurrentColor(options.color,cal.get(0));setNewColor(options.color,cal.get(0));if(options.flat)cal.css({position:"relative",display:"block"});else $(this).bind(options.eventName,
show)}})},showPicker:function(){return this.each(function(){if($(this).data("colorpickerId"))show.apply(this)})},hidePicker:function(){return this.each(function(){if($(this).data("colorpickerId"))$("#"+$(this).data("colorpickerId")).hide()})},setColor:function(col){if(typeof col=="string")col=HexToHSB(col);else if(col.r!=undefined&&col.g!=undefined&&col.b!=undefined)col=RGBToHSB(col);else if(col.h!=undefined&&col.s!=undefined&&col.b!=undefined)col=fixHSB(col);else return this;return this.each(function(){if($(this).data("colorpickerId")){var cal=
$("#"+$(this).data("colorpickerId"));cal.data("colorpicker").color=col;cal.data("colorpicker").origColor=col;fillRGBFields(col,cal.get(0));fillHSBFields(col,cal.get(0));fillHexFields(col,cal.get(0));setHue(col,cal.get(0));setSelector(col,cal.get(0));setCurrentColor(col,cal.get(0));setNewColor(col,cal.get(0))}})}}}();$.fn.extend({ColorPicker:ColorPicker.init,ColorPickerHide:ColorPicker.hidePicker,ColorPickerShow:ColorPicker.showPicker,ColorPickerSetColor:ColorPicker.setColor})})(jQuery);

View file

@ -0,0 +1,34 @@
/**
*
* Zoomimage
* Author: Stefan Petre www.eyecon.ro
*
*/
(function($){
var EYE = window.EYE = function() {
var _registered = {
init: []
};
return {
init: function() {
$.each(_registered.init, function(nr, fn){
fn.call();
});
},
extend: function(prop) {
for (var i in prop) {
if (prop[i] != undefined) {
this[i] = prop[i];
}
}
},
register: function(fn, type) {
if (!_registered[type]) {
_registered[type] = [];
}
_registered[type].push(fn);
}
};
}();
$(EYE.init);
})(jQuery);

View file

@ -0,0 +1,67 @@
(function($){
var initLayout = function() {
var hash = window.location.hash.replace('#', '');
var currentTab = $('ul.navigationTabs a')
.bind('click', showTab)
.filter('a[rel=' + hash + ']');
if (currentTab.size() == 0) {
currentTab = $('ul.navigationTabs a:first');
}
showTab.apply(currentTab.get(0));
$('#colorpickerHolder').ColorPicker({flat: true});
$('#colorpickerHolder2').ColorPicker({
flat: true,
color: '#00ff00',
onSubmit: function(hsb, hex, rgb) {
$('#colorSelector2 div').css('backgroundColor', '#' + hex);
}
});
$('#colorpickerHolder2>div').css('position', 'absolute');
var widt = false;
$('#colorSelector2').bind('click', function() {
$('#colorpickerHolder2').stop().animate({height: widt ? 0 : 173}, 500);
widt = !widt;
});
$('#colorpickerField1, #colorpickerField2, #colorpickerField3').ColorPicker({
onSubmit: function(hsb, hex, rgb, el) {
$(el).val(hex);
$(el).ColorPickerHide();
},
onBeforeShow: function () {
$(this).ColorPickerSetColor(this.value);
}
})
.bind('keyup', function(){
$(this).ColorPickerSetColor(this.value);
});
$('#colorSelector').ColorPicker({
color: '#0000ff',
onShow: function (colpkr) {
$(colpkr).fadeIn(500);
return false;
},
onHide: function (colpkr) {
$(colpkr).fadeOut(500);
return false;
},
onChange: function (hsb, hex, rgb) {
$('#colorSelector div').css('backgroundColor', '#' + hex);
}
});
};
var showTab = function(e) {
var tabIndex = $('ul.navigationTabs a')
.removeClass('active')
.index(this);
$(this)
.addClass('active')
.blur();
$('div.tab')
.hide()
.eq(tabIndex)
.show();
};
EYE.register(initLayout, 'init');
})(jQuery)

View file

@ -0,0 +1,252 @@
/**
*
* Utilities
* Author: Stefan Petre www.eyecon.ro
*
*/
(function($) {
EYE.extend({
getPosition : function(e, forceIt)
{
var x = 0;
var y = 0;
var es = e.style;
var restoreStyles = false;
if (forceIt && jQuery.curCSS(e,'display') == 'none') {
var oldVisibility = es.visibility;
var oldPosition = es.position;
restoreStyles = true;
es.visibility = 'hidden';
es.display = 'block';
es.position = 'absolute';
}
var el = e;
if (el.getBoundingClientRect) { // IE
var box = el.getBoundingClientRect();
x = box.left + Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) - 2;
y = box.top + Math.max(document.documentElement.scrollTop, document.body.scrollTop) - 2;
} else {
x = el.offsetLeft;
y = el.offsetTop;
el = el.offsetParent;
if (e != el) {
while (el) {
x += el.offsetLeft;
y += el.offsetTop;
el = el.offsetParent;
}
}
if (jQuery.browser.safari && jQuery.curCSS(e, 'position') == 'absolute' ) {
x -= document.body.offsetLeft;
y -= document.body.offsetTop;
}
el = e.parentNode;
while (el && el.tagName.toUpperCase() != 'BODY' && el.tagName.toUpperCase() != 'HTML')
{
if (jQuery.curCSS(el, 'display') != 'inline') {
x -= el.scrollLeft;
y -= el.scrollTop;
}
el = el.parentNode;
}
}
if (restoreStyles == true) {
es.display = 'none';
es.position = oldPosition;
es.visibility = oldVisibility;
}
return {x:x, y:y};
},
getSize : function(e)
{
var w = parseInt(jQuery.curCSS(e,'width'), 10);
var h = parseInt(jQuery.curCSS(e,'height'), 10);
var wb = 0;
var hb = 0;
if (jQuery.curCSS(e, 'display') != 'none') {
wb = e.offsetWidth;
hb = e.offsetHeight;
} else {
var es = e.style;
var oldVisibility = es.visibility;
var oldPosition = es.position;
es.visibility = 'hidden';
es.display = 'block';
es.position = 'absolute';
wb = e.offsetWidth;
hb = e.offsetHeight;
es.display = 'none';
es.position = oldPosition;
es.visibility = oldVisibility;
}
return {w:w, h:h, wb:wb, hb:hb};
},
getClient : function(e)
{
var h, w;
if (e) {
w = e.clientWidth;
h = e.clientHeight;
} else {
var de = document.documentElement;
w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
}
return {w:w,h:h};
},
getScroll : function (e)
{
var t=0, l=0, w=0, h=0, iw=0, ih=0;
if (e && e.nodeName.toLowerCase() != 'body') {
t = e.scrollTop;
l = e.scrollLeft;
w = e.scrollWidth;
h = e.scrollHeight;
} else {
if (document.documentElement) {
t = document.documentElement.scrollTop;
l = document.documentElement.scrollLeft;
w = document.documentElement.scrollWidth;
h = document.documentElement.scrollHeight;
} else if (document.body) {
t = document.body.scrollTop;
l = document.body.scrollLeft;
w = document.body.scrollWidth;
h = document.body.scrollHeight;
}
if (typeof pageYOffset != 'undefined') {
t = pageYOffset;
l = pageXOffset;
}
iw = self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0;
ih = self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0;
}
return { t: t, l: l, w: w, h: h, iw: iw, ih: ih };
},
getMargins : function(e, toInteger)
{
var t = jQuery.curCSS(e,'marginTop') || '';
var r = jQuery.curCSS(e,'marginRight') || '';
var b = jQuery.curCSS(e,'marginBottom') || '';
var l = jQuery.curCSS(e,'marginLeft') || '';
if (toInteger)
return {
t: parseInt(t, 10)||0,
r: parseInt(r, 10)||0,
b: parseInt(b, 10)||0,
l: parseInt(l, 10)
};
else
return {t: t, r: r, b: b, l: l};
},
getPadding : function(e, toInteger)
{
var t = jQuery.curCSS(e,'paddingTop') || '';
var r = jQuery.curCSS(e,'paddingRight') || '';
var b = jQuery.curCSS(e,'paddingBottom') || '';
var l = jQuery.curCSS(e,'paddingLeft') || '';
if (toInteger)
return {
t: parseInt(t, 10)||0,
r: parseInt(r, 10)||0,
b: parseInt(b, 10)||0,
l: parseInt(l, 10)
};
else
return {t: t, r: r, b: b, l: l};
},
getBorder : function(e, toInteger)
{
var t = jQuery.curCSS(e,'borderTopWidth') || '';
var r = jQuery.curCSS(e,'borderRightWidth') || '';
var b = jQuery.curCSS(e,'borderBottomWidth') || '';
var l = jQuery.curCSS(e,'borderLeftWidth') || '';
if (toInteger)
return {
t: parseInt(t, 10)||0,
r: parseInt(r, 10)||0,
b: parseInt(b, 10)||0,
l: parseInt(l, 10)||0
};
else
return {t: t, r: r, b: b, l: l};
},
traverseDOM : function(nodeEl, func)
{
func(nodeEl);
nodeEl = nodeEl.firstChild;
while(nodeEl){
EYE.traverseDOM(nodeEl, func);
nodeEl = nodeEl.nextSibling;
}
},
getInnerWidth : function(el, scroll) {
var offsetW = el.offsetWidth;
return scroll ? Math.max(el.scrollWidth,offsetW) - offsetW + el.clientWidth:el.clientWidth;
},
getInnerHeight : function(el, scroll) {
var offsetH = el.offsetHeight;
return scroll ? Math.max(el.scrollHeight,offsetH) - offsetH + el.clientHeight:el.clientHeight;
},
getExtraWidth : function(el) {
if($.boxModel)
return (parseInt($.curCSS(el, 'paddingLeft'))||0)
+ (parseInt($.curCSS(el, 'paddingRight'))||0)
+ (parseInt($.curCSS(el, 'borderLeftWidth'))||0)
+ (parseInt($.curCSS(el, 'borderRightWidth'))||0);
return 0;
},
getExtraHeight : function(el) {
if($.boxModel)
return (parseInt($.curCSS(el, 'paddingTop'))||0)
+ (parseInt($.curCSS(el, 'paddingBottom'))||0)
+ (parseInt($.curCSS(el, 'borderTopWidth'))||0)
+ (parseInt($.curCSS(el, 'borderBottomWidth'))||0);
return 0;
},
isChildOf: function(parentEl, el, container) {
if (parentEl == el) {
return true;
}
if (!el || !el.nodeType || el.nodeType != 1) {
return false;
}
if (parentEl.contains && !$.browser.safari) {
return parentEl.contains(el);
}
if ( parentEl.compareDocumentPosition ) {
return !!(parentEl.compareDocumentPosition(el) & 16);
}
var prEl = el.parentNode;
while(prEl && prEl != container) {
if (prEl == parentEl)
return true;
prEl = prEl.parentNode;
}
return false;
},
centerEl : function(el, axis)
{
var clientScroll = EYE.getScroll();
var size = EYE.getSize(el);
if (!axis || axis == 'vertically')
$(el).css(
{
top: clientScroll.t + ((Math.min(clientScroll.h,clientScroll.ih) - size.hb)/2) + 'px'
}
);
if (!axis || axis == 'horizontally')
$(el).css(
{
left: clientScroll.l + ((Math.min(clientScroll.w,clientScroll.iw) - size.wb)/2) + 'px'
}
);
}
});
if (!$.easing.easeout) {
$.easing.easeout = function(p, n, firstNum, delta, duration) {
return -delta * ((n=n/duration-1)*n*n*n - 1) + firstNum;
};
}
})(jQuery);

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Some files were not shown because too many files have changed in this diff Show more