Exemplo n.º 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;
}
Exemplo n.º 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;
}
Exemplo n.º 4
0
function fpf_refetch_all($pages, $printProgress = false)
{
    //Increase the timelimit of the script to make sure it can finish
    if (!ini_get('safe_mode') && !strstr(ini_get('disabled_functions'), 'set_time_limit')) {
        set_time_limit(500);
    }
    $outputString = "";
    $total = count($pages);
    $index = 0;
    foreach ($pages as $page) {
        $index++;
        $outputString .= "Checking {$index}/{$total}: {$page->post_title}......";
        if (!fpf_find_tags($page->post_content)) {
            $outputString .= "No gallery tag found.\n";
        } else {
            //Categories need special handling; before re-saving the post, we need to explicitly place a list of cats or they'll be lost.
            $cats = get_the_category($page->ID);
            $page->post_category = array();
            foreach ($cats as $cat) {
                array_push($page->post_category, $cat->cat_ID);
            }
            $outputString .= "Found!\n<b>.........Fetching......";
            if ($printProgress) {
                echo $outputString;
                $outputString = "";
            }
            wp_insert_post($page);
            $fetchCount = get_post_meta($page->ID, '_fb_album_size', true);
            if (!$fetchCount) {
                $fetchCount = "0";
            }
            $outputString .= $fetchCount . " photos fetched.</b>\n";
        }
        if ($printProgress) {
            echo $outputString;
            $outputString = "";
        }
    }
    return $outputString;
}
Exemplo n.º 5
0
/**
 * Output the plugin's Admin Page 
 */
function fpf_admin_page()
{
    global $appapikey, $appsecret;
    global $fpf_identifier, $fpf_homepage;
    global $opt_thumb_path, $opt_last_uid_search;
    global $opt_fb_sess_key, $opt_fb_sess_sec, $opt_fb_sess_uid, $opt_fb_sess_uname;
    ?>
<div class="wrap">
      <h2>Facebook Photo Fetcher</h2><?php 
    //Show a warning if they're using a naughty other plugin
    if (class_exists('Facebook')) {
        ?>
<div class="error"><p><strong>Warning:</strong> Another plugin has included the Facebook API throughout all of Wordpress.  I suggest you contact that plugin's author and ask them to include it only in pages where it's actually needed.<br /><br />Things may work fine as-is, but only if the API version included by the other plugin is at least as recent as the one required by Facebook Photo Fetcher.</p></div><?php 
    } else {
        if (version_compare('5', PHP_VERSION, "<=")) {
            require_once 'facebook-platform/php/facebook.php';
        } else {
            die("Sorry, but as of version 1.2.0, Facebook Photo Fetcher requires PHP5.");
        }
    }
    //Connect to Facebook and create an auth token.
    //Note: We only care about $token when the user is creating/saving a session; otherwise it's irrelevant and we just ignore it.
    $facebook = new Facebook($appapikey, $appsecret, null, true);
    $facebook->api_client->secret = $appsecret;
    $token = $facebook->api_client->auth_createToken();
    if (!$token) {
        echo 'Failed to create Facebook authentication token!';
    }
    //Check $_POST for what we're doing, show a message, update any necessary options,
    //and get the corresponding $action_performed.
    $action_performed = do_POST_actions($facebook);
    //Get all the options from the database
    $thumb_path = get_option($opt_thumb_path);
    $search_uid = get_option($opt_last_uid_search);
    $session_key = get_option($opt_fb_sess_key);
    $session_sec = get_option($opt_fb_sess_sec);
    $my_uid = get_option($opt_fb_sess_uid);
    $my_name = get_option($opt_fb_sess_uname);
    if (!$search_uid) {
        $search_uid = $my_uid;
    }
    //Finally, OUTPUT THE ADMIN PAGE.
    ?>
      <div style="position:absolute; right:30px; margin-top:-50px;">
      <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
        <input type="hidden" name="cmd" value="_s-xclick" />
        <input type="hidden" name="hosted_button_id" value="L32NVEXQWYN8A" />
        <input type="hidden" name="return" value="http://www.justin-klein.com/thank-you" />
        <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" />
        <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
      </form>
      </div>
    <hr />  
    
    <?php 
    //SECTION - Overview
    ?>
    <h3>Overview</h3>
    This plugin allows you to create Wordpress photo galleries from any Facebook album you can access.<br /><br />
    To get started, you must first connect with your Facebook account using the button below.  Once connected, you can create a gallery by making a new Wordpress post or page and pasting in one line of special HTML, like this:<br /><br />
    <b>&lt;!--<?php 
    echo $fpf_identifier;
    ?>
 1234567890123456789 --&gt;&lt;!--/<?php 
    echo $fpf_identifier;
    ?>
--&gt;</b><br /><br />
    Whenever you save a post or page containing these tags, this plugin will automatically download the album information and insert its contents between them.  You are free to include any normal content you like before or after, as usual.<br /><br />
    The example number above (1234567890123456789) is an ID that tells the plugin which Facebook album you'd like to import.  To find a list of all available albums, you can use the "Search for Albums" feature below (visible once you've successfully connected).<br /><br />
    That's all there is to it!  Note that this plugin supports quite a few additional parameters you can use to customize how your albums look - i.e. change the number of columns, show only a subset of photos, show or hide photo captions, etc.  You can also use its template functions to directly insert an album from PHP.  Full documentation and a demo gallery is available on the <a href="<?php 
    echo $fpf_homepage;
    ?>
