Crosspost your messages to Juick.com https://wordpress.org/plugins/juick-xp/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

193 lines
6.0KB

  1. <?php
  2. /**
  3. * Plugin Name: Juick Crossposter
  4. * Plugin URI: https://github.com/sandfox-im/juick-xp
  5. * Description: A simple Juick.com crossposter plugin
  6. * Version: 0.3.1
  7. * Author: Sand Fox
  8. * Author URI: http://sandfox.im/
  9. * License: GNU GPL v2
  10. */
  11. add_action('publish_post', 'juickxp_post');
  12. function juickxp_post($post_id)
  13. {
  14. $juick = get_option('juickxp_custom_jid');
  15. $include_text = get_option('juickxp_include_text', false);
  16. if (!function_exists('xmpp_send')) // no xmpp sender plugin
  17. {
  18. return;
  19. }
  20. $tags_s = '';
  21. $tags = array();
  22. $tags_custom = explode(' ', get_option('juickxp_jtags_custom'));
  23. foreach ($tags_custom as $tag) {
  24. if (!empty($tag)) {
  25. $tags[] = $tag;
  26. }
  27. }
  28. $post = get_post($post_id);
  29. $post_link = get_permalink($post_id);
  30. if (get_option('juickxp_jtags_categories')) {
  31. foreach (wp_get_object_terms($post_id, 'category') as $tag) {
  32. $tags [] = str_replace(' ', '-', $tag->name);
  33. }
  34. }
  35. if (get_option('juickxp_jtags_tags')) {
  36. foreach (wp_get_object_terms($post_id, 'post_tag') as $tag) {
  37. $tags [] = str_replace(' ', '-', $tag->name);
  38. }
  39. }
  40. $k = 5;
  41. foreach ($tags as $tag) {
  42. if (!$k) {
  43. break;
  44. }
  45. $tags_s .= "*$tag ";
  46. $k--;
  47. }
  48. if (empty($juick)) {
  49. $juick = '[email protected]';
  50. }
  51. if ($post->post_type != 'post') // no pages or attachments!
  52. {
  53. return;
  54. }
  55. $message = $tags_s;
  56. $message .= $post->post_title . "\n";
  57. if ($include_text) {
  58. $message .= "\n" . strip_tags($post->post_excerpt ? $post->post_excerpt : $post->post_content) . "\n\n";
  59. }
  60. $message .= $post_link;
  61. xmpp_send($juick, $message);
  62. }
  63. /* ----- settings section -------- */
  64. add_action('admin_menu', 'juickxp_create_menu');
  65. function juickxp_create_menu()
  66. {
  67. if (!function_exists('xmpp_send')) // in case XMPP Enabled is not present
  68. {
  69. add_submenu_page('plugins.php', 'Juick Crossposter Settings', 'Juick Crossposter', 'administrator', __FILE__, 'juickxp_settings_page');
  70. }
  71. add_submenu_page('xmpp-enabled', 'Juick Crossposter Settings', 'Juick Crossposter', 'administrator', __FILE__, 'juickxp_settings_page');
  72. add_action('admin_init', 'register_juickxp_settings');
  73. }
  74. function register_juickxp_settings()
  75. {
  76. register_setting('juickxp-settings', 'juickxp_include_text');
  77. register_setting('juickxp-settings', 'juickxp_jtags_custom');
  78. register_setting('juickxp-settings', 'juickxp_jtags_categories');
  79. register_setting('juickxp-settings', 'juickxp_jtags_tags');
  80. register_setting('juickxp-settings', 'juickxp_custom_jid');
  81. }
  82. function juickxp_settings_page()
  83. {
  84. ?>
  85. <div class="wrap">
  86. <h2>Juick XP Settings</h2>
  87. <?php if (!function_exists('xmpp_send')):
  88. ?><p style="color: red">Error: <strong>XMPP Enabled</strong> is not installed.
  89. Please install the <strong>XMPP Enabled</strong> plugin for this plugin to work</p>
  90. <ul>
  91. <li><a href="http://wordpress.org/extend/plugins/xmpp-enabled/">
  92. http://wordpress.org/extend/plugins/xmpp-enabled/</a>
  93. </li>
  94. <li>
  95. <a href="http://sandfox.org/projects/xmpp-enabled.html">
  96. http://sandfox.org/projects/xmpp-enabled.html</a>
  97. </li>
  98. </ul>
  99. <hr/>
  100. <?php
  101. endif;
  102. ?>
  103. <form method="post" action="options.php">
  104. <?php settings_fields('juickxp-settings'); ?>
  105. <table class="form-table">
  106. <tr valign="top">
  107. <th scope="row">Custom tags (separated by space)<br/>
  108. <small>(prefix * is added automatically)</small>
  109. </th>
  110. <td>
  111. <input type="text" name="juickxp_jtags_custom"
  112. value="<?php echo get_option('juickxp_jtags_custom', 'wp-juick-xp'); ?>"/>
  113. </td>
  114. </tr>
  115. <tr>
  116. <th scope="row" colspan="2">
  117. <input type="checkbox" value="1" name="juickxp_jtags_categories" id="juickxp_jtags_categories"
  118. <?php if (get_option('juickxp_jtags_categories', true)) echo 'checked="checked"' ?>
  119. /> <label for="juickxp_jtags_categories">Include post categories as Juick tags</label>
  120. </th>
  121. </tr>
  122. <tr>
  123. <th scope="row" colspan="2">
  124. <input type="checkbox" value="1" name="juickxp_jtags_tags" id="juickxp_jtags_tags"
  125. <?php if (get_option('juickxp_jtags_tags', true)) echo 'checked="checked"' ?>
  126. /> <label for="juickxp_jtags_tags">Include post tags as Juick tags</label>
  127. </th>
  128. </tr>
  129. <tr>
  130. <th scope="row" colspan="2">
  131. The order is {custom, categories, tags} limited by 5
  132. </th>
  133. </tr>
  134. <tr>
  135. <th scope="row" colspan="2">
  136. <input type="checkbox" value="1" name="juickxp_include_text" id="juickxp_include_text"
  137. <?php if (get_option('juickxp_include_text', false)) echo 'checked="checked"' ?>
  138. /> <label for="juickxp_include_text">Include excerpt<br/>
  139. <small>Experimental feature</small>
  140. </label>
  141. </th>
  142. </tr>
  143. <tr valign="top">
  144. <th scope="row">Custom Juick JID<br/>
  145. <small>Leave blank for [email protected]</small>
  146. </th>
  147. <td>
  148. <input type="text" name="juickxp_custom_jid"
  149. value="<?php echo get_option('juickxp_custom_jid'); ?>"/>
  150. </td>
  151. </tr>
  152. </table>
  153. <p class="submit">
  154. <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>"/>
  155. </p>
  156. </form>
  157. </div><?php
  158. }