params->getValue('pages'); $path = drupal_get_path_alias($_GET['q']); $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($pages, '/')) .')$/'; // Compare with the internal and path alias (if any). $page_match = preg_match($regexp, $path); if ($path != $_GET['q']) { $page_match = $page_match || preg_match($regexp, $_GET['q']); } if (!$page_match) { drupal_set_html_head($tool->headers(base_path() . $module_path)); define('_MAGICZOOM_MODULE_ALLOWED', true); } else { define('_MAGICZOOM_MODULE_ALLOWED', false); } } function magiczoom_load_core_class() { if(!isset($GLOBALS["magictoolbox"])) $GLOBALS["magictoolbox"] = array(); if(!isset($GLOBALS["magictoolbox"]["magiczoom"])) { /* load core class */ require_once(dirname(__FILE__) . '/magiczoom.module.core.class.php'); $tool = new MagicZoomModuleCoreClass(); /* add category for core params */ $params = $tool->params->getArray(); foreach($params as $k => $v) { $v['category'] = array( "name" => 'General options', "id" => 'general_options' ); $params[$k] = $v; } $tool->params->appendArray($params); /* add params used only for drupal with IMAGE module */ if (module_exists('image')) { $sizes = Array(); foreach (image_get_sizes() as $label => $size) { $sizes[$label] = $size['label']; //if($size['width']) $sizes[$label] .= ' (' . $size['width'] . 'x' . $size['height'] . ')'; } $tool->params->appendArray(array( "auto" => array( "id" => "auto", "label" => "Enable for image nodes", "type" => "array", "subType" => "radio", "values" => Array("Yes", "No"), "default" => "Yes", "description" => "Automatically activate effect for all image nodes (requires the image module).", "category" => Array( "id" => 'imagemodule', "name" => 'Image module options' ), ), "derivatives" => array( "id" => "derivatives", "label" => "Image derivatives", "type" => "array", "subType" => "checkboxes", "values" => $sizes, "default" => Array("thumbnail" => "thumbnail", "preview" => "preview", "_original" => 0), "description" => "Select which image derivatives will be zoomed", "category" => Array( "id" => 'imagemodule', "name" => 'Image module options' ), ), "large_derivative" => array( "id" => "large_derivative", "label" => "Large Image derivative", "type" => "array", "subType" => "select", "values" => $sizes, "default" => "_original", "description" => "Select which image derivative will be used as the large (zoomed) image.", "category" => Array( "id" => 'imagemodule', "name" => 'Image module options' ), ), "pages" => array( "id" => "pages", "label" => "Deactivate Magic Zoom on specific pages", "type" => "textarea", "default" => t("admin*\nimg_assist*\nnode/add/*\nnode/*/edit"), "description" => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')), "category" => Array( "id" => 'general_options', "name" => 'General options' ), ) )); } if (module_exists('img_assist')) { $tool->params->appendArray(array( "img_links" => array( "id" => "img_links", "label" => "Support image links", "type" => "array", "subType" => "radio", "values" => Array("Yes", "No"), "default" => "No", "description" => "Support native image links. Links will be able for onclick action", "category" => Array( "id" => 'imagemodule', "name" => 'Image module options' ), ))); } /* load params */ foreach($tool->params->getNames() as $name) { $val = variable_get('magictoolbox_magiczoom_' . $name, $tool->params->getValue($name)); $tool->params->set($name, $val); } $GLOBALS["magictoolbox"]["magiczoom"] = & $tool; } return $GLOBALS["magictoolbox"]["magiczoom"]; } function magiczoom_menu() { global $user; $items = array(); $args = func_get_args(); if(count($argc) > 0 && !$arcgs[0]) { // for drupal5 we do not need load menu in caching mode return $items; } if(defined('VERSION') && intval(VERSION) >= 6) { $items['admin/settings/magiczoom'] = array( 'title' => 'Magic Zoom', 'description' => 'Configure Magic Zoom settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('magiczoom_admin_settings'), 'access arguments' => array('administer site configuration'), 'type' => MENU_NORMAL_ITEM, ); } else { $items[] = array( 'path' => 'admin/settings/magiczoom', 'title' => 'Magic Zoom', 'description' => 'Configure Magic Zoom settings', 'callback' => 'drupal_get_form', 'callback arguments' => array('magiczoom_admin_settings'), 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM, ); } return $items; } /** * Menu callback for admin_settings. */ function magiczoom_admin_settings() { $tool = & magiczoom_load_core_class(); $form = Array(); foreach($tool->params->getArray() as $name=> $value) { if(!isset($form['magiczoom_' . $value['category']['id']])) { $form['magiczoom_' . $value['category']['id']] = array( '#type' => 'fieldset', '#title' => t($value['category']['name']) ); } switch($value['type']) { case 'array': $type = ($value['subType'] == 'radio' ? 'radios' : ($value['subType'] == 'checkboxes' ? 'checkboxes' : 'select')); break; case 'textarea': $type = 'textarea'; break; default: $type = 'textfield'; } $form['magiczoom_' . $value['category']['id']]['magictoolbox_magiczoom_' . $name] = array( '#type' => $type, '#title' => t($value['label']), '#default_value' => $tool->params->getValue($name), ); if($value["type"] == 'array') { $options = array(); if($value['subType'] == 'checkboxes') $options = $value['values']; else { foreach($value['values'] as $v) { $options[$v] = t($v); } } $form['magiczoom_' . $value['category']['id']]['magictoolbox_magiczoom_' . $name]['#options'] = $options; } if(isset($value['description'])) { $form['magiczoom_' . $value['category']['id']]['magictoolbox_magiczoom_' . $name]['#description'] = $value['description']; } /*if($type == 'textfield') { $form['magiczoom_' . $value['category']['id']]['magictoolbox_magiczoom_' . $name]['#size'] = 50; $form['magiczoom_' . $value['category']['id']]['magictoolbox_magiczoom_' . $name]['#maxlength'] = 50; }*/ } return system_settings_form($form); } function magiczoom_theme_registry_alter(&$theme_registry) { $tool = & magiczoom_load_core_class(); if(defined('VERSION') && intval(VERSION) < 6) { if($tool->params->checkValue('auto', 'Yes')) { $theme_registry["image_display"] = "theme_magiczoom_image_display"; } $theme_registry["uc_product_image"] = "theme_magiczoom_uc_product_image"; } else { if($tool->params->checkValue('auto', 'Yes')) { $theme_registry["image_display"]["function"] = "theme_magiczoom_image_display"; } $theme_registry["uc_product_image"]["function"] = "theme_magiczoom_uc_product_image"; } return $theme_registry; } function theme_magiczoom_image_display($node, $label, $url, $attributes) { $tool = & magiczoom_load_core_class(); // Support of links with enabled MZ effect $img_nid = $node->nid; // current image nod id; if ($tool->params->checkValue('img_links', 'Yes') && $tool->params->checkValue('drag_mode', 'No') && $tool->params->checkValue('click_to_initialize', 'No') && $tool->params->checkValue('click_to_activate', 'No') && $tool->params->checkValue('click_to_activate', 'No')) { //if image links are enabled in MZ /*$ch1 = 0; foreach (arg() as $value) { if ($ch1 % 2) $arg[] = $value; else $num[] = $value; $ch1++; } $arguments = array_combine($num,$arg); $nid = intval($arguments['node']);*/ $nid = arg(1); // current node id (parent) $result = db_query('SELECT * FROM {node_revisions} WHERE nid = %d', $nid); $row = db_fetch_object($result); preg_match_all('/\[img_assist.*?\]/is',$row->body,$matches); // get all img_assist images in $matches array if (count($matches[0]) > 0) { foreach ($matches[0] as $img_assist_img) { $img_assist_img = preg_replace('/\[/is','',$img_assist_img); $img_assist_img = preg_replace('/\]/is','',$img_assist_img); $img_assist_img = explode ('|',$img_assist_img); foreach ($img_assist_img as $img_param) { list($node_arg[],$node_arg_value[]) = explode('=',$img_param); } $img_assist_img = array_combine($node_arg,$node_arg_value); $img_assist_array[$img_assist_img['nid']] = $img_assist_img; } //if we have an external link if ($img_assist_array[$img_nid]['link'] == 'url' && !empty($img_assist_array[$img_nid]['url'])) $img_url = $img_assist_array[$img_nid]['url']; if ($img_assist_array[$img_nid]['link'] == 'node' && url(arg(0).'/'.$img_nid)) $img_url = url(arg(0).'/'.$img_nid); //if we have a link to image node if ($img_assist_array[$img_nid]['link'] == 'popup') { //if we have a 'popup' option selected $popup_size = variable_get('img_assist_popup_label', IMAGE_PREVIEW); $info = image_get_info(file_create_path($node->images[$popup_size])); } //if we have no link if ($img_assist_array[$img_nid]['link'] == 'none') $img_url = ''; } } $imageHTML = theme('image', $url, $node->title, $node->title, $attributes, FALSE); if($tool->params->checkValue('auto', 'No')) return $imageHTML; if(!_MAGICZOOM_MODULE_ALLOWED) return $imageHTML; $allowed = $tool->params->getValue('derivatives'); if((string)($allowed[(string)$label]) !== (string)$label) return $imageHTML; /* is this image node ? */ //if(!isset($node->build_mode) && !isset($node->readmore) && !isset($node->content)) return $imageHTML; $title = trim($node->title); $thumb = preg_replace("/^.*?src=\"(.*?)\".*$/is", "$1", $imageHTML); if(!defined('_MAGICZOOM_ADDONS_TEMPLATE_LOADED')) { $addons = $tool->addonsTemplate(base_path() . drupal_get_path('module', 'magiczoom')); define('_MAGICZOOM_ADDONS_TEMPLATE_LOADED', 1); } else $addons = ''; $t = $tool->params->getValue('large_derivative'); $t = strtolower($t); if($t == 'original') $t = '_' . $t; $img = $node->images[$t]; $img = (url($img) == $img) ? $img : (base_path() . $img); $img = check_url($img); $html = $tool->template(array( "img" => $img, "thumb" => $thumb, "title" => $title, )); /*img_assist onclick*/ if ($img_url) { $html = preg_replace('/' . $html . $addons . ''; } function theme_magiczoom_uc_product_image($images, $teaser = 0, $page = 0) { // use orig function for same tests =) //$args = func_get_args(); //return call_user_func_array('theme_uc_product_image', $args); // We should ensure that the first element is image if(count($images) > 0) { $imagesOld = $images; foreach($imagesOld as $img) { // Node preview adds extra values to $images that aren't files. if (!is_array($img) || empty($img['filepath'])) { array_shift($images); } else { break; } } } if(count($images) < 1) { // We have not images? We should not process... return ''; } $tool = & magiczoom_load_core_class(); $html = ''; static $rel_count = 0; // Get the current product image widget. $image_widget = uc_product_get_image_widget(); //print_r($image_widget); die(); if($image_widget) {die('c'); $image_widget_func = $image_widget['callback']; $image_widget_html = $image_widget_func($rel_count); } if(!defined('_MAGICZOOM_ADDONS_TEMPLATE_LOADED')) { $addons = $tool->addonsTemplate(base_path() . drupal_get_path('module', 'magiczoom')); define('_MAGICZOOM_ADDONS_TEMPLATE_LOADED', 1); } else $addons = ''; $html .= $addons; $html .= '
'; // main image $html .= '
'; $a = $tool->template(array( 'img' => imagecache_create_url('product_full', $images[0]['filepath']), 'thumb' => imagecache_create_url('product', $images[0]['filepath']), 'alt' => $images[0]['data']['alt'], 'title' => $images[0]['data']['title'], 'id' => 'MainProductImage', )); if($image_widget) { $a = preg_replace(']+)>', '', $a); } $html .= $a; $html .= '
'; // selectors if(count($images) > 1) { $html .= '
'; foreach($images as $img) { // Node preview adds extra values to $images that aren't files. if (!is_array($img) || empty($img['filepath'])) { continue; } $a = $tool->subTemplate(array( 'img' => imagecache_create_url('product_full', $img['filepath']), 'medium' => imagecache_create_url('product', $img['filepath']), 'thumb' => imagecache_create_url('uc_thumbnail', $img['filepath']), 'alt' => $img['data']['alt'], 'title' => $img['data']['title'], 'id' => 'MainProductImage', )); if($image_widget) { $a = preg_replace(']+)>', '', $a); } $html .= $a; } $html .= '
'; } $html .= '
'; $rel_count++; return $html; } function magiczoom_nodeapi(&$node, $op, $a3, $a4) { switch($op) { case 'view': break; case 'alter': if(isset($node->content['add_to_cart']) && user_access('view option images') && count($node->attributes) && isset($node->content['option_image'])) { $html = ''; $tool = & magiczoom_load_core_class(); // code here $attributes = $node->attributes; $attribute = $attributes[0]; $page_size = variable_get('uc_option_image_page_size', 'preview'); $teaser_size = variable_get('uc_option_image_teaser_size', 'thumbnail'); //$size = $a4 ? $page_size : $teaser_size; // Determine if we have a default option using if ($attribute->default_option){ $default_option = $attribute->default_option; } else { foreach($attribute->options as $key => $option) { $default_option = $key; break; } } $html .= '
'; // main image // Load the default image file $file = uc_option_image_load($node->nid, $attribute->aid, $default_option); $html .= $tool->template(array( 'img' => imagecache_create_url('product_full', $file->filepath), 'thumb' => imagecache_create_url($page_size, $file->filepath), 'alt' => $attribute->options[$default_option]->name, 'id' => 'MainProductAttributesImage', )); // additional images $html .= '
'; foreach($attribute->options as $key => $option) { $file = uc_option_image_load($node->nid, $attribute->aid, $key); $html .= $tool->subTemplate(array( 'img' => imagecache_create_url('product_full', $file->filepath), 'medium' => imagecache_create_url($page_size, $file->filepath), 'thumb' => imagecache_create_url($teaser_size, $file->filepath), 'alt' => $option->name, 'id' => 'MainProductAttributesImage', )); } $html .= '
'; $html .= '
'; $node->body = str_replace($node->content['option_image']['#value'], $html, $node->body); //print_r($node); //die(); } } }