domain_conf.module

Tracking 6.x-2.x branch
  1. drupal
    1. 5 contributions/domain/domain_conf/domain_conf.module
    2. 6 contributions/domain/domain_conf/domain_conf.module

Domain manager configuration options.

Functions & methods

NameDescription
domain_conf_apiRetrieves elements from hook_domainconf() and formats them as needed.
domain_conf_blockImplement hook_block().
domain_conf_disableImplement hook_disable().
domain_conf_domainbatchImplement hook_domainbatch()
domain_conf_domainlinksImplement hook_domainlinks()
domain_conf_domainupdateImplement hook_domainupdate().
domain_conf_domainwarningsImplement hook_domainwarnings()
domain_conf_domain_bootstrap_fullImplements hook_domain_bootstrap_full().
domain_conf_enableImplement hook_enable().
domain_conf_initImplement hook_init()
domain_conf_language_optionsGet the language options for use in forms.
domain_conf_menuImplement hook_menu()
domain_conf_themeImplement hook_theme()
domain_conf_variable_deleteDelete a setting from {domain_conf}.
domain_conf_variable_getLoad a variable specific to a domain.
domain_conf_variable_saveStore a single variable in {domain_conf}.
domain_conf_variable_setChange the variable setting for a domain. This function is called by external modules that wish to alter Domain Conf settings.
_domain_conf_load_primaryLoad the variables from the primary domain.

File

