quickpost_bookmarklet.module

  1. cis7 sites/all/modules/elmsln_contrib/quickpost_bookmarklet/quickpost_bookmarklet.module
  2. cle7 sites/all/modules/elmsln_contrib/quickpost_bookmarklet/quickpost_bookmarklet.module
  3. ecd7 sites/all/modules/elmsln_contrib/quickpost_bookmarklet/quickpost_bookmarklet.module
  4. elmsmedia7 sites/all/modules/elmsln_contrib/quickpost_bookmarklet/quickpost_bookmarklet.module
  5. harmony7 sites/all/modules/elmsln_contrib/quickpost_bookmarklet/quickpost_bookmarklet.module
  6. icor7 sites/all/modules/elmsln_contrib/quickpost_bookmarklet/quickpost_bookmarklet.module
  7. meedjum_blog7 sites/all/modules/elmsln_contrib/quickpost_bookmarklet/quickpost_bookmarklet.module
  8. mooc7 sites/all/modules/elmsln_contrib/quickpost_bookmarklet/quickpost_bookmarklet.module

QuickPost Bookmarklet

Build a bookmarklet to streamline posting outside articles to your site.

Functions

Namesort descending Description
quickpost_bookmarklet_menu Implements hook_menu().
quickpost_bookmarklet_settings Helper function to add js to the settings form.
quickpost_bookmarklet_settings_form Bookmarklet settings form.
quickpost_bookmarklet_settings_form_submit Implements hook_form_submit().
_quickpost_bookmarklet_generate Bookmarklet generator, this removes the need for the js calls.

Constants

File

