public static function getMostRecentCommentsForProjects($bimsieUrl, $projects)
 {
     global $wpdb;
     if (!isset($projects) || !is_array($projects)) {
         return array();
     }
     $options = BIMBCFManagement::getOptions();
     // get issues for bimsie url and poid
     $bimsieUrl = BIMBCFManagement::removeProtocol($bimsieUrl);
     $issues = array();
     foreach ($projects as $project) {
         $issues = array_merge($issues, get_posts(array('post_type' => $options['bcf_issue_post_type'], 'posts_per_page' => -1, 'meta_query' => array('relation' => 'AND', array('key' => 'import_status', 'value' => 'complete'), array('key' => '_bimsie_uri', 'value' => $bimsieUrl), array('key' => 'poid', 'value' => $project->oid)))));
     }
     $includeList = array();
     foreach ($issues as $issue) {
         $includeList[] = $issue->ID;
     }
     if (count($includeList) > 0) {
         $commentPostIds = $wpdb->get_results("SELECT comment_post_ID\n               FROM {$wpdb->comments}\n               WHERE comment_post_ID IN (" . implode(', ', $includeList) . ")\n               ORDER BY comment_date DESC\n               LIMIT 10");
     } else {
         $commentPostIds = array();
     }
     $markups = array();
     $comments = array();
     foreach ($commentPostIds as $commentPostId) {
         if (!isset($markups[$commentPostId->comment_post_ID])) {
             $markups[$commentPostId->comment_post_ID] = get_post_meta($commentPostId->comment_post_ID, 'markup', true);
         }
         $comments[] = array_pop($markups[$commentPostId->comment_post_ID]['Comment']);
     }
     return $comments;
 }
Esempio n. 2
0
 public static function getServerByUri($uri, $userId = -1)
 {
     $servers = BIMsie::getServers(false, $userId);
     $foundServer = false;
     foreach ($servers as $server) {
         $oldServer = $server;
         if (BIMBCFManagement::removeProtocol($server['uri']) == BIMBCFManagement::removeProtocol($uri)) {
             $foundServer = $server;
             if ($foundServer['remember'] == 0) {
                 if (isset($_POST['username']) && isset($_POST['password'])) {
                     $foundServer['username'] = $_POST['username'];
                     $foundServer['password'] = $_POST['password'];
                 }
                 if (isset($_POST['remember']) && $_POST['remember'] != '') {
                     $foundServer['remember'] = 1;
                 }
             }
             if ($foundServer['remember'] == 0 || !isset($foundServer['token']) || $foundServer['tokenValid'] < time()) {
                 $token = BIMsie::publicRequest($foundServer['uri'], 'Bimsie1AuthInterface', 'login', array('username' => isset($foundServer['username']) ? $foundServer['username'] : '', 'password' => isset($foundServer['password']) ? $foundServer['password'] : ''));
                 if (isset($token) && isset($token->response) && isset($token->response->result) && BIMsie::getErrorMessage($token) === false) {
                     $token = $token->response->result;
                     $foundServer['token'] = $token;
                     $foundServer['tokenValid'] = time() + BIMsie::$tokenTimeout;
                     if ($foundServer['remember'] == 1) {
                         update_user_meta($userId == -1 ? get_current_user_id() : $userId, 'bimsie-servers', $foundServer, $oldServer);
                     }
                 }
             }
             break;
         }
     }
     return $foundServer;
 }