panels.module 69 KB

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