PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/besana/besana_callback.php

https://github.com/eloypineda/XHTMLized
PHP | 72 lines | 28 code | 10 blank | 34 comment | 5 complexity | 85d3aa6bf1534ae6c1862b1f86548f6e MD5 | raw file
  1. <?php
  2. /**
  3. * Template Name: callback
  4. *
  5. * This page will response AJAX callbacks
  6. *
  7. * @package WordPress
  8. * @subpackage Besana
  9. * @since Besana 1.0
  10. */
  11. ?>
  12. <?php
  13. if (isset($_POST['post_id'])) {
  14. $post_ID = $_POST['post_id'];
  15. } else {
  16. $post_ID = '';
  17. }
  18. //$post_ID = '47';
  19. //$post = get_post($post_ID);
  20. global $wpdb;
  21. $result = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID = '$post_ID' LIMIT 1");
  22. if ($result) {
  23. $post_data = $result[0];
  24. } else {
  25. die('No exite.');
  26. }
  27. /*
  28. echo "<br />----------- blog post -----------<br />";
  29. echo "<pre>";
  30. print_r($post_data);
  31. echo "</pre>";
  32. */
  33. if (has_post_thumbnail($post_data->ID)) {
  34. $image = wp_get_attachment_image_src(get_post_thumbnail_id($post_data->ID), 'full');
  35. }
  36. $site_url = site_url();
  37. $image_path = dirname($_SERVER['SCRIPT_NAME']) . str_replace($site_url, '', $image[0]);
  38. /*
  39. echo $image_path;
  40. echo "<br />----------- image -----------<br />";
  41. echo "<pre>";
  42. print_r($image);
  43. echo "</pre>";
  44. echo '<p>dirname SERVER[SCRIPT_NAME]: ' . dirname($_SERVER['SCRIPT_NAME']) . '</p>';
  45. echo "dirname: " . basename($image_path);
  46. echo "<br />----------- SERVER -----------<br />";
  47. echo "<pre>";
  48. print_r($_SERVER);
  49. echo "</pre>";
  50. */
  51. header('Content-type: application/json');
  52. echo json_encode(array(
  53. 'ID' => $post_data->ID,
  54. 'title' => $post_data->post_title,
  55. 'content' => $post_data->post_content,
  56. 'image_path' => $image_path
  57. ));
  58. ?>