function widgetControl($baseurl = "widgets/wControl.php", $forcemenu = false) { global $mfpsecured, $mfpapikey; $json = '{"status":true}'; $errmsg = ''; if (!empty($_GET["style"]) && ($_GET["style"] == "w" || $_GET["style"] == "m")) { $displayMenu = $_GET["style"] == "m" || $forcemenu; if (!empty($_GET["cmd"])) { switch ($_GET["cmd"]) { case "shutdown": // Shutdown $results = jsonmethodcall("System.Shutdown"); break; case "suspend": // Suspend $results = jsonmethodcall("System.Suspend"); break; case "hibernate": // Hibernate $results = jsonmethodcall("System.Hibernate"); break; case "reboot": // Reboot $results = jsonmethodcall("System.Reboot"); break; case "exit": // Exit // Exit case "quit": $results = jsonmethodcall("XBMC.Quit"); break; case "vidscan": // Video Library ScanForContent $results = jsonmethodcall("VideoLibrary.ScanForContent"); break; default: $errmsg = "Invalid Command"; $displayMenu = $_GET["style"] != "m"; } } elseif (!empty($_GET["json"])) { $request = stripslashes(urldecode($_GET["json"])); $results = jsoncall($request); // This method will only work if MFP is on the same system as xbmc. } elseif (!empty($_GET["xbmcsend"])) { if (!empty($mfpapikey) && !empty($_GET["apikey"]) && $_GET["apikey"] == $mfpapikey || $mfpsecured) { $request = "xbmc-send"; $request .= !empty($_GET["host"]) ? " --host=" . $_GET["host"] : ""; $request .= !empty($_GET["port"]) ? " --port=" . $_GET["port"] : ""; $request .= " --action=\"" . stripslashes(urldecode($_GET["xbmcsend"])) . "\""; $results = shell_exec($request); $json = '{"status":true, "message": "' . str_replace("\"", "\\\"", $results) . '"}'; } else { $errmsg = "Authorization failure"; } } elseif (!empty($_GET["shell"])) { if (!empty($mfpapikey) && !empty($_GET["apikey"]) && $_GET["apikey"] == $mfpapikey || $mfpsecured) { $request = stripslashes(urldecode($_GET["shell"])); $results = shell_exec($request); $json = '{"status":true, "message": "' . str_replace("\"", "\\\"", $results) . '"}'; } else { $errmsg = "Authorization failure"; } } else { $displayMenu = $forcemenu; $errmsg = "No action."; } } else { $displayMenu = $forcemenu; } if ($displayMenu) { widgetMenu($baseurl); } else { if (!empty($_GET["style"]) && $_GET["style"] == "w") { if (!empty($errmsg)) { $json = '{"status":false, "error": "' . $errmsg . '"}'; } echo str_replace("\n", "\\n", $json); } } }
function xbmc_passthough($arrRequest) { if (!empty($arrRequest["params"]) && is_array($arrRequest["params"])) { $request = json_encode($arrRequest["params"]); $arrResult = jsoncall($request); if (empty($arrResult) || !is_array($arrResult)) { $arrResult = error_array(-32503, "Invalid response."); } } else { $arrResult = error_array(-32602, "Invalid parameters."); } return $arrResult; }
function jsonmethodcall($method, $args = array(), $service_uri = "") { $request = jsonstring($method, $args); return jsoncall($request, $service_uri); }
function playSongFromList($songid) { echo "1"; $jsonVersion = jsonmethodcall("JSONRPC.Version"); //pull the JSON version # from XBMC $results = jsonmethodcall("Player.GetActivePlayers"); if (!empty($results)) { if ($results['result']['audio'] == 1) { if ($jsonVersion['result']['version'] == '2') { $request = jsonstring("AudioPlaylist.Add", $songid); } if ($jsonVersion['result']['version'] == '3') { $request = jsonstring("AudioPlaylistV3.Add", $songid); } } else { if ($jsonVersion['result']['version'] == '2') { $request = jsonstring("XBMC.Play", '"songid": ' . $songid); } if ($jsonVersion['result']['version'] == '3') { jsoncall(jsonstring("AudioPlaylist.Clear")); jsoncall(jsonstring("AudioPlaylistV3.Add", $songid)); jsoncall(jsonstring("AudioPlaylist.Play")); } } $results = jsoncall($request); if (empty($results)) { echo $COMM_ERROR; echo "<pre>{$request}</pre>"; } } else { echo $COMM_ERROR; } }
function playSongFromList($songid) { $results = jsonmethodcall("Player.GetActivePlayers"); if (!empty($results)) { if ($results['result']['audio'] == 1) { $request = jsonstring("AudioPlaylist.Add", $songid); } else { $request = jsonstring("XBMC.Play", '"songid": ' . $songid); } $results = jsoncall($request); if (empty($results)) { echo $COMM_ERROR; echo "<pre>{$request}</pre>"; } } else { echo $COMM_ERROR; } }