Beispiel #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;
 }
Beispiel #2
0
 public function __construct($db, $host = null, $user_not_used = null, $password_not_used = null)
 {
     try {
         $this->pdo = new PDO('sqlite:' . BF::gr($db, $host ? $host : 'DB')->path());
         $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $e) {
         throw new exception('Failed connecting to SQLite3 via PDO : ' . $e->getMessage());
     }
 }
Beispiel #3
0
function smarty_block_js($p, $content, Smarty_Internal_Template $template, &$repeat = false)
{
    // only output on the closing tag
    if (!$repeat) {
        if (isset($p["src"])) {
            return "<script language='javascript' src='" . BF::gr($p['src'], 'js')->url() . "' type='text/javascript'></script>";
        } elseif (isset($content)) {
            return "<script language='javascript' type='text/javascript'>//<![CDATA[\n" . $content . "\n//]]></script>";
        }
    }
}
Beispiel #4
0
function smarty_block_css($p, $content, Smarty_Internal_Template $template, &$repeat)
{
    // only output on the closing tag
    if (!$repeat) {
        if (isset($p["src"])) {
            $html = "<link " . $template->smarty->attr("href", BF::gr($p["src"], 'css')->url()) . " rel='stylesheet' type='text/css'";
            foreach ($p as $key => $val) {
                if ($key == 'src') {
                    continue;
                }
                $html .= $template->smarty->attr($key, $val);
            }
            return $html . " />";
        } elseif (isset($content)) {
            $html = "<style";
            foreach ($p as $key => $val) {
                $html .= $template->smarty->attr($key, $val);
            }
            return $html . ">" . $content . "</style>";
        }
    }
}
Beispiel #5
0
function smarty_function_img($p, Smarty_Internal_Template $template)
{
    // set border to 0 to prevent ugly looking border when image is in an anchor tag
    if (!isset($p["border"])) {
        $p["border"] = '0';
    }
    $src = BF::gr($p["src"], 'img');
    // if image has an hover src
    if (isset($p["hover"])) {
        $hover = BF::gr($p['hover'], 'img');
        $p["onmouseover"] = (isset($p["onmouseover"]) ? $p["onmouseover"] . ";" : "") . "this.src=\"./" . $hover->url() . "\";";
        $p["onmouseout"] = (isset($p["onmouseout"]) ? $p["onmouseout"] . ";" : "") . "this.src=\"./" . $src->url() . "\";";
    }
    $html = "<img" . $template->smarty->attr('src', $src->url()) . $template->smarty->attr('alt', isset($p["alt"]) ? $p["alt"] : null, isset($p["title"]) ? $p["title"] : null);
    foreach ($p as $key => $val) {
        if ($key == 'src' || $key == 'alt' || $key == 'hover') {
            continue;
        }
        $html .= $template->smarty->attr($key, $val);
    }
    return $html . " />";
}
Beispiel #6
0
    }
    BF::load_module("BF_output_template");
    $tpl = new BF_output_template("view_car");
    $tpl->assign('car', $car);
    $tpl->disp();
} elseif ($action == "save") {
    BF::load_module("BF_form");
    $form = new BF_form('edit_car');
    $car = new car($id);
    if (!$car->exists()) {
        throw new BF_not_found();
    }
    // check
    if (!$form->check()) {
        $form->show_error();
    }
    // process
    $car->name = $form->gval("name");
    $car->price = $form->gval("price");
    $car->save();
    // redirect
    BF::gr("example")->redirect();
} else {
    // list all cars from db
    $list = BF::glist('car');
    // display
    BF::load_module("BF_output_template");
    $tpl = new BF_output_template("list_cars");
    $tpl->assign('list', $list);
    $tpl->disp();
}
Beispiel #7
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();
}
Beispiel #8
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);
     }
 }
Beispiel #9
0
function smarty_function_imgurl($p, Smarty_Internal_Template $template)
{
    return BF::gr($p["src"], 'img')->url();
}
Beispiel #10
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;
}
Beispiel #11
0
 /**
  * Load a model from the models folder. The name of the model correspond to the name of the php file, without '.php'
  * @param	string	$model_name : name of the model to load
  * @warning	Will trigger a fatal error if file cannot be found
  * return	bool	true
  */
 public static function load_model($model_name)
 {
     // try to load module (will trigger fatal error if failed)
     try {
         return BF::gr($model_name . ".php", 'model')->load_once();
     } catch (exception $e) {
         throw new exception("Failed loading model : " . $model_name . " (" . $e->getMessage() . ")");
     }
 }
Beispiel #12
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();
     }
 }