"><b>plugin homepage</b></a>.<br /><br />    
    Have fun!  And if you like this plugin, please don't forget to donate a few bucks to buy me a beer (or a pitcher).  I promise to enjoy every ounce of it :)<br /><br />
    <hr />
    
    <?php 
    //SECTION - Connect to Facebook.  See note at top of file.
    ?>
    <h3>Connect with Facebook</h3><?php 
    if ($my_uid) {
        echo "<i>This plugin is successfully connected with <b>{$my_name}</b>'s Facebook account and is ready to create galleries.</i>";
    } else {
        echo "Before this plugin can be used, you must connect it with your Facebook account.<br /><br />Please click the following button and complete the pop-up login form.  When finished, click the button again to save your session. You will only have to do this once.";
    }
    ?>
      <br /><br />
      <div id="step1wrap">
      <form method="get" id="step1Frm" action="http://www.facebook.com/login.php" target="_blank">
        <input type="hidden" name="api_key" value="<?php 
    echo $appapikey;
    ?>
" />
        <input type="hidden" name="auth_token" value="<?php 
    echo $token;
    ?>
" />
        <input type="hidden" name="popup" value="1" />      <?php 
    //Style the window as a popup
    ?>
        <input type="hidden" name="skipcookie" value="1" /> <?php 
    //User must enter login info even if already logged in
    ?>
        <input type="hidden" name="req_perms" value="offline_access" /> <?php 
    //Require an infinite session
    ?>
        <input type="hidden" name="v" value="1.0" />
        <input type="submit" class="button-secondary" id="step1Btn" value="<?php 
    echo $my_uid ? "Change Facebook Account" : "Login to Facebook";
    ?>
" />
      </form>
      </div>
      
      <!-- NEW STEP!  Added when FB changed their policies in June, 2010... -->
      <div id="step2wrap" style="display:none">
          <a id="step2link" style="font-weight:bold;background:#00FF00;border:1px solid grey;padding:2px;width:auto;" target="newperms" href="http://www.facebook.com/connect/prompt_permission.php?api_key=<?php 
    echo $appapikey;
    ?>
&next=http://www.facebook.com/connect/login_success.html&cancel=http://www.facebook.com/connect/login_failure.html&display=wap&ext_perm=user_photos,friends_photos">Grant Photo Permissions</a>
      </div>
            
      <div id="step3wrap" style="display:none;">
      <form method="post" action="">
        <input type="hidden" name="save-facebook-session" value="<?php 
    echo $token;
    ?>
