PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/simple-forum/linking/forms/sf-form-blog-link.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 163 lines | 119 code | 17 blank | 27 comment | 20 complexity | b38038a78bafee67f585107e988597b9 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /*
  3. Simple:Press
  4. Blog Linking - blog post form
  5. $LastChangedDate: 2011-03-05 07:42:11 -0700 (Sat, 05 Mar 2011) $
  6. $Rev: 5631 $
  7. */
  8. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
  9. die('Access Denied');
  10. }
  11. # ------------------------------------------------------------------
  12. # sf_blog_link_form()
  13. #
  14. # Filter call
  15. # Sets up the forum post linking form in the Post/Page Write screen
  16. # ------------------------------------------------------------------
  17. function sf_blog_link_form()
  18. {
  19. global $current_user;
  20. if(function_exists('add_meta_box'))
  21. {
  22. sf_initialise_globals();
  23. # can the user do this?
  24. if (!$current_user->sflinkuse) return;
  25. $sflinkposttype = array();
  26. $sflinkposttype = sf_get_option('sflinkposttype');
  27. if($sflinkposttype)
  28. {
  29. foreach($sflinkposttype as $key=>$value)
  30. {
  31. if($value == true)
  32. {
  33. add_meta_box('sfforumlink', esc_attr(__("Link To Forum", "sforum")), 'sf_populate_post_form', $key, 'advanced');
  34. }
  35. }
  36. }
  37. }
  38. return;
  39. }
  40. # ------------------------------------------------------------------
  41. # sf_populate_post_form()
  42. #
  43. # Callback functin to display form in blog post/page panels
  44. # ------------------------------------------------------------------
  45. function sf_populate_post_form()
  46. {
  47. global $post;
  48. $forumid = 0;
  49. $checked = 'checked="checked"';
  50. $linkchecked = '';
  51. $editchecked = '';
  52. $sfpostlinking = sf_get_option('sfpostlinking');
  53. if(isset($post->ID))
  54. {
  55. $links = sf_blog_links_control('read', $post->ID);
  56. if($links)
  57. {
  58. $linkchecked = $checked;
  59. if($links->syncedit || $sfpostlinking['sfautoupdate']) $editchecked=$checked;
  60. $forumid = $links->forum_id;
  61. } else {
  62. if($sfpostlinking['sfautocreate'])
  63. {
  64. $linkchecked = 'checked="checked"';
  65. $forumid = $sfpostlinking['sfautoforum'];
  66. if($sfpostlinking['sfautoupdate']) $editchecked=$checked;
  67. }
  68. }
  69. }
  70. echo '<div id="spf-linking">';
  71. if(!$links)
  72. {
  73. # No current link or new
  74. ?>
  75. <p><label for="sflink" class="selectit">
  76. <input type="checkbox" <?php echo($linkchecked); ?> name="sflink" id="sflink" />
  77. <?php _e("Create forum topic", "sforum"); ?></label><br /><br />
  78. <label for="sfforum" class="selectit"><?php esc_attr_e("Select forum:", "sforum"); ?><br />
  79. <?php echo(sf_blog_links_list($forumid)).'</label>';
  80. } else {
  81. # existing link
  82. $ahahURL = SFHOMEURL."index.php?sf_ahah=linking&action=breaklink&postid=".$post->ID;
  83. $target = 'spf-linking';
  84. $confirm = esc_js(__("Are you sure you want to break this link?", "sforum"));
  85. echo '<p>'.sprintf(__("This post is linked to the forum %s", "sforum"), '<br /><b>'.sf_get_forum_name_from_id($links->forum_id)).'</b><br /><br />';
  86. echo '<a target="_blank" class="button" href="'.sf_build_url(sf_get_forum_slug($links->forum_id), sf_get_topic_slug($links->topic_id), 1, 0).'">'.__("View Topic in Forum", "sforum").'</a>&nbsp;';
  87. echo '<a class="button" href="javascript:void(0);" onclick="javascript: if(confirm(\''.$confirm.'\')) {sfjBreakBlogLink(\''.$ahahURL.'\', \''.$target.'\');}">'.__("Break Forum Link", "sforum").'</a>';
  88. }
  89. ?>
  90. <br /><br />
  91. <label for="sfedit" class="selectit">
  92. <input type="checkbox" <?php echo($editchecked); ?> name="sfedit" id="sfedit" />
  93. <?php _e("Update forum topic with subsequent edits", "sforum"); ?></label><br /><br />
  94. <?php
  95. echo '</p>';
  96. echo '</div>';
  97. ?>
  98. <script type="text/javascript">
  99. function sfjBreakBlogLink(ahahurl, target)
  100. {
  101. jQuery(document).ready(function() {
  102. jQuery('#'+<?php echo(target); ?>).load(<?php echo(ahahurl); ?>);
  103. });
  104. }
  105. </script>
  106. <?php
  107. return;
  108. }
  109. # ------------------------------------------------------------------
  110. # sf_blog_links_list()
  111. #
  112. # Support Routine
  113. # Lists forums for the post write link box
  114. # $forumid ID of the forum if already linked (Edit mode)
  115. # ------------------------------------------------------------------
  116. function sf_blog_links_list($forumid)
  117. {
  118. $space = '&nbsp;&nbsp;';
  119. $groups = sf_get_combined_groups_and_forums_bloglink();
  120. if($groups)
  121. {
  122. $out = '';
  123. $out.= '<select id="sfforum" name="sfforum">'."\n";
  124. foreach($groups as $group)
  125. {
  126. $out.= '<optgroup label="'.sf_create_name_extract(sf_filter_title_display($group['group_name'])).'">'."\n";
  127. if($group['forums'])
  128. {
  129. foreach($group['forums'] as $forum)
  130. {
  131. if($forumid == $forum['forum_id'])
  132. {
  133. $text = 'selected="selected" ';
  134. } else {
  135. $text = '';
  136. }
  137. $out.='<option '.$text.'value="'.$forum['forum_id'].'">'.$space.sf_create_name_extract(sf_filter_title_display($forum['forum_name'])).'</option>'."\n";
  138. }
  139. }
  140. $out.='</optgroup>';
  141. }
  142. $out.='</select>'."\n";
  143. }
  144. return $out;
  145. }
  146. ?>