PluginProbe
Statify Widget / 1.1.3
Statify Widget v1.1.3
trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 All 39 releases
statify-widget / Statify_Posts.class.php

Statify_Posts.class.php in Statify Widget 1.1.3, at Statify_Posts.class.php

91 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Statify_Posts {
4
5
6 /**
7 * Gibt die Inhalte zurück
8 *
9 * @since 1.0
10 * @change 1.1
11 */
12
13 public static function get_posts($post_type, $amount) {
14 $posts = array();
15 $counter = 0;
16 $wpurl = parse_url(get_bloginfo('wpurl'));
17 $targets = self::get_all_targets();
18
19 foreach ($targets as $entry) {
20 $clear_url = str_replace($wpurl['path'],"",$entry['url']);
21 $id = url_to_postid(home_url( $clear_url ));
22
23 if ( $id == 0 ) {
24 $page = get_page_by_path( $clear_url );
25 if (empty($page) && get_option('show_on_front') == 'page') $page = get_page(get_option('page_on_front'));
26 } else $page = get_page($id);
27
28 // Falls noch leer und Artikel als Startseite
29 if (empty($page) && $post_type == 'page') {
30 $posts[0]['title'] = "Startseite";
31 $posts[0]['url'] = home_url("/");
32 if ($posts[0]['visits'] == NULL) $posts[0]['visits'] = 0;
33 $posts[0]['visits'] += $entry['count'];
34 $counter++;
35 }
36
37 if($page->post_type == $post_type) {
38 $posts[$page->ID]['title'] = $page->post_title;
39 $posts[$page->ID]['url'] = home_url($clear_url);
40 if ($posts[$page->ID]['visits'] == NULL) $posts[$page->ID]['visits'] = 0;
41 $posts[$page->ID]['visits'] += $entry['count'];
42 $counter++;
43 }
44
45 if ($counter >= $amount) break;
46
47 }
48 usort($posts, array("Statify_Posts", "visitSort"));
49 return $posts;
50 }
51
52 /**
53 * Sortiert nach Aufurfen
54 *
55 * @since 1.0
56 */
57
58 private static function visitSort($a, $b) {
59 if ($a==$b) return 0;
60 return ($a['visits']>$b['visits'])?-1:1;
61 }
62
63 /**
64 * Gibt alle Ziele zurück und cachet diese.
65 *
66 * @since 1.1
67 */
68
69 public static function get_all_targets()
70 {
71 /* Auf Cache zugreifen */
72 if ( $data = get_transient('statify_targets') ) {
73 return $data;
74 }
75
76 global $wpdb;
77
78 $data = $wpdb->get_results(
79 "SELECT COUNT(`target`) as `count`, `target` as `url` FROM `$wpdb->statify` GROUP BY `target` ORDER BY `count` DESC",
80 ARRAY_A
81 );
82
83 /* Merken */
84 set_transient(
85 'statify_targets', $data, 60 * 4 // = 4 Minuten
86 );
87
88 return $data;
89 }
90
91 }