source: sipes/modules_contrib/views_bulk_operations/actions_permissions.module @ 1e95969

stableversion-3.0
Last change on this file since 1e95969 was 177a560, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio de modulos contribuidos de drupal

  • Propiedad mode establecida a 100755
File size: 2.7 KB
Línea 
1<?php
2
3/**
4 * Implementation of hook_perm().
5 */
6function actions_permissions_perm() {
7  $perms = array();
8  $actions = actions_list() + _actions_permissions_get_custom_actions();
9  foreach ($actions as $callback => $action) {
10    $perms[] = actions_permissions_get_perm($action['description'], empty($action['callback']) ? $callback : $action['callback']);
11  }
12  module_load_include('inc', 'node', 'node.admin');
13  foreach (array('node', 'user') as $type) {
14    foreach (module_invoke_all($type .'_operations') as $operation) {
15      if (is_array($operation['label']) || empty($operation['callback'])) continue;
16      $perms[] = actions_permissions_get_perm($operation['label'], $operation['callback']);
17    }
18  }
19  return $perms;
20}
21
22function _actions_permissions_get_custom_actions() {
23  $actions = array();
24  $static_actions = actions_list();
25  $result = db_query("SELECT * FROM {actions} WHERE parameters > ''");
26  while ($action = db_fetch_object($result)) {
27    $actions[$action->aid] = array(
28      'description' => $action->description,
29      'type' => $action->type,
30      'configurable' => FALSE,
31      'parameters' => unserialize($action->parameters),
32    );
33    $actions[$action->aid]['behavior'] = isset($static_actions[$action->callback]['behavior']) ? $static_actions[$action->callback]['behavior'] : null;
34  }
35  return $actions;
36}
37
38function actions_permissions_get_perm($label, $callback) {
39  return 'execute '. rt($label) .' ('. $callback .')';
40}
41
42/**
43 * Reverse translation: find English string given translated string.
44 * WARNING: Will not work for strings with params.
45 */
46function rt($string) {
47  global $language;
48  $langcode = $language->language;
49
50  // 1. Lookup custom strings.
51  static $custom_strings;
52  if (!isset($custom_strings[$langcode])) {
53    $custom_strings[$langcode] = variable_get('locale_custom_strings_'. $langcode, array());
54  }
55  if ($source = array_search($string, $custom_strings[$langcode])) {
56    return $source;
57  }
58
59  // 2. Lookup locale translations.
60  if (!function_exists('locale') || $langcode == 'en') return $string;
61  if (variable_get('locale_cache_strings', 1) == 1) {
62    // Cache is on: this string is in the static cache for sure since we have its translated version.
63    $locale_t = locale();
64    if (isset($locale_t[$langcode]) && ($source = array_search($string, $locale_t[$langcode], TRUE))) {
65      return $source;
66    }
67    else {
68      return $string;
69    }
70  }
71  else {
72    // Cache is off: look it up in the database.
73    $source = db_result(db_query("SELECT s.source FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = '%s' WHERE t.translation = '%s' AND s.textgroup = 'default'", $langcode, $string));
74    return $source ? $source : $string;
75  }
76}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.