1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756 |
- <?php
- if (!drupal_autoload_class('RulesEventHandlerEntityBundle')) {
- require_once dirname(__FILE__) . '/includes/rules.event.inc';
- }
- require_once dirname(__FILE__) . '/modules/events.inc';
- function rules_module_implements_alter(&$implementations, $hook) {
-
-
-
- if ($hook == 'menu_get_item_alter' && array_key_exists('rules', $implementations)) {
- $group = $implementations['rules'];
- unset($implementations['rules']);
- $implementations = array_merge(array('rules' => $group), $implementations);
- }
- }
- function rules_menu_get_item_alter() {
-
-
-
-
-
-
-
-
- if (!drupal_static('rules_init', FALSE)) {
- rules_event_invocation_enabled(TRUE);
- }
- }
- function rules_init() {
-
- $rules_init = &drupal_static(__FUNCTION__, FALSE);
- $rules_init = TRUE;
-
- rules_event_invocation_enabled(TRUE);
- rules_invoke_event('init');
- }
- function rules_ui() {
- $static = drupal_static(__FUNCTION__);
- if (!isset($static)) {
- $static = new RulesUIController();
- }
- return $static;
- }
- function rules_action($name, $settings = array()) {
- return rules_plugin_factory('action', $name, $settings);
- }
- function rules_condition($name, $settings = array()) {
- return rules_plugin_factory('condition', $name, $settings);
- }
- function rule($variables = NULL, $provides = array()) {
- return rules_plugin_factory('rule', $variables, $provides);
- }
- function rules_reaction_rule() {
- return rules_plugin_factory('reaction rule');
- }
- function rules_or($variables = NULL) {
- return rules_plugin_factory('or', $variables);
- }
- function rules_and($variables = NULL) {
- return rules_plugin_factory('and', $variables);
- }
- function rules_loop($settings = array(), $variables = NULL) {
- return rules_plugin_factory('loop', $settings, $variables);
- }
- function rules_rule_set($variables = array(), $provides = array()) {
- return rules_plugin_factory('rule set', $variables, $provides);
- }
- function rules_action_set($variables = array(), $provides = array()) {
- return rules_plugin_factory('action set', $variables, $provides);
- }
- function rules_log($msg, $args = array(), $priority = RulesLog::INFO, RulesPlugin $element = NULL, $scope = NULL) {
- static $logger, $settings;
-
- if (!isset($settings)) {
- $settings['rules_log_errors'] = variable_get('rules_log_errors', RulesLog::WARN);
- $settings['rules_debug_log'] = variable_get('rules_debug_log', FALSE);
- $settings['rules_debug'] = variable_get('rules_debug', FALSE);
- }
- if ($priority >= $settings['rules_log_errors']) {
- $link = NULL;
- if (isset($element) && isset($element->root()->name)) {
- $link = l(t('edit configuration'), RulesPluginUI::path($element->root()->name, 'edit', $element));
- }
-
-
- rules_event_invocation_enabled(FALSE);
- watchdog('rules', $msg, $args, $priority == RulesLog::WARN ? WATCHDOG_WARNING : WATCHDOG_ERROR, $link);
- rules_event_invocation_enabled(TRUE);
- }
-
- if (!$settings['rules_debug_log'] && !$settings['rules_debug']) {
- return;
- }
- if (!isset($logger)) {
- $logger = RulesLog::logger();
- }
- $path = isset($element) && isset($element->root()->name) ? RulesPluginUI::path($element->root()->name, 'edit', $element) : NULL;
- $logger->log($msg, $args, $priority, $scope, $path);
- }
- function rules_fetch_data($hook) {
- $data = &drupal_static(__FUNCTION__, array());
- static $discover = array(
- 'action_info' => 'RulesActionHandlerInterface',
- 'condition_info' => 'RulesConditionHandlerInterface',
- 'event_info' => 'RulesEventHandlerInterface',
- );
- if (!isset($data[$hook])) {
- $data[$hook] = array();
- foreach (module_implements('rules_' . $hook) as $module) {
- $result = call_user_func($module . '_rules_' . $hook);
- if (isset($result) && is_array($result)) {
- foreach ($result as $name => $item) {
- $item += array('module' => $module);
- $data[$hook][$name] = $item;
- }
- }
- }
-
- if (isset($discover[$hook])) {
- $data[$hook] += rules_discover_plugins($discover[$hook]);
- }
- drupal_alter('rules_' . $hook, $data[$hook]);
- }
- return $data[$hook];
- }
- function rules_discover_plugins($class) {
-
- RulesAbstractPlugin::includeFiles();
- $items = array();
- foreach (get_declared_classes() as $plugin_class) {
- if (is_subclass_of($plugin_class, $class) && method_exists($plugin_class, 'getInfo')) {
- $info = call_user_func(array($plugin_class, 'getInfo'));
- $info['class'] = $plugin_class;
- $info['module'] = _rules_discover_module($plugin_class);
- $items[$info['name']] = $info;
- }
- }
- return $items;
- }
- function _rules_discover_module($class) {
- $paths = &drupal_static(__FUNCTION__);
- if (!isset($paths)) {
-
- foreach (system_list('module_enabled') as $name => $module_info) {
- $paths[dirname($module_info->filename)] = $name;
- }
- }
-
-
- $reflection = new ReflectionClass($class);
- $path = str_replace(realpath(DRUPAL_ROOT) . DIRECTORY_SEPARATOR, '', realpath(dirname($reflection->getFileName())));
- $path = DIRECTORY_SEPARATOR != '/' ? str_replace(DIRECTORY_SEPARATOR, '/', $path) : $path;
-
- $parts = explode('/', $path);
- while (!isset($paths[$path]) && array_pop($parts)) {
- $path = dirname($path);
- }
- return isset($paths[$path]) ? $paths[$path] : FALSE;
- }
- function &rules_get_cache($cid = 'data') {
-
- static $drupal_static_fast;
- if (!isset($drupal_static_fast)) {
- $drupal_static_fast['cache'] = &drupal_static(__FUNCTION__, array());
- }
- $cache = &$drupal_static_fast['cache'];
- if (!isset($cache[$cid])) {
-
-
- $cid_suffix = $cid == 'data' ? ':' . $GLOBALS['language']->language : '';
- if ($get = cache_get($cid . $cid_suffix, 'cache_rules')) {
- $cache[$cid] = $get->data;
- }
- else {
-
-
- while (!lock_acquire(__FUNCTION__ . $cid . $cid_suffix, 60)) {
-
- lock_wait(__FUNCTION__ . $cid . $cid_suffix, 30);
-
-
- if ($get = cache_get($cid . $cid_suffix, 'cache_rules')) {
- $cache[$cid] = $get->data;
- return $cache[$cid];
- }
- }
- if ($cid === 'data') {
-
-
-
-
- _rules_rebuild_cache($cache['data']);
- }
- elseif (strpos($cid, 'comp_') === 0) {
- $cache[$cid] = FALSE;
- _rules_rebuild_component_cache();
- }
- elseif (strpos($cid, 'event_') === 0 || $cid == 'rules_event_whitelist') {
- $cache[$cid] = FALSE;
- RulesEventSet::rebuildEventCache();
- }
- else {
- $cache[$cid] = FALSE;
- }
-
- lock_release(__FUNCTION__ . $cid . $cid_suffix);
- }
- }
- return $cache[$cid];
- }
- function _rules_rebuild_cache(&$cache) {
- foreach (array('data_info', 'plugin_info') as $hook) {
- $cache[$hook] = rules_fetch_data($hook);
- }
- foreach ($cache['plugin_info'] as $name => &$info) {
-
- $item = new $info['class']();
- $item->rebuildCache($info, $cache);
- }
- $cid_suffix = ':' . $GLOBALS['language']->language;
- cache_set('data' . $cid_suffix, $cache, 'cache_rules');
- }
- function _rules_rebuild_component_cache() {
- $components = rules_get_components();
- foreach ($components as $id => $component) {
-
- if ($component->dirty) {
- rules_config_update_dirty_flag($component);
- }
- if (!$component->dirty) {
-
-
- $component = clone $component;
- $component->optimize();
-
- drupal_alter('rules_component', $component->plugin, $component);
- rules_set_cache('comp_' . $component->name, $component);
- }
- }
- }
- function rules_set_cache($cid, $data) {
- $cache = &drupal_static('rules_get_cache', array());
- $cache[$cid] = $data;
- cache_set($cid, $data, 'cache_rules');
- }
- function rules_flush_caches() {
- return array('cache_rules');
- }
- function rules_clear_cache() {
- cache_clear_all('*', 'cache_rules', TRUE);
- drupal_static_reset('rules_get_cache');
- drupal_static_reset('rules_fetch_data');
- drupal_static_reset('rules_config_update_dirty_flag');
- entity_get_controller('rules_config')->resetCache();
- }
- function rules_import($export, &$error_msg = '') {
- return entity_get_controller('rules_config')->import($export, $error_msg);
- }
- function &rules_wrap_data($data = NULL, $info, $force = FALSE) {
-
- if ($data instanceof EntityMetadataWrapper) {
- return $data;
- }
- $cache = rules_get_cache();
-
- $wrapper_keys = array_flip(array('property info', 'property defaults'));
- if (isset($cache['data_info'][$info['type']])) {
- $info += array_intersect_key($cache['data_info'][$info['type']], $wrapper_keys);
- }
-
- $list_item_type = entity_property_list_extract_type($info['type']);
- if ($list_item_type && isset($cache['data_info'][$list_item_type])) {
- $info += array_intersect_key($cache['data_info'][$list_item_type], $wrapper_keys);
- }
-
- if (!empty($cache['data_info'][$info['type']]['wrap']) || $list_item_type || $force || empty($cache['data_info'][$info['type']])) {
- unset($info['handler']);
-
- if (!empty($cache['data_info'][$info['type']]['wrapper class'])) {
- $class = $cache['data_info'][$info['type']]['wrapper class'];
- $wrapper = new $class($info['type'], $data, $info);
- }
- else {
- $wrapper = entity_metadata_wrapper($info['type'], $data, $info);
- }
- return $wrapper;
- }
- return $data;
- }
- function rules_unwrap_data(array $data, $info = array()) {
- $cache = rules_get_cache();
- foreach ($data as $key => $entry) {
-
- if ($entry instanceof EntityMetadataWrapper) {
- if (!isset($info[$key]['allow null'])) {
- $info[$key]['allow null'] = FALSE;
- }
- if (!isset($info[$key]['wrapped'])) {
-
- $info[$key]['wrapped'] = (isset($info[$key]['type']) && is_string($info[$key]['type']) && !empty($cache['data_info'][$info[$key]['type']]['is wrapped']));
- }
-
-
-
- $options = $info[$key] + array('decode' => empty($info[$key]['sanitize']));
- try {
- if (!($info[$key]['allow null'] && $info[$key]['wrapped'])) {
- $value = $entry->value($options);
- if (!$info[$key]['wrapped']) {
- $data[$key] = $value;
- }
- if (!$info[$key]['allow null'] && !isset($value)) {
- throw new RulesEvaluationException('The variable or parameter %name is empty.', array('%name' => $key));
- }
- }
- }
- catch (EntityMetadataWrapperException $e) {
- throw new RulesEvaluationException('Unable to get the data value for the variable or parameter %name. Error: !error', array('%name' => $key, '!error' => $e->getMessage()));
- }
- }
- }
- return $data;
- }
- function rules_get_event_info($event_name) {
- $base_event_name = rules_get_event_base_name($event_name);
- $events = rules_fetch_data('event_info');
- if (isset($events[$base_event_name])) {
- return $events[$base_event_name] + array('name' => $base_event_name);
- }
- return array(
- 'label' => t('Unknown event "!event_name"', array('!event_name' => $base_event_name)),
- 'name' => $base_event_name,
- );
- }
- function rules_get_event_base_name($event_name) {
-
- if (strpos($event_name, '--') !== FALSE) {
- $parts = explode('--', $event_name, 2);
- return $parts[0];
- }
- return $event_name;
- }
- function rules_get_event_handler($event_name, array $settings = NULL) {
- $event_name = rules_get_event_base_name($event_name);
- $event_info = rules_get_event_info($event_name);
- $class = !empty($event_info['class']) ? $event_info['class'] : 'RulesEventDefaultHandler';
- $handler = new $class($event_name, $event_info);
- return isset($settings) ? $handler->setSettings($settings) : $handler;
- }
- function rules_plugin_factory($plugin_name, $arg1 = NULL, $arg2 = NULL) {
- $cache = rules_get_cache();
- if (isset($cache['plugin_info'][$plugin_name]['class'])) {
- return new $cache['plugin_info'][$plugin_name]['class']($arg1, $arg2);
- }
- }
- function rules_rules_plugin_info() {
- return array(
- 'condition' => array(
- 'class' => 'RulesCondition',
- 'embeddable' => 'RulesConditionContainer',
- 'extenders' => array(
- 'RulesPluginImplInterface' => array(
- 'class' => 'RulesAbstractPluginDefaults',
- ),
- 'RulesPluginFeaturesIntegrationInterface' => array(
- 'methods' => array(
- 'features_export' => 'rules_features_abstract_default_features_export',
- ),
- ),
- 'RulesPluginUIInterface' => array(
- 'class' => 'RulesAbstractPluginUI',
- ),
- ),
- ),
- 'action' => array(
- 'class' => 'RulesAction',
- 'embeddable' => 'RulesActionContainer',
- 'extenders' => array(
- 'RulesPluginImplInterface' => array(
- 'class' => 'RulesAbstractPluginDefaults',
- ),
- 'RulesPluginFeaturesIntegrationInterface' => array(
- 'methods' => array(
- 'features_export' => 'rules_features_abstract_default_features_export',
- ),
- ),
- 'RulesPluginUIInterface' => array(
- 'class' => 'RulesAbstractPluginUI',
- ),
- ),
- ),
- 'or' => array(
- 'label' => t('Condition set (OR)'),
- 'class' => 'RulesOr',
- 'embeddable' => 'RulesConditionContainer',
- 'component' => TRUE,
- 'extenders' => array(
- 'RulesPluginUIInterface' => array(
- 'class' => 'RulesConditionContainerUI',
- ),
- ),
- ),
- 'and' => array(
- 'label' => t('Condition set (AND)'),
- 'class' => 'RulesAnd',
- 'embeddable' => 'RulesConditionContainer',
- 'component' => TRUE,
- 'extenders' => array(
- 'RulesPluginUIInterface' => array(
- 'class' => 'RulesConditionContainerUI',
- ),
- ),
- ),
- 'action set' => array(
- 'label' => t('Action set'),
- 'class' => 'RulesActionSet',
- 'embeddable' => FALSE,
- 'component' => TRUE,
- 'extenders' => array(
- 'RulesPluginUIInterface' => array(
- 'class' => 'RulesActionContainerUI',
- ),
- ),
- ),
- 'rule' => array(
- 'label' => t('Rule'),
- 'class' => 'Rule',
- 'embeddable' => 'RulesRuleSet',
- 'component' => TRUE,
- 'extenders' => array(
- 'RulesPluginUIInterface' => array(
- 'class' => 'RulesRuleUI',
- ),
- ),
- ),
- 'loop' => array(
- 'class' => 'RulesLoop',
- 'embeddable' => 'RulesActionContainer',
- 'extenders' => array(
- 'RulesPluginUIInterface' => array(
- 'class' => 'RulesLoopUI',
- ),
- ),
- ),
- 'reaction rule' => array(
- 'class' => 'RulesReactionRule',
- 'embeddable' => FALSE,
- 'extenders' => array(
- 'RulesPluginUIInterface' => array(
- 'class' => 'RulesReactionRuleUI',
- ),
- ),
- ),
- 'event set' => array(
- 'class' => 'RulesEventSet',
- 'embeddable' => FALSE,
- ),
- 'rule set' => array(
- 'label' => t('Rule set'),
- 'class' => 'RulesRuleSet',
- 'component' => TRUE,
-
- 'embeddable' => FALSE,
- 'extenders' => array(
- 'RulesPluginUIInterface' => array(
- 'class' => 'RulesRuleSetUI',
- ),
- ),
- ),
- );
- }
- function rules_entity_info() {
- return array(
- 'rules_config' => array(
- 'label' => t('Rules configuration'),
- 'controller class' => 'RulesEntityController',
- 'base table' => 'rules_config',
- 'fieldable' => TRUE,
- 'entity keys' => array(
- 'id' => 'id',
- 'name' => 'name',
- 'label' => 'label',
- ),
- 'module' => 'rules',
- 'static cache' => TRUE,
- 'bundles' => array(),
- 'configuration' => TRUE,
- 'exportable' => TRUE,
- 'export' => array(
- 'default hook' => 'default_rules_configuration',
- ),
- 'access callback' => 'rules_config_access',
- 'features controller class' => 'RulesFeaturesController',
- ),
- );
- }
- function rules_hook_info() {
- foreach (array('plugin_info', 'rules_directory', 'data_info', 'condition_info', 'action_info', 'event_info', 'file_info', 'evaluator_info', 'data_processor_info') as $hook) {
- $hooks['rules_' . $hook] = array(
- 'group' => 'rules',
- );
- $hooks['rules_' . $hook . '_alter'] = array(
- 'group' => 'rules',
- );
- }
- $hooks['default_rules_configuration'] = array(
- 'group' => 'rules_defaults',
- );
- $hooks['default_rules_configuration_alter'] = array(
- 'group' => 'rules_defaults',
- );
- return $hooks;
- }
- function rules_config_load_multiple($names = array(), $conditions = array()) {
- return entity_load_multiple_by_name('rules_config', $names, $conditions);
- }
- function rules_config_load($name) {
- return entity_load_single('rules_config', $name);
- }
- function rules_get_components($label = FALSE, $type = NULL, $conditions = array()) {
- $cache = rules_get_cache();
- $plugins = array_keys(rules_filter_array($cache['plugin_info'], 'component', TRUE));
- $conditions = $conditions + array('plugin' => $plugins);
- $faces = array(
- 'action' => 'RulesActionInterface',
- 'condition' => 'RulesConditionInterface',
- );
- $items = array();
- foreach (rules_config_load_multiple(FALSE, $conditions) as $name => $config) {
- if (!isset($type) || $config instanceof $faces[$type]) {
- $items[$name] = $label ? $config->label() : $config;
- }
- }
- return $items;
- }
- function rules_config_delete(array $ids) {
- return entity_get_controller('rules_config')->delete($ids);
- }
- function rules_config_update_dirty_flag($rules_config, $update = TRUE) {
-
-
-
- $checked = &drupal_static(__FUNCTION__, array());
- if (!empty($checked[$rules_config->name])) {
- return;
- }
- $checked[$rules_config->name] = TRUE;
- $was_dirty = !empty($rules_config->dirty);
- try {
-
-
- $rules_config->dirty = FALSE;
- $rules_config->integrityCheck();
- if ($was_dirty) {
- $variables = array('%label' => $rules_config->label(), '%name' => $rules_config->name, '@plugin' => $rules_config->plugin());
- watchdog('rules', 'The @plugin %label (%name) was marked dirty, but passes the integrity check now and is active again.', $variables, WATCHDOG_INFO);
- }
- }
- catch (RulesIntegrityException $e) {
- $rules_config->dirty = TRUE;
- if (!$was_dirty) {
- $variables = array('%label' => $rules_config->label(), '%name' => $rules_config->name, '!message' => $e->getMessage(), '@plugin' => $rules_config->plugin());
- watchdog('rules', 'The @plugin %label (%name) fails the integrity check and cannot be executed. Error: !message', $variables, WATCHDOG_ERROR);
- }
- }
-
- if ($was_dirty != $rules_config->dirty) {
- db_update('rules_config')
- ->fields(array('dirty' => (int) $rules_config->dirty))
- ->condition('id', $rules_config->id)
- ->execute();
- }
- }
- function rules_invoke_all() {
-
- $args = func_get_args();
- $hook = $args[0];
- unset($args[0]);
- $return = array();
- foreach (module_implements($hook) as $module) {
- $function = $module . '_' . $hook;
- if (function_exists($function)) {
- $result = call_user_func_array($function, $args);
- if (isset($result) && is_array($result)) {
- $return = array_merge_recursive($return, $result);
- }
- elseif (isset($result)) {
- $return[] = $result;
- }
- }
- }
-
- rules_invoke_event_by_args($hook, $args);
- return $return;
- }
- function rules_invoke_event() {
- $args = func_get_args();
- $event_name = $args[0];
- unset($args[0]);
-
-
- if (rules_event_invocation_enabled()) {
- $whitelist = rules_get_cache('rules_event_whitelist');
- if ((($whitelist === FALSE) || isset($whitelist[$event_name])) && $event = rules_get_cache('event_' . $event_name)) {
- $event->executeByArgs($args);
- }
- }
- }
- function rules_invoke_event_by_args($event_name, $args = array()) {
-
-
- if (rules_event_invocation_enabled()) {
- $whitelist = rules_get_cache('rules_event_whitelist');
- if ((empty($whitelist) || isset($whitelist[$event_name])) && $event = rules_get_cache('event_' . $event_name)) {
- $event->executeByArgs($args);
- }
- }
- }
- function rules_invoke_component() {
- $args = func_get_args();
- $name = array_shift($args);
- if ($component = rules_get_cache('comp_' . $name)) {
- return $component->executeByArgs($args);
- }
- return FALSE;
- }
- function rules_filter_array($array, $key, $value) {
- $return = array();
- foreach ($array as $i => $entry) {
- $entry += array($key => NULL);
- if ($entry[$key] == $value) {
- $return[$i] = $entry;
- }
- }
- return $return;
- }
- function rules_update_array(array $array, array $update) {
- foreach ($update as $key => $data) {
- if (isset($array[$key]) && is_array($array[$key]) && is_array($data)) {
- $array[$key] = rules_update_array($array[$key], $data);
- }
- else {
- $array[$key] = $data;
- }
- }
- return $array;
- }
- function rules_extract_property($arrays, $key) {
- $data = array();
- foreach ($arrays as $name => $item) {
- $data[$name] = $item[$key];
- }
- return $data;
- }
- function rules_array_key($array) {
- reset($array);
- return key($array);
- }
- function rules_path_clean_replacement_values(&$replacements, $data = array(), $options = array()) {
-
- module_load_include('inc', 'rules', 'modules/path.eval');
- foreach ($replacements as $token => $value) {
- $replacements[$token] = rules_clean_path($value);
- }
- }
- function rules_theme() {
- return array(
- 'rules_elements' => array(
- 'render element' => 'element',
- 'file' => 'ui/ui.theme.inc',
- ),
- 'rules_content_group' => array(
- 'render element' => 'element',
- 'file' => 'ui/ui.theme.inc',
- ),
- 'rules_parameter_configuration' => array(
- 'render element' => 'element',
- 'file' => 'ui/ui.theme.inc',
- ),
- 'rules_variable_view' => array(
- 'render element' => 'element',
- 'file' => 'ui/ui.theme.inc',
- ),
- 'rules_data_selector_help' => array(
- 'variables' => array('parameter' => NULL, 'variables' => NULL),
- 'file' => 'ui/ui.theme.inc',
- ),
- 'rules_ui_variable_form' => array(
- 'render element' => 'element',
- 'file' => 'ui/ui.theme.inc',
- ),
- 'rules_log' => array(
- 'render element' => 'element',
- 'file' => 'ui/ui.theme.inc',
- ),
- 'rules_autocomplete' => array(
- 'render element' => 'element',
- 'file' => 'ui/ui.theme.inc',
- ),
- 'rules_debug_element' => array(
- 'render element' => 'element',
- 'file' => 'ui/ui.theme.inc',
- ),
- 'rules_settings_help' => array(
- 'variables' => array('text' => '', 'heading' => ''),
- 'file' => 'ui/ui.theme.inc',
- ),
- );
- }
- function rules_permission() {
- $perms = array(
- 'administer rules' => array(
- 'title' => t('Administer rule configurations'),
- 'description' => t('Administer rule configurations including events, conditions and actions for which the user has sufficient access permissions.'),
- ),
- 'bypass rules access' => array(
- 'title' => t('Bypass Rules access control'),
- 'description' => t('Control all configurations regardless of permission restrictions of events, conditions or actions.'),
- 'restrict access' => TRUE,
- ),
- 'access rules debug' => array(
- 'title' => t('Access the Rules debug log'),
- ),
- );
-
- $conditions['plugin'] = array_keys(rules_filter_array(rules_fetch_data('plugin_info'), 'component', TRUE));
- $conditions['access_exposed'] = 1;
- $components = entity_load('rules_config', FALSE, $conditions);
- $perms += rules_permissions_by_component($components);
- return $perms;
- }
- function rules_permissions_by_component(array $components = array()) {
- $perms = array();
- foreach ($components as $component) {
- $perms += array(
- "use Rules component $component->name" => array(
- 'title' => t('Use Rules component %component', array('%component' => $component->label())),
- 'description' => t('Controls access for using the component %component via the provided action or condition. <a href="@component-edit-url">Edit this component.</a>', array('%component' => $component->label(), '@component-edit-url' => url(RulesPluginUI::path($component->name)))),
- ),
- );
- }
- return $perms;
- }
- function rules_element_load($element_id, $config_name) {
- $config = rules_config_load($config_name);
- return $config->elementMap()->lookup($element_id);
- }
- function rules_get_title($text, $element) {
- if ($element instanceof RulesPlugin) {
- $cache = rules_get_cache();
- $plugin = $element->plugin();
- $plugin = isset($cache['plugin_info'][$plugin]['label']) ? $cache['plugin_info'][$plugin]['label'] : $plugin;
- $plugin = drupal_strtolower(drupal_substr($plugin, 0, 1)) . drupal_substr($plugin, 1);
- return t($text, array('!label' => $element->label(), '!plugin' => $plugin));
- }
-
- return t($text, array('!plugin' => $element));
- }
- function rules_menu_add_element_title($array) {
- $plugin_name = arg($array[0]);
- $cache = rules_get_cache();
- if (isset($cache['plugin_info'][$plugin_name]['class'])) {
- $info = $cache['plugin_info'][$plugin_name] + array('label' => $plugin_name);
- $label = drupal_strtolower(drupal_substr($info['label'], 0, 1)) . drupal_substr($info['label'], 1);
- return t('Add a new !plugin', array('!plugin' => $label));
- }
- }
- function rules_debug_log_region() {
-
- global $theme_key;
- $theme_default = variable_get('theme_default', 'bartik');
- return variable_get('rules_debug_region_' . $theme_key, variable_get('rules_debug_region_' . $theme_default, 'help'));
- }
- function rules_page_build(&$page) {
-
-
- if (isset($GLOBALS['_rules_action_drupal_goto_do'])) {
- list($url, $force) = $GLOBALS['_rules_action_drupal_goto_do'];
- drupal_goto($url);
- }
- if (isset($_SESSION['rules_debug'])) {
- $region = rules_debug_log_region();
- foreach ($_SESSION['rules_debug'] as $log) {
- $page[$region]['rules_debug'][] = array(
- '#markup' => $log,
- );
- $page[$region]['rules_debug']['#theme_wrappers'] = array('rules_log');
- }
- unset($_SESSION['rules_debug']);
- }
- if (rules_show_debug_output()) {
- $region = rules_debug_log_region();
- $page[$region]['rules_debug']['#pre_render'] = array('rules_debug_log_pre_render');
- }
- }
- function rules_debug_log_pre_render($elements) {
- $logger = RulesLog::logger();
- if ($log = $logger->render()) {
- $logger = RulesLog::logger();
- $logger->clear();
- $elements[] = array('#markup' => $log);
- $elements['#theme_wrappers'] = array('rules_log');
-
- if (variable_get('rules_debug_log', FALSE)) {
- watchdog('rules', 'Rules debug information: !log', array('!log' => $log), WATCHDOG_NOTICE);
- }
- }
- return $elements;
- }
- function rules_drupal_goto_alter(&$path, &$options, &$http_response_code) {
-
- if (isset($GLOBALS['_rules_action_drupal_goto_do'])) {
- list($url, $force) = $GLOBALS['_rules_action_drupal_goto_do'];
- if ($force || !isset($_GET['destination'])) {
- $url = drupal_parse_url($url);
- $path = $url['path'];
- $options['query'] = $url['query'];
- $options['fragment'] = $url['fragment'];
- $http_response_code = 302;
- }
- }
- }
- function rules_show_debug_output() {
-
- if (!class_exists('RulesLog', FALSE)) {
- return FALSE;
- }
- if (variable_get('rules_debug', 0) == RulesLog::INFO && user_access('access rules debug')) {
- return TRUE;
- }
- return variable_get('rules_debug', 0) == RulesLog::WARN && user_access('access rules debug') && RulesLog::logger()->hasErrors();
- }
- function rules_exit() {
-
- if (!module_exists('rules') || !module_exists('user')) {
- return;
- }
- if (rules_show_debug_output()) {
- if ($log = RulesLog::logger()->render()) {
-
- $_SESSION['rules_debug'][] = $log;
- }
- }
-
- if (variable_get('rules_debug_log', FALSE) && $log = RulesLog::logger()->render()) {
- watchdog('rules', 'Rules debug information: !log', array('!log' => $log), WATCHDOG_NOTICE);
- }
- }
- function rules_element_info() {
-
- $types['rules_duration'] = array(
- '#input' => TRUE,
- '#tree' => TRUE,
- '#default_value' => 0,
- '#value_callback' => 'rules_ui_element_duration_value',
- '#process' => array('rules_ui_element_duration_process', 'ajax_process_form'),
- '#after_build' => array('rules_ui_element_duration_after_build'),
- '#pre_render' => array('form_pre_render_conditional_form_element'),
- );
- $types['rules_data_selection'] = array(
- '#input' => TRUE,
- '#pre_render' => array('form_pre_render_conditional_form_element'),
- '#process' => array('rules_data_selection_process', 'ajax_process_form'),
- '#theme' => 'rules_autocomplete',
- );
- return $types;
- }
- function rules_modules_enabled($modules) {
-
-
- $query = db_select('rules_dependencies', 'rd');
- $query->join('rules_config', 'rc', 'rd.id = rc.id');
- $query->fields('rd', array('id'))
- ->condition('rd.module', $modules, 'IN')
- ->condition('rc.dirty', 1);
- $ids = $query->execute()->fetchCol();
-
-
-
- if ($ids) {
- $rules_configs = rules_config_load_multiple(FALSE, array('dirty' => 1));
- foreach ($rules_configs as $rules_config) {
- try {
- $rules_config->integrityCheck();
-
- db_update('rules_config')
- ->fields(array('dirty' => 0))
- ->condition('id', $rules_config->id)
- ->execute();
- if ($rules_config->active) {
- drupal_set_message(t('All dependencies for the Rules configuration %config are met again, so it has been re-activated.', array('%config' => $rules_config->label())));
- }
- }
- catch (RulesIntegrityException $e) {
-
- }
- }
- }
- rules_clear_cache();
- }
- function rules_modules_disabled($modules) {
-
- $query = db_select('rules_dependencies', 'rd');
- $query->join('rules_config', 'rc', 'rd.id = rc.id');
- $query->fields('rd', array('id'))
- ->distinct()
- ->condition('rd.module', $modules, 'IN')
- ->condition('rc.dirty', 0);
- $ids = $query->execute()->fetchCol();
- if (!empty($ids)) {
- db_update('rules_config')
- ->fields(array('dirty' => 1))
- ->condition('id', $ids, 'IN')
- ->execute();
-
- $count = db_select('rules_config', 'r')
- ->fields('r')
- ->condition('id', $ids, 'IN')
- ->condition('active', 1)
- ->countQuery()
- ->execute()
- ->fetchField();
- if ($count > 0) {
- $message = format_plural($count,
- '1 Rules configuration requires some of the disabled modules to function and cannot be executed any more.',
- '@count Rules configurations require some of the disabled modules to function and cannot be executed any more.'
- );
- drupal_set_message($message, 'warning');
- }
- }
- rules_clear_cache();
- }
- function rules_config_access($op, $rules_config = NULL, $account = NULL) {
- if (user_access('bypass rules access', $account)) {
- return TRUE;
- }
-
- $access = module_invoke_all('rules_config_access', $op, $rules_config, $account);
-
-
- if (in_array(FALSE, $access, TRUE)) {
- return FALSE;
- }
- elseif (in_array(TRUE, $access, TRUE)) {
- return TRUE;
- }
- return FALSE;
- }
- function rules_rules_config_access($op, $rules_config = NULL, $account = NULL) {
-
-
- if (!isset($rules_config) || (isset($account) && $account->uid != $GLOBALS['user']->uid)) {
- return;
- }
- if (user_access('administer rules', $account) && ($op == 'view' || $rules_config->access())) {
- return TRUE;
- }
- }
- function rules_menu() {
- $items['admin/config/workflow/rules/upgrade'] = array(
- 'title' => 'Upgrade',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('rules_upgrade_form'),
- 'access arguments' => array('administer rules'),
- 'file' => 'includes/rules.upgrade.inc',
- 'file path' => drupal_get_path('module', 'rules'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/config/workflow/rules/upgrade/clear'] = array(
- 'title' => 'Clear',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('rules_upgrade_confirm_clear_form'),
- 'access arguments' => array('administer rules'),
- 'file' => 'includes/rules.upgrade.inc',
- 'file path' => drupal_get_path('module', 'rules'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/config/workflow/rules/autocomplete_tags'] = array(
- 'title' => 'Rules tags autocomplete',
- 'page callback' => 'rules_autocomplete_tags',
- 'page arguments' => array(5),
- 'access arguments' => array('administer rules'),
- 'file' => 'ui/ui.forms.inc',
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- function rules_external_help($topic = NULL) {
- $help = array(
- 'rules' => 'https://www.drupal.org/node/298480',
- 'terminology' => 'https://www.drupal.org/node/1299990',
- 'condition-components' => 'https://www.drupal.org/node/1300034',
- 'data-selection' => 'https://www.drupal.org/node/1300042',
- 'chained-tokens' => 'https://www.drupal.org/node/1300042',
- 'loops' => 'https://www.drupal.org/node/1300058',
- 'components' => 'https://www.drupal.org/node/1300024',
- 'component-types' => 'https://www.drupal.org/node/1300024',
- 'variables' => 'https://www.drupal.org/node/1300024',
- 'scheduler' => 'https://www.drupal.org/node/1300068',
- 'coding' => 'https://www.drupal.org/node/878720',
- );
- if (isset($topic)) {
- return isset($help[$topic]) ? $help[$topic] : FALSE;
- }
- return $help;
- }
- function rules_help($path, $arg) {
-
- if ($path == 'admin/help#rules' && module_exists('rules_admin')) {
- $output['header'] = array(
- '#markup' => t('Rules documentation is kept online. Please use the links below for more information about Rules. Feel free to contribute to improving the online documentation!'),
- );
-
- $link_list['rules'] = l(t('Rules introduction'), rules_external_help('rules'));
- $link_list['terminology'] = l(t('Rules terminology'), rules_external_help('terminology'));
- $link_list['scheduler'] = l(t('Rules Scheduler'), rules_external_help('scheduler'));
- $link_list['coding'] = l(t('Coding for Rules'), rules_external_help('coding'));
- $output['topic-list'] = array(
- '#markup' => theme('item_list', array('items' => $link_list)),
- );
- return render($output);
- }
- }
- function rules_token_info() {
- $cache = rules_get_cache();
- $data_info = $cache['data_info'];
- $types = array('text', 'integer', 'uri', 'token', 'decimal', 'date', 'duration');
- foreach ($types as $type) {
- $token_type = $data_info[$type]['token type'];
- $token_info['types'][$token_type] = array(
- 'name' => $data_info[$type]['label'],
- 'description' => t('Tokens related to %label Rules variables.', array('%label' => $data_info[$type]['label'])),
- 'needs-data' => $token_type,
- );
- $token_info['tokens'][$token_type]['value'] = array(
- 'name' => t("Value"),
- 'description' => t('The value of the variable.'),
- );
- }
- return $token_info;
- }
- function rules_tokens($type, $tokens, $data, $options = array()) {
-
- if (substr($type, 0, 6) == 'rules_' && !empty($data[$type])) {
-
- $info['property info']['value'] = array(
- 'type' => substr($type, 6),
- 'label' => '',
- );
-
- $wrapper = entity_metadata_wrapper('struct', array('value' => $data[$type]), $info);
- return entity_token_tokens('struct', $tokens, array('struct' => $wrapper), $options);
- }
- }
- function rules_get_entity_metadata_wrapper_all_properties(RulesAbstractPlugin $element) {
- return entity_metadata_wrapper($element->settings['type'], NULL, array(
- 'property info alter' => 'rules_entity_metadata_wrapper_all_properties_callback',
- ));
- }
- function rules_entity_metadata_wrapper_all_properties_callback(EntityMetadataWrapper $wrapper, $property_info) {
- $info = $wrapper->info();
- $properties = entity_get_all_property_info($info['type']);
- $property_info['properties'] += $properties;
- return $property_info;
- }
- function rules_event_invocation_enabled($enable = NULL) {
- static $invocation_enabled = FALSE;
- if (isset($enable)) {
- $invocation_enabled = (bool) $enable;
- }
-
- return $invocation_enabled && !defined('MAINTENANCE_MODE');
- }
|