/**
  * Retrieves and caches an I_Gallery_Mapper instance for this gallery id
  *
  * @param int $gallery_id Gallery ID
  * @return mixed
  */
 public function get_gallery($gallery_id)
 {
     if (!isset($this->galleries[$gallery_id]) || is_null($this->galleries[$gallery_id])) {
         $this->galleries[$gallery_id] = C_Component_Registry::get_instance()->get_utility('I_Gallery_Mapper');
     }
     return $this->galleries[$gallery_id];
 }
 function getData($number)
 {
     global $wpdb;
     $data = array();
     $pictures = $wpdb->get_results("SELECT a.*, b.path FROM " . $wpdb->base_prefix . "ngg_pictures AS a LEFT JOIN " . $wpdb->base_prefix . "ngg_gallery AS b ON a.galleryid = b.gid WHERE a.galleryid = '" . intval($this->_data->get('nggsourcegallery', 0)) . "'");
     $i = 0;
     if (class_exists('nggGallery') && !class_exists('C_Component_Registry')) {
         // legacy
         foreach ($pictures as $p) {
             $data[$i]['alt_text'] = $p->alttext;
             $data[$i]['image'] = nggGallery::get_image_url($p->pid, $p->path, $p->filename);
             $data[$i]['thumbnail'] = nggGallery::get_thumbnail_url($p->pid, $p->path, $p->filename);
             $i++;
         }
     } else {
         $storage = C_Component_Registry::get_instance()->get_utility('I_Gallery_Storage');
         foreach ($pictures as $p) {
             $data[$i]['alt_text'] = $p->alttext;
             $data[$i]['image'] = $storage->get_image_url($p);
             $data[$i]['thumbnail'] = $storage->get_thumbnail_url($p);
             $i++;
         }
     }
     return $data;
 }
 function render_related_string()
 {
     $settings = C_NextGen_Settings::get_instance();
     $type = $settings->appendType;
     $maxImages = $settings->maxImages;
     $sluglist = array();
     switch ($type) {
         case 'tags':
             if (function_exists('get_the_tags')) {
                 $taglist = get_the_tags();
                 if (is_array($taglist)) {
                     foreach ($taglist as $tag) {
                         $sluglist[] = $tag->slug;
                     }
                 }
             }
             break;
         case 'category':
             $catlist = get_the_category();
             if (is_array($catlist)) {
                 foreach ($catlist as $cat) {
                     $sluglist[] = $cat->category_nicename;
                 }
             }
             break;
     }
     $taglist = implode(',', $sluglist);
     if ($taglist === 'uncategorized' || empty($taglist)) {
         return;
     }
     $renderer = C_Component_Registry::get_instance()->get_utility('I_Displayed_Gallery_Renderer');
     $view = C_Component_Registry::get_instance()->get_utility('I_Component_Factory')->create('mvc_view', '');
     $retval = $renderer->display_images(array('source' => 'tags', 'container_ids' => $taglist, 'display_type' => NEXTGEN_GALLERY_BASIC_THUMBNAILS, 'images_per_page' => $maxImages, 'maximum_entity_count' => $maxImages, 'template' => $view->get_template_abspath('photocrati-nextgen_gallery_display#related'), 'show_all_in_lightbox' => FALSE, 'show_slideshow_link' => FALSE, 'disable_pagination' => TRUE));
     return apply_filters('ngg_show_related_gallery_content', $retval, $taglist);
 }
 function enqueue_displayed_gallery_trigger_buttons_resources($displayed_gallery = FALSE)
 {
     if (!wp_style_is('fontawesome', 'registered')) {
         if (strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'microsoft-iis') !== FALSE) {
             wp_register_style('fontawesome', site_url('/?ngg_serve_fontawesome_css=1'));
         } else {
             $router = C_Component_Registry::get_instance()->get_utility('I_Router');
             wp_register_style('fontawesome', $router->get_static_url('photocrati-nextgen_gallery_display#fontawesome/font-awesome.css'));
         }
     }
     if (!$this->run_once && !empty($displayed_gallery) && !empty($displayed_gallery->display_settings['ngg_triggers_display']) && $displayed_gallery->display_settings['ngg_triggers_display'] !== 'never') {
         $pro_active = FALSE;
         if (defined('NGG_PRO_PLUGIN_VERSION')) {
             $pro_active = 'NGG_PRO_PLUGIN_VERSION';
         }
         if (defined('NEXTGEN_GALLERY_PRO_VERSION')) {
             $pro_active = 'NEXTGEN_GALLERY_PRO_VERSION';
         }
         if (!empty($pro_active)) {
             $pro_active = constant($pro_active);
         }
         if (!is_admin() && (empty($pro_active) || version_compare($pro_active, '1.0.11') >= 0)) {
             wp_enqueue_style('fontawesome');
             $this->run_once = TRUE;
         }
     }
 }
Example #5
0
 /**
  * Gets the Pope component registry
  * @return C_Component_Registry
  */
 function get_registry()
 {
     if (!isset($this->_registry)) {
         $this->_registry = C_Component_Registry::get_instance();
     }
     return $this->_registry;
 }
 /**
  * Returns a singleton
  * @return C_Component_Registry()
  */
 static function &get_instance()
 {
     if (is_null(self::$_instance)) {
         $klass = get_class();
         self::$_instance = new $klass();
     }
     return self::$_instance;
 }
