'BeautyTips Custom-Tips', 'page callback' => 'beautytips_manager_tips_manager_page', 'access arguments' => array('administer site configuration'), 'type' => MENU_LOCAL_TASK, ); $items['admin/settings/beautytips/custom-tips/%/edit'] = array( 'title' => 'BeautyTips Custom-Tip Edit', 'page callback' => 'drupal_get_form', 'page arguments' => array('beautytips_manager_admin', 4), 'access arguments' => array('administer site configuration'), 'type' => MENU_LOCAL_TASK, ); $items['admin/settings/beautytips/custom-tips/%/delete'] = array( 'title' => 'BeautyTips Custom-Tip Delete', 'page callback' => 'drupal_get_form', 'page arguments' => array('beautytips_manager_delete_confirm_form', 4), 'access arguments' => array('administer site configuration'), 'type' => MENU_LOCAL_TASK, ); $items['admin/settings/beautytips/custom-tips/add'] = array( 'title' => 'BeautyTips Custom-Tip Add', 'page callback' => 'drupal_get_form', 'page arguments' => array('beautytips_manager_admin'), 'access arguments' => array('administer site configuration'), 'type' => MENU_LOCAL_TASK, ); $items['admin/settings/beautytips/custom-styles'] = array( 'title' => 'BeautyTips Custom Styles', 'page callback' => 'beautytips_manager_styles_manager_page', 'access arguments' => array('administer site configuration'), 'type' => MENU_LOCAL_TASK, ); $items['admin/settings/beautytips/custom-styles/%/edit'] = array( 'title' => 'BeautyTips Custom Style Edit', 'page callback' => 'drupal_get_form', 'page arguments' => array('beautytips_manager_custom_styles_form', 4), 'access arguments' => array('administer site configuration'), 'type' => MENU_LOCAL_TASK, ); $items['admin/settings/beautytips/custom-styles/%/delete'] = array( 'title' => 'BeautyTips Manager Delete', 'page callback' => 'drupal_get_form', 'page arguments' => array('beautytips_manager_delete_confirm_form', 4), 'access arguments' => array('administer site configuration'), 'type' => MENU_LOCAL_TASK, ); $items['admin/settings/beautytips/custom-styles/add'] = array( 'title' => 'BeautyTips Custom Style Add', 'page callback' => 'drupal_get_form', 'page arguments' => array('beautytips_manager_custom_styles_form'), 'access arguments' => array('administer site configuration'), 'type' => MENU_LOCAL_TASK, ); return $items; } /** * Implementation of hook_init(). */ function beautytips_manager_init() { $options = array(); $tips = beautytips_manager_get_custom_tips(); if (count($tips)) { foreach ($tips as $tip) { // Match path if necessary if ($tip->pages) { $path = drupal_get_path_alias($_GET['q']); // Compare with the internal and path alias (if any). $page_match = drupal_match_path($path, $tip->pages); if ($path != $_GET['q']) { $page_match = $page_match || drupal_match_path($_GET['q'], $tip->pages); } // When $tip->visibility has a value of 0, the beautytip is displayed on // all pages except those listed in $tip->pages. When set to 1, it // is displayed only on those pages listed in $tip->pages. $page_match = !($tip->visibility XOR $page_match); } else if (!$tip->visibility) { $page_match = TRUE; } else { $page_match = FALSE; } if ($page_match) { $options['beautytips_manager_custom_' . $tip->id] = beautytips_manager_build_beautytip($tip); } } } if (count($options)) { beautytips_add_beautytips($options); } } /** * Implementation of hook_perm(). */ function beautytips_manager_perm() { return array('use Javascript for custom beautytip display'); } /** * Listing of all beautytips available. */ function beautytips_manager_tips_manager_page() { $rows = array(); $empty = ''; $header = array(t('Element'), t('Style'), t('Visibility'), t('Pages'), t('operations')); $tips = beautytips_manager_get_custom_tips(); $link = l(t('Add New Custom Beautytip'), 'admin/settings/beautytips/custom-tips/add'); if (count($tips)) { $visibility = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')); foreach ($tips as $tip) { $tip->pages = check_plain($tip->pages); $pages = ($tip->pages != substr($tip->pages, 0, 40)) ? substr($tip->pages, 0, 40) . '...' : substr($tip->pages, 0, 40); $rows[$tip->id]['element'] = check_plain($tip->element); $rows[$tip->id]['style'] = $tip->style; $rows[$tip->id]['visibility'] = $visibility[$tip->visibility]; $rows[$tip->id]['pages'] = $pages; $rows[$tip->id]['edit'] = l(t('edit'), "admin/settings/beautytips/custom-tips/$tip->id/edit"); $rows[$tip->id]['delete'] = l(t('delete'), "admin/settings/beautytips/custom-tips/$tip->id/delete"); } } else { $empty = t('There are no custom beautytips yet.'); } return $link . theme('table', $header, $rows) . $empty; } /** * Page callback for custom styles administration. */ function beautytips_manager_styles_manager_page() { $rows = array(); $empty = ''; $header = array(t('Name'), t('Example'), t('operations')); $styles = beautytips_manager_get_custom_styles(); $link = l(t('Add New Custom Beautytip Style'), 'admin/settings/beautytips/custom-styles/add'); if (count($styles)) { $visibility = array(t('Show on every page except the listed pages.'), t('Show on only the listed pages.')); foreach ($styles as $style) { $name = check_plain($style->name); unset($style->name); $rows[$style->id]['name'] = $name; $rows[$style->id]['testing'] = '' . t('Test Me!') . ''; $rows[$style->id]['edit'] = l(t('edit'), "admin/settings/beautytips/custom-styles/$style->id/edit"); $rows[$style->id]['delete'] = l(t('delete'), "admin/settings/beautytips/custom-styles/$style->id/delete"); $options = array( 'cssSelect' => 'td .bt-style-' . $name, 'text' => t('

Default Text

Nam magna enim, accumsan eu, blandit sed, blandit a, eros.

Cras ultricies placerat eros.

Nulla facilisi. Nam magna enim, accumsan eu, blandit sed, blandit a, eros.

'), 'trigger' => 'hover', 'style' => $name, 'shrinkToFit' => TRUE, ); beautytips_add_beautytips(array($name => $options)); } } else { $empty = t('There are no custom beautytip styles yet.'); } return $link . theme('table', $header, $rows) . $empty; } /** * Form for configuring custom beautytips. */ function beautytips_manager_admin(&$form_state, $id = NULL) { drupal_add_css(drupal_get_path('module', 'beautytips') . '/css/beautytips.css'); $tip = beautytips_manager_get_custom_tip($id); $form = array(); $form['tip'] = array( '#type' => 'markup', '#value' => '', '#tree' => TRUE, ); $form['tip']['id'] = array( '#type' => 'value', '#value' => is_object($tip) ? $tip->id : 0, ); $form['tip']['element'] = array( '#type' => 'textfield', '#title' => t('Element'), '#default_value' => is_object($tip) ? $tip->element : '', ); $content_options = array('attribute' => 'attribute', 'text' => 'text', 'ajax' => 'ajax'); $description = t('Content to display in the beautytip. The data entered here depends on the Content Type.'); $types = array(); $types[0] = t('attribute - Enter the attribute of the element that should be displayed. (If empty, the title will be selected.)'); $types[0] .= '
' . t('ex. "alt"'); $types[1] = t('text - Enter the text that should be displayed with in the beautytip.'); $types[1] .= '
' . t('ex. "This is my beautytip!"'); $types[2] = t('ajax - This will grab the page from the "href" attribute and display that page. Enter css selectors to narrow the down the content from that page.'); $types[2] .= '
' . t('ex. "#my-id .my-class"'); if (user_access('use Javascript for custom beautytip display')) { $content_options['js'] = 'js'; $types[3] = 'js - Directly enter javascript to select the content.'; $types[3] .= '
' . t('ex. "$(this).next(\'.description\').html()"'); } $form['tip']['content_type'] = array( '#type' => 'radios', '#title' => t('Type of Content'), '#description' => t('This helps determine from where to pull the content to be displayed.'), '#options' => $content_options, '#default_value' => is_object($tip) ? $tip->content_type : 0, ); $form['tip']['content'] = array( '#type' => 'textarea', '#title' => t('Content to Display'), '#description' => theme('item_list', $types), '#default_value' => is_object($tip) ? $tip->content : '', ); $triggers = beautytips_manager_get_triggers(); $form['tip']['trigger_on'] = array( '#type' => 'select', '#title' => t('Trigger On'), '#description' => t('Not all events are available for all elements. See jQuery events documentation for details.', array('@events' => 'http://docs.jquery.com/Events')), '#options' => $triggers, '#default_value' => is_object($tip) ? $tip->trigger_on : 0, '#prefix' => '
', ); $form['tip']['trigger_off'] = array( '#type' => 'select', '#title' => t('Trigger Off'), '#options' => $triggers, '#suffix' => '
', '#default_value' => is_object($tip) ? $tip->trigger_off : 0, ); $styles = beautytips_get_styles(); foreach ($styles as $key => $style) { $style_options[$key] = $key; } $form['tip']['style'] = array( '#type' => 'select', '#title' => t('Style'), '#options' => $style_options, '#default_value' => is_object($tip) ? $tip->style : 'default', ); $form['tip']['shrink'] = array( '#type' => 'checkbox', '#title' => t('Shrink to Fit'), '#description' => t('Shrink the beautytip to the size of the content. This can sometimes help with sizing problems and is good for tips with just one line.'), '#default_value' => is_object($tip) ? $tip->shrink : FALSE, ); $positions = is_object($tip) ? explode(',', $tip->positions) : array(); $form['tip']['positions'] = array( '#type' => 'fieldset', '#title' => t('Positions'), '#description' => t("Optionally enter the order of positions in which you want the tip to appear. It will use first in order with available space. The last value will be used if others don't have enough space. If no entries, then the tip will be placed in the area with the most space. Only enter an order for those you wish to use"), '#tree' => TRUE, ); $positions_list = array('top', 'bottom', 'left', 'right'); foreach ($positions_list as $position) { $form['tip']['positions'][$position] = array( '#type' => 'textfield', '#title' => t($position), '#default_value' => (array_search($position, $positions) !== FALSE) ? array_search($position, $positions) : '', '#size' => 1, '#maxlength' => 1, '#prefix' => '
', '#suffix' => '
', ); } $form['tip']['animation_on'] = array( '#type' => 'select', '#title' => t('Animation (On)'), '#options' => array('' => '', 'fadeIn' => 'fadeIn'), '#description' => t("These animations will be applied to the tip when it is turn on or off."), '#default_value' => is_object($tip) ? $tip->animation_on : '', '#prefix' => '
', ); $form['tip']['animation_off'] = array( '#type' => 'select', '#title' => t('Animation (Off)'), '#options' => array('' => '', 'fadeOut' => 'fadeOut', 'slideOut' => 'slideOut'), '#default_value' => is_object($tip) ? $tip->animation_off : '', '#suffix' => '
', ); $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' => '')); $form['tip']['visibility'] = array( '#type' => 'radios', '#title' => t('Show beautytip on specific pages'), '#options' => $options, '#default_value' => is_object($tip) ? $tip->visibility : 0, '#prefix' => '
', '#suffix' => '
', ); $form['tip']['pages'] = array( '#type' => 'textarea', '#title' => t('Pages'), '#default_value' => is_object($tip) ? $tip->pages : '', '#description' => $description, ); $form['save'] = array( '#type' => 'submit', '#value' => t('Save configuration'), ); $form['delete'] = array( '#type' => 'submit', '#value' => t('Delete'), ); $form['#submit'][] = 'beautytips_manager_admin_submit'; return $form; } /** * Validation callback for beautytips manager admin form. */ function beautytips_manager_admin_validate($form, &$form_state) { // TODO: Validate $positions = $form_state['values']['tip']['positions']; foreach ($positions as $position => $order) { if ($order !== '' && !is_numeric($order)) { form_set_error("tip][positions][$position", t("You must enter a numeric value for position order (Or leave it blank).")); } } } /** * Submission callback for beautytips manager admin form. */ function beautytips_manager_admin_submit($form, &$form_state) { $tip = $form_state['values']['tip']; $positions = array(); foreach ($tip['positions'] as $position => $order) { if ($order !== '') { while (isset($positions[$order])) { $order++; } $positions[$order] = $position; } } ksort($positions); $tip['positions'] = (count($positions)) ? implode(',', $positions) : ''; beautytips_manager_save_custom_tip($tip); cache_clear_all('beautytips:beautytips-ui-custom-tips', 'cache'); $form_state['redirect'] = 'admin/settings/beautytips/manager'; } /** * Confirm form for deleting a custom beautytip. */ function beautytips_manager_delete_confirm_form(&$form_state, $id) { $tip = beautytips_manager_get_custom_tip($id); $form['id'] = array( '#type' => 'value', '#value' => $id, ); $question = t('Are you sure you want to the beautytip applied to element %element?', array('%element' => $tip->element)); return confirm_form($form, $question, 'admin/settings/beautytips/manager'); } /** * Submit callback for beautytips delete confirm form. */ function beautytips_manager_delete_confirm_form_submit($form, &$form_state) { beautytips_manager_delete_custom_tip($form_state['values']['id']); cache_clear_all('beautytips:beautytips-ui-custom-tips', 'cache'); $form_state['redirect'] = 'admin/settings/beautytips/manager'; } /** * Delete a singular custom beautytip. */ function beautytips_manager_delete_custom_tip($id) { db_query("DELETE FROM {beautytips_custom_tips} WHERE id = %d", $id); } /** * Save a singular beautytip. */ function beautytips_manager_save_custom_tip($tip) { $tip = (object) $tip; if (isset($tip->id) && $tip->id) { drupal_write_record('beautytips_custom_tips', $tip, 'id'); } else { drupal_write_record('beautytips_custom_tips', $tip); } return $tip; } /** * Retrieve a list of all possible triggers. * TODO: Don't include all of these */ function beautytips_manager_get_triggers() { return array( 'hover' => 'hover', 'hoverIntent' => 'hoverIntent', 'click' => 'click', 'dblclick' => 'dblclick', 'blur' => 'blur', 'focus' => 'focus', 'mouseover' => 'mouseover', 'mouseout' => 'mouseout', 'mousedown' => 'mousedown', 'mousemove' => 'mousemove', 'mouseenter' => 'mouseenter', 'mouseleave' => 'mouseleave', 'change' => 'change', 'select' => 'select', 'submit' => 'submit', 'keydown' => 'keydown', 'keypress' => 'keypress', 'keyup' => 'keyup', 'error' => 'error', 'load' => 'load', 'unload' => 'unload', 'resize' => 'resize', 'scroll' => 'scroll', ); } /** * Retrieve all custom beautytips. */ function beautytips_manager_get_custom_tips() { $cache = cache_get('beautytips:beautytips-ui-custom-tips'); if (!$cache) { $tips = array(); $results = db_query("SELECT * FROM {beautytips_custom_tips}"); while ($tip = db_fetch_object($results)) { $tips[] = $tip; } cache_set('beautytips:beautytips-ui-custom-tips', $tips); } else { $tips = $cache->data; } return $tips; } /** * Retrieves a single custom beautytip. */ function beautytips_manager_get_custom_tip($id) { $sql = "SELECT * FROM {beautytips_custom_tips} WHERE id = %d"; return db_fetch_object(db_query($sql, $id)); } /** * Given a custom tip, build an array of options * that can be passed to beautytips_add_beautytips(). */ function beautytips_manager_build_beautytip($tip) { $single_triggers = array('hover', 'hoverIntent'); $trigger = in_array($tip->trigger_on, $single_triggers) ? $tip->trigger_on : array($tip->trigger_on, $tip->trigger_off); $options = array( 'cssSelect' => check_plain($tip->element), 'style' => $tip->style, 'trigger' => $trigger, 'shrinkToFit' => (boolean) $tip->shrink, ); if ($tip->animation_on) { $options['animate']['on'] = $tip->animation_on; } if ($tip->animation_off) { $options['animate']['off'] = $tip->animation_off; } if ($tip->positions) { $options['positions'] = explode(',', $tip->positions); } switch ($tip->content_type) { case 'attribute': if ($tip->content) { $options['contentSelector'] = "$(this).attr('" . check_plain($tip->content) . "')"; } break; case 'text': $options['text'] = check_markup($tip->content); break; case 'ajax': $options['ajaxPath'] = !$tip->content ? "$(this).attr('href')" : array("$(this).attr('href')", check_plain($tip->content)); break; case 'js': $options['contentSelector'] = check_plain($tip->content); break; } return $options; } /** * Form for editing a custom beautytip style. */ function beautytips_manager_custom_styles_form(&$form_state, $id = NULL) { if (!is_null($id)) { $style = beautytips_manager_get_custom_style($id); $style_map = beautytips_manager_style_mapping(); $style_options = $style_map['options']; $css_style_options = $style_map['css_options']; } // TODO: Make bubble scroll with page to see changes. $form = array(); $form['name'] = array( '#type' => 'textfield', '#title' => t('Style Name'), '#description' => t('It must contain only alphanumeric characters and underscores.'), '#default_value' => isset($style->name) ? $style->name : '', ); $form['style'] = array( '#type' => 'value', '#value' => isset($style) ? $style : NULL, ); // TODO: Add this into mapping $style_info = array( 'fill' => t('background color (string - html color)'), 'strokeWidth' => t('width of border (integer)'), 'strokeStyle' => t('color of border (string - html color)'), 'width' => t('width of popup (number in px)'), 'padding' => t('space between content and border (number in px)'), 'cornerRadius' => t('Controls roundness of corners (integer)'), 'spikeGirth' => t('thickness of spike (integer)'), 'spikeLength' => t('length of spike (integer)'), 'shadowBlur' => t('Size of popup shadow (integer)'), 'shadowColor' => t('Color of popup shadow (string - html color)'), ); $form['custom_styles'] = array( '#type' => 'fieldset', '#title' => t('Custom Style Options'), '#description' => t('

'), '#attributes' => array('class' => 'bt-custom-styles'), '#tree' => TRUE, ); foreach ($style_info as $option => $description) { $form['custom_styles'][$option] = array( '#title' => $option, '#description' => $description, '#type' => 'textfield', '#default_value' => (isset($style->{$style_options[$option]}) && !is_null($style->{$style_options[$option]})) ? $style->{$style_options[$option]} : '', ); } $form['custom_styles']['shadow'] = array( '#title' => 'shadow', '#description' => t('Whether or not the popup has a shadow'), '#type' => 'radios', '#options' => array('default' => t('Default'), 'shadow' => t('Shadow On'), 'no_shadow' => t('Shadow Off')), '#attributes' => array('class' => 'beautytips-options-shadow'), '#default_value' => isset($style->shadow) ? $style->shadow : 'default', ); $form['custom_styles']['cssClass'] = array( '#title' => 'cssClass', '#description' => t('The class that will be applied to the box wrapper div (of the TIP)'), '#type' => 'textfield', '#default_value' => isset($style->css_class) ? $style->css_class : '', ); $css_style_info = array('color', 'fontFamily', 'fontWeight', 'fontSize'); $form['custom_styles']['css-styles'] = array( '#type' => 'fieldset', '#title' => t('Font Styling'), '#description' => t('Enter css options for changing the font style'), '#attributes' => array('class' => 'beautytips-css-styling'), '#collapsible' => FALSE, ); foreach ($css_style_info as $option) { $form['custom_styles']['css-styles'][$option] = array( '#title' => $option, '#type' => 'textfield', '#default_value' => (isset($style->{$css_style_options[$option]}) && !is_null($style->{$css_style_options[$option]})) ? $style->{$css_style_options[$option]} : '', ); } $path = drupal_get_path('module', 'beautytips'); drupal_add_js($path . '/other_libs/colorpicker/js/colorpicker.js'); drupal_add_css($path . '/other_libs/colorpicker/css/colorpicker.css'); drupal_add_css($path .'/css/beautytips.css'); beautytips_add_beautytips(); drupal_add_js($path . '/js/bt_custom_styles.js'); $form['save'] = array( '#type' => 'submit', '#value' => t('Save'), ); return $form; } /** * Validation callback on beautytips_manager_custom_styles_form. */ function beautytips_manager_custom_styles_form_validate($form, &$form_state) { if (empty($form_state['values']['name'])) { form_set_error('name', t('You must name this custom style.')); } if (preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['name'])) { form_set_error('name', t('Style name must be alphanumeric or underscores only.')); } } /** * Validation callback on beautytips_manager_custom_styles_form. */ function beautytips_manager_custom_styles_form_submit($form, &$form_state) { $style = new stdClass; $style->name = $form_state['values']['name']; $mapping = beautytips_manager_style_mapping(); foreach ($form_state['values']['custom_styles'] as $custom_style => $value) { if (!is_array($value)) { $field = $custom_style; if (isset($mapping['options'][$custom_style])) { $style->{$mapping['options'][$custom_style]} = $value; } } else { if ($custom_style == 'css-styles') { foreach ($value as $css_style => $css_value) { if (isset($mapping['css_options'][$css_style])) { $style->{$mapping['css_options'][$css_style]} = $css_value; } } } } } if (!is_null($form_state['values']['style'])) { $style->id = $form_state['values']['style']->id; } beautytips_manager_save_custom_style($style); cache_clear_all('beautytips:beautytips-styles', 'cache'); $form_state['redirect'] = 'admin/settings/beautytips/custom-styles'; } /** * Delete a singular custom beautytip. */ function beautytips_manager_delete_custom_style($id) { db_query("DELETE FROM {beautytips_custom_styles} WHERE id = %d", $id); } /** * Save a singular beautytip style. */ function beautytips_manager_save_custom_style($style) { $style = (object) $style; if (isset($style->id) && $style->id) { drupal_write_record('beautytips_custom_styles', $style, 'id'); } else { drupal_write_record('beautytips_custom_styles', $style); } return $style; } /** * Contains an array of beautytip style options * for mapping the names between php and javascript. */ function beautytips_manager_style_mapping() { return array( 'options' => array( 'fill' => 'fill', 'strokeWidth' => 'stroke_width', 'strokeStyle' => 'stroke_style', 'width' => 'width', 'padding' => 'padding', 'cornerRadius' => 'corner_radius', 'spikeGirth' => 'spike_girth', 'spikeLength' => 'spike_length', 'shadow' => 'shadow', 'shadowBlur' => 'shadow_blur', 'shadowColor' => 'shadow_color', 'cssClass' => 'css_class', ), 'css_options' => array( 'color' => 'css_color', 'fontFamily' => 'css_font_family', 'fontWeight' => 'css_font_weight', 'fontSize' => 'css_font_size', ), ); } /** * Get all defined custom styles. */ function beautytips_manager_get_custom_styles() { $styles = array(); $results = db_query("SELECT * FROM {beautytips_custom_styles}"); while ($style = db_fetch_object($results)) { $styles[] = $style; } return $styles; } /** * Grab a custom style from the database. */ function beautytips_manager_get_custom_style($id) { $sql = "SELECT * FROM {beautytips_custom_styles} WHERE id = %d"; return db_fetch_object(db_query($sql, $id)); } /** * Implemenatation of hook_define_beautytips_styles(). */ function beautytips_manager_define_beautytips_styles() { $styles = array(); $custom_styles = beautytips_manager_get_custom_styles(); $style_map = beautytips_manager_style_mapping(); $style_options = array_flip($style_map['options']); $css_style_options = array_flip($style_map['css_options']); if (count($custom_styles)) { foreach ($custom_styles as $id => $style) { $options = array(); foreach ($style as $key => $value) { if (isset($style_options[$key])) { if ($key == 'shadow') { if ($value != 'default') { $options['shadow'] = $value == 'shadow' ? TRUE : FALSE; } } else if (!is_null($value) && $value != '') { $options[$style_options[$key]] = $value; } } else if (isset($css_style_options[$key])) { if (!is_null($value) && $value != '') { $options['cssStyles'][$css_style_options[$key]] = $value; } } } $styles[$style->name] = $options; } } return $styles; }