/**
  * @param $extensions
  */
 public function __construct($extensions)
 {
     $apg_addon_manager = new Addonmanager($extensions);
     $this->extensions = $extensions;
     $this->addons = $apg_addon_manager->get_addons();
     if (($page = filter_input(INPUT_GET, 'createpage')) && $page !== '') {
         $nonce = filter_input(INPUT_GET, 'apg_nonce');
         if (current_user_can('edit_posts') && wp_verify_nonce($nonce, 'apg-create-page-nonce')) {
             $this->create_apg_page();
         }
     }
 }
 /**
  * Render the upload page for new photos (and handle the initial post request to upload new photos)
  */
 public function render()
 {
     wp_enqueue_media();
     if (isset($_POST['apg_photo_uploader_nonce'], $_POST['photoalbum']) && wp_verify_nonce($_POST['apg_photo_uploader_nonce'], 'apg_photo_uploader_nonce') && current_user_can('edit_post', $_POST['photoalbum'])) {
         $results = $this->handle_upload_post();
         if ($results['success'] >= 1 && $results['failures'] === 0) {
             // Succes!
             $this->apg_success(__('Your photo(s) are uploaded successfully to the album!', 'apg') . ' <a href="' . admin_url('post.php?post=' . esc_attr($_POST['photoalbum']) . '&action=edit') . '" class="button">' . __('View album', 'apg') . '</a>');
         } else {
             // Failure
             $this->error = $results['error'];
             $this->apg_error();
         }
     }
     $this->template['photoalbums'] = $this->get_all_photo_albums();
     $addons = new Addonmanager($this->extensions);
     $this->render_view('backend/upload', $addons->get_addons());
 }
 /**
  * Render the settings page
  */
 public function render()
 {
     if (isset($_POST['apg_photo_settings_nonce'], $_POST['apg_settings']) && wp_verify_nonce($_POST['apg_photo_settings_nonce'], 'apg_photo_settings_nonce') && current_user_can('manage_options')) {
         $results = $this->handle_upload_post();
         if ($results === true) {
             $this->save_options();
             $this->extensions = apply_filters('apg_extensions', array());
             $this->apg_success(__('Your new settings are saved successfully!', 'apg'));
         } else {
             // Failure
             $this->error = $results['error'];
             if (empty($this->error)) {
                 $this->error = __('There are no changes to save.', 'apg');
             }
             $this->apg_error();
         }
     }
     $apg_licenses = new Licenses($this->extensions);
     $this->template['settings'] = array();
     $this->template['settings']['extensions'] = $this->extensions;
     $this->template['settings']['licenses'] = $apg_licenses->get_licenses();
     $this->template['settings']['gallery'] = $this->get('gallery');
     $this->template['settings']['thumb_size'] = (int) $this->get('thumb_size');
     $this->template['settings']['album_description'] = $this->get('album_description');
     $this->template['settings']['disable_frontend_css'] = (bool) $this->get('disable_frontend_css');
     $this->template['settings']['disable_frontend_js'] = (bool) $this->get('disable_frontend_js');
     $this->template['settings']['archive_limit'] = (int) $this->get('archive_limit');
     $this->template['settings']['enable_slideshow'] = (bool) $this->get('enable_slideshow');
     $this->template['settings']['slideshow_timeout'] = (int) $this->get('slideshow_timeout');
     $this->template['settings']['slideshow_autostart'] = (bool) $this->get('slideshow_autostart');
     $this->template['settings']['enable_thumb_shadow'] = (bool) $this->get('enable_thumb_shadow');
     $this->template['settings']['thumb_shadow_color'] = $this->get('thumb_shadow_color');
     $this->template['settings']['thumb_shadow_width'] = $this->get('thumb_shadow_width');
     $this->template['settings']['thumb_border_width'] = $this->get('thumb_border_width');
     $this->template['settings']['thumb_border_color'] = $this->get('thumb_border_color');
     $this->template['settings']['google_analytics_event'] = (bool) $this->get('google_analytics_event');
     /**
      * Filter API: add extra fields here with the values, in order to work in the template views
      */
     $this->template['settings'] = apply_filters('apg_settings_fields', $this->template['settings']);
     /**
      * Checks whether Awesome Google Analytics is installed or not
      */
     $this->template['installed_aga'] = defined('AGA_VERSION');
     if ($this->template['installed_aga']) {
         $aga = get_option('aga', array());
         if (!isset($aga['ua_code'])) {
             $aga['ua_code'] = __('not set', 'aga');
         }
         $this->template['ga_ua_code'] = $aga['ua_code'];
     }
     // Manage Add-ons
     $addons = new Addonmanager($this->extensions);
     $this->template['addons'] = $addons->get_addons();
     $this->template['addons_full'] = $this->extensions;
     $this->render_view('backend/settings', $addons->get_addons());
 }