panels.module 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021
  1. <?php
  2. /**
  3. * @file panels.module
  4. *
  5. * Core functionality for the Panels engine.
  6. */
  7. define('PANELS_REQUIRED_CTOOLS_API', '2.0.8');
  8. /**
  9. * The current working panels version.
  10. *
  11. * In a release, it should be 7.x-3.x, which should match what drush make will
  12. * create. In a dev format, it should be 7.x-3.(x+1)-dev, which will allow
  13. * modules depending on new features in panels to depend on panels > 7.x-3.x.
  14. *
  15. * To define a specific version of Panels as a dependency for another module,
  16. * simply include a dependency line in that module's info file, e.g.:
  17. * ; Requires Panels v7.x-3.4 or newer.
  18. * dependencies[] = panels (>=3.4)
  19. */
  20. define('PANELS_VERSION', '7.x-3.6');
  21. define('PANELS_TITLE_FIXED', 0); // Hide title use to be true/false. So false remains old behavior.
  22. define('PANELS_TITLE_NONE', 1); // And true meant no title.
  23. define('PANELS_TITLE_PANE', 2); // And this is the new behavior, where the title field will pick from a pane.
  24. /**
  25. * Returns the API version of Panels. This didn't exist in 1.
  26. *
  27. * @todo -- this should work more like the CTools API version.
  28. *
  29. * @return An array with the major and minor versions
  30. */
  31. function panels_api_version() {
  32. return array(3, 1);
  33. }
  34. // --------------------------------------------------------------------------
  35. // Core Drupal hook implementations
  36. /**
  37. * Implementation of hook_theme()
  38. */
  39. function panels_theme() {
  40. // Safety: go away if CTools is not at an appropriate version.
  41. if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
  42. return array();
  43. }
  44. $theme = array();
  45. $theme['panels_layout_link'] = array(
  46. 'variables' => array('title' => NULL, 'id' => NULL, 'image' => NULL, 'link' => NULL, 'class' => NULL),
  47. );
  48. $theme['panels_layout_icon'] = array(
  49. 'variables' => array('id' => NULL, 'image' => NULL, 'title' => NULL),
  50. );
  51. $theme['panels_pane'] = array(
  52. 'variables' => array('content' => array(), 'pane' => array(), 'display' => array()),
  53. 'path' => drupal_get_path('module', 'panels') . '/templates',
  54. 'template' => 'panels-pane',
  55. );
  56. $theme['panels_common_content_list'] = array(
  57. 'variables' => array('display' => NULL),
  58. 'file' => 'includes/common.inc',
  59. );
  60. $theme['panels_render_display_form'] = array(
  61. 'render element' => 'element',
  62. );
  63. $theme['panels_dashboard'] = array(
  64. 'variables' => array(),
  65. 'path' => drupal_get_path('module', 'panels') . '/templates',
  66. 'file' => '../includes/callbacks.inc',
  67. 'template' => 'panels-dashboard',
  68. );
  69. $theme['panels_dashboard_link'] = array(
  70. 'variables' => array('link' => array()),
  71. 'path' => drupal_get_path('module', 'panels') . '/templates',
  72. 'file' => '../includes/callbacks.inc',
  73. 'template' => 'panels-dashboard-link',
  74. );
  75. $theme['panels_dashboard_block'] = array(
  76. 'variables' => array('block' => array()),
  77. 'path' => drupal_get_path('module', 'panels') . '/templates',
  78. 'file' => '../includes/callbacks.inc',
  79. 'template' => 'panels-dashboard-block',
  80. );
  81. $theme['panels_add_content_modal'] = array(
  82. 'variables' => array('renderer' => NULL, 'categories' => array(), 'region' => NULL, 'category' => NULL, 'column_count' => 2),
  83. 'path' => drupal_get_path('module', 'panels') . '/templates',
  84. 'file' => '../includes/add-content.inc',
  85. 'template' => 'panels-add-content-modal',
  86. );
  87. $theme['panels_add_content_link'] = array(
  88. 'variables' => array('renderer' => NULL, 'region' => NULL, 'content_type' => NULL),
  89. 'path' => drupal_get_path('module', 'panels') . '/templates',
  90. 'file' => '../includes/add-content.inc',
  91. 'template' => 'panels-add-content-link',
  92. );
  93. // We don't need layout and style themes in maintenance mode.
  94. // Disabling this: See http://drupal.org/node/979912 for information.
  95. // if (defined('MAINTENANCE_MODE')) {
  96. // return $theme;
  97. // }
  98. // Register layout and style themes on behalf of all of these items.
  99. ctools_include('plugins', 'panels');
  100. // No need to worry about files; the plugin has to already be loaded for us
  101. // to even know what the theme function is, so files will be auto included.
  102. $layouts = panels_get_layouts();
  103. foreach ($layouts as $name => $data) {
  104. foreach (array('theme', 'admin theme') as $callback) {
  105. if (!empty($data[$callback])) {
  106. $theme[$data[$callback]] = array(
  107. 'variables' => array('css_id' => NULL, 'content' => NULL, 'settings' => NULL, 'display' => NULL, 'layout' => NULL, 'renderer' => NULL),
  108. 'path' => $data['path'],
  109. 'file' => $data['file'],
  110. );
  111. // if no theme function exists, assume template.
  112. if (!function_exists("theme_$data[theme]")) {
  113. $theme[$data[$callback]]['template'] = str_replace('_', '-', $data[$callback]);
  114. $theme[$data[$callback]]['file'] = $data['file']; // for preprocess.
  115. }
  116. }
  117. }
  118. }
  119. $styles = panels_get_styles();
  120. foreach ($styles as $name => $data) {
  121. if (!empty($data['render pane'])) {
  122. $theme[$data['render pane']] = array(
  123. 'variables' => array('content' => NULL, 'pane' => NULL, 'display' => NULL, 'style' => NULL, 'settings' => NULL),
  124. 'path' => $data['path'],
  125. 'file' => $data['file'],
  126. );
  127. }
  128. if (!empty($data['render region'])) {
  129. $theme[$data['render region']] = array(
  130. 'variables' => array('display' => NULL, 'owner_id' => NULL, 'panes' => NULL, 'settings' => NULL, 'region_id' => NULL, 'style' => NULL),
  131. 'path' => $data['path'],
  132. 'file' => $data['file'],
  133. );
  134. }
  135. if (!empty($data['hook theme'])) {
  136. if (is_array($data['hook theme'])) {
  137. $theme += $data['hook theme'];
  138. }
  139. else if (function_exists($data['hook theme'])) {
  140. $data['hook theme']($theme, $data);
  141. }
  142. }
  143. }
  144. return $theme;
  145. }
  146. /**
  147. * Implementation of hook_menu
  148. */
  149. function panels_menu() {
  150. // Safety: go away if CTools is not at an appropriate version.
  151. if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
  152. return array();
  153. }
  154. $items = array();
  155. // Base AJAX router callback.
  156. $items['panels/ajax'] = array(
  157. 'access arguments' => array('access content'),
  158. 'page callback' => 'panels_ajax_router',
  159. 'theme callback' => 'ajax_base_page_theme',
  160. 'delivery callback' => 'ajax_deliver',
  161. 'type' => MENU_CALLBACK,
  162. );
  163. $admin_base = array(
  164. 'file' => 'includes/callbacks.inc',
  165. 'access arguments' => array('use panels dashboard'),
  166. );
  167. // Provide a nice location for a panels admin panel.
  168. $items['admin/structure/panels'] = array(
  169. 'title' => 'Panels',
  170. 'page callback' => 'panels_admin_page',
  171. 'description' => 'Get a bird\'s eye view of items related to Panels.',
  172. ) + $admin_base;
  173. $items['admin/structure/panels/dashboard'] = array(
  174. 'title' => 'Dashboard',
  175. 'page callback' => 'panels_admin_page',
  176. 'type' => MENU_DEFAULT_LOCAL_TASK,
  177. 'weight' => -10,
  178. ) + $admin_base;
  179. $items['admin/structure/panels/settings'] = array(
  180. 'title' => 'Settings',
  181. 'page callback' => 'drupal_get_form',
  182. 'page arguments' => array('panels_admin_settings_page'),
  183. 'type' => MENU_LOCAL_TASK,
  184. ) + $admin_base;
  185. $items['admin/structure/panels/settings/general'] = array(
  186. 'title' => 'General',
  187. 'page callback' => 'drupal_get_form',
  188. 'page arguments' => array('panels_admin_settings_page'),
  189. 'access arguments' => array('administer page manager'),
  190. 'type' => MENU_DEFAULT_LOCAL_TASK,
  191. 'weight' => -10,
  192. ) + $admin_base;
  193. if (module_exists('page_manager')) {
  194. $items['admin/structure/panels/settings/panel-page'] = array(
  195. 'title' => 'Panel pages',
  196. 'page callback' => 'panels_admin_panel_context_page',
  197. 'type' => MENU_LOCAL_TASK,
  198. 'weight' => -10,
  199. ) + $admin_base;
  200. }
  201. ctools_include('plugins', 'panels');
  202. $layouts = panels_get_layouts();
  203. foreach ($layouts as $name => $data) {
  204. if (!empty($data['hook menu'])) {
  205. if (is_array($data['hook menu'])) {
  206. $items += $data['hook menu'];
  207. }
  208. else if (function_exists($data['hook menu'])) {
  209. $data['hook menu']($items, $data);
  210. }
  211. }
  212. }
  213. return $items;
  214. }
  215. /**
  216. * Menu loader function to load a cache item for Panels AJAX.
  217. *
  218. * This load all of the includes needed to perform AJAX, and loads the
  219. * cache object and makes sure it is valid.
  220. */
  221. function panels_edit_cache_load($cache_key) {
  222. ctools_include('display-edit', 'panels');
  223. ctools_include('plugins', 'panels');
  224. ctools_include('ajax');
  225. ctools_include('modal');
  226. ctools_include('context');
  227. return panels_edit_cache_get($cache_key);
  228. }
  229. /**
  230. * Implementation of hook_init()
  231. */
  232. function panels_init() {
  233. // Safety: go away if CTools is not at an appropriate version.
  234. if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
  235. if (user_access('administer site configuration')) {
  236. drupal_set_message(t('Panels is enabled but CTools is out of date. All Panels modules are disabled until CTools is updated. See the status page for more information.'), 'error');
  237. }
  238. return;
  239. }
  240. ctools_add_css('panels', 'panels');
  241. }
  242. /**
  243. * Implementation of hook_permission().
  244. *
  245. * @todo Almost all of these need to be moved into pipelines.
  246. */
  247. function panels_permission() {
  248. return array(
  249. 'use panels dashboard' => array(
  250. 'title' => t("Use Panels Dashboard"),
  251. 'description' => t('Allows a user to access the <a href="@url">Panels Dashboard</a>.', array('@url' => url('admin/structure/panels'))),
  252. ),
  253. 'view pane admin links' => array( // @todo
  254. 'title' => t("View administrative links on Panel panes"),
  255. 'description' => t(""),
  256. ),
  257. 'administer pane access' => array( // @todo should we really have a global perm for this, or should it be moved into a pipeline question?
  258. 'title' => t("Configure access settings on Panel panes"),
  259. 'description' => t("Access rules (often also called visibility rules) can be configured on a per-pane basis. This permission allows users to configure those settings."),
  260. ),
  261. 'use panels in place editing' => array(
  262. 'title' => t("Use the Panels In-Place Editor"),
  263. 'description' => t("Allows a user to utilize Panels' In-Place Editor."),
  264. ),
  265. 'change layouts in place editing' => array(
  266. 'title' => t("Change layouts with the Panels In-Place Editor"),
  267. 'description' => t("Allows a user to change layouts with the IPE."),
  268. ),
  269. 'bypass access in place editing' => array(
  270. 'title' => t("Bypass access checks when using Panels In-Place Editor"),
  271. 'description' => t("Allows using IPE even if user does not have additional permissions granted by other modules."),
  272. 'restrict access' => TRUE,
  273. ),
  274. 'administer advanced pane settings' => array(
  275. 'title' => t("Configure advanced settings on Panel panes"),
  276. 'description' => t(""),
  277. ),
  278. 'administer panels layouts' => array(
  279. 'title' => t("Administer Panels layouts"),
  280. 'description' => t("Allows a user to administer exported Panels layout plugins & instances."),
  281. ),
  282. 'administer panels styles' => array(
  283. 'title' => t("Administer Panels styles"),
  284. 'description' => t("Allows a user to administer the styles of Panel panes."),
  285. ),
  286. 'use panels caching features' => array(
  287. 'title' => t("Configure caching settings on Panels"),
  288. 'description' => t("Allows a user to configure caching on Panels displays and panes."),
  289. ),
  290. 'use panels locks' => array(
  291. 'title' => t('Use panel locks'),
  292. 'description' => t('Allows a user to lock and unlock panes in a panel display.'),
  293. ),
  294. 'use ipe with page manager' => array(
  295. 'title' => t("Use the Panels In-Place Editor with Page Manager"),
  296. 'description' => t('Allows users with access to the In-Place editor to administer page manager pages. This permission is only needed for users without "use page manager" access.'),
  297. ),
  298. );
  299. }
  300. /**
  301. * Implements hook_flush_caches().
  302. */
  303. function panels_flush_caches() {
  304. if (db_table_exists('cache_panels')) {
  305. return array('cache_panels');
  306. }
  307. }
  308. // ---------------------------------------------------------------------------
  309. // CTools hook implementations
  310. //
  311. // These aren't core Drupal hooks but they are just as important.
  312. /**
  313. * Implementation of hook_ctools_plugin_directory() to let the system know
  314. * we implement task and task_handler plugins.
  315. */
  316. function panels_ctools_plugin_directory($module, $plugin) {
  317. // Safety: go away if CTools is not at an appropriate version.
  318. if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
  319. return;
  320. }
  321. // We don't support the 'ctools' 'cache' plugin and pretending to causes
  322. // errors when they're in use.
  323. if ($module == 'ctools' && $plugin == 'cache') {
  324. return;
  325. // if we did we'd make a plugin/ctools_cache or something.
  326. }
  327. if ($module == 'page_manager' || $module == 'panels' || $module == 'ctools' || $module == 'stylizer') {
  328. // Panels and CTools both implement a 'cache' plugin but we don't implement
  329. // the CTools version.
  330. if ($module == 'ctools' && $plugin == 'cache') {
  331. return;
  332. }
  333. return 'plugins/' . $plugin;
  334. }
  335. }
  336. /**
  337. * Implements hook_ctools_plugin_type().
  338. *
  339. * Register layout, style, cache, and display_renderer plugin types, declaring
  340. * relevant plugin type information as necessary.
  341. */
  342. function panels_ctools_plugin_type() {
  343. return array(
  344. 'layouts' => array(
  345. 'load themes' => TRUE, // Can define layouts in themes
  346. 'process' => 'panels_layout_process',
  347. 'child plugins' => TRUE,
  348. ),
  349. 'styles' => array(
  350. 'load themes' => TRUE,
  351. 'process' => 'panels_plugin_styles_process',
  352. 'child plugins' => TRUE,
  353. ),
  354. 'cache' => array(),
  355. 'display_renderers' => array(
  356. 'classes' => array('renderer'),
  357. ),
  358. 'panels_storage' => array(),
  359. );
  360. }
  361. /**
  362. * Ensure a layout has a minimal set of data.
  363. */
  364. function panels_layout_process(&$plugin) {
  365. $plugin += array(
  366. 'category' => t('Miscellaneous'),
  367. 'description' => '',
  368. );
  369. }
  370. /**
  371. * Implementation of hook_ctools_plugin_api().
  372. *
  373. * Inform CTools about version information for various plugins implemented by
  374. * Panels.
  375. *
  376. * @param string $owner
  377. * The system name of the module owning the API about which information is
  378. * being requested.
  379. * @param string $api
  380. * The name of the API about which information is being requested.
  381. */
  382. function panels_ctools_plugin_api($owner, $api) {
  383. if ($owner == 'panels' && $api == 'styles') {
  384. // As of 6.x-3.6, Panels has a slightly new system for style plugins.
  385. return array('version' => 2.0);
  386. }
  387. if ($owner == 'panels' && $api == 'pipelines') {
  388. return array(
  389. 'version' => 1,
  390. 'path' => drupal_get_path('module', 'panels') . '/includes',
  391. );
  392. }
  393. }
  394. /**
  395. * Implementation of hook_views_api().
  396. */
  397. function panels_views_api() {
  398. return array(
  399. 'api' => 2,
  400. 'path' => drupal_get_path('module', 'panels') . '/plugins/views',
  401. );
  402. }
  403. /**
  404. * Perform additional processing on a style plugin.
  405. *
  406. * Currently this is only being used to apply versioning information to style
  407. * plugins in order to ensure the legacy renderer passes the right type of
  408. * parameters to a style plugin in a hybrid environment of both new and old
  409. * plugins.
  410. *
  411. * @see _ctools_process_data()
  412. *
  413. * @param array $plugin
  414. * The style plugin that is being processed.
  415. * @param array $info
  416. * The style plugin type info array.
  417. */
  418. function panels_plugin_styles_process(&$plugin, $info) {
  419. $plugin += array(
  420. 'weight' => 0,
  421. );
  422. $compliant_modules = ctools_plugin_api_info('panels', 'styles', 2.0, 2.0);
  423. $plugin['version'] = empty($compliant_modules[$plugin['module']]) ? 1.0 : $compliant_modules[$plugin['module']]['version'];
  424. }
  425. /**
  426. * Declare what style types Panels uses.
  427. */
  428. function panels_ctools_style_base_types() {
  429. return array(
  430. 'region' => array(
  431. 'title' => t('Panel region'),
  432. 'preview' => 'panels_stylizer_region_preview',
  433. 'theme variables' => array('settings' => NULL, 'class' => NULL, 'content' => NULL),
  434. ),
  435. 'pane' => array(
  436. 'title' => t('Panel pane'),
  437. 'preview' => 'panels_stylizer_pane_preview',
  438. 'theme variables' => array('settings' => NULL, 'content' => NULL, 'pane' => NULL, 'display' => NULL),
  439. ),
  440. );
  441. }
  442. function panels_stylizer_lipsum() {
  443. return "
  444. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus at velit dolor. Donec egestas tellus sit amet urna rhoncus adipiscing. Proin nec porttitor sem. Maecenas aliquam, purus nec tempus dignissim, nulla arcu aliquam diam, non tincidunt massa ante vel dolor. Aliquam sapien sapien, tincidunt id tristique at, pretium sagittis libero.</p>
  445. <p>Nulla facilisi. Curabitur lacinia, tellus sed tristique consequat, diam lorem scelerisque felis, at dictum purus augue facilisis lorem. Duis pharetra dignissim rutrum. Curabitur ac elit id dui dapibus tincidunt. Nulla eget sem quam, non eleifend eros. Cras porttitor tempus lectus ac scelerisque. Curabitur vehicula bibendum lorem, vitae ornare ligula venenatis ut.</p>
  446. ";
  447. }
  448. /**
  449. * Generate a preview given the current settings.
  450. */
  451. function panels_stylizer_region_preview($plugin, $settings) {
  452. ctools_stylizer_add_css($plugin, $settings);
  453. return theme($plugin['theme'], array('settings' => $settings, 'class' => ctools_stylizer_get_css_class($plugin, $settings), 'content' => panels_stylizer_lipsum()));
  454. }
  455. /**
  456. * Generate a preview given the current settings.
  457. */
  458. function panels_stylizer_pane_preview($plugin, $settings) {
  459. ctools_stylizer_add_css($plugin, $settings);
  460. $pane = new stdClass();
  461. $content = new stdClass;
  462. $content->title = t('Lorem ipsum');
  463. $content->content = panels_stylizer_lipsum();
  464. $content->type = 'dummy';
  465. $content->subtype = 'dummy';
  466. $content->css_class = ctools_stylizer_get_css_class($plugin, $settings);
  467. $display = new panels_display();
  468. if (!empty($plugin['theme'])) {
  469. return theme($plugin['theme'], array('settings' => $settings, 'content' => $content, 'pane' => $pane, 'display' => $display));
  470. }
  471. else {
  472. return theme('panels_pane', array('content' => $content, 'pane' => $pane, 'display' => $display));
  473. }
  474. }
  475. // ---------------------------------------------------------------------------
  476. // Panels display editing
  477. /**
  478. * @defgroup mainapi Functions comprising the main panels API
  479. * @{
  480. */
  481. /**
  482. * Main API entry point to edit a panel display.
  483. *
  484. * Sample implementations utiltizing the the complex $destination behavior can be found
  485. * in panels_page_edit_content() and, in a separate contrib module, OG Blueprints
  486. * (http://drupal.org/project/og_blueprints), og_blueprints_blueprint_edit().
  487. *
  488. * @ingroup mainapi
  489. *
  490. * @param object $display instanceof panels_display \n
  491. * A fully loaded panels $display object, as returned from panels_load_display().
  492. * Merely passing a did is NOT sufficient. \n
  493. * Note that 'fully loaded' means the $display must already be loaded with any contexts
  494. * the caller wishes to have set for the display.
  495. * @param mixed $destination \n
  496. * The redirect destination that the user should be taken to on form submission or
  497. * cancellation. With panels_edit, $destination has complex effects on the return
  498. * values of panels_edit() once the form has been submitted. See the explanation of
  499. * the return value below to understand the different types of values returned by panels_edit()
  500. * at different stages of FAPI. Under most circumstances, simply passing in
  501. * drupal_get_destination() is all that's necessary.
  502. * @param array $content_types \n
  503. * An associative array of allowed content types, typically as returned from
  504. * panels_common_get_allowed_types(). Note that context partially governs available content types,
  505. * so you will want to create any relevant contexts using panels_create_context() or
  506. * panels_create_context_empty() to make sure all the appropriate content types are available.
  507. *
  508. * @return
  509. * Because the functions called by panels_edit() invoke the form API, this function
  510. * returns different values depending on the stage of form submission we're at. In Drupal 5,
  511. * the phase of form submission is indicated by the contents of $_POST['op']. Here's what you'll
  512. * get at different stages:
  513. * -# If !$_POST['op']: then we're on on the initial passthrough and the form is being
  514. * rendered, so it's the $form itself that's being returned. Because negative margins,
  515. * a common CSS technique, bork the display editor's ajax drag-and-drop, it's important
  516. * that the $output be printed, not returned. Use this syntax in the caller function: \n
  517. * print theme('page', panels_edit($display, $destination, $content_types), FALSE); \n
  518. * -# If $_POST['op'] == t('Cancel'): form submission has been cancelled. If empty($destination) == FALSE,
  519. * then there is no return value and the panels API takes care of redirecting to $destination.
  520. * If empty($destination) == TRUE, then there's still no return value, but the caller function
  521. * has to take care of form redirection.
  522. * -# If $_POST['op'] == ('Save'): the form has been submitted successfully and has run through
  523. * panels_edit_display_submit(). $output depends on the value of $destination:
  524. * - If empty($destination) == TRUE: $output contains the modified $display
  525. * object, and no redirection will occur. This option is useful if the caller
  526. * needs to perform additional operations on or with the modified $display before
  527. * the page request is complete. Using hook_form_alter() to add an additional submit
  528. * handler is typically the preferred method for something like this, but there
  529. * are certain use cases where that is infeasible and $destination = NULL should
  530. * be used instead. If this method is employed, the caller will need to handle form
  531. * redirection. Note that having $_REQUEST['destination'] set, whether via
  532. * drupal_get_destination() or some other method, will NOT interfere with this
  533. * functionality; consequently, you can use drupal_get_destination() to safely store
  534. * your desired redirect in the caller function, then simply use drupal_goto() once
  535. * panels_edit() has done its business.
  536. * - If empty($destination) == FALSE: the form will redirect to the URL string
  537. * given in $destination and NO value will be returned.
  538. */
  539. function panels_edit($display, $destination = NULL, $content_types = NULL, $title = FALSE) {
  540. ctools_include('display-edit', 'panels');
  541. ctools_include('ajax');
  542. ctools_include('plugins', 'panels');
  543. return _panels_edit($display, $destination, $content_types, $title);
  544. }
  545. /**
  546. * API entry point for selecting a layout for a given display.
  547. *
  548. * Layout selection is nothing more than a list of radio items encompassing the available
  549. * layouts for this display, as defined by .inc files in the panels/layouts subdirectory.
  550. * The only real complexity occurs when a user attempts to change the layout of a display
  551. * that has some content in it.
  552. *
  553. * @param object $display instanceof panels_display \n
  554. * A fully loaded panels $display object, as returned from panels_load_display().
  555. * Merely passing a did is NOT sufficient.
  556. * @param string $finish
  557. * A string that will be used for the text of the form submission button. If no value is provided,
  558. * then the form submission button will default to t('Save').
  559. * @param mixed $destination
  560. * Basic usage is a string containing the URL that the form should redirect to upon submission.
  561. * For a discussion of advanced usages, see panels_edit().
  562. * @param mixed $allowed_layouts
  563. * Allowed layouts has three different behaviors that depend on which of three value types
  564. * are passed in by the caller:
  565. * #- if $allowed_layouts instanceof panels_allowed_layouts (includes subclasses): the most
  566. * complex use of the API. The caller is passing in a loaded panels_allowed_layouts object
  567. * that the client module previously created and stored somewhere using a custom storage
  568. * mechanism.
  569. * #- if is_string($allowed_layouts): the string will be used in a call to variable_get() which
  570. * will call the $allowed_layouts . '_allowed_layouts' var. If the data was stored properly
  571. * in the system var, the $allowed_layouts object will be unserialized and recreated.
  572. * @see panels_common_set_allowed_layouts()
  573. * #- if is_null($allowed_layouts): the default behavior, which also provides backwards
  574. * compatibility for implementations of the Panels2 API written before beta4. In this case,
  575. * a dummy panels_allowed_layouts object is created which does not restrict any layouts.
  576. * Subsequent behavior is indistinguishable from pre-beta4 behavior.
  577. *
  578. * @return
  579. * Can return nothing, or a modified $display object, or a redirection string; return values for the
  580. * panels_edit* family of functions are quite complex. See panels_edit() for detailed discussion.
  581. * @see panels_edit()
  582. */
  583. function panels_edit_layout($display, $finish, $destination = NULL, $allowed_layouts = NULL) {
  584. ctools_include('display-layout', 'panels');
  585. ctools_include('plugins', 'panels');
  586. return _panels_edit_layout($display, $finish, $destination, $allowed_layouts);
  587. }
  588. // ---------------------------------------------------------------------------
  589. // Panels database functions
  590. /**
  591. * Forms the basis of a panel display
  592. */
  593. class panels_display {
  594. var $args = array();
  595. var $content = array();
  596. var $panels = array();
  597. var $incoming_content = NULL;
  598. var $css_id = NULL;
  599. var $context = array();
  600. var $did = 'new';
  601. var $renderer = 'standard';
  602. function add_pane(&$pane, $location = NULL) {
  603. // If no location specified, use what's set in the pane.
  604. if (empty($location)) {
  605. $location = $pane->panel;
  606. }
  607. else {
  608. $pane->panel = $location;
  609. }
  610. // Generate a permanent uuid for this pane, and use
  611. // it as a temporary pid.
  612. $pane->uuid = ctools_uuid_generate();
  613. $pane->pid = 'new-' . $pane->uuid;
  614. // Add the pane to the approprate spots.
  615. $this->content[$pane->pid] = &$pane;
  616. $this->panels[$location][] = $pane->pid;
  617. }
  618. function duplicate_pane($pid, $location = FALSE) {
  619. $pane = $this->clone_pane($pid);
  620. $this->add_pane($pane, $location);
  621. }
  622. function clone_pane($pid) {
  623. $pane = clone $this->content[$pid];
  624. $pane->uuid = ctools_uuid_generate();
  625. return $pane;
  626. }
  627. /**
  628. * Get the title from a display.
  629. *
  630. * The display must have already been rendered, or the setting to set the
  631. * display's title from a pane's title will not have worked.
  632. *
  633. * @return
  634. * The title to use. If NULL, this means to let any default title that may be in use
  635. * pass through. i.e, do not actually set the title.
  636. */
  637. function get_title() {
  638. switch ($this->hide_title) {
  639. case PANELS_TITLE_NONE:
  640. return '';
  641. case PANELS_TITLE_PANE:
  642. return isset($this->stored_pane_title) ? $this->stored_pane_title : '';
  643. case PANELS_TITLE_FIXED:
  644. case FALSE; // For old exported panels that are not in the database.
  645. if (!empty($this->title)) {
  646. return filter_xss_admin(ctools_context_keyword_substitute($this->title, array(), $this->context));
  647. }
  648. return NULL;
  649. }
  650. }
  651. /**
  652. * Render this panels display.
  653. *
  654. * After checking to ensure the designated layout plugin is valid, a
  655. * display renderer object is spawned and runs its rendering logic.
  656. *
  657. * @param mixed $renderer
  658. * An instantiated display renderer object, or the name of a display
  659. * renderer plugin+class to be fetched. Defaults to NULL. When NULL, the
  660. * predesignated display renderer will be used.
  661. */
  662. function render($renderer = NULL) {
  663. $layout = panels_get_layout($this->layout);
  664. if (!$layout) {
  665. return NULL;
  666. }
  667. // If we were not given a renderer object, load it.
  668. if (!is_object($renderer)) {
  669. // If the renderer was not specified, default to $this->renderer
  670. // which is either standard or was already set for us.
  671. $renderer = panels_get_renderer_handler(!empty($renderer) ? $renderer : $this->renderer, $this);
  672. if (!$renderer) {
  673. return NULL;
  674. }
  675. }
  676. $output = '';
  677. // Let modules act just prior to render.
  678. foreach (module_implements('panels_pre_render') as $module) {
  679. $function = $module . '_panels_pre_render';
  680. $output .= $function($this, $renderer);
  681. }
  682. $output .= $renderer->render();
  683. // Let modules act just after render.
  684. foreach (module_implements('panels_post_render') as $module) {
  685. $function = $module . '_panels_post_render';
  686. $output .= $function($this, $renderer);
  687. }
  688. return $output;
  689. }
  690. /**
  691. * Determine if the given user can perform the requested operation.
  692. *
  693. * @param string $op
  694. * An operation like: create, read, update, or delete.
  695. * @param object $account
  696. * (optional) The account to check access for.
  697. *
  698. * @return bool
  699. * TRUE if access is granted; otherwise FALSE.
  700. */
  701. function access($op, $account = NULL) {
  702. global $user;
  703. if (!$account) {
  704. $account = $user;
  705. }
  706. // Even administrators need to go through the access system. However, to
  707. // support legacy plugins, user 1 gets full access no matter what.
  708. if ($account->uid == 1) {
  709. return TRUE;
  710. }
  711. if (!in_array($op, array('create', 'read', 'update', 'delete', 'change layout'))) {
  712. return FALSE;
  713. }
  714. if (empty($this->storage_type) || empty($this->storage_id)) {
  715. return FALSE;
  716. }
  717. if ($this->storage_type == 'unknown') {
  718. return FALSE;
  719. }
  720. $storage_plugin = panels_get_panels_storage_plugin($this->storage_type);
  721. if (!$storage_plugin) {
  722. return FALSE;
  723. }
  724. $access_callback = panels_plugin_get_function('panels_storage', $storage_plugin, 'access callback');
  725. if (!$access_callback) {
  726. return FALSE;
  727. }
  728. return $access_callback($this->storage_type, $this->storage_id, $op, $account);
  729. }
  730. }
  731. /**
  732. * }@ End of 'defgroup mainapi', although other functions are specifically added later
  733. */
  734. /**
  735. * Creates a new display, setting the ID to our magic new id.
  736. */
  737. function panels_new_display() {
  738. ctools_include('export');
  739. $display = ctools_export_new_object('panels_display', FALSE);
  740. $display->did = 'new';
  741. return $display;
  742. }
  743. /**
  744. * Create a new pane.
  745. *
  746. * @todo -- use schema API for some of this?
  747. */
  748. function panels_new_pane($type, $subtype, $set_defaults = FALSE) {
  749. ctools_include('export');
  750. $pane = ctools_export_new_object('panels_pane', FALSE);
  751. $pane->pid = 'new';
  752. $pane->type = $type;
  753. $pane->subtype = $subtype;
  754. if ($set_defaults) {
  755. ctools_include('content');
  756. $content_type = ctools_get_content_type($type);
  757. $content_subtype = ctools_content_get_subtype($content_type, $subtype);
  758. $pane->configuration = ctools_content_get_defaults($content_type, $content_subtype);
  759. }
  760. drupal_alter('panels_new_pane', $pane);
  761. return $pane;
  762. }
  763. /**
  764. * Load and fill the requested $display object(s).
  765. *
  766. * Helper function primarily for for panels_load_display().
  767. *
  768. * @param array $dids
  769. * An indexed array of dids to be loaded from the database.
  770. *
  771. * @return $displays
  772. * An array of displays, keyed by their display dids.
  773. *
  774. * @todo schema API can drasticly simplify this code.
  775. */
  776. function panels_load_displays($dids) {
  777. $displays = array();
  778. if (empty($dids) || !is_array($dids)) {
  779. return $displays;
  780. }
  781. $result = db_query("SELECT * FROM {panels_display} WHERE did IN (:dids)", array(':dids' => $dids));
  782. ctools_include('export');
  783. foreach ($result as $obj) {
  784. $displays[$obj->did] = ctools_export_unpack_object('panels_display', $obj);
  785. // Modify the hide_title field to go from a bool to an int if necessary.
  786. }
  787. $result = db_query("SELECT * FROM {panels_pane} WHERE did IN (:dids) ORDER BY did, panel, position", array(':dids' => $dids));
  788. foreach ($result as $obj) {
  789. $pane = ctools_export_unpack_object('panels_pane', $obj);
  790. $displays[$pane->did]->panels[$pane->panel][] = $pane->pid;
  791. $displays[$pane->did]->content[$pane->pid] = $pane;
  792. }
  793. return $displays;
  794. }
  795. /**
  796. * Load a single display.
  797. *
  798. * @ingroup mainapi
  799. *
  800. * @param int $did
  801. * The display id (did) of the display to be loaded.
  802. *
  803. * @return object $display instanceof panels_display \n
  804. * Returns a partially-loaded panels_display object. $display objects returned from
  805. * from this function have only the following data:
  806. * - $display->did (the display id)
  807. * - $display->name (the 'name' of the display, where applicable - it often isn't)
  808. * - $display->layout (a string with the system name of the display's layout)
  809. * - $display->panel_settings (custom layout style settings contained in an associative array; NULL if none)
  810. * - $display->layout_settings (panel size and configuration settings for Flexible layouts; NULL if none)
  811. * - $display->css_id (the special css_id that has been assigned to this display, if any; NULL if none)
  812. * - $display->content (an array of pane objects, keyed by pane id (pid))
  813. * - $display->panels (an associative array of panel regions, each an indexed array of pids in the order they appear in that region)
  814. * - $display->cache (any relevant data from panels_simple_cache)
  815. * - $display->args
  816. * - $display->incoming_content
  817. *
  818. * While all of these members are defined, $display->context is NEVER defined in the returned $display;
  819. * it must be set using one of the ctools_context_create() functions.
  820. */
  821. function panels_load_display($did) {
  822. $displays = panels_load_displays(array($did));
  823. if (!empty($displays)) {
  824. return array_shift($displays);
  825. }
  826. }
  827. /**
  828. * Save a display object.
  829. *
  830. * @ingroup mainapi
  831. *
  832. * Note that a new $display only receives a real did once it is run through
  833. * this function, and likewise for the pid of any new pane.
  834. *
  835. * Until then, a new display uses a string placeholder, 'new', in place of
  836. * a real did, and a new pane (whether on a new $display or not) appends a
  837. * universally-unique identifier (which is stored permanently in the 'uuid'
  838. * field). This format is also used in place of the real pid for exports.
  839. *
  840. * @param object $display instanceof panels_display \n
  841. * The display object to be saved. Passed by reference so the caller need not use
  842. * the return value for any reason except convenience.
  843. *
  844. * @return object $display instanceof panels_display \n
  845. */
  846. function panels_save_display(&$display) {
  847. $update = (isset($display->did) && is_numeric($display->did)) ? array('did') : array();
  848. if (empty($display->uuid) || !ctools_uuid_is_valid($display->uuid)) {
  849. $display->uuid = ctools_uuid_generate();
  850. }
  851. drupal_write_record('panels_display', $display, $update);
  852. $pids = array();
  853. if ($update) {
  854. // Get a list of all panes currently in the database for this display so we can know if there
  855. // are panes that need to be deleted. (i.e, aren't currently in our list of panes).
  856. $result = db_query("SELECT pid FROM {panels_pane} WHERE did = :did", array(':did' => $display->did));
  857. foreach ($result as $pane) {
  858. $pids[$pane->pid] = $pane->pid;
  859. }
  860. }
  861. // update all the panes
  862. ctools_include('plugins', 'panels');
  863. ctools_include('content');
  864. foreach ($display->panels as $id => $panes) {
  865. $position = 0;
  866. $new_panes = array();
  867. foreach ((array) $panes as $pid) {
  868. if (!isset($display->content[$pid])) {
  869. continue;
  870. }
  871. $pane = $display->content[$pid];
  872. $type = ctools_get_content_type($pane->type);
  873. $pane->position = $position++;
  874. $pane->did = $display->did;
  875. $old_pid = $pane->pid;
  876. if (empty($pane->uuid) || !ctools_uuid_is_valid($pane->uuid)) {
  877. $pane->uuid = ctools_uuid_generate();
  878. }
  879. drupal_write_record('panels_pane', $pane, is_numeric($pid) ? array('pid') : array());
  880. // Allow other modules to take action after a pane is saved.
  881. if ($pane->pid == $old_pid) {
  882. module_invoke_all('panels_pane_update', $pane);
  883. }
  884. else {
  885. module_invoke_all('panels_pane_insert', $pane);
  886. }
  887. if ($pane->pid != $old_pid) {
  888. // Remove the old new-* entry from the displays content.
  889. unset($display->content[$pid]);
  890. // and put it back so our pids and positions can be used.
  891. $display->content[$pane->pid] = $pane;
  892. // If the title pane was one of our panes that just got its ID changed,
  893. // we need to change it in the database, too.
  894. if (isset($display->title_pane) && $display->title_pane == $old_pid) {
  895. $display->title_pane = $pane->pid;
  896. // Do a simple update query to write it so we don't have to rewrite
  897. // the whole record. We can't just save writing the whole record here
  898. // because it was needed to get the did. Chicken, egg, more chicken.
  899. db_update('panels_display')
  900. ->fields(array(
  901. 'title_pane' => $pane->pid
  902. ))
  903. ->condition('did', $display->did)
  904. ->execute();
  905. }
  906. }
  907. // re-add this to the list of content for this panel.
  908. $new_panes[] = $pane->pid;
  909. // Remove this from the list of panes scheduled for deletion.
  910. if (isset($pids[$pane->pid])) {
  911. unset($pids[$pane->pid]);
  912. }
  913. }
  914. $display->panels[$id] = $new_panes;
  915. }
  916. if (!empty($pids)) {
  917. // Allow other modules to take action before a panes are deleted.
  918. module_invoke_all('panels_pane_delete', $pids);
  919. db_delete('panels_pane')->condition('pid', $pids)->execute();
  920. }
  921. // Clear any cached content for this display.
  922. panels_clear_cached_content($display);
  923. // Allow other modules to take action when a display is saved.
  924. module_invoke_all('panels_display_save', $display);
  925. // Log the change to watchdog, using the same style as node.module
  926. $watchdog_args = array('%did' => $display->did);
  927. if (!empty($display->title)) {
  928. $watchdog_args['%title'] = $display->title;
  929. watchdog('content', 'Panels: saved display "%title" with display id %did', $watchdog_args, WATCHDOG_NOTICE);
  930. }
  931. else {
  932. watchdog('content', 'Panels: saved display with id %did', $watchdog_args, WATCHDOG_NOTICE);
  933. }
  934. // to be nice, even tho we have a reference.
  935. return $display;
  936. }
  937. /**
  938. * Delete a display.
  939. */
  940. function panels_delete_display($display) {
  941. if (is_object($display)) {
  942. $did = $display->did;
  943. }
  944. else {
  945. $did = $display;
  946. }
  947. module_invoke_all('panels_delete_display', $did);
  948. db_delete('panels_display')->condition('did', $did)->execute();
  949. db_delete('panels_pane')->condition('did', $did)->execute();
  950. }
  951. /**
  952. * Exports the provided display into portable code.
  953. *
  954. * This function is primarily intended as a mechanism for cloning displays.
  955. * It generates an exact replica (in code) of the provided $display, with
  956. * the exception that it replaces all ids (dids and pids) with place-holder
  957. * values (consisting of the display or pane's uuid, with a 'new-' prefix).
  958. *
  959. * Only once panels_save_display() is called on the code version of $display
  960. * will the exported display be written to the database and permanently saved.
  961. *
  962. * @see panels_page_export() or _panels_page_fetch_display() for sample implementations.
  963. *
  964. * @ingroup mainapi
  965. *
  966. * @param object $display instanceof panels_display \n
  967. * This export function does no loading of additional data about the provided
  968. * display. Consequently, the caller should make sure that all the desired data
  969. * has been loaded into the $display before calling this function.
  970. * @param string $prefix
  971. * A string prefix that is prepended to each line of exported code. This is primarily
  972. * used for prepending a double space when exporting so that the code indents and lines up nicely.
  973. *
  974. * @return string $output
  975. * The passed-in $display expressed as code, ready to be imported. Import by running
  976. * eval($output) in the caller function; doing so will create a new $display variable
  977. * with all the exported values. Note that if you have already defined a $display variable in
  978. * the same scope as where you eval(), your existing $display variable WILL be overwritten.
  979. */
  980. function panels_export_display($display, $prefix = '') {
  981. ctools_include('export');
  982. if (empty($display->uuid) || !ctools_uuid_is_valid($display->uuid)) {
  983. $display->uuid = ctools_uuid_generate();
  984. }
  985. $display->did = 'new-' . $display->uuid;
  986. $output = ctools_export_object('panels_display', $display, $prefix);
  987. // Initialize empty properties.
  988. $output .= $prefix . '$display->content = array()' . ";\n";
  989. $output .= $prefix . '$display->panels = array()' . ";\n";
  990. $panels = array();
  991. $title_pid = 0;
  992. if (!empty($display->content)) {
  993. $region_counters = array();
  994. foreach ($display->content as $pane) {
  995. if (!isset($pane->uuid) || !ctools_uuid_is_valid($pane->uuid)) {
  996. $pane->uuid = ctools_uuid_generate();
  997. }
  998. $pid = 'new-' . $pane->uuid;
  999. if ($pane->pid == $display->title_pane) {
  1000. $title_pid = $pid;
  1001. }
  1002. $pane->pid = $pid;
  1003. $output .= ctools_export_object('panels_pane', $pane, $prefix);
  1004. $output .= $prefix . '$display->content[\'' . $pane->pid . '\'] = $pane' . ";\n";
  1005. if (!isset($region_counters[$pane->panel])) {
  1006. $region_counters[$pane->panel] = 0;
  1007. }
  1008. $output .= $prefix . '$display->panels[\'' . $pane->panel . '\'][' . $region_counters[$pane->panel]++ .'] = \'' . $pane->pid . "';\n";
  1009. }
  1010. }
  1011. $output .= $prefix . '$display->hide_title = ';
  1012. switch ($display->hide_title) {
  1013. case PANELS_TITLE_FIXED:
  1014. $output .= 'PANELS_TITLE_FIXED';
  1015. break;
  1016. case PANELS_TITLE_NONE:
  1017. $output .= 'PANELS_TITLE_NONE';
  1018. break;
  1019. case PANELS_TITLE_PANE:
  1020. $output .= 'PANELS_TITLE_PANE';
  1021. break;
  1022. }
  1023. $output .= ";\n";
  1024. $output .= $prefix . '$display->title_pane =' . " '$title_pid';\n";
  1025. return $output;
  1026. }
  1027. /**
  1028. * Render a display by loading the content into an appropriate
  1029. * array and then passing through to panels_render_layout.
  1030. *
  1031. * if $incoming_content is NULL, default content will be applied. Use
  1032. * an empty string to indicate no content.
  1033. * @ingroup hook_invocations
  1034. */
  1035. function panels_render_display(&$display, $renderer = NULL) {
  1036. ctools_include('plugins', 'panels');
  1037. ctools_include('context');
  1038. if (!empty($display->context)) {
  1039. if ($form_context = ctools_context_get_form($display->context)) {
  1040. $form_context->form['#theme'] = 'panels_render_display_form';
  1041. if (empty($form_context->form['#theme_wrappers']) || !in_array('form', $form_context->form['#theme_wrappers'])) {
  1042. $form_context['#theme_wrappers'][] = 'form';
  1043. }
  1044. $form_context->form['#display'] = &$display;
  1045. return $form_context->form;
  1046. }
  1047. }
  1048. return $display->render($renderer);
  1049. }
  1050. /**
  1051. * Theme function to render our panel as a form.
  1052. *
  1053. * When rendering a display as a form, the entire display needs to be
  1054. * inside the <form> tag so that the form can be spread across the
  1055. * panes. This sets up the form system to be the main caller and we
  1056. * then operate as a theme function of the form.
  1057. */
  1058. function theme_panels_render_display_form($vars) {
  1059. return $vars['element']['#display']->render();
  1060. }
  1061. // @layout
  1062. function panels_print_layout_icon($id, $layout, $title = NULL) {
  1063. ctools_add_css('panels_admin', 'panels');
  1064. $file = $layout['path'] . '/' . $layout['icon'];
  1065. return theme('panels_layout_icon', array('id' => $id, 'image' => theme('image', array('path' => $file, 'alt' => strip_tags($layout['title']), 'title' => strip_tags($layout['description']))), 'title' => $title));
  1066. }
  1067. /**
  1068. * Theme the layout icon image
  1069. * @layout
  1070. * @todo move to theme.inc
  1071. */
  1072. function theme_panels_layout_icon($vars) {
  1073. $id = $vars['id'];
  1074. $image = $vars['image'];
  1075. $title = $vars['title'];
  1076. $output = '<div class="layout-icon">';
  1077. $output .= $image;
  1078. if ($title) {
  1079. $output .= '<div class="caption">' . $title . '</div>';
  1080. }
  1081. $output .= '</div>';
  1082. return $output;
  1083. }
  1084. /**
  1085. * Theme the layout link image
  1086. * @layout
  1087. *
  1088. * @todo Why isn't this a template at this point?
  1089. * @todo Why does this take 4 arguments but only makes use of two?
  1090. */
  1091. function theme_panels_layout_link($vars) {
  1092. $title = $vars['title'];
  1093. $image = $vars['image'];
  1094. $class = $vars['class'];
  1095. $output = '<div class="' . implode(' ', $class) . '">';
  1096. $output .= $vars['image'];
  1097. $output .= '<div>' . $vars['title'] . '</div>';
  1098. $output .= '</div>';
  1099. return $output;
  1100. }
  1101. /**
  1102. * Print the layout link. Sends out to a theme function.
  1103. * @layout
  1104. */
  1105. function panels_print_layout_link($id, $layout, $link, $options = array(), $current_layout = FALSE) {
  1106. if (isset($options['query']['q'])) {
  1107. unset($options['query']['q']);
  1108. }
  1109. // Setup classes for layout link, including current-layout information
  1110. $class = array('layout-link');
  1111. if ($current_layout == $id) {
  1112. $options['attributes']['class'][] = 'current-layout-link';
  1113. $class[] = 'current-layout';
  1114. }
  1115. ctools_add_css('panels_admin', 'panels');
  1116. $file = $layout['path'] . '/' . $layout['icon'];
  1117. $image = l(theme('image', array('path' => $file)), $link, array('html' => true) + $options);
  1118. $title = l($layout['title'], $link, $options);
  1119. return theme('panels_layout_link', array('title' => $title, 'image' => $image, 'class' => $class));
  1120. }
  1121. /**
  1122. * Gateway to the PanelsLegacyState class/object, which does all legacy state
  1123. * checks and provides information about the cause of legacy states as needed.
  1124. *
  1125. * @return PanelsLegacyState $legacy
  1126. */
  1127. function panels_get_legacy_state() {
  1128. static $legacy = NULL;
  1129. if (!isset($legacy)) {
  1130. ctools_include('legacy', 'panels');
  1131. $legacy = new PanelsLegacyState();
  1132. }
  1133. return $legacy;
  1134. }
  1135. /**
  1136. * Get the display that is currently being rendered as a page.
  1137. *
  1138. * Unlike in previous versions of this, this only returns the display,
  1139. * not the page itself, because there are a number of different ways
  1140. * to get to this point. It is hoped that the page data isn't needed
  1141. * at this point. If it turns out there is, we will do something else to
  1142. * get that functionality.
  1143. */
  1144. function panels_get_current_page_display($change = NULL) {
  1145. static $display = NULL;
  1146. if ($change) {
  1147. $display = $change;
  1148. }
  1149. return $display;
  1150. }
  1151. /**
  1152. * Clean up the panel pane variables for the template.
  1153. */
  1154. function template_preprocess_panels_pane(&$vars) {
  1155. $content = &$vars['content'];
  1156. $vars['contextual_links'] = array();
  1157. $vars['classes_array'] = array();
  1158. $vars['admin_links'] = '';
  1159. if (module_exists('contextual') && user_access('access contextual links')) {
  1160. $links = array();
  1161. // These are specified by the content.
  1162. if (!empty($content->admin_links)) {
  1163. $links += $content->admin_links;
  1164. }
  1165. // Take any that may have been in the render array we were given and
  1166. // move them up so they appear outside the pane properly.
  1167. if (is_array($content->content) && isset($content->content['#contextual_links'])) {
  1168. $element = array(
  1169. '#type' => 'contextual_links',
  1170. '#contextual_links' => $content->content['#contextual_links'],
  1171. );
  1172. unset($content->content['#contextual_links']);
  1173. // Add content to $element array
  1174. if (is_array($content->content)) {
  1175. $element['#element'] = $content->content;
  1176. }
  1177. $element = contextual_pre_render_links($element);
  1178. if(!empty($element['#links'])) {
  1179. $links += $element['#links'];
  1180. }
  1181. }
  1182. if ($links) {
  1183. $build = array(
  1184. '#prefix' => '<div class="contextual-links-wrapper">',
  1185. '#suffix' => '</div>',
  1186. '#theme' => 'links__contextual',
  1187. '#links' => $links,
  1188. '#attributes' => array('class' => array('contextual-links')),
  1189. '#attached' => array(
  1190. 'library' => array(array('contextual', 'contextual-links')),
  1191. ),
  1192. );
  1193. $vars['classes_array'][] = 'contextual-links-region';
  1194. $vars['admin_links'] = drupal_render($build);
  1195. }
  1196. }
  1197. // basic classes
  1198. $vars['classes_array'][] = 'panel-pane';
  1199. $vars['id'] = '';
  1200. // Add some usable classes based on type/subtype
  1201. ctools_include('cleanstring');
  1202. $type_class = $content->type ? 'pane-'. ctools_cleanstring($content->type, array('lower case' => TRUE)) : '';
  1203. $subtype_class = $content->subtype ? 'pane-'. ctools_cleanstring($content->subtype, array('lower case' => TRUE)) : '';
  1204. // Sometimes type and subtype are the same. Avoid redundant classes.
  1205. $vars['classes_array'][] = $type_class;
  1206. if ($type_class != $subtype_class) {
  1207. $vars['classes_array'][] = $subtype_class;
  1208. }
  1209. // Add id and custom class if sent in.
  1210. if (!empty($content->content)) {
  1211. if (!empty($content->css_id)) {
  1212. $vars['id'] = ' id="' . $content->css_id . '"';
  1213. }
  1214. if (!empty($content->css_class)) {
  1215. $vars['classes_array'][] = $content->css_class;
  1216. }
  1217. }
  1218. // Set up some placeholders for constructing template file names.
  1219. $base = 'panels_pane';
  1220. $delimiter = '__';
  1221. // Add template file suggestion for content type and sub-type.
  1222. $vars['theme_hook_suggestions'][] = $base . $delimiter . $content->type;
  1223. $vars['theme_hook_suggestions'][] = $base . $delimiter . strtr(ctools_cleanstring($content->type, array('lower case' => TRUE)), '-', '_') . $delimiter . strtr(ctools_cleanstring($content->subtype, array('lower case' => TRUE)), '-', '_');
  1224. $vars['pane_prefix'] = !empty($content->pane_prefix) ? $content->pane_prefix : '';
  1225. $vars['pane_suffix'] = !empty($content->pane_suffix) ? $content->pane_suffix : '';
  1226. $vars['title'] = !empty($content->title) ? $content->title : '';
  1227. $vars['title_heading'] = !empty($content->title_heading) ? $content->title_heading : variable_get('override_title_heading', 'h2');
  1228. $vars['title_attributes_array']['class'][] = 'pane-title';
  1229. $vars['feeds'] = !empty($content->feeds) ? implode(' ', $content->feeds) : '';
  1230. $vars['links'] = !empty($content->links) ? theme('links', array('links' => $content->links)) : '';
  1231. $vars['more'] = '';
  1232. if (!empty($content->more)) {
  1233. if (empty($content->more['title'])) {
  1234. $content->more['title'] = t('more');
  1235. }
  1236. $vars['more'] = l($content->more['title'], $content->more['href'], $content->more);
  1237. }
  1238. $vars['content'] = !empty($content->content) ? $content->content : '';
  1239. }
  1240. /**
  1241. * Route Panels' AJAX calls to the correct object.
  1242. *
  1243. * Panels' AJAX is controlled mostly by renderer objects. This menu callback
  1244. * accepts the incoming request, figures out which object should handle the
  1245. * request, and attempts to route it. If no object can be found, the default
  1246. * Panels editor object is used.
  1247. *
  1248. * Calls are routed via the ajax_* method space. For example, if visiting
  1249. * panels/ajax/add-pane then $renderer::ajax_add_pane() will be called.
  1250. * This means commands can be added without having to create new callbacks.
  1251. *
  1252. * The first argument *must always* be the cache key so that a cache object
  1253. * can be passed through. Other arguments will be passed through untouched
  1254. * so that the method can do whatever it needs to do.
  1255. */
  1256. function panels_ajax_router() {
  1257. $args = func_get_args();
  1258. if (count($args) < 3) {
  1259. return MENU_NOT_FOUND;
  1260. }
  1261. ctools_include('display-edit', 'panels');
  1262. ctools_include('plugins', 'panels');
  1263. ctools_include('ajax');
  1264. ctools_include('modal');
  1265. ctools_include('context');
  1266. ctools_include('content');
  1267. $plugin_name = array_shift($args);
  1268. $method = array_shift($args);
  1269. $cache_key = array_shift($args);
  1270. $plugin = panels_get_display_renderer($plugin_name);
  1271. if (!$plugin) {
  1272. // This is the default renderer for handling AJAX commands.
  1273. $plugin = panels_get_display_renderer('editor');
  1274. }
  1275. $cache = panels_edit_cache_get($cache_key);
  1276. if (empty($cache)) {
  1277. return MENU_ACCESS_DENIED;
  1278. }
  1279. $renderer = panels_get_renderer_handler($plugin, $cache->display);
  1280. if (!$renderer) {
  1281. return MENU_ACCESS_DENIED;
  1282. }
  1283. $method = 'ajax_' . str_replace('-', '_', $method);
  1284. if (!method_exists($renderer, $method)) {
  1285. return MENU_NOT_FOUND;
  1286. }
  1287. $renderer->cache = &$cache;
  1288. ctools_include('cleanstring');
  1289. $renderer->clean_key = ctools_cleanstring($cache_key);
  1290. $op = $renderer->get_panels_storage_op_for_ajax($method);
  1291. if (!$cache->display->access($op)) {
  1292. return MENU_ACCESS_DENIED;
  1293. }
  1294. $output = call_user_func_array(array($renderer, $method), $args);
  1295. if (empty($output) && !empty($renderer->commands)) {
  1296. return array(
  1297. '#type' => 'ajax',
  1298. '#commands' => $renderer->commands,
  1299. );
  1300. }
  1301. else {
  1302. return $output;
  1303. }
  1304. }
  1305. // --------------------------------------------------------------------------
  1306. // Panels caching functions and callbacks
  1307. //
  1308. // When editing displays and the like, Panels has a caching system that relies
  1309. // on a callback to determine where to get the actual cache.
  1310. // @todo This system needs to be better documented so that it can be
  1311. // better used.
  1312. /**
  1313. * Get an object from cache.
  1314. */
  1315. function panels_cache_get($obj, $did, $skip_cache = FALSE) {
  1316. ctools_include('object-cache');
  1317. // we often store contexts in cache, so let's just make sure we can load
  1318. // them.
  1319. ctools_include('context');
  1320. return ctools_object_cache_get($obj, 'panels_display:' . $did, $skip_cache);
  1321. }
  1322. /**
  1323. * Save the edited object into the cache.
  1324. */
  1325. function panels_cache_set($obj, $did, $cache) {
  1326. ctools_include('object-cache');
  1327. return ctools_object_cache_set($obj, 'panels_display:' . $did, $cache);
  1328. }
  1329. /**
  1330. * Clear a object from the cache; used if the editing is aborted.
  1331. */
  1332. function panels_cache_clear($obj, $did) {
  1333. ctools_include('object-cache');
  1334. return ctools_object_cache_clear($obj, 'panels_display:' . $did);
  1335. }
  1336. /**
  1337. * Create the default cache for editing panel displays.
  1338. *
  1339. * If an application is using the Panels display editor without having
  1340. * specified a cache key, this method can be used to create the default
  1341. * cache.
  1342. */
  1343. function panels_edit_cache_get_default(&$display, $content_types = NULL, $title = FALSE) {
  1344. if (empty($content_types)) {
  1345. $content_types = ctools_content_get_available_types();
  1346. }
  1347. $display->cache_key = $display->did;
  1348. panels_cache_clear('display', $display->did);
  1349. $cache = new stdClass();
  1350. $cache->display = &$display;
  1351. $cache->content_types = $content_types;
  1352. $cache->display_title = $title;
  1353. panels_edit_cache_set($cache);
  1354. return $cache;
  1355. }
  1356. /**
  1357. * Method to allow modules to provide their own caching mechanism for the
  1358. * display editor.
  1359. */
  1360. function panels_edit_cache_get($cache_key) {
  1361. if (strpos($cache_key, ':') !== FALSE) {
  1362. list($module, $argument) = explode(':', $cache_key, 2);
  1363. return module_invoke($module, 'panels_cache_get', $argument);
  1364. }
  1365. // Fall back to our normal method:
  1366. return panels_cache_get('display', $cache_key);
  1367. }
  1368. /**
  1369. * Method to allow modules to provide their own caching mechanism for the
  1370. * display editor.
  1371. */
  1372. function panels_edit_cache_set($cache) {
  1373. $cache_key = $cache->display->cache_key;
  1374. if (strpos($cache_key, ':') !== FALSE) {
  1375. list($module, $argument) = explode(':', $cache_key, 2);
  1376. return module_invoke($module, 'panels_cache_set', $argument, $cache);
  1377. }
  1378. // Fall back to our normal method:
  1379. return panels_cache_set('display', $cache_key, $cache);
  1380. }
  1381. /**
  1382. * Method to allow modules to provide their own mechanism to write the
  1383. * cache used in the display editor.
  1384. */
  1385. function panels_edit_cache_save($cache) {
  1386. $cache_key = $cache->display->cache_key;
  1387. if (strpos($cache_key, ':') !== FALSE) {
  1388. list($module, $argument) = explode(':', $cache_key, 2);
  1389. if (function_exists($module . '_panels_cache_save')) {
  1390. return module_invoke($module, 'panels_cache_save', $argument, $cache);
  1391. }
  1392. }
  1393. // Fall back to our normal method:
  1394. return panels_save_display($cache->display);
  1395. }
  1396. /**
  1397. * Method to allow modules to provide their own mechanism to clear the
  1398. * cache used in the display editor.
  1399. */
  1400. function panels_edit_cache_clear($cache) {
  1401. $cache_key = $cache->display->cache_key;
  1402. if (strpos($cache_key, ':') !== FALSE) {
  1403. list($module, $argument) = explode(':', $cache_key, 2);
  1404. if (function_exists($module . '_panels_cache_clear')) {
  1405. return module_invoke($module, 'panels_cache_clear', $argument, $cache);
  1406. }
  1407. }
  1408. // Fall back to our normal method:
  1409. return panels_cache_clear('display', $cache_key);
  1410. }
  1411. /**
  1412. * Method to allow modules to provide a mechanism to break locks.
  1413. */
  1414. function panels_edit_cache_break_lock($cache) {
  1415. if (empty($cache->locked)) {
  1416. return;
  1417. }
  1418. $cache_key = $cache->display->cache_key;
  1419. if (strpos($cache_key, ':') !== FALSE) {
  1420. list($module, $argument) = explode(':', $cache_key, 2);
  1421. if (function_exists($module . '_panels_cache_break_lock')) {
  1422. return module_invoke($module, 'panels_cache_break_lock', $argument, $cache);
  1423. }
  1424. }
  1425. // Normal panel display editing has no locks, so we do nothing if there is
  1426. // no fallback.
  1427. return;
  1428. }
  1429. // --------------------------------------------------------------------------
  1430. // Callbacks on behalf of the panel_context plugin.
  1431. //
  1432. // The panel_context plugin lets Panels be used in page manager. These
  1433. // callbacks allow the display editing system to use the page manager
  1434. // cache rather than the default display cache. They are routed by the cache
  1435. // key via panels_edit_cache_* functions.
  1436. /**
  1437. * Get display edit cache on behalf of panel context.
  1438. *
  1439. * The key is the second half of the key in this form:
  1440. * panel_context:TASK_NAME::HANDLER_NAME::args::url;
  1441. */
  1442. function panel_context_panels_cache_get($key) {
  1443. ctools_include('common', 'panels');
  1444. ctools_include('context');
  1445. ctools_include('context-task-handler');
  1446. // this loads the panel context inc even if we don't use the plugin.
  1447. $plugin = page_manager_get_task_handler('panel_context');
  1448. list($task_name, $handler_name, $args, $q) = explode('::', $key, 4);
  1449. $page = page_manager_get_page_cache($task_name);
  1450. if (isset($page->display_cache[$handler_name])) {
  1451. return $page->display_cache[$handler_name];
  1452. }
  1453. if ($handler_name) {
  1454. $handler = &$page->handlers[$handler_name];
  1455. }
  1456. else {
  1457. $handler = &$page->new_handler;
  1458. }
  1459. $cache = new stdClass();
  1460. $task = page_manager_get_task($page->task_id);
  1461. //ctools_context_handler_get_all_contexts($page->task, $page->subtask, $handler);
  1462. $arguments = array();
  1463. if ($args) {
  1464. $arguments = explode('\\', $args);
  1465. $contexts = ctools_context_handler_get_task_contexts($task, $page->subtask, $arguments);
  1466. $contexts = ctools_context_handler_get_handler_contexts($contexts, $handler);
  1467. }
  1468. else {
  1469. $contexts = ctools_context_handler_get_all_contexts($page->task, $page->subtask, $handler);
  1470. }
  1471. $cache->display = &panels_panel_context_get_display($handler);
  1472. $cache->display->context = $contexts;
  1473. $cache->display->cache_key = 'panel_context:' . $key;
  1474. $cache->content_types = panels_common_get_allowed_types('panels_page', $cache->display->context);
  1475. $cache->display_title = TRUE;
  1476. $cache->locked = $page->locked;
  1477. return $cache;
  1478. }
  1479. /**
  1480. * Get the Page Manager cache for the panel_context plugin.
  1481. */
  1482. function _panel_context_panels_cache_get_page_cache($key, $cache) {
  1483. list($task_name, $handler_name, $args, $q) = explode('::', $key, 4);
  1484. $page = page_manager_get_page_cache($task_name);
  1485. $page->display_cache[$handler_name] = $cache;
  1486. if ($handler_name) {
  1487. $page->handlers[$handler_name]->conf['display'] = $cache->display;
  1488. $page->handler_info[$handler_name]['changed'] |= PAGE_MANAGER_CHANGED_CACHED;
  1489. }
  1490. else {
  1491. $page->new_handler->conf['display'] = $cache->display;
  1492. }
  1493. return $page;
  1494. }
  1495. /**
  1496. * Store a display edit in progress in the page cache.
  1497. */
  1498. function panel_context_panels_cache_set($key, $cache) {
  1499. $page = _panel_context_panels_cache_get_page_cache($key, $cache);
  1500. page_manager_set_page_cache($page);
  1501. }
  1502. /**
  1503. * Save all changes made to a display using the Page Manager page cache.
  1504. */
  1505. function panel_context_panels_cache_clear($key, $cache) {
  1506. $page = _panel_context_panels_cache_get_page_cache($key, $cache);
  1507. page_manager_clear_page_cache($page->task_name);
  1508. }
  1509. /**
  1510. * Save all changes made to a display using the Page Manager page cache.
  1511. */
  1512. function panel_context_panels_cache_save($key, $cache) {
  1513. $page = _panel_context_panels_cache_get_page_cache($key, $cache);
  1514. page_manager_save_page_cache($page);
  1515. }
  1516. /**
  1517. * Break the lock on a page manager page.
  1518. */
  1519. function panel_context_panels_cache_break_lock($key, $cache) {
  1520. $page = _panel_context_panels_cache_get_page_cache($key, $cache);
  1521. ctools_object_cache_clear_all('page_manager_page', $page->task_name);
  1522. }
  1523. // --------------------------------------------------------------------------
  1524. // Callbacks on behalf of the panels page wizards
  1525. //
  1526. // The page wizards are a pluggable set of 'wizards' to make it easy to create
  1527. // specific types of pages based upon whatever someone felt like putting
  1528. // together. Since they will very often have content editing, we provide
  1529. // a generic mechanism to allow them to store their editing cache in the
  1530. // wizard cache.
  1531. //
  1532. // For them to use this mechanism, they just need to use:
  1533. // $cache = panels_edit_cache_get('panels_page_wizard:' . $plugin['name']);
  1534. /**
  1535. * Get display edit cache for the panels mini export UI
  1536. *
  1537. * The key is the second half of the key in this form:
  1538. * panels_page_wizard:TASK_NAME:HANDLER_NAME;
  1539. */
  1540. function panels_page_wizard_panels_cache_get($key) {
  1541. ctools_include('page-wizard');
  1542. ctools_include('context');
  1543. $wizard_cache = page_manager_get_wizard_cache($key);
  1544. if (isset($wizard_cache->display_cache)) {
  1545. return $wizard_cache->display_cache;
  1546. }
  1547. ctools_include('common', 'panels');
  1548. $cache = new stdClass();
  1549. $cache->display = $wizard_cache->display;
  1550. $cache->display->context = !empty($wizard_cache->context) ? $wizard_cache->context : array();
  1551. $cache->display->cache_key = 'panels_page_wizard:' . $key;
  1552. $cache->content_types = panels_common_get_allowed_types('panels_page', $cache->display->context);
  1553. $cache->display_title = TRUE;
  1554. return $cache;
  1555. }
  1556. /**
  1557. * Store a display edit in progress in the page cache.
  1558. */
  1559. function panels_page_wizard_panels_cache_set($key, $cache) {
  1560. ctools_include('page-wizard');
  1561. $wizard_cache = page_manager_get_wizard_cache($key);
  1562. $wizard_cache->display_cache = $cache;
  1563. page_manager_set_wizard_cache($wizard_cache);
  1564. }
  1565. /**
  1566. * Alter the page wizard basic page, when panels is selected, to inject page
  1567. * manager as the storage plugin for panels.
  1568. * @param $form
  1569. * @param $form_state
  1570. */
  1571. function panels_form_page_manager_page_form_basic_alter(&$form, &$form_state) {
  1572. $form['#validate'][] = 'panels_page_manager_handler_add_validate';
  1573. }
  1574. /**
  1575. * Alter the variant add page, so when panels is selected, page manager is the
  1576. * storage plugin for panels.
  1577. * @param $form
  1578. * @param $form_state
  1579. */
  1580. function panels_form_page_manager_handler_add_alter(&$form, &$form_state) {
  1581. $form['#validate'][] = 'panels_page_manager_handler_add_validate';
  1582. }
  1583. /**
  1584. * Perform the validation check to see if panel context is selected to use
  1585. * page manager as the storage plugin.
  1586. * @param $form
  1587. * @param $form_state
  1588. */
  1589. function panels_page_manager_handler_add_validate($form, &$form_state) {
  1590. if($form_state['values']['handler'] == 'panel_context') {
  1591. $form_state['page']->storage_type = 'page_manager';
  1592. }
  1593. }
  1594. /**
  1595. * Implements hook_default_page_manager_handlers_alter().
  1596. *
  1597. * If a default Panels display has no storage type, set it.
  1598. */
  1599. function panels_default_page_manager_handlers_alter(&$handlers) {
  1600. foreach ($handlers as &$handler) {
  1601. if ($handler->handler == 'panel_context') {
  1602. $display =& $handler->conf['display'];
  1603. if (empty($display->storage_type)) {
  1604. $display->storage_type = 'page_manager';
  1605. $display->storage_id = $handler->name;
  1606. }
  1607. }
  1608. }
  1609. }
  1610. /**
  1611. * Implements hook_default_page_manager_pages_alter().
  1612. */
  1613. function panels_default_page_manager_pages_alter(&$pages) {
  1614. foreach ($pages as &$page) {
  1615. panels_default_page_manager_handlers_alter($page->default_handlers);
  1616. }
  1617. }
  1618. // --------------------------------------------------------------------------
  1619. // General utility functions
  1620. /**
  1621. * Perform a drupal_goto on a destination that may be an array like url().
  1622. */
  1623. function panels_goto($destination) {
  1624. if (!is_array($destination)) {
  1625. return drupal_goto($destination);
  1626. }
  1627. else {
  1628. // Prevent notices by adding defaults
  1629. $destination += array(
  1630. 'query' => NULL,
  1631. 'fragment' => NULL,
  1632. 'http_response_code' => NULL,
  1633. );
  1634. return drupal_goto($destination['path'], $destination['query'], $destination['fragment'], $destination['http_response_code']);
  1635. }
  1636. }
  1637. /**
  1638. * For external use: Given a layout ID and a $content array, return the
  1639. * panel display.
  1640. *
  1641. * The content array is filled in based upon the content available in the
  1642. * layout. If it's a two column with a content array defined like
  1643. * @code
  1644. * array(
  1645. * 'left' => t('Left side'),
  1646. * 'right' => t('Right side')
  1647. * ),
  1648. * @endcode
  1649. *
  1650. * Then the $content array should be
  1651. * @code
  1652. * array(
  1653. * 'left' => $output_left,
  1654. * 'right' => $output_right,
  1655. * )
  1656. * @endcode
  1657. *
  1658. * The output within each panel region can be either a single rendered
  1659. * HTML string or an array of rendered HTML strings as though they were
  1660. * panes. They will simply be concatenated together without separators.
  1661. */
  1662. function panels_print_layout($layout, $content, $meta = 'standard') {
  1663. ctools_include('plugins', 'panels');
  1664. // Create a temporary display for this.
  1665. $display = panels_new_display();
  1666. $display->layout = is_array($layout) ? $layout['name'] : $layout;
  1667. $display->content = $content;
  1668. // Get our simple renderer
  1669. $renderer = panels_get_renderer_handler('simple', $display);
  1670. $renderer->meta_location = $meta;
  1671. return $renderer->render();
  1672. }
  1673. /**
  1674. * Filter callback for array_filter to remove builders from a list of layouts.
  1675. */
  1676. function _panels_builder_filter($layout) {
  1677. return empty($layout['builder']);
  1678. }
  1679. /**
  1680. * Implements hook_get_pane_links_alter().
  1681. *
  1682. * add links to the Panels pane dropdown menu.
  1683. */
  1684. function panels_get_pane_links_alter(&$links, $pane, $content_type) {
  1685. if ($pane->type === "block"){
  1686. $prefixed_name = $pane->subtype;
  1687. // breakup the subtype string into parts.
  1688. $exploded_subtype = explode('-', $pane->subtype);
  1689. // get the first part of the string.
  1690. $subtype_prefix = $exploded_subtype[0];
  1691. // get the first part of the string and add a hyphen.
  1692. $subtype_prefix_hyphen = $exploded_subtype[0] . '-';
  1693. // remove the prefix block- to get the name.
  1694. $name_of_block = ltrim( $prefixed_name, $subtype_prefix_hyphen);
  1695. // check for user added menus created at /admin/structure/menu/add
  1696. // menus of that type have a subtype that is prefixed with menu-menu-
  1697. if (substr($prefixed_name, 0, 10) === "menu-menu-"){
  1698. // remove the first prefix menu- from menu-menu- to get the name.
  1699. $name_of_block = substr($prefixed_name, 5);
  1700. $links['top'][] = array(
  1701. 'title' => t('Edit block'),
  1702. 'href' => url('admin/structure/block/manage/' . $subtype_prefix . '/' . $name_of_block . '/configure', array('absolute' => TRUE)),
  1703. 'attributes' => array('target' => array('_blank')),
  1704. );
  1705. $links['top'][] = array(
  1706. 'title' => t('Edit menu links'),
  1707. 'href' => url('admin/structure/menu/manage/' . $name_of_block, array('absolute' => TRUE)),
  1708. 'attributes' => array('target' => array('_blank')),
  1709. );
  1710. }
  1711. // check for module provided menu blocks like Devels or Features
  1712. // menus of that type have a subtype that is prefixed with menu-
  1713. elseif(substr($prefixed_name, 0, 5) === "menu-"){
  1714. // remove the first prefix menu- to get the name.
  1715. $name_of_block = substr($prefixed_name, 5);
  1716. $links['top'][] = array(
  1717. 'title' => t('Edit block'),
  1718. 'href' => url('admin/structure/block/manage/' . $subtype_prefix . '/' . $name_of_block . '/configure', array('absolute' => TRUE)),
  1719. 'attributes' => array('target' => array('_blank')),
  1720. );
  1721. $links['top'][] = array(
  1722. 'title' => t('Edit menu links'),
  1723. 'href' => url('admin/structure/menu/manage/' . $name_of_block, array('absolute' => TRUE)),
  1724. 'attributes' => array('target' => array('_blank')),
  1725. );
  1726. }
  1727. // check for system blocks with menu links
  1728. elseif(substr($prefixed_name, 0, 7) === "system-") {
  1729. // remove the first prefix system- to get the name
  1730. $name_of_block = substr($prefixed_name, 7);
  1731. $names_of_system_menus = menu_list_system_menus();
  1732. $links['top'][] = array(
  1733. 'title' => t('Edit block'),
  1734. 'href' => url('admin/structure/block/manage/' . $subtype_prefix . '/' . $name_of_block . '/configure', array('absolute' => TRUE)),
  1735. 'attributes' => array('target' => array('_blank')),
  1736. );
  1737. if (array_key_exists($name_of_block, $names_of_system_menus)){
  1738. $links['top'][] = array(
  1739. 'title' => t('Edit menu links'),
  1740. 'href' => url('admin/structure/menu/manage/' . $name_of_block, array('absolute' => TRUE)),
  1741. 'attributes' => array('target' => array('_blank')),
  1742. );
  1743. }
  1744. }
  1745. // for all other blocks without menus
  1746. else{
  1747. $links['top'][] = array(
  1748. 'title' => t('Edit block'),
  1749. 'href' => url('admin/structure/block/manage/' . $subtype_prefix . '/' . $name_of_block . '/configure', array('absolute' => TRUE)),
  1750. 'attributes' => array('target' => array('_blank')),
  1751. );
  1752. }
  1753. }
  1754. }
  1755. // --------------------------------------------------------------------------
  1756. // Deprecated functions
  1757. //
  1758. // Everything below this line will eventually go away.
  1759. /**
  1760. * panels path helper function
  1761. */
  1762. function panels_get_path($file, $base_path = FALSE, $module = 'panels') {
  1763. $output = $base_path ? base_path() : '';
  1764. return $output . drupal_get_path('module', $module) . '/' . $file;
  1765. }
  1766. /**
  1767. * Remove default sidebar related body classes and provide own css classes
  1768. */
  1769. function panels_preprocess_html(&$vars) {
  1770. $panel_body_css = &drupal_static('panel_body_css');
  1771. if (!empty($panel_body_css['body_classes_to_remove'])) {
  1772. $classes_to_remove = array_filter(explode(' ', $panel_body_css['body_classes_to_remove']), 'strlen');
  1773. foreach ($vars['classes_array'] as $key => $css_class) {
  1774. if (in_array($css_class, $classes_to_remove)) {
  1775. unset($vars['classes_array'][$key]);
  1776. }
  1777. }
  1778. }
  1779. if (!empty($panel_body_css['body_classes_to_add'])) {
  1780. $vars['classes_array'][] = check_plain($panel_body_css['body_classes_to_add']);
  1781. }
  1782. }