Ejemplo n.º 1
0
function commsy_auth()
{
    global $commsy_auth_commsy_url;
    if (isset($_GET['commsy_session_id'])) {
        // try to authenticate via session
        try {
            if ($GLOBALS['blog_id'] > 1) {
                $options = array();
                if (defined('WP_PROXY_HOST')) {
                    $options['proxy_host'] = WP_PROXY_HOST;
                }
                if (defined('WP_PROXY_PORT')) {
                    $options['proxy_port'] = WP_PROXY_PORT;
                }
                $soapClient = new SoapClient($commsy_auth_commsy_url . '/soap_wsdl.php', $options);
                $user = $soapClient->wordpressAuthenticateViaSession($_GET['commsy_session_id']);
                if (isset($user['login'])) {
                    #$addUserToBlog = (false == get_user_by('login', $user['login']));
                    $user_id = cs_update_user($user);
                    // $blogId ??? (15.11.2010 IJ)
                    $blogId = $GLOBALS['blog_id'];
                    // (12.05.2011 js)
                    $blogusers = get_users(array('blog_id' => $blogId));
                    $addUserToBlog = true;
                    foreach ($blogusers as $bloguser) {
                        if ($bloguser->ID == $user_id) {
                            $addUserToBlog = false;
                        }
                    }
                    if ($addUserToBlog) {
                        add_user_to_blog($blogId, $user_id, get_option('default_role'));
                    }
                }
                if ($user_id) {
                    if (is_user_logged_in()) {
                        wp_logout();
                    }
                    add_filter('authenticate', 'cs_authenticate_hashed', 99, 3);
                    $result = wp_signon(array('user_login' => $user['login'], 'user_password' => $user['password']));
                    if (!is_wp_error($result)) {
                        add_action('get_header', 'commsy_clean_permalink', 0);
                    }
                    remove_filter('authenticate', 'cs_authenticate_hashed');
                    //wp_login();
                }
            }
        } catch (Exception $e) {
            echo $e->getMessage();
            // session not valid, do nothing
        }
    }
}
Ejemplo n.º 2
0
 /**
  * @param string $session_id session_id to authenticate user
  * @param array $post Data to insert
  * @param array $user Data to insert
  * @param int $blogId Data to insert
  * @param string $category Data to insert
  * @return int Id of Post or 0 on error
  */
 public function insertPost($session_id, $post, $user, $blogId, $category, $postId)
 {
     if ($this->_isSessionValid($session_id) and $this->_isUserAllowed($session_id, CS_ROLE_USER, $blogId)) {
         try {
             if ($blogId == 0) {
                 throw new Exception('Invalid Blog ID!');
             }
             switch_to_blog($blogId);
             $catId = get_cat_ID($category);
             if ($catId == 0) {
                 include_once 'wp-admin/includes/taxonomy.php';
                 $catId = wp_create_category($category);
             }
             $post['post_category'] = array($catId);
             $post['post_author'] = cs_update_user($user);
             if (!$this->_isUserOfBlog($user['login'], $blogId)) {
                 $success = add_user_to_blog($blogId, $post['post_author'], get_option('default_role'));
             }
             if ($postId != '') {
                 $post['ID'] = $postId;
                 wp_update_post($post);
             } else {
                 $postId = wp_insert_post($post);
             }
             restore_current_blog();
         } catch (Exception $e) {
             throw new SoapFault('insertpost', 'Insert Post failed: ' . $e->getMessage());
         }
     } else {
         if (!$this->_isSessionValid($session_id)) {
             throw new SoapFault('insertPost', 'insert post failed: Session-ID (' . $session_id . ') is not valid');
         } else {
             throw new SoapFault('insertPost', 'insert post failed: User (' . $this->_sessionid_to_userid_array[$session_id] . ') is not allowed to add post to this blog (' . $blogId . ').');
         }
     }
     return $postId;
 }