Example #7
0
 /**
  * Parses certain paths through get_static_url
  *
  * @param string $url
  * @return string Resulting URL
  */
 static function _handle_url($url)
 {
     $router = C_Component_Registry::get_instance()->get_utility('I_Router');
     if (0 !== strpos($url, '/') && 0 !== strpos($url, 'wordpress#') && 0 !== strpos($url, 'http://') && 0 !== strpos($url, 'https://')) {
         $url = $router->get_static_url($url);
     } elseif (strpos($url, '/') === 0) {
         $url = home_url($url);
     }
     return $url;
 }
 static function _generate_module_info()
 {
     $retval = array();
     $registry = C_Component_Registry::get_instance();
     foreach ($registry->get_module_list() as $module_id) {
         $module_version = $registry->get_module($module_id)->module_version;
         $retval[$module_id] = "{$module_id}|{$module_version}";
     }
     return $retval;
 }
 function _filter_modules($pope_modules_list, $product)
 {
     foreach ($product as $module_name) {
         $module = C_Component_Registry::get_instance()->get_module($module_name);
         $str = $module->module_id . '|' . $module->module_version;
         $search = array_search($str, $pope_modules_list);
         if (FALSE !== $search) {
             unset($pope_modules_list[$search]);
         }
     }
     return $pope_modules_list;
 }
Example #10
0
 function render_slideshow($galleryID, $irWidth = '', $irHeight = '', $args)
 {
     $registry = C_Component_Registry::get_instance();
     $renderer = $registry->get_utility('I_Displayed_Gallery_Renderer');
     $params = array('container_ids' => $galleryID, 'display_type' => 'photocrati-nextgen_basic_slideshow', 'gallery_width' => $irWidth, 'gallery_height' => $irHeight, 'source' => 'galleries', 'slug' => 'widget-' . $args['widget_id'], 'entity_types' => array('image'), 'show_thumbnail_link' => FALSE, 'ngg_triggers_display' => 'never');
     if (0 === $galleryID) {
         $params['source'] = 'random_images';
         unset($params['container_ids']);
     }
     $retval = $renderer->display_images($params, NULL);
     $retval = apply_filters('ngg_show_slideshow_widget_content', $retval, $galleryID, $irWidth, $irHeight);
     return $retval;
 }
Example #11
0
 function widget($args, $instance)
 {
     // these are handled by extract() but I want to silence my IDE warnings that these vars don't exist
     $before_widget = NULL;
     $before_title = NULL;
     $after_widget = NULL;
     $after_title = NULL;
     $widget_id = NULL;
     extract($args);
     $settings = C_NextGen_Settings::get_instance();
     $parent = C_Component_Registry::get_instance()->get_utility('I_Widget');
     $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title'], $instance, $this->id_base);
     $parent->render_partial('photocrati-widget#display_mediarss', array('self' => $this, 'instance' => $instance, 'title' => $title, 'settings' => $settings, 'before_widget' => $before_widget, 'before_title' => $before_title, 'after_widget' => $after_widget, 'after_title' => $after_title, 'widget_id' => $widget_id));
 }
