isLogged(); function tpl_assign($key, $value=null) { if (is_array($key)) { foreach ($key as $k=>$v) { $GLOBALS['tpl_vars'][$k] = $v; } } else { $GLOBALS['tpl_vars'][$key] = $value; } } function tpl_error($key, $msg) { $GLOBALS['tpl_error_messages'][$key] = $msg; } function form_error($key) { $GLOBALS['form_errors'][$key] = true; } function form_has_errors() { if (empty($GLOBALS['form_errors'])) return false; else return true; } function get_form_errors() { $out = array(); if (!form_has_errors()) return $out; foreach ($GLOBALS['form_errors'] as $key=>$v) { if (array_key_exists($key, $GLOBALS['tpl_error_messages'])) $out[] = $GLOBALS['tpl_error_messages'][$key]; else $out[] = $key; } return $out; } function show_form_errors() { if (form_has_errors()) { echo ' '; } } function inc($tpl) { if (!preg_match(TEMPLATE_NAME_REGEXP, $tpl)) { throw new nkTemplateException('Invalid template filename in include (allowed: [a-zA-Z0-9_-]): '.(string)$tpl); } global $nk; extract($GLOBALS['tpl_vars'], EXTR_SKIP | EXTR_REFS); if (!file_exists(TEMPLATES_PATH . '/' . (string)$tpl .'.php')) { throw new nkTemplateException('Unable to find template filename '.$tpl); } require TEMPLATES_PATH . '/' . (string)$tpl .'.php'; } function display_toolbar($show_login_link=false) { $nk = nanoKubbe::instance(); $u = utils::getBaseUrl(); if (!$nk->isLogged()) { echo 'Connexion'; } else { echo ' '; } } function escape($string, $method='html', $charset='UTF-8') { // Allows to do multiple escapes in one call if (strpos($method, ',')) { $methods = explode(',', $method); foreach ($methods as $method) { $string = escape($string, trim($method), $charset); } return $string; } switch ($method) { case 'html': if (version_compare(PHP_VERSION, '5.2.3') === 1) { return htmlspecialchars($string, ENT_QUOTES, $charset, false); } else { $string = htmlspecialchars($string, ENT_QUOTES, $charset); return strtr($string, array('&amp;' => '&', '&#' => '&#')); } case 'htmlall': case 'entities': if (version_compare(PHP_VERSION, '5.2.3') === 1) { return htmlentities($string, ENT_QUOTES, $charset, false); } else { $string = htmlentities($string, ENT_QUOTES, $charset, false); return strtr($string, array('&amp;' => '&', '&#' => '&#')); } case 'js': case 'javascript': // escape quotes and backslashes, newlines, etc. return strtr($string, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n',''<\/')); case 'mail': return str_replace('@', '@', $string); case 'url': return rawurlencode($string); default: throw new jTpl_Template_Exception("Unknown method for escape: ".$method, jTpl_Template_Exception::IN_MODIFIER); } } function date_format_fr($ts, $format=false) { if (!isset($GLOBALS['french_date_replace'])) { $GLOBALS['french_date_replace'] = array( "January"=>"Janvier", "February"=>"Février", "March"=>"Mars", "April"=>"Avril", "May"=>"Mai", "June"=>"Juin", "July"=>"Juillet", "August"=>"Août", "September"=>"Septembre", "October"=>"Octobre", "November"=>"Novembre", "December"=>"Décembre", "Monday"=>"Lundi", "Tuesday"=>"Mardi", "Wednesday"=>"Mercredi", "Thursday"=>"Jeudi","Friday"=>"Vendredi","Saturday"=>"Samedi","Sunday"=>"Dimanche", "Feb"=>"Fév","Apr"=>"Avr","May"=>"Mai","Jun"=>"Juin", "Jul"=>"Juil","Aug"=>"Aout","Dec"=>"Déc", "Mon"=>"Lun","Tue"=>"Mar","Wed"=>"Mer","Thu"=>"Jeu","Fri"=>"Ven","Sat"=>"Sam","Sun"=>"Dim" ); } if (!$format) $format = '%d/%m/%Y à %H:%M'; $date = strftime($format, $ts); $date = strtr($date, $GLOBALS['french_date_replace']); $date = strtolower($date); return $date; } function links_on_urls($str) { preg_match_all('(^|[\s>])((ftp|http|https)://([^\s<]+))u', $str, $match, PREG_SET_ORDER); foreach ($match as &$m) { $text = ($m[3] == 'http') ? $m[4] : $m[2]; $text = isset($text[51]) ? substr($text, 0, 50) . '...' : $text; $str = str_replace($m[0], $m[1].''.$text.'', $str); } return $str; } function garbage2xhtml($content) { require_once BASE_PATH . '/include/garbage2xhtml/class.garbage2xhtml.php'; global $nk; $g2x = new Garbage2xhtml(); $g2x->allowed_tags = $nk->allowed_html; $g2x->remove_forbidden_tags = false; $content = $g2x->Process($content); unset($g2x); return $content; } function block_format($content) { require_once BASE_PATH . '/include/garbage2xhtml/class.blockformat.php'; // Make paragraphs $block_format = new BlockFormat(); $content = $block_format->Process($content); return $content; } function apply_content_plugins($content) { preg_match_all('!\{([^\s\}]+)\s*([^\}]*)\}!', $content, $plugins, PREG_SET_ORDER); foreach ($plugins as $plugin) { $name = strtolower(trim($plugin[1])); $params = parsePluginParams($plugin[2]); if (!is_array($params)) { $plugin_out = '

Error in arguments of plugin '.$name.' : '.$params.'

'; } elseif (!file_exists(BASE_PATH . '/datas/plugins/function.' . $name . '.php')) { $plugin_out = '

There is no plugin named '.$name.'

'; } else { require_once BASE_PATH . '/datas/plugins/function.' . $name . '.php'; $function_name = 'tpl_function_'.$name; $plugin_out = $function_name($params, &$tpl, &$content); } $content = str_replace($plugin[0], $plugin_out, $content); } unset($plugins); return $content; } function html_diff($old, $new) { require_once BASE_PATH . '/include/diff/class.simplediff.php'; $diff = simpleDiff::diff_to_array(false, $old, $new, 1); $out = ''; $prev = key($diff); foreach ($diff as $i=>$line) { if ($i > $prev + 1) { $out .= ''; } list($type, $old, $new) = $line; $class1 = $class2 = ''; $t1 = $t2 = ''; if ($type == simpleDiff::INS) { $class2 = 'ins'; $t2 = '+'; } elseif ($type == simpleDiff::DEL) { $class1 = 'del'; $t1 = '-'; } elseif ($type == simpleDiff::CHANGED) { $class1 = 'del'; $class2 = 'ins'; $t1 = '-'; $t2 = '+'; $lineDiff = simpleDiff::wdiff($old, $new); // Don't show new things in deleted line $old = preg_replace('!\{\+(?:.*)\+\}!U', '', $lineDiff); $old = str_replace(' ', ' ', $old); $old = str_replace('-] [-', ' ', $old); $old = preg_replace('!\[-(.*)-\]!U', '\\1', $old); // Don't show old things in added line $new = preg_replace('!\[-(?:.*)-\]!U', '', $lineDiff); $new = str_replace(' ', ' ', $new); $new = str_replace('+} {+', ' ', $new); $new = preg_replace('!\{\+(.*)\+\}!U', '\\1', $new); } $out .= ''; $out .= ''; $out .= ''; $out .= ''; $out .= ''; $out .= ''; $out .= ''; $prev = $i; } $out .= '

'.($i+1).''.$t1.''.$old.''.$t2.''.$new.'
'; return $out; } ?>