Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated vendor module Pf4wp to Github location

  • Loading branch information...
commit b399e86b5a662749b7b59bee205579e25bfaf7f7 1 parent 6f9872b
@Myatu authored
View
2  .gitmodules
@@ -3,4 +3,4 @@
url = http://github.com/fabpot/Twig.git
[submodule "vendor/pf4wp"]
path = vendor/pf4wp
- url = git://projects.emixode.net/pf4wp.git
+ url = git://github.com/Myatu/pf4wp.git
View
66 app/Myatu/WordPress/BackgroundManager/Importers/WpFlickrBackground.php
@@ -20,27 +20,13 @@
* @package BackgroundManager
* @subpackage Importers
*/
-class WpFlickrBackground
+class WpFlickrBackground extends Importer
{
const WP_OPTION_NAME = 'wp-flickr-background';
- /**
- * Protected constructor, as this is a purely static class
- */
- protected function __construct() {}
-
- /**
- * Returns information about the importer
- *
- * @return array
- */
- static public function info()
- {
- return array(
- 'name' => 'WP Flickr Background Importer',
- 'desc' => 'Imports the galleries from WP Flickr Background into the Background Manager.'
- );
- }
+ // Overrides
+ const NAME = 'WP Flickr Background Importer';
+ const DESC = 'Imports the galleries from WP Flickr Background into the Background Manager.';
static public function preImport(Main $main)
{
@@ -52,27 +38,11 @@ static public function preImport(Main $main)
* Imports galleries from WP Flickr Background
*
* @param object $main The object of the Main class
- * @return array Array of import errors, if any.
*/
- static public function import(Main $main)
+ static public function doImport(Main $main)
{
global $wpdb;
- $setProgress = function($percentage) { echo '<script type="text/javascript">/* <![CDATA[ */ mainWin.doImportProgress(' . $percentage . '); /* ]]> */</script>'; };
-
- /* Prevent this function from timing out, and set implicit flush on output buffer writes */
- set_time_limit(0);
- ignore_user_abort(true);
- while (ob_get_level())
- ob_end_clean();
- ob_implicit_flush(true);
-
- echo '<!DOCTYPE html><html><head></head><body><script type="text/javascript">/* <![CDATA[ */ mainWin = window.dialogArguments || opener || parent || top; /* ]]> */</script>';
-
- echo $_REQUEST['test'];
-
- $errors = array();
-
// Ensure we have valid options
if (($options = get_option(static::WP_OPTION_NAME)) === false || !array_key_exists('galleries', $options) || !is_array($options['galleries']) || count($options['galleries']) == 0)
return;
@@ -85,8 +55,8 @@ static public function import(Main $main)
$chunk = 0;
// TESTING!!!!
- for ($i = 1; $i < 101; $i++) {
- $setProgress($i);
+ for ($i = 1; $i < 20; $i++) {
+ static::setProgress($i);
sleep(1);
}
return;
@@ -94,10 +64,8 @@ static public function import(Main $main)
foreach ($options['galleries'] as $wpfbg_gallery) {
$gallery_id = $galleries->save(0, $wpfbg_gallery['name'], $wpfbg_gallery['desc']);
- if (!$gallery_id) {
- $errors[] = sprintf(__('Could not import gallery \'%s\'', $main->getName()), $wpfbg_gallery['name']);
+ if (!$gallery_id)
continue;
- }
// If we have custom CSS, add this as a meta to the gallery
if (!empty($wpfbg_gallery['customcss']))
@@ -106,10 +74,7 @@ static public function import(Main $main)
foreach ($wpfbg_gallery['photos'] as $photo) {
if ($photo['id'][0] != 'L') {
// Images that do not start with an "L" are only available via a remote URL.
- $r = media_sideload_image($photo['background'], $gallery_id);
-
- if (is_wp_error($r))
- $errors[] = sprintf(__('Could not import remote image from \'%s\'', $main->getName()), $photo['background']);
+ media_sideload_image($photo['background'], $gallery_id);
} else {
// Strip any -DDDxDDD from the filename within the URL
$background_image_url = preg_replace('#^(.*?)(-\d{2,4}x\d{2,4}(?=\.))(.*)$#', '$1$3', $photo['background']);
@@ -118,25 +83,16 @@ static public function import(Main $main)
$background_image_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM `{$wpdb->posts}` WHERE `guid` = %s", $background_image_url));
// Change the parent of the image attachment to that of the gallery
- if ($background_image_id && ($image = get_post($background_image_id))) {
+ if ($background_image_id && ($image = get_post($background_image_id)))
wp_insert_attachment($image, false, $gallery_id);
- } else {
- $errors[] = sprintf(__('Could not import local image at \'%s\'', $main->getName()), $photo['background']);
- }
}
}
$chunk++;
- $setProgress($chunk * $chunks);
+ static::setProgress($chunk * $chunks);
}
unset($galleries);
unset($images);
-
- // Finalize progress bar
- $setProgress(100);
- echo '</body></html>';
-
- return $errors;
}
}
View
53 app/Myatu/WordPress/BackgroundManager/Main.php
@@ -369,7 +369,7 @@ public function getSettingGalleries($active_gallery)
'orderby' => 'title',
'order' => 'ASC',
'numberposts' => 0,
- 'post_type' => \Myatu\WordPress\BackgroundManager\Main::PT_GALLERY)
+ 'post_type' => static::PT_GALLERY)
);
foreach ($gallery_posts as $gallery_post) {
@@ -439,7 +439,7 @@ public function getSettingOverlays($active_overlay)
}
// Sort overlays
- usort($overlays, function($a, $b){ return strcmp($a['desc'], $b['desc']); });
+ usort($overlays, function($a, $b){ return strcasecmp($a['desc'], $b['desc']); });
return $overlays;
}
@@ -447,24 +447,35 @@ public function getSettingOverlays($active_overlay)
/**
* Obtains an array of available Importers
*
- * @return array Array containing a list of importers, indexed by classname, containing a display name and description.
+ * @filter myatu_bgm_importers
+ * @return array Array containing a list of importers, indexed by classname, containing a display name, description and namespace+class.
*/
protected function getImporters()
{
$importers = array();
$iterator = new \RecursiveIteratorIterator(new \Pf4wp\Storage\IgnorantRecursiveDirectoryIterator($this->getPluginDir() . static::DIR_IMPORTERS, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST);
- $files = iterator_to_array(new \RegexIterator($iterator, '/^.+\.php$/i', \RecursiveRegexIterator::GET_MATCH));
+ $files = iterator_to_array(new \RegexIterator($iterator, '/^.+\.php?$/i', \RecursiveRegexIterator::GET_MATCH));
foreach ($files as $file) {
- try {
- $class_name = basename($file[0], '.php');
- $class = __NAMESPACE__ . '\\Importers\\' . $class_name;
-
- // Obtain information about the Importer, and add it to the array
- $importers[$class_name] = $class::info();
- } catch (Exception $e) {}
+ $class_name = basename($file[0], '.php');
+ $class = __NAMESPACE__ . '\\Importers\\' . $class_name;
+
+ // Obtain information about the Importer, and add it to the array
+ if (is_callable($class . '::info'))
+ $importers[$class_name] = array_merge($class::info(), array('class' => $class));
}
+ // Allow filtering of importers
+ $importers = apply_filters('myatu_bgm_importers', $importers);
+
+ // Classes must be a subclass of Importers\Importer
+ foreach ($importers as $importer_key => $importer)
+ if (!is_subclass_of($importer['class'], __NAMESPACE__ . '\\Importers\\Importer'))
+ unset($importers[$importer_key]);
+
+ // Sort importers by name
+ uasort($importers, function($a, $b){ return strcasecmp($a['name'], $b['name']); });
+
return $importers;
}
@@ -1114,6 +1125,9 @@ public function onTrashMenu($data, $per_page)
/**
* Import Menu Loader
+ *
+ * This will check the form response for a valid import job request, and
+ * performs it accordingly.
*/
public function onImportMenuLoad($current_screen)
{
@@ -1126,12 +1140,11 @@ public function onImportMenuLoad($current_screen)
$importer = $_REQUEST['run_import_job'];
if (array_key_exists($importer, $importers)) {
- $class = __NAMESPACE__ . '\\Importers\\' . $importer;
+ $class = $importers[$importer]['class'];
// Run import job
- $class::import($this);
-
- die();
+ if (is_callable($class . '::import'))
+ $class::import($this);
}
}
@@ -1161,15 +1174,17 @@ public function onImportMenu($data)
} else {
// Obtain any pre-import information from the user, if required
if (empty($_POST['pre_import_done'])) {
- $class = __NAMESPACE__ . '\\Importers\\' . $importer;
- $pre_import = $class::preImport($this);
+ $class = $importers[$importer]['class'];
+
+ if (is_callable($class . '::preImport'))
+ $pre_import = $class::preImport($this);
}
// Scrub POST variables, and pass them on to the import job source args
$args = array();
foreach ($_POST as $post_key => $post_val) {
- $post_key = preg_replace('#_desc$#', '', $post_key);
+ $post_key = preg_replace('#_desc$#', '', $post_key); // Both regular class names and descriptions are ignored
if (!array_key_exists($post_key, $importers) &&
!in_array($post_key, array('_nonce', 'submit', 'importer', 'pre_import_done', '_wp_http_referer')))
@@ -1186,7 +1201,7 @@ public function onImportMenu($data)
'submit_button' => get_submit_button('Import'),
'importers' => $importers,
'importer' => $importer,
- 'show_pre_import' => (!empty($pre_import)),
+ 'show_pre_import' => (!empty($importer) && !empty($pre_import)),
'pre_import' => $pre_import,
'run_import' => (!empty($importer) && empty($pre_import)),
'import_job_src' => $import_job_src,
View
1  resources/css/pub.css
@@ -77,3 +77,4 @@
z-index: -1999;
}
+
View
8 resources/js/pub.dev.js
@@ -63,7 +63,6 @@
$(document).ready(function($){
myatu_bgm.SetTimer();
- // Activate balloon tip
if ($.isFunction($('#myatu_bgm_info_tab').bt)) {
$('#myatu_bgm_info_tab').bt({
contentSelector: "$('.myatu_bgm_info_tab_content')",
@@ -91,15 +90,14 @@
shadowOffsetX: 4,
shadowOffsetY: 4,
showTip: function(box) {
- /* Only show the tip if there's something to show. As content is dynamic, we use this callback for that. */
+ // Only show the tip if there's something to show. As content is dynamic, we use this callback for that.
if (!$('.myatu_bgm_info_tab_content img').attr('src') &&
!$('.myatu_bgm_info_tab_desc').text() &&
!$('.myatu_bgm_info_tab_content h3').text())
return;
- /* Only set to width to 'auto' if there's no description. This maintains the
- * width (and float of image) if there's something present and prevents overflow if shrunk.
- */
+ // Only set to width to 'auto' if there's no description. This maintains the
+ // width (and float of image) if there's something present and prevents overflow if shrunk.
if ($('.myatu_bgm_info_tab_desc').text() == '')
$(box).css('width', 'auto');
Please sign in to comment.
Something went wrong with that request. Please try again.