/** * New messenger method: * Uses an expandable array of options and supports direct template rendering and subject prepending. * * @param array $message_options An array of message options. * @return bool|void */ public static function send($message_options) { $di = \Phalcon\Di::getDefault(); $config = $di->get('config'); $default_options = array('reply_to' => NULL, 'delivery_date' => NULL, 'options' => NULL); $options = array_merge($default_options, $message_options); // Render the template as the message if a template is specified. if (isset($options['template'])) { $previous_sp_setting = \DF\Url::getSchemePrefixSetting(); \DF\Url::forceSchemePrefix(TRUE); $view = \DF\Phalcon\View::getView(array('views_dir' => 'messages', 'layouts_dir' => '../templates', 'layout' => 'message')); $view->subject = $options['subject']; $view->setVars((array) $options['vars']); $options['message'] = $view->getRender('', $options['template']); \DF\Url::forceSchemePrefix($previous_sp_setting); } else { if (isset($options['body']) && !isset($options['message'])) { $options['message'] = $options['body']; unset($options['body']); } } // Append the system name as a prefix to the message. if (!isset($options['no_prefix']) || $options['no_prefix'] == FALSE) { $app_name = $config->application->name; $options['subject'] = $app_name . ': ' . $options['subject']; } return self::sendMail($options); }
public static function run($force = false) { $di = \Phalcon\Di::getDefault(); \DF\Url::forceSchemePrefix(true); self::_runNetworkNews($di, $force); self::_runStationEvents($di, $force); self::_runPodcastEpisodes($di, $force); }
public static function generate() { set_time_limit(60); // Fix DF\URL // prefixing. \DF\Url::forceSchemePrefix(true); $nowplaying = self::loadNowPlaying(); // Post statistics to official record (legacy for duplication, for now) // Analytics::post($nowplaying['api']); // Post statistics to InfluxDB. $influx = self::getInflux(); $influx->setDatabase('pvlive_stations'); $active_shortcodes = Station::getShortNameLookup(); $total_overall = 0; foreach ($nowplaying['api'] as $short_code => $info) { $listeners = (int) $info['listeners']['current']; $station_id = $info['station']['id']; if (isset($active_shortcodes[$short_code])) { $total_overall += $listeners; } $influx->insert('station.' . $station_id . '.listeners', ['value' => $listeners]); } $influx->insert('all.listeners', ['value' => $total_overall]); // Clear any records that are not audio/video category. $api_categories = array('audio', 'video'); foreach ($nowplaying['api'] as $station_shortcode => $station_info) { if (!in_array($station_info['station']['category'], $api_categories)) { unset($nowplaying['api'][$station_shortcode]); unset($nowplaying['legacy'][$station_shortcode]); } } // Generate PVL legacy nowplaying file. $nowplaying_feed = json_encode($nowplaying['legacy'], JSON_UNESCAPED_SLASHES); $pvl_file_path = \PVL\Service\AmazonS3::path('api/nowplaying.json'); @file_put_contents($pvl_file_path, $nowplaying_feed); $legacy_file_path = DF_INCLUDE_STATIC . '/api/nowplaying.json'; @file_put_contents($legacy_file_path, $nowplaying_feed); // Generate PVL API cache. $np_api = $nowplaying['api']; foreach ($np_api as $station => $np_info) { $np_api[$station]['cache'] = 'hit'; } Cache::save($np_api, 'api_nowplaying_data', array('nowplaying'), 60); foreach ($np_api as $station => $np_info) { $np_api[$station]['cache'] = 'flatfile'; } // Generate PVL API nowplaying file. $file_path_api = \PVL\Service\AmazonS3::path('api/nowplaying_api.json'); $nowplaying_api = json_encode(array('status' => 'success', 'result' => $np_api), JSON_UNESCAPED_SLASHES); @file_put_contents($file_path_api, $nowplaying_api); // Push to live-update service. PvlNode::push('nowplaying', $nowplaying['api']); return $pvl_file_path; }
public function preDispatch() { parent::preDispatch(); // Disable session creation. \DF\Session::disable(); // Disable rendering. $this->doNotRender(); // Allow AJAX retrieval. $this->response->setHeader('Access-Control-Allow-Origin', '*'); // Fix the base URL prefixed with '//'. \DF\Url::forceSchemePrefix(true); $this->_time_start = microtime(true); // Set all API calls to be public cache-controlled by default. $this->setCachePrivacy('public'); $this->setCacheLifetime(30); }