l(t('add pageear page'), 'admin/build/pageear/add'), '%edit' => t('edit')); return t('Pageears are peelads which are shown at the top of pages - in the left or right \'corner\'. Create new pageears on the !add_new or edit existing pageears by clicking the %edit link next to each one.', $params); } } /** * Implementation of hook_init(). * * We can't move this into pageear_footer(), because PHP-only based themes * like chameleon load and output scripts and stylesheets in front of * theme_closure(), so we ensure the style(s) are loaded on all pages. */ function pageear_init() { $num_active = variable_get('numEnabledPageears', 0); $current_topleft_pageear = FALSE; $current_topright_pageear = FALSE; // Add the JS only if we have any active pageear. // Test if pageear must be displayed in this node // and prepare it for hook_footer. if ($num_active) { // Fetch all active pageears. // TODO: cache? $pageears = array(); $result = db_query("SELECT * FROM {pageears} WHERE status = 1 ORDER BY weight ASC, peid ASC"); while ($row = db_fetch_object($result)) { $pageears[] = $row; } global $user; global $language; $rids = array_keys($user->roles); $lang_name = $language->language; // Pageear for the current path/role/language. If more than one are configured for this path/role/language, only first would be presented. foreach ($pageears as $pageear) { if ($pageear->peelPosition == 'topright' && $current_topright_pageear) { continue; } if ($pageear->peelPosition == 'topleft' && $current_topleft_pageear) { continue; } // Get the settings $vis_languages = explode(',', $pageear->languages); $vis_roles = explode(',', $pageear->roles); $vis_vis = $pageear->visibility; $vis_pages = $pageear->pages; // Match languages if (module_exists('locale') && count(array_filter($vis_languages))) { $lang_enabled = in_array($lang_name, $vis_languages); } else { $lang_enabled = TRUE; } // Match roles if (count(array_filter($vis_roles))) { $role_enabled = count(array_intersect($vis_roles, $rids)) ? TRUE : FALSE; } else { $role_enabled = TRUE; } // Match path if necessary if ($vis_pages) { if ($vis_vis < 2) { $path = drupal_get_path_alias($_GET['q']); // Compare with the internal and path alias (if any). $page_match = drupal_match_path($path, $vis_pages); if ($path != $_GET['q']) { $page_match = $page_match || drupal_match_path($_GET['q'], $vis_pages); } // When $vis_vis has a value of 0, the pageear is displayed on // all pages except those listed in $vis_pages. When set to 1, it // is displayed only on those pages listed in $vis_pages. $page_match = !($vis_vis xor $page_match); } else { $page_match = drupal_eval($vis_pages); } } else { $page_match = TRUE; } // Generate pageears if enabled for current path, role and language if ($lang_enabled === TRUE && $role_enabled === TRUE && $page_match) { // Prepare the pageear object to adjust it to pageTurn javascript variable needs // and store it on persistent variable currentPageear if ($pageear->peelPosition == 'topright') { $current_topright_pageear = pageear_prepare($pageear); } else { $current_topleft_pageear = pageear_prepare($pageear); } // if both pageears are just set, there is not need to continue // analyzing the rest of pageears. Write pageears and return. if ($current_topleft_pageear && $current_topright_pageear) { write_pageears($current_topleft_pageear, $current_topright_pageear); return; } } } // All enabled pageears have been analyzed. Write pageears. if ($current_topleft_pageear || $current_topright_pageear) { write_pageears($current_topleft_pageear, $current_topright_pageear); } } } /** * Implementation of hook_perm(). */ function pageear_perm() { return array('administer pageears', 'use PHP for pageear visibility'); } /** * Implementation of hook_menu(). */ function pageear_menu() { $items = array(); $items['admin/build/pageear'] = array( 'title' => 'Pageears', 'description' => 'Edit pageears, how they look and where they appear on the site.', //'page callback' => 'pageear_admin_display', 'page callback' => 'drupal_get_form', 'page arguments' => array('pageear_list_form'), 'access arguments' => array('administer pageears'), 'file' => 'pageear.admin.inc', ); $items['admin/build/pageear/list'] = array( 'title' => 'List', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items['admin/build/pageear/add'] = array( 'title' => 'Add pageear', 'page callback' => 'drupal_get_form', 'page arguments' => array('pageear_admin_edit', NULL, 'add'), 'access arguments' => array('administer pageears'), 'type' => MENU_LOCAL_TASK, 'file' => 'pageear.admin.inc', ); $items['admin/build/pageear/%pageear/edit'] = array( 'title' => 'Edit pageear', 'page callback' => 'drupal_get_form', 'page arguments' => array('pageear_admin_edit', 3), 'access arguments' => array('administer pageears'), 'type' => MENU_CALLBACK, 'file' => 'pageear.admin.inc', ); $items['admin/build/pageear/%pageear/clone'] = array( 'title' => 'Clone pageear', 'page callback' => 'drupal_get_form', 'page arguments' => array('pageear_admin_edit', 3, 'clone'), 'access arguments' => array('administer pageears'), 'type' => MENU_CALLBACK, 'file' => 'pageear.admin.inc', ); $items['admin/build/pageear/%pageear/delete'] = array( 'title' => 'Delete pageear', 'page callback' => 'drupal_get_form', 'page arguments' => array('pageear_admin_delete', 3), 'access arguments' => array('administer pageears'), 'type' => MENU_CALLBACK, 'file' => 'pageear.admin.inc', ); $items['admin/build/pageear/%pageear/disable'] = array( 'title' => 'Disables pageear', 'page callback' => 'pageear_admin_disable', 'page arguments' => array(3), 'access arguments' => array('administer pageears'), 'type' => MENU_CALLBACK, 'file' => 'pageear.admin.inc', ); $items['admin/build/pageear/%pageear/enable'] = array( 'title' => 'Enables pageear', 'page callback' => 'pageear_admin_enable', 'page arguments' => array(3), 'access arguments' => array('administer pageears'), 'type' => MENU_CALLBACK, 'file' => 'pageear.admin.inc', ); return $items; } /** * Output pageears. */ function write_pageears($current_topleft_pageear = FALSE, $current_topright_pageear = FALSE) { if ($current_topleft_pageear || $current_topright_pageear) { $path = drupal_get_path('module', 'pageear'); drupal_add_js($path .'/pageturn/swfobject.js', 'module', 'header', FALSE, FALSE, TRUE); drupal_add_js($path .'/pageturn/pageTurn.js', 'module', 'header', FALSE, FALSE, TRUE); drupal_add_css($path .'/pageturn/pageTurn.css', 'module', 'all', TRUE); // Output pageears if there is one for current node $js = "flagSwf = '". $base_url . base_path() . drupal_get_path('module', 'pageear') ."/pageturn/flag.swf';\n"; $js .= "peelSwf = '". $base_url . base_path() . drupal_get_path('module', 'pageear') ."/pageturn/turn.swf';\n"; if ($current_topleft_pageear) { $js .= "topleft_pageearvars = {\n"; foreach ($current_topleft_pageear as $key => $value) { $js .= $key .": escape(". drupal_to_js($value) ."),\n"; } $js .= "};\n"; $js .= "topleft_pageear = new pageear(topleft_pageearvars);\n"; $js .= "topleft_pageear.write();\n"; } if ($current_topright_pageear) { $js .= "topright_pageearvars = {\n"; foreach ($current_topright_pageear as $key => $value) { $js .= $key .": escape(". drupal_to_js($value) ."),\n"; } $js .= "};\n"; $js .= "topright_pageear = new pageear(topright_pageearvars);\n"; $js .= "topright_pageear.write();\n"; } drupal_add_js($js, 'inline', 'footer'); } } /** * Prepares a pageear object prior to being use in JS. * * @param $pageear A pageear object * @return A prepared pageear object */ function pageear_prepare($pageear) { // No need to carry over these values to JS unset($pageear->peid); unset($pageear->name); unset($pageear->status); unset($pageear->roles); unset($pageear->visibility); unset($pageear->pages); unset($pageear->languages); unset($pageear->weight); // Construct the image and sound paths $pageear->waitURL = base_path() . $pageear->waitURL; $pageear->smallURL = base_path() . $pageear->smallURL; $pageear->bigURL = base_path() . $pageear->bigURL; $pageear->loadSoundURL = ($pageear->loadSoundURL == '') ? '' : base_path() . $pageear->loadSoundURL; $pageear->openSoundURL = ($pageear->openSoundURL == '') ? '' : base_path() . $pageear->openSoundURL; $pageear->closeSoundURL = ($pageear->closeSoundURL == '') ? '' : base_path() . $pageear->closeSoundURL; // Convert automaticOpen, automaticClose from seconds to milliseconds $pageear->automaticOpen = $pageear->automaticOpen * 1000; $pageear->automaticClose = $pageear->automaticClose * 1000; return $pageear; } /** * Get a pageear by its id or a combination of other fields. * * @param $array An associative array of attributes to search for in selecting the pageear, * such as pageear id (peid) or name (name). * @return A pageear array if found, otherwise false. */ //function pageear_load($array = array()) { // // Dynamically compose a SQL query (similar to user.module -> user_load): // $query = array(); // $params = array(); // // if (is_numeric($array)) { // $array = array('peid' => $array); // } // elseif (!is_array($array)) { // return FALSE; // } // // foreach ($array as $key => $value) { // if ($key == 'peid' || $key == 'status' || $key == 'visibility' || $key == 'mirror' || $key == 'transitionDuration' || $key == 'redValue' || $key == 'greenValue' || $key == 'blueValue' || $key == 'flagSpeed' || $key == 'peelSpeed' || $key == 'automaticOpen' || $key == 'automaticClose' || $key == 'close_button_enable' || $key == 'close_redValue' || $key == 'close_greenValue' || $key == 'close_blueValue' || $key == 'flagWidth' || $key == 'flagHeight' || $key == 'peelWidth' || $key == 'peelHeight' || $key == 'linkEnabled') { // $query[] = "$key = %d"; // $params[] = $value; // } // else { // $query[]= "LOWER($key) = LOWER('%s')"; // $params[] = $value; // } // } // // Only return first hit // $pageear = db_fetch_object(db_query('SELECT * FROM {pageears} WHERE '. implode(' AND ', $query), $params)); // return $pageear; //} /** * Loading one, more or all pageears. */ function pageear_load($peid = NULL) { static $pageears; if (!is_array($pageears)) { if (is_numeric($peid)) { $pageear = db_fetch_object(db_query("SELECT * FROM {pageears} WHERE peid = %d", array(':peid' => $peid))); return $pageear; } else { $result = db_query("SELECT * FROM {pageears} ORDER BY weight ASC"); $pageears = array(); while ($pageear = db_fetch_object($result)) { $pageears[$pageear->peid] = $pageear; } } } if (is_array($pageears)) { if (is_numeric($peid)) { return $pageears[$peid]; } elseif (is_array($peid)) { return array_intersect_key($pageears, array_flip($peid)); } else { return $pageears; } } } /** * Get the default values of a new pageear */ function pageear_get_default() { $default = new stdClass(); $default->peid = 0; $default->weight = 0; $default->status = 1; $default->name = ''; $default->flagStyle = 'style1'; $default->peelStyle = 'style1'; $default->peelPosition = 'topright'; $default->peelPositionModel = 'absolute'; $default->flagWidth = 100; $default->flagHeight = 100; $default->peelWidth = 500; $default->peelHeight = 500; $default->waitEnable = 0; $default->waitURL = drupal_get_path('module', 'pageear') .'/pageturn/wait.gif'; $default->waitWidth = 42; $default->waitHeight = 42; $default->smallURL = drupal_get_path('module', 'pageear') .'/pageturn/small.jpg'; $default->bigURL = drupal_get_path('module', 'pageear') .'/pageturn/big.jpg'; $default->mirror = 1; $default->inTransition = 'none'; $default->transitionDuration = 4; $default->peelColor = 'custom'; $default->peelColorStyle = 'gradient'; $default->redValue = 255; $default->greenValue = 255; $default->blueValue = 255; $default->linkEnabled = 1; $default->linkTarget = '_blank'; $default->link = 'http://www.drupal.org/'; $default->loadSoundURL = ''; $default->openSoundURL = ''; $default->closeSoundURL = ''; $default->flagSpeed = 4; $default->peelSpeed = 4; $default->automaticOpen = 0; $default->automaticClose = 0; $default->close_button_enable = 0; $default->text_on_close_button = 'close'; $default->close_redValue = 255; $default->close_greenValue = 255; $default->close_blueValue = 255; $default->languages = ''; $default->roles = ''; $default->visibility = 0; $default->pages = ''; return (object) $default; } /** * Returns either an array of select options or, if a key is specified, the value for the specific key in the given array. * * @param $type * @param $key A key corresponding to a specific entry in one of the options arrays * @return mixed */ function pageear_get_options($type, $key = '') { switch ($type) { case 'flagStyle': $options = array( 'style1' => t('Style') .' 1', 'style2' => t('Style') .' 2', 'style3' => t('Style') .' 3', ); break; case 'peelStyle': $options = array( 'style1' => t('Style') .' 1', 'style2' => t('Style') .' 2', 'style3' => t('Style') .' 3', ); break; case 'peelPosition': $options = array( 'topleft' => t('Top left'), 'topright' => t('Top right') ); break; case 'peelPositionModel': $options = array( 'absolute' => t('absolute'), 'fixed' => t('fixed') ); break; case 'inTransition': $options = array( 'none' => t('(disabled)'), 'Blinds' => t('Blinds'), 'Fade' => t('Fade'), 'Fly' => t('Fly'), 'Iris' => t('Iris'), 'Photo' => t('Photo'), 'Rotate' => t('Rotate'), 'Squeeze' => t('Squeeze'), 'Wipe' => t('Wipe'), 'PixelDissolve' => t('PixelDissolve'), 'Zoom' => t('Zoom') ); break; case 'peelColor': $options = array( 'golden' => t('Golden'), 'silver' => t('Silver'), 'custom' => t('Custom') ); break; case 'peelColorStyle': $options = array( 'flat' => t('Flat'), 'gradient' => t('Gradient') ); break; case 'linkTarget': $options = array( '_self' => t('Same window'), '_blank' => t('New window') ); break; default: $options = array(); } if ($key == '') { return $options; } else { return $options[$key]; } } /** * Implementation of hook_theme(). */ function pageear_theme() { return array( 'pageear_list_form' => array('arguments' => array('form' => NULL)), ); }