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_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('Edit pageears, how they look and where they appear on the site.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('pageear_list_form'), '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_edit', 'add', NULL), 'access' => user_access('administer pageears'), 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/build/pageear/edit', 'title' => t('Edit pageear'), 'callback' => 'drupal_get_form', 'callback arguments' => array('pageear_admin_edit', 'edit'), '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_edit', '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, ); } else { $num_active = variable_get('numEnabledPageears', 0); $current_topleft_pageear = FALSE; $current_topright_pageear = FALSE; $current_bottomleft_pageear = FALSE; $current_bottomright_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 $locale; $rids = array_keys($user->roles); $lang_name = $locale; // 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 == 'topleft' && $current_topleft_pageear) { continue; } if ($pageear->peelPosition == 'topright' && $current_topright_pageear) { continue; } if ($pageear->peelPosition == 'bottomleft' && $current_bottomleft_pageear) { continue; } if ($pageear->peelPosition == 'bottomright' && $current_bottomright_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']); $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; } // 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 switch ($pageear->peelPosition) { case 'topleft': $current_topleft_pageear = pageear_prepare($pageear); break; case 'topright': $current_topright_pageear = pageear_prepare($pageear); break; case 'bottomleft': $current_bottomleft_pageear = pageear_prepare($pageear); break; case 'bottomright': $current_bottomright_pageear = pageear_prepare($pageear); break; default: break; } // if all 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 && $current_bottomleft_pageear && $current_bottomright_pageear) { write_pageears($current_topleft_pageear, $current_topright_pageear, $current_bottomleft_pageear, $current_bottomright_pageear); return; } } } // All enabled pageears have been analyzed. Write pageears. if ($current_topleft_pageear || $current_topright_pageear || $current_bottomleft_pageear || $current_bottomright_pageear) { write_pageears($current_topleft_pageear, $current_topright_pageear, $current_bottomleft_pageear, $current_bottomright_pageear); } } } return $items; } /** * Output pageears. */ function write_pageears($current_topleft_pageear = FALSE, $current_topright_pageear = FALSE, $current_bottomleft_pageear = FALSE, $current_bottomright_pageear = FALSE) { if ($current_topleft_pageear || $current_topright_pageear || $current_bottomleft_pageear || $current_bottomright_pageear) { $path = drupal_get_path('module', 'pageear'); drupal_add_js($path .'/pageturn/swfobject.js', 'module', 'header', FALSE, FALSE); drupal_add_js($path .'/pageturn/pageTurn.js', 'module', 'header', FALSE, FALSE); 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 = substr_replace($js, "", -2, 1); $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 = substr_replace($js, "", -2, 1); $js .= "};\n"; $js .= "topright_pageear = new pageear(topright_pageearvars);\n"; $js .= "topright_pageear.write();\n"; } if ($current_bottomleft_pageear) { $js .= "bottomleft_pageearvars = {\n"; foreach ($current_bottomleft_pageear as $key => $value) { $js .= $key .": escape(". drupal_to_js($value) ."),\n"; } $js = substr_replace($js, "", -2, 1); $js .= "};\n"; $js .= "bottomleft_pageear = new pageear(bottomleft_pageearvars);\n"; $js .= "bottomleft_pageear.write();\n"; } if ($current_bottomright_pageear) { $js .= "bottomright_pageearvars = {\n"; foreach ($current_bottomright_pageear as $key => $value) { $js .= $key .": escape(". drupal_to_js($value) ."),\n"; } $js = substr_replace($js, "", -2, 1); $js .= "};\n"; $js .= "bottomright_pageear = new pageear(bottomright_pageearvars);\n"; $js .= "bottomright_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 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 .''; // Check plain link and text on close button $pageear->link = check_plain($pageear->link); $pageear->text_on_close_button = check_plain($pageear->text_on_close_button); 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", $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'), 'bottomleft' => t('Bottom left'), 'bottomright' => t('Bottom 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]; } } /** * Menu callback for admin/build/pageear. * List of pageears. */ function pageear_list_form() { $pageears = pageear_load(); if (count($pageears)) { foreach ($pageears as $pageear) { $form['pageears'][$pageear->peid] = array( '#tree' => TRUE, ); $form['pageears'][$pageear->peid]['peid'] = array( '#type' => 'hidden', '#value' => $pageear->peid, ); $form['pageears'][$pageear->peid]['name'] = array( '#value' => check_plain($pageear->name), ); $form['pageears'][$pageear->peid]['link'] = array( '#value' => check_plain($pageear->link), ); $form['pageears'][$pageear->peid]['peelPosition'] = array( '#value' => pageear_get_options('peelPosition', $pageear->peelPosition), ); $form['pageears'][$pageear->peid]['status'] = array( '#type' => 'checkbox', '#default_value' => (bool) (isset($form_state['pageears'][$pageear->peid]['status']) ? $form_state['pageears'][$pageear->peid]['status'] : $pageear->status), ); $form['pageears'][$pageear->peid]['weight'] = array( '#type' => 'weight', '#delta' => 50, '#default_value' => isset($form_state['pageears'][$pageear->peid]['weight']) ? $form_state['pageears'][$pageear->peid]['weight'] : $pageear->weight, ); $form['pageears'][$pageear->peid]['clone'] = array( '#value' => l(t('clone'), 'admin/build/pageear/clone/'. $pageear->peid), ); $form['pageears'][$pageear->peid]['edit'] = array( '#value' => l(t('edit'), 'admin/build/pageear/edit/'. $pageear->peid), ); $form['pageears'][$pageear->peid]['delete'] = array( '#value' => l(t('delete'), 'admin/build/pageear/delete/'. $pageear->peid), ); } $form['submit'] = array( '#type' => 'submit', '#value' => t('Save configuration'), ); } else { $form['empty'] = array('#value' => t('There are no pageears yet. !Add_new a pageear first.', array('!Add_new' => l(t('Add'), 'admin/build/pageear/add')))); } return $form; } /** * Theme: List of pageears. */ function theme_pageear_list_form($form) { $path = drupal_get_path('module', 'pageear'); drupal_add_css($path .'/pageear-admin.css', 'module', 'all', TRUE); $header = array( t('Pageear'), t('Link'), t('Position'), array('data' => t('Enabled'), 'class' => 'checkbox'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'), ); $pageears = array(); foreach (element_children($form['pageears']) as $peid) { $pageears[] = array( 'data' => array( drupal_render($form['pageears'][$peid]['name']), drupal_render($form['pageears'][$peid]['link']), drupal_render($form['pageears'][$peid]['peelPosition']), array( 'data' => drupal_render($form['pageears'][$peid]['status']), 'class' => 'checkbox' ), drupal_render($form['pageears'][$peid]['weight']), drupal_render($form['pageears'][$peid]['clone']), drupal_render($form['pageears'][$peid]['edit']), drupal_render($form['pageears'][$peid]['delete']), ), 'class' => $form['pageears'][$peid]['status']['#value'] ? 'enabled' : 'disabled', ); } $output = ''; if (count($pageears)) { $output .= theme('table', $header, $pageears, $attributes = array('class' => 'pageear-admin-list'), NULL); } $output .= drupal_render($form); return $output; } /** * Submit: List of pageears. */ function pageear_list_form_submit($form_id, $form_values) { $num_enabled_pageears = 0; // for each pageear update its status and its weight. foreach ($form_values as $peid) { if (is_array($peid)) { if ($peid['status']) { $num_enabled_pageears++; } $sql = "UPDATE {pageears} SET"; $sql .= " weight = '%d', status = '%d'"; $sql .= " WHERE peid = %d"; db_query($sql, $peid['weight'], $peid['status'], $peid['peid'] ); } } // Update the persistent variable numEnabledPageears that tracks number of pageears enabled variable_set('numEnabledPageears', $num_enabled_pageears); } /** * Menu callback; displays the pageear configuration form. * * Using the same form for three different operations ($op): * - 'edit': edit an existing pageear (default) * - 'add': add a new pageear * - 'clone': clone an existing pageear */ function pageear_admin_edit($op = 'edit', $peid) { if ($op == 'add' || !$peid) { $pageear = pageear_get_default(); } else { $pageear = pageear_load($peid); } if ($op == 'clone') { $pageear->peid = 0; } // Add Farbtastic color picker drupal_add_css('misc/farbtastic/farbtastic.css', 'module', 'all', TRUE); drupal_add_js('misc/farbtastic/farbtastic.js', 'module', 'header', FALSE, TRUE); $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 (you can edit visibility settings below).'), ); // previous status of this pageear before starting configuration $form['info']['previous_status'] = array( '#type' => 'hidden', '#value' => $pageear->status, ); $form['info']['name'] = array( '#type' => 'textfield', '#title' => t('Pageear name'), '#default_value' => $pageear->name, '#required' => TRUE, '#maxlength' => 64, '#size' => 40, ); // End Info // Details $form['details'] = array( '#type' => 'fieldset', '#title' => t('Pageear details'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); // Position settings. $form['details']['position_settings'] = array( '#type' => 'fieldset', '#title' => t('Position Settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); // Set position of pageear ( topleft, topright, bottomleft or bottomright). $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, '#attributes' => array('onclick' => 'checkPeelPosition()'), ); // Disable absolute position model if pageear is set on bottom corner $peel_position_check_js = "function checkPeelPosition() {\n"; $peel_position_check_js .= "(function($) {\n"; $peel_position_check_js .= "if ($('#edit-peelPosition-bottomleft-wrapper label input').attr('checked') || $('#edit-peelPosition-bottomright-wrapper label input').attr('checked')) {\n"; $peel_position_check_js .= "$('#edit-peelPositionModel-absolute-wrapper label input').attr('disabled', true);\n"; $peel_position_check_js .= "$('#edit-peelPositionModel-fixed-wrapper label input').attr('checked', true);\n"; $peel_position_check_js .= "} else {\n"; $peel_position_check_js .= "$('#edit-peelPositionModel-absolute-wrapper label input').removeAttr('disabled');\n"; $peel_position_check_js .= "}\n"; $peel_position_check_js .= "}) (jQuery);\n"; $peel_position_check_js .= "}"; drupal_add_js($peel_position_check_js, 'inline'); // Set position model of peageear ( absolute | fixed ). $form['details']['position_settings']['peelPositionModel'] = array( '#type' => 'radios', '#title' => t('Position Model'), '#description' => t('The CSS Position model you would prefer to use.'), '#options' => pageear_get_options('peelPositionModel'), '#default_value' => $pageear->peelPositionModel, '#required' => TRUE, ); $peel_position_model_ini_js = "(function($){\n"; $peel_position_model_ini_js .= "$(document).ready(function() {\n"; $peel_position_model_ini_js .= "if ($('#edit-peelPosition-bottomleft-wrapper label input').attr('checked') || $('#edit-peelPosition-bottomright-wrapper label input').attr('checked')) {\n"; $peel_position_model_ini_js .= "$('#edit-peelPositionModel-absolute-wrapper label input').attr('disabled', true);\n"; $peel_position_model_ini_js .= "}\n"; $peel_position_model_ini_js .= "});\n"; $peel_position_model_ini_js .= "}) (jQuery);"; drupal_add_js($peel_position_model_ini_js, 'inline'); // End Position settings. // Wait settings. $form['details']['wait_settings'] = array( '#type' => 'fieldset', '#title' => t('Wait Icon Settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['details']['wait_settings']['waitEnable'] = array( '#type' => 'checkbox', '#title' => t('Enable wait icon'), '#default_value' => $pageear->waitEnable, '#description' => t('If this setting is enabled, a wait icon will be displayed while pageear is loading.'), ); // Set wait icon width $form['details']['wait_settings']['waitWidth'] = array( '#type' => 'textfield', '#title' => t('Wait Icon Width'), '#required' => TRUE, '#default_value' => $pageear->waitWidth, '#maxlength' => 3, '#size' => 8, ); // Set wait icon height $form['details']['wait_settings']['waitHeight'] = array( '#type' => 'textfield', '#title' => t('Wait Icon Height'), '#required' => TRUE, '#default_value' => $pageear->waitHeight, '#maxlength' => 3, '#size' => 8, ); // URL to wait icon. $form['details']['wait_settings']['waitURL'] = array( '#type' => 'item', '#title' => t('Wait icon'), '#value' => check_plain($pageear->waitURL), ); $form['details']['wait_settings']['waitURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an image to show while pageear is loading (most common an animated GIF, Wait Icon Width x Wait Icon Height pixels).'), '#tree' => FALSE, '#size' => 40, ); // End wait settings. // Style settings. $form['details']['style_settings'] = array( '#type' => 'fieldset', '#title' => t('Style Settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); // Style of flag ('style1' | 'style2'). $form['details']['style_settings']['flagStyle'] = array( '#type' => 'select', '#title' => t('Flag Style'), '#options' => pageear_get_options('flagStyle'), '#default_value' => $pageear->flagStyle, '#required' => TRUE, ); // Style of peel ('style1' | 'style2'). $form['details']['style_settings']['peelStyle'] = array( '#type' => 'select', '#title' => t('Peel Style'), '#options' => pageear_get_options('peelStyle'), '#default_value' => $pageear->peelStyle, '#required' => TRUE, ); // End Style settings. // Size Settings. $form['details']['size_settings'] = array( '#type' => 'fieldset', '#title' => t('Size Settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#description' => t('Design sizes are 100x100px and 500x500px for flag and peel respectively. If you decide to use a custom size try to use logical values. For example it makes not sense to use a larger size for the flag than for the peel. For a further explanation refer to !pageear_size_manual.', array('!pageear_size_manual' => l(t('howto on home page'), 'http://www.pageeargpl.co.cc/content/size-settings', array('target' => '_blank')))), ); // Set flag width $form['details']['size_settings']['flagWidth'] = array( '#type' => 'textfield', '#title' => t('Flag Width'), '#required' => TRUE, '#default_value' => $pageear->flagWidth, '#maxlength' => 4, '#size' => 8, ); // Set flag height $form['details']['size_settings']['flagHeight'] = array( '#type' => 'textfield', '#title' => t('Flag Height'), '#required' => TRUE, '#default_value' => $pageear->flagHeight, '#maxlength' => 4, '#size' => 8, ); // Set peel width $form['details']['size_settings']['peelWidth'] = array( '#type' => 'textfield', '#title' => t('Peel Width'), '#required' => TRUE, '#default_value' => $pageear->peelWidth, '#maxlength' => 5, '#size' => 8, ); // Set peel height $form['details']['size_settings']['peelHeight'] = array( '#type' => 'textfield', '#title' => t('Peel Height'), '#required' => TRUE, '#default_value' => $pageear->peelHeight, '#maxlength' => 5, '#size' => 8, ); // End Size settings. // Image Settings. $form['details']['image_settings'] = array( '#type' => 'fieldset', '#title' => t('Image Settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); // URL to small image. $form['details']['image_settings']['smallURL'] = array( '#type' => 'item', '#title' => t('Unpeeled image'), '#value' => check_plain($pageear->smallURL), ); $form['details']['image_settings']['smallURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an image to show when the ad is not peeled (JPG, GIF or PNG 100x100 pixels).'), '#tree' => FALSE, '#size' => 40, ); // URL to big image. $form['details']['image_settings']['bigURL'] = array( '#type' => 'item', '#title' => t('Peeled image'), '#value' => check_plain($pageear->bigURL), ); $form['details']['image_settings']['bigURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an image to show when the ad is peeled (JPG, GIF or PNG 500x500 pixels).'), '#tree' => FALSE, '#size' => 40, ); // 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, '#size' => 8, ); // Style of peel back color. $form['details']['image_settings']['peelColorStyle'] = array( '#type' => 'radios', '#title' => t('Back color style'), '#description' => t('Choose a flat or gradient color for the back of the peel.'), '#options' => pageear_get_options('peelColorStyle'), '#default_value' => $pageear->peelColorStyle, '#required' => TRUE, ); // 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 on Peel. $form['details']['image_settings']['custom_color'] = array( '#type' => 'textfield', '#title' => t('Custom Color'), '#required' => TRUE, '#prefix' => '
', '#default_value' => rgb2hex($pageear->redValue, $pageear->greenValue, $pageear->blueValue), '#maxlength' => 7, '#size' => 8, ); $customcolor_picker_ini = "(function($) {\n"; $customcolor_picker_ini .= "$(document).ready(function() {\n"; $customcolor_picker_ini .= "$('#pageear-customcolor-picker').farbtastic('#edit-custom-color');\n"; $customcolor_picker_ini .= "})\n"; $customcolor_picker_ini .= "}) (jQuery);"; drupal_add_js($customcolor_picker_ini, 'inline'); // Red Value for Custom Color Peel. $form['details']['image_settings']['redValue'] = array( '#type' => 'hidden', '#value' => $pageear->redValue, ); // Green Value for Custom Color Peel. $form['details']['image_settings']['greenValue'] = array( '#type' => 'hidden', '#value' => $pageear->greenValue, ); // Blue Value for Custom Color Peel. $form['details']['image_settings']['blueValue'] = array( '#type' => 'hidden', '#value' => $pageear->blueValue, ); // End Image Settings. // Sound Settings. $form['details']['sound_settings'] = array( '#type' => 'fieldset', '#title' => t('Sound Settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); // URL to onload sound. $form['details']['sound_settings']['loadSoundURL'] = array( '#type' => 'item', '#title' => t('Onload Sound'), '#value' => check_plain($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, '#size' => 40, ); if ($pageear->loadSoundURL != "") { $form['details']['sound_settings']['loadSoundRemove'] = array( '#type' => 'checkbox', '#default_value' => 0, '#description' => t('Check this box if you want to remove load sound.'), ); } // URL to open peel sound. $form['details']['sound_settings']['openSoundURL'] = array( '#type' => 'item', '#title' => t('Open Peel Sound'), '#value' => check_plain($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, '#size' => 40, ); if ($pageear->openSoundURL != "") { $form['details']['sound_settings']['openSoundRemove'] = array( '#type' => 'checkbox', '#default_value' => 0, '#description' => t('Check this box if you want to remove open sound.'), ); } // URL to close peel sound. $form['details']['sound_settings']['closeSoundURL'] = array( '#type' => 'item', '#title' => t('Close Peel Sound'), '#value' => check_plain($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, '#size' => 40, ); if ($pageear->closeSoundURL != "") { $form['details']['sound_settings']['closeSoundRemove'] = array( '#type' => 'checkbox', '#default_value' => 0, '#description' => t('Check this box if you want to remove close sound.'), ); } // End Sound Settings. // Linking Settings. $form['details']['linking_settings'] = array( '#type' => 'fieldset', '#title' => t('URL Settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); // Link Enable ( true | false ). $form['details']['linking_settings']['linkEnabled'] = array( '#type' => 'checkbox', '#title' => t('Enabled'), '#default_value' => $pageear->linkEnabled, '#description' => t('Enable or disable the link.'), ); // 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, '#size' => 40, ); // 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, '#collapsed' => 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, '#size' => 8, ); // 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, '#size' => 8, ); // 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, '#size' => 8, ); // 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, '#size' => 8, ); // End Motion Settings. // Close button settings. $form['details']['closebutton_settings'] = array( '#type' => 'fieldset', '#title' => t('Close Button Settings'), '#collapsible' => TRUE, '#collapsed' => 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, '#maxlength' => 20, '#size' => 40, ); // Close Button Color. $form['details']['closebutton_settings']['closebutton_color'] = array( '#type' => 'textfield', '#title' => t('Close Button Color'), '#required' => TRUE, '#prefix' => '
', '#default_value' => rgb2hex($pageear->close_redValue, $pageear->close_greenValue, $pageear->close_blueValue), '#maxlength' => 7, '#size' => 8, ); $closebuttoncolor_picker_ini = "(function($) {\n"; $closebuttoncolor_picker_ini .= "$(document).ready(function() {\n"; $closebuttoncolor_picker_ini .= "$('#pageear-closebuttoncolor-picker').farbtastic('#edit-closebutton-color');\n"; $closebuttoncolor_picker_ini .= "})\n"; $closebuttoncolor_picker_ini .= "}) (jQuery);"; drupal_add_js($closebuttoncolor_picker_ini, 'inline'); // Close Button Color Red Value. $form['details']['closebutton_settings']['close_redValue'] = array( '#type' => 'hidden', '#value' => $pageear->close_redValue, ); // Close Button Color Green Value. $form['details']['closebutton_settings']['close_greenValue'] = array( '#type' => 'hidden', '#value' => $pageear->close_greenValue, ); // Close Button Color Blue Value. $form['details']['closebutton_settings']['close_blueValue'] = array( '#type' => 'hidden', '#value' => $pageear->close_blueValue, ); // End Close Button Settings. // Visibility settings. $form['visibility_settings'] = array( '#type' => 'fieldset', '#title' => t('Pageear visibility settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); // Language-based visibility settings - only visible if 'locale' module enabled if (module_exists('locale')) { $form['visibility_settings']['language_vis_settings'] = array( '#type' => 'fieldset', '#title' => t('Language specific visibility settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $language_enabled = locale_supported_languages(TRUE); $language_options = $language_enabled['name']; $form['visibility_settings']['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['visibility_settings']['roles_vis_settings'] = array( '#type' => 'fieldset', '#title' => t('Role specific visibility settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['visibility_settings']['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['visibility_settings']['page_vis_settings'] = array( '#type' => 'fieldset', '#title' => t('Page specific visibility settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $access = user_access('use PHP for pageear visibility'); if ($pageear->visibility == 2 && !$access) { $form['visibility_settings']['page_vis_settings'] = array(); $form['visibility_settings']['page_vis_settings']['visibility'] = array( '#type' => 'value', '#value' => 2, ); $form['visibility_settings']['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['visibility_settings']['page_vis_settings']['visibility'] = array( '#type' => 'radios', '#title' => t('Show pageear on specific pages'), '#options' => $options, '#default_value' => $pageear->visibility, ); $form['visibility_settings']['page_vis_settings']['pages'] = array( '#type' => 'textarea', '#title' => t('Pages'), '#default_value' => $pageear->pages, '#description' => $description, ); } if ($op == 'edit') { $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_edit_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'); if ($file = file_save_upload('waitURL_upload')) { $parts = pathinfo($file->filename); if ($parts['extension'] != 'jpeg' && $parts['extension'] != 'jpg' && $parts['extension'] != 'gif' && $parts['extension'] != 'png') { file_delete($file->filepath); form_set_error('waitURL_upload', t('Uploaded file must be an image. JPEG, PNG or GIF')); } else { $dest_filename = $directory_path .'/waitURL_'. $form_values['peid'] .'.'. $parts['extension']; $source_path = $file->filepath; // copy temp uploaded file to its destination // and delete temp uploaded file if (file_copy($source_path, $dest_filename)) { file_delete($file->filepath); form_set_value($form['details']['wait_settings']['waitURL'], $source_path); } else { file_delete($file->filepath); form_set_error('waitURL_upload', t('Wait icon upload failed. Please try again.')); } } } else { form_set_value($form['details']['wait_settings']['waitURL'], $form['details']['wait_settings']['waitURL']['#value']); } // 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' && $parts['extension'] != 'swf') { file_delete($file->filepath); form_set_error($image .'_upload', t('Uploaded file must be an image or flash movie. JPEG, PNG, GIF or SWF')); } else { $dest_filename = $directory_path .'/'. $image .'_'. $form_values['peid'] .'.'. $parts['extension']; $source_path = $file->filepath; if (file_copy($source_path, $dest_filename)) { file_delete($file->filepath); form_set_value($form['details']['image_settings'][$image], $source_path); } else { file_delete($file->filepath); form_set_error($image .'_upload', t('Media upload failed. Please try again.')); } } } else { form_set_value($form['details']['image_settings'][$image], $form['details']['image_settings'][$image]['#value']); } } // 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') { file_delete($file->filepath); form_set_error($sound .'_upload', t('Uploaded sound must be a MP3 file.')); } else { $dest_filename = $directory_path .'/'. $sound .'_'. $form_values['peid'] .'.'. $parts['extension']; $source_path = $file->filepath; if (file_copy($source_path, $dest_filename)) { file_delete($file->filepath); form_set_value($form['details']['sound_settings'][$sound], $source_path); } else { file_delete($file->filepath); form_set_error($sound .'_upload', t('Sound upload failed. Please try again.')); } } } else { form_set_value($form['details']['sound_settings'][$sound], $form['details']['sound_settings'][$sound]['#value']); } } // Remove sounds checked for removal // TODO remove files too or wait till they are removed when the pageear is removed? if ($form_values['loadSoundRemove']) { form_set_value($form['details']['sound_settings']['loadSoundURL'], ''); } if ($form_values['openSoundRemove']) { form_set_value($form['details']['sound_settings']['openSoundURL'], ''); } if ($form_values['closeSoundRemove']) { form_set_value($form['details']['sound_settings']['closeSoundURL'], ''); } // Sizes validation // TODO Review if I must restrict this more. For example test the ratio peel/flag. if (!is_numeric($form_values['waitWidth']) || $form_values['waitWidth'] < 10) { form_set_error('waitWidth', t('Wait Icon Width must be a number greater than 10')); } if (!is_numeric($form_values['waitHeight']) || $form_values['waitHeight'] < 10) { form_set_error('waitHeight', t('Wait Icon Height must be a number greater than 10')); } if (!is_numeric($form_values['flagWidth']) || $form_values['flagWidth'] < 10) { form_set_error('flagWidth', t('Flag Width must be a number greater than 10')); } if (!is_numeric($form_values['flagHeight']) || $form_values['flagHeight'] < 10) { form_set_error('flagHeight', t('Flag Height must be a number greater than 10')); } if (!is_numeric($form_values['peelWidth']) || $form_values['peelWidth'] < 50) { form_set_error('peelWidth', t('Peel Width must be a number greater than 50')); } if (!is_numeric($form_values['peelHeight']) || $form_values['peelHeight'] < 50) { form_set_error('peelHeight', t('Peel Height must be a number greater than 50')); } // 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 validation. // If user sets color manually with input textfield wrong hex values would be ignored by conversion function. $custom_rgb_peel_color = hex2rgb($form_values['custom_color']); form_set_value($form['details']['image_settings']['redValue'], $custom_rgb_peel_color[0]); form_set_value($form['details']['image_settings']['greenValue'], $custom_rgb_peel_color[1]); form_set_value($form['details']['image_settings']['blueValue'], $custom_rgb_peel_color[2]); // 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 validation // If user sets color manually with input textfield wrong hex values would be ignored by conversion function. $custom_rgb_close_button_color = hex2rgb($form_values['closebutton_color']); form_set_value($form['details']['closebutton_settings']['close_redValue'], $custom_rgb_close_button_color[0]); form_set_value($form['details']['closebutton_settings']['close_greenValue'], $custom_rgb_close_button_color[1]); form_set_value($form['details']['closebutton_settings']['close_blueValue'], $custom_rgb_close_button_color[2]); // Text on close button if (preg_match("/^[a-z][a-z ]+$/", $form_values['text_on_close_button']) == 0) { form_set_error('text_on_close_button', t('Only lowercase letters and spaces are allowed for text on close button. It must start with a lowercase letter too.')); } } /** * hook_submit: submit function for the pageear configuration form. */ function pageear_admin_edit_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', peelPositionModel = '%s', waitEnable = '%d', waitURL = '%s', waitWidth = '%d', waitHeight = '%d', flagStyle = '%s', peelStyle = '%s', flagWidth = '%d', flagHeight = '%d', peelWidth = '%d', peelHeight = '%d', smallURL = '%s', bigURL = '%s', mirror = '%d', inTransition = '%s', transitionDuration = '%d', peelColorStyle = '%s', peelColor = '%s', redValue = '%d', greenValue = '%d', blueValue = '%d', linkEnabled = '%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['peelPositionModel'], $form_values['waitEnable'], $form_values['waitURL'], $form_values['waitWidth'], $form_values['waitHeight'], $form_values['flagStyle'], $form_values['peelStyle'], $form_values['flagWidth'], $form_values['flagHeight'], $form_values['peelWidth'], $form_values['peelHeight'], $form_values['smallURL'], $form_values['bigURL'], $form_values['mirror'], $form_values['inTransition'], $form_values['transitionDuration'], $form_values['peelColorStyle'], $form_values['peelColor'], $form_values['redValue'], $form_values['greenValue'], $form_values['blueValue'], $form_values['linkEnabled'], $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'] ); // Update the global variable numEnabledPageears that tracks number of pageears enabled if ($form_values['status'] != $form_values['previous_status']) { if ($form_values['status']) { variable_set('numEnabledPageears', variable_get('numEnabledPageears', 0) + 1); } else { variable_set('numEnabledPageears', variable_get('numEnabledPageears', 1) - 1); } } 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, peelPositionModel, waitEnable, waitURL, waitWidth, waitHeight, flagStyle, peelStyle, flagWidth, flagHeight, peelWidth, peelHeight, smallURL, bigURL, mirror, inTransition, transitionDuration, peelColorStyle, peelColor, redValue, greenValue, blueValue, linkEnabled, 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', '%d', '%s', '%d', '%d', '%s', '%s', '%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s', '%d', '%s', '%s', '%d', '%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['peelPositionModel'], $form_values['waitEnable'], $form_values['waitURL'], $form_values['waitWidth'], $form_values['waitHeight'], $form_values['flagStyle'], $form_values['peelStyle'], $form_values['flagWidth'], $form_values['flagHeight'], $form_values['peelWidth'], $form_values['peelHeight'], $form_values['smallURL'], $form_values['bigURL'], $form_values['mirror'], $form_values['inTransition'], $form_values['transitionDuration'], $form_values['peelColorStyle'], $form_values['peelColor'], $form_values['redValue'], $form_values['greenValue'], $form_values['blueValue'], $form_values['linkEnabled'], $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('waitURL', 'smallURL', 'bigURL', 'loadSoundURL', 'openSoundURL', 'closeSoundURL') as $image_sound) { //if ($image_sound == 'smallURL' || $image_sound == 'bigURL') { // $extension = '.jpg'; //} //else { // $extension = '.mp3'; //} $stringparts = explode(".", $form_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); // Update the global variable numEnabledPageears that tracks number of pageears enabled if ($form_values['status']) { variable_set('numEnabledPageears', variable_get('numEnabledPageears', 0) + 1); } 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); // Update the global variable numEnabledPageears that tracks number of pageears enabled variable_set('numEnabledPageears', variable_get('numEnabledPageears', 1) - 1); 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); // Update the global variable numEnabledPageears that tracks number of pageears enabled variable_set('numEnabledPageears', variable_get('numEnabledPageears', 0) + 1); 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('waitURL', 'smallURL', 'bigURL', 'loadSoundURL', 'openSoundURL', 'closeSoundURL') as $image_sound) { if ($image_sound == 'waitURL' || $image_sound == 'smallURL' || $image_sound == 'bigURL') { $extensions = array('.jpg', '.jpeg', '.gif', '.png', '.swf'); } 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'; } /** * Helper functions for color conversions */ function hex2rgb($color) { if ($color[0] == '#') { $color = drupal_substr($color, 1); } if (drupal_strlen($color) == 6) { list($r, $g, $b) = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); } elseif (drupal_strlen($color) == 3) { list($r, $g, $b) = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); } else { return array(0, 0, 0); } $r = hexdec($r); $g = hexdec($g); $b = hexdec($b); return array($r, $g, $b); } function rgb2hex($r, $g=-1, $b=-1) { if (is_array($r) && sizeof($r) == 3) { list($r, $g, $b) = $r; } $r = intval($r); $g = intval($g); $b = intval($b); $r = dechex($r<0?0:($r>255?255:$r)); $g = dechex($g<0?0:($g>255?255:$g)); $b = dechex($b<0?0:($b>255?255:$b)); $color = (drupal_strlen($r) < 2?'0':'') . $r; $color .= (drupal_strlen($g) < 2?'0':'') . $g; $color .= (drupal_strlen($b) < 2?'0':'') . $b; return '#'. $color; }