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 = db_result(db_query("SELECT COUNT(*) FROM {pageears} WHERE status = 1")); if ($num_active) { $path = drupal_get_path('module', 'pageear'); drupal_add_js($path .'/pageturn/AC_RunActiveContent.js'); drupal_add_js($path .'/pageturn/pageTurn.js'); } } /** * Implementation of hook_perm(). */ function pageear_perm() { return array('administer pageears', 'use PHP for pageear visibility'); } /** * Implementation of hook_menu(). */ function pageear_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array( 'path' => 'admin/build/pageear', 'title' => t('Pageears'), 'description' => t('Configure pageears, how they look and where they appear on the site.'), 'callback' => 'pageear_admin_display', 'access' => user_access('administer pageears'), ); $items[] = array( 'path' => 'admin/build/pageear/list', 'title' => t('List'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[] = array( 'path' => 'admin/build/pageear/add', 'title' => t('Add pageear'), 'callback' => 'drupal_get_form', 'callback arguments' => array('pageear_admin_configure', 'add', NULL), 'access' => user_access('administer pageears'), 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/build/pageear/configure', 'title' => t('Configure pageear'), 'callback' => 'drupal_get_form', 'callback arguments' => array('pageear_admin_configure', 'configure'), 'access' => user_access('administer pageears'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/build/pageear/clone', 'title' => t('Clone pageear'), 'callback' => 'drupal_get_form', 'callback arguments' => array('pageear_admin_configure', 'clone'), 'access' => user_access('administer pageears'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/build/pageear/delete', 'title' => t('Delete pageear'), 'callback' => 'drupal_get_form', 'callback arguments' => array('pageear_admin_delete'), 'access' => user_access('administer pageears'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/build/pageear/disable', 'title' => t('Disables pageear'), 'callback' => 'pageear_admin_disable', 'access' => user_access('administer pageears'), 'type' => MENU_CALLBACK, ); $items[] = array( 'path' => 'admin/build/pageear/enable', 'title' => t('Enables pageear'), 'callback' => 'pageear_admin_enable', 'access' => user_access('administer pageears'), 'type' => MENU_CALLBACK, ); } return $items; } /** * Implementation of hook_footer(). */ function pageear_footer($main = 0) { // 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; } // Nothing to do - return. if (!count($pageears)) { return; } global $user; global $locale; $rids = array_keys($user->roles); $lang_name = $locale; $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']); $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($vis_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']); } // 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 webpicasso pageear javascript variable needs $pageear = pageear_prepare($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 = url($pageear->smallURL, NULL, NULL, TRUE); $pageear->bigURL = url($pageear->bigURL, NULL, NULL, TRUE); $pageear->loadSoundURL = ($pageear->loadSoundURL == '') ? '' : url($pageear->loadSoundURL, NULL, NULL, TRUE); $pageear->openSoundURL = ($pageear->openSoundURL == '') ? '' : url($pageear->openSoundURL, NULL, NULL, TRUE); $pageear->closeSoundURL = ($pageear->closeSoundURL == '') ? '' : url($pageear->closeSoundURL, NULL, NULL, TRUE); // 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]; } } /** * Menu callback for admin/build/pageear. */ function pageear_admin_display() { $path = drupal_get_path('module', 'pageear'); drupal_add_css($path .'/pageear-admin.css', 'module', 'all', FALSE); $result = db_query("SELECT * FROM {pageears} ORDER BY peid"); $rows = array(); while ($row = db_fetch_object($result)) { $rows[] = array( 'data' => array( check_plain($row->name), check_plain($row->link), pageear_get_options('peelPosition', $row->peelPosition), !$row->status ? l(t('enable'), 'admin/build/pageear/enable/'. $row->peid) : l(t('disable'), 'admin/build/pageear/disable/'. $row->peid), l(t('clone'), 'admin/build/pageear/clone/'. $row->peid), l(t('configure'), 'admin/build/pageear/configure/'. $row->peid), l(t('delete'), 'admin/build/pageear/delete/'. $row->peid), ), 'class' => $row->status ? 'enabled' : 'disabled', ); } $header = array(t('Pageear'), t('Link'), t('Position'), array('data' => t('Operations'), 'colspan' => '4')); return theme('table', $header, $rows, $attributes = array('class' => 'pageear-admin-list'), NULL); } /** * Menu callback; displays the pageear configuration form. * * Using the same form for three different operations ($op): * - 'configure': configure an existing pageear (default) * - 'add': add a new pageear * - 'clone': clone an existing pageear */ function pageear_admin_configure($op = 'configure', $peid) { if ($op == 'add' || !$peid) { $pageear = pageear_get_default(); } else { $pageear = pageear_load($peid); } if ($op == 'clone') { $pageear->peid = 0; } $form = array(); $form['#attributes'] = array('enctype' => "multipart/form-data"); $form['peid'] = array( '#type' => 'value', '#value' => $pageear->peid, ); // Info $form['info'] = array( '#type' => 'fieldset', '#title' => t('Pageear info'), '#collapsible' => TRUE, ); $form['info']['status'] = array( '#type' => 'checkbox', '#title' => t('Enable pageear'), '#default_value' => $pageear->status, '#description' => t('If this setting is enabled, the current pageear is shown on the configured pages (see specific options below).'), ); $form['info']['name'] = array( '#type' => 'textfield', '#title' => t('Pageear name'), '#default_value' => $pageear->name, '#description' => t('The name of the pageear.'), '#required' => TRUE, '#maxlength' => 64, ); // End Info // Details $form['details'] = array( '#type' => 'fieldset', '#title' => t('Pageear details'), '#collapsible' => TRUE, ); // Position settings. $form['details']['position_settings'] = array( '#type' => 'fieldset', '#title' => t('Position Settings'), '#collapsible' => TRUE, ); // Set direction of pageear in left or right top browser corner ( topleft: left | topright: right ). $form['details']['position_settings']['peelPosition'] = array( '#type' => 'radios', '#title' => t('Corner'), '#description' => t('In what corner the ad will be displayed.'), '#options' => pageear_get_options('peelPosition'), '#default_value' => $pageear->peelPosition, '#required' => TRUE, ); // End Position settings. // Image Settings. $form['details']['image_settings'] = array( '#type' => 'fieldset', '#title' => t('Image Settings'), '#collapsible' => TRUE, ); // URL to small image. $form['details']['image_settings']['smallURL'] = array( '#type' => 'textfield', '#title' => t('Unpeeled image'), '#description' => t('URL of image to show when the ad is not peeled (JPEG, GIF or PNG 100x100 pixels).'), '#required' => TRUE, '#default_value' => $pageear->smallURL, '#maxlength' => 255, ); $form['details']['image_settings']['smallURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an image to show when the ad is not peeled.'), '#tree' => FALSE, ); // URL to big image. $form['details']['image_settings']['bigURL'] = array( '#type' => 'textfield', '#title' => t('Peeled image'), '#description' => t('URL of the image to show when the ad is peeled (JPEG, GIF or PNG 500x500 pixels).'), '#required' => TRUE, '#default_value' => $pageear->bigURL, '#maxlength' => 255, ); $form['details']['image_settings']['bigURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an image to show when the ad is peeled.'), '#tree' => FALSE, ); // Mirror image ( true | false ). $form['details']['image_settings']['mirror'] = array( '#type' => 'checkbox', '#title' => t('Back mirror'), '#default_value' => $pageear->mirror, '#description' => t('Mirror the ad on the back of the peeled page.'), ); // In Transition for pageear. $form['details']['image_settings']['inTransition'] = array( '#type' => 'select', '#title' => t('In Transition'), '#description' => t('In Transition for the pageear.'), '#options' => pageear_get_options('inTransition'), '#default_value' => $pageear->inTransition, '#required' => TRUE, ); // Duration of In Transition (1-9). $form['details']['image_settings']['transitionDuration'] = array( '#type' => 'textfield', '#title' => t('In Transition Duration'), '#description' => t('Duration of in transition. (1-9)'), '#required' => TRUE, '#default_value' => $pageear->transitionDuration, '#maxlength' => 1, ); // Color of peel back. $form['details']['image_settings']['peelColor'] = array( '#type' => 'radios', '#title' => t('Back color'), '#description' => t('This color will be used on the back of peel.'), '#options' => pageear_get_options('peelColor'), '#default_value' => $pageear->peelColor, '#required' => TRUE, ); // Custom color. $form['details']['image_settings']['custom_color'] = array( '#type' => 'fieldset', '#title' => t('Custom Color'), '#collapsible' => TRUE, ); // Red Value for Custom Color Peel. $form['details']['image_settings']['custom_color']['redValue'] = array( '#type' => 'textfield', '#title' => t('Red Value'), '#description' => t('Red Value of Custom Color Peel (0-255).'), '#required' => TRUE, '#default_value' => $pageear->redValue, '#maxlength' => 3, ); // Green Value for Custom Color Peel. $form['details']['image_settings']['custom_color']['greenValue'] = array( '#type' => 'textfield', '#title' => t('Green Value'), '#description' => t('Green Value of Custom Color Peel (0-255).'), '#required' => TRUE, '#default_value' => $pageear->greenValue, '#maxlength' => 3, ); // Blue Value for Custom Color Peel. $form['details']['image_settings']['custom_color']['blueValue'] = array( '#type' => 'textfield', '#title' => t('Blue Value'), '#description' => t('Blue Value of Custom Color Peel (0-255).'), '#required' => TRUE, '#default_value' => $pageear->blueValue, '#maxlength' => 3, ); // End Image Settings. // Sound Settings. $form['details']['sound_settings'] = array( '#type' => 'fieldset', '#title' => t('Sound Settings'), '#collapsible' => TRUE, ); // URL to onload sound. $form['details']['sound_settings']['loadSoundURL'] = array( '#type' => 'textfield', '#title' => t('Onload Sound'), '#description' => t('URL of mp3 file to play when the ad is loaded.'), '#default_value' => $pageear->loadSoundURL, ); $form['details']['sound_settings']['loadSoundURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an mp3 file to play when the ad is loaded.'), '#tree' => FALSE, ); // URL to open peel sound. $form['details']['sound_settings']['openSoundURL'] = array( '#type' => 'textfield', '#title' => t('Open Peel Sound'), '#description' => t('URL of mp3 file to play when the peel is opened.'), '#default_value' => $pageear->openSoundURL, ); $form['details']['sound_settings']['openSoundURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an mp3 file to play when the peel is opened.'), '#tree' => FALSE, ); // URL to close peel sound. $form['details']['sound_settings']['closeSoundURL'] = array( '#type' => 'textfield', '#title' => t('Close Peel Sound'), '#description' => t('URL of mp3 file to play when the peel is closed.'), '#default_value' => $pageear->closeSoundURL, ); $form['details']['sound_settings']['closeSoundURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an mp3 file to play when the peel is closed.'), '#tree' => FALSE, ); // End Sound Settings. // Linking Settings. $form['details']['linking_settings'] = array( '#type' => 'fieldset', '#title' => t('URL Settings'), '#collapsible' => TRUE, ); // URL to open on pageear click. $form['details']['linking_settings']['link'] = array( '#type' => 'textfield', '#title' => t('URL'), '#description' => t('URL to go when user click on the ad.'), '#required' => TRUE, '#default_value' => $pageear->link, ); // Browser target (new) or self (self). $form['details']['linking_settings']['linkTarget'] = array( '#type' => 'radios', '#title' => t('URL target'), '#description' => t('Where to open the URL.'), '#options' => pageear_get_options('linkTarget'), '#default_value' => $pageear->linkTarget, '#required' => TRUE, ); //End Linking Settings. // Motion Settings. $form['details']['motion_settings'] = array( '#type' => 'fieldset', '#title' => t('Motion Settings'), '#collapsible' => TRUE, ); // Speed of flag movement (1-9). $form['details']['motion_settings']['flagSpeed'] = array( '#type' => 'textfield', '#title' => t('Flag motion speed'), '#description' => t('Speed for flag motion. (1-9)'), '#required' => TRUE, '#default_value' => $pageear->flagSpeed, '#maxlength' => 1, ); // Speed of peel movement (1-9). $form['details']['motion_settings']['peelSpeed'] = array( '#type' => 'textfield', '#title' => t('Peel motion speed'), '#description' => t('Speed for peel motion. (1-9)'), '#required' => TRUE, '#default_value' => $pageear->peelSpeed, '#maxlength' => 1, ); // Opens pageear automaticaly after configured seconds. $form['details']['motion_settings']['automaticOpen'] = array( '#type' => 'textfield', '#title' => t('Automatically peel on load'), '#description' => t('Unpeel automatically when the page loads after configured seconds. 0 means no automatically open.'), '#required' => TRUE, '#default_value' => $pageear->automaticOpen, '#maxlength' => 3, ); // Seconds until pageear close after automatically open. $form['details']['motion_settings']['automaticClose'] = array( '#type' => 'textfield', '#title' => t('Automatically unpeel'), '#description' => t('Automatically close after unpeeling after configured seconds. 0 means no automatically unpeel.'), '#required' => TRUE, '#default_value' => $pageear->automaticClose, '#maxlength' => 3, ); // End Motion Settings. // Close button settings. $form['details']['closebutton_settings'] = array( '#type' => 'fieldset', '#title' => t('Close Button Settings'), '#collapsible' => TRUE, ); // Clickable button on open peel ( true | false ). $form['details']['closebutton_settings']['close_button_enable'] = array( '#type' => 'checkbox', '#title' => t('Close Button'), '#default_value' => $pageear->close_button_enable, '#description' => t('Show a close button on open peel. If this is enabled the peel will not close on mouse out. Users must click button to close peel.'), ); // Text on close button. $form['details']['closebutton_settings']['text_on_close_button'] = array( '#type' => 'textfield', '#title' => t('Close Button Text'), '#description' => t('Text on clickable close button.'), '#required' => TRUE, '#default_value' => $pageear->text_on_close_button, ); // Close button color. $form['details']['closebutton_settings']['closebutton_color'] = array( '#type' => 'fieldset', '#title' => t('Close Button Color'), '#collapsible' => TRUE, ); // Close Button Color Red Value. $form['details']['closebutton_settings']['closebutton_color']['close_redValue'] = array( '#type' => 'textfield', '#title' => t('Red Value'), '#description' => t('Close Button Color Red Value (0-255).'), '#required' => TRUE, '#default_value' => $pageear->close_redValue, '#maxlength' => 3, ); // Close Button Color Green Value. $form['details']['closebutton_settings']['closebutton_color']['close_greenValue'] = array( '#type' => 'textfield', '#title' => t('Green Value'), '#description' => t('Close Button Color Green Value (0-255).'), '#required' => TRUE, '#default_value' => $pageear->close_greenValue, '#maxlength' => 3, ); // Close Button Color Blue Value. $form['details']['closebutton_settings']['closebutton_color']['close_blueValue'] = array( '#type' => 'textfield', '#title' => t('Blue Value'), '#description' => t('Close Button Color Blue Value (0-255).'), '#required' => TRUE, '#default_value' => $pageear->close_blueValue, '#maxlength' => 3, ); // End Close Button Settings. // Language-based visibility settings - only visible if 'locale' module enabled if (module_exists('locale')) { $form['language_vis_settings'] = array( '#type' => 'fieldset', '#title' => t('Language specific visibility settings'), '#collapsible' => TRUE, ); $language_enabled = locale_supported_languages(TRUE); $language_options = $language_enabled['name']; $form['language_vis_settings']['languages'] = array( '#type' => 'checkboxes', '#title' => t('Show pageear for specific languages'), '#options' => $language_options, '#default_value' => generate_defaults($pageear->languages), '#description' => t('Show the pageear only for the selected language(s). If you select no languages, the pageear will be visible for all languages.'), ); } // Role-based visibility settings (mostly borrowed from 'block.admin.inc') $result = db_query('SELECT rid, name FROM {role} ORDER BY name'); $role_options = array(); while ($role = db_fetch_object($result)) { $role_options[$role->rid] = $role->name; } $form['roles_vis_settings'] = array( '#type' => 'fieldset', '#title' => t('Role specific visibility settings'), '#collapsible' => TRUE, ); $form['roles_vis_settings']['roles'] = array( '#type' => 'checkboxes', '#title' => t('Show pageear for specific roles'), '#options' => $role_options, '#default_value' => generate_defaults($pageear->roles), '#description' => t('Show the pageear only for the selected role(s). If you select no roles, the pageear will be visible to all users.'), ); $form['page_vis_settings'] = array( '#type' => 'fieldset', '#title' => t('Page specific visibility settings'), '#collapsible' => TRUE, ); $access = user_access('use PHP for pageear visibility'); if ($pageear->visibility == 2 && !$access) { $form['page_vis_settings'] = array(); $form['page_vis_settings']['visibility'] = array( '#type' => 'value', '#value' => 2, ); $form['page_vis_settings']['pages'] = array( '#type' => 'value', '#value' => $pageear->pages, ); } else { $options = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')); $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' => '')); if ($access) { $options[] = t('Show if the following PHP code returns TRUE (PHP-mode, experts only).'); $description .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '')); } $form['page_vis_settings']['visibility'] = array( '#type' => 'radios', '#title' => t('Show pageear on specific pages'), '#options' => $options, '#default_value' => $pageear->visibility, ); $form['page_vis_settings']['pages'] = array( '#type' => 'textarea', '#title' => t('Pages'), '#default_value' => $pageear->pages, '#description' => $description, ); } if ($op == 'configure') { $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), ); $form['cancel'] = array( '#type' => 'markup', '#value' => l(t('Cancel'), referer_uri()), ); } else if ($op == 'add' || $op == 'clone') { $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), ); $form['#submit']['pageear_admin_add_submit'] = array(); $form['cancel'] = array( '#type' => 'markup', '#value' => l(t('Cancel'), referer_uri()), ); } return $form; } // helper function to generate array of keys from values stored on database // to use on default_values of checkboxes function generate_defaults($stored_value) { $result = array(); if ($stored_value == '') { return $result; } $stored_value_array = explode(',', $stored_value); foreach ($stored_value_array as $key => $value) { if ($value != '0') { $result[] = $value; } } return $result; } /** * hook_validate: validation function for the pageear configuration form. */ function pageear_admin_configure_validate($form_id, $form_values, $form) { $directory_path = file_directory_path() .'/'. PAGEEAR_PATH_IMAGES; // checks if directory exist and creates it if it don't file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path'); // uploads images from image upload fields foreach (array('smallURL', 'bigURL') as $image) { if ($file = file_save_upload($image .'_upload')) { $parts = pathinfo($file->filename); if ($parts['extension'] != 'jpeg' && $parts['extension'] != 'jpg' && $parts['extension'] != 'gif' && $parts['extension'] != 'png') { form_set_error($image, t('Uploaded image must be an image file. JPEG, PNG or GIF')); } else { $filename = $directory_path .'/'. $image .'_'. $form_values['peid'] .'.'. $parts['extension']; if (file_copy($file, $filename)) { form_set_value($form['details']['image_settings'][$image], $file->filepath); } } } } // uploads images from sound upload fields foreach (array('loadSoundURL', 'openSoundURL', 'closeSoundURL') as $sound) { if ($file = file_save_upload($sound .'_upload')) { $parts = pathinfo($file->filename); if ($parts['extension'] != 'mp3') { form_set_error($sound, t('Uploaded sound must be a MP3 file.')); } else { $filename = $directory_path .'/'. $sound .'_'. $form_values['peid'] .'.'. $parts['extension']; if (file_copy($file, $filename)) { form_set_value($form['details']['sound_settings'][$sound], $file->filepath); } } } } // Duration or Transition validation if (!is_numeric($form_values['transitionDuration']) || $form_values['transitionDuration'] == 0) { form_set_error('transitionDuration', t('Duration of transition must be a number between 1 and 9')); } // Peel custom color red value validation if (!is_numeric($form_values['redValue']) || $form_values['redValue'] < 0 || $form_values['redValue'] > 255) { form_set_error('redValue', t('Custom color red value must be a number between 0 and 255')); } // Peel custom color green value validation if (!is_numeric($form_values['greenValue']) || $form_values['greenValue'] < 0 || $form_values['greenValue'] > 255) { form_set_error('greenValue', t('Custom color green value must be a number between 0 and 255')); } // Peel custom color blue value validation if (!is_numeric($form_values['blueValue']) || $form_values['blueValue'] < 0 || $form_values['blueValue'] > 255) { form_set_error('blueValue', t('Custom color blue value must be a number between 0 and 255')); } // Flag speed validation if (!is_numeric($form_values['flagSpeed']) || $form_values['flagSpeed'] == 0) { form_set_error('flagSpeed', t('Flag motion speed must be a number between 1 and 9')); } // Peel speed validation if (!is_numeric($form_values['peelSpeed']) || $form_values['peelSpeed'] == 0) { form_set_error('peelSpeed', t('Peel motion speed must be a number between 1 and 9')); } // AutomaticOpen validation if (!is_numeric($form_values['automaticOpen']) || $form_values['automaticOpen'] < 0) { form_set_error('automaticOpen', t('Automatically peel onload seconds must be a number between 0 and 999')); } // AutomaticClose validation if (!is_numeric($form_values['automaticClose']) || $form_values['automaticClose'] < 0) { form_set_error('automaticClose', t('Automatically peel onclose seconds must be a number between 0 and 999')); } // Close button color red value validation if (!is_numeric($form_values['close_redValue']) || $form_values['close_redValue'] < 0 || $form_values['close_redValue'] > 255) { form_set_error('close_redValue', t('Close button color red value must be a number between 0 and 255')); } // Close button color green value validation if (!is_numeric($form_values['close_greenValue']) || $form_values['close_greenValue'] < 0 || $form_values['close_greenValue'] > 255) { form_set_error('close_greenValue', t('Close button color green value must be a number between 0 and 255')); } // Close button color blue value validation if (!is_numeric($form_values['close_blueValue']) || $form_values['close_blueValue'] < 0 || $form_values['close_blueValue'] > 255) { form_set_error('close_blueValue', t('Close button color blue value must be a number between 0 and 255')); } } /** * hook_submit: submit function for the pageear configuration form. */ function pageear_admin_configure_submit($form_id, $form_values) { // Save the edited pageear if (!form_get_errors()) { if (module_exists('locale')) { $languages = implode(',', $form_values['languages']); } else { $languages = ''; } $roles = implode(',', $form_values['roles']); $sql = "UPDATE {pageears} SET"; $sql .= " status = '%d', name = '%s', peelPosition = '%s', smallURL = '%s', bigURL = '%s', mirror = '%d', inTransition = '%s', transitionDuration = '%d', peelColor = '%s', redValue = '%d', greenValue = '%d', blueValue = '%d', linkTarget = '%s', link = '%s', loadSoundURL = '%s', openSoundURL = '%s', closeSoundURL = '%s', flagSpeed = '%d', peelSpeed = '%d', automaticOpen = '%d', automaticClose = '%d', close_button_enable = '%d', text_on_close_button = '%s', close_redValue = '%d', close_greenValue = '%d', close_blueValue = '%d', languages = '%s', roles = '%s', visibility = '%d', pages = '%s'"; $sql .= " WHERE peid = %d"; db_query($sql, $form_values['status'], $form_values['name'], $form_values['peelPosition'], $form_values['smallURL'], $form_values['bigURL'], $form_values['mirror'], $form_values['inTransition'], $form_values['transitionDuration'], $form_values['peelColor'], $form_values['redValue'], $form_values['greenValue'], $form_values['blueValue'], $form_values['linkTarget'], $form_values['link'], $form_values['loadSoundURL'], $form_values['openSoundURL'], $form_values['closeSoundURL'], $form_values['flagSpeed'], $form_values['peelSpeed'], $form_values['automaticOpen'], $form_values['automaticClose'], $form_values['close_button_enable'], $form_values['text_on_close_button'], $form_values['close_redValue'], $form_values['close_greenValue'], $form_values['close_blueValue'], $languages, $roles, $form_values['visibility'], $form_values['pages'], $form_values['peid'] ); drupal_set_message(t('The pageear %name has been saved.', array('%name' => $form_values['name']))); } return 'admin/build/pageear'; } /** * hook_submit: when adding new pageear. */ function pageear_admin_add_submit($form_id, $form_values) { if (module_exists('locale')) { $languages = implode(',', $form_values['languages']); } else { $languages = ''; } $roles = implode(',', $form_values['roles']); $sql = "INSERT INTO {pageears} (status, name, peelPosition, smallURL, bigURL, mirror, inTransition, transitionDuration, peelColor, redValue, greenValue, blueValue, linkTarget, link, loadSoundURL, openSoundURL, closeSoundURL, flagSpeed, peelSpeed, automaticOpen, automaticClose, close_button_enable, text_on_close_button, close_redValue, close_greenValue, close_blueValue, languages, roles, visibility, pages)"; $sql .= " VALUES ('%d', '%s', '%s', '%s', '%s', '%d', '%s', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%d', '%s')"; db_query($sql, $form_values['status'], $form_values['name'], $form_values['peelPosition'], $form_values['smallURL'], $form_values['bigURL'], $form_values['mirror'], $form_values['inTransition'], $form_values['transitionDuration'], $form_values['peelColor'], $form_values['redValue'], $form_values['greenValue'], $form_values['blueValue'], $form_values['linkTarget'], $form_values['link'], $form_values['loadSoundURL'], $form_values['openSoundURL'], $form_values['closeSoundURL'], $form_values['flagSpeed'], $form_values['peelSpeed'], $form_values['automaticOpen'], $form_values['automaticClose'], $form_values['close_button_enable'], $form_values['text_on_close_button'], $form_values['close_redValue'], $form_values['close_greenValue'], $form_values['close_blueValue'], $languages, $roles, $form_values['visibility'], $form_values['pages'] ); // Move any images or sounds // to reflect the peid on its names // get last used peid $result = db_query("SELECT p.peid FROM {pageears} p ORDER BY peid"); while ($row = db_fetch_object($result)) { $last_used_peid = $row->peid; } $directory_path = file_directory_path() .'/'. PAGEEAR_PATH_IMAGES; foreach (array('smallURL', 'bigURL', 'loadSoundURL', 'openSoundURL', 'closeSoundURL') as $image_sound) { //if ($image_sound == 'smallURL' || $image_sound == 'bigURL') { // $extension = '.jpg'; //} //else { // $extension = '.mp3'; //} $stringparts = explode(".", $form_state['values'][$image_sound]); $extension = $stringparts[count($stringparts)-1]; $source_path = $form_values[$image_sound]; if ($source_path != '') { $destination_path = $directory_path .'/'. $image_sound .'_'. $last_used_peid . $extension; file_copy($source_path, $destination_path, FILE_EXISTS_REPLACE); $sql = "UPDATE {pageears} SET"; $sql .= " ". $image_sound ." = '%s'"; $sql .= " WHERE peid = %d"; db_query($sql, $destination_path, $last_used_peid ); } } // Delete possible images sounds uploaded as peid = 0 delete_images_sounds(0); drupal_set_message(t('The pageear %name has been created.', array('%name' => $form_values['name']))); return 'admin/build/pageear'; } /** * Menu callback: disable a specific pageear. */ function pageear_admin_disable($peid) { db_query("UPDATE {pageears} SET status = 0 WHERE peid = %d", $peid); drupal_goto('admin/build/pageear'); } /** * Menu callback: enable a specific pageear. */ function pageear_admin_enable($peid) { db_query("UPDATE {pageears} SET status = 1 WHERE peid = %d", $peid); drupal_goto('admin/build/pageear'); } /** * Deletes images and sounds for specific pageear. */ function delete_images_sounds($peid) { $directory_path = file_directory_path() .'/'. PAGEEAR_PATH_IMAGES; // if the directory where files reside does not exists nothing to do if (!file_check_directory($directory_path)) { return; } foreach (array('smallURL', 'bigURL', 'loadSoundURL', 'openSoundURL', 'closeSoundURL') as $image_sound) { if ($image_sound == 'smallURL' || $image_sound == 'bigURL') { $extensions = array('.jpg', '.jpeg', '.gif', '.png'); } else { $extensions = array('.mp3'); } foreach ($extensions as $extension) { $filename = $directory_path .'/'. $image_sound .'_'. $peid; $filepath = $filename . $extension; file_delete($filepath); $i = 0; $filepath = $filename .'_'. $i . $extension; while (file_delete($filepath)) { $i += 1; $filepath = $filename .'_'. $i . $extension; } } } } /** * Menu callback; confirm deletion of a pageear. */ function pageear_admin_delete($peid) { $form['pageear'] = array('#type' => 'hidden', '#value' => serialize(pageear_load($peid))); $params = array('%name' => $pageear->name); return confirm_form($form, t('Are you sure you want to delete the pageear %name?', $params), 'admin/build/pageear', NULL, t('Delete'), t('Cancel')); } /** * hook_submit: deletion of pageear confirmed. */ function pageear_admin_delete_submit($form_id, $form_values) { $pageear = unserialize($form_values['pageear']); db_query('DELETE FROM {pageears} WHERE peid = %d', $pageear->peid); delete_images_sounds($pageear->peid); drupal_set_message(t('The pageear %name has been removed.', array('%name' => $pageear->name))); return 'admin/build/pageear'; }