function wpu_get_comment_author_link() { global $comment; $uID = get_wpu_user_id($comment->user_id); if (empty($uID)) { return $wpu_link = get_comment_author(); } else { global $scriptPath; if (empty($scriptPath)) { $connSettings = get_settings('wputd_connection'); $phpbbPath = $connSettings['path_to_phpbb']; } else { $phpbbPath = $scriptPath; } if (file_exists($phpbb_root_path . 'phpbb_seo/phpbb_seo_class.php')) { return $wpu_link = '<a href="' . $phpbbPath . 'member' . $uID . '.html">' . $comment->comment_author . '</a>'; } else { return $wpu_link = '<a href="' . $phpbbPath . 'memberlist.php?mode=viewprofile&u=' . $uID . '" rel="nofollow">' . $comment->comment_author . '</a>'; } } }
/** * Cross-posts a blog-post that was just added, to the relevant forum */ public function do_crosspost($postID, $post, $future = false) { global $phpbbForum, $phpbb_root_path, $phpEx, $db, $auth; $forum_id = false; if (isset($_POST['sel_wpuxpost']) && isset($_POST['chk_wpuxpost'])) { $forum_id = (int) $_POST['sel_wpuxpost']; } else { if ($this->get_setting('xpostforce') > -1) { $forum_id = $this->get_setting('xpostforce'); } else { if ($future) { $forum_id = get_post_meta($postID, '_wpu_future_xpost', true); if ($forum_id === '') { $forum_id = false; } else { $forum_id = (int) $forum_id; delete_post_meta($postID, '_wpu_future_xpost'); } } } } // If this is already cross-posted, then edit the post $details = $this->get_xposted_details($postID); if ($forum_id === false && $details === false) { return false; } $fStateChanged = $phpbbForum->foreground(); // if the author was a different user, use them as the topic author, // but still authenticate as the user who is publishing $phpbbID = get_wpu_user_id($post->post_author); if ($phpbbID > 1) { $topicUsername = $phpbbForum->get_userdata('username', $phpbbID); } else { $topicUsername = $phpbbForum->get_username(); } $mode = 'post'; $prefix = $this->get_setting('xpostprefix'); $subject = htmlspecialchars($prefix . $post->post_title, ENT_COMPAT, 'UTF-8'); $data = array(); $data['post_time'] = 0; if ($details !== false) { if (isset($details['post_id'])) { $mode = 'edit'; //$subject = $details['post_subject']; // commented, because we may want to edit the post title after xposting $forum_id = $details['forum_id']; $data['topic_id'] = $details['topic_id']; $data['post_id'] = $details['post_id']; $data['poster_id'] = $details['poster_id']; $data['post_time'] = $details['post_time']; $data['topic_type'] = $details['topic_type']; $topicUsername = $details['topic_first_poster_name']; } } // If this is a future xpost, authenticate as the user who made the post if ($future) { // get phpBB user IP (from WP meta, so need to exit phpBB env) $phpbbForum->background(); $phpbbIP = get_post_meta($postID, '_wpu_future_ip', true); delete_post_meta($postID, '_wpu_future_ip'); $phpbbForum->foreground(); $phpbbForum->transition_user($phpbbID, $phpbbIP); } //Check that user has the authority to cross-post there // If we are editing a post, check other permissions if it has been made global/sticky etc. if ($mode == 'edit') { if ($data['topic_type'] == POST_GLOBAL && !$auth->acl_getf('f_announce', 0)) { wp_die(__('You do not have permission required to edit global announcements', 'wp-united')); } if ($data['topic_type'] == POST_ANNOUNCE && !$auth->acl_getf('f_announce', $forum_id)) { wp_die(__('You do not have the permission required to edit this announcement', 'wp-united')); } if ($data['topic_type'] == POST_STICKY && !$auth->acl_getf('f_sticky', $forum_id)) { wp_die(__('You do not have the permission required to edit stickies', 'wp-united')); } if (!$auth->acl_getf('f_edit', $forum_id)) { wp_die(__('You do not have the permission required to edit posts in this forum', 'wp-united')); } } if ($forum_id > 0) { $can_crosspost_list = $this->get_xpost_forum_list(); if (!in_array($forum_id, (array) $can_crosspost_list['forum_id'])) { $phpbbForum->restore_state($fStateChanged); return false; } } $phpbbForum->background(); $content = $post->post_content; // should we post an excerpt, or a full post? $postType = 'excerpt'; if (!$future) { if ($this->get_setting('xposttype') == 'askme') { if (isset($_POST['rad_xpost_type'])) { $postType = $_POST['rad_xpost_type'] == 'fullpost' ? 'fullpost' : 'excerpt'; } } else { if ($this->get_setting('xposttype') == 'fullpost') { $postType = 'fullpost'; } } update_post_meta($postID, '_wpu_posttype', $postType); } else { $postType = get_post_meta($postID, '_wpu_posttype', true); } // Get the post excerpt if ($postType == 'excerpt') { if (!($excerpt = $post->post_excerpt)) { if (preg_match('/<!--more(.*?)?-->/', $content, $matches)) { $excerpt = explode($matches[0], $content, 2); $content = $excerpt[0]; } } else { $content = $excerpt; } } if (defined('WPU_SHOW_TAGCATS') && WPU_SHOW_TAGCATS) { $cat_list = $tag_list = ''; } else { $cats = array(); $tags = array(); $tag_list = ''; $cat_list = ''; $cats = get_the_category($postID); if (sizeof($cats)) { foreach ($cats as $cat) { $cat_list .= empty($cat_list) ? $cat->cat_name : ', ' . $cat->cat_name; } } $tag_list = ''; $tag_list = get_the_term_list($post->ID, 'post_tag', '', ', ', ''); if ($tag_list == "") { $tag_list = __('No tags defined.', 'wp-united'); } $tags = !empty($tag_list) ? '[b]' . __('Tags: ', 'wp-united') . "[/b]{$tag_list}\n" : ''; $cats = !empty($cat_list) ? '[b]' . __('Posted under: ', 'wp-united') . "[/b]{$cat_list}\n" : ''; } $content = sprintf(__('This is a %1$sblog post%2$s. To read the original post, please %3$sclick here »%4$s', 'wp-united'), '[b]', '[/b]', '[url=' . get_permalink($postID) . ']', '[/url]') . "\n\n" . $content . "\n\n" . $tags . $cats; $phpbbForum->foreground(); $content = utf8_normalize_nfc($content, '', true); $subject = utf8_normalize_nfc($subject, '', true); wpu_html_to_bbcode($content, 0); //$uid=0, but will get removed) $uid = $poll = $bitfield = $options = ''; generate_text_for_storage($content, $uid, $bitfield, $options, true, true, true); require_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx; $data = array_merge($data, array('forum_id' => $forum_id, 'icon_id' => false, 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $content, 'message_md5' => md5($content), 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'post_edit_locked' => ITEM_LOCKED, 'topic_title' => $subject, 'notify_set' => false, 'notify' => false, 'enable_indexing' => true)); $topic_url = submit_post($mode, $subject, $topicUsername, POST_NORMAL, $poll, $data); // If this is a future xpost, switch back to current user if ($future) { $phpbbForum->transition_user(); } //Update the cross-posted columns so we can remain "in sync" with it, and set the post time/date if ($data !== false && $mode == 'post' && !empty($data['post_id'])) { // Get timestamp for WP's gmt date. the fallback options won't give correct timezones, but should // only get used if the WP time is really unexpected (e.g. broken by a plugin). // We need to set this because this could be a past or a future post $utcTime = strtotime($post->post_date_gmt . ' UTC'); $utcTime = $utcTime === false ? strtotime($post->post_date) : $utcTime; $utcTimeSql = $utcTime !== false ? ', topic_time =' . $utcTime : ''; $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_wpu_xpost = ' . $postID . "{$utcTimeSql} WHERE topic_id = {$data['topic_id']}"; if (!($result = $db->sql_query($sql))) { $phpbbForum->restore_state($fStateChanged); wp_die(__('Could not access the WP-United database fields. Please ensure WP-United is installed correctly. ', 'wp-united')); } if ($utcTime !== false) { $sql = 'UPDATE ' . POSTS_TABLE . " SET post_time = {$utcTime} WHERE post_id = {$data['post_id']}"; $result = $db->sql_query($sql); } $db->sql_freeresult($result); $phpbbForum->restore_state($fStateChanged); return true; } else { if ($mode == 'edit' && !empty($data['topic_id'])) { $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_type = ' . $data['topic_type'] . " WHERE topic_id = {$data['topic_id']}"; $result = $db->sql_query($sql); $db->sql_freeresult($result); } } $phpbbForum->restore_state($fStateChanged); }
/** * Returns the phpBB user profile link for the current commenter * @author John Wells * @since v0.7.0 */ function wpu_get_comment_author_link($link = '') { global $comment, $phpbb_root_path, $phpbbForum; // comment URL could already be filled by cross-posted comments if (!empty($comment->phpbb_id) && !empty($link)) { return $link; } if (empty($comment->user_id)) { return empty($link) ? '<a href="' . $comment->comment_author_url . '" rel="nofollow">' . $comment->comment_author . '</a>' : $link; } $uID = get_wpu_user_id($comment->user_id); if (empty($uID)) { return empty($link) ? '<a href="' . $comment->comment_author_url . '" rel="nofollow">' . $comment->comment_author . '</a>' : $link; } else { if ($phpbbForum->seo) { return $wpu_link = '<a href="' . $phpbbForum->get_board_url() . 'member' . $uID . '.html">' . $comment->comment_author . '</a>'; } else { return $wpu_link = '<a href="' . $phpbbForum->get_board_url() . 'memberlist.php?mode=viewprofile&u=' . $uID . '" rel="nofollow">' . $comment->comment_author . '</a>'; } } }