Ejemplo n.º 1
0
function wp_comment_sync_to_d3forum($comment_ID = 0, $sync_mode)
{
    global $xpress_config, $xoops_db, $xoops_config, $wpdb, $blog_id;
    if (empty($blog_id)) {
        $blog_id = 1;
    }
    if (!is_d3forum_setting()) {
        die('The setting of the D3Forum comment integration is wrong. ');
    }
    $mydirname = $xoops_config->module_name;
    $d3f_forum_id = $xpress_config->d3forum_forum_id;
    $d3f_forum_dir = $xpress_config->d3forum_module_dir;
    $d3forum_prefix = get_xoops_prefix() . $d3f_forum_dir . '_';
    $xpress_prefix = get_wp_prefix();
    $wp_comments = $wpdb->comments;
    //	$wp_comments = $xpress_prefix . 'comments';
    $wp_posts = $wpdb->posts;
    //	$wp_posts = $xpress_prefix . 'posts';
    $wp_d3forum_link = $xpress_prefix . 'd3forum_link';
    $d3f_topic = $d3forum_prefix . 'topics';
    $d3f_posts = $d3forum_prefix . 'posts';
    $sql = "SELECT {$wp_comments}.comment_ID,{$wp_comments}.comment_post_ID, ";
    $sql .= "{$wp_comments}.comment_author, {$wp_comments}.comment_author_email,  {$wp_comments}.comment_date, {$wp_comments}.comment_date_gmt, ";
    $sql .= "{$wp_comments}.comment_author_url, {$wp_comments}.comment_author_IP, ";
    $sql .= "{$wp_comments}.comment_content, {$wp_comments}.comment_karma, ";
    $sql .= "{$wp_comments}.comment_approved, {$wp_comments}.comment_agent, ";
    $sql .= "{$wp_comments}.comment_type, {$wp_comments}.comment_parent, {$wp_comments}.user_id, ";
    $sql .= "{$wp_posts}.post_title ,{$wp_posts}.comment_count ";
    $sql .= "FROM {$wp_comments} INNER JOIN  {$wp_posts} ON {$wp_comments}.comment_post_ID = {$wp_posts}.ID ";
    $sql .= "WHERE (comment_ID = {$comment_ID}) AND ({$wp_comments}.comment_approved NOT LIKE 'spam') ";
    //	$row = $xoops_db->get_row($sql) ;
    $row = $wpdb->get_row($sql);
    if (empty($row)) {
        die('READ ' . $wp_comments . '_NG...' . $sql);
    }
    if (!empty($row->comment_type)) {
        return;
    }
    $forum_id = $d3f_forum_id;
    $d3forum_dirname = $d3f_forum_dir;
    $topic_external_link_id = $row->comment_post_ID;
    //There is information on WP post_ID in topic_external_link_id of D3Forum
    $topic_title = 'Re.' . addSlashes($row->post_title);
    $post_time = strtotime($row->comment_date_gmt);
    $modified_time = strtotime($row->comment_date_gmt);
    require_once get_xpress_dir_path() . 'include/general_functions.php';
    if (empty($row->user_id)) {
        $uid = wp_comment_author_to_xoops_uid($row->comment_author, $row->comment_author_email);
    } else {
        $uid = wp_uid_to_xoops_uid($row->user_id, $mydirname);
    }
    $poster_ip = "'" . addslashes($row->comment_author_IP) . "'";
    $modifier_ip = "'" . addslashes($row->comment_author_IP) . "'";
    $subject = "'" . $topic_title . "'";
    $post_text = "'" . addSlashes($row->comment_content) . "'";
    $guest_name = "'" . addSlashes($row->comment_author) . "'";
    $guest_email = "'" . $row->comment_author_email . "'";
    $guest_url = "'" . $row->comment_author_url . "'";
    $approval = $row->comment_approved;
    $comment_count = $row->comment_count;
    $comment_parent = $row->comment_parent;
    if ($sync_mode == 'delete') {
        $mode = 'delete';
        $delete_post_id = $xoops_db->get_var("SELECT post_id FROM {$wp_d3forum_link} WHERE comment_ID = {$comment_ID} AND  blog_id = {$blog_id}");
        if (empty($delete_post_id)) {
            return;
        }
        $topic_id = $xoops_db->get_var("SELECT topic_id FROM {$d3f_topic} WHERE topic_external_link_id = {$topic_external_link_id} AND forum_id = {$forum_id}");
        if (empty($topic_id)) {
            return;
        }
    } else {
        // Does the first comment (= topic) on the post exist?
        $sql = "SELECT * FROM {$d3f_topic} WHERE topic_external_link_id = {$topic_external_link_id} AND forum_id = {$forum_id}";
        $row = $xoops_db->get_row($sql);
        $topic_first_post_id = $row->topic_first_post_id;
        if (empty($row)) {
            $mode = $mode = 'newtopic';
        } else {
            $topic_id = $row->topic_id;
            // if comment on same ID exists then edits comment else reply comment
            $row = $xoops_db->get_row("SELECT * FROM {$wp_d3forum_link} WHERE comment_ID = {$comment_ID} AND blog_id = {$blog_id}");
            if (!empty($row)) {
                $mode = $mode = 'edit';
                $edit_post_id = $row->post_id;
            } else {
                $mode = $mode = 'reply';
                $reply_pid = 0;
                if ($comment_parent > 0) {
                    $reply_pid = get_d3forum_post_ID($comment_parent);
                }
                if ($reply_pid == 0) {
                    $reply_pid = $topic_first_post_id;
                    //reply_first_comment
                }
            }
        }
    }
    $modified_time = $post_time;
    // make set part of INSERT or UPDATE (refalence d3forum main/post.php)
    $set4sql = "modified_time= {$modified_time} , modifier_ip= {$modifier_ip} ";
    $set4sql .= ",subject= {$subject} ";
    $set4sql .= ",post_text= {$post_text} ";
    if ($uid == 0) {
        @(list($guest_name, $trip_base) = explode('#', $guest_name, 2));
        if (!trim(@$guest_name)) {
            $guest_name = get_xoops_config('anonymous_name', $d3f_forum_dir);
        }
        if (!empty($trip_base) && function_exists('crypt')) {
            $salt = strtr(preg_replace('/[^\\.-z]/', '.', substr($trip_base . 'H.', 1, 2)), ':;<=>?@[\\]^_`', 'ABCDEFGabcdef');
            $guest_trip = substr(crypt($trip_base, $salt), -10);
        } else {
            $guest_trip = '';
        }
        $guest_url = preg_match('#^https?\\://#', $guest_url) ? $guest_url : '';
        foreach (array('guest_name', 'guest_email', 'guest_url', 'guest_trip') as $key) {
            $set4sql .= ",{$key}='" . addslashes(${$key}) . "'";
        }
        if (!empty($guest_pass)) {
            $set4sql .= ",guest_pass_md5='" . md5($guest_pass . 'd3forum') . "'";
        }
    }
    $hide_uid = get_xoops_config('allow_hideuid', $d3f_forum_dir);
    switch ($mode) {
        case 'edit':
            $edit_post = $xoops_db->get_row("SELECT * FROM {$d3f_posts} WHERE post_id= {$edit_post_id} ");
            if (empty($edit_post)) {
                die('READ ' . $d3forum_comments . '_NG...' . $sql);
            }
            // approval
            if ($approval) {
                $set4sql .= ',approval=1';
                $topic_invisible = 0;
                $need_notify = true;
            } else {
                $set4sql .= ',approval=0';
                $topic_invisible = 0;
                $need_admin_notify = true;
            }
            // hide_uid
            if ($hide_uid) {
                $set4sql .= ",uid=0,uid_hidden='{$uid}'";
            } else {
                $set4sql .= ",uid='{$uid}',uid_hidden=0";
            }
            // update post specified post_id
            wp_d3forum_transact_make_post_history($d3forum_dirname, $edit_post_id);
            $sql = "UPDATE " . $d3f_posts . " SET {$set4sql} WHERE post_id={$edit_post_id}";
            $xoops_db->query($sql);
            $xoops_db->query($sql);
            if ($edit_post_pid == 0) {
                $sql = "UPDATE " . $d3f_topic . " SET topic_invisible={$topic_invisible} WHERE topic_id={$topic_id}";
                $xoops_db->query($sql);
            }
            wp_d3forum_sync_topic($d3forum_dirname, $topic_id, true, !$edit_post_pid);
            break;
        case 'reply':
            // approval
            if ($approval) {
                $set4sql .= ',approval=1';
                $need_notify = true;
            } else {
                $set4sql .= ',approval=0';
                $need_admin_notify = true;
            }
            // hide_uid
            if ($hide_uid) {
                $set4sql .= ",uid=0,uid_hidden='{$uid}'";
            } else {
                $set4sql .= ",uid='{$uid}',uid_hidden=0";
            }
            // create post under specified post_id
            $sql = "INSERT INTO " . $d3f_posts . " SET {$set4sql},pid={$reply_pid},topic_id={$topic_id},post_time={$post_time},poster_ip={$poster_ip}";
            $xoops_db->query($sql);
            $post_id = mysql_insert_id();
            wp_d3forum_sync_topic($d3forum_dirname, $topic_id);
            $wp_sql = "INSERT INTO {$wp_d3forum_link} ";
            $wp_sql .= "(comment_ID , post_id, wp_post_ID, forum_id, blog_id) ";
            $wp_sql .= "VALUES ";
            $wp_sql .= "({$comment_ID}, {$post_id}, {$topic_external_link_id}, {$d3f_forum_id}, {$blog_id})";
            $xoops_db->query($wp_sql);
            break;
        case 'newtopic':
            // approval
            if ($approval) {
                $set4sql .= ',approval=1';
                $topic_invisible = 0;
                $need_notify = true;
            } else {
                $set4sql .= ',approval=0';
                $topic_invisible = 0;
                $need_admin_notify = true;
            }
            // hide_uid
            if ($hide_uid) {
                $set4sql .= ",uid=0,uid_hidden='{$uid}'";
            } else {
                $set4sql .= ",uid='{$uid}',uid_hidden=0";
            }
            // create topic and get a new topic_id
            $sql = "INSERT INTO " . $d3f_topic . " SET forum_id={$forum_id},topic_invisible={$topic_invisible},topic_external_link_id='" . addslashes($topic_external_link_id) . "'";
            $xoops_db->query($sql);
            $topic_id = mysql_insert_id();
            // create post in the topic
            $sql = "INSERT INTO " . $d3f_posts . " SET {$set4sql},topic_id={$topic_id},post_time={$post_time},poster_ip={$poster_ip}";
            $xoops_db->query($sql);
            $post_id = mysql_insert_id();
            wp_d3forum_sync_topic($d3forum_dirname, $topic_id, true, true);
            $wp_sql = "INSERT INTO {$wp_d3forum_link} ";
            $wp_sql .= "(comment_ID , post_id , wp_post_ID, forum_id, blog_id) ";
            $wp_sql .= "VALUES ";
            $wp_sql .= "({$comment_ID}, {$post_id}, {$topic_external_link_id}, {$d3f_forum_id}, {$blog_id})";
            $xoops_db->query($wp_sql);
            break;
        case 'delete':
            wp_d3forum_delete_post_recursive($d3forum_dirname, $delete_post_id);
            wp_d3forum_sync_topic($d3forum_dirname, $topic_id);
            break;
        default:
    }
    // increment post
    if (is_object(@$xoopsUser) && $mode != 'edit') {
        $xoopsUser->incrementPost();
    }
    // set u2t_marked
    $allow_mark = get_xoops_config('allow_mark', $d3f_forum_dir);
    if ($uid && $allow_mark) {
        $u2t_marked = empty($_POST['u2t_marked']) ? 0 : 1;
        $sql = "UPDATE " . $d3forum_prefix . "users2topics" . " SET u2t_marked={$u2t_marked},u2t_time=UNIX_TIMESTAMP() WHERE uid={$uid} AND topic_id={$topic_id}";
        if (!$xoops_db->query($sql)) {
            $sql = "INSERT INTO " . $d3forum_prefix . "users2topics" . " SET uid={$uid},topic_id={$topic_id},u2t_marked={$u2t_marked},u2t_time=UNIX_TIMESTAMP()";
            $xoops_db->query($sql);
        }
    }
}
Ejemplo n.º 2
0
function _xpress_new($mydirname, $limit=0, $offset=0) 
{
	global $xoopsDB;

	$wp_prefix = preg_replace('/wordpress/','wp',$mydirname);
	require_once (XOOPS_ROOT_PATH . '/modules/'.$mydirname . '/include/general_functions.php');
	include(XOOPS_ROOT_PATH . '/modules/'.$mydirname . '/wp-includes/version.php');

	$modules_table = $xoopsDB->prefix('modules');
	$modSQL ="SELECT mid FROM " . $modules_table . " WHERE dirname LIKE '" . $mydirname . "'";
	$modRes = $xoopsDB->query($modSQL, 0, 0);
	$modRow = $xoopsDB->fetchArray($modRes);
	$module_id = $modRow['mid'];

	$table_config = $xoopsDB->prefix('config');
	$confSQL ="SELECT conf_value FROM " . $table_config . " WHERE (conf_modid = " . $module_id . ") AND (conf_name LIKE 'whatsnew_use_mod_date')";
	$confRes = $xoopsDB->query($confSQL, 0, 0);
	$confRow = $xoopsDB->fetchArray($confRes);
	$use_modified_date = $confRow['conf_value'];

	$url_mod = XOOPS_URL."/modules/".$mydirname;
	
	require_once (XOOPS_ROOT_PATH . '/modules/'.$mydirname . '/include/general_functions.php');
	$prefix = $xoopsDB->prefix($wp_prefix);
	$options_tables = get_table_list($prefix,'options');
	$table_count = count($options_tables);
	$sql1 = '';
	foreach( $options_tables as $options_table){
		$blog_url = get_blog_option($options_table , 'siteurl');
		$blog_url = preg_replace('/\/$/', '' ,$blog_url);
		$blogname = get_blog_option($options_table , 'blogname');
		
		$table_prefix = get_multi_prefix($options_table,'options');
		
		$table_posts      = $table_prefix . "posts";
		
		$sub_sql  = "SELECT ID, post_author, post_title, post_content, post_type, comment_count, post_date, UNIX_TIMESTAMP(post_date) AS unix_post_date, UNIX_TIMESTAMP(post_modified) AS unix_post_modified, post_status, '$blog_url' AS blog_url, '$table_prefix' AS table_prefix, '$blogname' AS blogname ";
		$sub_sql .= " FROM ".$table_posts;
		$sub_sql .= " WHERE (post_status='publish') AND (UNIX_TIMESTAMP(post_date) <= UNIX_TIMESTAMP()) ";

		if ($table_count > 1){
			$sub_sql = '(' . $sub_sql . ')';
			if (!empty($sql1)) $sql1 = $sql1 . ' UNION ';
			$sql1 = $sql1 . $sub_sql;
		} else {
			$sql1 =  $sub_sql;
		}
	}
	$sql1 .= " ORDER BY post_date DESC LIMIT $offset,$limit";

	$res1 = $xoopsDB->queryF($sql1);

	$i = 0;
	$ret = array();

	while($row1 = $xoopsDB->fetchArray($res1))
	{
		$id = $row1['ID'];
		$blog_url = $row1['blog_url'];
		$blogname = $row1['blogname'];
		$table_views   =$modules_table = $xoopsDB->prefix($wp_prefix) . "_views";
		$table_term_relationships = $row1['table_prefix'] . "term_relationships";
		$table_term_taxonomy = $row1['table_prefix'] . "term_taxonomy";
		$table_terms = $row1['table_prefix'] . "terms";
		$table_categories = $row1['table_prefix'] . "categories";
		$table_post2cat   = $row1['table_prefix'] . "post2cat";

		if ($table_count <= 1){
			if ($wp_db_version < 6124){
				$sql2 = "SELECT c.cat_ID, c.cat_name FROM ".$table_categories." c, ".$table_post2cat." p2c WHERE c.cat_ID = p2c.category_id AND p2c.post_id=".$id;
			} else {
				$sql2  = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name ";
				$sql2 .= "FROM $table_term_relationships INNER JOIN ($table_term_taxonomy INNER JOIN $table_terms ON $table_term_taxonomy.term_id = $table_terms.term_id) ON $table_term_relationships.term_taxonomy_id = $table_term_taxonomy.term_taxonomy_id ";
				$sql2 .= "WHERE ($table_term_relationships.object_id =" . $id.") AND ($table_term_taxonomy.taxonomy='category')";		
			}
			$row2 = $xoopsDB->fetchArray( $xoopsDB->query($sql2) );
			$ret[$i]['cat_link'] = $blog_url."/index.php?cat=".$row2['cat_ID'];
			$ret[$i]['cat_name'] = $row2['cat_name'];
		} else {
			$ret[$i]['cat_link'] = $blog_url;
			$ret[$i]['cat_name'] = $blogname;
		}

		if ($row1['post_type'] == 'page'){
				$ret[$i]['link']     = $blog_url."/?page_id=".$id;
		} else {
			$ret[$i]['link']     = $blog_url."/index.php?p=".$id;
		}

		$ret[$i]['title']    = $row1['post_title'];

		$ret[$i]['uid'] = wp_uid_to_xoops_uid($row1['post_author'],$mydirname);
		$ret[$i]['replies'] = $row1['comment_count'];


		if(empty($use_modified_date)) {
			$time = $row1['unix_post_date'];
		} else {

			if ($row1['unix_post_modified'] > $row1['unix_post_date']){
				$time = $row1['unix_post_modified'];
			} else {
				$time = $row1['unix_post_date'];
			}
		}

	   	$ret[$i]['time']     = $time;
		$ret[$i]['modified'] = $time;
		$ret[$i]['issued']   = $row1['unix_post_date'];
		$content=$row1['post_content'];
		$content = strip_tags($content);

		$ret[$i]['description'] = $content;

		$sql3 = "SELECT post_views FROM  " .  $table_views . " WHERE post_id = " . $id;
		$row3 = $xoopsDB->fetchArray( $xoopsDB->query($sql3) );
	   	$ret[$i]['hits']     = $row3['post_views'];



		$i++;
	}

	return $ret;
}
Ejemplo n.º 3
0
 function xpress_global_search_base($mydirname, $queryarray, $andor, $limit, $offset, $userid)
 {
     global $xoopsDB, $myts;
     require_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/general_functions.php';
     $myts =& MyTextSanitizer::getInstance();
     $xp_prefix = preg_replace('/wordpress/', 'wp', $mydirname);
     if ($userid) {
         $wp_uid = xoops_uid_to_wp_uid(intval($userid), $mydirname);
     }
     $prefix = XOOPS_DB_PREFIX . '_' . $xp_prefix;
     $posts_tables = get_table_list($prefix, 'posts');
     $i = 0;
     $ret = array();
     foreach ($posts_tables as $views_table) {
         $mid_prefix = get_multi_mid_prefix($prefix, 'posts', $views_table);
         $option_table = $prefix . $mid_prefix . 'options';
         $time_difference = get_blog_option($option_table, 'gmt_offset');
         $blog_url = get_blog_option($option_table, 'siteurl');
         $pattern = '/.*' . $mydirname . '/';
         $mid_url = preg_replace($pattern, '', $blog_url);
         $mid_url = preg_replace('/\\//', '', $mid_url);
         if (!empty($mid_url)) {
             $mid_url = $mid_url . '/';
         }
         $blog_name = get_blog_option($option_table, 'blogname');
         if (empty($mid_url)) {
             $blog_name = '';
         } else {
             $blog_name = $blog_name . ':: ';
         }
         $now = date('Y-m-d H:i:s', time() + $time_difference * 3600);
         $where = "(post_status = 'publish') AND (post_date <= '" . $now . "') AND (post_type <> 'revision') AND (post_type <> 'nav_menu_item') ";
         if (is_array($queryarray) && ($count = count($queryarray))) {
             $str_query = array();
             for ($j = 0; $j < $count; $j++) {
                 $str_query[] = "(post_title LIKE '%" . $queryarray[$j] . "%' OR post_content LIKE '%" . $queryarray[$j] . "%')";
             }
             $where .= " AND " . implode(" {$andor} ", $str_query);
         }
         if ($userid) {
             if ($wp_uid) {
                 $where .= " AND (post_author=" . $wp_uid . ")";
             } else {
                 $where .= " AND 0 ";
             }
         }
         $request = "SELECT * FROM " . $views_table . " WHERE " . $where;
         $request .= " ORDER BY post_date DESC";
         $result = $xoopsDB->query($request, $limit, $offset);
         while ($myrow = $xoopsDB->fetchArray($result)) {
             if ($myrow['post_type'] !== 'revision' && $myrow['post_type'] !== 'nav_menu_item') {
                 switch ($myrow['post_type']) {
                     case 'page':
                         $ret[$i]['link'] = $mid_url . '?page_id=' . $myrow['ID'];
                         break;
                     case 'post':
                     case '':
                         $ret[$i]['link'] = $mid_url . '?p=' . $myrow['ID'];
                         break;
                     default:
                         $ret[$i]['link'] = $mid_url . '?' . $myrow['post_type'] . '=' . $myrow['post_name'];
                 }
             }
             $ret[$i]['title'] = $blog_name . $myts->htmlSpecialChars($myrow['post_title']);
             $date_str = $myrow['post_date'];
             $yyyy = substr($date_str, 0, 4);
             $mm = substr($date_str, 5, 2);
             $dd = substr($date_str, 8, 2);
             $hh = substr($date_str, 11, 2);
             $nn = substr($date_str, 14, 2);
             $ss = substr($date_str, 17, 2);
             $ret[$i]['time'] = mktime($hh, $nn, $ss, $mm, $dd, $yyyy);
             $ret[$i]['uid'] = wp_uid_to_xoops_uid($myrow['post_author'], $mydirname);
             $context = '';
             $text = $myrow['post_content'];
             // get context for module "search"
             $showcontext = empty($_GET['showcontext']) ? 0 : 1;
             if (function_exists('search_make_context') && $showcontext) {
                 if (function_exists('easiestml')) {
                     $text = easiestml($text);
                 }
                 $full_context = strip_tags($text);
                 $context = search_make_context($full_context, $queryarray);
             }
             $ret[$i]['context'] = $context;
             $i++;
         }
     }
     return $ret;
 }