Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 public function log()
 {
     // timestamp for the error entry
     $dt = date("Y-m-d H:i:s (T)", BF::$time);
     // define an assoc array of error string
     // in reality the only entries we should
     // consider are E_WARNING, E_NOTICE, E_USER_ERROR,
     // E_USER_WARNING and E_USER_NOTICE
     $errortype = array(E_WARNING => 'Warning', E_NOTICE => 'Notice', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice', E_STRICT => 'Runtime Notice');
     if (defined('E_RECOVERABLE_ERROR')) {
         $errortype[E_RECOVERABLE_ERROR] = 'Catchable Fatal Error';
     }
     $this->debug_html = "<b><u>Debug Info</u></b>\n\n";
     $this->debug_html .= "Date time : <b>" . $dt . "</b>\n";
     $this->debug_html .= "Error num : <b>" . $this->e->getCode() . "</b>\n";
     $this->debug_html .= "Error type : <b>" . (isset($errortype[$this->e->getCode()]) ? $errortype[$this->e->getCode()] : '-') . "</b>\n";
     $this->debug_html .= "Error msg : <b>" . $this->e->getMessage() . "</b>\n";
     $this->debug_html .= "Script name : <b>" . $this->e->getFile() . "</b>\n";
     $this->debug_html .= "Script line num : <b>" . $this->e->getLine() . "</b>\n";
     $this->debug_html .= "Trace : \n\t" . str_replace("\n", "\n\t", htmlentities($this->e->getTraceAsString()));
     $debug_xml = "<errorentry>\n";
     $debug_xml .= "\t<datetime>" . $dt . "</datetime>\n";
     $debug_xml .= "\t<errornum>" . $this->e->getCode() . "</errornum>\n";
     $debug_xml .= "\t<errortype>" . (isset($errortype[$this->e->getCode()]) ? $errortype[$this->e->getCode()] : '-') . "</errortype>\n";
     $debug_xml .= "\t<errormsg>" . $this->e->getMessage() . "</errormsg>\n";
     $debug_xml .= "\t<scriptname>" . $this->e->getFile() . "</scriptname>\n";
     $debug_xml .= "\t<scriptlinenum>" . $this->e->getLine() . "</scriptlinenum>\n";
     $debug_xml .= "\t<trace><entry>" . implode('</entry><entry>', explode("\n", $this->e->getTraceAsString())) . "</entry></trace>\n";
     $debug_xml .= "</errorentry>\n\n";
     // send error mail
     try {
         if (BF::gc('error_send_mail')) {
             if (!BF::gc('error_email') || !@mail(BF::gc('error_email'), 'Critical error on ' . $_SERVER['HTTP_HOST'], $debug_xml, 'From: Error Handler')) {
                 // if failed sending mail, add a notice to the log
                 $this->debug_html .= "\nFailed sending error mail to " . BF::gc('error_email');
                 $debug_xml .= "<errorentry>\n";
                 $debug_xml .= "\t<datetime>" . $dt . "</datetime>\n";
                 $debug_xml .= "\t<errormsg>Failed sending error mail to " . BF::gc('error_email') . "</errormsg>\n";
                 $debug_xml .= "</errorentry>\n\n";
             }
         }
     } catch (exception $new_e) {
     }
     // log error
     if (BF::gc('error_log')) {
         @error_log($this->debug_xml, 3, BF::gf('log')->path() . 'errorlog.txt');
     }
 }
Exemplo n.º 3
0
<?php

/*-----------------------------------------------------*\

                  YOUR WEBSITE HERE

\*-----------------------------------------------------*/
// This website uses phpBF
require_once './core/lib/phpbf/framework.php';
BF::init();
$page = BF::gg(0);
if (!$page || $page == "index.php") {
    BF::gr(BF::gc('page_default'))->redirect();
    // try loading a template
} elseif (BF::gr("/tpl/" . $page . '.tpl')->exists()) {
    BF::load_module("BF_output_template");
    $tpl = new BF_output_template($page);
    $tpl->disp();
} else {
    throw new BF_not_found();
}
Exemplo n.º 4
0
 /**
  * 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);
     }
 }
Exemplo n.º 5
0
 public function is_logged()
 {
     if (isset($this->_data['_logged'])) {
         return $this->_data['_logged'];
     }
     if (isset($_SESSION['BF_' . BF::gc('project_id') . '_login_time'], $_SESSION['BF_' . BF::gc('project_id') . '_logged_id_user']) && $_SESSION['BF_' . BF::gc('project_id') . '_logged_id_user'] == $this->_id && (BF::gc('user_login_time') == 0 || $_SESSION['BF_' . BF::gc('project_id') . '_login_time'] > BF::$time - 3600 * BF::gc('user_login_time')) && (BF::gc('user_inactivity_time') == 0 || isset($_SESSION['BF_' . BF::gc('project_id') . '_activity_time']) && $_SESSION['BF_' . BF::gc('project_id') . '_activity_time'] > BF::$time - 3600 * BF::gc('user_inactivity_time'))) {
         return $this->_data['_logged'] = true;
     } else {
         if (isset($_SESSION['BF_' . BF::gc('project_id') . '_logged_id_user'])) {
             unset($_SESSION['BF_' . BF::gc('project_id') . '_logged_id_user']);
         }
         return $this->_data['_logged'] = false;
     }
 }
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
 /**
  * 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;
             }
     }
 }
Exemplo n.º 8
0
 /**
  * Constructor
  * @param	string	$id [optional default null] : Name of the file containing form data (without the .frm extension). If null, no data will be loaded initialy
  * @param	string	$method [optional default POST] : form method : either GET or POST
  */
 public function __construct($id = null, $method = 'post')
 {
     $this->method = strtolower($method) == 'post' ? 'post' : 'get';
     if ($id == null) {
         $this->fields = array();
     } else {
         $source = BF::gr($id . ".frm", 'forms');
         $compiled = BF::gr($id . (BF::gc('locale_enabled') ? '.' . BF::gl()->locale : '') . '.php', 'compiled_forms');
         if (!$source->exists()) {
             throw new exception('No XML form data found for form id : ' . $id . ', make sure ' . $id . '.frm is placed in the forms directory');
         }
         // check if compiled exists and is not outdated
         if (!$compiled->exists() || filemtime($compiled->path()) < filemtime($source->path())) {
             // COMPILE FORM FILE
             // pase data xml file
             $fields = array();
             // output to be saved in the php file
             // open file and translate
             $source = file_get_contents($source->path());
             $xmlDoc = new DOMDocument();
             $xmlDoc->loadXML(BF::gc('locale_enabled') ? BF::gl()->tl($source) : $source);
             // search for FIELD entries
             foreach ($xmlDoc->documentElement->childNodes as $field) {
                 if ($field->nodeName == 'field' && $field->hasAttribute('name')) {
                     $name = $field->getAttribute('name');
                     $fields[$name] = array();
                     // add all attributes
                     foreach ($field->attributes as $attr) {
                         $fields[$name][$attr->nodeName] = $attr->nodeValue;
                     }
                     // add all properties and options
                     foreach ($field->childNodes as $item) {
                         // add all properties
                         if ($item instanceof DOMElement && $item->tagName == 'property' && $item->hasAttribute('name')) {
                             $fields[$name]['properties'][$item->getAttribute('name')] = array();
                             $property =& $fields[$name]['properties'][$item->getAttribute('name')];
                             if ($item->hasAttribute('delay')) {
                                 $property['delay'] = (int) $item->getAttribute('delay');
                             }
                             // if value attribute is set
                             if ($item->hasAttribute('value')) {
                                 $property['value'] = $item->getAttribute('value');
                                 // else get value could be an array of nested option/item tags
                             } else {
                                 // each option/item
                                 foreach ($item->childNodes as $property_item) {
                                     // add an option value
                                     if ($property_item instanceof DOMElement && $property_item->tagName == 'option') {
                                         // add some options to this property
                                         $option = array('text' => '');
                                         foreach ($item->childNodes as $child) {
                                             $option['text'] .= $xmlDoc->saveXML($child);
                                         }
                                         // add all option's attributes
                                         foreach ($property_item->attributes as $attr) {
                                             $option[$attr->nodeName] = $attr->nodeValue;
                                         }
                                         $property['value'][] = $option;
                                         // add an item value
                                     } elseif ($property_item instanceof DOMElement && $property_item->tagName == 'item' && $property_item->hasAttribute('value')) {
                                         $property['value'][] = $property_item->getAttribute('value');
                                     }
                                 }
                                 // in case no option/item were found
                                 //if (!isset($fields[$name]['properties'][$item->getAttribute('name')]['value'])) $fields[$name]['properties'][$item->getAttribute('name')] = ;
                             }
                             // text to display in case value is invalid
                             if ($item->hasAttribute('invalid_message')) {
                                 $property['invalid_message'] = $item->getAttribute('invalid_message');
                             } elseif (BF::gc('locale_enabled') && BF::gl()->block_exists('form.error_' . $item->getAttribute('name'))) {
                                 // see if there are any default message to display
                                 $property['invalid_message'] = BF::gl()->tl_tag('form.error_' . $item->getAttribute('name') . '|' . (isset($property['value']) ? $property['value'] : '') . '|' . ucfirst(isset($fields[$name]['title']) ? $fields[$name]['title'] : (isset($fields[$name]['alt']) ? $fields[$name]['alt'] : $fields[$name]['name'])));
                             }
                             // add all options
                         } elseif ($item->nodeName == 'option') {
                             // add a field option
                             $option = array('text' => '');
                             foreach ($item->childNodes as $child) {
                                 $option['text'] .= $xmlDoc->saveXML($child);
                             }
                             // add all option's attributes
                             foreach ($item->attributes as $attr) {
                                 $option[$attr->nodeName] = $attr->nodeValue;
                             }
                             $fields[$name]['options'][] = $option;
                         }
                     }
                 }
             }
             // save php to file
             if (file_put_contents($compiled->path(), '<?php return ' . var_export($fields, true) . '; ?>') === false) {
                 throw new exception('Failed writing compiled form file, path : ' . $compiled->path());
             }
         }
         // load form fields
         $this->fields = $compiled->load();
     }
 }