/** * 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; } }
/** * 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; }
/** * 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()); } } }