public function __construct() { $this->session = Session::getInstance(); $this->su = ScreenUtils::getInstance(); $this->user = User::getInstance(); $this->user->auth('*****@*****.**', 'tenant'); }
public static function getInstance() { if (null == self::$instance) { self::$instance = new ScreenUtils(); } return self::$instance; }
public function saveLayoutJSON() { $cfg = ScreenUtils::getInstance()->getDefaultConfig(); $cfg = json_decode($cfg); // --> !!!!! $cfg->formats[0]->title = '"23 years too late"'; $cfg->formats[0]->title = "'23 years too late'"; $cfg->formats[0]->title = "`23 years too late`"; $cfg->formats[0]->title = "''23 years too late''"; $cfg->formats[0]->title = "''\"23 years too late\"''"; print_r($cfg); $cfg = json_encode($cfg, JSON_PRETTY_PRINT); print 'Sending: (escape the unescape)'; print PHP_EOL; print_r($cfg); print PHP_EOL; $pd = ['rid' => '1', 'cfg' => $cfg, 'nme' => 'yodel', 'req' => 'saveLayoutJSON']; $res = $this->post(Settings::baseRef . '/admin/save-layout-json', $pd); $this->printMsg('ServiceTest::saveLayoutJSON():' . $res); $this->printErr(Session::getInstance()->flushError()); print PHP_EOL; }
public function addMockRadio() { $name = 'Yodli Radio'; $station_id = Utils::getInstance()->strToFilename($name); $uid = 1; $url = "http://stream"; $facebook = "http://facebook"; $twitter = "http://twitter"; $logopath = "http://logo"; $config = ScreenUtils::getInstance()->getDefaultConfig(); $args = ["station_id" => $station_id, "user_id" => $uid, "name" => $name, "logopath" => $logopath, "url" => $url, "facebook" => $facebook, "twitter" => $twitter, "config" => $config]; $res = $this->webDBUtils->addRadio($args); if (false == $res) { $this->printErr('WebDBUtilsTest::addMockRadio(): failed'); $this->printErr($this->session->flushError()); } else { $this->printMsg('WebDBUtilsTest:addMockRadio(): succeeded'); print_r($res); print PHP_EOL; } }
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; }