peid] = array( '#tree' => TRUE, ); $form['pageears'][$pageear->peid]['peid'] = array( '#type' => 'hidden', '#value' => $pageear->peid, ); $form['pageears'][$pageear->peid]['name'] = array( '#markup' => check_plain($pageear->name), ); $form['pageears'][$pageear->peid]['link'] = array( '#markup' => check_plain($pageear->link), ); $form['pageears'][$pageear->peid]['peel_position'] = array( '#markup' => pageear_get_options('peel_position', $pageear->peel_position), ); $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( '#markup' => l(t('clone'), 'admin/structure/pageear/'. $pageear->peid .'/clone'), ); $form['pageears'][$pageear->peid]['edit'] = array( '#markup' => l(t('edit'), 'admin/structure/pageear/'. $pageear->peid .'/edit'), ); $form['pageears'][$pageear->peid]['delete'] = array( '#markup' => l(t('delete'), 'admin/structure/pageear/'. $pageear->peid .'/delete'), ); } $form['submit'] = array( '#type' => 'submit', '#value' => t('Save configuration'), ); } else { $form['empty'] = array('#markup' => t('There are no pageears yet. !Add_new a pageear first.', array('!Add_new' => l(t('Add'), 'admin/structure/pageear/add')))); } return $form; } /** * Theme: List of pageears. */ function theme_pageear_list_form($variables) { $form = $variables['form']; $header = array( t('Pageear'), t('Link'), t('Position'), array('data' => t('Enabled'), 'class' => array('checkbox')), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'), ); $pageears = array(); foreach (element_children($form['pageears']) as $peid) { $form['pageears'][$peid]['weight']['#attributes']['class'] = array('pageear-weight'); $pageears[] = array( 'data' => array( drupal_render($form['pageears'][$peid]['name']), drupal_render($form['pageears'][$peid]['link']), drupal_render($form['pageears'][$peid]['peel_position']), array( 'data' => drupal_render($form['pageears'][$peid]['status']), 'class' => array('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' => array('draggable'), ); } $output = ''; if (count($pageears)) { $output .= theme('table', array('header' => $header, 'rows' => $pageears, 'attributes' => array('id' => 'order-pageears'))); } $output .= drupal_render_children($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('num_enabled_pageears', $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, &$form_state, $pageear, $op = 'edit') { if ($op == 'add' || !$pageear->peid) { $pageear = pageear_get_default(); } if ($op == 'clone') { $pageear->peid = 0; } // @todo All sliders css styles should not be inline. Create stylesheet file. $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' => 'vertical_tabs', //'#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 | bottomright ). $form['details']['position_settings']['peel_position'] = array( '#type' => 'radios', '#title' => t('Corner'), '#description' => t('In what corner the ad will be displayed.'), '#options' => pageear_get_options('peel_position'), '#default_value' => $pageear->peel_position, '#required' => TRUE, '#attributes' => array('onclick' => 'checkPeelPosition()'), ); // Disable absolute position model if pageear is set on bottom corner $peel_position_check_js = "function checkPeelPosition() {"; $peel_position_check_js .= "(function($) {"; $peel_position_check_js .= "if ($('#edit-peel-position-bottomleft').attr('checked') || $('#edit-peel-position-bottomright').attr('checked')) {"; $peel_position_check_js .= "$('#edit-peel-position-model-absolute').attr('disabled', true);"; $peel_position_check_js .= "$('#edit-peel-position-model-fixed').attr('checked', true);"; $peel_position_check_js .= "} else {"; $peel_position_check_js .= "$('#edit-peel-position-model-absolute').removeAttr('disabled');"; $peel_position_check_js .= "}"; $peel_position_check_js .= "}) (jQuery);"; $peel_position_check_js .= "}"; $form['details']['position_settings']['peel_position']['#attached']['js'][] = array( 'data' => $peel_position_check_js, 'type' => 'inline', ); // Set position model of peageear ( absolute | fixed ). $form['details']['position_settings']['peel_position_model'] = array( '#type' => 'radios', '#title' => t('Position Model'), '#description' => t('The CSS Position model you would prefer to use.'), '#options' => pageear_get_options('peel_position_model'), '#default_value' => $pageear->peel_position_model, '#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').attr('checked') || $('#edit-peelPosition-bottomright').attr('checked')) {\n"; $peel_position_model_ini_js .= "$('#edit-peelPositionModel-absolute').attr('disabled', true);\n"; $peel_position_model_ini_js .= "}\n"; $peel_position_model_ini_js .= "});\n"; $peel_position_model_ini_js .= "}) (jQuery);"; $form['details']['position_settings']['peel_position_model']['#attached']['js'][] = array( 'data' => $peel_position_model_ini_js, 'type' => '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']['wait_enable'] = array( '#type' => 'checkbox', '#title' => t('Enable wait icon'), '#default_value' => $pageear->wait_enable, '#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']['wait_width'] = array( '#type' => 'textfield', '#title' => t('Wait Icon Width'), '#required' => TRUE, '#default_value' => $pageear->wait_width, '#maxlength' => 3, '#size' => 8, ); // Set wait icon height $form['details']['wait_settings']['wait_height'] = array( '#type' => 'textfield', '#title' => t('Wait Icon Height'), '#required' => TRUE, '#default_value' => $pageear->wait_height, '#maxlength' => 3, '#size' => 8, ); // URL to wait icon. $form['details']['wait_settings']['wait_url'] = array( '#type' => 'item', '#title' => t('Wait icon'), '#markup' => check_plain($pageear->wait_url), ); $form['details']['wait_settings']['wait_url_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']['flag_style'] = array( '#type' => 'select', '#title' => t('Flag Style'), '#options' => pageear_get_options('flag_style'), '#default_value' => $pageear->flag_style, '#required' => TRUE, ); // Style of peel ('style1' | 'style2'). $form['details']['style_settings']['peel_style'] = array( '#type' => 'select', '#title' => t('Peel Style'), '#options' => pageear_get_options('peel_style'), '#default_value' => $pageear->peel_style, '#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']['flag_width'] = array( '#type' => 'textfield', '#title' => t('Flag Width'), '#required' => TRUE, '#default_value' => $pageear->flag_width, '#maxlength' => 4, '#size' => 8, ); // Set flag height $form['details']['size_settings']['flag_height'] = array( '#type' => 'textfield', '#title' => t('Flag Height'), '#required' => TRUE, '#default_value' => $pageear->flag_height, '#maxlength' => 4, '#size' => 8, ); // Set peel width $form['details']['size_settings']['peel_width'] = array( '#type' => 'textfield', '#title' => t('Peel Width'), '#required' => TRUE, '#default_value' => $pageear->peel_width, '#maxlength' => 5, '#size' => 8, ); // Set peel height $form['details']['size_settings']['peel_height'] = array( '#type' => 'textfield', '#title' => t('Peel Height'), '#required' => TRUE, '#default_value' => $pageear->peel_height, '#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']['small_url'] = array( '#type' => 'item', '#title' => t('Unpeeled image'), '#markup' => check_plain($pageear->small_url), ); $form['details']['image_settings']['small_url_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']['big_url'] = array( '#type' => 'item', '#title' => t('Peeled image'), '#markup' => check_plain($pageear->big_url), ); $form['details']['image_settings']['big_url_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']['in_transition'] = array( '#type' => 'select', '#title' => t('In Transition'), '#description' => t('In Transition for the pageear.'), '#options' => pageear_get_options('in_transition'), '#default_value' => $pageear->in_transition, '#required' => TRUE, ); // Duration of in transition (1-9). $form['details']['image_settings']['transition_duration'] = array( '#type' => 'hidden', ); $form['details']['image_settings']['transition_duration_slider'] = array( '#type' => 'item', '#title' => t('Transition Duration'), '#description' => t('Duration of in transition. (1-9)'), '#required' => TRUE, '#markup' => '
', ); $form['details']['image_settings']['transition_duration_slider']['#attached']['library'][] = array( 'system', 'ui.slider', ); $transition_duration_slider_js = '(function($) { '; $transition_duration_slider_js .= '$(document).ready(function() { '; $transition_duration_slider_js .= '$("#edit-transition-duration").attr("value", '. $pageear->transition_duration .'); '; $transition_duration_slider_js .= '$("#transition-duration-slider").slider('; $transition_duration_slider_js .= '{ animate: true, '; $transition_duration_slider_js .= 'min: 1, '; $transition_duration_slider_js .= 'max: 9, '; $transition_duration_slider_js .= 'value: '. $pageear->transition_duration .', '; $transition_duration_slider_js .= 'start: function(event, ui) { $("#transition-duration-callout").fadeIn("fast"); }, '; $transition_duration_slider_js .= 'stop: function(event, ui) { $("#transition-duration-callout").fadeOut("fast"); }, '; $transition_duration_slider_js .= 'slide: function(event, ui) { $("#edit-transition-duration").attr("value", ui.value); $("#transition-duration-callout").css("left", (ui.value - 1)*160/8).text(ui.value); } '; $transition_duration_slider_js .= '}); '; $transition_duration_slider_js .= '}); '; $transition_duration_slider_js .= '}) (jQuery);'; $form['details']['image_settings']['transition_duration_slider']['#attached']['js'][] = array( 'data' => $transition_duration_slider_js, 'type' => 'inline', ); // Style of peel back color. $form['details']['image_settings']['peel_color_style'] = 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('peel_color_style'), '#default_value' => $pageear->peel_color_style, '#required' => TRUE, ); // Color of peel back. $form['details']['image_settings']['peel_color'] = array( '#type' => 'radios', '#title' => t('Back color'), '#description' => t('This color will be used on the back of peel.'), '#options' => pageear_get_options('peel_color'), '#default_value' => $pageear->peel_color, '#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->red_value, $pageear->green_value, $pageear->blue_value), '#maxlength' => 7, '#size' => 8, ); $form['details']['image_settings']['custom_color']['#attached']['library'][] = array( 'system', 'farbtastic', ); $form['details']['image_settings']['custom_color']['#attached']['js'][] = array( 'data' => '(function($) { $(document).ready(function() { $("#pageear-customcolor-picker").farbtastic("#edit-custom-color"); }); }) (jQuery);', 'type' => 'inline', ); // Red Value for Custom Color Peel. $form['details']['image_settings']['red_value'] = array( '#type' => 'hidden', '#value' => $pageear->red_value, ); // Green Value for Custom Color Peel. $form['details']['image_settings']['green_value'] = array( '#type' => 'hidden', '#value' => $pageear->green_value, ); // Blue Value for Custom Color Peel. $form['details']['image_settings']['blue_value'] = array( '#type' => 'hidden', '#value' => $pageear->blue_value, ); // 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']['load_sound_url'] = array( '#type' => 'item', '#title' => t('Onload Sound'), '#markup' => check_plain($pageear->load_sound_url), ); $form['details']['sound_settings']['load_sound_url_upload'] = array( '#type' => 'file', '#description' => t('Upload an mp3 file to play when the ad is loaded.'), '#tree' => FALSE, '#size' => 40, ); if ($pageear->load_sound_url != "") { $form['details']['sound_settings']['load_sound_remove'] = 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']['open_sound_url'] = array( '#type' => 'item', '#title' => t('Open Peel Sound'), '#markup' => check_plain($pageear->open_sound_url), ); $form['details']['sound_settings']['open_sound_url_upload'] = array( '#type' => 'file', '#description' => t('Upload an mp3 file to play when the peel is opened.'), '#tree' => FALSE, '#size' => 40, ); if ($pageear->open_sound_url != "") { $form['details']['sound_settings']['open_sound_remove'] = 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']['close_sound_url'] = array( '#type' => 'item', '#title' => t('Close Peel Sound'), '#markup' => check_plain($pageear->close_sound_url), ); $form['details']['sound_settings']['close_sound_url_upload'] = array( '#type' => 'file', '#description' => t('Upload an mp3 file to play when the peel is closed.'), '#tree' => FALSE, '#size' => 40, ); if ($pageear->close_sound_url != "") { $form['details']['sound_settings']['close_sound_remove'] = 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']['link_enable'] = array( '#type' => 'checkbox', '#title' => t('Enabled'), '#default_value' => $pageear->link_enable, '#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']['link_target'] = array( '#type' => 'radios', '#title' => t('URL target'), '#description' => t('Where to open the URL.'), '#options' => pageear_get_options('link_target'), '#default_value' => $pageear->link_target, '#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']['flag_speed'] = array( '#type' => 'hidden', ); $form['details']['motion_settings']['flag_speed_slider'] = array( '#type' => 'item', '#title' => t('Flag motion speed'), '#description' => t('Speed for flag motion. (1-9)'), '#required' => TRUE, '#markup' => '
', ); $form['details']['motion_settings']['flag_speed_slider']['#attached']['library'][] = array( 'system', 'ui.slider', ); $flag_speed_slider_js = '(function($) { '; $flag_speed_slider_js .= '$(document).ready(function() { '; $flag_speed_slider_js .= '$("#edit-flag-speed").attr("value", '. $pageear->flag_speed .'); '; $flag_speed_slider_js .= '$("#flag-speed-slider").slider('; $flag_speed_slider_js .= '{ animate: true, '; $flag_speed_slider_js .= 'min: 1, '; $flag_speed_slider_js .= 'max: 9, '; $flag_speed_slider_js .= 'value: '. $pageear->flag_speed .', '; $flag_speed_slider_js .= 'start: function(event, ui) { $("#flag-speed-callout").fadeIn("fast"); }, '; $flag_speed_slider_js .= 'stop: function(event, ui) { $("#flag-speed-callout").fadeOut("fast"); }, '; $flag_speed_slider_js .= 'slide: function(event, ui) { $("#edit-flag-speed").attr("value", ui.value); $("#flag-speed-callout").css("left", (ui.value - 1)*160/8).text(ui.value); } '; $flag_speed_slider_js .= '}); '; $flag_speed_slider_js .= '}); '; $flag_speed_slider_js .= '}) (jQuery);'; $form['details']['motion_settings']['flag_speed_slider']['#attached']['js'][] = array( 'data' => $flag_speed_slider_js, 'type' => 'inline', ); // Speed of peel movement (1-9). $form['details']['motion_settings']['peel_speed'] = array( '#type' => 'hidden', ); $form['details']['motion_settings']['peel_speed_slider'] = array( '#type' => 'item', '#title' => t('Peel motion speed'), '#description' => t('Speed for peel motion. (1-9)'), '#required' => TRUE, '#markup' => '
', ); $form['details']['motion_settings']['peel_speed_slider']['#attached']['library'][] = array( 'system', 'ui.slider', ); $peel_speed_slider_js = '(function($) { '; $peel_speed_slider_js .= '$(document).ready(function() { '; $peel_speed_slider_js .= '$("#edit-peel-speed").attr("value", '. $pageear->peel_speed .'); '; $peel_speed_slider_js .= '$("#peel-speed-slider").slider('; $peel_speed_slider_js .= '{ animate: true, '; $peel_speed_slider_js .= 'min: 1, '; $peel_speed_slider_js .= 'max: 9, '; $peel_speed_slider_js .= 'value: '. $pageear->peel_speed .', '; $peel_speed_slider_js .= 'start: function(event, ui) { $("#peel-speed-callout").fadeIn("fast"); }, '; $peel_speed_slider_js .= 'stop: function(event, ui) { $("#peel-speed-callout").fadeOut("fast"); }, '; $peel_speed_slider_js .= 'slide: function(event, ui) { $("#edit-peel-speed").attr("value", ui.value); $("#peel-speed-callout").css("left", (ui.value - 1)*160/8).text(ui.value); } '; $peel_speed_slider_js .= '}); '; $peel_speed_slider_js .= '}); '; $peel_speed_slider_js .= '}) (jQuery);'; $form['details']['motion_settings']['peel_speed_slider']['#attached']['js'][] = array( 'data' => $peel_speed_slider_js, 'type' => 'inline', ); // Opens pageear automaticaly after configured seconds. $form['details']['motion_settings']['automatic_open'] = 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, '#field_prefix' => '
', '#default_value' => $pageear->automatic_open, '#maxlength' => 3, '#size' => 8, ); $form['details']['motion_settings']['automatic_open']['#attached']['library'][] = array( 'system', 'ui.slider', ); $automatic_open_slider_js = '(function($) { '; $automatic_open_slider_js .= '$(document).ready(function() { '; $automatic_open_slider_js .= '$("#edit-automatic-open").keyup(function(event) { if (!isNaN(parseInt($("#edit-automatic-open").attr("value")))) { $("#automatic-open-slider").slider("value", $("#edit-automatic-open").attr("value")); } else { if ($("#edit-automatic-open").attr("value") != "") { $("#edit-automatic-open").attr("value", $("#automatic-open-slider").slider("value")); } } }); '; $automatic_open_slider_js .= '$("#edit-automatic-open").change(function(event) { if ($("#edit-automatic-open").attr("value") == "") { $("#edit-automatic-open").attr("value", 0); $("#automatic-open-slider").slider("value", 0); } } ); '; $automatic_open_slider_js .= '$("#automatic-open-callout").hide(); '; $automatic_open_slider_js .= '$("#automatic-open-slider").slider('; $automatic_open_slider_js .= '{ animate: true, '; $automatic_open_slider_js .= 'min: 0, '; $automatic_open_slider_js .= 'max: 999, '; $automatic_open_slider_js .= 'value: $("#edit-automatic-open").attr("value"), '; $automatic_open_slider_js .= 'start: function(event, ui) { $("#automatic-open-callout").fadeIn("fast"); }, '; $automatic_open_slider_js .= 'stop: function(event, ui) { $("#automatic-open-callout").fadeOut("fast"); }, '; $automatic_open_slider_js .= 'slide: function(event, ui) { $("#edit-automatic-open").attr("value", ui.value); $("#automatic-open-callout").css("left", ui.value*500/1000).text(ui.value); } '; $automatic_open_slider_js .= '}); '; $automatic_open_slider_js .= '}); '; $automatic_open_slider_js .= '}) (jQuery);'; $form['details']['motion_settings']['automatic_open']['#attached']['js'][] = array( 'data' => $automatic_open_slider_js, 'type' => 'inline', ); // Seconds until pageear close after automatically open. $form['details']['motion_settings']['automatic_close'] = array( '#type' => 'textfield', '#title' => t('Automatically unpeel'), '#description' => t('Automatically close after unpeeling after configured seconds. 0 means no automatically unpeel.'), '#required' => TRUE, '#field_prefix' => '
', '#default_value' => $pageear->automatic_close, '#maxlength' => 3, '#size' => 8, ); $form['details']['motion_settings']['automatic_close']['#attached']['library'][] = array( 'system', 'ui.slider', ); $automatic_close_slider_js = '(function($) { '; $automatic_close_slider_js .= '$(document).ready(function() { '; $automatic_close_slider_js .= '$("#edit-automatic-close").keyup(function(event) { if (!isNaN(parseInt($("#edit-automatic-close").attr("value")))) { $("#automatic-close-slider").slider("value", $("#edit-automatic-close").attr("value")); } else { if ($("#edit-automatic-close").attr("value") != "") { $("#edit-automatic-close").attr("value", $("#automatic-close-slider").slider("value")); } } }); '; $automatic_close_slider_js .= '$("#edit-automatic-close").change(function(event) { if ($("#edit-automatic-close").attr("value") == "") { $("#edit-automatic-close").attr("value", 0); $("#automatic-close-slider").slider("value", 0); } } ); '; $automatic_close_slider_js .= '$("#automatic-close-callout").hide(); '; $automatic_close_slider_js .= '$("#automatic-close-slider").slider('; $automatic_close_slider_js .= '{ animate: true, '; $automatic_close_slider_js .= 'min: 0, '; $automatic_close_slider_js .= 'max: 999, '; $automatic_close_slider_js .= 'value: $("#edit-automatic-close").attr("value"), '; $automatic_close_slider_js .= 'start: function(event, ui) { $("#automatic-close-callout").fadeIn("fast"); }, '; $automatic_close_slider_js .= 'stop: function(event, ui) { $("#automatic-close-callout").fadeOut("fast"); }, '; $automatic_close_slider_js .= 'slide: function(event, ui) { $("#edit-automatic-close").attr("value", ui.value); $("#automatic-close-callout").css("left", ui.value*500/1000).text(ui.value); } '; $automatic_close_slider_js .= '}); '; $automatic_close_slider_js .= '}); '; $automatic_close_slider_js .= '}) (jQuery);'; $form['details']['motion_settings']['automatic_close']['#attached']['js'][] = array( 'data' => $automatic_close_slider_js, 'type' => 'inline', ); // 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']['close_button_color'] = array( '#type' => 'textfield', '#title' => t('Close Button Color'), '#required' => TRUE, '#prefix' => '
', '#default_value' => rgb2hex($pageear->close_red_value, $pageear->close_green_value, $pageear->close_blue_value), '#maxlength' => 7, '#size' => 8, ); $form['details']['closebutton_settings']['close_button_color']['#attached']['library'][] = array( 'system', 'farbtastic', ); $form['details']['closebutton_settings']['close_button_color']['#attached']['js'][] = array( 'data' => '(function($) { $(document).ready(function() { $("#pageear-closebuttoncolor-picker").farbtastic("#edit-close-button-color"); }); }) (jQuery);', 'type' => 'inline', ); // Close Button Color Red Value. $form['details']['closebutton_settings']['close_red_value'] = array( '#type' => 'hidden', '#value' => $pageear->close_red_value, ); // Close Button Color Green Value. $form['details']['closebutton_settings']['close_green_value'] = array( '#type' => 'hidden', '#value' => $pageear->close_green_value, ); // Close Button Color Blue Value. $form['details']['closebutton_settings']['close_blue_value'] = array( '#type' => 'hidden', '#value' => $pageear->close_blue_value, ); // End Close Button Settings. // Visibility settings. $form['visibility_settings'] = array( '#type' => 'vertical_tabs', //'#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(); foreach ($result as $role) { $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 settings'); 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( '#markup' => l(t('Cancel'), $_SERVER['HTTP_REFERER']), ); } elseif ($op == 'add' || $op == 'clone') { $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), '#submit' => array('pageear_admin_add_submit'), ); $form['cancel'] = array( '#markup' => l(t('Cancel'), $_SERVER['HTTP_REFERER']), ); } return $form; } /** * hook_validate: validation function for the pageear configuration form. */ function pageear_admin_edit_validate($form, &$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']['wait_width']) || $form_state['values']['wait_width'] < 10) { form_set_error('wait_width', t('Wait Icon Width must be a number greater than 10')); } if (!is_numeric($form_state['values']['wait_height']) || $form_state['values']['wait_height'] < 10) { form_set_error('wait_height', t('Wait Icon Height must be a number greater than 10')); } if (!is_numeric($form_state['values']['flag_width']) || $form_state['values']['flag_width'] < 10) { form_set_error('flag_width', t('Flag Width must be a number greater than 10')); } if (!is_numeric($form_state['values']['flag_height']) || $form_state['values']['flag_height'] < 10) { form_set_error('flag_height', t('Flag Height must be a number greater than 10')); } if (!is_numeric($form_state['values']['peel_width']) || $form_state['values']['peel_width'] < 50) { form_set_error('peel_width', t('Peel Width must be a number greater than 50')); } if (!is_numeric($form_state['values']['peel_height']) || $form_state['values']['peel_height'] < 50) { form_set_error('peel_height', t('Peel Height must be a number greater than 50')); } // Duration of transition validation if (!is_numeric($form_state['values']['transition_duration']) || $form_state['values']['transition_duration'] == 0) { form_set_error('transition_duration', 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']['red_value'], $custom_rgb_peel_color[0], $form_state); form_set_value($form['details']['image_settings']['green_value'], $custom_rgb_peel_color[1], $form_state); form_set_value($form['details']['image_settings']['blue_value'], $custom_rgb_peel_color[2], $form_state); // Flag speed validation if (!is_numeric($form_state['values']['flag_speed']) || $form_state['values']['flag_speed'] == 0) { form_set_error('flag_speed', t('Flag motion speed must be a number between 1 and 9')); } // Peel speed validation if (!is_numeric($form_state['values']['peel_speed']) || $form_state['values']['peel_speed'] == 0) { form_set_error('peel_speed', t('Peel motion speed must be a number between 1 and 9')); } // AutomaticOpen validation if (!is_numeric($form_state['values']['automatic_open']) || $form_state['values']['automatic_open'] < 0) { form_set_error('automatic_open', t('Automatically peel onload seconds must be a number between 0 and 999')); } // AutomaticClose validation if (!is_numeric($form_state['values']['automatic_close']) || $form_state['values']['automatic_close'] < 0) { form_set_error('automatic_close', 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']['close_button_color']); form_set_value($form['details']['closebutton_settings']['close_red_value'], $custom_rgb_close_button_color[0], $form_state); form_set_value($form['details']['closebutton_settings']['close_green_value'], $custom_rgb_close_button_color[1], $form_state); form_set_value($form['details']['closebutton_settings']['close_blue_value'], $custom_rgb_close_button_color[2], $form_state); // Text on close button if (preg_match("/^[a-z][a-z ]+$/", $form_state['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.')); } // Code from here is to validate file uploads. $directory_path = 'public://'. PAGEEAR_PATH_IMAGES; // checks if directory exist and creates it if it don't //file_prepare_directory($directory_path, FILE_CREATE_DIRECTORY); file_prepare_directory($directory_path, FILE_CREATE_DIRECTORY); if ($file = file_save_upload('wait_url_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); form_set_error('wait_url_upload', t('Uploaded file must be an image. JPEG, PNG or GIF')); } else { $dest_filename = 'wait_url_'. $form_state['values']['peid'] .'.'. $parts['extension']; $dest_uri = $directory_path .'/'. $dest_filename; $source_path = $file->uri; if ($dest_uri = file_unmanaged_copy($source_path, $dest_uri)) { file_delete($file); form_set_value($form['details']['wait_settings']['wait_url'], file_directory_path() .'/'. file_uri_target($dest_uri), $form_state); } else{ file_delete($file); form_set_error('wait_url_upload', t('Wait icon upload failed. Please try again.')); } } } else { form_set_value($form['details']['wait_settings']['wait_url'], $form['details']['wait_settings']['wait_url']['#markup'], $form_state); } // uploads images from image upload fields foreach (array('small_url', 'big_url') 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); 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']; $dest_uri = $directory_path .'/'. $dest_filename; $source_path = $file->uri; if ($dest_uri = file_unmanaged_copy($source_path, $dest_uri)) { file_delete($file); form_set_value($form['details']['image_settings'][$image], file_directory_path() .'/'. file_uri_target($dest_uri), $form_state); } else{ file_delete($file); form_set_error($image .'_upload', t('Media uploaded failed. Please try again.')); } } } else { form_set_value($form['details']['image_settings'][$image], $form['details']['image_settings'][$image]['#markup'], $form_state); } } // uploads images from sound upload fields foreach (array('load_sound_url', 'open_sound_url', 'close_sound_url') as $sound) { if ($file = file_save_upload($sound .'_upload')) { $parts = pathinfo($file->filename); if ($parts['extension'] != 'mp3') { file_delete($file); form_set_error($sound .'_upload', t('Uploaded sound must be a MP3 file.')); } else { $dest_filename = $sound .'_'. $form_state['values']['peid'] .'.'. $parts['extension']; $dest_uri = $directory_path .'/'. $dest_filename; $source_path = $file->uri; if ($dest_uri = file_unmanaged_copy($source_path, $dest_uri)) { file_delete($file); form_set_value($form['details']['sound_settings'][$sound], file_directory_path() .'/'. file_uri_target($dest_uri), $form_state); } else { file_delete($file); form_set_error($sound .'_upload', t('Sound uploaded failed. Please try again.')); } } } else { form_set_value($form['details']['sound_settings'][$sound], $form['details']['sound_settings'][$sound]['#markup'], $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']['load_sound_url'] != '' && $form_state['values']['load_sound_remove']) { form_set_value($form['details']['sound_settings']['load_sound_url'], '', $form_state); } if ($form_state['values']['open_sound_url'] != '' && $form_state['values']['open_sound_remove']) { form_set_value($form['details']['sound_settings']['open_sound_url'], '', $form_state); } if ($form_state['values']['open_sound_url'] != '' && $form_state['values']['close_sound_remove']) { form_set_value($form['details']['sound_settings']['close_sound_url'], '', $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->peel_position = $form_state['values']['peel_position']; $new_pageear->peel_position_model = $form_state['values']['peel_position_model']; $new_pageear->wait_enable = $form_state['values']['wait_enable']; $new_pageear->wait_width = $form_state['values']['wait_width']; $new_pageear->wait_height = $form_state['values']['wait_height']; $new_pageear->wait_url = $form_state['values']['wait_url']; $new_pageear->flag_style = $form_state['values']['flag_style']; $new_pageear->peel_style = $form_state['values']['peel_style']; $new_pageear->flag_width = $form_state['values']['flag_width']; $new_pageear->flag_height = $form_state['values']['flag_height']; $new_pageear->peel_width = $form_state['values']['peel_width']; $new_pageear->peel_height = $form_state['values']['peel_height']; $new_pageear->small_url = $form_state['values']['small_url']; $new_pageear->big_url = $form_state['values']['big_url']; $new_pageear->mirror = $form_state['values']['mirror']; $new_pageear->in_transition = $form_state['values']['in_transition']; $new_pageear->transition_duration = $form_state['values']['transition_duration']; $new_pageear->peel_color_style = $form_state['values']['peel_color_style']; $new_pageear->peel_color = $form_state['values']['peel_color']; $new_pageear->red_value = $form_state['values']['red_value']; $new_pageear->green_value = $form_state['values']['green_value']; $new_pageear->blue_value = $form_state['values']['blue_value']; $new_pageear->link_enable = $form_state['values']['link_enable']; $new_pageear->link_target = $form_state['values']['link_target']; $new_pageear->link = $form_state['values']['link']; $new_pageear->load_sound_url = $form_state['values']['load_sound_url']; $new_pageear->open_sound_url = $form_state['values']['open_sound_url']; $new_pageear->close_sound_url = $form_state['values']['close_sound_url']; $new_pageear->flag_speed = $form_state['values']['flag_speed']; $new_pageear->peel_speed = $form_state['values']['peel_speed']; $new_pageear->automatic_open = $form_state['values']['automatic_open']; $new_pageear->automatic_close = $form_state['values']['automatic_close']; $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_red_value = $form_state['values']['close_red_value']; $new_pageear->close_green_value = $form_state['values']['close_green_value']; $new_pageear->close_blue_value = $form_state['values']['close_blue_value']; $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('num_enabled_pageears', variable_get('num_enabled_pageears', 0) + 1); } else { variable_set('num_enabled_pageears', variable_get('num_enabled_pageears', 1) - 1); } } drupal_set_message(t('The pageear %name has been saved.', array('%name' => $form_state['values']['name']))); $form_state['redirect'] = 'admin/structure/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->peel_position = $form_state['values']['peel_position']; $new_pageear->peel_position_model = $form_state['values']['peel_position_model']; $new_pageear->wait_enable = $form_state['values']['wait_enable']; $new_pageear->wait_width = $form_state['values']['wait_width']; $new_pageear->wait_height = $form_state['values']['wait_height']; $new_pageear->wait_url = $form_state['values']['wait_url']; $new_pageear->flag_style = $form_state['values']['flag_style']; $new_pageear->peel_style = $form_state['values']['peel_style']; $new_pageear->flag_width = $form_state['values']['flag_width']; $new_pageear->flag_height = $form_state['values']['flag_height']; $new_pageear->peel_width = $form_state['values']['peel_width']; $new_pageear->peel_height = $form_state['values']['peel_height']; $new_pageear->small_url = $form_state['values']['small_url']; $new_pageear->big_url = $form_state['values']['big_url']; $new_pageear->mirror = $form_state['values']['mirror']; $new_pageear->in_transition = $form_state['values']['in_transition']; $new_pageear->transition_duration = $form_state['values']['transition_duration']; $new_pageear->peel_color_style = $form_state['values']['peel_color_style']; $new_pageear->peel_color = $form_state['values']['peel_color']; $new_pageear->red_value = $form_state['values']['red_value']; $new_pageear->green_value = $form_state['values']['green_value']; $new_pageear->blue_value = $form_state['values']['blue_value']; $new_pageear->link_enable = $form_state['values']['link_enable']; $new_pageear->link_target = $form_state['values']['link_target']; $new_pageear->link = $form_state['values']['link']; $new_pageear->load_sound_url = $form_state['values']['load_sound_url']; $new_pageear->open_sound_url = $form_state['values']['open_sound_url']; $new_pageear->close_sound_url = $form_state['values']['close_sound_url']; $new_pageear->flag_speed = $form_state['values']['flag_speed']; $new_pageear->peel_speed = $form_state['values']['peel_speed']; $new_pageear->automatic_open = $form_state['values']['automatic_open']; $new_pageear->automatic_close = $form_state['values']['automatic_close']; $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_red_value = $form_state['values']['close_red_value']; $new_pageear->close_green_value = $form_state['values']['close_green_value']; $new_pageear->close_blue_value = $form_state['values']['close_blue_value']; $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; $directory_path = 'public://'. PAGEEAR_PATH_IMAGES; //$change_new_pageear = new stdClass(); $change_new_pageear->peid = $new_pageear->peid; unset($new_pageear); foreach (array('wait_url', 'small_url', 'big_url', 'load_sound_url', 'open_sound_url', 'close_sound_url') as $image_sound) { if ($form_state['values'][$image_sound] != '') { $source_filepath = $form_state['values'][$image_sound]; $stringparts = explode(".", $form_state['values'][$image_sound]); $extension = $stringparts[count($stringparts)-1]; $dest_filename = $image_sound .'_'. $change_new_pageear->peid .'.'. $extension; $dest_uri = $directory_path .'/'. $dest_filename; $dest_uri = file_unmanaged_copy($source_filepath, $dest_uri, FILE_EXISTS_REPLACE); $change_new_pageear->$image_sound = file_directory_path() .'/'. file_uri_target($dest_uri); } } // Update the pageear with moved images and sounds. drupal_write_record('pageears', $change_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('num_enabled_pageears', variable_get('num_enabled_pageears', 0) + 1); } drupal_set_message(t('The pageear %name has been created.', array('%name' => $form_state['values']['name']))); $form_state['redirect'] = 'admin/structure/pageear'; return; } /** * Menu callback: disable a specific pageear. */ function pageear_admin_disable($pageear) { db_query("UPDATE {pageears} SET status = 0 WHERE peid = :peid", array(':peid' => $pageear->peid)); // Update the persistent variable numEnabledPageears that tracks number of pageears enabled variable_set('num_enabled_pageears', variable_get('num_enabled_pageears', 1) - 1); drupal_goto('admin/structure/pageear'); } /** * Menu callback: enable a specific pageear. */ function pageear_admin_enable($pageear) { db_query("UPDATE {pageears} SET status = 1 WHERE peid = :peid", array(':peid' => $pageear->peid)); // Update the persistent variable numEnabledPageears that tracks number of pageears enabled variable_set('num_enabled_pageears', variable_get('num_enabled_pageears', 0) + 1); drupal_goto('admin/structure/pageear'); } /** * Deletes images and sounds for specific pageear. */ function delete_images_sounds($peid) { //$directory_path = file_directory_path() .'/'. PAGEEAR_PATH_IMAGES; $directory_path = 'public://'. PAGEEAR_PATH_IMAGES; // if the directory where files reside does not exists nothing to do if (!file_prepare_directory($directory_path)) { return; } foreach (array('wait_url', 'small_url', 'big_url', 'load_sound_url', 'open_sound_url', 'close_sound_url') as $image_sound) { if ($image_sound == 'wait_url' || $image_sound == 'small_url' || $image_sound == 'big_url') { $extensions = array('.jpg', '.jpeg', '.gif', '.png', '.swf'); } else { $extensions = array('.mp3'); } foreach ($extensions as $extension) { $filename_noext = $image_sound .'_'. $peid; $file_uri_noext = $directory_path .'/'. $filename_noext; $file_uri = $file_uri_noext . $extension; file_unmanaged_delete($file_uri); $i = 0; $file_uri = $file_uri_noext .'_'. $i . $extension; while (file_exists(drupal_realpath($file_uri))) { file_unmanaged_delete($file_uri); $i += 1; $file_uri = $file_uri_noext .'_'. $i . $extension; } } } } /** * Menu callback; confirm deletion of a pageear. */ function pageear_admin_delete($form, &$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/structure/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)); db_delete('pageears') ->condition('peid', $pageear->peid) ->execute(); delete_images_sounds($pageear->peid); drupal_set_message(t('The pageear %name has been removed.', array('%name' => $pageear->name))); $form_state['redirect'] = 'admin/structure/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; }