function get_subscribed_topic_func()
{
    global $config, $db, $user, $auth, $mobiquo_config;
    // Only registered users can go beyond this point
    if (!$user->data['is_registered']) {
        return get_error(9);
    }
    $topic_list = array();
    if ($config['allow_topic_notify']) {
        $forbidden_forums = $auth->acl_getf('!f_read', true);
        $forbidden_forums = array_unique(array_keys($forbidden_forums));
        if (isset($mobiquo_config['hide_forum_id'])) {
            $forbidden_forums = array_unique(array_merge($forbidden_forums, $mobiquo_config['hide_forum_id']));
        }
        $sql_array = array('SELECT' => 't.*, 
                            f.forum_name,
                            u.user_avatar,
                            u.user_avatar_type', 'FROM' => array(TOPICS_WATCH_TABLE => 'tw', TOPICS_TABLE => 't', USERS_TABLE => 'u'), 'WHERE' => 'tw.user_id = ' . $user->data['user_id'] . '
                AND t.topic_id = tw.topic_id
                AND u.user_id = t.topic_last_poster_id
                AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true), 'ORDER_BY' => 't.topic_last_post_time DESC');
        $sql_array['LEFT_JOIN'] = array();
        $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id');
        if ($config['allow_bookmarks']) {
            $sql_array['SELECT'] .= ', bm.topic_id as bookmarked';
            $sql_array['LEFT_JOIN'][] = array('FROM' => array(BOOKMARKS_TABLE => 'bm'), 'ON' => 'bm.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = bm.topic_id');
        }
        $sql = $db->sql_build_query('SELECT', $sql_array);
        $result = $db->sql_query_limit($sql, 20);
        $topic_list = array();
        while ($row = $db->sql_fetchrow($result)) {
            $forum_id = $row['forum_id'];
            $topic_id = isset($row['b_topic_id']) ? $row['b_topic_id'] : $row['topic_id'];
            // Replies
            $replies = $auth->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies'];
            if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id'])) {
                $topic_id = $row['topic_moved_id'];
            }
            // Get folder img, topic status/type related information
            $folder_img = $folder_alt = $topic_type = '';
            topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
            $short_content = get_short_content($row['topic_last_post_id']);
            if ($forum_id) {
                $topic_tracking = get_complete_topic_tracking($forum_id, $topic_id);
                $new_post = $topic_tracking[$topic_id] < $row['topic_last_post_time'] ? true : false;
            } else {
                $new_post = false;
            }
            $user_avatar_url = get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']);
            $allow_change_type = $auth->acl_get('m_', $forum_id) || $user->data['is_registered'] && $user->data['user_id'] == $row['topic_poster'] ? true : false;
            $xmlrpc_topic = new xmlrpcval(array('forum_id' => new xmlrpcval($forum_id), 'forum_name' => new xmlrpcval(html_entity_decode($row['forum_name']), 'base64'), 'topic_id' => new xmlrpcval($topic_id), 'topic_title' => new xmlrpcval(html_entity_decode(strip_tags(censor_text($row['topic_title']))), 'base64'), 'reply_number' => new xmlrpcval(intval($replies), 'int'), 'view_number' => new xmlrpcval(intval($row['topic_views']), 'int'), 'short_content' => new xmlrpcval($short_content, 'base64'), 'post_author_id' => new xmlrpcval($row['topic_last_poster_id']), 'post_author_name' => new xmlrpcval(html_entity_decode($row['topic_last_poster_name']), 'base64'), 'new_post' => new xmlrpcval($new_post, 'boolean'), 'post_time' => new xmlrpcval(mobiquo_iso8601_encode($row['topic_last_post_time']), 'dateTime.iso8601'), 'icon_url' => new xmlrpcval($user_avatar_url), 'can_delete' => new xmlrpcval($auth->acl_get('m_delete', $forum_id), 'boolean'), 'can_bookmark' => new xmlrpcval($user->data['is_registered'] && $config['allow_bookmarks'], 'boolean'), 'isbookmarked' => new xmlrpcval($row['bookmarked'] ? true : false, 'boolean'), 'can_close' => new xmlrpcval($auth->acl_get('m_lock', $forum_id) || $auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $row['topic_poster'], 'boolean'), 'is_closed' => new xmlrpcval($row['topic_status'] == ITEM_LOCKED, 'boolean'), 'can_stick' => new xmlrpcval($allow_change_type && $auth->acl_get('f_sticky', $forum_id) && $row['topic_type'] != POST_STICKY, 'boolean')), 'struct');
            $topic_list[] = $xmlrpc_topic;
        }
        $db->sql_freeresult($result);
    }
    $topic_num = count($topic_list);
    $response = new xmlrpcval(array('total_topic_num' => new xmlrpcval($topic_num, 'int'), 'topics' => new xmlrpcval($topic_list, 'array')), 'struct');
    return new xmlrpcresp($response);
}
function login_func($xmlrpc_params)
{
    global $auth, $user, $config, $db, $phpbb_root_path, $phpEx;
    $params = php_xmlrpc_decode($xmlrpc_params);
    $user->setup('ucp');
    $username = $params[0];
    $password = $params[1];
    $viewonline = isset($params[2]) ? !$params[2] : 1;
    set_var($username, $username, 'string', true);
    set_var($password, $password, 'string', true);
    header('Set-Cookie: mobiquo_a=0');
    header('Set-Cookie: mobiquo_b=0');
    header('Set-Cookie: mobiquo_c=0');
    $login_result = $auth->login($username, $password, true, $viewonline);
    $usergroup_id = array();
    if ($login_result['status'] == LOGIN_SUCCESS) {
        $auth->acl($user->data);
        //add tapatalk_users here,for push service
        if ($params[3] == '1' && push_table_exists()) {
            global $table_prefix;
            $sql = "SELECT * FROM " . $table_prefix . "tapatalk_users where userid = '" . $user->data['user_id'] . "'";
            $result = $db->sql_query($sql);
            $userInfo = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            $time = time();
            if (empty($userInfo)) {
                $sql_data[$table_prefix . "tapatalk_users"]['sql'] = array('userid' => $user->data['user_id'], 'announcement' => 1, 'pm' => 1, 'subscribe' => 1, 'quote' => 1, 'tag' => 1, 'newtopic' => 1, 'updated' => time());
                $sql = 'INSERT INTO ' . $table_prefix . "tapatalk_users" . ' ' . $db->sql_build_array('INSERT', $sql_data[$table_prefix . "tapatalk_users"]['sql']);
                $db->sql_query($sql);
            } else {
                $sql = "UPDATE " . $table_prefix . "tapatalk_users \n\t        \tSET updated= '" . time() . "' WHERE userid='" . $user->data['user_id'] . "'";
                $db->sql_query($sql);
            }
        }
        // Compatibility with mod NV who was here
        if (file_exists($phpbb_root_path . 'includes/mods/who_was_here.' . $phpEx)) {
            include_once $phpbb_root_path . 'includes/mods/who_was_here.' . $phpEx;
            if (class_exists('phpbb_mods_who_was_here') && method_exists('phpbb_mods_who_was_here', 'update_session')) {
                @phpbb_mods_who_was_here::update_session();
            }
        }
    } else {
        $error_msg = str_replace('%s', '', strip_tags($user->lang[$login_result['error_msg']]));
        return new xmlrpcresp(new xmlrpcval(array('result' => new xmlrpcval(false, 'boolean'), 'result_text' => new xmlrpcval($error_msg, 'base64')), 'struct'));
    }
    if ($config['max_attachments'] == 0) {
        $config['max_attachments'] = 100;
    }
    $usergroup_id[] = new xmlrpcval($user->data['group_id']);
    $can_readpm = $config['allow_privmsg'] && $auth->acl_get('u_readpm') && ($user->data['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'));
    $can_sendpm = $config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($user->data['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'));
    $can_upload = $config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && (function_exists('phpbb_is_writable') ? phpbb_is_writable($phpbb_root_path . $config['avatar_path']) : 1) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false;
    $can_search = $auth->acl_get('u_search') && $auth->acl_getf_global('f_search') && $config['load_search'];
    $can_whosonline = $auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel');
    $max_filesize = $config['max_filesize'] === '0' || $config['max_filesize'] > 10485760 ? 10485760 : $config['max_filesize'];
    $response = new xmlrpcval(array('result' => new xmlrpcval(true, 'boolean'), 'user_id' => new xmlrpcval($user->data['user_id'], 'string'), 'username' => new xmlrpcval($user->data['username'], 'base64'), 'usergroup_id' => new xmlrpcval($usergroup_id, 'array'), 'icon_url' => new xmlrpcval(get_user_avatar_url($user->data['user_avatar'], $user->data['user_avatar_type']), 'string'), 'post_count' => new xmlrpcval($user->data['user_posts'], 'int'), 'can_pm' => new xmlrpcval($can_readpm, 'boolean'), 'can_send_pm' => new xmlrpcval($can_sendpm, 'boolean'), 'can_moderate' => new xmlrpcval($auth->acl_get('m_') || $auth->acl_getf_global('m_'), 'boolean'), 'max_attachment' => new xmlrpcval($config['max_attachments'], 'int'), 'max_png_size' => new xmlrpcval($max_filesize, 'int'), 'max_jpg_size' => new xmlrpcval($max_filesize, 'int'), 'can_search' => new xmlrpcval($can_search, 'boolean'), 'can_whosonline' => new xmlrpcval($can_whosonline, 'boolean'), 'can_upload_avatar' => new xmlrpcval($can_upload, 'boolean')), 'struct');
    return new xmlrpcresp($response);
}
function search_user_func()
{
    global $user, $config, $auth, $db, $phpbb_root_path;
    // Start session management
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup(array('memberlist', 'groups'));
    if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel')) {
        if ($user->data['user_id'] != ANONYMOUS) {
            trigger_error('NO_VIEW_USERS');
        }
        trigger_error('LOGIN_EXPLAIN_MEMBERLIST');
    }
    if ($config['load_search'] || $auth->acl_get('a_')) {
        $username = request_var('username', '', true);
        $email = strtolower(request_var('email', ''));
        $sql_where .= $username ? ' AND u.username_clean ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($username))) : '';
        $sql_where .= $auth->acl_get('a_user') && $email ? ' OR u.user_email ' . $db->sql_like_expression(str_replace('*', $db->any_char, $email)) . ' ' : '';
    } else {
        trigger_error('NO_VIEW_USERS');
    }
    $page = request_var('page', 1);
    $per_page = request_var('perpage', 20);
    $start = ($page - 1) * $per_page;
    $default_key = 'c';
    $sort_key = request_var('sk', $default_key);
    $sort_dir = request_var('sd', 'a');
    $sort_key_sql = array('a' => 'u.username_clean', 'b' => 'u.user_from', 'c' => 'u.user_regdate', 'd' => 'u.user_posts', 'f' => 'u.user_website', 'g' => 'u.user_icq', 'h' => 'u.user_aim', 'i' => 'u.user_msnm', 'j' => 'u.user_yim', 'k' => 'u.user_jabber');
    // Sorting and order
    if (!isset($sort_key_sql[$sort_key])) {
        $sort_key = $default_key;
    }
    $order_by .= $sort_key_sql[$sort_key] . ' ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
    // Unfortunately we must do this here for sorting by rank, else the sort order is applied wrongly
    if ($sort_key == 'm') {
        $order_by .= ', u.user_posts DESC';
    }
    // Count the users ...
    if ($sql_where) {
        $sql = 'SELECT COUNT(u.user_id) AS total_users
			FROM ' . USERS_TABLE . " u\r\r\n\t\t\tWHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")\r\r\n\t\t\t{$sql_where}";
        $result = $db->sql_query($sql);
        $total_users = (int) $db->sql_fetchfield('total_users');
        $db->sql_freeresult($result);
    } else {
        $total_users = $config['num_users'];
    }
    // Get us some users :D
    $sql = "SELECT u.*\r\r\n\t\tFROM " . USERS_TABLE . " u\r\r\n\t\tWHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")\r\r\n\t\t\t{$sql_where}\r\r\n\t\tORDER BY {$order_by}";
    $result = $db->sql_query_limit($sql, $per_page, $start);
    $user_list = array();
    while ($row = $db->sql_fetchrow($result)) {
        $return_user_lists[] = new xmlrpcval(array('username' => new xmlrpcval(basic_clean($row['username']), 'base64'), 'user_id' => new xmlrpcval($row['user_id'], 'string'), 'icon_url' => new xmlrpcval(get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']), 'string')), 'struct');
    }
    $db->sql_freeresult($result);
    $suggested_users = new xmlrpcval(array('total' => new xmlrpcval($total_users, 'int'), 'list' => new xmlrpcval($return_user_lists, 'array')), 'struct');
    return new xmlrpcresp($suggested_users);
}
function prefetch_account_func()
{
    global $db;
    $user = tt_get_user_by_email(trim($_POST['email']));
    if (empty($user['user_id'])) {
        trigger_error("Can't find the user");
    }
    $result = array('result' => new xmlrpcval(true, 'boolean'), 'result_text' => new xmlrpcval('', 'base64'), 'user_id' => new xmlrpcval($user['user_id'], 'string'), 'login_name' => new xmlrpcval(basic_clean($user['username']), 'base64'), 'display_name' => new xmlrpcval(basic_clean($user['username']), 'base64'), 'avatar' => new xmlrpcval(get_user_avatar_url($user['user_avatar'], $user['user_avatar_type']), 'string'));
    return new xmlrpcresp(new xmlrpcval($result, 'struct'));
}
Exemple #5
0
 /**
  * Build teh evobar menu
  */
 function build_evobar_menu()
 {
     /**
      * @var Menu
      */
     global $topleft_Menu, $topright_Menu;
     global $current_User;
     global $home_url, $admin_url, $dispatcher, $debug, $seo_page_type, $robots_index;
     global $Blog, $blog;
     global $Settings;
     $perm_admin_normal = $current_User->check_perm('admin', 'normal');
     $perm_admin_restricted = $current_User->check_perm('admin', 'restricted');
     $entries = NULL;
     if ($perm_admin_normal) {
         // Normal Access to Admin:
         $entries = array('b2evo' => array('text' => '<strong>b2evolution</strong>', 'href' => $home_url), 'dashboard' => array('text' => T_('Dashboard'), 'href' => $admin_url, 'title' => T_('Go to admin dashboard')), 'see' => array('text' => T_('See'), 'href' => $home_url, 'title' => T_('See the home page')), 'write' => array('text' => T_('Write'), 'title' => T_('No blog is currently selected'), 'disabled' => true), 'blog' => array('text' => T_('Blog'), 'title' => T_('No blog is currently selected'), 'disabled' => true), 'tools' => array('text' => T_('More'), 'disabled' => true));
     } elseif ($perm_admin_restricted) {
         // restricted Access to Admin:
         $entries = array('see' => array('text' => T_('Site'), 'href' => $home_url, 'title' => T_('See the home page')));
         if ($current_User->check_perm('blogs', 'create')) {
             $entries['blog'] = array('text' => T_('Blog'), 'title' => T_('No blog is currently selected'), 'disabled' => true);
         }
         $entries['tools'] = array('text' => T_('More'), 'disabled' => true);
     }
     if (!empty($Blog)) {
         // A blog is currently selected:
         if ($perm_admin_normal) {
             $entries['dashboard']['href'] = $admin_url . '?blog=' . $Blog->ID;
         }
         if ($perm_admin_restricted) {
             $entries['see']['href'] = $Blog->get('url');
             $entries['see']['title'] = T_('See the public view of this blog');
         }
         if ($current_User->check_perm('blog_post_statuses', 'edit', false, $Blog->ID)) {
             // We have permission to add a post with at least one status:
             $write_item_url = $Blog->get_write_item_url();
             if ($write_item_url) {
                 // write item URL is not empty, so it's sure that user can create new post
                 if (!$perm_admin_normal) {
                     $entries['write'] = array('text' => T_('Write'));
                 }
                 $entries['write']['href'] = $write_item_url;
                 $entries['write']['disabled'] = false;
                 $entries['write']['title'] = T_('Write a new post into this blog');
             }
         }
         if ($perm_admin_normal) {
             if (empty($write_item_url)) {
                 // Display restricted message on this blog
                 $entries['write']['title'] = T_('You don\'t have permission to post into this blog');
             }
             // BLOG MENU:
             $items_url = $admin_url . '?ctrl=items&amp;blog=' . $Blog->ID . '&amp;filter=restore';
             $entries['blog']['href'] = $items_url;
             $entries['blog']['disabled'] = false;
             $entries['blog']['title'] = T_('Manage this blog');
             if ($Blog->get('type') == 'manual') {
                 // Manual Pages
                 $entries['blog']['entries']['manual'] = array('text' => T_('Manual Pages') . '&hellip;', 'href' => $items_url . '&amp;tab=manual');
             }
             $entries['blog']['entries']['posts'] = array('text' => T_('Posts') . '&hellip;', 'href' => $items_url);
             // Check if user has permission for published, draft or depreceted comments (any of these)
             if ($current_User->check_perm('blog_comments', 'edit', false, $Blog->ID)) {
                 // Comments:
                 $entries['blog']['entries']['comments'] = array('text' => T_('Comments') . '&hellip;', 'href' => $admin_url . '?ctrl=comments&amp;blog=' . $Blog->ID . '&amp;filter=restore');
             }
             // Chapters / Categories:
             if ($current_User->check_perm('blog_cats', 'edit', false, $Blog->ID)) {
                 // Either permission for a specific blog or the global permission:
                 $entries['blog']['entries']['chapters'] = array('text' => T_('Categories') . '&hellip;', 'href' => $admin_url . '?ctrl=chapters&amp;blog=' . $Blog->ID);
             }
             // PLACE HOLDER FOR FILES MODULE:
             $entries['blog']['entries']['files'] = NULL;
             // BLOG SETTINGS:
             if ($current_User->check_perm('blog_properties', 'edit', false, $Blog->ID)) {
                 // We have permission to edit blog properties:
                 $blog_param = '&amp;blog=' . $Blog->ID;
                 if (!empty($entries['blog']['entries'])) {
                     // There are already entries aboce, insert a separator:
                     $entries['blog']['entries'][] = array('separator' => true);
                 }
                 $entries['blog']['entries']['general'] = array('text' => T_('Blog settings'), 'href' => $admin_url . '?ctrl=coll_settings' . $blog_param, 'entries' => array('general' => array('text' => T_('General') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=general' . $blog_param), 'features' => array('text' => T_('Features') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=features' . $blog_param), 'skin' => array('text' => T_('Skin') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=skin' . $blog_param), 'plugin_settings' => array('text' => T_('Plugins') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=plugin_settings' . $blog_param), 'widgets' => array('text' => T_('Widgets') . '&hellip;', 'href' => $admin_url . '?ctrl=widgets' . $blog_param), 'urls' => array('text' => T_('URLs') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=urls' . $blog_param), 'seo' => array('text' => T_('SEO') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=seo' . $blog_param), 'advanced' => array('text' => T_('Advanced') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=advanced' . $blog_param)));
                 if ($Blog && $Blog->advanced_perms) {
                     $entries['blog']['entries']['general']['entries']['userperms'] = array('text' => T_('User perms') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=perm' . $blog_param);
                     $entries['blog']['entries']['general']['entries']['groupperms'] = array('text' => T_('Group perms') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=permgroup' . $blog_param);
                 }
             }
         }
     }
     // SYSTEM MENU:
     if ($perm_admin_restricted) {
         if ($debug) {
             $debug_text = 'DEBUG: ';
             if (!empty($seo_page_type)) {
                 // Set in skin_init()
                 $debug_text = $seo_page_type . ': ';
             }
             if ($robots_index === false) {
                 $debug_text .= 'NO INDEX';
             } else {
                 $debug_text .= 'do index';
             }
             $entries['tools']['entries']['noindex'] = array('text' => $debug_text, 'disabled' => true);
             $entries['tools']['entries'][''] = array('separator' => true);
         }
         if ($current_User->check_perm('users', 'view')) {
             // Users:
             $entries['tools']['disabled'] = false;
             $entries['tools']['entries']['users'] = array('text' => T_('Users') . '&hellip;', 'href' => $admin_url . '?ctrl=users');
         }
         // PLACE HOLDER FOR MESSAGING MODULE:
         $entries['tools']['entries']['messaging'] = NULL;
         // PLACE HOLDER FOR FILES MODULE:
         $entries['tools']['entries']['files'] = NULL;
         $perm_spam = $current_User->check_perm('spamblacklist', 'view');
         $perm_options = $current_User->check_perm('options', 'view');
         $perm_emails = $current_User->check_perm('emails', 'view');
         $perm_slugs = $current_User->check_perm('slugs', 'view');
         $perm_maintenance = $current_User->check_perm('perm_maintenance', 'upgrade');
         if ($perm_spam || $perm_options || $perm_slugs || $perm_maintenance) {
             if ($perm_emails) {
                 $entries['tools']['entries']['email'] = array('text' => T_('Emails'), 'href' => $admin_url . '?ctrl=email', 'entries' => array('blocked' => array('text' => T_('Addresses') . '&hellip;', 'href' => $admin_url . '?ctrl=email'), 'sent' => array('text' => T_('Sent') . '&hellip;', 'href' => $admin_url . '?ctrl=email&amp;tab=sent'), 'return' => array('text' => T_('Returned') . '&hellip;', 'href' => $admin_url . '?ctrl=email&amp;tab=return'), 'settings' => array('text' => T_('Settings') . '&hellip;', 'href' => $admin_url . '?ctrl=email&amp;tab=settings')));
             }
             $entries['tools']['disabled'] = false;
             $entries['tools']['entries']['tools_sep'] = array('separator' => true);
             if ($perm_options) {
                 $entries['tools']['entries']['status'] = array('text' => T_('System status') . '&hellip;', 'href' => $admin_url . '?ctrl=system');
             }
             if ($perm_options) {
                 $entries['tools']['entries']['crontab'] = array('text' => T_('Scheduler') . '&hellip;', 'href' => $admin_url . '?ctrl=crontab');
             }
             if ($perm_spam) {
                 $entries['tools']['entries']['antispam'] = array('text' => T_('Antispam'), 'href' => $admin_url . '?ctrl=antispam', 'entries' => array('blacklist' => array('text' => T_('Blacklist') . '&hellip;', 'href' => $admin_url . '?ctrl=antispam')));
                 if ($perm_options) {
                     // If we have access to options, then we add a submenu:
                     $entries['tools']['entries']['antispam']['entries']['ipranges'] = array('text' => T_('IP Ranges') . '&hellip;', 'href' => $admin_url . '?ctrl=antispam&amp;tab3=ipranges');
                     $entries['tools']['entries']['antispam']['entries']['settings'] = array('text' => T_('Settings') . '&hellip;', 'href' => $admin_url . '?ctrl=antispam&amp;tab3=settings');
                     if ($current_User->check_perm('options', 'edit')) {
                         $entries['tools']['entries']['antispam']['entries']['tools'] = array('text' => T_('Tools') . '&hellip;', 'href' => $admin_url . '?ctrl=antispam&amp;tab3=tools');
                     }
                 }
             }
             if ($perm_slugs) {
                 $entries['tools']['entries']['slugs'] = array('text' => T_('Slugs') . '&hellip;', 'href' => $admin_url . '?ctrl=slugs');
             }
         }
         if ($perm_options) {
             // Global settings:
             $entries['tools']['entries']['general'] = array('text' => T_('General') . '&hellip;', 'href' => $admin_url . '?ctrl=gensettings');
             $entries['tools']['entries']['regional'] = array('text' => T_('Regional'), 'href' => $admin_url . '?ctrl=regional', 'entries' => array('locales' => array('text' => T_('Locales') . '&hellip;', 'href' => $admin_url . '?ctrl=locales'), 'time' => array('text' => T_('Time') . '&hellip;', 'href' => $admin_url . '?ctrl=time'), 'countries' => array('text' => T_('Countries') . '&hellip;', 'href' => $admin_url . '?ctrl=countries'), 'regions' => array('text' => T_('Regions') . '&hellip;', 'href' => $admin_url . '?ctrl=regions'), 'subregions' => array('text' => T_('Sub-regions') . '&hellip;', 'href' => $admin_url . '?ctrl=subregions'), 'cities' => array('text' => T_('Cities') . '&hellip;', 'href' => $admin_url . '?ctrl=cities'), 'currencies' => array('text' => T_('Currencies') . '&hellip;', 'href' => $admin_url . '?ctrl=currencies')));
             $entries['tools']['entries']['plugins'] = array('text' => T_('Plugins') . '&hellip;', 'href' => $admin_url . '?ctrl=plugins');
             $entries['tools']['entries']['remote'] = array('text' => T_('Remote publishing') . '&hellip;', 'href' => $admin_url . '?ctrl=remotepublish');
             $entries['tools']['entries']['maintenance'] = array('text' => T_('Maintenance'), 'href' => $admin_url . '?ctrl=tools', 'entries' => array('tools' => array('text' => T_('Tools') . '&hellip;', 'href' => $admin_url . '?ctrl=tools'), 'import' => array('text' => T_('Import') . '&hellip;', 'href' => $admin_url . '?ctrl=tools&amp;tab3=import'), 'test' => array('text' => T_('Testing') . '&hellip;', 'href' => $admin_url . '?ctrl=tools&amp;tab3=test'), 'backup' => array('text' => T_('Backup') . '&hellip;', 'href' => $admin_url . '?ctrl=backup'), 'upgrade' => array('text' => T_('Check for updates') . '&hellip;', 'href' => $admin_url . '?ctrl=upgrade')));
         }
     }
     global $debug, $debug_jslog;
     if ($debug || $debug_jslog) {
         // Show JS log menu if debug is enabled
         $entries['jslog'] = array('text' => T_('JS log'), 'title' => T_('JS log'), 'class' => 'jslog_switcher');
     }
     if ($entries !== NULL) {
         $topleft_Menu->add_menu_entries(NULL, $entries);
     }
     // ---------------------------------------------------------------------------
     /*
      * RIGHT MENU
      */
     global $localtimenow, $is_admin_page;
     $entries = array('userprefs' => array('text' => $current_User->get_avatar_imgtag('crop-top-15x15', '', 'top') . ' <strong>' . $current_User->get_colored_login() . '</strong>', 'href' => get_user_profile_url(), 'entries' => array('profile' => array('text' => T_('Edit your profile') . '&hellip;', 'href' => get_user_profile_url()), 'avatar' => array('text' => T_('Your profile picture') . '&hellip;', 'href' => get_user_avatar_url()), 'pwdchange' => array('text' => T_('Change password') . '&hellip;', 'href' => get_user_pwdchange_url()), 'userprefs' => array('text' => T_('Preferences') . '&hellip;', 'href' => get_user_preferences_url()), 'subs' => array('text' => T_('Notifications') . '&hellip;', 'href' => get_user_subs_url()))), 'time' => array('text' => date(locale_shorttimefmt(), $localtimenow), 'disabled' => true, 'class' => 'noborder'));
     // ADMIN SKINS:
     if ($is_admin_page) {
         $admin_skins = get_admin_skins();
         if (count($admin_skins) > 1) {
             // We have several admin skins available: display switcher:
             $entries['userprefs']['entries']['admskins_sep'] = array('separator' => true);
             $entries['userprefs']['entries']['admskins'] = array('text' => T_('Admin skin'));
             $redirect_to = rawurlencode(regenerate_url('', '', '', '&'));
             foreach ($admin_skins as $admin_skin) {
                 $entries['userprefs']['entries']['admskins']['entries'][$admin_skin] = array('text' => $admin_skin, 'href' => $dispatcher . '?ctrl=users&amp;action=change_admin_skin&amp;new_admin_skin=' . rawurlencode($admin_skin) . '&amp;redirect_to=' . $redirect_to);
             }
         }
     }
     $entries['userprefs']['entries']['logout_sep'] = array('separator' => true);
     $entries['userprefs']['entries']['logout'] = array('text' => T_('Logout'), 'href' => get_user_logout_url());
     // AB switch:
     if ($perm_admin_normal) {
         // User must have permission to access admin...
         if ($is_admin_page) {
             if (!empty($Blog)) {
                 $entries['abswitch'] = array('text' => T_('Blog') . ' ' . get_icon('switch-to-blog'), 'href' => $Blog->get('url'));
             } else {
                 $entries['abswitch'] = array('text' => T_('Home') . ' ' . get_icon('switch-to-blog'), 'href' => $home_url);
             }
         } else {
             $entries['abswitch'] = array('text' => T_('Admin') . ' ' . get_icon('switch-to-admin'), 'href' => $admin_url);
         }
     }
     $topright_Menu->add_menu_entries(NULL, $entries);
     $topright_Menu->add_menu_entries(NULL, array('logout' => array('text' => T_('Logout') . ' ' . get_icon('close'), 'class' => 'rollover_sprite', 'href' => get_user_logout_url())));
 }
function reply_post_func($xmlrpc_params)
{
    global $db, $auth, $user, $config, $phpbb_root_path, $phpEx, $mobiquo_config, $phpbb_home;
    require_once 'include/emoji.php';
    $user->setup('posting');
    if (!$user->data['is_registered']) {
        trigger_error('LOGIN_EXPLAIN_POST');
    }
    $params = php_xmlrpc_decode($xmlrpc_params);
    // get parameters
    $forum_id = isset($params[0]) ? intval($params[0]) : '';
    $topic_id = isset($params[1]) ? intval($params[1]) : '';
    $subject = isset($params[2]) ? $params[2] : '';
    $text_body = isset($params[3]) ? $params[3] : '';
    $text_body = emoji_unified_to_names($text_body);
    $attach_list = isset($params[4]) ? $params[4] : array();
    $_POST['attachment_data'] = isset($params[5]) && $params[5] ? unserialize(base64_decode($params[5])) : array();
    $GLOBALS['return_html'] = isset($params[6]) ? $params[6] : false;
    if (!$topic_id) {
        trigger_error('NO_TOPIC');
    }
    if (utf8_clean_string($text_body) === '') {
        trigger_error('TOO_FEW_CHARS');
    }
    $post_data = array();
    $current_time = time();
    // get topic data
    $sql = 'SELECT *
            FROM ' . TOPICS_TABLE . '
            WHERE topic_id = ' . $topic_id;
    $result = $db->sql_query($sql);
    $post_data = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    // get forum data
    $sql = 'SELECT *
            FROM ' . FORUMS_TABLE . "\n            WHERE forum_type = " . FORUM_POST . ($post_data['forum_id'] ? "\n            AND forum_id = '{$post_data['forum_id']}' " : '');
    $result = $db->sql_query_limit($sql, 1);
    $forum_data = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    $post_data = array_merge($post_data, $forum_data);
    if (!$post_data) {
        trigger_error('NO_TOPIC');
    }
    // Use post_row values in favor of submitted ones...
    $forum_id = !empty($post_data['forum_id']) ? (int) $post_data['forum_id'] : (int) $forum_id;
    $topic_id = !empty($post_data['topic_id']) ? (int) $post_data['topic_id'] : (int) $topic_id;
    // Need to login to passworded forum first?
    if ($post_data['forum_password'] && !check_forum_password($forum_id)) {
        trigger_error('LOGIN_FORUM');
    }
    // Check permissions
    if ($user->data['is_bot']) {
        trigger_error('NOT_AUTHORISED');
    }
    // Is the user able to read within this forum?
    if (!$auth->acl_get('f_read', $forum_id)) {
        if ($user->data['user_id'] != ANONYMOUS) {
            trigger_error('USER_CANNOT_READ');
        }
        trigger_error('LOGIN_EXPLAIN_POST');
    }
    // Permission to do the reply
    if (!$auth->acl_get('f_reply', $forum_id)) {
        if ($user->data['user_id'] != ANONYMOUS) {
            trigger_error('USER_CANNOT_REPLY');
        }
        trigger_error('LOGIN_EXPLAIN_POST');
    }
    // Is the user able to post within this forum?
    if ($post_data['forum_type'] != FORUM_POST) {
        trigger_error('USER_CANNOT_FORUM_POST');
    }
    // Forum/Topic locked?
    if (($post_data['forum_status'] == ITEM_LOCKED || isset($post_data['topic_status']) && $post_data['topic_status'] == ITEM_LOCKED) && !$auth->acl_get('m_edit', $forum_id)) {
        trigger_error($post_data['forum_status'] == ITEM_LOCKED ? 'FORUM_LOCKED' : 'TOPIC_LOCKED');
    }
    $subject = (strpos($subject, 'Re: ') !== 0 ? 'Re: ' : '') . ($subject ? $subject : censor_text($post_data['topic_title']));
    $post_data['post_edit_locked'] = isset($post_data['post_edit_locked']) ? (int) $post_data['post_edit_locked'] : 0;
    $post_data['post_subject'] = isset($post_data['topic_title']) ? $post_data['topic_title'] : '';
    $post_data['topic_time_limit'] = isset($post_data['topic_time_limit']) ? $post_data['topic_time_limit'] ? (int) $post_data['topic_time_limit'] / 86400 : (int) $post_data['topic_time_limit'] : 0;
    $post_data['poll_length'] = !empty($post_data['poll_length']) ? (int) $post_data['poll_length'] / 86400 : 0;
    $post_data['poll_start'] = !empty($post_data['poll_start']) ? (int) $post_data['poll_start'] : 0;
    $post_data['icon_id'] = 0;
    $post_data['poll_options'] = array();
    // Get Poll Data
    if ($post_data['poll_start']) {
        $sql = 'SELECT poll_option_text
            FROM ' . POLL_OPTIONS_TABLE . "\n            WHERE topic_id = {$topic_id}\n            ORDER BY poll_option_id";
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $post_data['poll_options'][] = trim($row['poll_option_text']);
        }
        $db->sql_freeresult($result);
    }
    $orig_poll_options_size = sizeof($post_data['poll_options']);
    include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
    $message_parser = new parse_message();
    // Set some default variables
    $uninit = array('post_attachment' => 0, 'poster_id' => $user->data['user_id'], 'enable_magic_url' => 0, 'topic_status' => 0, 'topic_type' => POST_NORMAL, 'post_subject' => '', 'topic_title' => '', 'post_time' => 0, 'post_edit_reason' => '', 'notify_set' => 0);
    foreach ($uninit as $var_name => $default_value) {
        if (!isset($post_data[$var_name])) {
            $post_data[$var_name] = $default_value;
        }
    }
    unset($uninit);
    // Always check if the submitted attachment data is valid and belongs to the user.
    // Further down (especially in submit_post()) we do not check this again.
    $message_parser->get_submitted_attachment_data($post_data['poster_id']);
    $post_data['username'] = '';
    $post_data['enable_urls'] = $post_data['enable_magic_url'];
    $post_data['enable_sig'] = $config['allow_sig'] && $user->optionget('attachsig') ? true : false;
    $post_data['enable_smilies'] = $config['allow_smilies'] && $user->optionget('smilies') ? true : false;
    $post_data['enable_bbcode'] = $config['allow_bbcode'] && $user->optionget('bbcode') ? true : false;
    $post_data['enable_urls'] = true;
    $post_data['enable_magic_url'] = $post_data['drafts'] = false;
    $check_value = ($post_data['enable_bbcode'] + 1 << 8) + ($post_data['enable_smilies'] + 1 << 4) + ($post_data['enable_urls'] + 1 << 2) + ($post_data['enable_sig'] + 1 << 1);
    // Check if user is watching this topic
    if ($config['allow_topic_notify'] && $user->data['is_registered']) {
        $sql = 'SELECT topic_id
                FROM ' . TOPICS_WATCH_TABLE . '
                WHERE topic_id = ' . $topic_id . '
                AND user_id = ' . $user->data['user_id'];
        $result = $db->sql_query($sql);
        $post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id');
        $db->sql_freeresult($result);
    }
    // HTML, BBCode, Smilies, Images and Flash status
    $bbcode_status = $config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id) ? true : false;
    $smilies_status = $bbcode_status && $config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id) ? true : false;
    $img_status = $bbcode_status && $auth->acl_get('f_img', $forum_id) ? true : false;
    $url_status = $config['allow_post_links'] ? true : false;
    $flash_status = $bbcode_status && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash'] ? true : false;
    $quote_status = $auth->acl_get('f_reply', $forum_id) ? true : false;
    $post_data['topic_cur_post_id'] = request_var('topic_cur_post_id', 0);
    $post_data['post_subject'] = utf8_normalize_nfc($subject);
    $message_parser->message = utf8_normalize_nfc(htmlspecialchars($text_body));
    $post_data['username'] = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
    $post_data['post_edit_reason'] = '';
    $post_data['orig_topic_type'] = $post_data['topic_type'];
    $post_data['topic_type'] = request_var('topic_type', (int) $post_data['topic_type']);
    $post_data['topic_time_limit'] = request_var('topic_time_limit', (int) $post_data['topic_time_limit']);
    $post_data['icon_id'] = request_var('icon', 0);
    $post_data['enable_bbcode'] = !$bbcode_status || isset($_POST['disable_bbcode']) ? false : true;
    $post_data['enable_smilies'] = !$smilies_status || isset($_POST['disable_smilies']) ? false : true;
    $post_data['enable_urls'] = isset($_POST['disable_magic_url']) ? 0 : 1;
    $post_data['enable_sig'] = !$config['allow_sig'] || !$auth->acl_get('f_sigs', $forum_id) || !$auth->acl_get('u_sig') ? false : ($user->data['is_registered'] ? true : false);
    if ($config['allow_topic_notify'] && $user->data['is_registered']) {
        $notify = !$post_data['notify_set'] ? $user->data['user_notify'] : $post_data['notify_set'] ? true : false;
    } else {
        $notify = false;
    }
    $post_data['poll_title'] = utf8_normalize_nfc(request_var('poll_title', '', true));
    $post_data['poll_length'] = request_var('poll_length', 0);
    $post_data['poll_option_text'] = utf8_normalize_nfc(request_var('poll_option_text', '', true));
    $post_data['poll_max_options'] = request_var('poll_max_options', 1);
    $post_data['poll_vote_change'] = $auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change']) ? 1 : 0;
    // Parse Attachments - before checksum is calculated
    $message_parser->parse_attachments('fileupload', 'reply', $forum_id, true, false, false);
    // Grab md5 'checksum' of new message
    $message_md5 = md5($message_parser->message);
    // Check checksum ... don't re-parse message if the same
    if (sizeof($message_parser->warn_msg)) {
        trigger_error(join("\n", $message_parser->warn_msg));
    }
    $message_parser->parse($post_data['enable_bbcode'], $config['allow_post_links'] ? $post_data['enable_urls'] : false, $post_data['enable_smilies'], $img_status, $flash_status, $quote_status, $config['allow_post_links']);
    if ($config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id)) {
        // Flood check
        $last_post_time = 0;
        if ($user->data['is_registered']) {
            $last_post_time = $user->data['user_lastpost_time'];
        } else {
            $sql = 'SELECT post_time AS last_post_time
                FROM ' . POSTS_TABLE . "\n                WHERE poster_ip = '" . $user->ip . "'\n                    AND post_time > " . ($current_time - $config['flood_interval']);
            $result = $db->sql_query_limit($sql, 1);
            if ($row = $db->sql_fetchrow($result)) {
                $last_post_time = $row['last_post_time'];
            }
            $db->sql_freeresult($result);
        }
        if ($last_post_time && $current_time - $last_post_time < intval($config['flood_interval'])) {
            trigger_error('FLOOD_ERROR');
        }
    }
    // Validate username
    if ($post_data['username'] && !$user->data['is_registered']) {
        include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
        if (($result = validate_username($post_data['username'], !empty($post_data['post_username']) ? $post_data['post_username'] : '')) !== false) {
            $user->add_lang('ucp');
            trigger_error($result . '_USERNAME');
        }
    }
    $post_data['poll_last_vote'] = isset($post_data['poll_last_vote']) ? $post_data['poll_last_vote'] : 0;
    $poll = array();
    //    if (sizeof($message_parser->warn_msg))
    //    {
    //        return get_error();
    //    }
    // DNSBL check
    if ($config['check_dnsbl'] && $mobiquo_config['check_dnsbl']) {
        if (($dnsbl = $user->check_dnsbl('post')) !== false) {
            trigger_error(sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]));
        }
    }
    // Store message, sync counters
    $data = array('topic_title' => empty($post_data['topic_title']) ? $post_data['post_subject'] : $post_data['topic_title'], 'topic_first_post_id' => isset($post_data['topic_first_post_id']) ? (int) $post_data['topic_first_post_id'] : 0, 'topic_last_post_id' => isset($post_data['topic_last_post_id']) ? (int) $post_data['topic_last_post_id'] : 0, 'topic_time_limit' => (int) $post_data['topic_time_limit'], 'topic_attachment' => isset($post_data['topic_attachment']) ? (int) $post_data['topic_attachment'] : 0, 'post_id' => 0, 'topic_id' => (int) $topic_id, 'forum_id' => (int) $forum_id, 'icon_id' => (int) $post_data['icon_id'], 'poster_id' => (int) $post_data['poster_id'], 'enable_sig' => (bool) $post_data['enable_sig'], 'enable_bbcode' => (bool) $post_data['enable_bbcode'], 'enable_smilies' => (bool) $post_data['enable_smilies'], 'enable_urls' => (bool) $post_data['enable_urls'], 'enable_indexing' => (bool) $post_data['enable_indexing'], 'message_md5' => (string) $message_md5, 'post_time' => isset($post_data['post_time']) ? (int) $post_data['post_time'] : $current_time, 'post_checksum' => isset($post_data['post_checksum']) ? (string) $post_data['post_checksum'] : '', 'post_edit_reason' => $post_data['post_edit_reason'], 'post_edit_user' => isset($post_data['post_edit_user']) ? (int) $post_data['post_edit_user'] : 0, 'forum_parents' => $post_data['forum_parents'], 'forum_name' => $post_data['forum_name'], 'notify' => $notify, 'notify_set' => $post_data['notify_set'], 'poster_ip' => isset($post_data['poster_ip']) ? $post_data['poster_ip'] : $user->ip, 'post_edit_locked' => (int) $post_data['post_edit_locked'], 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'message' => $message_parser->message, 'attachment_data' => $message_parser->attachment_data, 'filename_data' => $message_parser->filename_data, 'topic_approved' => isset($post_data['topic_approved']) ? $post_data['topic_approved'] : false, 'post_approved' => isset($post_data['post_approved']) ? $post_data['post_approved'] : false, 'post_expire_time' => -1);
    include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
    $update_message = true;
    $cwd = getcwd();
    chdir('../');
    $phpbb_root_path_tmp = $phpbb_root_path;
    $phpbb_root_path = './';
    $redirect_url = submit_post('reply', $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message);
    chdir($cwd);
    $phpbb_root_path = $phpbb_root_path_tmp;
    // Check the permissions for post approval, as well as the queue trigger where users are put on approval with a post count lower than specified. Moderators are not affected.
    $approved = true;
    if (($config['enable_queue_trigger'] && $user->data['user_posts'] < $config['queue_trigger_posts'] || !$auth->acl_get('f_noapprove', $data['forum_id'])) && !$auth->acl_get('m_approve', $data['forum_id'])) {
        $approved = false;
    }
    $reply_success = false;
    $post_id = '';
    if ($redirect_url) {
        preg_match('/&amp;p=(\\d+)/', $redirect_url, $matches);
        $post_id = $matches[1];
        $reply_success = true;
        // get new post_content
        $message = censor_text($data['message']);
        $quote_wrote_string = $user->lang['WROTE'];
        $message = str_replace('[/quote:' . $data['bbcode_uid'] . ']', '[/quote]', $message);
        $message = preg_replace('/\\[quote(?:=&quot;(.*?)&quot;)?:' . $data['bbcode_uid'] . '\\]/ise', "'[quote]' . ('\$1' ? '\$1' . ' {$quote_wrote_string}:\n' : '\n')", $message);
        $blocks = preg_split('/(\\[\\/?quote\\])/i', $message, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        $quote_level = 0;
        $message = '';
        foreach ($blocks as $block) {
            if ($block == '[quote]') {
                if ($quote_level == 0) {
                    $message .= $block;
                }
                $quote_level++;
            } else {
                if ($block == '[/quote]') {
                    if ($quote_level <= 1) {
                        $message .= $block;
                    }
                    if ($quote_level >= 1) {
                        $quote_level--;
                    }
                } else {
                    if ($quote_level <= 1) {
                        $message .= $block;
                    }
                }
            }
        }
        $message = preg_replace('/\\[(youtube|video|googlevideo|gvideo):' . $data['bbcode_uid'] . '\\](.*?)\\[\\/\\1:' . $data['bbcode_uid'] . '\\]/sie', "video_bbcode_format('\$1', '\$2')", $message);
        $message = preg_replace('/\\[(BBvideo)[\\d, ]+:' . $row['bbcode_uid'] . '\\](.*?)\\[\\/\\1:' . $row['bbcode_uid'] . '\\]/si', "[url=\$2]YouTube Video[/url]", $message);
        $message = preg_replace('/\\[(spoil|spoiler):' . $row['bbcode_uid'] . '\\](.*?)\\[\\/\\1:' . $row['bbcode_uid'] . '\\]/si', "[spoiler]\$2[/spoiler]", $message);
        $message = preg_replace('/\\[b:' . $data['bbcode_uid'] . '\\](.*?)\\[\\/b:' . $data['bbcode_uid'] . '\\]/si', '[b]$1[/b]', $message);
        $message = preg_replace('/\\[i:' . $data['bbcode_uid'] . '\\](.*?)\\[\\/i:' . $data['bbcode_uid'] . '\\]/si', '[i]$1[/i]', $message);
        $message = preg_replace('/\\[u:' . $data['bbcode_uid'] . '\\](.*?)\\[\\/u:' . $data['bbcode_uid'] . '\\]/si', '[u]$1[/u]', $message);
        $message = preg_replace('/\\[color=#(\\w{6}):' . $data['bbcode_uid'] . '\\](.*?)\\[\\/color:' . $data['bbcode_uid'] . '\\]/si', '[color=#$1]$2[/color]', $message);
        // Second parse bbcode here
        if ($data['bbcode_bitfield']) {
            $bbcode = new bbcode(base64_encode($data['bbcode_bitfield']));
            $bbcode->bbcode_second_pass($message, $data['bbcode_uid'], $data['bbcode_bitfield']);
        }
        $message = bbcode_nl2br($message);
        $message = smiley_text($message);
        if (!empty($data['attachment_data'])) {
            parse_attachments($forum_id, $message, $data['attachment_data'], $update_count);
        }
        $updated_post_title = html_entity_decode(strip_tags(censor_text($data['topic_title'])), ENT_QUOTES, 'UTF-8');
        $edit_allowed = $auth->acl_get('m_edit', $forum_id) || $auth->acl_get('f_edit', $forum_id) && !$data['post_edit_locked'] && ($data['post_time'] > time() - $config['edit_time'] * 60 || !$config['edit_time']);
        $delete_allowed = $auth->acl_get('m_delete', $forum_id) || $auth->acl_get('f_delete', $forum_id) && ($data['post_time'] > time() - $config['delete_time'] * 60 || !$config['delete_time']) && !$data['post_edit_locked'];
        $attachments = array();
        if (sizeof($attach_list) && sizeof($data['attachment_data'])) {
            $sql = 'SELECT *
                FROM ' . ATTACHMENTS_TABLE . '
                WHERE ' . $db->sql_in_set('attach_id', $attach_list) . '
                    AND in_message = 0
                ORDER BY filetime DESC';
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $attachment_by_id[$row['attach_id']] = $row;
            }
            $db->sql_freeresult($result);
            foreach ($data['attachment_data'] as $attachment) {
                if (preg_match('/<img src=\\".*?(\\/download\\/file.php\\?id=(\\d+).*?)\\"/is', $attachment, $matches)) {
                    $file_url = html_entity_decode($phpbb_home . $matches[1]);
                    $attach_id = $matches[2];
                    unset($matches);
                    $xmlrpc_attachment = new xmlrpcval(array('filename' => new xmlrpcval($attachment_by_id[$attach_id]['real_filename'], 'base64'), 'filesize' => new xmlrpcval($attachment_by_id[$attach_id]['filesize'], 'int'), 'content_type' => new xmlrpcval('image'), 'thumbnail_url' => new xmlrpcval(''), 'url' => new xmlrpcval($file_url)), 'struct');
                    $attachments[] = $xmlrpc_attachment;
                }
            }
        }
    }
    $xmlrpc_reply_topic = new xmlrpcval(array('result' => new xmlrpcval($reply_success, 'boolean'), 'post_id' => new xmlrpcval($post_id, 'string'), 'state' => new xmlrpcval($approved ? 0 : 1, 'int'), 'post_title' => new xmlrpcval($updated_post_title, 'base64'), 'post_content' => new xmlrpcval(post_html_clean($message), 'base64'), 'post_author_name' => new xmlrpcval(html_entity_decode($user->data['username']), 'base64'), 'is_online' => new xmlrpcval(true, 'boolean'), 'can_edit' => new xmlrpcval($edit_allowed, 'boolean'), 'icon_url' => new xmlrpcval($user->optionget('viewavatars') ? get_user_avatar_url($user->data['user_avatar'], $user->data['user_avatar_type']) : ''), 'post_time' => new xmlrpcval(mobiquo_iso8601_encode($current_time), 'dateTime.iso8601'), 'can_delete' => new xmlrpcval($delete_allowed, 'boolean'), 'allow_smilies' => new xmlrpcval($data['enable_smilies'] ? true : false, 'boolean'), 'attachments' => new xmlrpcval($attachments, 'array')), 'struct');
    return new xmlrpcresp($xmlrpc_reply_topic);
}
Exemple #7
0
 /**
  * Build the evobar menu
  */
 function build_evobar_menu()
 {
     /**
      * @var Menu
      */
     global $topleft_Menu, $topright_Menu;
     global $current_User;
     global $baseurl, $home_url, $admin_url, $debug, $debug_jslog, $dev_menu, $seo_page_type, $robots_index;
     global $Blog, $blog, $activate_collection_toolbar;
     global $Settings;
     $perm_admin_normal = $current_User->check_perm('admin', 'normal');
     $perm_admin_restricted = $current_User->check_perm('admin', 'restricted');
     $entries = NULL;
     $working_blog = get_working_blog();
     if ($working_blog) {
         // Set collection url only when current user has an access to the working blog
         if (is_admin_page()) {
             // Front page of the working blog
             $BlogCache =& get_BlogCache();
             $working_Blog =& $BlogCache->get_by_ID($working_blog);
             $collection_url = $working_Blog->get('url');
         } else {
             // Dashboard of the working blog
             $collection_url = $admin_url . '?ctrl=dashboard&amp;blog=' . $working_blog;
         }
     }
     if ($perm_admin_normal || $perm_admin_restricted) {
         // Normal OR Restricted Access to Admin:
         $entries = array();
         if ($perm_admin_normal) {
             // Only for normal access
             $entries['b2evo'] = array('text' => '<strong>b2evolution</strong>', 'href' => $home_url, 'entry_class' => 'rwdhide');
         }
         $entries['front'] = array('text' => T_('Front<u>-office</u>'), 'href' => $baseurl, 'title' => T_('Go to the site home page (Front-office)'));
         $entries['dashboard'] = array('text' => T_('Back<u>-office</u>'), 'href' => $admin_url, 'title' => T_('Go to the site dashboard (Back-office)'));
         if ($perm_admin_normal) {
             // Only for normal access
             $entries['write'] = array('text' => '<span class="fa fa-plus-square"></span> ' . T_('Post'), 'title' => T_('No blog is currently selected'), 'disabled' => true, 'entry_class' => 'rwdhide');
         }
         if ($working_blog) {
             // Display a link to manage first available collection
             $entries['blog'] = array('text' => T_('Collection'), 'href' => $collection_url, 'disabled' => true);
         }
         $entries['tools'] = array('text' => T_('More'), 'href' => $admin_url . '#', 'disabled' => true);
     }
     if ((!is_admin_page() || !empty($activate_collection_toolbar)) && !empty($Blog)) {
         // A blog is currently selected AND we can activate toolbar items for selected collection:
         if ($current_User->check_perm('blog_post_statuses', 'edit', false, $Blog->ID)) {
             // We have permission to add a post with at least one status:
             $write_item_url = $Blog->get_write_item_url();
             if ($write_item_url) {
                 // write item URL is not empty, so it's sure that user can create new post
                 if (!$perm_admin_normal) {
                     $entries['write'] = array('text' => '<span class="fa fa-plus-square"></span> ' . T_('Post'));
                 }
                 $entries['write']['href'] = $write_item_url;
                 $entries['write']['disabled'] = false;
                 $entries['write']['title'] = T_('Write a new post into this blog');
             }
         }
         if ($perm_admin_normal && $working_blog) {
             if (empty($write_item_url)) {
                 // Display restricted message on this blog
                 $entries['write']['title'] = T_('You don\'t have permission to post into this blog');
             }
             // BLOG MENU:
             $entries['blog'] = array('text' => T_('Collection'), 'title' => T_('Manage this blog'), 'href' => $collection_url);
             $display_separator = false;
             if ($current_User->check_perm('blog_ismember', 'view', false, $Blog->ID)) {
                 // Check if current user has an access to post lists
                 $items_url = $admin_url . '?ctrl=items&amp;blog=' . $Blog->ID . '&amp;filter=restore';
                 // Collection front page
                 $entries['blog']['entries']['coll_front'] = array('text' => T_('Collection Front Page') . '&hellip;', 'href' => $Blog->get('url'));
                 // Collection dashboard
                 $entries['blog']['entries']['coll_dashboard'] = array('text' => T_('Collection Dashboard') . '&hellip;', 'href' => $admin_url . '?ctrl=dashboard&amp;blog=' . $Blog->ID);
                 $entries['blog']['entries'][] = array('separator' => true);
                 if ($Blog->get('type') == 'manual') {
                     // Manual view
                     $entries['blog']['entries']['manual'] = array('text' => T_('Manual view') . '&hellip;', 'href' => $items_url . '&amp;tab=manual');
                 }
                 if ($Blog->get_setting('use_workflow')) {
                     // Workflow view
                     $entries['blog']['entries']['workflow'] = array('text' => T_('Workflow view') . '&hellip;', 'href' => $items_url . '&amp;tab=tracker');
                 }
                 $entries['blog']['entries']['posts'] = array('text' => T_('Posts') . '&hellip;', 'href' => $items_url);
                 $display_separator = true;
             }
             // Check if user has permission for published, draft or depreceted comments (any of these)
             if ($current_User->check_perm('blog_comments', 'edit', false, $Blog->ID)) {
                 // Comments:
                 $entries['blog']['entries']['comments'] = array('text' => T_('Comments') . '&hellip;', 'href' => $admin_url . '?ctrl=comments&amp;blog=' . $Blog->ID . '&amp;filter=restore');
                 $display_separator = true;
             }
             // Chapters / Categories:
             if ($current_User->check_perm('blog_cats', 'edit', false, $Blog->ID)) {
                 // Either permission for a specific blog or the global permission:
                 $entries['blog']['entries']['chapters'] = array('text' => T_('Categories') . '&hellip;', 'href' => $admin_url . '?ctrl=chapters&amp;blog=' . $Blog->ID);
                 $display_separator = true;
             }
             if ($display_separator) {
                 $entries['blog']['entries'][] = array('separator' => true);
             }
             // PLACE HOLDER FOR FILES MODULE:
             $entries['blog']['entries']['files'] = NULL;
             // BLOG SETTINGS:
             if ($current_User->check_perm('blog_properties', 'edit', false, $Blog->ID)) {
                 // We have permission to edit blog properties:
                 $blog_param = '&amp;blog=' . $Blog->ID;
                 $entries['blog']['entries']['features'] = array('text' => T_('Features'), 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=home' . $blog_param, 'entries' => array('front' => array('text' => T_('Front page') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=home' . $blog_param), 'posts' => array('text' => T_('Posts') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=features' . $blog_param), 'comments' => array('text' => T_('Comments') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=comments' . $blog_param), 'other' => array('text' => T_('Other displays') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=other' . $blog_param), 'more' => array('text' => T_('More') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=more' . $blog_param)));
                 $entries['blog']['entries']['skin'] = array('text' => T_('Skin') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=skin' . $blog_param);
                 $entries['blog']['entries']['plugin_settings'] = array('text' => T_('Plugins') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=plugin_settings' . $blog_param);
                 $entries['blog']['entries']['widgets'] = array('text' => T_('Widgets') . '&hellip;', 'href' => $admin_url . '?ctrl=widgets' . $blog_param);
                 if (!is_admin_page()) {
                     // Display a menu to turn on/off the debug containers
                     global $ReqURI, $Session;
                     if ($Session->get('display_containers_' . $Blog->ID) == 1) {
                         // To hide the debug containers
                         $entries['blog']['entries']['containers'] = array('text' => T_('Hide containers'), 'href' => url_add_param(regenerate_url('display_containers'), 'display_containers=hide'));
                     } else {
                         // To show the debug containers
                         $entries['blog']['entries']['containers'] = array('text' => T_('Show containers'), 'href' => url_add_param(regenerate_url('display_containers'), 'display_containers=show'));
                     }
                 }
                 $entries['blog']['entries']['general'] = array('text' => T_('Settings'), 'href' => $admin_url . '?ctrl=coll_settings' . $blog_param, 'entries' => array('general' => array('text' => T_('General') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=general' . $blog_param), 'urls' => array('text' => T_('URLs') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=urls' . $blog_param), 'seo' => array('text' => T_('SEO') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=seo' . $blog_param)));
                 if ($current_User->check_perm('options', 'view', false, $Blog->ID)) {
                     // Post Types & Statuses
                     $entries['blog']['entries']['general']['entries']['item_types'] = array('text' => T_('Post Types') . '&hellip;', 'href' => $admin_url . '?ctrl=itemtypes&amp;tab=settings&amp;tab3=types' . $blog_param);
                     $entries['blog']['entries']['general']['entries']['item_statuses'] = array('text' => T_('Post Statuses') . '&hellip;', 'href' => $admin_url . '?ctrl=itemstatuses&amp;tab=settings&amp;tab3=statuses' . $blog_param);
                 }
                 $entries['blog']['entries']['general']['entries']['advanced'] = array('text' => T_('Advanced') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=advanced' . $blog_param);
                 if ($Blog && $Blog->advanced_perms) {
                     $entries['blog']['entries']['general']['entries']['userperms'] = array('text' => T_('User perms') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=perm' . $blog_param);
                     $entries['blog']['entries']['general']['entries']['groupperms'] = array('text' => T_('Group perms') . '&hellip;', 'href' => $admin_url . '?ctrl=coll_settings&amp;tab=permgroup' . $blog_param);
                 }
                 if ($current_User->check_perm('options', 'view')) {
                     // Check if current user has a permission to view the common settings of the blogs
                     $entries['blog']['entries']['general']['entries']['common_settings'] = array('text' => T_('Common Settings') . '&hellip;', 'href' => $admin_url . '?ctrl=collections&amp;tab=blog_settings');
                 }
             }
         }
     }
     if ($perm_admin_restricted) {
         // DEV MENU:
         $dev_entries = array();
         if ($dev_menu || $debug || $debug_jslog) {
             if (isset($Blog)) {
                 $dev_entries['coll'] = array('text' => 'Collection = ' . $Blog->shortname, 'disabled' => true);
             }
             global $disp, $is_front;
             if (!empty($disp)) {
                 $dev_entries['disp'] = array('text' => '$disp = ' . $disp, 'disabled' => true);
             }
             global $disp_detail;
             if (!empty($disp_detail)) {
                 $dev_entries['disp_detail'] = array('text' => '$disp_detail = ' . $disp_detail, 'disabled' => true);
             }
             if (!empty($seo_page_type)) {
                 // Set in skin_init()
                 $dev_entries['seo_page_type'] = array('text' => '> ' . $seo_page_type, 'disabled' => true);
             }
             global $is_front;
             if (!empty($is_front)) {
                 $dev_entries['front'] = array('text' => 'This is the FRONT page', 'disabled' => true);
             }
             if ($robots_index === false) {
                 $debug_text = 'NO INDEX';
             } else {
                 $debug_text = 'do index';
             }
             $dev_entries['noindex'] = array('text' => $debug_text, 'disabled' => true);
         }
         if (($dev_menu || $debug) && !is_admin_page() && !empty($Blog)) {
             // Display a menu to turn on/off the debug containers
             global $ReqURI, $Session;
             $dev_entries[] = array('separator' => true);
             if ($Session->get('display_containers_' . $Blog->ID) == 1) {
                 // To hide the debug containers
                 $dev_entries['containers'] = array('text' => T_('Hide containers'), 'href' => url_add_param(regenerate_url('display_containers'), 'display_containers=hide'));
             } else {
                 // To show the debug containers
                 $dev_entries['containers'] = array('text' => T_('Show containers'), 'href' => url_add_param(regenerate_url('display_containers'), 'display_containers=show'));
             }
             if ($Session->get('display_includes_' . $Blog->ID) == 1) {
                 // To hide the debug includes
                 $dev_entries['includes'] = array('text' => T_('Hide includes'), 'href' => url_add_param(regenerate_url('display_containers'), 'display_includes=hide'));
             } else {
                 // To show the debug includes
                 $dev_entries['includes'] = array('text' => T_('Show includes'), 'href' => url_add_param(regenerate_url('display_containers'), 'display_includes=show'));
             }
         }
         // MORE menu:
         if ($current_User->check_perm('users', 'view')) {
             // Users:
             $entries['tools']['disabled'] = false;
             $entries['tools']['entries']['users'] = array('text' => T_('Users') . '&hellip;', 'href' => $admin_url . '?ctrl=users');
         }
         // PLACE HOLDER FOR MESSAGING MODULE:
         $entries['tools']['entries']['messaging'] = NULL;
         // PLACE HOLDER FOR FILES MODULE:
         $entries['tools']['entries']['files'] = NULL;
         $perm_options = $current_User->check_perm('options', 'view');
         $perm_spam = $perm_options && $current_User->check_perm('spamblacklist', 'view');
         $perm_emails = $current_User->check_perm('emails', 'view');
         $perm_maintenance = $current_User->check_perm('perm_maintenance', 'upgrade');
         if ($perm_spam || $perm_options || $perm_maintenance) {
             $entries['tools']['entries'][] = array('separator' => true);
             if ($perm_emails) {
                 $entries['tools']['entries']['email'] = array('text' => T_('Emails'), 'href' => $admin_url . '?ctrl=campaigns', 'entries' => array('campaigns' => array('text' => T_('Campaigns') . '&hellip;', 'href' => $admin_url . '?ctrl=campaigns'), 'blocked' => array('text' => T_('Addresses') . '&hellip;', 'href' => $admin_url . '?ctrl=email'), 'sent' => array('text' => T_('Sent') . '&hellip;', 'href' => $admin_url . '?ctrl=email&amp;tab=sent'), 'return' => array('text' => T_('Returned') . '&hellip;', 'href' => $admin_url . '?ctrl=email&amp;tab=return'), 'settings' => array('text' => T_('Settings') . '&hellip;', 'href' => $admin_url . '?ctrl=email&amp;tab=settings')));
             }
             $entries['tools']['disabled'] = false;
             $entries['tools']['entries']['system'] = array('text' => T_('System'), 'href' => $admin_url . '?ctrl=system');
             if ($perm_options) {
                 $entries['tools']['entries']['system']['entries']['status'] = array('text' => T_('Status') . '&hellip;', 'href' => $admin_url . '?ctrl=system');
             }
             if ($perm_options) {
                 $entries['tools']['entries']['system']['entries']['crontab'] = array('text' => T_('Scheduler') . '&hellip;', 'href' => $admin_url . '?ctrl=crontab');
             }
             if ($perm_spam) {
                 $entries['tools']['entries']['system']['entries']['antispam'] = array('text' => T_('Antispam') . '&hellip;', 'href' => $admin_url . '?ctrl=antispam');
             }
         }
         if ($perm_options) {
             // Global settings:
             $entries['tools']['entries']['system']['entries']['regional'] = array('text' => T_('Regional') . '&hellip;', 'href' => $admin_url . '?ctrl=regional');
             $entries['tools']['entries']['system']['entries']['skins'] = array('text' => T_('Skins') . '&hellip;', 'href' => $admin_url . '?ctrl=skins&amp;tab=system');
             $entries['tools']['entries']['system']['entries']['plugins'] = array('text' => T_('Plugins') . '&hellip;', 'href' => $admin_url . '?ctrl=plugins');
             $entries['tools']['entries']['system']['entries']['remote'] = array('text' => T_('Remote publishing') . '&hellip;', 'href' => $admin_url . '?ctrl=remotepublish');
             $entries['tools']['entries']['system']['entries']['maintenance'] = array('text' => T_('Maintenance') . '&hellip;', 'href' => $admin_url . '?ctrl=tools');
             $entries['tools']['entries']['system']['entries']['syslog'] = array('text' => T_('System log'), 'href' => '?ctrl=syslog');
         }
     }
     if ($entries !== NULL) {
         $topleft_Menu->add_menu_entries(NULL, $entries);
     }
     // ---------------------------------------------------------------------------
     /*
      * RIGHT MENU
      */
     global $localtimenow, $is_admin_page;
     $entries = array();
     // Dev menu:
     global $debug_jslog;
     if ($debug || $debug_jslog) {
         // Show JS log menu if debug is enabled
         $dev_entries[] = array('separator' => true);
         $dev_entries['jslog'] = array('text' => T_('JS log'), 'title' => T_('JS log'), 'class' => 'jslog_switcher');
     }
     if (!empty($dev_entries)) {
         // Add Dev menu if at least one entry is should be displayed
         $entries['dev'] = array('href' => $admin_url . '#', 'text' => '<span class="fa fa-wrench"></span> Dev', 'entries' => $dev_entries);
     }
     // User menu:
     $current_user_Group = $current_User->get_Group();
     $userprefs_entries = array('name' => array('text' => $current_User->get_avatar_imgtag('crop-top-32x32', '', 'left') . '&nbsp;' . $current_User->get_preferred_name() . '<br />&nbsp;<span class="note">' . $current_user_Group->get_name() . '</span>', 'href' => get_user_profile_url()));
     $userprefs_entries[] = array('separator' => true);
     $user_profile_url = get_user_profile_url();
     if (!empty($user_profile_url)) {
         // Display this menu item only when url is available to current user
         $userprefs_entries['profile'] = array('text' => T_('Edit your profile') . '&hellip;', 'href' => $user_profile_url);
     }
     $user_avatar_url = get_user_avatar_url();
     if (!empty($user_avatar_url)) {
         // Display this menu item only when url is available to current user
         $userprefs_entries['avatar'] = array('text' => T_('Your profile picture') . '&hellip;', 'href' => $user_avatar_url);
     }
     $user_pwdchange_url = get_user_pwdchange_url();
     if (!empty($user_pwdchange_url)) {
         // Display this menu item only when url is available to current user
         $userprefs_entries['pwdchange'] = array('text' => T_('Change password') . '&hellip;', 'href' => $user_pwdchange_url);
     }
     $user_preferences_url = get_user_preferences_url();
     if (!empty($user_preferences_url)) {
         // Display this menu item only when url is available to current user
         $userprefs_entries['userprefs'] = array('text' => T_('Preferences') . '&hellip;', 'href' => $user_preferences_url);
     }
     $user_subs_url = get_user_subs_url();
     if (!empty($user_subs_url)) {
         // Display this menu item only when url is available to current user
         $userprefs_entries['subs'] = array('text' => T_('Notifications') . '&hellip;', 'href' => $user_subs_url);
     }
     $entries['userprefs'] = array('text' => '<strong>' . $current_User->get_colored_login(array('login_text' => 'name')) . '</strong>', 'href' => get_user_profile_url(), 'entries' => $userprefs_entries);
     $entries['time'] = array('text' => date(locale_shorttimefmt(), $localtimenow), 'disabled' => true, 'entry_class' => 'rwdhide');
     if ($current_User->check_perm('admin', 'normal') && $current_User->check_perm('options', 'view')) {
         // Make time as link to Timezone settings if permission
         $entries['time']['disabled'] = false;
         $entries['time']['href'] = $admin_url . '?ctrl=time';
     }
     // ADMIN SKINS:
     if ($is_admin_page) {
         $admin_skins = get_admin_skins();
         if (count($admin_skins) > 1) {
             // We have several admin skins available: display switcher:
             $entries['userprefs']['entries']['admskins'] = array('text' => T_('Admin skin'));
             $redirect_to = rawurlencode(regenerate_url('', '', '', '&'));
             foreach ($admin_skins as $admin_skin) {
                 $entries['userprefs']['entries']['admskins']['entries'][$admin_skin] = array('text' => $admin_skin, 'href' => $admin_url . '?ctrl=users&amp;action=change_admin_skin&amp;new_admin_skin=' . rawurlencode($admin_skin) . '&amp;redirect_to=' . $redirect_to);
             }
         }
     }
     $entries['userprefs']['entries'][] = array('separator' => true);
     $entries['userprefs']['entries']['logout'] = array('text' => T_('Log out!'), 'href' => get_user_logout_url());
     $topright_Menu->add_menu_entries(NULL, $entries);
 }
function get_online_users_func()
{
    global $db, $auth, $config, $user, $phpbb_root_path;
    $user->setup('memberlist');
    // Get and set some variables
    $mode = '';
    $session_id = '';
    $start = 0;
    $sort_key = 'b';
    $sort_dir = 'd';
    $show_guests = 0;
    if (!$user->data['is_registered']) {
        trigger_error('LOGIN_EXPLAIN_VIEWONLINE');
    }
    if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel')) {
        trigger_error('NO_VIEW_USERS');
    }
    $sort_key_sql = array('a' => 'u.username_clean', 'b' => 's.session_time', 'c' => 's.session_page');
    $order_by = $sort_key_sql[$sort_key] . ' ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
    // Forum info
    $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
        FROM ' . FORUMS_TABLE . '
        ORDER BY left_id ASC';
    $result = $db->sql_query($sql, 600);
    $forum_data = array();
    while ($row = $db->sql_fetchrow($result)) {
        $forum_data[$row['forum_id']] = $row;
    }
    $db->sql_freeresult($result);
    $guest_counter = 0;
    // Get number of online guests (if we do not display them)
    if (!$show_guests) {
        switch ($db->sql_layer) {
            case 'sqlite':
                $sql = 'SELECT COUNT(session_ip) as num_guests
                    FROM (
                        SELECT DISTINCT session_ip
                            FROM ' . SESSIONS_TABLE . '
                            WHERE session_user_id = ' . ANONYMOUS . '
                                AND session_time >= ' . (time() - $config['load_online_time'] * 60) . ')';
                break;
            default:
                $sql = 'SELECT COUNT(DISTINCT session_ip) as num_guests
                    FROM ' . SESSIONS_TABLE . '
                    WHERE session_user_id = ' . ANONYMOUS . '
                        AND session_time >= ' . (time() - $config['load_online_time'] * 60);
                break;
        }
        $result = $db->sql_query($sql);
        $guest_counter = (int) $db->sql_fetchfield('num_guests');
        $db->sql_freeresult($result);
    }
    // Get user list
    $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_type, u.user_avatar, u.user_avatar_type, s.session_id, s.session_time, s.session_page, s.session_ip, s.session_browser, s.session_viewonline, s.session_forum_id
        FROM ' . USERS_TABLE . ' u, ' . SESSIONS_TABLE . ' s
        WHERE u.user_id = s.session_user_id
            AND s.session_time >= ' . (time() - $config['load_online_time'] * 60) . (!$show_guests ? ' AND s.session_user_id <> ' . ANONYMOUS : '') . '
        ORDER BY ' . $order_by;
    $result = $db->sql_query($sql);
    $prev_id = $prev_ip = $user_list = array();
    $logged_visible_online = $logged_hidden_online = $counter = 0;
    while ($row = $db->sql_fetchrow($result)) {
        if ($row['user_id'] != ANONYMOUS && !isset($prev_id[$row['user_id']])) {
            $view_online = $s_user_hidden = false;
            if (!$row['session_viewonline']) {
                $view_online = $auth->acl_get('u_viewonline') ? true : false;
                $logged_hidden_online++;
                $s_user_hidden = true;
            } else {
                $view_online = true;
                $logged_visible_online++;
            }
            $prev_id[$row['user_id']] = 1;
            if ($view_online) {
                $counter++;
            }
            if (!$view_online || $counter > $start + 100 || $counter <= $start) {
                continue;
            }
        } else {
            if ($show_guests && $row['user_id'] == ANONYMOUS && !isset($prev_ip[$row['session_ip']])) {
                $prev_ip[$row['session_ip']] = 1;
                $guest_counter++;
                $counter++;
                if ($counter > $start + 100 || $counter <= $start) {
                    continue;
                }
                $s_user_hidden = false;
            } else {
                continue;
            }
        }
        preg_match('#^([a-z0-9/_-]+)#i', $row['session_page'], $on_page);
        if (!sizeof($on_page)) {
            $on_page[1] = '';
        }
        if (file_exists($phpbb_root_path . $config['tapatalkdir'] . '/include/online_hook.php')) {
            include $phpbb_root_path . $config['tapatalkdir'] . '/include/online_hook.php';
        }
        switch ($on_page[1]) {
            case 'index':
                $location = $user->lang['INDEX'];
                $location_url = append_sid("{$phpbb_root_path}index.{$phpEx}");
                break;
            case 'adm/index':
                $location = $user->lang['ACP'];
                $location_url = append_sid("{$phpbb_root_path}index.{$phpEx}");
                break;
            case 'posting':
            case 'viewforum':
            case 'viewtopic':
                $forum_id = $row['session_forum_id'];
                if ($forum_id && $auth->acl_get('f_list', $forum_id)) {
                    $location = '';
                    $location_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id);
                    if ($forum_data[$forum_id]['forum_type'] == FORUM_LINK) {
                        $location = sprintf($user->lang['READING_LINK'], $forum_data[$forum_id]['forum_name']);
                        break;
                    }
                    switch ($on_page[1]) {
                        case 'posting':
                            preg_match('#mode=([a-z]+)#', $row['session_page'], $on_page);
                            $posting_mode = !empty($on_page[1]) ? $on_page[1] : '';
                            switch ($posting_mode) {
                                case 'reply':
                                case 'quote':
                                    $location = sprintf($user->lang['REPLYING_MESSAGE'], $forum_data[$forum_id]['forum_name']);
                                    break;
                                default:
                                    $location = sprintf($user->lang['POSTING_MESSAGE'], $forum_data[$forum_id]['forum_name']);
                                    break;
                            }
                            break;
                        case 'viewtopic':
                            $location = sprintf($user->lang['READING_TOPIC'], $forum_data[$forum_id]['forum_name']);
                            break;
                        case 'viewforum':
                            $location = sprintf($user->lang['READING_FORUM'], $forum_data[$forum_id]['forum_name']);
                            break;
                    }
                } else {
                    $location = $user->lang['INDEX'];
                    $location_url = append_sid("{$phpbb_root_path}index.{$phpEx}");
                }
                break;
            case 'search':
                $location = $user->lang['SEARCHING_FORUMS'];
                $location_url = append_sid("{$phpbb_root_path}search.{$phpEx}");
                break;
            case 'faq':
                $location = $user->lang['VIEWING_FAQ'];
                $location_url = append_sid("{$phpbb_root_path}faq.{$phpEx}");
                break;
            case 'viewonline':
                $location = $user->lang['VIEWING_ONLINE'];
                $location_url = append_sid("{$phpbb_root_path}viewonline.{$phpEx}");
                break;
            case 'memberlist':
                $location = strpos($row['session_page'], 'mode=viewprofile') !== false ? $user->lang['VIEWING_MEMBER_PROFILE'] : $user->lang['VIEWING_MEMBERS'];
                $location_url = append_sid("{$phpbb_root_path}memberlist.{$phpEx}");
                break;
            case 'mcp':
                $location = $user->lang['VIEWING_MCP'];
                $location_url = append_sid("{$phpbb_root_path}index.{$phpEx}");
                break;
            case 'ucp':
                $location = $user->lang['VIEWING_UCP'];
                // Grab some common modules
                $url_params = array('mode=register' => 'VIEWING_REGISTER', 'i=pm&mode=compose' => 'POSTING_PRIVATE_MESSAGE', 'i=pm&' => 'VIEWING_PRIVATE_MESSAGES', 'i=profile&' => 'CHANGING_PROFILE', 'i=prefs&' => 'CHANGING_PREFERENCES');
                foreach ($url_params as $param => $lang) {
                    if (strpos($row['session_page'], $param) !== false) {
                        $location = $user->lang[$lang];
                        break;
                    }
                }
                $location_url = append_sid("{$phpbb_root_path}index.{$phpEx}");
                break;
            case 'download/file':
                $location = $user->lang['DOWNLOADING_FILE'];
                $location_url = append_sid("{$phpbb_root_path}index.{$phpEx}");
                break;
            case 'report':
                $location = $user->lang['REPORTING_POST'];
                $location_url = append_sid("{$phpbb_root_path}index.{$phpEx}");
                break;
            default:
                $location = $user->lang['INDEX'];
                $location_url = append_sid("{$phpbb_root_path}index.{$phpEx}");
                break;
        }
        $user_avatar_url = get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']);
        $row['from'] = 'broswer';
        if (!empty($row['is_tapatalk'])) {
            $row['from'] = 'tapatalk';
        } else {
            if (!empty($row['is_byo'])) {
                $row['from'] = 'byo';
            } else {
                if (strpos($row['session_browser'], 'Android') !== false || strpos($row['session_browser'], 'iPhone') !== false || strpos($row['session_browser'], 'BlackBerry') !== false) {
                    $row['from'] = 'mobile';
                }
            }
        }
        $user_list[] = new xmlrpcval(array('user_id' => new xmlrpcval($row['user_id'], 'string'), 'username' => new xmlrpcval(basic_clean($row['username']), 'base64'), 'from' => new xmlrpcval($row['from'], 'string'), 'user_type' => check_return_user_type($row['username']), 'user_name' => new xmlrpcval($row['username'], 'base64'), 'icon_url' => new xmlrpcval($user_avatar_url), 'display_text' => new xmlrpcval($location, 'base64')), 'struct');
    }
    $db->sql_freeresult($result);
    unset($prev_id, $prev_ip);
    $online_users = array('member_count' => new xmlrpcval($logged_visible_online, 'int'), 'guest_count' => new xmlrpcval($guest_counter, 'int'), 'list' => new xmlrpcval($user_list, 'array'));
    $response = new xmlrpcval($online_users, 'struct');
    return new xmlrpcresp($response);
}
function get_user_info_func($xmlrpc_params)
{
    global $db, $user, $auth, $template, $config, $phpbb_root_path, $phpEx, $table_prefix;
    $user->setup(array('memberlist', 'groups'));
    if (!$auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel')) {
        if ($user->data['user_id'] != ANONYMOUS) {
            trigger_error('NO_VIEW_USERS');
        }
        trigger_error('LOGIN_EXPLAIN_VIEWPROFILE');
    }
    $params = php_xmlrpc_decode($xmlrpc_params);
    $username = $params[0];
    if (isset($params[1]) && !empty($params[1])) {
        $user_id = $params[1];
    } elseif (isset($params[0]) && !empty($params[0])) {
        $username = $params[0];
        $user_id = get_user_id_by_name($username);
    } else {
        $user_id = $user->data['user_id'];
    }
    $user_id = intval($user_id);
    // Display a profile
    if (!$user_id) {
        trigger_error('NO_USER');
    }
    // Get user...
    $sql = 'SELECT *
        FROM ' . USERS_TABLE . "\r\r\n        WHERE user_id = '{$user_id}'";
    $result = $db->sql_query($sql);
    $member = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    if (!$member) {
        trigger_error('NO_USER');
    }
    // a_user admins and founder are able to view inactive users and bots to be able to manage them more easily
    // Normal users are able to see at least users having only changed their profile settings but not yet reactivated.
    if (!$auth->acl_get('a_user') && $user->data['user_type'] != USER_FOUNDER) {
        if ($member['user_type'] == USER_IGNORE) {
            trigger_error('NO_USER');
        } else {
            if ($member['user_type'] == USER_INACTIVE && $member['user_inactive_reason'] != INACTIVE_PROFILE) {
                trigger_error('NO_USER');
            }
        }
    }
    $user_id = (int) $member['user_id'];
    // Do the SQL thang
    $sql = 'SELECT g.group_id, g.group_name, g.group_type
        FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug\r\r\n        WHERE ug.user_id = {$user_id}\r\r\n            AND g.group_id = ug.group_id" . (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') ? ' AND g.group_type <> ' . GROUP_HIDDEN : '') . '
            AND ug.user_pending = 0
        ORDER BY g.group_type, g.group_name';
    $result = $db->sql_query($sql);
    $group_options = '';
    while ($row = $db->sql_fetchrow($result)) {
        if ($row['group_type'] == GROUP_SPECIAL) {
            // Lookup group name in language dictionary
            if (isset($user->lang['G_' . $row['group_name']])) {
                $row['group_name'] = $user->lang['G_' . $row['group_name']];
            }
        } else {
            if (!$auth_hidden_groups && $row['group_type'] == GROUP_HIDDEN && !isset($user_groups[$row['group_id']])) {
                // Skip over hidden groups the user cannot see
                continue;
            }
        }
        $group_options .= $row['group_id'] == $member['group_id'] ? $row['group_name'] . " *\n" : $row['group_name'] . "\n";
    }
    $group_options = trim($group_options);
    $db->sql_freeresult($result);
    // What colour is the zebra
    $sql = 'SELECT friend, foe
        FROM ' . ZEBRA_TABLE . "\r\r\n        WHERE zebra_id = {$user_id}\r\r\n            AND user_id = {$user->data['user_id']}";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $foe = $row['foe'] ? true : false;
    $friend = $row['friend'] ? true : false;
    $db->sql_freeresult($result);
    if ($config['load_onlinetrack']) {
        if ($config['version'] < '3.0.3') {
            $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline, session_page
            FROM ' . SESSIONS_TABLE . "\r\r\n            WHERE session_user_id = {$user_id}\r\r\n            GROUP BY session_page\r\r\n            ORDER BY session_time DESC";
        } else {
            $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline, session_page, session_forum_id
            FROM ' . SESSIONS_TABLE . "\r\r\n            WHERE session_user_id = {$user_id}\r\r\n            GROUP BY session_page, session_forum_id\r\r\n            ORDER BY session_time DESC";
        }
        $result = $db->sql_query_limit($sql, 1);
        $row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        $member['session_time'] = isset($row['session_time']) ? $row['session_time'] : 0;
        $member['session_viewonline'] = isset($row['session_viewonline']) ? $row['session_viewonline'] : 0;
        $member['session_page'] = isset($row['session_page']) ? $row['session_page'] : 0;
        $member['session_forum_id'] = isset($row['session_forum_id']) ? $row['session_forum_id'] : 0;
        unset($row);
    }
    if ($config['load_user_activity']) {
        display_user_activity($member);
    }
    // Do the relevant calculations
    $memberdays = max(1, round((time() - $member['user_regdate']) / 86400));
    $posts_per_day = $member['user_posts'] / $memberdays;
    $percentage = $config['num_posts'] ? min(100, $member['user_posts'] / $config['num_posts'] * 100) : 0;
    if ($member['user_sig']) {
        $member['user_sig'] = censor_text($member['user_sig']);
        if ($member['user_sig_bbcode_bitfield']) {
            include_once $phpbb_root_path . 'includes/bbcode.' . $phpEx;
            $bbcode = new bbcode();
            $bbcode->bbcode_second_pass($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield']);
        }
        $member['user_sig'] = bbcode_nl2br($member['user_sig']);
        $member['user_sig'] = smiley_text($member['user_sig']);
    }
    $poster_avatar = get_user_avatar($member['user_avatar'], $member['user_avatar_type'], $member['user_avatar_width'], $member['user_avatar_height']);
    // We need to check if the modules 'zebra' ('friends' & 'foes' mode),  'notes' ('user_notes' mode) and  'warn' ('warn_user' mode) are accessible to decide if we can display appropriate links
    $zebra_enabled = $friends_enabled = $foes_enabled = $user_notes_enabled = $warn_user_enabled = false;
    // Only check if the user is logged in
    if ($user->data['is_registered']) {
        if (!class_exists('p_master')) {
            include $phpbb_root_path . 'includes/functions_module.' . $phpEx;
        }
        $module = new p_master();
        $module->list_modules('ucp');
        $module->list_modules('mcp');
        $user_notes_enabled = $module->loaded('notes', 'user_notes') ? true : false;
        $warn_user_enabled = $module->loaded('warn', 'warn_user') ? true : false;
        $zebra_enabled = $module->loaded('zebra') ? true : false;
        $friends_enabled = $module->loaded('zebra', 'friends') ? true : false;
        $foes_enabled = $module->loaded('zebra', 'foes') ? true : false;
        unset($module);
    }
    $template->assign_vars(show_profile($member, $user_notes_enabled, $warn_user_enabled));
    // Custom Profile Fields
    $profile_fields = array();
    if ($config['load_cpf_viewprofile']) {
        include_once $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx;
        $cp = new custom_profile();
        $profile_fields = $cp->generate_profile_fields_template('grab', $user_id);
        $profile_fields = isset($profile_fields[$user_id]) ? $cp->generate_profile_fields_template('show', false, $profile_fields[$user_id]) : array();
    }
    // If the user has m_approve permission or a_user permission, then list then display unapproved posts
    if ($auth->acl_getf_global('m_approve') || $auth->acl_get('a_user')) {
        $sql = 'SELECT COUNT(post_id) as posts_in_queue
            FROM ' . POSTS_TABLE . '
            WHERE poster_id = ' . $user_id . '
                AND post_approved = 0';
        $result = $db->sql_query($sql);
        $member['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
        $db->sql_freeresult($result);
    } else {
        $member['posts_in_queue'] = 0;
    }
    $template->assign_vars(array('OCCUPATION' => !empty($member['user_occ']) ? censor_text($member['user_occ']) : '', 'INTERESTS' => !empty($member['user_interests']) ? censor_text($member['user_interests']) : '', 'SIGNATURE' => $member['user_sig'], 'POSTS_IN_QUEUE' => $member['posts_in_queue'], 'AVATAR_IMG' => $poster_avatar, 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE']), 'EMAIL_IMG' => $user->img('icon_contact_email', $user->lang['EMAIL']), 'WWW_IMG' => $user->img('icon_contact_www', $user->lang['WWW']), 'ICQ_IMG' => $user->img('icon_contact_icq', $user->lang['ICQ']), 'AIM_IMG' => $user->img('icon_contact_aim', $user->lang['AIM']), 'MSN_IMG' => $user->img('icon_contact_msnm', $user->lang['MSNM']), 'YIM_IMG' => $user->img('icon_contact_yahoo', $user->lang['YIM']), 'JABBER_IMG' => $user->img('icon_contact_jabber', $user->lang['JABBER']), 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']), 'S_PROFILE_ACTION' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=group'), 'S_GROUP_OPTIONS' => $group_options, 'S_CUSTOM_FIELDS' => isset($profile_fields['row']) && sizeof($profile_fields['row']) ? true : false, 'U_USER_ADMIN' => $auth->acl_get('a_user') ? append_sid("{$phpbb_root_path}adm/index.{$phpEx}", 'i=users&amp;mode=overview&amp;u=' . $user_id, true, $user->session_id) : '', 'U_USER_BAN' => $auth->acl_get('m_ban') && $user_id != $user->data['user_id'] ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=ban&amp;mode=user&amp;u=' . $user_id, true, $user->session_id) : '', 'U_MCP_QUEUE' => $auth->acl_getf_global('m_approve') ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue', true, $user->session_id) : '', 'S_USER_NOTES' => $user_notes_enabled ? true : false, 'S_WARN_USER' => $warn_user_enabled ? true : false, 'S_ZEBRA' => $user->data['user_id'] != $user_id && $user->data['is_registered'] && $zebra_enabled ? true : false, 'U_ADD_FRIEND' => !$friend && !$foe && $friends_enabled ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=zebra&amp;add=' . urlencode(htmlspecialchars_decode($member['username']))) : '', 'U_ADD_FOE' => !$friend && !$foe && $foes_enabled ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=zebra&amp;mode=foes&amp;add=' . urlencode(htmlspecialchars_decode($member['username']))) : '', 'U_REMOVE_FRIEND' => $friend && $friends_enabled ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=zebra&amp;remove=1&amp;usernames[]=' . $user_id) : '', 'U_REMOVE_FOE' => $foe && $foes_enabled ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=zebra&amp;remove=1&amp;mode=foes&amp;usernames[]=' . $user_id) : ''));
    if (!empty($profile_fields['row'])) {
        $template->assign_vars($profile_fields['row']);
    }
    if (!empty($profile_fields['blockrow'])) {
        foreach ($profile_fields['blockrow'] as $field_data) {
            $template->assign_block_vars('custom_fields', $field_data);
        }
    }
    // Inactive reason/account?
    if ($member['user_type'] == USER_INACTIVE) {
        $user->add_lang('acp/common');
        $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
        switch ($member['user_inactive_reason']) {
            case INACTIVE_REGISTER:
                $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
                break;
            case INACTIVE_PROFILE:
                $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
                break;
            case INACTIVE_MANUAL:
                $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
                break;
            case INACTIVE_REMIND:
                $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
                break;
        }
        $template->assign_vars(array('S_USER_INACTIVE' => true, 'USER_INACTIVE_REASON' => $inactive_reason));
    }
    $custom_fields_list = get_custom_fields();
    if (!empty($member['user_sig'])) {
        $custom_fields_list[] = new xmlrpcval(array('name' => new xmlrpcval($user->lang['SIGNATURE'], 'base64'), 'value' => new xmlrpcval(basic_clean($member['user_sig']), 'base64')), 'struct');
    }
    if ($member['user_id'] == $user->data['user_id'] && push_table_exists()) {
        $sql = "SELECT * FROM " . $table_prefix . "tapatalk_users WHERE userid = '" . $member['user_id'] . "'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        if (!empty($row)) {
            array_push($custom_fields_list, new xmlrpcval(array('name' => new xmlrpcval('Notification - Message', 'base64'), 'value' => new xmlrpcval($row['pm'] ? 'On' : 'Off', 'base64')), 'struct'));
            array_push($custom_fields_list, new xmlrpcval(array('name' => new xmlrpcval('Notification - Quoted', 'base64'), 'value' => new xmlrpcval($row['quote'] ? 'On' : 'Off', 'base64')), 'struct'));
            array_push($custom_fields_list, new xmlrpcval(array('name' => new xmlrpcval('Notification - Mentioned', 'base64'), 'value' => new xmlrpcval($row['tag'] ? 'On' : 'Off', 'base64')), 'struct'));
            array_push($custom_fields_list, new xmlrpcval(array('name' => new xmlrpcval('Notification - New Topic', 'base64'), 'value' => new xmlrpcval($row['newtopic'] ? 'On' : 'Off', 'base64')), 'struct'));
            array_push($custom_fields_list, new xmlrpcval(array('name' => new xmlrpcval('Notification - Replies', 'base64'), 'value' => new xmlrpcval($row['subscribe'] ? 'On' : 'Off', 'base64')), 'struct'));
        }
    }
    $user_avatar_url = get_user_avatar_url($member['user_avatar'], $member['user_avatar_type']);
    // Forum info
    $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
        FROM ' . FORUMS_TABLE . '
        ORDER BY left_id ASC';
    $result = $db->sql_query($sql, 600);
    $forum_data = array();
    while ($row = $db->sql_fetchrow($result)) {
        $forum_data[$row['forum_id']] = $row;
    }
    $db->sql_freeresult($result);
    // get user current activity
    preg_match('#^([a-z0-9/_-]+)#i', $member['session_page'], $on_page);
    if (!sizeof($on_page)) {
        $on_page[1] = '';
    }
    switch ($on_page[1]) {
        case 'index':
            $location = $user->lang['INDEX'];
            break;
        case 'adm/index':
            $location = $user->lang['ACP'];
            break;
        case 'posting':
        case 'viewforum':
        case 'viewtopic':
            $forum_id = $member['session_forum_id'];
            if ($forum_id && $auth->acl_get('f_list', $forum_id)) {
                $location = '';
                if ($forum_data[$forum_id]['forum_type'] == FORUM_LINK) {
                    $location = sprintf($user->lang['READING_LINK'], $forum_data[$forum_id]['forum_name']);
                    break;
                }
                switch ($on_page[1]) {
                    case 'posting':
                        preg_match('#mode=([a-z]+)#', $member['session_page'], $on_page);
                        $posting_mode = !empty($on_page[1]) ? $on_page[1] : '';
                        switch ($posting_mode) {
                            case 'reply':
                            case 'quote':
                                $location = sprintf($user->lang['REPLYING_MESSAGE'], $forum_data[$forum_id]['forum_name']);
                                break;
                            default:
                                $location = sprintf($user->lang['POSTING_MESSAGE'], $forum_data[$forum_id]['forum_name']);
                                break;
                        }
                        break;
                    case 'viewtopic':
                        $location = sprintf($user->lang['READING_TOPIC'], $forum_data[$forum_id]['forum_name']);
                        break;
                    case 'viewforum':
                        $location = sprintf($user->lang['READING_FORUM'], $forum_data[$forum_id]['forum_name']);
                        break;
                }
            } else {
                $location = $user->lang['INDEX'];
            }
            break;
        case 'search':
            $location = $user->lang['SEARCHING_FORUMS'];
            break;
        case 'faq':
            $location = $user->lang['VIEWING_FAQ'];
            break;
        case 'viewonline':
            $location = $user->lang['VIEWING_ONLINE'];
            break;
        case 'memberlist':
            $location = strpos($member['session_page'], 'mode=viewprofile') !== false ? $user->lang['VIEWING_MEMBER_PROFILE'] : $user->lang['VIEWING_MEMBERS'];
            break;
        case 'mcp':
            $location = $user->lang['VIEWING_MCP'];
            break;
        case 'ucp':
            $location = $user->lang['VIEWING_UCP'];
            // Grab some common modules
            $url_params = array('mode=register' => 'VIEWING_REGISTER', 'i=pm&mode=compose' => 'POSTING_PRIVATE_MESSAGE', 'i=pm&' => 'VIEWING_PRIVATE_MESSAGES', 'i=profile&' => 'CHANGING_PROFILE', 'i=prefs&' => 'CHANGING_PREFERENCES');
            foreach ($url_params as $param => $lang) {
                if (strpos($member['session_page'], $param) !== false) {
                    $location = $user->lang[$lang];
                    break;
                }
            }
            break;
        case 'download/file':
            $location = $user->lang['DOWNLOADING_FILE'];
            break;
        case 'report':
            $location = $user->lang['REPORTING_POST'];
            break;
        case 'mobiquo/mobiquo':
            $location = 'On Tapatalk';
            break;
        default:
            $location = $user->lang['INDEX'];
            break;
    }
    $user_info = array('user_id' => new xmlrpcval($member['user_id']), 'username' => new xmlrpcval(basic_clean($member['username']), 'base64'), 'user_type' => check_return_user_type($member['username']), 'post_count' => new xmlrpcval($member['user_posts'], 'int'), 'reg_time' => new xmlrpcval(mobiquo_iso8601_encode($member['user_regdate']), 'dateTime.iso8601'), 'timestamp_reg' => new xmlrpcval($member['user_regdate'], 'string'), 'last_activity_time' => new xmlrpcval(mobiquo_iso8601_encode($template->_rootref['VISITED']), 'dateTime.iso8601'), 'timestamp' => new xmlrpcval($template->_rootref['VISITED'], 'string'), 'is_online' => new xmlrpcval($template->_rootref['S_ONLINE'], 'boolean'), 'accept_pm' => new xmlrpcval($template->_rootref['U_PM'] ? true : false, 'boolean'), 'display_text' => new xmlrpcval('', 'base64'), 'icon_url' => new xmlrpcval($user_avatar_url), 'current_activity' => new xmlrpcval($location, 'base64'), 'custom_fields_list' => new xmlrpcval($custom_fields_list, 'array'));
    $xmlrpc_user_info = new xmlrpcval($user_info, 'struct');
    return new xmlrpcresp($xmlrpc_user_info);
}
function tt_login_success()
{
    global $config, $db, $user, $phpbb_root_path, $phpEx, $user_info, $auth, $register;
    header('Set-Cookie: mobiquo_a=0');
    header('Set-Cookie: mobiquo_b=0');
    header('Set-Cookie: mobiquo_c=0');
    $result = $user->session_create($user_info['user_id'], 0, true, 1);
    if ($result) {
        $usergroup_id = array();
        $auth->acl($user->data);
        //add tapatalk_users here,for push service
        if (push_table_exists()) {
            global $table_prefix;
            $sql = "SELECT * FROM " . $table_prefix . "tapatalk_users where userid = '" . $user->data['user_id'] . "'";
            $result = $db->sql_query($sql);
            $userInfo = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            $time = time();
            if (empty($userInfo)) {
                $sql_data[$table_prefix . "tapatalk_users"]['sql'] = array('userid' => $user->data['user_id'], 'announcement' => 1, 'pm' => 1, 'subscribe' => 1, 'quote' => 1, 'tag' => 1, 'newtopic' => 1, 'updated' => time());
                $sql = 'INSERT INTO ' . $table_prefix . "tapatalk_users" . ' ' . $db->sql_build_array('INSERT', $sql_data[$table_prefix . "tapatalk_users"]['sql']);
                $db->sql_query($sql);
            }
        }
        // Compatibility with mod NV who was here
        if (file_exists($phpbb_root_path . 'includes/mods/who_was_here.' . $phpEx)) {
            include_once $phpbb_root_path . 'includes/mods/who_was_here.' . $phpEx;
            if (class_exists('phpbb_mods_who_was_here') && method_exists('phpbb_mods_who_was_here', 'update_session')) {
                @phpbb_mods_who_was_here::update_session();
            }
        }
        if ($config['max_attachments'] == 0) {
            $config['max_attachments'] = 100;
        }
        $usergroup_id[] = new xmlrpcval($user->data['group_id']);
        $can_readpm = $config['allow_privmsg'] && $auth->acl_get('u_readpm') && ($user->data['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'));
        $can_sendpm = $config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($user->data['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'));
        $can_upload = $config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && (function_exists('phpbb_is_writable') ? phpbb_is_writable($phpbb_root_path . $config['avatar_path']) : 1) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false;
        $can_search = $auth->acl_get('u_search') && $auth->acl_getf_global('f_search') && $config['load_search'];
        $can_whosonline = $auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel');
        $max_filesize = $config['max_filesize'] === '0' || $config['max_filesize'] > 10485760 ? 10485760 : $config['max_filesize'];
        $userPushType = array('pm' => 1, 'newtopic' => 1, 'sub' => 1, 'tag' => 1, 'quote' => 1);
        $push_type = array();
        foreach ($userPushType as $name => $value) {
            $push_type[] = new xmlrpcval(array('name' => new xmlrpcval($name, 'string'), 'value' => new xmlrpcval($value, 'boolean')), 'struct');
        }
        $response = new xmlrpcval(array('result' => new xmlrpcval(true, 'boolean'), 'user_id' => new xmlrpcval($user->data['user_id'], 'string'), 'username' => new xmlrpcval(basic_clean($user->data['username']), 'base64'), 'email' => new xmlrpcval($user->data['user_email'], 'base64'), 'user_type' => check_return_user_type($user->data['username']), 'usergroup_id' => new xmlrpcval($usergroup_id, 'array'), 'ignored_uids' => new xmlrpcval(implode(',', tt_get_ignore_users($user->data['user_id'])), 'string'), 'icon_url' => new xmlrpcval(get_user_avatar_url($user->data['user_avatar'], $user->data['user_avatar_type']), 'string'), 'post_count' => new xmlrpcval($user->data['user_posts'], 'int'), 'can_pm' => new xmlrpcval($can_readpm, 'boolean'), 'can_send_pm' => new xmlrpcval($can_sendpm, 'boolean'), 'can_moderate' => new xmlrpcval($auth->acl_get('m_') || $auth->acl_getf_global('m_'), 'boolean'), 'max_attachment' => new xmlrpcval($config['max_attachments'], 'int'), 'max_png_size' => new xmlrpcval($max_filesize, 'int'), 'max_jpg_size' => new xmlrpcval($max_filesize, 'int'), 'can_search' => new xmlrpcval($can_search, 'boolean'), 'can_whosonline' => new xmlrpcval($can_whosonline, 'boolean'), 'can_upload_avatar' => new xmlrpcval($can_upload, 'boolean'), 'register' => new xmlrpcval($register, "boolean"), 'push_type' => new xmlrpcval($push_type, 'array')), 'struct');
        return new xmlrpcresp($response);
    }
}
 /**
  * Display the widget!
  *
  * @param array MUST contain at least the basic display params
  */
 function display($params)
 {
     /**
      * @var Blog
      */
     global $Blog;
     global $disp;
     $this->init_display($params);
     // Default link class
     $link_class = $this->disp_params['link_default_class'];
     switch ($this->disp_params['link_type']) {
         case 'search':
             $url = $Blog->get('searchurl');
             $text = T_('Search');
             // Is this the current display?
             if ($disp == 'search') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'arcdir':
             $url = $Blog->get('arcdirurl');
             $text = T_('Archives');
             if ($disp == 'arcdir') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'catdir':
             $url = $Blog->get('catdirurl');
             $text = T_('Categories');
             if ($disp == 'catdir') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'postidx':
             $url = $Blog->get('postidxurl');
             $text = T_('Post index');
             if ($disp == 'postidx') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'mediaidx':
             $url = $Blog->get('mediaidxurl');
             $text = T_('Photo index');
             if ($disp == 'mediaidx') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'sitemap':
             $url = $Blog->get('sitemapurl');
             $text = T_('Site map');
             if ($disp == 'sitemap') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'latestcomments':
             if (!$Blog->get_setting('comments_latest')) {
                 // This page is disabled
                 return false;
             }
             $url = $Blog->get('lastcommentsurl');
             $text = T_('Latest comments');
             if ($disp == 'comments') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'owneruserinfo':
             $url = url_add_param($Blog->get('userurl'), 'user_ID=' . $Blog->owner_user_ID);
             $text = T_('Owner details');
             // Is this the current display?
             global $User;
             if ($disp == 'user' && !empty($User) && $User->ID == $Blog->owner_user_ID) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'ownercontact':
             if (!($url = $Blog->get_contact_url(true))) {
                 // user does not allow contact form:
                 return;
             }
             $text = T_('Contact');
             // Is this the current display?
             if ($disp == 'msgform') {
                 // Let's display the link as selected
                 // fp> I think it's interesting to select this link , even if the recipient ID is different from the owner
                 // odds are there is no other link to highlight in this case
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'login':
             if (is_logged_in()) {
                 return false;
             }
             $url = get_login_url('menu link');
             if (isset($this->BlockCache)) {
                 // Do NOT cache because some of these links are using a redirect_to param, which makes it page dependent.
                 // so this will be cached by the PageCache; there is no added benefit to cache it in the BlockCache
                 // (which could have been shared between several pages):
                 $this->BlockCache->abort_collect();
             }
             $text = T_('Log in');
             // Is this the current display?
             if ($disp == 'login') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'register':
             if (!($url = get_user_register_url(NULL, 'menu link'))) {
                 return false;
             }
             if (isset($this->BlockCache)) {
                 // Do NOT cache because some of these links are using a redirect_to param, which makes it page dependent.
                 // Note: also beware of the source param.
                 // so this will be cached by the PageCache; there is no added benefit to cache it in the BlockCache
                 // (which could have been shared between several pages):
                 $this->BlockCache->abort_collect();
             }
             $text = T_('Register');
             // Is this the current display?
             if ($disp == 'register') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'profile':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_profile_url();
             $text = T_('Edit profile');
             // Is this the current display?  (Edit my Profile)
             if (in_array($disp, array('profile', 'avatar', 'pwdchange', 'userprefs', 'subs'))) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'avatar':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_avatar_url();
             $text = T_('Profile picture');
             // Note: we never highlight this, it will always highlight 'profile' instead
             break;
         case 'users':
             global $Settings;
             if (!is_logged_in() && !$Settings->get('allow_anonymous_user_list')) {
                 // Don't allow anonymous users to see users list
                 return false;
             }
             $url = $Blog->get('usersurl');
             $text = T_('User directory');
             // Is this the current display?
             // Note: If $user_ID is not set, it means we are viewing "My Profile" instead
             global $user_ID;
             if ($disp == 'users' || $disp == 'user' && !empty($user_ID)) {
                 // Let's display the link as selected
                 // Note: we also highlight this for any user profile that is displayed
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'item':
             $ItemCache =& get_ItemCache();
             /**
              * @var Item
              */
             $item_ID = (int) $this->disp_params['item_ID'];
             $disp_Item =& $ItemCache->get_by_ID($item_ID, false, false);
             if (empty($disp_Item)) {
                 // Item not found
                 return false;
             }
             $url = $disp_Item->get_permanent_url();
             $text = $disp_Item->title;
             // Is this the current item?
             global $Item;
             if (!empty($Item) && $disp_Item->ID == $Item->ID) {
                 // The current page is currently displaying the Item this link is pointing to
                 // Let's display it as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'url':
             $url = $this->disp_params['link_href'];
             $text = '[URL]';
             // should normally be overriden below...
             // Note: we never highlight this link
             break;
         case 'postnew':
             if (!check_item_perm_create()) {
                 // Don't allow users to create a new post
                 return false;
             }
             $url = url_add_param($Blog->get('url'), 'disp=edit');
             $text = T_('Write a new post');
             // Is this the current display?
             if ($disp == 'edit') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'myprofile':
             if (!is_logged_in()) {
                 // Don't show this link for not logged in users
                 return false;
             }
             $url = url_add_param($Blog->get('url'), 'disp=user');
             $text = T_('My profile');
             // Is this the current display?  (Edit my Profile)
             global $user_ID, $current_User;
             // If $user_ID is not set, it means we will fall back to the current user, so it's ok
             // If $user_ID is set, it means we are browsing the directory instead
             if ($disp == 'user' && empty($user_ID)) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'home':
         default:
             $url = $Blog->get('url');
             $text = T_('Home');
     }
     // Override default link text?
     if (!empty($this->param_array['link_text'])) {
         // We have a custom link text:
         $text = $this->param_array['link_text'];
     }
     echo $this->disp_params['block_start'];
     echo $this->disp_params['list_start'];
     echo $this->disp_params['item_start'];
     echo '<a href="' . $url . '" class="' . $link_class . '">' . $text . '</a>';
     echo $this->disp_params['item_end'];
     echo $this->disp_params['list_end'];
     echo $this->disp_params['block_end'];
     return true;
 }
function get_topic_func($xmlrpc_params)
{
    global $db, $auth, $user, $config;
    $user->setup('viewforum');
    $params = php_xmlrpc_decode($xmlrpc_params);
    list($start, $limit) = process_page($params[1], $params[2]);
    // get forum id from parameters
    $forum_id = intval($params[0]);
    if (!$forum_id) {
        trigger_error('NO_FORUM');
    }
    // check if need sticky/announce topic only
    $topic_type = '';
    if (isset($params[3])) {
        // check if need sticky topic only
        if ($params[3] == 'TOP') {
            $topic_type = POST_STICKY;
            $start = 0;
            $limit = 20;
        } else {
            if ($params[3] == 'ANN') {
                $topic_type = POST_ANNOUNCE . ', ' . POST_GLOBAL;
                $start = 0;
                $limit = 20;
            }
        }
    }
    //    $default_sort_days  = (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0;
    //    $default_sort_key   = (!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't';
    //    $default_sort_dir   = (!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd';
    //
    //    $sort_days  = request_var('st', $default_sort_days); // default to get all topic
    //    $sort_key   = request_var('sk', $default_sort_key);  // default sort by last post time
    //    $sort_dir   = request_var('sd', $default_sort_dir);  // default sort as DESC
    $sort_days = 0;
    $sort_key = 't';
    $sort_dir = 'd';
    //------- Grab appropriate forum data --------
    $sql = "SELECT f.* FROM " . FORUMS_TABLE . " f WHERE f.forum_id = {$forum_id}";
    $result = $db->sql_query($sql);
    $forum_data = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    // Forum does not exist
    if (!$forum_data) {
        trigger_error('NO_FORUM');
    }
    // Can not get topics from link forum
    if ($forum_data['forum_type'] == FORUM_LINK) {
        trigger_error('NO_FORUM');
    }
    // Permissions check
    if (!$auth->acl_gets('f_list', 'f_read', $forum_id) || $forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'] && !$auth->acl_get('f_read', $forum_id)) {
        if ($user->data['user_id'] != ANONYMOUS) {
            trigger_error('SORRY_AUTH_READ');
        }
        trigger_error('LOGIN_VIEWFORUM');
    }
    // Forum is passworded
    if ($forum_data['forum_password'] && !check_forum_password($forum_id)) {
        trigger_error('LOGIN_FORUM');
    }
    if (!$auth->acl_get('f_read', $forum_id)) {
        trigger_error('NO_READ_ACCESS');
    }
    // Topic ordering options
    $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views');
    // Limit topics to certain time frame, obtain correct topic count
    // global announcements must not be counted, normal announcements have to
    // be counted, as forum_topics(_real) includes them
    $sql_approved = $auth->acl_get('m_approve', $forum_id) ? '' : ' AND t.topic_approved = 1 ';
    // Get all shadow topics in this forum
    $sql = 'SELECT t.topic_moved_id, t.topic_id
            FROM ' . TOPICS_TABLE . ' t
            WHERE t.forum_id = ' . $forum_id . '
            AND t.topic_type IN (' . POST_NORMAL . ', ' . POST_STICKY . ', ' . POST_ANNOUNCE . ', ' . POST_GLOBAL . ')
            AND t.topic_status = ' . ITEM_MOVED . ' ' . $sql_approved;
    $result = $db->sql_query($sql);
    $shadow_topic_list = array();
    while ($row = $db->sql_fetchrow($result)) {
        $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
    }
    $db->sql_freeresult($result);
    // Pick out those shadow topics that the user has no permission to access
    if (!empty($shadow_topic_list)) {
        $sql = 'SELECT t.topic_id, t.forum_id
                FROM ' . TOPICS_TABLE . ' t
                WHERE ' . $db->sql_in_set('t.topic_id', array_keys($shadow_topic_list));
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            if ($auth->acl_get('f_read', $row['forum_id'])) {
                unset($shadow_topic_list[$row['topic_id']]);
            }
        }
        $db->sql_freeresult($result);
    }
    // Grab all topic data
    $topic_list = array();
    $sql_limit = $limit;
    // num of topics needs to be return, default is 20, at most 50
    $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
    $sql_shadow_out = empty($shadow_topic_list) ? '' : 'AND ' . $db->sql_in_set('t.topic_moved_id', $shadow_topic_list, true);
    // If the user is trying to reach late pages, start searching from the end
    $store_reverse = false;
    $unread_sticky_num = $unread_announce_count = 0;
    //get subscribe users
    $user_watch_row = array();
    $sql = 'SELECT * FROM ' . TOPICS_WATCH_TABLE . ' WHERE user_id = ' . $user->data['user_id'];
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)) {
        $user_watch_row[$row['topic_id']] = $row['notify_status'];
    }
    $db->sql_freeresult($result);
    if (!empty($topic_type)) {
        $sql = 'SELECT t.*, u.user_avatar, u.user_avatar_type,bm.topic_id as bookmarked
                FROM ' . TOPICS_TABLE . ' t
                    LEFT JOIN ' . USERS_TABLE . ' u ON (t.topic_poster = u.user_id)
                    LEFT JOIN ' . BOOKMARKS_TABLE . ' bm ON (bm.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = bm.topic_id) 
                WHERE t.forum_id IN (' . $forum_id . ', 0)
                AND t.topic_type IN (' . $topic_type . ') ' . $sql_shadow_out . ' ' . $sql_approved . '
                ORDER BY ' . $sql_sort_order;
        $result = $db->sql_query_limit($sql, $sql_limit, $start);
    } else {
        if ($user->data['user_id'] != ANONYMOUS) {
            // get total number of unread sticky topics number
            $sql = 'SELECT t.topic_id, t.topic_last_post_time
                    FROM ' . TOPICS_TABLE . ' t
                    WHERE t.forum_id = ' . $forum_id . '
                    AND t.topic_type = ' . POST_STICKY . ' ' . $sql_shadow_out . ' ' . $sql_approved;
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                if (empty($forum_id) || empty($row['topic_id'])) {
                    continue;
                }
                $topic_tracking = get_complete_topic_tracking($forum_id, $row['topic_id']);
                if (isset($topic_tracking[$row['topic_id']]) && $topic_tracking[$row['topic_id']] < $row['topic_last_post_time']) {
                    $unread_sticky_num++;
                }
            }
            $db->sql_freeresult($result);
            // get total number of unread announce topics number
            $sql = 'SELECT t.topic_id, t.topic_last_post_time
                    FROM ' . TOPICS_TABLE . ' t
                    WHERE t.forum_id IN (' . $forum_id . ', 0)
                    AND t.topic_type IN (' . POST_ANNOUNCE . ', ' . POST_GLOBAL . ') ' . $sql_shadow_out . ' ' . $sql_approved;
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                if (empty($forum_id) || empty($row['topic_id'])) {
                    continue;
                }
                $topic_tracking = get_complete_topic_tracking($forum_id, $row['topic_id']);
                if (isset($topic_tracking[$row['topic_id']]) && $topic_tracking[$row['topic_id']] < $row['topic_last_post_time']) {
                    $unread_announce_count++;
                }
            }
            $db->sql_freeresult($result);
        }
        // get total number of normal topics
        $sql = 'SELECT count(t.topic_id) AS num_topics
                FROM ' . TOPICS_TABLE . ' t
                WHERE t.forum_id = ' . $forum_id . '
                AND t.topic_type = ' . POST_NORMAL . ' ' . $sql_shadow_out . ' ' . $sql_approved;
        $result = $db->sql_query($sql);
        $topics_count = (int) $db->sql_fetchfield('num_topics');
        $db->sql_freeresult($result);
        if ($start > $topics_count / 2) {
            $store_reverse = true;
            if ($start + $sql_limit > $topics_count) {
                $sql_limit = min($sql_limit, max(1, $topics_count - $start));
            }
            // Select the sort order
            $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'ASC' : 'DESC');
            $start = max(0, $topics_count - $sql_limit - $start);
        }
        $sql = 'SELECT t.*, u.user_avatar, u.user_avatar_type,bm.topic_id as bookmarked
                FROM ' . TOPICS_TABLE . ' t
                    LEFT JOIN ' . USERS_TABLE . ' u ON (t.topic_poster = u.user_id)
                    LEFT JOIN ' . BOOKMARKS_TABLE . ' bm ON (bm.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = bm.topic_id) 
                WHERE t.forum_id = ' . $forum_id . '
                AND t.topic_type = ' . POST_NORMAL . ' ' . $sql_shadow_out . ' ' . $sql_approved . '
                ORDER BY ' . $sql_sort_order;
        $result = $db->sql_query_limit($sql, $sql_limit, $start);
    }
    $tids = array();
    $rowset = array();
    while ($row = $db->sql_fetchrow($result)) {
        $rowset[] = $row;
        $tids[] = $row['topic_moved_id'] ? $row['topic_moved_id'] : $row['topic_id'];
    }
    $db->sql_freeresult($result);
    // get participated users of each topic
    //    get_participated_user_avatars($tids);
    //    global $topic_users, $user_avatar;
    $topic_list = array();
    foreach ($rowset as $row) {
        $replies = $auth->acl_get('m_approve', $forum_id) ? $row['topic_replies_real'] : $row['topic_replies'];
        $short_content = get_short_content($row['topic_first_post_id']);
        $user_avatar_url = get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']);
        $new_post = false;
        if ($user->data['user_id'] != ANONYMOUS) {
            if (empty($forum_id) || empty($row['topic_id'])) {
                continue;
            }
            $topic_tracking = get_complete_topic_tracking($forum_id, $row['topic_id']);
            $new_post = $topic_tracking[$row['topic_id']] < $row['topic_last_post_time'] ? true : false;
        }
        $allow_change_type = $auth->acl_get('m_', $forum_id) || $user->data['is_registered'] && $user->data['user_id'] == $row['topic_poster'] ? true : false;
        $topic_id = $row['topic_moved_id'] ? $row['topic_moved_id'] : $row['topic_id'];
        //        $icon_urls = array();
        //        foreach($topic_users[$topic_id] as $posterid){
        //            $icon_urls[] = new xmlrpcval($user_avatar[$posterid], 'string');
        //        }
        $can_rename = $user->data['is_registered'] && ($auth->acl_get('m_edit', $forum_id) || $user->data['user_id'] == $row['topic_poster'] && $auth->acl_get('f_edit', $forum_id) && ($row['topic_time'] > time() - $config['edit_time'] * 60 || !$config['edit_time']));
        $xmlrpc_topic = new xmlrpcval(array('forum_id' => new xmlrpcval($forum_id), 'topic_id' => new xmlrpcval($row['topic_moved_id'] ? $row['topic_moved_id'] : $row['topic_id']), 'topic_title' => new xmlrpcval(html_entity_decode(strip_tags(censor_text($row['topic_title'])), ENT_QUOTES, 'UTF-8'), 'base64'), 'topic_author_id' => new xmlrpcval($row['topic_first_post_id'], 'string'), 'topic_author_name' => new xmlrpcval(html_entity_decode($row['topic_first_poster_name']), 'base64'), 'last_reply_time' => new xmlrpcval(mobiquo_iso8601_encode($row['topic_last_post_time']), 'dateTime.iso8601'), 'timestamp' => new xmlrpcval($row['topic_last_post_time'], 'string'), 'reply_number' => new xmlrpcval($replies, 'int'), 'view_number' => new xmlrpcval($row['topic_views'], 'int'), 'short_content' => new xmlrpcval($short_content, 'base64'), 'new_post' => new xmlrpcval($new_post, 'boolean'), 'icon_url' => new xmlrpcval($user_avatar_url), 'attachment' => new xmlrpcval($auth->acl_get('u_download') && $auth->acl_get('f_download', $forum_id) && $row['topic_attachment'] ? 1 : 0, 'string'), 'can_delete' => new xmlrpcval($auth->acl_get('m_delete', $forum_id), 'boolean'), 'can_move' => new xmlrpcval($auth->acl_get('m_move', $forum_id), 'boolean'), 'can_subscribe' => new xmlrpcval(($config['email_enable'] || $config['jab_enable']) && $config['allow_topic_notify'] && $user->data['is_registered'], 'boolean'), 'is_subscribed' => new xmlrpcval(isset($user_watch_row[$topic_id]) ? true : false, 'boolean'), 'can_close' => new xmlrpcval($auth->acl_get('m_lock', $forum_id) || $auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && $user->data['user_id'] == $row['topic_poster'], 'boolean'), 'is_closed' => new xmlrpcval($row['topic_status'] == ITEM_LOCKED, 'boolean'), 'can_stick' => new xmlrpcval($allow_change_type && $auth->acl_get('f_sticky', $forum_id), 'boolean'), 'is_sticky' => new xmlrpcval($row['topic_type'] == POST_STICKY, 'boolean'), 'can_approve' => new xmlrpcval($auth->acl_get('m_approve', $forum_id) && !$row['topic_approved'], 'boolean'), 'is_approved' => new xmlrpcval($row['topic_approved'] ? true : false, 'boolean'), 'can_rename' => new xmlrpcval($can_rename, 'boolean')), 'struct');
        $topic_list[] = $xmlrpc_topic;
        unset($xmlrpc_topic);
    }
    if ($store_reverse) {
        $topic_list = array_reverse($topic_list);
    }
    if (!empty($topic_type)) {
        $topic_num = count($topic_list);
    } else {
        $topic_num = $topics_count;
    }
    $allowed = $config['max_attachments'] && $auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && $config['allow_attachments'] && @ini_get('file_uploads') != '0' && strtolower(@ini_get('file_uploads')) != 'off';
    $max_attachment = $auth->acl_get('a_') || $auth->acl_get('m_', $forum_id) ? 99 : ($allowed ? $config['max_attachments'] : 0);
    $max_png_size = $auth->acl_get('a_') || $auth->acl_get('m_', $forum_id) ? 10485760 : ($allowed ? $config['max_filesize'] === '0' ? 10485760 : $config['max_filesize'] : 0);
    $max_jpg_size = $auth->acl_get('a_') || $auth->acl_get('m_', $forum_id) ? 10485760 : ($allowed ? $config['max_filesize'] === '0' ? 10485760 : $config['max_filesize'] : 0);
    $read_only_forums = explode(",", $config['tapatalk_forum_read_only']);
    $can_post = true;
    if (empty($read_only_forums) || !is_array($read_only_forums)) {
        $read_only_forums = array();
    }
    if (!$auth->acl_get('f_post', $forum_id) || in_array($forum_id, $read_only_forums)) {
        $can_post = false;
    }
    $response = new xmlrpcval(array('total_topic_num' => new xmlrpcval($topic_num, 'int'), 'unread_sticky_count' => new xmlrpcval($unread_sticky_num, 'int'), 'unread_announce_count' => new xmlrpcval($unread_announce_count, 'int'), 'forum_id' => new xmlrpcval($forum_id, 'string'), 'forum_name' => new xmlrpcval(html_entity_decode($forum_data['forum_name']), 'base64'), 'can_post' => new xmlrpcval($can_post, 'boolean'), 'can_upload' => new xmlrpcval($allowed, 'boolean'), 'max_attachment' => new xmlrpcval($max_attachment, 'int'), 'max_png_size' => new xmlrpcval($max_png_size, 'int'), 'max_jpg_size' => new xmlrpcval($max_jpg_size, 'int'), 'topics' => new xmlrpcval($topic_list, 'array')), 'struct');
    return new xmlrpcresp($response);
}
function get_user_avatars($users, $is_username = false)
{
    global $db;
    if (empty($users)) {
        return array();
    }
    if (!is_array($users)) {
        $users = array($users);
    }
    if ($is_username) {
        foreach ($users as $key => $username) {
            $users[$key] = $db->sql_escape(utf8_clean_string($username));
        }
    }
    $sql = 'SELECT user_id, username, user_avatar, user_avatar_type 
            FROM ' . USERS_TABLE . '
            WHERE ' . $db->sql_in_set($is_username ? 'username_clean' : 'user_id', $users);
    $result = $db->sql_query($sql);
    $user_avatar = array();
    $user_key = $is_username ? 'username' : 'user_id';
    while ($row = $db->sql_fetchrow($result)) {
        $user_avatar[$row[$user_key]] = get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']);
    }
    $db->sql_freeresult($result);
    return $user_avatar;
}
function get_topic_func($xmlrpc_params)
{
    $params = php_xmlrpc_decode($xmlrpc_params);
    $forum_id = isset($params[0]) ? intval($params[0]) : 0;
    if (!$forum_id) {
        return get_error(3);
    }
    $offset = 0;
    $limit = 20;
    $topic_type = '0,1,2';
    switch (count($params)) {
        case 4:
            $offset = intval($params[1]);
            // start_num
            $limit = intval($params[2]);
            // end_num
            $topic_type = $params[3] == 'TOP' ? '1' : ($params[3] == 'ANN' ? '2' : $topic_type);
            break;
        case 3:
            $offset = intval($params[1]);
            $limit = intval($params[2]);
            break;
        case 2:
            $topic_type = $params[1] == 'TOP' ? '1' : ($params[1] == 'ANN' ? '2' : $topic_type);
    }
    if ($offset > $limit) {
        # check if topic index is out of range
        return get_error(5);
    } else {
        if ($limit - $offset >= 50) {
            # return at most 50 topics
            $limit = 50;
        } else {
            if (0 === $offset && 0 === $limit) {
                # if both are present and are set to 0, return the first topic only
                $limit = 1;
            } else {
                if ($offset || $limit) {
                    $limit = 1 + $limit - $offset;
                }
            }
        }
    }
    global $db, $prefix;
    $forum = mobi_forums($forum_id);
    $forum = !empty($forum[0]) ? $forum[0] : 0;
    if (!$forum) {
        return get_error(3);
    }
    if (!$forum['auth_read']) {
        get_error(7);
    }
    if (isset($forum['subforums'])) {
        unset($forum['subforums']);
    }
    if (FORUM_LINK == $forum['forum_type']) {
        return get_error(4);
    }
    $result = $db->sql_query("SELECT t.*, u.username, u.user_avatar, u.user_avatar_type, u.user_allowavatar\n\t\tFROM {$prefix}_bbtopics t\n\t\tLEFT JOIN {$prefix}_users u\n\t\tON t.topic_poster=u.user_id\n\t\tWHERE t.forum_id = {$forum_id}\n\t\tAND t.topic_type IN ({$topic_type})\n\t\tORDER BY t.topic_id DESC\n\t\tLIMIT {$limit} OFFSET {$offset}");
    $topic_list = array();
    $unread_sticky_num = $unread_announce_count = 0;
    while ($row = $db->sql_fetchrow($result, SQL_ASSOC)) {
        if (is_user()) {
            if (POST_ANNOUNCE == $row['type']) {
                ++$unread_announce_count;
            } elseif (POST_STICKY == $row['type']) {
                ++$unread_sticky_num;
            }
        }
        $short_content = get_short_content($row['topic_first_post_id']);
        $user_avatar_url = $row['user_allowavatar'] ? get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']) : '';
        $rpc = array('forum_id' => new xmlrpcval($forum_id), 'topic_id' => new xmlrpcval($row['topic_moved_id'] ?: $row['topic_id']), 'topic_title' => new xmlrpcval(html_entity_decode(strip_tags($row['topic_title']), ENT_QUOTES, 'UTF-8'), 'base64'), 'topic_author_id' => new xmlrpcval($row['topic_poster']), 'topic_author_name' => new xmlrpcval(html_entity_decode($row['username']), 'base64'), 'is_subscribed' => new xmlrpcval($forum['auth_read'] && !empty($_SESSION['CPG_SESS']['Forums']['track_topics'][$row['topic_id']]), 'boolean'), 'can_subscribe' => new xmlrpcval($forum['auth_read'], 'boolean'), 'is_closed' => new xmlrpcval(TOPIC_LOCKED == $row['topic_status'], 'boolean'), 'last_reply_time' => new xmlrpcval(mobiquo_iso8601_encode($row['topic_time']), 'dateTime.iso8601'), 'reply_number' => new xmlrpcval($row['topic_replies'], 'int'), 'new_post' => new xmlrpcval(false, 'boolean'), 'view_number' => new xmlrpcval($row['topic_views'], 'int'), 'short_content' => new xmlrpcval(get_short_content($row['topic_first_post_id']), 'base64'));
        if ($user_avatar_url) {
            $rpc['icon_url'] = new xmlrpcval($user_avatar_url);
        }
        $topic_list[] = new xmlrpcval($rpc, 'struct');
    }
    $db->sql_freeresult($result);
    $rpc = array('total_topic_num' => new xmlrpcval($forum['forum_topics'], 'int'), 'forum_id' => new xmlrpcval($forum['forum_id'], 'string'), 'forum_name' => new xmlrpcval(html_entity_decode($forum['forum_name']), 'base64'), 'can_post' => new xmlrpcval($forum['auth_post'], 'boolean'), 'unread_sticky_count' => new xmlrpcval($unread_sticky_num, 'int'), 'unread_announce_count' => new xmlrpcval($unread_announce_count, 'int'), 'can_subscribe' => new xmlrpcval($forum['auth_read'], 'boolean'), 'is_subscribed' => new xmlrpcval($forum['auth_read'] && !empty($_SESSION['CPG_SESS']['Forums']['track_forums'][$forum['forum_id']]), 'boolean'), 'require_prefix' => new xmlrpcval(false, 'boolean'), 'prefixes' => new xmlrpcval(array(), 'array'));
    if ($topic_list) {
        $rpc['topics'] = new xmlrpcval($topic_list, 'array');
    }
    return new xmlrpcresp(new xmlrpcval($rpc, 'struct'));
}
 /**
  * Display the widget!
  *
  * @param array MUST contain at least the basic display params
  */
 function display($params)
 {
     /**
      * @var Blog
      */
     global $Blog;
     global $disp;
     $this->init_display($params);
     // Default link class
     $link_class = $this->disp_params['link_default_class'];
     $blog_ID = intval($this->disp_params['blog_ID']);
     if ($blog_ID > 0) {
         // Try to use blog from widget setting
         $BlogCache =& get_BlogCache();
         $current_Blog =& $BlogCache->get_by_ID($blog_ID, false, false);
     }
     if (empty($current_Blog)) {
         // Blog is not defined in setting or it doesn't exist in DB
         // Use current blog
         $current_Blog =& $Blog;
     }
     if (empty($current_Blog)) {
         // We cannot use this widget without a current collection:
         return false;
     }
     switch ($this->disp_params['link_type']) {
         case 'recentposts':
             $url = $current_Blog->get('recentpostsurl');
             if (is_same_url($url, $Blog->get('url'))) {
                 // This menu item has the same url as front page of blog
                 $EnabledWidgetCache =& get_EnabledWidgetCache();
                 $Widget_array =& $EnabledWidgetCache->get_by_coll_container($current_Blog->ID, NT_('Menu'));
                 if (!empty($Widget_array)) {
                     foreach ($Widget_array as $Widget) {
                         $Widget->init_display($params);
                         if (isset($Widget->param_array, $Widget->param_array['link_type']) && $Widget->param_array['link_type'] == 'home') {
                             // Don't display this menu if 'Blog home' menu item exists with the same url
                             return false;
                         }
                     }
                 }
             }
             $text = T_('Recently');
             if ($disp == 'posts') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'search':
             $url = $current_Blog->get('searchurl');
             $text = T_('Search');
             // Is this the current display?
             if ($disp == 'search') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'arcdir':
             $url = $current_Blog->get('arcdirurl');
             $text = T_('Archives');
             if ($disp == 'arcdir') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'catdir':
             $url = $current_Blog->get('catdirurl');
             $text = T_('Categories');
             if ($disp == 'catdir') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'tags':
             $url = $current_Blog->get('tagsurl');
             $text = T_('Tags');
             if ($disp == 'tags') {
                 // Let's display the link as selected:
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'postidx':
             $url = $current_Blog->get('postidxurl');
             $text = T_('Post index');
             if ($disp == 'postidx') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'mediaidx':
             $url = $current_Blog->get('mediaidxurl');
             $text = T_('Photo index');
             if ($disp == 'mediaidx') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'sitemap':
             $url = $current_Blog->get('sitemapurl');
             $text = T_('Site map');
             if ($disp == 'sitemap') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'latestcomments':
             if (!$current_Blog->get_setting('comments_latest')) {
                 // This page is disabled
                 return false;
             }
             $url = $current_Blog->get('lastcommentsurl');
             $text = T_('Latest comments');
             if ($disp == 'comments') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'owneruserinfo':
             $url = url_add_param($current_Blog->get('userurl'), 'user_ID=' . $current_Blog->owner_user_ID);
             $text = T_('Owner details');
             // Is this the current display?
             global $User;
             if ($disp == 'user' && !empty($User) && $User->ID == $current_Blog->owner_user_ID) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'ownercontact':
             if (!($url = $current_Blog->get_contact_url(true))) {
                 // user does not allow contact form:
                 return;
             }
             $text = T_('Contact');
             // Is this the current display?
             if ($disp == 'msgform' || isset($_GET['disp']) && $_GET['disp'] == 'msgform') {
                 // Let's display the link as selected
                 // fp> I think it's interesting to select this link , even if the recipient ID is different from the owner
                 // odds are there is no other link to highlight in this case
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'login':
             if (is_logged_in()) {
                 // Don't display this link for already logged in users
                 return false;
             }
             global $Settings;
             $url = get_login_url('menu link', $Settings->get('redirect_to_after_login'), false, $current_Blog->ID);
             if (isset($this->BlockCache)) {
                 // Do NOT cache because some of these links are using a redirect_to param, which makes it page dependent.
                 // so this will be cached by the PageCache; there is no added benefit to cache it in the BlockCache
                 // (which could have been shared between several pages):
                 $this->BlockCache->abort_collect();
             }
             $text = T_('Log in');
             // Is this the current display?
             if ($disp == 'login') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'logout':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_logout_url($current_Blog->ID);
             $text = T_('Log out');
             break;
         case 'register':
             if (!($url = get_user_register_url(NULL, 'menu link', false, '&amp;', $current_Blog->ID))) {
                 return false;
             }
             if (isset($this->BlockCache)) {
                 // Do NOT cache because some of these links are using a redirect_to param, which makes it page dependent.
                 // Note: also beware of the source param.
                 // so this will be cached by the PageCache; there is no added benefit to cache it in the BlockCache
                 // (which could have been shared between several pages):
                 $this->BlockCache->abort_collect();
             }
             $text = T_('Register');
             // Is this the current display?
             if ($disp == 'register') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'profile':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_profile_url($current_Blog->ID);
             $text = T_('Edit profile');
             // Is this the current display?  (Edit my Profile)
             if (in_array($disp, array('profile', 'avatar', 'pwdchange', 'userprefs', 'subs'))) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'avatar':
             if (!is_logged_in()) {
                 return false;
             }
             $url = get_user_avatar_url($current_Blog->ID);
             $text = T_('Profile picture');
             // Note: we never highlight this, it will always highlight 'profile' instead
             break;
         case 'users':
             global $Settings;
             if (!is_logged_in() && !$Settings->get('allow_anonymous_user_list')) {
                 // Don't allow anonymous users to see users list
                 return false;
             }
             $url = $current_Blog->get('usersurl');
             $text = T_('User directory');
             // Is this the current display?
             // Note: If $user_ID is not set, it means we are viewing "My Profile" instead
             global $user_ID;
             if ($disp == 'users' || $disp == 'user' && !empty($user_ID)) {
                 // Let's display the link as selected
                 // Note: we also highlight this for any user profile that is displayed
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'item':
             $ItemCache =& get_ItemCache();
             /**
              * @var Item
              */
             $item_ID = intval($this->disp_params['item_ID']);
             $disp_Item =& $ItemCache->get_by_ID($item_ID, false, false);
             if (empty($disp_Item)) {
                 // Item not found
                 return false;
             }
             $url = $disp_Item->get_permanent_url();
             $text = $disp_Item->title;
             // Is this the current item?
             global $Item;
             if (!empty($Item) && $disp_Item->ID == $Item->ID) {
                 // The current page is currently displaying the Item this link is pointing to
                 // Let's display it as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'url':
             if (empty($this->disp_params['link_href'])) {
                 // Don't display a link if url is empty
                 return false;
             }
             $url = $this->disp_params['link_href'];
             $text = '[URL]';
             // should normally be overriden below...
             // Note: we never highlight this link
             break;
         case 'postnew':
             if (!check_item_perm_create()) {
                 // Don't allow users to create a new post
                 return false;
             }
             $url = url_add_param($current_Blog->get('url'), 'disp=edit');
             $text = T_('Write a new post');
             // Is this the current display?
             if ($disp == 'edit') {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'myprofile':
             if (!is_logged_in()) {
                 // Don't show this link for not logged in users
                 return false;
             }
             $url = $current_Blog->get('userurl');
             $text = T_('My profile');
             // Is this the current display?  (Edit my Profile)
             global $user_ID, $current_User;
             // If $user_ID is not set, it means we will fall back to the current user, so it's ok
             // If $user_ID is set, it means we are browsing the directory instead
             if ($disp == 'user' && empty($user_ID)) {
                 // Let's display the link as selected
                 $link_class = $this->disp_params['link_selected_class'];
             }
             break;
         case 'admin':
             global $current_User;
             if (!(is_logged_in() && $current_User->check_perm('admin', 'restricted') && $current_User->check_status('can_access_admin'))) {
                 // Don't allow admin url for users who have no access to backoffice
                 return false;
             }
             global $admin_url;
             $url = $admin_url;
             $text = T_('Admin') . ' &raquo;';
             break;
         case 'home':
         default:
             $url = $current_Blog->get('url');
             $text = T_('Front Page');
             global $is_front;
             if ($disp == 'front' || !empty($is_front)) {
                 // Let's display the link as selected on front page
                 $link_class = $this->disp_params['link_selected_class'];
             }
     }
     // Override default link text?
     if (!empty($this->param_array['link_text'])) {
         // We have a custom link text:
         $text = $this->param_array['link_text'];
     }
     echo $this->disp_params['block_start'];
     echo $this->disp_params['block_body_start'];
     echo $this->disp_params['list_start'];
     if ($link_class == $this->disp_params['link_selected_class']) {
         echo $this->disp_params['item_selected_start'];
     } else {
         echo $this->disp_params['item_start'];
     }
     echo '<a href="' . $url . '" class="' . $link_class . '">' . $text . '</a>';
     if ($link_class == $this->disp_params['link_selected_class']) {
         echo $this->disp_params['item_selected_end'];
     } else {
         echo $this->disp_params['item_end'];
     }
     echo $this->disp_params['list_end'];
     echo $this->disp_params['block_body_end'];
     echo $this->disp_params['block_end'];
     return true;
 }
function get_message_func($xmlrpc_params)
{
    global $db, $auth, $user, $config, $template, $phpbb_root_path, $phpEx;
    if (file_exists($phpbb_root_path . 'includes/functions_profile_control.' . $phpEx)) {
        require_once $phpbb_root_path . 'includes/functions_profile_control.' . $phpEx;
    }
    $user->setup('ucp');
    $params = php_xmlrpc_decode($xmlrpc_params);
    if (!$user->data['is_registered']) {
        trigger_error('LOGIN_EXPLAIN_UCP');
    }
    if (!$config['allow_privmsg']) {
        trigger_error('Module not accessible');
    }
    // get msg id from parameters
    $msg_id = intval($params[0]);
    if (!$msg_id) {
        trigger_error('NO_MESSAGE');
    }
    $GLOBALS['return_html'] = isset($params[2]) ? $params[2] : false;
    $message_row = array();
    // Get Message user want to see
    $sql = 'SELECT t.*, p.*, u.*
            FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
            WHERE t.user_id = ' . $user->data['user_id'] . "\r\r\n            AND p.author_id = u.user_id\r\r\n            AND t.msg_id = p.msg_id\r\r\n            AND p.msg_id = {$msg_id}";
    $result = $db->sql_query($sql);
    $message_row = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    if (!$message_row) {
        trigger_error('NO_MESSAGE');
    }
    $message_row['message_text'] = preg_replace('/\\[b:' . $message_row['bbcode_uid'] . '\\](.*?)\\[\\/b:' . $message_row['bbcode_uid'] . '\\]/si', '[b]$1[/b]', $message_row['message_text']);
    $message_row['message_text'] = preg_replace('/\\[i:' . $message_row['bbcode_uid'] . '\\](.*?)\\[\\/i:' . $message_row['bbcode_uid'] . '\\]/si', '[i]$1[/i]', $message_row['message_text']);
    $message_row['message_text'] = preg_replace('/\\[u:' . $message_row['bbcode_uid'] . '\\](.*?)\\[\\/u:' . $message_row['bbcode_uid'] . '\\]/si', '[u]$1[/u]', $message_row['message_text']);
    $message_row['message_text'] = preg_replace('/\\[color=#(\\w{6}):' . $message_row['bbcode_uid'] . '\\](.*?)\\[\\/color:' . $message_row['bbcode_uid'] . '\\]/si', '[color=#$1]$2[/color]', $message_row['message_text']);
    // Update unread status
    $user->add_lang('posting');
    include_once $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
    update_unread_status($message_row['pm_unread'], $message_row['msg_id'], $user->data['user_id'], $message_row['folder_id']);
    include $phpbb_root_path . 'includes/ucp/ucp_pm_viewmessage.' . $phpEx;
    view_message('', '', $message_row['folder_id'], $msg_id, '', $message_row);
    $msg_to = array();
    foreach ($template->_tpldata['to_recipient'] as $address_row) {
        $msg_to[] = new xmlrpcval(array('user_id' => new xmlrpcval($address_row['UG_ID'], 'string'), 'username' => new xmlrpcval($address_row['NAME'], 'base64'), 'user_type' => check_return_user_type($address_row['NAME'])), 'struct');
    }
    $sent_date = mobiquo_iso8601_encode($message_row['message_time']);
    $icon_url = $user->optionget('viewavatars') ? get_user_avatar_url($message_row['user_avatar'], $message_row['user_avatar_type']) : '';
    $msg_subject = html_entity_decode(strip_tags(censor_text($message_row['message_subject'])));
    $msg_body = post_html_clean(parse_quote($template->_rootref['MESSAGE']));
    if ($config['load_onlinetrack']) {
        $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
                FROM ' . SESSIONS_TABLE . '
                WHERE session_user_id=' . $message_row['user_id'] . '
                GROUP BY session_user_id';
        $result = $db->sql_query($sql);
        $online_info = $db->sql_fetchrow($result);
        $update_time = $config['load_online_time'] * 60;
        $is_online = time() - $update_time < $online_info['online_time'] && ($online_info['viewonline'] || $auth->acl_get('u_viewonline')) ? true : false;
    } else {
        $is_online = false;
    }
    $result = new xmlrpcval(array('msg_from' => new xmlrpcval($message_row['username'], 'base64'), 'msg_from_id' => new xmlrpcval($message_row['user_id'], 'string'), 'msg_to' => new xmlrpcval($msg_to, 'array'), 'icon_url' => new xmlrpcval($icon_url), 'sent_date' => new xmlrpcval($sent_date, 'dateTime.iso8601'), 'timestamp' => new xmlrpcval($message_row['message_time'], 'string'), 'msg_subject' => new xmlrpcval($msg_subject, 'base64'), 'text_body' => new xmlrpcval($msg_body, 'base64'), 'is_online' => new xmlrpcval($is_online, 'boolean'), 'allow_smilies' => new xmlrpcval($message_row['enable_smilies'] ? true : false, 'boolean')), 'struct');
    return new xmlrpcresp($result);
}
function getAlert()
{
    global $db, $request_params, $user, $config, $table_prefix, $totalAlert;
    $push_table = $table_prefix . "tapatalk_push_data";
    $lang = array('reply_to_you' => "%s replied to \"%s\"", 'quote_to_you' => '%s quoted your post in thread "%s"', 'tag_to_you' => '%s mentioned you in thread "%s"', 'post_new_topic' => '%s started a new thread "%s"', 'like_your_thread' => '%s liked your post in thread "%s"', 'pm_to_you' => '%s sent you a message "%s"');
    $alertData = array();
    if (!$user->data['is_registered']) {
        trigger_error('No auth to get alert data');
    }
    if (!push_data_table_exists()) {
        trigger_error('Push data table not exist');
    }
    $page = !empty($request_params[0]) ? $request_params[0] : 1;
    $per_page = !empty($request_params[1]) ? $request_params[1] : 20;
    $nowtime = time();
    $monthtime = 30 * 24 * 60 * 60;
    $preMonthtime = $nowtime - $monthtime;
    $startNum = ($page - 1) * $per_page;
    $sql = 'DELETE FROM ' . $push_table . ' WHERE create_time < ' . $preMonthtime . ' and user_id = ' . $user->data['user_id'];
    $db->sql_query($sql);
    $sql_select = "SELECT p.* FROM " . $push_table . " p \r\r\n    WHERE p.user_id = " . $user->data['user_id'] . "\r\r\n    ORDER BY create_time DESC LIMIT {$startNum},{$per_page} ";
    $query = $db->sql_query($sql_select);
    $total_sql = "SELECT count(*) as total FROM " . $push_table . " p \r\r\n    WHERE p.user_id = " . $user->data['user_id'];
    $query_total = $db->sql_query($total_sql);
    $total_data = $db->sql_fetchrow($query_total);
    $totalAlert = $total_data['total'];
    $author_arr = array();
    while ($data = $db->sql_fetchrow($query)) {
        if (!isset($author_arr[$data['user_id']])) {
            $author_clean = $db->sql_escape(utf8_clean_string($data['author']));
            $sql_author = "SELECT u.user_id as author_id, u.user_avatar, u.user_avatar_type FROM " . USERS_TABLE . " AS u WHERE username_clean = '{$author_clean}'";
            $query_author = $db->sql_query($sql_author);
            $author_data = $db->sql_fetchrow($query_author);
            if (!empty($author_data)) {
                $author_arr[$data['user_id']] = $author_data;
            } else {
                $totalAlert = $totalAlert - 1;
                continue;
            }
        }
        $data = array_merge($author_arr[$data['user_id']], $data);
        switch ($data['data_type']) {
            case 'sub':
                $data['message'] = sprintf($lang['reply_to_you'], $data['author'], $data['title']);
                break;
            case 'tag':
                $data['message'] = sprintf($lang['tag_to_you'], $data['author'], $data['title']);
                break;
            case 'newtopic':
                $data['message'] = sprintf($lang['post_new_topic'], $data['author'], $data['title']);
                break;
            case 'quote':
                $data['message'] = sprintf($lang['quote_to_you'], $data['author'], $data['title']);
                break;
            case 'pm':
            case 'conv':
                $data['message'] = sprintf($lang['pm_to_you'], $data['author'], $data['title']);
                break;
        }
        $data['icon_url'] = get_user_avatar_url($data['user_avatar'], $data['user_avatar_type']);
        $alertData[] = $data;
    }
    return $alertData;
}
Exemple #18
0
} else {
    // Avatar settings for anonymous user
    $avatar_image_size = $params['avatar_image_size_if_anonymous'];
    if ($params['avatar_overlay_text_if_anonymous'] != '#default#') {
        // Get overlay text from params
        $avatar_overlay_text = $params['avatar_overlay_text_if_anonymous'];
    } else {
        // Get default overlay text from Back-office settings
        $avatar_overlay_text = $Settings->get('bubbletip_overlay');
    }
}
$avatar_imgtag = $User->get_avatar_imgtag($avatar_image_size, 'main_profile_picture', '', true, $avatar_overlay_text, 'user', '300x300');
if ($is_logged_in) {
    if ($User->ID == $current_User->ID && !$User->has_avatar()) {
        // If user hasn't an avatar, add a link to go for uploading of avatar
        $avatar_imgtag = '<a href="' . get_user_avatar_url() . '">' . $avatar_imgtag . '</a>';
    }
}
echo $params['profile_avatar_before'] . $avatar_imgtag . $params['profile_avatar_after'];
// First Last Names:
$first_last_name = '';
if ($Settings->get('firstname_editing') != 'hidden' && $User->get('firstname') != '') {
    $first_last_name .= $User->get('firstname');
}
if ($Settings->get('lastname_editing') != 'hidden' && $User->get('lastname') != '') {
    $first_last_name .= ' ' . $User->get('lastname');
}
$first_last_name = utf8_trim($first_last_name);
if (!empty($first_last_name)) {
    // Display first last name of it is not empty
    echo '<h1>' . $first_last_name . '</h1>';
function m_get_report_post_func()
{
    global $template, $auth, $user;
    $posts = array();
    foreach ($template->_tpldata['postrow'] as $postinfo) {
        $posts[] = $postinfo['POST_ID'];
    }
    $posts = get_post_data($posts);
    $post_list = array();
    foreach ($template->_tpldata['postrow'] as $postinfo) {
        $post = $posts[$postinfo['POST_ID']];
        if (empty($post['forum_id'])) {
            $user->setup('viewforum');
            $post['forum_id'] = 0;
            $post['forum_name'] = $user->lang['ANNOUNCEMENTS'];
        }
        $post_list[] = new xmlrpcval(array('forum_id' => new xmlrpcval($post['forum_id']), 'forum_name' => new xmlrpcval(basic_clean($post['forum_name']), 'base64'), 'topic_id' => new xmlrpcval($post['topic_id']), 'topic_title' => new xmlrpcval(basic_clean($post['topic_title']), 'base64'), 'post_id' => new xmlrpcval($post['post_id']), 'post_title' => new xmlrpcval(basic_clean($post['post_subject']), 'base64'), 'post_author_name' => new xmlrpcval(basic_clean($post['username']), 'base64'), 'icon_url' => new xmlrpcval(get_user_avatar_url($post['user_avatar'], $post['user_avatar_type'])), 'post_time' => new xmlrpcval(mobiquo_iso8601_encode($post['post_time']), 'dateTime.iso8601'), 'short_content' => new xmlrpcval(process_short_content($post['post_text']), 'base64'), 'can_delete' => new xmlrpcval($auth->acl_get('m_delete', $forum_id), 'boolean')), 'struct');
    }
    $response = new xmlrpcval(array('total_report_num' => new xmlrpcval($template->_rootref['TOTAL'], 'int'), 'reports' => new xmlrpcval($post_list, 'array')), 'struct');
    return new xmlrpcresp($response);
}
          <!-- The user image in the navbar-->
          <img src="<?php 
    echo get_user_avatar_url($this->session->userdata('email'));
    ?>
" class="user-image" alt="User Image">
          <!-- hidden-xs hides the username on small devices so only the image appears. -->
          <span class="hidden-xs"><?php 
    echo $this->session->userdata('first_name') . " " . $this->session->userdata('last_name');
    ?>
</span>
        </a>
        <ul class="dropdown-menu">
          <!-- The user image in the menu -->
          <li class="user-header">
            <img src="<?php 
    echo get_user_avatar_url($this->session->userdata('email'));
    ?>
" class="img-circle" alt="User Image">

            <p>
              <?php 
    echo $this->session->userdata('first_name') . " " . $this->session->userdata('last_name');
    ?>
              <small>Member since XXXXXXXXX</small>
            </p>
          </li>
          <!-- Menu Body -->
          <li class="user-body">
            <div class="row">
              <div class="col-xs-4 text-center">
                <a href="#"></a>
<?php

define('IN_MOBIQUO', 1);
define('IN_PHPBB', true);
//error_reporting(0);
$forum_root = dirname(dirname(__FILE__));
$mobiquo_root = dirname(__FILE__);
if (!$forum_root) {
    $forum_root = '.';
}
if (!$mobiquo_root) {
    $mobiquo_root = '.';
}
include $mobiquo_root . '/config/config.php';
include $forum_root . '/common.' . $phpEx;
require_once $mobiquo_root . '/mobiquo_common.php';
if (!empty($_GET['user_id'])) {
    $uid = intval($_GET['user_id']);
} else {
    if (!empty($_GET['username'])) {
        $_GET['username'] = base64_decode($_GET['username']);
        $_GET['username'] = trim($_GET['username']);
        $uid = get_user_id_by_name($_GET['username']);
    } else {
        die('Invalid params!');
    }
}
$phpbb_home = generate_board_url() . '/';
$user_info = tt_get_user_by_id($uid);
$icon_url = get_user_avatar_url($user_info['user_avatar'], $user_info['user_avatar_type']);
header("Location:{$icon_url}");
    $Messages->add(T_('Unable to find the selected blog'), 'error');
    header_redirect($baseurl);
}
if (param_errors_detected() || $action == 'refresh_regional') {
    // unable to update, store unsaved user into session
    $Session->set('core.unsaved_User', $current_User);
} elseif (!param_errors_detected()) {
    // update was successful on user profile
    switch ($action) {
        case 'update':
            if ($current_User->has_avatar()) {
                // Redirect to display user page
                $redirect_to = $Blog->get('userurl', array('glue' => '&'));
            } else {
                // Redirect to upload avatar
                $redirect_to = get_user_avatar_url();
            }
            break;
        case 'upload_avatar':
            // Redirect to display user profile form
            $redirect_to = url_add_param($Blog->gen_blogurl(), 'disp=profile', '&');
            break;
    }
    if (!empty($redirect_to)) {
        header_redirect($redirect_to);
    }
}
if (!param_errors_detected() || !isset($disp)) {
    // User data is updated without errors
    // redirect will save $Messages into Session:
    $redirect_to = NULL;
     $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['user_sig_bbcode_bitfield']);
 }
 // Cache various user specific data ... so we don't have to recompute
 // this each time the same user appears on this page
 if (!isset($user_cache[$poster_id])) {
     if ($poster_id == ANONYMOUS) {
         $user_cache[$poster_id] = array('joined' => '', 'posts' => '', 'from' => '', 'sig' => '', 'sig_bbcode_uid' => '', 'sig_bbcode_bitfield' => '', 'online' => false, 'avatar' => $user->optionget('viewavatars') ? get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']) : '', 'rank_title' => '', 'rank_image' => '', 'rank_image_src' => '', 'sig' => '', 'profile' => '', 'pm' => '', 'email' => '', 'www' => '', 'icq_status_img' => '', 'icq' => '', 'aim' => '', 'msn' => '', 'yim' => '', 'jabber' => '', 'search' => '', 'age' => '', 'username' => $row['username'], 'user_colour' => $row['user_colour'], 'warnings' => 0, 'allow_pm' => 0);
         //get_user_rank($row['user_rank'], false, $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']);
     } else {
         $user_sig = '';
         // We add the signature to every posters entry because enable_sig is post dependant
         if ($row['user_sig'] && $config['allow_sig'] && $user->optionget('viewsigs')) {
             $user_sig = $row['user_sig'];
         }
         $id_cache[] = $poster_id;
         $user_cache[$poster_id] = array('joined' => $user->format_date($row['user_regdate']), 'posts' => $row['user_posts'], 'warnings' => isset($row['user_warnings']) ? $row['user_warnings'] : 0, 'from' => !empty($row['user_from']) ? $row['user_from'] : '', 'sig' => $user_sig, 'sig_bbcode_uid' => !empty($row['user_sig_bbcode_uid']) ? $row['user_sig_bbcode_uid'] : '', 'sig_bbcode_bitfield' => !empty($row['user_sig_bbcode_bitfield']) ? $row['user_sig_bbcode_bitfield'] : '', 'viewonline' => $row['user_allow_viewonline'], 'allow_pm' => $row['user_allow_pm'], 'avatar' => $user->optionget('viewavatars') ? get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']) : '', 'age' => '', 'rank_title' => '', 'rank_image' => '', 'rank_image_src' => '', 'username' => $row['username'], 'user_colour' => $row['user_colour'], 'online' => false, 'profile' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=viewprofile&amp;u={$poster_id}"), 'www' => $row['user_website'], 'aim' => $row['user_aim'] && $auth->acl_get('u_sendim') ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=contact&amp;action=aim&amp;u={$poster_id}") : '', 'msn' => $row['user_msnm'] && $auth->acl_get('u_sendim') ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=contact&amp;action=msnm&amp;u={$poster_id}") : '', 'yim' => $row['user_yim'] ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($row['user_yim']) . '&amp;.src=pg' : '', 'jabber' => $row['user_jabber'] && $auth->acl_get('u_sendim') ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=contact&amp;action=jabber&amp;u={$poster_id}") : '', 'search' => $auth->acl_get('u_search') ? append_sid("{$phpbb_root_path}search.{$phpEx}", "author_id={$poster_id}&amp;sr=posts") : '', 'author_full' => get_username_string('full', $poster_id, $row['username'], $row['user_colour']), 'author_colour' => get_username_string('colour', $poster_id, $row['username'], $row['user_colour']), 'author_username' => get_username_string('username', $poster_id, $row['username'], $row['user_colour']), 'author_profile' => get_username_string('profile', $poster_id, $row['username'], $row['user_colour']));
         //get_user_rank($row['user_rank'], $row['user_posts'], $user_cache[$poster_id]['rank_title'], $user_cache[$poster_id]['rank_image'], $user_cache[$poster_id]['rank_image_src']);
         if (!empty($row['user_allow_viewemail']) && $auth->acl_get('u_sendemail') || $auth->acl_get('a_email')) {
             $user_cache[$poster_id]['email'] = $config['board_email_form'] && $config['email_enable'] ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=email&amp;u={$poster_id}") : ($config['board_hide_emails'] && !$auth->acl_get('a_email') ? '' : 'mailto:' . $row['user_email']);
         } else {
             $user_cache[$poster_id]['email'] = '';
         }
         if (!empty($row['user_icq'])) {
             $user_cache[$poster_id]['icq'] = 'http://www.icq.com/people/' . urlencode($row['user_icq']) . '/';
             $user_cache[$poster_id]['icq_status_img'] = '<img src="http://web.icq.com/whitepages/online?icq=' . $row['user_icq'] . '&amp;img=5" width="18" height="18" alt="" />';
         } else {
             $user_cache[$poster_id]['icq_status_img'] = '';
             $user_cache[$poster_id]['icq'] = '';
         }
         if ($config['allow_birthdays'] && !empty($row['user_birthday'])) {
             list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $row['user_birthday']));
              </div>
            </div>

				  
                  <div class="box-body bg-info ">

			 <p>
			 <div class="box-comments">
				 <?php 
if ($client_comments) {
    foreach ($client_comments as $comment) {
        ?>
						<div class="box-comment">
					
							<img class="img-circle img-sm" alt="User Image" src="<?php 
        echo get_user_avatar_url($comment['created_by'], '50');
        ?>
" />
			<div class="comment-text">
							<span class="username">
								<?php 
        echo get_user_full_name($comment['created_by']);
        ?>
								<span class="text-muted pull-right">
									<?php 
        echo getDateTime($comment['created_on'], "dtShort");
        ?>
								</span>
							</span>
							<?php 
        echo $comment['comment'];
function get_box_func($xmlrpc_params)
{
    global $db, $auth, $user, $cache, $config, $phpbb_home, $phpbb_root_path, $phpEx;
    $params = php_xmlrpc_decode($xmlrpc_params);
    $user->setup('ucp');
    if (!$user->data['is_registered']) {
        trigger_error('LOGIN_EXPLAIN_UCP');
    }
    if (!$config['allow_privmsg']) {
        trigger_error('Module not accessible');
    }
    if (!isset($params[0])) {
        trigger_error('UNKNOWN_FOLDER');
    }
    // get folder id from parameters
    $folder_id = intval($params[0]);
    if (PRIVMSGS_INBOX !== $folder_id) {
        $folder_id = PRIVMSGS_SENTBOX;
    }
    list($start, $limit, $page) = process_page($params[1], $params[2]);
    // Grab icons
    //$icons = $cache->obtain_icons();
    $user_id = $user->data['user_id'];
    include_once $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
    $folder = get_folder($user_id, $folder_id);
    include $phpbb_root_path . 'includes/ucp/ucp_pm_viewfolder.' . $phpEx;
    $folder_info = get_pm_from($folder_id, $folder, $user_id);
    $address_list = array();
    // Build Recipient List if in outbox/sentbox - max two additional queries
    if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) {
        $recipient_list = $address = array();
        foreach ($folder_info['rowset'] as $message_id => $row) {
            $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address']));
            $_save = array('u', 'g');
            foreach ($_save as $save) {
                if (isset($address[$message_id][$save]) && sizeof($address[$message_id][$save])) {
                    foreach (array_keys($address[$message_id][$save]) as $ug_id) {
                        $recipient_list[$save][$ug_id] = array('name' => $user->lang['NA'], 'colour' => '');
                    }
                }
            }
        }
        $_types = array('u', 'g');
        foreach ($_types as $ug_type) {
            if (!empty($recipient_list[$ug_type])) {
                if ($ug_type == 'u') {
                    $sql = 'SELECT user_id as id, username as name, user_colour as colour
                        FROM ' . USERS_TABLE . '
                        WHERE ';
                } else {
                    $sql = 'SELECT group_id as id, group_name as name, group_colour as colour, group_type
                        FROM ' . GROUPS_TABLE . '
                        WHERE ';
                }
                $sql .= $db->sql_in_set($ug_type == 'u' ? 'user_id' : 'group_id', array_map('intval', array_keys($recipient_list[$ug_type])));
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    if ($ug_type == 'g') {
                        $row['name'] = $row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['name']] : $row['name'];
                    }
                    $recipient_list[$ug_type][$row['id']] = array('id' => $row['id'], 'name' => $row['name'], 'colour' => $row['colour']);
                }
                $db->sql_freeresult($result);
            }
        }
        foreach ($address as $message_id => $adr_ary) {
            foreach ($adr_ary as $type => $id_ary) {
                foreach ($id_ary as $ug_id => $_id) {
                    $address_list[$message_id][] = $recipient_list[$type][$ug_id];
                }
            }
        }
        unset($recipient_list, $address);
    }
    // get unread count in inbox only
    if (PRIVMSGS_INBOX === $folder_id) {
        $sql = 'SELECT COUNT(msg_id) as num_messages
                FROM ' . PRIVMSGS_TO_TABLE . '
                WHERE pm_unread = 1
                    AND folder_id = ' . PRIVMSGS_INBOX . '
                    AND user_id = ' . $user->data['user_id'];
        $result = $db->sql_query($sql);
        $unread_num = (int) $db->sql_fetchfield('num_messages');
        $db->sql_freeresult($result);
    } else {
        $unread_num = 0;
    }
    $sql = 'SELECT COUNT(msg_id) as num_messages
            FROM ' . PRIVMSGS_TO_TABLE . '
            WHERE folder_id = ' . $folder_id . '
                AND user_id = ' . $user->data['user_id'];
    $result = $db->sql_query($sql);
    $total_num = (int) $db->sql_fetchfield('num_messages');
    $db->sql_freeresult($result);
    $sql = 'SELECT t.*, p.*, u.username, u.user_avatar, u.user_avatar_type, u.user_id
            FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . " u\r\r\n            WHERE t.user_id = {$user_id}\r\r\n            AND p.author_id = u.user_id\r\r\n            AND t.folder_id = {$folder_id}\r\r\n            AND t.msg_id = p.msg_id\r\r\n            ORDER BY p.message_time DESC";
    $result = $db->sql_query_limit($sql, $limit, $start);
    $total_message_count = $total_unread_count = 0;
    $online_cache = array();
    while ($row = $db->sql_fetchrow($result)) {
        $msg_state = 2;
        // message read
        if ($row['pm_unread']) {
            $msg_state = 1;
        } else {
            if ($row['pm_replied']) {
                $msg_state = 3;
            } else {
                if ($row['pm_forwarded']) {
                    $msg_state = 4;
                }
            }
        }
        if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) {
            $msg_to_list = $address_list[$row['msg_id']];
        } else {
            $msg_to_list = array(array('id' => $user->data['user_id'], 'name' => $user->data['username']));
        }
        $msg_to = array();
        foreach ($msg_to_list as $address) {
            $msg_to[] = new xmlrpcval(array('user_id' => new xmlrpcval($address['id'], 'string'), 'username' => new xmlrpcval(basic_clean($address['name']), 'base64'), 'user_type' => check_return_user_type($address['name'])), 'struct');
        }
        $sent_date = mobiquo_iso8601_encode($row['message_time']);
        //$icon_url   = (!empty($icons[$row['icon_id']])) ? $phpbb_home . $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] : '';
        $icon_url = $user->optionget('viewavatars') ? get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']) : '';
        $msg_subject = html_entity_decode(strip_tags(censor_text($row['message_subject'])));
        $short_content = censor_text($row['message_text']);
        $short_content = preg_replace('/\\[url.*?\\].*?\\[\\/url.*?\\]/', '[url]', $short_content);
        $short_content = preg_replace('/\\[img.*?\\].*?\\[\\/img.*?\\]/', '[img]', $short_content);
        $short_content = preg_replace('/[\\n\\r\\t]+/', ' ', $short_content);
        strip_bbcode($short_content);
        $short_content = html_entity_decode($short_content);
        $short_content = substr($short_content, 0, 200);
        if ($config['load_onlinetrack'] && !isset($online_cache[$row['user_id']])) {
            $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline
                    FROM ' . SESSIONS_TABLE . '
                    WHERE session_user_id=' . $row['user_id'] . '
                    GROUP BY session_user_id';
            $online_result = $db->sql_query($sql);
            $online_info = $db->sql_fetchrow($online_result);
            $db->sql_freeresult($online_result);
            $update_time = $config['load_online_time'] * 60;
            $online_cache[$row['user_id']] = time() - $update_time < $online_info['online_time'] && ($online_info['viewonline'] || $auth->acl_get('u_viewonline')) ? true : false;
        }
        $is_online = isset($online_cache[$row['user_id']]) ? $online_cache[$row['user_id']] : false;
        $pm_list[] = new xmlrpcval(array('msg_id' => new xmlrpcval($row['msg_id']), 'msg_state' => new xmlrpcval($msg_state, 'int'), 'sent_date' => new xmlrpcval($sent_date, 'dateTime.iso8601'), 'timestamp' => new xmlrpcval($row['message_time'], 'string'), 'msg_from' => new xmlrpcval(basic_clean($row['username']), 'base64'), 'msg_from_id' => new xmlrpcval($row['user_id']), 'icon_url' => new xmlrpcval($icon_url), 'msg_to' => new xmlrpcval($msg_to, 'array'), 'msg_subject' => new xmlrpcval($msg_subject, 'base64'), 'short_content' => new xmlrpcval($short_content, 'base64'), 'is_online' => new xmlrpcval($is_online, 'boolean')), 'struct');
    }
    $db->sql_freeresult($result);
    $result = new xmlrpcval(array('total_message_count' => new xmlrpcval($total_num, 'int'), 'total_unread_count' => new xmlrpcval($unread_num, 'int'), 'list' => new xmlrpcval($pm_list, 'array')), 'struct');
    return new xmlrpcresp($result);
}
                					}
                
                					$row['post_text'] = bbcode_nl2br($row['post_text']);
                					$row['post_text'] = smiley_text($row['post_text']);
                
                					if (!empty($attachments[$row['post_id']]))
                					{
                						parse_attachments($forum_id, $row['post_text'], $attachments[$row['post_id']], $update_count);
                
                						// we only display inline attachments
                						unset($attachments[$row['post_id']]);
                					}
                				}
                
                				if ($hilit)
                				{
                					// post highlighting
                					$row['post_text'] = preg_replace('#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $row['post_text']);
                					$row['post_subject'] = preg_replace('#(?!<.*)(?<!\w)(' . $hilit . ')(?!\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">$1</span>', $row['post_subject']);
                				}
                */
                $tpl_ary = array('POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 'POST_AUTHOR_ID' => $row['poster_id'], 'POST_TIMESTAMP' => $row['post_time'], 'POSTER_AVATAR' => get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']), 'POST_APPROVED' => $row['post_approved'], 'TOPIC_LAST_POST_ID' => $row['topic_last_post_id'], 'POST_EDIT_LOCKED' => $row['post_edit_locked'], 'POST_SUBJECT' => $row['post_subject'], 'POST_DATE' => !empty($row['post_time']) ? $user->format_date($row['post_time']) : '', 'MESSAGE' => $row['post_text']);
            }
            $template->assign_block_vars('searchresults', array_merge($tpl_ary, array('FORUM_ID' => $forum_id, 'TOPIC_ID' => $result_topic_id, 'POST_ID' => $show_results == 'posts' ? $row['post_id'] : false, 'FORUM_TITLE' => $forum_id ? $row['forum_name'] : (isset($user->lang['GLOBAL']) ? $user->lang['GLOBAL'] : 'Global announcement'), 'TOPIC_TITLE' => $topic_title, 'TOPIC_REPLIES' => $replies, 'TOPIC_VIEWS' => $row['topic_views'], 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id), 'U_VIEW_POST' => !empty($row['post_id']) ? append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t=" . $row['topic_id'] . '&amp;p=' . $row['post_id'] . ($u_hilit ? '&amp;hilit=' . $u_hilit : '')) . '#p' . $row['post_id'] : '')));
        }
        if ($topic_id && $topic_id == $result_topic_id) {
            $template->assign_vars(array('SEARCH_TOPIC' => $topic_title, 'U_SEARCH_TOPIC' => $view_topic_url));
        }
    }
    unset($rowset);
}
function get_unread_topic_func($xmlrpc_params)
{
    global $db, $auth, $user, $userinfo, $prefix, $config, $mobiquo_config, $phpbb_home;
    $params = php_xmlrpc_decode($xmlrpc_params);
    $start_num = 0;
    $end_num = 19;
    if (isset($params[0]) && is_int($params[0])) {
        $start_num = $params[0];
    }
    // get end index of topic from parameters
    if (isset($params[1]) && is_int($params[1])) {
        $end_num = $params[1];
    }
    // check if topic index is out of range
    if ($start_num > $end_num) {
        return get_error(5);
    }
    // return at most 50 topics
    if ($end_num - $start_num >= 50) {
        $end_num = $start_num + 49;
    }
    $sql_limit = $end_num - $start_num + 1;
    $not_in_fid = '';
    //$ex_fid_ary = array_unique(array_merge(array_keys($auth->acl_getf('!f_read', true)), array_keys($auth->acl_getf('!f_search', true))));
    //if (isset($mobiquo_config['hide_forum_id']))
    //{
    //$ex_fid_ary = array_unique(array_merge($ex_fid_ary, $mobiquo_config['hide_forum_id']));
    //}
    //$not_in_fid = (sizeof($ex_fid_ary)) ? 'WHERE ' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . ';
    $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, forum_order
		FROM ' . $prefix . '_bbforums
		' . $not_in_fid . '
		ORDER BY forum_order';
    $result = $db->sql_query($sql);
    $db->sql_freeresult($result);
    // find out in which forums the user is allowed to view approved posts
    $sql = 'SELECT t.topic_id, t.forum_id, t.topic_last_post_id, p.post_time AS topic_last_post_time FROM ' . $prefix . '_bbtopics t, ' . $prefix . '_bbposts p
		WHERE p.topic_id = t.topic_id AND p.post_time > ' . $userinfo['user_lastvisit'] . ' ORDER BY topic_last_post_time DESC LIMIT ' . $sql_limit . '';
    //if ($fh = fopen('log.txt', 'w'))
    //{
    //fwrite($fh, $userinfo['username']);
    //fclose($fh);
    //}
    $result = $db->sql_query($sql);
    $unread_tids = array();
    while ($row = $db->sql_fetchrow($result)) {
        $topic_id = $row['topic_id'];
        //$forum_id = $row['forum_id'];
        //$topic_tracking = get_complete_topic_tracking($forum_id, $topic_id);
        //if ($topic_tracking[$topic_id] < $row['topic_last_post_time'])
        //{
        $unread_tids[] = $topic_id;
        //}
    }
    $db->sql_freeresult($result);
    $topic_list = array();
    $ur_tids = implode(",", $unread_tids);
    if (count($unread_tids)) {
        $sql = 'SELECT f.forum_id,
			f.forum_name,
			t.topic_id,
			t.topic_title,
			t.topic_replies,
			t.topic_views,
			t.topic_poster,
			t.topic_status,
			t.topic_type,
			t.topic_last_post_id,
			u.user_avatar,
			u.user_avatar_type,
			tw.notify_status,
			p.post_time AS topic_last_post_time,
			u.username AS topic_last_poster_name,
			p.poster_id AS topic_last_poster_id
			FROM ' . $prefix . '_bbtopics t
			LEFT JOIN ' . $prefix . '_bbposts p ON (p.post_id = t.topic_last_post_id)
			LEFT JOIN ' . $prefix . '_bbforums f ON (t.forum_id = f.forum_id)
			LEFT JOIN ' . $prefix . '_users u ON (p.poster_id = u.user_id)
			LEFT JOIN ' . $prefix . '_bbtopics_watch tw ON (tw.user_id = ' . $userinfo['user_id'] . ' AND t.topic_id = tw.topic_id)
			WHERE t.topic_id IN (' . $ur_tids . ')
			ORDER BY topic_last_post_time DESC LIMIT ' . $sql_limit . '';
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $topic_id = $row['topic_id'];
            $forum_id = $row['forum_id'];
            $short_content = get_short_content($row['topic_last_post_id']);
            $user_avatar_url = get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']);
            //$allow_change_type = ($auth->acl_get('m_', $forum_id) || ($user->data['is_registered'] && $user->data['user_id'] == $row['topic_poster'])) ? true : false;
            $xmlrpc_topic = new xmlrpcval(array('forum_id' => new xmlrpcval($forum_id), 'forum_name' => new xmlrpcval(html_entity_decode($row['forum_name']), 'base64'), 'topic_id' => new xmlrpcval($topic_id), 'topic_title' => new xmlrpcval(html_entity_decode(strip_tags($row['topic_title'])), 'base64'), 'reply_number' => new xmlrpcval($row['topic_replies'], 'int'), 'new_post' => new xmlrpcval(true, 'boolean'), 'view_number' => new xmlrpcval($row['topic_views'], 'int'), 'short_content' => new xmlrpcval($short_content, 'base64'), 'post_author_id' => new xmlrpcval($row['topic_last_poster_id']), 'post_author_name' => new xmlrpcval(html_entity_decode($row['topic_last_poster_name']), 'base64'), 'post_time' => new xmlrpcval(mobiquo_iso8601_encode($row['topic_last_post_time']), 'dateTime.iso8601'), 'icon_url' => new xmlrpcval($user_avatar_url), 'can_delete' => new xmlrpcval(false, 'boolean'), 'can_subscribe' => new xmlrpcval(($config['email_enable'] || $config['jab_enable']) && $config['allow_topic_notify'] && $user->data['is_registered'], 'boolean'), 'can_bookmark' => new xmlrpcval($user->data['is_registered'] && $config['allow_bookmarks'], 'boolean'), 'issubscribed' => new xmlrpcval(!is_null($row['notify_status']) && $row['notify_status'] !== '' ? true : false, 'boolean'), 'is_subscribed' => new xmlrpcval(!is_null($row['notify_status']) && $row['notify_status'] !== '' ? true : false, 'boolean'), 'isbookmarked' => new xmlrpcval($row['bookmarked'] ? true : false, 'boolean'), 'can_close' => new xmlrpcval(false, 'boolean'), 'is_closed' => new xmlrpcval($row['topic_status'] == ITEM_LOCKED, 'boolean'), 'can_stick' => new xmlrpcval(false, 'boolean')), 'struct');
            $topic_list[] = $xmlrpc_topic;
        }
        $db->sql_freeresult($result);
    }
    $response = new xmlrpcval(array('total_topic_num' => new xmlrpcval(count($unread_tids), 'int'), 'topics' => new xmlrpcval($topic_list, 'array')), 'struct');
    return new xmlrpcresp($response);
}
	<?php 