Example #12
0
function media_upload_nextgen()
{
    // Not in use
    $errors = false;
    // Generate TinyMCE HTML output
    if (isset($_POST['send'])) {
        $keys = array_keys($_POST['send']);
        $send_id = (int) array_shift($keys);
        $image = $_POST['image'][$send_id];
        $alttext = stripslashes(htmlspecialchars($image['alttext'], ENT_QUOTES));
        $description = stripslashes(htmlspecialchars($image['description'], ENT_QUOTES));
        // here is no new line allowed
        $clean_description = preg_replace("/\n|\r\n|\r\$/", " ", $description);
        $img = nggdb::find_image($send_id);
        $thumbcode = $img->get_thumbcode();
        $class = "ngg-singlepic ngg-{$image['align']}";
        // Create a shell displayed-gallery so we can inspect its settings
        $registry = C_Component_Registry::get_instance();
        $mapper = $registry->get_utility('I_Displayed_Gallery_Mapper');
        $factory = $registry->get_utility('I_Component_Factory');
        $args = array('display_type' => NGG_BASIC_SINGLEPIC);
        $displayed_gallery = $factory->create('displayed_gallery', $args, $mapper);
        $width = $displayed_gallery->display_settings['width'];
        $height = $displayed_gallery->display_settings['height'];
        // Build output
        if ($image['size'] == "thumbnail") {
            $html = "<img src='{$image['thumb']}' alt='{$alttext}' class='{$class}' />";
        } else {
            $html = '';
        }
        // Wrap the link to the fullsize image around
        $html = "<a {$thumbcode} href='{$image['url']}' title='{$clean_description}'>{$html}</a>";
        if ($image['size'] == "full") {
            $html = "<img src='{$image['url']}' alt='{$alttext}' class='{$class}' />";
        }
        if ($image['size'] == "singlepic") {
            $html = "[singlepic id={$send_id} w={$width} h={$height} float={$image['align']}]";
        }
        media_upload_nextgen_save_image();
        // Return it to TinyMCE
        return media_send_to_editor($html);
    }
    // Save button
    if (isset($_POST['save'])) {
        media_upload_nextgen_save_image();
    }
    return wp_iframe('media_upload_nextgen_form', $errors);
}
 function enqueue_nextgen_proofing_trigger_buttons_resources($displayed_gallery = FALSE)
 {
     $retval = FALSE;
     if (!$this->run_once && !empty($displayed_gallery) && !empty($displayed_gallery->display_settings['ngg_proofing_display'])) {
         $router = C_Component_Registry::get_instance()->get_utility('I_Router');
         wp_enqueue_script('jquery-placeholder', $router->get_static_url('photocrati-nextgen_admin#jquery.placeholder.min.js'), 'jquery', FALSE, FALSE);
         wp_enqueue_script('ngg-pro-proofing-script', $router->get_static_url('photocrati-nextgen_pro_proofing#nextgen_pro-proofing.js'), array('jquery', 'underscore', 'jquery-placeholder'), FALSE, FALSE);
         wp_localize_script('ngg-pro-proofing-script', 'ngg_pro_proofing_i18n', array('image_list' => __('Submitting {0} image{1}', 'nextgen-gallery-pro'), 'submit_cancel' => __('Cancel', 'nextgen-gallery-pro'), 'submit_button' => __('Send', 'nextgen-gallery-pro'), 'submit_message' => __('Submitting...', 'nextgen-gallery-pro'), 'example_name' => __('Name', 'nextgen-gallery-pro'), 'example_email' => __('Email', 'nextgen-gallery-pro'), 'nggpl_title' => __('Proof image?', 'nextgen-gallery-pro')));
         $deps = false;
         if (wp_script_is('ngg-trigger-buttons', 'registered')) {
             $deps = array('ngg-trigger-buttons');
         }
         wp_enqueue_style('ngg-pro-proofing-style', $router->get_static_url('photocrati-nextgen_pro_proofing#nextgen_pro-proofing.css'), $deps);
         $this->run_once = TRUE;
     }
     return $retval;
 }
 function uninstall($hard)
 {
     // remove this products modules from the pope_module_list registry
     $registry = C_Component_Registry::get_instance();
     $nextgen_product = $registry->get_product('photocrati-nextgen');
     $pope_modules_list = get_option('pope_module_list', array());
     $pope_modules_list = $this->_filter_modules($pope_modules_list, $nextgen_product->get_modules_to_load());
     // run each modules respective uninstall routines
     foreach ($nextgen_product->get_modules_to_load() as $module_name) {
         if ($handler = C_Photocrati_Installer::get_handler_instance($module_name)) {
             if (method_exists($handler, 'uninstall')) {
                 $handler->uninstall($hard);
             }
         }
     }
     // lastly remove this product itself from the pope_module_list registry
     $search = array_search('photocrati-nextgen|' . NGG_PLUGIN_VERSION, $pope_modules_list);
     if (FALSE !== $search) {
         unset($pope_modules_list[$search]);
     }
     // TODO: remove this. NextGen Pro's uninstall routine will be updated in a separate release,
     // so to maintain proper support we run the same routine as above for it
     $pro_version = FALSE;
     if (defined('NGG_PRO_PLUGIN_VERSION')) {
         $pro_version = 'NGG_PRO_PLUGIN_VERSION';
     }
     if (defined('NEXTGEN_GALLERY_PRO_VERSION')) {
         $pro_version = 'NEXTGEN_GALLERY_PRO_VERSION';
     }
     if (FALSE !== $pro_version) {
         $pro_version = constant($pro_version);
     }
     if (FALSE !== $pro_version) {
         $pope_modules_list = $this->_filter_modules($pope_modules_list, $this->get_modules_to_load_for('photocrati-nextgen-pro'));
         $search = array_search('photocrati-nextgen-pro|' . $pro_version, $pope_modules_list);
         if (FALSE !== $search) {
             unset($pope_modules_list[$search]);
         }
     }
     if (empty($pope_modules_list)) {
         delete_option('pope_module_list');
     } else {
         update_option('pope_module_list', $pope_modules_list);
     }
 }
 function widget($args, $instance)
 {
     $router = C_Router::get_instance();
     wp_enqueue_style('nextgen_widgets_style', $router->get_static_url('photocrati-widget#widgets.css'));
     wp_enqueue_style('nextgen_basic_thumbnails_style', $router->get_static_url('photocrati-nextgen_basic_gallery#thumbnails/nextgen_basic_thumbnails.css'));
     // these are handled by extract() but I want to silence my IDE warnings that these vars don't exist
     $before_widget = NULL;
     $before_title = NULL;
     $after_widget = NULL;
     $after_title = NULL;
     $widget_id = NULL;
     extract($args);
     $title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title'], $instance, $this->id_base);
     $renderer = C_Component_Registry::get_instance()->get_utility('I_Displayed_Gallery_Renderer');
     $factory = C_Component_Registry::get_instance()->get_utility('I_Component_Factory');
     $view = $factory->create('mvc_view', '');
     // IE8 webslice support if needed
     if ($instance['webslice']) {
         $before_widget .= '<div class="hslice" id="ngg-webslice">';
         $before_title = str_replace('class="', 'class="entry-title ', $before_title);
         $after_widget = '</div>' . $after_widget;
     }
     $source = $instance['type'] == 'random' ? 'random_images' : 'recent';
     $params = array('slug' => 'widget-' . $args['widget_id'], 'source' => $source, 'display_type' => NEXTGEN_GALLERY_BASIC_THUMBNAILS, 'images_per_page' => $instance['items'], 'maximum_entity_count' => $instance['items'], 'template' => $view->get_template_abspath('photocrati-widget#display_gallery'), 'image_type' => $instance['show'] == 'original' ? 'full' : 'thumb', 'show_all_in_lightbox' => FALSE, 'show_slideshow_link' => FALSE, 'disable_pagination' => TRUE, 'image_width' => $instance['width'], 'image_height' => $instance['height'], 'ngg_triggers_display' => 'never', 'widget_setting_title' => $title, 'widget_setting_before_widget' => $before_widget, 'widget_setting_before_title' => $before_title, 'widget_setting_after_widget' => $after_widget, 'widget_setting_after_title' => $after_title, 'widget_setting_width' => $instance['width'], 'widget_setting_height' => $instance['height'], 'widget_setting_show_setting' => $instance['show'], 'widget_setting_widget_id' => $widget_id);
     switch ($instance['exclude']) {
         case 'all':
             break;
         case 'denied':
             $mapper = C_Component_Registry::get_instance()->get_utility('I_Gallery_Mapper');
             $gallery_ids = array();
             $list = explode(',', $instance['list']);
             foreach ($mapper->find_all() as $gallery) {
                 if (!in_array($gallery->{$gallery->id_field}, $list)) {
                     $gallery_ids[] = $gallery->{$gallery->id_field};
                 }
             }
             $params['container_ids'] = implode(',', $gallery_ids);
             break;
         case 'allow':
             $params['container_ids'] = $instance['list'];
             break;
     }
     echo $renderer->display_images($params);
 }
Example #16
0
 /**
  * Checks the 'callback' parameter for possible ajax-like actions to take
  *
  * @param $wp
  */
 function check_request($wp)
 {
     $app = C_Component_Registry::get_instance()->get_utility('I_Router')->get_routed_app();
     if (!$app->get_parameter('callback')) {
         return;
     }
     switch ($app->get_parameter('callback')) {
         case 'imagerotator':
             require_once dirname(__FILE__) . '/xml/imagerotator.php';
             break;
         case 'json':
             require_once dirname(__FILE__) . '/xml/json.php';
             break;
         case 'image':
             require_once dirname(__FILE__) . '/nggshow.php';
             break;
         default:
             return;
     }
     C_NextGEN_Bootstrap::shutdown();
 }
 /**
  * Returns Smush option / Stats, depending if image is already smushed or not
  *
  * @param $column_name
  * @param $id
  */
 function wp_smush_column_options($column_name, $id)
 {
     global $wpsmushnextgenstats;
     //NExtGen Doesn't returns Column name, weird? yeah, right, it is proper because hook is called for the particular column
     if ($column_name == 'wp_smush_image' || $column_name == '') {
         $supported_image = array('image/jpeg', 'image/gif', 'image/png', 'image/jpg');
         // Registry Object for NextGen Gallery
         $registry = C_Component_Registry::get_instance();
         //Gallery Storage Object
         $storage = $registry->get_utility('I_Gallery_Storage');
         //We'll get the image object in $id itself, else fetch it using Gallery Storage
         if (is_object($id)) {
             $image = $id;
         } else {
             // get an image object
             $image = $storage->object->_image_mapper->find($id);
         }
         //Check if it is supported image format, get image type to do that
         // get the absolute path
         $file_path = $storage->get_image_abspath($image, 'full');
         //Get image type from file path
         $image_type = $this->get_file_type($file_path);
         //If image type not supported
         if (!in_array($image_type, $supported_image)) {
             return;
         }
         //Check Image metadata, if smushed, print the stats or super smush button
         if (!empty($image->meta_data['wp_smush'])) {
             //Echo the smush stats
             $wpsmushnextgenstats->show_stats($image->pid, $image->meta_data['wp_smush'], $image_type, false, true);
             return;
         }
         //Print the status of image, if Not smushed
         $this->set_status($image->pid, true, false);
     }
 }
 function get_router()
 {
     return C_Component_Registry::get_instance()->get_utility('I_Router');
 }
Example #19
0
 protected function task($item)
 {
     session_write_close();
     $max_attempts = 15;
     if (empty($item['attempts'])) {
         $item['attempts'] = 0;
     }
     $id = $item['id'];
     ewwwio_debug_message("background processing nextgen2: {$id}");
     // creating the 'registry' object for working with nextgen
     $registry = C_Component_Registry::get_instance();
     // creating a database storage object from the 'registry' object
     $storage = $registry->get_utility('I_Gallery_Storage');
     // get an image object
     $image = $storage->object->_image_mapper->find($id);
     if (!is_object($image) && $item['attempts'] < $max_attempts) {
         $item['attempts']++;
         sleep(4);
         ewwwio_debug_message("could not retrieve image, requeueing {$item['attempts']}");
         ewww_image_optimizer_debug_log();
         return $item;
     } elseif (empty($image)) {
         ewwwio_debug_message("could not retrieve image, out of attempts");
         ewww_image_optimizer_debug_log();
         delete_transient('ewwwio-background-in-progress-ngg-' . $id);
         return false;
     }
     global $ewwwngg;
     $ewwwngg->ewww_added_new_image($image, $storage);
     delete_transient('ewwwio-background-in-progress-ngg-' . $id);
     sleep(ewww_image_optimizer_get_option('ewww_image_optimizer_delay'));
     ewww_image_optimizer_debug_log();
     return false;
 }
