function smarty_block_form($p, $content, Smarty_Internal_Template $template, &$repeat = false) { // only output on the closing tag if (!$repeat) { $smarty = $template->smarty; // look up form data BF::load_module('BF_form'); $form = gform(isset($smarty->_tag_stack[0][1]['data']) ? $smarty->_tag_stack[0][1]['data'] : null); if (!isset($p['method'])) { $p['method'] = $form->method; } if (!isset($p['id']) && isset($p['name'])) { $p['id'] = $p['name']; } if (!isset($p['enctype']) && $form->enctype) { $p['enctype'] = $form->enctype; } // if enctype is 'file' alias if (isset($p['enctype']) && $p['enctype'] == 'file') { $p['enctype'] = "multipart/form-data"; } // set url $html = "<form" . $smarty->attr('action', $smarty->make_url(isset($p["href"]) ? $p["href"] : false, isset($p["locale"]) ? $p["locale"] : null)); foreach ($p as $key => $val) { if ($key == 'action' || $key == 'data') { continue; } $html .= $smarty->attr($key, $val); } return $html . ">" . $content . "</form>"; } }
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; }
/** * Contructor * @param string $class : Name of model of objects to be listed * @param string $condition [optional default NULL] : SQL query condition * @param string $extra [optional default NULL] : append some commands at the end of the SQL query (such as ORDER BY, LIMIT) * @param array $extra_fields [optional default NULL] : Array of fields to get from DB that are not listed in data model. You may use names in the form : "tablealias.field as field", table name's will then be converted to real tables' names as defined in config file */ public function __construct($class, $condition = null, $extra = null, $extra_fields = null) { $this->db = BF::gdb($class::$db); $this->class = $class; // fields to load if (!is_array($class::$default_fields)) { // all fields $fields = "*"; } else { $fields_array = $class::$default_fields; if (is_array($extra_fields)) { $fields_array = array_unique(array_merge($fields_array, $extra_fields)); } $fields = implode(', ', $fields_array); } // built query $query_str = "SELECT " . $fields . " FROM " . $class::$table; if ($condition != NULL) { $query_str .= " WHERE " . $condition; } if ($extra != NULL) { $query_str .= " " . $extra; } // perfom query $this->resource = $this->db->query($query_str); }
function smarty_function_protect($params, Smarty_Internal_Template $template) { if (isset($params['access'])) { $template->smarty->data['access'] = $params['access']; if (!BF::ga($template->smarty->data['access'])) { throw new BF_forbidden(); } } }
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()); } }
/** * Function to quote a variable into a string. Depending on flags, quotes (double by default) will be added * @param int/string $flags [optional default Q_ALL] : * IF flag is a string : SQL quoting for given class name (based on what is required from database used) * IF flag is int : * For value === NULL or value === '' * - if Q_NULL => 'null' * - if Q_STRING => '""' * - if Q_INT or Q_FLOAT => '0' * - if Q_BOOL => 'false' * For value === TRUE / FALSE * - if Q_BOOL => 'true' / 'false' * - if Q_INT or Q_FLOAT => '1' / '0' * - if Q_STRING => '"1"' / '""' * For value is an INT (123) * - if Q_INT => '123' * - if Q_STRING => '"123"' * - if Q_BOOL => 'true' (if int!=0) / 'false' (if int==0) * For value is a FLOAT (12.3) * - if Q_FLOAT => '12.3' * else round and act like an INT * For value is a string not empty ('abc') * - if Q_STRING => '"abc"' * - if Q_INT or Q_FLOAT => cast to numeric and act as an int/float * - if Q_BOOL => 'true' * For value is array or object : * - if Q_ARRAY => print_r array/object and act as string * * Q_FLOAT implies Q_INT * Q_ESCAPE_HTML : Escape quotes and all other html entities into their HTML code (see htmlspecialchars on php doc) * Q_JSON_WRAPER : Wrap variables in JSON structure (ie. {} or [] if array, normal quotes otherwise) * Q_JSON : Format in JSON style. Implies Q_ALL, Q_ARRAY and Q_JSON_WRAPER * Q_HTML will set Q_STRING and Q_HTML_ESCAPE * Q_ALL will set Q_NULL, Q_FLOAT, Q_BOOL and Q_STRING (for use in sql queries) but NOT Q_ARRAY * Q_SINGLE will set quoting with single quotes instead of double quotes * If could not be determined, or only Q_NULL is set, fatal error is thrown */ function Q($value, $flags = Q_ALL) { if (is_string($flags)) { return BF::gdb($flags::$db)->Q($value); } if ($flags <= Q_NULL) { throw new exception('Invalid flag passed to Q'); } // array and objects if (is_object($value)) { return Q((array) $value, $flags); } if (is_array($value)) { if ($flags & Q_ARRAY && $flags & Q_JSON_WRAPER) { $parts = array(); //Find out if the given array is a numerical array $is_list = 0 !== array_reduce(array_keys($value), 'Q_callbackReduceNotAssociativeArray', 0); foreach ($value as $key => $val) { $parts[] = ($is_list ? '' : '"' . $key . '":') . Q($val, $flags); } return str_replace(array("\n", "\t"), array("\\n", "\\t"), $is_list ? '[' . implode(',', $parts) . ']' : '{' . implode(',', $parts) . '}'); } elseif ($flags & Q_ARRAY) { $value = print_r($value, true); } else { throw new exception('Calling quote on an array or object without Q_ARRAY flag set'); } } if ($value === NULL || $value === '') { if ($flags & Q_NULL) { return 'null'; } elseif ($flags & Q_STRING) { $value = ''; } elseif ($flags & Q_INT) { return '0'; } elseif ($flags & Q_BOOL) { return 'false'; } else { throw new exception('Invalid flags passed to Q()'); } } elseif ($value === TRUE || $value === FALSE || !($flags & Q_INT) && !($flags & Q_STRING)) { if ($flags & Q_BOOL) { return $value ? 'true' : 'false'; } elseif ($flags & Q_INT) { return $value ? '1' : '0'; } elseif ($flags & Q_STRING) { $value = $value ? '1' : '0'; } else { throw new exception('Invalid flags passed to Q()'); } } elseif ((is_int($value) || is_float($value) || !($flags & Q_STRING)) && $flags & Q_INT) { return $flags & Q_FLOAT ? (string) (double) $value : (string) (int) $value; } elseif (!($flags & Q_STRING)) { throw new exception('Invalid flags passed to Q()'); } return ($flags & Q_SINGLE ? '\'' : '"') . ($flags & Q_ESCAPE_HTML ? htmlspecialchars($value, $flags & Q_SINGLE ? ENT_QUOTES : ENT_COMPAT, BF::$encoding) : addslashes($value)) . ($flags & Q_SINGLE ? '\'' : '"'); }
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>"; } } }
public static function check($password) { if (isset($_SESSION["_simple_password_md5"]) && $_SESSION["_simple_password_md5"] == md5($password)) { return true; } if (isset($_POST["_simple_password"]) && md5($_POST["_simple_password"]) == md5($password)) { $_SESSION["_simple_password_md5"] = md5($_POST["_simple_password"]); return true; } BF::load_module("BF_output_template"); $tpl = new BF_output_template("simple_password"); $tpl->disp(); die; }
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 . " />"; }
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>"; } } }
<?php /** * 箱庭諸島 S.E - BattleField管理用ファイル - * @copyright 箱庭諸島 ver2.30 * @since 箱庭諸島 S.E ver23_r09 by SERA * @author hiro <@hiro0218> */ require_once 'config.php'; require_once MODELPATH . '/admin.php'; require_once MODELPATH . '/hako-cgi.php'; require_once MODELPATH . '/hako-file.php'; require_once PRESENTER . '/hako-html.php'; require_once CONTROLLERPATH . '/admin/bf.php'; $init = new Init(); $start = new BF(); $start->execute();
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'); } }
/*-------------------------------------------------------*\ | PHP BasicFramework - Ready to use PHP site framework | | License: LGPL, see LICENSE | \*-------------------------------------------------------*/ /** * Database module * @file BF_DB_inerface.php * @package PhpBF * @subpackage database * @version 0.7 * @author Loic Minghetti * @date Started on the 2008-01-09 * @comment These classes were originaly placed in framework.php and later generic.php */ BF::load_module("BF_DB_interface"); abstract class BF_DB implements BF_DB_interface { public function get_query($query) { $result = $this->query($query); $rows = array(); while ($row = $this->fetch_array($result)) { $rows[] = $row; } return $rows; } public function get_first($query) { $result = $this->get_query($query); if (count($result) == 0) {
function __construct() { BF::register_error_output_callback(array($this, "show_error")); }
print ' If you see no error above, then include was ' . test::ok("successful") . ' <h3>Initializing framework</h3>'; BF::init(); print ' If you see no error above, then initialization was ' . test::ok("successful") . ' <h3>Database connexions</h3>'; if (count(test::dbconnections()) > 0) { print '<table cellspacing="0" cellpadding="5" class="tests"><tr>'; foreach (test::dbconnections() as $id => $data) { $error = false; try { BF::load_module("database"); BF::load_module("database." . $data[0]); $class = "BF_DB_" . $data[0]; if (!call_user_func(array($class, "supported"))) { throw new exception($data[0] . " is not supported by your PHP server"); } $db = BF::gdb($id); } catch (exception $e) { $error = $e->getMessage(); } print ' <tr> <td class="title"><b>ID: ' . $id . '</b> (' . implode(", ", $data) . ')</td> <td>' . ($error ? test::invalid($error) : test::ok()) . '</td> </tr>'; } print '</table>'; } else { print ' ' . test::ok("None"); } }
<?php /*-------------------------------------------------------*\ | PhpBF | | License: LGPL, see LICENSE | \*-------------------------------------------------------*/ /** * MySQL DB module * @file BF_DB_mysql.php * @package PhpBF * @subpackage database_mysql * @version 0.7 * @author Loic Minghetti * @date Started on the 2007-08-18 */ BF::load_module("BF_DB"); /** * Class to access mysql database */ class BF_DB_mysql extends BF_DB { private $link; private $last_result; public $num_queries = 0; public function __construct($db, $host = null, $user = null, $password = null) { $this->link = @mysql_pconnect($host, $user, $password); if ($this->link) { if (!@mysql_select_db($db)) { @mysql_close($this->link); $this->link = NULL;
/** * 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; } } }
<?php /** * @file car.php */ BF::load_module('BF_record'); class car extends BF_record { public static $table = "car"; public static $id_field = "id"; public static $default_fields = array("id", "name", "price"); public static $db = "database"; }
/** * Reset user password and send by email */ public function send_password() { /** * Example */ BF::load_module('BF_mail'); BF::load_module("BF_output_template"); $tpl = new BF_output_template('mail_user_password'); $user =& $this; $tpl->assign('user', $user); $tpl->assign('password', $this->reset_password()); $mail = new BF_mail(); $mail->From = BF::gu()->_email; $mail->FromName = BF::gu()->_username; $mail->AddReplyTo($mail->From, $mail->FromName); $mail->AddAddress($this->_email); $mail->Body = $tpl->disp(false); $mail->Subject = $tpl->get_template_vars('subject'); if ($mail->send()) { return true; } else { throw new exception('Failed sending password mail'); } }
function smarty_function_imgurl($p, Smarty_Internal_Template $template) { return BF::gr($p["src"], 'img')->url(); }
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; }
} 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(); }
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; } }
function smarty_prefilter_translate($source, Smarty_Internal_Template $template) { return BF::gl()->tl($source); }
/** * 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); } }
/** * Contructor * @param string $class : Name of the table holding the object's data * @param int $id [optional default NULL] : Identifier of the element * @param mixed $fields [optional default NULL] : List of fields to load, or FALSE for default as defined in class, NULL for all fields, or string (eg. "*") * @return void */ public function __construct($id = NULL, $fields = false) { $class = get_class($this); $this->_class = $class; if (BF::gdb($class::$db) != null) { $this->_db = BF::gdb($class::$db); } else { $this->_db = null; } $this->_fields = $fields === false ? $class::$default_fields : $fields; $this->_id = $id; }
/** * 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']); }