| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode — Living Tree: metric helpers. | |
| 3 | + * OpenStation — Living Tree: metric helpers. | |
| 4 | 4 | * |
| 5 | 5 | * The scalar signals the snapshot builder folds into the site's DNA. |
| 6 | 6 | * Each helper composes existing WordPress aggregates (`wp_count_posts`, |
| 7 | 7 | * `wp_count_comments`, `wp_count_terms`), the site-views traffic signal, |
| @@ -8,10 +8,9 @@ | ||
| 8 | 8 | * and framework presence — never a per-row payload. The golden rule |
| 9 | 9 | * (WordPress emits hormones, never geometry) starts here: everything |
| 10 | 10 | * returned is a scalar or a tiny capped list. |
| 11 | 11 | * |
| 12 | - * @package WPDesktopMode | |
| 13 | - * @since 0.9.4 | |
| 12 | + * @package OpenStation | |
| 14 | 13 | */ |
| 15 | 14 | |
| 16 | 15 | defined( 'ABSPATH' ) || exit; |
| 17 | 16 | |
| @@ -21,13 +20,11 @@ | ||
| 21 | 20 | * between requests. Composed (core has no first-party "install time"): |
| 22 | 21 | * the earlier of the oldest user registration and the oldest published |
| 23 | 22 | * post date. |
| 24 | 23 | * |
| 25 | - * @since 0.9.4 | |
| 26 | - * | |
| 27 | 24 | * @return int Unix timestamp, or 0 when the site has neither. |
| 28 | 25 | */ |
| 29 | -function desktop_mode_living_tree_install_epoch() { | |
| 26 | +function openstation_living_tree_install_epoch() { | |
| 30 | 27 | global $wpdb; |
| 31 | 28 | |
| 32 | 29 | $oldest_user = $wpdb->get_var( |
| 33 | 30 | "SELECT MIN( user_registered ) FROM {$wpdb->users}" |
| @@ -53,14 +50,12 @@ | ||
| 53 | 50 | /** |
| 54 | 51 | * Age of the site in whole days, from the install epoch. Clamped to be |
| 55 | 52 | * non-negative — the master clock never runs backwards. |
| 56 | 53 | * |
| 57 | - * @since 0.9.4 | |
| 58 | - * | |
| 59 | 54 | * @return int Whole days since the site's inception. >= 0. |
| 60 | 55 | */ |
| 61 | -function desktop_mode_living_tree_site_age_days() { | |
| 62 | - $epoch = desktop_mode_living_tree_install_epoch(); | |
| 56 | +function openstation_living_tree_site_age_days() { | |
| 57 | + $epoch = openstation_living_tree_install_epoch(); | |
| 63 | 58 | if ( $epoch <= 0 ) { |
| 64 | 59 | return 0; |
| 65 | 60 | } |
| 66 | 61 | return max( 0, (int) floor( ( time() - $epoch ) / DAY_IN_SECONDS ) ); |
| @@ -71,20 +66,18 @@ | ||
| 71 | 66 | * site-views widget uses: Jetpack Stats first, then the |
| 72 | 67 | * `_post_views_YYYY-MM-DD` post-meta convention — both summed over the |
| 73 | 68 | * last 14 days. Sites with neither simply report 0 (a windless day). |
| 74 | 69 | * |
| 75 | - * The final value passes through the `desktop_mode_living_tree_traffic` | |
| 70 | + * The final value passes through the `openstation_living_tree_traffic` | |
| 76 | 71 | * filter so analytics plugins with their own counters can feed the |
| 77 | 72 | * real number in. |
| 78 | 73 | * |
| 79 | - * @since 0.9.4 | |
| 80 | - * | |
| 81 | 74 | * @return int Recent view sum. >= 0. |
| 82 | 75 | */ |
| 83 | -function desktop_mode_living_tree_traffic() { | |
| 84 | - $views = desktop_mode_living_tree_jetpack_visits(); | |
| 76 | +function openstation_living_tree_traffic() { | |
| 77 | + $views = openstation_living_tree_jetpack_visits(); | |
| 85 | 78 | if ( null === $views ) { |
| 86 | - $views = desktop_mode_living_tree_meta_views(); | |
| 79 | + $views = openstation_living_tree_meta_views(); | |
| 87 | 80 | } |
| 88 | 81 | |
| 89 | 82 | /** |
| 90 | 83 | * Filter the Living Tree traffic hormone source. Return a |
| @@ -90,15 +83,13 @@ | ||
| 90 | 83 | * Filter the Living Tree traffic hormone source. Return a |
| 91 | 84 | * non-negative view count for the last ~14 days — it drives the |
| 92 | 85 | * wind (canopy sway amplitude / frequency). |
| 93 | 86 | * |
| 94 | - * @since 0.9.5 | |
| 95 | - * | |
| 96 | 87 | * @param int $views Views in the window. Default: Jetpack Stats |
| 97 | 88 | * when available, else the `_post_views_*` meta |
| 98 | 89 | * sum, else 0. |
| 99 | 90 | */ |
| 100 | - $views = (int) apply_filters( 'desktop_mode_living_tree_traffic', $views ); | |
| 91 | + $views = (int) apply_filters( 'openstation_living_tree_traffic', $views ); | |
| 101 | 92 | return max( 0, $views ); |
| 102 | 93 | } |
| 103 | 94 | |
| 104 | 95 | /** |
| @@ -113,14 +104,12 @@ | ||
| 113 | 104 | * unexpected payload — returns `null` and the caller falls back to the |
| 114 | 105 | * post-views meta. A successful `0` is trusted (a quiet site is a |
| 115 | 106 | * valid answer), matching the widget's source-ladder semantics. |
| 116 | 107 | * |
| 117 | - * @since 0.9.5 | |
| 118 | - * | |
| 119 | 108 | * @return int|null Views over the last 14 days, or null when Jetpack |
| 120 | 109 | * Stats can't answer. |
| 121 | 110 | */ |
| 122 | -function desktop_mode_living_tree_jetpack_visits() { | |
| 111 | +function openstation_living_tree_jetpack_visits() { | |
| 123 | 112 | if ( ! class_exists( '\Automattic\Jetpack\Stats\WPCOM_Stats' ) ) { |
| 124 | 113 | return null; |
| 125 | 114 | } |
| 126 | 115 | $wpcom_stats = new \Automattic\Jetpack\Stats\WPCOM_Stats(); |
| @@ -172,13 +161,11 @@ | ||
| 172 | 161 | * Last-14-days view sum from the `_post_views_YYYY-MM-DD` post-meta |
| 173 | 162 | * convention — the plain-WP fallback shared with the site-views |
| 174 | 163 | * widget. Sites without a view-counter plugin report 0. |
| 175 | 164 | * |
| 176 | - * @since 0.9.5 | |
| 177 | - * | |
| 178 | 165 | * @return int Recent view sum. >= 0. |
| 179 | 166 | */ |
| 180 | -function desktop_mode_living_tree_meta_views() { | |
| 167 | +function openstation_living_tree_meta_views() { | |
| 181 | 168 | global $wpdb; |
| 182 | 169 | |
| 183 | 170 | $total = 0; |
| 184 | 171 | $today = current_time( 'Y-m-d' ); |
| @@ -200,20 +187,18 @@ | ||
| 200 | 187 | |
| 201 | 188 | /** |
| 202 | 189 | * Number of users currently online, from framework presence. |
| 203 | 190 | * |
| 204 | - * @since 0.9.4 | |
| 205 | - * | |
| 206 | 191 | * @return int Count of users with `online` presence status. >= 0. |
| 207 | 192 | */ |
| 208 | -function desktop_mode_living_tree_active_users() { | |
| 209 | - if ( ! function_exists( 'desktop_mode_presence_snapshot' ) ) { | |
| 193 | +function openstation_living_tree_active_users() { | |
| 194 | + if ( ! function_exists( 'openstation_presence_snapshot' ) ) { | |
| 210 | 195 | return 0; |
| 211 | 196 | } |
| 212 | 197 | $count = 0; |
| 213 | - foreach ( desktop_mode_presence_snapshot() as $record ) { | |
| 198 | + foreach ( openstation_presence_snapshot() as $record ) { | |
| 214 | 199 | if ( isset( $record['status'] ) && 'online' === $record['status'] ) { |
| 215 | - $count++; | |
| 200 | + ++$count; | |
| 216 | 201 | } |
| 217 | 202 | } |
| 218 | 203 | return $count; |
| 219 | 204 | } |
| @@ -229,23 +214,19 @@ | ||
| 229 | 214 | * SEO plugins store in post-meta into a site-wide average. Until then, |
| 230 | 215 | * an SEO or monitoring plugin that *does* know the site's health can |
| 231 | 216 | * feed the real value in via the filter. |
| 232 | 217 | * |
| 233 | - * @since 0.9.4 | |
| 234 | - * | |
| 235 | 218 | * @return float Health score in [0, 1]. |
| 236 | 219 | */ |
| 237 | -function desktop_mode_living_tree_seo_health() { | |
| 220 | +function openstation_living_tree_seo_health() { | |
| 238 | 221 | /** |
| 239 | 222 | * Filter the Living Tree health hormone source. Return 0..1 — it |
| 240 | 223 | * drives the canopy's colour temperature (green → yellow → red → |
| 241 | 224 | * grey). |
| 242 | 225 | * |
| 243 | - * @since 0.9.4 | |
| 244 | - * | |
| 245 | 226 | * @param float $health Default 0.7. |
| 246 | 227 | */ |
| 247 | - $health = (float) apply_filters( 'desktop_mode_living_tree_seo_health', 0.7 ); | |
| 228 | + $health = (float) apply_filters( 'openstation_living_tree_seo_health', 0.7 ); | |
| 248 | 229 | return min( 1.0, max( 0.0, $health ) ); |
| 249 | 230 | } |
| 250 | 231 | |
| 251 | 232 | /** |
| @@ -251,19 +232,17 @@ | ||
| 251 | 232 | /** |
| 252 | 233 | * Performance headroom, normalised 0..1 (1 = plenty, 0 = under load). |
| 253 | 234 | * |
| 254 | 235 | * Sourced from core's own Site Health tallies when available (see |
| 255 | - * {@see desktop_mode_living_tree_site_health_performance()}), falling | |
| 236 | + * {@see openstation_living_tree_site_health_performance()}), falling | |
| 256 | 237 | * back to a comfortable 0.8 until the weekly Site Health cron has run |
| 257 | 238 | * at least once. The filter remains the integration point for plugins |
| 258 | 239 | * with real runtime telemetry. |
| 259 | 240 | * |
| 260 | - * @since 0.9.4 | |
| 261 | - * | |
| 262 | 241 | * @return float Performance score in [0, 1]. |
| 263 | 242 | */ |
| 264 | -function desktop_mode_living_tree_performance() { | |
| 265 | - $performance = desktop_mode_living_tree_site_health_performance(); | |
| 243 | +function openstation_living_tree_performance() { | |
| 244 | + $performance = openstation_living_tree_site_health_performance(); | |
| 266 | 245 | if ( null === $performance ) { |
| 267 | 246 | $performance = 0.8; |
| 268 | 247 | } |
| 269 | 248 | |
| @@ -270,16 +249,14 @@ | ||
| 270 | 249 | /** |
| 271 | 250 | * Filter the Living Tree performance hormone source. Return 0..1 — |
| 272 | 251 | * it throttles growth vigour. |
| 273 | 252 | * |
| 274 | - * @since 0.9.4 | |
| 275 | - * | |
| 276 | 253 | * @param float $performance Default: a composite of core's Site |
| 277 | 254 | * Health issue counts when the |
| 278 | 255 | * `health-check-site-status-result` |
| 279 | 256 | * transient exists, else 0.8. |
| 280 | 257 | */ |
| 281 | - $performance = (float) apply_filters( 'desktop_mode_living_tree_performance', $performance ); | |
| 258 | + $performance = (float) apply_filters( 'openstation_living_tree_performance', $performance ); | |
| 282 | 259 | return min( 1.0, max( 0.0, $performance ) ); |
| 283 | 260 | } |
| 284 | 261 | |
| 285 | 262 | /** |
| @@ -300,14 +277,12 @@ | ||
| 300 | 277 | * flavour for a "growth vigour" hormone. The transient is absent on a |
| 301 | 278 | * brand-new site until the weekly cron first fires or someone opens |
| 302 | 279 | * the Site Health screen; callers fall back to the 0.8 default then. |
| 303 | 280 | * |
| 304 | - * @since 0.9.5 | |
| 305 | - * | |
| 306 | 281 | * @return float|null Composite in [0.2, 1], or null when the Site |
| 307 | 282 | * Health tallies aren't available (yet). |
| 308 | 283 | */ |
| 309 | -function desktop_mode_living_tree_site_health_performance() { | |
| 284 | +function openstation_living_tree_site_health_performance() { | |
| 310 | 285 | $raw = get_transient( 'health-check-site-status-result' ); |
| 311 | 286 | if ( is_string( $raw ) && '' !== $raw ) { |
| 312 | 287 | $counts = json_decode( $raw, true ); |
| 313 | 288 | } elseif ( is_array( $raw ) ) { |
| @@ -336,13 +311,11 @@ | ||
| 336 | 311 | * posts grouped by year, each year mapped to a depth/girth/length hint |
| 337 | 312 | * normalised against the busiest year. This is DNA, not geometry — the |
| 338 | 313 | * simulator may bias growth density with it, never position anything. |
| 339 | 314 | * |
| 340 | - * @since 0.9.4 | |
| 341 | - * | |
| 342 | 315 | * @return array[] Compact branch DNA hints (max 12 entries). |
| 343 | 316 | */ |
| 344 | -function desktop_mode_living_tree_branch_dna() { | |
| 317 | +function openstation_living_tree_branch_dna() { | |
| 345 | 318 | global $wpdb; |
| 346 | 319 | |
| 347 | 320 | $rows = $wpdb->get_results( |
| 348 | 321 | "SELECT YEAR( post_date_gmt ) AS y, COUNT(*) AS n |
| @@ -370,8 +343,8 @@ | ||
| 370 | 343 | 'depth' => $depth, |
| 371 | 344 | 'girth' => round( (int) $row['n'] / $max, 3 ), |
| 372 | 345 | 'length' => round( min( 1.0, (int) $row['n'] / $max + 0.2 ), 3 ), |
| 373 | 346 | ); |
| 374 | - $depth++; | |
| 347 | + ++$depth; | |
| 375 | 348 | } |
| 376 | 349 | return $out; |
| 377 | 350 | } |