PluginProbe
WPMobile.App / trunk
WPMobile.App vtrunk
wpappninja / inc / api / json.php

json.php in WPMobile.App trunk, at inc/api/json.php

1,275 lines 38.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
3
4 /**
5 * Return menu and parameters
6 *
7 * @since 1.0
8 */
9
10 function wpappninja_category() {
11
12 //$wpappninja_locale = wpappninja_get_lang();
13 //if (get_wpappninja_option('speed') == '1') {
14 $wpappninja_locale = 'speed';
15 //}
16
17 $json = array();
18
19 /*******************************
20 * CAT FOR SUBSCRIBE
21 *******************************/
22 $json['subscribe'] = array();
23 $category = get_terms(array('category'), array(
24 'orderby' => 'count', 'order' => 'DESC', 'number' => 40,
25 'parent' => 0,
26 'hide_empty' => true
27 ));
28
29 $silent = array();
30 if (is_array(get_wpappninja_option( 'silent' , ''))) {
31 $silent = get_wpappninja_option( 'silent' , '');
32 }
33
34 foreach ( $category as $cat ) {
35 if (!in_array($cat->term_id, $silent)) {
36 /*$json['subscribe'][] = array(
37 'name' => html_entity_decode(trim($cat->name)),
38 'id' => strval($cat->term_id)
39 );*/
40 }
41 }
42
43 /*******************************
44 * MENU
45 ******************************/
46 if (get_wpappninja_option('speed') == '1') {
47 $json['menu'] = array();
48 } else {
49 $json['menu'] = wpappninja_get_menu_reloaded($wpappninja_locale, true);
50 }
51
52 /*******************************
53 * THEME
54 *******************************/
55 $app_data = get_wpappninja_option('app');
56
57 $app_theme_primary = isset($app_data['theme']['primary']) ? $app_data['theme']['primary'] : "#0f53a6";
58 $app_theme_accent = isset($app_data['theme']['accent']) ? $app_data['theme']['accent'] : "#dd9933";
59 $app_theme_status = wpappninja_adjustBrightness($app_theme_primary, -50);
60
61 if (get_wpappninja_option('speed', '0') == '1') {
62 $app_theme_primary = get_wpappninja_option('css_' . md5('body.wpappninja .navbar,body.wpappninja .tabbar,body.wpappninja .toolbarbackground'), $app_theme_primary);
63 $app_theme_status = get_wpappninja_option('css_' . md5('.progressbar,.progressbar-infinite,.statusbar-overlaybackground'), $app_theme_status);
64
65 }
66
67 $lightstatus = "0";
68 if (wpappninja_need_light_status($app_theme_status)) {
69 $lightstatus = "1";
70 }
71 $app_name = isset($app_data['name']) ? $app_data['name'] : wpappninja_get_appname();
72
73 /*******************************
74 * OPTIONS
75 ******************************/
76
77 // Récupération du timestamp de l'article le plus récent pour la gestion des non lus
78
79 $has_password = null;
80 if (get_wpappninja_option('has_password', "0") == "0") {
81 $has_password = false;
82 }
83
84 $maxID = 0;
85 $maxID_q = wp_get_recent_posts(array(
86 'orderby' => get_wpappninja_option('orderby_list', 'post_date'),
87 'order' => get_wpappninja_option('order_list', 'DESC'),
88 'has_password' => $has_password,
89 'date_query' => array(
90 'column' => 'post_date',
91 'after' => '- '.get_wpappninja_option('maxage', '365000').' days'
92 ),
93 'tag__not_in' => get_wpappninja_option('excluded', ''),
94 'posts_per_page' => 1,
95 'ignore_sticky_posts' => 1,
96 'post_type' => get_post_types(array('public'=>true)),
97 'post_status' => 'publish',
98 'numberposts' => 1,
99 'offset'=>0
100 ));
101
102 if (isset($maxID_q[0]['post_date'])) {
103 $maxID = strtotime($maxID_q[0]['post_date']);
104 }
105
106 $spamBee = '';
107
108 // dummy admob to check
109 $admob_float = '';
110 if (wpappninja_is_apple_reviewer()) {
111 $admob_float = 'ca-app-pub-4670434097606105/3232908161';
112 }
113
114 $default_homepage = "";
115 if (get_wpappninja_option('speed') == '1') {
116 $default_homepage = wpappninja_get_home();
117 }
118
119 $homepage_wpapp = get_wpappninja_option('pageashome_' . $wpappninja_locale, $default_homepage);
120
121 if (get_wpappninja_option('speed', '1') == '1' && !preg_match('#^http#', $homepage_wpapp)) {
122
123 if (preg_match('#^cat_#', $homepage_wpapp)) {
124
125 $homepage_wpapp = preg_replace('#^cat_#', '', $homepage_wpapp);
126 $taxonomy = wpappninja_get_all_taxonomy();
127
128 foreach ($taxonomy as $tax) {
129 $obj = get_term_by('id', $homepage_wpapp, $tax);
130 if (is_object($obj)) {
131
132 $homepage_wpapp = get_term_link($obj);
133 break;
134 }
135 }
136 } else {
137
138 if (get_permalink(intval($homepage_wpapp))) {
139 $homepage_wpapp = get_permalink(intval($homepage_wpapp));
140 }
141 }
142
143 if (!preg_match('#^http#', $homepage_wpapp)) {
144 $homepage_wpapp = wpappninja_get_home();
145 }
146 }
147
148 if (!$homepage_wpapp) {
149 $homepage_wpapp = "";
150 if (get_wpappninja_option('speed') == '1') {
151 $homepage_wpapp = wpappninja_get_home();
152
153 if (!$homepage_wpapp) {
154 $homepage_wpapp = get_bloginfo('url') . '/';
155 }
156 }
157 }
158
159 $homepage_title = get_wpappninja_option('pageashometitle_' . $wpappninja_locale, __('Recent posts', 'wpappninja'));
160
161
162 if (get_wpappninja_option('speed_trad') == 'manual') {
163
164 $homepage_wpapp = wpappninja_translate($homepage_wpapp);
165 $homepage_title = wpappninja_translate($homepage_title);
166 } else {
167 $homepage_wpapp = wpappninja_cache_friendly($homepage_wpapp);
168 }
169
170 if (get_wpappninja_option('speed') == '1' && get_wpappninja_option('speed_trad') == 'weglot') {
171
172 if (wpappninja_get_lang() != get_wpappninja_option('weglot_original', '')) {
173 $homepage_wpapp = wpmobile_weglot($homepage_wpapp);
174 }
175 }
176
177 $homepage_icon = get_wpappninja_option('pageashomeicon_' . $wpappninja_locale, 'arrowlight');
178
179 if (get_wpappninja_option('speed') != '1' && $homepage_icon == 'chevron_right') {
180 $homepage_icon = 'arrow';
181 }
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197 // fix id or url
198 if (get_wpappninja_option('speed') == '1') {
199
200 if (!preg_match('#^http#', $homepage_wpapp)) {
201
202 if (preg_match('#^cat_#', $homepage_wpapp)) {
203
204 $taxonomy = wpappninja_get_all_taxonomy();
205
206 foreach ($taxonomy as $tax) {
207 $obj = get_term_by('id', preg_replace('#cat_#', '', $homepage_wpapp), $tax);
208 if (is_object($obj)) {
209 $homepage_wpapp = get_term_link($obj);
210 break;
211 }
212 }
213
214 } else {
215
216 if (get_permalink(intval($homepage_wpapp))) {
217 $homepage_wpapp = get_permalink(intval($homepage_wpapp));
218 }
219
220 }
221
222 }
223
224 } else {
225
226 if (preg_match('#^http#', $homepage_wpapp)) {
227
228 $id = wpappninja_url_to_catid($homepage_wpapp);
229
230 if ($id !== 0) {
231 $homepage_wpapp = "cat_" . strval($id);
232 } else {
233
234 $id = wpappninja_url_to_postid($homepage_wpapp);
235
236 if ($id !== 0) {
237 $homepage_wpapp = strval($id);
238 }
239 }
240
241 }
242
243 }
244
245
246
247
248
249 $homepage_wpapp = wpappninja_cache_friendly($homepage_wpapp);
250
251
252 $app_theme_primary = wpappninja_verify_color($app_theme_primary, "#dedede");
253 $app_theme_accent = wpappninja_verify_color($app_theme_accent, "#333333");
254 $app_theme_status = wpappninja_verify_color($app_theme_status, "#333333");
255
256
257 $api = array(
258 'version' => WPAPPNINJA_VERSION,
259 'version_app' => get_wpappninja_option('version_app', "1"),
260 'domain' => get_bloginfo('url') . '/',
261
262 'appname' => $app_name,
263
264 'theme_primary' => str_replace('#', '', $app_theme_primary),
265 'theme_accent' => str_replace('#', '', $app_theme_accent),
266 'theme_status' => str_replace('#', '', $app_theme_status),
267
268 'lightstatus' => $lightstatus,
269
270 'webview' => get_wpappninja_option('webview', '0'),
271
272 'theme' => get_wpappninja_option('theme', 'blue'),
273
274 'home_icon' => $homepage_icon,
275 'home_title' => $homepage_title,
276 'home_page' => $homepage_wpapp,
277
278 'list_default_size' => get_wpappninja_option('typedevue', 'big'),
279
280 'speed' => get_wpappninja_option('speed', '0'),
281
282 'show_search' => get_wpappninja_option('show_search', '1'),
283 'show_bio' => get_wpappninja_option('bio', '1'),
284 'show_similar' => get_wpappninja_option('similaire', '1'),
285 'show_share' => get_wpappninja_option('share', '1'),
286 'show_comments' => get_wpappninja_option('commentaire', '1'),
287 'show_abonnement' => get_wpappninja_option('show_abonnement', '0'),
288 'show_favori' => get_wpappninja_option('show_favori', '1'),
289 'show_avatar' => get_wpappninja_option('show_avatar', '1'),
290 'show_date' => get_wpappninja_option('show_date', '1'),
291 'show_browser' => get_wpappninja_option('show_browser', '1'),
292 'remove_title' => get_wpappninja_option('remove_title', '0'),
293
294 'iosmenulabel' => get_wpappninja_option('iosmenulabel_' . $wpappninja_locale, 'Menu'),
295
296 'launchscreen' => get_wpappninja_option('launchscreen', '0'),
297
298 'hideimgonlypage' => get_wpappninja_option('hideimgonlypage', '0'),
299
300 'errormsg' => nl2br(get_wpappninja_option('errormsg', '<center><h1>Error.</h1></center>')),
301
302 'all_link_browser' => get_wpappninja_option('all_link_browser', '0'),
303
304 'readmarginbottom' => "1",
305
306 'rating_title' => __('You like this app?', 'wpappninja'),
307 'rating_texte' => preg_replace('/ Play/', '', ucfirst(__('Take 5 seconds to rate it on the Play Store', 'wpappninja'))),
308 'rating_seuil' => '999999999',
309
310 'page_welcome' => nl2br(get_wpappninja_option('bienvenue_' . $wpappninja_locale, '')),
311 'page_about' => nl2br(get_wpappninja_option('mentions_' . $wpappninja_locale, '')),
312
313 'third_party_push' => get_wpappninja_option('project', '352104594960'),
314 'third_party_analytics' => get_wpappninja_option('ga', ''),
315 'third_party_admob_float' => wpappninja_is_ios() ? get_wpappninja_option('admob_float_ios', $admob_float) : get_wpappninja_option('admob_float', ''),
316 'third_party_admob_splash' => wpappninja_is_ios() ? get_wpappninja_option('admob_splash_ios', '') : get_wpappninja_option('admob_splash', ''),
317 'third_party_admob_top' => wpappninja_is_ios() ? get_wpappninja_option('admob_t_ios', '') : get_wpappninja_option('admob_t', ''),
318 'third_party_admob_bottom' => wpappninja_is_ios() ? get_wpappninja_option('admob_b_ios', '') : get_wpappninja_option('admob_b', ''),
319
320 'third_party_adbuddiz' => wpappninja_is_ios() ? get_wpappninja_option('adbuddiz_ios', '') : get_wpappninja_option('adbuddiz', ''),
321
322 'spambee' => $spamBee,
323
324 'maxID' => strval(abs($maxID)),
325
326 'force_locale' => wpappninja_get_lang(),
327 );
328
329
330 if (wpappninja_webview_mode(0) == '4' || get_wpappninja_option('speed', '0') == '1') {
331
332 if (get_wpappninja_option('nospeed_notheme') == '1') {
333 $api['remove_title'] = "1";
334 $api['show_avatar'] = "0";
335 $api['show_date'] = "0";
336 }
337 if (get_wpappninja_option('speed', '0') == '1') {
338
339 $api['webview'] = "4";
340
341 $api['hideimgonlypage'] = "1";
342 $api['show_bio'] = "0";
343 //$api['similarnb'] = "0";
344
345 $api['show_comments'] = "0";
346
347 //$api['all_link_browser'] = "1";
348 }
349 }
350
351 $api['show_avatar'] = "0";
352
353 /*if (get_wpappninja_option('speed', '0') == '1') {
354 $api['home_page'] = wpappninja_get_home();
355 }*/
356
357 $deprecated = array();
358 if ( preg_match( '#/android_json/(.*)$#', $_SERVER['REQUEST_URI'], $match )) {
359 $deprecated = array(
360 'pageashomeicon' => get_wpappninja_option('pageashomeicon', ''),
361 'pageashometitle' => get_wpappninja_option('pageashometitle_' . $wpappninja_locale, __('Recent posts', 'wpappninja')),
362 'pageashome' => get_wpappninja_option('pageashome', ''),
363 'titrerate' => get_wpappninja_option('rating_titre_' . $wpappninja_locale, __('You like this app?', 'wpappninja')),
364 'texterate' => get_wpappninja_option('rating_texte_' . $wpappninja_locale, __('Take 5 seconds to rate it on the Play Store', 'wpappninja')),
365 'seuilrate' => get_wpappninja_option('rating_seuil', '10'),
366 'iconmenu' => 'arrow',
367 'header_image' => '',
368 'titreform' => 'Formulaires',
369 'pagetitre' => 'Pages',
370 'featformicon' => get_wpappninja_option('pageashomeicon', ''),
371 'featform' => get_wpappninja_option('pageashome', ''),
372 'type_de_vue' => get_wpappninja_option('typedevue', 'big'),
373 'bio' => get_wpappninja_option('bio', '1'),
374 'similaire' => get_wpappninja_option('similaire', '1'),
375 'share' => get_wpappninja_option('share', '1'),
376 'commentaire' => get_wpappninja_option('commentaire', '1'),
377 'bienvenue' => nl2br(get_wpappninja_option('bienvenue_' . $wpappninja_locale, '')),
378 'mentions' => nl2br(get_wpappninja_option('mentions_' . $wpappninja_locale, '')),
379 'projectid' => get_wpappninja_option('project', ''),
380 'ga' => get_wpappninja_option('ga', ''),
381 'admob_float' => get_wpappninja_option('admob_float', ''),
382 'admob_splash' => get_wpappninja_option('admob_splash', ''),
383 'admob_t' => get_wpappninja_option('admob_t', ''),
384 'admob_b' => get_wpappninja_option('admob_b', ''),
385 'bee' => $spamBee,
386 );
387
388 $json['forms'] = array();
389 $json['data'][] = array(
390 'name' => '_NB_',
391 'id' => '',
392 'nb' => '',
393 'icon' => ''
394 );
395 $json['data'][] = array(
396 'name' => '_divider_',
397 'id' => '0',
398 'nb' => '0',
399 'icon' => ''
400 );
401
402 $category = get_terms('category', array(
403 'parent' => 0,
404 'hide_empty' => true,
405 'exclude' => get_wpappninja_option('menu')
406 )
407 );
408
409 foreach ( $category as $cat ) {
410 $json['data'][] = array(
411 'name' => html_entity_decode(trim($cat->name)),
412 'id' => strval($cat->term_id),
413 'nb' => '',
414 'icon' => 'folder'
415 );
416 }
417 }
418
419 $json['config'][] = array_merge($api, $deprecated);
420
421 return json_encode($json);
422 }
423
424 /**
425 * Get recent posts
426 *
427 * @since 1.0
428 */
429 function wpappninja_recent($offset = 0, $isCat = 0, $isSearch = false, $silenced = '', $similaire = false) {
430
431 $json = array();
432 $json['data'] = array();
433
434 return $json;
435
436 // notifications archive
437 if ($isCat == '-100') {
438
439 global $wpdb;
440 $query = $wpdb->get_results($wpdb->prepare("SELECT `titre`, `message`, `image`, `id`, `send_date` FROM {$wpdb->prefix}wpappninja_push WHERE `sended` = %s AND (lang = %s OR lang = 'all') ORDER BY `send_date` DESC LIMIT %d,%d", '1', wpappninja_get_lang(), $offset, 10));
441 foreach($query as $obj) {
442
443 $excerpt = wpappninja_human_time(current_time('timestamp') - $obj->send_date);
444
445 $json['data'][] = array(
446 'maxID' => "0",
447 'sticky' => "0",
448 'cat' => "",
449 'titre' => wp_strip_all_tags(stripslashes(html_entity_decode($obj->titre))),
450 'texte' => stripslashes($excerpt),
451 'image' => $obj->image,
452 'id' => "-" . strval($obj->id),
453 'backgroundColor' => "FFFFFF"
454 );
455 }
456
457 return json_encode($json);
458 }
459
460 $search = '';
461 if($isSearch) {
462 $search = $isSearch;
463 $isCat = get_wpappninja_option('search_cat', '');
464 }
465
466 $stickys = array();
467 if (is_array(get_option( 'sticky_posts' ))) {
468 $stickys = get_option( 'sticky_posts' );
469 }
470 $catIsSticky = false;
471
472 $silent = array();
473 if ($isCat == 0 && !$isSearch) {
474 if ($silenced != '') {
475 if (is_array(get_wpappninja_option( 'silent' , ''))) {
476 $silent = get_wpappninja_option( 'silent' , '');
477 }
478 $silents_custom = explode('!', $silenced);
479 foreach($silents_custom as $silent_custom) {
480 if ($silent_custom != '') {
481 if (!in_array($silent_custom, $silent)) {
482 $silent[] = $silent_custom;
483 }
484 }
485 }
486 }
487
488 // add child
489 foreach ($silent as $s) {
490 $silent = array_merge( $silent, get_terms('category', array( 'child_of' => $s, 'fields'=>'ids' ) ) );
491 }
492 }
493
494 if (isset($stickys[0]) && !$isSearch) {
495 $catIsSticky = true;
496 }
497
498 $has_password = null;
499 if (get_wpappninja_option('has_password', "0") == "0") {
500 $has_password = false;
501 }
502
503 $get_recent_post = array('orderby' => get_wpappninja_option('orderby_list', 'post_date'),'order' => get_wpappninja_option('order_list', 'DESC'), 'lang' => wpappninja_get_lang(), 'has_password' => $has_password,'category__not_in' => $silent, 'date_query' => array('column' => 'post_date', 'after' => '- '.get_wpappninja_option('maxage', '365000').' days'),'tag__not_in' => get_wpappninja_option('excluded',''),'s' => $search, 'post_status' => 'publish','post_type' => get_post_types(array('public'=>true)),'offset'=>$offset);
504
505 if ($search != "") {
506 $get_recent_post['orderby'] = get_wpappninja_option('orderby_search', 'relevance');
507 $get_recent_post['order'] = get_wpappninja_option('order_search', 'DESC');
508 }
509
510 if (defined('WPAPPNINJA_API_DEBUG')) {echo $isCat;}
511 if ($isCat != 0 || $search != "") {
512
513 $taxonomy = wpappninja_get_all_taxonomy();
514 foreach ($taxonomy as $tax) {
515 $obj = get_term_by('id', round($isCat), $tax);
516 if (is_object($obj)) {
517 $the_taxo = $obj;
518 break;
519 }
520 }
521
522 if (defined('WPAPPNINJA_API_DEBUG')) {print_r($the_taxo);}
523
524 if ($the_taxo === false OR $the_taxo->taxonomy == "") {
525
526 $get_recent_post['category'] = $isCat;
527
528 } else {
529
530 $get_recent_post['tax_query'] = array(
531 array(
532 'taxonomy' => $the_taxo->taxonomy,
533 'terms' => $the_taxo->term_id
534 )
535 );
536
537 }
538 } else {
539
540 $get_recent_post['post_type'] = 'post';
541
542 }
543 if (defined('WPAPPNINJA_API_DEBUG')) {print_r($data);print_r($get_recent_post);}
544
545
546 // STICKY POST
547 $numberposts = 10;
548
549 $get_sticky_post = $get_recent_post;
550 $get_sticky_post['posts_per_page'] = 1;
551 $get_sticky_post['post__in'] = $stickys;
552 $get_sticky_post['ignore_sticky_posts'] = 1;
553 $get_sticky_post['numberposts'] = 1;
554 $get_sticky_post['offset'] = 0;
555
556 $firstSticky = wp_get_recent_posts($get_sticky_post);
557
558 if (count($firstSticky) > 1) {
559 $firstSticky = array_slice($firstSticky, 0, 1);
560 }
561
562 $postExclude = '';
563 if (isset($firstSticky[0]['ID'])) {
564 $postExclude = $firstSticky[0]['ID'];
565 }
566
567 if ($offset == 0) {
568
569 $sticky = $firstSticky;
570 if ($postExclude != '') {
571 $numberposts = 9;
572 }
573
574 } else {
575
576 $sticky = array();
577 if ($postExclude != '') {
578 $get_recent_post['offset'] = ($offset - 1);
579 }
580
581 }
582
583 $get_recent_post['post__not_in'] = array( $postExclude );
584 $get_recent_post['numberposts'] = $numberposts;
585 $get_recent_post['posts_per_page'] = $numberposts;
586
587 $normal = wp_get_recent_posts($get_recent_post);
588
589 $data = array_merge($sticky, $normal);
590
591 if (defined('WPAPPNINJA_API_DEBUG')) {print_r($data);print_r($normal);print_r($get_recent_post);}
592
593 foreach($data as $d) {
594
595 if (in_array($d['ID'], $stickys)) {
596 $hessticky = '1';
597 } else {
598 $hessticky = '0';
599 }
600
601 $categories = get_the_category($d['ID']);
602 $separator = ' ';
603 $output = '';
604 $cat = '';
605 if($categories){
606 if ($categories[0]->parent == 0) {
607 $cat = $categories[0]->name;
608 $catID = $categories[0]->term_id;
609 } else {
610 $parent = get_term_by( 'id', $categories[0]->parent, 'category' );
611 $cat = $parent->name;
612 $catID = $parent->term_id;
613 }
614 }
615
616 $content_post = get_post($d['ID']);
617
618 $excerpt = wpappninja_human_time(current_time('timestamp') - strtotime($content_post->post_date));
619
620 $image = wpappninja_get_image($d['ID']);
621
622 if (defined("WPAPPNINJA_FORCE_IMG")) {
623 $image = wpappninja_get_image($d['ID'], '0', true);
624 }
625
626 $titre = $d['post_title'];
627
628 $json['data'][] = array(
629 'maxID' => strval(strtotime($content_post->post_date)),
630 'sticky' => $hessticky,
631 'cat' => html_entity_decode($cat),
632 'titre' => wp_strip_all_tags(html_entity_decode($titre)),
633 'texte' => $excerpt,
634 'image' => $image,
635 'id' => strval($d['ID']),
636 'backgroundColor' => "FFFFFF"
637 );
638 }
639
640 return json_encode($json);
641 }
642
643 /**
644 * Read post
645 */
646 function wpappninja_read($id) {
647
648 $json = array();
649 $json['data'] = array();
650
651 // push notification
652 if (substr($id, 0, 4) == "-999") {
653
654 if (1>0) {
655
656 $date = "";
657
658 $bio = array();
659 $bio[] = array(
660 'avatar' => "",
661 'name' => "",
662 'description' => "",
663 'url' => ""
664 );
665
666 $api = array(
667 'catID' => "0",
668 'isPage' => "1",
669 'cat' => "",
670 'info_name' => "",
671 'info_avatar' => "",
672 'info' => $date,
673 'share_permalink' => '',
674 'permalink' => get_bloginfo('url') . '/' . "?wpappninja_read_enhanced=" . $id,
675 'titre' => "",
676 'texte' => "",
677 'image' => "",
678 'id' => -999,
679 'bio' => array('data' => $bio),
680 'similaire' => array('data' => array()),
681 'commentaire_count' => "0",
682 'commentopen' => "0"
683 );
684 }
685
686 if (isset($api)) {
687 $json['data'][] = $api;
688 } else {
689 $json['data'][] = array('id' => '0');
690 }
691 return json_encode($json);
692
693 } elseif (substr($id, 0, 1) == "-") {
694
695 global $wpdb;
696
697 $id = str_replace("-", "", $id);
698
699 $query = $wpdb->get_results($wpdb->prepare("SELECT `titre`, `message`, `image`, `id`, `id_post`, `send_date` FROM {$wpdb->prefix}wpappninja_push WHERE `sended` = %s AND (lang = %s OR lang = 'all') AND id = %s", '1', wpappninja_get_lang(), $id));
700 foreach($query as $obj) {
701
702 $date = wpappninja_human_time(current_time('timestamp') - $obj->send_date);
703
704 $bio = array();
705 $bio[] = array(
706 'avatar' => "",
707 'name' => "",
708 'description' => "",
709 'url' => ""
710 );
711
712 if ($obj->id_post > 0) {
713 $read_link = '<br/><br/><a href="' . get_permalink( $obj->id_post ) . '">' . __('Read', 'wpappninja') . '</a>';
714 $read_link = wpappninja_deeplink_process($read_link);
715 }
716
717 $api = array(
718 'catID' => "0",
719 'isPage' => "1",
720 'cat' => "",
721 'info_name' => "",
722 'info_avatar' => "",
723 'info' => $date,
724 'share_permalink' => '',
725 'permalink' => get_bloginfo('url') . '/' . "?wpappninja_read_enhanced=-" . $id,
726 'titre' => wp_strip_all_tags(stripslashes($obj->titre)),
727 'texte' => stripslashes($obj->message) . " " . $read_link,
728 'image' => $obj->image,
729 'id' => strval($id),
730 'bio' => array('data' => $bio),
731 'similaire' => array('data' => array()),
732 'commentaire_count' => "0",
733 'commentopen' => "0"
734 );
735 }
736
737 if (isset($api)) {
738 $json['data'][] = $api;
739 } else {
740 $json['data'][] = array('id' => '0');
741 }
742 return json_encode($json);
743
744 }
745
746 $url = "";
747 if (preg_match('#^http#', $id)) {
748 $url = preg_replace('#__sla_sh__#', '/', preg_replace('#__dot__#', ':', $id));
749
750 $scheme = parse_url( get_bloginfo('url'), PHP_URL_SCHEME );
751 $url = set_url_scheme( $url, $scheme );
752
753 $id = url_to_postid($url);
754 if ($id === 0) {
755 $id = wpappninja_url_to_catid($url);
756 if ($id != 0) {
757 $json['data'][] = array('id' => 'cat', 'id_cat' => strval($id));
758 return json_encode($json);
759 } else {
760 $id = wpappninja_url_to_postid($url);
761 }
762 }
763 }
764
765 if ($id === 0) {
766
767 $bio = array();
768 $bio[] = array(
769 'avatar' => "",
770 'name' => "",
771 'description' => "",
772 'url' => ""
773 );
774
775 $api = array(
776 'catID' => "0",
777 'isPage' => "1",
778 'cat' => "",
779 'info_name' => "",
780 'info_avatar' => "",
781 'info' => "",
782 'share_permalink' => '',
783 'permalink' => $url,
784 'titre' => "",
785 'texte' => "",
786 'image' => "",
787 'id' => "0",
788 'bio' => array('data' => $bio),
789 'similaire' => array('data' => array()),
790 'commentaire_count' => "0",
791 'commentopen' => "0"
792 );
793
794 $json['data'][] = $api;
795
796 return json_encode($json);
797 }
798
799 $content_post = get_post($id);
800
801 if ($content_post == null) {
802 return '{"data":[]}';
803 }
804
805 $categories = get_the_category($id);
806 $separator = ' ';
807 $output = '';
808 $cat = '';
809 $catID = '';
810 $nbcomment = '';
811 if($categories){
812 if ($categories[0]->parent == 0) {
813 $cat = $categories[0]->name;
814 $catID = $categories[0]->term_id;
815 } else {
816 $parent = get_term_by( 'id', $categories[0]->parent, 'category' );
817 $cat = $parent->name;
818 $catID = $parent->term_id;
819 }
820 }
821
822 $info = wpappninja_human_time(current_time('timestamp') - strtotime($content_post->post_date));
823
824 $content = '';
825 if (wpappninja_webview_mode($id) == '0') {
826 $content = $content_post->post_content;
827 $content = apply_filters('the_content', $content);
828 if (defined('WPAPPNINJA_API_DEBUG')) {echo wpappninja_html_diff($content_post->post_content, $content, 'filter the content');$wpappninja_diff = $content;}
829 $content = apply_filters('appandroid_content', $content, array('id' => $id));
830 $content = get_wpappninja_option('beforepost', '') . $content . get_wpappninja_option('afterpost', '');
831 $content = strip_shortcodes( $content );
832 if (defined('WPAPPNINJA_API_DEBUG')) {echo wpappninja_html_diff($wpappninja_diff, $content, 'strip shortcode');$wpappninja_diff = $content;}
833 $content = str_replace(']]>', ']]&gt;', $content);
834 $content = str_replace("&nbsp;", " ", $content);
835 $content = html_entity_decode($content);
836 $content = wpappninja_pre_tags($content);
837 if (defined('WPAPPNINJA_API_DEBUG')) {echo wpappninja_html_diff($wpappninja_diff, $content, 'pre tags');$wpappninja_diff = $content;}
838 $content = str_replace(array("\r", "\n"),"", $content);
839
840 // youtube
841 $content = preg_replace('/<iframe.*?src=[\'"](https?:)?(\/\/)?(www\.)?(youtu\.be\/|youtube(-nocookie)?\.[a-z]{2,4}(?:\/embed\/|\/v\/|\/watch\?.*?v=))([\w\-]{10,12})([\?|&]?.*?)?[\'"]([^>]+|)><\/iframe>/', '$1$2$3$4$5$6', $content);
842
843 if (defined('WPAPPNINJA_API_DEBUG')) {echo wpappninja_html_diff($wpappninja_diff, $content, 'youtube');$wpappninja_diff = $content;}
844
845 // dailymotion
846
847 if (defined('WPAPPNINJA_API_DEBUG')) {echo wpappninja_html_diff($wpappninja_diff, $content, 'dailymotion');$wpappninja_diff = $content;}
848
849
850 // vimeo
851
852 if (defined('WPAPPNINJA_API_DEBUG')) {echo wpappninja_html_diff($wpappninja_diff, $content, 'vimeo');$wpappninja_diff = $content;}
853
854
855
856 // convert table to list
857 $content = preg_replace('#<tr([^>]+|)>#', '<ul>', $content);
858 $content = preg_replace('#</tr>#', '</ul><br/>', $content);
859
860 $content = preg_replace('#<thead([^>]+|)>#', '<span>', $content);
861 $content = preg_replace('#</thead>#', '</span>', $content);
862
863 $content = preg_replace('#<th([^>]+|)>#', '<li><b>', $content);
864 $content = preg_replace('#</th>#', '</b></li>', $content);
865
866 $content = preg_replace('#<td([^>]+|)>#', '<li>', $content);
867 $content = preg_replace('#</td>#', '</li>', $content);
868 if (defined('WPAPPNINJA_API_DEBUG')) {echo wpappninja_html_diff($wpappninja_diff, $content, 'table');$wpappninja_diff = $content;}
869
870 // suppression des shortcodes recalcitrants
871 $content = preg_replace('/\[[^\]]+\]/', '', $content);
872 if (defined('WPAPPNINJA_API_DEBUG')) {echo wpappninja_html_diff($wpappninja_diff, $content, 'shortcodes');$wpappninja_diff = $content;}
873
874 // tweet
875 $content = preg_replace_callback('/p>https?:\/\/twitter\.com\/(?:#!\/)?(\w+)\/status(es)?\/(\d+)</', function ($matches) {
876 $jsonTweet = json_decode(file_get_contents('https://api.twitter.com/1/statuses/oembed.json?url=https://twitter.com/'.$matches[1].'/status/'.$matches[3]), TRUE);
877 return 'p>'.$jsonTweet['html'].'<';
878 }, $content);
879 if (defined('WPAPPNINJA_API_DEBUG')) {echo wpappninja_html_diff($wpappninja_diff, $content, 'tweet');$wpappninja_diff = $content;}
880
881 $content = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $content);
882 $content = preg_replace('#<style(.*?)>(.*?)</style>#is', '', $content);
883 $content = preg_replace('# #is', '', $content);
884 $content = preg_replace('# style="[^"]+"#is', '', $content);
885 $content = preg_replace('# class="(?!wp-smiley)[^"]+"#is', '', $content);
886 if (defined('WPAPPNINJA_API_DEBUG')) {echo wpappninja_html_diff($wpappninja_diff, $content, 'class css js');$wpappninja_diff = $content;}
887
888 // remove content by regex
889 $regex = get_wpappninja_option('regex');
890 if ($regex !== FALSE) {
891 $rules = explode("\n", $regex);
892
893 foreach($rules as $rule) {
894 $rule = trim(preg_replace('/^\s+|\n|\r|\s+$/m', '', $rule));
895 $content = preg_replace($rule, '', $content);
896 }
897
898 if (defined('WPAPPNINJA_API_DEBUG')) {echo wpappninja_html_diff($wpappninja_diff, $content, 'regex');$wpappninja_diff = $content;}
899 }
900 }
901
902 if (defined('WPAPPNINJA_API_DEBUG')) {echo '<br/><br/><hr/><br/>' . $content;}
903
904 $titre = html_entity_decode(get_the_title($id));
905
906 //$data = get_terms('category', array('hide_empty' => 1));
907 $has_password = null;
908 if (get_wpappninja_option('has_password', "0") == "0") {
909 $has_password = false;
910 }
911
912 // similar articles
913 $terms = wp_get_post_terms( $id, get_wpappninja_option('similartype', 'category'), array('fields' => 'ids') );
914 $args = array(
915 'has_password' => $has_password,
916 'date_query' => array('column' => 'post_date', 'after' => '- '.get_wpappninja_option('maxage', '365000').' days'),
917 'tag__not_in' => get_wpappninja_option('excluded',''),
918 'post__not_in' => array( $id ),
919 'numberposts' => get_wpappninja_option('similarnb', 10),
920 'offset' => 0,
921 'orderby' => get_wpappninja_option('orderby_list', 'post_date'),
922 'order' => get_wpappninja_option('order_list', 'DESC'),
923 'post_type' => get_post_types(array('public'=>true)),
924 'post_status' => 'publish',
925 'tax_query' => array(
926 array(
927 'taxonomy' => get_wpappninja_option('similartype', 'category'),
928 'terms' => $terms,
929 'include_children' => false
930 )
931 )
932 );
933
934 $similaire = array();
935 if (get_wpappninja_option('similarnb', 10) > 0) {
936 if ($content_post->post_type != 'page') {
937 $recent_posts = wp_get_recent_posts( $args, OBJECT );
938 if (is_array($recent_posts)) {
939 foreach($recent_posts as $p) {
940 $title_similaire = wp_strip_all_tags(html_entity_decode($p->post_title));
941 $content_post_simil = get_post($p->ID);
942 $excerpt = wpappninja_human_time(current_time('timestamp') - strtotime($content_post_simil->post_date));
943 $similaire[] = array(
944 'excerpt' => $excerpt,
945 'postID' => strval($p->ID),
946 'titre' => $title_similaire,
947 'image' => wpappninja_get_image($p->ID)
948 );
949 }
950 }
951 }
952 }
953
954 $bio = array();
955
956 if (wpappninja_webview_mode(0) == '4') {
957
958 $bio[] = array(
959 'avatar' => "",
960 'name' => "",
961 'description' => "",
962 'url' => ""
963 );
964
965 } else {
966
967 $bio[] = array(
968 'avatar' => wpappninja_get_gravatar(get_the_author_meta('user_email', $content_post->post_author)),
969 'name' => get_the_author_meta('display_name', $content_post->post_author),
970 'description' => nl2br(get_the_author_meta('description', $content_post->post_author)),
971 'url' => get_the_author_meta('user_url', $content_post->post_author)
972 );
973
974 }
975
976 $commentaire = array();
977 $commentisopen = '0';
978 if (comments_open( $id )) {
979 $commentisopen = '1';
980 }
981 $nbcomment = $content_post->comment_count;
982
983 $isPage = '0';
984 if ($content_post->post_type == 'page') {
985 $isPage = '1';
986 }
987 $image = wpappninja_get_image($id, $isPage, false, true);
988 $permalink = get_permalink($id);
989 if ($id == get_option('page_on_front')) {
990 $permalink = get_bloginfo('url') . '/';
991 }
992
993 if (function_exists('icl_get_home_url') && $permalink == get_bloginfo('url') . '/home/') {
994 $permalink = get_bloginfo('url') . '/';
995 }
996
997 $share_permalink = $permalink;
998
999 if ($content == "") {
1000 //$permalink .= (preg_match('#\?#', $permalink) ? '&' : '?') . 'WPAPPNINJA=PREVENT_CACHE';
1001
1002 if (wpappninja_webview_mode($id) == '1') {
1003 $permalink = get_bloginfo('url') . '/' . "?wpappninja_read_enhanced=" . $id;
1004 }
1005 } else {
1006 $content .= '<p><br/></p>';
1007 }
1008
1009 $content = wpappninja_deeplink_process($content);
1010
1011 $api = array(
1012 'catID' => strval($catID),
1013 'isPage' => $isPage,
1014 'cat' => html_entity_decode($cat),
1015 'info_name' => get_the_author_meta('display_name', $content_post->post_author),
1016 'info_avatar' => wpappninja_get_gravatar(get_the_author_meta('user_email', $content_post->post_author)),
1017 'info' => $info,
1018 'permalink' => wpappninja_translate($permalink),
1019 'share_permalink' => $share_permalink,
1020 'titre' => html_entity_decode(wp_strip_all_tags($titre)),
1021 'texte' => $content,
1022 'image' => $image,
1023 'id' => strval($id),
1024 'bio' => array('data' => $bio),
1025 'similaire' => array('data' => $similaire),
1026 'commentaire_count' => $nbcomment,
1027 'commentopen' => $commentisopen
1028 );
1029
1030 $deprecated = array();
1031 if ( preg_match( '#/android_json/(.*)$#', $_SERVER['REQUEST_URI'], $match )) {
1032 $deprecated['commentaire']['data'] = array();
1033 }
1034
1035 $json['data'][] = array_merge($api, $deprecated);
1036
1037 return json_encode($json);
1038 }
1039
1040 /**
1041 * Get comments
1042 *
1043 * int $id Post ID
1044 * int $offset Pagination
1045 * @since 1.0
1046 */
1047 function wpappninja_comment($id, $offset = 0) {
1048
1049 $json = array();
1050 $json['data'] = array();
1051 //if (comments_open( $id )) {
1052 $comments = get_comments('status=approve&offset=' . $offset . '&number=10&post_id=' . $id);
1053 foreach($comments as $comment) {
1054 if ($comment->comment_approved == 1) {
1055
1056 $titre = strtoupper($comment->comment_author);
1057 $texte = wpappninja_add_links(nl2br($comment->comment_content));
1058
1059 // is a child
1060 if ($comment->comment_parent != 0) {
1061 $parent = get_comment( $comment->comment_parent );
1062 if (is_object($parent)) {
1063 $titre .= ' @ ' . strtoupper($parent->comment_author);
1064 $texte = '<blockquote><i>' . wpappninja_add_links(wp_strip_all_tags($parent->comment_content)) . '</i></blockquote>' . $texte;
1065 }
1066 }
1067
1068 $texte = wp_strip_all_tags(wpappninja_deeplink_process($texte));
1069
1070 $json['data'][] = array(
1071 'maxID' => '1',
1072 'sticky' => 'nope',
1073 'id' => '0',
1074 'image' => wpappninja_get_gravatar($comment->comment_author_email),
1075 'titre' => wp_strip_all_tags($titre),
1076 'texte' => $texte,
1077 'cat' => wpappninja_human_time(current_time('timestamp') - strtotime($comment->comment_date)),
1078 'backgroundColor' => "FFFFFF"
1079 );
1080 }
1081 }
1082 //}
1083
1084 return json_encode($json);
1085 }
1086
1087 /**
1088 * Redirect post to the web version
1089 *
1090 * int $id Post ID
1091 * @since 1.0
1092 */
1093 function wpappninja_redirection($id) {
1094 $url = get_permalink($id);
1095 header('Location: ' . $url, TRUE, 301);
1096 exit(0);
1097 }
1098
1099 /**
1100 * Render gravity form in html
1101 *
1102 * int $id Form ID
1103 * @since 1.0
1104 */
1105 function wpappninja_form($id) {
1106 header("HTTP/1.1 200 OK");
1107 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
1108 header("Cache-Control: no-store, no-cache, must-revalidate");
1109 header("Cache-Control: post-check=0, pre-check=0", false);
1110 header("Pragma: no-cache");
1111 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
1112
1113 preg_match('/type=form\/([^&]+)&/', $_SERVER['REQUEST_URI'], $m);
1114
1115 if (preg_match('/^http/', $m[1])) {
1116 header('Location: ' . $m[1]);
1117 exit();
1118 }
1119
1120 if ( ! class_exists( 'RGForms' ) ) {
1121 for ( $i = 0; $i < $depth = 10; $i ++ ) {
1122 $wp_root_path = str_repeat( '../', $i );
1123 if ( file_exists( "{$wp_root_path}wp-load.php" ) ) {
1124 require_once( "{$wp_root_path}wp-load.php" );
1125 break;
1126 }
1127 }
1128 }
1129
1130 if (!class_exists('GFCommon')) {
1131 echo 'ERROR';
1132 exit(0);
1133 }
1134
1135 ?>
1136 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1137 <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
1138 <head>
1139 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
1140 <meta name="viewport" content="width=device-width">
1141 <link rel='stylesheet' href='<?php echo GFCommon::get_base_url() ?>/css/reset.min.css' type='text/css' />
1142 <link rel='stylesheet' href='<?php echo GFCommon::get_base_url() ?>/css/formreset.min.css' type='text/css' />
1143 <link rel='stylesheet' href='<?php echo GFCommon::get_base_url() ?>/css/datepicker.min.css' type='text/css' />
1144 <link rel='stylesheet' href='<?php echo GFCommon::get_base_url() ?>/css/formsmain.min.css' type='text/css' />
1145 <link rel='stylesheet' href='<?php echo GFCommon::get_base_url() ?>/css/readyclass.min.css' type='text/css' />
1146 <link rel='stylesheet' href='<?php echo GFCommon::get_base_url() ?>/css/browsers.min.css' type='text/css' />
1147 <link rel='stylesheet' href='<?php echo GFCommon::get_base_url() ?>/css/preview.min.css' type='text/css' />
1148 <?php
1149 require_once( GFCommon::get_base_path() . '/form_display.php' );
1150 $form = RGFormsModel::get_form_meta( $id );
1151 GFFormDisplay::enqueue_form_scripts( $form );
1152 wp_print_scripts();
1153 $styles = apply_filters( 'gform_preview_styles', array(), $form );
1154 if ( ! empty( $styles ) ) {
1155 wp_print_styles( $styles );
1156 }
1157 ?>
1158 <style type="text/css">
1159 body {background:#fff !important;}
1160 input {width: 97.5% !important;}
1161 <?php
1162 if (isset($_GET['night'])) {
1163 ?>
1164 form,#preview_form_container,body {background:#000 !important;color:#fff}
1165 input, textarea {background: #333;border-color: #666;color: #fff;}
1166 <?php
1167 }
1168 ?>
1169 body input.button {background-color: #<?php echo substr(sanitize_text_field($_GET['c']), 0, 6);?> !important;box-shadow: 0 0px 0 #000 !important;}
1170 </style>
1171 </head>
1172 <body style="font-size: 1.2em;">
1173 <div id="preview_form_container" style="margin:0">
1174 <?php
1175 echo RGForms::get_form( $id, true, true, true);
1176 ?>
1177 </div>
1178 <?php
1179 do_action( 'gform_preview_footer', $id );
1180 ?>
1181 </body>
1182 </html>
1183 <?php
1184 exit(0);
1185 }
1186
1187 /**
1188 * Show favorited posts
1189 */
1190 function wpappninja_favoris($offset = 0, $favoris = '') {
1191
1192 $json = array();
1193
1194
1195 $stickys = array();
1196 if (is_array(get_option( 'sticky_posts' ))) {
1197 $stickys = get_option( 'sticky_posts' );
1198 }
1199
1200 $fav = array();
1201 if ($favoris != '') {
1202 $silents_custom = explode('!', $favoris);
1203 foreach($silents_custom as $silent_custom) {
1204 if ($silent_custom != '') {
1205 if (!in_array($silent_custom, $fav)) {
1206 $fav[] = $silent_custom;
1207 }
1208 }
1209 }
1210 }
1211
1212 if (count($fav) == 0) {
1213 return '{"data":[]}';
1214 }
1215
1216 $has_password = null;
1217 if (get_wpappninja_option('has_password', "0") == "0") {
1218 $has_password = false;
1219 }
1220
1221 $data = wp_get_recent_posts(array(
1222 'has_password' => $has_password,
1223 'post__in' => $fav,
1224 'post_type' => get_post_types(array('public'=>true)),
1225 'post_status' => 'publish',
1226 'numberposts' => 10,
1227 'offset'=>$offset
1228 )
1229 );
1230
1231 foreach($data as $d) {
1232
1233 if (in_array($d['ID'], $stickys)) {
1234 $hessticky = '1';
1235 } else {
1236 $hessticky = '0';
1237 }
1238
1239 $categories = get_the_category($d['ID']);
1240 $separator = ' ';
1241 $output = '';
1242 $cat = '';
1243 if($categories){
1244 if ($categories[0]->parent == 0) {
1245 $cat = $categories[0]->name;
1246 $catID = $categories[0]->term_id;
1247 } else {
1248 $parent = get_term_by( 'id', $categories[0]->parent, 'category' );
1249 $cat = $parent->name;
1250 $catID = $parent->term_id;
1251 }
1252 }
1253
1254 $content_post = get_post($d['ID']);
1255
1256 $excerpt = wpappninja_human_time(current_time('timestamp') - strtotime($content_post->post_date));
1257 $image = wpappninja_get_image($d['ID']);
1258
1259 $titre = $d['post_title'];
1260
1261 $json['data'][] = array(
1262 'maxID' => strval(strtotime($content_post->post_date)),
1263 'sticky' => $hessticky,
1264 'cat' => html_entity_decode($cat),
1265 'titre' => wp_strip_all_tags(html_entity_decode($titre)),
1266 'texte' => $excerpt,
1267 'image' => $image,
1268 'id' => strval($d['ID']),
1269 'backgroundColor' => "FFFFFF"
1270 );
1271 }
1272
1273 return json_encode($json);
1274 }
1275