page_manager.module 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  1. <?php
  2. /**
  3. * @file
  4. * The page manager module provides a UI and API to manage pages.
  5. *
  6. * It defines pages, both for system pages, overrides of system pages, and
  7. * custom pages using Drupal's normal menu system. It allows complex
  8. * manipulations of these pages, their content, and their hierarchy within
  9. * the site. These pages can be exported to code for superior revision
  10. * control.
  11. */
  12. /**
  13. * Bit flag on the 'changed' value to tell us if an item was moved.
  14. */
  15. define('PAGE_MANAGER_CHANGED_MOVED', 0x01);
  16. /**
  17. * Bit flag on the 'changed' value to tell us if an item edited or added.
  18. */
  19. define('PAGE_MANAGER_CHANGED_CACHED', 0x02);
  20. /**
  21. * Bit flag on the 'changed' value to tell us if an item deleted.
  22. */
  23. define('PAGE_MANAGER_CHANGED_DELETED', 0x04);
  24. /**
  25. * Bit flag on the 'changed' value to tell us if an item has had its disabled status changed.
  26. */
  27. define('PAGE_MANAGER_CHANGED_STATUS', 0x08);
  28. // --------------------------------------------------------------------------
  29. // Drupal hooks
  30. /**
  31. * Implements hook_permission().
  32. */
  33. function page_manager_permission() {
  34. return array(
  35. 'use page manager' => array(
  36. 'title' => t('Use Page Manager'),
  37. 'description' => t("Allows users to use most of Page Manager's features, though restricts some of the most powerful, potentially site-damaging features. Note that even the reduced featureset still allows for enormous control over your website."),
  38. 'restrict access' => TRUE,
  39. ),
  40. 'administer page manager' => array(
  41. 'title' => t('Administer Page Manager'),
  42. 'description' => t('Allows complete control over Page Manager, i.e., complete control over your site. Grant with extreme caution.'),
  43. 'restrict access' => TRUE,
  44. ),
  45. );
  46. }
  47. /**
  48. * Implements hook_ctools_plugin_directory() to let the system know
  49. * where our task and task_handler plugins are.
  50. */
  51. function page_manager_ctools_plugin_directory($owner, $plugin_type) {
  52. if ($owner == 'page_manager') {
  53. return 'plugins/' . $plugin_type;
  54. }
  55. if ($owner == 'ctools' && $plugin_type == 'cache') {
  56. return 'plugins/' . $plugin_type;
  57. }
  58. }
  59. /**
  60. * Implements hook_ctools_plugin_type() to inform the plugin system that Page
  61. * Manager owns task, task_handler, and page_wizard plugin types.
  62. *
  63. * All of these are empty because the defaults all work.
  64. */
  65. function page_manager_ctools_plugin_type() {
  66. return array(
  67. 'tasks' => array(),
  68. 'task_handlers' => array(),
  69. 'page_wizards' => array(),
  70. );
  71. }
  72. /**
  73. * Delegated implementation of hook_menu().
  74. */
  75. function page_manager_menu() {
  76. // For some reason, some things can activate modules without satisfying
  77. // dependencies. I don't know how, but this helps prevent things from
  78. // whitescreening when this happens.
  79. if (!module_exists('ctools')) {
  80. return;
  81. }
  82. $items = array();
  83. $base = array(
  84. 'access arguments' => array('use page manager'),
  85. 'file' => 'page_manager.admin.inc',
  86. 'theme callback' => 'ajax_base_page_theme',
  87. );
  88. $items['admin/structure/pages'] = array(
  89. 'title' => 'Pages',
  90. 'description' => 'Add, edit and remove overridden system pages and user defined pages from the system.',
  91. 'page callback' => 'page_manager_list_page',
  92. ) + $base;
  93. $items['admin/structure/pages/list'] = array(
  94. 'title' => 'List',
  95. 'page callback' => 'page_manager_list_page',
  96. 'type' => MENU_DEFAULT_LOCAL_TASK,
  97. 'weight' => -10,
  98. ) + $base;
  99. $items['admin/structure/pages/edit/%page_manager_cache'] = array(
  100. 'title' => 'Edit',
  101. 'page callback' => 'page_manager_edit_page',
  102. 'page arguments' => array(4),
  103. 'type' => MENU_NORMAL_ITEM,
  104. ) + $base;
  105. $items['admin/structure/pages/%ctools_js/operation/%page_manager_cache'] = array(
  106. 'page callback' => 'page_manager_edit_page_operation',
  107. 'page arguments' => array(3, 5),
  108. 'type' => MENU_NORMAL_ITEM,
  109. ) + $base;
  110. $items['admin/structure/pages/%ctools_js/enable/%page_manager_cache'] = array(
  111. 'page callback' => 'page_manager_enable_page',
  112. 'page arguments' => array(FALSE, 3, 5),
  113. 'type' => MENU_CALLBACK,
  114. ) + $base;
  115. $items['admin/structure/pages/%ctools_js/disable/%page_manager_cache'] = array(
  116. 'page callback' => 'page_manager_enable_page',
  117. 'page arguments' => array(TRUE, 3, 5),
  118. 'type' => MENU_CALLBACK,
  119. ) + $base;
  120. $tasks = page_manager_get_tasks();
  121. // Provide menu items for each task.
  122. foreach ($tasks as $task_id => $task) {
  123. // Allow the task to add its own menu items.
  124. if ($function = ctools_plugin_get_function($task, 'hook menu')) {
  125. $function($items, $task);
  126. }
  127. // And for those that provide subtasks, provide menu items for them, as well.
  128. foreach (page_manager_get_task_subtasks($task) as $subtask_id => $subtask) {
  129. // Allow the task to add its own menu items.
  130. if ($function = ctools_plugin_get_function($task, 'hook menu')) {
  131. $function($items, $subtask);
  132. }
  133. }
  134. }
  135. return $items;
  136. }
  137. function page_manager_admin_paths() {
  138. /* @todo FIX ME this is a major resource suck. */
  139. return;
  140. $items = array();
  141. ctools_include('page', 'page_manager', 'plugins/tasks');
  142. $pages = page_manager_page_load_all();
  143. foreach ($pages as $page) {
  144. // Make sure the page we're on is set to be an administrative path and that
  145. // it is not set to be a frontpage path.
  146. if ((isset($page->conf['admin_paths']) && $page->conf['admin_paths']) && (!isset($page->make_frontpage) || !$page->make_frontpage)) {
  147. $path_parts = explode('/', $page->path);
  148. foreach ($path_parts as $key => $part) {
  149. if (strpos($part, '%') !== FALSE || strpos($part, '!') !== FALSE) {
  150. $path_parts[$key] = '*';
  151. }
  152. }
  153. $path = implode('/', $path_parts);
  154. if ($page->menu['type'] == 'default tab') {
  155. array_pop($path_parts);
  156. $parent_path = implode('/', $path_parts);
  157. $items[$parent_path] = TRUE;
  158. }
  159. $items[$path] = TRUE;
  160. }
  161. }
  162. return $items;
  163. }
  164. /**
  165. * Implements hook_menu_alter.
  166. *
  167. * Get a list of all tasks and delegate to them.
  168. */
  169. function page_manager_menu_alter(&$items) {
  170. // For some reason, some things can activate modules without satisfying
  171. // dependencies. I don't know how, but this helps prevent things from
  172. // whitescreening when this happens.
  173. if (!module_exists('ctools')) {
  174. return;
  175. }
  176. $tasks = page_manager_get_tasks();
  177. foreach ($tasks as $task) {
  178. if ($function = ctools_plugin_get_function($task, 'hook menu alter')) {
  179. $function($items, $task);
  180. }
  181. // let the subtasks alter the menu items too.
  182. foreach (page_manager_get_task_subtasks($task) as $subtask_id => $subtask) {
  183. if ($function = ctools_plugin_get_function($subtask, 'hook menu alter')) {
  184. $function($items, $subtask);
  185. }
  186. }
  187. }
  188. // Override the core node revisions display to use the configured Page
  189. // display handler.
  190. if (!variable_get('page_manager_node_view_disabled', TRUE) && isset($items['node/%node/revisions/%/view'])) {
  191. // Abstract the basic settings.
  192. $item = array(
  193. // Handle the page arguments.
  194. 'load arguments' => array(3),
  195. 'page arguments' => array(1, TRUE),
  196. // Replace the normal node_show call with Page Manager's node view.
  197. 'page callback' => 'page_manager_node_view_page',
  198. // Provide the correct path to the Page Manager file.
  199. 'file' => 'node_view.inc',
  200. 'file path' => drupal_get_path('module', 'page_manager') . '/plugins/tasks',
  201. );
  202. // Re-build the menu item using the normal values from node.module.
  203. $items['node/%node/revisions/%/view'] = array(
  204. 'title' => 'Revisions',
  205. 'access callback' => '_node_revision_access',
  206. 'access arguments' => array(1),
  207. ) + $item;
  208. }
  209. return $items;
  210. }
  211. /*
  212. * Implements hook_theme()
  213. */
  214. function page_manager_theme() {
  215. // For some reason, some things can activate modules without satisfying
  216. // dependencies. I don't know how, but this helps prevent things from
  217. // whitescreening when this happens.
  218. if (!module_exists('ctools')) {
  219. return;
  220. }
  221. $base = array(
  222. 'path' => drupal_get_path('module', 'page_manager') . '/theme',
  223. 'file' => 'page_manager.theme.inc',
  224. );
  225. $items = array(
  226. 'page_manager_handler_rearrange' => array(
  227. 'render element' => 'form',
  228. ) + $base,
  229. 'page_manager_edit_page' => array(
  230. 'template' => 'page-manager-edit-page',
  231. 'variables' => array('page' => NULL, 'save' => NULL, 'operations' => array(), 'content' => array()),
  232. ) + $base,
  233. 'page_manager_lock' => array(
  234. 'variables' => array('page' => array()),
  235. ) + $base,
  236. 'page_manager_changed' => array(
  237. 'variables' => array('text' => NULL, 'description' => NULL),
  238. ) + $base,
  239. );
  240. // Allow task plugins to have theme registrations by passing through:
  241. $tasks = page_manager_get_tasks();
  242. // Provide menu items for each task.
  243. foreach ($tasks as $task_id => $task) {
  244. if ($function = ctools_plugin_get_function($task, 'hook theme')) {
  245. $function($items, $task);
  246. }
  247. }
  248. return $items;
  249. }
  250. // --------------------------------------------------------------------------
  251. // Page caching
  252. //
  253. // The page cache is used to store a page temporarily, using the ctools object
  254. // cache. When loading from the page cache, it will either load the cached
  255. // version, or if there is not one, load the real thing and create a cache
  256. // object which can then be easily stored.
  257. /**
  258. * Get the cached changes to a given task handler.
  259. */
  260. function page_manager_get_page_cache($task_name) {
  261. $caches = drupal_static(__FUNCTION__, array());
  262. if (!isset($caches[$task_name])) {
  263. ctools_include('object-cache');
  264. $cache = ctools_object_cache_get('page_manager_page', $task_name);
  265. if (!$cache) {
  266. $cache = new stdClass();
  267. $cache->task_name = $task_name;
  268. list($cache->task_id, $cache->subtask_id) = page_manager_get_task_id($cache->task_name);
  269. $cache->task = page_manager_get_task($cache->task_id);
  270. if (empty($cache->task)) {
  271. return FALSE;
  272. }
  273. if ($cache->subtask_id) {
  274. $cache->subtask = page_manager_get_task_subtask($cache->task, $cache->subtask_id);
  275. if (empty($cache->subtask)) {
  276. return FALSE;
  277. }
  278. }
  279. else {
  280. $cache->subtask = $cache->task;
  281. $cache->subtask['name'] = '';
  282. }
  283. $cache->handlers = page_manager_load_sorted_handlers($cache->task, $cache->subtask_id);
  284. $cache->handler_info = array();
  285. foreach ($cache->handlers as $id => $handler) {
  286. $cache->handler_info[$id] = array(
  287. 'weight' => $handler->weight,
  288. 'changed' => FALSE,
  289. 'name' => $id,
  290. );
  291. }
  292. }
  293. else {
  294. // ensure the task is loaded.
  295. page_manager_get_task($cache->task_id);
  296. }
  297. if ($task_name != '::new') {
  298. $cache->locked = ctools_object_cache_test('page_manager_page', $task_name);
  299. }
  300. else {
  301. $cache->locked = FALSE;
  302. }
  303. $caches[$task_name] = $cache;
  304. }
  305. return $caches[$task_name];
  306. }
  307. /**
  308. * Store changes to a task handler in the object cache.
  309. */
  310. function page_manager_set_page_cache($page) {
  311. if (!empty($page->locked)) {
  312. return;
  313. }
  314. if (empty($page->task_name)) {
  315. return;
  316. }
  317. ctools_include('object-cache');
  318. $page->changed = TRUE;
  319. $cache = ctools_object_cache_set('page_manager_page', $page->task_name, $page);
  320. }
  321. /**
  322. * Remove an item from the object cache.
  323. */
  324. function page_manager_clear_page_cache($name) {
  325. ctools_include('object-cache');
  326. ctools_object_cache_clear('page_manager_page', $name);
  327. }
  328. /**
  329. * Write all changes from the page cache and clear it out.
  330. */
  331. function page_manager_save_page_cache($cache) {
  332. // Save the subtask:
  333. if ($function = ctools_plugin_get_function($cache->task, 'save subtask callback')) {
  334. $function($cache->subtask, $cache);
  335. }
  336. // Iterate through handlers and save/delete/update as necessary.
  337. // Go through each of the task handlers, check to see if it needs updating,
  338. // and update it if so.
  339. foreach ($cache->handler_info as $id => $info) {
  340. $handler = &$cache->handlers[$id];
  341. // If it has been marked for deletion, delete it.
  342. if ($info['changed'] & PAGE_MANAGER_CHANGED_DELETED) {
  343. page_manager_delete_task_handler($handler);
  344. }
  345. // If it has been somehow edited (or added), write the cached version
  346. elseif ($info['changed'] & PAGE_MANAGER_CHANGED_CACHED) {
  347. // Make sure we get updated weight from the form for this.
  348. $handler->weight = $info['weight'];
  349. page_manager_save_task_handler($handler);
  350. }
  351. // Otherwise, check to see if it has moved and, if so, update the weight.
  352. elseif ($info['weight'] != $handler->weight) {
  353. // Theoretically we could only do this for in code objects, but since our
  354. // load mechanism checks for all, this is less database work.
  355. page_manager_update_task_handler_weight($handler, $info['weight']);
  356. }
  357. // Set enable/disabled status.
  358. if ($info['changed'] & PAGE_MANAGER_CHANGED_STATUS) {
  359. ctools_include('export');
  360. ctools_export_set_object_status($cache->handlers[$id], $info['disabled']);
  361. }
  362. }
  363. page_manager_clear_page_cache($cache->task_name);
  364. if (!empty($cache->path_changed) || !empty($cache->new)) {
  365. // Force a menu rebuild to make sure the menu entries are set.
  366. menu_rebuild();
  367. }
  368. cache_clear_all();
  369. }
  370. /**
  371. * Menu callback to load a page manager cache object for menu callbacks.
  372. */
  373. function page_manager_cache_load($task_name) {
  374. // load context plugin as there may be contexts cached here.
  375. ctools_include('context');
  376. return page_manager_get_page_cache($task_name);
  377. }
  378. /**
  379. * Generate a unique name for a task handler.
  380. *
  381. * Task handlers need to be named but they aren't allowed to set their own
  382. * names. Instead, they are named based upon their parent task and type.
  383. */
  384. function page_manager_handler_get_name($task_name, $handlers, $handler) {
  385. $base = str_replace('-', '_', $task_name);
  386. $name = '';
  387. // Optional machine name.
  388. if (!empty($handler->conf['name'])) {
  389. $name = $base . '__' . $handler->conf['name'];
  390. if (count(ctools_export_load_object('page_manager_handlers', 'names', array($name)))) {
  391. $name = '';
  392. }
  393. }
  394. // If no machine name was provided or the name is in use, generate a unique name.
  395. if (empty($name)) {
  396. $base .= '__' . $handler->handler;
  397. // Use the ctools uuid generator to generate a unique id.
  398. $name = $base . '_' . ctools_uuid_generate();
  399. }
  400. return $name;
  401. }
  402. /**
  403. * Import a handler into a page.
  404. *
  405. * This is used by both import and clone, since clone just exports the
  406. * handler and immediately imports it.
  407. */
  408. function page_manager_handler_add_to_page(&$page, &$handler, $title = NULL) {
  409. $last = end($page->handler_info);
  410. $handler->weight = $last ? $last['weight'] + 1 : 0;
  411. $handler->task = $page->task_id;
  412. $handler->subtask = $page->subtask_id;
  413. $handler->export_type = EXPORT_IN_DATABASE;
  414. $handler->type = t('Normal');
  415. if ($title) {
  416. $handler->conf['title'] = $title;
  417. $handler->conf['name'] = trim(preg_replace('/[^a-z0-9_]+/', '-', strtolower($title)), '-');
  418. }
  419. else {
  420. $handler->conf['name'] = '';
  421. }
  422. $name = page_manager_handler_get_name($page->task_name, $page->handlers, $handler);
  423. $handler->name = $name;
  424. $page->handlers[$name] = $handler;
  425. $page->handler_info[$name] = array(
  426. 'weight' => $handler->weight,
  427. 'name' => $handler->name,
  428. 'changed' => PAGE_MANAGER_CHANGED_CACHED,
  429. );
  430. }
  431. // --------------------------------------------------------------------------
  432. // Database routines
  433. //
  434. // This includes fetching plugins and plugin info as well as specialized
  435. // fetch methods to get groups of task handlers per task.
  436. /**
  437. * Load a single task handler by name.
  438. *
  439. * Handlers can come from multiple sources; either the database or by normal
  440. * export method, which is handled by the ctools library, but handlers can
  441. * also be bundled with task/subtask. We have to check there and perform
  442. * overrides as appropriate.
  443. *
  444. * Handlers bundled with the task are of a higher priority than default
  445. * handlers provided by normal code, and are of a lower priority than
  446. * the database, so we have to check the source of handlers when we have
  447. * multiple to choose from.
  448. */
  449. function page_manager_load_task_handler($task, $subtask_id, $name) {
  450. ctools_include('export');
  451. $result = ctools_export_load_object('page_manager_handlers', 'names', array($name));
  452. $handlers = page_manager_get_default_task_handlers($task, $subtask_id);
  453. return page_manager_compare_task_handlers($result, $handlers, $name);
  454. }
  455. /**
  456. * Load all task handlers for a given task/subtask.
  457. */
  458. function page_manager_load_task_handlers($task, $subtask_id = NULL, $default_handlers = NULL) {
  459. ctools_include('export');
  460. $conditions = array(
  461. 'task' => $task['name'],
  462. );
  463. if (isset($subtask_id)) {
  464. $conditions['subtask'] = $subtask_id;
  465. }
  466. $handlers = ctools_export_load_object('page_manager_handlers', 'conditions', $conditions);
  467. $defaults = isset($default_handlers) ? $default_handlers : page_manager_get_default_task_handlers($task, $subtask_id);
  468. foreach ($defaults as $name => $default) {
  469. $result = page_manager_compare_task_handlers($handlers, $defaults, $name);
  470. if ($result) {
  471. $handlers[$name] = $result;
  472. // Ensure task and subtask are correct, because it's easy to change task
  473. // names when editing a default and fail to do it on the associated handlers.
  474. $result->task = $task['name'];
  475. $result->subtask = $subtask_id;
  476. }
  477. }
  478. // Override weights from the weight table.
  479. if ($handlers) {
  480. $names = array();
  481. $placeholders = array();
  482. foreach ($handlers as $handler) {
  483. $names[] = $handler->name;
  484. $placeholders[] = "'%s'";
  485. }
  486. $result = db_query('SELECT name, weight FROM {page_manager_weights} WHERE name IN (:names)', array(':names' => $names));
  487. foreach ($result as $weight) {
  488. $handlers[$weight->name]->weight = $weight->weight;
  489. }
  490. }
  491. return $handlers;
  492. }
  493. /**
  494. * Get the default task handlers from a task, if they exist.
  495. *
  496. * Tasks can contain 'default' task handlers which are provided by the
  497. * default task. Because these can come from either the task or the
  498. * subtask, the logic is abstracted to reduce code duplication.
  499. */
  500. function page_manager_get_default_task_handlers($task, $subtask_id) {
  501. // Load default handlers that are provied by the task/subtask itself.
  502. $handlers = array();
  503. if ($subtask_id) {
  504. $subtask = page_manager_get_task_subtask($task, $subtask_id);
  505. if (isset($subtask['default handlers'])) {
  506. $handlers = $subtask['default handlers'];
  507. }
  508. }
  509. else if (isset($task['default handlers'])) {
  510. $handlers = $task['default handlers'];
  511. }
  512. return $handlers;
  513. }
  514. /**
  515. * Compare a single task handler from two lists and provide the correct one.
  516. *
  517. * Task handlers can be gotten from multiple sources. As exportable objects,
  518. * they can be provided by default hooks and the database. But also, because
  519. * they are tightly bound to tasks, they can also be provided by default
  520. * tasks. This function reconciles where to pick up a task handler between
  521. * the exportables list and the defaults provided by the task itself.
  522. *
  523. * @param $result
  524. * A list of handlers provided by export.inc
  525. * @param $handlers
  526. * A list of handlers provided by the default task.
  527. * @param $name
  528. * Which handler to compare.
  529. * @return
  530. * Which handler to use, if any. May be NULL.
  531. */
  532. function page_manager_compare_task_handlers($result, $handlers, $name) {
  533. // Compare our special default handler against the actual result, if
  534. // any, and do the right thing.
  535. if (!isset($result[$name]) && isset($handlers[$name])) {
  536. $handlers[$name]->type = t('Default');
  537. $handlers[$name]->export_type = EXPORT_IN_CODE;
  538. return $handlers[$name];
  539. }
  540. else if (isset($result[$name]) && !isset($handlers[$name])) {
  541. return $result[$name];
  542. }
  543. else if (isset($result[$name]) && isset($handlers[$name])) {
  544. if ($result[$name]->export_type & EXPORT_IN_DATABASE) {
  545. $result[$name]->type = t('Overridden');
  546. $result[$name]->export_type = $result[$name]->export_type | EXPORT_IN_CODE;
  547. return $result[$name];
  548. }
  549. else {
  550. // In this case, our default is a higher priority than the standard default.
  551. $handlers[$name]->type = t('Default');
  552. $handlers[$name]->export_type = EXPORT_IN_CODE;
  553. return $handlers[$name];
  554. }
  555. }
  556. }
  557. /**
  558. * Load all task handlers for a given task and subtask and sort them.
  559. */
  560. function page_manager_load_sorted_handlers($task, $subtask_id = NULL, $enabled = FALSE) {
  561. $handlers = page_manager_load_task_handlers($task, $subtask_id);
  562. if ($enabled) {
  563. foreach ($handlers as $id => $handler) {
  564. if (!empty($handler->disabled)) {
  565. unset($handlers[$id]);
  566. }
  567. }
  568. }
  569. uasort($handlers, 'page_manager_sort_task_handlers');
  570. return $handlers;
  571. }
  572. /**
  573. * Callback for uasort to sort task handlers.
  574. *
  575. * Task handlers are sorted by weight then by name.
  576. */
  577. function page_manager_sort_task_handlers($a, $b) {
  578. if ($a->weight < $b->weight) {
  579. return -1;
  580. }
  581. elseif ($a->weight > $b->weight) {
  582. return 1;
  583. }
  584. elseif ($a->name < $b->name) {
  585. return -1;
  586. }
  587. elseif ($a->name > $b->name) {
  588. return 1;
  589. }
  590. return 0;
  591. }
  592. /**
  593. * Write a task handler to the database.
  594. */
  595. function page_manager_save_task_handler(&$handler) {
  596. $update = (isset($handler->did)) ? array('did') : array();
  597. // Let the task handler respond to saves:
  598. if ($function = ctools_plugin_load_function('page_manager', 'task_handlers', $handler->handler, 'save')) {
  599. $function($handler, $update);
  600. }
  601. drupal_write_record('page_manager_handlers', $handler, $update);
  602. db_delete('page_manager_weights')
  603. ->condition('name', $handler->name)
  604. ->execute();
  605. // If this was previously a default handler, we may have to write task handlers.
  606. if (!$update) {
  607. // @todo wtf was I going to do here?
  608. }
  609. return $handler;
  610. }
  611. /**
  612. * Remove a task handler.
  613. */
  614. function page_manager_delete_task_handler($handler) {
  615. // Let the task handler respond to saves:
  616. if ($function = ctools_plugin_load_function('page_manager', 'task_handlers', $handler->handler, 'delete')) {
  617. $function($handler);
  618. }
  619. db_delete('page_manager_handlers')
  620. ->condition('name', $handler->name)
  621. ->execute();
  622. db_delete('page_manager_weights')
  623. ->condition('name', $handler->name)
  624. ->execute();
  625. }
  626. /**
  627. * Export a task handler into code suitable for import or use as a default
  628. * task handler.
  629. */
  630. function page_manager_export_task_handler($handler, $indent = '') {
  631. ctools_include('export');
  632. ctools_include('plugins');
  633. $handler = clone $handler;
  634. $append = '';
  635. if ($function = ctools_plugin_load_function('page_manager', 'task_handlers', $handler->handler, 'export')) {
  636. $append = $function($handler, $indent);
  637. }
  638. $output = ctools_export_object('page_manager_handlers', $handler, $indent);
  639. $output .= $append;
  640. return $output;
  641. }
  642. /**
  643. * Loads page manager handler for export.
  644. *
  645. * Callback to load page manager handler within ctools_export_crud_load().
  646. *
  647. * @param string $name
  648. * The name of the handler to load.
  649. *
  650. * @return
  651. * Loaded page manager handler object, extended with external properties.
  652. */
  653. function page_manager_export_task_handler_load($name) {
  654. $table = 'page_manager_handlers';
  655. $schema = ctools_export_get_schema($table);
  656. $export = $schema['export'];
  657. $result = ctools_export_load_object($table, 'names', array($name));
  658. if (isset($result[$name])) {
  659. $handler = $result[$name];
  660. // Weight is stored in additional table so that in-code task handlers
  661. // don't need to get written to the database just because they have their
  662. // weight changed. Therefore, handler could have no correspondent database
  663. // entry. Revert will not be performed for this handler and the weight
  664. // will not be reverted. To make possible revert of the weight field
  665. // export_type must simulate that the handler is stored in the database.
  666. $handler->export_type = EXPORT_IN_DATABASE;
  667. // Also, page manager handler weight should be overriden with correspondent
  668. // weight from page_manager_weights table, if there is one.
  669. $result = db_query('SELECT weight FROM {page_manager_weights} WHERE name = (:names)', array(':names' => $handler->name))->fetchField();
  670. if (is_numeric($result)) {
  671. $handler->weight = $result;
  672. }
  673. return $handler;
  674. }
  675. }
  676. /**
  677. * Create a new task handler object.
  678. *
  679. * @param $plugin
  680. * The plugin this task handler is created from.
  681. */
  682. function page_manager_new_task_handler($plugin) {
  683. // Generate a unique name. Unlike most named objects, we don't let people choose
  684. // names for task handlers because they mostly don't make sense.
  685. // Create a new, empty handler object.
  686. $handler = new stdClass;
  687. $handler->title = $plugin['title'];
  688. $handler->task = NULL;
  689. $handler->subtask = NULL;
  690. $handler->name = NULL;
  691. $handler->handler = $plugin['name'];
  692. $handler->weight = 0;
  693. $handler->conf = array();
  694. // These are provided by the core export API provided by ctools and we
  695. // set defaults here so that we don't cause notices. Perhaps ctools should
  696. // provide a way to do this for us so we don't have to muck with it.
  697. $handler->export_type = EXPORT_IN_DATABASE;
  698. $handler->type = t('Local');
  699. if (isset($plugin['default conf'])) {
  700. if (is_array($plugin['default conf'])) {
  701. $handler->conf = $plugin['default conf'];
  702. }
  703. else if (function_exists($plugin['default conf'])) {
  704. $handler->conf = $plugin['default conf']($handler);
  705. }
  706. }
  707. return $handler;
  708. }
  709. /**
  710. * Set an overidden weight for a task handler.
  711. *
  712. * We do this so that in-code task handlers don't need to get written
  713. * to the database just because they have their weight changed.
  714. */
  715. function page_manager_update_task_handler_weight($handler, $weight) {
  716. db_delete('page_manager_weights')
  717. ->condition('name', $handler->name)
  718. ->execute();
  719. db_insert('page_manager_weights')
  720. ->fields(array(
  721. 'name' => $handler->name,
  722. 'weight' => $weight,
  723. ))
  724. ->execute();
  725. }
  726. /**
  727. * Shortcut function to get task plugins.
  728. */
  729. function page_manager_get_tasks() {
  730. ctools_include('plugins');
  731. return ctools_get_plugins('page_manager', 'tasks');
  732. }
  733. /**
  734. * Shortcut function to get a task plugin.
  735. */
  736. function page_manager_get_task($id) {
  737. ctools_include('plugins');
  738. return ctools_get_plugins('page_manager', 'tasks', $id);
  739. }
  740. /**
  741. * Get all tasks for a given type.
  742. */
  743. function page_manager_get_tasks_by_type($type) {
  744. ctools_include('plugins');
  745. $all_tasks = ctools_get_plugins('page_manager', 'tasks');
  746. $tasks = array();
  747. foreach ($all_tasks as $id => $task) {
  748. if (isset($task['task type']) && $task['task type'] == $type) {
  749. $tasks[$id] = $task;
  750. }
  751. }
  752. return $tasks;
  753. }
  754. /**
  755. * Fetch all subtasks for a page managertask.
  756. *
  757. * @param $task
  758. * A loaded $task plugin object.
  759. */
  760. function page_manager_get_task_subtasks($task) {
  761. if (empty($task['subtasks'])) {
  762. return array();
  763. }
  764. if ($function = ctools_plugin_get_function($task, 'subtasks callback')) {
  765. $retval = $function($task);
  766. if (is_array($retval)) {
  767. return $retval;
  768. }
  769. }
  770. return array();
  771. }
  772. /**
  773. * Fetch all subtasks for a page managertask.
  774. *
  775. * @param $task
  776. * A loaded $task plugin object.
  777. * @param $subtask_id
  778. * The subtask ID to load.
  779. */
  780. function page_manager_get_task_subtask($task, $subtask_id) {
  781. if (empty($task['subtasks'])) {
  782. return;
  783. }
  784. if ($function = ctools_plugin_get_function($task, 'subtask callback')) {
  785. return $function($task, $subtask_id);
  786. }
  787. }
  788. /**
  789. * Shortcut function to get task handler plugins.
  790. */
  791. function page_manager_get_task_handlers() {
  792. ctools_include('plugins');
  793. return ctools_get_plugins('page_manager', 'task_handlers');
  794. }
  795. /**
  796. * Shortcut function to get a task handler plugin.
  797. */
  798. function page_manager_get_task_handler($id) {
  799. ctools_include('plugins');
  800. return ctools_get_plugins('page_manager', 'task_handlers', $id);
  801. }
  802. /**
  803. * Retrieve a list of all applicable task handlers for a given task.
  804. *
  805. * This looks at the $task['handler type'] and compares that to $task_handler['handler type'].
  806. * If the task has no type, the id of the task is used instead.
  807. */
  808. function page_manager_get_task_handler_plugins($task, $all = FALSE) {
  809. $type = isset($task['handler type']) ? $task['handler type'] : $task['name'];
  810. $name = $task['name'];
  811. $handlers = array();
  812. $task_handlers = page_manager_get_task_handlers();
  813. foreach ($task_handlers as $id => $handler) {
  814. $task_type = is_array($handler['handler type']) ? $handler['handler type'] : array($handler['handler type']);
  815. if (in_array($type, $task_type) || in_array($name, $task_type)) {
  816. if ($all || !empty($handler['visible'])) {
  817. $handlers[$id] = $handler;
  818. }
  819. }
  820. }
  821. return $handlers;
  822. }
  823. /**
  824. * Get the title for a given handler.
  825. *
  826. * If the plugin has no 'admin title' function, the generic title of the
  827. * plugin is used instead.
  828. */
  829. function page_manager_get_handler_title($plugin, $handler, $task, $subtask_id) {
  830. $function = ctools_plugin_get_function($plugin, 'admin title');
  831. if ($function) {
  832. return $function($handler, $task, $subtask_id);
  833. }
  834. else {
  835. return $plugin['title'];
  836. }
  837. }
  838. /**
  839. * Get the admin summary (additional info) for a given handler.
  840. */
  841. function page_manager_get_handler_summary($plugin, $handler, $page, $title = TRUE) {
  842. if ($function = ctools_plugin_get_function($plugin, 'admin summary')) {
  843. return $function($handler, $page->task, $page->subtask, $page, $title);
  844. }
  845. }
  846. /**
  847. * Get the admin summary (additional info) for a given page.
  848. */
  849. function page_manager_get_page_summary($task, $subtask) {
  850. if ($function = ctools_plugin_get_function($subtask, 'admin summary')) {
  851. return $function($task, $subtask);
  852. }
  853. }
  854. /**
  855. * Split a task name into a task id and subtask id, if applicable.
  856. */
  857. function page_manager_get_task_id($task_name) {
  858. if (strpos($task_name, '-') !== FALSE) {
  859. return explode('-', $task_name, 2);
  860. }
  861. else {
  862. return array($task_name, NULL);
  863. }
  864. }
  865. /**
  866. * Turn a task id + subtask_id into a task name.
  867. */
  868. function page_manager_make_task_name($task_id, $subtask_id) {
  869. if ($subtask_id) {
  870. return $task_id . '-' . $subtask_id;
  871. }
  872. else {
  873. return $task_id;
  874. }
  875. }
  876. /**
  877. * Get the render function for a handler.
  878. */
  879. function page_manager_get_renderer($handler) {
  880. return ctools_plugin_load_function('page_manager', 'task_handlers', $handler->handler, 'render');
  881. }
  882. // --------------------------------------------------------------------------
  883. // Functions existing on behalf of tasks and task handlers
  884. /**
  885. * Page manager arg load function because menu system will not load extra
  886. * files for these; they must be in a .module.
  887. */
  888. function pm_arg_load($value, $subtask, $argument) {
  889. page_manager_get_task('page');
  890. return _pm_arg_load($value, $subtask, $argument);
  891. }
  892. /**
  893. * Special arg_load function to use %menu_tail like functionality to
  894. * get everything after the arg together as a single value.
  895. */
  896. function pm_arg_tail_load($value, $subtask, $argument, $map) {
  897. $value = implode('/', array_slice($map, $argument));
  898. page_manager_get_task('page');
  899. return _pm_arg_load($value, $subtask, $argument);
  900. }
  901. /**
  902. * Special menu _load() function for the user:uid argument.
  903. *
  904. * This is just the normal page manager argument. It only exists so that
  905. * the to_arg can exist.
  906. */
  907. function pm_uid_arg_load($value, $subtask, $argument) {
  908. page_manager_get_task('page');
  909. return _pm_arg_load($value, $subtask, $argument);
  910. }
  911. /**
  912. * to_arg function for the user:uid argument to provide the arg for the
  913. * current global user.
  914. */
  915. function pm_uid_arg_to_arg($arg) {
  916. return user_uid_optional_to_arg($arg);
  917. }
  918. /**
  919. * Callback for access control ajax form on behalf of page.inc task.
  920. *
  921. * Returns the cached access config and contexts used.
  922. */
  923. function page_manager_page_ctools_access_get($argument) {
  924. $page = page_manager_get_page_cache($argument);
  925. $contexts = array();
  926. // Load contexts based on argument data:
  927. if ($arguments = _page_manager_page_get_arguments($page->subtask['subtask'])) {
  928. $contexts = ctools_context_get_placeholders_from_argument($arguments);
  929. }
  930. return array($page->subtask['subtask']->access, $contexts);
  931. }
  932. /**
  933. * Callback for access control ajax form on behalf of page.inc task.
  934. *
  935. * Writes the changed access to the cache.
  936. */
  937. function page_manager_page_ctools_access_set($argument, $access) {
  938. $page = page_manager_get_page_cache($argument);
  939. $page->subtask['subtask']->access = $access;
  940. page_manager_set_page_cache($page);
  941. }
  942. /**
  943. * Callback for access control ajax form on behalf of context task handler.
  944. *
  945. * Returns the cached access config and contexts used.
  946. */
  947. function page_manager_task_handler_ctools_access_get($argument) {
  948. list($task_name, $name) = explode('*', $argument);
  949. $page = page_manager_get_page_cache($task_name);
  950. if (empty($name)) {
  951. $handler = &$page->new_handler;
  952. }
  953. else {
  954. $handler = &$page->handlers[$name];
  955. }
  956. if (!isset($handler->conf['access'])) {
  957. $handler->conf['access'] = array();
  958. }
  959. ctools_include('context-task-handler');
  960. $contexts = ctools_context_handler_get_all_contexts($page->task, $page->subtask, $handler);
  961. return array($handler->conf['access'], $contexts);
  962. }
  963. /**
  964. * Callback for access control ajax form on behalf of context task handler.
  965. *
  966. * Writes the changed access to the cache.
  967. */
  968. function page_manager_task_handler_ctools_access_set($argument, $access) {
  969. list($task_name, $name) = explode('*', $argument);
  970. $page = page_manager_get_page_cache($task_name);
  971. if (empty($name)) {
  972. $handler = &$page->new_handler;
  973. }
  974. else {
  975. $handler = &$page->handlers[$name];
  976. }
  977. $handler->conf['access'] = $access;
  978. page_manager_set_page_cache($page);
  979. }
  980. /**
  981. * Form a URL to edit a given page given the trail.
  982. */
  983. function page_manager_edit_url($task_name, $trail = array()) {
  984. if (!is_array($trail)) {
  985. $trail = array($trail);
  986. }
  987. if (empty($trail) || $trail == array('summary')) {
  988. return "admin/structure/pages/edit/$task_name";
  989. }
  990. return 'admin/structure/pages/nojs/operation/' . $task_name . '/' . implode('/', $trail);
  991. }
  992. /**
  993. * Watch menu links during the menu rebuild, and re-parent things if we need to.
  994. */
  995. function page_manager_menu_link_alter(&$item) {
  996. return;
  997. /** -- disabled, concept code --
  998. static $mlids = array();
  999. // Keep an array of mlids as links are saved that we can use later.
  1000. if (isset($item['mlid'])) {
  1001. $mlids[$item['path']] = $item['mlid'];
  1002. }
  1003. if (isset($item['parent_path'])) {
  1004. if (isset($mlids[$item['parent_path']])) {
  1005. $item['plid'] = $mlids[$item['parent_path']];
  1006. }
  1007. else {
  1008. // Since we didn't already see an mlid, let's check the database for one.
  1009. $mlid = db_query('SELECT mlid FROM {menu_links} WHERE router_path = :path', array('path' => $item['parent_path']))->fetchField();
  1010. if ($mlid) {
  1011. $item['plid'] = $mlid;
  1012. }
  1013. }
  1014. }
  1015. */
  1016. }
  1017. /**
  1018. * Callback to list handlers available for export.
  1019. */
  1020. function page_manager_page_manager_handlers_list() {
  1021. $list = $types = array();
  1022. $tasks = page_manager_get_tasks();
  1023. foreach ($tasks as $type => $info) {
  1024. if (empty($info['non-exportable'])) {
  1025. $types[] = $type;
  1026. }
  1027. }
  1028. $handlers = ctools_export_load_object('page_manager_handlers');
  1029. foreach ($handlers as $handler) {
  1030. if (in_array($handler->task, $types)) {
  1031. $plugin = page_manager_get_task_handler($handler->handler);
  1032. $title = page_manager_get_handler_title($plugin, $handler, $tasks[$handler->task], $handler->subtask);
  1033. if ($title) {
  1034. $list[$handler->name] = check_plain("$handler->task: $title ($handler->name)");
  1035. }
  1036. else {
  1037. $list[$handler->name] = check_plain("$handler->task: ($handler->name)");
  1038. }
  1039. }
  1040. }
  1041. return $list;
  1042. }
  1043. /**
  1044. * Callback to bulk export page manager pages.
  1045. */
  1046. function page_manager_page_manager_pages_to_hook_code($names = array(), $name = 'foo') {
  1047. $schema = ctools_export_get_schema('page_manager_pages');
  1048. $export = $schema['export'];
  1049. $objects = ctools_export_load_object('page_manager_pages', 'names', array_values($names));
  1050. if ($objects) {
  1051. $code = "/**\n";
  1052. $code .= " * Implements hook_{$export['default hook']}()\n";
  1053. $code .= " */\n";
  1054. $code .= "function " . $name . "_{$export['default hook']}() {\n";
  1055. foreach ($objects as $object) {
  1056. // Have to implement our own because this export func sig requires it
  1057. $code .= $export['export callback']($object, TRUE, ' ');
  1058. $code .= " \${$export['identifier']}s['" . check_plain($object->{$export['key']}) . "'] = \${$export['identifier']};\n\n";
  1059. }
  1060. $code .= " return \${$export['identifier']}s;\n";
  1061. $code .= "}\n";
  1062. return $code;
  1063. }
  1064. }
  1065. /**
  1066. * Get the current page information.
  1067. *
  1068. * @return $page
  1069. * An array containing the following information.
  1070. *
  1071. * - 'name': The name of the page as used in the page manager admin UI.
  1072. * - 'task': The plugin for the task in use. If this is a system page it
  1073. * will contain information about that page, such as what functions
  1074. * it uses.
  1075. * - 'subtask': The plugin for the subtask. If this is a custom page, this
  1076. * will contain information about that custom page. See 'subtask' in this
  1077. * array to get the actual page object.
  1078. * - 'handler': The actual handler object used. If using panels, see
  1079. * $page['handler']->conf['display'] for the actual panels display
  1080. * used to render.
  1081. * - 'contexts': The context objects used to render this page.
  1082. * - 'arguments': The raw arguments from the URL used on this page.
  1083. */
  1084. function page_manager_get_current_page($page = NULL) {
  1085. static $current = array();
  1086. if (isset($page)) {
  1087. $current = $page;
  1088. }
  1089. return $current;
  1090. }
  1091. /**
  1092. * Implementation of hook_panels_dashboard_blocks().
  1093. *
  1094. * Adds page information to the Panels dashboard.
  1095. */
  1096. function page_manager_panels_dashboard_blocks(&$vars) {
  1097. $vars['links']['page_manager'] = array(
  1098. 'weight' => -100,
  1099. 'title' => l(t('Panel page'), 'admin/structure/pages/add'),
  1100. 'description' => t('Panel pages can be used as landing pages. They have a URL path, accept arguments and can have menu entries.'),
  1101. );
  1102. module_load_include('inc', 'page_manager', 'page_manager.admin');
  1103. $tasks = page_manager_get_tasks_by_type('page');
  1104. $pages = array('operations' => array());
  1105. page_manager_get_pages($tasks, $pages);
  1106. $count = 0;
  1107. $rows = array();
  1108. foreach ($pages['rows'] as $id => $info) {
  1109. $rows[] = array(
  1110. 'data' => array(
  1111. $info['data']['title'],
  1112. $info['data']['operations'],
  1113. ),
  1114. 'class' => $info['class'],
  1115. );
  1116. // Only show 10.
  1117. if (++$count >= 10) {
  1118. break;
  1119. }
  1120. }
  1121. $vars['blocks']['page_manager'] = array(
  1122. 'weight' => -100,
  1123. 'title' => t('Manage pages'),
  1124. 'link' => l(t('Go to list'), 'admin/structure/pages'),
  1125. 'content' => theme('table', array('header' => array(), 'rows' => $rows, 'attributes' => array('class' => 'panels-manage'))),
  1126. 'class' => 'dashboard-pages',
  1127. 'section' => 'right',
  1128. );
  1129. }
  1130. /**
  1131. * Implement pseudo-hook to fetch addressable content.
  1132. *
  1133. * For Page Manager, the address will be an array. The first
  1134. * element will be the $task and the second element will be the
  1135. * $task_handler. The third elements will be the arguments
  1136. * provided.
  1137. */
  1138. function page_manager_addressable_content($address, $type) {
  1139. if (count($address) < 3) {
  1140. return;
  1141. }
  1142. $task_name = array_shift($address);
  1143. $subtask_name = array_shift($address);
  1144. $handler_name = array_shift($address);
  1145. if ($address) {
  1146. $arguments = array_shift($address);
  1147. }
  1148. // Since $arguments is an array of arbitrary size, we need to implode it:
  1149. if (!empty($arguments)) {
  1150. // The only choices we have for separators since :: is already
  1151. // used involve ., - or _. Since - and _ are more common than .
  1152. // in URLs, let's try .. as an argument separator.
  1153. $arguments = explode('..', $arguments);
  1154. }
  1155. else {
  1156. // implode does not return an empty array on an empty
  1157. // string so do it specifically.
  1158. $arguments = array();
  1159. }
  1160. $task = page_manager_get_task($task_name);
  1161. if (!$task) {
  1162. return;
  1163. }
  1164. $handler = page_manager_load_task_handler($task, $subtask_name, $handler_name);
  1165. if (!$handler) {
  1166. return;
  1167. }
  1168. $handler_plugin = page_manager_get_task_handler($handler->handler);
  1169. if (!$handler_plugin) {
  1170. return;
  1171. }
  1172. // Load the contexts for the task.
  1173. ctools_include('context');
  1174. ctools_include('context-task-handler');
  1175. $contexts = ctools_context_handler_get_task_contexts($task, $subtask_name, $arguments);
  1176. // With contexts loaded, ensure the task is accessible. Tasks without a callback
  1177. // are automatically accessible.
  1178. $function = ctools_plugin_get_function($task, 'access callback');
  1179. if ($function && !$function($task, $subtask_name, $contexts)) {
  1180. return;
  1181. }
  1182. $function = ctools_plugin_get_function($handler_plugin, 'addressable callback');
  1183. if ($function) {
  1184. return $function($task, $subtask_name, $handler, $address, $contexts, $arguments, $type);
  1185. }
  1186. }