X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Futil.php;h=7f9b237249dddd0ec4dcbc3ff37996859eaaee75;hb=67921b1c1871e881f71f8f15aa7fc9c2b11da64d;hp=f431c64ecbea74d824d5687f2892bbdfbb9f0a58;hpb=2b842b5e452c71a390a8cd005daad797a88cef55;p=quix0rs-gnu-social.git diff --git a/lib/util.php b/lib/util.php index f431c64ecb..f4245693fb 100644 --- a/lib/util.php +++ b/lib/util.php @@ -93,14 +93,22 @@ 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; - $xw->endElement(); + # 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); + common_element_start($tag, $attrs); + global $xw; if ($content) { - global $xw; $xw->text($content); } common_element_end($tag); @@ -123,10 +131,24 @@ function common_end_xml() { $xw->flush(); } -function common_show_header($pagetitle, $callable=NULL, $data=NULL) { +define('PAGE_TYPE_PREFS', 'text/html,application/xhtml+xml,application/xml;q=0.3,text/xml;q=0.2'); + +function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=NULL) { global $config, $xw; - header('Content-Type: application/xhtml+xml'); + $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', @@ -143,16 +165,23 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL) { $pagetitle . " - " . $config['site']['name']); common_element('link', array('rel' => 'stylesheet', 'type' => 'text/css', - 'href' => common_path('theme/default/style/html.css'), - 'media' => 'screen, projection, tv')); - common_element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => common_path('theme/default/style/layout.css'), + 'href' => theme_path('display.css'), 'media' => 'screen, projection, tv')); - common_element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => common_path('theme/default/style/print.css'), - 'media' => 'print')); + 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.']> 'text/javascript', + 'src' => common_path('js/jquery.min.js')), + ' '); + common_element('script', array('type' => 'text/javascript', + 'src' => common_path('js/util.js')), + ' '); + if ($callable) { if ($data) { call_user_func($callable, $data); @@ -162,23 +191,68 @@ function common_show_header($pagetitle, $callable=NULL, $data=NULL) { } common_element_end('head'); common_element_start('body'); - common_element_start('div', array('id' => 'wrapper')); - common_element_start('div', array('id' => 'content')); + common_element_start('div', array('id' => 'wrap')); common_element_start('div', array('id' => 'header')); - common_element('h1', 'title', $pagetitle); - common_element('h2', 'subtitle', $config['site']['name']); + common_nav_menu(); + if ((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']) ? + ($config['site']['logo']) : theme_path('logo.png'), + 'alt' => $config['site']['name'], + 'id' => 'logo')); + common_element_end('a'); + } else { + common_element_start('p', array('id' => 'branding')); + common_element('a', array('href' => common_local_url('public')), + $config['site']['name']); + common_element_end('p'); + } + + common_element('h1', 'pagetitle', $pagetitle); + + if ($headercall) { + if ($data) { + call_user_func($headercall, $data); + } else { + call_user_func($headercall); + } + } common_element_end('div'); - common_head_menu(); - common_element_start('div', array('id' => 'page')); + common_element_start('div', array('id' => 'content')); } function common_show_footer() { global $xw, $config; - common_element_start('div', 'footer'); + common_element_end('div'); # content div common_foot_menu(); - common_license_block(); - common_element_end('div'); + common_element_start('div', array('id' => 'footer')); + common_element_start('div', 'laconica'); + if (common_config('site', 'broughtby')) { + $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). '); + } else { + $instr = _('**%%site.name%%** is a microblogging service. '); + } + $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'); + common_element('img', array('id' => 'cc', + 'src' => $config['license']['image'], + 'alt' => $config['license']['title'])); + common_element_start('p'); + 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']), + $config['license']['title']); + common_text(_('. Contributors should be attributed by full name or nickname.')); + common_element_end('p'); common_element_end('div'); common_element_end('div'); common_element_end('body'); @@ -196,86 +270,96 @@ function common_raw($xml) { $xw->writeRaw($xml); } -function common_license_block() { - global $config, $xw; - common_element_start('p', 'license greenBg'); - common_element_start('span', 'floatLeft width25'); - common_element_start('a', array('class' => 'license', - 'rel' => 'license', - href => $config['license']['url'])); - common_element('img', array('class' => 'license', - 'src' => $config['license']['image'], - 'alt' => $config['license']['title'])); - common_element_end('a'); - common_element_end('span'); - common_element_start('span', 'floatRight width75'); - common_text(_t('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']), - $config['license']['title']); - common_text(_t('. Contributors should be attributed by full name or nickname.')); - common_element_end('span'); - common_element_end('p'); -} - -function common_head_menu() { +function common_nav_menu() { $user = common_current_user(); - common_element_start('ul', array('id' => 'menu', 'class' => ($user) ? 'five' : 'three')); + common_element_start('ul', array('id' => 'nav')); + if ($user) { + common_menu_item(common_local_url('all', array('nickname' => $user->nickname)), + _('Home')); + } common_menu_item(common_local_url('public'), _t('Public')); + common_menu_item(common_local_url('doc', array('title' => 'help')), + _('Help')); if ($user) { - common_menu_item(common_local_url('all', array('nickname' => - $user->nickname)), - _t('Home')); - common_menu_item(common_local_url('showstream', array('nickname' => - $user->nickname)), - _t('Profile'), $user->fullname || $user->nickname); common_menu_item(common_local_url('profilesettings'), - _t('Settings')); + _('Settings')); 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('login'), _('Login')); + 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', 'footmenu menuish'); + common_element_start('ul', array('id' => 'nav_sub')); common_menu_item(common_local_url('doc', array('title' => 'about')), - _t('About')); - common_menu_item(common_local_url('doc', array('title' => 'help')), - _t('Help')); + _('About')); + common_menu_item(common_local_url('doc', array('title' => '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')), + _('Contact')); common_element_end('ul'); } -function common_menu_item($url, $text, $title=NULL) { +function common_menu_item($url, $text, $title=NULL, $is_selected=false) { + $lattrs = array(); + if ($is_selected) { + $lattrs['class'] = 'current'; + } + common_element_start('li', $lattrs); $attrs['href'] = $url; if ($title) { $attrs['title'] = $title; } - common_element_start('li', 'menuitem'); common_element('a', $attrs, $text); common_element_end('li'); } -function common_input($id, $label, $value=NULL) { +function common_input($id, $label, $value=NULL,$instructions=NULL) { common_element_start('p'); common_element('label', array('for' => $id), $label); $attrs = array('name' => $id, 'type' => 'text', + 'class' => 'input_text', + 'id' => $id); + if ($value) { + $attrs['value'] = htmlspecialchars($value); + } + common_element('input', $attrs); + if ($instructions) { + common_element('span', 'input_instructions', $instructions); + } + common_element_end('p'); +} + +function common_checkbox($id, $label, $checked=false, $instructions=NULL, $value='true') +{ + common_element_start('p'); + $attrs = array('name' => $id, + 'type' => 'checkbox', + 'class' => 'checkbox', 'id' => $id); if ($value) { $attrs['value'] = htmlspecialchars($value); } + if ($checked) { + $attrs['checked'] = 'checked'; + } common_element('input', $attrs); + # XXX: use a