tpw_complete': // 重置密码 $pre .= $default_pre .= 'user_resetpw_complete.htm'; break; case 'user_comment': // 我的首页评论 $pre .= $default_pre .= 'user_comment.htm'; break; case 'single_page': // 单页 $pre .= $default_pre .= 'single_page.htm'; break; case 'search': // 搜索 $pre .= $default_pre .= 'search.htm'; break; case 'operate_sticky': // 置顶 $pre .= $default_pre .= 'operate_sticky.htm'; break; case 'operate_close': // 关闭 $pre .= $default_pre .= 'operate_close.htm'; break; case 'operate_delete': // 删除 $pre .= $default_pre .= 'operate_delete.htm'; break; case 'operate_move': // 移动 $pre .= $default_pre .= 'operate_move.htm'; break; case '404': $pre .= $default_pre .= '404.htm'; break; case 'read_404': $pre .= $default_pre .= 'read_404.htm'; break; case 'list_404': $pre .= $default_pre .= 'list_404.htm'; break; default: // 首页 $pre .= $default_pre .= theme_mode_pre(); break; } if ($config['theme']) { $conffile = APP_PATH . 'view/template/' . $config['theme'] . '/conf.json'; $json = is_file($conffile) ? xn_json_decode(file_get_contents($conffile)) : array(); } // 加载绑定ID安装风格 !empty($json['installed']) and $path_file = APP_PATH . 'view/template/' . $config['theme'] . '/htm/' . ($id ? $id . '_' : '') . $pre; // 加载安装风格 (empty($path_file) || !is_file($path_file)) and $path_file = APP_PATH . 'view/template/' . $config['theme'] . '/htm/' . $pre; // 主风格下可安装多个子风格 if (!empty($config['theme_child']) && is_array($config['theme_child'])) { foreach ($config['theme_child'] as $theme) { if (empty($theme) || is_array($theme)) continue; // 加载绑定ID安装风格 $path_file = APP_PATH . 'view/template/' . $theme . '/htm/' . ($id ? $id . '_' : '') . $pre; // 加载安装风格 !is_file($path_file) and $path_file = APP_PATH . 'view/template/' . $theme . '/htm/' . $pre; } } // 风格不存在加载适配端 !is_file($path_file) and $path_file = APP_PATH . ($dir ? 'plugin/' . $dir . '/view/htm/' : 'view/htm/') . $default_pre; return $path_file; } // 依据模式返回适配文件 function theme_mode_pre($type = 0) { global $config; // 网站模式 $mode = $config['setting']['website_mode']; $pre = ''; // 首页文件前缀 if (1 == $mode) { // 门户模式 $pre .= 2 == $type ? 'portal_category.htm' : 'portal.htm'; } elseif (2 == $mode) { // 扁平模式 $pre .= 2 == $type ? 'flat_category.htm' : 'flat.htm'; } else { // 自定义模式 $pre .= 2 == $type ? 'index_category.htm' : 'index.htm'; } return $pre; } ?>php - Need help to create Wordpress page that decodes a text file and publishes it in JSON format|Concepts Of Algorithm

php - Need help to create Wordpress page that decodes a text file and publishes it in JSON format

admin2025-06-04  1

I would like to create a Wordpress page that lists temperature and humidity data. The data originates in an encoded .txt file. I'm using the following PHP file to decode the data in the text file. I haven't been successful at creating a functional page in Wordpress using this code.

The .txt file is also reproduced below.

<?php
// publish_payload_in_json.php
// Remote Home Monitor with Hologram Nova
// Publish JSON payload
// Decodes Hologram payload and publishes it in JSON format. JSON data is
// later loaded by the Remote Home Monitor dashboard with JQuery.
//
// Luis Ortiz - luislab
// January 5, 2018

$whFileName = "./payload.txt";   // Home Monitor payload

if ( is_readable($whFileName) ) {             // better than file_exists()
    $whFileHandle = fopen($whFileName, 'r') or die("1815");

    $data = trim(fgets($whFileHandle));
    $data = base64_decode($data);

    fclose($whFileHandle);

    if ( $_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_SERVER['QUERY_STRING']) ) {
        header('HTTP/1.1 200 OK');
        header('Content-Type: application/json');
        echo $data;
    }else {
        header('HTTP/1.1 503 Service Temporarily Unavailable');
        header('Status: 503 Service Temporarily Unavailable');
    }
}

?>

Payload.txt

eyJ0ZW1wZXJhdHVyZSI6IDY3LjQ2MDAwMTM3MzI5MTAyLCAiaHVtaWRpdHkiOiA0OC45MDAwMDE1MjU4Nzg5MDZ9
5x.20x.5x.21x
HologramCloud ()
webhookkeyxxxxxx
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749046893a315901.html

lang[new_post](0)