Advertisement
Guest User

WP API Extension

a guest
Sep 13th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 39.55 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. 2013/09/12, Plugin functionality extended by Christian Schneider:
  5. In order to be able to provide JSonP documents besides JSon documents a
  6. few simple changes have been made in this file:
  7. - the method printJSonPIfRequired($textToBePrinted) has been added at
  8.   the end. It checks whether the GET-variable 'callbackp' is set and
  9.   (if so) sends a JsonP document as specified in the variable. If
  10.   'callbackp' is not set, the a JSon document ist being printed.
  11. - whenever the GET-parameter 'div' is set 0, my print-function is being
  12.   called instead of the default print-function.
  13. */
  14.  
  15.  
  16.  
  17. @include_once('JSON.php');
  18. @include_once ('DEV.php');
  19. class get_posts
  20. {
  21.     function __construct()
  22.     {
  23.         add_filter('rewrite_rules_array','get_posts::insertRules');
  24.         add_filter('query_vars','get_posts::insertQueryVars');
  25.         add_action('parse_query','get_posts::insertParseQuery');   
  26.     }
  27.     static function posts_info($dev,$comm,$con,$type)
  28.     {
  29.         global $wpdb;
  30.         $sql = 'SELECT DISTINCT * FROM '.$wpdb->posts.' AS POSTS WHERE POSTS.post_status="publish"';
  31.         $obj = $wpdb->get_results($sql);
  32.         $count_total = 0;
  33.         foreach($obj as $num)
  34.         {
  35.             $count_total++;
  36.         }
  37.         $count = $count_total;
  38.         $page =  get_posts::_numpage($count_total,$count);
  39.         $check_err = true;
  40.         $err_msg = '';
  41.         $status = 'ok';
  42.         if (!$obj)
  43.         {
  44.             $check_err = false;
  45.             $err_msg = 'the query can not connect to database';
  46.             $status = 'error';
  47.             $info = array(
  48.             'status' => $status,
  49.             'msg' => $err_msg,
  50.             );
  51.             $json = new Services_JSON();
  52.             $encode = $json->encode($info);
  53.             if($dev == 1)
  54.             {
  55.                 $dev = new Dev();
  56.                 $output = $dev-> json_format($encode);
  57.                 print($output);
  58.             }
  59.             if ($dev != 1)
  60.             {
  61.                 //print ($encode);
  62.                 get_posts::printJSonPIfRequired($encode);
  63.             }
  64.         }
  65.         if(empty($obj))
  66.         {
  67.             $check_err = false;
  68.             $err_msg = 'the table is empty';
  69.             $status = 'error';
  70.             $info = array(
  71.             'status' => $status,
  72.             'msg' => $err_msg
  73.             );
  74.             $json = new Services_JSON();
  75.             $encode = $json->encode($info);
  76.             if($dev == 1)
  77.             {
  78.                 $dev = new Dev();
  79.                 $output = $dev-> json_format($encode);
  80.                 print($output);
  81.             }
  82.             if ($dev != 1)
  83.             {
  84.                 //print ($encode);
  85.                 get_posts::printJSonPIfRequired($encode);
  86.             }
  87.         }
  88.         if((int) $type)
  89.         {
  90.             $check_err = false;
  91.             $err_msg = 'type can not an integer number';
  92.             $status = 'error';
  93.             $info = array(
  94.             'status' => $status,
  95.             'msg' => $err_msg
  96.             );
  97.             $json = new Services_JSON();
  98.             $encode = $json->encode($info);
  99.             if($dev == 1)
  100.             {
  101.                 $dev = new Dev();
  102.                 $output = $dev-> json_format($encode);
  103.                 print($output);
  104.             }
  105.             if ($dev != 1)
  106.             {
  107.                 //print ($encode);
  108.                 get_posts::printJSonPIfRequired($encode);
  109.             }  
  110.         }
  111.         if($check_err)
  112.         {
  113.             if(empty($type))
  114.             {
  115.                 foreach($obj as $key => $value)
  116.                 {
  117.                     $cat = get_the_category($value->ID);
  118.                     $tag = get_the_tags($value->ID);
  119.                     $author = get_posts::return_author($value->post_author);
  120.                     $exp = explode("\n",$value->post_content);
  121.                     if(empty($value->post_excerpt))
  122.                     {
  123.                         if(count($exp) > 1)
  124.                         {
  125.                             $value->post_excerpt = explode(" ",strrev(substr(strip_tags($value->post_content), 0, 175)),2);
  126.                             $value->post_excerpt = strrev($value->post_excerpt[1]).' '.'&hellip; <a href="'.$value->guid.'"> Continue reading <span class="meta-nav">&rarr;</span></a>';
  127.                             $order   = array("\r\n", "\n", "\r");
  128.                             $replace = ' ';
  129.                             $value->post_excerpt = str_replace($order, $replace, $value->post_excerpt);
  130.                         }
  131.                         else
  132.                         {
  133.                             $value->post_excerpt = $value->post_content;
  134.                             $order   = array("\r\n", "\n", "\r");
  135.                             $replace = ' ';
  136.                             $value->post_excerpt = str_replace($order, $replace, $value->post_excerpt);
  137.                         }  
  138.                     }
  139.                     else $value->post_excerpt = $value->post_excerpt.' '.'<a href="'.$value->guid.'"> Continue reading <span class="meta-nav">&rarr;</span></a>';    
  140.                     if($tag == false)
  141.                     {
  142.                         $tag = array();
  143.                     }
  144.                     if(($comm == null and $con == null) or ($comm == 0 and $con == 0))
  145.                     {
  146.                         $obj[$key] = array(
  147.                         'id' => $value->ID,
  148.                         'type' => $value->post_type,
  149.                         'slug' => $value->post_name,
  150.                         'url' => $value->guid,
  151.                         'status' => $value->post_status,
  152.                         'title' => $value->post_title,
  153.                         'title_plain' => $value->post_title,
  154.                         'date' => $value->post_date,
  155.                         'modified' => $value->post_modified,
  156.                         'excerpt' => $value->post_excerpt,
  157.                         'parent' => $value->post_parent,
  158.                         'category' => $cat,
  159.                         'tag' => $tag,
  160.                         'author' => $author,
  161.                         'comment_count' => $value->comment_count,
  162.                         'comment_status' => $value->comment_status
  163.                         );
  164.                     }
  165.                     if($con == 1 or ($con == 1 and $comm == 0))
  166.                     {
  167.                         $obj[$key] = array(
  168.                         'id' => $value->ID,
  169.                         'type' => $value->post_type,
  170.                         'slug' => $value->post_name,
  171.                         'url' => $value->guid,
  172.                         'status' => $value->post_status,
  173.                         'title' => $value->post_title,
  174.                         'title_plain' => $value->post_title,
  175.                         'content' => $value->post_content,
  176.                         'date' => $value->post_date,
  177.                         'modified' => $value->post_modified,
  178.                         'excerpt' => $value->post_excerpt,
  179.                         'parent' => $value->post_parent,
  180.                         'category' => $cat,
  181.                         'tag' => $tag,
  182.                         'author' => $author,
  183.                         'comment_count' => $value->comment_count,
  184.                         'comment_status' => $value->comment_status
  185.                         );                 
  186.                     }
  187.                     if($comm == 1 or ($comm == 1 and $con == 0))
  188.                     {
  189.                         $com = get_posts::return_comment($value->ID);
  190.                         if($com == null)
  191.                         {
  192.                             $com = array();
  193.                         }      
  194.                         $obj[$key] = array(
  195.                         'id' => $value->ID,
  196.                         'type' => $value->post_type,
  197.                         'slug' => $value->post_name,
  198.                         'url' => $value->guid,
  199.                         'status' => $value->post_status,
  200.                         'title' => $value->post_title,
  201.                         'title_plain' => $value->post_title,
  202.                         'date' => $value->post_date,
  203.                         'modified' => $value->post_modified,
  204.                         'excerpt' => $value->post_excerpt,
  205.                         'parent' => $value->post_parent,
  206.                         'category' => $cat,
  207.                         'tag' => $tag,
  208.                         'author' => $author,
  209.                         'comment_count' => $value->comment_count,
  210.                         'comment_status' => $value->comment_status,
  211.                         'comments' => $com
  212.                         );
  213.                     }
  214.                     if($comm == 1 and $con == 1)
  215.                     {
  216.                         $com = get_posts::return_comment($value->ID);
  217.                         if($com == null)
  218.                         {
  219.                             $com = array();
  220.                         }
  221.                         $obj[$key] = array(
  222.                         'id' => $value->ID,
  223.                         'type' => $value->post_type,
  224.                         'slug' => $value->post_name,
  225.                         'url' => $value->guid,
  226.                         'status' => $value->post_status,
  227.                         'title' => $value->post_title,
  228.                         'title_plain' => $value->post_title,
  229.                         'content' => $value->post_content,
  230.                         'date' => $value->post_date,
  231.                         'modified' => $value->post_modified,
  232.                         'excerpt' => $value->post_excerpt,
  233.                         'parent' => $value->post_parent,
  234.                         'category' => $cat,
  235.                         'tag' => $tag,
  236.                         'author' => $author,
  237.                         'comment_count' => $value->comment_count,
  238.                         'comment_status' => $value->comment_status,
  239.                         'comments' => $com
  240.                         );                 
  241.                     }
  242.                     $posts[] = $obj[$key];
  243.                 }
  244.             }
  245.             else if(!empty($type) and !(int) $type)
  246.             {
  247.                 $check_type = '';
  248.                 $count_total_type = 0;
  249.                 $count_type;
  250.                 foreach($obj as $key => $value)
  251.                 {
  252.                     if($value->post_type == $type)
  253.                     {
  254.                         $count_total_type++;
  255.                         $check_type = true;
  256.                         $cat = get_the_category($value->ID);
  257.                         $tag = get_the_tags($value->ID);
  258.                         $author = get_posts::return_author($value->post_author);
  259.                         $exp = explode("\n",$value->post_content);
  260.                         if(empty($value->post_excerpt))
  261.                         {
  262.                             if(count($exp) > 1)
  263.                             {
  264.                                 $value->post_excerpt = explode(" ",strrev(substr(strip_tags($value->post_content), 0, 175)),2);
  265.                                 $value->post_excerpt = strrev($value->post_excerpt[1]).' '.'&hellip; <a href="'.$value->guid.'"> Continue reading <span class="meta-nav">&rarr;</span></a>';
  266.                                 $order   = array("\r\n", "\n", "\r");
  267.                                 $replace = ' ';
  268.                                 $value->post_excerpt = str_replace($order, $replace, $value->post_excerpt);
  269.                             }
  270.                             else
  271.                             {
  272.                                 $value->post_excerpt = $value->post_content;
  273.                                 $order   = array("\r\n", "\n", "\r");
  274.                                 $replace = ' ';
  275.                                 $value->post_excerpt = str_replace($order, $replace, $value->post_excerpt);
  276.                             }  
  277.                         }
  278.                         else $value->post_excerpt = $value->post_excerpt.' '.'<a href="'.$value->guid.'"> Continue reading <span class="meta-nav">&rarr;</span></a>';
  279.                         if($tag == false)
  280.                         {
  281.                             $tag = array();
  282.                         }
  283.                         if(($comm == null and $con == null) or ($comm == 0 and $con == 0))
  284.                         {
  285.                             $obj[$key] = array(
  286.                             'id' => $value->ID,
  287.                             'type' => $value->post_type,
  288.                             'slug' => $value->post_name,
  289.                             'url' => $value->guid,
  290.                             'status' => $value->post_status,
  291.                             'title' => $value->post_title,
  292.                             'title_plain' => $value->post_title,
  293.                             'date' => $value->post_date,
  294.                             'modified' => $value->post_modified,
  295.                             'excerpt' => $value->post_excerpt,
  296.                             'parent' => $value->post_parent,
  297.                             'category' => $cat,
  298.                             'tag' => $tag,
  299.                             'author' => $author,
  300.                             'comment_count' => $value->comment_count,
  301.                             'comment_status' => $value->comment_status
  302.                             );
  303.                         }
  304.                         if($con == 1 or ($con == 1 and $comm == 0))
  305.                         {
  306.                             $obj[$key] = array(
  307.                             'id' => $value->ID,
  308.                             'type' => $value->post_type,
  309.                             'slug' => $value->post_name,
  310.                             'url' => $value->guid,
  311.                             'status' => $value->post_status,
  312.                             'title' => $value->post_title,
  313.                             'title_plain' => $value->post_title,
  314.                             'content' => $value->post_content,
  315.                             'date' => $value->post_date,
  316.                             'modified' => $value->post_modified,
  317.                             'excerpt' => $value->post_excerpt,
  318.                             'parent' => $value->post_parent,
  319.                             'category' => $cat,
  320.                             'tag' => $tag,
  321.                             'author' => $author,
  322.                             'comment_count' => $value->comment_count,
  323.                             'comment_status' => $value->comment_status
  324.                             );                 
  325.                         }
  326.                         if($comm == 1 or ($comm == 1 and $con == 0))
  327.                         {
  328.                             $com = get_posts::return_comment($value->ID);
  329.                             if($com == null)
  330.                             {
  331.                                 $com = array();
  332.                             }      
  333.                             $obj[$key] = array(
  334.                             'id' => $value->ID,
  335.                             'type' => $value->post_type,
  336.                             'slug' => $value->post_name,
  337.                             'url' => $value->guid,
  338.                             'status' => $value->post_status,
  339.                             'title' => $value->post_title,
  340.                             'title_plain' => $value->post_title,
  341.                             'date' => $value->post_date,
  342.                             'modified' => $value->post_modified,
  343.                             'excerpt' => $value->post_excerpt,
  344.                             'parent' => $value->post_parent,
  345.                             'category' => $cat,
  346.                             'tag' => $tag,
  347.                             'author' => $author,
  348.                             'comment_count' => $value->comment_count,
  349.                             'comment_status' => $value->comment_status,
  350.                             'comments' => $com
  351.                             );
  352.                         }
  353.                         if($comm == 1 and $con == 1)
  354.                         {
  355.                             $com = get_posts::return_comment($value->ID);
  356.                             if($com == null)
  357.                             {
  358.                                 $com = array();
  359.                             }
  360.                             $obj[$key] = array(
  361.                             'id' => $value->ID,
  362.                             'type' => $value->post_type,
  363.                             'slug' => $value->post_name,
  364.                             'url' => $value->guid,
  365.                             'status' => $value->post_status,
  366.                             'title' => $value->post_title,
  367.                             'title_plain' => $value->post_title,
  368.                             'content' => $value->post_content,
  369.                             'date' => $value->post_date,
  370.                             'modified' => $value->post_modified,
  371.                             'excerpt' => $value->post_excerpt,
  372.                             'parent' => $value->post_parent,
  373.                             'category' => $cat,
  374.                             'tag' => $tag,
  375.                             'author' => $author,
  376.                             'comment_count' => $value->comment_count,
  377.                             'comment_status' => $value->comment_status,
  378.                             'comments' => $com
  379.                             );                 
  380.                         }
  381.                         $posts[] = $obj[$key];
  382.                     }
  383.                     else if($value->post_type != $type and $check_type != true)
  384.                     {
  385.                         $check_type = false;   
  386.                     }
  387.                 }
  388.                 if($check_type == false)
  389.                 {
  390.                     $check_err = false;
  391.                     $err_msg = 'this type not found';
  392.                     $status = 'error';
  393.                     $info = array(
  394.                     'status' => $status,
  395.                     'msg' => $err_msg
  396.                     );
  397.                     $json = new Services_JSON();
  398.                     $encode = $json->encode($info);
  399.                     if($dev == 1)
  400.                     {
  401.                         $dev = new Dev();
  402.                         $output = $dev-> json_format($encode);
  403.                         print($output);
  404.                         exit();
  405.                     }
  406.                     if ($dev != 1)
  407.                     {
  408.                         //print ($encode);
  409.                         get_posts::printJSonPIfRequired($encode);
  410.                         exit();
  411.                     }      
  412.                 }
  413.                 $count_type = $count_total_type;
  414.                 $page_type = $count_total_type / $count_type;
  415.                 if(empty($posts))
  416.                 {
  417.                     $posts = array();
  418.                 }
  419.                 @rsort($posts);
  420.                 $info = array(
  421.                 'status' => $status,
  422.                 'count' => $count_type,
  423.                 'count_total' => $count_total_type,
  424.                 'pages' => $page_type,
  425.                 'posts' => $posts
  426.                 );
  427.                  $json = new Services_JSON();
  428.                  $encode = $json->encode($info);
  429.                  if($dev == 1)
  430.                  {
  431.                     $dev = new Dev();
  432.                     $output = $dev-> json_format($encode);
  433.                     print($output);
  434.                     exit();
  435.                  }
  436.                  if($dev != 1)
  437.                  {
  438.                     //print ($encode);
  439.                     get_posts::printJSonPIfRequired($encode);
  440.                     exit();
  441.                  }
  442.             }
  443.             if(empty($posts))
  444.             {
  445.                 $posts = array();
  446.             }
  447.             @rsort($posts);
  448.             $info = array(
  449.             'status' => $status,
  450.             'count' => $count,
  451.             'count_total' => $count_total,
  452.             'pages' => $page,
  453.             'posts' => $posts
  454.             );
  455.              $json = new Services_JSON();
  456.              $encode = $json->encode($info);
  457.              if($dev == 1)
  458.              {
  459.                 $dev = new Dev();
  460.                 $output = $dev-> json_format($encode);
  461.                 print($output);
  462.              }
  463.              if($dev != 1)
  464.              {
  465.                 //print ($encode);
  466.                 get_posts::printJSonPIfRequired($encode);
  467.              }
  468.         }
  469.            
  470.     }
  471.     static function return_comment($id)
  472.     {
  473.         global $wpdb;
  474.         $sqlc = 'SELECT DISTINCT * FROM '.$wpdb->comments.' AS COMM
  475.                 WHERE COMM.comment_post_id="'.$id.'" AND COMM.comment_approved = 1';
  476.         $obj = $wpdb->get_results($sqlc);
  477.         foreach ($obj as $key => $comment)
  478.         {
  479.             $obj[$key] = array(
  480.             'id' => $comment->comment_ID,
  481.             'author' => $comment->comment_author,
  482.             'author_url' => $comment->comment_author_url,
  483.             'parent' => $comment->comment_parent,
  484.             'date' => $comment->comment_date,
  485.             'content' => $comment->comment_content,
  486.             'gravatar' => get_posts::get_gravatar($comment->comment_author_email)
  487.             );
  488.             $comments[] = $obj[$key];
  489.         }      
  490.         return $comments;
  491.     }                          
  492.     static function return_author($id)
  493.     {
  494.         global $wpdb;
  495.         $sql = 'SELECT * FROM '.$wpdb->users;
  496.         $obj = $wpdb->get_results($sql);
  497.         foreach($obj as $key => $value)
  498.             {
  499.                 if($id == $value->ID)
  500.                 {
  501.                 $obj[$key] = array(
  502.                 'id' => $value->ID,
  503.                 'slug' => $value->user_nicename,
  504.                 'name' => $value->display_name,
  505.                 'first_name' => get_user_meta($value->ID, 'first_name', true),
  506.                 'last_name' => get_user_meta($value->ID, 'last_name', true),
  507.                 'nickname' => $value->user_nicename,
  508.                 'url' => $value->user_url,
  509.                 'description' => get_user_meta($value->ID, 'description', true),
  510.                 'gravatar' => get_posts::get_gravatar($value->user_email)
  511.                 );
  512.                 $authors[] = $obj[$key];
  513.                 return $authors;
  514.                 }
  515.             }
  516.            
  517.     }
  518.     static function get_id_info($dev,$ID,$comm,$con)
  519.     {  
  520.         global $wpdb;
  521.         $sql = 'SELECT DISTINCT * FROM '.$wpdb->posts.' AS POSTS WHERE POSTS.post_status="publish"';
  522.         $obj = $wpdb->get_results($sql);
  523.         $check_err = true;
  524.         $err_msg = '';
  525.         $status = 'ok';
  526.         if(!(int) $ID)
  527.         {
  528.             $check_err = false;
  529.             $err_msg = 'id should be an integer number';
  530.             $status = 'error';
  531.             $info = array(
  532.             'status' => $status,
  533.             'msg' => $err_msg,
  534.             );
  535.             $json = new Services_JSON();
  536.             $encode = $json->encode($info);
  537.             if($dev == 1)
  538.             {
  539.                 $dev = new Dev();
  540.                 $output = $dev-> json_format($encode);
  541.                 print($output);
  542.             }
  543.             if ($dev != 1)
  544.             {
  545.                 //print ($encode);
  546.                 get_posts::printJSonPIfRequired($encode);
  547.             }
  548.         }
  549.         if (!$obj)
  550.         {
  551.             $check_err = false;
  552.             $err_msg = 'the query can not connect to database ';
  553.             $status = 'error';
  554.             $info = array(
  555.             'status' => $status,
  556.             'msg' => $err_msg,
  557.             );
  558.             $json = new Services_JSON();
  559.             $encode = $json->encode($info);
  560.             if($dev == 1)
  561.             {
  562.                 $dev = new Dev();
  563.                 $output = $dev-> json_format($encode);
  564.                 print($output);
  565.             }
  566.             if ($dev != 1)
  567.             {
  568.                 //print ($encode);
  569.                 get_posts::printJSonPIfRequired($encode);
  570.             }
  571.         }
  572.         if(empty($obj))
  573.         {
  574.             $check_err = false;
  575.             $err_msg = 'the table is empty';
  576.             $status = 'error';
  577.             $info = array(
  578.             'status' => $status,
  579.             'msg' => $err_msg
  580.             );
  581.             $json = new Services_JSON();
  582.             $encode = $json->encode($info);
  583.             if($dev == 1)
  584.             {
  585.                 $dev = new Dev();
  586.                 $output = $dev-> json_format($encode);
  587.                 print($output);
  588.             }
  589.             if ($dev != 1)
  590.             {
  591.                 //print ($encode);
  592.                 get_posts::printJSonPIfRequired($encode);
  593.             }
  594.         }
  595.         if($check_err)
  596.         {
  597.             $check = '';
  598.             foreach($obj as $key => $value)
  599.             {
  600.                 if($ID == $value->ID)
  601.                 {
  602.                     $cat = get_the_category($value->ID);
  603.                     $tag = get_the_tags($value->ID);
  604.                     $author = get_posts::return_author($value->post_author);
  605.                     $exp = explode("\n",$value->post_content);
  606.                     if(empty($value->post_excerpt))
  607.                     {
  608.                         if(count($exp) > 1)
  609.                         {
  610.                             $value->post_excerpt = explode(" ",strrev(substr(strip_tags($value->post_content), 0, 175)),2);
  611.                             $value->post_excerpt = strrev($value->post_excerpt[1]).' '.'&hellip; <a href="'.$value->guid.'"> Continue reading <span class="meta-nav">&rarr;</span></a>';
  612.                             $order   = array("\r\n", "\n", "\r");
  613.                             $replace = ' ';
  614.                             $value->post_excerpt = str_replace($order, $replace, $value->post_excerpt);
  615.                         }
  616.                         else
  617.                         {
  618.                             $value->post_excerpt = $value->post_content;
  619.                             $order   = array("\r\n", "\n", "\r");
  620.                             $replace = ' ';
  621.                             $value->post_excerpt = str_replace($order, $replace, $value->post_excerpt);
  622.                         }  
  623.                     }
  624.                     else $value->post_excerpt = $value->post_excerpt.' '.'<a href="'.$value->guid.'"> Continue reading <span class="meta-nav">&rarr;</span></a>';
  625.                     if($tag == false)
  626.                     {
  627.                         $tag = array();
  628.                     }
  629.                     if(($comm == null and $con == null) or ($comm == 0 and $con == 0))
  630.                     {
  631.                         $obj[$key] = array(
  632.                         'id' => $value->ID,
  633.                         'type' => $value->post_type,
  634.                         'slug' => $value->post_name,
  635.                         'url' => $value->guid,
  636.                         'status' => $value->post_status,
  637.                         'title' => $value->post_title,
  638.                         'title_plain' => $value->post_title,
  639.                         'date' => $value->post_date,
  640.                         'modified' => $value->post_modified,
  641.                         'excerpt' => $value->post_excerpt,
  642.                         'parent' => $value->post_parent,
  643.                         'category' => $cat,
  644.                         'tag' => $tag,
  645.                         'author' => $author,
  646.                         'comment_count' => $value->comment_count,
  647.                         'comment_status' => $value->comment_status
  648.                         );
  649.                     }
  650.                     if($comm == 1 or ($comm == 1 and $con == 0))
  651.                     {
  652.                         $com = get_posts::return_comment($value->ID);
  653.                         if($com == null)
  654.                         {
  655.                             $com = array();
  656.                         }      
  657.                         $obj[$key] = array(
  658.                         'id' => $value->ID,
  659.                         'type' => $value->post_type,
  660.                         'slug' => $value->post_name,
  661.                         'url' => $value->guid,
  662.                         'status' => $value->post_status,
  663.                         'title' => $value->post_title,
  664.                         'title_plain' => $value->post_title,
  665.                         'date' => $value->post_date,
  666.                         'modified' => $value->post_modified,
  667.                         'excerpt' => $value->post_excerpt,
  668.                         'parent' => $value->post_parent,
  669.                         'category' => $cat,
  670.                         'tag' => $tag,
  671.                         'author' => $author,
  672.                         'comment_count' => $value->comment_count,
  673.                         'comment_status' => $value->comment_status,
  674.                         'comments' => $com
  675.                         );
  676.                     }
  677.                 if($con == 1 or ($con == 1 and $comm == 0))
  678.                 {
  679.                     $obj[$key] = array(
  680.                     'id' => $value->ID,
  681.                     'type' => $value->post_type,
  682.                     'slug' => $value->post_name,
  683.                     'url' => $value->guid,
  684.                     'status' => $value->post_status,
  685.                     'title' => $value->post_title,
  686.                     'title_plain' => $value->post_title,
  687.                     'content' => $value->post_content,
  688.                     'date' => $value->post_date,
  689.                     'modified' => $value->post_modified,
  690.                     'excerpt' => $value->post_excerpt,
  691.                     'parent' => $value->post_parent,
  692.                     'category' => $cat,
  693.                     'tag' => $tag,
  694.                     'author' => $author,
  695.                     'comment_count' => $value->comment_count,
  696.                     'comment_status' => $value->comment_status
  697.                     );                 
  698.                 }
  699.                 if($comm == 1 and $con == 1)
  700.                 {
  701.                     $com = get_posts::return_comment($value->ID);
  702.                     if($com == null)
  703.                     {
  704.                         $com = array();
  705.                     }
  706.                     $obj[$key] = array(
  707.                     'id' => $value->ID,
  708.                     'type' => $value->post_type,
  709.                     'slug' => $value->post_name,
  710.                     'url' => $value->guid,
  711.                     'status' => $value->post_status,
  712.                     'title' => $value->post_title,
  713.                     'title_plain' => $value->post_title,
  714.                     'content' => $value->post_content,
  715.                     'date' => $value->post_date,
  716.                     'modified' => $value->post_modified,
  717.                     'excerpt' => $value->post_excerpt,
  718.                     'parent' => $value->post_parent,
  719.                     'category' => $cat,
  720.                     'tag' => $tag,
  721.                     'author' => $author,
  722.                     'comment_count' => $value->comment_count,
  723.                     'comment_status' => $value->comment_status,
  724.                     'comments' => $com
  725.                     );                 
  726.                 }
  727.                     $posts[] = $obj[$key];
  728.                     $info = array(
  729.                     'status' => $status,
  730.                     'posts' => $posts
  731.                     );
  732.                     $json = new Services_JSON();
  733.                     $encode = $json->encode($info);
  734.                     if($dev == 1)
  735.                     {
  736.                         $dev = new Dev();
  737.                         $output = $dev-> json_format($encode);
  738.                         print($output);
  739.                         $check = true;
  740.                     }
  741.                     if($dev != 1)
  742.                     {
  743.                         //print ($encode);
  744.                         get_posts::printJSonPIfRequired($encode);
  745.                         $check = true;
  746.                     }
  747.                     }
  748.                     if($check == true)
  749.                     {
  750.                         exit();
  751.                     }
  752.                     if($ID !== $value->ID)
  753.                     {
  754.                     $check = false;
  755.                     }
  756.             }
  757.         }
  758.             if ($check == false and (int) $ID)
  759.             {
  760.                 $status = 'error';
  761.                 $err_msg = 'this id is not available';
  762.                 $info = array(
  763.                 'status' => $status,
  764.                 'msg' => $err_msg  
  765.                 );
  766.                 $json = new Services_JSON();
  767.                 $encode = $json->encode($info);
  768.                 if($dev == 1)
  769.                 {
  770.                     $dev = new Dev();
  771.                     $output = $dev-> json_format($encode);
  772.                     print($output);
  773.                 }
  774.                 if ($dev != 1)
  775.                 {
  776.                     //print ($encode);
  777.                     get_posts::printJSonPIfRequired($encode);
  778.                 }
  779.             }  
  780.        
  781.     }
  782.     static function get_count_page($dev,$co,$pa,$comm,$con,$type) {
  783.         global $wpdb;
  784.         $sql = 'SELECT DISTINCT * FROM '.$wpdb->posts.' AS POSTS WHERE POSTS.post_status="publish"';
  785.         $obj = $wpdb->get_results($sql);
  786.         $count_total = 0;
  787.         foreach($obj as $num)
  788.         {
  789.             $count_total++;
  790.         }
  791.         $check_err = true;
  792.         $err_msg = '';
  793.         $status = 'ok';
  794.         if(!(int) $co)
  795.         {
  796.             $check_err = false;
  797.             $err_msg = 'the value of count should be an integer number';
  798.             $status = 'error';
  799.             $info = array(
  800.             'status' => $status,
  801.             'msg' => $err_msg
  802.             );
  803.             $json = new Services_JSON();
  804.             $encode = $json->encode($info);
  805.             if($dev == 1)
  806.             {
  807.                 $dev = new Dev();
  808.                 $output = $dev-> json_format($encode);
  809.                 print($output);
  810.             }
  811.             if ($dev != 1)
  812.             {
  813.                 //print ($encode);
  814.                 get_posts::printJSonPIfRequired($encode);
  815.             }
  816.         }
  817.         if(!empty($pa) and !(int) $pa)
  818.         {
  819.             $check_err = false;
  820.             $err_msg = 'the value of page should be an integer number';
  821.             $status = 'error';
  822.             $info = array(
  823.             'status' => $status,
  824.             'msg' => $err_msg
  825.             );
  826.             $json = new Services_JSON();
  827.             $encode = $json->encode($info);
  828.             if($dev == 1)
  829.             {
  830.                 $dev = new Dev();
  831.                 $output = $dev-> json_format($encode);
  832.                 print($output);
  833.             }
  834.             if ($dev != 1)
  835.             {
  836.                 //print ($encode);
  837.                 get_posts::printJSonPIfRequired($encode);
  838.             }
  839.         }
  840.         if($co > $count_total)
  841.         {
  842.             $check_err = false;
  843.             $err_msg = 'count can not be lower than count_total';
  844.             $status = 'error';
  845.             $info = array(
  846.             'status' => $status,
  847.             'msg' => $err_msg
  848.             );
  849.             $json = new Services_JSON();
  850.             $encode = $json->encode($info);
  851.             if($dev == 1)
  852.             {
  853.                 $dev = new Dev();
  854.                 $output = $dev-> json_format($encode);
  855.                 print($output);
  856.             }
  857.             if ($dev != 1)
  858.             {
  859.                 //print ($encode);
  860.                 get_posts::printJSonPIfRequired($encode);
  861.             }          
  862.         }
  863.         if (!$obj)
  864.         {
  865.             $check_err = false;
  866.             $err_msg = 'the query can not connect to database ';
  867.             $status = 'error';
  868.             $info = array(
  869.             'status' => $status,
  870.             'msg' => $err_msg
  871.             );
  872.             $json = new Services_JSON();
  873.             $encode = $json->encode($info);
  874.             if($dev == 1)
  875.             {
  876.                 $dev = new Dev();
  877.                 $output = $dev-> json_format($encode);
  878.                 print($output);
  879.             }
  880.             if ($dev != 1)
  881.             {
  882.                 //print ($encode);
  883.                 get_posts::printJSonPIfRequired($encode);
  884.             }
  885.         }
  886.         if(empty($obj))
  887.         {
  888.             $check_err = false;
  889.             $err_msg = 'the table is empty';
  890.             $status = 'error';
  891.             $info = array(
  892.             'status' => $status,
  893.             'msg' => $err_msg
  894.             );
  895.             $json = new Services_JSON();
  896.             $encode = $json->encode($info);
  897.             if($dev == 1)
  898.             {
  899.                 $dev = new Dev();
  900.                 $output = $dev-> json_format($encode);
  901.                 print($output);
  902.             }
  903.             if ($dev != 1)
  904.             {
  905.                 //print ($encode);
  906.                 get_posts::printJSonPIfRequired($encode);
  907.             }
  908.         }
  909.         if((int) $type)
  910.         {
  911.             $check_err = false;
  912.             $err_msg = 'type can not an integer number';
  913.             $status = 'error';
  914.             $info = array(
  915.             'status' => $status,
  916.             'msg' => $err_msg
  917.             );
  918.             $json = new Services_JSON();
  919.             $encode = $json->encode($info);
  920.             if($dev == 1)
  921.             {
  922.                 $dev = new Dev();
  923.                 $output = $dev-> json_format($encode);
  924.                 print($output);
  925.             }
  926.             if ($dev != 1)
  927.             {
  928.                 //print ($encode);
  929.                 get_posts::printJSonPIfRequired($encode);
  930.             }  
  931.         }
  932.         if($check_err)
  933.         {
  934.             if(empty($type))
  935.             {
  936.                 $page = get_posts::_numpage($count_total,$co);
  937.                 foreach($obj as $key => $value)
  938.                 {
  939.                     $cat = get_the_category($value->ID);
  940.                     $tag = get_the_tags($value->ID);
  941.                     $author = get_posts::return_author($value->post_author);
  942.                     $exp = explode("\n",$value->post_content);
  943.                     if(empty($value->post_excerpt))
  944.                     {
  945.                         if(count($exp) > 1)
  946.                         {
  947.                             $value->post_excerpt = explode(" ",strrev(substr(strip_tags($value->post_content), 0, 175)),2);
  948.                             $value->post_excerpt = strrev($value->post_excerpt[1]).' '.'&hellip; <a href="'.$value->guid.'"> Continue reading <span class="meta-nav">&rarr;</span></a>';
  949.                             $order   = array("\r\n", "\n", "\r");
  950.                             $replace = ' ';
  951.                             $value->post_excerpt = str_replace($order, $replace, $value->post_excerpt);
  952.                         }
  953.                         else
  954.                         {
  955.                             $value->post_excerpt = $value->post_content;
  956.                             $order   = array("\r\n", "\n", "\r");
  957.                             $replace = ' ';
  958.                             $value->post_excerpt = str_replace($order, $replace, $value->post_excerpt);
  959.                         }  
  960.                     }
  961.                     else $value->post_excerpt = $value->post_excerpt.' '.'<a href="'.$value->guid.'"> Continue reading <span class="meta-nav">&rarr;</span></a>';
  962.                     if($tag == false)
  963.                     {
  964.                         $tag = array();
  965.                     }
  966.                     if(($comm == null and $con == null) or ($comm == 0 and $con == 0))
  967.                     {
  968.                         $obj[$key] = array(
  969.                         'id' => $value->ID,
  970.                         'type' => $value->post_type,
  971.                         'slug' => $value->post_name,
  972.                         'url' => $value->guid,
  973.                         'status' => $value->post_status,
  974.                         'title' => $value->post_title,
  975.                         'title_plain' => $value->post_title,
  976.                         'date' => $value->post_date,
  977.                         'modified' => $value->post_modified,
  978.                         'excerpt' => $value->post_excerpt,
  979.                         'parent' => $value->post_parent,
  980.                         'category' => $cat,
  981.                         'tag' => $tag,
  982.                         'author' => $author,
  983.                         'comment_count' => $value->comment_count,
  984.                         'comment_status' => $value->comment_status
  985.                         );
  986.                     }
  987.                     if($con == 1 or ($con == 1 and $comm == 0))
  988.                     {
  989.                         $obj[$key] = array(
  990.                         'id' => $value->ID,
  991.                         'type' => $value->post_type,
  992.                         'slug' => $value->post_name,
  993.                         'url' => $value->guid,
  994.                         'status' => $value->post_status,
  995.                         'title' => $value->post_title,
  996.                         'title_plain' => $value->post_title,
  997.                         'content' => $value->post_content,
  998.                         'date' => $value->post_date,
  999.                         'modified' => $value->post_modified,
  1000.                         'excerpt' => $value->post_excerpt,
  1001.                         'parent' => $value->post_parent,
  1002.                         'category' => $cat,
  1003.                         'tag' => $tag,
  1004.                         'author' => $author,
  1005.                         'comment_count' => $value->comment_count,
  1006.                         'comment_status' => $value->comment_status
  1007.                         ); 
  1008.                     }
  1009.                     if($comm == 1 or ($comm == 1 and $con == 0))
  1010.                     {
  1011.                         $com = get_posts::return_comment($value->ID);
  1012.                         if($com == null)
  1013.                         {
  1014.                             $com = array();
  1015.                         }      
  1016.                         $obj[$key] = array(
  1017.                         'id' => $value->ID,
  1018.                         'type' => $value->post_type,
  1019.                         'slug' => $value->post_name,
  1020.                         'url' => $value->guid,
  1021.                         'status' => $value->post_status,
  1022.                         'title' => $value->post_title,
  1023.                         'title_plain' => $value->post_title,
  1024.                         'date' => $value->post_date,
  1025.                         'modified' => $value->post_modified,
  1026.                         'excerpt' => $value->post_excerpt,
  1027.                         'parent' => $value->post_parent,
  1028.                         'category' => $cat,
  1029.                         'tag' => $tag,
  1030.                         'author' => $author,
  1031.                         'comment_count' => $value->comment_count,
  1032.                         'comment_status' => $value->comment_status,
  1033.                         'comments' => $com
  1034.                         );
  1035.                     }
  1036.                     if($comm == 1 and $con == 1)
  1037.                     {
  1038.                         $com = get_posts::return_comment($value->ID);
  1039.                         if($com == null)
  1040.                         {
  1041.                             $com = array();
  1042.                         }
  1043.                         $obj[$key] = array(
  1044.                         'id' => $value->ID,
  1045.                         'type' => $value->post_type,
  1046.                         'slug' => $value->post_name,
  1047.                         'url' => $value->guid,
  1048.                         'status' => $value->post_status,
  1049.                         'title' => $value->post_title,
  1050.                         'title_plain' => $value->post_title,
  1051.                         'content' => $value->post_content,
  1052.                         'date' => $value->post_date,
  1053.                         'modified' => $value->post_modified,
  1054.                         'excerpt' => $value->post_excerpt,
  1055.                         'parent' => $value->post_parent,
  1056.                         'category' => $cat,
  1057.                         'tag' => $tag,
  1058.                         'author' => $author,
  1059.                         'comment_count' => $value->comment_count,
  1060.                         'comment_status' => $value->comment_status,
  1061.                         'comments' => $com
  1062.                         );
  1063.                     }
  1064.                     $posts[] = $obj[$key];
  1065.                 }
  1066.             }
  1067.             else if(!empty($type) and !(int) $type)
  1068.             {
  1069.                 $check_type = '';
  1070.                 $count_total = 0;
  1071.                 foreach($obj as $key => $value)
  1072.                 {
  1073.                     if($value->post_type == $type)
  1074.                     {
  1075.                         $count_total++;
  1076.                         $check_type = true;
  1077.                         $cat = get_the_category($value->ID);
  1078.                         $tag = get_the_tags($value->ID);
  1079.                         $author = get_posts::return_author($value->post_author);
  1080.                         $exp = explode("\n",$value->post_content);
  1081.                     if(empty($value->post_excerpt))
  1082.                     {
  1083.                         if(count($exp) > 1)
  1084.                         {
  1085.                             $value->post_excerpt = explode(" ",strrev(substr(strip_tags($value->post_content), 0, 175)),2);
  1086.                             $value->post_excerpt = strrev($value->post_excerpt[1]).' '.'&hellip; <a href="'.$value->guid.'"> Continue reading <span class="meta-nav">&rarr;</span></a>';
  1087.                             $order   = array("\r\n", "\n", "\r");
  1088.                             $replace = ' ';
  1089.                             $value->post_excerpt = str_replace($order, $replace, $value->post_excerpt);
  1090.                         }
  1091.                         else
  1092.                         {
  1093.                             $value->post_excerpt = $value->post_content;
  1094.                             $order   = array("\r\n", "\n", "\r");
  1095.                             $replace = ' ';
  1096.                             $value->post_excerpt = str_replace($order, $replace, $value->post_excerpt);
  1097.                         }  
  1098.                     }
  1099.                     else $value->post_excerpt = $value->post_excerpt.' '.'<a href="'.$value->guid.'"> Continue reading <span class="meta-nav">&rarr;</span></a>';
  1100.                         if($tag == false)
  1101.                         {
  1102.                             $tag = array();
  1103.                         }
  1104.                         if(($comm == null and $con == null) or ($comm == 0 and $con == 0))
  1105.                         {
  1106.                             $obj[$key] = array(
  1107.                             'id' => $value->ID,
  1108.                             'type' => $value->post_type,
  1109.                             'slug' => $value->post_name,
  1110.                             'url' => $value->guid,
  1111.                             'status' => $value->post_status,
  1112.                             'title' => $value->post_title,
  1113.                             'title_plain' => $value->post_title,
  1114.                             'date' => $value->post_date,
  1115.                             'modified' => $value->post_modified,
  1116.                             'excerpt' => $value->post_excerpt,
  1117.                             'parent' => $value->post_parent,
  1118.                             'category' => $cat,
  1119.                             'tag' => $tag,
  1120.                             'author' => $author,
  1121.                             'comment_count' => $value->comment_count,
  1122.                             'comment_status' => $value->comment_status
  1123.                             );
  1124.                         }
  1125.                         if($con == 1 or ($con == 1 and $comm == 0))
  1126.                         {
  1127.                             $obj[$key] = array(
  1128.                             'id' => $value->ID,
  1129.                             'type' => $value->post_type,
  1130.                             'slug' => $value->post_name,
  1131.                             'url' => $value->guid,
  1132.                             'status' => $value->post_status,
  1133.                             'title' => $value->post_title,
  1134.                             'title_plain' => $value->post_title,
  1135.                             'content' => $value->post_content,
  1136.                             'date' => $value->post_date,
  1137.                             'modified' => $value->post_modified,
  1138.                             'excerpt' => $value->post_excerpt,
  1139.                             'parent' => $value->post_parent,
  1140.                             'category' => $cat,
  1141.                             'tag' => $tag,
  1142.                             'author' => $author,
  1143.                             'comment_count' => $value->comment_count,
  1144.                             'comment_status' => $value->comment_status
  1145.                             );                 
  1146.                         }
  1147.                         if($comm == 1 or ($comm == 1 and $con == 0))
  1148.                         {
  1149.                             $com = get_posts::return_comment($value->ID);
  1150.                             if($com == null)
  1151.                             {
  1152.                                 $com = array();
  1153.                             }      
  1154.                             $obj[$key] = array(
  1155.                             'id' => $value->ID,
  1156.                             'type' => $value->post_type,
  1157.                             'slug' => $value->post_name,
  1158.                             'url' => $value->guid,
  1159.                             'status' => $value->post_status,
  1160.                             'title' => $value->post_title,
  1161.                             'title_plain' => $value->post_title,
  1162.                             'date' => $value->post_date,
  1163.                             'modified' => $value->post_modified,
  1164.                             'excerpt' => $value->post_excerpt,
  1165.                             'parent' => $value->post_parent,
  1166.                             'category' => $cat,
  1167.                             'tag' => $tag,
  1168.                             'author' => $author,
  1169.                             'comment_count' => $value->comment_count,
  1170.                             'comment_status' => $value->comment_status,
  1171.                             'comments' => $com
  1172.                             );
  1173.                         }
  1174.                         if($comm == 1 and $con == 1)
  1175.                         {
  1176.                             $com = get_posts::return_comment($value->ID);
  1177.                             if($com == null)
  1178.                             {
  1179.                                 $com = array();
  1180.                             }
  1181.                             $obj[$key] = array(
  1182.                             'id' => $value->ID,
  1183.                             'type' => $value->post_type,
  1184.                             'slug' => $value->post_name,
  1185.                             'url' => $value->guid,
  1186.                             'status' => $value->post_status,
  1187.                             'title' => $value->post_title,
  1188.                             'title_plain' => $value->post_title,
  1189.                             'content' => $value->post_content,
  1190.                             'date' => $value->post_date,
  1191.                             'modified' => $value->post_modified,
  1192.                             'excerpt' => $value->post_excerpt,
  1193.                             'parent' => $value->post_parent,
  1194.                             'category' => $cat,
  1195.                             'tag' => $tag,
  1196.                             'author' => $author,
  1197.                             'comment_count' => $value->comment_count,
  1198.                             'comment_status' => $value->comment_status,
  1199.                             'comments' => $com
  1200.                             );                 
  1201.                         }
  1202.                         $posts[] = $obj[$key];
  1203.                     }
  1204.                     else if($value->post_type != $type and $check_type != true)
  1205.                     {
  1206.                         $check_type = false;   
  1207.                     }
  1208.                 }
  1209.                 if($check_type == false)
  1210.                 {
  1211.                     $check_err = false;
  1212.                     $err_msg = 'this type not found';
  1213.                     $status = 'error';
  1214.                     $info = array(
  1215.                     'status' => $status,
  1216.                     'msg' => $err_msg
  1217.                     );
  1218.                     $json = new Services_JSON();
  1219.                     $encode = $json->encode($info);
  1220.                     if($dev == 1)
  1221.                     {
  1222.                         $dev = new Dev();
  1223.                         $output = $dev-> json_format($encode);
  1224.                         print($output);
  1225.                         exit();
  1226.                     }
  1227.                     if ($dev != 1)
  1228.                     {
  1229.                         //print ($encode);
  1230.                         get_posts::printJSonPIfRequired($encode);
  1231.                         exit();
  1232.                     }      
  1233.                 }
  1234.             }
  1235.             $page = get_posts::_numpage($count_total,$co);
  1236.             if(empty($posts))
  1237.             {
  1238.                 $posts = array();  
  1239.             }
  1240.             @rsort($posts);
  1241.             if(empty($pa) or $pa == 1 or $page == 1)
  1242.             {
  1243.                 for($i=0;$i<$co;$i++)
  1244.                 {
  1245.                     $post[] = $posts[$i];
  1246.                 }
  1247.                 @rsort($post);
  1248.                 $info = array(
  1249.                 'status' => $status,
  1250.                 'count' => $co,
  1251.                 'count_total' => $count_total,
  1252.                 'pages' => $page,
  1253.                 'currPage' => 1,
  1254.                 'posts' => $post
  1255.                 );
  1256.                 $json = new Services_JSON();
  1257.                 $encode = $json->encode($info);
  1258.                 if($dev == 1)
  1259.                 {
  1260.                     $dev = new Dev();
  1261.                     $output = $dev-> json_format($encode);
  1262.                     print($output);
  1263.                 }
  1264.                 if ($dev != 1)
  1265.                 {
  1266.                     //print ($encode);
  1267.                     get_posts::printJSonPIfRequired($encode);
  1268.                 }
  1269.             }
  1270.             if(!empty($pa) and $pa != 1 and $page != 1)
  1271.             {
  1272.                 if($pa >= $page and $page != 1)
  1273.                 {
  1274.                     $pa = $page;
  1275.                     $count = 0;
  1276.                     $begin = $co*($pa-1);
  1277.                     $end = $begin + ($co - 1);
  1278.                     for($i=$begin;$i<=$end;$i++)
  1279.                     {
  1280.                         if($posts[$i] == null)
  1281.                         {
  1282.                             break;
  1283.                         }
  1284.                         else
  1285.                         {
  1286.                             $count++;
  1287.                             $co = $count;  
  1288.                         }
  1289.                     }
  1290.                 }
  1291.                 $begin = $co*($pa-1);
  1292.                 $end = $begin + ($co - 1);
  1293.                 for($i=$begin;$i<=$end;$i++)
  1294.                 {
  1295.                     if($posts[$i] == null)
  1296.                     {
  1297.                         break;
  1298.                     }
  1299.                     else
  1300.                     {
  1301.                         $post[] = $posts[$i];
  1302.                     }
  1303.                 }      
  1304.                 $info = array(
  1305.                 'status' => $status,
  1306.                 'count' => $co,
  1307.                 'count_total' => $count_total,
  1308.                 'pages' => $page,
  1309.                 'currPage' => $pa,
  1310.                 'posts' => $post
  1311.                 );
  1312.                 $json = new Services_JSON();
  1313.                 $encode = $json->encode($info);
  1314.                 if($dev == 1)
  1315.                 {
  1316.                     $dev = new Dev();
  1317.                     $output = $dev-> json_format($encode);
  1318.                     print($output);
  1319.                 }
  1320.                 if ($dev != 1)
  1321.                 {
  1322.                     //print ($encode);
  1323.                     get_posts::printJSonPIfRequired($encode);
  1324.                 }
  1325.             }
  1326.         }
  1327.     }
  1328.     static function get_gravatar( $email, $s = 100, $d = 'mm', $r = 'g', $img = false, $atts = array() )
  1329.     {
  1330.         $url = 'http://www.gravatar.com/avatar/';
  1331.         $url .= md5( strtolower( trim( $email ) ) );
  1332.         $url .= "?s=$s&d=$d&r=$r";
  1333.         if ( $img )
  1334.         {
  1335.             $url = '<img src="' . $url . '"';
  1336.             foreach ( $atts as $key => $val )
  1337.                 $url .= ' ' . $key . '="' . $val . '"';
  1338.                 $url .= ' />';
  1339.         }
  1340.     return $url;
  1341.     }
  1342.     static function _numpage($co_tot,$co)
  1343.     {
  1344.         if($co > $co_tot)
  1345.         {
  1346.             $co_tot = $co;
  1347.             $page = $co_tot / $co;
  1348.             return $page;
  1349.         }
  1350.         else
  1351.         {
  1352.             $page = $co_tot / $co;
  1353.             if ($page > 0 and $page < 1)
  1354.             {
  1355.                 $page = 2;
  1356.                 return $page;
  1357.             }
  1358.             else if ($page > 1 and $page < 2)
  1359.             {
  1360.                 $page = 2;
  1361.                 return $page;
  1362.             }
  1363.              return ceil($page);
  1364.         }
  1365.     }
  1366.     static  function insertRules($rules){
  1367.         $newrules = array();
  1368.         $newrules['redirect/url/(.+)$']='index.php?wpapi=get_posts&dev&id&count&page&comment&content&type';
  1369.         return $newrules+$rules;
  1370.     }
  1371.     static function insertQueryVars($vars){
  1372.         array_push($vars, 'wpapi','dev','id','count','page','comment','content','type');
  1373.         return $vars;
  1374.     }
  1375.     static function insertParseQuery($query)
  1376.     {
  1377.         if(!empty($query->query_vars['wpapi']) and $query->query_vars['wpapi'] == 'get_posts')
  1378.         {
  1379.             $dev = $_GET['dev'];
  1380.             $id = $_GET['id'];
  1381.             $page = $_GET['page'];
  1382.             $count = $_GET['count'];
  1383.             $comm = $_GET['comment'];
  1384.             $con = $_GET['content'];
  1385.             $type = $_GET['type'];
  1386.            
  1387.             if(!empty($query->query_vars['id']) and $query->query_vars['id'] == $id)
  1388.             {
  1389.                 get_posts::get_id_info($dev,$id,$comm,$con);
  1390.                 header('Content-type: text/plain');
  1391.                 exit();
  1392.                
  1393.             }
  1394.             else if(!empty($query->query_vars['count']) and $query->query_vars['count'] == $count and $query->query_vars['page'] == $page)
  1395.             {
  1396.                 get_posts::get_count_page($dev,$count,$page,$comm,$con,$type);
  1397.                 header('Content-type: text/plain');
  1398.                 exit();
  1399.             }
  1400.             get_posts::posts_info($dev,$comm,$con,$type);
  1401.             header('Content-type: text/plain');
  1402.             exit();
  1403.         }
  1404.     }
  1405.     static function printJSonPIfRequired($textToBePrinted) {
  1406.  
  1407.         if (isset($_GET['callbackp']) && '' != $_GET['callbackp']) {
  1408.             //echo 'hi';
  1409.             $textToBePrinted = $_GET['callbackp'] . '(' . $textToBePrinted . ')';
  1410.         }
  1411.  
  1412.         print($textToBePrinted);
  1413.     }
  1414.    
  1415. }
  1416. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement