示例#1
0
 /**
  * Generates the Shopp admin menus
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @return void
  **/
 public function menus()
 {
     global $menu, $plugin_page;
     $access = 'shopp_menu';
     if (Shopp::maintenance()) {
         $access = 'manage_options';
     }
     // Add main menus
     $position = shopp_admin_add_menu(Shopp::__('Shopp'), 'orders', 40, false, 'shopp_orders', Shopp::clearpng());
     shopp_admin_add_menu(Shopp::__('Catalog'), 'products', $position, false, 'shopp_products', Shopp::clearpng());
     // Add after the Shopp menus to avoid being purged by the duplicate separator check
     $menu[$position - 1] = array('', 'read', 'separator-shopp', '', 'wp-menu-separator');
     // Add menus to WordPress admin
     foreach ($this->pages as $page) {
         $this->submenus($page);
     }
     $parent = get_admin_page_parent();
     if (isset($this->menus[$parent]) && false === strpos($this->menus[$parent], 'toplevel')) {
         $current_page = $plugin_page;
         $plugin_page = $parent;
         add_action('adminmenu', create_function('', 'global $plugin_page; $plugin_page = "' . $current_page . '";'));
     }
 }
示例#2
0
 /**
  * Provides markup for a product image gallery
  *
  * @api `shopp('product.gallery')`
  * @since 1.0
  *
  * @param string       $result  The output
  * @param array        $options The options
  * - **margins**: `20` Informs the PHP environment of the CSS margins used around elements for more accurate layout calculations
  * - **rowthumbs**: Sets the number of thumbnails per row to automatically resize the thumbnails to fit the space
  * - **p.setting**: Sets the image setting name to use for the preview image (individual settings can still be overridden)
  * - **p.size**: Sets the width and height of the preview image
  * - **p.width**: Sets the width of the preview image
  * - **p.height**: Sets the height of the preview image
  * - **p.fit**: `all` The fit of unproportional images to the requested size:
  *   - **all**: Scale the image down to fit within the new size (the final size may differ from the specified dimensions)
  *   - **crop**: Scale the image down to fit by the smallest dimension to fill the entire image, cropping the extra off the other dimension (specific cropping adjustments can be made in the product editor)
  *   - **height**: Scale the image down to fit the image in the new size by the height, cropping any extra width
  *   - **matte**: Scale the image down to fit within the new size filling extra space with a background color
  *   - **width**: Scale the image down to fit the image in the new size by the width, cropping any extra height
  * - **p.sharpen**: `0` The amount of unsharp mask to use on the preview image
  * - **p.quality**: `80` (0%-100%) The JPEG image quality of the preview image
  * - **p.bg**: `#ffffff` (#rrggbb) The background color to use with the `matte` setting for the **p_fit** option
  * - **p.link**: `on` (on,off) Include a link to the original full-size image
  * - **rel**: Used to provide information about the relationship between the product and the linked image
  * - **thumbsetting**: Specifies the image setting name to use for thumbnail images (individual settings can still be overridden)
  * - **thumbsize**: Sets the width and height of the thumbnail images
  * - **thumbwidth**: Sets the width of the thumbnail images
  * - **thumbheight**: Sets the height of the thumbnail images
  * - **thumbfit**: `all` Sets fit of unproportional images to the requested size:
  *   - **all**: Scale the image down to fit within the new size (the final size may differ from the specified dimensions)
  *   - **crop**: Scale the image down to fit by the smallest dimension to fill the entire image, cropping the extra off the other dimension (specific cropping adjustments can be made in the product editor)
  *   - **height**: Scale the image down to fit the image in the new size by the height, cropping any extra width
  *   - **matte**: Scale the image down to fit within the new size filling extra space with a background color
  *   - **width**: Scale the image down to fit the image in the new size by the width, cropping any extra height
  * - **thumbsharpen**: `0` The amount of unsharp mask to use on thumbnail images
  * - **thumbquality**: `80` (0%-100%) The JPEG image quality of the thumbnail images
  * - **thumbbg**: `#ffffff` (#rrggbb) The background color to use with the `matte` setting for the **thumbfit** option
  * - **zoomfx**: `shopp-zoom` Enables zoom (also known as a lightbox) effects for alternate JavaScript-based modal viewers. To change the built-in Colorbox options @use `shopp('storefront.zoom-options')`
  * - **preview**: `click` (click,hover,dblclick,mousedown) The browser action to use to preview a thumbnail
  * @param ShoppProduct $O       The working object
  * @return string The gallery markup
  **/
 public static function gallery($result, $options, $O)
 {
     if (empty($O->images)) {
         $O->load_data(array('images'));
     }
     if (empty($O->images)) {
         return false;
     }
     $_size = 240;
     $_width = shopp_setting('gallery_small_width');
     $_height = shopp_setting('gallery_small_height');
     if (!$_width) {
         $_width = $_size;
     }
     if (!$_height) {
         $_height = $_size;
     }
     $defaults = array('margins' => 20, 'rowthumbs' => false, 'p_setting' => false, 'p_size' => false, 'p_width' => false, 'p_height' => false, 'p_fit' => false, 'p_sharpen' => false, 'p_quality' => false, 'p_bg' => false, 'p_link' => true, 'rel' => '', 'thumbsetting' => false, 'thumbsize' => false, 'thumbwidth' => false, 'thumbheight' => false, 'thumbfit' => false, 'thumbsharpen' => false, 'thumbquality' => false, 'thumbbg' => false, 'zoomfx' => 'shopp-zoom', 'preview' => 'click');
     // Populate defaults from named settings, if provided
     $ImageSettings = ImageSettings::object();
     if (!empty($options['p_setting'])) {
         $settings = $ImageSettings->get($options['p_setting']);
         if ($settings) {
             $defaults = array_merge($defaults, $settings->options('p_'));
         }
     }
     if (!empty($options['thumbsetting'])) {
         $settings = $ImageSettings->get($options['thumbsetting']);
         if ($settings) {
             $defaults = array_merge($defaults, $settings->options('thumb'));
         }
     }
     $optionset = array_merge($defaults, $options);
     // Translate dot-notation options to underscore
     $options = array();
     $keys = array_keys($optionset);
     foreach ($keys as $key) {
         $options[str_replace('.', '_', $key)] = $optionset[$key];
     }
     extract($options);
     if ($p_size > 0) {
         $_width = $_height = $p_size;
     }
     $width = $p_width > 0 ? $p_width : $_width;
     $height = $p_height > 0 ? $p_height : $_height;
     $preview_width = $width;
     // Find the max dimensions to use for the preview spacing image
     $maxwidth = $maxheight = 0;
     foreach ($O->images as $img) {
         $scale = $p_fit ? array_search($p_fit, ImageAsset::$defaults['scaling']) : false;
         $scaled = $img->scaled($width, $height, $scale);
         $maxwidth = max($maxwidth, $scaled['width']);
         $maxheight = max($maxheight, $scaled['height']);
     }
     if (0 == $maxwidth) {
         $maxwidth = $width;
     }
     if (0 == $maxheight) {
         $maxheight = $height;
     }
     $p_link = Shopp::str_true($p_link);
     $product_class = 'product_' . (int) $O->id;
     // Setup preview images
     $previews = '';
     if ('transparent' == strtolower($p_bg)) {
         $fill = -1;
     } else {
         $fill = $p_bg ? hexdec(ltrim($p_bg, '#')) : false;
     }
     $lowest_quality = min(ImageSetting::$qualities);
     $scale = $p_fit ? array_search($p_fit, ImageAsset::$defaults['scaling']) : false;
     $sharpen = $p_sharpen ? max($p_sharpen, ImageAsset::$defaults['sharpen']) : false;
     $quality = $p_quality ? max($p_quality, $lowest_quality) : false;
     foreach ($O->images as $Image) {
         $firstPreview = false;
         if (empty($previews)) {
             // Adds "filler" image to reserve the dimensions in the DOM
             $firstPreview = $previews .= '<li class="fill">' . '<img src="' . Shopp::clearpng() . '" alt="" style="width: ' . (int) $maxwidth . 'px; height: ' . (int) $maxheight . 'px;" />' . '</li>';
         }
         $scaled = $Image->scaled($width, $height, $scale);
         $titleattr = !empty($Image->title) ? ' title="' . esc_attr($Image->title) . '"' : '';
         $alt = esc_attr(!empty($Image->alt) ? $Image->alt : $Image->filename);
         $src = $Image->url($width, $height, $scale, $sharpen, $quality, $fill);
         $img = '<img src="' . $src . '"' . $titleattr . ' alt="' . $alt . '" width="' . (int) $scaled['width'] . '" height="' . (int) $scaled['height'] . '" />';
         if ($p_link) {
             $hrefattr = $Image->url();
             $relattr = empty($rel) ? '' : ' rel="' . esc_attr($rel) . '"';
             $linkclasses = array('gallery', $product_class, $zoomfx);
             $img = '<a href="' . $hrefattr . '" class="' . join(' ', $linkclasses) . '"' . $relattr . $titleattr . '>' . $img . '</a>';
         }
         $previews .= '<li id="preview-' . $Image->id . '"' . (empty($firstPreview) ? '' : '  class="active"') . '>' . $img . '</li>';
     }
     $previews = '<ul class="previews">' . $previews . '</ul>';
     $thumbs = '';
     $twidth = $preview_width + $margins;
     // Add thumbnails (if needed)
     if (count($O->images) > 1) {
         $default_size = 64;
         $_thumbwidth = shopp_setting('gallery_thumbnail_width');
         $_thumbheight = shopp_setting('gallery_thumbnail_height');
         if (!$_thumbwidth) {
             $_thumbwidth = $default_size;
         }
         if (!$_thumbheight) {
             $_thumbheight = $default_size;
         }
         if ($thumbsize > 0) {
             $thumbwidth = $thumbheight = $thumbsize;
         }
         $width = $thumbwidth > 0 ? $thumbwidth : $_thumbwidth;
         $height = $thumbheight > 0 ? $thumbheight : $_thumbheight;
         $thumbs = '';
         foreach ($O->images as $Image) {
             $scale = $thumbfit ? array_search($thumbfit, ImageAsset::$defaults['scaling']) : false;
             $sharpen = $thumbsharpen ? min($thumbsharpen, ImageAsset::$defaults['sharpen']) : false;
             $quality = $thumbquality ? min($thumbquality, ImageAsset::$defaults['quality']) : false;
             if ('transparent' == strtolower($thumbbg)) {
                 $fill = -1;
             } else {
                 $fill = $thumbbg ? hexdec(ltrim($thumbbg, '#')) : false;
             }
             $scaled = $Image->scaled($width, $height, $scale);
             $titleattr = empty($Image->title) ? '' : ' title="' . esc_attr($Image->title) . '"';
             $alt = esc_attr(empty($Image->alt) ? $Image->name : $Image->alt);
             $src = $Image->url($width, $height, $scale, $sharpen, $quality, $fill);
             $thumbclasses = array('preview-' . $Image->id);
             if (empty($thumbs)) {
                 $thumbclasses[] = 'first';
             }
             $thumbclasses = esc_attr(join(' ', $thumbclasses));
             $thumbs .= '<li id="thumbnail-' . $Image->id . '" class="' . $thumbclasses . '">' . '<img src="' . $src . '"' . $titleattr . ' alt="' . $alt . '" width="' . (int) $scaled['width'] . '" height="' . (int) $scaled['height'] . '" />' . '</li> ';
         }
         $thumbs = '<ul class="thumbnails">' . $thumbs . '</ul>';
     }
     // end count($O->images)
     if ($rowthumbs > 0) {
         $twidth = ($width + $margins + 2) * (int) $rowthumbs;
     }
     $result = '<div id="gallery-' . $O->id . '" class="gallery">' . $previews . $thumbs . '</div>';
     $script = "\t" . 'ShoppGallery("#gallery-' . $O->id . '","' . $preview . '"' . ($twidth ? ",{$twidth}" : "") . ');';
     add_storefrontjs($script);
     return $result;
 }