if (is_logged_in()) {
    // Display user menu
    ?>
	<div class="wptouch-menu-inner" rel="profile">
		<ul id="head-account">
			<li><a href="<?php 
    echo get_user_profile_url();
    ?>
"><?php 
    echo T_('Edit your profile');
    ?>
</a></li>
			<li><a href="<?php 
    echo get_user_avatar_url();
    ?>
"><?php 
    echo T_('Your profile picture');
    ?>
</a></li>
			<li><a href="<?php 
    echo get_user_pwdchange_url();
    ?>
"><?php 
    echo T_('Change password');
    ?>
</a></li>
			<li><a href="<?php 
    echo get_user_preferences_url();
    ?>
function get_recommended_user_func()
{
    global $db, $auth, $user, $config, $phpbb_home, $table_prefix, $tapatalk_users;
    $tapatalk_users = array();
    $users = array();
    //get tapatalk users
    $sql = "SELECT userid AS uid FROM " . $table_prefix . "tapatalk_users";
    $query = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($query)) {
        $tapatalk_users[] = $row['uid'];
    }
    //get pm users
    $sql = "SELECT user_id AS uid FROM " . PRIVMSGS_TO_TABLE . " WHERE author_id = '" . $user->data['user_id'] . "'";
    $query = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($query)) {
        if (isset($users[$row['uid']])) {
            $users[$row['uid']] = $users[$row['uid']] + 10;
        } else {
            $users[$row['uid']] = 10;
        }
    }
    //get pm to me users
    $sql = "SELECT author_id AS uid FROM " . PRIVMSGS_TO_TABLE . " WHERE user_id = '" . $user->data['user_id'] . "'";
    $query = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($query)) {
        if (isset($users[$row['uid']])) {
            $users[$row['uid']] = $users[$row['uid']] + 10;
        } else {
            $users[$row['uid']] = 10;
        }
    }
    //get sub users
    $sql = "SELECT tw.user_id AS uid FROM " . TOPICS_WATCH_TABLE . " AS tw \r\r\n\tLEFT JOIN " . TOPICS_TABLE . " AS t ON tw.topic_id=t.topic_id \r\r\n\tWHERE t.topic_poster = '" . $user->data['user_id'] . "'";
    $query = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($query)) {
        if (isset($users[$row['uid']])) {
            $users[$row['uid']] = $users[$row['uid']] + 5;
        } else {
            $users[$row['uid']] = 5;
        }
    }
    //get me sub users
    $sql = "SELECT t.topic_poster AS uid FROM " . TOPICS_WATCH_TABLE . " AS tw \r\r\n\tRIGHT JOIN " . TOPICS_TABLE . " AS t ON tw.topic_id=t.topic_id \r\r\n\tWHERE tw.user_id = '" . $user->data['user_id'] . "'";
    $query = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($query)) {
        if (isset($users[$row['uid']])) {
            $users[$row['uid']] = $users[$row['uid']] + 5;
        } else {
            $users[$row['uid']] = 5;
        }
    }
    arsort($users);
    foreach ($users as $key => $row) {
        //non tapatalk users
        if (isset($_POST['mode']) && $_POST['mode'] == 2 && in_array($key, $tapatalk_users)) {
            unset($users[$key]);
        }
        if ($key == $user->data['user_id']) {
            unset($users[$key]);
        }
        if ($key == 1) {
            unset($users[$key]);
        }
    }
    $page = intval($_POST['page']);
    $perpage = intval($_POST['perpage']);
    $start = ($page - 1) * $perpage;
    $total = count($users);
    $users_keys = array_keys($users);
    $users_slice = array_slice($users_keys, $start, $perpage);
    $id_str = implode(',', $users_slice);
    $return_user_lists = array();
    if (!empty($id_str)) {
        $sql = "SELECT * FROM " . USERS_TABLE . " WHERE user_id in (" . $id_str . ")";
        $query = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($query)) {
            $return_user_lists[] = new xmlrpcval(array('username' => new xmlrpcval(basic_clean($row['username']), 'base64'), 'user_id' => new xmlrpcval($row['user_id'], 'string'), 'icon_url' => new xmlrpcval(get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']), 'string'), 'type' => new xmlrpcval('', 'string'), 'enc_email' => new xmlrpcval(base64_encode(encrypt($row['user_email'], loadAPIKey())), 'string')), 'struct');
        }
    }
    $suggested_users = new xmlrpcval(array('total' => new xmlrpcval($total, 'int'), 'list' => new xmlrpcval($return_user_lists, 'array')), 'struct');
    return new xmlrpcresp($suggested_users);
}