public function __construct() { switch (BF::gc('mail_method')) { case "smtp": $this->Host = BF::gc('mail_smtp_host'); $this->Mailer = 'smtp'; if (BF::gc('mail_smtp_username') != NULL) { $this->SMTPAuth = true; $this->Username = BF::gc('mail_smtp_username'); $this->Password = BF::gc('mail_smtp_password'); $this->SMTPSecure = 'ssl'; } if (BF::gc('mail_smtp_port') != NULL) { $this->Port = BF::gc('mail_smtp_port'); } break; case "sendmail": $this->Mailer = "sendmail"; $this->Sendmail = BF::gc('mail_sendmail_path'); break; case "mail": default: $this->Mailer = "mail"; break; } $this->PluginDir = BF::gr('/lib/phpmailer/')->path(); $this->SetLanguage(BF::gl()->lang, BF::gr('/lib/phpmailer/language/')->path()); $this->WordWrap = 75; }
public function __construct($e) { $this->e = $e; if (!$e instanceof BF_user_exception) { // log error and send mail if requiered BF_error::log($e); } // array of infos to display to user try { // if we are dealing with a user error if ($e instanceof BF_user_exception) { $this->display['type'] = get_class($e); $this->display['title'] = BF::gl()->tl($this->e->display['title'] ? $this->e->display['title'] : '[xx:error.title_' . $this->display['type'] . ']'); $this->display['message'] = BF::gl()->tl($this->e->display['message'] ? $this->e->display['message'] : '[xx:error.' . $this->display['type'] . ']'); // otherwise if a php error (bug) } else { $this->display['title'] = BF::gl()->tl_tag("error.title_BF_internal"); $this->display['message'] = BF::gl()->tl_tag("error.BF_internal"); $this->display['type'] = 'BF_internal'; } } catch (exception $new_e) { // if a second exception occurs while translating, then just skip this step $this->display['title'] = 'Error occured'; $this->display['message'] = 'Internal Error'; $this->display['type'] = 'BF_internal'; } }
/** * Login the user * @param string $password : Password submited by user * @param string $force [optional default false] : Force login, even if password doesn't match * @return bool true */ public function login($password, $force = false) { if (!$force && !$this->check_password($password)) { return false; } $this->register(); if (isset($this->locale)) { BF::gl()->set($this->locale); } $this->set_login_time(BF::$time); return true; }
/** * Generate an url * @param string $href [optional default false] : file to point, see doc of BF::gr function for detail * @param string $locale [optional default false] : force a locale for href (or current page if href is false) * @return string url */ public function make_url($href = false, $locale = null) { if ($href === false && $locale != null && BF::gc('locale_enabled')) { if (BF::gc('locale_use_url')) { $base = BF::$base_url . (isset($_GET['detected_locale']) ? $_GET['detected_locale'] . '/' : ''); $url = substr($_SERVER['REQUEST_URI'], strlen($base)); return BF::gr($url)->url($locale); } else { return BF::gl()->format_url('', $_SERVER['REQUEST_URI'], $p['locale']); } } else { return BF::gr($href)->url($locale); } }
function smarty_function_input($p, Smarty_Internal_Template $template) { $smarty = $template->smarty; BF::load_module('BF_form'); // Determine input ID and field name if (!isset($p['id']) || $p['id'] == '') { static $counter = 0; $id = $p['id'] = 'input_unnamed_' . ++$counter; } else { $id = $p['id']; } if (!isset($p['name']) || $p['name'] == '') { $name = $p['name'] = $p['id']; } else { $name = $p['name']; } // Load form data from <form> tag, or from a given form_data if (isset($p['form_data'])) { $form = gform($p['form_data']); } else { for ($i = count($smarty->_tag_stack) - 1; $i >= 0; $i--) { if ($smarty->_tag_stack[$i][0] == 'form') { $form = $smarty->_tag_stack[$i][1]['data'] = gform(isset($smarty->_tag_stack[$i][1]['data']) ? $smarty->_tag_stack[$i][1]['data'] : null); break; } } } if (!isset($form)) { $form = gform(); } // if no forms were found, then juste create a new form object // properties set as parmeters and not in the properties array should be appended foreach ($p as $param => $value) { if (in_array($param, BF_form::$properties)) { $p['properties'][$param]['value'] = $value; // see if there are any default invalid message to display if (BF::gc('locale_enabled') && BF::gl()->block_exists('form.error_' . $param)) { $p['properties'][$param]['invalid_message'] = BF::gl()->tl_tag('form.error_' . $param . '|' . $value . '|' . ucfirst(isset($p['title']) ? $p['title'] : ($form->get_title($name) ? $form->get_title($name) : (isset($p['alt']) ? $p['alt'] : $name)))); } unset($p[$param]); } } // get data from field and append passed properties and options $field =& $form->get_field($name); // mix prameters and field data, parameters override field data if (isset($p['properties']) && is_array($p['properties'])) { $field['properties'] = array_merge(isset($field['properties']) && is_array($field['properties']) ? $field['properties'] : array(), $p['properties']); } if (isset($p['options']) && is_array($p['options'])) { $field['options'] = array_merge(isset($field['options']) && is_array($field['options']) ? $field['options'] : array(), $p['options']); } $p = array_merge($field, $p); $p['properties'] =& $form->get_properties($name); $p['options'] =& $form->get_options($name); // get input type $type = isset($p['type']) ? $p['type'] : 'text'; // if file input, set form enctype to multipart, if not already set if ($type == 'file' && !$form->enctype) { $form->enctype = 'file'; } // if using max length, then add the html MAXLENGTH attribut too if ($form->get_property($name, 'max_length') > 0) { $maxlength = $form->get_property($name, 'max_length'); $p['maxlength'] = $maxlength['value']; } // see if input is disabled or checked if (array_key_exists('disabled', $p)) { if ($p['disabled']) { $p['disabled'] = 'disabled'; } else { unset($p['disabled']); } } if (array_key_exists('readonly', $p)) { if ($p['readonly']) { $p['readonly'] = 'readonly'; } else { unset($p['readonly']); } } if (array_key_exists('checked', $p)) { if ($p['checked']) { $p['checked'] = 'checked'; } else { unset($p['checked']); } } if (array_key_exists('multiple', $p)) { if ($p['multiple']) { $p['multiple'] = 'multiple'; } else { unset($p['multiple']); } } // init the output string $html = ""; // compute options list for iselect/select/radioset if ($type == 'select' || $type == 'iselect' || $type == 'radioset') { $options_html = ''; $selected_option = false; if ($type == 'iselect') { $options_html .= "<div" . $smarty->attr('id', $id . '_iselect_div') . $smarty->attr('class', 'input_iselect_list') . ">"; } if (isset($p['options']) && is_array($p['options'])) { foreach ($p['options'] as $option) { if (!is_array($option)) { $option = array('value' => $option); } if (!isset($option['value'])) { $option['value'] = ''; } if (!isset($option['text'])) { $option['text'] = isset($option['label']) ? $option['label'] : $option['value']; } if (isset($option['selected']) && $option['selected'] || isset($option['checked']) && $option['checked'] || isset($p['value']) && (string) $p['value'] === (string) $option['value'] && !$selected_option) { if ($type == 'radioset') { $option['checked'] = 'checked'; } else { $option['selected'] = 'selected'; } $p['value'] = $option['value']; if ($type != 'select' || !isset($p['multiple'])) { $selected_option =& $option; } // save selected option, so that we don't select followings options that have the same value } else { unset($option['selected'], $option['checked']); } if (isset($option['disabled']) && $option['disabled']) { $option['disabled'] = 'disabled'; } else { unset($option['disabled']); } if ($type == 'iselect') { $options_html .= '<a'; } else { if ($type == 'select') { $options_html .= '<option'; } else { if ($type == 'radioset') { $option['class'] = 'input input_radio' . (isset($option['class']) ? ' ' . $option['class'] : ''); $options_html .= '<label><input type="radio"' . $smarty->attr('name', $name) . (isset($p["onchange"]) ? $smarty->attr('onchange', $p["onchange"]) : "") . (isset($p["onclick"]) ? $smarty->attr('onclick', $p["onclick"]) : ""); } } } foreach ($option as $key => $val) { if ($key != 'text' && $key != 'label') { $options_html .= $smarty->attr($key, $val); } } if ($type == 'iselect') { $options_html .= '>' . $option['text'] . '</a>'; } elseif ($type == 'select') { $options_html .= '>' . $option['text'] . '</option>'; } elseif ($type == 'radioset') { $options_html .= '/>' . $option['text'] . '</label>'; } } } if ($type == 'iselect' || $type == 'radioset') { unset($p["onchange"], $p["onclick"]); } if ($type == 'iselect') { // if type is iselect, print options now and change type to normal text or hidden $html .= $options_html . '</div>'; // by default, an iselect should be an hidden field, but it may also be a text field $type = $form->has_property($name, 'editable') ? 'text' : 'hidden'; // set the iselect property $p['properties']['iselect'] = array('value' => $id . '_iselect_div'); } } // append common class names $p['class'] = 'input input_' . $type . (isset($p['class']) ? ' ' . $p['class'] : ''); // open html tag if ($type == 'textarea' || $type == 'button' || $type == 'select') { $html .= "<" . $type; } elseif ($type == 'radioset') { $html .= "<div"; } else { $html .= "<input" . $smarty->attr('type', $type); } // append all other params $reserved = array('properties', 'options', 'label', 'type', 'form_data'); if ($type == 'textarea') { $reserved[] = 'value'; } //if ($type == 'checkbox' && isset($p['value']) && !isset($p['checked'])) { // if ($p['value']) $p['checked'] = 'checked'; //} foreach ($p as $key => $val) { if ($key != '' && !in_array($key, $reserved)) { $html .= $smarty->attr($key, $val); } } // close tag if ($type == 'textarea') { $html .= ">" . htmlspecialchars(isset($p['value']) ? $p['value'] : '', ENT_COMPAT, BF::$encoding) . "</textarea>"; } elseif ($type == 'button') { $html .= ">" . htmlspecialchars(isset($p['label']) ? $p['label'] : (isset($p['value']) ? $p['value'] : ''), ENT_COMPAT, BF::$encoding) . "</button>"; } elseif ($type == 'select') { $html .= ">" . $options_html . "</select>"; } elseif ($type == 'radioset') { $html .= ">" . $options_html . "</div>"; } else { $html .= " />"; } // print label for radio, checkbox, etc... if (isset($p['label']) && $p['label'] != '') { $html .= '<label' . $smarty->attr('for', $id) . '>' . $p['label'] . '</label>'; } // if there are at least one property if (count($p['properties'])) { // load js file if it is the first time a field requires such options /*static $js_loaded; if (!$js_loaded) { $html .= $smarty->tpl_js(Array(), 'if (window.Prototype == undefined) document.write('.str_replace('/', '\\/', Q($smarty->tpl_js(Array('src' => "lib/prototype.js"), '', $smarty))).');', $smarty); $html .= $smarty->tpl_js(Array(), 'if (window.advancedFormControl == undefined) document.write('.str_replace('/', '\\/', Q($smarty->tpl_js(Array('src' => "form.js"), '', $smarty))).');', $smarty); // Note : Of script is loaded that way, then it might not be laoded yet when next line is executed //$html .= $smarty->tpl_js(Array(), 'if (window.advancedFormControl == undefined) document.getElementsByTagName("head")[0].appendChild(new Element("script", {type: "text/javascript", src: "'.gf('js')->web_path.'form.js"}));', $smarty); $js_loaded = true; }*/ BF::gr("/tags/block.js.php")->load_once(); $load_js = smarty_block_js(array('src' => "lib/form.js"), "", $template); $html .= smarty_block_js(array(), 'if (afcUtils == undefined) document.write(' . str_replace('/', '\\/', Q($load_js)) . ');', $template); $html .= smarty_block_js(array(), $form->get_js($name, $id), $template); } return $html; }
/** * Generate a url to folder * @param String $locale [optional default null] : Set a different locale for url (if site is locale-enabled and uses url to transmit locale) * @return An URL to ressource */ public function url($locale = null) { switch ($this->type) { case self::REMOTE: return $this->path; case self::ABSOLUTE: throw new exception("Folder '" . $this->id . "' has an absolute path and cannot be accessed from outside, it has no URL"); default: if (BF::gc('locale_enabled')) { return BF::gl()->format_url(BF::$base_url, $this->path, $locale); } else { return BF::$base_url . $this->path; } } }
/** * Show last error message by throwing a BF_invalid_form * Note : shows only one error message for last invalid field * @return bool false if no error, throw exception otherwise */ public function show_error() { if (!$this->error) { return false; } $condition = $this->get_property($this->error['field'], $this->error['property']); if (!isset($condition['invalid_message'])) { $condition['invalid_message'] = $message = BF::gl()->block_exists('form.error_' . $this->error['property']) ? 'form.error_' . $this->error['property'] : 'form.error' . '|' . (isset($condition['value']) ? $condition['value'] : "") . '|' . $this->get_title($this->error['field']); } throw new BF_invalid_form($condition['invalid_message']); }
function smarty_prefilter_translate($source, Smarty_Internal_Template $template) { return BF::gl()->tl($source); }