function getNGGalleryImages($ngGalleries, $ngImages, $dt, $lat, $lon, $dtoffset, &$error)
{
    $result = array();
    $galids = explode(',', $ngGalleries);
    $imgids = explode(',', $ngImages);
    if (!isNGGalleryActive()) {
        return '';
    }
    try {
        $pictures = array();
        foreach ($galids as $g) {
            $pictures = array_merge($pictures, nggdb::get_gallery($g));
        }
        foreach ($imgids as $i) {
            array_push($pictures, nggdb::find_image($i));
        }
        foreach ($pictures as $p) {
            $item = array();
            $item["data"] = $p->thumbHTML;
            if (is_callable('exif_read_data')) {
                $exif = @exif_read_data($p->imagePath);
                if ($exif !== false) {
                    $item["lon"] = getExifGps($exif["GPSLongitude"], $exif['GPSLongitudeRef']);
                    $item["lat"] = getExifGps($exif["GPSLatitude"], $exif['GPSLatitudeRef']);
                    if ($item["lat"] != 0 || $item["lon"] != 0) {
                        $result[] = $item;
                    } else {
                        if (isset($p->imagedate)) {
                            $_dt = strtotime($p->imagedate) + $dtoffset;
                            $_item = findItemCoordinate($_dt, $dt, $lat, $lon);
                            if ($_item != null) {
                                $item["lat"] = $_item["lat"];
                                $item["lon"] = $_item["lon"];
                                $result[] = $item;
                            }
                        }
                    }
                }
            } else {
                $error .= "Sorry, <a href='http://php.net/manual/en/function.exif-read-data.php' target='_blank' >exif_read_data</a> function not found! check your hosting..<br />";
            }
        }
        /* START FIX NEXT GEN GALLERY 2.x */
        if (class_exists("C_Component_Registry")) {
            $renderer = C_Component_Registry::get_instance()->get_utility('I_Displayed_Gallery_Renderer');
            $params['gallery_ids'] = $ngGalleries;
            $params['image_ids'] = $ngImages;
            $params['display_type'] = NEXTGEN_GALLERY_BASIC_THUMBNAILS;
            $params['images_per_page'] = 999;
            // also add js references to get the gallery working
            $dummy = $renderer->display_images($params, $inner_content);
            /* START FIX NEXT GEN GALLERY PRO */
            if (preg_match("/data-nplmodal-gallery-id=[\"'](.*?)[\"']/", $dummy, $m)) {
                $galid = $m[1];
                if ($galid) {
                    for ($i = 0; $i < count($result); ++$i) {
                        $result[$i]["data"] = str_replace("%PRO_LIGHTBOX_GALLERY_ID%", $galid, $result[$i]["data"]);
                    }
                }
            }
            /* END FIX NEXT GEN GALLERY PRO */
        }
        /* END FIX NEXT GEN GALLERY 2.x */
    } catch (Exception $e) {
        $error .= 'Error When Retrieving NextGen Gallery galleries/images: $e <br />';
    }
    return $result;
}
 /**
  * Overrides the NextGen Gallery function, to smush the dynamic images and thumbnails created by gallery
  *
  * @param C_Image|int|stdClass $image
  * @param $size
  * @param null $params
  * @param bool|false $skip_defaults
  *
  * @return bool|object
  */
 function generate_image_size($image, $size, $params = null, $skip_defaults = false)
 {
     global $WpSmush;
     $image_id = !empty($image->pid) ? $image->pid : '';
     //Get image from storage object if we don't have it already
     if (empty($image_id)) {
         //Get metadata For the image
         // Registry Object for NextGen Gallery
         $registry = C_Component_Registry::get_instance();
         //Gallery Storage Object
         $storage = $registry->get_utility('I_Gallery_Storage');
         $image_id = $storage->object->_get_image_id($image);
     }
     //Call the actual function to generate the image, and pass the image to smush
     $success = $this->call_parent('generate_image_size', $image, $size, $params, $skip_defaults);
     if ($success) {
         $filename = $success->fileName;
         //Smush it, if it exists
         if (file_exists($filename)) {
             $response = $WpSmush->do_smushit($filename, $image_id, 'nextgen');
             //If the image was smushed
             if (!is_wp_error($response) && !empty($response['data']) && $response['data']->bytes_saved > 0) {
                 //Check for existing stats
                 if (!empty($image->meta_data) && !empty($image->meta_data['wp_smush'])) {
                     $stats = $image->meta_data['wp_smush'];
                 } else {
                     //Initialize stats array
                     $stats = array("stats" => array_merge($WpSmush->_get_size_signature(), array('api_version' => -1, 'lossy' => -1, 'keep_exif' => false)), 'sizes' => array());
                     $stats['bytes'] = $response['data']->bytes_saved;
                     $stats['percent'] = $response['data']->compression;
                     $stats['size_after'] = $response['data']->after_size;
                     $stats['size_before'] = $response['data']->before_size;
                     $stats['time'] = $response['data']->time;
                 }
                 $stats['sizes'][$size] = (object) $WpSmush->_array_fill_placeholders($WpSmush->_get_size_signature(), (array) $response['data']);
                 if (isset($image->metadata)) {
                     $image->meta_data['wp_smush'] = $stats;
                     nggdb::update_image_meta($image->pid, $image->meta_data);
                 }
                 //Allows To get the stats for each image, after the image is smushed
                 do_action('wp_smush_nextgen_image_stats', $image_id, $stats);
             }
         }
     }
     return $success;
 }
