peid] = array( '#tree' => TRUE, ); $form['pageears'][$pageear->peid]['peid'] = array( '#type' => 'hidden', '#value' => $pageear->peid, ); $form['pageears'][$pageear->peid]['name'] = array( '#value' => $pageear->name, ); $form['pageears'][$pageear->peid]['link'] = array( '#value' => $pageear->link, ); $form['pageears'][$pageear->peid]['peelPosition'] = array( '#value' => $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/'. $pageear->peid .'/clone'), ); $form['pageears'][$pageear->peid]['edit'] = array( '#value' => l(t('edit'), 'admin/build/pageear/'. $pageear->peid .'/edit'), ); $form['pageears'][$pageear->peid]['delete'] = array( '#value' => l(t('delete'), 'admin/build/pageear/'. $pageear->peid .'/delete'), ); } $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) { $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) { $form['pageears'][$peid]['weight']['#attributes']['class'] = 'pageear-weight'; $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' => 'draggable', ); } $output = ''; if (count($pageears)) { $output .= theme('table', $header, $pageears, array('id' => 'order-pageears')); } $output .= drupal_render($form); drupal_add_tabledrag('order-pageears', 'order', 'sibling', 'pageear-weight'); return $output; } /** * Submit: List of pageears. */ function pageear_list_form_submit($form, &$form_state) { $num_enabled_pageears = 0; // for each pageear update its status and its weight. foreach (element_children($form['pageears']) as $peid) { $pageear->peid = $form['pageears'][$peid]['peid']['#value']; $pageear->weight = $form['pageears'][$peid]['weight']['#value']; $pageear->status = $form['pageears'][$peid]['status']['#value']; if ($pageear->status) { $num_enabled_pageears++; } drupal_write_record('pageears', $pageear, '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($form_state, $pageear, $op = 'edit') { if ($op == 'add' || !$pageear->peid) { $pageear = pageear_get_default(); } 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, FALSE, TRUE); // Add js that links farbtastic pickers with its input fields drupal_add_js(drupal_get_path('module', 'pageear') .'/earsConfigForm_farbtastic_ini.js', 'module', 'header', FALSE, 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 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, ); // 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, ); // 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' => $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('attributes' => 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' => $pageear->smallURL, ); $form['details']['image_settings']['smallURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an image or flash movie to show when the ad is not peeled (JPG, GIF, PNG or SWF, Flag Width x Flag Height pixels).'), '#tree' => FALSE, '#size' => 40, ); // URL to big image. $form['details']['image_settings']['bigURL'] = array( '#type' => 'item', '#title' => t('Peeled image'), '#value' => $pageear->bigURL, ); $form['details']['image_settings']['bigURL_upload'] = array( '#type' => 'file', '#description' => t('Upload an image or flash movie to show when the ad is peeled (JPG, GIF, PNG or SWF, Peel Width x Peel Height 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('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. $form['details']['image_settings']['custom_color'] = array( '#type' => 'fieldset', '#title' => t('Custom Color'), '#collapsible' => 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, ); // 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' => $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' => $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' => $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, '#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, ); // 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_options = locale_language_list('name'); $form['visibility_settings']['language_vis_settings']['languages'] = array( '#type' => 'checkboxes', '#title' => t('Show pageear for specific languages'), '#options' => $language_options, '#default_value' => explode(',', $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' => explode(',', $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.'), ); // Page visibility settings $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()), ); } elseif ($op == 'add' || $op == 'clone') { $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), '#submit' => array('pageear_admin_add_submit'), ); $form['cancel'] = array( '#type' => 'markup', '#value' => l(t('Cancel'), referer_uri()), ); } return $form; } /** * hook_validate: validation function for the pageear configuration form. */ function pageear_admin_edit_validate($form, &$form_state) { $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')) { //, array('file_validate_is_image' => array()))) { $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_state['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, $form_state); } 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'], $form_state); } // uploads images from image upload fields foreach (array('smallURL', 'bigURL') as $image) { if ($file = file_save_upload($image .'_upload')) { //, array('file_validate_is_image' => array()))) { $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_state['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, $form_state); } 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'], $form_state); } } // 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_state['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, $form_state); } 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'], $form_state); } } // Remove sounds checked for removal // TODO remove files too or wait till they are removed when the pageear is removed? if ($form_state['values']['loadSoundRemove']) { form_set_value($form['details']['sound_settings']['loadSoundURL'], '', $form_state); } if ($form_state['values']['openSoundRemove']) { form_set_value($form['details']['sound_settings']['openSoundURL'], '', $form_state); } if ($form_state['values']['closeSoundRemove']) { form_set_value($form['details']['sound_settings']['closeSoundURL'], '', $form_state); } // Sizes validation // TODO Review if I must restrict this more. For example test the ratio peel/flag. if (!is_numeric($form_state['values']['waitWidth']) || $form_state['values']['waitWidth'] < 10) { form_set_error('waitWidth', t('Wait Icon Width must be a number greater than 10')); } if (!is_numeric($form_state['values']['waitHeight']) || $form_state['values']['waitHeight'] < 10) { form_set_error('waitHeight', t('Wait Icon Height must be a number greater than 10')); } if (!is_numeric($form_state['values']['flagWidth']) || $form_state['values']['flagWidth'] < 10) { form_set_error('flagWidth', t('Flag Width must be a number greater than 10')); } if (!is_numeric($form_state['values']['flagHeight']) || $form_state['values']['flagHeight'] < 10) { form_set_error('flagHeight', t('Flag Height must be a number greater than 10')); } if (!is_numeric($form_state['values']['peelWidth']) || $form_state['values']['peelWidth'] < 50) { form_set_error('peelWidth', t('Peel Width must be a number greater than 50')); } if (!is_numeric($form_state['values']['peelHeight']) || $form_state['values']['peelHeight'] < 50) { form_set_error('peelHeight', t('Peel Height must be a number greater than 50')); } // Duration of transition validation if (!is_numeric($form_state['values']['transitionDuration']) || $form_state['values']['transitionDuration'] == 0) { form_set_error('transitionDuration', t('Transition duration 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_state['values']['custom_color']); form_set_value($form['details']['image_settings']['redValue'], $custom_rgb_peel_color[0], $form_state); form_set_value($form['details']['image_settings']['greenValue'], $custom_rgb_peel_color[1], $form_state); form_set_value($form['details']['image_settings']['blueValue'], $custom_rgb_peel_color[2], $form_state); // Flag speed validation if (!is_numeric($form_state['values']['flagSpeed']) || $form_state['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_state['values']['peelSpeed']) || $form_state['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_state['values']['automaticOpen']) || $form_state['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_state['values']['automaticClose']) || $form_state['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_state['values']['closebutton_color']); form_set_value($form['details']['closebutton_settings']['close_redValue'], $custom_rgb_close_button_color[0], $form_state); form_set_value($form['details']['closebutton_settings']['close_greenValue'], $custom_rgb_close_button_color[1], $form_state); form_set_value($form['details']['closebutton_settings']['close_blueValue'], $custom_rgb_close_button_color[2], $form_state); } /** * hook_submit: submit function for the pageear configuration form. */ function pageear_admin_edit_submit($form, &$form_state) { // Save the edited pageear if (!form_get_errors()) { if (module_exists('locale')) { $languages = implode(',', $form_state['values']['languages']); } else { $languages = ''; } $roles = implode(',', $form_state['values']['roles']); $new_pageear = new stdClass(); $new_pageear->peid = $form_state['values']['peid']; $new_pageear->status = $form_state['values']['status']; $new_pageear->name = $form_state['values']['name']; $new_pageear->peelPosition = $form_state['values']['peelPosition']; $new_pageear->peelPositionModel = $form_state['values']['peelPositionModel']; $new_pageear->waitEnable = $form_state['values']['waitEnable']; $new_pageear->waitWidth = $form_state['values']['waitWidth']; $new_pageear->waitHeight = $form_state['values']['waitHeight']; $new_pageear->waitURL = $form_state['values']['waitURL']; $new_pageear->flagStyle = $form_state['values']['flagStyle']; $new_pageear->peelStyle = $form_state['values']['peelStyle']; $new_pageear->flagWidth = $form_state['values']['flagWidth']; $new_pageear->flagHeight = $form_state['values']['flagHeight']; $new_pageear->peelWidth = $form_state['values']['peelWidth']; $new_pageear->peelHeight = $form_state['values']['peelHeight']; $new_pageear->smallURL = $form_state['values']['smallURL']; $new_pageear->bigURL = $form_state['values']['bigURL']; $new_pageear->mirror = $form_state['values']['mirror']; $new_pageear->inTransition = $form_state['values']['inTransition']; $new_pageear->transitionDuration = $form_state['values']['transitionDuration']; $new_pageear->peelColorStyle = $form_state['values']['peelColorStyle']; $new_pageear->peelColor = $form_state['values']['peelColor']; $new_pageear->redValue = $form_state['values']['redValue']; $new_pageear->greenValue = $form_state['values']['greenValue']; $new_pageear->blueValue = $form_state['values']['blueValue']; $new_pageear->linkEnabled = $form_state['values']['linkEnabled']; $new_pageear->linkTarget = $form_state['values']['linkTarget']; $new_pageear->link = $form_state['values']['link']; $new_pageear->loadSoundURL = $form_state['values']['loadSoundURL']; $new_pageear->openSoundURL = $form_state['values']['openSoundURL']; $new_pageear->closeSoundURL = $form_state['values']['closeSoundURL']; $new_pageear->flagSpeed = $form_state['values']['flagSpeed']; $new_pageear->peelSpeed = $form_state['values']['peelSpeed']; $new_pageear->automaticOpen = $form_state['values']['automaticOpen']; $new_pageear->automaticClose = $form_state['values']['automaticClose']; $new_pageear->close_button_enable = $form_state['values']['close_button_enable']; $new_pageear->text_on_close_button = $form_state['values']['text_on_close_button']; $new_pageear->close_redValue = $form_state['values']['close_redValue']; $new_pageear->close_greenValue = $form_state['values']['close_greenValue']; $new_pageear->close_blueValue = $form_state['values']['close_blueValue']; $new_pageear->languages = $languages; $new_pageear->roles = $roles; $new_pageear->visibility = $form_state['values']['visibility']; $new_pageear->pages = $form_state['values']['pages']; drupal_write_record('pageears', $new_pageear, 'peid'); // Update the persistent variable numEnabledPageears that tracks number of pageears enabled if ($form_state['values']['status'] != $form_state['values']['previous_status']) { if ($form_state['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_state['values']['name']))); $form_state['redirect'] = 'admin/build/pageear'; } return; } /** * hook_submit: when adding new pageear. */ function pageear_admin_add_submit($form, &$form_state) { if (module_exists('locale')) { $languages = implode(',', $form_state['values']['languages']); } else { $languages = ''; } $roles = implode(',', $form_state['values']['roles']); // Writes new pageear $new_pageear = new stdClass(); $new_pageear->status = $form_state['values']['status']; $new_pageear->name = $form_state['values']['name']; $new_pageear->peelPosition = $form_state['values']['peelPosition']; $new_pageear->peelPositionModel = $form_state['values']['peelPositionModel']; $new_pageear->waitEnable = $form_state['values']['waitEnable']; $new_pageear->waitWidth = $form_state['values']['waitWidth']; $new_pageear->waitHeight = $form_state['values']['waitHeight']; $new_pageear->waitURL = $form_state['values']['waitURL']; $new_pageear->flagStyle = $form_state['values']['flagStyle']; $new_pageear->peelStyle = $form_state['values']['peelStyle']; $new_pageear->flagWidth = $form_state['values']['flagWidth']; $new_pageear->flagHeight = $form_state['values']['flagHeight']; $new_pageear->peelWidth = $form_state['values']['peelWidth']; $new_pageear->peelHeight = $form_state['values']['peelHeight']; $new_pageear->smallURL = $form_state['values']['smallURL']; $new_pageear->bigURL = $form_state['values']['bigURL']; $new_pageear->mirror = $form_state['values']['mirror']; $new_pageear->inTransition = $form_state['values']['inTransition']; $new_pageear->transitionDuration = $form_state['values']['transitionDuration']; $new_pageear->peelColorStyle = $form_state['values']['peelColorStyle']; $new_pageear->peelColor = $form_state['values']['peelColor']; $new_pageear->redValue = $form_state['values']['redValue']; $new_pageear->greenValue = $form_state['values']['greenValue']; $new_pageear->blueValue = $form_state['values']['blueValue']; $new_pageear->linkEnabled = $form_state['values']['linkEnabled']; $new_pageear->linkTarget = $form_state['values']['linkTarget']; $new_pageear->link = $form_state['values']['link']; $new_pageear->loadSoundURL = $form_state['values']['loadSoundURL']; $new_pageear->openSoundURL = $form_state['values']['openSoundURL']; $new_pageear->closeSoundURL = $form_state['values']['closeSoundURL']; $new_pageear->flagSpeed = $form_state['values']['flagSpeed']; $new_pageear->peelSpeed = $form_state['values']['peelSpeed']; $new_pageear->automaticOpen = $form_state['values']['automaticOpen']; $new_pageear->automaticClose = $form_state['values']['automaticClose']; $new_pageear->close_button_enable = $form_state['values']['close_button_enable']; $new_pageear->text_on_close_button = $form_state['values']['text_on_close_button']; $new_pageear->close_redValue = $form_state['values']['close_redValue']; $new_pageear->close_greenValue = $form_state['values']['close_greenValue']; $new_pageear->close_blueValue = $form_state['values']['close_blueValue']; $new_pageear->languages = $languages; $new_pageear->roles = $roles; $new_pageear->visibility = $form_state['values']['visibility']; $new_pageear->pages = $form_state['values']['pages']; drupal_write_record('pageears', $new_pageear); // Move any images or sounds // to reflect the peid on its names $directory_path = file_directory_path() .'/'. PAGEEAR_PATH_IMAGES; foreach (array('waitURL', 'smallURL', 'bigURL', 'loadSoundURL', 'openSoundURL', 'closeSoundURL') as $image_sound) { $stringparts = explode(".", $form_state['values'][$image_sound]); $extension = $stringparts[count($stringparts)-1]; $source_path = $form_state['values'][$image_sound]; if ($source_path != '') { $destination_path = $directory_path .'/'. $image_sound .'_'. $new_pageear->peid .'.'. $extension; file_copy($source_path, $destination_path, FILE_EXISTS_REPLACE); $new_pageear->$image_sound = $destination_path; } } // Update the pageear with moved images and sounds. drupal_write_record('pageears', $new_pageear, 'peid'); // Delete possible images sounds uploaded with peid=0 delete_images_sounds(0); // Update the persistent variable numEnabledPageears that tracks number of pageears enabled if ($form_state['values']['status']) { variable_set('numEnabledPageears', variable_get('numEnabledPageears', 0) + 1); } drupal_set_message(t('The pageear %name has been created.', array('%name' => $form_state['values']['name']))); $form_state['redirect'] = 'admin/build/pageear'; return; } /** * Menu callback: disable a specific pageear. */ function pageear_admin_disable($pageear) { db_query("UPDATE {pageears} SET status = 0 WHERE peid = %d", array(':peid' => $pageear->peid)); // Update the persistent 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($pageear) { db_query("UPDATE {pageears} SET status = 1 WHERE peid = %d", array(':peid' => $pageear->peid)); // Update the persistent 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($form_state, $pageear) { $form['pageear'] = array('#type' => 'hidden', '#value' => serialize($pageear)); $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')); } function pageear_admin_delete_submit($form, &$form_state) { $pageear = unserialize($form_state['values']['pageear']); db_query('DELETE FROM {pageears} WHERE peid = %d', array(':peid' => $pageear->peid)); delete_images_sounds($pageear->peid); drupal_set_message(t('The pageear %name has been removed.', array('%name' => $pageear->name))); $form_state['redirect'] = 'admin/build/pageear'; return; } /** * 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; }