Пример #1
0
function sparky_status_shortcode($atts)
{
    $atts = shortcode_atts(array('id' => false), $atts);
    // no ID? fail
    if (!$atts['id']) {
        return;
    }
    // get post
    $post = get_post($atts['id']);
    // not a spark? fail
    if (!$post) {
        return;
    }
    if ($post->post_type != 'spark') {
        return;
    }
    // grab the post meta
    $core = get_post_meta($post->ID, 'spark-core', true);
    $cache = get_post_meta($post->ID, 'spark-cache', true);
    // return the value
    $sa = new spark_api();
    $status = $sa->spark_devices($cache);
    if (is_array($status)) {
        foreach ($status as $stat) {
            if ($stat['id'] == $core) {
                if ($stat['connected']) {
                    $online = true;
                    $corestatus = __('Online', 'sparky');
                } else {
                    $online = false;
                    $corestatus = __('Offline', 'sparky');
                }
            }
        }
    } else {
        $corestatus = $status;
    }
    return $corestatus;
}
Пример #2
0
    public function status_box($post)
    {
        if ($post->post_status != 'publish') {
            ?>
<p><?php 
            _e('Save your Spark to see status.', $this->plugin_slug);
            ?>
</p><?php 
        } else {
            $core = get_post_meta($post->ID, 'spark-core', true);
            $variable = get_post_meta($post->ID, 'spark-variable', true);
            $cache = get_post_meta($post->ID, 'spark-cache', true);
            $sa = new spark_api();
            $status = $sa->spark_devices();
            if (is_array($status)) {
                foreach ($status as $stat) {
                    if ($stat['id'] == $core) {
                        if ($stat['connected']) {
                            $online = true;
                            $corestatus = __('Online', $this->plugin_slug);
                        } else {
                            $online = false;
                            $corestatus = __('Offline', $this->plugin_slug);
                        }
                    }
                }
            } else {
                $corestatus = $status;
            }
            ?>
			<h4><?php 
            _e('Live Data', $this->plugin_slug);
            ?>
</h4>
			
			<ul>
				<li><?php 
            _e('Core:', $this->plugin_slug);
            ?>
 <?php 
            echo $corestatus;
            ?>
</li>
				<?php 
            if ($online) {
                ?>
					<?php 
                $value = $sa->spark_variable($core, $variable, false);
                if (is_array($value)) {
                    $livevalue = $value['result'];
                } else {
                    $livevalue = $value;
                }
                ?>
					<li><?php 
                _e('Value:', $this->plugin_slug);
                ?>
 <?php 
                echo $livevalue;
                ?>
</li>
				<?php 
            }
            ?>
			</ul>

			<h4><?php 
            _e('Cached Data', $this->plugin_slug);
            ?>
</h4>
			
			<?php 
            $value = $sa->spark_variable($core, $variable, $cache);
            if (is_array($value)) {
                $cachevalue = $value['result'];
            } else {
                $cachevalue = __('Cache expired.', $this->plugin_slug);
            }
            ?>

			<ul>
				<li><?php 
            _e('Value:', $this->plugin_slug);
            ?>
 <?php 
            echo $cachevalue;
            ?>
</li>
			</ul>

			<?php 
        }
    }