CWS_Google_Picasa_Pro_Admin

The admin-specific functionality of the plugin.

Defined (2)

The class is defined in the following location(s).

/admin/class-cws-google-picasa-pro-admin.php  
  1. class CWS_Google_Picasa_Pro_Admin { 
  2.  
  3. var $debug = false; 
  4.  
  5. /** 
  6. * The ID of this plugin. 
  7. * @since 2.0.0 
  8. * @access private 
  9. * @var string $plugin_name The ID of this plugin. 
  10. */ 
  11. private $plugin_name; 
  12.  
  13. /** 
  14. * The version of this plugin. 
  15. * @since 2.0.0 
  16. * @access private 
  17. * @var string $version The current version of this plugin. 
  18. */ 
  19. private $version; 
  20.  
  21. /** 
  22. * The is user authenticated with Google. 
  23. * @since 2.0.0 
  24. * @access private 
  25. * @var int $authenticated Check is user authenticated with Google. 
  26. */  
  27. private $authenticated = 0; 
  28.  
  29. /** 
  30. * The check is this a Pro version. 
  31. * @since 2.0.0 
  32. * @access private 
  33. * @var int $isPro Check is if this is pro version. 
  34. */  
  35. private $isPro ;  
  36.  
  37. /** 
  38. * User Id used to check ignore upgrade notice. 
  39. * @since 2.1.1 
  40. * @access private 
  41. * @var int $userId User Id of loggedin user. 
  42. */  
  43. private $userId; 
  44.  
  45. var $client; // Used for Google Client 
  46.  
  47. /** 
  48. * Initialize the class and set its properties. 
  49. * @since 2.0.0 
  50. * @param string $plugin_name The name of this plugin. 
  51. * @param string $version The version of this plugin. 
  52. */ 
  53. public function __construct( $plugin_name, $version, $isPro ) { 
  54.  
  55. $this->plugin_name = $plugin_name; 
  56. $this->version = $version; 
  57. $this->isPro = $isPro; 
  58. $this->client = new Google_Client(); 
  59. $this->client->setApplicationName("Client_Library_Examples"); 
  60. $this->client->setDeveloperKey("AIzaSyCP9XMYoQdxXfI-gK1bvZDW2RxyfvYENuM");  
  61. $this->client->setClientId('806353319710-g782kn9ed0gm77ucl0meen5ohs84qgqm.apps.googleusercontent.com'); 
  62. $this->client->setClientSecret('P6BMMEWLKUSoxB48X2Tzu8ds'); 
  63. $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob'); 
  64. $this->client->setScopes('https://picasaweb.google.com/data/'); 
  65. $this->client->setAccessType('offline'); 
  66.  
  67. // Include required files 
  68. $this->includes(); 
  69.  
  70. //$this->cws_gpp_admin_installed_notice(); 
  71. //$this->cws_gpp_admin_notices_styles(); 
  72.  
  73.  
  74. /** 
  75. * Register the stylesheets for the admin area. 
  76. * @since 1.0.0 
  77. */ 
  78. public function includes() { 
  79.  
  80. if( $this->debug ) error_log( 'Inside: CWS_WPPicasaPro::includes()' ); 
  81.  
  82. if ( is_admin() ) $this->admin_includes(); 
  83.  
  84. include_once( dirname(__FILE__) . '/../cws-gpp-functions.php' ); // TODO: split file out in admin and non-admin functions 
  85. include_once( dirname(__FILE__) . '/../shortcodes/shortcode-init.php' ); // Init the shortcodes 
  86. include_once( dirname(__FILE__) . '/../widgets/widget-init.php' ); // Widget classes  
  87.  
  88. if( $this->isPro ==1 ) { 
  89. // TODO: change this into an include for Pro shortcodes... 
  90. add_shortcode( 'cws_gpp_images_by_albumid', 'cws_gpp_shortcode_images_in_album' ); // new one, shortcode provides album id 
  91.  
  92. public function admin_includes() { 
  93.  
  94. if( $this->debug ) error_log( 'Inside: CWS_WPPicasaPro::admin_includes()' ); 
  95.  
  96. include_once( dirname(__FILE__) . '/../cws-gpp-functions.php' ); // TODO: split file out in admin and non-admin functions 
  97. }  
  98.  
  99.  
  100. /** 
  101. * Register the stylesheets for the admin area. 
  102. * @since 2.0.0 
  103. */ 
  104. public function enqueue_styles() { 
  105.  
  106. /** 
  107. * This function is provided for demonstration purposes only. 
  108. * An instance of this class should be passed to the run() function 
  109. * defined in Plugin_Name_Loader as all of the hooks are defined 
  110. * in that particular class. 
  111. * The Plugin_Name_Loader will then create the relationship 
  112. * between the defined hooks and the functions defined in this 
  113. * class. 
  114. */ 
  115.  
  116. wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/cws-google-picasa-pro-admin.css', array(), $this->version, 'all' ); 
  117.  
  118.  
  119. /** 
  120. * Register the JavaScript for the admin area. 
  121. * @since 2.0.0 
  122. */ 
  123. public function enqueue_scripts() { 
  124.  
  125. /** 
  126. * This function is provided for demonstration purposes only. 
  127. * An instance of this class should be passed to the run() function 
  128. * defined in Plugin_Name_Loader as all of the hooks are defined 
  129. * in that particular class. 
  130. * The Plugin_Name_Loader will then create the relationship 
  131. * between the defined hooks and the functions defined in this 
  132. * class. 
  133. */ 
  134.  
  135. wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/cws-google-picasa-pro-admin.js', array( 'jquery' ), $this->version, false ); 
  136.  
  137.  
  138. /** 
  139. * Check if the plugin is a Pro version. 
  140. * @since 2.0.0 
  141. */  
  142. private function get_Pro( $isPro ) { 
  143.  
  144. if( $isPro == 1 ) { return "Pro"; } 
  145. return; 
  146.  
  147.  
  148. /** 
  149. * Register the Options for the admin area. 
  150. * @since 2.0.0 
  151. */  
  152. /** 
  153. public function add_options_page() { 
  154.  
  155. $strIsPro = $this->get_Pro( $this->isPro ); 
  156.   
  157. // add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function); 
  158. add_options_page( 'Google Picasa ' . $strIsPro, 'Google Picasa '. $strIsPro, 'manage_options', 'cws_gpp', array( $this, 'options_page') );  
  159. } */ 
  160.  
  161. /** 
  162. * Register the Top Level Menu Page for the admin area. 
  163. * @since 2.3.0 
  164. */  
  165. public function add_menu_page() { 
  166.  
  167. $strIsPro = $this->get_Pro( $this->isPro ); 
  168. // add_menu_page('Page Title', 'Google Photos', 10, 'cws_gpp', 'section'); 
  169. add_menu_page( 'Page Title', 'Google Photos', 'manage_options', 'cws_gpp', array( $this, 'options_page') ); 
  170. add_submenu_page( 'cws_gpp', 'Google Photos Settings', 'Settings', 'manage_options', 'cws_gpp', array( $this, 'options_page') ); 
  171. //add_submenu_page( 'cws_gpp', 'Google Photos Getting Started', 'Get Started', 'manage_options', 'cws_gpp', array( $this, 'getting_started_page') ); 
  172. }  
  173.  
  174. /** 
  175. * Register the Options for the admin area. 
  176. * @since 2.3.0 
  177. */  
  178. public function add_options_sc_page() { 
  179.  
  180. //$strIsPro = $this->get_Pro( $this->isPro ); 
  181. // add_submenu_page( 'cws_gpp', 'Google Photos Album Shortcodes', 'Album Shortcodes', 'manage_options', 'cws_sc', array( $this, 'options_page_sc') ); 
  182. add_submenu_page( 'cws_gpp', 'Google Photos Album Shortcodes', 'Shortcode Examples', 'manage_options', 'cws_sc', array( $this, 'options_page_sc') ); 
  183.  
  184.  
  185. /** 
  186. * Register the Getting Started Options for the admin area. 
  187. * @since 3.0.9 
  188. */  
  189. public function add_options_gs_page() { 
  190.  
  191. //$strIsPro = $this->get_Pro( $this->isPro ); 
  192. add_submenu_page( 'cws_gpp', 'Google Photos Getting Started', 'Getting Started', 'manage_options', 'cws_gs', array( $this, 'options_page_gs') ); 
  193.  
  194.  
  195. /** 
  196. * Draw the Options page for the admin area. This contains simple shortcode snippets for *** PRO ONLY *** 
  197. * @since 2.3.0 
  198. */ 
  199. public function options_page_gs() { 
  200. ?> 
  201. <div class="wrap"> 
  202. <?php screen_icon(); ?> 
  203. <h2>Getting Started</h2> 
  204.  
  205. <!-- <div class="widget-liquid-left"> --> 
  206. <div> 
  207.  
  208. <form action="options.php" method="post"> 
  209.  
  210. <?php  
  211. // Step 1: The user has not authenticated we give them a link to login  
  212. if( $this->isAuthenticated() !== true ) { 
  213. // settings_fields( $option_group ) 
  214. // Output nonce, action, and option_page fields for a settings page. Please note that this function must be called inside of the form tag for the options page. 
  215. // $option_group - A settings group name. This should match the group name used in register_setting().  
  216. ////settings_fields( 'cws_gpp_code' ); 
  217.  
  218. // do_settings_sections( $page ); 
  219. // Prints out all settings sections added to a particular settings page. 
  220. // The slug name of the page whose settings sections you want to output. This should match the page name used in add_settings_section(). 
  221. ////do_settings_sections( 'cws_gpp' );  
  222. ?> 
  223.  
  224. Not authenticated... 
  225. <!-- <input name="Submit" type="submit" value="Save Changes" /> --> 
  226. </form>  
  227. <?php 
  228. } else { 
  229. ?> 
  230. <style> 
  231. span.sc-highlight{ 
  232. background-color:#f7f7f7;padding:6px;border:1px solid #c2c2c2; border-radius:4px; 
  233. </style> 
  234. <div style="width: 95%;" class="postbox-container"> 
  235. <h2>1. Basic Setup</h2> 
  236. <p>To have your albums covers on one page and display the your images from within the selected album on another page.</p> 
  237. <p>See example on <a href="http://wordpress-plugin-google-photos.cheshirewebsolutions.com/display-albums-grid/" target="_blank">demo site</a> or <a href="https://www.youtube.com/watch?v=cx-2PcRcbao" target="_blank">watch video</a> of what we are trying to achieve.</p> 
  238.  
  239. <p>First, it's important to realise that 2 shortcodes are needed for this. One shortcode (a) to display the album covers and and the second shortcode (b) to display the results of the clicked album.</p> 
  240. <p>Second, it's also important to realise that you must put the slug of the page from the second shortcode (b) into the first shortcode (a).</p> 
  241.  
  242. <p>Stick with it, it's not nearly as complicated as it sounds.</p> 
  243. <br/>  
  244. <h3>Display Album Covers</h3> 
  245.  
  246. <p><strong>(a) Shortcode to display album covers</strong></p> 
  247. <p>Below is an example of the shortcode to display the album covers. Place the shortcode on a page and update the <span class="sc-highlight"><i>results_page='results-grid'</i></span> to the slug of the page where you place shortcode (b)</p> 
  248. <p><strong>[cws_gpp_albums theme='grid' results_page='results-grid' show_title=1 show_details=1 num_results=6 hide_albums='Auto Backup, Profile Photos']</strong></p> 
  249. <p>The option <i>results-page='results-grid'</i> is set to the slug of the page where you place shortcode (b). So if you placed shortcode (b) on a page called 'images' then  
  250. you would use <span class="sc-highlight"><i>results-page='images'</i></span>.</p> 
  251.  
  252. <h4>Shortcode (a) Options</h4> 
  253. <p>The album title and details (Date created and number of images in album) can be hidden using options <span class="sc-highlight"><i>show_title=0</i></span> and <span class="sc-highlight"><i>show_details=0</i></span> respectively.</p> 
  254. <p>Control the number of albums covers per page using <span class="sc-highlight"><i>num_results=6</i></span> 
  255. <p>Hide unwanted albums using <span class="sc-highlight"><i>hide_albums='Auto Backup, Profile Photos'</i></span>, obviously replacing with the names of the albums you want to hide</p> 
  256.  
  257. <br/>  
  258. <h3>Display Images in Clicked Album</h3> 
  259.  
  260.  
  261. <p><strong>(b) Shortcode to display images in clicked album</strong></p> 
  262. <p>[cws_gpp_images_in_album theme=grid show_title=1 show_details=1 album_title=1]</p> 
  263. <h4>Shortcode (b) Options</h4> 
  264. <p>The album title can be hidden using option <span class="sc-highlight"><i>album_title=0</i></span></p> 
  265. <p>The image titles and details can be hidden using options <span class="sc-highlight"><i>show_title=0</i></span> and <span class="sc-highlight"><i>show_details=0</i></span> respectively.</p> 
  266.  
  267. <br/>  
  268. <h3>What is the <i>theme</i> option all about?</h3> 
  269. <p>This option controls the display of the Albums and Images, it has 3 options (grid, list, carousel)</p> 
  270. <p>To display albums / images in a <strong>grid</strong> format use <span class="sc-highlight"><i>theme=grid</i></span> 
  271. <p>To display albums / images in a <strong>list</strong> format use <span class="sc-highlight"><i>theme=list</i></span> 
  272. <p>To display albums / images in a <strong>carousel</strong> format use <span class="sc-highlight"><i>theme=carousel</i></span> 
  273. <p>This option is supported in both shortcode (a) and shortcode (b)</p> 
  274.  
  275. <div class="metabox-holder"> 
  276.  
  277. <div class="postboxxxx" id="settingsxxx"> 
  278. <?php 
  279. // $plugin = new CWS_Google_Picasa_Pro( $plugin_name, $version, $isPro ); 
  280. $plugin = new CWS_Google_Picasa_Pro(); 
  281. $plugin_admin = new CWS_Google_Picasa_Pro_Admin( $plugin->get_plugin_name(), $plugin->get_version(), $plugin->get_isPro() ); 
  282.  
  283. // Only display shortcode snippets to Pro users... 
  284. if( $plugin->isPro == 1 ) { 
  285.  
  286. ?> 
  287. <!-- <h2>Pro Features Setup</h2> --> 
  288. <?php 
  289.  
  290. // Grab options stored in db 
  291. $options = get_option( 'cws_gpp_options' ); 
  292.  
  293. // set some defaults... 
  294. $options['results_page'] = isset($options['results_page']) ? $options['results_page'] : ""; 
  295. $options['hide_albums'] = isset($options['hide_albums']) ? $options['hide_albums'] : ""; 
  296. $options['theme'] = isset($options['theme']) ? $options['theme'] : ""; 
  297.  
  298. // Extract the options from db and overwrite with any set in the shortcode 
  299. // extract( shortcode_atts( array( 
  300. extract( array( 
  301. 'thumb_size' => $options['thumb_size'],  
  302. 'album_thumb_size' => $options['album_thumb_size'],  
  303. 'show_title' => $options['show_album_title'],  
  304. 'show_details' => $options['show_album_details'],  
  305. 'num_results' => $options['num_album_results'],  
  306. 'visibility' => $options['private_albums'],  
  307. 'results_page' => $options['results_page'],  
  308. 'hide_albums' => $options['hide_albums'],  
  309. 'theme' => $options['theme'],  
  310. 'imgmax' => $options['lightbox_image_size'],  
  311. ) ); 
  312. // ), $atts ) ); 
  313. // Map albums names to hide to array and trim white space 
  314. //$hide_albums = array_map( 'trim', explode( ', ', $hide_albums ) ); 
  315. /** 
  316. if( isset( $hide_albums ) ) { 
  317. $hide_albums[] = 'Auto Backup'; 
  318. else { 
  319. $hide_albums = 'Auto Backup'; 
  320. */ 
  321. // TODO: cast other vars to int if required 
  322. $thumb_size = (int) $thumb_size; 
  323.  
  324. if ( $show_title === 'false' ) $show_title = false; // just to be sure... 
  325. if ( $show_title === 'true' ) $show_title = true; // just to be sure... 
  326. if ( $show_title === '0' ) $show_title = false; // just to be sure... 
  327. if ( $show_title === '1' ) $show_title = true; // just to be sure... 
  328. $show_title = (bool) $show_title;  
  329.  
  330. if ( $show_details === 'false' ) $show_details = false; // just to be sure... 
  331. if ( $show_details === 'true' ) $show_details = true; // just to be sure... 
  332. if ( $show_details === '0' ) $show_details = false; // just to be sure... 
  333. if ( $show_details === '1' ) $show_details = true; // just to be sure... 
  334. $show_details = (bool) $show_details;  
  335.  
  336. // Grab page from url 
  337. $cws_page = $_GET[ 'cws_page' ]; // $cws_page = get_query_var( 'cws_page' ); 
  338.  
  339. // Grab the access token 
  340. $AccessToken = get_option( 'cws_gpp_access_token' ); 
  341.  
  342. // Get Albums 
  343. $response = $plugin_admin->getAlbumList( $AccessToken, $album_thumb_size, $show_title, 0, 0, $visibility );  
  344.  
  345. ?> 
  346. </div> <!-- / . postbox --> 
  347.  
  348. </div> <!-- / meta holder --> 
  349. </div> <!-- / .postbox-container --> 
  350. <?php } else { ?> 
  351. <?php // Display upgrade content if not Pro 
  352. // echo $plugin_admin->cws_gpp_upgrade_content();  
  353.  
  354. }  
  355.  
  356. ?> 
  357.  
  358. </div><!-- / left --> 
  359. </div> 
  360. <?php 
  361. } // end function options_page_gs() 
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372. /** 
  373. * Draw the Options page for the admin area. This contains simple shortcode snippets for *** PRO ONLY *** 
  374. * @since 2.3.0 
  375. */ 
  376. public function options_page_sc() { 
  377. ?> 
  378. <div class="wrap"> 
  379. <?php screen_icon(); ?> 
  380. <h2>Google Picasa <?php echo $this->get_Pro( $this->isPro );?> Settings</h2> 
  381.  
  382. <!-- <div class="widget-liquid-left"> --> 
  383. <div> 
  384.  
  385. <form action="options.php" method="post"> 
  386.  
  387. <?php  
  388. // Step 1: The user has not authenticated we give them a link to login  
  389. if( $this->isAuthenticated() !== true ) { 
  390. // settings_fields( $option_group ) 
  391. // Output nonce, action, and option_page fields for a settings page. Please note that this function must be called inside of the form tag for the options page. 
  392. // $option_group - A settings group name. This should match the group name used in register_setting().  
  393. ////settings_fields( 'cws_gpp_code' ); 
  394.  
  395. // do_settings_sections( $page ); 
  396. // Prints out all settings sections added to a particular settings page. 
  397. // The slug name of the page whose settings sections you want to output. This should match the page name used in add_settings_section(). 
  398. ////do_settings_sections( 'cws_gpp' );  
  399. ?> 
  400.  
  401. Not authenticated... 
  402. <!-- <input name="Submit" type="submit" value="Save Changes" /> --> 
  403. </form>  
  404. <?php 
  405. } else { 
  406. ?> 
  407. <div style="width: 95%;" class="postbox-container"> 
  408. <h2>Google Photo Album Details</h2> 
  409. <p>Use this shortcode to display photos in a album specified by the ID.</p> 
  410. <div class="metabox-holder"> 
  411.  
  412. <div class="postbox" id="settings"> 
  413. <?php 
  414. // $plugin = new CWS_Google_Picasa_Pro( $plugin_name, $version, $isPro ); 
  415. $plugin = new CWS_Google_Picasa_Pro(); 
  416. $plugin_admin = new CWS_Google_Picasa_Pro_Admin( $plugin->get_plugin_name(), $plugin->get_version(), $plugin->get_isPro() ); 
  417.  
  418. // Only display shortcode snippets to Pro users... 
  419. if( $plugin->isPro == 1 ) { 
  420.  
  421. // Grab options stored in db 
  422. $options = get_option( 'cws_gpp_options' ); 
  423.  
  424. // set some defaults... 
  425. $options['results_page'] = isset($options['results_page']) ? $options['results_page'] : ""; 
  426. $options['hide_albums'] = isset($options['hide_albums']) ? $options['hide_albums'] : ""; 
  427. $options['theme'] = isset($options['theme']) ? $options['theme'] : ""; 
  428.  
  429. // Extract the options from db and overwrite with any set in the shortcode 
  430. // extract( shortcode_atts( array( 
  431. extract( array( 
  432. 'thumb_size' => $options['thumb_size'],  
  433. 'album_thumb_size' => $options['album_thumb_size'],  
  434. 'show_title' => $options['show_album_title'],  
  435. 'show_details' => $options['show_album_details'],  
  436. 'num_results' => $options['num_album_results'],  
  437. 'visibility' => $options['private_albums'],  
  438. 'results_page' => $options['results_page'],  
  439. 'hide_albums' => $options['hide_albums'],  
  440. 'theme' => $options['theme'],  
  441. 'imgmax' => $options['lightbox_image_size'],  
  442. ) ); 
  443. // ), $atts ) ); 
  444. // Map albums names to hide to array and trim white space 
  445. //$hide_albums = array_map( 'trim', explode( ', ', $hide_albums ) ); 
  446. /** 
  447. if( isset( $hide_albums ) ) { 
  448. $hide_albums[] = 'Auto Backup'; 
  449. else { 
  450. $hide_albums = 'Auto Backup'; 
  451. */ 
  452. // TODO: cast other vars to int if required 
  453. $thumb_size = (int) $thumb_size; 
  454.  
  455. if ( $show_title === 'false' ) $show_title = false; // just to be sure... 
  456. if ( $show_title === 'true' ) $show_title = true; // just to be sure... 
  457. if ( $show_title === '0' ) $show_title = false; // just to be sure... 
  458. if ( $show_title === '1' ) $show_title = true; // just to be sure... 
  459. $show_title = (bool) $show_title;  
  460.  
  461. if ( $show_details === 'false' ) $show_details = false; // just to be sure... 
  462. if ( $show_details === 'true' ) $show_details = true; // just to be sure... 
  463. if ( $show_details === '0' ) $show_details = false; // just to be sure... 
  464. if ( $show_details === '1' ) $show_details = true; // just to be sure... 
  465. $show_details = (bool) $show_details;  
  466.  
  467. // Grab page from url 
  468. $cws_page = $_GET[ 'cws_page' ]; // $cws_page = get_query_var( 'cws_page' ); 
  469.  
  470. // Grab the access token 
  471. $AccessToken = get_option( 'cws_gpp_access_token' ); 
  472.  
  473. // Get Albums 
  474. $response = $plugin_admin->getAlbumList( $AccessToken, $album_thumb_size, $show_title, 0, 0, $visibility );  
  475. // $response = $plugin_admin->getAlbumList( $AccessToken, $album_thumb_size, $show_title, 0, 0 );  
  476.  
  477. // var_dump($response); 
  478.  
  479. #---------------------------------------------------------------------------- 
  480. # Convert the XML response into SimpleXML Object 
  481. #---------------------------------------------------------------------------- 
  482. if (!function_exists('produce_XML_object_tree')) { 
  483.  
  484. function produce_XML_object_tree( $response ) { 
  485. libxml_use_internal_errors( true ); 
  486. try { 
  487. // Create simplexml object from feed 
  488. $xml = new SimpleXMLElement( $response ); 
  489. } catch ( Exception $e ) { 
  490. // Something went wrong. 
  491. $error_message = 'SimpleXMLElement threw an exception.'; 
  492. foreach( libxml_get_errors() as $error_line ) { 
  493. $error_message .= "\t" . $error_line->message; 
  494. trigger_error( $error_message ); 
  495. return false; 
  496. return $xml; 
  497. } // end function produce 
  498.  
  499.  
  500. // Create SimpleXML Object 
  501. $xml = produce_XML_object_tree ( $response ); 
  502.  
  503. if( $xml === false ) { 
  504. echo 'Sorry there has been a problem with your feed.'; 
  505. } else { 
  506.  
  507. // TODO: create a helper function 
  508. $cws_debug = $_GET[ 'cws_debug' ]; // $cws_debug = get_query_var( 'cws_debug' ); 
  509. if( $_GET["cws_debug"] == "1" ) {  
  510. echo "<pre>" . print_r( $xml, true ) . "</pre>"; 
  511.  
  512. $xml->registerXPathNamespace('gphoto', 'http://schemas.google.com/photos/2007'); 
  513. $xml->registerXPathNamespace('media', 'http://search.yahoo.com/mrss/'); 
  514.  
  515. // register namespace to get access to total number of albums found 
  516. $xml->registerXPathNamespace('opensearch', 'http://a9.com/-/spec/opensearch/1.1/'); 
  517. $totalResults = $xml->xpath( "opensearch:totalResults" ); 
  518. $total_num_albums = $totalResults[0];  
  519. ?> 
  520. <table class="wp-list-table widefat fixed posts"> 
  521. <thead> 
  522. <tr valign="top"> 
  523. <th scope="row" width="100">Album Name </th> 
  524. <!--<th scope="row" width="70">Published</th> 
  525. <th scope="row" width="50">Num Photos </th> --> 
  526. <th scope="row" width="100">Album ID </th> 
  527. <th scope="row">Example shortcode</th> 
  528. </tr> 
  529. </thead> 
  530. <?php 
  531. // loop over the albums 
  532. foreach( $xml->entry as $feed ) { 
  533.  
  534. // get the data we need 
  535. $title = $feed->title; 
  536.  
  537. $gphoto = $feed->children( 'http://schemas.google.com/photos/2007' ); 
  538. $num_photos = $gphoto->numphotos;  
  539. $published = $feed->published;  
  540. $published = trim( $published ); 
  541. $published = substr( $published, 0, 10 );  
  542.  
  543. $group = $feed->xpath( './media:group/media:thumbnail' ); 
  544. $a = $group[0]->attributes(); // we need thumbnail path 
  545. $id = $feed->xpath( './gphoto:id' ); // and album id for our thumbnail 
  546. ?> 
  547. <tbody data-wp-lists="list:post" id="the-list"> 
  548.  
  549. <tr> 
  550. <td class="title column-title"> 
  551. <strong><?php echo $title;?></strong> 
  552. </td> 
  553. <td class="shortcode column-deescription"><?php echo $id[0];?></td> 
  554. <td class="shortcode column-shortcode"> 
  555. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_images_by_albumid theme=grid id="<?php echo $id[0];?>"]" readonly="readonly" onfocus="this.select();">  
  556. </tr> 
  557.  
  558. </tbody> 
  559. <?php 
  560. } // end foreach 
  561. ?> 
  562. <foot> 
  563. <tr valign="top"> 
  564. <th scope="row">Album Name </th> 
  565. <!-- <th scope="row">Published</th> 
  566. <th scope="row">Num Photos </th> -->  
  567. <th scope="row">Album ID </th> 
  568. <th scope="row">Example shortcode </th> 
  569. </tr> 
  570. </foot>  
  571. </table>  
  572. <?php 
  573. } // end else 
  574. ?> 
  575. </div> <!-- / . postbox --> 
  576.  
  577. <h3>Shortcode Usage Examples</h3> 
  578.  
  579. <h4>Display Albums Covers in a Carousel</h4> 
  580. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_albums theme='carousel' results_page='page-slug-here' show_titles=1]" readonly="readonly" onfocus="this.select();">  
  581.  
  582. <h4>Display Album Covers in a Grid View</h4> 
  583. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_albums theme='grid' results_page='page-slug-here' show_details='1' num_results=5]" readonly="readonly" onfocus="this.select();">  
  584.  
  585. <h4>Display Album Covers in a List View</h4> 
  586. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_albums theme='list' results_page='page-slug-here' show_title='1' show_details='1' thumb_size='250' num_results='3' visibility='all']" readonly="readonly" onfocus="this.select();">  
  587.  
  588. <h4>Display Images from Clicked Album Cover in a Carousel View</h4> 
  589. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_images_in_album theme='carousel' show_title=0 thumbsize='150']" readonly="readonly" onfocus="this.select();">  
  590.  
  591. <h4>Display Images from Clicked Album Cover in a Grid View</h4> 
  592. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_images_in_album theme='grid' show_title=1 show_details='1']" readonly="readonly" onfocus="this.select();">  
  593.  
  594. <h4>Display Images from Clicked Album Cover in a List View</h4> 
  595. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_images_in_album theme='list' show_title=1 show_details=1 num_results='13' thumb_size='250']" readonly="readonly" onfocus="this.select();">  
  596. <!-- 
  597. <h4>Display Images from Clicked Album Cover in a Expander View, great for when there are long Captions.</h4> 
  598. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_images_in_album theme='expander' show_title=0]" readonly="readonly" onfocus="this.select();">  
  599. --> 
  600. <h4>Display Images in a Specific Album. Only one album per page.</h4> 
  601. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_images_by_albumid id='05218507736478682657' theme='grid' show_title='0' show_details='0']" readonly="readonly" onfocus="this.select();">  
  602.  
  603. <!-- <h4>Display Album Images in Photo Booth Strips</h4> 
  604. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_albums theme='propbs' show_details='1' num_results='4']" readonly="readonly" onfocus="this.select();">  
  605.  
  606. <h4>Display Album Covers in Polaroid Scatter Grid</h4> 
  607. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_albums theme='propsg' results_page='results-grid' show_details='1']" readonly="readonly" onfocus="this.select();">  
  608. <p>Theme options supported by the results page for this are 'grid', 'list', 'carousel' </p> --> 
  609. </div> <!-- / meta holder --> 
  610. </div> <!-- / .postbox-container --> 
  611. <?php } else { ?> 
  612. <?php // Display upgrade content if not Pro 
  613. echo $plugin_admin->cws_gpp_upgrade_content();  
  614.  
  615. }  
  616.  
  617. ?> 
  618.  
  619. </div><!-- / left --> 
  620. </div> 
  621. <?php 
  622. } // end function options_page_sc() 
  623.  
  624.  
  625. /** 
  626. * Draw the Options page for the admin area. 
  627. * @since 2.0.0 
  628. */ 
  629. public function options_page() { 
  630.  
  631. if( $this->deauthorizeGoogleAccount() ) { 
  632. // TODO: finsish this delete_option unset() 
  633. delete_option( 'cws_gpp_reset' ); 
  634. delete_option( 'cws_gpp_token_expires' ); 
  635. delete_option( 'cws_gpp_code' ); 
  636. delete_option( 'cws_gpp_access_token' ); 
  637. } ?> 
  638.  
  639. <div class="wrap"> 
  640. <?php screen_icon(); ?> 
  641. <h2>Google Picasa <?php echo $this->get_Pro( $this->isPro );?> Settings</h2> 
  642.  
  643. <div class="widget-liquid-left"> 
  644.  
  645. <form action="options.php" method="post"> 
  646.  
  647. <?php  
  648. // Step 1: The user has not authenticated we give them a link to login  
  649. if( $this->isAuthenticated() !== true ) { 
  650. // settings_fields( $option_group ) 
  651. // Output nonce, action, and option_page fields for a settings page. Please note that this function must be called inside of the form tag for the options page. 
  652. // $option_group - A settings group name. This should match the group name used in register_setting().  
  653. settings_fields( 'cws_gpp_code' ); 
  654.  
  655. // do_settings_sections( $page ); 
  656. // Prints out all settings sections added to a particular settings page. 
  657. // The slug name of the page whose settings sections you want to output. This should match the page name used in add_settings_section(). 
  658. do_settings_sections( 'cws_gpp' );  
  659. ?> 
  660. <input name="Submit" type="submit" value="Save Changes" />  
  661.  
  662. </form>  
  663. <?php 
  664. }  
  665. else { 
  666. /** 
  667. * User is authenticated so display plugin config settings 
  668. *  
  669. */ 
  670.  
  671. // Get Access Token 
  672. $token = $this->getAccessToken(); 
  673.  
  674. settings_fields( 'cws_gpp_options' ); 
  675. do_settings_sections( 'cws_gpp_defaults' ); 
  676. ?> 
  677. <input name="Submit" type="submit" value="Save Changes" />  
  678. </form>  
  679.  
  680. <form action="options.php" method="post"> 
  681.  
  682. <?php settings_fields( 'cws_gpp_reset' ); 
  683. do_settings_sections( 'cws_gpp_reset' );  
  684. ?> 
  685. <input name="Submit" type="submit" value="Deauthorise" onclick="if(!this.form.reset.checked) {alert('You must click the checkbox to confirm you want to deauthorize current Google account.');return false}" /> 
  686.  
  687. </form>  
  688. <?php  
  689. ?> 
  690.  
  691. </div><!-- / left --> 
  692. <?php // $this->cws_gpp_meta_box_feedback(); ?> 
  693.  
  694. <?php 
  695. if( !$this->isPro == 1 ) { 
  696. // Only call for the upgrade meta box if this is not a Pro install 
  697. $this->cws_gpp_meta_box_pro();  
  698. ?> 
  699.  
  700. </div> 
  701. <?php 
  702.  
  703.  
  704. // Display a feedback links 
  705. public function cws_gpp_meta_box_feedback() { 
  706. ?> 
  707.  
  708. <div class="widget-liquid-right"> 
  709. <div id="widgets-right">  
  710. <div style="width:20%;" class="postbox-container side"> 
  711. <div class="metabox-holder"> 
  712. <div class="postbox" id="feedback"> 
  713. <h3><span>Please rate the plugin!</span></h3> 
  714. <div class="inside">  
  715. <p>If you have found this useful please leave us a <a href="http://wordpress.org/extend/plugins/google-picasa-albums-viewer/">good rating</a></p> 
  716. <p>» Share it with your friends <a href="<?php echo "http://twitter.com/share?url=http://bit.ly/q4nqNA&text=Check out this awesome WordPress Plugin I'm using - Google Picasa Viewer" ?>">Tweet It</a></p> 
  717. <p>If you have found a bug please email me <a href="mailto:info@cheshirewebsolutions.com?subject=Feedback%20Google%20Picasa%20Viewer">info@cheshirewebsolutions.com</a></p>  
  718. </div> 
  719. </div> 
  720. </div> 
  721. </div>  
  722. </div> 
  723. </div>  
  724.  
  725. <?php 
  726.  
  727.  
  728.  
  729. // Display a Picasa Pro Promo Box 
  730. function cws_gpp_meta_box_pro() { 
  731. ?> 
  732. <div class="widget-liquid-right"> 
  733. <div id="widgets-right"> 
  734. <!-- <div style="width:20%;" class="postbox-container side"> --> 
  735. <div class="postbox-container side"> 
  736. <div class="metabox-holder"> 
  737. <div class="postbox" id="donate"> 
  738. <?php echo $this->cws_gpp_upgrade_content(); ?> 
  739. </div> 
  740. </div> 
  741. </div> 
  742. </div> 
  743. </div><?php  
  744.  
  745.  
  746. // seperate upgrade content from markup so can use content in more places, like shortcode snippets page and pro shortcodes in the frontend 
  747. function cws_gpp_upgrade_content() { 
  748.  
  749. $strOutput = "<h3><span>Get Google Picasa Pro!</span></h3> 
  750. <div class=\"inside\"> 
  751. <p>Grab yourself the <a href=\"http://www.cheshirewebsolutions.com/?utm_source=cws_gpp_config&utm_medium=text-link&utm_content=meta_box_pro&utm_campaign=cws_gpp_plugin\">Pro</a> version of the plugin.  
  752. <a href=\"http://www.cheshirewebsolutions.com/?utm_source=wp_gp_viewer&utm_medium=wp_plugin&utm_content=meta_box_download_it_here&utm_campaign=plugin_upgrade\">Download it here</a> <span><strong>GET 25% OFF!</strong> * use discount code <strong>WPMEGA25</strong> on checkout</span></p> 
  753. <h3> 
  754. Reasons to UPGRADE! 
  755. </h3> 
  756. <ol> 
  757. <li>Priority Email Support!</li> 
  758. <li>It*s much faster! We cache the Google Feed</li> 
  759. <li>Justified Image Grid Layout</li> 
  760. <li>Touch enabled lightbox, flick to the next or previous image, spread to zoom in etc</li> 
  761. <li>Native HTML5 full screen lightbox</li> 
  762. <li>Display image description as caption in lightbox</li> 
  763. <li>Social sharing</li> 
  764. <li>Customisable Lightbox Dimensions! have it as big as you like</li> 
  765. <li>Fantastic hover style effects</li> 
  766. <li>Display images in a specific album! just supply the album id</li> 
  767. <li>Helpful Shortcode Snippets Admin page!</li> 
  768. <li>Powered by link has been removed!</li> 
  769. <li>Included Download Original Image link</li> 
  770. </ol> 
  771.  
  772. </div>"; 
  773.  
  774. return $strOutput; 
  775.  
  776.  
  777. /** 
  778. * Register Settings, Settings Section and Settings Fileds. 
  779. *  
  780. * @link https://codex.wordpress.org/Function_Reference/register_setting 
  781. * @link https://codex.wordpress.org/Function_Reference/add_settings_section 
  782. * @link https://codex.wordpress.org/Function_Reference/add_settings_field 
  783. * @since 2.0.0 
  784. */  
  785. public function register_plugin_settings() { 
  786. // register_setting( $option_group, $option_name, $sanitize_callback ). 
  787. // $option_group - A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields(). 
  788. // $option_name - The name of an option to sanitize and save. 
  789. // $sanitize_callback - A callback function that sanitizes the option's value. 
  790. register_setting( 'cws_gpp_code', 'cws_gpp_code', array( $this, 'validate_options' ) ); 
  791. register_setting( 'cws_gpp_options', 'cws_gpp_options', array( $this, 'validate_main_options' ) ); 
  792.  
  793. register_setting( 'cws_gpp_reset', 'cws_gpp_reset', array( $this, 'validate_reset_options' ) ); 
  794.  
  795. // add_settings_section( $id, $title, $callback, $page ) 
  796. // $id - String for use in the 'id' attribute of tags 
  797. // $title - Title of the section 
  798. // $callback - Function that fills the section with the desired content. The function should echo its output. 
  799. // $page - The menu page on which to display this section. Should match $menu_slug in add_options_page(); 
  800. add_settings_section( 'cws_gpp_add_code', 'Authenticate with Google', array( $this, 'section_text' ), 'cws_gpp' ); 
  801. add_settings_section( 'cws_gpp_add_options', 'Default Settings', array( $this, 'section_main_text' ), 'cws_gpp_defaults' ); 
  802.  
  803. add_settings_section( 'cws_gpp_add_reset', 'Deauthorise Plugin from your Google Account', array( $this, 'section_reset_text' ), 'cws_gpp_reset' ); 
  804.  
  805. // add_settings_field( $id, $title, $callback, $page, $section, $args ); 
  806. // $id - String for use in the 'id' attribute of tags 
  807. // $title - Title of the field 
  808. // $callback - Function that fills the field with the desired inputs as part of the larger form. Passed a single argument,  
  809. // the $args array. Name and id of the input should match the $id given to this function. The function should echo its output. 
  810. // $page - The menu page on which to display this field. Should match $menu_slug in add_options_page(); 
  811. // $section - (optional) The section of the settings page in which to show the box. A section added with add_settings_section() [optional] 
  812. // $args - (optional) Additional arguments that are passed to the $callback function 
  813. add_settings_field( 'cws_myplugin_oauth2_code', 'Enter Google Access Code here', array( $this, 'setting_input' ), 'cws_gpp', 'cws_gpp_add_code' ); 
  814.  
  815.  
  816. // Add default option field - Thumbnail Size  
  817. add_settings_field( 'cws_gpp_thumbnail_size', 'Thumbnail Size (px)', array( $this, 'options_thumbnail_size' ), 'cws_gpp_defaults', 'cws_gpp_add_options' ); 
  818.  
  819. // Add default option field - Album Thumbnail Size  
  820. add_settings_field( 'cws_gpp_album_thumbnail_size', 'Album Thumbnail Size (px)', array( $this, 'options_album_thumbnail_size' ), 'cws_gpp_defaults', 'cws_gpp_add_options' ); 
  821.  
  822. if( $this->isPro ) { 
  823. // PRO ONLY 
  824. // Add default option field - Lighbox Image Size  
  825. add_settings_field( 'cws_gpp_lightbox_image_size', 'Lightbox Image Size (px)', array( $this, 'options_lightbox_image_size' ), 'cws_gpp_defaults', 'cws_gpp_add_options' );  
  826. // Add default option field - Number of image results 
  827. add_settings_field( 'cws_gpp_num_image_results', 'Number of images per page', array( $this, 'options_num_image_results' ), 'cws_gpp_defaults', 'cws_gpp_add_options' ); 
  828.  
  829. // Add default option field - Number of album results 
  830. add_settings_field( 'cws_gpp_num_album_results', 'Number of albums per page', array( $this, 'options_num_album_results' ), 'cws_gpp_defaults', 'cws_gpp_add_options' ); 
  831.  
  832. // Add default option checkbox - Show private albums checkbox 
  833. add_settings_field( 'cws_gpp_show_private_albums', 'Show which albums', array( $this, 'options_show_private_albums' ), 'cws_gpp_defaults', 'cws_gpp_add_options' );  
  834.  
  835. // Add default option checkbox - Show album title 
  836. add_settings_field( 'cws_gpp_show_album_title', 'Show Album Title', array( $this, 'options_show_album_title' ), 'cws_gpp_defaults', 'cws_gpp_add_options' );  
  837.  
  838. // Add default option checkbox - Show image title 
  839. add_settings_field( 'cws_gpp_show_image_title', 'Show Image Title', array( $this, 'options_show_image_title' ), 'cws_gpp_defaults', 'cws_gpp_add_options' );  
  840.  
  841. // Add default option checkbox - Show album details 
  842. add_settings_field( 'cws_gpp_show_album_details', 'Show Album Details', array( $this, 'options_show_album_details' ), 'cws_gpp_defaults', 'cws_gpp_add_options' );  
  843.  
  844. // Add default option checkbox - Show image details 
  845. add_settings_field( 'cws_gpp_show_image_details', 'Show Image Details', array( $this, 'options_show_image_details' ), 'cws_gpp_defaults', 'cws_gpp_add_options' );  
  846.  
  847. if( $this->isPro ) { 
  848. // PRO ONLY 
  849. // Add default option checkbox - Enable Cache 
  850. add_settings_field( 'cws_gpp_enable_cache', 'Enable Cache', array( $this, 'options_enable_cache' ), 'cws_gpp_defaults', 'cws_gpp_add_options' ); 
  851. // Add default option checkbox - Expose Original file 
  852. add_settings_field( 'cws_gpp_enable_download', 'Download Original Image Link', array( $this, 'options_enable_download' ), 'cws_gpp_defaults', 'cws_gpp_add_options' ); 
  853.  
  854. // Add reset option 
  855. add_settings_field( 'cws_gpp_reset', 'Click here to confirm you want to deauthorise plugin from your google account', array( $this, 'options_reset' ), 'cws_gpp_reset', 'cws_gpp_add_reset' );  
  856.  
  857.  
  858. /** 
  859. * Draw the Section Header for the admin area. 
  860. * @since 2.0.0 
  861. */ 
  862. function section_text() { 
  863. echo 'You need to click here to authorize access and paste the Access Code provided by Google in the field below.'; 
  864.  
  865. // get the google authorisation url 
  866. $authUrl = $this->client->createAuthUrl(); 
  867.  
  868. // display the google authorisation url 
  869. echo $this->createAuthLink( $authUrl ); 
  870.  
  871. $code = get_option( 'cws_gpp_code' ); 
  872. $oauth2_code = $code['oauth2_code']; 
  873.  
  874. $token = get_option( 'cws_gpp_access_token' ); 
  875. $token = $token['access_token']; 
  876.  
  877. if ( isset( $code['oauth2_code'] ) ) { 
  878.  
  879. $this->client->authenticate( $code['oauth2_code'] );  
  880. $AccessToken = $this->client->getAccessToken(); 
  881. $AccessToken = json_decode( $AccessToken, TRUE ); 
  882.  
  883. // delete code 
  884. $code = get_option( 'cws_gpp_code' ); 
  885.  
  886. if ( $code ) { 
  887. unset($code['oauth2_code']); 
  888. update_option( 'cws_gpp_code', $code ); 
  889.  
  890. // store access token 
  891. if( update_option( 'cws_gpp_access_token', $AccessToken ) ) 
  892. if( $this->debug ) error_log( 'Update option: cws_gpp_access_token' ); 
  893.  
  894. // store token expires 
  895. $now = date("U"); 
  896. $token_expires = $now + $AccessToken['expires_in']; 
  897. add_option( 'cws_gpp_token_expires', $token_expires );  
  898.  
  899. $url = admin_url( "options-general.php?page=".$_GET["page"] ); 
  900. // error_log($url); 
  901.  
  902. wp_redirect( "$url" ); 
  903. exit;  
  904. }  
  905.  
  906.  
  907. function section_main_text() { 
  908.  
  909.  
  910. // 
  911. function section_reset_text() { 
  912.  
  913. }  
  914.  
  915. function section() { 
  916.  
  917. }  
  918.  
  919.  
  920. /** 
  921. * Get the Access Token stored in db. 
  922. * @since 2.0.0 
  923. */  
  924. public function getAccessToken() { 
  925. $token = get_option( 'cws_gpp_access_token' ); 
  926.  
  927. return $token; 
  928.  
  929.  
  930. /** 
  931. * Get the authourisation link. 
  932. * @since 2.0.0 
  933. */  
  934. public function createAuthLink( $authUrl ) { 
  935.  
  936. if ( isset( $authUrl ) ) { 
  937.  
  938. $output = "<br><br><a class='login' href='$authUrl' target='_blank'>Connect My Google Account</a>";  
  939. } else { 
  940. $output = "There was a problem generating the Google Autherisation link"; 
  941.  
  942. return $output; 
  943.  
  944.  
  945. /** GOOD WORKFLOW OF STEPS https://www.domsammut.com/code/php-server-side-youtube-v3-oauth-api-video-upload-guide **/  
  946. /** 
  947. * Get the Reset option stored in db. 
  948. * @since 2.0.0 
  949. */  
  950. public function deauthorizeGoogleAccount() { 
  951. // get options from db 
  952.  
  953. if( get_option( 'cws_gpp_reset' ) ) { 
  954. return true; 
  955. }  
  956.  
  957. return false; 
  958.  
  959.  
  960. public function isAuthenticated() { 
  961.  
  962. // get options from db 
  963. $code = get_option( 'cws_gpp_code' ); 
  964. $token = get_option( 'cws_gpp_access_token' ); 
  965.  
  966. if ( !isset( $token['access_token'] ) ) { 
  967. // get oauth2 code 
  968. //$this->getOAuthToken(); 
  969. else{ 
  970. // check if it needs refreshing 
  971. $now = date("U"); 
  972.  
  973. // get cws_gpp_token_expires 
  974. $token_expires = get_option( 'cws_gpp_token_expires' ); 
  975.  
  976. // check if $now is greater than cws_gpp_token_expires 
  977. if ( $now > $token_expires ) { 
  978. $this->refreshToken();  
  979. return; 
  980. }  
  981.  
  982. return true; 
  983.  
  984. return false; 
  985.  
  986.  
  987. public function refreshToken() { 
  988.  
  989. if($this->debug) { error_log('Inside refreshToken()'); } 
  990.  
  991. $GOOGLE_OAUTH2_REFERER = ""; 
  992.  
  993. // get access token and refresh it  
  994. $now = date( "U" ); 
  995. $clientId = '806353319710-g782kn9ed0gm77ucl0meen5ohs84qgqm.apps.googleusercontent.com'; 
  996. $clientSecret = 'P6BMMEWLKUSoxB48X2Tzu8ds'; 
  997. $token = get_option( 'cws_gpp_access_token' ); 
  998. $refreshToken = $token['refresh_token']; 
  999.  
  1000. $postBody = 'client_id='.urlencode($clientId) 
  1001. .'&client_secret='.urlencode($clientSecret) 
  1002. .'&refresh_token='.urlencode($refreshToken) 
  1003. .'&grant_type=refresh_token'; 
  1004.  
  1005. $curl = curl_init(); 
  1006. curl_setopt_array( $curl,  
  1007. array( CURLOPT_CUSTOMREQUEST => 'POST' 
  1008. , CURLOPT_URL => 'https://www.googleapis.com/oauth2/v3/token' 
  1009. , CURLOPT_HTTPHEADER => array( 'Content-Type: application/x-www-form-urlencoded' 
  1010. , 'Content-Length: '.strlen($postBody) 
  1011. , CURLOPT_POSTFIELDS => $postBody  
  1012. , CURLOPT_REFERER => $GOOGLE_OAUTH2_REFERER 
  1013. , CURLOPT_RETURNTRANSFER => 1 // means output will be a return value from curl_exec() instead of simply echoed 
  1014. , CURLOPT_TIMEOUT => 12 // max seconds to wait 
  1015. , CURLOPT_FOLLOWLOCATION => 0 // don't follow any Location headers, use only the CURLOPT_URL, this is for security 
  1016. , CURLOPT_FAILONERROR => 0 // do not fail verbosely fi the http_code is an error, this is for security 
  1017. , CURLOPT_SSL_VERIFYPEER => 0 // do verify the SSL of CURLOPT_URL, this is for security 
  1018. , CURLOPT_VERBOSE => 0 // don't output verbosely to stderr, this is for security 
  1019. ) ); 
  1020.  
  1021. $orig_response = curl_exec( $curl ); 
  1022. $response = json_decode( $orig_response, true ); // convert returned objects into associative arrays 
  1023. $token_expires = $now + $response['expires_in']; 
  1024. $http_code = curl_getinfo( $curl, CURLINFO_HTTP_CODE ); 
  1025. curl_close( $curl ); 
  1026.  
  1027. if ( $response['access_token'] ) {  
  1028. // get options update access token part 
  1029. $token = get_option( 'cws_gpp_access_token' ); 
  1030. $token['access_token'] = $response['access_token']; 
  1031.  
  1032. update_option("cws_gpp_access_token", $token); # save the access token 
  1033. update_option("cws_gpp_token_expires", $token_expires); # save the epoch when the token expires 
  1034.  
  1035. if( $this->debug ) { error_log( 'Refresh Access Token...' ); } 
  1036.  
  1037. $url = $this->getUrl(); 
  1038. wp_redirect( "$url" ); 
  1039. exit;  
  1040.  
  1041. } else { 
  1042. // echo "refreshOAuth2Token got the following response:<br />"; 
  1043. // echo $orig_response; 
  1044. // echo "using refreshToken $refreshToken"; 
  1045. }  
  1046. // TODO: Improve error handling here for various curl error codes etc  
  1047.  
  1048.  
  1049. /** 
  1050. * Get current url. 
  1051. * @since 2.3.0 
  1052. */  
  1053. function getUrl() { 
  1054. $url = ( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"]; 
  1055. $url .= ( $_SERVER["SERVER_PORT"] != 80 ) ? ":".$_SERVER["SERVER_PORT"] : ""; 
  1056. $url .= $_SERVER["REQUEST_URI"]; 
  1057. return $url; 
  1058.  
  1059.  
  1060. /** 
  1061. * Get list of Albums for authenticated user. 
  1062. * @since 2.0.0 
  1063. */  
  1064. public function getAlbumList( $AccessToken, $album_thumb_size, $show_title, $cws_page, $num_image_results, $visibility) {  
  1065.  
  1066. if( $this->debug ) { error_log( 'Inside getAlbumList()' ); } 
  1067.  
  1068. // Work out pagination variables 
  1069. if ( !( isset( $cws_page ) ) ) { 
  1070. $cws_page = 1; 
  1071. if ( $cws_page > 1 ) { 
  1072. $start_index = ( ( $cws_page - 1 ) * $num_image_results ) + 1; 
  1073. } else { 
  1074. $start_index = 1; 
  1075. }  
  1076.  
  1077. $visibility = strtolower( $visibility ); 
  1078.  
  1079. // https://developers.google.com/accounts/docs/OAuth2WebServer#callinganapi 
  1080. $curl = curl_init(); 
  1081. // https://developers.google.com/picasa-web/docs/2.0/reference#Visibility 
  1082. // http://picasaweb.google.com/data/feed/api/user/userID?kind=photo&q=penguin 
  1083.  
  1084. // limit results or not 
  1085. if( $num_image_results > 0 ) { 
  1086. $url = "https://picasaweb.google.com/data/feed/api/user/default?kind=album&thumbsize=" . $album_thumb_size . "c&max-results=" . $num_image_results . "&start-index=" . $start_index . "&access=" . $visibility; 
  1087. //$url = "https://picasaweb.google.com/data/feed/api/user/default?kind=album&thumbsize=" . $album_thumb_size . "c&max-results=" . $num_image_results . "&start-index=" . $start_index ;  
  1088. //$url = "https://picasaweb.google.com/data/feed/api/user/default?kind=album&thumbsize=" . $album_thumb_size . "c&max-results=" . $num_image_results . "&start-index=" . $start_index . "&access=all";  
  1089. } else { 
  1090. $url = "https://picasaweb.google.com/data/feed/api/user/default?kind=album&thumbsize=" . $album_thumb_size . "c&access=" . $visibility; 
  1091. // $url = "https://picasaweb.google.com/data/feed/api/user/default?kind=album&thumbsize=" . $album_thumb_size . "c"; 
  1092. //$url = "https://picasaweb.google.com/data/feed/api/user/default?kind=album&thumbsize=" . $album_thumb_size . "c&access=visible"; 
  1093.  
  1094. // TODO: create a helper function 
  1095. $cws_debug = $_GET[ 'cws_debug' ];// $cws_debug = get_query_var( 'cws_debug' ); 
  1096.  
  1097. if( $cws_debug == "1" ) {  
  1098. echo "url = $url<br>";  
  1099. echo "show_title = $show_title<br>"; 
  1100.  
  1101. curl_setopt_array( $curl,  
  1102. array( CURLOPT_CUSTOMREQUEST => 'GET' 
  1103. , CURLOPT_URL => $url 
  1104. , CURLOPT_HTTPHEADER => array( 'GData-Version: 2' 
  1105. , 'Authorization: Bearer '.$AccessToken['access_token'] ) 
  1106. , CURLOPT_REFERER => 'http://wp-picasa-pro.wordpress.dev/wp-admin/options-general.php?page=cws_gpp' 
  1107. , CURLOPT_RETURNTRANSFER => 1 // means output will be a return value from curl_exec() instead of simply echoed 
  1108. ) ); 
  1109. $response = curl_exec($curl); 
  1110. $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
  1111. curl_close($curl); 
  1112.  
  1113. // Return $response to shortcode if http_code is 200 
  1114. if( $http_code == 200 ) { return $response; } 
  1115. // TODO: Add in some error handling better reporting of http code 
  1116. return false; 
  1117.  
  1118.  
  1119. /** 
  1120. * Get list of Images in a specific Album for authenticated user. 
  1121. * @since 2.0.0 
  1122. */ 
  1123. // public function getAlbumImages( $AccessToken, $album_thumb_size, $show_album_ttl, $cws_page, $num_image_results, $cws_album, $imgmax='450' ) { 
  1124. public function getAlbumImages( $AccessToken, $album_thumb_size, $show_album_ttl, $cws_page, $num_image_results, $cws_album, $imgmax='450', $theme ) { 
  1125.  
  1126. // Crop the image or not, projig wants not cropped... 
  1127. if ( $theme != 'projig' ) { $crop = 'c'; } else { $crop = ''; } 
  1128.  
  1129. if( $imgmax == 0 || $imgmax == 0 ) { $imgmax = 450; } 
  1130.  
  1131. if( $this->debug ) { error_log( 'Inside getAlbumImages()' ); } 
  1132.  
  1133. // Work out pagination variables 
  1134. if ( !( isset( $cws_page ) ) ) { 
  1135. $cws_page = 1; 
  1136. if ( $cws_page > 1 ) { 
  1137. $start_index = ( ( $cws_page - 1 ) * $num_image_results ) + 1; 
  1138. } else { 
  1139. $start_index = 1; 
  1140. }  
  1141.  
  1142. $curl = curl_init(); 
  1143.  
  1144. if( $num_image_results > 0 ) { 
  1145. // $url = "https://picasaweb.google.com/data/feed/api/user/default/albumid/" . $cws_album . "?thumbsize=" . $album_thumb_size . "c&max-results=" . $num_image_results . "&start-index=" . $start_index . "&imgmax=" . $imgmax;  
  1146. $url = "https://picasaweb.google.com/data/feed/api/user/default/albumid/" . $cws_album . "?thumbsize=" . $album_thumb_size . $crop . "&max-results=" . $num_image_results . "&start-index=" . $start_index . "&imgmax=" . $imgmax;  
  1147. } else { 
  1148. // $url = "https://picasaweb.google.com/data/feed/api/user/default/albumid/" . $cws_album . "?thumbsize=" . $album_thumb_size . "c&imgmax=" . $imgmax; 
  1149. $url = "https://picasaweb.google.com/data/feed/api/user/default/albumid/" . $cws_album . "?thumbsize=" . $album_thumb_size . $crop . "&imgmax=" . $imgmax;  
  1150. // TODO: create a helper function 
  1151. $cws_debug = $_GET[ 'cws_debug' ]; // $cws_debug = get_query_var( 'cws_debug' ); 
  1152.  
  1153. //, CURLOPT_REFERER => 'http://wp-picasa-pro.wordpress.dev/wp-admin/options-general.php?page=cws_gpp' 
  1154.  
  1155. curl_setopt_array( $curl,  
  1156. array( CURLOPT_CUSTOMREQUEST => 'GET' 
  1157. , CURLOPT_URL => $url 
  1158. , CURLOPT_HTTPHEADER => array( 'GData-Version: 2' 
  1159. , 'Authorization: Bearer '.$AccessToken['access_token'] ) 
  1160. , CURLOPT_RETURNTRANSFER => 1 // means output will be a return value from curl_exec() instead of simply echoed 
  1161. ) ); 
  1162. $response = curl_exec( $curl ); 
  1163. $http_code = curl_getinfo( $curl, CURLINFO_HTTP_CODE ); 
  1164. curl_close( $curl ); 
  1165.  
  1166. if( $cws_debug == "1" ) {  
  1167. echo "url = $url"; 
  1168. echo "http code: $http_code<br>"; 
  1169. echo '<pre>'; 
  1170. print_r($response); 
  1171. echo '</pre>';  
  1172. var_dump($imgmax); 
  1173.  
  1174. // Return $response to shortcode if http_code is 200 
  1175. if( $http_code == 200 ) { return $response; } 
  1176.  
  1177.  
  1178. /** 
  1179. * Pagination Helper 
  1180. * $num_pages, int 
  1181. * $current_page, int 
  1182. * $album_id 
  1183. * return string 
  1184. */  
  1185. public function get_pagination( $total_num_albums, $num_image_results, $cws_page, $album_id=NULL ) { 
  1186.  
  1187. // global $post; 
  1188.  
  1189. // echo $post->post_name; 
  1190.  
  1191. if( $this->debug ) error_log( 'Inside: CWS_Google_Picasa_Pro_Admin::get_pagination()' );  
  1192.  
  1193. // Calcualte how many pages we need, total number of albums / number of images to display per page as set in settings of shortcode 
  1194. if( $num_image_results > 0 ) { 
  1195. $num_pages = ceil( $total_num_albums / $num_image_results ); 
  1196.  
  1197. // If ony need one page then do not display pagination 
  1198. if ( $num_pages <= 1 ) { 
  1199. return; 
  1200.  
  1201.  
  1202. if( ! isset( $cws_page ) || $cws_page < 1 ) { $cws_page = 1; } // TODO: Do we need this check? 
  1203.  
  1204. // Create page links 
  1205. $html[] = "<div class=\"cws-pagination\"><ul class=\"page-nav\">\n"; 
  1206.  
  1207. $previous = $cws_page - 1; 
  1208. $next = $cws_page + 1; 
  1209.  
  1210. // Previous link 
  1211. if( $previous > 0 ) { 
  1212.  
  1213. // if have album id, i.e. display this on the results page 
  1214. if( $album_id ) { 
  1215. $html[] = "<li><a href=\"?cws_page=$previous&cws_album=$album_id\" id='prev_page'>Previous</a></li>"; 
  1216. } else { 
  1217. $html[] = "<li><a href=\"?cws_page=$previous\" id='prev_page'>Previous</a></li>";  
  1218.  
  1219. for( $i=1; $i <= $num_pages; $i++ ) { 
  1220.  
  1221. $class = ""; 
  1222.  
  1223. // Add class to current page 
  1224. if( $i == $cws_page) { 
  1225. $class = " class='selected'"; 
  1226.  
  1227. $html[] = "<li".$class.">"; 
  1228.  
  1229. if( $album_id ) { 
  1230. $html[] = "<a href=\"?cws_page=$i&cws_album=$album_id\" id='page_".$i."'>".$i."</a></li>\n"; 
  1231. } else { 
  1232. $html[] = "<a href=\"?cws_page=$i\" id='page_".$i."'>".$i."</a></li>\n"; 
  1233.  
  1234. // Next link 
  1235. if( $next <= $num_pages ) { 
  1236.  
  1237. // if have album id 
  1238. if( $album_id ) { 
  1239. $html[] = "<li><a href=\"?cws_page=$next&cws_album=$album_id\" id='next_page'>Next</a></li>"; 
  1240. } else { 
  1241. $html[] = "<li><a href=\"?cws_page=$next\" id='next_page'>Next</a></li>"; 
  1242.  
  1243. // Display Powered by link if not Pro 
  1244. if( !$this->isPro == 1 ) { 
  1245. // $html[] = "</ul><span>Powered by: <a href=\"http://www.cheshirewebsolutions.com/\">Cheshire Web Solutions</a></span></div>\n"; 
  1246. $html[] = "</ul><span>Powered by: <a href=\"http://www.cheshirewebsolutions.com/\">Google Photos for WordPress Plugin</a></span></div>\n";  
  1247. } else { 
  1248. $html[] = "</ul></div>\n"; 
  1249. return implode( "\n", $html ); 
  1250. return; 
  1251.  
  1252.  
  1253. /** 
  1254. * Display and fill the form field. 
  1255. * @since 2.0.0 
  1256. */  
  1257. function setting_input() { 
  1258.  
  1259. // get option 'oauth2_code' value from the database 
  1260. $code = get_option( 'cws_gpp_code' ); 
  1261. $oauth2_code = $code['oauth2_code']; 
  1262. // echo the field 
  1263. echo "<input id='oauth2_code' name='cws_gpp_code[oauth2_code]' type='text' value='$oauth2_code' >"; 
  1264.  
  1265.  
  1266. /** 
  1267. * Display and fill the form fields for storing defaults. 
  1268. * Thumbnail Size in pixels 
  1269. * @since 2.0.0 
  1270. */  
  1271. function options_thumbnail_size() { 
  1272.  
  1273. // get option 'thumb_size' value from the database 
  1274. $options = get_option( 'cws_gpp_options' ); 
  1275. $thumb_size = $options['thumb_size']; 
  1276.  
  1277. echo "<input id='thumb_size' name='cws_gpp_options[thumb_size]' type='text' value='$thumb_size' >"; 
  1278. }  
  1279.  
  1280.  
  1281. /** 
  1282. * Display and fill the form fields for storing defaults. 
  1283. * Album Thumbnail Size in pixels 
  1284. * @since 2.0.0 
  1285. */  
  1286. function options_album_thumbnail_size() { 
  1287.  
  1288. // get option 'album_thumb_size' value from the database 
  1289. $options = get_option( 'cws_gpp_options' ); 
  1290. $album_thumb_size = $options['album_thumb_size']; 
  1291.  
  1292. echo "<input id='album_thumb_size' name='cws_gpp_options[album_thumb_size]' type='text' value='$album_thumb_size' >"; 
  1293. }  
  1294.  
  1295.  
  1296. /** 
  1297. * Display and fill the form fields for storing defaults. 
  1298. * Lightbox Image Size in pixels 
  1299. * @since 2.3.0 
  1300. */  
  1301. function options_lightbox_image_size() { 
  1302.  
  1303. // get option 'lightbox_image_size' value from the database 
  1304. $options = get_option( 'cws_gpp_options' ); 
  1305. $lightbox_image_size = $options['lightbox_image_size']; 
  1306.  
  1307. echo "<input id='lightbox_image_size' name='cws_gpp_options[lightbox_image_size]' type='text' value='$lightbox_image_size' >"; 
  1308. }  
  1309.  
  1310.  
  1311. /** 
  1312. * Enable Cache 
  1313. * caches feed and stores for 1 hour 
  1314. * Pro Only 
  1315. * @since 2.3.0 
  1316. */  
  1317. function options_enable_cache() { 
  1318.  
  1319. // set some defaults... 
  1320. $checked = ''; 
  1321.  
  1322. // get option 'enable_cache' value from the database 
  1323. $options = get_option( 'cws_gpp_options' ); 
  1324. $enable_cache = $options['enable_cache']; 
  1325.  
  1326. if($options['enable_cache']) { $checked = ' checked="checked" '; } 
  1327. echo "<input ".$checked." id='enable_cache' name='cws_gpp_options[enable_cache]' type='checkbox' /><small>Only check this once you are happy with other settings.</small>"; 
  1328. }  
  1329.  
  1330.  
  1331. /** 
  1332. * Enable Download 
  1333. * Exposes download link next to each thumbnail to allow user to access original image file 
  1334. * Pro Only 
  1335. * @since 2.3.1 
  1336. */  
  1337. function options_enable_download() { 
  1338.  
  1339. // set some defaults... 
  1340. $checked = ''; 
  1341.  
  1342. // get option 'enable_download' value from the database 
  1343. $options = get_option( 'cws_gpp_options' ); 
  1344.  
  1345. $options['enable_download'] = isset($options['enable_download']) ? $options['enable_download'] : ""; 
  1346.  
  1347. $enable_cache = $options['enable_download']; 
  1348.  
  1349. if($options['enable_download']) { $checked = ' checked="checked" '; } 
  1350. echo "<input ".$checked." id='enable_download' name='cws_gpp_options[enable_download]' type='checkbox' /><small>Allow user to download original image file.</small>"; 
  1351. }  
  1352.  
  1353. /** 
  1354. * Display and fill the form fields for storing defaults. 
  1355. * Number of images results to display per page 
  1356. * @since 2.0.0 
  1357. */  
  1358. function options_num_image_results() { 
  1359.  
  1360. // get option 'num_image_results' value from the database 
  1361. $options = get_option( 'cws_gpp_options' ); 
  1362. $num_image_results = $options['num_image_results']; 
  1363.  
  1364. echo "<input id='num_image_results' name='cws_gpp_options[num_image_results]' type='text' value='$num_image_results' >"; 
  1365. }  
  1366.  
  1367.  
  1368. /** 
  1369. * Display and fill the form fields for storing defaults. 
  1370. * Number of albums results to display per page 
  1371. * @since 2.0.0 
  1372. */  
  1373. function options_num_album_results() { 
  1374.  
  1375. // get option 'num_album_results' value from the database 
  1376. $options = get_option( 'cws_gpp_options' ); 
  1377. $num_album_results = $options['num_album_results']; 
  1378.  
  1379. echo "<input id='num_album_results' name='cws_gpp_options[num_album_results]' type='text' value='$num_album_results' >"; 
  1380. }  
  1381.  
  1382.  
  1383. /** 
  1384. * Display and fill the form fields for storing defaults. 
  1385. * Show Private Albums 
  1386. * @since 2.0.0 
  1387. */ 
  1388.  
  1389. function options_show_private_albums() { 
  1390. $options = get_option('cws_gpp_options');  
  1391. $options['private_albums'] = isset($options['private_albums']) ? $options['private_albums'] : ""; 
  1392.  
  1393. // DROP-DOWN-BOX - Name: plugin_options[dropdown1] 
  1394. $items = array("All", "Private", "Public", "Visible"); 
  1395. echo "<select id='cws_gpp_show_private_albums' name='cws_gpp_options[private_albums]'>"; 
  1396. foreach($items as $item) { 
  1397. $selected = ($options['private_albums']==$item) ? 'selected="selected"' : ''; 
  1398. echo "<option value='$item' $selected>$item</option>"; 
  1399. echo "</select>"; 
  1400.  
  1401.  
  1402. /** 
  1403. * Display and fill the form fields for storing defaults. 
  1404. * Show Album Title 
  1405. * @since 2.0.0 
  1406. */  
  1407. function options_show_album_title() { 
  1408.  
  1409. // set some defaults... 
  1410. $checked = ''; 
  1411.  
  1412. // get option 'show_album_title' value from the database 
  1413. $options = get_option( 'cws_gpp_options' ); 
  1414. $show_album_title = $options['show_album_title']; 
  1415.  
  1416. if($options['show_album_title']) { $checked = ' checked="checked" '; } 
  1417. echo "<input ".$checked." id='show_album_title' name='cws_gpp_options[show_album_title]' type='checkbox' />"; 
  1418. }  
  1419.  
  1420.  
  1421. /** 
  1422. * Display and fill the form fields for storing defaults. 
  1423. * Show Image Title 
  1424. * @since 2.0.0 
  1425. */  
  1426. function options_show_image_title() { 
  1427.  
  1428. // set some defaults... 
  1429. $checked = ''; 
  1430.  
  1431. // get option 'show_image_title' value from the database 
  1432. $options = get_option( 'cws_gpp_options' ); 
  1433. $show_album_title = $options['show_image_title']; 
  1434.  
  1435. if($options['show_image_title']) { $checked = ' checked="checked" '; } 
  1436. echo "<input ".$checked." id='show_image_title' name='cws_gpp_options[show_image_title]' type='checkbox' />"; 
  1437. }  
  1438.  
  1439.  
  1440. /** 
  1441. * Display and fill the form fields for storing defaults. 
  1442. * Show Album Details 
  1443. * @since 2.0.0 
  1444. */  
  1445.  
  1446. function options_show_album_details() { 
  1447.  
  1448. // set some defaults... 
  1449. $checked = ''; 
  1450.  
  1451. // get option 'show_album_details' value from the database 
  1452. $options = get_option( 'cws_gpp_options' ); 
  1453. $show_album_details = $options['show_album_details']; 
  1454.  
  1455. if($options['show_album_details']) { $checked = ' checked="checked" '; } 
  1456. echo "<input ".$checked." id='show_album_details' name='cws_gpp_options[show_album_details]' type='checkbox' />"; 
  1457. }  
  1458.  
  1459.  
  1460. /** 
  1461. * Display and fill the form fields for storing defaults. 
  1462. * Show Image Details 
  1463. * @since 2.0.0 
  1464. */  
  1465. function options_show_image_details() { 
  1466.  
  1467. // set some defaults... 
  1468. $checked = ''; 
  1469.  
  1470. // get option 'show_album_details' value from the database 
  1471. $options = get_option( 'cws_gpp_options' ); 
  1472. $options['show_image_details'] = isset($options['show_image_details']) ? $options['show_image_details'] : ""; 
  1473. $show_image_details = $options['show_image_details']; 
  1474.  
  1475. if($options['show_image_details']) { $checked = ' checked="checked" '; } 
  1476. echo "<input ".$checked." id='show_image_details' name='cws_gpp_options[show_image_details]' type='checkbox' />"; 
  1477. }  
  1478.  
  1479.  
  1480. /** 
  1481. * Display and fill the form fields for storing defaults. 
  1482. * Show Album Details 
  1483. * @since 2.0.0 
  1484. */  
  1485. function options_reset() { 
  1486.  
  1487. // set some defaults... 
  1488. $checked = ''; 
  1489.  
  1490. // get option 'show_album_details' value from the database 
  1491. $options = get_option( 'cws_gpp_reset' );  
  1492.  
  1493. if($options['cws_gpp_reset']) { $checked = ' checked="checked" '; } 
  1494. echo "<input ".$checked." id='reset' name='cws_gpp_reset[reset]' type='checkbox' required />"; 
  1495. }  
  1496.  
  1497.  
  1498. /** 
  1499. * Validate user input (we want text only). 
  1500. * @since 2.0.0 
  1501. */  
  1502. function validate_options( $input ) { 
  1503.  
  1504. $valid['oauth2_code'] = esc_attr ( $input['oauth2_code'] ); 
  1505.  
  1506. return $valid; 
  1507.  
  1508.  
  1509. /** 
  1510. * Validate user input. 
  1511. * @since 2.0.0 
  1512. */  
  1513. function validate_main_options( $input ) { 
  1514.  
  1515. $valid['thumb_size'] = esc_attr( $input['thumb_size'] ); 
  1516. $valid['album_thumb_size'] = esc_attr( $input['album_thumb_size'] ); 
  1517. $valid['num_image_results'] = esc_attr( $input['num_image_results'] ); 
  1518. $valid['num_album_results'] = esc_attr( $input['num_album_results'] ); 
  1519. $valid['lightbox_image_size'] = esc_attr( $input['lightbox_image_size'] ); 
  1520. $valid['private_albums'] = esc_attr( $input['private_albums'] ); 
  1521.  
  1522. // Correct validation of checkboxes 
  1523. $valid['show_album_title'] = ( isset( $input['show_album_title'] ) && true == $input['show_album_title'] ? true : false ); 
  1524. $valid['show_album_details'] = ( isset( $input['show_album_details'] ) && true == $input['show_album_details'] ? true : false ); 
  1525.  
  1526. $valid['show_image_title'] = ( isset( $input['show_image_title'] ) && true == $input['show_image_title'] ? true : false ); 
  1527. $valid['enable_cache'] = ( isset( $input['enable_cache'] ) && true == $input['enable_cache'] ? true : false ); 
  1528. $valid['show_image_details'] = ( isset( $input['show_image_details'] ) && true == $input['show_image_details'] ? true : false ); 
  1529. $valid['enable_download'] = ( isset( $input['enable_download'] ) && true == $input['enable_download'] ? true : false ); 
  1530.  
  1531. return $valid; 
  1532. }  
  1533.  
  1534.  
  1535. /** 
  1536. * Validate user input. 
  1537. * @since 2.0.0 
  1538. */  
  1539. function validate_reset_options( $input ) { 
  1540.  
  1541. // Correct validation of checkboxes 
  1542. $valid['reset'] = ( isset( $input['reset'] ) && true == $input['reset'] ? true : false ); 
  1543.  
  1544. return $valid; 
  1545. }  
  1546.  
  1547.  
  1548. // Dispay upgrade notice 
  1549. function cws_gpp_admin_installed_notice( $userObj ) { 
  1550.  
  1551. // var_dump($userObj->ID); 
  1552.  
  1553. // check if already Pro 
  1554. if( !$this->isPro ) { 
  1555.  
  1556. // Check if user has dismissed notice previously 
  1557. // if ( ! get_user_meta( $current_user->getID(), 'cws_gpp_ignore_upgrade' ) )  
  1558. if ( ! get_user_meta( $userObj->ID, 'cws_gpp_ignore_upgrade' ) ) { 
  1559. global $pagenow; 
  1560. // Only show upgrade notice if on this page 
  1561. if ( $pagenow == 'options-general.php' || $pagenow == 'admin.php' ) { 
  1562. ?> 
  1563. <div id="message" class="updated cws-gpp-message"> 
  1564. <div class="squeezer"> 
  1565. <h4><?php _e( '<strong>Google Photos Viewer has been installed – Get the Pro version</strong>', 'cws_gpp_' ); ?></h4> 
  1566. <h4><?php _e( '<strong>GET 25% OFF! – use discount code WPMEGA25 on checkout</strong>', 'cws_gpp_' ); ?></h4> 
  1567. <p class="submit"> 
  1568. <a href="http://www.cheshirewebsolutions.com/?utm_source=cws_gpp_config&utm_medium=button&utm_content=upgrade_notice_message&utm_campaign=cws_gpp_plugin" class="button-primary"><?php _e( 'Visit Site', 'cws_gpp_' ); ?></a> 
  1569. <a href="<?php echo admin_url('admin.php?page=cws_gpp'); ?>" class="button-primary"><?php _e( 'Settings', 'cws_gpp_' ); ?></a> 
  1570. <a href="?cws_gpp_ignore_upgrade=0" class="secondary-button">Hide Notice</a> 
  1571. </p> 
  1572. </div> 
  1573. </div> 
  1574. <?php 
  1575. }  
  1576. } // end check if already dismissed 
  1577.  
  1578. } // end isPro check 
  1579.  
  1580. // Set installed option 
  1581. //update_option( 'cws_gpp_installed', 0); 
  1582.  
  1583.  
  1584. // If installed display upgrade notice 
  1585. function cws_gpp_admin_notices_styles() { 
  1586.  
  1587. // Installed notices 
  1588. if ( get_option( 'cws_gpp_installed' ) == 1 ) { 
  1589. // error_log("****** ADDING ACTION ADMIN NOTICES ********"); 
  1590. //add_action( 'admin_notices', 'cws_gpp_admin_installed_notice' );  
  1591. add_action( 'admin_notices', $this->cws_gpp_admin_installed_notice() );  
  1592.  
  1593. // Allow user to dismiss upgrade notice :) 
  1594. function cws_gpp_ignore_upgrade( $userObj2 ) {  
  1595.  
  1596. /** If user clicks to ignore the notice, add that to their user meta */ 
  1597. if ( isset( $_GET['cws_gpp_ignore_upgrade'] ) && '0' == $_GET['cws_gpp_ignore_upgrade'] ) { 
  1598. // add_user_meta($current_user->ID, 'cws_gpp_ignore_upgrade', 'true', true); 
  1599. add_user_meta($userObj2->ID, 'cws_gpp_ignore_upgrade', 'true', true); 
  1600.  
  1601. // Redirect to plugin settings page 
  1602. wp_redirect( admin_url( 'admin.php?page=cws_gpp' ) ); 
  1603. }  
  1604.  
  1605. // 
  1606.   
  1. class CWS_Google_Picasa_Pro_Admin { 
  2.  
  3. var $debug = false; 
  4.  
  5. /** 
  6. * The ID of this plugin. 
  7. * @since 2.0.0 
  8. * @access private 
  9. * @var string $plugin_name The ID of this plugin. 
  10. */ 
  11. private $plugin_name; 
  12.  
  13. /** 
  14. * The version of this plugin. 
  15. * @since 2.0.0 
  16. * @access private 
  17. * @var string $version The current version of this plugin. 
  18. */ 
  19. private $version; 
  20.  
  21. /** 
  22. * The is user authenticated with Google. 
  23. * @since 2.0.0 
  24. * @access private 
  25. * @var int $authenticated Check is user authenticated with Google. 
  26. */  
  27. private $authenticated = 0; 
  28.  
  29. /** 
  30. * The check is this a Pro version. 
  31. * @since 2.0.0 
  32. * @access private 
  33. * @var int $isPro Check is if this is pro version. 
  34. */  
  35. private $isPro ;  
  36.  
  37. /** 
  38. * User Id used to check ignore upgrade notice. 
  39. * @since 2.1.1 
  40. * @access private 
  41. * @var int $userId User Id of loggedin user. 
  42. */  
  43. private $userId; 
  44.  
  45. var $client; // Used for Google Client 
  46.  
  47. /** 
  48. * Initialize the class and set its properties. 
  49. * @since 2.0.0 
  50. * @param string $plugin_name The name of this plugin. 
  51. * @param string $version The version of this plugin. 
  52. */ 
  53. public function __construct( $plugin_name, $version, $isPro ) { 
  54.  
  55. $this->plugin_name = $plugin_name; 
  56. $this->version = $version; 
  57. $this->isPro = $isPro; 
  58. $this->client = new Google_Client(); 
  59. $this->client->setApplicationName("Client_Library_Examples"); 
  60. $this->client->setDeveloperKey("AIzaSyCP9XMYoQdxXfI-gK1bvZDW2RxyfvYENuM");  
  61. $this->client->setClientId('806353319710-g782kn9ed0gm77ucl0meen5ohs84qgqm.apps.googleusercontent.com'); 
  62. $this->client->setClientSecret('P6BMMEWLKUSoxB48X2Tzu8ds'); 
  63. $this->client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob'); 
  64. $this->client->setScopes('https://picasaweb.google.com/data/'); 
  65. $this->client->setAccessType('offline'); 
  66.  
  67. // Include required files 
  68. $this->includes(); 
  69.  
  70. //$this->cws_gpp_admin_installed_notice(); 
  71. //$this->cws_gpp_admin_notices_styles(); 
  72.  
  73.  
  74. /** 
  75. * Register the stylesheets for the admin area. 
  76. * @since 1.0.0 
  77. */ 
  78. public function includes() { 
  79.  
  80. if( $this->debug ) error_log( 'Inside: CWS_WPPicasaPro::includes()' ); 
  81.  
  82. if ( is_admin() ) $this->admin_includes(); 
  83.  
  84. include_once( dirname(__FILE__) . '/../cws-gpp-functions.php' ); // TODO: split file out in admin and non-admin functions 
  85. include_once( dirname(__FILE__) . '/../shortcodes/shortcode-init.php' ); // Init the shortcodes 
  86. include_once( dirname(__FILE__) . '/../widgets/widget-init.php' ); // Widget classes  
  87.  
  88. if( $this->isPro ==1 ) { 
  89. // TODO: change this into an include for Pro shortcodes... 
  90. add_shortcode( 'cws_gpp_images_by_albumid', 'cws_gpp_shortcode_images_in_album' ); // new one, shortcode provides album id 
  91.  
  92. public function admin_includes() { 
  93.  
  94. if( $this->debug ) error_log( 'Inside: CWS_WPPicasaPro::admin_includes()' ); 
  95.  
  96. include_once( dirname(__FILE__) . '/../cws-gpp-functions.php' ); // TODO: split file out in admin and non-admin functions 
  97. }  
  98.  
  99.  
  100. /** 
  101. * Register the stylesheets for the admin area. 
  102. * @since 2.0.0 
  103. */ 
  104. public function enqueue_styles() { 
  105.  
  106. /** 
  107. * This function is provided for demonstration purposes only. 
  108. * An instance of this class should be passed to the run() function 
  109. * defined in Plugin_Name_Loader as all of the hooks are defined 
  110. * in that particular class. 
  111. * The Plugin_Name_Loader will then create the relationship 
  112. * between the defined hooks and the functions defined in this 
  113. * class. 
  114. */ 
  115.  
  116. wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/cws-google-picasa-pro-admin.css', array(), $this->version, 'all' ); 
  117.  
  118.  
  119. /** 
  120. * Register the JavaScript for the admin area. 
  121. * @since 2.0.0 
  122. */ 
  123. public function enqueue_scripts() { 
  124.  
  125. /** 
  126. * This function is provided for demonstration purposes only. 
  127. * An instance of this class should be passed to the run() function 
  128. * defined in Plugin_Name_Loader as all of the hooks are defined 
  129. * in that particular class. 
  130. * The Plugin_Name_Loader will then create the relationship 
  131. * between the defined hooks and the functions defined in this 
  132. * class. 
  133. */ 
  134.  
  135. wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/cws-google-picasa-pro-admin.js', array( 'jquery' ), $this->version, false ); 
  136.  
  137.  
  138. /** 
  139. * Check if the plugin is a Pro version. 
  140. * @since 2.0.0 
  141. */  
  142. private function get_Pro( $isPro ) { 
  143.  
  144. if( $isPro == 1 ) { return "Pro"; } 
  145. return; 
  146.  
  147.  
  148. /** 
  149. * Register the Options for the admin area. 
  150. * @since 2.0.0 
  151. */  
  152. /** 
  153. public function add_options_page() { 
  154.  
  155. $strIsPro = $this->get_Pro( $this->isPro ); 
  156.   
  157. // add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function); 
  158. add_options_page( 'Google Picasa ' . $strIsPro, 'Google Picasa '. $strIsPro, 'manage_options', 'cws_gpp', array( $this, 'options_page') );  
  159. } */ 
  160.  
  161. /** 
  162. * Register the Top Level Menu Page for the admin area. 
  163. * @since 2.3.0 
  164. */  
  165. public function add_menu_page() { 
  166.  
  167. $strIsPro = $this->get_Pro( $this->isPro ); 
  168. // add_menu_page('Page Title', 'Google Photos', 10, 'cws_gpp', 'section'); 
  169. add_menu_page( 'Page Title', 'Google Photos', 'manage_options', 'cws_gpp', array( $this, 'options_page') ); 
  170. add_submenu_page( 'cws_gpp', 'Google Photos Settings', 'Settings', 'manage_options', 'cws_gpp', array( $this, 'options_page') ); 
  171. }  
  172.  
  173. /** 
  174. * Register the Options for the admin area. 
  175. * @since 2.3.0 
  176. */  
  177. public function add_options_sc_page() { 
  178.  
  179. //$strIsPro = $this->get_Pro( $this->isPro ); 
  180. add_submenu_page( 'cws_gpp', 'Google Photos Album Shortcodes', 'Album Shortcodes', 'manage_options', 'cws_sc', array( $this, 'options_page_sc') ); 
  181.  
  182.  
  183. /** 
  184. * Draw the Options page for the admin area. This contains simple shortcode snippets for *** PRO ONLY *** 
  185. * @since 2.3.0 
  186. */ 
  187. public function options_page_sc() { 
  188. ?> 
  189. <div class="wrap"> 
  190. <?php screen_icon(); ?> 
  191. <h2>Google Picasa <?php echo $this->get_Pro( $this->isPro );?> Settings</h2> 
  192.  
  193. <!-- <div class="widget-liquid-left"> --> 
  194. <div> 
  195.  
  196. <form action="options.php" method="post"> 
  197.  
  198. <?php  
  199. // Step 1: The user has not authenticated we give them a link to login  
  200. if( $this->isAuthenticated() !== true ) { 
  201. // settings_fields( $option_group ) 
  202. // Output nonce, action, and option_page fields for a settings page. Please note that this function must be called inside of the form tag for the options page. 
  203. // $option_group - A settings group name. This should match the group name used in register_setting().  
  204. ////settings_fields( 'cws_gpp_code' ); 
  205.  
  206. // do_settings_sections( $page ); 
  207. // Prints out all settings sections added to a particular settings page. 
  208. // The slug name of the page whose settings sections you want to output. This should match the page name used in add_settings_section(). 
  209. ////do_settings_sections( 'cws_gpp' );  
  210. ?> 
  211.  
  212. Not authenticated... 
  213. <!-- <input name="Submit" type="submit" value="Save Changes" /> --> 
  214. </form>  
  215. <?php 
  216. } else { 
  217. ?> 
  218. <div style="width: 95%;" class="postbox-container"> 
  219. <h2>Google Photo Album Details</h2> 
  220. <p>Use this shortcode to display photos in a album specified by the ID.</p> 
  221. <div class="metabox-holder"> 
  222.  
  223. <div class="postbox" id="settings"> 
  224. <?php 
  225. // $plugin = new CWS_Google_Picasa_Pro( $plugin_name, $version, $isPro ); 
  226. $plugin = new CWS_Google_Picasa_Pro(); 
  227. $plugin_admin = new CWS_Google_Picasa_Pro_Admin( $plugin->get_plugin_name(), $plugin->get_version(), $plugin->get_isPro() ); 
  228.  
  229. // Only display shortcode snippets to Pro users... 
  230. if( $plugin->isPro == 1 ) { 
  231.  
  232. // Grab options stored in db 
  233. $options = get_option( 'cws_gpp_options' ); 
  234.  
  235. // set some defaults... 
  236. $options['results_page'] = isset($options['results_page']) ? $options['results_page'] : ""; 
  237. $options['hide_albums'] = isset($options['hide_albums']) ? $options['hide_albums'] : ""; 
  238. $options['theme'] = isset($options['theme']) ? $options['theme'] : ""; 
  239.  
  240. // Extract the options from db and overwrite with any set in the shortcode 
  241. // extract( shortcode_atts( array( 
  242. extract( array( 
  243. 'thumb_size' => $options['thumb_size'],  
  244. 'album_thumb_size' => $options['album_thumb_size'],  
  245. 'show_title' => $options['show_album_title'],  
  246. 'show_details' => $options['show_album_details'],  
  247. 'num_results' => $options['num_album_results'],  
  248. 'visibility' => $options['private_albums'],  
  249. 'results_page' => $options['results_page'],  
  250. 'hide_albums' => $options['hide_albums'],  
  251. 'theme' => $options['theme'],  
  252. 'imgmax' => $options['lightbox_image_size'],  
  253. ) ); 
  254. // ), $atts ) ); 
  255. // Map albums names to hide to array and trim white space 
  256. //$hide_albums = array_map( 'trim', explode( ', ', $hide_albums ) ); 
  257. /** 
  258. if( isset( $hide_albums ) ) { 
  259. $hide_albums[] = 'Auto Backup'; 
  260. else { 
  261. $hide_albums = 'Auto Backup'; 
  262. */ 
  263. // TODO: cast other vars to int if required 
  264. $thumb_size = (int) $thumb_size; 
  265.  
  266. if ( $show_title === 'false' ) $show_title = false; // just to be sure... 
  267. if ( $show_title === 'true' ) $show_title = true; // just to be sure... 
  268. if ( $show_title === '0' ) $show_title = false; // just to be sure... 
  269. if ( $show_title === '1' ) $show_title = true; // just to be sure... 
  270. $show_title = (bool) $show_title;  
  271.  
  272. if ( $show_details === 'false' ) $show_details = false; // just to be sure... 
  273. if ( $show_details === 'true' ) $show_details = true; // just to be sure... 
  274. if ( $show_details === '0' ) $show_details = false; // just to be sure... 
  275. if ( $show_details === '1' ) $show_details = true; // just to be sure... 
  276. $show_details = (bool) $show_details;  
  277.  
  278. // Grab page from url 
  279. $cws_page = $_GET[ 'cws_page' ]; // $cws_page = get_query_var( 'cws_page' ); 
  280.  
  281. // Grab the access token 
  282. $AccessToken = get_option( 'cws_gpp_access_token' ); 
  283.  
  284. // Get Albums 
  285. $response = $plugin_admin->getAlbumList( $AccessToken, $album_thumb_size, $show_title, 0, 0, $visibility );  
  286. // $response = $plugin_admin->getAlbumList( $AccessToken, $album_thumb_size, $show_title, 0, 0 );  
  287.  
  288. // var_dump($response); 
  289.  
  290. #---------------------------------------------------------------------------- 
  291. # Convert the XML response into SimpleXML Object 
  292. #---------------------------------------------------------------------------- 
  293. if (!function_exists('produce_XML_object_tree')) { 
  294.  
  295. function produce_XML_object_tree( $response ) { 
  296. libxml_use_internal_errors( true ); 
  297. try { 
  298. // Create simplexml object from feed 
  299. $xml = new SimpleXMLElement( $response ); 
  300. } catch ( Exception $e ) { 
  301. // Something went wrong. 
  302. $error_message = 'SimpleXMLElement threw an exception.'; 
  303. foreach( libxml_get_errors() as $error_line ) { 
  304. $error_message .= "\t" . $error_line->message; 
  305. trigger_error( $error_message ); 
  306. return false; 
  307. return $xml; 
  308. } // end function produce 
  309.  
  310.  
  311. // Create SimpleXML Object 
  312. $xml = produce_XML_object_tree ( $response ); 
  313.  
  314. if( $xml === false ) { 
  315. echo 'Sorry there has been a problem with your feed.'; 
  316. } else { 
  317.  
  318. // TODO: create a helper function 
  319. $cws_debug = $_GET[ 'cws_debug' ]; // $cws_debug = get_query_var( 'cws_debug' ); 
  320. if( $_GET["cws_debug"] == "1" ) {  
  321. echo "<pre>" . print_r( $xml, true ) . "</pre>"; 
  322.  
  323. $xml->registerXPathNamespace('gphoto', 'http://schemas.google.com/photos/2007'); 
  324. $xml->registerXPathNamespace('media', 'http://search.yahoo.com/mrss/'); 
  325.  
  326. // register namespace to get access to total number of albums found 
  327. $xml->registerXPathNamespace('opensearch', 'http://a9.com/-/spec/opensearch/1.1/'); 
  328. $totalResults = $xml->xpath( "opensearch:totalResults" ); 
  329. $total_num_albums = $totalResults[0];  
  330. ?> 
  331. <table class="wp-list-table widefat fixed posts"> 
  332. <thead> 
  333. <tr valign="top"> 
  334. <th scope="row" width="100">Album Name </th> 
  335. <!--<th scope="row" width="70">Published</th> 
  336. <th scope="row" width="50">Num Photos </th> --> 
  337. <th scope="row" width="100">Album ID </th> 
  338. <th scope="row">Example shortcode</th> 
  339. </tr> 
  340. </thead> 
  341. <?php 
  342. // loop over the albums 
  343. foreach( $xml->entry as $feed ) { 
  344.  
  345. // get the data we need 
  346. $title = $feed->title; 
  347.  
  348. $gphoto = $feed->children( 'http://schemas.google.com/photos/2007' ); 
  349. $num_photos = $gphoto->numphotos;  
  350. $published = $feed->published;  
  351. $published = trim( $published ); 
  352. $published = substr( $published, 0, 10 );  
  353.  
  354. $group = $feed->xpath( './media:group/media:thumbnail' ); 
  355. $a = $group[0]->attributes(); // we need thumbnail path 
  356. $id = $feed->xpath( './gphoto:id' ); // and album id for our thumbnail 
  357. ?> 
  358. <tbody data-wp-lists="list:post" id="the-list"> 
  359.  
  360. <tr> 
  361. <td class="title column-title"> 
  362. <strong><?php echo $title;?></strong> 
  363. </td> 
  364. <td class="shortcode column-deescription"><?php echo $id[0];?></td> 
  365. <td class="shortcode column-shortcode"> 
  366. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_images_by_albumid theme=grid id="<?php echo $id[0];?>"]" readonly="readonly" onfocus="this.select();">  
  367. </tr> 
  368.  
  369. </tbody> 
  370. <?php 
  371. } // end foreach 
  372. ?> 
  373. <foot> 
  374. <tr valign="top"> 
  375. <th scope="row">Album Name </th> 
  376. <!-- <th scope="row">Published</th> 
  377. <th scope="row">Num Photos </th> -->  
  378. <th scope="row">Album ID </th> 
  379. <th scope="row">Example shortcode </th> 
  380. </tr> 
  381. </foot>  
  382. </table>  
  383. <?php 
  384. } // end else 
  385. ?> 
  386. </div> <!-- / . postbox --> 
  387.  
  388. <h3>Shortcode Usage Examples</h3> 
  389.  
  390. <h4>Display Albums Covers in a Carousel</h4> 
  391. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_albums theme='carousel' results_page='page-slug-here' show_titles=1]" readonly="readonly" onfocus="this.select();">  
  392.  
  393. <h4>Display Album Covers in a Grid View</h4> 
  394. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_albums theme='grid' results_page='page-slug-here' show_details='1' num_results=5]" readonly="readonly" onfocus="this.select();">  
  395.  
  396. <h4>Display Album Covers in a List View</h4> 
  397. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_albums theme='list' results_page='page-slug-here' show_title='1' show_details='1' thumb_size='250' num_results='3' visibility='all']" readonly="readonly" onfocus="this.select();">  
  398.  
  399. <h4>Display Images from Clicked Album Cover in a Carousel View</h4> 
  400. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_images_in_album theme='carousel' show_title=0 thumbsize='150']" readonly="readonly" onfocus="this.select();">  
  401.  
  402. <h4>Display Images from Clicked Album Cover in a Grid View</h4> 
  403. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_images_in_album theme='grid' show_title=1 show_details='1']" readonly="readonly" onfocus="this.select();">  
  404.  
  405. <h4>Display Images from Clicked Album Cover in a List View</h4> 
  406. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_images_in_album theme='list' show_title=1 show_details=1 num_results='13' thumb_size='250']" readonly="readonly" onfocus="this.select();">  
  407. <!-- 
  408. <h4>Display Images from Clicked Album Cover in a Expander View, great for when there are long Captions.</h4> 
  409. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_images_in_album theme='expander' show_title=0]" readonly="readonly" onfocus="this.select();">  
  410. --> 
  411. <h4>Display Images in a Specific Album. Only one album per page.</h4> 
  412. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_images_by_albumid id='05218507736478682657' theme='grid' show_title='0' show_details='0']" readonly="readonly" onfocus="this.select();">  
  413.  
  414. <!-- <h4>Display Album Images in Photo Booth Strips</h4> 
  415. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_albums theme='propbs' show_details='1' num_results='4']" readonly="readonly" onfocus="this.select();">  
  416.  
  417. <h4>Display Album Covers in Polaroid Scatter Grid</h4> 
  418. <input size="80" type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value="[cws_gpp_albums theme='propsg' results_page='results-grid' show_details='1']" readonly="readonly" onfocus="this.select();">  
  419. <p>Theme options supported by the results page for this are 'grid', 'list', 'carousel' </p> --> 
  420. </div> <!-- / meta holder --> 
  421. </div> <!-- / .postbox-container --> 
  422. <?php } else { ?> 
  423. <?php // Display upgrade content if not Pro 
  424. echo $plugin_admin->cws_gpp_upgrade_content();  
  425.  
  426. }  
  427.  
  428. ?> 
  429.  
  430. </div><!-- / left --> 
  431. </div> 
  432. <?php 
  433. } // end function options_page_sc() 
  434.  
  435.  
  436. /** 
  437. * Draw the Options page for the admin area. 
  438. * @since 2.0.0 
  439. */ 
  440. public function options_page() { 
  441.  
  442. if( $this->deauthorizeGoogleAccount() ) { 
  443. // TODO: finsish this delete_option unset() 
  444. delete_option( 'cws_gpp_reset' ); 
  445. delete_option( 'cws_gpp_token_expires' ); 
  446. delete_option( 'cws_gpp_code' ); 
  447. delete_option( 'cws_gpp_access_token' ); 
  448. } ?> 
  449.  
  450. <div class="wrap"> 
  451. <?php screen_icon(); ?> 
  452. <h2>Google Picasa <?php echo $this->get_Pro( $this->isPro );?> Settings</h2> 
  453.  
  454. <div class="widget-liquid-left"> 
  455.  
  456. <form action="options.php" method="post"> 
  457.  
  458. <?php  
  459. // Step 1: The user has not authenticated we give them a link to login  
  460. if( $this->isAuthenticated() !== true ) { 
  461. // settings_fields( $option_group ) 
  462. // Output nonce, action, and option_page fields for a settings page. Please note that this function must be called inside of the form tag for the options page. 
  463. // $option_group - A settings group name. This should match the group name used in register_setting().  
  464. settings_fields( 'cws_gpp_code' ); 
  465.  
  466. // do_settings_sections( $page ); 
  467. // Prints out all settings sections added to a particular settings page. 
  468. // The slug name of the page whose settings sections you want to output. This should match the page name used in add_settings_section(). 
  469. do_settings_sections( 'cws_gpp' );  
  470. ?> 
  471. <input name="Submit" type="submit" value="Save Changes" />  
  472.  
  473. </form>  
  474. <?php 
  475. }  
  476. else { 
  477. /** 
  478. * User is authenticated so display plugin config settings 
  479. *  
  480. */ 
  481.  
  482. // Get Access Token 
  483. $token = $this->getAccessToken(); 
  484.  
  485. settings_fields( 'cws_gpp_options' ); 
  486. do_settings_sections( 'cws_gpp_defaults' ); 
  487. ?> 
  488. <input name="Submit" type="submit" value="Save Changes" />  
  489. </form>  
  490.  
  491. <form action="options.php" method="post"> 
  492.  
  493. <?php settings_fields( 'cws_gpp_reset' ); 
  494. do_settings_sections( 'cws_gpp_reset' );  
  495. ?> 
  496. <input name="Submit" type="submit" value="Deauthorise" onclick="if(!this.form.reset.checked) {alert('You must click the checkbox to confirm you want to deauthorize current Google account.');return false}" /> 
  497.  
  498. </form>  
  499. <?php  
  500. ?> 
  501.  
  502. </div><!-- / left --> 
  503. <?php $this->cws_gpp_meta_box_feedback(); ?> 
  504.  
  505. <?php 
  506. if( !$this->isPro == 1 ) { 
  507. // Only call for the upgrade meta box if this is not a Pro install 
  508. $this->cws_gpp_meta_box_pro();  
  509. ?> 
  510.  
  511. </div> 
  512. <?php 
  513.  
  514.  
  515. // Display a feedback links 
  516. public function cws_gpp_meta_box_feedback() { 
  517. ?> 
  518.  
  519. <div class="widget-liquid-right"> 
  520. <div id="widgets-right">  
  521. <div style="width:20%;" class="postbox-container side"> 
  522. <div class="metabox-holder"> 
  523. <div class="postbox" id="feedback"> 
  524. <h3><span>Please rate the plugin!</span></h3> 
  525. <div class="inside">  
  526. <p>If you have found this useful please leave us a <a href="http://wordpress.org/extend/plugins/google-picasa-albums-viewer/">good rating</a></p> 
  527. <p>» Share it with your friends <a href="<?php echo "http://twitter.com/share?url=http://bit.ly/q4nqNA&text=Check out this awesome WordPress Plugin I'm using - Google Picasa Viewer" ?>">Tweet It</a></p> 
  528. <p>If you have found a bug please email me <a href="mailto:info@cheshirewebsolutions.com?subject=Feedback%20Google%20Picasa%20Viewer">info@cheshirewebsolutions.com</a></p>  
  529. </div> 
  530. </div> 
  531. </div> 
  532. </div>  
  533. </div> 
  534. </div>  
  535.  
  536. <?php 
  537.  
  538.  
  539.  
  540. // Display a Picasa Pro Promo Box 
  541. function cws_gpp_meta_box_pro() { 
  542. ?> 
  543. <div class="widget-liquid-right"> 
  544. <div id="widgets-right"> 
  545. <!-- <div style="width:20%;" class="postbox-container side"> --> 
  546. <div class="postbox-container side"> 
  547. <div class="metabox-holder"> 
  548. <div class="postbox" id="donate"> 
  549. <?php echo $this->cws_gpp_upgrade_content(); ?> 
  550. </div> 
  551. </div> 
  552. </div> 
  553. </div> 
  554. </div><?php  
  555.  
  556.  
  557. // seperate upgrade content from markup so can use content in more places, like shortcode snippets page and pro shortcodes in the frontend 
  558. function cws_gpp_upgrade_content() { 
  559.  
  560. $strOutput = "<h3><span>Get Google Picasa Pro!</span></h3> 
  561. <div class=\"inside\"> 
  562. <p>Grab yourself the <a href=\"http://www.cheshirewebsolutions.com/?utm_source=cws_gpp_config&utm_medium=text-link&utm_content=meta_box_pro&utm_campaign=cws_gpp_plugin\">Pro</a> version of the plugin.  
  563. <a href=\"http://www.cheshirewebsolutions.com/?utm_source=wp_gp_viewer&utm_medium=wp_plugin&utm_content=meta_box_download_it_here&utm_campaign=plugin_upgrade\">Download it here</a> <span><strong>GET 25% OFF!</strong> * use discount code <strong>WPMEGA25</strong> on checkout</span></p> 
  564. <h3> 
  565. Reasons to UPGRADE! 
  566. </h3> 
  567. <ol> 
  568. <li>Priority Email Support!</li> 
  569. <li>It*s much faster! We cache the Google Feed</li> 
  570. <li>Justified Image Grid Layout</li> 
  571. <li>Touch enabled lightbox, flick to the next or previous image, spread to zoom in etc</li> 
  572. <li>Native HTML5 full screen lightbox</li> 
  573. <li>Display image description as caption in lightbox</li> 
  574. <li>Social sharing</li> 
  575. <li>Customisable Lightbox Dimensions! have it as big as you like</li> 
  576. <li>Fantastic hover style effects</li> 
  577. <li>Display images in a specific album! just supply the album id</li> 
  578. <li>Helpful Shortcode Snippets Admin page!</li> 
  579. <li>Powered by link has been removed!</li> 
  580. <li>Included Download Original Image link</li> 
  581. </ol> 
  582.  
  583. </div>"; 
  584.  
  585. return $strOutput; 
  586.  
  587.  
  588. /** 
  589. * Register Settings, Settings Section and Settings Fileds. 
  590. *  
  591. * @link https://codex.wordpress.org/Function_Reference/register_setting 
  592. * @link https://codex.wordpress.org/Function_Reference/add_settings_section 
  593. * @link https://codex.wordpress.org/Function_Reference/add_settings_field 
  594. * @since 2.0.0 
  595. */  
  596. public function register_plugin_settings() { 
  597. // register_setting( $option_group, $option_name, $sanitize_callback ). 
  598. // $option_group - A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields(). 
  599. // $option_name - The name of an option to sanitize and save. 
  600. // $sanitize_callback - A callback function that sanitizes the option's value. 
  601. register_setting( 'cws_gpp_code', 'cws_gpp_code', array( $this, 'validate_options' ) ); 
  602. register_setting( 'cws_gpp_options', 'cws_gpp_options', array( $this, 'validate_main_options' ) ); 
  603.  
  604. register_setting( 'cws_gpp_reset', 'cws_gpp_reset', array( $this, 'validate_reset_options' ) ); 
  605.  
  606. // add_settings_section( $id, $title, $callback, $page ) 
  607. // $id - String for use in the 'id' attribute of tags 
  608. // $title - Title of the section 
  609. // $callback - Function that fills the section with the desired content. The function should echo its output. 
  610. // $page - The menu page on which to display this section. Should match $menu_slug in add_options_page(); 
  611. add_settings_section( 'cws_gpp_add_code', 'Authenticate with Google', array( $this, 'section_text' ), 'cws_gpp' ); 
  612. add_settings_section( 'cws_gpp_add_options', 'Default Settings', array( $this, 'section_main_text' ), 'cws_gpp_defaults' ); 
  613.  
  614. add_settings_section( 'cws_gpp_add_reset', 'Deauthorise Plugin from your Google Account', array( $this, 'section_reset_text' ), 'cws_gpp_reset' ); 
  615.  
  616. // add_settings_field( $id, $title, $callback, $page, $section, $args ); 
  617. // $id - String for use in the 'id' attribute of tags 
  618. // $title - Title of the field 
  619. // $callback - Function that fills the field with the desired inputs as part of the larger form. Passed a single argument,  
  620. // the $args array. Name and id of the input should match the $id given to this function. The function should echo its output. 
  621. // $page - The menu page on which to display this field. Should match $menu_slug in add_options_page(); 
  622. // $section - (optional) The section of the settings page in which to show the box. A section added with add_settings_section() [optional] 
  623. // $args - (optional) Additional arguments that are passed to the $callback function 
  624. add_settings_field( 'cws_myplugin_oauth2_code', 'Enter Google Access Code here', array( $this, 'setting_input' ), 'cws_gpp', 'cws_gpp_add_code' ); 
  625.  
  626.  
  627. // Add default option field - Thumbnail Size  
  628. add_settings_field( 'cws_gpp_thumbnail_size', 'Thumbnail Size (px)', array( $this, 'options_thumbnail_size' ), 'cws_gpp_defaults', 'cws_gpp_add_options' ); 
  629.  
  630. // Add default option field - Album Thumbnail Size  
  631. add_settings_field( 'cws_gpp_album_thumbnail_size', 'Album Thumbnail Size (px)', array( $this, 'options_album_thumbnail_size' ), 'cws_gpp_defaults', 'cws_gpp_add_options' ); 
  632.  
  633. if( $this->isPro ) { 
  634. // PRO ONLY 
  635. // Add default option field - Lighbox Image Size  
  636. add_settings_field( 'cws_gpp_lightbox_image_size', 'Lightbox Image Size (px)', array( $this, 'options_lightbox_image_size' ), 'cws_gpp_defaults', 'cws_gpp_add_options' );  
  637. // Add default option field - Number of image results 
  638. add_settings_field( 'cws_gpp_num_image_results', 'Number of images per page', array( $this, 'options_num_image_results' ), 'cws_gpp_defaults', 'cws_gpp_add_options' ); 
  639.  
  640. // Add default option field - Number of album results 
  641. add_settings_field( 'cws_gpp_num_album_results', 'Number of albums per page', array( $this, 'options_num_album_results' ), 'cws_gpp_defaults', 'cws_gpp_add_options' ); 
  642.  
  643. // Add default option checkbox - Show private albums checkbox 
  644. add_settings_field( 'cws_gpp_show_private_albums', 'Show which albums', array( $this, 'options_show_private_albums' ), 'cws_gpp_defaults', 'cws_gpp_add_options' );  
  645.  
  646. // Add default option checkbox - Show album title 
  647. add_settings_field( 'cws_gpp_show_album_title', 'Show Album Title', array( $this, 'options_show_album_title' ), 'cws_gpp_defaults', 'cws_gpp_add_options' );  
  648.  
  649. // Add default option checkbox - Show image title 
  650. add_settings_field( 'cws_gpp_show_image_title', 'Show Image Title', array( $this, 'options_show_image_title' ), 'cws_gpp_defaults', 'cws_gpp_add_options' );  
  651.  
  652. // Add default option checkbox - Show album details 
  653. add_settings_field( 'cws_gpp_show_album_details', 'Show Album Details', array( $this, 'options_show_album_details' ), 'cws_gpp_defaults', 'cws_gpp_add_options' );  
  654.  
  655. // Add default option checkbox - Show image details 
  656. add_settings_field( 'cws_gpp_show_image_details', 'Show Image Details', array( $this, 'options_show_image_details' ), 'cws_gpp_defaults', 'cws_gpp_add_options' );  
  657.  
  658. if( $this->isPro ) { 
  659. // PRO ONLY 
  660. // Add default option checkbox - Enable Cache 
  661. add_settings_field( 'cws_gpp_enable_cache', 'Enable Cache', array( $this, 'options_enable_cache' ), 'cws_gpp_defaults', 'cws_gpp_add_options' ); 
  662. // Add default option checkbox - Expose Original file 
  663. add_settings_field( 'cws_gpp_enable_download', 'Download Original Image Link', array( $this, 'options_enable_download' ), 'cws_gpp_defaults', 'cws_gpp_add_options' ); 
  664.  
  665. // Add reset option 
  666. add_settings_field( 'cws_gpp_reset', 'Click here to confirm you want to deauthorise plugin from your google account', array( $this, 'options_reset' ), 'cws_gpp_reset', 'cws_gpp_add_reset' );  
  667.  
  668.  
  669. /** 
  670. * Draw the Section Header for the admin area. 
  671. * @since 2.0.0 
  672. */ 
  673. function section_text() { 
  674. echo 'You need to click here to authorize access and paste the Access Code provided by Google in the field below.'; 
  675.  
  676. // get the google authorisation url 
  677. $authUrl = $this->client->createAuthUrl(); 
  678.  
  679. // display the google authorisation url 
  680. echo $this->createAuthLink( $authUrl ); 
  681.  
  682. $code = get_option( 'cws_gpp_code' ); 
  683. $oauth2_code = $code['oauth2_code']; 
  684.  
  685. $token = get_option( 'cws_gpp_access_token' ); 
  686. $token = $token['access_token']; 
  687.  
  688. if ( isset( $code['oauth2_code'] ) ) { 
  689.  
  690. $this->client->authenticate( $code['oauth2_code'] );  
  691. $AccessToken = $this->client->getAccessToken(); 
  692. $AccessToken = json_decode( $AccessToken, TRUE ); 
  693.  
  694. // delete code 
  695. $code = get_option( 'cws_gpp_code' ); 
  696.  
  697. if ( $code ) { 
  698. unset($code['oauth2_code']); 
  699. update_option( 'cws_gpp_code', $code ); 
  700.  
  701. // store access token 
  702. if( update_option( 'cws_gpp_access_token', $AccessToken ) ) 
  703. if( $this->debug ) error_log( 'Update option: cws_gpp_access_token' ); 
  704.  
  705. // store token expires 
  706. $now = date("U"); 
  707. $token_expires = $now + $AccessToken['expires_in']; 
  708. add_option( 'cws_gpp_token_expires', $token_expires );  
  709.  
  710. $url = admin_url( "options-general.php?page=".$_GET["page"] ); 
  711. // error_log($url); 
  712.  
  713. wp_redirect( "$url" ); 
  714. exit;  
  715. }  
  716.  
  717.  
  718. function section_main_text() { 
  719.  
  720.  
  721. // 
  722. function section_reset_text() { 
  723.  
  724. }  
  725.  
  726. function section() { 
  727.  
  728. }  
  729.  
  730.  
  731. /** 
  732. * Get the Access Token stored in db. 
  733. * @since 2.0.0 
  734. */  
  735. public function getAccessToken() { 
  736. $token = get_option( 'cws_gpp_access_token' ); 
  737.  
  738. return $token; 
  739.  
  740.  
  741. /** 
  742. * Get the authourisation link. 
  743. * @since 2.0.0 
  744. */  
  745. public function createAuthLink( $authUrl ) { 
  746.  
  747. if ( isset( $authUrl ) ) { 
  748.  
  749. $output = "<br><br><a class='login' href='$authUrl' target='_blank'>Connect My Google Account</a>";  
  750. } else { 
  751. $output = "There was a problem generating the Google Autherisation link"; 
  752.  
  753. return $output; 
  754.  
  755.  
  756. /** GOOD WORKFLOW OF STEPS https://www.domsammut.com/code/php-server-side-youtube-v3-oauth-api-video-upload-guide **/  
  757. /** 
  758. * Get the Reset option stored in db. 
  759. * @since 2.0.0 
  760. */  
  761. public function deauthorizeGoogleAccount() { 
  762. // get options from db 
  763.  
  764. if( get_option( 'cws_gpp_reset' ) ) { 
  765. return true; 
  766. }  
  767.  
  768. return false; 
  769.  
  770.  
  771. public function isAuthenticated() { 
  772.  
  773. // get options from db 
  774. $code = get_option( 'cws_gpp_code' ); 
  775. $token = get_option( 'cws_gpp_access_token' ); 
  776.  
  777. if ( !isset( $token['access_token'] ) ) { 
  778. // get oauth2 code 
  779. //$this->getOAuthToken(); 
  780. else{ 
  781. // check if it needs refreshing 
  782. $now = date("U"); 
  783.  
  784. // get cws_gpp_token_expires 
  785. $token_expires = get_option( 'cws_gpp_token_expires' ); 
  786.  
  787. // check if $now is greater than cws_gpp_token_expires 
  788. if ( $now > $token_expires ) { 
  789. $this->refreshToken();  
  790. return; 
  791. }  
  792.  
  793. return true; 
  794.  
  795. return false; 
  796.  
  797.  
  798. public function refreshToken() { 
  799.  
  800. if($this->debug) { error_log('Inside refreshToken()'); } 
  801.  
  802. $GOOGLE_OAUTH2_REFERER = ""; 
  803.  
  804. // get access token and refresh it  
  805. $now = date( "U" ); 
  806. $clientId = '806353319710-g782kn9ed0gm77ucl0meen5ohs84qgqm.apps.googleusercontent.com'; 
  807. $clientSecret = 'P6BMMEWLKUSoxB48X2Tzu8ds'; 
  808. $token = get_option( 'cws_gpp_access_token' ); 
  809. $refreshToken = $token['refresh_token']; 
  810.  
  811. $postBody = 'client_id='.urlencode($clientId) 
  812. .'&client_secret='.urlencode($clientSecret) 
  813. .'&refresh_token='.urlencode($refreshToken) 
  814. .'&grant_type=refresh_token'; 
  815.  
  816. $curl = curl_init(); 
  817. curl_setopt_array( $curl,  
  818. array( CURLOPT_CUSTOMREQUEST => 'POST' 
  819. , CURLOPT_URL => 'https://www.googleapis.com/oauth2/v3/token' 
  820. , CURLOPT_HTTPHEADER => array( 'Content-Type: application/x-www-form-urlencoded' 
  821. , 'Content-Length: '.strlen($postBody) 
  822. , CURLOPT_POSTFIELDS => $postBody  
  823. , CURLOPT_REFERER => $GOOGLE_OAUTH2_REFERER 
  824. , CURLOPT_RETURNTRANSFER => 1 // means output will be a return value from curl_exec() instead of simply echoed 
  825. , CURLOPT_TIMEOUT => 12 // max seconds to wait 
  826. , CURLOPT_FOLLOWLOCATION => 0 // don't follow any Location headers, use only the CURLOPT_URL, this is for security 
  827. , CURLOPT_FAILONERROR => 0 // do not fail verbosely fi the http_code is an error, this is for security 
  828. , CURLOPT_SSL_VERIFYPEER => 0 // do verify the SSL of CURLOPT_URL, this is for security 
  829. , CURLOPT_VERBOSE => 0 // don't output verbosely to stderr, this is for security 
  830. ) ); 
  831.  
  832. $orig_response = curl_exec( $curl ); 
  833. $response = json_decode( $orig_response, true ); // convert returned objects into associative arrays 
  834. $token_expires = $now + $response['expires_in']; 
  835. $http_code = curl_getinfo( $curl, CURLINFO_HTTP_CODE ); 
  836. curl_close( $curl ); 
  837.  
  838. if ( $response['access_token'] ) {  
  839. // get options update access token part 
  840. $token = get_option( 'cws_gpp_access_token' ); 
  841. $token['access_token'] = $response['access_token']; 
  842.  
  843. update_option("cws_gpp_access_token", $token); # save the access token 
  844. update_option("cws_gpp_token_expires", $token_expires); # save the epoch when the token expires 
  845.  
  846. if( $this->debug ) { error_log( 'Refresh Access Token...' ); } 
  847.  
  848. $url = $this->getUrl(); 
  849. wp_redirect( "$url" ); 
  850. exit;  
  851.  
  852. } else { 
  853. // echo "refreshOAuth2Token got the following response:<br />"; 
  854. // echo $orig_response; 
  855. // echo "using refreshToken $refreshToken"; 
  856. }  
  857. // TODO: Improve error handling here for various curl error codes etc  
  858.  
  859.  
  860. /** 
  861. * Get current url. 
  862. * @since 2.3.0 
  863. */  
  864. function getUrl() { 
  865. $url = ( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"]; 
  866. $url .= ( $_SERVER["SERVER_PORT"] != 80 ) ? ":".$_SERVER["SERVER_PORT"] : ""; 
  867. $url .= $_SERVER["REQUEST_URI"]; 
  868. return $url; 
  869.  
  870.  
  871. /** 
  872. * Get list of Albums for authenticated user. 
  873. * @since 2.0.0 
  874. */  
  875. public function getAlbumList( $AccessToken, $album_thumb_size, $show_title, $cws_page, $num_image_results, $visibility) {  
  876.  
  877. if( $this->debug ) { error_log( 'Inside getAlbumList()' ); } 
  878.  
  879. // Work out pagination variables 
  880. if ( !( isset( $cws_page ) ) ) { 
  881. $cws_page = 1; 
  882. if ( $cws_page > 1 ) { 
  883. $start_index = ( ( $cws_page - 1 ) * $num_image_results ) + 1; 
  884. } else { 
  885. $start_index = 1; 
  886. }  
  887.  
  888. $visibility = strtolower( $visibility ); 
  889.  
  890. // https://developers.google.com/accounts/docs/OAuth2WebServer#callinganapi 
  891. $curl = curl_init(); 
  892. // https://developers.google.com/picasa-web/docs/2.0/reference#Visibility 
  893. // http://picasaweb.google.com/data/feed/api/user/userID?kind=photo&q=penguin 
  894.  
  895. // limit results or not 
  896. if( $num_image_results > 0 ) { 
  897. $url = "https://picasaweb.google.com/data/feed/api/user/default?kind=album&thumbsize=" . $album_thumb_size . "c&max-results=" . $num_image_results . "&start-index=" . $start_index . "&access=" . $visibility; 
  898. //$url = "https://picasaweb.google.com/data/feed/api/user/default?kind=album&thumbsize=" . $album_thumb_size . "c&max-results=" . $num_image_results . "&start-index=" . $start_index ;  
  899. //$url = "https://picasaweb.google.com/data/feed/api/user/default?kind=album&thumbsize=" . $album_thumb_size . "c&max-results=" . $num_image_results . "&start-index=" . $start_index . "&access=all";  
  900. } else { 
  901. $url = "https://picasaweb.google.com/data/feed/api/user/default?kind=album&thumbsize=" . $album_thumb_size . "c&access=" . $visibility; 
  902. // $url = "https://picasaweb.google.com/data/feed/api/user/default?kind=album&thumbsize=" . $album_thumb_size . "c"; 
  903. //$url = "https://picasaweb.google.com/data/feed/api/user/default?kind=album&thumbsize=" . $album_thumb_size . "c&access=visible"; 
  904.  
  905. // TODO: create a helper function 
  906. $cws_debug = $_GET[ 'cws_debug' ];// $cws_debug = get_query_var( 'cws_debug' ); 
  907.  
  908. if( $cws_debug == "1" ) {  
  909. echo "url = $url<br>";  
  910. echo "show_title = $show_title<br>"; 
  911.  
  912. curl_setopt_array( $curl,  
  913. array( CURLOPT_CUSTOMREQUEST => 'GET' 
  914. , CURLOPT_URL => $url 
  915. , CURLOPT_HTTPHEADER => array( 'GData-Version: 2' 
  916. , 'Authorization: Bearer '.$AccessToken['access_token'] ) 
  917. , CURLOPT_REFERER => 'http://wp-picasa-pro.wordpress.dev/wp-admin/options-general.php?page=cws_gpp' 
  918. , CURLOPT_RETURNTRANSFER => 1 // means output will be a return value from curl_exec() instead of simply echoed 
  919. ) ); 
  920. $response = curl_exec($curl); 
  921. $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
  922. curl_close($curl); 
  923.  
  924. // Return $response to shortcode if http_code is 200 
  925. if( $http_code == 200 ) { return $response; } 
  926. // TODO: Add in some error handling better reporting of http code 
  927. return false; 
  928.  
  929.  
  930. /** 
  931. * Get list of Images in a specific Album for authenticated user. 
  932. * @since 2.0.0 
  933. */ 
  934. // public function getAlbumImages( $AccessToken, $album_thumb_size, $show_album_ttl, $cws_page, $num_image_results, $cws_album, $imgmax='450' ) { 
  935. public function getAlbumImages( $AccessToken, $album_thumb_size, $show_album_ttl, $cws_page, $num_image_results, $cws_album, $imgmax='450', $theme ) { 
  936.  
  937. // Crop the image or not, projig wants not cropped... 
  938. if ( $theme != 'projig' ) { $crop = 'c'; } else { $crop = ''; } 
  939.  
  940. if( $imgmax == 0 || $imgmax == 0 ) { $imgmax = 450; } 
  941.  
  942. if( $this->debug ) { error_log( 'Inside getAlbumImages()' ); } 
  943.  
  944. // Work out pagination variables 
  945. if ( !( isset( $cws_page ) ) ) { 
  946. $cws_page = 1; 
  947. if ( $cws_page > 1 ) { 
  948. $start_index = ( ( $cws_page - 1 ) * $num_image_results ) + 1; 
  949. } else { 
  950. $start_index = 1; 
  951. }  
  952.  
  953. $curl = curl_init(); 
  954.  
  955. if( $num_image_results > 0 ) { 
  956. // $url = "https://picasaweb.google.com/data/feed/api/user/default/albumid/" . $cws_album . "?thumbsize=" . $album_thumb_size . "c&max-results=" . $num_image_results . "&start-index=" . $start_index . "&imgmax=" . $imgmax;  
  957. $url = "https://picasaweb.google.com/data/feed/api/user/default/albumid/" . $cws_album . "?thumbsize=" . $album_thumb_size . $crop . "&max-results=" . $num_image_results . "&start-index=" . $start_index . "&imgmax=" . $imgmax;  
  958. } else { 
  959. // $url = "https://picasaweb.google.com/data/feed/api/user/default/albumid/" . $cws_album . "?thumbsize=" . $album_thumb_size . "c&imgmax=" . $imgmax; 
  960. $url = "https://picasaweb.google.com/data/feed/api/user/default/albumid/" . $cws_album . "?thumbsize=" . $album_thumb_size . $crop . "&imgmax=" . $imgmax;  
  961. // TODO: create a helper function 
  962. $cws_debug = $_GET[ 'cws_debug' ]; // $cws_debug = get_query_var( 'cws_debug' ); 
  963.  
  964. //, CURLOPT_REFERER => 'http://wp-picasa-pro.wordpress.dev/wp-admin/options-general.php?page=cws_gpp' 
  965.  
  966. curl_setopt_array( $curl,  
  967. array( CURLOPT_CUSTOMREQUEST => 'GET' 
  968. , CURLOPT_URL => $url 
  969. , CURLOPT_HTTPHEADER => array( 'GData-Version: 2' 
  970. , 'Authorization: Bearer '.$AccessToken['access_token'] ) 
  971. , CURLOPT_RETURNTRANSFER => 1 // means output will be a return value from curl_exec() instead of simply echoed 
  972. ) ); 
  973. $response = curl_exec( $curl ); 
  974. $http_code = curl_getinfo( $curl, CURLINFO_HTTP_CODE ); 
  975. curl_close( $curl ); 
  976.  
  977. if( $cws_debug == "1" ) {  
  978. echo "url = $url"; 
  979. echo "http code: $http_code<br>"; 
  980. echo '<pre>'; 
  981. print_r($response); 
  982. echo '</pre>';  
  983. var_dump($imgmax); 
  984.  
  985. // Return $response to shortcode if http_code is 200 
  986. if( $http_code == 200 ) { return $response; } 
  987.  
  988.  
  989. /** 
  990. * Pagination Helper 
  991. * $num_pages, int 
  992. * $current_page, int 
  993. * $album_id 
  994. * return string 
  995. */  
  996. public function get_pagination( $total_num_albums, $num_image_results, $cws_page, $album_id=NULL ) { 
  997.  
  998. // global $post; 
  999.  
  1000. // echo $post->post_name; 
  1001.  
  1002. if( $this->debug ) error_log( 'Inside: CWS_Google_Picasa_Pro_Admin::get_pagination()' );  
  1003.  
  1004. // Calcualte how many pages we need, total number of albums / number of images to display per page as set in settings of shortcode 
  1005. if( $num_image_results > 0 ) { 
  1006. $num_pages = ceil( $total_num_albums / $num_image_results ); 
  1007.  
  1008. // If ony need one page then do not display pagination 
  1009. if ( $num_pages <= 1 ) { 
  1010. return; 
  1011.  
  1012.  
  1013. if( ! isset( $cws_page ) || $cws_page < 1 ) { $cws_page = 1; } // TODO: Do we need this check? 
  1014.  
  1015. // Create page links 
  1016. $html[] = "<div class=\"cws-pagination\"><ul class=\"page-nav\">\n"; 
  1017.  
  1018. $previous = $cws_page - 1; 
  1019. $next = $cws_page + 1; 
  1020.  
  1021. // Previous link 
  1022. if( $previous > 0 ) { 
  1023.  
  1024. // if have album id, i.e. display this on the results page 
  1025. if( $album_id ) { 
  1026. $html[] = "<li><a href=\"?cws_page=$previous&cws_album=$album_id\" id='prev_page'>Previous</a></li>"; 
  1027. } else { 
  1028. $html[] = "<li><a href=\"?cws_page=$previous\" id='prev_page'>Previous</a></li>";  
  1029.  
  1030. for( $i=1; $i <= $num_pages; $i++ ) { 
  1031.  
  1032. $class = ""; 
  1033.  
  1034. // Add class to current page 
  1035. if( $i == $cws_page) { 
  1036. $class = " class='selected'"; 
  1037.  
  1038. $html[] = "<li".$class.">"; 
  1039.  
  1040. if( $album_id ) { 
  1041. $html[] = "<a href=\"?cws_page=$i&cws_album=$album_id\" id='page_".$i."'>".$i."</a></li>\n"; 
  1042. } else { 
  1043. $html[] = "<a href=\"?cws_page=$i\" id='page_".$i."'>".$i."</a></li>\n"; 
  1044.  
  1045. // Next link 
  1046. if( $next <= $num_pages ) { 
  1047.  
  1048. // if have album id 
  1049. if( $album_id ) { 
  1050. $html[] = "<li><a href=\"?cws_page=$next&cws_album=$album_id\" id='next_page'>Next</a></li>"; 
  1051. } else { 
  1052. $html[] = "<li><a href=\"?cws_page=$next\" id='next_page'>Next</a></li>"; 
  1053.  
  1054. // Display Powered by link if not Pro 
  1055. if( !$this->isPro == 1 ) { 
  1056. // $html[] = "</ul><span>Powered by: <a href=\"http://www.cheshirewebsolutions.com/\">Cheshire Web Solutions</a></span></div>\n"; 
  1057. $html[] = "</ul><span>Powered by: <a href=\"http://www.cheshirewebsolutions.com/\">Google Photos for WordPress Plugin</a></span></div>\n";  
  1058. } else { 
  1059. $html[] = "</ul></div>\n"; 
  1060. return implode( "\n", $html ); 
  1061. return; 
  1062.  
  1063.  
  1064. /** 
  1065. * Display and fill the form field. 
  1066. * @since 2.0.0 
  1067. */  
  1068. function setting_input() { 
  1069.  
  1070. // get option 'oauth2_code' value from the database 
  1071. $code = get_option( 'cws_gpp_code' ); 
  1072. $oauth2_code = $code['oauth2_code']; 
  1073. // echo the field 
  1074. echo "<input id='oauth2_code' name='cws_gpp_code[oauth2_code]' type='text' value='$oauth2_code' >"; 
  1075.  
  1076.  
  1077. /** 
  1078. * Display and fill the form fields for storing defaults. 
  1079. * Thumbnail Size in pixels 
  1080. * @since 2.0.0 
  1081. */  
  1082. function options_thumbnail_size() { 
  1083.  
  1084. // get option 'thumb_size' value from the database 
  1085. $options = get_option( 'cws_gpp_options' ); 
  1086. $thumb_size = $options['thumb_size']; 
  1087.  
  1088. echo "<input id='thumb_size' name='cws_gpp_options[thumb_size]' type='text' value='$thumb_size' >"; 
  1089. }  
  1090.  
  1091.  
  1092. /** 
  1093. * Display and fill the form fields for storing defaults. 
  1094. * Album Thumbnail Size in pixels 
  1095. * @since 2.0.0 
  1096. */  
  1097. function options_album_thumbnail_size() { 
  1098.  
  1099. // get option 'album_thumb_size' value from the database 
  1100. $options = get_option( 'cws_gpp_options' ); 
  1101. $album_thumb_size = $options['album_thumb_size']; 
  1102.  
  1103. echo "<input id='album_thumb_size' name='cws_gpp_options[album_thumb_size]' type='text' value='$album_thumb_size' >"; 
  1104. }  
  1105.  
  1106.  
  1107. /** 
  1108. * Display and fill the form fields for storing defaults. 
  1109. * Lightbox Image Size in pixels 
  1110. * @since 2.3.0 
  1111. */  
  1112. function options_lightbox_image_size() { 
  1113.  
  1114. // get option 'lightbox_image_size' value from the database 
  1115. $options = get_option( 'cws_gpp_options' ); 
  1116. $lightbox_image_size = $options['lightbox_image_size']; 
  1117.  
  1118. echo "<input id='lightbox_image_size' name='cws_gpp_options[lightbox_image_size]' type='text' value='$lightbox_image_size' >"; 
  1119. }  
  1120.  
  1121.  
  1122. /** 
  1123. * Enable Cache 
  1124. * caches feed and stores for 1 hour 
  1125. * Pro Only 
  1126. * @since 2.3.0 
  1127. */  
  1128. function options_enable_cache() { 
  1129.  
  1130. // set some defaults... 
  1131. $checked = ''; 
  1132.  
  1133. // get option 'enable_cache' value from the database 
  1134. $options = get_option( 'cws_gpp_options' ); 
  1135. $enable_cache = $options['enable_cache']; 
  1136.  
  1137. if($options['enable_cache']) { $checked = ' checked="checked" '; } 
  1138. echo "<input ".$checked." id='enable_cache' name='cws_gpp_options[enable_cache]' type='checkbox' /><small>Only check this once you are happy with other settings.</small>"; 
  1139. }  
  1140.  
  1141.  
  1142. /** 
  1143. * Enable Download 
  1144. * Exposes download link next to each thumbnail to allow user to access original image file 
  1145. * Pro Only 
  1146. * @since 2.3.1 
  1147. */  
  1148. function options_enable_download() { 
  1149.  
  1150. // set some defaults... 
  1151. $checked = ''; 
  1152.  
  1153. // get option 'enable_download' value from the database 
  1154. $options = get_option( 'cws_gpp_options' ); 
  1155.  
  1156. $options['enable_download'] = isset($options['enable_download']) ? $options['enable_download'] : ""; 
  1157.  
  1158. $enable_cache = $options['enable_download']; 
  1159.  
  1160. if($options['enable_download']) { $checked = ' checked="checked" '; } 
  1161. echo "<input ".$checked." id='enable_download' name='cws_gpp_options[enable_download]' type='checkbox' /><small>Allow user to download original image file.</small>"; 
  1162. }  
  1163.  
  1164. /** 
  1165. * Display and fill the form fields for storing defaults. 
  1166. * Number of images results to display per page 
  1167. * @since 2.0.0 
  1168. */  
  1169. function options_num_image_results() { 
  1170.  
  1171. // get option 'num_image_results' value from the database 
  1172. $options = get_option( 'cws_gpp_options' ); 
  1173. $num_image_results = $options['num_image_results']; 
  1174.  
  1175. echo "<input id='num_image_results' name='cws_gpp_options[num_image_results]' type='text' value='$num_image_results' >"; 
  1176. }  
  1177.  
  1178.  
  1179. /** 
  1180. * Display and fill the form fields for storing defaults. 
  1181. * Number of albums results to display per page 
  1182. * @since 2.0.0 
  1183. */  
  1184. function options_num_album_results() { 
  1185.  
  1186. // get option 'num_album_results' value from the database 
  1187. $options = get_option( 'cws_gpp_options' ); 
  1188. $num_album_results = $options['num_album_results']; 
  1189.  
  1190. echo "<input id='num_album_results' name='cws_gpp_options[num_album_results]' type='text' value='$num_album_results' >"; 
  1191. }  
  1192.  
  1193.  
  1194. /** 
  1195. * Display and fill the form fields for storing defaults. 
  1196. * Show Private Albums 
  1197. * @since 2.0.0 
  1198. */ 
  1199.  
  1200. function options_show_private_albums() { 
  1201. $options = get_option('cws_gpp_options');  
  1202. $options['private_albums'] = isset($options['private_albums']) ? $options['private_albums'] : ""; 
  1203.  
  1204. // DROP-DOWN-BOX - Name: plugin_options[dropdown1] 
  1205. $items = array("All", "Private", "Public", "Visible"); 
  1206. echo "<select id='cws_gpp_show_private_albums' name='cws_gpp_options[private_albums]'>"; 
  1207. foreach($items as $item) { 
  1208. $selected = ($options['private_albums']==$item) ? 'selected="selected"' : ''; 
  1209. echo "<option value='$item' $selected>$item</option>"; 
  1210. echo "</select>"; 
  1211.  
  1212.  
  1213. /** 
  1214. * Display and fill the form fields for storing defaults. 
  1215. * Show Album Title 
  1216. * @since 2.0.0 
  1217. */  
  1218. function options_show_album_title() { 
  1219.  
  1220. // set some defaults... 
  1221. $checked = ''; 
  1222.  
  1223. // get option 'show_album_title' value from the database 
  1224. $options = get_option( 'cws_gpp_options' ); 
  1225. $show_album_title = $options['show_album_title']; 
  1226.  
  1227. if($options['show_album_title']) { $checked = ' checked="checked" '; } 
  1228. echo "<input ".$checked." id='show_album_title' name='cws_gpp_options[show_album_title]' type='checkbox' />"; 
  1229. }  
  1230.  
  1231.  
  1232. /** 
  1233. * Display and fill the form fields for storing defaults. 
  1234. * Show Image Title 
  1235. * @since 2.0.0 
  1236. */  
  1237. function options_show_image_title() { 
  1238.  
  1239. // set some defaults... 
  1240. $checked = ''; 
  1241.  
  1242. // get option 'show_image_title' value from the database 
  1243. $options = get_option( 'cws_gpp_options' ); 
  1244. $show_album_title = $options['show_image_title']; 
  1245.  
  1246. if($options['show_image_title']) { $checked = ' checked="checked" '; } 
  1247. echo "<input ".$checked." id='show_image_title' name='cws_gpp_options[show_image_title]' type='checkbox' />"; 
  1248. }  
  1249.  
  1250.  
  1251. /** 
  1252. * Display and fill the form fields for storing defaults. 
  1253. * Show Album Details 
  1254. * @since 2.0.0 
  1255. */  
  1256.  
  1257. function options_show_album_details() { 
  1258.  
  1259. // set some defaults... 
  1260. $checked = ''; 
  1261.  
  1262. // get option 'show_album_details' value from the database 
  1263. $options = get_option( 'cws_gpp_options' ); 
  1264. $show_album_details = $options['show_album_details']; 
  1265.  
  1266. if($options['show_album_details']) { $checked = ' checked="checked" '; } 
  1267. echo "<input ".$checked." id='show_album_details' name='cws_gpp_options[show_album_details]' type='checkbox' />"; 
  1268. }  
  1269.  
  1270.  
  1271. /** 
  1272. * Display and fill the form fields for storing defaults. 
  1273. * Show Image Details 
  1274. * @since 2.0.0 
  1275. */  
  1276. function options_show_image_details() { 
  1277.  
  1278. // set some defaults... 
  1279. $checked = ''; 
  1280.  
  1281. // get option 'show_album_details' value from the database 
  1282. $options = get_option( 'cws_gpp_options' ); 
  1283. $options['show_image_details'] = isset($options['show_image_details']) ? $options['show_image_details'] : ""; 
  1284. $show_image_details = $options['show_image_details']; 
  1285.  
  1286. if($options['show_image_details']) { $checked = ' checked="checked" '; } 
  1287. echo "<input ".$checked." id='show_image_details' name='cws_gpp_options[show_image_details]' type='checkbox' />"; 
  1288. }  
  1289.  
  1290.  
  1291. /** 
  1292. * Display and fill the form fields for storing defaults. 
  1293. * Show Album Details 
  1294. * @since 2.0.0 
  1295. */  
  1296. function options_reset() { 
  1297.  
  1298. // set some defaults... 
  1299. $checked = ''; 
  1300.  
  1301. // get option 'show_album_details' value from the database 
  1302. $options = get_option( 'cws_gpp_reset' );  
  1303.  
  1304. if($options['cws_gpp_reset']) { $checked = ' checked="checked" '; } 
  1305. echo "<input ".$checked." id='reset' name='cws_gpp_reset[reset]' type='checkbox' required />"; 
  1306. }  
  1307.  
  1308.  
  1309. /** 
  1310. * Validate user input (we want text only). 
  1311. * @since 2.0.0 
  1312. */  
  1313. function validate_options( $input ) { 
  1314.  
  1315. $valid['oauth2_code'] = esc_attr ( $input['oauth2_code'] ); 
  1316.  
  1317. return $valid; 
  1318.  
  1319.  
  1320. /** 
  1321. * Validate user input. 
  1322. * @since 2.0.0 
  1323. */  
  1324. function validate_main_options( $input ) { 
  1325.  
  1326. $valid['thumb_size'] = esc_attr( $input['thumb_size'] ); 
  1327. $valid['album_thumb_size'] = esc_attr( $input['album_thumb_size'] ); 
  1328. $valid['num_image_results'] = esc_attr( $input['num_image_results'] ); 
  1329. $valid['num_album_results'] = esc_attr( $input['num_album_results'] ); 
  1330. $valid['lightbox_image_size'] = esc_attr( $input['lightbox_image_size'] ); 
  1331. $valid['private_albums'] = esc_attr( $input['private_albums'] ); 
  1332.  
  1333. // Correct validation of checkboxes 
  1334. $valid['show_album_title'] = ( isset( $input['show_album_title'] ) && true == $input['show_album_title'] ? true : false ); 
  1335. $valid['show_album_details'] = ( isset( $input['show_album_details'] ) && true == $input['show_album_details'] ? true : false ); 
  1336.  
  1337. $valid['show_image_title'] = ( isset( $input['show_image_title'] ) && true == $input['show_image_title'] ? true : false ); 
  1338. $valid['enable_cache'] = ( isset( $input['enable_cache'] ) && true == $input['enable_cache'] ? true : false ); 
  1339. $valid['show_image_details'] = ( isset( $input['show_image_details'] ) && true == $input['show_image_details'] ? true : false ); 
  1340. $valid['enable_download'] = ( isset( $input['enable_download'] ) && true == $input['enable_download'] ? true : false ); 
  1341.  
  1342. return $valid; 
  1343. }  
  1344.  
  1345.  
  1346. /** 
  1347. * Validate user input. 
  1348. * @since 2.0.0 
  1349. */  
  1350. function validate_reset_options( $input ) { 
  1351.  
  1352. // Correct validation of checkboxes 
  1353. $valid['reset'] = ( isset( $input['reset'] ) && true == $input['reset'] ? true : false ); 
  1354.  
  1355. return $valid; 
  1356. }  
  1357.  
  1358.  
  1359. // Dispay upgrade notice 
  1360. function cws_gpp_admin_installed_notice( $userObj ) { 
  1361.  
  1362. // var_dump($userObj->ID); 
  1363.  
  1364. // check if already Pro 
  1365. if( !$this->isPro ) { 
  1366.  
  1367. // Check if user has dismissed notice previously 
  1368. // if ( ! get_user_meta( $current_user->getID(), 'cws_gpp_ignore_upgrade' ) )  
  1369. if ( ! get_user_meta( $userObj->ID, 'cws_gpp_ignore_upgrade' ) ) { 
  1370. global $pagenow; 
  1371. // Only show upgrade notice if on this page 
  1372. if ( $pagenow == 'options-general.php' || $pagenow == 'admin.php' ) { 
  1373. ?> 
  1374. <div id="message" class="updated cws-gpp-message"> 
  1375. <div class="squeezer"> 
  1376. <h4><?php _e( '<strong>Google Photos Viewer has been installed – Get the Pro version</strong>', 'cws_gpp_' ); ?></h4> 
  1377. <h4><?php _e( '<strong>GET 25% OFF! – use discount code WPMEGA25 on checkout</strong>', 'cws_gpp_' ); ?></h4> 
  1378. <p class="submit"> 
  1379. <a href="http://www.cheshirewebsolutions.com/?utm_source=cws_gpp_config&utm_medium=button&utm_content=upgrade_notice_message&utm_campaign=cws_gpp_plugin" class="button-primary"><?php _e( 'Visit Site', 'cws_gpp_' ); ?></a> 
  1380. <a href="<?php echo admin_url('admin.php?page=cws_gpp'); ?>" class="button-primary"><?php _e( 'Settings', 'cws_gpp_' ); ?></a> 
  1381. <a href="?cws_gpp_ignore_upgrade=0" class="secondary-button">Hide Notice</a> 
  1382. </p> 
  1383. </div> 
  1384. </div> 
  1385. <?php 
  1386. }  
  1387. } // end check if already dismissed 
  1388.  
  1389. } // end isPro check 
  1390.  
  1391. // Set installed option 
  1392. //update_option( 'cws_gpp_installed', 0); 
  1393.  
  1394.  
  1395. // If installed display upgrade notice 
  1396. function cws_gpp_admin_notices_styles() { 
  1397.  
  1398. // Installed notices 
  1399. if ( get_option( 'cws_gpp_installed' ) == 1 ) { 
  1400. // error_log("****** ADDING ACTION ADMIN NOTICES ********"); 
  1401. //add_action( 'admin_notices', 'cws_gpp_admin_installed_notice' );  
  1402. add_action( 'admin_notices', $this->cws_gpp_admin_installed_notice() );  
  1403.  
  1404. // Allow user to dismiss upgrade notice :) 
  1405. function cws_gpp_ignore_upgrade( $userObj2 ) {  
  1406.  
  1407. /** If user clicks to ignore the notice, add that to their user meta */ 
  1408. if ( isset( $_GET['cws_gpp_ignore_upgrade'] ) && '0' == $_GET['cws_gpp_ignore_upgrade'] ) { 
  1409. // add_user_meta($current_user->ID, 'cws_gpp_ignore_upgrade', 'true', true); 
  1410. add_user_meta($userObj2->ID, 'cws_gpp_ignore_upgrade', 'true', true); 
  1411.  
  1412. // Redirect to plugin settings page 
  1413. wp_redirect( admin_url( 'admin.php?page=cws_gpp' ) ); 
  1414. }  
  1415.  
  1416. // 
  1417.