Guest User

Untitled

a guest
Aug 3rd, 2012
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Plugin Name: Simple Picasa Album Embedder
  4. Plugin URI: http://www.caekcraft.co.uk/simple-picasa-album-embedder/
  5. Description: A simple way to embed the pictures of a picasa album. You supply your e-mail address and password. The plugin then gets all your albums (the private ones as well), allows you to select which page you want to embed your full album, and voilá. It puts the gallery before the actual content.
  6.  
  7. Version: 1.0.7
  8. Author: CaekCraft
  9. Author URI: http://www.caekcraft.co.uk
  10. License: GPL2
  11. */
  12. add_action('admin_init', array('spae_jg','init'));
  13. add_action('admin_menu',array('spae_jg','admin_menus'));
  14. add_action('wp_head',array('spae_jg','add_css'));
  15. add_filter('the_content', array('spae_jg','insert_gallery'));
  16. add_action('admin_print_styles', array('spae_jg','add_css'));
  17.  
  18.  
  19. class spae_jg {
  20.  
  21.     /* ---- This is the description of the function immediately following this flag ----
  22.      *
  23.      * name: set_defaults()
  24.      * purpose: When the plugin is first installed, populate the database with initial data to avoid calling the validation function twice on first submit.
  25.      * called from: init()
  26.      * calls: default_values()
  27.      * returns: none
  28.      */
  29.     function set_defaults() {
  30.         global $spae_vars;
  31.         $spae_vars = get_option('spae_DB');
  32.         if( false === $spae_vars) {
  33.             $def_options = self::default_values();
  34.             update_option('spae_DB',$def_options);
  35.         }
  36.     }
  37.  
  38.     /* ---- This is the description of the function immediately following this flag ----
  39.      *
  40.      * name: default_values()
  41.      * purpose: Populate an array with default values, before user inputs anything.
  42.      * called from: set_defaults()
  43.      * calls: none
  44.      * returns: $options (array)
  45.      */
  46.     function default_values() {
  47.         $options = array(
  48.             'gmail' => '',
  49.             'pass' => '',
  50.             'album' => '',
  51.             'key' => '',
  52.             'pageid' => '');
  53.         return $options;
  54.     }
  55.  
  56.     /* ---- This is the description of the function immediately following this flag ----
  57.      *
  58.      * name: include_zend()
  59.      * purpose: The plugin needs certain Zend classes to work (to be able to connect to google's api and user content). This checks whether these classes are present, and if not, tries to include them, then checks again, and provides feedback.
  60.      * called from: init()
  61.      * returns: true upon success (classes are included and ready to use), false (otherwise)
  62.      */
  63.     function include_zend()
  64.     {
  65.         $zclassesincluded = 0; //I use this to check whether all classes are present
  66.         $paths = explode(PATH_SEPARATOR, get_include_path()); //get the include paths to search for Zend. The Zend gdata interfaces plugin adds an include path, so it will show up here
  67.         foreach ($paths as $path) {
  68.             if(file_exists($path.'/Zend/Loader.php')) {
  69.                 require_once($path.'/Zend/Loader.php'); //if the file is found, include it
  70.                 $zend_classes = array('Zend_Gdata','Zend_Gdata_ClientLogin','Zend_Gdata_Photos','Zend_Http_Client','Zend_Gdata_Photos_UserQuery','Zend_Gdata_Feed','Zend_Uri_Http'); // populate with all the classes the plugin needs
  71.                 foreach ($zend_classes as $class_to_include) { // iterate
  72.                     Zend_Loader::loadClass($class_to_include); // include
  73.                     if(class_exists($class_to_include)) {
  74.                         $zclassesincluded++; } // check if include successful, and increase the variable
  75.                 }
  76.                 break; // if found once in the include paths, stop. We don't want to include it twice
  77.             }
  78.         }
  79.         if($zclassesincluded == 7) { // if all classes are included, the value should be 7. If it is not 7, some or all classes did not get included => problem
  80.             return true; // green light for the rest of the plugin
  81.         } else {
  82.             return false; // red light for the rest of the plugin
  83.         }
  84.     }
  85.  
  86.     /* ---- This is the description of the function immediately following this flag ----
  87.      *
  88.      * name: google_login()
  89.      * purpose: Checks whether credentials supplied are valid or not
  90.      * called from: init(), insert_gallery()
  91.      * calls: various Zend classes that connect to google
  92.      * returns: true on success, false on failure
  93.      */
  94.     function google_login($jg_gmail, $password) {
  95.         $svc = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  96.         try {
  97.             $client = Zend_Gdata_ClientLogin::getHttpClient($jg_gmail, $password, $svc);
  98.             return true;
  99.         }
  100.         catch (Zend_Gdata_App_AuthException $e)
  101.         {
  102.             $gerror = "error: ". $e->getMessage();
  103.             return false;
  104.         }
  105.     }
  106.  
  107.     /* ---- This is the description of the function immediately following this flag ----
  108.      *
  109.      * name: decrypt_all()
  110.      * purpose: decrypts everything, and stores them in constants
  111.      * called from: init(), insert_gallery()
  112.      * calls: Encryption::decrypt
  113.      * returns: constants
  114.      */
  115.     function decrypt_all() {
  116.         $spae_vars = get_option('spae_DB');
  117.         if(is_array($spae_vars) && $spae_vars['gmail'] != '') {
  118.             $remove = array('key');
  119.             foreach ($spae_vars as $key => $value) {
  120.                 if($value == '') {
  121.                     array_push($remove, $key);
  122.                 }
  123.             }
  124.             $fremove = array_flip($remove);
  125.             $to_decrypt = array_diff_key($spae_vars, $fremove);
  126.  
  127.             foreach($to_decrypt as $key => $value) {
  128.                 $decrypted[$key] = Encryption::decrypt($value, $spae_vars['key']);
  129.             }
  130.             $key_to_vars = array('key' => $spae_vars['key']);
  131.             $to_define = array_merge($decrypted, $key_to_vars);
  132.         }
  133.         if (isset($to_define) && array_key_exists('gmail',$to_define)) { define('email',$to_define['gmail'], true); } else { define('email',''); }
  134.         if (isset($to_define) && array_key_exists('pass',$to_define)) { define('password', $to_define['pass'], true); } else { define('password',''); }
  135.         if (isset($to_define) && array_key_exists('key',$to_define)) { define('keyphrase', $to_define['key'], true); } else { define('keyphrase',''); }
  136.         if (isset($to_define) && array_key_exists('album',$to_define)) { define('albumid', $to_define['album'], true); } else { define('albumid',''); }
  137.         if (isset($to_define) && array_key_exists('pageid',$to_define)) { define('pageid', $to_define['pageid'], true); } else { define('pageid',''); }
  138.     }
  139.  
  140.     /* ---- This is the description of the function immediately following this flag ----
  141.      *
  142.      * name: embed_paypal()
  143.      * purpose: to embed a donation button to me
  144.      * called from: SPAE_form()
  145.      * calls: none
  146.      * returns: html
  147.      */
  148.     function embed_paypal() {
  149.         ?>
  150.         <div id="paypalbutton">
  151.             <h3>Keep me fed!</h3>
  152.             <p>If this plugin helped you in any way, don't shy away from clicking the Donate button. I will be grateful. You could buy me ink for the printer, paper for the printer, coffee to keep me alive, and so on.</p>
  153.             <form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="paypal" target="_blank">
  154.                 <input type="hidden" name="cmd" value="_s-xclick">
  155.                 <input type="hidden" name="hosted_button_id" value="4WEWF3GDRR3RC">
  156.                 <input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110401-1/en_US/GB/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
  157.                 <img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110401-1/en_GB/i/scr/pixel.gif" width="1" height="1">
  158.             </form>
  159.         </div>
  160.         <?php
  161.     }
  162.  
  163.     /* ---- This is the description of the function immediately following this flag ----
  164.      *
  165.      * name: init()
  166.      * purpose: Builds up the necessary framework for the options. Sets the section, field, checks whether all prerequisites are present, and if not, notifies the user.
  167.      * called from: add_action() -> "admin_init" hook (line 10)
  168.      * calls: various functions that display the sections and fields.
  169.      * returns: html
  170.      */
  171.     function init(){
  172.         self::set_defaults(); // checks if first install, populates DB, otherwise nothing
  173.         self::decrypt_all(); // gets data from DB, decrypts them and makes them ready for further use
  174.         $check_zend = self::include_zend(); // checks whether Zend is present or not
  175.         if($check_zend) {
  176.             $check_google_login = self::google_login(email,password); // checks if credentials are good to make a connection or not. Also needed to embed this here, because PHP will die if zend is not present (as google_login uses zend)
  177.         } else {
  178.             $check_google_login = false; // sets google_login to false if zend is not present (thus cannot even check)
  179.         }
  180.  
  181.         register_setting(
  182.             'spae_main', //the settings group name
  183.             'spae_DB', //the var to store the array in the DB (key)
  184.             array('spae_jg','validate')); //  'plugin_options_validate'
  185.         add_settings_section(
  186.             'spae_section', //the section id
  187.             'Account Data', // the section title
  188.             array('spae_jg','HTML_SECTION'), //the callback function
  189.             'spae_settings'); //the page id (options-general.php?page=XXX <- this)
  190.  
  191.         /*  these are the fields from now on */
  192.         add_settings_field(
  193.             'spae_email', //the field ID
  194.             'Your e-mail address', // the field title
  195.             array('spae_jg', 'HTML_email'), //the callback function
  196.             'spae_settings', // the page id (options-general.php?page=XXX <- this)
  197.             'spae_section'); // the section ID
  198.         add_settings_field(
  199.             'spae_pwd', //the field ID
  200.             'Password', // the field title
  201.             array('spae_jg', 'HTML_pwd'), //the callback function
  202.             'spae_settings', // the page id (options-general.php?page=XXX <- this)
  203.             'spae_section'); // the section ID
  204.         add_settings_field(
  205.             'spae_key', // the field ID
  206.             'Key', // field title (cuz it's hidden)
  207.             array('spae_jg', 'HTML_key'), // the callback function
  208.             'spae_settings', // the page id (options-general.php?page=XXX <- this)
  209.             'spae_section'); // the section ID
  210.  
  211.         if($check_zend) {
  212.             if($check_google_login) {
  213.                 //these are only run if Zend is present, and credentials are good
  214.  
  215.                 add_settings_field(
  216.                     'spae_album', //the field ID
  217.                     'Which album would you like to embed?', // the field title
  218.                     array('spae_jg', 'HTML_album'), //the callback function
  219.                     'spae_settings', // the page id (options-general.php?page=XXX <- this)
  220.                     'spae_section'); // the section ID
  221.                 add_settings_field(
  222.                     'spae_pageid', //the field ID
  223.                     'ID of the target page', // the field title
  224.                     array('spae_jg', 'HTML_pageid'), //the callback function
  225.                     'spae_settings', // the page id (options-general.php?page=XXX <- this)
  226.                     'spae_section'); // the section ID
  227.             } else {
  228.                 // this is run when Zend is present, but google credentials are not okay
  229.  
  230.                 add_settings_field(
  231.                     'spae_nogoogle', //the field ID
  232.                     'Google Login Unsuccessful', // the field title
  233.                     array('spae_jg', 'HTML_nogoogle'), //the callback function
  234.                     'spae_settings', // the page id (options-general.php?page=XXX <- this)
  235.                     'spae_section'); // the section ID
  236.             }
  237.         } else {
  238.             // this is run when Zend is not present, even though inclusion has been tried.
  239.  
  240.             add_settings_field(
  241.                 'spae_nozend',
  242.                 'Ooops, Zend is borked',
  243.                 array('spae_jg', 'HTML_nozend'),
  244.                 'spae_settings',
  245.                 'spae_section');
  246.         }
  247.     }
  248.  
  249.     /* ---- This is the description of the function immediately following this flag ----
  250.      *
  251.      * name: admin_menus()
  252.      * purpose: Adds capability and means for the user to interact with the plugin (which means adds a menu under the "Settings" section, and a page where all the settings can be tweaked).
  253.      * called from: add_action -> "admin_menu" hook (line 11)
  254.      * calls: add_options_page() -> SPAE_form() : to render the option page
  255.      * returns: html
  256.      */
  257.     function admin_menus() {
  258.         if (!function_exists('current_user_can') || !current_user_can('manage_options')) {
  259.             return;
  260.         }
  261.         if (function_exists('add_options_page')) {
  262.             add_options_page(
  263.                 'SPAE Settings', // Title of the page
  264.                 'SPAE Settings menu', // menu text
  265.                 'manage_options',  // credentials necessary to display the menu
  266.                 'spae_settings',   // the page id (options-general.php?page=XXX <- this)
  267.                 array('spae_jg', 'SPAE_form')); // calls the function that actually displays the settings page for it. (important, as without the settings fields and do functions, jack shit will be visible.
  268.         }
  269.     }
  270.  
  271.     /* ---- This is the description of the function immediately following this flag ----
  272.      *
  273.      * name: SPAE_form()
  274.      * purpose: Renders the initial html content on the options page
  275.      * called from: admin_menus
  276.      * calls: the html functions as set out in the add_settings_field() and add_settings_section() functions within init()
  277.      * returns:
  278.      */
  279.     function SPAE_form() {
  280.         $spae_vars = get_option('spae_DB');
  281.         ?>
  282.         <div id="spae_wrap">
  283.             <?php screen_icon("options-general"); ?>
  284.             <h2>Simple Picasa Album Embedder Settingz</h2>
  285.             <form name="spae" action="options.php" method="post">
  286.                 <?php settings_fields('spae_main'); // the group id is needed (register settings) ?>
  287.                 <?php do_settings_sections('spae_settings');  // the page id (options-general.php?page=XXX <- this)?>
  288.                 <p class="submit">
  289.                     <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?>" />
  290.                 </p>
  291.             </form>
  292.             <?php self::embed_paypal(); ?>
  293.  
  294.         </div>
  295.         <?php
  296.     }
  297.  
  298.     /* ---- This is the description of the function immediately following this flag ----
  299.      *
  300.      * name: Overview()
  301.      * purpose: display optional html content at the beginning of the settings section
  302.      * called from: spae_jg::init::add_settings_section
  303.      * calls: void
  304.      * returns: html
  305.      */
  306.     function HTML_SECTION() {
  307.  
  308.     }
  309.  
  310.     /* ---- This is the description of the function immediately following this flag ----
  311.      *
  312.      * name: HTML_email
  313.      * purpose: displays the form field for one of the sections
  314.      * called from: spae_jg::init::add_settings_field()
  315.      * calls: void
  316.      * returns: html
  317.      */
  318.     function HTML_email() { //the html for the email input field
  319.         $spae_vars = get_option('spae_DB'); //the DB key is needed here
  320.         ?>
  321.         <input
  322.             id="gmail"
  323.             name="spae_DB[gmail]"
  324.             class="regular-text"
  325.             value="<?php echo email; ?>"
  326.         />
  327.         <?php
  328.     }
  329.  
  330.     /* ---- This is the description of the function immediately following this flag ----
  331.      *
  332.      * name: HTML_pwd
  333.      * purpose: displays the password field for the settings section
  334.      * called from: spae_jg::init::add_settings_field()
  335.      * calls: void
  336.      * returns: html
  337.      */
  338.     function HTML_pwd() { //the html for the password input field
  339.         $spae_vars = get_option('spae_DB'); //the DB key is needed here
  340.         ?>
  341.         <input
  342.             id="pass"
  343.             type="password"
  344.             name="spae_DB[pass]"
  345.             class="regular-text"
  346.             value="<?php echo password; ?>"
  347.         />
  348.         <?php
  349.     }
  350.  
  351.     /* ---- This is the description of the function immediately following this flag ----
  352.      *
  353.      * name: HTML_key
  354.      * purpose: displays the hidden field for the keyphrase
  355.      * called from:
  356.      * calls:
  357.      * returns:
  358.      */
  359.  
  360.     function HTML_key() { //the html for the password input field
  361.         $spae_vars = get_option('spae_DB'); //the DB key is needed here
  362.         if(isset($spae_vars['key']) && strlen($spae_vars['key']) == 15) {
  363.             $keyhelper = $spae_vars['key'];
  364.         } else {
  365.             $keyhelper = self::random_string();
  366.         }
  367.         define('keyphrase2', $keyhelper, true);
  368. ?>
  369.         <input
  370.             id="pass"
  371.             type="hidden"
  372.             name="spae_DB[key]"
  373.             class="regular-text"
  374.             value="<?php echo keyphrase2; ?>"
  375.         />
  376.         <?php
  377.     }
  378.  
  379.     /* ---- This is the description of the function immediately following this flag ----
  380.      *
  381.      * name: HTML_album
  382.      * purpose: does logic based on whether the plugin can connect to the user's google account or not. If not, displays warning messages, and informs the user about the next steps. If it can, displays a dropdown list of the albums that the user has on her picasa web albums.
  383.      * called from: spae_jg::init::add_settings_field()
  384.      * calls: TBC
  385.      * returns: TBC
  386.      */
  387.     function HTML_album() { //the html for selecting the album (will only work, if there is a connection made, and the list is fetched successfully)
  388.         $spae_vars = get_option('spae_DB'); //the DB key is needed here
  389.         $svc = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  390.         $client = Zend_Gdata_ClientLogin::getHttpClient(email, password, $svc);
  391.         $gphoto = new Zend_Gdata_Photos($client);
  392.         $query = new Zend_Gdata_Photos_UserQuery();
  393.         $query->setType("entry");
  394.         try {
  395.             $userFeed = $gphoto->getUserFeed(null, $query);
  396.             echo "<select id='album' name='spae_DB[album]' >";
  397.             foreach ($userFeed as $user_entry) {
  398.                 $albumid = $user_entry->id->text;
  399.                 $albumid_array = explode("/",$albumid);
  400.                 $rev_albumid_array = array_reverse($albumid_array);
  401.                 $clean_albumid = $rev_albumid_array[0];
  402.                 $selected = (albumid == $clean_albumid) ? ' selected="selected" ' : '';
  403.  
  404.                 $option = '<option value="'.$clean_albumid.'"'. $selected . '/>';
  405.                 $option .= $user_entry->title->text;
  406.                 $option .= '</option>';
  407.                 echo $option;
  408.             }
  409.             echo "</select>";
  410.         } catch (Zend_Gdata_App_HttpException $e) {
  411.             echo "Error: ". $e->getMessage() . "<br />\n";
  412.             if( $e->getReponse() != null) {
  413.                 echo "Body: <br />\n" . $e->getResponse()->getBody() . "<br />\n";
  414.             }
  415.             echo "Error: " . $e->getMessage();
  416.         }
  417.     }
  418.  
  419.     /* ---- This is the description of the function immediately following this flag ----
  420.      *
  421.      * name: HTML_pageid()
  422.      * purpose: To display a field where user can specify which page she wants to embed the gallery. If plugin cannot connect, does not display anything, since there is no point.
  423.      * called from: spae_jg::init::add_settings_field()
  424.      * calls: TBC
  425.      * returns: TBC
  426.      */
  427.     function HTML_pageid() { //the html for selecting the page to include the gallery in
  428.         $spae_vars = get_option('spae_DB'); //the DB key is needed here
  429.         $pages = get_pages();
  430.         echo "<select id='pageid' name='spae_DB[pageid]' >";
  431.         foreach ($pages as $pagg) {
  432.             $selected = (pageid == $pagg->ID) ? ' selected="selected" ' : '';
  433.             $option = '<option value="'.$pagg->ID .'"'. $selected . '/>';
  434.             $option .= $pagg->post_title;
  435.             $option .= '</option>';
  436.             echo $option;
  437.         }
  438.         echo "</select>";
  439.     }
  440.  
  441.     /* ---- This is the description of the function immediately following this flag ----
  442.      *
  443.      * name: HTML_nozend
  444.      * purpose: displays warning, informing user that the Zend library is not available, therefore it cannot connect to the google account
  445.      * called from: spae_jg::init::add_settings_field() after logic check
  446.      * calls: void
  447.      * returns: html
  448.      */
  449.     function HTML_nozend() {
  450.         ?>
  451.         <div class="trolling">
  452.             <p>Sorry, Zend is not loaded. It is entirely pointless to select the album and the page you want to include the album to, because the connection will not be made.</p>
  453.             <p>If this happens, download the <a href="http://wordpress.org/extend/plugins/zend-gdata-interfaces/" target="_blank">Zend Gdata Interfaces plugin</a>, and you should be ready to go.</p>
  454.         </div>
  455.         <?php
  456.     }
  457.  
  458.     /* ---- This is the description of the function immediately following this flag ----
  459.      *
  460.      * name: HTML_nogoogle
  461.      * purpose: to display a warning message should the user provide fake credentials
  462.      * called from: init()
  463.      * calls: void
  464.      * returns: html
  465.      */
  466.     function HTML_nogoogle() {
  467.         ?>
  468.         <div class="trolling">
  469.             <p>Sorry, the credentials you supplied are not a valid pair, I cannot make the connection to your google account.</p>
  470.             <p>Please enter the e-mail address and password correctly.</p>
  471.         </div>
  472.         <?php
  473.     }
  474.  
  475.     /* ---- This is the description of the function immediately following this flag ----
  476.      *
  477.      * name: validate($input)
  478.      * purpose: Validates and cleans input. E-mail field only accepts e-mails, etcetc
  479.      * called from: spae_jg::init::add_settings_section()
  480.      * calls: TBC
  481.      * returns: cleaned data
  482.      */
  483.     function validate($input) {
  484.         $remove = array('key');
  485.         //function to remove the pageid and album from encryption if google login fails, and blank them
  486.         $val_checkgoogle = self::google_login($input['gmail'], $input['pass']);
  487.         if(!$val_checkgoogle) {
  488.             array_push($remove, 'album','pageid', 'gmail', 'pass');
  489.             $input['pageid'] = '';
  490.             $input['album'] = '';
  491.             $input['gmail'] = '';
  492.             $input['pass'] = '';
  493.         }
  494.  
  495.         $fremove = array_flip($remove);
  496.         $to_encrypt = array_diff_key($input, $fremove);
  497.  
  498.         $encrypted = array();
  499.         foreach ($to_encrypt as $key => $value) {
  500.             $encrypted[$key] = Encryption::encrypt($value, $input['key']);
  501.  
  502.         }
  503.         //$encrypted = array_map(array('Encryption','encrypt'),$to_encrypt, $key_array);
  504.         $key_to_DB = array('key' => $input['key']);
  505.         $to_DB = array_merge($encrypted, $key_to_DB);
  506.  
  507.         return $to_DB;
  508.     }
  509.  
  510.     /* ---- This is the description of the function immediately following this flag ----
  511.      *
  512.      * name: insert_gallery()
  513.      * purpose: Inserts the gallery retrieved from the album by the user to the specified page
  514.      * called from: TBC
  515.      * calls: TBC
  516.      * returns: html
  517.      */
  518.     function insert_gallery($content) {
  519.         self::include_zend();
  520.         $currentid = get_the_ID();
  521.         self::decrypt_all();
  522.         if ($currentid != pageid ) {
  523.             return $content;
  524.         } else {
  525.             $svc = Zend_Gdata_Photos::AUTH_SERVICE_NAME;
  526.             try {
  527.                 $client = Zend_Gdata_ClientLogin::getHttpClient(email, password, $svc);
  528.             }
  529.             catch (Zend_Gdata_App_AuthException $e) {
  530.                 //echo "error: ". $e->getMessage();
  531.                 //echo "Sorry, e-mail and password don't match. Please correct it!";
  532.             }
  533.             $gphoto = new Zend_Gdata_Photos($client);
  534.  
  535.             // generate query to get album feed
  536.             $query = $gphoto->newAlbumQuery();
  537.             $query->setAlbumId(albumid);
  538.  
  539.             // get and parse album feed
  540.             try
  541.             {
  542.                 $feed = $gphoto->getAlbumFeed($query);
  543.             }
  544.             catch (Zend_Gdata_App_Exception $e)
  545.             {
  546.                 echo "Error: " . $e->getResponse();
  547.             }
  548.             ?>
  549.             <!-- this bit is responsible for the output -->
  550.             <?php
  551.             // process each photo entry
  552.             // print each entry's title, size, dimensions, tags, and thumbnail image
  553.             $html_gallery ='<ul class="spae"><div id="picasaPictures">';
  554.             foreach ($feed as $entry) {
  555.                 $title = $entry->getTitle();
  556.                 $summary = $entry->getSummary();
  557.                 $stuff = $entry->getMediaGroup()->getContent();
  558.                 $url = $stuff[0]->getUrl();
  559.                 $thumbnail = $entry->getMediaGroup()->getThumbnail();
  560.                 $tags = $entry->getMediaGroup()->getKeywords();
  561.                 $size = $entry->getGphotoSize();
  562.                 $height = $entry->getGphotoHeight();
  563.                 $width = $entry->getGphotoWidth();
  564.                 $html_gallery .= "<li><a href='".$url."' rel='lightbox[dude]'><img src='".$thumbnail[1]->url."' width='".$thumbnail[1]->width."' height='".$thumbnail[1]->height."'></a></li>";
  565.  
  566.             }
  567.             $html_gallery .= "</div></ul>";
  568.  
  569.             $content = $html_gallery.$content;
  570.             return $content;
  571.         }
  572.     }
  573.  
  574.     /* ---- This is the description of the function immediately following this flag ----
  575.      *
  576.      * name: add_css()
  577.      * purpose: to add css -- will need to modify it
  578.      * called from: root
  579.      * calls: nope
  580.      * returns: nope
  581.      */
  582.  
  583.     function add_css() {
  584.         $dir = dirname(__FILE__);
  585.         $plugindir = str_replace(WP_PLUGIN_DIR, '', $dir);
  586.         $absolute_css_url = WP_PLUGIN_URL . $plugindir . "/options.css";
  587.  
  588.         $css_include_relpath = str_replace(site_url(), '', $absolute_css_url);
  589.         wp_register_style('spae_jg_admin', $css_include_relpath);
  590.         wp_enqueue_style('spae_jg_admin');
  591.     }
  592.  
  593.     /* ---- This is the description of the function immediately following this flag ----
  594.      *
  595.      * name: random_string()
  596.      * purpose: to generate a random string for a key
  597.      * called from:
  598.      * calls:
  599.      * returns:
  600.      */
  601.     function random_string() {
  602.         $count_int = 15;
  603.         $tmp_num = array();
  604.         for ($k = 0; $k <3 ; $k++) {
  605.             if ($k != 2) {
  606.                 $tmp_num[$k] = rand(0,$count_int);
  607.                 $count_int = $count_int - $tmp_num[$k];
  608.             } else {
  609.                 $tmp_num[$k] = $count_int;
  610.             }
  611.         }
  612.         $character_set_array = array();
  613.         $character_set_array[ ] = array( 'count' => $tmp_num[0], 'characters' => 'abcdefghijklmnopqrstuvwxyz' );
  614.         $character_set_array[ ] = array( 'count' => $tmp_num[1], 'characters' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' );
  615.         $character_set_array[ ] = array( 'count' => $tmp_num[2], 'characters' => '0123456789' );
  616.  
  617.         $temp_array = array();
  618.         foreach ( $character_set_array as $character_set ) {
  619.             for ( $i = 0; $i < $character_set[ 'count' ]; $i++ ) {
  620.                 $temp_array[ ] = $character_set[ 'characters' ][ rand( 0, strlen( $character_set[ 'characters' ] ) - 1 ) ];
  621.             }
  622.         }
  623.         shuffle( $temp_array );
  624.         return implode( '', $temp_array );
  625.     }
  626. }
  627.  
  628. class Encryption
  629. {
  630.     const CYPHER = 'blowfish';
  631.     const MODE   = 'cfb';
  632.     //const KEY    = '7QQvcT9Ga7R6QC3';
  633.     //spae_jg::keyphrase;
  634.     public function encrypt($plaintext, $key)
  635.     {
  636.         //$spae_vars = get_option('spae_DB'); //the DB key is needed here
  637.         //$keyphrase2 = $spae_vars['key'];
  638.         $td = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
  639.         $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
  640.         mcrypt_generic_init($td, $key, $iv);
  641.         $crypttext = mcrypt_generic($td, $plaintext);
  642.         mcrypt_generic_deinit($td);
  643.         return base64_encode($iv.$crypttext);
  644.     }
  645.  
  646.     public function decrypt($deccrypttext, $key)
  647.     {
  648.         //$spae_vars = get_option('spae_DB'); //the DB key is needed here
  649.         //$keyphrase2 = $spae_vars['key'];
  650.         $crypttext = base64_decode($deccrypttext);
  651.         $plaintext = '';
  652.         $td        = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
  653.         $ivsize    = mcrypt_enc_get_iv_size($td);
  654.         $iv        = substr($crypttext, 0, $ivsize);
  655.         $crypttext = substr($crypttext, $ivsize);
  656.         if ($iv)
  657.         {
  658.             mcrypt_generic_init($td, $key, $iv);
  659.             $plaintext = mdecrypt_generic($td, $crypttext);
  660.         }
  661.         return $plaintext;
  662.     }
  663. }
  664. ?>
RAW Paste Data