function lccc_breadcrumb() { $crumb_seperator = ' > '; $base_url = get_option('lccc_base_path', ''); $domain = str_replace("/", "", str_replace("http://", "", network_site_url())); if ($base_url == true) { $base_url_pieces = explode("/", $base_url); $base_breadcrumb = '<a href="/" alt="LCCC Home" class="breadcrumb_crumb">Home</a>' . $crumb_seperator; $breadcrumb = $base_breadcrumb; foreach ($base_url_pieces as $url_piece) { $blog_id = get_blog_id_from_url($domain, "/" . $url_piece . "/"); $site_details = get_blog_details($blog_id); $breadcrumb = $breadcrumb . '<a href="/' . $url_piece . '/" class="breadcrumb_crumb">' . $site_details->blogname . '</a>' . $crumb_seperator; } return $breadcrumb; } else { return; } }
/** * Filters a URL in order to apply domain mapping. * * @since 150821 Improving multisite compat. * * @param string $url The input URL to filter. * * @return string The filtered URL; else the original URL. * * @note The return value of this function is NOT cached, but inner portions are. */ public function domainMappingUrlFilter($url) { $original_url = (string) $url; // Preserve. $url = trim((string) $url); if (!is_multisite() || !$this->canConsiderDomainMapping()) { return $original_url; // Not possible. } if (!$url || !($url_parts = $this->parseUrl($url))) { return $original_url; // Not possible. } if (empty($url_parts['host'])) { return $original_url; // Not possible. } $blog_domain = mb_strtolower($url_parts['host']); // In the unfiltered URL. $blog_path = $this->hostDirToken(false, false, !empty($url_parts['path']) ? $url_parts['path'] : '/'); if (!($blog_id = (int) get_blog_id_from_url($blog_domain, $blog_path))) { return $original_url; // Not possible. } if (!($domain = $this->domainMappingBlogDomain($blog_id)) || $domain === $blog_domain) { return $original_url; // Not applicable. } $url_parts['host'] = $domain; // Filter the URL now. if (!empty($url_parts['path']) && $url_parts['path'] !== '/') { if ($host_base_dir_tokens = trim($this->hostBaseDirTokens(false, false, $url_parts['path']), '/')) { $url_parts['path'] = preg_replace('/^\\/' . preg_quote($host_base_dir_tokens, '/') . '(\\/|$)/ui', '${1}', $url_parts['path']); } } return $url = $this->unParseUrl($url_parts); }
/** * Set any additional blogs to query along with the current blog * * This method accepts an array of additional blog names, in the format of vip.wordpress.com, * that should be queried. * * @param array $domains The additional blogs to query */ public function set_additional_blogs($domains = array()) { $this->additional_indices = array(); foreach ($domains as $domain) { $blog_id = (int) get_blog_id_from_url($domain); if ($blog_id) { $this->additional_indices[] = array('blog_id' => $blog_id); } } }
function folios2eval_profpage($atts) { global $wpdb; $user = wp_get_current_user(); $major = get_the_user_major($user->ID); $eval_table_name = 'wp_seufolios_evaluations'; $max_evals = 2; //!!HARD CODED!!! $return = ''; $folio_ids = $wpdb->get_results("SELECT blogid FROM wp_seufolios_folios2eval WHERE deptid=" . $major); foreach ($folio_ids as $id) { $folios[] = get_blog_details($id->blogid); } $return .= "<style>.folios li{color: #666;}.callout-right{font-size:0.85em;margin:2em;padding:0.5em;float:right; background-color:white;border:thin solid #ccc; width:250px;max-width:40%;box-shadow: 5px 5px 3px #888888;}</style>\n"; $time = date('Y-m-d H:i:s', time() - 7776000); $sql = "SELECT id FROM {$eval_table_name} WHERE profid=" . $user->ID . " AND submittime>'" . $time . "'"; $result = $wpdb->get_results($sql); $return .= "<p>Hi {$user->user_nicename},</p><p>"; if ($wpdb->num_rows) { $return .= "Congratulations! "; } $return .= "You've completed <strong>" . $wpdb->num_rows . "</strong> evaluations so far this semester"; $sql = "SELECT id FROM {$eval_table_name} WHERE profid=" . $user->ID; $result = $wpdb->get_results($sql); $return .= " (and <strong>" . $wpdb->num_rows . "</strong> all time).</p>\n<hr>\n"; $temp_return = "<p class='callout-right'>When you're ready to give feedback on the portfolio click the <em>Evaluate</em> link in the black admin bar at the top of the screen.<br><br>Oh, and once you've opened the evaluation form please either complete the evaluation or delete your feedback. Otherwise we assume you'll finish it and won't assign it to anyone else.</p>\n\t<p>There's still work to be done, though. The portfoios below need to be evaluated. Mind doing one?</p>\n<ul class='folios'>\n"; $count = 0; foreach ($folios as $folio) { $student = get_user_by('email', get_blog_option($folio->blog_id, 'admin_email')); $result = $wpdb->get_results("SELECT id FROM {$eval_table_name} WHERE studentid=" . $student->ID); if ($max_evals - $wpdb->num_rows > 0) { $temp_return .= "<li><a href='http://" . $folio->domain . $folio->path . "' target='_blank'>" . $student->user_nicename . " - " . get_blog_option($folio->blog_id, 'blogname') . "</a> (Needs <strong>" . ($max_evals - $wpdb->num_rows) . "</strong> more evaluation" . ($max_evals - $wpdb->num_rows > 1 ? "s)" : ")") . "</li>\n"; $count++; } } $temp_return .= "</ul>"; if ($count) { $return .= $temp_return; } else { $return .= "<p>Looks like the portfolios have all been evaluated this year. You're done!</p>"; } //favorites $star_table_name = "wp_seufolios_starred"; $portfolios = $wpdb->get_results("SELECT * FROM {$star_table_name} WHERE deptid={$major}"); if ($portfolios) { $return .= "<h2>Department's Favorites</h2>\n<ul>"; //$return .= print_r($portfolios, true); foreach ($portfolios as $p) { $profs = unserialize($p->profids); $p_url = parse_url($p->blogurl); if (strlen($p_url['path'])) { if (substr($p_url['path'], -1) != '/') { $p_url['path'] = $p_url['path'] . '/'; } $p_blog = get_blog_details(get_blog_id_from_url($p_url['host'], $p_url['path'])); } else { $p_blog = get_blog_details(get_blog_id_from_url($p_url['host'])); } $plist[]['txt'] = "<li><a href='{$p->blogurl}'>{$p_blog->blogname}</a> (" . count($profs) . " favorite" . (count($profs) > 1 ? "s)" : ")") . "</li>"; $plist[]['count'] = count($profs); } usort($plist, "cmp_plist"); foreach ($plist as $pl) { $return .= $pl['txt']; } $return .= "</ul>"; } return $return; }
<?php require_once './config.php'; // require_once('./classes/MySQL.class.php'); require_once './classes/MySQL.class.php'; require_once '../wp-load.php'; global $wpdb; //echo get_blog_id_from_url('lola-fr.restofactory.be'); $resto_details = $wpdb->get_results("SELECT url_resto FROM wp_opengraphy WHERE wp_id_blog IS NULL"); // print_r($resto_details); foreach ($resto_details as $value) { //print_r($value->url_resto."/opengraphy/index.php"); //file_get_contents($value->url_resto); //print_r($value->url_resto); $url_resto = explode('//', $value->url_resto); $wp_url = $value->url_resto; $blog_id = get_blog_id_from_url($url_resto[1]); if ($blog_id != '0') { $wpdb->query("UPDATE wp_opengraphy SET wp_id_blog = {$blog_id} WHERE url_resto = '{$wp_url}'"); } } //print_r($resto_details); //opengraphy/index.php
/** * cfgp_get_shadow_blog_id * * "get_blog_id_from_url" function may return a zero, so we want to force a bool false if that's the case. Otherwise return the blog id. * * @return bool/int */ function cfgp_get_shadow_blog_id() { /* Allow an override here */ if (defined('CFGP_BLOG_ID') && CFGP_BLOG_ID) { return CFGP_BLOG_ID; } /* Utilize the domain to get the blog id */ $cfgp_blog_id = get_blog_id_from_url(CFGP_SITE_DOMAIN); return $cfgp_blog_id === 0 ? false : $cfgp_blog_id; }
/** * When deleted with the drop parameter as true, the cache will first be false, then set to * -1 after an attempt at `get_blog_id_from_url()` is made. */ function test_get_blog_id_from_url_after_dropped() { $blog_id = self::factory()->blog->create(); $details = get_blog_details($blog_id, false); $key = md5($details->domain . $details->path); wpmu_delete_blog($blog_id, true); $this->assertEquals(false, wp_cache_get($key, 'blog-id-cache')); $this->assertEquals(0, get_blog_id_from_url($details->domain, $details->path)); $this->assertEquals(-1, wp_cache_get($key, 'blog-id-cache')); }
/** * Fix links and forms * * @param none * @return void */ public function fixLinksAndForms() { global $wpdb; // Update anchor and form tags to appropriate URL's preg_match_all('/\\<(a|form)[^>]+[\'"]((http|https):\\/\\/[^\'"]+)[\'"][^>]*>/im', $this->_html, $matches); for ($i = 0; $i < sizeof($matches[0]); $i++) { $html = $matches[0][$i]; $type = $matches[1][$i]; $url = $matches[2][$i]; $scheme = $matches[3][$i]; $updated = false; $post_id = null; $blog_id = null; $force_ssl = null; $url_path = '/'; if (!$this->getPlugin()->isUrlLocal($url)) { continue; } if ($url != '' && ($url_parts = parse_url($url)) && isset($url_parts['path'])) { if ($this->getPlugin()->getHttpsUrl()->getPath() != '/') { if ($this->getPlugin()->getSetting('ssl_host_diff')) { $url_parts['path'] = str_replace($this->getPlugin()->getHttpsUrl()->getPath(), '', $url_parts['path']); } if ($this->getPlugin()->getHttpUrl()->getPath() != '/') { $url_parts['path'] = str_replace($this->getPlugin()->getHttpUrl()->getPath(), '', $url_parts['path']); } } // qTranslate integration - strips language from beginning of url path if (defined('QTRANS_INIT') && constant('QTRANS_INIT') == true) { global $q_config; if (isset($q_config['enabled_languages'])) { foreach ($q_config['enabled_languages'] as $language) { $url_parts['path'] = preg_replace('/^\\/' . $language . '\\//', '/', $url_parts['path']); } } } if (preg_match("/page_id=([\\d]+)/", parse_url($url, PHP_URL_QUERY), $postID)) { $post_id = $postID[1]; } else { if (isset($url_parts['path']) && ($url_parts['path'] == '' || $url_parts['path'] == '/')) { if (get_option('show_on_front') == 'page') { $post_id = get_option('page_on_front'); } } else { if (isset($url_parts['path']) && ($post = get_page_by_path($url_parts['path']))) { $post_id = $post->ID; } } } if (is_multisite() && isset($url_parts['host'])) { if (is_subdomain_install()) { $blog_id = get_blog_id_from_url($url_parts['host'], '/'); } else { $url_path_segments = explode('/', $url_parts['path']); if (sizeof($url_path_segments) > 1) { foreach ($url_path_segments as $url_path_segment) { if (is_null($blog_id) && $url_path_segment != '') { $url_path .= $url_path_segment . '/'; if (($blog_id = get_blog_id_from_url($url_parts['host'], $url_path)) > 0) { break; } else { $blog_id = null; } } } } } if (!is_null($blog_id) && $blog_id != $wpdb->blogid) { // URL Filters if (sizeof((array) $this->getPlugin()->getSetting('secure_filter', $blog_id)) > 0) { foreach ($this->getPlugin()->getSetting('secure_filter', $blog_id) as $filter) { if (preg_match('/' . str_replace('/', '\\/', $filter) . '/', $url) === 1) { $force_ssl = true; } } } if (($this->getPlugin()->getSetting('ssl_admin', $blog_id) || defined('FORCE_SSL_ADMIN') && constant('FORCE_SSL_ADMIN')) && strpos($url_parts['path'], 'wp-admin') !== false && (!$this->getPlugin()->getSetting('ssl_host_diff', $blog_id) || $this->getPlugin()->getSetting('ssl_host_diff', $blog_id) && function_exists('is_user_logged_in') && is_user_logged_in())) { $force_ssl = true; } else { if (is_null($force_ssl) && $this->getPlugin()->getSetting('exclusive_https', $blog_id)) { $force_ssl = false; } else { if (strpos($url, 'https://') === 0) { $force_ssl = true; } } } } } } // Only apply force_ssl filters for current blog if (is_null($blog_id)) { $force_ssl = apply_filters('force_ssl', null, isset($post_id) ? $post_id : 0, $url); } if ($force_ssl == true) { if (is_null($blog_id)) { $updated = $this->getPlugin()->makeUrlHttps($url); } else { if ($this->getPlugin()->getSetting('ssl_host', $blog_id)) { $ssl_host = $this->getPlugin()->getSetting('ssl_host', $blog_id); } else { $ssl_host = parse_url(get_home_url($blog_id, '/'), PHP_URL_HOST); } if (is_subdomain_install()) { $host = $url_parts['host'] . '/'; } else { $host = $url_parts['host'] . '/' . $url_path; } $updated = str_replace($url_parts['scheme'] . '://' . $host, $ssl_host, $url); } $this->_html = str_replace($html, str_replace($url, $updated, $html), $this->_html); } else { if (!is_null($force_ssl) && !$force_ssl) { if (is_null($blog_id)) { $updated = $this->getPlugin()->makeUrlHttp($url); } else { if (is_subdomain_install()) { $host = $url_parts['host'] . '/'; } else { $host = $url_parts['host'] . '/' . $url_path; } $updated = str_replace($url_parts['scheme'] . '://' . $host, get_home_url($blog_id, '/'), $url); } $this->_html = str_replace($html, str_replace($url, $updated, $html), $this->_html); } } // Add log entry if this change hasn't been logged if ($updated && $url != $updated) { $log = '[FIXED] Element: <' . $type . '> - ' . $url . ' => ' . $updated; if (!in_array($log, $this->getPlugin()->getLogger()->getLog())) { $this->getPlugin()->getLogger()->log($log); } } } }
/** RESTful endpoint for this multisite function. * * Get $_REQUEST options for this endpoint: * * u (optional) -- Username (if not logged in) * p (optional) -- Password (if not logged in) * domain (required) full domain we want the blog id for * path (optional) path we want the blog id for (defaults to '/') * */ public function get_blog_id_from_url() { global $json_api; $this->_verify_admin(); extract($_REQUEST); if (!isset($domain)) { $json_api->error(__("You must send the 'domain' parameter.")); } if (!isset($path)) { $path = '/'; } if ($blog_id = get_blog_id_from_url($domain, $path)) { return array("blog_id" => $blog_id); } else { $json_api->error(__("No blogs were found for this user.")); } }
if (!is_multisite() || !$self->canConsiderDomainMapping()) { return $original_url; // Not possible. } if (!$url || !($url_parts = $self->parseUrl($url))) { return $original_url; // Not possible. } if (empty($url_parts['host'])) { return $original_url; // Not possible. } $blog_domain = strtolower($url_parts['host']); // In the unfiltered URL. $blog_path = $self->hostDirToken(false, false, !empty($url_parts['path']) ? $url_parts['path'] : '/'); if (!($blog_id = (int) get_blog_id_from_url($blog_domain, $blog_path))) { return $original_url; // Not possible. } if (!($domain = $self->domainMappingBlogDomain($blog_id)) || $domain === $blog_domain) { return $original_url; // Not applicable. } $url_parts['host'] = $domain; // Filter the URL now. if (!empty($url_parts['path']) && $url_parts['path'] !== '/') { if ($host_base_dir_tokens = trim($self->hostBaseDirTokens(false, false, $url_parts['path']), '/')) { $url_parts['path'] = preg_replace('/^\\/' . preg_quote($host_base_dir_tokens, '/') . '(\\/|$)/i', '${1}', $url_parts['path']); } } return $url = $self->unParseUrl($url_parts);
function s4w_build_document($post_info, $domain = NULL, $path = NULL) { global $blog_id; global $current_blog; $doc = NULL; $plugin_s4w_settings = s4w_get_option(); $exclude_ids = $plugin_s4w_settings['s4w_exclude_pages']; $categoy_as_taxonomy = $plugin_s4w_settings['s4w_cat_as_taxo']; $index_comments = $plugin_s4w_settings['s4w_index_comments']; $index_custom_fields = $plugin_s4w_settings['s4w_index_custom_fields']; if ($post_info) { # check if we need to exclude this document if (is_multisite() && in_array($current_blog->domain . $post_info->ID, (array) $exclude_ids)) { return NULL; } else { if (!is_multisite() && in_array($post_info->ID, (array) $exclude_ids)) { return NULL; } } $doc = new Apache_Solr_Document(); $auth_info = get_userdata($post_info->post_author); # wpmu specific info if (is_multisite()) { // if we get here we expect that we've "switched" what blog we're running // as if ($domain == NULL) { $domain = $current_blog->domain; } if ($path == NULL) { $path = $current_blog->path; } $blogid = get_blog_id_from_url($domain, $path); $doc->setField('id', $domain . $path . $post_info->ID); $doc->setField('permalink', get_blog_permalink($blogid, $post_info->ID)); $doc->setField('blogid', $blogid); $doc->setField('blogdomain', $domain); $doc->setField('blogpath', $path); $doc->setField('wp', 'multisite'); } else { $doc->setField('id', $post_info->ID); $doc->setField('permalink', get_permalink($post_info->ID)); $doc->setField('wp', 'wp'); } $numcomments = 0; if ($index_comments) { $comments = get_comments("status=approve&post_id={$post_info->ID}"); foreach ($comments as $comment) { $doc->addField('comments', $comment->comment_content); $numcomments += 1; } } $doc->setField('title', $post_info->post_title); $doc->setField('content', strip_tags($post_info->post_content)); // rawcontent strips out characters lower than 0x20 $doc->setField('rawcontent', strip_tags(preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $post_info->post_content))); // contentnoshortcodes also strips characters below 0x20 but also strips shortcodes // used in WP to add images or other content, useful if you're pulling this data // into another system // // For example // [caption id="attachment_92495" align="alignright" width="160" caption="Duane Sand"][/caption] FARGO - Republican U.S. Senate... // // Will become // FARGO - Republican U.S. Senate... $doc->setField('contentnoshortcodes', strip_tags(preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', strip_tags(strip_shortcodes($post_info->post_content))))); $doc->setField('numcomments', $numcomments); $doc->setField('author', $auth_info->display_name); $doc->setField('author_s', get_author_posts_url($auth_info->ID, $auth_info->user_nicename)); $doc->setField('type', $post_info->post_type); $doc->setField('date', s4w_format_date($post_info->post_date_gmt)); $doc->setField('tdate', s4w_format_date($post_info->post_date_gmt)); $doc->setField('modified', s4w_format_date($post_info->post_modified_gmt)); $doc->setField('displaydate', $post_info->post_date); $doc->setField('displaymodified', $post_info->post_modified); $categories = get_the_category($post_info->ID); if (!$categories == NULL) { foreach ($categories as $category) { if ($categoy_as_taxonomy) { $doc->addField('categories', get_category_parents($category->cat_ID, FALSE, '^^')); } else { $doc->addField('categories', $category->cat_name); } } } //get all the taxonomy names used by wp $taxonomies = (array) get_taxonomies(array('_builtin' => FALSE), 'names'); foreach ($taxonomies as $parent) { $terms = get_the_terms($post_info->ID, $parent); if ((array) $terms === $terms) { //we are creating *_taxonomy as dynamic fields using our schema //so lets set up all our taxonomies in that format $parent = $parent . "_taxonomy"; foreach ($terms as $term) { $doc->addField($parent, $term->name); } } } $tags = get_the_tags($post_info->ID); if (!$tags == NULL) { foreach ($tags as $tag) { $doc->addField('tags', $tag->name); } } if (count($index_custom_fields) > 0 && count($custom_fields = get_post_custom($post_info->ID))) { foreach ((array) $index_custom_fields as $field_name) { $field = (array) $custom_fields[$field_name]; foreach ($field as $key => $value) { $doc->addField($field_name . '_str', $value); $doc->addField($field_name . '_srch', $value); } } } // add full json respone $json_response = new JSON_API_Response(); $json_post = new JSON_API_Post_full(get_post($post_info->ID)); $response = (object) array('post' => $json_post); $doc->setField('json', $json_response->get_json($response)); // add tone: /nieuws/beste van het web/weblog/column/ $tone = 'Nieuws'; if ($blog_id > 1) { $nmt_blog_type = stripslashes(get_blog_option($blog_id, 'nmt_blog_type')); $nmt_blog_types = array(1 => 'Weblog', 2 => 'Column', 3 => 'Nieuws', 4 => 'Fotoserie'); $tone = $nmt_blog_types[$nmt_blog_type]; } else { $category_slugs = array(); if (!$categories == NULL) { foreach ($categories as $category) { $category_slugs[] = $category->slug; } } if (in_array('beste-van-het-web', $category_slugs)) { $tone = 'Beste van het web'; } } $doc->setField('tone', $tone); } else { // this will fire during blog sign up on multisite, not sure why _e('Post Information is NULL', 'solr4wp'); } syslog(LOG_ERR, "built document for {$blog_id} - {$domain}{$path} with title " . $post_info->post_title . " and status of " . $post_info->post_status); return $doc; }
/** * Fix links and forms * * @param none * @return void */ public function fixLinksAndForms() { global $wpdb; // Update anchor and form tags to appropriate URL's preg_match_all('/\\<(a|form)[^>]+[\'"]((http|https):\\/\\/[^\'"]+)[\'"][^>]*>/im', $this->_html, $matches); $plugin = $this->getPlugin(); $path_cache = $plugin->getSetting('path_cache'); $blog_cache = $plugin->getSetting('blog_cache'); for ($i = 0; $i < sizeof($matches[0]); $i++) { $html = $matches[0][$i]; $type = $matches[1][$i]; $url = $matches[2][$i]; $scheme = $matches[3][$i]; $updated = false; $post_id = null; $blog_id = null; $force_ssl = null; $url_path = null; $blog_path = null; $blog_url_path = '/'; if (!$plugin->isUrlLocal($url)) { continue; } if ($url != '' && ($url_parts = parse_url($url)) && isset($url_parts['path'])) { if ($plugin->getHttpsUrl()->getPath() != '/') { if ($plugin->getSetting('ssl_host_diff')) { $url_parts['path'] = str_replace($plugin->getHttpsUrl()->getPath(), '', $url_parts['path']); } if ($plugin->getHttpUrl()->getPath() != '/') { $url_parts['path'] = str_replace($plugin->getHttpUrl()->getPath(), '', $url_parts['path']); } } // qTranslate integration - strips language from beginning of url path if (defined('QTRANS_INIT') && constant('QTRANS_INIT') == true) { global $q_config; if (isset($q_config['enabled_languages'])) { foreach ($q_config['enabled_languages'] as $language) { $url_parts['path'] = preg_replace('/^\\/' . $language . '\\//', '/', $url_parts['path']); } } } if (preg_match("/page_id=([\\d]+)/", parse_url($url, PHP_URL_QUERY), $postID)) { $post_id = $postID[1]; } else { if (isset($url_parts['path']) && ($url_parts['path'] == '' || $url_parts['path'] == '/')) { if (get_option('show_on_front') == 'page') { $post_id = get_option('page_on_front'); } } else { if (isset($url_parts['path'])) { $url_path = $url_parts['path']; if (!array_key_exists($url_path, $path_cache)) { if ($post = get_page_by_path($url_path)) { $post_id = $post->ID; $path_cache[$url_path] = $post_id; } else { $path_cache[$url_path] = 0; } } else { $post_id = $path_cache[$url_path]; } } } } if (is_multisite() && isset($url_parts['host'])) { if (is_subdomain_install()) { $blog_path = $url_parts['host'] . '/'; if (array_key_exists($blog_path, $blog_cache)) { $blog_id = $blog_cache[$blog_path]; } else { $blog_id = get_blog_id_from_url($url_parts['host'], '/'); } } else { $url_path_segments = explode('/', $url_parts['path']); if (sizeof($url_path_segments) > 1) { foreach ($url_path_segments as $url_path_segment) { if (is_null($blog_id) && $url_path_segment != '') { $blog_url_path .= $url_path_segment . '/'; $blog_path = $url_parts['host'] . $blog_url_path; if (array_key_exists($blog_path, $blog_cache)) { $blog_id = $blog_cache[$blog_path]; } else { $blog_id = $blog_cache[$blog_path] = get_blog_id_from_url($url_parts['host'], $blog_url_path); } } } } } } } // Only apply force_ssl filters for current blog if (is_null($blog_id)) { $force_ssl = apply_filters('force_ssl', null, isset($post_id) ? $post_id : 0, $url); } if ($force_ssl == true) { if (is_null($blog_id)) { $updated = $plugin->makeUrlHttps($url); } $this->_html = str_replace($html, str_replace($url, $updated, $html), $this->_html); } else { if (!is_null($force_ssl) && !$force_ssl) { if (is_null($blog_id)) { $updated = $plugin->makeUrlHttp($url); } $this->_html = str_replace($html, str_replace($url, $updated, $html), $this->_html); } } // Add log entry if this change hasn't been logged if ($updated && $url != $updated) { $log = '[FIXED] Element: <' . $type . '> - ' . $url . ' => ' . $updated; if (!in_array($log, $plugin->getLogger()->getLog())) { $plugin->getLogger()->log($log); } } } $plugin->setSetting('path_cache', $path_cache); $plugin->setSetting('blog_cache', $blog_cache); }
private function cli_init_blog($blog) { if (is_multisite()) { if (is_numeric($blog)) { $blog_address = get_blogaddress_by_id((int) $blog); } else { $blog_address = get_blogaddress_by_name($blog); } if ($blog_address == 'http://' || strstr($blog_address, 'wordpress.com.wordpress.com')) { $this->debug_msg(sprintf("the blog_address received from %s looks weird: %s", $blog, $blog_address)); return false; } $blog_address = str_replace('http://', '', $blog_address); $blog_address = preg_replace('#/$#', '', $blog_address); $blog_id = get_blog_id_from_url($blog_address); } else { $blog_id = 1; } $home_url = str_replace('http://', '', get_home_url($blog_id)); $home_url = preg_replace('#/$#', '', $home_url); $this->blog_address = $home_url; if ($blog_id > 0) { $this->debug_msg(sprintf("the blog_address we found is %s (%d)", $this->blog_address, $blog_id)); $this->args->blog = $blog_id; if (function_exists('is_multisite') && is_multisite()) { switch_to_blog((int) $blog_id); } $this->blog_id = (int) $blog_id; return true; } else { $this->debug_msg(sprintf("could not get a blog_id for this address: %s", var_export($blog_id, true))); die; } }
function redirect_user_to_blog() { global $current_user, $current_site; $details = get_active_blog_for_user($current_user->ID); if ($details == "username only") { add_user_to_blog(get_blog_id_from_url($current_site->domain, $current_site->path), $current_user->ID, 'subscriber'); // Add subscriber permission for first blog. wp_redirect('http://' . $current_site->domain . $current_site->path . 'wp-admin/'); exit; } elseif (is_object($details)) { wp_redirect("http://" . $details->domain . $details->path . 'wp-admin/'); exit; } else { wp_redirect("http://" . $current_site->domain . $current_site->path); exit; } wp_die(__('You do not have sufficient permissions to access this page.')); }
function s4wp_build_document(Solarium\QueryType\Update\Query\Document\Document $doc, $post_info, $domain = NULL, $path = NULL) { $plugin_s4wp_settings = s4wp_get_option(); $exclude_ids = $plugin_s4wp_settings['s4wp_exclude_pages']; if (!is_array($plugin_s4wp_settings['s4wp_exclude_pages'])) { $exclude_ids = explode(',', $plugin_s4wp_settings['s4wp_exclude_pages']); } $categoy_as_taxonomy = $plugin_s4wp_settings['s4wp_cat_as_taxo']; $index_comments = $plugin_s4wp_settings['s4wp_index_comments']; $index_custom_fields = $plugin_s4wp_settings['s4wp_index_custom_fields']; if (!is_array($plugin_s4wp_settings['s4wp_index_custom_fields'])) { $index_custom_fields = explode(',', $plugin_s4wp_settings['s4wp_index_custom_fields']); } if ($post_info) { # check if we need to exclude this document if (is_multisite() && in_array(substr(site_url(), 7) . $post_info->ID, (array) $exclude_ids)) { return NULL; } else { if (!is_multisite() && in_array($post_info->ID, (array) $exclude_ids)) { return NULL; } } $auth_info = get_userdata($post_info->post_author); # wpmu specific info if (is_multisite()) { // if we get here we expect that we've "switched" what blog we're running // as if ($domain == NULL) { $domain = $current_blog->domain; } if ($path == NULL) { $path = $current_blog->path; } $blogid = get_blog_id_from_url($domain, $path); $doc->setField('id', $domain . $path . $post_info->ID); $doc->setField('permalink', get_blog_permalink($blogid, $post_info->ID)); $doc->setField('blogid', $blogid); $doc->setField('blogdomain', $domain); $doc->setField('blogpath', $path); $doc->setField('wp', 'multisite'); } else { $doc->setField('id', $post_info->ID); $doc->setField('permalink', get_permalink($post_info->ID)); $doc->setField('wp', 'wp'); } $numcomments = 0; if ($index_comments) { $comments = get_comments("status=approve&post_id={$post_info->ID}"); foreach ($comments as $comment) { $doc->addField('comments', $comment->comment_content); $numcomments += 1; } } $doc->setField('title', $post_info->post_title); $doc->setField('content', strip_tags($post_info->post_content)); $doc->setField('numcomments', $numcomments); if (isset($auth_info->display_name)) { $doc->setField('author', $auth_info->display_name); } if (isset($auth_info->user_nicename)) { $doc->setField('author_s', get_author_posts_url($auth_info->ID, $auth_info->user_nicename)); } $doc->setField('type', $post_info->post_type); $doc->setField('date', s4wp_format_date($post_info->post_date_gmt)); $doc->setField('modified', s4wp_format_date($post_info->post_modified_gmt)); $doc->setField('displaydate', $post_info->post_date); $doc->setField('displaymodified', $post_info->post_modified); $categories = get_the_category($post_info->ID); if (!$categories == NULL) { foreach ($categories as $category) { if ($categoy_as_taxonomy) { $doc->addField('categories', get_category_parents($category->cat_ID, FALSE, '^^')); } else { $doc->addField('categories', $category->cat_name); } } } //get all the taxonomy names used by wp $taxonomies = (array) get_taxonomies(array('_builtin' => FALSE), 'names'); foreach ($taxonomies as $parent) { $terms = get_the_terms($post_info->ID, $parent); if ((array) $terms === $terms) { //we are creating *_taxonomy as dynamic fields using our schema //so lets set up all our taxonomies in that format $parent = $parent . "_taxonomy"; foreach ($terms as $term) { $doc->addField($parent, $term->name); } } } $tags = get_the_tags($post_info->ID); if (!$tags == NULL) { foreach ($tags as $tag) { $doc->addField('tags', $tag->name); } } if (count($index_custom_fields) > 0 && count($custom_fields = get_post_custom($post_info->ID))) { foreach ((array) $index_custom_fields as $field_name) { // test a php error notice. if (isset($custom_fields[$field_name])) { $field = (array) $custom_fields[$field_name]; foreach ($field as $key => $value) { $doc->addField($field_name . '_str', $value); $doc->addField($field_name . '_srch', $value); } } } } } else { // this will fire during blog sign up on multisite, not sure why _e('Post Information is NULL', 'solr4wp'); } return $doc; }
function test_get_blog_id_from_url() { $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/testdomainexists', 'title' => 'Test Title' ) ); $details = get_blog_details( $blog_id, false ); $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) ); $key = md5( $details->domain . $details->path ); $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) ); $this->assertEquals( 0, get_blog_id_from_url( $details->domain, 'foo' ) ); wpmu_delete_blog( $blog_id ); $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) ); wpmu_delete_blog( $blog_id, true ); $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) ); $this->assertEquals( 0, get_blog_id_from_url( $details->domain, $details->path ) ); }
/** * Returns an object with information about site on network based on a given URL * @param [string] $url [url of a site on network] * @return [object] [object with information of site based on given URL] */ function inspect_rampage($url) { $rampage = (object) []; $domain = parse_url($url, PHP_URL_HOST); $path = parse_url($url, PHP_URL_PATH); $targetId = get_blog_id_from_url($domain, $path); switch_to_blog($targetId); $rampage->site_title = get_bloginfo('name'); $rampage->site_url = get_bloginfo('home'); $rampage->site_description = get_bloginfo('description'); $rampage->admin_email = get_option('admin_email'); $rampage->theme = get_option('template'); $rampage->active_plugins = get_option('active_plugins'); restore_current_blog(); return $rampage; }