Ejemplo n.º 1
0
 /**
  * Creates a static custom stylesheet based on any customizations
  * the user has made to their gallery. This allows for selective namespacing
  * of the CSS selectors, giving much more control over what we target.
  *
  * This is super rad.
  *
  * @return void
  */
 public function vimeography_validate_theme_settings($input)
 {
     if (isset($input['vimeography_theme_settings_serialized']) and !empty($input['vimeography_theme_settings_serialized'])) {
         $input = unserialize(stripslashes($input['vimeography_theme_settings_serialized']));
     } else {
         $input = $input['vimeography_theme_settings'];
     }
     // if this fails, check_admin_referer() will automatically print a "failed" page and die.
     if (check_admin_referer('vimeography-theme-settings-action', 'vimeography-theme-settings-verification')) {
         try {
             $settings = array();
             foreach ($input as $setting) {
                 $attributes = array();
                 foreach ($setting['attributes'] as $attribute) {
                     $attributes[] = self::_convert_jquery_css_attribute($attribute);
                 }
                 $setting['attributes'] = $attributes;
                 if (isset($setting['expressions']) and !empty($setting['expressions'])) {
                     foreach ($setting['expressions'] as $selector => $attributes) {
                         foreach ($attributes as $attribute => $value) {
                             $new_attr = self::_convert_jquery_css_attribute($attribute);
                             unset($setting['expressions'][$selector][$attribute]);
                             $setting['expressions'][$selector][$new_attr] = $value;
                         }
                     }
                 }
                 $targets = array();
                 foreach ($setting['targets'] as $target) {
                     $targets[] = esc_attr($target);
                 }
                 $setting['targets'] = $targets;
                 $setting['value'] = esc_attr($setting['value']);
                 $settings[] = $setting;
             }
             // Settings are ready to be generated.
             $css = '';
             $filename = 'vimeography-gallery-' . $this->_gallery_id . '-custom.css';
             $filepath = VIMEOGRAPHY_CUSTOMIZATIONS_PATH . $filename;
             foreach ($settings as $setting) {
                 $namespace = $setting['namespace'] == TRUE ? '#vimeography-gallery-' . $this->_gallery_id : '';
                 $important = isset($setting['important']) ? ' !important' : '';
                 $target_count = count($setting['targets']);
                 for ($i = 0; $i < $target_count; $i++) {
                     // If this is an expression, change the value to the expression value calculated by the appearance widget.
                     if (isset($setting['expressions']) and array_key_exists($setting['targets'][$i], $setting['expressions'])) {
                         if (array_key_exists($setting['attributes'][$i], $setting['expressions'][$setting['targets'][$i]])) {
                             $setting['value'] = $setting['expressions'][$setting['targets'][$i]][$setting['attributes'][$i]];
                         }
                     }
                     $css .= $namespace . $setting['targets'][$i] . ' { ' . $setting['attributes'][$i] . ': ' . $setting['value'] . $important . "; } \n";
                 }
             }
             // Do filesystem stuffs here… a simple file_put_contents would be nice.
             $_POST['vimeography_theme_settings_serialized'] = serialize($input);
             $url = wp_nonce_url(network_admin_url(add_query_arg(array('page' => 'vimeography-edit-galleries', 'id' => $this->_gallery_id), 'admin.php')), 'vimeography-theme-settings-action', 'vimeography-theme-settings-verification');
             $filesystem = new Vimeography_Filesystem($url, array('vimeography_theme_settings_serialized', 'vimeography-action'));
             if ($filesystem->connect()) {
                 global $wp_filesystem;
                 if (!$wp_filesystem->exists(VIMEOGRAPHY_CUSTOMIZATIONS_PATH)) {
                     if (!wp_mkdir_p(VIMEOGRAPHY_CUSTOMIZATIONS_PATH)) {
                         throw new Exception(__('Vimeography could not create the customizations directory.', 'vimeography'));
                     }
                 }
                 // If there is an error, output a message for the user to see
                 if (!$wp_filesystem->put_contents($filepath, $css, FS_CHMOD_FILE)) {
                     throw new Exception(__('There was an error writing your file. Please try again!', 'vimeography'));
                 }
             } else {
                 exit;
             }
             $this->messages[] = array('type' => 'updated', 'heading' => __('Theme updated.', 'vimeography'), 'message' => __("I didn't know that you were such a great designer!", 'vimeography'));
         } catch (Exception $e) {
             $this->messages[] = array('type' => 'error', 'heading' => __('Oh no!', 'vimeography'), 'message' => $e->getMessage());
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * 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());
         }
     }
 }