sites/all/modules/elmsln_contrib/quickpost_bookmarklet/quickpost_bookmarklet.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * QuickPost Bookmarklet
  5. *
  6. * Build a bookmarklet to streamline posting outside articles to your site.
  7. */
  8. // token to replace for title
  9. define('QUICKPOST_BOOKMARKLET_TITLE', '[title]');
  10. // token replacement for body format
  11. define('QUICKPOST_BOOKMARKLET_BODY', "<blockquote>[selection]</blockquote>\n\nFrom <a href='[url]'>[title]</a>");
  12. // label of the item by default
  13. define('QUICKPOST_BOOKMARKLET_LABEL', 'QuickPost');
  14. // default mode for opening
  15. define('QUICKPOST_BOOKMARKLET_OPEN_IN', 'popup');
  16. /**
  17. * Implements hook_menu().
  18. */
  19. function quickpost_bookmarklet_menu() {
  20. $items['admin/config/content/quickpost_bookmarklet'] = array(
  21. 'title' => 'QuickPost bookmarklet',
  22. 'description' => 'Customize a QuickPost bookmarklet that can be dragged to your bookmarks toolbar.',
  23. 'page callback' => 'quickpost_bookmarklet_settings',
  24. 'access arguments' => array('administer content'),
  25. );
  26. return $items;
  27. }
  28. /**
  29. * Helper function to add js to the settings form.
  30. */
  31. function quickpost_bookmarklet_settings() {
  32. drupal_add_js(drupal_get_path('module', 'quickpost_bookmarklet') . '/options.js');
  33. drupal_add_js(array('bookmarklet_base_path' => url('node/add', array('absolute' => TRUE))), 'setting');
  34. drupal_add_js(array('bookmarklet_clean_url' => variable_get('clean_url', FALSE)), 'setting');
  35. return drupal_get_form('quickpost_bookmarklet_settings_form');
  36. }
  37. /**
  38. * Bookmarklet settings form.
  39. */
  40. function quickpost_bookmarklet_settings_form($form, &$form_state) {
  41. $form['#attributes'] = array(
  42. 'class' => 'quickpost_bookmarklet_settings_form',
  43. );
  44. $node_types = array();
  45. foreach (node_type_get_types() as $type) {
  46. $type_url_str = str_replace('_', '-', $type->type);
  47. $node_types[$type_url_str] = $type->name;
  48. }
  49. $form['#prefix'] = "<div class='admin'>";
  50. $form['#suffix'] = "</div>";
  51. $form['bookmarklet_options'] = array(
  52. '#type' => 'fieldset',
  53. '#title' => t('Bookmarklet options'),
  54. '#collapsible' => FALSE,
  55. '#prefix' => "<div class='left clearfix'>",
  56. '#suffix' => "</div>",
  57. );
  58. $form['bookmarklet_options']['content_type'] = array(
  59. '#type' => 'select',
  60. '#title' => t('Content type'),
  61. '#description' => t('Which content type should be created by this bookmarklet?'),
  62. '#options' => $node_types,
  63. '#multiple' => TRUE,
  64. '#default_value' => variable_get('quickpost_bookmarklet_types', ''),
  65. );
  66. $form['bookmarklet_options']['available_tokens'] = array(
  67. '#type' => 'fieldset',
  68. '#title' => t('Available tokens'),
  69. '#description' => t('The following tokens may be used in the title and body templates.'),
  70. '#collapsible' => TRUE,
  71. '#collapsed' => TRUE,
  72. );
  73. $table_options = array(
  74. 'header' => array(
  75. t('Token'),
  76. t('Description'),
  77. ),
  78. 'rows' => array(
  79. array(
  80. '[title]',
  81. t('Page title'),
  82. ),
  83. array(
  84. '[url]',
  85. t('Page url'),
  86. ),
  87. array(
  88. '[selection]',
  89. t('User-selected text on the page'),
  90. ),
  91. ),
  92. );
  93. $form['bookmarklet_options']['available_tokens']['tokens'] = array(
  94. '#markup' => theme('table', $table_options),
  95. '#prefix' => '<div>',
  96. '#suffix' => '</div>',
  97. );
  98. $form['bookmarklet_options']['title_template'] = array(
  99. '#type' => 'textfield',
  100. '#title' => t('Title template'),
  101. '#description' => t('Template to use for the title on the new node.'),
  102. '#default_value' => variable_get('quickpost_bookmarklet_title', QUICKPOST_BOOKMARKLET_TITLE),
  103. '#size' => 40,
  104. '#maxlength' => 255,
  105. );
  106. $form['bookmarklet_options']['body_template'] = array(
  107. '#type' => 'textarea',
  108. '#title' => t('Body template'),
  109. '#description' => t('Template to use for the body on the new node.'),
  110. '#default_value' => variable_get('quickpost_bookmarklet_body', QUICKPOST_BOOKMARKLET_BODY),
  111. '#cols' => 60,
  112. '#rows' => 5,
  113. );
  114. $form['bookmarklet_options']['additional_options'] = array(
  115. '#type' => 'fieldset',
  116. '#title' => t('Additional options'),
  117. '#collapsible' => TRUE,
  118. '#collapsed' => TRUE,
  119. );
  120. $form['bookmarklet_options']['additional_options']['open_in'] = array(
  121. '#type' => 'radios',
  122. '#title' => t('Open in'),
  123. '#description' => t('Where should the node add page open?'),
  124. '#options' => array(
  125. 'popup' => 'Pop-up window',
  126. 'window' => 'Full window/new tab (depends on browser settings)',
  127. ),
  128. '#default_value' => variable_get('quickpost_bookmarklet_open_in', QUICKPOST_BOOKMARKLET_OPEN_IN),
  129. );
  130. $form['bookmarklet_options']['additional_options']['bookmarklet_label'] = array(
  131. '#type' => 'textfield',
  132. '#title' => t('Bookmarklet label'),
  133. '#description' => t('Used as the default label for the bookmarklet.'),
  134. '#size' => 40,
  135. '#maxlength' => 255,
  136. '#default_value' => variable_get('quickpost_bookmarklet_label', QUICKPOST_BOOKMARKLET_LABEL),
  137. );
  138. $form['bookmarklet_options']['generate_bookmarklet'] = array(
  139. '#type' => 'button',
  140. '#value' => t('Generate bookmarklet'),
  141. );
  142. $form['bookmarklet'] = array(
  143. '#type' => 'fieldset',
  144. '#title' => t('Bookmarklet'),
  145. '#collapsible' => FALSE,
  146. '#prefix' => "<div class='right clearfix'>",
  147. '#suffix' => "</div>",
  148. );
  149. $form['bookmarklet']['bookmarklet_container'] = array(
  150. '#markup' => t('(Your bookmarklet will appear here after you click Generate Bookmarklet above)'),
  151. '#prefix' => '<div class="bookmarklet_container">',
  152. '#suffix' => '</div>',
  153. );
  154. $form['#submit'][] = 'quickpost_bookmarklet_settings_form_submit';
  155. return system_settings_form($form);
  156. }
  157. /**
  158. * Implements hook_form_submit().
  159. */
  160. function quickpost_bookmarklet_settings_form_submit($form, &$form_state) {
  161. $value = $form_state['values'];
  162. // capture form settings as variables for defaults
  163. variable_set('quickpost_bookmarklet_types', $value['content_type']);
  164. variable_set('quickpost_bookmarklet_title', $value['title_template']);
  165. variable_set('quickpost_bookmarklet_body', $value['body_template']);
  166. variable_set('quickpost_bookmarklet_open_in', $value['open_in']);
  167. variable_set('quickpost_bookmarklet_label', $value['bookmarklet_label']);
  168. }
  169. /**
  170. * Bookmarklet generator, this removes the need for the js calls.
  171. *
  172. * Disadvantage of this approach is that it currently has less flexibility
  173. * Advantage is that it's very easy to modify.
  174. */
  175. function _quickpost_bookmarklet_generate($options) {
  176. $links = array();
  177. // build the standard js
  178. $js ='javascript:var nodeaddpath="';
  179. // build base url
  180. $js .= url('node/add/', array('absolute' => TRUE));
  181. // add in the type that's getting populated
  182. $js .= $options['type'];
  183. // more standard js
  184. $js .= '",d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=e?e():k?k():x?x.createRange().text:0,l=d.location,e=encodeURIComponent,';
  185. // @todo Apply body
  186. // @todo Apply open_in option
  187. // @todo Apply utilize tokens like generator button does
  188. $js .= 'title="' . $options['title'] . '"+d.title+"",body="<blockquote>"+s+\'</blockquote>\nFrom <a href="\'+d.location+\'">\'+d.title+"</a>",url=nodeaddpath+"' . (variable_get('clean_url', FALSE) ? '?' : '&') . 'edit[title]="+e(title)+"&edit[body][und][0][value]="+e(body);nourl=function(){w.location=nodeaddpath};a=function(){w.open(url,"quickpost","toolbar=0,resizable=1,scrollbars=1,status=1,width=1024,height=570")||(l.href=url)};/Firefox/.test(navigator.userAgent)?"about:blank"==l?setTimeout(nourl,0):setTimeout(a,0):"about:blank"==l?nourl():a();;void(0);';
  189. $links['quickpost_bookmarklet'] = array(
  190. 'title' => $options['label'],
  191. 'href' => $js,
  192. 'absolute' => TRUE,
  193. 'external' => TRUE,
  194. 'attributes' => array(
  195. 'title' => t('Bookmark this link to quickly create content'),
  196. ),
  197. );
  198. return $links;
  199. }
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.