public static function getInstance() { if (null == self::$instance) { self::$instance = new RadioUtils(); } return self::$instance; }
public function __construct() { $this->session = Session::getInstance(); $this->radioUtils = RadioUtils::getInstance(); }
function saveLayoutJSON($app) { // sets up utils $user = User::getInstance(); $utils = Utils::getInstance(); $screenUtils = ScreenUtils::getInstance(); $radioUtils = RadioUtils::getInstance(); $session = Session::getInstance(); // reads incoming $nme = $utils->iStr($app->request()->post('nme'), 255); $rid = $utils->iStr($app->request()->post('rid'), 64); $cfg = $utils->iJsonDoc($app->request()->post('cfg'), 1000000); $station_id = $utils->iStr($app->request()->post('station_id'), 255); // generates station_id if (false == $station_id) { $station_id = $utils->strToFilename($nme); } // ... $uid = $user->getId(); $twitter = $utils->iStr($app->request()->post('twitter'), 64); $facebook = $utils->iStr($app->request()->post('facebook'), 64); $url = $utils->iStr($app->request()->post('url'), 64); $logopath = $utils->iStr($app->request()->post('logopath'), 64); // returns with invalid json if (false == $cfg) { $res = array('req' => 'saveLayoutJSON', 'res' => 'false', 'err' => L::__('Invalid JSON.'), 'rid' => $rid); header('Content-Type: application/json'); print json_encode($res); return; } // sets station id $cfg->stationId = $station_id; // saves a copy $path = Settings::jsonPath . '/config_' . $rid . '.json'; if (false == is_dir(Settings::jsonPath)) { @mkdir(Settings::jsonPath); } // saves another copy $path = Settings::jsonPath . '/' . $station_id . '.json'; if (false == is_dir(Settings::jsonPath)) { @mkdir(Settings::jsonPath); } // $f = json_encode($cfg, JSON_PRETTY_PRINT); $res = file_put_contents($path, $f); $res = chmod($path, 0775); // $doc = json_encode($cfg); $args = ["station_id" => $station_id, "user_id" => $uid, "name" => $nme, "logopath" => $logopath, "url" => $url, "facebook" => $facebook, "twitter" => $twitter, "config" => $doc]; $res = $radioUtils->updateRadio($rid, $args); $err = false == $res ? $session->flushError() : ''; $res = false == $res ? 'false' : 'ok'; $screenUtils->getConfig($rid); $channels = $screenUtils->getChannels(); $res = array('req' => 'saveLayoutJSON', 'res' => $res, 'err' => $err, 'rid' => $rid, 'cfg' => $cfg, 'channels' => $channels); return $res; }