function wp_title($sep = '»', $echo = true)
 {
     // If there's a category
     $title = '';
     if (!empty($GLOBALS['cat'])) {
         if (!stristr($GLOBALS['cat'], '-')) {
             // category excluded
             $title = get_the_category_by_ID($GLOBALS['cat']);
         }
     }
     if (!empty($GLOBALS['category_name'])) {
         $categoryHandler =& wp_handler('Category');
         $categoryObject =& $categoryHandler->getByNiceName($GLOBALS['category_name']);
         if ($categoryObject) {
             $title = $categoryObject->getVar('cat_name');
         }
     }
     if (!empty($GLOBALS['monthnum']) && !empty($GLOBALS['year'])) {
         $my_year = $GLOBALS['year'];
         $my_month = $GLOBALS['month'][zeroise($GLOBALS['monthnum'], 2)];
         if (!empty($GLOBALS['day'])) {
             $my_month = zeroise($GLOBALS['monthnum'], 2);
             $my_day = zeroise($GLOBALS['day'], 2);
         }
     } elseif (!empty($GLOBALS['m'])) {
         $my_year = substr($GLOBALS['m'], 0, 4);
         $my_month = $GLOBALS['month'][substr($GLOBALS['m'], 4, 2)];
         if (strlen($GLOBALS['m']) == 6) {
             $my_month = substr($GLOBALS['m'], 4, 2);
             $my_day = substr($GLOBALS['m'], 6, 2);
         }
     }
     if (!empty($my_day)) {
         $title = mysql2date($GLOBALS['dateformat'], $my_year . '-' . $my_month . '-' . $my_day . ' 00:00:00');
     } else {
         if (!empty($my_month)) {
             $title = format_month($my_year, $my_month);
         }
     }
     // If there's a post
     if (!empty($GLOBALS['p']) && intval($GLOBALS['p']) || !empty($GLOBALS['name']) && $GLOBALS['name'] != '') {
         if (empty($GLOBALS['p'])) {
             $criteria = new CriteriaCompo(new Criteria('post_name', $GLOBALS['name']));
             if (!empty($GLOBALS['year'])) {
                 $criteria->add(new Criteria('YEAR(post_date)', intCriteriaVal($GLOBALS['year'])));
             }
             if (!empty($GLOBALS['monthnum'])) {
                 $criteria->add(new Criteria('MONTH(post_date)', intCriteriaVal($GLOBALS['monthnum'])));
             }
             if (!empty($GLOBALS['day'])) {
                 $criteria->add(new Criteria('DAYOFMONTH(post_date)', intCriteriaVal($GLOBALS['day'])));
             }
             $postHandler =& wp_handler('Post');
             $postObjects =& $postHandler->getObjects($criteria);
             if ($postObjects) {
                 $GLOBALS['p'] = $postObjects[0]->getVar('ID');
             }
         }
         if (!empty($GLOBALS['p'])) {
             $post_data = get_postdata($GLOBALS['p']);
             $title = strip_tags($post_data['Title']);
             if (trim($title) == "") {
                 $title = _WP_POST_NOTITLE;
             }
             $title = apply_filters('single_post_title', $title);
         }
     }
     $userObject = false;
     if (!empty($GLOBALS['author_name'])) {
         $userHandler =& wp_handler('User');
         $userObject =& $userHandler->getByLogin($GLOBALS['author_name']);
     } elseif (!empty($GLOBALS['author'])) {
         $userHandler =& wp_handler('User');
         $userObject =& $userHandler->get($GLOBALS['author']);
     } elseif (!empty($GLOBALS['p'])) {
         $postHandler =& wp_handler('Post');
         if ($postObject =& $postHandler->get($GLOBALS['p'])) {
             $userHandler =& wp_handler('User');
             $userObject =& $userHandler->get($postObject->getVar('post_author'));
         }
     }
     if ($userObject) {
         $result = $userObject->exportWpObject();
         $idmode = $result->user_idmode;
         if ($idmode == 'nickname') {
             $id = $result->user_nickname;
         }
         if ($idmode == 'login') {
             $id = $result->user_login;
         }
         if ($idmode == 'firstname') {
             $id = $result->user_firstname;
         }
         if ($idmode == 'lastname') {
             $id = $result->user_lastname;
         }
         if ($idmode == 'namefl') {
             $id = $result->user_firstname . ' ' . $result->user_lastname;
         }
         if ($idmode == 'namelf') {
             $id = $result->user_lastname . ' ' . $result->user_firstname;
         }
         if ($idmode == 'ID') {
             $id = $result->ID;
         }
         if (!$idmode) {
             $id = $result->user_nickname;
         }
         $title .= " by {$id}";
     }
     if (!empty($title)) {
         $title = $sep . $title;
     }
     return _echo($title, $echo);
 }
            $GLOBALS['category_name'] = $GLOBALS['category_name'][count($GLOBALS['category_name']) - 2];
            // there was a trailling slash
        }
    }
    $GLOBALS['category_name'] = preg_replace('|[^a-z0-9-]|', '', $GLOBALS['category_name']);
    $_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id');
    $_joinCriteria->cascade(new XoopsJoinCriteria(wp_table('categories'), 'category_id', 'cat_ID'));
    $_wCriteria =& new CriteriaCompo(new Criteria('category_nicename', $GLOBALS['category_name']));
    $categoryHandler =& wp_handler('Category');
    $categoryObject =& $categoryHandler->getByNiceName($GLOBALS['category_name']);
    if ($categoryObject) {
        $GLOBALS['cat'] = $categoryObject->getVar('cat_ID');
        $_catc = trim(get_category_children($GLOBALS['cat'], '', ' '));
        $_catc_array = explode(' ', $_catc);
        for ($_i = 0; $_i < count($_catc_array); $_i++) {
            $_wCriteria->add(new Criteria('category_id', intCriteriaVal($_catc_array[$_i])), 'OR');
        }
        $_criteria->add($_wCriteria);
        unset($_wCriteria);
    }
}
// author stuff
if (test_param('author') && get_param('author') != 'all') {
    $GLOBALS['author'] = '' . urldecode(get_param('author')) . '';
    if (stristr($GLOBALS['author'], '-')) {
        $_eq = '!=';
        $_andor = 'AND';
        $GLOBALS['author'] = explode('-', $GLOBALS['author']);
        $GLOBALS['author'] = '' . $GLOBALS['author'][1];
    } else {
        $_eq = '=';
 function _b_wp_contents_show($options, $wp_num = "")
 {
     $no_posts = empty($options[0]) ? 10 : $options[0];
     $tpl_file = empty($options[1]) ? 'wp_contents.html' : $options[1];
     $category = empty($options[2]) ? "all" : intval($options[2]);
     $GLOBALS['dateformat'] = get_settings('date_format');
     $GLOBALS['timeformat'] = get_settings('time_format');
     $_criteria = new CriteriaCompo(new Criteria('post_status', 'publish'));
     $_criteria->add(new Criteria('post_date', current_time('mysql'), '<='));
     if (empty($category) || $category == 'all' || $category == '0') {
         $_joinCriteria = null;
     } else {
         $_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id');
         $_wCriteria =& new CriteriaCompo();
         $_wCriteria->add(new Criteria('category_id', intCriteriaVal($category)), 'OR');
         $_catc = trim(get_category_children($category, '', ' '));
         if ($_catc !== "") {
             $_catc_array = explode(' ', $_catc);
             for ($_j = 0; $_j < count($_catc_array); $_j++) {
                 $_wCriteria->add(new Criteria('category_id', intCriteriaVal($_catc_array[$_j])), 'OR');
             }
         }
         $_criteria->add($_wCriteria);
     }
     $_criteria->setGroupBy(wp_table('posts') . '.ID');
     $_criteria->setSort('post_date');
     $_criteria->setOrder('DESC');
     $_criteria->setLimit($no_posts);
     $_criteria->setStart(0);
     $postHandler =& wp_handler('Post');
     $postObjects =& $postHandler->getObjects($_criteria, false, '', 'DISTINCT', $_joinCriteria);
     //		echo $postHandler->getLastSQL();
     $lposts = array();
     foreach ($postObjects as $postObject) {
         $lposts[] =& $postObject->exportWpObject();
     }
     if ($lposts) {
         // Get the categories for all the posts
         $_post_id_list = array();
         foreach ($lposts as $post) {
             $_post_id_list[] = $post->ID;
             $GLOBALS['category_cache'][wp_id()][$post->ID] = array();
         }
         $_post_id_list = implode(',', $_post_id_list);
         $_post_id_criteria =& new Criteria('post_id', '(' . $_post_id_list . ')', 'IN');
         $_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id');
         $_joinCriteria->cascade(new XoopsJoinCriteria(wp_table('categories'), 'category_id', 'cat_ID'));
         $postObjects =& $postHandler->getObjects($_post_id_criteria, false, 'ID, category_id, cat_name, category_nicename, category_description, category_parent', true, $_joinCriteria);
         foreach ($postObjects as $postObject) {
             $_cat->ID = $postObject->getVar('ID');
             $_cat->category_id = $postObject->getExtraVar('category_id');
             $_cat->cat_name = $postObject->getExtraVar('cat_name');
             $_cat->category_nicename = $postObject->getExtraVar('category_nicename');
             $_cat->category_description = $postObject->getExtraVar('category_description');
             $_cat->category_parent = $postObject->getExtraVar('category_parent');
             $GLOBALS['category_cache'][wp_id()][$postObject->getVar('ID')][] =& $_cat;
             unset($_cat);
         }
         // Do the same for comment numbers
         $_post_id_criteria =& new Criteria('comment_post_ID', '(' . $_post_id_list . ')', 'IN');
         $_criteria =& new CriteriaCompo(new Criteria('post_status', 'publish'));
         $_criteria->add(new Criteria('comment_approved', '1 '));
         $_criteria->add($_post_id_criteria);
         $_criteria->setGroupBy('ID');
         $_joinCriteria =& new XoopsJoinCriteria(wp_table('comments'), 'ID', 'comment_post_ID');
         $postObjects =& $postHandler->getObjects($_criteria, false, 'ID, COUNT( comment_ID ) AS ccount', false, $_joinCriteria);
         foreach ($postObjects as $postObject) {
             $GLOBALS['comment_count_cache'][wp_id()]['' . $postObject->getVar('ID')] = $postObject->getExtraVar('ccount');
         }
         // Get post-meta info
         if ($meta_list = $GLOBALS['wpdb']->get_results('SELECT post_id, meta_key, meta_value FROM ' . wp_table('postmeta') . ' WHERE post_id IN(' . $_post_id_list . ') ORDER BY post_id, meta_key', ARRAY_A)) {
             // Change from flat structure to hierarchical:
             $GLOBALS['post_meta_cache'][wp_id()] = array();
             foreach ($meta_list as $metarow) {
                 $mpid = $metarow['post_id'];
                 $mkey = $metarow['meta_key'];
                 $mval = $metarow['meta_value'];
                 // Force subkeys to be array type:
                 if (!isset($GLOBALS['post_meta_cache'][wp_id()][$mpid]) || !is_array($GLOBALS['post_meta_cache'][wp_id()][$mpid])) {
                     $GLOBALS['post_meta_cache'][wp_id()][$mpid] = array();
                 }
                 if (!isset($GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"]) || !is_array($GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"])) {
                     $GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"] = array();
                 }
                 // Add a value to the current pid/key:
                 $GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"][] = $mval;
             }
         }
     }
     $blog = 1;
     $block = array();
     $block['use_theme_template'] = get_xoops_option(wp_mod(), 'use_theme_template');
     $block['style'] = block_style_get(false);
     $block['divid'] = 'wpBlockContent' . $wp_num;
     $block['template_content'] = "";
     $i = 0;
     $GLOBALS['previousday'] = 0;
     foreach ($lposts as $post) {
         $GLOBALS['post'] = $post;
         if ($block['use_theme_template'] == 0) {
             $content = array();
             start_wp();
             $content['date'] = the_date($GLOBALS['dateformat'], '', '', false);
             $content['time'] = the_time('', false);
             $content['title'] = the_title('', '', false);
             $content['permlink'] = get_permalink();
             $content['author'] = the_author_posts_link('', false);
             $content['category'] = the_category('', '', false);
             $content['body'] = the_content(_WP_TPL_MORE, 0, '', false);
             $content['linkpage'] = link_pages('<br />Pages: ', '<br />', 'number', 'next page', 'previous page', '%', '', false);
             if (get_xoops_option(wp_mod(), 'wp_use_xoops_comments') == 0) {
                 $content['comments'] = comments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS, '', 'Comments Off', false);
             } else {
                 $content['comments'] = xcomments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS, '', 'Comments Off', false);
                 $content['comments'] .= " | ";
                 $content['comments'] .= comments_popup_link(_WP_TPL_TRACKBACK0, _WP_TPL_TRACKBACK1, _WP_TPL_TRACKBACKS, '', 'Trackback Off', false);
             }
             $content['trackback'] = trackback_rdf(0, false);
             $block['contents'][] = $content;
         } else {
             ob_start();
             include get_custom_path('content_block-template.php');
             $block['template_content'] .= ob_get_contents();
             ob_end_clean();
         }
     }
     $_wpTpl =& new WordPresTpl('theme');
     $_wpTpl->assign('block', $block);
     if (!$_wpTpl->tpl_exists($tpl_file)) {
         $tpl_file = 'wp_contents.html';
     }
     $block['content'] = $_wpTpl->fetch($tpl_file);
     $GLOBALS['previousday'] = 0;
     $GLOBALS['day'] = 0;
     $GLOBALS['comment_count_cache'][wp_id()] = array();
     return $block;
 }
 function url_to_postid($url = '')
 {
     // Take a link like 'http://example.com/blog/something'
     // and extract just the '/something':
     $uri = preg_replace('#' . wp_siteurl() . '#i', '', $url);
     // on failure, preg_replace just returns the subject string
     // so if $uri and $siteurl are the same, they didn't match:
     if ($uri == wp_siteurl()) {
         return 0;
     }
     // First, check to see if there is a 'p=N' to match against:
     preg_match('#[?&]p=(\\d+)#', $uri, $values);
     $p = intval($values[1]);
     if ($p) {
         return $p;
     }
     // Match $uri against our permalink structure
     $permalink_structure = get_settings('permalink_structure');
     // Matt's tokenizer code
     $rewritecode = array('%year%', '%monthnum%', '%day%', '%postname%', '%post_id%');
     $rewritereplace = array('([0-9]{4})?', '([0-9]{1,2})?', '([0-9]{1,2})?', '([0-9a-z-]+)?', '([0-9]+)?');
     // Turn the structure into a regular expression
     $matchre = str_replace('/', '/?', $permalink_structure);
     $matchre = str_replace($rewritecode, $rewritereplace, $matchre);
     // Extract the key values from the uri:
     preg_match("#{$matchre}#", $uri, $values);
     // Extract the token names from the structure:
     preg_match_all("#%(.+?)%#", $permalink_structure, $tokens);
     for ($i = 0; $i < count($tokens[1]); $i++) {
         $name = $tokens[1][$i];
         $value = $values[$i + 1];
         // Create a variable named $year, $monthnum, $day, $postname, or $post_id:
         ${$name} = $value;
     }
     // If using %post_id%, we're done:
     if (intval($post_id)) {
         return intval($post_id);
     }
     // Otherwise, build a WHERE clause, making the values safe along the way:
     $criteria &= new CriteriaCompo(new Criteria(1, 1));
     if ($year) {
         $criteria->add('YEAR(post_date)', intCriteriaVal($year));
     }
     if ($monthnum) {
         $criteria->add('MONTH(post_date)', intCriteriaVal($monthnum));
     }
     if ($day) {
         $criteria->add('DAYOFMONTH(post_date)', intCriteriaVal($day));
     }
     if ($postname) {
         $criteria->add('post_name', $postname);
     }
     $postHandler =& wp_handler('Post');
     $postObjects =& $postHandler->getObjects($criteria, false, 'ID');
     $id = $postObjects[0]->getVar('ID');
     return $id;
 }