Example #1
0
/**
 * Handle importer uploading and add attachment.
 *
 * @since 2.0.0
 *
 * @return array Uploaded file's details on success, error message on failure
 */
function nxt_import_handle_upload()
{
    if (!isset($_FILES['import'])) {
        $file['error'] = __('File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.');
        return $file;
    }
    $overrides = array('test_form' => false, 'test_type' => false);
    $_FILES['import']['name'] .= '.txt';
    $file = nxt_handle_upload($_FILES['import'], $overrides);
    if (isset($file['error'])) {
        return $file;
    }
    $url = $file['url'];
    $type = $file['type'];
    $file = $file['file'];
    $filename = basename($file);
    // Construct the object array
    $object = array('post_title' => $filename, 'post_content' => $url, 'post_mime_type' => $type, 'guid' => $url, 'context' => 'import', 'post_status' => 'private');
    // Save the data
    $id = nxt_insert_attachment($object, $file);
    // schedule a cleanup for one day from now in case of failed import or missing nxt_import_cleanup() call
    nxt_schedule_single_event(time() + 86400, 'importer_scheduled_cleanup', array($id));
    return array('file' => $file, 'id' => $id);
}
 /**
  * Checks if sitemap building after content changed is enabled and rebuild the sitemap
  *
  * @param int $postID The ID of the post to handle. Used to avoid double rebuilding if more than one hook was fired.
  * @param bool $external Added in 3.1.9. Skips checking of b_auto_enabled if set to true
  * @since 3.0
  * @access public
  * @author Arne Brachhold
  */
 function CheckForAutoBuild($postID, $external = false)
 {
     global $nxt_version;
     $this->Initate();
     //Build one time per post and if not importing.
     if (($this->GetOption("b_auto_enabled") === true && $this->_lastPostID != $postID || $external) && (!defined('nxt_IMPORTING') || nxt_IMPORTING != true)) {
         //Build the sitemap directly or schedule it with nxt cron
         if ($this->GetOption("b_auto_delay") == true && floatval($nxt_version) >= 2.1) {
             if (!$this->_isScheduled) {
                 //Schedule in 15 seconds, this should be enough to catch all changes.
                 //Clear all other existing hooks, so the sitemap is only built once.
                 nxt_clear_scheduled_hook('sm_build_cron');
                 nxt_schedule_single_event(time() + 15, 'sm_build_cron');
                 $this->_isScheduled = true;
             }
         } else {
             //Build sitemap only once and never in bulk mode
             if (!$this->_lastPostID && (!isset($_GET["delete"]) || count((array) $_GET['delete']) <= 0)) {
                 $this->BuildSitemap();
             }
         }
         $this->_lastPostID = $postID;
     }
 }
Example #3
0
/**
 * Hook to schedule pings and enclosures when a post is published.
 *
 * @since 2.3.0
 * @access private
 * @uses $nxtdb
 * @uses XMLRPC_REQUEST and APP_REQUEST constants.
 * @uses do_action() Calls 'xmlprc_publish_post' on post ID if XMLRPC_REQUEST is defined.
 * @uses do_action() Calls 'app_publish_post' on post ID if APP_REQUEST is defined.
 *
 * @param int $post_id The ID in the database table of the post being published
 */
function _publish_post_hook($post_id)
{
    global $nxtdb;
    if (defined('XMLRPC_REQUEST')) {
        do_action('xmlrpc_publish_post', $post_id);
    }
    if (defined('APP_REQUEST')) {
        do_action('app_publish_post', $post_id);
    }
    if (defined('nxt_IMPORTING')) {
        return;
    }
    $data = array('post_id' => $post_id, 'meta_value' => '1');
    if (get_option('default_pingback_flag')) {
        $nxtdb->insert($nxtdb->postmeta, $data + array('meta_key' => '_pingme'));
        do_action('added_postmeta', $nxtdb->insert_id, $post_id, '_pingme', 1);
    }
    $nxtdb->insert($nxtdb->postmeta, $data + array('meta_key' => '_encloseme'));
    do_action('added_postmeta', $nxtdb->insert_id, $post_id, '_encloseme', 1);
    nxt_schedule_single_event(time(), 'do_pings');
}
Example #4
0
/**
 * Execute changes made in NXTClass 2.1.
 *
 * @since 2.1.0
 */
