custom.inc

  1. cis7 sites/all/modules/ulmus/ctools/plugins/content_types/custom/custom.inc
  2. cle7 sites/all/modules/ulmus/ctools/plugins/content_types/custom/custom.inc
  3. ecd7 sites/all/modules/ulmus/ctools/plugins/content_types/custom/custom.inc
  4. elmsmedia7 sites/all/modules/ulmus/ctools/plugins/content_types/custom/custom.inc
  5. harmony7 sites/all/modules/ulmus/ctools/plugins/content_types/custom/custom.inc
  6. icor7 sites/all/modules/ulmus/ctools/plugins/content_types/custom/custom.inc
  7. meedjum_blog7 sites/all/modules/ulmus/ctools/plugins/content_types/custom/custom.inc
  8. mooc7 sites/all/modules/ulmus/ctools/plugins/content_types/custom/custom.inc

Custom content type.

This content type is nothing more than a title and a body that is entered by the user and run through standard filters. The information is stored right in the config, so each custom content is unique.

Functions

Namesort descending Description
ctools_custom_content_type_admin_info Callback to provide administrative info. In this case we'll render the content as long as it's not PHP, which is too risky to render here.
ctools_custom_content_type_admin_title Callback to provide the administrative title of the custom content.
ctools_custom_content_type_content_type Return the custom content types with the specified $subtype_id.
ctools_custom_content_type_content_types Return all custom content types available.
ctools_custom_content_type_editable
ctools_custom_content_type_edit_form Returns an edit form for the custom type.
ctools_custom_content_type_edit_form_submit The submit form stores the data in $conf.
ctools_custom_content_type_edit_form_validate The validate form to ensure the custom content data is okay.
ctools_custom_content_type_get_conf Given a subtype and a $conf, return the actual settings to use.
ctools_custom_content_type_render Output function for the 'custom' content type. Outputs a custom based on the module and delta supplied in the configuration.
_ctools_custom_content_type_content_type Return an info array for a specific custom content type.
_ctools_custom_content_type_edit_save
_ctools_default_content_type_content_type Settings for the default custom content type.

File

