Пример #1
0
function fpf_run_main($data)
{
    //Don't process anything but POSTS and PAGES (i.e. no revisions)
    if ($data['post_type'] != 'post' && $data['post_type'] != 'page') {
        return $data;
    }
    //Check the content for our magic tag (and parse out everything we need if found)
    $parsed_content = fpf_find_tags($data['post_content']);
    if (!$parsed_content) {
        return $data;
    }
    //Connect to Facebook and generate the album content
    $album_content = fpf_fetch_album_content($parsed_content['aid'], $parsed_content);
    //Update the post we're about to save
    $data['post_content'] = $parsed_content['before'] . $parsed_content['startTag'] . $album_content['content'] . $parsed_content['endTag'] . $parsed_content['after'];
    //Set postmeta with the album's size (can be optionally referenced by the user)
    //(Note: for some stupid reason, $data doesn't have the ID - we need to parse it out of the guid.)
    $post_ID = substr(strrchr($data['guid'], '='), 1);
    update_post_meta($post_ID, '_fb_album_size', $album_content['count']);
    //If the album has a thumbnail, download it from FB and add it as an attachment with add-from-server
    if (isset($GLOBALS['add-from-server']) && isset($album_content['thumb'])) {
        fpf_attach_thumbnail($post_ID, $album_content['thumb']);
    }
    //Done!
    return $data;
}
Пример #2
0
function fpf_run_main($data)
{
    //Don't process REVISIONS (would result in 2 fetches per save)
    if ($data['post_type'] == 'revision') {
        return $data;
    }
    //Check the content for our magic tag (and parse out everything we need if found)
    $parsed_content = fpf_find_tags($data['post_content']);
    if (!$parsed_content) {
        return $data;
    }
    //Connect to Facebook and generate the album content
    $album_content = fpf_fetch_album_content($parsed_content['aid'], $parsed_content);
    //Update the post we're about to save
    $data['post_content'] = $parsed_content['before'] . $parsed_content['startTag'] . $album_content['content'] . $parsed_content['endTag'] . $parsed_content['after'];
    //Set postmeta with the album's size and cover photo (can be optionally referenced by the user)
    //(Note: for some stupid reason, $data doesn't have the ID - we need to parse it out of the guid.)
    $post_ID = substr(strrchr($data['guid'], '='), 1);
    update_post_meta($post_ID, '_fpf_album_size', $album_content['count']);
    if (isset($album_content['cover'])) {
        update_post_meta($post_ID, '_fpf_album_cover', $album_content['cover']);
    } else {
        delete_post_meta($post_ID, '_fpf_album_cover');
    }
    //Done!
    return $data;
}
function fpf_run_main($post_id)
{
    // If this is an autosave, our form has not been submitted, so we don't want to do anything.
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    //Don't process REVISIONS (would result in 2 fetches per save)
    if (wp_is_post_revision($post_id)) {
        return $post_id;
    }
    // Check the user's permissions.
    if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return $post_id;
        }
    } else {
        if (!current_user_can('edit_post', $post_id)) {
            return $post_id;
        }
    }
    /* OK, it's safe for us to save the data now. */
    // Make sure that it is set.
    if (!isset($_POST['post_content'])) {
        return $post_id;
    }
    $parsed_content = '';
    $parsed_content = fpf_find_shortcode($_POST['post_content']);
    // back compatibility for old "magic tags"
    if (!$parsed_content) {
        $parsed_content = fpf_find_tags($_POST['post_content']);
        if (isset($parsed_content['aid'])) {
            $parsed_content['id'] = $parsed_content['aid'];
        }
    }
    // return early if nothing doing
    if (empty($parsed_content) || !isset($parsed_content['id'])) {
        return $post_id;
    }
    //Connect to Facebook and generate the album content
    $album_content = fpf_fetch_album_content($parsed_content['id'], $parsed_content);
    //Update the post we're about to save
    $album = $parsed_content['before'] . $parsed_content['startTag'] . $album_content['content'] . $parsed_content['endTag'] . $parsed_content['after'];
    $album = balanceTags($album);
    // @todo add more sanitization
    update_post_meta($post_id, '_fpf_album_html', $album);
    //Set postmeta with the album's size and cover photo (can be optionally referenced by the user)
    update_post_meta($post_id, '_fpf_album_size', $album_content['count']);
    if (isset($album_content['cover'])) {
        update_post_meta($post_id, '_fpf_album_cover', $album_content['cover']);
    } else {
        delete_post_meta($post_id, '_fpf_album_cover');
    }
    //Done!
    return $post_id;
}