advagg.admin.inc

  1. cis7 sites/all/modules/ulmus/advagg/advagg.admin.inc
  2. cle7 sites/all/modules/ulmus/advagg/advagg.admin.inc
  3. ecd7 sites/all/modules/ulmus/advagg/advagg.admin.inc
  4. elmsmedia7 sites/all/modules/ulmus/advagg/advagg.admin.inc
  5. harmony7 sites/all/modules/ulmus/advagg/advagg.admin.inc
  6. icor7 sites/all/modules/ulmus/advagg/advagg.admin.inc
  7. meedjum_blog7 sites/all/modules/ulmus/advagg/advagg.admin.inc
  8. mooc7 sites/all/modules/ulmus/advagg/advagg.admin.inc

Admin page callbacks for the advanced CSS/JS aggregation module.

Functions

Namesort descending Description
advagg_admin_cleanup_semaphore_table_button Delete orphaned/expired advagg locks from the semaphore database table.
advagg_admin_clear_all_caches_button Clear out all advagg cache bins.
advagg_admin_clear_all_files_button Clear out all advagg cache bins and clear out all advagg aggregated files.
advagg_admin_flush_cache_button Perform a smart flush.
advagg_admin_flush_stale_files_button Clear out all stale advagg aggregated files.
advagg_admin_get_file_info Get detailed info about the given filename.
advagg_admin_get_file_info_callback Display file info via ajax callback.
advagg_admin_get_file_info_submit Display file info in a drupal message.
advagg_admin_get_file_info_validate Verify that the filename is correct.
advagg_admin_increment_global_counter Clear out all advagg cache bins and increment the counter.
advagg_admin_info_form Form builder; Show info about advagg and advagg settings.
advagg_admin_operations_form Form builder; Do advagg operations.
advagg_admin_remove_missing_files_from_db_button Scan for missing files and remove the associated entries in the database.
advagg_admin_remove_old_unused_aggregates_button Delete aggregates that have not been accessed in the last 6 weeks.
advagg_admin_settings_form Form builder; Configure advagg settings.
advagg_admin_settings_form_submit Clear out the advagg cache bin when the save configuration button is pressed.
advagg_admin_toggle_bypass_cookie Set or remove the AdvAggDisabled cookie.

File

