array( check_plain($row->name), check_plain($row->link), pageear_get_options('peelPosition', $row->peelPosition), !$row->status ? l(t('enable'), 'admin/build/pageear/'. $row->peid .'/enable') : l(t('disable'), 'admin/build/pageear/'. $row->peid .'/disable'), l(t('clone'), 'admin/build/pageear/'. $row->peid .'/clone'), l(t('configure'), 'admin/build/pageear/'. $row->peid .'/configure'), l(t('delete'), 'admin/build/pageear/'. $row->peid .'/delete'), ), 'class' => $row->status ? 'enabled' : 'disabled', ); } $header = array(t('Pageear'), t('Link'), t('Position'), array('data' => t('Operations'), 'colspan' => '4')); return theme('table', $header, $rows, $attributes = array('class' => 'pageear-admin-list'), NULL); } /** * Menu callback; displays the pageear configuration form. * * Using the same form for three different operations ($op): * - 'configure': configure an existing pageear (default) * - 'add': add a new pageear * - 'clone': clone an existing pageear */ function pageear_admin_configure($form_state, $pageear, $op = 'configure') { 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', FALSE); drupal_add_js('misc/farbtastic/farbtastic.js'); // Add js that links farbtastic pickers with its input fields drupal_add_js(drupal_get_path('module', 'pageear') .'/earsConfigForm_farbtastic_ini.js'); $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 configure visibility settings below).'), ); $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, ); // End Position 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 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' => $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('Transition Duration'), '#description' => t('Duration of in transition. (1-9)'), '#required' => TRUE, '#default_value' => $pageear->transitionDuration, '#maxlength' => 1, '#size' => 8, ); // 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, ); // 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, ); // 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, ); // End Sound Settings. // Linking Settings. $form['details']['linking_settings'] = array( '#type' => 'fieldset', '#title' => t('URL Settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); // URL to open on pageear click. $form['details']['linking_settings']['link'] = array( '#type' => 'textfield', '#title' => t('URL'), '#description' => t('URL to go when user click on the ad.'), '#required' => TRUE, '#default_value' => $pageear->link, '#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.'), ); $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 == 'configure') { $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), ); $form['cancel'] = array( '#type' => 'markup', '#value' => l(t('Cancel'), referer_uri()), ); } else if ($op == 'add' || $op == 'clone') { $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), '#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_configure_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'); // 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') { form_set_error($image, t('Uploaded image must be an image file. JPEG, PNG or GIF')); } else { $filename = $directory_path .'/'. $image .'_'. $form_state['values']['peid'] .'.'. $parts['extension']; if (file_copy($file, $filename)) { form_set_value($form['details']['image_settings'][$image], $file->filepath, $form_state); } } } 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') { form_set_error($sound, t('Uploaded sound must be a MP3 file.')); } else { $filename = $directory_path .'/'. $sound .'_'. $form_state['values']['peid'] .'.'. $parts['extension']; if (file_copy($file, $filename)) { form_set_value($form['details']['sound_settings'][$sound], $file->filepath, $form_state); } } } else { form_set_value($form['details']['sound_settings'][$sound], $form['details']['sound_settings'][$sound]['#value'], $form_state); } } // 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_configure_submit($form, &$form_state) { // Save the edited pageear if (!form_get_errors()) { // previous status of this pageear before starting configuration $sql = "SELECT p.status FROM {pageears} p"; $sql .= " WHERE peid = %d"; $previous_status = db_fetch_object(db_query($sql, $form_state['values']['peid']))->status; if (module_exists('locale')) { $languages = implode(',', $form_state['values']['languages']); } else { $languages = ''; } $roles = implode(',', $form_state['values']['roles']); $sql = "UPDATE {pageears} SET"; $sql .= " status = '%d', name = '%s', peelPosition = '%s', smallURL = '%s', bigURL = '%s', mirror = '%d', inTransition = '%s', transitionDuration = '%d', peelColor = '%s', redValue = '%d', greenValue = '%d', blueValue = '%d', linkTarget = '%s', link = '%s', loadSoundURL = '%s', openSoundURL = '%s', closeSoundURL = '%s', flagSpeed = '%d', peelSpeed = '%d', automaticOpen = '%d', automaticClose = '%d', close_button_enable = '%d', text_on_close_button = '%s', close_redValue = '%d', close_greenValue = '%d', close_blueValue = '%d', languages = '%s', roles = '%s', visibility = '%d', pages = '%s'"; $sql .= " WHERE peid = %d"; db_query($sql, $form_state['values']['status'], $form_state['values']['name'], $form_state['values']['peelPosition'], $form_state['values']['smallURL'], $form_state['values']['bigURL'], $form_state['values']['mirror'], $form_state['values']['inTransition'], $form_state['values']['transitionDuration'], $form_state['values']['peelColor'], $form_state['values']['redValue'], $form_state['values']['greenValue'], $form_state['values']['blueValue'], $form_state['values']['linkTarget'], $form_state['values']['link'], $form_state['values']['loadSoundURL'], $form_state['values']['openSoundURL'], $form_state['values']['closeSoundURL'], $form_state['values']['flagSpeed'], $form_state['values']['peelSpeed'], $form_state['values']['automaticOpen'], $form_state['values']['automaticClose'], $form_state['values']['close_button_enable'], $form_state['values']['text_on_close_button'], $form_state['values']['close_redValue'], $form_state['values']['close_greenValue'], $form_state['values']['close_blueValue'], $languages, $roles, $form_state['values']['visibility'], $form_state['values']['pages'], $form_state['values']['peid'] ); // Update the global variable numEnabledPageears that tracks number of pageears enabled if ($form_state['values']['status'] != $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']); $sql = "INSERT INTO {pageears} (status, name, peelPosition, smallURL, bigURL, mirror, inTransition, transitionDuration, peelColor, redValue, greenValue, blueValue, linkTarget, link, loadSoundURL, openSoundURL, closeSoundURL, flagSpeed, peelSpeed, automaticOpen, automaticClose, close_button_enable, text_on_close_button, close_redValue, close_greenValue, close_blueValue, languages, roles, visibility, pages)"; $sql .= " VALUES ('%d', '%s', '%s', '%s', '%s', '%d', '%s', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%d', '%d', '%d', '%s', '%s', '%d', '%s')"; db_query($sql, $form_state['values']['status'], $form_state['values']['name'], $form_state['values']['peelPosition'], $form_state['values']['smallURL'], $form_state['values']['bigURL'], $form_state['values']['mirror'], $form_state['values']['inTransition'], $form_state['values']['transitionDuration'], $form_state['values']['peelColor'], $form_state['values']['redValue'], $form_state['values']['greenValue'], $form_state['values']['blueValue'], $form_state['values']['linkTarget'], $form_state['values']['link'], $form_state['values']['loadSoundURL'], $form_state['values']['openSoundURL'], $form_state['values']['closeSoundURL'], $form_state['values']['flagSpeed'], $form_state['values']['peelSpeed'], $form_state['values']['automaticOpen'], $form_state['values']['automaticClose'], $form_state['values']['close_button_enable'], $form_state['values']['text_on_close_button'], $form_state['values']['close_redValue'], $form_state['values']['close_greenValue'], $form_state['values']['close_blueValue'], $languages, $roles, $form_state['values']['visibility'], $form_state['values']['pages'] ); // Move any images or sounds // to reflect the peid on its names // get last used peid $last_used_peid = db_last_insert_id('pageears', 'peid'); $directory_path = file_directory_path() .'/'. PAGEEAR_PATH_IMAGES; foreach (array('smallURL', 'bigURL', 'loadSoundURL', 'openSoundURL', 'closeSoundURL') as $image_sound) { //if ($image_sound == 'smallURL' || $image_sound == 'bigURL') { // $extension = '.jpg'; //} //else { // $extension = '.mp3'; //} $stringparts = explode(".", $form_state['values'][$image_sound]); $extension = $stringparts[count($stringparts)-1]; $source_path = $form_state['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 with peid=0 delete_images_sounds(0); // Update the global 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", $pageear->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($pageear) { db_query("UPDATE {pageears} SET status = 1 WHERE peid = %d", $pageear->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('smallURL', 'bigURL', 'loadSoundURL', 'openSoundURL', 'closeSoundURL') as $image_sound) { if ($image_sound == 'smallURL' || $image_sound == 'bigURL') { $extensions = array('.jpg', '.jpeg', '.gif', '.png'); } else { $extensions = array('.mp3'); } foreach ($extensions as $extension) { $filename = $directory_path .'/'. $image_sound .'_'. $peid; $filepath = $filename . $extension; file_delete($filepath); $i = 0; $filepath = $filename .'_'. $i . $extension; while (file_delete($filepath)) { $i += 1; $filepath = $filename .'_'. $i . $extension; } } } } /** * Menu callback; confirm deletion of a pageear. */ function pageear_admin_delete($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', $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 = substr($color, 1); } if (strlen($color) == 6) { list($r, $g, $b) = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); } elseif (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 = (strlen($r) < 2?'0':'') . $r; $color .= (strlen($g) < 2?'0':'') . $g; $color .= (strlen($b) < 2?'0':'') . $b; return '#'. $color; }