function upgrade_210()
{
    global $nxtdb, $nxt_current_db_version;
    if ($nxt_current_db_version < 3506) {
        // Update status and type.
        $posts = $nxtdb->get_results("SELECT ID, post_status FROM {$nxtdb->posts}");
        if (!empty($posts)) {
            foreach ($posts as $post) {
                $status = $post->post_status;
                $type = 'post';
                if ('static' == $status) {
                    $status = 'publish';
                    $type = 'page';
                } else {
                    if ('attachment' == $status) {
                        $status = 'inherit';
                        $type = 'attachment';
                    }
                }
                $nxtdb->query($nxtdb->prepare("UPDATE {$nxtdb->posts} SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID));
            }
        }
    }
    if ($nxt_current_db_version < 3845) {
        populate_roles_210();
    }
    if ($nxt_current_db_version < 3531) {
        // Give future posts a post_status of future.
        $now = gmdate('Y-m-d H:i:59');
        $nxtdb->query("UPDATE {$nxtdb->posts} SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '{$now}'");
        $posts = $nxtdb->get_results("SELECT ID, post_date FROM {$nxtdb->posts} WHERE post_status ='future'");
        if (!empty($posts)) {
            foreach ($posts as $post) {
                nxt_schedule_single_event(mysql2date('U', $post->post_date, false), 'publish_future_post', array($post->ID));
            }
        }
    }
}
 /**
  * Prime cache
  *
  * @param integer $start
  * @return void
  */
 function prime($start = 0)
 {
     $start = (int) $start;
     /**
      * Don't start cache prime if queues are still scheduled
      */
     if ($start == 0) {
         $crons = _get_cron_array();
         foreach ($crons as $timestamp => $hooks) {
             foreach ($hooks as $hook => $keys) {
                 foreach ($keys as $key => $data) {
                     if ($hook == 'w3_pgcache_prime' && count($data['args'])) {
                         return;
                     }
                 }
             }
         }
     }
     $interval = $this->_config->get_integer('pgcache.prime.interval');
     $limit = $this->_config->get_integer('pgcache.prime.limit');
     $sitemap = $this->_config->get_string('pgcache.prime.sitemap');
     /**
      * Parse XML sitemap
      */
     $urls = $this->parse_sitemap($sitemap);
     /**
      * Queue URLs
      */
     $queue = array_slice($urls, $start, $limit);
     if (count($urls) > $start + $limit) {
         nxt_schedule_single_event(time() + $interval, 'w3_pgcache_prime', array($start + $limit));
     }
     /**
      * Make HTTP requests and prime cache
      */
     require_once W3TC_INC_DIR . '/functions/http.php';
     foreach ($queue as $url) {
         $url = w3_url_format($url, array('w3tc_preload' => 1));
         w3_http_get($url);
     }
 }
Example #6
0
function bb_insert_post($args = null)
{
    global $bbdb, $bb_current_user, $bb;
    if (!($args = nxt_parse_args($args))) {
        return false;
    }
    $fields = array_keys($args);
    if (isset($args['post_id']) && false !== $args['post_id']) {
        $update = true;
        if (!($post_id = (int) get_post_id($args['post_id']))) {
            return false;
        }
        // Get from db, not cache.  Good idea?
        $post = $bbdb->get_row($bbdb->prepare("SELECT * FROM {$bbdb->posts} WHERE post_id = %d", $post_id));
        $defaults = get_object_vars($post);
        unset($defaults['post_id']);
        // Only update the args we passed
        $fields = array_intersect($fields, array_keys($defaults));
        if (in_array('topic_id', $fields)) {
            $fields[] = 'forum_id';
        }
        // No need to run filters if these aren't changing
        // bb_new_post() and bb_update_post() will always run filters
        $run_filters = (bool) array_intersect(array('post_status', 'post_text'), $fields);
    } else {
        $post_id = false;
        $update = false;
        $now = bb_current_time('mysql');
        $current_user_id = bb_get_current_user_info('id');
        $ip_address = $_SERVER['REMOTE_ADDR'];
        $defaults = array('topic_id' => 0, 'post_text' => '', 'post_time' => $now, 'poster_id' => $current_user_id, 'poster_ip' => $ip_address, 'post_status' => 0, 'post_position' => false);
        // Insert all args
        $fields = array_keys($defaults);
        $fields[] = 'forum_id';
        $run_filters = true;
    }
    $defaults['throttle'] = true;
    extract(nxt_parse_args($args, $defaults));
    // If the user is not logged in and loginless posting is ON, then this function expects $post_author, $post_email and $post_url to be sanitized (check bb-post.php for example)
    if (!($topic = get_topic($topic_id))) {
        return false;
    }
    if (bb_is_login_required() && !($user = bb_get_user($poster_id))) {
        return false;
    }
    $topic_id = (int) $topic->topic_id;
    $forum_id = (int) $topic->forum_id;
    if ($run_filters && !($post_text = apply_filters('pre_post', $post_text, $post_id, $topic_id))) {
        return false;
    }
    if ($update) {
        // Don't change post_status with this function.  Use bb_delete_post().
        $post_status = $post->post_status;
    }
    if ($run_filters) {
        $post_status = (int) apply_filters('pre_post_status', $post_status, $post_id, $topic_id);
    }
    if (false === $post_position) {
        $post_position = $topic_posts = intval(0 == $post_status ? $topic->topic_posts + 1 : $topic->topic_posts);
    }
    unset($defaults['throttle']);
    if ($update) {
        $bbdb->update($bbdb->posts, compact($fields), compact('post_id'));
        nxt_cache_delete($post_id, 'bb_post');
    } else {
        $bbdb->insert($bbdb->posts, compact($fields));
        $post_id = $topic_last_post_id = (int) $bbdb->insert_id;
        if (0 == $post_status) {
            $topic_time = $post_time;
            $topic_last_poster = !bb_is_user_logged_in() && !bb_is_login_required() ? -1 : $poster_id;
            $topic_last_poster_name = !bb_is_user_logged_in() && !bb_is_login_required() ? $post_author : $user->user_login;
            $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET posts = posts + 1 WHERE forum_id = %d;", $topic->forum_id));
            $bbdb->update($bbdb->topics, compact('topic_time', 'topic_last_poster', 'topic_last_poster_name', 'topic_last_post_id', 'topic_posts'), compact('topic_id'));
            $query = new BB_Query('post', array('post_author_id' => $poster_id, 'topic_id' => $topic_id, 'post_id' => "-{$post_id}"));
            if (!$query->results) {
                $topics_replied_key = $bbdb->prefix . 'topics_replied';
                bb_update_usermeta($poster_id, $topics_replied_key, $user->{$topics_replied_key} + 1);
            }
        } else {
            bb_update_topicmeta($topic->topic_id, 'deleted_posts', isset($topic->deleted_posts) ? $topic->deleted_posts + 1 : 1);
        }
    }
    bb_update_topic_voices($topic_id);
    // if user not logged in, save user data as meta data
    if (!$user) {
        bb_update_meta($post_id, 'post_author', $post_author, 'post');
        bb_update_meta($post_id, 'post_email', $post_email, 'post');
        bb_update_meta($post_id, 'post_url', $post_url, 'post');
    }
    if ($throttle && !bb_current_user_can('throttle')) {
        if ($user) {
            bb_update_usermeta($poster_id, 'last_posted', time());
        } else {
            bb_set_transient($_SERVER['REMOTE_ADDR'] . '_last_posted', time());
        }
    }
    if (!bb_is_login_required() && !($user = bb_get_user($poster_id))) {
        $post_cookie_lifetime = apply_filters('bb_post_cookie_lifetime', 30000000);
        setcookie('post_author_' . BB_HASH, $post_author, time() + $post_cookie_lifetime, $bb->cookiepath, $bb->cookiedomain);
        setcookie('post_author_email_' . BB_HASH, $post_email, time() + $post_cookie_lifetime, $bb->cookiepath, $bb->cookiedomain);
        setcookie('post_author_url_' . BB_HASH, $post_url, time() + $post_cookie_lifetime, $bb->cookiepath, $bb->cookiedomain);
    }
    nxt_cache_delete($topic_id, 'bb_topic');
    nxt_cache_delete($topic_id, 'bb_thread');
    nxt_cache_delete($forum_id, 'bb_forum');
    nxt_cache_flush('bb_forums');
    nxt_cache_flush('bb_query');
    nxt_cache_flush('bb_cache_posts_post_ids');
    if ($update) {
        // fire actions after cache is flushed
        do_action('bb_update_post', $post_id);
    } else {
        do_action('bb_new_post', $post_id);
    }
    do_action('bb_insert_post', $post_id, $args, compact(array_keys($args)));
    // post_id, what was passed, what was used
    if (bb_get_option('enable_pingback')) {
        bb_update_postmeta($post_id, 'pingback_queued', '');
        nxt_schedule_single_event(time(), 'do_pingbacks');
    }
    return $post_id;
}
Example #7
0
 function __construct($form, $urlholder)
 {
     if (empty($_FILES[$form]['name']) && empty($_GET[$urlholder])) {
         nxt_die(__('Please select a file'));
     }
     //Handle a newly uploaded file, Else assume its already been uploaded
     if (!empty($_FILES)) {
         $overrides = array('test_form' => false, 'test_type' => false);
         $file = nxt_handle_upload($_FILES[$form], $overrides);
         if (isset($file['error'])) {
             nxt_die($file['error']);
         }
         $this->filename = $_FILES[$form]['name'];
         $this->package = $file['file'];
         // Construct the object array
         $object = array('post_title' => $this->filename, 'post_content' => $file['url'], 'post_mime_type' => $file['type'], 'guid' => $file['url'], 'context' => 'upgrader', 'post_status' => 'private');
         // Save the data
         $this->id = nxt_insert_attachment($object, $file['file']);
         // schedule a cleanup for 2 hours from now in case of failed install
         nxt_schedule_single_event(time() + 7200, 'upgrader_scheduled_cleanup', array($this->id));
     } elseif (is_numeric($_GET[$urlholder])) {
         // Numeric Package = previously uploaded file, see above.
         $this->id = (int) $_GET[$urlholder];
         $attachment = get_post($this->id);
         if (empty($attachment)) {
             nxt_die(__('Please select a file'));
         }
         $this->filename = $attachment->post_title;
         $this->package = get_attached_file($attachment->ID);
     } else {
         // Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler.
         if (!(($uploads = nxt_upload_dir()) && false === $uploads['error'])) {
             nxt_die($uploads['error']);
         }
         $this->filename = $_GET[$urlholder];
         $this->package = $uploads['basedir'] . '/' . $this->filename;
     }
 }