Révision 7e72b748
Ajouté par Assos Assos il y a plus de 6 ans
drupal7/sites/all/modules/ctools/ctools.module | ||
---|---|---|
23 | 23 |
* ; Requires CTools v7.x-1.4 or newer. |
24 | 24 |
* dependencies[] = ctools (>=1.4) |
25 | 25 |
*/ |
26 |
define('CTOOLS_MODULE_VERSION', '7.x-1.11');
|
|
26 |
define('CTOOLS_MODULE_VERSION', '7.x-1.13');
|
|
27 | 27 |
|
28 | 28 |
/** |
29 | 29 |
* Test the CTools API version. |
... | ... | |
75 | 75 |
* The minimum version of CTools necessary for your software to run with it. |
76 | 76 |
* @param $maximum |
77 | 77 |
* The maximum version of CTools allowed for your software to run with it. |
78 |
* |
|
79 |
* @return bool |
|
80 |
* TRUE if the running ctools is usable, FALSE otherwise. |
|
78 | 81 |
*/ |
79 | 82 |
function ctools_api_version($minimum, $maximum = NULL) { |
80 | 83 |
if (version_compare(CTOOLS_API_VERSION, $minimum, '<')) { |
... | ... | |
89 | 92 |
} |
90 | 93 |
|
91 | 94 |
// ----------------------------------------------------------------------- |
92 |
// General utility functions |
|
93 |
|
|
95 |
// General utility functions. |
|
94 | 96 |
/** |
95 | 97 |
* Include .inc files as necessary. |
96 | 98 |
* |
... | ... | |
118 | 120 |
* @param $dir |
119 | 121 |
* Optional subdirectory containing the include file. |
120 | 122 |
*/ |
123 |
|
|
121 | 124 |
function ctools_include($file, $module = 'ctools', $dir = 'includes') { |
122 | 125 |
static $used = array(); |
123 | 126 |
|
... | ... | |
147 | 150 |
/** |
148 | 151 |
* Add an arbitrary path to the $form_state so it can work with form cache. |
149 | 152 |
* |
150 |
* module_load_include uses an unfortunately annoying syntax to work, making it
|
|
151 |
* difficult to translate the more simple $path + $file syntax. |
|
153 |
* The module_load_include() function uses an unfortunately annoying syntax to
|
|
154 |
* work, making it difficult to translate the more simple $path + $file syntax.
|
|
152 | 155 |
*/ |
153 | 156 |
function ctools_form_include_file(&$form_state, $filename) { |
154 | 157 |
if (!isset($form_state['build_info']['args'])) { |
... | ... | |
172 | 175 |
* Optional module containing the include. |
173 | 176 |
* @param $dir |
174 | 177 |
* Optional subdirectory containing the include file. |
178 |
* |
|
179 |
* @return string |
|
180 |
* A string containing the appropriate path from drupal root. |
|
175 | 181 |
*/ |
176 | 182 |
function ctools_image_path($image, $module = 'ctools', $dir = 'images') { |
177 | 183 |
return drupal_get_path('module', $module) . "/$dir/" . $image; |
... | ... | |
211 | 217 |
* Optional module containing the include. |
212 | 218 |
* @param $dir |
213 | 219 |
* Optional subdirectory containing the include file. |
220 |
* |
|
221 |
* @return string |
|
222 |
* A string containing the appropriate path from drupal root. |
|
214 | 223 |
*/ |
215 | 224 |
function ctools_attach_css($file, $module = 'ctools', $dir = 'css') { |
216 | 225 |
return drupal_get_path('module', $module) . "/$dir/$file.css"; |
... | ... | |
249 | 258 |
* Optional module containing the include. |
250 | 259 |
* @param $dir |
251 | 260 |
* Optional subdirectory containing the include file. |
261 |
* |
|
262 |
* @return string |
|
263 |
* A string containing the appropriate path from drupal root. |
|
252 | 264 |
*/ |
253 | 265 |
function ctools_attach_js($file, $module = 'ctools', $dir = 'js') { |
254 | 266 |
return drupal_get_path('module', $module) . "/$dir/$file.js"; |
... | ... | |
267 | 279 |
return user_roles(); |
268 | 280 |
} |
269 | 281 |
|
270 |
/* |
|
271 |
* Break x,y,z and x+y+z into an array. Numeric only. |
|
282 |
/** |
|
283 |
* Parse integer sequences of the form "x,y,z" or "x+y+z" into separate values. |
|
284 |
* |
|
285 |
* A string with integers separated by comma (,) is reported as an 'and' set; |
|
286 |
* separation by a plus sign (+) or a space ( ) is an 'or' set. The meaning |
|
287 |
* of this is up to the caller. Negative or fractional numbers are not |
|
288 |
* recognised. |
|
289 |
* |
|
290 |
* Additional space characters within or around the sequence are not allowed. |
|
272 | 291 |
* |
273 | 292 |
* @param $str |
274 | 293 |
* The string to parse. |
275 | 294 |
* |
276 |
* @return $object |
|
277 |
* An object containing |
|
278 |
* - operator: Either 'and' or 'or' |
|
279 |
* - value: An array of numeric values. |
|
295 |
* @return object |
|
296 |
* An object containing the properties: |
|
297 |
* |
|
298 |
* - operator: Either 'and' or 'or' when there are multiple matched values. |
|
299 |
* Absent when invalid_input is TRUE or there is only one value. |
|
300 |
* - value: An array of integers (never strings) from $str. An empty array is |
|
301 |
* returned if the input is empty. A single integer input is returned |
|
302 |
* as a single value, but no 'operator' is defined. |
|
303 |
* - invalid_input: TRUE if input could not be parsed and the values array |
|
304 |
* will contain just -1. This property is otherwise absent. |
|
280 | 305 |
*/ |
281 | 306 |
function ctools_break_phrase($str) { |
282 | 307 |
$object = new stdClass(); |
... | ... | |
286 | 311 |
$object->operator = 'or'; |
287 | 312 |
$object->value = preg_split('/[+ ]/', $str); |
288 | 313 |
} |
289 |
else if (preg_match('/^([0-9]+,)*[0-9]+$/', $str)) {
|
|
314 |
elseif (preg_match('/^([0-9]+,)*[0-9]+$/', $str)) { |
|
290 | 315 |
$object->operator = 'and'; |
291 | 316 |
$object->value = explode(',', $str); |
292 | 317 |
} |
... | ... | |
304 | 329 |
|
305 | 330 |
// Doubly ensure that all values are numeric only. |
306 | 331 |
foreach ($object->value as $id => $value) { |
307 |
$object->value[$id] = intval($value);
|
|
332 |
$object->value[$id] = (int) $value;
|
|
308 | 333 |
} |
309 | 334 |
|
310 | 335 |
return $object; |
... | ... | |
314 | 339 |
* Set a token/value pair to be replaced later in the request, specifically in |
315 | 340 |
* ctools_page_token_processing(). |
316 | 341 |
* |
317 |
* @param $token |
|
342 |
* @param string $token
|
|
318 | 343 |
* The token to be replaced later, during page rendering. This should |
319 |
* ideally be a string inside of an HTML comment, so that if there is |
|
320 |
* no replacement, the token will not render on the page. |
|
321 |
* @param $type |
|
344 |
* ideally be a string inside of an HTML comment, so that if there is |
|
345 |
* no replacement, the token will not render on the page. |
|
346 |
* If $token is NULL, the token set is not changed, but is still |
|
347 |
* returned. |
|
348 |
* @param string $type |
|
322 | 349 |
* The type of the token. Can be either 'variable', which will pull data |
323 |
* directly from the page variables |
|
324 |
* @param $argument |
|
325 |
* If $type == 'variable' then argument should be the key to fetch from |
|
326 |
* the $variables. If $type == 'callback' then it should either be the |
|
327 |
* callback, or an array that will be sent to call_user_func_array(). |
|
328 |
* |
|
329 |
* @return |
|
350 |
* directly from the page variables, or 'callback', which causes a function |
|
351 |
* to be called to calculate the value. No other values are supported. |
|
352 |
* @param string|array $argument |
|
353 |
* For $type of: |
|
354 |
* - 'variable': argument should be the key to fetch from the $variables. |
|
355 |
* - 'callback': then it should either be the callback function name as a |
|
356 |
* string, or an array that will be sent to call_user_func_array(). Argument |
|
357 |
* arrays must not use array keys (i.e. $a[0] is the first and $a[1] the |
|
358 |
* second element, etc.) |
|
359 |
* |
|
360 |
* @return array |
|
330 | 361 |
* A array of token/variable names to be replaced. |
331 | 362 |
*/ |
332 | 363 |
function ctools_set_page_token($token = NULL, $type = NULL, $argument = NULL) { |
333 |
static $tokens = array();
|
|
364 |
$tokens = &drupal_static('ctools_set_page_token', array());
|
|
334 | 365 |
|
335 | 366 |
if (isset($token)) { |
336 | 367 |
$tokens[$token] = array($type, $argument); |
... | ... | |
339 | 370 |
} |
340 | 371 |
|
341 | 372 |
/** |
342 |
* Easily set a token from the page variables. |
|
373 |
* Reset the defined page tokens within this request. |
|
374 |
* |
|
375 |
* Introduced for simpletest purposes. Normally not needed. |
|
376 |
*/ |
|
377 |
function ctools_reset_page_tokens() { |
|
378 |
drupal_static_reset('ctools_set_page_token'); |
|
379 |
} |
|
380 |
|
|
381 |
/** |
|
382 |
* Set a replacement token from the containing element's children during #post_render. |
|
343 | 383 |
* |
344 | 384 |
* This function can be used like this: |
345 |
* $token = ctools_set_variable_token('tabs'); |
|
385 |
* $token = ctools_set_variable_token('tabs');
|
|
346 | 386 |
* |
347 |
* $token will then be a simple replacement for the 'tabs' about of the |
|
348 |
* variables available in the page template. |
|
387 |
* The token "<!-- ctools-page-tabs -->" would then be replaced by the value of |
|
388 |
* this element's (sibling) render array key 'tabs' during post-render (or be |
|
389 |
* deleted if there was no such key by that point). |
|
390 |
* |
|
391 |
* @param string $token |
|
392 |
* The token string for the page callback, e.g. 'title'. |
|
393 |
* |
|
394 |
* @return string |
|
395 |
* The constructed token. |
|
396 |
* |
|
397 |
* @see ctools_set_callback_token() |
|
398 |
* @see ctools_page_token_processing() |
|
349 | 399 |
*/ |
350 | 400 |
function ctools_set_variable_token($token) { |
351 | 401 |
$string = '<!-- ctools-page-' . $token . ' -->'; |
... | ... | |
354 | 404 |
} |
355 | 405 |
|
356 | 406 |
/** |
357 |
* Easily set a token from the page variables.
|
|
407 |
* Set a replacement token from the value of a function during #post_render.
|
|
358 | 408 |
* |
359 | 409 |
* This function can be used like this: |
360 |
* $token = ctools_set_variable_token('id', 'mymodule_myfunction'); |
|
410 |
* $token = ctools_set_callback_token('id', 'mymodule_myfunction'); |
|
411 |
* |
|
412 |
* Or this (from its use in ctools_page_title_content_type_render): |
|
413 |
* $token = ctools_set_callback_token('title', array( |
|
414 |
* 'ctools_page_title_content_type_token', $conf['markup'], $conf['id'], $conf['class'] |
|
415 |
* ) |
|
416 |
* ); |
|
417 |
* |
|
418 |
* The token (e.g: "<!-- ctools-page-id-1b7f84d1c8851290cc342631ac663053 -->") |
|
419 |
* would then be replaced during post-render by the return value of: |
|
420 |
* |
|
421 |
* ctools_page_title_content_type_token($value_markup, $value_id, $value_class); |
|
422 |
* |
|
423 |
* @param string $token |
|
424 |
* The token string for the page callback, e.g. 'title'. |
|
425 |
* |
|
426 |
* @param string|array $callback |
|
427 |
* For callback functions that require no args, the name of the function as a |
|
428 |
* string; otherwise an array of two or more elements: the function name |
|
429 |
* followed by one or more function arguments. |
|
430 |
* |
|
431 |
* NB: the value of $callback must be a procedural (non-class) function that |
|
432 |
* passes the php function_exists() check. |
|
433 |
* |
|
434 |
* The callback function itself will be called with args dependent |
|
435 |
* on $callback. If: |
|
436 |
* - $callback is a string, the function is called with a reference to the |
|
437 |
* render array; |
|
438 |
* - $callback is an array, the function is called with $callback merged |
|
439 |
* with an array containing a reference to the render array. |
|
440 |
* |
|
441 |
* @return string |
|
442 |
* The constructed token. |
|
443 |
* |
|
444 |
* @see ctools_set_variable_token() |
|
445 |
* @see ctools_page_token_processing() |
|
361 | 446 |
*/ |
362 | 447 |
function ctools_set_callback_token($token, $callback) { |
363 | 448 |
// If the callback uses arguments they are considered in the token. |
... | ... | |
384 | 469 |
/** |
385 | 470 |
* Wrapper function to create UUIDs via ctools, falls back on UUID module |
386 | 471 |
* if it is enabled. This code is a copy of uuid.inc from the uuid module. |
472 |
* |
|
387 | 473 |
* @see http://php.net/uniqid#65879 |
388 | 474 |
*/ |
389 |
|
|
390 | 475 |
function ctools_uuid_generate() { |
391 | 476 |
if (!module_exists('uuid')) { |
392 | 477 |
ctools_include('uuid'); |
... | ... | |
413 | 498 |
|
414 | 499 |
/** |
415 | 500 |
* Check that a string appears to be in the format of a UUID. |
501 |
* |
|
416 | 502 |
* @see http://drupal.org/project/uuid |
417 | 503 |
* |
418 | 504 |
* @param $uuid |
... | ... | |
468 | 554 |
*/ |
469 | 555 |
function ctools_class_remove($classes, $hook = 'html') { |
470 | 556 |
if (!is_array($classes)) { |
557 |
// @todo Consider using explode(' ', $classes); |
|
558 |
// @todo Consider checking that $classes is a string before adding. |
|
471 | 559 |
$classes = array($classes); |
472 | 560 |
} |
473 | 561 |
|
... | ... | |
480 | 568 |
} |
481 | 569 |
} |
482 | 570 |
|
483 |
// ----------------------------------------------------------------------- |
|
484 |
// Drupal core hooks |
|
571 |
/** |
|
572 |
* Reset the storage used for ctools_class_add and ctools_class_remove. |
|
573 |
* |
|
574 |
* @see ctools_class_add() |
|
575 |
* @see ctools_class_remove() |
|
576 |
*/ |
|
577 |
function ctools_class_reset() { |
|
578 |
drupal_static_reset('ctools_process_classes'); |
|
579 |
} |
|
580 |
|
|
581 |
/** |
|
582 |
* Return the classes for the body (added by ctools_class_add). |
|
583 |
* |
|
584 |
* @return array |
|
585 |
* A copy of the array of classes to add to the body tag. If none have been |
|
586 |
* added, this will be an empty array. |
|
587 |
* |
|
588 |
* @see ctools_class_add() |
|
589 |
*/ |
|
590 |
function ctools_get_classes() { |
|
591 |
return drupal_static('ctools_process_classes', array()); |
|
592 |
} |
|
485 | 593 |
|
594 |
// ----------------------------------------------------------------------- |
|
595 |
// Drupal core hooks. |
|
486 | 596 |
/** |
487 | 597 |
* Implement hook_init to keep our global CSS at the ready. |
488 | 598 |
*/ |
599 |
|
|
489 | 600 |
function ctools_init() { |
490 | 601 |
ctools_add_css('ctools'); |
491 | 602 |
// If we are sure that CTools' AJAX is in use, change the error handling. |
... | ... | |
504 | 615 |
* Shutdown handler used during ajax operations to help catch fatal errors. |
505 | 616 |
*/ |
506 | 617 |
function ctools_shutdown_handler() { |
507 |
if (function_exists('error_get_last') AND ($error = error_get_last())) {
|
|
618 |
if (function_exists('error_get_last') && ($error = error_get_last())) {
|
|
508 | 619 |
switch ($error['type']) { |
509 | 620 |
case E_ERROR: |
510 | 621 |
case E_CORE_ERROR: |
... | ... | |
583 | 694 |
|
584 | 695 |
/** |
585 | 696 |
* Implements hook_element_info_alter(). |
586 |
* |
|
587 | 697 |
*/ |
588 | 698 |
function ctools_element_info_alter(&$type) { |
589 | 699 |
ctools_include('dependent'); |
... | ... | |
619 | 729 |
|
620 | 730 |
// ----------------------------------------------------------------------- |
621 | 731 |
// FAPI hooks that must be in the .module file. |
622 |
|
|
623 | 732 |
/** |
624 | 733 |
* Alter the comment form to get a little more control over it. |
625 | 734 |
*/ |
735 |
|
|
626 | 736 |
function ctools_form_comment_form_alter(&$form, &$form_state) { |
627 | 737 |
if (!empty($form_state['ctools comment alter'])) { |
628 | 738 |
// Force the form to post back to wherever we are. |
... | ... | |
640 | 750 |
|
641 | 751 |
// ----------------------------------------------------------------------- |
642 | 752 |
// CTools hook implementations. |
643 |
|
|
644 | 753 |
/** |
645 | 754 |
* Implementation of hook_ctools_plugin_directory() to let the system know |
646 | 755 |
* where all our own plugins are. |
647 | 756 |
*/ |
757 |
|
|
648 | 758 |
function ctools_ctools_plugin_directory($owner, $plugin_type) { |
649 | 759 |
if ($owner == 'ctools') { |
650 | 760 |
return 'plugins/' . $plugin_type; |
... | ... | |
665 | 775 |
|
666 | 776 |
// ----------------------------------------------------------------------- |
667 | 777 |
// Drupal theme preprocess hooks that must be in the .module file. |
668 |
|
|
669 | 778 |
/** |
670 | 779 |
* A theme preprocess function to automatically allow panels-based node |
671 | 780 |
* templates based upon input when the panel was configured. |
672 | 781 |
*/ |
782 |
|
|
673 | 783 |
function ctools_preprocess_node(&$vars) { |
674 | 784 |
// The 'ctools_template_identifier' attribute of the node is added when the pane is |
675 | 785 |
// rendered. |
... | ... | |
679 | 789 |
} |
680 | 790 |
} |
681 | 791 |
|
682 |
|
|
683 | 792 |
/** |
684 | 793 |
* Implements hook_page_alter(). |
685 | 794 |
* |
686 | 795 |
* Last ditch attempt to remove sidebar regions if the "no blocks" |
687 | 796 |
* functionality has been activated. |
688 | 797 |
* |
689 |
* @see ctools_block_list_alter().
|
|
798 |
* @see ctools_block_list_alter() |
|
690 | 799 |
*/ |
691 | 800 |
function ctools_page_alter(&$page) { |
692 | 801 |
$check = drupal_static('ctools_set_no_blocks', TRUE); |
... | ... | |
716 | 825 |
case 'variable': |
717 | 826 |
$tokens[$token] = isset($elements[$argument]) ? $elements[$argument] : ''; |
718 | 827 |
break; |
828 |
|
|
719 | 829 |
case 'callback': |
720 | 830 |
if (is_string($argument) && function_exists($argument)) { |
721 | 831 |
$tokens[$token] = $argument($elements); |
... | ... | |
744 | 854 |
return; |
745 | 855 |
} |
746 | 856 |
|
747 |
$classes = drupal_static('ctools_process_classes', array());
|
|
857 |
$classes = ctools_get_classes();
|
|
748 | 858 |
|
749 | 859 |
// Process the classses to add. |
750 | 860 |
if (!empty($classes[$hook]['add'])) { |
... | ... | |
758 | 868 |
$variables['classes_array'] = array_diff($variables['classes_array'], $remove_classes); |
759 | 869 |
} |
760 | 870 |
|
761 |
// Update the classes within the attributes array to match the classes array |
|
762 |
if (isset($variables['attributes_array']['class'])) { |
|
763 |
$variables['attributes_array']['class'] = array_unique(array_merge($variables['classes_array'], $variables['attributes_array']['class'])); |
|
764 |
$variables['attributes'] = $variables['attributes_array'] ? drupal_attributes($variables['attributes_array']) : ''; |
|
765 |
} |
|
766 |
|
|
767 | 871 |
// Since this runs after template_process(), we need to re-implode the |
768 | 872 |
// classes array. |
769 | 873 |
$variables['classes'] = implode(' ', $variables['classes_array']); |
... | ... | |
771 | 875 |
|
772 | 876 |
// ----------------------------------------------------------------------- |
773 | 877 |
// Menu callbacks that must be in the .module file. |
774 |
|
|
775 | 878 |
/** |
776 | 879 |
* Determine if the current user has access via a plugin. |
777 | 880 |
* |
... | ... | |
795 | 898 |
* @return |
796 | 899 |
* TRUE if access is granted, false if otherwise. |
797 | 900 |
*/ |
901 |
|
|
798 | 902 |
function ctools_access_menu($access) { |
799 | 903 |
// Short circuit everything if there are no access tests. |
800 | 904 |
if (empty($access['plugins'])) { |
... | ... | |
823 | 927 |
* An indexed array of zero or more permission strings to be checked by |
824 | 928 |
* user_access(). |
825 | 929 |
* |
826 |
* @return |
|
930 |
* @return bool
|
|
827 | 931 |
* Iff all checks pass will this function return TRUE. If an invalid argument |
828 | 932 |
* is passed (e.g., not a string), this function errs on the safe said and |
829 | 933 |
* returns FALSE. |
... | ... | |
885 | 989 |
|
886 | 990 |
// ----------------------------------------------------------------------- |
887 | 991 |
// Caching callbacks on behalf of export-ui. |
888 |
|
|
889 | 992 |
/** |
890 | 993 |
* Menu access callback for various tasks of export-ui. |
891 | 994 |
*/ |
... | ... | |
929 | 1032 |
} |
930 | 1033 |
|
931 | 1034 |
/** |
932 |
* Callback for access control ajax form on behalf of export ui |
|
1035 |
* Callback for access control ajax form on behalf of export ui.
|
|
933 | 1036 |
* |
934 | 1037 |
* Returns the cached access config and contexts used. |
935 | 1038 |
* Note that this is assuming that access will be in $item->access -- if it |
... | ... | |
962 | 1065 |
} |
963 | 1066 |
|
964 | 1067 |
/** |
965 |
* Implement hook_block_list_alter() to potentially remove blocks.
|
|
1068 |
* Implements hook_block_list_alter().
|
|
966 | 1069 |
* |
1070 |
* Used to potentially remove blocks. |
|
967 | 1071 |
* This exists in order to replicate Drupal 6's "no blocks" functionality. |
968 | 1072 |
*/ |
969 | 1073 |
function ctools_block_list_alter(&$blocks) { |
... | ... | |
1026 | 1130 |
case 'entity_id:taxonomy_term': |
1027 | 1131 |
$plugin['no ui'] = TRUE; |
1028 | 1132 |
break; |
1133 |
|
|
1029 | 1134 |
case 'entity:user': |
1030 | 1135 |
$plugin = ctools_get_context('user'); |
1031 | 1136 |
unset($plugin['no ui']); |
... | ... | |
1059 | 1164 |
function ctools_field_create_instance($instance) { |
1060 | 1165 |
ctools_flush_field_caches(); |
1061 | 1166 |
} |
1167 |
|
|
1062 | 1168 |
/** |
1063 | 1169 |
* Implements hook_field_delete_field(). |
1064 | 1170 |
*/ |
1065 | 1171 |
function ctools_field_delete_field($field) { |
1066 | 1172 |
ctools_flush_field_caches(); |
1067 | 1173 |
} |
1174 |
|
|
1068 | 1175 |
/** |
1069 | 1176 |
* Implements hook_field_delete_instance(). |
1070 | 1177 |
*/ |
1071 | 1178 |
function ctools_field_delete_instance($instance) { |
1072 | 1179 |
ctools_flush_field_caches(); |
1073 | 1180 |
} |
1181 |
|
|
1074 | 1182 |
/** |
1075 | 1183 |
* Implements hook_field_update_field(). |
1076 | 1184 |
*/ |
Formats disponibles : Unified diff
Weekly update of contrib modules