X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Futil.php;h=6f6f1dd249121be3f5ccc34a3ebd539a48a105df;hb=33b04107231823b48ee27ca28b73266c706e105f;hp=7b821e63513d214bb298a26c892b8b108e864673;hpb=121b7e60b491ecc01634d275f6b234f2cb628f01;p=quix0rs-gnu-social.git diff --git a/lib/util.php b/lib/util.php index 7b821e6351..5c5c7179ce 100644 --- a/lib/util.php +++ b/lib/util.php @@ -93,16 +93,25 @@ function common_element_start($tag, $attrs=NULL) { } function common_element_end($tag) { + static $empty_tag = array('base', 'meta', 'link', 'hr', + 'br', 'param', 'img', 'area', + 'input', 'col'); global $xw; - # TODO: switch based on $tag - $xw->fullEndElement(); + # XXX: check namespace + if (in_array($tag, $empty_tag)) { + $xw->endElement(); + } else { + $xw->fullEndElement(); + } } function common_element($tag, $attrs=NULL, $content=NULL) { - common_element_start($tag, $attrs); - global $xw; - $xw->text($content); - common_element_end($tag); + common_element_start($tag, $attrs); + global $xw; + if (!is_null($content)) { + $xw->text($content); + } + common_element_end($tag); } function common_start_xml($doc=NULL, $public=NULL, $system=NULL) { @@ -122,47 +131,46 @@ function common_end_xml() { $xw->flush(); } -define('PAGE_TYPE_PREFS', 'application/xhtml+xml,text/html;q=0.7,application/xml;q=0.3,text/xml;q=0.2'); - -function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=NULL) { - global $config, $xw; - - $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : NULL; - - # XXX: allow content negotiation for RDF, RSS, or XRDS - - $type = common_negotiate_type(common_accept_to_prefs($httpaccept), - common_accept_to_prefs(PAGE_TYPE_PREFS)); - - if (!$type) { - common_user_error(_t('This page is not available in a media type you accept'), 406); - exit(0); +function common_init_language() { + mb_internal_encoding('UTF-8'); + $language = common_language(); + # So we don't have to make people install the gettext locales + putenv('LANGUAGE='.$language); + putenv('LANG='.$language); + $locale_set = setlocale(LC_ALL, $language . ".utf8", + $language . ".UTF8", + $language . ".utf-8", + $language . ".UTF-8", + $language); + bindtextdomain("laconica", common_config('site','locale_path')); + bind_textdomain_codeset("laconica", "UTF-8"); + textdomain("laconica"); + setlocale(LC_CTYPE, 'C'); + if(!$local_set) { + common_log(LOG_INFO,'Language requested:'.$language.' - locale could not be set:',__FILE__); } +} - header('Content-Type: '.$type); - - common_start_xml('html', - '-//W3C//DTD XHTML 1.0 Strict//EN', - 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); - - # FIXME: correct language for interface +define('PAGE_TYPE_PREFS', 'text/html,application/xhtml+xml,application/xml;q=0.3,text/xml;q=0.2'); - common_element_start('html', array('xmlns' => 'http://www.w3.org/1999/xhtml', - 'xml:lang' => 'en', - 'lang' => 'en')); +function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=NULL) { + + global $config, $xw; + common_start_html(); + common_element_start('head'); common_element('title', NULL, $pagetitle . " - " . $config['site']['name']); common_element('link', array('rel' => 'stylesheet', 'type' => 'text/css', - 'href' => theme_path('display.css'), + 'href' => theme_path('display.css') . '?version=' . LACONICA_VERSION, 'media' => 'screen, projection, tv')); foreach (array(6,7) as $ver) { if (file_exists(theme_file('ie'.$ver.'.css'))) { # Yes, IE people should be put in jail. $xw->writeComment('[if lte IE '.$ver.']> common_path('js/jquery.min.js')), ' '); common_element('script', array('type' => 'text/javascript', - 'src' => common_path('js/util.js')), + 'src' => common_path('js/jquery.form.js')), + ' '); + common_element('script', array('type' => 'text/javascript', + 'src' => common_path('js/util.js?version='.LACONICA_VERSION)), ' '); + common_element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml', + 'href' => common_local_url('opensearch', array('type' => 'people')), + 'title' => common_config('site', 'name').' People Search')); + + common_element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml', + 'href' => common_local_url('opensearch', array('type' => 'notice')), + 'title' => common_config('site', 'name').' Notice Search')); if ($callable) { if ($data) { @@ -185,11 +203,11 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall= common_element_start('div', array('id' => 'wrap')); common_element_start('div', array('id' => 'header')); common_nav_menu(); - if ((is_string($config['site']['logo']) && (strlen($config['site']['logo']) > 0)) + if ((isset($config['site']['logo']) && is_string($config['site']['logo']) && (strlen($config['site']['logo']) > 0)) || file_exists(theme_file('logo.png'))) { common_element_start('a', array('href' => common_local_url('public'))); - common_element('img', array('src' => ($config['site']['logo']) ? + common_element('img', array('src' => isset($config['site']['logo']) ? ($config['site']['logo']) : theme_path('logo.png'), 'alt' => $config['site']['name'], 'id' => 'logo')); @@ -214,6 +232,37 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall= common_element_start('div', array('id' => 'content')); } +function common_start_html($type=NULL) { + + if (!$type) { + $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : NULL; + + # XXX: allow content negotiation for RDF, RSS, or XRDS + + $type = common_negotiate_type(common_accept_to_prefs($httpaccept), + common_accept_to_prefs(PAGE_TYPE_PREFS)); + + if (!$type) { + common_user_error(_('This page is not available in a media type you accept'), 406); + exit(0); + } + } + + header('Content-Type: '.$type); + + common_start_xml('html', + '-//W3C//DTD XHTML 1.0 Strict//EN', + 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); + + # FIXME: correct language for interface + + $language = common_language(); + + common_element_start('html', array('xmlns' => 'http://www.w3.org/1999/xhtml', + 'xml:lang' => $language, + 'lang' => $language)); +} + function common_show_footer() { global $xw, $config; common_element_end('div'); # content div @@ -221,15 +270,11 @@ function common_show_footer() { common_element_start('div', array('id' => 'footer')); common_element_start('div', 'laconica'); if (common_config('site', 'broughtby')) { - $instr = _t('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). '); + $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). '); } else { - $instr = _t('**%%site.name%%** is a microblogging service. '); + $instr = _('**%%site.name%%** is a microblogging service. '); } - $instr .= _t('It runs the [Laconica](http://laconi.ca/) ' . - 'microblogging software, version ' . LACONICA_VERSION . ', ' . - 'available under the ' . - '[GNU Affero General Public License]' . - '(http://www.fsf.org/licensing/licenses/agpl-3.0.html).'); + $instr .= sprintf(_('It runs the [Laconica](http://laconi.ca/) microblogging software, version %s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), LACONICA_VERSION); $output = common_markup_to_html($instr); common_raw($output); common_element_end('div'); @@ -237,12 +282,12 @@ function common_show_footer() { 'src' => $config['license']['image'], 'alt' => $config['license']['title'])); common_element_start('p'); - common_text(_t('Unless otherwise specified, contents of this site are copyright by the contributors and available under the ')); + common_text(_('Unless otherwise specified, contents of this site are copyright by the contributors and available under the ')); common_element('a', array('class' => 'license', 'rel' => 'license', - href => $config['license']['url']), + 'href' => $config['license']['url']), $config['license']['title']); - common_text(_t('. Contributors should be attributed by full name or nickname.')); + common_text(_('. Contributors should be attributed by full name or nickname.')); common_element_end('p'); common_element_end('div'); common_element_end('div'); @@ -266,36 +311,41 @@ function common_nav_menu() { common_element_start('ul', array('id' => 'nav')); if ($user) { common_menu_item(common_local_url('all', array('nickname' => $user->nickname)), - _t('Home')); + _('Home')); } - common_menu_item(common_local_url('public'), _t('Public')); - common_menu_item(common_local_url('doc', array('title' => 'help')), - _t('Help')); + common_menu_item(common_local_url('peoplesearch'), _('Search')); + common_menu_item(common_local_url('tags'), _('Tags')); if ($user) { common_menu_item(common_local_url('profilesettings'), - _t('Settings')); + _('Settings')); + common_menu_item(common_local_url('invite'), + _('Invite')); common_menu_item(common_local_url('logout'), - _t('Logout')); + _('Logout')); } else { - common_menu_item(common_local_url('login'), _t('Login')); - common_menu_item(common_local_url('register'), _t('Register')); - common_menu_item(common_local_url('openidlogin'), _t('OpenID')); + common_menu_item(common_local_url('login'), _('Login')); + if (!common_config('site', 'closed')) { + common_menu_item(common_local_url('register'), _('Register')); + } + common_menu_item(common_local_url('openidlogin'), _('OpenID')); } common_element_end('ul'); } function common_foot_menu() { common_element_start('ul', array('id' => 'nav_sub')); + common_menu_item(common_local_url('doc', array('title' => 'help')), + _('Help')); common_menu_item(common_local_url('doc', array('title' => 'about')), - _t('About')); + _('About')); common_menu_item(common_local_url('doc', array('title' => 'faq')), - _t('FAQ')); + _('FAQ')); common_menu_item(common_local_url('doc', array('title' => 'privacy')), - _t('Privacy')); + _('Privacy')); common_menu_item(common_local_url('doc', array('title' => 'source')), - _t('Source')); + _('Source')); common_menu_item(common_local_url('doc', array('title' => 'contact')), - _t('Contact')); + _('Contact')); common_element_end('ul'); } @@ -330,7 +380,7 @@ function common_input($id, $label, $value=NULL,$instructions=NULL) { common_element_end('p'); } -function common_checkbox($id, $label, $checked=false, $instructions=NULL, $value='true') +function common_checkbox($id, $label, $checked=false, $instructions=NULL, $value='true', $disabled=false) { common_element_start('p'); $attrs = array('name' => $id, @@ -343,6 +393,9 @@ function common_checkbox($id, $label, $checked=false, $instructions=NULL, $value if ($checked) { $attrs['checked'] = 'checked'; } + if ($disabled) { + $attrs['disabled'] = 'true'; + } common_element('input', $attrs); # XXX: use a