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; }
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; }
} } else { $invalid = true; $errorType = 'InvalidRequest'; $errorMessage = __('Unsupported interface or method, check supported methods by browsing to: ', 'bim-bcf-management') . plugins_url('api.php', __FILE__); } } else { $invalid = true; $errorType = 'UserException'; $errorMessage = __('Invalid token', 'bim-bcf-management'); } } elseif ($request['request']['method'] == 'getComments') { $userId = BIMsie::getUserIdByToken(isset($request['token']) ? $request['token'] : ''); if ($userId !== false) { if (isset($request['request']['parameters']['bimsieUrl'])) { $result = BIMBCFManagement::getComments($request['request']['parameters']['bimsieUrl'], $userId); if ($result === false) { $invalid = true; $errorType = 'InvalidRequest'; $errorMessage = __('Invalid parameters or not allowed to comment on this issue.', 'bim-bcf-management'); } } else { $invalid = true; $errorType = 'InvalidRequest'; $errorMessage = __('Unsupported interface or method, check supported methods by browsing to: ', 'bim-bcf-management') . plugins_url('api.php', __FILE__); } } else { $invalid = true; $errorType = 'UserException'; $errorMessage = __('Invalid token', 'bim-bcf-management'); }
fclose($file); } else { ?> <p> <?php _e('Could not write extensions.xsd, make sure the file is writable.', 'bim-bcf-management'); ?> <br /> <?php print plugin_dir_path(__FILE__) . 'xsd/extensions.xsd'; ?> </p> <?php } } else { $bimBCFManagementOptions = BIMBCFManagement::getOptions(); } $postTypes = get_post_types(array(), 'objects'); $pages = get_posts(array('post_type' => 'page', 'posts_per_page' => -1)); ?> <div class="wrap"> <div class="icon32" id="icon-options-general"></div> <h2>BIM BCF Management Options</h2> <form method="post" enctype="multipart/form-data"> <table class="form-table"> <tr valign="top"> <td><label for="bcf-issue-post-type">BCF Issue Post Type</label></td> <td> <?php if (is_array($postTypes)) { ?>
} } if (isset($error) && $error !== false) { $response['error'] = $error; } } elseif ($_POST['method'] == 'submitProjects') { // set this project for this issue and retrieve a list of revisions for this project from the BIMsie server $projects = isset($_POST['projects']) ? $_POST['projects'] : ''; $projects = explode(',', $projects); array_walk($projects, 'intval'); // I think project oid should always be an integer $names = isset($_POST['names']) ? $_POST['names'] : ''; $names = explode(',', $names); $revisions = isset($_POST['revisions']) ? $_POST['revisions'] : ''; $revisions = explode(',', $revisions); $projectsLackingRevision = BIMBCFManagement::setProjectForPendingIssues($projects, $names, $revisions); foreach ($projectsLackingRevision as $key => $project) { if ($project['oid'] != '') { $BIMsieResponse = BIMsie::request($uri, $token, 'Bimsie1ServiceInterface', 'getAllRevisionsOfProject', array('poid' => $project['oid'])); $error = BIMsie::getErrorMessage($BIMsieResponse); if ($error === false && isset($BIMsieResponse->response) && isset($BIMsieResponse->response->result)) { $projectsLackingRevision[$key]['revisions'] = $BIMsieResponse->response->result; foreach ($projectsLackingRevision[$key]['revisions'] as $key2 => $revision) { if (isset($revision->date) && is_numeric($revision->date)) { $projectsLackingRevision[$key]['revisions'][$key2]->dateString = date('d-m-Y H:i', $revision->date * 0.001); } else { $projectsLackingRevision[$key]['revisions'][$key2]->dateString = __('unknown', 'bim-bcf-management'); } } } else { if (isset($response['error'])) {