sites/all/modules/ulmus/ctools/plugins/content_types/custom/custom.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Custom content type.
  5. *
  6. * This content type is nothing more than a title and a body that is entered
  7. * by the user and run through standard filters. The information is stored
  8. * right in the config, so each custom content is unique.
  9. */
  10. /**
  11. * Plugins are described by creating a $plugin array which will be used
  12. * by the system that includes this file.
  13. */
  14. $plugin = array(
  15. 'title' => t('Custom content'),
  16. 'no title override' => TRUE,
  17. 'defaults' => array('admin_title' => '', 'title' => '', 'body' => '', 'format' => filter_default_format(), 'substitute' => TRUE),
  18. 'js' => array('misc/autocomplete.js', 'misc/textarea.js', 'misc/collapse.js'),
  19. // Make sure the edit form is only used for some subtypes.
  20. 'edit form' => '',
  21. 'add form' => '',
  22. 'edit text' => t('Edit'),
  23. 'all contexts' => TRUE,
  24. );
  25. /**
  26. * Return the custom content types with the specified $subtype_id.
  27. */
  28. function ctools_custom_content_type_content_type($subtype_id) {
  29. if ($subtype_id == 'custom') {
  30. return _ctools_default_content_type_content_type();
  31. }
  32. elseif (module_exists('ctools_custom_content')) {
  33. ctools_include('export');
  34. $content = ctools_export_crud_load('ctools_custom_content', $subtype_id);
  35. if ($content) {
  36. return _ctools_custom_content_type_content_type($content);
  37. }
  38. }
  39. }
  40. /**
  41. * Return all custom content types available.
  42. */
  43. function ctools_custom_content_type_content_types() {
  44. $types = &drupal_static(__FUNCTION__);
  45. if (isset($types)) {
  46. return $types;
  47. }
  48. ctools_include('export');
  49. $types = array();
  50. $types['custom'] = _ctools_default_content_type_content_type();
  51. if (module_exists('ctools_custom_content')) {
  52. foreach (ctools_export_crud_load_all('ctools_custom_content') as $name => $content) {
  53. $types[$name] = _ctools_custom_content_type_content_type($content);
  54. }
  55. }
  56. return $types;
  57. }
  58. /**
  59. * Settings for the default custom content type.
  60. *
  61. * The default is the one that allows the user to actually create a type.
  62. */
  63. function _ctools_default_content_type_content_type() {
  64. $info = array(
  65. 'name' => 'custom',
  66. 'title' => t('New custom content'),
  67. 'top level' => TRUE,
  68. 'category' => t('Custom'),
  69. 'description' => t('Create a completely custom piece of HTML content.'),
  70. 'edit form' => 'ctools_custom_content_type_edit_form',
  71. 'all contexts' => TRUE,
  72. 'check editable' => 'ctools_custom_content_type_editable',
  73. );
  74. return $info;
  75. }
  76. /**
  77. * Return an info array for a specific custom content type.
  78. */
  79. function _ctools_custom_content_type_content_type($content) {
  80. $info = array(
  81. 'name' => $content->name,
  82. 'title' => check_plain($content->admin_title),
  83. 'description' => check_plain($content->admin_description),
  84. 'category' => $content->category ? check_plain($content->category) : t('Miscellaneous'),
  85. 'all contexts' => TRUE,
  86. 'icon' => 'icon_block_custom.png',
  87. // Store this here to make it easy to access.
  88. 'content' => $content,
  89. );
  90. return $info;
  91. }
  92. /**
  93. * Given a subtype and a $conf, return the actual settings to use.
  94. *
  95. * The actual settings may be stored directly in the pane or this may
  96. * be a pointer to re-usable content that may be in the database or in
  97. * an export. We have to determine from the subtype whether or not it
  98. * is local or shared custom content.
  99. */
  100. function ctools_custom_content_type_get_conf($subtype, $conf) {
  101. if ($subtype['name'] != 'custom') {
  102. $settings = $subtype['content']->settings;
  103. $settings['custom_type'] = 'fixed';
  104. $settings['content'] = $subtype['content'];
  105. }
  106. else {
  107. // This means they created it as custom content and then set it as
  108. // reusable. Since we're not allowed to change the subtype, we're
  109. // still stored as though we are local, but are pointing off to
  110. // non-local.
  111. if (!empty($conf['name']) && module_exists('ctools_custom_content')) {
  112. ctools_include('export');
  113. $content = ctools_export_crud_load('ctools_custom_content', $conf['name']);
  114. if ($content) {
  115. $settings = $content->settings;
  116. $settings['custom_type'] = 'fixed';
  117. $settings['content'] = $content;
  118. $settings['admin_title'] = $content->admin_title;
  119. }
  120. else {
  121. $content = ctools_export_crud_new('ctools_custom_content');
  122. $content->name = $conf['name'];
  123. $settings = array(
  124. 'admin_title' => t('Missing/deleted content'),
  125. 'title' => '',
  126. 'body' => '',
  127. 'format' => filter_default_format(),
  128. 'substitute' => TRUE,
  129. 'custom_type' => 'fixed',
  130. 'content' => $content,
  131. );
  132. }
  133. }
  134. // This means that it is created as custom and has not been set to
  135. // reusable.
  136. else {
  137. $settings = $conf;
  138. $settings['custom_type'] = 'local';
  139. }
  140. }
  141. // Correct for an error that came in because filter format changed.
  142. if (is_array($settings['body'])) {
  143. $settings['format'] = $settings['body']['format'];
  144. $settings['body'] = $settings['body']['value'];
  145. }
  146. return $settings;
  147. }
  148. function ctools_custom_content_type_editable($content_type, $subtype, $conf) {
  149. if ($subtype['name'] == 'custom' && !empty($conf['name'])) {
  150. return FALSE;
  151. }
  152. return TRUE;
  153. }
  154. /**
  155. * Output function for the 'custom' content type. Outputs a custom
  156. * based on the module and delta supplied in the configuration.
  157. */
  158. function ctools_custom_content_type_render($subtype, $conf, $args, $contexts) {
  159. $settings = ctools_custom_content_type_get_conf(ctools_custom_content_type_content_type($subtype), $conf);
  160. static $delta = 0;
  161. $block = new stdClass();
  162. $block->subtype = ++$delta;
  163. $block->title = filter_xss_admin($settings['title']);
  164. // Add keyword substitutions if we were configured to do so.
  165. $content = $settings['body'];
  166. if (!empty($contexts) && !empty($settings['substitute'])) {
  167. $content = ctools_context_keyword_substitute($content, array(), $contexts);
  168. }
  169. $block->content = check_markup($content, $settings['format']);
  170. if ($settings['custom_type'] == 'fixed' && user_access('administer custom content')) {
  171. $block->admin_links = array(
  172. array(
  173. 'title' => t('Configure content pane'),
  174. 'alt' => t("Configure this pane in administer >> structure >> custom content panes"),
  175. 'href' => 'admin/structure/ctools-content/list/' . $settings['content']->name . '/edit',
  176. 'query' => drupal_get_destination(),
  177. ),
  178. );
  179. }
  180. return $block;
  181. }
  182. /**
  183. * Callback to provide the administrative title of the custom content.
  184. */
  185. function ctools_custom_content_type_admin_title($subtype, $conf) {
  186. $settings = ctools_custom_content_type_get_conf(ctools_custom_content_type_content_type($subtype), $conf);
  187. $output = t('Custom');
  188. $title = !empty($settings['admin_title']) ? $settings['admin_title'] : $settings['title'];
  189. if ($title) {
  190. if ($settings['custom_type'] != 'fixed') {
  191. $output = t('Custom: @title', array('@title' => $title));
  192. }
  193. else {
  194. $output = $title;
  195. }
  196. }
  197. return $output;
  198. }
  199. /**
  200. * Callback to provide administrative info. In this case we'll render the
  201. * content as long as it's not PHP, which is too risky to render here.
  202. */
  203. function ctools_custom_content_type_admin_info($subtype, $conf) {
  204. $settings = ctools_custom_content_type_get_conf(ctools_custom_content_type_content_type($subtype), $conf);
  205. $block = new stdClass();
  206. $block->title = filter_xss_admin($settings['title']);
  207. // We don't want to render php output on preview here, because if something is
  208. // wrong the whole display will be borked. So we check to see if the php
  209. // evaluator filter is being used, and make a temporary change to the filter
  210. // so that we get the printed php, not the eval'ed php.
  211. $php_filter = FALSE;
  212. foreach (filter_list_format($settings['format']) as $filter) {
  213. if ($filter->module == 'php') {
  214. $php_filter = TRUE;
  215. break;
  216. }
  217. }
  218. // If a php filter is active, just print the source, but only if the current
  219. // user has access to the actual filter.
  220. if ($php_filter) {
  221. $filter = filter_format_load($settings['format']);
  222. if (!filter_access($filter)) {
  223. return NULL;
  224. }
  225. $block->content = '<pre>' . check_plain($settings['body']) . '</pre>';
  226. }
  227. else {
  228. // We also need to filter through XSS admin because <script> tags can
  229. // cause javascript which will interfere with our ajax.
  230. $block->content = filter_xss_admin(check_markup($settings['body'], $settings['format']));
  231. }
  232. return $block;
  233. }
  234. /**
  235. * Returns an edit form for the custom type.
  236. */
  237. function ctools_custom_content_type_edit_form($form, &$form_state) {
  238. $settings = ctools_custom_content_type_get_conf($form_state['subtype'], $form_state['conf']);
  239. $form_state['settings'] = $settings;
  240. if ($settings['custom_type'] == 'fixed') {
  241. return $form; // no form for this case.
  242. }
  243. $form['admin_title'] = array(
  244. '#type' => 'textfield',
  245. '#default_value' => isset($settings['admin_title']) ? $settings['admin_title'] : '',
  246. '#title' => t('Administrative title'),
  247. '#description' => t('This title will be used administratively to identify this pane. If blank, the regular title will be used.'),
  248. );
  249. $form['title'] = array(
  250. '#type' => 'textfield',
  251. '#default_value' => $settings['title'],
  252. '#title' => t('Title'),
  253. );
  254. $form['body'] = array(
  255. '#type' => 'text_format',
  256. '#title' => t('Body'),
  257. '#default_value' => $settings['body'],
  258. '#format' => $settings['format'],
  259. );
  260. if (!empty($form_state['contexts'])) {
  261. // Set extended description if both CCK and Token modules are enabled, notifying of unlisted keywords
  262. if (module_exists('content') && module_exists('token')) {
  263. $description = t('If checked, context keywords will be substituted in this content. Note that CCK fields may be used as keywords using patterns like <em>%node:field_name-formatted</em>.');
  264. }
  265. elseif (!module_exists('token')) {
  266. $description = t('If checked, context keywords will be substituted in this content. More keywords will be available if you install the Token module, see http://drupal.org/project/token.');
  267. }
  268. else {
  269. $description = t('If checked, context keywords will be substituted in this content.');
  270. }
  271. $form['substitute'] = array(
  272. '#type' => 'checkbox',
  273. '#title' => t('Use context keywords'),
  274. '#description' => $description,
  275. '#default_value' => !empty($settings['substitute']),
  276. );
  277. $form['contexts'] = array(
  278. '#title' => t('Substitutions'),
  279. '#type' => 'fieldset',
  280. '#collapsible' => TRUE,
  281. '#collapsed' => TRUE,
  282. );
  283. $rows = array();
  284. foreach ($form_state['contexts'] as $context) {
  285. foreach (ctools_context_get_converters('%' . check_plain($context->keyword) . ':', $context) as $keyword => $title) {
  286. $rows[] = array(
  287. check_plain($keyword),
  288. t('@identifier: @title', array('@title' => $title, '@identifier' => $context->identifier)),
  289. );
  290. }
  291. }
  292. $header = array(t('Keyword'), t('Value'));
  293. $form['contexts']['context'] = array('#markup' => theme('table', array('header' => $header, 'rows' => $rows)));
  294. }
  295. if (!user_access('administer custom content') || !module_exists('ctools_custom_content')) {
  296. return $form;
  297. }
  298. // Make the other form items dependent upon it.
  299. ctools_include('dependent');
  300. ctools_add_js('dependent');
  301. $form['reusable'] = array(
  302. '#type' => 'checkbox',
  303. '#title' => t('Make this content reusable'),
  304. '#default_value' => FALSE,
  305. );
  306. $form['name'] = array(
  307. '#type' => 'textfield',
  308. '#title' => t('Machine name'),
  309. '#description' => t('The machine readable name of this content. It must be unique, and it must contain only alphanumeric characters and underscores. Once created, you will not be able to change this value!'),
  310. '#dependency' => array('edit-reusable' => array(1)),
  311. );
  312. $form['category'] = array(
  313. '#type' => 'textfield',
  314. '#title' => t('Category'),
  315. '#description' => t('What category this content should appear in. If left blank the category will be "Miscellaneous".'),
  316. '#dependency' => array('edit-reusable' => array(1)),
  317. );
  318. $form['admin_description'] = array(
  319. '#type' => 'textarea',
  320. '#title' => t('Administrative description'),
  321. '#description' => t('A description of what this content is, does or is for, for administrative use.'),
  322. '#dependency' => array('edit-reusable' => array(1)),
  323. );
  324. return $form;
  325. }
  326. function _ctools_custom_content_type_edit_save(&$content, $form_state) {
  327. // Apply updates to the content object.
  328. $content->category = $form_state['values']['category'];
  329. $content->admin_title = $form_state['values']['admin_title'];
  330. $content->admin_description = $form_state['values']['admin_description'];
  331. foreach (array_keys($form_state['plugin']['defaults']) as $key) {
  332. if (isset($form_state['values'][$key])) {
  333. $content->settings[$key] = $form_state['values'][$key];
  334. }
  335. }
  336. ctools_export_crud_save('ctools_custom_content', $content);
  337. }
  338. /**
  339. * The validate form to ensure the custom content data is okay.
  340. */
  341. function ctools_custom_content_type_edit_form_validate(&$form, &$form_state) {
  342. if ($form_state['settings']['custom_type'] != 'fixed' && !empty($form_state['values']['reusable'])) {
  343. if (empty($form_state['values']['name'])) {
  344. form_error($form['name'], t('Name is required.'));
  345. }
  346. // Check for string identifier sanity
  347. if (!preg_match('!^[a-z0-9_]+$!', $form_state['values']['name'])) {
  348. form_error($form['name'], t('The name can only consist of lowercase letters, underscores, and numbers.'));
  349. return;
  350. }
  351. if (!module_exists('ctools_custom_content')) {
  352. return;
  353. }
  354. // Check for name collision
  355. if ($form_state['values']['name'] == 'custom' || (ctools_export_crud_load('ctools_custom_content', $form_state['values']['name']))) {
  356. form_error($form['name'], t('Content with this name already exists. Please choose another name or delete the existing item before creating a new one.'));
  357. }
  358. }
  359. }
  360. /**
  361. * The submit form stores the data in $conf.
  362. */
  363. function ctools_custom_content_type_edit_form_submit($form, &$form_state) {
  364. // Because of changes in filter form, these two keys are out of position:
  365. $form_state['values']['format'] = $form_state['values']['body']['format'];
  366. $form_state['values']['body'] = $form_state['values']['body']['value'];
  367. if ($form_state['settings']['custom_type'] == 'fixed') {
  368. _ctools_custom_content_type_edit_save($form_state['settings']['content'], $form_state);
  369. }
  370. // If the 'reusable' checkbox was checked, we will create a new
  371. // custom content and give it the proper values.
  372. else if (!empty($form_state['values']['reusable'])) {
  373. $content = ctools_export_crud_new('ctools_custom_content');
  374. $content->name = $form_state['values']['name'];
  375. _ctools_custom_content_type_edit_save($content, $form_state);
  376. $form_state['conf']['name'] = $content->name;
  377. }
  378. else {
  379. // Otherwise, just save values into $conf normally.
  380. foreach (array_keys($form_state['plugin']['defaults']) as $key) {
  381. $form_state['conf'][$key] = isset($form_state['values'][$key]) ? $form_state['values'][$key] : $form_state['plugin']['defaults'][$key];
  382. }
  383. }
  384. }
Error | ELMSLN API

Error

×

Error message

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