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')); }
/** * Fetch messages of the stream. * @method getMessages * @param {array} [options=array()] An array of options determining how messages will be fetched, which can include: * "min" => Minimum ordinal of the message to select from (inclusive). Defaults to minimum ordinal of existing messages (if any). * "max" => Maximum ordinal of the message to select to (inclusive). Defaults to maximum ordinal of existing messages (if any). * Can also be negative, then the value will be substracted from maximum number of existing messages and +1 will be added * to guarantee that $max = -1 means highest message ordinal. * "limit" => Number of the messages to be selected. Defaults to 1000. * "ascending" => Sorting of fetched messages by ordinal. If true, sorting is ascending, if false - descending. * Defaults to true, but in case if 'min' option not given and only 'max' and 'limit' are given, we assuming * fetching in reverse order, so 'ascending' will default to false. * "type" => Optional string specifying the particular type of messages to get */ function getMessages($options) { // preparing default query $criteria = array('publisherId' => $this->publisherId, 'streamName' => $this->name); if (!empty($options['type'])) { $criteria['type'] = $options['type']; } $q = Streams_Message::select('*')->where($criteria); // getting $min and $max $result = Streams_Message::select("MIN(ordinal) AS min, MAX(ordinal) AS max")->where($criteria)->fetchAll(PDO::FETCH_ASSOC); if (!$result[0]) { return array(); } $min = (int) $result[0]['min']; $max = (int) $result[0]['max']; // default sorting is 'ORDER BY `ordinal` ASC', but it can be changed depending on options $ascending = true; if (!isset($options['min'])) { $options['min'] = $min; // if 'min' is not given, assume 'reverse' fetching, so $ascending is false $ascending = false; } if (!isset($options['max'])) { $options['max'] = $max; } else { if ($options['max'] < 0) { // if 'max' is negative, substract value from existing maximum $options['max'] = $max + $options['max'] + 1; } } if (empty($options['limit'])) { $options['limit'] = self::getConfigField($this->type, 'getMessagesLimit', 100); } if ($options['min'] > $options['max']) { return array(); } $q->where(array('ordinal >=' => $options['min'], 'ordinal <=' => $options['max'])); $q->limit($options['limit']); $q->orderBy('ordinal', isset($options['ascending']) ? $options['ascending'] : $ascending); return $q->fetchDbRows(null, '', 'ordinal'); }