View source
  1. <?php
  2. /**
  3. * @defgroup domain_conf Domain Conf: configuration extension
  4. * Functions for the Domain Conf module.
  5. */
  6. /**
  7. * @file
  8. * Domain manager configuration options.
  9. *
  10. * @ingroup domain_conf
  11. */
  12. /**
  13. * Implements hook_domain_bootstrap_full().
  14. */
  15. function domain_conf_domain_bootstrap_full($domain) {
  16. static $check;
  17. // If running domain_set_domain(), we have issues with the variables
  18. // from the primary domain, which need to be loaded from cache.
  19. // @link http://drupal.org/node/412156
  20. if ($check) {
  21. global $_domain;
  22. if ($domain['domain_id'] == 0 && $check != $_domain['domain_id']) {
  23. _domain_conf_load_primary(TRUE);
  24. }
  25. }
  26. // Flag that we have already loaded.
  27. $check = $domain['domain_id'];
  28. $data = array();
  29. $data = db_fetch_array(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id']));
  30. if (!empty($data)) {
  31. global $conf;
  32. $settings = domain_unserialize($data['settings']);
  33. // Overwrite the $conf variables.
  34. foreach ($settings as $key => $value) {
  35. if ($value === 'domain-conf-ignore') {
  36. continue;
  37. }
  38. // Language handling is a special case.
  39. if ($key == 'language_default') {
  40. $table = domain_get_primary_table('system');
  41. $language = (bool) db_result(db_query("SELECT status FROM $table WHERE name = 'locale' AND type = 'module'"));
  42. if ($language) {
  43. $table = domain_get_primary_table('languages');
  44. $temp = db_fetch_object(db_query("SELECT * FROM $table WHERE language = '%s'", $value));
  45. if (!empty($temp)) {
  46. $value = $temp;
  47. $GLOBALS['language'] = $temp;
  48. $conf[$key] = $value;
  49. }
  50. }
  51. }
  52. else {
  53. $conf[$key] = $value;
  54. }
  55. }
  56. }
  57. }
  58. /**
  59. * Implement hook_init()
  60. */
  61. function domain_conf_init() {
  62. // Allow sites to add implementations of hook_domainconf() without hacking.
  63. // See http://drupal.org/node/236877.
  64. if (arg(0) == 'admin') {
  65. $extra = drupal_get_path('module', 'domain_conf') .'/domain_conf.inc';
  66. if (file_exists($extra)) {
  67. include $extra;
  68. }
  69. }
  70. }
  71. /**
  72. * Implement hook_menu()
  73. */
  74. function domain_conf_menu() {
  75. $items = array();
  76. $items['admin/build/domain/conf/%domain'] = array(
  77. 'title' => 'Domain site settings',
  78. 'type' => MENU_CALLBACK,
  79. 'access arguments' => array('administer domains'),
  80. 'page callback' => 'domain_conf_page',
  81. 'page arguments' => array(4),
  82. 'file' => 'domain_conf.admin.inc',
  83. );
  84. $items['admin/build/domain/conf-reset/%domain'] = array(
  85. 'title' => 'Domain site settings',
  86. 'type' => MENU_CALLBACK,
  87. 'access arguments' => array('administer domains'),
  88. 'page callback' => 'domain_conf_reset',
  89. 'page arguments' => array(4),
  90. 'file' => 'domain_conf.admin.inc',
  91. );
  92. return $items;
  93. }
  94. /**
  95. * Implement hook_theme()
  96. */
  97. function domain_conf_theme() {
  98. $themes = array(
  99. 'domain_conf_reset' => array(
  100. 'arguments' => array('domain' => array()),
  101. ),
  102. );
  103. return $themes;
  104. }
  105. /**
  106. * Implement hook_enable().
  107. *
  108. * Register domain_conf with the domain module so it's loaded during domain
  109. * bootstrap and can implement domain_bootstrap hooks.
  110. */
  111. function domain_conf_enable() {
  112. domain_bootstrap_register();
  113. }
  114. /**
  115. * Implement hook_disable().
  116. */
  117. function domain_conf_disable() {
  118. domain_bootstrap_unregister('domain_conf');
  119. }
  120. /**
  121. * Implement hook_domainlinks()
  122. */
  123. function domain_conf_domainlinks($domain) {
  124. static $extra;
  125. if (!isset($extra)) {
  126. $extra = domain_conf_api();
  127. }
  128. if ($domain['domain_id'] > 0 || !empty($extra)) {
  129. $links[] = array(
  130. 'title' => t('settings'),
  131. 'path' => 'admin/build/domain/conf/'. $domain['domain_id']
  132. );
  133. return $links;
  134. }
  135. return FALSE;
  136. }
  137. /**
  138. * Implement hook_domainwarnings()
  139. */
  140. function domain_conf_domainwarnings() {
  141. // These are the forms for variables set by Domain Conf.
  142. $forms = array(
  143. 'system_admin_theme_settings',
  144. 'system_date_time_settings',
  145. 'system_performance_settings',
  146. 'system_site_information_settings',
  147. 'system_site_maintenance_settings',
  148. 'locale_languages_overview_form',
  149. 'menu_configure',
  150. );
  151. $return = array();
  152. foreach ($forms as $form) {
  153. $return[$form] = 'admin/build/domain/conf/%domain_id';
  154. }
  155. return $return;
  156. }
  157. /**
  158. * Implement hook_domainbatch()
  159. */
  160. function domain_conf_domainbatch() {
  161. $batch = array();
  162. // Allows the deletion of all Domain Configuration rows.
  163. $batch['domain_conf'] = array(
  164. '#form' => array(
  165. '#title' => t('Reset configurations'),
  166. '#type' => 'checkbox',
  167. '#options' => array(0 => 1, 1 => t('Reset')),
  168. '#description' => t('Delete custom settings for this domain.'),
  169. ),
  170. '#domain_action' => 'domain_delete',
  171. '#system_default' => 0,
  172. '#variable' => 'domain_conf',
  173. '#meta_description' => t('Delete custom settings for domains as supplied by Domain Configuration.'),
  174. '#table' => 'domain_conf',
  175. '#weight' => -10,
  176. );
  177. // Change the email address.
  178. $batch['site_mail'] = array(
  179. '#form' => array(
  180. '#title' => t('Email address'),
  181. '#type' => 'textfield',
  182. '#size' => 40,
  183. '#maxlength' => 255,
  184. '#description' => t('Set the email address for this domain.'),
  185. ),
  186. '#permission' => 'administer site configuration',
  187. '#domain_action' => 'domain_conf',
  188. '#system_default' => variable_get('site_mail', ''),
  189. '#variable' => 'site_mail',
  190. '#meta_description' => t('Set the email address for all domains.'),
  191. '#data_type' => 'string',
  192. '#weight' => -8,
  193. '#update_all' => TRUE,
  194. '#group' => t('Site configuration'),
  195. );
  196. // Change the site slogan.
  197. $batch['site_slogan'] = array(
  198. '#form' => array(
  199. '#title' => t('Site slogan'),
  200. '#type' => 'textfield',
  201. '#size' => 60,
  202. '#maxlength' => 255,
  203. '#description' => t('The slogan of this domain. Some themes display a slogan when available.'),
  204. ),
  205. '#permission' => 'administer site configuration',
  206. '#domain_action' => 'domain_conf',
  207. '#system_default' => variable_get('site_slogan', ''),
  208. '#variable' => 'site_slogan',
  209. '#meta_description' => t('Set the site slogan for all domains.'),
  210. '#data_type' => 'string',
  211. '#weight' => -8,
  212. '#update_all' => TRUE,
  213. '#group' => t('Site configuration'),
  214. );
  215. // Change the site slogan.
  216. $batch['site_mission'] = array(
  217. '#form' => array(
  218. '#title' => t('Site mission'),
  219. '#type' => 'textarea',
  220. '#cols' => 30,
  221. '#rows' => 5,
  222. '#description' => t('The mission statement or focus for this domain.'),
  223. ),
  224. '#domain_action' => 'domain_conf',
  225. '#system_default' => variable_get('site_mission', ''),
  226. '#variable' => 'site_mission',
  227. '#meta_description' => t('Set the site mission for all domains.'),
  228. '#data_type' => 'string',
  229. '#weight' => -8,
  230. '#update_all' => TRUE,
  231. '#group' => t('Site configuration'),
  232. );
  233. // Change the site footer.
  234. $batch['site_footer'] = array(
  235. '#form' => array(
  236. '#title' => t('Site footer'),
  237. '#type' => 'textarea',
  238. '#cols' => 30,
  239. '#rows' => 5,
  240. '#description' => t('This text will be displayed at the bottom of each page for this domain.'),
  241. ),
  242. '#domain_action' => 'domain_conf',
  243. '#system_default' => variable_get('site_footer', ''),
  244. '#variable' => 'site_footer',
  245. '#meta_description' => t('Set the site footer for all domains.'),
  246. '#data_type' => 'string',
  247. '#weight' => -8,
  248. '#update_all' => TRUE,
  249. '#group' => t('Site configuration'),
  250. );
  251. // Change the site frontpage.
  252. $batch['site_frontpage'] = array(
  253. '#form' => array(
  254. '#title' => t('Site frontpage'),
  255. '#type' => 'textfield',
  256. '#size' => 30,
  257. '#maxlength' => 255,
  258. '#description' => t('The home page displays content from this relative URL. If unsure, specify "node".'),
  259. ),
  260. '#permission' => 'administer site configuration',
  261. '#domain_action' => 'domain_conf',
  262. '#system_default' => variable_get('site_frontpage', 'node'),
  263. '#variable' => 'site_frontpage',
  264. '#meta_description' => t('Set the site frontpage for all domains.'),
  265. '#data_type' => 'string',
  266. '#weight' => -8,
  267. '#update_all' => TRUE,
  268. '#group' => t('Site configuration'),
  269. );
  270. // Change the anonymous user name.
  271. $batch['anonymous'] = array(
  272. '#form' => array(
  273. '#title' => t('Anonymous user'),
  274. '#type' => 'textfield',
  275. '#size' => 30,
  276. '#maxlength' => 255,
  277. '#description' => t('The name used to indicate anonymous users for this domain.'),
  278. ),
  279. '#permission' => 'administer site configuration',
  280. '#domain_action' => 'domain_conf',
  281. '#system_default' => variable_get('anonymous', 'Anonymous'),
  282. '#variable' => 'anonymous',
  283. '#meta_description' => t('Set the anonymous user label for all domains.'),
  284. '#data_type' => 'string',
  285. '#weight' => -8,
  286. '#update_all' => TRUE,
  287. '#group' => t('Site configuration'),
  288. );
  289. // Change the administrative theme.
  290. $themes = list_themes();
  291. ksort($themes);
  292. $options[] = t('Use domain default theme');
  293. foreach ($themes as $key => $value) {
  294. $options[$key] = $key;
  295. }
  296. $batch['admin_theme'] = array(
  297. '#form' => array(
  298. '#title' => t('Administrative theme'),
  299. '#type' => 'select',
  300. '#options' => $options,
  301. '#description' => t('Select the administrative theme for this domain.'),
  302. ),
  303. '#permission' => 'administer site configuration',
  304. '#domain_action' => 'domain_conf',
  305. '#system_default' => variable_get('admin_theme', 0),
  306. '#variable' => 'admin_theme',
  307. '#meta_description' => t('Set the administrative theme for all domains.'),
  308. '#data_type' => 'string',
  309. '#weight' => -8,
  310. '#update_all' => TRUE,
  311. '#group' => t('Administrative theme'),
  312. );
  313. // Change the timezone.
  314. $zones = _system_zonelist();
  315. $batch['date_default_timezone'] = array(
  316. '#form' => array(
  317. '#title' => t('Timezone default'),
  318. '#type' => 'select',
  319. '#options' => $zones,
  320. '#description' => t('Select the default site time zone.'),
  321. ),
  322. '#permission' => 'administer site configuration',
  323. '#domain_action' => 'domain_conf',
  324. '#system_default' => variable_get('date_default_timezone', 0),
  325. '#variable' => 'date_default_timezone',
  326. '#meta_description' => t('Set the default timezone for all domains.'),
  327. '#data_type' => 'string',
  328. '#weight' => -6,
  329. '#update_all' => TRUE,
  330. '#group' => t('Timezone settings'),
  331. );
  332. // Change the caching mode.
  333. $batch['cache'] = array(
  334. '#form' => array(
  335. '#type' => 'radios',
  336. '#title' => t('Caching mode'),
  337. '#options' => array(CACHE_DISABLED => t('Disabled'), CACHE_NORMAL => t('Normal (recommended for production sites, no side effects)')),
  338. '#description' => t('Enabling the page cache will offer a significant performance boost. Drupal can store and send compressed cached pages requested by <em>anonymous</em> users. By caching a web page, Drupal does not have to construct the page each time it is viewed.') .'<em> '. t('Aggressive mode caching is not supported when using Domain Access.') .'</em>',
  339. ),
  340. '#permission' => 'administer site configuration',
  341. '#domain_action' => 'domain_conf',
  342. '#system_default' => variable_get('cache', CACHE_DISABLED),
  343. '#variable' => 'cache',
  344. '#meta_description' => t('Set the page cache options for all domains.'),
  345. '#data_type' => 'integer',
  346. '#weight' => -5,
  347. '#update_all' => TRUE,
  348. '#group' => t('Performance'),
  349. );
  350. // Change the cache lifetime.
  351. $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval');
  352. $period[0] = '<'. t('none') .'>';
  353. $batch['cache_lifetime'] = array(
  354. '#form' => array(
  355. '#type' => 'select',
  356. '#title' => t('Minimum cache lifetime'),
  357. '#options' => $period,
  358. '#description' => t('On high-traffic sites, it may be necessary to enforce a minimum cache lifetime. The minimum cache lifetime is the minimum amount of time that will elapse before the cache is emptied and recreated, and is applied to both page and block caches. A larger minimum cache lifetime offers better performance, but users will not see new content for a longer period of time.')
  359. ),
  360. '#permission' => 'administer site configuration',
  361. '#domain_action' => 'domain_conf',
  362. '#system_default' => variable_get('cache_lifetime', 0),
  363. '#variable' => 'cache_lifetime',
  364. '#meta_description' => t('Set the minimum cache lifetime for all domains.'),
  365. '#data_type' => 'integer',
  366. '#weight' => -5,
  367. '#update_all' => TRUE,
  368. '#group' => t('Performance'),
  369. );
  370. //Add support of Pressflow external cache if available
  371. if (defined('CACHE_EXTERNAL')){
  372. $batch['cache']['#form']['#options'][CACHE_EXTERNAL] = t('External (experts only, possible side effects)');
  373. $batch['page_cache_max_age'] = array(
  374. '#form' => array(
  375. '#type' => 'select',
  376. '#title' => t('Page cache maximum age'),
  377. '#options' => $period,
  378. '#description' => t('Internal and external page caches will not deliver cached paged older than this setting.')
  379. ),
  380. '#domain_action' => 'domain_conf',
  381. '#system_default' => variable_get('page_cache_max_age', 0),
  382. '#variable' => 'cache_lifetime',
  383. '#meta_description' => t('Set the page cache maximum age for all domains.'),
  384. '#data_type' => 'integer',
  385. '#weight' => -4,
  386. '#update_all' => TRUE,
  387. '#group' => t('Performance'),
  388. );
  389. }
  390. // Change the page compression settings.
  391. $batch['page_compression'] = array(
  392. '#form' => array(
  393. '#type' => 'radios',
  394. '#title' => t('Page compression'),
  395. '#options' => array(t('Disabled'), t('Enabled')),
  396. '#description' => t("By default, Drupal compresses the pages it caches in order to save bandwidth and improve download times. This option should be disabled when using a webserver that performs compression."),
  397. ),
  398. '#permission' => 'administer site configuration',
  399. '#domain_action' => 'domain_conf',
  400. '#system_default' => variable_get('page_compression', TRUE),
  401. '#variable' => 'page_compression',
  402. '#meta_description' => t('Set the page compression status for all domains.'),
  403. '#data_type' => 'integer',
  404. '#weight' => -5,
  405. '#update_all' => TRUE,
  406. '#group' => t('Performance'),
  407. );
  408. // Toggle the site offline status.
  409. $batch['site_offline'] = array(
  410. '#form' => array(
  411. '#title' => t('Site status'),
  412. '#type' => 'radios',
  413. '#options' => array(t('Online'), t('Off-line')),
  414. '#description' => t('Toggle online/offline status.'),
  415. ),
  416. '#domain_action' => 'domain_conf',
  417. '#system_default' => variable_get('site_offline', 0),
  418. '#variable' => 'site_offline',
  419. '#meta_description' => t('Set the online / offline status for all domains.'),
  420. '#data_type' => 'integer',
  421. '#weight' => -4,
  422. '#update_all' => TRUE,
  423. '#group' => t('Site status'),
  424. );
  425. // Change the site offline message.
  426. $batch['site_offline_message'] = array(
  427. '#form' => array(
  428. '#title' => t('Site offline message'),
  429. '#type' => 'textarea',
  430. '#cols' => 30,
  431. '#rows' => 5,
  432. '#description' => t('Message to show visitors when this domain is in off-line mode.'),
  433. ),
  434. '#permission' => 'administer site configuration',
  435. '#domain_action' => 'domain_conf',
  436. '#system_default' => t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal'))),
  437. '#variable' => 'site_offline_message',
  438. '#meta_description' => t('Set the site offline message for all domains.'),
  439. '#data_type' => 'string',
  440. '#weight' => -2,
  441. '#update_all' => TRUE,
  442. '#group' => t('Site status'),
  443. );
  444. // Change the default language.
  445. if (module_exists('locale')) {
  446. $languages = domain_conf_language_options();
  447. $default = language_default();
  448. $batch['language_default'] = array(
  449. '#form' => array(
  450. '#title' => t('Default language'),
  451. '#type' => 'select',
  452. '#options' => $languages,
  453. '#description' => t('The default language to use for this domain. <em>Note: This setting only works with path-based language switching.</em>'),
  454. ),
  455. '#permission' => 'administer languages',
  456. '#domain_action' => 'domain_conf',
  457. '#system_default' => $default->language,
  458. '#override_default' => TRUE,
  459. '#variable' => '', // deliberately empty, since this is an array and cannot be set.
  460. '#meta_description' => t('Set the default language for all domains.'),
  461. '#data_type' => 'string',
  462. '#weight' => 6,
  463. '#update_all' => TRUE,
  464. '#group' => t('Language settings'),
  465. '#module' => t('Language'),
  466. );
  467. }
  468. // Change the menus
  469. if (module_exists('menu')) {
  470. $menus = menu_get_menus();
  471. $batch['menu_default_node_menu'] = array(
  472. '#form' => array(
  473. '#title' => t('Default menu for content'),
  474. '#type' => 'select',
  475. '#options' => $menus,
  476. '#description' => t('Choose the menu to be the default in the menu options in the content authoring form.'),
  477. ),
  478. '#permission' => 'administer menu',
  479. '#domain_action' => 'domain_conf',
  480. '#system_default' => variable_get('menu_default_node_menu', 0),
  481. '#variable' => 'menu_default_node_menu',
  482. '#meta_description' => t('Set the default menu options for the content authoring form in all domains.'),
  483. '#data_type' => 'string',
  484. '#weight' => 0,
  485. '#update_all' => TRUE,
  486. '#group' => t('Menu settings'),
  487. '#module' => t('Menu'),
  488. );
  489. $menus[0] = t('Do not use for this site');
  490. $batch['menu_primary_links_source'] = array(
  491. '#form' => array(
  492. '#title' => t('Primary links menu'),
  493. '#type' => 'select',
  494. '#options' => $menus,
  495. '#description' => t('Select the primary links for this site.'),
  496. ),
  497. '#permission' => 'administer menu',
  498. '#domain_action' => 'domain_conf',
  499. '#system_default' => variable_get('menu_primary_links_source', 0),
  500. '#variable' => 'menu_primary_links_source',
  501. '#meta_description' => t('Set the primary links menu in all domains.'),
  502. '#data_type' => 'string',
  503. '#weight' => 2,
  504. '#update_all' => TRUE,
  505. '#group' => t('Menu settings'),
  506. '#module' => t('Menu'),
  507. );
  508. $batch['menu_secondary_links_source'] = array(
  509. '#form' => array(
  510. '#title' => t('Secondary links menu'),
  511. '#type' => 'select',
  512. '#options' => $menus,
  513. '#description' => t('Select the secondary links for this site.'),
  514. ),
  515. '#domain_action' => 'domain_conf',
  516. '#system_default' => variable_get('menu_secondary_links_source', 0),
  517. '#variable' => 'menu_secondary_links_source',
  518. '#meta_description' => t('Set the secondary links menu in all domains.'),
  519. '#data_type' => 'string',
  520. '#weight' => 4,
  521. '#update_all' => TRUE,
  522. '#group' => t('Menu settings'),
  523. '#module' => t('Menu'),
  524. );
  525. }
  526. foreach ($batch as $key => $value) {
  527. if (!isset($batch[$key]['#module'])) {
  528. $batch[$key]['#module'] = t('Domain Configuration');
  529. }
  530. }
  531. return $batch;
  532. }
  533. /**
  534. * Implement hook_domainupdate().
  535. */
  536. function domain_conf_domainupdate($op, $domain, $form_state = array()) {
  537. if ($op == 'delete') {
  538. db_query("DELETE FROM {domain_conf} WHERE domain_id = %d", $domain['domain_id']);
  539. cache_clear_all('variables', 'cache');
  540. }
  541. }
  542. /**
  543. * Retrieves elements from hook_domainconf() and formats them
  544. * as needed.
  545. *
  546. * @param $all
  547. * Should the function return all hook implementations or just those marked
  548. * with the domain_settings flag. Defaults to FALSE. Used to determine if
  549. * we are loading configuration options specific to the Domain Access module.
  550. * @return
  551. * An array of form elements according to the FormsAPI or an empty array.
  552. */
  553. function domain_conf_api($all = FALSE, $settings = array()) {
  554. global $_domain;
  555. $options = array();
  556. $extra = module_invoke_all('domainconf', $_domain);
  557. if (!empty($extra)) {
  558. foreach ($extra as $key => $value) {
  559. foreach (element_children($value) as $element) {
  560. if (isset($value[$element]['#default_value']) && isset($settings[$element])) {
  561. $value[$element]['#default_value'] = $settings[$element];
  562. }
  563. }
  564. if ($value['#domain_setting'] == TRUE || $all == TRUE) {
  565. // Discard the #domain_setting flag; it is not needed.
  566. unset($value['#domain_setting']);
  567. // Set the $options array.
  568. $options[$key] = $value;
  569. }
  570. }
  571. }
  572. return $options;
  573. }
  574. /**
  575. * Implement hook_block().
  576. *
  577. * The primary links and secondary links blocks do not respect our settings,
  578. * so we replace it with the following blocks.
  579. */
  580. function domain_conf_block($op = 'list', $delta = 0, $edit = array()) {
  581. if ($op == 'list') {
  582. $blocks = array();
  583. $blocks['domain-primary-links']['info'] = t('Domain primary links');
  584. $blocks['domain-secondary-links']['info'] = t('Domain secondary links');
  585. // Menu blocks can't be cached because each menu item can have
  586. // a custom access callback. menu.inc manages its own caching.
  587. $blocks['domain-primary-links']['cache'] = BLOCK_NO_CACHE;
  588. $blocks['domain-secondary-links']['cache'] = BLOCK_NO_CACHE;
  589. return $blocks;
  590. }
  591. else if ($op == 'view') {
  592. $menus = menu_get_menus();
  593. $string = str_replace('domain-', '', $delta);
  594. $source = 'menu_'. str_replace('-', '_', $string) .'_source';
  595. $delta = variable_get($source, $string);
  596. // Some domains can disable primary and secondary links.
  597. if (empty($delta)) {
  598. return;
  599. }
  600. $data['subject'] = check_plain($menus[$string]);
  601. $data['content'] = menu_tree($delta);
  602. return $data;
  603. }
  604. }
  605. /**
  606. * Change the variable setting for a domain.
  607. * This function is called by external modules that wish
  608. * to alter Domain Conf settings.
  609. *
  610. * Note that this function saves the value to the database
  611. * and changes the active $conf array.
  612. *
  613. * @link http://drupal.org/node/367963
  614. * @see domain_conf_variable_save()
  615. *
  616. * @param $domain_id
  617. * The unique domain ID that is being edited.
  618. * @param $variable
  619. * The name of the variable you wish to set.
  620. * @param $value
  621. * The value of the variable to set. You may leave this
  622. * value blank in order to unset the custom variable.
  623. */
  624. function domain_conf_variable_set($domain_id, $variable, $value = NULL) {
  625. global $conf, $_domain;
  626. domain_conf_variable_save($domain_id, $variable, $value);
  627. // Clear the cache.
  628. cache_clear_all('variables', 'cache');
  629. // If we are on the active domain, set the active variable.
  630. if ($domain_id == $_domain['domain_id']) {
  631. $conf[$variable] = $value;
  632. }
  633. }
  634. /**
  635. * Load a variable specific to a domain.
  636. *
  637. * @param $domain_id
  638. * The unique domain ID that is being edited.
  639. * @param $variable
  640. * The name of the variable you wish to get.
  641. * @param $all
  642. * A boolean flag indicating whether to return the entire variable array.
  643. * @param $reset
  644. * A boolean flag to reset the static variable array for the domain. Useful
  645. * if you are changing variables during a page request.
  646. * @return
  647. * The value of the variable for that domain, or NULL if not set,
  648. * or an array of variables, in the case of $all.
  649. */
  650. function domain_conf_variable_get($domain_id, $variable = '', $all = FALSE, $reset = FALSE) {
  651. global $_domain;
  652. static $settings, $base;
  653. if (empty($base)) {
  654. $base = _domain_conf_load_primary(FALSE);
  655. }
  656. if (!isset($settings[$domain_id]) || $reset) {
  657. // Get the current settings for this domain, if any.
  658. $data = domain_unserialize(db_result(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain_id)));
  659. if (empty($data)) {
  660. $data = array();
  661. }
  662. $settings[$domain_id] = array_merge($base, $data);
  663. }
  664. if ($all) {
  665. return $settings[$domain_id];
  666. }
  667. if (isset($settings[$domain_id][$variable])) {
  668. return $settings[$domain_id][$variable];
  669. }
  670. return NULL;
  671. }
  672. /**
  673. * Get the language options for use in forms.
  674. */
  675. function domain_conf_language_options() {
  676. $languages = language_list('language', TRUE);
  677. $options = array();
  678. foreach ($languages as $key => $lang) {
  679. $extra = '';
  680. if ($lang->native != $lang->name) {
  681. $extra = ' ('. $lang->name .')';
  682. }
  683. $options[$key] = check_plain($lang->native . $extra);
  684. }
  685. return $options;
  686. }
  687. /**
  688. * Load the variables from the primary domain.
  689. *
  690. * We run this special handler when not able to trust variable_get()
  691. * during domain switching.
  692. *
  693. * @see domain_set_domain()
  694. *
  695. * @param $unset
  696. * If TRUE, this will reset the global $conf array.
  697. * @return
  698. * If set to TRUE, no return, just modify the global $conf array.
  699. * Otherwise, return the settings data for the primary domain.
  700. */
  701. function _domain_conf_load_primary($unset = FALSE) {
  702. static $settings;
  703. if (!isset($settings)) {
  704. // Account for table prefixing.
  705. $cache_table = domain_get_primary_table('cache');
  706. // Load the query.
  707. $data = db_result(db_query("SELECT data FROM $cache_table WHERE cid = 'variables'"));
  708. if (!empty($data)) {
  709. $settings = domain_unserialize($data);
  710. }
  711. // If the cache has been cleared, this data will be empty.
  712. // In this case, grab the data directly from the base {variable} table.
  713. else {
  714. $variable_table = domain_get_primary_table('variable');
  715. $result = db_query("SELECT name, value FROM $variable_table");
  716. while ($vars = db_fetch_array($result)) {
  717. $data[$vars['name']] = domain_unserialize($vars['value']);
  718. }
  719. $settings = $data;
  720. }
  721. }
  722. // Do we reset the global or just return data?
  723. if ($unset) {
  724. global $conf;
  725. $conf = $settings;
  726. return;
  727. }
  728. return $settings;
  729. }
  730. /**
  731. * Delete a setting from {domain_conf}.
  732. *
  733. * @param $domain_id
  734. * The unique domain ID that is being edited.
  735. * @param $variable
  736. * The name of the variable you wish to delete.
  737. */
  738. function domain_conf_variable_delete($domain_id, $variable) {
  739. // Get the current settings for this domain, if any.
  740. $settings = domain_unserialize(db_result(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain_id)));
  741. // Settings found, remove them.
  742. if (!empty($settings)) {
  743. unset($settings[$variable]);
  744. db_query("UPDATE {domain_conf} SET settings = %b WHERE domain_id = %d", serialize($settings), $domain_id);
  745. }
  746. }
  747. /**
  748. * Store a single variable in {domain_conf}.
  749. *
  750. * @link http://drupal.org/node/367963
  751. * @see domain_conf_variable_set()
  752. *
  753. * @param $domain_id
  754. * The unique domain ID that is being edited.
  755. * @param $variable
  756. * The name of the variable you wish to set.
  757. * @param $value
  758. * The value of the variable to set. You may leave this
  759. * value blank in order to unset the custom variable.
  760. */
  761. function domain_conf_variable_save($domain_id, $variable, $value = NULL) {
  762. // Get the current settings for this domain, if any.
  763. $serialized = db_result(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $domain_id));
  764. // Settings found, update them.
  765. if ($serialized) {
  766. $settings = domain_unserialize($serialized);
  767. $settings[$variable] = $value;
  768. db_query("UPDATE {domain_conf} SET settings = %b WHERE domain_id = %d", serialize($settings), $domain_id);
  769. }
  770. else if (domain_lookup($domain_id) != -1) {
  771. $settings = array($variable => $value);
  772. db_query("INSERT INTO {domain_conf} (domain_id, settings) VALUES (%d, %b)", $domain_id, serialize($settings));
  773. }
  774. }

Related topics