'helpers/void', 'type' => MENU_CALLBACK, 'callback' => 'void_page', 'access' => TRUE, ); } return $items; } /** * Test if a string is empty, or equals another string. If so, return a themed empty placeholder. Else return the input string. * @param $string: The string we want to find out if its empty; * @param $test: Optionally you can test against this string; In case you want to redefine "empty". */ function test_empty_string($string, $test = '') { if ($string == $test) { return theme('empty_placeholder'); } return $string; } /** * Formats a chopped off string of a certain length. Calls a theme function to * do the actual formatting. By default it will return strings in the form of * verylongstringwithsomecoo... * @param $string the original string. * @param $length Optional provide a length for the string * @param $count_addition Optional provide an amount for the additional * charachters. Giving this parameter, for example a value of 5, you will * recieve a shortened string in the form of verylongstringwithsomec..... */ function format_shorten_string($string, $length = 15, $count_addition = 3) { if (drupal_strlen($string) > $length) { $out = theme('shorten_string', drupal_substr($string, 0, ($length - $count_addition)), $string, $count_addition); } else { $out = $string; } return $out; } /** * Page functions. Render pages */ /** * Void. Render nothing. A blank page. */ function void_page() { return ''; } /** * Common API functions */ /** * Get a block as object prepared to use in the theme_block function * @param $name the modulename (block name) to get the block from. * @param $delta the blok delta. Each block in each module has a unique delta value. A number indicating that block. */ function get_block($name, $delta = 0) { if ($result = module_invoke($name, 'block', 'view', $delta)) { $block = (object)$result; $block->module = $name; $block->delta = $delta; return $block; } } /** * Find out if a user has a certain role or roles. * @param $user a user object. Must only contain the $user->roles array. * @param $roles an array of roles to check for. * @return TRUE if the user has a role you checked for, FALSE if the user is not * within any of the requested roles. */ function user_has_role($user, $roles) { foreach ($roles as $rid) { if(in_array($rid, array_keys($user->roles))) { return TRUE; } } return FALSE; } /** * Theme functions */ /** * Theme an "empty" placeholder. Outputs a translated "not available" by default. * @param $message: Optional. Provide a translated message string. * @return a string that can be used as placeholder for non existing content. */ function theme_empty_placeholder($message = NULL) { $message = ($message ? $message : t("not available")); return '' . $message .''; } /** * Return a themed list of definition items. * Patch pending at http://drupal.org/node/54898 * @param $items * An array of items to be displayed in the list. * The argument is: array("term" => $term, "definitions" => $definitions) * If you provide the $definition as arrays, you will get multiple DDs with each DT. * If you provide the $definitions as a string, only one DD will be added to the DT. * @param $title * The title of the list. * @param $filter * Boolean value to define wether or not you wish to filter the input. Should be left TRUE, unless you sanitize your input yourself. * @return * A string containing the list output. */ function theme_definition_list($items = array(), $title = NULL, $filter = TRUE) { $output = '
'; if (isset($title)) { $output .= '

'. ($filter ? check_plain($title) : $title).'

'; } if (!empty($items)) { $output .= "
"; foreach ($items as $item) { $output .= '
'. ($filter ? check_plain($item['term']) : $item['term']) .'
'; if (is_string($item['definitions'])) { $output .= '
'. ($filter ? filter_xss($item['definitions']) : $item['definitions']) .'
'; } elseif (is_array($item['definitions'])) { foreach ($item['definitions'] as $definition) { $output .= '
'. ($filter ? filter_xss($definition) : $definition) ."
\n"; } } } $output .= "
"; } $output .= '
'; return $output; } /** * Return a themed name: value DT DL pair. * @param $name * The name string. * @param $value * The value string. * @param $filter * Bool passed on to definition list. */ function theme_name_and_value_pair($name, $value, $filter = TRUE) { //simple version: return "$name: $value"; $items[] = array('term' => $name .':', 'definitions' => $value); return theme('definition_list', $items, NULL, $filter); } /** * Returns a themed "none" string, for usage in a select form. * In case you wish a general way of building the <none> strings. * @param $string optionally provide a string that goes in the place of the word "none". If you provide this, it will not be translated. */ function theme_none_option($string = NULL) { $string = ($string ? $string : t('none')); return '<'. $string .'>'; } /** * Function to theme the read more links * Drupal issue number 69571 * @ingroup themeable * @param $path a drupal path or full url to the full resource. Include http:// if you link to external resource. * @param $title an optional title that will provide a tooltip text when hovering over the link. */ function theme_read_more($path, $title = NULL) { if ($title) { $params['title'] = check_plain($title); } $params['class'] = 'read-more'; return l(t('read more'), $path, $params); } /** * Function to theme the read more links * @ingroup themeable * @param $short_string The shortened string * @param $full_string The unshortened string, for display in the tooltip * @param $count_addition The amount of charanters that the calling function wants to be added. Defaults to three. Optional. */ function theme_shorten_string($short_string, $full_string, $count_addition = 3) { while ($i < $count_addition) { $i++; $addition .= '.'; } return ''. $short_string . $addition .''; }