| @@ -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,9 +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 | |
| 12 | + * @package OpenStation | |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | defined( 'ABSPATH' ) || exit; |
| 16 | 16 | |
| @@ -22,9 +22,9 @@ | ||
| 22 | 22 | * post date. |
| 23 | 23 | * |
| 24 | 24 | * @return int Unix timestamp, or 0 when the site has neither. |
| 25 | 25 | */ |
| 26 | -function desktop_mode_living_tree_install_epoch() { | |
| 26 | +function openstation_living_tree_install_epoch() { | |
| 27 | 27 | global $wpdb; |
| 28 | 28 | |
| 29 | 29 | $oldest_user = $wpdb->get_var( |
| 30 | 30 | "SELECT MIN( user_registered ) FROM {$wpdb->users}" |
| @@ -52,10 +52,10 @@ | ||
| 52 | 52 | * non-negative — the master clock never runs backwards. |
| 53 | 53 | * |
| 54 | 54 | * @return int Whole days since the site's inception. >= 0. |
| 55 | 55 | */ |
| 56 | -function desktop_mode_living_tree_site_age_days() { | |
| 57 | - $epoch = desktop_mode_living_tree_install_epoch(); | |
| 56 | +function openstation_living_tree_site_age_days() { | |
| 57 | + $epoch = openstation_living_tree_install_epoch(); | |
| 58 | 58 | if ( $epoch <= 0 ) { |
| 59 | 59 | return 0; |
| 60 | 60 | } |
| 61 | 61 | return max( 0, (int) floor( ( time() - $epoch ) / DAY_IN_SECONDS ) ); |
| @@ -66,18 +66,18 @@ | ||
| 66 | 66 | * site-views widget uses: Jetpack Stats first, then the |
| 67 | 67 | * `_post_views_YYYY-MM-DD` post-meta convention — both summed over the |
| 68 | 68 | * last 14 days. Sites with neither simply report 0 (a windless day). |
| 69 | 69 | * |
| 70 | - * The final value passes through the `desktop_mode_living_tree_traffic` | |
| 70 | + * The final value passes through the `openstation_living_tree_traffic` | |
| 71 | 71 | * filter so analytics plugins with their own counters can feed the |
| 72 | 72 | * real number in. |
| 73 | 73 | * |
| 74 | 74 | * @return int Recent view sum. >= 0. |
| 75 | 75 | */ |
| 76 | -function desktop_mode_living_tree_traffic() { | |
| 77 | - $views = desktop_mode_living_tree_jetpack_visits(); | |
| 76 | +function openstation_living_tree_traffic() { | |
| 77 | + $views = openstation_living_tree_jetpack_visits(); | |
| 78 | 78 | if ( null === $views ) { |
| 79 | - $views = desktop_mode_living_tree_meta_views(); | |
| 79 | + $views = openstation_living_tree_meta_views(); | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * Filter the Living Tree traffic hormone source. Return a |
| @@ -87,9 +87,9 @@ | ||
| 87 | 87 | * @param int $views Views in the window. Default: Jetpack Stats |
| 88 | 88 | * when available, else the `_post_views_*` meta |
| 89 | 89 | * sum, else 0. |
| 90 | 90 | */ |
| 91 | - $views = (int) apply_filters( 'desktop_mode_living_tree_traffic', $views ); | |
| 91 | + $views = (int) apply_filters( 'openstation_living_tree_traffic', $views ); | |
| 92 | 92 | return max( 0, $views ); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
| @@ -107,9 +107,9 @@ | ||
| 107 | 107 | * |
| 108 | 108 | * @return int|null Views over the last 14 days, or null when Jetpack |
| 109 | 109 | * Stats can't answer. |
| 110 | 110 | */ |
| 111 | -function desktop_mode_living_tree_jetpack_visits() { | |
| 111 | +function openstation_living_tree_jetpack_visits() { | |
| 112 | 112 | if ( ! class_exists( '\Automattic\Jetpack\Stats\WPCOM_Stats' ) ) { |
| 113 | 113 | return null; |
| 114 | 114 | } |
| 115 | 115 | $wpcom_stats = new \Automattic\Jetpack\Stats\WPCOM_Stats(); |
| @@ -163,9 +163,9 @@ | ||
| 163 | 163 | * widget. Sites without a view-counter plugin report 0. |
| 164 | 164 | * |
| 165 | 165 | * @return int Recent view sum. >= 0. |
| 166 | 166 | */ |
| 167 | -function desktop_mode_living_tree_meta_views() { | |
| 167 | +function openstation_living_tree_meta_views() { | |
| 168 | 168 | global $wpdb; |
| 169 | 169 | |
| 170 | 170 | $total = 0; |
| 171 | 171 | $today = current_time( 'Y-m-d' ); |
| @@ -189,16 +189,16 @@ | ||
| 189 | 189 | * Number of users currently online, from framework presence. |
| 190 | 190 | * |
| 191 | 191 | * @return int Count of users with `online` presence status. >= 0. |
| 192 | 192 | */ |
| 193 | -function desktop_mode_living_tree_active_users() { | |
| 194 | - if ( ! function_exists( 'desktop_mode_presence_snapshot' ) ) { | |
| 193 | +function openstation_living_tree_active_users() { | |
| 194 | + if ( ! function_exists( 'openstation_presence_snapshot' ) ) { | |
| 195 | 195 | return 0; |
| 196 | 196 | } |
| 197 | 197 | $count = 0; |
| 198 | - foreach ( desktop_mode_presence_snapshot() as $record ) { | |
| 198 | + foreach ( openstation_presence_snapshot() as $record ) { | |
| 199 | 199 | if ( isset( $record['status'] ) && 'online' === $record['status'] ) { |
| 200 | - $count++; | |
| 200 | + ++$count; | |
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | return $count; |
| 204 | 204 | } |
| @@ -216,9 +216,9 @@ | ||
| 216 | 216 | * feed the real value in via the filter. |
| 217 | 217 | * |
| 218 | 218 | * @return float Health score in [0, 1]. |
| 219 | 219 | */ |
| 220 | -function desktop_mode_living_tree_seo_health() { | |
| 220 | +function openstation_living_tree_seo_health() { | |
| 221 | 221 | /** |
| 222 | 222 | * Filter the Living Tree health hormone source. Return 0..1 — it |
| 223 | 223 | * drives the canopy's colour temperature (green → yellow → red → |
| 224 | 224 | * grey). |
| @@ -224,9 +224,9 @@ | ||
| 224 | 224 | * grey). |
| 225 | 225 | * |
| 226 | 226 | * @param float $health Default 0.7. |
| 227 | 227 | */ |
| 228 | - $health = (float) apply_filters( 'desktop_mode_living_tree_seo_health', 0.7 ); | |
| 228 | + $health = (float) apply_filters( 'openstation_living_tree_seo_health', 0.7 ); | |
| 229 | 229 | return min( 1.0, max( 0.0, $health ) ); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
| @@ -232,9 +232,9 @@ | ||
| 232 | 232 | /** |
| 233 | 233 | * Performance headroom, normalised 0..1 (1 = plenty, 0 = under load). |
| 234 | 234 | * |
| 235 | 235 | * Sourced from core's own Site Health tallies when available (see |
| 236 | - * {@see desktop_mode_living_tree_site_health_performance()}), falling | |
| 236 | + * {@see openstation_living_tree_site_health_performance()}), falling | |
| 237 | 237 | * back to a comfortable 0.8 until the weekly Site Health cron has run |
| 238 | 238 | * at least once. The filter remains the integration point for plugins |
| 239 | 239 | * with real runtime telemetry. |
| 240 | 240 | * |
| @@ -239,10 +239,10 @@ | ||
| 239 | 239 | * with real runtime telemetry. |
| 240 | 240 | * |
| 241 | 241 | * @return float Performance score in [0, 1]. |
| 242 | 242 | */ |
| 243 | -function desktop_mode_living_tree_performance() { | |
| 244 | - $performance = desktop_mode_living_tree_site_health_performance(); | |
| 243 | +function openstation_living_tree_performance() { | |
| 244 | + $performance = openstation_living_tree_site_health_performance(); | |
| 245 | 245 | if ( null === $performance ) { |
| 246 | 246 | $performance = 0.8; |
| 247 | 247 | } |
| 248 | 248 | |
| @@ -254,9 +254,9 @@ | ||
| 254 | 254 | * Health issue counts when the |
| 255 | 255 | * `health-check-site-status-result` |
| 256 | 256 | * transient exists, else 0.8. |
| 257 | 257 | */ |
| 258 | - $performance = (float) apply_filters( 'desktop_mode_living_tree_performance', $performance ); | |
| 258 | + $performance = (float) apply_filters( 'openstation_living_tree_performance', $performance ); | |
| 259 | 259 | return min( 1.0, max( 0.0, $performance ) ); |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
| @@ -280,9 +280,9 @@ | ||
| 280 | 280 | * |
| 281 | 281 | * @return float|null Composite in [0.2, 1], or null when the Site |
| 282 | 282 | * Health tallies aren't available (yet). |
| 283 | 283 | */ |
| 284 | -function desktop_mode_living_tree_site_health_performance() { | |
| 284 | +function openstation_living_tree_site_health_performance() { | |
| 285 | 285 | $raw = get_transient( 'health-check-site-status-result' ); |
| 286 | 286 | if ( is_string( $raw ) && '' !== $raw ) { |
| 287 | 287 | $counts = json_decode( $raw, true ); |
| 288 | 288 | } elseif ( is_array( $raw ) ) { |
| @@ -313,9 +313,9 @@ | ||
| 313 | 313 | * simulator may bias growth density with it, never position anything. |
| 314 | 314 | * |
| 315 | 315 | * @return array[] Compact branch DNA hints (max 12 entries). |
| 316 | 316 | */ |
| 317 | -function desktop_mode_living_tree_branch_dna() { | |
| 317 | +function openstation_living_tree_branch_dna() { | |
| 318 | 318 | global $wpdb; |
| 319 | 319 | |
| 320 | 320 | $rows = $wpdb->get_results( |
| 321 | 321 | "SELECT YEAR( post_date_gmt ) AS y, COUNT(*) AS n |
| @@ -343,8 +343,8 @@ | ||
| 343 | 343 | 'depth' => $depth, |
| 344 | 344 | 'girth' => round( (int) $row['n'] / $max, 3 ), |
| 345 | 345 | 'length' => round( min( 1.0, (int) $row['n'] / $max + 0.2 ), 3 ), |
| 346 | 346 | ); |
| 347 | - $depth++; | |
| 347 | + ++$depth; | |
| 348 | 348 | } |
| 349 | 349 | return $out; |
| 350 | 350 | } |