l(t('add pageear page'), 'admin/build/pageear/add'), '%configure' => t('configure')); 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 configure existing pageears by clicking the %configure 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() { // Add the JS only if we have any active pageear. // TODO: should this be a cached flag - and should it be determined on a page/role basis? $num_active = variable_get('numEnabledPageears', 0); if ($num_active) { // Fetch all active pageears. // TODO: cache? $pageears = array(); $result = db_query("SELECT * FROM {pageears} WHERE status = 1"); while ($row = db_fetch_object($result)) { $pageears[] = $row; } // This is a redundant test by now because we know there are pageeears active. Nothing to do - return. if (!count($pageears)) { return; } global $user; global $language; $rids = array_keys($user->roles); $lang_name = $language->language; $output = ''; // Output pageear for the current path/role. If more than one are configured for this path and role, only first would be present. foreach ($pageears as $pageear) { // 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; } // Output pageear 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 variable currentPageear variable_set('current_pageear', pageear_prepare($pageear)); // Include on page javascript files needed to make pageear work $path = drupal_get_path('module', 'pageear'); drupal_add_js($path .'/pageturn/AC_RunActiveContent.js'); drupal_add_js($path .'/pageturn/pageTurn.js'); return; } } // There is no pageear enabled for this node variable_set('current_pageear', FALSE); } } /** * 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' => 'Configure pageears, how they look and where they appear on the site.', 'page callback' => 'pageear_admin_display', '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_configure', NULL, 'add'), 'access arguments' => array('administer pageears'), 'type' => MENU_LOCAL_TASK, 'file' => 'pageear.admin.inc', ); $items['admin/build/pageear/%pageear/configure'] = array( 'title' => 'Configure pageear', 'page callback' => 'drupal_get_form', 'page arguments' => array('pageear_admin_configure', 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_configure', 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; } /** * Implementation of hook_footer(). */ function pageear_footer($main = 0) { $current_pageear = variable_get('current_pageear', FALSE); // Output pageear if there is one for current node if ($current_pageear) { $js = "\n"; return $js; } } /** * 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 to JS unset($pageear->peid); unset($pageear->name); unset($pageear->status); unset($pageear->roles); unset($pageear->visibility); unset($pageear->pages); unset($pageear->languages); // Construct the image and sound paths $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') { $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; } /** * Get the default values of a new pageear */ function pageear_get_default() { $default = new stdClass(); $default->peid = 0; $default->status = 1; $default->name = ''; $default->peelPosition = 'topright'; $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->redValue = 255; $default->greenValue = 255; $default->blueValue = 255; $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 'peelPosition': $options = array( 'topleft' => t('Top left'), 'topright' => t('Top right') ); 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 'linkTarget': $options = array( '_self' => t('Same window'), '_blank' => t('New window') ); break; default: $options = array(); } if ($key == '') { return $options; } else { return $options[$key]; } }