/** * Purge content * * @param string $path * @param int $type * @param string $error * @return boolean */ function _purge_content($path, $type, &$error) { $url = sprintf(W3TC_CDN_EDGECAST_PURGE_URL, $this->_config['account']); $args = array('method' => 'PUT', 'user-agent' => W3TC_POWERED_BY, 'headers' => array('Accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => sprintf('TOK:%s', $this->_config['token'])), 'body' => json_encode(array('MediaPath' => $path, 'MediaType' => $type))); $response = nxt_remote_request($url, $args); if (is_nxt_error($response)) { $error = implode('; ', $response->get_error_messages()); return false; } switch ($response['response']['code']) { case 200: return true; case 400: $error = 'Invalid Request Parameter'; return false; case 403: $error = 'Authentication Failure or Insufficient Access Rights'; return false; case 404: $error = 'Invalid Request URI'; return false; case 405: $error = 'Invalid Request'; return false; case 500: $error = 'Server Error'; return false; } $error = 'Unknown error'; return false; }
function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) { $this->url = $url; $this->timeout = $timeout; $this->redirects = $redirects; $this->headers = $headers; $this->useragent = $useragent; $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE; if (preg_match('/^http(s)?:\\/\\//i', $url)) { $args = array('timeout' => $this->timeout, 'redirection' => $this->redirects); if (!empty($this->headers)) { $args['headers'] = $this->headers; } if (SIMPLEPIE_USERAGENT != $this->useragent) { //Use default nxt user agent unless custom has been specified $args['user-agent'] = $this->useragent; } $res = nxt_remote_request($url, $args); if (is_nxt_error($res)) { $this->error = 'nxt HTTP Error: ' . $res->get_error_message(); $this->success = false; } else { $this->headers = nxt_remote_retrieve_headers($res); $this->body = nxt_remote_retrieve_body($res); $this->status_code = nxt_remote_retrieve_response_code($res); } } else { if (!($this->body = file_get_contents($url))) { $this->error = 'file_get_contents could not read the file'; $this->success = false; } } }
/** * Register importer for NXTClass. * * @since 2.0.0 * * @param string $id Importer tag. Used to uniquely identify importer. * @param string $name Importer name and title. * @param string $description Importer description. * @param callback $callback Callback to run. * @return nxt_Error Returns nxt_Error when $callback is nxt_Error. */ function register_importer($id, $name, $description, $callback) { global $nxt_importers; if (is_nxt_error($callback)) { return $callback; } $nxt_importers[$id] = array($name, $description, $callback); }
/** * Retrieve the blog title for the feed title. * * @package NXTClass * @subpackage Feed * @since 2.2.0 * @uses apply_filters() Calls 'get_nxt_title_rss' hook on title. * @uses nxt_title() See function for $sep parameter usage. * * @param string $sep Optional.How to separate the title. See nxt_title() for more info. * @return string Error message on failure or blog title on success. */ function get_nxt_title_rss($sep = '»') { $title = nxt_title($sep, false); if (is_nxt_error($title)) { return $title->get_error_message(); } $title = apply_filters('get_nxt_title_rss', $title); return $title; }
/** * Append to XML response based on given arguments. * * The arguments that can be passed in the $args parameter are below. It is * also possible to pass a nxt_Error object in either the 'id' or 'data' * argument. The parameter isn't actually optional, content should be given * in order to send the correct response. * * 'what' argument is a string that is the XMLRPC response type. * 'action' argument is a boolean or string that acts like a nonce. * 'id' argument can be nxt_Error or an integer. * 'old_id' argument is false by default or an integer of the previous ID. * 'position' argument is an integer or a string with -1 = top, 1 = bottom, * html ID = after, -html ID = before. * 'data' argument is a string with the content or message. * 'supplemental' argument is an array of strings that will be children of * the supplemental element. * * @since 2.1.0 * * @param string|array $args Override defaults. * @return string XML response. */ function add($args = '') { $defaults = array('what' => 'object', 'action' => false, 'id' => '0', 'old_id' => false, 'position' => 1, 'data' => '', 'supplemental' => array()); $r = nxt_parse_args($args, $defaults); extract($r, EXTR_SKIP); $position = preg_replace('/[^a-z0-9:_-]/i', '', $position); if (is_nxt_error($id)) { $data = $id; $id = 0; } $response = ''; if (is_nxt_error($data)) { foreach ((array) $data->get_error_codes() as $code) { $response .= "<nxt_error code='{$code}'><![CDATA[" . $data->get_error_message($code) . "]]></nxt_error>"; if (!($error_data = $data->get_error_data($code))) { continue; } $class = ''; if (is_object($error_data)) { $class = ' class="' . get_class($error_data) . '"'; $error_data = get_object_vars($error_data); } $response .= "<nxt_error_data code='{$code}'{$class}>"; if (is_scalar($error_data)) { $response .= "<![CDATA[{$error_data}]]>"; } elseif (is_array($error_data)) { foreach ($error_data as $k => $v) { $response .= "<{$k}><![CDATA[{$v}]]></{$k}>"; } } $response .= "</nxt_error_data>"; } } else { $response = "<response_data><![CDATA[{$data}]]></response_data>"; } $s = ''; if (is_array($supplemental)) { foreach ($supplemental as $k => $v) { $s .= "<{$k}><![CDATA[{$v}]]></{$k}>"; } $s = "<supplemental>{$s}</supplemental>"; } if (false === $action) { $action = $_POST['action']; } $x = ''; $x .= "<response action='{$action}_{$id}'>"; // The action attribute in the xml output is formatted like a nonce action $x .= "<{$what} id='{$id}' " . (false === $old_id ? '' : "old_id='{$old_id}' ") . "position='{$position}'>"; $x .= $response; $x .= $s; $x .= "</{$what}>"; $x .= "</response>"; $this->responses[] = $x; return $x; }
/** * Makes external event request * * @param string $type * @param string $value * @return array */ function external_event($type, $value) { require_once W3TC_INC_DIR . '/functions/http.php'; $url = sprintf('%s?u=%s&tkn=%s&evnt_t=%s&evnt_v=%s', W3TC_CLOUDFLARE_EXTERNAL_EVENT_URL, urlencode($this->_config['email']), urlencode($this->_config['key']), urlencode($type), urlencode($value)); $response = w3_http_get($url); if (!is_nxt_error($response)) { return json_decode($response['body']); } return false; }
/** * Downloads URL into a file * * @param string $url * @param string $file * @return boolean */ function w3_download($url, $file) { if (strpos($url, '//') === 0) { $url = (w3_is_https() ? 'https:' : 'http:') . $url; } $response = w3_http_get($url); if (!is_nxt_error($response) && $response['response']['code'] == 200) { return @file_put_contents($file, $response['body']); } return false; }
function huddle_bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') { global $current_user, $current_site; global $bp; if (isset($_POST['submit'])) { huddle_bp_blogs_validate_blog_signup(); } else { if (!is_nxt_error($errors)) { $errors = new nxt_Error(); } // allow definition of default variables $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors)); $blogname = $filtered_results['blogname']; $blog_title = $filtered_results['blog_title']; $errors = $filtered_results['errors']; if ($errors->get_error_code()) { echo "<p>" . __('There was a problem, please correct the form below and try again.', 'buddypress') . "</p>"; } ?> <p><?php printf(__("By filling out the form below, you can <strong>add a site to your account</strong>. There is no limit to the number of sites that you can have, so create to your heart's content, but blog responsibly!", 'buddypress'), $current_user->display_name); ?> </p> <p><?php _e("If you’re not going to use a great domain, leave it for a new user. Now have at it!", 'buddypress'); ?> </p> <form class="standard-form" id="setupform" method="post" action=""> <input type="hidden" name="stage" value="gimmeanotherblog" /> <?php do_action('signup_hidden_fields'); ?> <?php huddle_bp_blogs_signup_blog($blogname, $blog_title, $errors); ?> <p class="editfield"> <input id="submit" type="submit" name="submit" class="btn-gray submit" value="<?php _e('Create Site', 'buddypress'); ?> " /> </p> <?php nxt_nonce_field('bp_blog_signup_form'); ?> </form> <?php } }
/** * Make API request * * @param string $url * @return string */ function _request($url) { require_once W3TC_INC_DIR . '/functions/http.php'; require_once W3TC_INC_DIR . '/functions/url.php'; $request_url = w3_url_format(W3TC_PAGESPEED_API_URL, array('url' => $url, 'key' => $this->key)); $response = w3_http_get($request_url); if (!is_nxt_error($response) && $response['response']['code'] == 200) { return $response['body']; } return false; }
/** * Adds and updates meta data in the database * * @internal */ function bb_update_meta($object_id = 0, $meta_key, $meta_value, $type, $global = false) { global $bbdb; if (!is_numeric($object_id) || empty($object_id) && !$global) { return false; } $cache_object_id = $object_id = (int) $object_id; switch ($type) { case 'option': $object_type = 'bb_option'; break; case 'user': global $nxt_users_object; $id = $object_id; $return = $nxt_users_object->update_meta(compact('id', 'meta_key', 'meta_value')); if (is_nxt_error($return)) { return false; } return $return; break; case 'forum': $object_type = 'bb_forum'; break; case 'topic': $object_type = 'bb_topic'; break; case 'post': $object_type = 'bb_post'; break; default: $object_type = $type; break; } $meta_key = bb_sanitize_meta_key($meta_key); $meta_tuple = compact('object_type', 'object_id', 'meta_key', 'meta_value', 'type'); $meta_tuple = apply_filters('bb_update_meta', $meta_tuple); extract($meta_tuple, EXTR_OVERWRITE); $meta_value = $_meta_value = maybe_serialize($meta_value); $meta_value = maybe_unserialize($meta_value); $cur = $bbdb->get_row($bbdb->prepare("SELECT * FROM `{$bbdb->meta}` WHERE `object_type` = %s AND `object_id` = %d AND `meta_key` = %s", $object_type, $object_id, $meta_key)); if (!$cur) { $bbdb->query($bbdb->prepare("INSERT INTO `{$bbdb->meta}` ( `object_type`, `object_id`, `meta_key`, `meta_value` ) VALUES( %s, %d, %s, %s )\n\t\t\tON DUPLICATE KEY UPDATE `meta_value` = VALUES( `meta_value` )", $object_type, $object_id, $meta_key, $_meta_value)); } elseif ($cur->meta_value != $meta_value) { $bbdb->update($bbdb->meta, array('meta_value' => $_meta_value), array('object_type' => $object_type, 'object_id' => $object_id, 'meta_key' => $meta_key)); } if ($object_type === 'bb_option') { $cache_object_id = $meta_key; nxt_cache_delete($cache_object_id, 'bb_option_not_set'); } nxt_cache_delete($cache_object_id, $object_type); if (!$cur) { return true; } }
function membership_is_active($userdata, $password) { global $nxtdb; // Checks if this member is an active one. if (!empty($userdata) && !is_nxt_error($userdata)) { $id = $userdata->ID; if (get_usermeta($id, $nxtdb->prefix . 'membership_active', true) == 'no') { return new nxt_Error('member_inactive', __('Sorry, this account is not active.', 'membership')); } } return $userdata; }
function query() { $args = func_get_args(); $method = array_shift($args); $request = new IXR_Request($method, $args); $xml = $request->getXml(); $url = $this->scheme . '://' . $this->server . ':' . $this->port . $this->path; $args = array('headers' => array('Content-Type' => 'text/xml'), 'user-agent' => $this->useragent, 'body' => $xml); // Merge Custom headers ala #8145 foreach ($this->headers as $header => $value) { $args['headers'][$header] = $value; } if ($this->timeout !== false) { $args['timeout'] = $this->timeout; } // Now send the request if ($this->debug) { echo '<pre class="ixr_request">' . htmlspecialchars($xml) . "\n</pre>\n\n"; } $response = nxt_remote_post($url, $args); if (is_nxt_error($response)) { $errno = $response->get_error_code(); $errorstr = $response->get_error_message(); $this->error = new IXR_Error(-32300, "transport error: {$errno} {$errstr}"); return false; } $code = $response['response']['code']; if ($code != 200) { $this->error = new IXR_Error(-32301, "transport error - HTTP status code was not 200 ({$code})"); return false; } if ($this->debug) { echo '<pre class="ixr_response">' . htmlspecialchars($response['body']) . "\n</pre>\n\n"; } // Now parse what we've got back $this->message = new IXR_Message($response['body']); if (!$this->message->parse()) { // XML error $this->error = new IXR_Error(-32700, 'parse error. not well formed'); return false; } // Is the message a fault? if ($this->message->messageType == 'fault') { $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); return false; } // Message must be OK return true; }
/** * Retrieve single bookmark data item or field. * * @since 2.3.0 * @uses get_bookmark() Gets bookmark object using $bookmark as ID * @uses sanitize_bookmark_field() Sanitizes Bookmark field based on $context. * * @param string $field The name of the data field to return * @param int $bookmark The bookmark ID to get field * @param string $context Optional. The context of how the field will be used. * @return string */ function get_bookmark_field($field, $bookmark, $context = 'display') { $bookmark = (int) $bookmark; $bookmark = get_bookmark($bookmark); if (is_nxt_error($bookmark)) { return $bookmark; } if (!is_object($bookmark)) { return ''; } if (!isset($bookmark->{$field})) { return ''; } return sanitize_bookmark_field($field, $bookmark->{$field}, $bookmark->link_id, $context); }
function nxt_credits() { global $nxt_version; $locale = get_locale(); $results = get_site_transient('nxtclass_credits_' . $locale); if (!is_array($results)) { $response = nxt_remote_get("http://api.nxtclass.org/core/credits/1.0/?version={$nxt_version}&locale={$locale}"); if (is_nxt_error($response) || 200 != nxt_remote_retrieve_response_code($response)) { return false; } $results = maybe_unserialize(nxt_remote_retrieve_body($response)); if (!is_array($results)) { return false; } set_site_transient('nxtclass_credits_' . $locale, $results, 86400); // One day } return $results; }
/** * Sets the prefix of the database tables * @param string prefix * @param false|array tables (optional: false) * table identifiers are array keys * array values * empty: set prefix: array( 'posts' => false, 'users' => false, ... ) * string: set to that array value: array( 'posts' => 'my_posts', 'users' => 'my_users' ) * array: array[0] is DB identifier, array[1] is table name: array( 'posts' => array( 'global', 'my_posts' ), 'users' => array( 'users', 'my_users' ) ) * OR array values (with numeric keys): array( 'posts', 'users', ... ) * * @return string the previous prefix (mostly only meaningful if all $table parameter was false) */ function set_prefix($prefix, $tables = false) { $old_prefix = parent::set_prefix($prefix, $tables); if (!$old_prefix || is_nxt_error($old_prefix)) { return $old_prefix; } if ($tables && is_array($tables)) { $_tables = $tables; } else { $_tables = $this->tables; } foreach ($_tables as $key => $value) { // array( 'posts' => array( 'global', 'my_posts' ), 'users' => array( 'users', 'my_users' ) ) if (is_array($value) && isset($this->db_servers['dbh_' . $value[0]])) { $this->add_db_table($value[0], $value[1]); $this->{$key} = $value[1]; } } return $old_prefix; }
function parse($file) { // Attempt to use proper XML parsers first if (extension_loaded('simplexml')) { $parser = new WXR_Parser_SimpleXML(); $result = $parser->parse($file); // If SimpleXML succeeds or this is an invalid WXR file then return the results if (!is_nxt_error($result) || 'SimpleXML_parse_error' != $result->get_error_code()) { return $result; } } else { if (extension_loaded('xml')) { $parser = new WXR_Parser_XML(); $result = $parser->parse($file); // If XMLParser succeeds or this is an invalid WXR file then return the results if (!is_nxt_error($result) || 'XML_parse_error' != $result->get_error_code()) { return $result; } } } // We have a malformed XML file, so display the error and fallthrough to regex if (isset($result) && defined('IMPORT_DEBUG') && IMPORT_DEBUG) { echo '<pre>'; if ('SimpleXML_parse_error' == $result->get_error_code()) { foreach ($result->get_error_data() as $error) { echo $error->line . ':' . $error->column . ' ' . esc_html($error->message) . "\n"; } } else { if ('XML_parse_error' == $result->get_error_code()) { $error = $result->get_error_data(); echo $error[0] . ':' . $error[1] . ' ' . esc_html($error[2]); } } echo '</pre>'; echo '<p><strong>' . __('There was an error when reading this WXR file', 'nxtclass-importer') . '</strong><br />'; echo __('Details are shown above. The importer will now try again with a different parser...', 'nxtclass-importer') . '</p>'; } // use regular expressions if nothing else available or this is bad XML $parser = new WXR_Parser_Regex(); return $parser->parse($file); }
/** * Purge URI * * @param string $uri * @return boolean */ function purge($uri) { require_once W3TC_INC_DIR . '/functions/http.php'; @set_time_limit($this->_timeout); if (strpos($uri, '/') !== 0) { $uri = '/' . $uri; } foreach ((array) $this->_servers as $server) { $url = sprintf('http://%s%s', $server, $uri); $response = w3_http_request($url, array('method' => 'PURGE')); if (is_nxt_error($response)) { $this->_log($url, sprintf('Unable to send request: %s.', implode('; ', $response->get_error_messages()))); return false; } if ($response['response']['code'] !== 200) { $this->_log($url, 'Bad response code.'); return false; } $this->_log($url, 'OK'); } return true; }
/** * Attempts activation of plugin in a "sandbox" and redirects on success. * * A plugin that is already activated will not attempt to be activated again. * * The way it works is by setting the redirection to the error before trying to * include the plugin file. If the plugin fails, then the redirection will not * be overwritten with the success message. Also, the options will not be * updated and the activation hook will not be called on plugin error. * * It should be noted that in no way the below code will actually prevent errors * within the file. The code should not be used elsewhere to replicate the * "sandbox", which uses redirection to work. * * If any errors are found or text is outputted, then it will be captured to * ensure that the success redirection will update the error redirection. * * @since 1.0 * * @param string $plugin Plugin path to main plugin file with plugin data. * @param string $redirect Optional. URL to redirect to. * @return nxt_Error|null nxt_Error on invalid file or null on success. */ function bb_activate_plugin($plugin, $redirect = '') { $active_plugins = (array) bb_get_option('active_plugins'); $plugin = bb_plugin_basename(trim($plugin)); $valid_path = bb_validate_plugin($plugin); if (is_nxt_error($valid_path)) { return $valid_path; } if (in_array($plugin, $active_plugins)) { return false; } if (!empty($redirect)) { // We'll override this later if the plugin can be included without fatal error nxt_redirect(add_query_arg('_scrape_nonce', bb_create_nonce('scrape-plugin_' . $plugin), $redirect)); } ob_start(); @(include $valid_path); // Add to the active plugins array $active_plugins[] = $plugin; ksort($active_plugins); bb_update_option('active_plugins', $active_plugins); do_action('bb_activate_plugin_' . $plugin); ob_end_clean(); return $valid_path; }
function delete_meta($args = null) { $defaults = array('id' => 0, 'meta_key' => null, 'meta_value' => null, 'meta_table' => 'usermeta', 'meta_field' => 'user_id', 'meta_id_field' => 'umeta_id', 'cache_group' => 'users'); $args = nxt_parse_args($args, $defaults); extract($args, EXTR_SKIP); $user = $this->get_user($id); if (!$user || is_nxt_error($user)) { return $user; } $id = (int) $id; if (is_null($meta_key)) { return false; } $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); $meta_tuple = compact('id', 'meta_key', 'meta_value', 'meta_table'); $meta_tuple = apply_filters(__CLASS__ . '::' . __FUNCTION__, $meta_tuple); extract($meta_tuple, EXTR_OVERWRITE); $_meta_value = is_null($meta_value) ? null : maybe_serialize($meta_value); if (is_null($_meta_value)) { $meta_id = $this->db->get_var($this->db->prepare("SELECT {$meta_id_field} FROM {$this->db->{$meta_table}} WHERE {$meta_field} = %d AND meta_key = %s", $id, $meta_key)); } else { $meta_id = $this->db->get_var($this->db->prepare("SELECT {$meta_id_field} FROM {$this->db->{$meta_table}} WHERE {$meta_field} = %d AND meta_key = %s AND meta_value = %s", $id, $meta_key, $_meta_value)); } if (!$meta_id) { return false; } if (is_null($_meta_value)) { $this->db->query($this->db->prepare("DELETE FROM {$this->db->{$meta_table}} WHERE {$meta_field} = %d AND meta_key = %s", $id, $meta_key)); } else { $this->db->query($this->db->prepare("DELETE FROM {$this->db->{$meta_table}} WHERE {$meta_id_field} = %d", $meta_id)); } nxt_cache_delete($id, $cache_group); return true; }
function get_inbox_count($user_id = 0) { global $nxtdb, $bp; if (empty($user_id)) { $user_id = $bp->loggedin_user->id; } $sql = $nxtdb->prepare("SELECT SUM(unread_count) FROM {$bp->messages->table_name_recipients} WHERE user_id = %d AND is_deleted = 0 AND sender_only = 0", $user_id); $unread_count = $nxtdb->get_var($sql); if (empty($unread_count) || is_nxt_error($unread_count)) { return 0; } return (int) $unread_count; }
function bb_tag_search($args = '') { global $page, $nxt_taxonomy_object; if ($args && is_string($args) && false === strpos($args, '=')) { $args = array('search' => $args); } $defaults = array('search' => '', 'number' => false); $args = nxt_parse_args($args); if (isset($args['query'])) { $args['search'] = $args['query']; } if (isset($args['tags_per_page'])) { $args['number'] = $args['tags_per_page']; } unset($args['query'], $args['tags_per_page']); $args = nxt_parse_args($args, $defaults); extract($args, EXTR_SKIP); $number = (int) $number; $search = trim($search); if (strlen($search) < 3) { return new nxt_Error('invalid-query', __('Your search term was too short')); } $number = 0 < $number ? $number : bb_get_option('page_topics'); if (1 < $page) { $offset = (intval($page) - 1) * $number; } $args = array_merge($args, compact('number', 'offset', 'search')); $terms = $nxt_taxonomy_object->get_terms('bb_topic_tag', $args); if (is_nxt_error($terms)) { return false; } for ($i = 0; isset($terms[$i]); $i++) { _bb_make_tag_compat($terms[$i]); } return $terms; }
/** * Returns the tags in a given topic or all tags * * @since 1.0 * @return integer|object The tag data when successfully executed or an IXR_Error object on failure * @param array $args Arguments passed by the XML-RPC call * @param string $args[0] The username for authentication * @param string $args[1] The password for authentication * @param integer|string $args[2] The topic id or slug (optional) * * XML-RPC request to get all tags in the topic with slug "woot-frist-topic" * <methodCall> * <methodName>bb.getTopicTags</methodName> * <params> * <param><value><string>joeblow</string></value></param> * <param><value><string>123password</string></value></param> * <param><value><string>woot-frist-topic</string></value></param> * </params> * </methodCall> */ function bb_getTopicTags($args) { do_action('bb_xmlrpc_call', 'bb.getTopicTags'); // Escape args $this->escape($args); // Get the login credentials $username = $args[0]; $password = (string) $args[1]; // Check the user is valid if ($this->auth_readonly) { $user = $this->authenticate($username, $password); } do_action('bb_xmlrpc_call_authenticated', 'bb.getTopicTags'); // If an error was raised by authentication or by an action then return it if ($this->error) { return $this->error; } // Can be numeric id or slug $topic_id = isset($args[2]) ? $args[2] : false; // Check for bad data if ($topic_id) { if (!is_string($topic_id) && !is_integer($topic_id)) { $this->error = new IXR_Error(400, __('The topic id is invalid.')); return $this->error; } // Check the requested topic exists if (!($topic = get_topic($topic_id))) { $this->error = new IXR_Error(400, __('No topic found.')); return $this->error; } // The topic id may have been a slug, so make sure it's an integer here $topic_id = (int) $topic->topic_id; // Now get the tags if (!($tags = bb_get_topic_tags($topic_id))) { $this->error = new IXR_Error(500, __('No topic tags found.')); return $this->error; } } else { global $nxt_taxonomy_object; $tags = $nxt_taxonomy_object->get_terms('bb_topic_tag', array('get' => 'all')); if (is_nxt_error($tags)) { $this->error = new IXR_Error(500, __('Could not retrieve all topic tags.')); return $this->error; } for ($i = 0; isset($tags[$i]); $i++) { _bb_make_tag_compat($tags[$i]); } } // Only include "safe" data in the array $_tags = array(); foreach ($tags as $tag) { $_tags[] = $this->prepare_topic_tag($tag); } do_action('bb_xmlrpc_call_return', 'bb.getTopicTags'); // Return the tags return $_tags; }
/** * Record blog comment activity. Checks if blog is public and post is not * password protected. * * @global $bp $bp * @param int $comment_id * @param bool $is_approved * @return mixed */ function bp_blogs_record_comment($comment_id, $is_approved = true) { global $bp; // Get the users comment $recorded_comment = get_comment($comment_id); // Don't record activity if the comment hasn't been approved if (empty($is_approved)) { return false; } // Don't record activity if no email address has been included if (empty($recorded_comment->comment_author_email)) { return false; } // Get the user_id from the comment author email. $user = get_user_by('email', $recorded_comment->comment_author_email); $user_id = (int) $user->ID; // If there's no registered user id, don't record activity if (empty($user_id)) { return false; } // Get blog and post data $blog_id = get_current_blog_id(); $recorded_comment->post = get_post($recorded_comment->comment_post_ID); if (empty($recorded_comment->post) || is_nxt_error($recorded_comment->post)) { return false; } // If this is a password protected post, don't record the comment if (!empty($recorded_comment->post->post_password)) { return false; } // Don't record activity if the comment's associated post isn't a NXTClass Post if (!in_array($recorded_comment->post->post_type, apply_filters('bp_blogs_record_comment_post_types', array('post')))) { return false; } $is_blog_public = apply_filters('bp_is_blog_public', (int) get_blog_option($blog_id, 'blog_public')); // If blog is public allow activity to be posted if ($is_blog_public) { // Get activity related links $post_permalink = get_permalink($recorded_comment->comment_post_ID); $comment_link = htmlspecialchars(get_comment_link($recorded_comment->comment_ID)); // Prepare to record in activity streams if (is_multisite()) { $activity_action = sprintf(__('%1$s commented on the post, %2$s, on the site %3$s', 'buddypress'), bp_core_get_userlink($user_id), '<a href="' . $post_permalink . '">' . apply_filters('the_title', $recorded_comment->post->post_title) . '</a>', '<a href="' . get_blog_option($blog_id, 'home') . '">' . get_blog_option($blog_id, 'blogname') . '</a>'); } else { $activity_action = sprintf(__('%1$s commented on the post, %2$s', 'buddypress'), bp_core_get_userlink($user_id), '<a href="' . $post_permalink . '">' . apply_filters('the_title', $recorded_comment->post->post_title) . '</a>'); } $activity_content = $recorded_comment->comment_content; // Record in activity streams bp_blogs_record_activity(array('user_id' => $user_id, 'action' => apply_filters_ref_array('bp_blogs_activity_new_comment_action', array($activity_action, &$recorded_comment, $comment_link)), 'content' => apply_filters_ref_array('bp_blogs_activity_new_comment_content', array($activity_content, &$recorded_comment, $comment_link)), 'primary_link' => apply_filters_ref_array('bp_blogs_activity_new_comment_primary_link', array($comment_link, &$recorded_comment)), 'type' => 'new_blog_comment', 'item_id' => $blog_id, 'secondary_item_id' => $comment_id, 'recorded_time' => $recorded_comment->comment_date_gmt)); // Update the blogs last active date bp_blogs_update_blogmeta($blog_id, 'last_activity', bp_core_current_time()); } return $recorded_comment; }
/** * Retrieve only the body from the raw response. * * @since 2.7.0 * * @param array $response HTTP response. * @return string The body of the response. Empty string if no body or incorrect parameter given. */ function nxt_remote_retrieve_body(&$response) { if (is_nxt_error($response) || !isset($response['body'])) { return ''; } return $response['body']; }
/** * Determine if the given object is associated with any of the given terms. * * The given terms are checked against the object's terms' term_ids, names and slugs. * Terms given as integers will only be checked against the object's terms' term_ids. * If no terms are given, determines if object is associated with any terms in the given taxonomy. * * @since 2.7.0 * @uses nxt_Taxonomy::get_object_term_cache() * @uses nxt_Taxonomy::get_object_terms() * * @param int $object_id. ID of the object (post ID, link ID, ...) * @param string $taxonomy. Single taxonomy name * @param int|string|array $terms Optional. Term term_id, name, slug or array of said * @return bool|nxt_Error. nxt_Error on input error. */ function is_object_in_term($object_id, $taxonomy, $terms = null) { if (!($object_id = (int) $object_id)) { return new nxt_Error('invalid_object', __('Invalid object ID')); } $object_terms = $this->get_object_term_cache($object_id, $taxonomy); if (empty($object_terms)) { $object_terms = $this->get_object_terms($object_id, $taxonomy); } if (is_nxt_error($object_terms)) { return $object_terms; } if (empty($object_terms)) { return false; } if (empty($terms)) { return !empty($object_terms); } $terms = (array) $terms; if ($ints = array_filter($terms, 'is_int')) { $strs = array_diff($terms, $ints); } else { $strs =& $terms; } foreach ($object_terms as $object_term) { if ($ints && in_array($object_term->term_id, $ints)) { return true; } // If int, check against term_id if ($strs) { if (in_array($object_term->term_id, $strs)) { return true; } if (in_array($object_term->name, $strs)) { return true; } if (in_array($object_term->slug, $strs)) { return true; } } } return false; }
function query() { if ($_results = bb_get_ids_by_role($this->role, 0, $this->page, $this->users_per_page)) { $this->results = bb_get_user($_results); $this->total_users_for_query = bb_count_last_query(); } else { $this->search_errors = new nxt_Error('no_matching_users_found', __('<strong>No matching users were found!</strong>')); } if (is_nxt_error($this->search_errors)) { bb_admin_notice($this->search_errors); } }
/** * Displays a navigation menu. * * Optional $args contents: * * menu - The menu that is desired. Accepts (matching in order) id, slug, name. Defaults to blank. * menu_class - CSS class to use for the ul element which forms the menu. Defaults to 'menu'. * menu_id - The ID that is applied to the ul element which forms the menu. Defaults to the menu slug, incremented. * container - Whether to wrap the ul, and what to wrap it with. Defaults to 'div'. * container_class - the class that is applied to the container. Defaults to 'menu-{menu slug}-container'. * container_id - The ID that is applied to the container. Defaults to blank. * fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'nxt_page_menu'. Set to false for no fallback. * before - Text before the link text. * after - Text after the link text. * link_before - Text before the link. * link_after - Text after the link. * echo - Whether to echo the menu or return it. Defaults to echo. * depth - how many levels of the hierarchy are to be included. 0 means all. Defaults to 0. * walker - allows a custom walker to be specified. * theme_location - the location in the theme to be used. Must be registered with register_nav_menu() in order to be selectable by the user. * items_wrap - How the list items should be wrapped. Defaults to a ul with an id and class. Uses printf() format with numbered placeholders. * * @since 3.0.0 * * @param array $args Arguments */ function nxt_nav_menu($args = array()) { static $menu_id_slugs = array(); $defaults = array('menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '', 'echo' => true, 'fallback_cb' => 'nxt_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'depth' => 0, 'walker' => '', 'theme_location' => ''); $args = nxt_parse_args($args, $defaults); $args = apply_filters('nxt_nav_menu_args', $args); $args = (object) $args; // Get the nav menu based on the requested menu $menu = nxt_get_nav_menu_object($args->menu); // Get the nav menu based on the theme_location if (!$menu && $args->theme_location && ($locations = get_nav_menu_locations()) && isset($locations[$args->theme_location])) { $menu = nxt_get_nav_menu_object($locations[$args->theme_location]); } // get the first menu that has items if we still can't find a menu if (!$menu && !$args->theme_location) { $menus = nxt_get_nav_menus(); foreach ($menus as $menu_maybe) { if ($menu_items = nxt_get_nav_menu_items($menu_maybe->term_id)) { $menu = $menu_maybe; break; } } } // If the menu exists, get its items. if ($menu && !is_nxt_error($menu) && !isset($menu_items)) { $menu_items = nxt_get_nav_menu_items($menu->term_id); } // If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists if ((!$menu || is_nxt_error($menu) || isset($menu_items) && empty($menu_items) && !$args->theme_location) && $args->fallback_cb && is_callable($args->fallback_cb)) { return call_user_func($args->fallback_cb, (array) $args); } // If no fallback function was specified and the menu doesn't exists, bail. if (!$menu || is_nxt_error($menu)) { return false; } $nav_menu = $items = ''; $show_container = false; if ($args->container) { $allowed_tags = apply_filters('nxt_nav_menu_container_allowedtags', array('div', 'nav')); if (in_array($args->container, $allowed_tags)) { $show_container = true; $class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : ' class="menu-' . $menu->slug . '-container"'; $id = $args->container_id ? ' id="' . esc_attr($args->container_id) . '"' : ''; $nav_menu .= '<' . $args->container . $id . $class . '>'; } } // Set up the $menu_item variables _nxt_menu_item_classes_by_context($menu_items); $sorted_menu_items = array(); foreach ((array) $menu_items as $key => $menu_item) { $sorted_menu_items[$menu_item->menu_order] = $menu_item; } unset($menu_items); $sorted_menu_items = apply_filters('nxt_nav_menu_objects', $sorted_menu_items, $args); $items .= walk_nav_menu_tree($sorted_menu_items, $args->depth, $args); unset($sorted_menu_items); // Attributes if (!empty($args->menu_id)) { $wrap_id = $args->menu_id; } else { $wrap_id = 'menu-' . $menu->slug; while (in_array($wrap_id, $menu_id_slugs)) { if (preg_match('#-(\\d+)$#', $wrap_id, $matches)) { $wrap_id = preg_replace('#-(\\d+)$#', '-' . ++$matches[1], $wrap_id); } else { $wrap_id = $wrap_id . '-1'; } } } $menu_id_slugs[] = $wrap_id; $wrap_class = $args->menu_class ? $args->menu_class : ''; // Allow plugins to hook into the menu to add their own <li>'s $items = apply_filters('nxt_nav_menu_items', $items, $args); $items = apply_filters("nxt_nav_menu_{$menu->slug}_items", $items, $args); $nav_menu .= sprintf($args->items_wrap, esc_attr($wrap_id), esc_attr($wrap_class), $items); unset($items); if ($show_container) { $nav_menu .= '</' . $args->container . '>'; } $nav_menu = apply_filters('nxt_nav_menu', $nav_menu, $args); if ($args->echo) { echo $nav_menu; } else { return $nav_menu; } }
/** * Delete a meta entry from the DB for an activity stream item * * @since 1.2.0 * * @param int $activity_id * @param string $meta_key * @param string $meta_value * * @global object $nxtdb * @global object $bp BuddyPress global settings * @uses nxt_cache_delete() * @uses is_nxt_error() * * @return bool True on success, false on failure */ function bp_activity_delete_meta($activity_id, $meta_key = '', $meta_value = '') { global $nxtdb, $bp; // Return false if any of the above values are not set if (!is_numeric($activity_id)) { return false; } // Sanitize key $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); if (is_array($meta_value) || is_object($meta_value)) { $meta_value = serialize($meta_value); } // Trim off whitespace $meta_value = trim($meta_value); // Delete all for activity_id if (empty($meta_key)) { $retval = $nxtdb->query($nxtdb->prepare("DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id)); } else { if ($meta_value) { $retval = $nxtdb->query($nxtdb->prepare("DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s AND meta_value = %s", $activity_id, $meta_key, $meta_value)); } else { $retval = $nxtdb->query($nxtdb->prepare("DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key)); } } // Delete cache entry nxt_cache_delete('bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp'); // Success if (!is_nxt_error($retval)) { return true; } else { return false; } }
$user_data = array(); $user_data['user_login'] = "******" . $fb_uid; $user_data['user_pass'] = nxt_generate_password(); $user_data['user_nicename'] = sanitize_title($user_data['user_login']); $user_data['first_name'] = $fbuser['first_name']; $user_data['last_name'] = $fbuser['last_name']; $user_data['display_name'] = $fbuser['first_name']; $user_data['user_url'] = $fbuser["profile_url"]; $user_data['user_email'] = $fbuser["email"]; //Run a filter so the user can be modified to something different before registration //NOTE: If the user has selected "pretty names", this'll change FB_xxx to i.e. "John.Smith" $user_data = apply_filters('nxtfb_insert_user', $user_data, $fbuser); $user_data = apply_filters('nxtfb_inserting_user', $user_data, array('nxt_ID' => $user_login_id, 'FB_ID' => $fb_uid, 'facebook' => $facebook, 'FB_UserData' => $fbuser)); //Insert a new user to our database and make sure it worked $user_login_id = nxt_insert_user($user_data); if (is_nxt_error($user_login_id)) { j_die("Error: nxt_insert_user failed!<br/><br/>" . "If you get this error while running a nxtclass MultiSite installation, it means you'll need to purchase the <a href=\"{$jfb_homepage}#premium\">premium version</a> of this plugin to enable full MultiSite support.<br/><br/>" . "If you're <u><i>not</i></u> using MultiSite, please report this bug to the plugin author on the support page <a href=\"{$jfb_homepage}#feedback\">here</a>.<br /><br />" . "Error message: " . (function_exists(array(&$user_login_id, 'get_error_message')) ? $user_login_id->get_error_message() : "Undefined") . "<br />" . "nxt_ALLOW_MULTISITE: " . (defined('nxt_ALLOW_MULTISITE') ? constant('nxt_ALLOW_MULTISITE') : "Undefined") . "<br />" . "is_multisite: " . (function_exists('is_multisite') ? is_multisite() : "Undefined")); } //Success! Notify the site admin. $user_login_name = $user_data['user_login']; nxt_new_user_notification($user_login_name); //Run an action so i.e. usermeta can be added to a user after registration do_action('nxtfb_inserted_user', array('nxt_ID' => $user_login_id, 'FB_ID' => $fb_uid, 'facebook' => $facebook, 'nxt_UserData' => $user_data)); } //Tag the user with our meta so we can recognize them next time, without resorting to email hashes update_user_meta($user_login_id, $jfb_uid_meta_name, $fb_uid); $jfb_log .= "nxt: Updated usermeta ({$jfb_uid_meta_name})\n"; //Also store the user's facebook avatar(s), in case the user wants to use them later if ($fbuser['pic_square']) { update_user_meta($user_login_id, 'facebook_avatar_thumb', $fbuser['pic_square']); update_user_meta($user_login_id, 'facebook_avatar_full', $fbuser['pic_big']);
/** * Handles avatar uploading. * * The functions starts off by checking that the file has been uploaded properly using bp_core_check_avatar_upload(). * It then checks that the file size is within limits, and that it has an accepted file extension (jpg, gif, png). * If everything checks out, crop the image and move it to its real location. * * @global object $bp BuddyPress global settings * @param array $file The appropriate entry the from $_FILES superglobal. * @param string $upload_dir_filter A filter to be applied to upload_dir * @return bool Success/failure * @see bp_core_check_avatar_upload() * @see bp_core_check_avatar_type() */ function bp_core_avatar_handle_upload($file, $upload_dir_filter) { global $bp; /*** * You may want to hook into this filter if you want to override this function. * Make sure you return false. */ if (!apply_filters('bp_core_pre_avatar_handle_upload', true, $file, $upload_dir_filter)) { return true; } require_once ABSPATH . '/nxt-admin/includes/image.php'; require_once ABSPATH . '/nxt-admin/includes/file.php'; $uploadErrors = array(0 => __("There is no error, the file uploaded with success", 'buddypress'), 1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(bp_core_avatar_original_max_filesize()), 2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(bp_core_avatar_original_max_filesize()), 3 => __("The uploaded file was only partially uploaded", 'buddypress'), 4 => __("No file was uploaded", 'buddypress'), 6 => __("Missing a temporary folder", 'buddypress')); if (!bp_core_check_avatar_upload($file)) { bp_core_add_message(sprintf(__('Your upload failed, please try again. Error was: %s', 'buddypress'), $uploadErrors[$file['file']['error']]), 'error'); return false; } if (!bp_core_check_avatar_size($file)) { bp_core_add_message(sprintf(__('The file you uploaded is too big. Please upload a file under %s', 'buddypress'), size_format(bp_core_avatar_original_max_filesize())), 'error'); return false; } if (!bp_core_check_avatar_type($file)) { bp_core_add_message(__('Please upload only JPG, GIF or PNG photos.', 'buddypress'), 'error'); return false; } // Filter the upload location add_filter('upload_dir', $upload_dir_filter, 10, 0); $bp->avatar_admin->original = nxt_handle_upload($file['file'], array('action' => 'bp_avatar_upload')); // Move the file to the correct upload location. if (!empty($bp->avatar_admin->original['error'])) { bp_core_add_message(sprintf(__('Upload Failed! Error was: %s', 'buddypress'), $bp->avatar_admin->original['error']), 'error'); return false; } // Get image size $size = @getimagesize($bp->avatar_admin->original['file']); // Check image size and shrink if too large if ($size[0] > bp_core_avatar_original_max_width()) { $thumb = nxt_create_thumbnail($bp->avatar_admin->original['file'], bp_core_avatar_original_max_width()); // Check for thumbnail creation errors if (is_nxt_error($thumb)) { bp_core_add_message(sprintf(__('Upload Failed! Error was: %s', 'buddypress'), $thumb->get_error_message()), 'error'); return false; } // Thumbnail is good so proceed $bp->avatar_admin->resized = $thumb; } // We only want to handle one image after resize. if (empty($bp->avatar_admin->resized)) { $bp->avatar_admin->image->dir = str_replace(bp_core_avatar_upload_path(), '', $bp->avatar_admin->original['file']); } else { $bp->avatar_admin->image->dir = str_replace(bp_core_avatar_upload_path(), '', $bp->avatar_admin->resized); @unlink($bp->avatar_admin->original['file']); } // Check for nxt_Error on what should be an image if (is_nxt_error($bp->avatar_admin->image->dir)) { bp_core_add_message(sprintf(__('Upload failed! Error was: %s', 'buddypress'), $bp->avatar_admin->image->dir->get_error_message()), 'error'); return false; } // Set the url value for the image $bp->avatar_admin->image->url = bp_core_avatar_url() . $bp->avatar_admin->image->dir; return true; }