sites/all/modules/ulmus/advagg/advagg.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Admin page callbacks for the advanced CSS/JS aggregation module.
  5. */
  6. /**
  7. * Form builder; Configure advagg settings.
  8. *
  9. * @ingroup forms
  10. * @see system_settings_form()
  11. */
  12. function advagg_admin_settings_form($form, $form_state) {
  13. drupal_set_title(t('AdvAgg: Configuration'));
  14. $config_path = advagg_admin_config_root_path();
  15. // Simple checkbox settings.
  16. $form['global'] = array(
  17. '#type' => 'fieldset',
  18. '#title' => t('Global Options'),
  19. );
  20. $form['global']['advagg_enabled'] = array(
  21. '#type' => 'checkbox',
  22. '#title' => t('Enable advanced aggregation'),
  23. '#default_value' => variable_get('advagg_enabled', ADVAGG_ENABLED),
  24. '#description' => t('Uncheck this box to completely disable AdvAgg functionality.'),
  25. );
  26. $form['global']['advagg_gzip'] = array(
  27. '#type' => 'checkbox',
  28. '#title' => t('Create .gz files'),
  29. '#default_value' => variable_get('advagg_gzip', ADVAGG_GZIP),
  30. '#description' => t('All aggregated files can be pre-compressed into a .gz file and
  31. served from Apache. This is faster then gzipping the file on each request.'),
  32. );
  33. $form['global']['advagg_core_groups'] = array(
  34. '#type' => 'checkbox',
  35. '#title' => t('Use cores grouping logic'),
  36. '#default_value' => variable_get('advagg_combine_css_media', ADVAGG_COMBINE_CSS_MEDIA) || variable_get('advagg_ie_css_selector_limiter', ADVAGG_IE_CSS_SELECTOR_LIMITER) ? FALSE : variable_get('advagg_core_groups', ADVAGG_CORE_GROUPS),
  37. '#description' => t('Will group files just like core does.'),
  38. '#states' => array(
  39. 'enabled' => array(
  40. '#edit-advagg-combine-css-media' => array('checked' => FALSE),
  41. '#edit-advagg-ie-css-selector-limiter' => array('checked' => FALSE),
  42. ),
  43. ),
  44. );
  45. $form['global']['advagg_use_httprl'] = array(
  46. '#type' => 'checkbox',
  47. '#title' => t('Use HTTPRL to generate aggregates.'),
  48. '#default_value' => module_exists('httprl') ? variable_get('advagg_use_httprl', ADVAGG_USE_HTTPRL) : FALSE,
  49. '#disabled' => module_exists('httprl') ? FALSE : TRUE,
  50. '#description' => t('If <a href="@link">HTTPRL</a> is installed, advagg will use it to generate aggregates on the fly in a background parallel process.', array('@link' => 'http://drupal.org/project/httprl')),
  51. );
  52. $options = array(
  53. -1 => t('Development ~ 100ms'),
  54. // 0 => t('Disabled ~ 70ms'),
  55. 1 => t('Normal ~ 10ms'),
  56. 3 => t('Aggressive ~ 4ms'),
  57. );
  58. $form['global']['advagg_cache_level'] = array(
  59. '#type' => 'radios',
  60. '#title' => t('AdvAgg Cache Settings'),
  61. '#default_value' => variable_get('advagg_cache_level', ADVAGG_CACHE_LEVEL),
  62. '#options' => $options,
  63. '#description' => t("As a reference, core takes about 7 ms to run. Development will scan all files for a change on every page load. Normal is should be fine for all use cases. Aggressive might break depending on how various hook_alter's for CSS/JS are implemented; to see what modules are using css/js_alter you can go to the <a href='@information'>Information Page</a> and under 'AdvAgg CSS/JS hooks implemented by modules' modules using both of these hooks will be listed near the bottom of that section; more information about the Aggressive setting can be found in the advagg README.txt file.", array(
  64. '@information' => url($config_path . '/advagg/info', array(
  65. 'fragment' => 'edit-hooks-implemented',
  66. )),
  67. )),
  68. );
  69. // Show msg about the jquery update compression setting.
  70. if (module_exists('jquery_update')) {
  71. if (variable_get('jquery_update_compression_type', 'min') == 'min') {
  72. $form['global']['dev_container'] = array(
  73. '#type' => 'container',
  74. '#states' => array(
  75. 'visible' => array(
  76. ':input[name="advagg_cache_level"]' => array('value' => '-1'),
  77. ),
  78. ),
  79. );
  80. $form['global']['dev_container']['advagg_jquery_update_development'] = array(
  81. '#markup' => '<p>' . t('You might want to change the <a href="!url">jQuery update compression level</a> to "Development" as well. ', array(
  82. '!url' => url('admin/config/development/jquery_update'),
  83. )) . '</p>',
  84. );
  85. }
  86. else {
  87. $form['global']['prod_container'] = array(
  88. '#type' => 'container',
  89. '#states' => array(
  90. 'visible' => array(
  91. ':input[name="advagg_cache_level"]' => array('!value' => '-1'),
  92. ),
  93. ),
  94. );
  95. $form['global']['prod_container']['advagg_jquery_update_development'] = array(
  96. '#markup' => '<p>' . t('You might want to change the <a href="!url">jQuery update compression level</a> to "Production" as well. ', array(
  97. '!url' => url('admin/config/development/jquery_update'),
  98. )) . '</p>',
  99. );
  100. }
  101. }
  102. $form['css'] = array(
  103. '#type' => 'fieldset',
  104. '#title' => t('CSS Options'),
  105. );
  106. $form['css']['advagg_combine_css_media'] = array(
  107. '#type' => 'checkbox',
  108. '#title' => t('Combine CSS files by using media queries'),
  109. '#default_value' => variable_get('advagg_combine_css_media', ADVAGG_COMBINE_CSS_MEDIA),
  110. '#description' => t('Will combine more CSS files together because different CSS media types can be used in the same file by using media queries. Use cores grouping logic needs to be unchecked in order for this to work. Also noted is that due to an issue with IE9, compatibility mode is forced off if this is enabled.'),
  111. '#states' => array(
  112. 'disabled' => array(
  113. '#edit-advagg-core-groups' => array('checked' => TRUE),
  114. ),
  115. ),
  116. );
  117. $form['css']['advagg_ie_css_selector_limiter'] = array(
  118. '#type' => 'checkbox',
  119. '#title' => t('Prevent more than %limit CSS selectors in an aggregated CSS file', array('%limit' => variable_get('advagg_ie_css_selector_limiter_value', ADVAGG_IE_CSS_SELECTOR_LIMITER_VALUE))),
  120. '#default_value' => variable_get('advagg_ie_css_selector_limiter', ADVAGG_IE_CSS_SELECTOR_LIMITER),
  121. '#description' => t('Internet Explorer before version 10; IE9, IE8, IE7, & IE6 all have 4095 as the limit for the maximum number of css selectors that can be in a file. Enabling this will prevent CSS aggregates from being created that exceed this limit. <a href="@link">More info</a>. Use cores grouping logic needs to be unchecked in order for this to work.', array('@link' => 'http://blogs.msdn.com/b/ieinternals/archive/2011/05/14/10164546.aspx')),
  122. '#states' => array(
  123. 'disabled' => array(
  124. '#edit-advagg-core-groups' => array('checked' => TRUE),
  125. ),
  126. ),
  127. );
  128. $form['css']['advagg_ie_css_selector_limiter_value'] = array(
  129. '#type' => 'textfield',
  130. '#title' => t('The selector count the IE CSS limiter should use'),
  131. '#default_value' => variable_get('advagg_ie_css_selector_limiter_value', ADVAGG_IE_CSS_SELECTOR_LIMITER_VALUE),
  132. '#description' => t('Internet Explorer before version 10; IE9, IE8, IE7, & IE6 all have 4095 as the limit for the maximum number of css selectors that can be in a file. Use this field to modify the value used 4095 sometimes may be still be too many with media queries.'),
  133. '#states' => array(
  134. 'visible' => array(
  135. '#edit-advagg-ie-css-selector-limiter' => array('checked' => TRUE),
  136. ),
  137. 'disabled' => array(
  138. '#edit-advagg-ie-css-selector-limiter' => array('checked' => FALSE),
  139. ),
  140. ),
  141. );
  142. $form['css']['advagg_css_fix_type'] = array(
  143. '#type' => 'checkbox',
  144. '#title' => t('Fix improperly set type'),
  145. '#default_value' => variable_get('advagg_css_fix_type', ADVAGG_CSS_FIX_TYPE),
  146. '#description' => t('If type is external but does not start with http, https, or // change it to be type file. If type is file but it starts with http, https, or // change type to be external.'),
  147. );
  148. $form['js'] = array(
  149. '#type' => 'fieldset',
  150. '#title' => t('JS Options'),
  151. );
  152. $form['js']['advagg_js_fix_type'] = array(
  153. '#type' => 'checkbox',
  154. '#title' => t('Fix improperly set type'),
  155. '#default_value' => variable_get('advagg_js_fix_type', ADVAGG_JS_FIX_TYPE),
  156. '#description' => t('If type is external but does not start with http, https, or // change it to be type file. If type is file but it starts with http, https, or // change type to be external.'),
  157. );
  158. // Clear the cache bins on submit.
  159. $form['#submit'][] = 'advagg_admin_settings_form_submit';
  160. return system_settings_form($form);
  161. }
  162. /**
  163. * Form builder; Do advagg operations.
  164. *
  165. * @ingroup forms
  166. */
  167. function advagg_admin_operations_form($form, $form_state) {
  168. drupal_set_title(t('AdvAgg: Operations'));
  169. // Explain what can be done on this page.
  170. $form['tip'] = array(
  171. '#markup' => '<p>' . t('This is a collection of commands to control the cache and to manage testing of this module. In general this page is useful when troubleshooting some aggregation issues. For normal operations, you do not need to do anything on this page below the Smart Cache Flush. There are no configuration options here.') . '</p>',
  172. );
  173. // Buttons to do stuff.
  174. // AdvAgg smart cache flushing.
  175. $form['smart_flush'] = array(
  176. '#type' => 'fieldset',
  177. '#title' => t('Smart Cache Flush'),
  178. '#description' => t('Scan all files referenced in aggregated files. If any of them have changed, clear that cache so the changes will go out.'),
  179. );
  180. $form['smart_flush']['advagg_flush'] = array(
  181. '#type' => 'submit',
  182. '#value' => t('Flush AdvAgg Cache'),
  183. '#submit' => array('advagg_admin_flush_cache_button'),
  184. );
  185. // Set/Remove Bypass Cookie.
  186. $form['bypass'] = array(
  187. '#type' => 'fieldset',
  188. '#title' => t('Aggregation Bypass Cookie'),
  189. '#description' => t('This will set or remove a cookie that disables aggregation for the remainder of the browser session.'),
  190. );
  191. $form['bypass']['submit'] = array(
  192. '#type' => 'submit',
  193. '#value' => t('Toggle The "aggregation bypass cookie" For This Browser'),
  194. '#attributes' => array('onclick' => 'javascript:return advagg_toggle_cookie()'),
  195. '#submit' => array('advagg_admin_toggle_bypass_cookie'),
  196. );
  197. // Add in aggregation bypass cookie javascript.
  198. $form['#attached']['js'][] = array(
  199. 'data' => array('advagg' => array('key' => drupal_hash_base64(drupal_get_private_key()))),
  200. 'type' => 'setting',
  201. );
  202. $form['#attached']['js'][] = drupal_get_path('module', 'advagg') . '/advagg.admin.js';
  203. // Smart flushing.
  204. $form['cron'] = array(
  205. '#type' => 'fieldset',
  206. '#title' => t('Cron Maintenance Tasks'),
  207. '#description' => t('The following 4 operations are ran on cron but you can run them manually here.'),
  208. );
  209. $form['cron']['smart_file_flush'] = array(
  210. '#type' => 'fieldset',
  211. '#collapsible' => TRUE,
  212. '#collapsed' => TRUE,
  213. '#title' => t('Clear All Stale Files'),
  214. '#description' => t('Remove all stale files. Scan all files in the advagg_css/js directories and remove the ones that have not been accessed in the last 30 days.'),
  215. );
  216. $form['cron']['smart_file_flush']['advagg_flush_stale_files'] = array(
  217. '#type' => 'submit',
  218. '#value' => t('Remove All Stale Files'),
  219. '#submit' => array('advagg_admin_flush_stale_files_button'),
  220. );
  221. $form['cron']['remove_missing_files'] = array(
  222. '#type' => 'fieldset',
  223. '#collapsible' => TRUE,
  224. '#collapsed' => TRUE,
  225. '#title' => t('Clear Missing Files From Database'),
  226. '#description' => t('Scan for missing files and remove the associated entries in the database.'),
  227. );
  228. $form['cron']['remove_missing_files']['advagg_remove_missing_files_from_db'] = array(
  229. '#type' => 'submit',
  230. '#value' => t('Clear Missing Files From Database'),
  231. '#submit' => array('advagg_admin_remove_missing_files_from_db_button'),
  232. );
  233. $form['cron']['remove_old_aggregates'] = array(
  234. '#type' => 'fieldset',
  235. '#collapsible' => TRUE,
  236. '#collapsed' => TRUE,
  237. '#title' => t('Delete Unused Aggregates From Database'),
  238. '#description' => t('Delete aggregates that have not been accessed in the last 6 weeks.'),
  239. );
  240. $form['cron']['remove_old_aggregates']['advagg_remove_old_unused_aggregates'] = array(
  241. '#type' => 'submit',
  242. '#value' => t('Delete Unused Aggregates From Database'),
  243. '#submit' => array('advagg_admin_remove_old_unused_aggregates_button'),
  244. );
  245. $form['cron']['cleanup_semaphore_table'] = array(
  246. '#type' => 'fieldset',
  247. '#collapsible' => TRUE,
  248. '#collapsed' => TRUE,
  249. '#title' => t('Delete Orphaned Semaphore Locks'),
  250. '#description' => t('Delete orphaned/expired advagg locks from the semaphore database table.'),
  251. );
  252. $form['cron']['cleanup_semaphore_table']['advagg_cleanup_semaphore_table'] = array(
  253. '#type' => 'submit',
  254. '#value' => t('Delete Unused Aggregates From Database'),
  255. '#submit' => array('advagg_admin_cleanup_semaphore_table_button'),
  256. );
  257. // Hide drastic measures as they should not be done unless you really need it.
  258. $form['drastic_measures'] = array(
  259. '#type' => 'fieldset',
  260. '#collapsible' => TRUE,
  261. '#collapsed' => TRUE,
  262. '#title' => t('Drastic Measures'),
  263. '#description' => t('The options below should normally never need to be done.'),
  264. );
  265. $form['drastic_measures']['dumb_cache_flush'] = array(
  266. '#type' => 'fieldset',
  267. '#collapsible' => TRUE,
  268. '#collapsed' => TRUE,
  269. '#title' => t('Clear All Caches'),
  270. '#description' => t('Remove all entries from the advagg cache bins. Useful if you suspect a cache is not getting cleared.'),
  271. );
  272. $form['drastic_measures']['dumb_cache_flush']['advagg_flush_all_caches'] = array(
  273. '#type' => 'submit',
  274. '#value' => t('Clear All Caches'),
  275. '#submit' => array('advagg_admin_clear_all_caches_button'),
  276. );
  277. $form['drastic_measures']['dumb_file_flush'] = array(
  278. '#type' => 'fieldset',
  279. '#collapsible' => TRUE,
  280. '#collapsed' => TRUE,
  281. '#title' => t('Clear All Files'),
  282. '#description' => t('Remove all generated files. Useful if you think some of the generated files got corrupted and thus need to be deleted.'),
  283. );
  284. $form['drastic_measures']['dumb_file_flush']['advagg_flush_all_files'] = array(
  285. '#type' => 'submit',
  286. '#value' => t('Remove All Generated Files'),
  287. '#submit' => array('advagg_admin_clear_all_files_button'),
  288. );
  289. $form['drastic_measures']['force_change'] = array(
  290. '#type' => 'fieldset',
  291. '#collapsible' => TRUE,
  292. '#collapsed' => TRUE,
  293. '#title' => t('Force new aggregates'),
  294. '#description' => t('Force the creation of all new aggregates by incrementing a global counter. Current value of counter: %value. This is useful if a CDN has cached an aggregate incorrectly as it will force new ones to be used even if nothing else has changed.', array('%value' => advagg_get_global_counter())),
  295. );
  296. $form['drastic_measures']['force_change']['increment_global_counter'] = array(
  297. '#type' => 'submit',
  298. '#value' => t('Increment Global Counter'),
  299. '#submit' => array('advagg_admin_increment_global_counter'),
  300. );
  301. return $form;
  302. }
  303. /**
  304. * Form builder; Show info about advagg and advagg settings.
  305. *
  306. * @ingroup forms
  307. * @see system_settings_form()
  308. */
  309. function advagg_admin_info_form($form, $form_state) {
  310. drupal_set_title(t('AdvAgg: Information'));
  311. // Explain what can be done on this page.
  312. $form['tip'] = array(
  313. '#markup' => '<p>' . t('This page provides debugging information. There are no configuration options here.') . '</p>',
  314. );
  315. // Get all hooks & variables.
  316. drupal_theme_initialize();
  317. $core_hooks = theme_get_registry();
  318. $advagg_hooks = advagg_hooks_implemented();
  319. list($css_path, $js_path) = advagg_get_root_files_dir();
  320. // Output html process functions hooks.
  321. $form['info'] = array(
  322. '#type' => 'fieldset',
  323. '#collapsible' => TRUE,
  324. '#collapsed' => TRUE,
  325. '#title' => t('Hook Theme Info'),
  326. );
  327. $data = implode("\n", $core_hooks['html']['process functions']);
  328. $form['info']['advagg_debug_info'] = array(
  329. '#markup' => '<pre>' . $data . '</pre>',
  330. );
  331. // Get all parent css and js files.
  332. $types = array('css', 'js');
  333. $css_file = '';
  334. foreach ($types as $type) {
  335. $form[$type] = array(
  336. '#type' => 'fieldset',
  337. '#collapsible' => TRUE,
  338. '#collapsed' => TRUE,
  339. '#title' => t('@type files', array('@type' => drupal_strtoupper($type))),
  340. );
  341. // Get filename, filename_hash, and changes.
  342. $results = db_select('advagg_files', 'af')
  343. ->fields('af', array('filename', 'filename_hash', 'changes'))
  344. ->condition('filetype', $type)
  345. ->execute();
  346. while ($row = $results->fetchAssoc()) {
  347. if (empty($css_file) && $type == 'css') {
  348. $css_file = basename($row['filename']);
  349. }
  350. $form[$type][$row['filename_hash']] = array(
  351. '#markup' => '<div>' . format_plural($row['changes'], 'changed 1 time - %file<br />', 'changed %changes times - %file<br /></div>', array(
  352. '%changes' => $row['changes'],
  353. '%file' => $row['filename'],
  354. )),
  355. );
  356. }
  357. }
  358. // Display as module -> hook instead of hook -> module.
  359. ksort($advagg_hooks);
  360. $module_hooks = array();
  361. foreach ($advagg_hooks as $hook => $values) {
  362. if (!empty($values)) {
  363. foreach ($values as $module_name) {
  364. if (!isset($module_hooks[$module_name])) {
  365. $module_hooks[$module_name] = array();
  366. }
  367. $module_hooks[$module_name][] = $hook;
  368. }
  369. }
  370. else {
  371. $module_hooks['not in use'][] = $hook;
  372. }
  373. }
  374. ksort($module_hooks);
  375. // Output all advagg hooks implemented.
  376. foreach ($module_hooks as $hook => $values) {
  377. if (empty($values)) {
  378. $form['modules_implementing_advagg'][$hook] = array(
  379. '#markup' => '<div><strong>' . check_plain($hook) . ':</strong> 0</div>',
  380. );
  381. }
  382. else {
  383. $form['modules_implementing_advagg'][$hook] = array(
  384. '#markup' => '<div><strong>' . check_plain($hook) . ':</strong> ' . count($values) . '<br />&nbsp;&nbsp;' . filter_xss(implode('<br />&nbsp;&nbsp;', $values), array('br')) . '</div>',
  385. );
  386. }
  387. }
  388. $form['modules_implementing_advagg'] += array(
  389. '#type' => 'fieldset',
  390. '#collapsible' => TRUE,
  391. '#collapsed' => TRUE,
  392. '#title' => t('Modules implementing AdvAgg CSS/JS hooks'),
  393. );
  394. // Output all advagg hooks implemented.
  395. foreach ($advagg_hooks as $hook => $values) {
  396. if (empty($values)) {
  397. $form['hooks_implemented'][$hook] = array(
  398. '#markup' => '<div><strong>' . check_plain($hook) . ':</strong> 0</div>',
  399. );
  400. }
  401. else {
  402. $form['hooks_implemented'][$hook] = array(
  403. '#markup' => '<div><strong>' . check_plain($hook) . ':</strong> ' . count($values) . '<br />&nbsp;&nbsp;' . filter_xss(implode('<br />&nbsp;&nbsp;', $values), array('br')) . '</div>',
  404. );
  405. }
  406. }
  407. $form['hooks_implemented'] += array(
  408. '#type' => 'fieldset',
  409. '#collapsible' => TRUE,
  410. '#collapsed' => TRUE,
  411. '#title' => t('AdvAgg CSS/JS hooks implemented by modules'),
  412. );
  413. // Output what is used inside of the advagg_get_current_hooks_hash() function.
  414. $form['hooks_variables_hash'] = array(
  415. '#type' => 'fieldset',
  416. '#collapsible' => TRUE,
  417. '#collapsed' => TRUE,
  418. '#title' => t('Hooks And Variables Used In Hash'),
  419. );
  420. $form['hooks_variables_hash']['description'] = array(
  421. '#markup' => t('Current Value: %value. Below is the listing of variables and hooks used to generate the 3rd hash of an aggregates filename.', array('%value' => advagg_get_current_hooks_hash())),
  422. );
  423. $form['hooks_variables_hash']['output'] = array(
  424. // @ignore production_php
  425. '#markup' => '<pre>' . print_r(advagg_current_hooks_hash_array(), TRUE) . '</pre>',
  426. );
  427. // Get info about a file.
  428. $form['get_info_about_agg'] = array(
  429. '#type' => 'fieldset',
  430. '#collapsible' => TRUE,
  431. '#collapsed' => FALSE,
  432. '#title' => t('Get detailed info about an aggregate file'),
  433. );
  434. $form['get_info_about_agg']['filename'] = array(
  435. '#type' => 'textfield',
  436. '#size' => 170,
  437. '#maxlength' => 256,
  438. '#default_value' => '',
  439. '#title' => t('Filename'),
  440. );
  441. $form['get_info_about_agg']['submit'] = array(
  442. '#type' => 'submit',
  443. '#value' => t('Lookup Details'),
  444. '#submit' => array('advagg_admin_get_file_info_submit'),
  445. '#validate' => array('advagg_admin_get_file_info_validate'),
  446. '#ajax' => array(
  447. 'callback' => 'advagg_admin_get_file_info_callback',
  448. 'wrapper' => 'advagg-file-info-ajax',
  449. 'effect' => 'fade',
  450. ),
  451. );
  452. module_load_include('install', 'advagg', 'advagg');
  453. $form['get_info_about_agg']['tip'] = array(
  454. '#markup' => '<p>' . t('Takes input like "@css_file" or a full aggregate name like "@advagg_js"', array(
  455. '@css_file' => $css_file,
  456. '@advagg_js' => advagg_install_get_first_advagg_file($js_path[1]),
  457. )) . '</p>',
  458. );
  459. $form['get_info_about_agg']['wrapper'] = array(
  460. '#markup' => "<div id='advagg-file-info-ajax'></div>",
  461. );
  462. return $form;
  463. }
  464. // Submit callback.
  465. /**
  466. * Clear out the advagg cache bin when the save configuration button is pressed.
  467. */
  468. function advagg_admin_settings_form_submit($form, &$form_state) {
  469. $cache_bins = advagg_flush_caches();
  470. foreach ($cache_bins as $bin) {
  471. cache_clear_all('*', $bin, TRUE);
  472. }
  473. }
  474. // Callbacks for buttons.
  475. /**
  476. * Set or remove the AdvAggDisabled cookie.
  477. */
  478. function advagg_admin_toggle_bypass_cookie() {
  479. $cookie_name = 'AdvAggDisabled';
  480. $key = drupal_hash_base64(drupal_get_private_key());
  481. // If the cookie does exist then remove it.
  482. if (!empty($_COOKIE[$cookie_name]) && $_COOKIE[$cookie_name] == $key) {
  483. setcookie($cookie_name, '', -1, $GLOBALS['base_path'], '.' . $_SERVER['HTTP_HOST']);
  484. unset($_COOKIE[$cookie_name]);
  485. drupal_set_message(t('AdvAgg Bypass Cookie Removed.'));
  486. }
  487. // If the cookie does not exist then set it.
  488. else {
  489. // Cookie will last for 12 hours.
  490. setcookie($cookie_name, $key, REQUEST_TIME + (60 * 60 * 12), $GLOBALS['base_path'], '.' . $_SERVER['HTTP_HOST']);
  491. $_COOKIE[$cookie_name] = $key;
  492. drupal_set_message(t('AdvAgg Bypass Cookie Set.'));
  493. }
  494. }
  495. /**
  496. * Display file info in a drupal message.
  497. */
  498. function advagg_admin_get_file_info_submit($form, &$form_state) {
  499. if (!empty($form_state['input']['ajax_page_state'])) {
  500. return;
  501. }
  502. $info = advagg_admin_get_file_info($form_state['values']['filename']);
  503. if (module_exists('httprl')) {
  504. $output = httprl_pr($info);
  505. }
  506. else {
  507. $output = '<pre>' . check_plain(print_r($info, TRUE)) . '</pre>';
  508. }
  509. // @ignore security_dsm
  510. drupal_set_message($output);
  511. }
  512. /**
  513. * Display file info via ajax callback.
  514. */
  515. function advagg_admin_get_file_info_callback($form, &$form_state) {
  516. if (!empty($form_state['values']['error'])) {
  517. return '<div id="advagg-file-info-ajax"></div>';
  518. }
  519. $info = advagg_admin_get_file_info($form_state['values']['filename']);
  520. if (empty($info)) {
  521. form_set_error('filename', 'Please input a valid aggregate filename.');
  522. return '<div id="advagg-file-info-ajax"></div>';
  523. }
  524. else {
  525. if (module_exists('httprl')) {
  526. $output = httprl_pr($info);
  527. }
  528. else {
  529. $output = '<pre>' . print_r($info, TRUE) . '</pre>';
  530. }
  531. return '<div id="advagg-file-info-ajax">' . $output . '</div>';
  532. }
  533. }
  534. /**
  535. * Verify that the filename is correct.
  536. */
  537. function advagg_admin_get_file_info_validate($form, &$form_state) {
  538. if (empty($form_state['values']['filename'])) {
  539. form_set_error('filename', 'Please input an aggregate filename.');
  540. $form_state['values']['error'] = TRUE;
  541. }
  542. }
  543. /**
  544. * Get detailed info about the given filename.
  545. *
  546. * @param string $filename
  547. * Name of file to lookup.
  548. *
  549. * @return array
  550. * Returns an array of detailed info about this file.
  551. */
  552. function advagg_admin_get_file_info($filename) {
  553. module_load_include('inc', 'advagg', 'advagg.missing');
  554. module_load_include('inc', 'advagg', 'advagg');
  555. // Strip quotes and trim.
  556. $filename = trim(str_replace(array('"', "'"), '', $filename));
  557. $data = advagg_get_hashes_from_filename(basename($filename));
  558. $output = array();
  559. if (is_array($data)) {
  560. list($type, $aggregate_filenames_hash, $aggregate_contents_hash, $aggregate_settings) = $data;
  561. // Get a list of files.
  562. $files = advagg_get_files_from_hashes($type, $aggregate_filenames_hash, $aggregate_contents_hash);
  563. $data['files'] = $files;
  564. // Get detailed info on each file.
  565. foreach ($data['files'] as $filename => &$info) {
  566. $info += advagg_get_info_on_file($filename);
  567. if (module_exists('advagg_bundler')) {
  568. $bundler = advagg_bundler_analysis($filename);
  569. $info['group_hash'] = $bundler['group_hash'];
  570. }
  571. }
  572. $output = $data;
  573. }
  574. else {
  575. $results = db_select('advagg_files', 'af')
  576. ->fields('af')
  577. ->condition('filename', '%' . db_like($filename), 'LIKE')
  578. ->execute();
  579. while ($row = $results->fetchAssoc()) {
  580. $row += advagg_get_info_on_file($row['filename']);
  581. if (module_exists('advagg_bundler')) {
  582. $bundler = advagg_bundler_analysis($row['filename']);
  583. $row['group_hash'] = $bundler['group_hash'];
  584. }
  585. $output[] = $row;
  586. }
  587. }
  588. return $output;
  589. }
  590. /**
  591. * Perform a smart flush.
  592. */
  593. function advagg_admin_flush_cache_button() {
  594. // Run the command.
  595. module_load_include('inc', 'advagg', 'advagg.cache');
  596. $flushed = advagg_push_new_changes();
  597. // Report back the results.
  598. if (empty($flushed)) {
  599. drupal_set_message(t('No changes found. Nothing was cleared.'));
  600. return;
  601. }
  602. foreach ($flushed as $filename => $data) {
  603. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  604. drupal_set_message(t('The file %filename has changed. %db_usage aggregates are using this file. %db_count db cache entries and all %type full cache entries have been flushed from the cache bins.', array(
  605. '%filename' => $filename,
  606. '%db_usage' => count($data[0]),
  607. '%db_count' => count($data[1]),
  608. '%type' => $ext,
  609. )));
  610. }
  611. }
  612. /**
  613. * Clear out all advagg cache bins.
  614. */
  615. function advagg_admin_clear_all_caches_button() {
  616. // Run the command.
  617. module_load_include('inc', 'advagg', 'advagg.cache');
  618. advagg_flush_all_cache_bins();
  619. // Report back the results.
  620. drupal_set_message(t('All AdvAgg cache bins have been cleared.'));
  621. }
  622. /**
  623. * Clear out all advagg cache bins and clear out all advagg aggregated files.
  624. */
  625. function advagg_admin_clear_all_files_button() {
  626. // Clear out the cache.
  627. advagg_admin_clear_all_caches_button();
  628. // Run the command.
  629. module_load_include('inc', 'advagg', 'advagg.cache');
  630. list($css_files, $js_files) = advagg_remove_all_aggregated_files();
  631. // Report back the results.
  632. drupal_set_message(t('All AdvAgg files have been deleted. %css_count CSS files and %js_count JS files have been removed.', array(
  633. '%css_count' => count($css_files),
  634. '%js_count' => count($js_files),
  635. )));
  636. }
  637. /**
  638. * Clear out all stale advagg aggregated files.
  639. */
  640. function advagg_admin_flush_stale_files_button() {
  641. // Run the command.
  642. module_load_include('inc', 'advagg', 'advagg.cache');
  643. list($css_files, $js_files) = advagg_delete_stale_aggregates();
  644. // Report back the results.
  645. if (count($css_files) > 0 || count($js_files) > 0) {
  646. drupal_set_message(t('All stale aggregates have been deleted. %css_count CSS files and %js_count JS files have been removed.', array(
  647. '%css_count' => count($css_files),
  648. '%js_count' => count($js_files),
  649. )));
  650. }
  651. else {
  652. drupal_set_message(t('No stale aggregates found. Nothing was deleted.'));
  653. }
  654. }
  655. /**
  656. * Clear out all advagg cache bins and increment the counter.
  657. */
  658. function advagg_admin_increment_global_counter() {
  659. // Clear out the cache.
  660. advagg_admin_clear_all_caches_button();
  661. // Increment counter.
  662. module_load_include('inc', 'advagg', 'advagg.cache');
  663. $new_value = advagg_increment_global_counter();
  664. drupal_set_message(t('Global counter is now set to %new_value', array('%new_value' => $new_value)));
  665. }
  666. /**
  667. * Scan for missing files and remove the associated entries in the database.
  668. */
  669. function advagg_admin_remove_missing_files_from_db_button() {
  670. module_load_include('inc', 'advagg', 'advagg.cache');
  671. // Remove aggregates that include missing files.
  672. $deleted = advagg_remove_missing_files_from_db();
  673. if (empty($deleted)) {
  674. drupal_set_message(t('No missing files found and/or could be safely cleared out of the database.'));
  675. }
  676. else {
  677. drupal_set_message(t('Some missing files were found and could be safely cleared out of the database. <pre> @raw </pre>', array('@raw' => print_r($deleted, TRUE))));
  678. }
  679. }
  680. /**
  681. * Delete aggregates that have not been accessed in the last 6 weeks.
  682. */
  683. function advagg_admin_remove_old_unused_aggregates_button() {
  684. module_load_include('inc', 'advagg', 'advagg.cache');
  685. // Remove unused aggregates.
  686. $count = advagg_remove_old_unused_aggregates();
  687. if (empty($count)) {
  688. drupal_set_message(t('No old and unused aggregates found. Nothing was deleted.'));
  689. }
  690. else {
  691. drupal_set_message(t('Some old and unused aggregates were found. A total of %count database entries were removed.', array('%count' => $count)));
  692. }
  693. }
  694. /**
  695. * Delete orphaned/expired advagg locks from the semaphore database table.
  696. */
  697. function advagg_admin_cleanup_semaphore_table_button() {
  698. module_load_include('inc', 'advagg', 'advagg.cache');
  699. // Delete orphaned/expired advagg locks from the semaphore database table.
  700. $count = advagg_cleanup_semaphore_table();
  701. if (empty($count)) {
  702. drupal_set_message(t('No orphaned advagg semaphore database table locks discovered. Nothing was deleted.'));
  703. }
  704. else {
  705. drupal_set_message(t('Some orphaned advagg semaphore database table locks discovered were found. A total of %count database entries were removed.', array('%count' => $count)));
  706. }
  707. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.