" />
        <input type="submit" class="button-secondary" style="font-weight:bold;background:#00FF00;" value="Save Facebook Session" />
      </form>
      </div>
            
      <script type="text/javascript">
      jQuery(document).ready(function() {
    	  jQuery('#step1Frm').submit(function() {
        	  jQuery('#step1wrap').toggle();
        	  jQuery('#step2wrap').toggle();
        	});

    	  jQuery('#step2link').click(function() {
        	  jQuery('#step2wrap').toggle();
        	  jQuery('#step3wrap').toggle();
        	});
    	});
      </script>
    <hr />

    <?php 
    //All features below here require connection with facebook
    if ($my_uid) {
        ?>
        
       <?php 
        //SECTION - Search for albums
        ?>
       <h3>Search for Albums</h3><?php 
        if ($action_performed == JGALLERY_ACTION_SEARCH) {
            $facebook->api_client->session_key = $session_key;
            $facebook->api_client->secret = $session_sec;
            $albums = $facebook->api_client->photos_getAlbums($search_uid, null);
            $user = $facebook->api_client->users_getInfo($search_uid, array('name'));
            //NOTE: Remove this outer check to show albums for FAN PAGES as well as users
            //(but those don't work because their AID's are weird, containing underscores, etc - why?)
            if (is_array($user)) {
                if (is_array($user)) {
                    echo "<b>Available Facebook albums for " . $user[0]['name'] . " ( uid {$search_uid} ):</b><br />";
                } else {
                    echo "<b>Available Facebook Albums for ID {$search_uid}</b><br />";
                }
                echo "<small>";
                if (is_array($albums)) {
                    foreach ($albums as $album) {
                        echo '[' . $fpf_identifier . ' ' . $album['aid'] . '] - <a href="' . $album['link'] . '">' . $album['name'] . '</a><br />';
                    }
                } else {
                    echo "None found.<br />";
                }
                echo "</small><br />";
            } else {
                echo "<b>Userid {$search_uid} not found.</b><br /><br />";
            }
        }
        ?>
       <form name="listalbums" method="post" action="">
           To get a list of album ID's that you can use to create galleries, enter a Facebook user ID below and click "Search."<br /><br />
           Your UserID is <b><?php 
        echo $my_uid;
        ?>
</b>. To get a friend's ID, go to their profile and click "View Videos of xx."  The URL will end in <b>?of=1234567</b>; this number is their ID.<br /><br /> 
           <input type="text" name="<?php 
        echo $opt_last_uid_search;
        ?>
" value="<?php 
        echo $search_uid;
        ?>
" size="20"><br /><br />
           <input type="submit" class="button-secondary"  name="Submit" value="Search" />
       </form>
       <hr />


       <?php 
        //SECTION - Thumbs
        ?>
       <h3>Album Thumbnails</h3>
       <?php 
        if (!isset($GLOBALS['add-from-server'])) {
            echo 'If you install the <a target="_blank" href="http://wordpress.org/extend/plugins/add-from-server">Add From Server</a> plugin, album thumbnails can be automatically copied from Facebook and attached to your galleries.  If you do not install it, the galleries will still work fine but they will not automatically have <a target="_blank" href="http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/">Post Thumbnails</a>.';
        } else {
            echo 'This plugin can automatically download album thumbnails from Facebook and attach them as Wordpress <a target="_blank" href="http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/">Post Thumbnails</a>.  Please select the full path to where you\'d like the thumbnails downloaded, or leave it blank to skip them.<br /><br />';
            ?>
       <form name="formOptions" method="post" action="">
           <input type="text" name="<?php 
            echo $opt_thumb_path;
            ?>
" value="<?php 
            echo $thumb_path;
            ?>
" size="90" <?php 
            echo isset($GLOBALS['add-from-server']) ? "" : "disabled='disabled'";
            ?>
>
           <br />
            (Hint: Your document root is <?php 
            echo $_SERVER["DOCUMENT_ROOT"];
            ?>
)
           <br /><br />
           <input type="submit" class="button-secondary" name="Submit" value="Update Options" />
           <input type="hidden" name="options_updated" value="Y">
       </form>
       <?php 
        }
        ?>
       <hr />
        

       <?php 
        //SECTION - Fetch all albums
        ?>
       <h3>Refresh Albums from Facebook</h3>
           This will scan all your posts and pages for galleries created with this plugin, 
           and regenerate each one it finds by re-fetching its information from Facebook.
           The only reason to use this would be if you've changed or updated something in many of your albums and want those changes to be reflected here as well.  It can be quite slow if you have lots of galleries, so use with caution.<br /><br />
           <form name="fetchallposts" method="post" action="">
             <input type="hidden" name="fetch_pages" value="Y">
             <input type="submit" class="button-secondary" name="Submit" value="Re-Fetch All Albums in Pages" />
            </form>
            <form name="fetchallpages" method="post" action="">
              <input type="hidden" name="fetch_posts" value="Y">
              <input type="submit" class="button-secondary" name="Submit" value="Re-Fetch All Albums in Posts" />
            </form>
        <?php 
        if ($action_performed == JGALLERY_ACTION_FETCHPAGES || $action_performed == JGALLERY_ACTION_FETCHPOSTS) {
            //Increase the timelimit of the script to make sure it can finish
            if (!ini_get('safe_mode') && !strstr(ini_get('disabled_functions'), 'set_time_limit')) {
                set_time_limit(500);
            }
            //Get the collection of pages or posts
            if ($action_performed == JGALLERY_ACTION_FETCHPAGES) {
                echo "<b>Checking All Pages for Facebook Albums</b>:<br />";
                $pages = get_pages();
            } else {
                echo "<b>Checking All Posts for Facebook Albums</b>:<br />";
                $pages = get_posts('post_type=post&numberposts=-1&post_status=publish');
            }
            //Go through each post/page and if it contains the magic tags, re-save it (which will cause the wp_insert_post filter below to run)
            echo "<small>";
            $total = count($pages);
            $index = 0;
            foreach ($pages as $page) {
                $index++;
                echo "Checking {$index}/{$total}: {$page->post_title}......";
                if (!fpf_find_tags($page->post_content)) {
                    echo "No gallery tag found.<br />";
                } else {
                    //Categories need special handling; before re-saving the post, we need to explicitly place a list of cats or they'll be lost.
                    $cats = get_the_category($page->ID);
                    $page->post_category = array();
                    foreach ($cats as $cat) {
                        array_push($page->post_category, $cat->cat_ID);
                    }
                    echo "<b>Fetching...</b>";
                    wp_insert_post($page);
                    echo "<b>Done.</b><br />";
                }
            }
            echo "</small>";
        }
        ?>
        <hr />
        <?php 
    }
    //Must connect with Facebook
    ?>
        
      <h4>Development</h4>
      Many hours have gone into making this plugin as versatile and easy to use as possible, far beyond my own personal needs. Although I offer it to you freely, please keep in mind that each hour spent extending and supporting it was an hour that could've also gone towards income-generating work. If you find it useful, a small donation would be greatly appreciated :)
      <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
        <input type="hidden" name="cmd" value="_s-xclick" />
        <input type="hidden" name="hosted_button_id" value="L32NVEXQWYN8A" />
        <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" />
        <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
      </form>
        
        
    </div>
    <?php 
}