public function __construct() { $this->updater = Vimeography::get_instance()->updater; add_action('vimeography_action_activate_license', array($this, 'activate_license')); add_action('vimeography_action_deactivate_license', array($this, 'deactivate_license')); self::_remove_duplicate_keys(); }
/** * Creates or returns an instance of this class. * * @return Vimeography A single instance of this class. */ public static function get_instance() { if (!isset(self::$instance) and !self::$instance instanceof Vimeography) { self::$instance = new self(); self::$instance->_define_constants(); self::$instance->_include_files(); Mustache_Autoloader::register(); if (is_admin()) { new Vimeography_Admin_Scripts(); new Vimeography_Admin_Actions(); new Vimeography_Base(); new Vimeography_Admin_Menu(); new Vimeography_Admin_Welcome(); new Vimeography_Admin_Plugins(); self::$instance->updater = new Vimeography_Update(); } // Can save these in public vars if need to access new Vimeography_Database(); new Vimeography_Upgrade(); new Vimeography_Deprecated(); new Vimeography_Init(); new Vimeography_Ajax(); self::$instance->addons = new Vimeography_Addons(); new Vimeography_Robots(); new Vimeography_Shortcode(); } return self::$instance; }
/** * Retrieve and set the meta headers for the current active theme. * * @param array Gallery settings */ protected function _set_active_theme($settings) { if (!isset($settings['theme'])) { throw new Vimeography_Exception(__('You must specify a theme in either the admin panel or the shortcode.', 'vimeography')); } $vimeography = Vimeography::get_instance(); $vimeography->addons->set_active_theme($settings['theme']); $this->_active_theme = $vimeography->addons->active_theme; }
/** * Checks the incoming form to make sure it is completed. * * @access protected * @return array $input */ protected static function _validate_form($input) { if (check_admin_referer('vimeography-gallery-action', 'vimeography-gallery-verification')) { if (empty($input['gallery_title']) or empty($input['source_url'])) { throw new Vimeography_Exception(__('Make sure you fill out both of the fields below!', 'vimeography')); } $input['resource_uri'] = Vimeography::validate_vimeo_source($input['source_url']); return $input; } }
/** * Runs before every test. * Think of it as emulating what would usually happen once the plugin is activated on a Wordpress site. * */ public function setUp() { parent::setUp(); $this->_vimeography = \Vimeography::get_instance(); // $z->installation_housekeeping(); // update_option('zam_options', array( // 'zam_twitter_id' => 'Wern_Ancheta' // )); //update_option('vimeography_db_version', VIMEOGRAPHY_VERSION); }
/** * Runs before every test. * Think of it as emulating what would usually happen once the plugin is activated on a Wordpress site. */ public function setUp() { parent::setUp(); $this->_class = new \Vimeography_Update(); $this->_addons = \Vimeography::get_instance()->addons; $entry = new \stdClass(); $entry->activation_key = 'ABCDEFED12345678'; $entry->product_name = 'Journey'; $entry->plugin_name = 'vimeography-journey'; $this->_fixture_activation_keys[] = $entry; $bugsauce = array('name' => 'Bugsauce', 'theme-uri' => 'vimeography.com/themes/bugsauce', 'version' => '1.0.2', 'description' => 'cool theme.', 'author' => 'Dave Kiss', 'author-uri' => 'http://davekiss.com', 'basename' => 'vimeography-bugsauce/vimeography-bugsauce.php', 'slug' => 'vimeography-bugsauce', 'thumbnail' => 'path/to/thumbnail.jpg', 'file_path' => realpath(dirname(__FILE__) . '/../fixtures/vimeography-journey/vimeography-journey.php'), 'plugin_path' => realpath(dirname(__FILE__) . '/../fixtures/vimeography-journey/'), 'type' => 'theme', 'partials_path' => 'path/to/partials', 'settings_file' => realpath(dirname(__FILE__) . '/../fixtures/vimeography-journey/settings.php')); $journey = array('name' => 'Journey', 'theme-uri' => 'vimeography.com/themes/journey', 'version' => '1.0.5', 'description' => 'cool theme.', 'author' => 'Dave Kiss', 'author-uri' => 'http://davekiss.com', 'basename' => 'vimeography-journey/vimeography-journey.php', 'slug' => 'vimeography-journey', 'thumbnail' => 'path/to/thumbnail.jpg', 'file_path' => realpath(dirname(__FILE__) . '/../fixtures/vimeography-journey/vimeography-journey.php'), 'plugin_path' => realpath(dirname(__FILE__) . '/../fixtures/vimeography-journey/'), 'type' => 'theme', 'partials_path' => 'path/to/partials', 'settings_file' => realpath(dirname(__FILE__) . '/../fixtures/vimeography-journey/settings.php')); $this->_addons->themes[0] = $bugsauce; $this->_addons->themes[] = $journey; $this->_addons->installed_addons[0] = $bugsauce; $this->_addons->installed_addons[] = $journey; }
/** * Creates the theme list to show in the appearance tab. * * @access public * @return array */ public function themes() { $themes = Vimeography::get_instance()->addons->themes; $activated_themes = get_option('vimeography_activation_keys'); $items = array(); foreach ($themes as $theme) { if (isset($this->_gallery)) { $theme['active'] = strtolower($theme['name']) == strtolower($this->_gallery[0]->theme_name) ? TRUE : FALSE; } if (is_array($activated_themes)) { foreach ($activated_themes as $activation) { if (strtolower($activation->plugin_name) == strtolower($theme['slug'])) { $theme['activation_key'] = TRUE; } } } $items[] = $theme; } return $items; }
/** * [_set_active_theme description] * @since 1.3 * @param string $theme_name [description] * @return array Theme meta */ private static function _set_active_theme($theme_name) { $vimeography = Vimeography::get_instance(); $vimeography->addons->set_active_theme($theme_name); return $vimeography->addons->active_theme; }
/** * Determines which gallery settings to use based on the provided * shortcode settings, the existing gallery db settings, and the * fallback gallery settings. * * @return array The gallery settings to be used to render the current gallery. */ private static function _apply_shortcode_gallery_settings($atts) { if (!empty($atts['id'])) { $db_gallery_settings = self::_get_db_gallery_settings(intval($atts['id'])); } // Get admin panel options $default_settings = get_option('vimeography_default_settings'); $fallback_gallery_settings = array(); $fallback_gallery_settings['theme'] = isset($db_gallery_settings->theme_name) ? $db_gallery_settings->theme_name : $default_settings['theme_name']; $fallback_gallery_settings['featured'] = isset($db_gallery_settings->featured_video) ? $db_gallery_settings->featured_video : $default_settings['featured_video']; $fallback_gallery_settings['endpoint'] = isset($db_gallery_settings->resource_uri) ? $db_gallery_settings->resource_uri : $default_settings['resource_uri']; $fallback_gallery_settings['limit'] = isset($db_gallery_settings->video_limit) ? $db_gallery_settings->video_limit : $default_settings['video_limit']; $fallback_gallery_settings['cache'] = isset($db_gallery_settings->cache_timeout) ? $db_gallery_settings->cache_timeout : $default_settings['cache_timeout']; $fallback_gallery_settings['width'] = isset($db_gallery_settings->gallery_width) ? $db_gallery_settings->gallery_width : ''; // Get shortcode attributes $shortcode_gallery_settings = shortcode_atts(array('theme' => $fallback_gallery_settings['theme'], 'featured' => $fallback_gallery_settings['featured'], 'source' => $fallback_gallery_settings['endpoint'], 'limit' => $fallback_gallery_settings['limit'], 'cache' => $fallback_gallery_settings['cache'], 'width' => $fallback_gallery_settings['width']), $atts, 'vimeography'); // Remove this line once 3.6 is the minimum supported version. $shortcode_gallery_settings = apply_filters('vimeography-pro/do-shortcode', $shortcode_gallery_settings, '', $atts); $shortcode_gallery_settings['width'] = self::_validate_gallery_width($shortcode_gallery_settings['width']); if ($shortcode_gallery_settings['source'] != $fallback_gallery_settings['endpoint']) { $shortcode_gallery_settings['source'] = Vimeography::validate_vimeo_source($shortcode_gallery_settings['source']); } $shortcode_gallery_settings['source'] = $shortcode_gallery_settings['source'] . '/videos'; return $shortcode_gallery_settings; }
/** * Add a plugins page message to any Vimeography add-ons that are installed, * but that do not have an activation key associated with the installation. * * @return void */ public function vimeography_check_for_missing_activation_keys() { $addons = Vimeography::get_instance()->addons->installed_addons; if (!empty($addons)) { // If the activation key is not found for the installed plugin, // add the plugin message hook $addons_with_missing_keys = array_filter($addons, array($this, 'vimeography_is_addon_missing_activation_key')); if (!empty($addons_with_missing_keys)) { foreach ($addons_with_missing_keys as $plugin) { $hook = 'after_plugin_row_' . $plugin['basename']; add_action($hook, array($this, 'vimeography_addon_update_message'), 10, 2); } } } }
/** * Creates a copy of the given gallery id in the database. * * @access public * @param array $params * @return void */ public function duplicate_gallery($params) { if (check_admin_referer('vimeography-duplicate-gallery-action', 'vimeography-duplicate-gallery-verification')) { if (isset($params['vimeography_duplicate_gallery_serialized']) and !empty($params['vimeography_duplicate_gallery_serialized'])) { $params = unserialize(stripslashes($params['vimeography_duplicate_gallery_serialized'])); } if (isset($params['duplicate_appearance'])) { // Do filesystem stuffs here… a simple file_put_contents would be nice. $_POST['vimeography_duplicate_gallery_serialized'] = serialize($params); $url = wp_nonce_url(network_admin_url(add_query_arg(array('page' => 'vimeography-edit-galleries'), 'admin.php')), 'vimeography-duplicate-gallery-action', 'vimeography-duplicate-gallery-verification'); $filesystem = new Vimeography_Filesystem($url, array('vimeography_duplicate_gallery_serialized', 'vimeography-action')); if ($filesystem->connect()) { $filesystem_connection = TRUE; } else { exit; } } try { $id = intval($params['gallery_id']); $title = $params['gallery_title']; $source_url = $params['gallery_source']; $resource_uri = Vimeography::validate_vimeo_source($params['gallery_source']); if (empty($title)) { throw new Vimeography_Exception(__('Make sure to give your new gallery a name!', 'vimeography')); } global $wpdb; $duplicate = $wpdb->get_results('SELECT * from ' . VIMEOGRAPHY_GALLERY_META_TABLE . ' AS meta JOIN ' . VIMEOGRAPHY_GALLERY_TABLE . ' AS gallery ON meta.gallery_id = gallery.id WHERE meta.gallery_id = ' . $id . ' LIMIT 1;'); $result = $wpdb->insert(VIMEOGRAPHY_GALLERY_TABLE, array('title' => $title, 'date_created' => current_time('mysql'), 'is_active' => 1)); if ($result === FALSE) { throw new Vimeography_Exception(__('Your gallery could not be duplicated.', 'vimeography')); } $gallery_id = $wpdb->insert_id; $result = $wpdb->insert(VIMEOGRAPHY_GALLERY_META_TABLE, array('gallery_id' => $gallery_id, 'source_url' => $source_url, 'video_limit' => $duplicate[0]->video_limit, 'featured_video' => $duplicate[0]->featured_video, 'cache_timeout' => $duplicate[0]->cache_timeout, 'theme_name' => $duplicate[0]->theme_name, 'resource_uri' => $resource_uri)); if ($result === FALSE) { throw new Vimeography_Exception(__('Your gallery could not be duplicated.', 'vimeography')); } if (isset($filesystem_connection)) { $old_filename = 'vimeography-gallery-' . $id . '-custom.css'; $old_filepath = VIMEOGRAPHY_CUSTOMIZATIONS_PATH . $old_filename; $search_string = '#vimeography-gallery-' . $id; $new_filename = 'vimeography-gallery-' . $gallery_id . '-custom.css'; $new_filepath = VIMEOGRAPHY_CUSTOMIZATIONS_PATH . $new_filename; $replace_string = '#vimeography-gallery-' . $gallery_id; global $wp_filesystem; if ($wp_filesystem->exists(VIMEOGRAPHY_CUSTOMIZATIONS_PATH)) { if ($wp_filesystem->exists($old_filepath) and $wp_filesystem->is_file($old_filepath)) { $old_css = $wp_filesystem->get_contents($old_filepath); $new_css = str_ireplace($search_string, $replace_string, $old_css); // If there is an error, output a message for the user to see if (!$wp_filesystem->put_contents($new_filepath, $new_css, FS_CHMOD_FILE)) { throw new Vimeography_Exception(__('There was an error writing your file. Please try again!', 'vimeography')); } } } } do_action('vimeography-pro/duplicate-gallery', $id, $gallery_id); do_action('vimeography/reload-galleries'); $this->messages[] = array('type' => 'updated', 'heading' => __('Gallery duplicated.', 'vimeography'), 'message' => __('You now have a clone of your own.', 'vimeography')); } catch (Vimeography_Exception $e) { $this->messages[] = array('type' => 'error', 'heading' => __('Ruh Roh.', 'vimeography'), 'message' => $e->getMessage()); } } }
/** * Retrieve and store more information about any saved license keys. * * @return void */ public static function vimeography_update_db_to_1_2_8() { if (version_compare(self::$_version, '1.2.8', '<')) { $licenses = get_site_option('vimeography_activation_keys'); if (!class_exists('Vimeography_Update')) { require_once VIMEOGRAPHY_PATH . 'lib/update.php'; $updater = new Vimeography_Update(); } else { $updater = Vimeography::get_instance()->updater; } if ($licenses) { foreach ($licenses as $index => $license) { // Retrieve more information about the license $result = $updater->check_license($license); $license->status = $result->license; $license->expires = $result->expires; $license->limit = $result->license_limit; $license->activations_left = $result->activations_left; $licenses[$index] = $license; } update_site_option('vimeography_activation_keys', $licenses); } } }