Example #22
0
 function ewww_ngg_bulk_loop()
 {
     global $ewww_defer;
     $ewww_defer = false;
     $output = array();
     $permissions = apply_filters('ewww_image_optimizer_bulk_permissions', '');
     if (!wp_verify_nonce($_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk') || !current_user_can($permissions)) {
         $output['error'] = esc_html__('Access token has expired, please reload the page.', EWWW_IMAGE_OPTIMIZER_DOMAIN);
         echo json_encode($output);
         die;
     }
     // find out what time we started, in microseconds
     $started = microtime(true);
     // get the list of attachments remaining from the db
     $attachments = get_option('ewww_image_optimizer_bulk_ngg_attachments');
     $id = array_shift($attachments);
     // creating the 'registry' object for working with nextgen
     $registry = C_Component_Registry::get_instance();
     // creating a database storage object from the 'registry' object
     $storage = $registry->get_utility('I_Gallery_Storage');
     // get an image object
     $image = $storage->object->_image_mapper->find($id);
     $image = $this->ewww_added_new_image($image, $storage);
     global $ewww_exceed;
     if (!empty($ewww_exceed)) {
         $output['error'] = esc_html__('License Exceeded', EWWW_IMAGE_OPTIMIZER_DOMAIN);
         echo json_encode($output);
         die;
     }
     // output the results of the optimization
     $output['results'] = sprintf("<p>" . esc_html__('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <strong>%s</strong><br>", esc_html(basename($storage->object->get_image_abspath($image, 'full'))));
     // get an array of sizes available for the $image
     $sizes = $storage->get_image_sizes();
     // run the optimizer on the image for each $size
     foreach ($sizes as $size) {
         if ($size === 'full') {
             $output['results'] .= sprintf(esc_html__('Full size - %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($image->meta_data['ewww_image_optimizer']));
         } elseif ($size === 'thumbnail') {
             // output the results of the thumb optimization
             $output['results'] .= sprintf(esc_html__('Thumbnail - %s', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "<br>", esc_html($image->meta_data[$size]['ewww_image_optimizer']));
         } else {
             // output savings for any other sizes, if they ever exist...
             $output['results'] .= ucfirst($size) . " - " . esc_html($image->meta_data[$size]['ewww_image_optimizer']) . "<br>";
         }
     }
     // outupt how much time we spent
     $elapsed = microtime(true) - $started;
     $output['results'] .= sprintf(esc_html__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "</p>", $elapsed);
     // store the list back in the db
     update_option('ewww_image_optimizer_bulk_ngg_attachments', $attachments);
     if (!empty($attachments)) {
         $next_attachment = array_shift($attachments);
         $next_file = $this->ewww_ngg_bulk_filename($next_attachment);
         $loading_image = plugins_url('/images/wpspin.gif', __FILE__);
         if ($next_file) {
             $output['next_file'] = "<p>" . esc_html__('Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " <b>{$next_file}</b>&nbsp;<img src='{$loading_image}' alt='loading'/></p>";
         } else {
             $output['next_file'] = "<p>" . esc_html__('Optimizing', EWWW_IMAGE_OPTIMIZER_DOMAIN) . "&nbsp;<img src='{$loading_image}' alt='loading'/></p>";
         }
     }
     echo json_encode($output);
     die;
 }
Example #23
0
function ewww_image_optimizer_bulk_ngg($delay = 0)
{
    if (get_option('ewww_image_optimizer_bulk_ngg_resume')) {
        // get the list of attachment IDs from the db
        $images = get_option('ewww_image_optimizer_bulk_ngg_attachments');
        // otherwise, get all the images in the db
    } else {
        global $wpdb;
        $images = $wpdb->get_col("SELECT pid FROM {$wpdb->nggpictures} ORDER BY sortorder ASC");
        // store the image IDs to process in the db
        update_option('ewww_image_optimizer_bulk_ngg_attachments', $images, false);
        // toggle the resume flag to indicate an operation is in progress
        update_option('ewww_image_optimizer_bulk_ngg_resume', 'true');
    }
    if (!ewww_image_optimizer_iterable($images)) {
        WP_CLI::line(__('You do not appear to have uploaded any images yet.', EWWW_IMAGE_OPTIMIZER_DOMAIN));
        return;
    }
    global $ewwwngg;
    foreach ($images as $id) {
        sleep($delay);
        // find out what time we started, in microseconds
        $started = microtime(true);
        // creating the 'registry' object for working with nextgen
        $registry = C_Component_Registry::get_instance();
        // creating a database storage object from the 'registry' object
        $storage = $registry->get_utility('I_Gallery_Storage');
        // get an image object
        $image = $storage->object->_image_mapper->find($id);
        $image = $ewwwngg->ewww_added_new_image($image, $storage);
        // output the results of the optimization
        WP_CLI::line(__('Optimized image:', EWWW_IMAGE_OPTIMIZER_DOMAIN) . " " . basename($storage->object->get_image_abspath($image, 'full')));
        // get an array of sizes available for the $image
        $sizes = $storage->get_image_sizes();
        if (ewww_image_optimizer_iterable($sizes)) {
            // output the results for each $size
            foreach ($sizes as $size) {
                if ($size === 'full') {
                    WP_CLI::line(sprintf(__('Full size - %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), html_entity_decode($image->meta_data['ewww_image_optimizer'])));
                } elseif ($size === 'thumbnail') {
                    // output the results of the thumb optimization
                    WP_CLI::line(sprintf(__('Thumbnail - %s', EWWW_IMAGE_OPTIMIZER_DOMAIN), html_entity_decode($image->meta_data[$size]['ewww_image_optimizer'])));
                } else {
                    // output savings for any other sizes, if they ever exist...
                    WP_CLI::line(ucfirst($size) . " - " . html_entity_decode($image->meta_data[$size]['ewww_image_optimizer']));
                }
            }
        }
        // outupt how much time we spent
        $elapsed = microtime(true) - $started;
        WP_CLI::line(sprintf(__('Elapsed: %.3f seconds', EWWW_IMAGE_OPTIMIZER_DOMAIN), $elapsed));
        // get the list of attachments remaining from the db
        $attachments = get_option('ewww_image_optimizer_bulk_ngg_attachments');
        // remove the first item
        if (!empty($attachments)) {
            array_shift($attachments);
        }
        // and store the list back in the db
        update_option('ewww_image_optimizer_bulk_ngg_attachments', $attachments, false);
    }
    // reset all the bulk options in the db
    update_option('ewww_image_optimizer_bulk_ngg_resume', '');
    update_option('ewww_image_optimizer_bulk_ngg_attachments', '', false);
    // and let the user know we are done
    WP_CLI::success(__('Finished Optimization!', EWWW_IMAGE_OPTIMIZER_DOMAIN));
}
Example #24
0
 function load_styles()
 {
     global $ngg;
     // load the icon for the navigation menu
     wp_enqueue_style('nggmenu', NGGALLERY_URLPATH . 'admin/css/menu.css', array());
     wp_register_style('nggadmin', NGGALLERY_URLPATH . 'admin/css/nggadmin.css', false, '2.8.1', 'screen');
     wp_register_style('ngg-jqueryui', NGGALLERY_URLPATH . 'admin/css/jquery.ui.css', false, '1.8.5', 'screen');
     // no need to go on if it's not a plugin page
     if (!isset($_GET['page'])) {
         return;
     }
     // used to retrieve the uri of some module resources
     $router = C_Component_Registry::get_instance()->get_utility('I_Router');
     switch ($_GET['page']) {
         case NGGFOLDER:
             wp_enqueue_style('thickbox');
         case "nggallery-about":
             wp_enqueue_style('nggadmin');
             //TODO:Remove after WP 3.3 release
             if (!defined('IS_WP_3_3')) {
                 wp_admin_css('css/dashboard');
             }
             break;
         case "nggallery-add-gallery":
             $this->enqueue_jquery_ui_theme();
             wp_enqueue_style('jqueryFileTree', NGGALLERY_URLPATH . 'admin/js/jqueryFileTree/jqueryFileTree.css', false, '1.0.1', 'screen');
         case "nggallery-options":
             wp_enqueue_style('nggtabs', NGGALLERY_URLPATH . 'admin/css/jquery.ui.tabs.css', false, '2.5.0', 'screen');
             wp_enqueue_style('nggadmin');
             break;
         case "nggallery-manage-gallery":
             wp_enqueue_script('jquery-ui-tooltip');
             wp_enqueue_style('shutter', $router->get_static_url('photocrati-lightbox#shutter/shutter.css'), false, '1.3.2', 'screen');
         case "nggallery-roles":
         case "nggallery-manage-album":
             $this->enqueue_jquery_ui_theme();
             wp_enqueue_style('nggadmin');
             break;
         case "nggallery-tags":
             wp_enqueue_style('nggtags', NGGALLERY_URLPATH . 'admin/css/tags-admin.css', false, '2.6.1', 'screen');
             break;
         case "nggallery-style":
             wp_admin_css('css/theme-editor');
             wp_enqueue_style('nggcolorpicker', NGGALLERY_URLPATH . 'admin/js/colorpicker/css/colorpicker.css', false, '1.0', 'screen');
             wp_enqueue_style('nggadmincp', NGGALLERY_URLPATH . 'admin/css/nggColorPicker.css', false, '1.0', 'screen');
             break;
     }
 }
 function get_registry()
 {
     return C_Component_Registry::get_instance();
 }
 /**
  * Renders the JS required for the Backbone-based Display Tab
  */
 public function display_tab_js_action($return = FALSE)
 {
     // Cache appropriately
     $this->object->do_not_cache();
     // Ensure that JS is returned
     $this->object->set_content_type('javascript');
     $buffer_limit = 0;
     $zlib = ini_get('zlib.output_compression');
     if (!is_numeric($zlib) && $zlib == 'On') {
         $buffer_limit = 1;
     } else {
         if (is_numeric($zlib) && $zlib > 0) {
             $buffer_limit = 1;
         }
     }
     while (ob_get_level() != $buffer_limit) {
         ob_end_clean();
     }
     // Get all entities used by the display tab
     $context = 'attach_to_post';
     $gallery_mapper = $this->get_registry()->get_utility('I_Gallery_Mapper', $context);
     $album_mapper = $this->get_registry()->get_utility('I_Album_Mapper', $context);
     $image_mapper = $this->get_registry()->get_utility('I_Image_Mapper', $context);
     $display_type_mapper = $this->get_registry()->get_utility('I_Display_Type_Mapper', $context);
     $sources = C_Displayed_Gallery_Source_Manager::get_instance();
     $security = $this->get_registry()->get_utility('I_Security_Manager');
     // Get the nextgen tags
     global $wpdb;
     $tags = $wpdb->get_results("SELECT DISTINCT name AS 'id', name FROM {$wpdb->terms}\n                        WHERE term_id IN (\n                                SELECT term_id FROM {$wpdb->term_taxonomy}\n                                WHERE taxonomy = 'ngg_tag'\n                        )");
     $all_tags = new stdClass();
     $all_tags->name = 'All';
     $all_tags->id = 'All';
     array_unshift($tags, $all_tags);
     $display_types = array();
     $registry = C_Component_Registry::get_instance();
     foreach ($display_type_mapper->find_all() as $display_type) {
         if (isset($display_type->hidden_from_ui) && $display_type->hidden_from_ui) {
             continue;
         }
         $available = $registry->is_module_loaded($display_type->name);
         if (!apply_filters('ngg_atp_show_display_type', $available, $display_type)) {
             continue;
         }
         $display_types[] = $display_type;
     }
     usort($display_types, array($this->object, '_display_type_list_sort'));
     $output = $this->object->render_view('photocrati-attach_to_post#display_tab_js', array('displayed_gallery' => json_encode($this->object->_displayed_gallery->get_entity()), 'sources' => json_encode($sources->get_all()), 'gallery_primary_key' => $gallery_mapper->get_primary_key_column(), 'galleries' => json_encode($gallery_mapper->find_all()), 'albums' => json_encode($album_mapper->find_all()), 'tags' => json_encode($tags), 'display_types' => json_encode($display_types), 'sec_token' => $security->get_request_token('nextgen_edit_displayed_gallery')->get_json(), 'image_primary_key' => $image_mapper->get_primary_key_column()), $return);
     return $output;
 }
Example #27
0
function ewww_image_optimizer_defer()
{
    ewwwio_debug_message('<b>' . __FUNCTION__ . '()</b>');
    global $ewww_defer;
    $ewww_defer = false;
    $deferred_attachments = get_option('ewww_image_optimizer_defer_attachments');
    if (empty($deferred_attachments)) {
        return;
    }
    $start_time = time();
    $delay = ewww_image_optimizer_get_option('ewww_image_optimizer_delay');
    foreach ($deferred_attachments as $image) {
        list($type, $id) = explode(',', $image, 2);
        switch ($type) {
            case 'media':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                $meta = wp_get_attachment_metadata($id, true);
                // do the optimization for the current attachment (including resizes)
                $meta = ewww_image_optimizer_resize_from_meta_data($meta, $id, false);
                // update the metadata for the current attachment
                wp_update_attachment_metadata($id, $meta);
                break;
            case 'nextgen2':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                // creating the 'registry' object for working with nextgen
                $registry = C_Component_Registry::get_instance();
                // creating a database storage object from the 'registry' object
                $storage = $registry->get_utility('I_Gallery_Storage');
                // get an image object
                $ngg_image = $storage->object->_image_mapper->find($id);
                ewwwngg::ewww_added_new_image($ngg_image, $storage);
                break;
            case 'nextcellent':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                ewwwngg::ewww_ngg_optimize($id);
                break;
            case 'flag':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                $flag_image = flagdb::find_image($id);
                ewwwflag::ewww_added_new_image($flag_image);
                break;
            case 'file':
                ewwwio_debug_message("processing deferred {$type}: {$id}");
                ewww_image_optimizer($id);
                break;
            default:
                ewwwio_debug_message("unknown type in deferrred queue: {$type}, {$id}");
        }
        ewww_image_optimizer_remove_deferred_attachment($image);
        $elapsed_time = time() - $start_time;
        ewwwio_debug_message("time elapsed during deferred opt: {$elapsed_time}");
        global $ewww_exceed;
        if (!empty($ewww_exceed)) {
            ewwwio_debug_message('Deferred opt aborted, license exceeded');
            die;
        }
        ewww_image_optimizer_debug_log();
        if (!empty($delay)) {
            sleep($delay);
        }
        // prevent running longer than an hour
        if ($elapsed_time > 3600) {
            return;
        }
    }
    ewwwio_memory(__FUNCTION__);
    return;
}
Example #28
0
 /**
  * nggAdmin::set_watermark() - set the watermark for the image
  *
  * @class nggAdmin
  * @param object | int $image contain all information about the image or the id
  * @return string result code
  */
 function set_watermark($image)
 {
     if (is_object($image)) {
         if (isset($image->id)) {
             $image = $image->id;
         } elseif (isset($image->pid)) {
             $image = $image->pid;
         }
     }
     $registry = C_Component_Registry::get_instance();
     $storage = $registry->get_utility('I_Gallery_Storage');
     // XXX NextGEN Legacy was only handling watermarks at this stage, so we're forcefully disabling all else
     $params = array('watermark' => true, 'reflection' => false, 'crop' => false);
     $result = $storage->generate_image_size($image, 'full', $params);
     if (!$result) {
         // XXX there isn't any error handling unfortunately at the moment in the generate_thumbnail functions, need a way to return proper error status
         return __('Error while applying watermark to image.', 'nggallery');
     }
     // success
     return '1';
 }
 /**
  * Loads the Pope Framework
  */
 function _load_pope()
 {
     // No need to initialize pope again
     if ($this->_pope_loaded) {
         return;
     }
     // Pope requires a a higher limit
     $tmp = ini_get('xdebug.max_nesting_level');
     if ($tmp && (int) $tmp <= 300) {
         @ini_set('xdebug.max_nesting_level', 300);
     }
     // Include pope framework
     require_once implode(DIRECTORY_SEPARATOR, array(NGG_PLUGIN_DIR, 'pope', 'lib', 'autoload.php'));
     // Get the component registry
     $this->_registry = C_Component_Registry::get_instance();
     // Add the default Pope factory utility, C_Component_Factory
     $this->_registry->add_utility('I_Component_Factory', 'C_Component_Factory');
     // Load embedded products. Each product is expected to load any
     // modules required
     $this->_registry->add_module_path(NGG_PRODUCT_DIR, true, false);
     $this->_registry->load_all_products();
     // Give third-party plugins that opportunity to include their own products
     // and modules
     do_action('load_nextgen_gallery_modules', $this->_registry);
     // Initializes all loaded modules
     $this->_registry->initialize_all_modules();
     $this->_pope_loaded = TRUE;
 }
Example #30
0
 function can_user_manage_gallery()
 {
     $retval = FALSE;
     $registry = C_Component_Registry::get_instance();
     $security = $registry->get_utility('I_Security_Manager');
     $actor = $security->get_current_actor();
     if ($this->gallery && $actor->get_entity_id() == $this->gallery->author) {
         $retval = TRUE;
     } elseif ($actor->is_allowed('nextgen_edit_gallery_unowned')) {
         $retval = TRUE;
     }
     return $retval;
 }