function Broadcast_control_response_delete($params) { $user = Users::loggedInUser(true); $agreement = new Broadcast_Agreement(); $agreement->userId = $user->id; $agreement->publisherId = $_REQUEST['publisherId']; $agreement->streamName = 'Broadcast/main'; $agreement->platform = 'facebook'; $agreement->remove(); return array('success' => 'true'); }
function Broadcast_control_response_content($params) { $user = Users::loggedInUser(true); $organizations = Broadcast_Agreement::select('a.userId, a.publisherId, u.organization_title, u.organization_domain', 'a')->join(Broadcast_User::table() . ' u', array('a.publisherId' => 'u.userId'))->where(array('a.userId' => $user->id))->fetchAll(PDO::FETCH_ASSOC); foreach ($organizations as $k => $org) { $messages = Streams_Message::select('content')->where(array('publisherId' => $org['publisherId'], 'streamName' => 'Broadcast/main'))->orderBy('sentTime')->fetchAll(PDO::FETCH_ASSOC); $organizations[$k]['messages'] = array(); foreach ($messages as $msg) { $content = json_decode($msg['content'], true); if (isset($content['link'])) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $content['link']); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux i686; cs-CZ; rv:1.7.12) Gecko/20050929"); $page_contents = curl_exec($ch); curl_close($ch); preg_match('/<title>([^<]+)<\\/title>/', $page_contents, $matches); if (isset($matches[1])) { $content['link_title'] = $matches[1]; } } $organizations[$k]['messages'][] = $content; } } Q_Config::set('Q', 'response', 'Broadcast', 'layout_html', 'Broadcast/layout/canvas.php'); Q_Response::addStylesheet('css/canvas.css'); Q_Response::addScript('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'); Q_Response::addScript('js/canvas.js'); return Q::view('Broadcast/content/control.php', compact('organizations')); }
function Broadcast_agreement_delete() { $user = Users::loggedInUser(true); foreach (array('publisherId', 'streamName') as $field) { if (empty($_REQUEST[$field])) { throw new Q_Exception_RequiredField(compact('field')); } } $streamName = is_array($_REQUEST['streamName']) ? implode('/', $_REQUEST['streamName']) : $_REQUEST['streamName']; $agreement = new Broadcast_Agreement(); $agreement->userId = $user->id; $agreement->publisherId = $_REQUEST['publisherId']; $agreement->streamName = $streamName; $agreement->platform = 'facebook'; $agreement->remove(); Broadcast::$cache['agreement'] = false; }
function Broadcast_agreement_response_data() { $streamName = is_array($_REQUEST['streamName']) ? implode('/', $_REQUEST['streamName']) : $_REQUEST['streamName']; if (!isset(Broadcast::$cache['agreement'])) { $user = Users::loggedInUser(true); $agreement = new Broadcast_Agreement(); $agreement->userId = $user->id; $agreement->publisherId = $_REQUEST['publisherId']; $agreement->streamName = $_REQUEST['streamName']; if ($agreement->retrieve()) { Broadcast::$cache['agreement'] = $agreement; } else { Broadcast::$cache['agreement'] = false; } } $agreed = !empty(Broadcast::$cache['agreement']); return compact('agreed'); }
function Broadcast_stream_response_content() { $publisherId = Streams::requestedPublisherId(true); $name = Streams::requestedName(true); $fields = Streams::requestedFields(); $user = Users::loggedInUser(); $userId = $user ? $user->id : 0; if (isset(Streams::$cache['stream'])) { $stream = Streams::$cache['stream']; } else { $streams = Streams::fetch($userId, $publisherId, $name, $fields, array('limit' => 30)); if (empty($streams)) { throw new Q_Exception("No such stream", 'name'); } $stream = reset($streams); } if ($publisherId != $userId and !$stream->testReadLevel('content')) { return "This belongs to someone else."; } if ($publisherId != $userId and !$stream->testReadLevel('content')) { throw new Users_Exception_NotAuthorized(); } $userIds = array(); $agreements = Broadcast_Agreement::select('userId')->where(array('publisherId' => $publisherId, 'streamName' => $name, 'platform' => 'facebook'))->fetchDbRows(); foreach ($agreements as $a) { $userIds[] = $a->userId; } if ($userIds) { $agreed_users = Users_User::select('*')->where(array('id' => $userIds))->fetchDbRows(); } else { $agreed_users = array(); } $src = 'Broadcast/widget?'; $q = array('publisherId' => $publisherId, 'streamName' => $name); foreach (array('css', 'button', 'checkmark', 'explanation') as $field) { if (isset($_REQUEST[$field])) { $q[$field] = $_REQUEST[$field]; } } $src .= http_build_query($q, null, '&'); $style = 'border: 0px;'; $code = Q_Html::tag('iframe', compact('src', 'style'), ''); Q_Response::addScript('plugins/Broadcast/js/Broadcast.js'); return Q::view('Broadcast/content/stream.php', compact('publisherId', 'name', 'fields', 'user', 'stream', 'agreed_users', 'code')); }