Example #1
0
 private function GetRssItems($text)
 {
     // Make sure we have the cache location configured
     Kit::ClassLoader('file');
     $file = new File($this->db);
     $file->EnsureLibraryExists();
     // Parse the text template
     $matches = '';
     preg_match_all('/\\[.*?\\]/', $text, $matches);
     Debug::LogEntry('audit', 'Loading SimplePie to handle RSS parsing');
     // Use SimplePie to get the feed
     include_once '3rdparty/simplepie/autoloader.php';
     $feed = new SimplePie();
     $feed->set_cache_location($file->GetLibraryCacheUri());
     $feed->set_feed_url(urldecode($this->GetOption('uri')));
     $feed->set_cache_duration($this->GetOption('updateInterval', 3600) * 60);
     $feed->handle_content_type();
     $feed->init();
     if ($feed->error()) {
         Debug::LogEntry('audit', 'Feed Error: ' . $feed->error());
         return array();
     }
     // Store our formatted items
     $items = array();
     foreach ($feed->get_items() as $item) {
         // Substitute for all matches in the template
         $rowString = $text;
         // Substitite
         foreach ($matches[0] as $sub) {
             $replace = '';
             // Pick the appropriate column out
             if (strstr($sub, '|') !== false) {
                 // Use the provided namespace to extract a tag
                 list($tag, $namespace) = explode('|', $sub);
                 $tags = $item->get_item_tags(str_replace(']', '', $namespace), str_replace('[', '', $tag));
                 $replace = is_array($tags) ? $tags[0]['data'] : '';
             } else {
                 // Use the pool of standard tags
                 switch ($sub) {
                     case '[Title]':
                         $replace = $item->get_title();
                         break;
                     case '[Description]':
                         $replace = $item->get_description();
                         break;
                     case '[Content]':
                         $replace = $item->get_content();
                         break;
                     case '[Copyright]':
                         $replace = $item->get_copyright();
                         break;
                     case '[Date]':
                         $replace = $item->get_local_date();
                         break;
                     case '[PermaLink]':
                         $replace = $item->get_permalink();
                         break;
                     case '[Link]':
                         $replace = $item->get_link();
                         break;
                 }
             }
             // Substitute the replacement we have found (it might be '')
             $rowString = str_replace($sub, $replace, $rowString);
         }
         $items[] = $rowString;
     }
     // Return the formatted items
     return $items;
 }
Example #2
0
 /**
  * Export a layout.
  * @param [type] $layoutId [description]
  */
 function Export($layoutId)
 {
     if ($layoutId == 0 || $layoutId == '') {
         return $this->SetError(__('Must provide layoutId'));
     }
     $config = new Config();
     if (!$config->CheckZip()) {
         return $this->SetError(__('Zip is not enabled on this server'));
     }
     $libraryPath = Config::GetSetting('LIBRARY_LOCATION');
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('
             SELECT layout, description, backgroundImageId, xml
               FROM layout
              WHERE layoutid = :layoutid');
         $sth->execute(array('layoutid' => $layoutId));
         if (!($row = $sth->fetch())) {
             $this->ThrowError(__('Layout not found.'));
         }
         // Open a ZIP file with the same name as the layout
         File::EnsureLibraryExists();
         $zip = new ZipArchive();
         $fileName = $libraryPath . 'temp/export_' . Kit::ValidateParam($row['layout'], _FILENAME) . '.zip';
         $result = $zip->open($fileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
         if ($result !== true) {
             $this->ThrowError(__('Can\'t create ZIP. Error Code: ' . $result));
         }
         // Add layout information to the ZIP
         $layout = array('layout' => Kit::ValidateParam($row['layout'], _STRING), 'description' => Kit::ValidateParam($row['description'], _STRING));
         $zip->addFromString('layout.json', json_encode($layout));
         // Add the layout XLF
         $xml = $row['xml'];
         $zip->addFromString('layout.xml', $xml);
         $params = array('layoutid' => $layoutId, 'excludeType' => 'module');
         $SQL = ' 
             SELECT media.mediaid, media.name, media.storedAs, originalFileName, type, duration
               FROM `media` 
                 INNER JOIN `lklayoutmedia`
                 ON lklayoutmedia.mediaid = media.mediaid
              WHERE lklayoutmedia.layoutid = :layoutid
                AND media.type <> :excludeType
             ';
         // Add the media to the ZIP
         $mediaSth = $dbh->prepare($SQL);
         $mediaSth->execute($params);
         $mappings = array();
         foreach ($mediaSth->fetchAll() as $media) {
             $mediaFilePath = $libraryPath . $media['storedAs'];
             $zip->addFile($mediaFilePath, 'library/' . $media['originalFileName']);
             $mappings[] = array('file' => $media['originalFileName'], 'mediaid' => $media['mediaid'], 'name' => $media['name'], 'type' => $media['type'], 'duration' => $media['duration'], 'background' => $media['mediaid'] == $row['backgroundImageId'] ? 1 : 0);
         }
         // Add the mappings file to the ZIP
         $zip->addFromString('mapping.json', json_encode($mappings));
         $zip->close();
         // Uncomment only if you are having permission issues
         // chmod($fileName, 0777);
         // Push file back to browser
         if (ini_get('zlib.output_compression')) {
             ini_set('zlib.output_compression', 'Off');
         }
         $size = filesize($fileName);
         header('Content-Type: application/octet-stream');
         header("Content-Transfer-Encoding: Binary");
         header("Content-disposition: attachment; filename=\"" . basename($fileName) . "\"");
         //Output a header
         header('Pragma: public');
         header('Cache-Control: max-age=86400');
         header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 86400));
         header('Content-Length: ' . $size);
         // Send via Apache X-Sendfile header?
         if (Config::GetSetting('SENDFILE_MODE') == 'Apache') {
             header("X-Sendfile: {$fileName}");
             exit;
         }
         // Send via Nginx X-Accel-Redirect?
         if (Config::GetSetting('SENDFILE_MODE') == 'Nginx') {
             header("X-Accel-Redirect: /download/temp/" . basename($fileName));
             exit;
         }
         // Return the file with PHP
         // Disable any buffering to prevent OOM errors.
         @ob_end_clean();
         @ob_end_flush();
         readfile($fileName);
         exit;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(1, __('Unknown Error'));
         }
         return false;
     }
 }
Example #3
0
 /**
  * End point for jQuery file uploader
  */
 public function JqueryFileUpload()
 {
     $db =& $this->db;
     require_once "3rdparty/jquery-file-upload/XiboUploadHandler.php";
     $type = Kit::GetParam('type', _REQUEST, _WORD);
     Kit::ClassLoader('file');
     $fileObject = new File($db);
     $libraryFolder = Config::GetSetting('LIBRARY_LOCATION');
     // Make sure the library exists
     $fileObject->EnsureLibraryExists();
     // Get Valid Extensions
     Kit::ClassLoader('media');
     $media = new Media($db);
     $validExt = $media->ValidExtensions($type);
     $options = array('db' => $this->db, 'user' => $this->user, 'upload_dir' => $libraryFolder . 'temp/', 'download_via_php' => true, 'script_url' => Kit::GetXiboRoot() . '?p=content&q=JqueryFileUpload', 'upload_url' => Kit::GetXiboRoot() . '?p=content&q=JqueryFileUpload', 'image_versions' => array(), 'accept_file_types' => '/\\.' . implode('|', $validExt) . '$/i');
     // Hand off to the Upload Handler provided by jquery-file-upload
     $handler = new XiboUploadHandler($options);
     // Must commit if in a transaction
     try {
         $dbh = PDOConnect::init();
         $dbh->commit();
     } catch (Exception $e) {
         Debug::LogEntry('audit', 'Unable to commit/rollBack');
     }
     // Must prevent from continuing (framework will try to issue a response)
     exit;
 }
Example #4
0
 /**
  * Submit ScreenShot
  * @param string $serverKey
  * @param string $hardwareKey
  * @param string $screenShot
  * @return bool
  * @throws SoapFault
  */
 public function SubmitScreenShot($serverKey, $hardwareKey, $screenShot)
 {
     // Sanitize
     $serverKey = Kit::ValidateParam($serverKey, _STRING);
     $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
     $screenShot = Kit::ValidateParam($screenShot, _HTMLSTRING);
     // Check the serverKey matches
     if ($serverKey != Config::GetSetting('SERVER_KEY')) {
         throw new SoapFault('Sender', 'The Server key you entered does not match with the server key at this address');
     }
     // Make sure we are sticking to our bandwidth limit
     if (!$this->CheckBandwidth()) {
         throw new SoapFault('Receiver', "Bandwidth Limit exceeded");
     }
     // Auth this request...
     if (!$this->AuthDisplay($hardwareKey)) {
         throw new SoapFault('Receiver', 'This display client is not licensed');
     }
     if ($this->isAuditing == 1) {
         Debug::Audit('Received Screen shot', $this->displayId);
     }
     // Open this displays screen shot file and save this.
     File::EnsureLibraryExists();
     $location = Config::GetSetting('LIBRARY_LOCATION') . 'screenshots/' . $this->displayId . '_screenshot.jpg';
     $fp = fopen($location, 'wb');
     fwrite($fp, $screenShot);
     fclose($fp);
     // Touch the display record
     $displayObject = new Display();
     $displayObject->Touch($this->displayId, array('screenShotRequested' => 0));
     $this->LogBandwidth($this->displayId, Bandwidth::$SCREENSHOT, filesize($location));
     return true;
 }
Example #5
0
 private function GetRssItems($isPreview, $text)
 {
     // Make sure we have the cache location configured
     $file = new File($this->db);
     File::EnsureLibraryExists();
     // Make sure we have a $media/$layout object to use
     $media = new Media();
     $layout = new Layout();
     // Parse the text template
     $matches = '';
     preg_match_all('/\\[.*?\\]/', $text, $matches);
     Debug::LogEntry('audit', 'Loading SimplePie to handle RSS parsing.' . urldecode($this->GetOption('uri')));
     // Use SimplePie to get the feed
     include_once '3rdparty/simplepie/autoloader.php';
     $feed = new SimplePie();
     $feed->set_cache_location($file->GetLibraryCacheUri());
     $feed->set_feed_url(urldecode($this->GetOption('uri')));
     $feed->force_feed(true);
     $feed->set_cache_duration($this->GetOption('updateInterval', 3600) * 60);
     $feed->handle_content_type();
     // Get a list of allowed attributes
     if ($this->GetOption('allowedAttributes') != '') {
         $attrsStrip = array_diff($feed->strip_attributes, explode(',', $this->GetOption('allowedAttributes')));
         //Debug::Audit(var_export($attrsStrip, true));
         $feed->strip_attributes($attrsStrip);
     }
     // Disable date sorting?
     if ($this->GetOption('disableDateSort') == 1) {
         $feed->enable_order_by_date(false);
     }
     // Init
     $feed->init();
     $dateFormat = $this->GetOption('dateFormat');
     if ($feed->error()) {
         Debug::LogEntry('audit', 'Feed Error: ' . $feed->error());
         return array();
     }
     // Set an expiry time for the media
     $expires = time() + $this->GetOption('updateInterval', 3600) * 60;
     // Store our formatted items
     $items = array();
     foreach ($feed->get_items() as $item) {
         /* @var SimplePie_Item $item */
         // Substitute for all matches in the template
         $rowString = $text;
         // Substitute
         foreach ($matches[0] as $sub) {
             $replace = '';
             // Pick the appropriate column out
             if (strstr($sub, '|') !== false) {
                 // Use the provided name space to extract a tag
                 $attribs = NULL;
                 if (substr_count($sub, '|') > 1) {
                     list($tag, $namespace, $attribs) = explode('|', $sub);
                 } else {
                     list($tag, $namespace) = explode('|', $sub);
                 }
                 // What are we looking at
                 Debug::Audit('Namespace: ' . str_replace(']', '', $namespace) . '. Tag: ' . str_replace('[', '', $tag) . '. ');
                 // Are we an image place holder?
                 if (strstr($namespace, 'image') != false) {
                     // Try to get a link for the image
                     $link = null;
                     switch (str_replace('[', '', $tag)) {
                         case 'Link':
                             if ($enclosure = $item->get_enclosure()) {
                                 // Use the link to get the image
                                 $link = $enclosure->get_link();
                             }
                             break;
                         default:
                             // Default behaviour just tries to get the content from the tag provided (without a name space).
                             $tags = $item->get_item_tags('', str_replace('[', '', $tag));
                             if ($tags != null) {
                                 $link = is_array($tags) ? $tags[0]['data'] : '';
                             }
                     }
                     if ($link == NULL) {
                         $dom = new DOMDocument();
                         $dom->loadHTML($item->get_content());
                         // Full
                         $images = $dom->getElementsByTagName('img');
                         foreach ($images as $key => $value) {
                             if ($key == 0) {
                                 $link = html_entity_decode($images->item($key)->getAttribute('src'));
                             }
                         }
                     }
                     if ($link == NULL) {
                         $dom = new DOMDocument();
                         $dom->loadHTML($item->get_description());
                         //Summary
                         $images = $dom->getElementsByTagName('img');
                         foreach ($images as $key => $value) {
                             if ($key == 0) {
                                 $link = html_entity_decode($images->item($key)->getAttribute('src'));
                             }
                         }
                     }
                     // If we have managed to resolve a link, download it and replace the tag with the downloaded
                     // image url
                     if ($link != NULL) {
                         // Grab the profile image
                         $file = $media->addModuleFileFromUrl($link, 'ticker_' . md5($this->GetOption('url') . $link), $expires);
                         // Tag this layout with this file
                         $layout->AddLk($this->layoutid, 'module', $file['mediaId']);
                         $replace = $isPreview ? '<img src="index.php?p=module&mod=image&q=Exec&method=GetResource&mediaid=' . $file['mediaId'] . '" ' . $attribs . '/>' : '<img src="' . $file['storedAs'] . '" ' . $attribs . ' />';
                     }
                 } else {
                     $tags = $item->get_item_tags(str_replace(']', '', $namespace), str_replace('[', '', $tag));
                     Debug::LogEntry('audit', 'Tags:' . var_export($tags, true));
                     // If we find some tags then do the business with them
                     if ($tags != NULL) {
                         if ($attribs != NULL) {
                             $replace = is_array($tags) ? $tags[0]['attribs'][''][str_replace(']', '', $attribs)] : '';
                         } else {
                             $replace = is_array($tags) ? $tags[0]['data'] : '';
                         }
                     }
                 }
             } else {
                 // Use the pool of standard tags
                 switch ($sub) {
                     case '[Name]':
                         $replace = $this->GetOption('name');
                         break;
                     case '[Title]':
                         $replace = $item->get_title();
                         break;
                     case '[Description]':
                         $replace = $item->get_description();
                         break;
                     case '[Content]':
                         $replace = $item->get_content();
                         break;
                     case '[Copyright]':
                         $replace = $item->get_copyright();
                         break;
                     case '[Date]':
                         $replace = DateManager::getLocalDate($item->get_date('U'), $dateFormat);
                         break;
                     case '[PermaLink]':
                         $replace = $item->get_permalink();
                         break;
                     case '[Link]':
                         $replace = $item->get_link();
                         break;
                 }
                 if ($this->GetOption('stripTags') != '') {
                     require_once '3rdparty/htmlpurifier/library/HTMLPurifier.auto.php';
                     $config = HTMLPurifier_Config::createDefault();
                     $config->set('HTML.ForbiddenElements', array_merge($feed->strip_htmltags, explode(',', $this->GetOption('stripTags'))));
                     $purifier = new HTMLPurifier($config);
                     $replace = $purifier->purify($replace);
                 }
             }
             // Substitute the replacement we have found (it might be '')
             $rowString = str_replace($sub, $replace, $rowString);
         }
         $items[] = $rowString;
     }
     // Copyright information?
     if ($this->GetOption('copyright', '') != '') {
         $items[] = '<span id="copyright">' . $this->GetOption('copyright') . '</span>';
     }
     // Return the formatted items
     return $items;
 }
Example #6
0
 /**
  * Saves the specified key
  * @param  string $key The key
  */
 private static function save($key)
 {
     File::EnsureLibraryExists();
     $location = Config::GetSetting('LIBRARY_LOCATION') . 'cache/cache_' . Kit::ValidateParam($key, _FILENAME);
     file_put_contents($location, serialize(self::$_data[$key]));
 }
Example #7
0
 /**
  * Writes the file to disk
  * @param <type> $fileId
  * @param <type> $payload
  */
 public function WriteToDisk($fileId, $payload)
 {
     try {
         $dbh = PDOConnect::init();
         // Directory location
         $libraryFolder = Config::GetSetting('LIBRARY_LOCATION');
         $libraryFolder = $libraryFolder . 'temp';
         if (!File::EnsureLibraryExists($libraryFolder)) {
             return false;
         }
         // Open a file pointer
         if (!($fp = fopen($libraryFolder . '/' . $fileId, 'a'))) {
             $this->ThrowError(5);
         }
         // Write the payload to the file handle.
         if (fwrite($fp, $payload) === false) {
             $this->ThrowError(6);
         }
         // Close the file pointer
         fclose($fp);
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(1, __('Unknown Error'));
         }
         return false;
     }
 }
 function displayPage()
 {
     // Set up some suffixes
     $suffixes = array('bytes', 'k', 'M', 'G', 'T');
     // Get some data for a bandwidth chart
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('SELECT FROM_UNIXTIME(month) AS month, IFNULL(SUM(Size), 0) AS size FROM `bandwidth` WHERE month > :month GROUP BY FROM_UNIXTIME(month) ORDER BY MIN(month);');
         $sth->execute(array('month' => time() - 86400 * 365));
         $results = $sth->fetchAll();
         // Monthly bandwidth - optionally tested against limits
         $xmdsLimit = Config::GetSetting('MONTHLY_XMDS_TRANSFER_LIMIT_KB');
         $maxSize = 0;
         foreach ($results as $row) {
             $maxSize = $row['size'] > $maxSize ? $row['size'] : $maxSize;
         }
         // Decide what our units are going to be, based on the size
         $base = $maxSize == 0 ? 0 : floor(log($maxSize) / log(1024));
         if ($xmdsLimit > 0) {
             // Convert to appropriate size (xmds limit is in KB)
             $xmdsLimit = $xmdsLimit * 1024 / pow(1024, $base);
             Theme::Set('xmdsLimit', $xmdsLimit . ' ' . $suffixes[$base]);
         }
         $output = array();
         foreach ($results as $row) {
             $size = (double) $row['size'] / pow(1024, $base);
             $remaining = $xmdsLimit - $size;
             $output[] = array('label' => DateManager::getLocalDate(DateManager::getDateFromGregorianString($row['month']), 'F'), 'value' => round($size, 2), 'limit' => round($remaining, 2));
         }
         // What if we are empty?
         if (count($output) == 0) {
             $output[] = array('label' => DateManager::getLocalDate(null, 'F'), 'value' => 0, 'limit' => 0);
         }
         // Set the data
         Theme::Set('xmdsLimitSet', $xmdsLimit > 0);
         Theme::Set('bandwidthSuffix', $suffixes[$base]);
         Theme::Set('bandwidthWidget', json_encode($output));
         // We would also like a library usage pie chart!
         $libraryLimit = Config::GetSetting('LIBRARY_SIZE_LIMIT_KB');
         $libraryLimit = $libraryLimit * 1024;
         // Library Size in Bytes
         $sth = $dbh->prepare('SELECT IFNULL(SUM(FileSize), 0) AS SumSize, type FROM media GROUP BY type;');
         $sth->execute();
         $results = $sth->fetchAll();
         // Do we base the units on the maximum size or the library limit
         $maxSize = 0;
         if ($libraryLimit > 0) {
             $maxSize = $libraryLimit;
         } else {
             // Find the maximum sized chunk of the items in the library
             foreach ($results as $library) {
                 $maxSize = $library['SumSize'] > $maxSize ? $library['SumSize'] : $maxSize;
             }
         }
         // Decide what our units are going to be, based on the size
         $base = $maxSize == 0 ? 0 : floor(log($maxSize) / log(1024));
         $output = array();
         $totalSize = 0;
         foreach ($results as $library) {
             $output[] = array('value' => round((double) $library['SumSize'] / pow(1024, $base), 2), 'label' => ucfirst($library['type']));
             $totalSize = $totalSize + $library['SumSize'];
         }
         // Do we need to add the library remaining?
         if ($libraryLimit > 0) {
             $remaining = round(($libraryLimit - $totalSize) / pow(1024, $base), 2);
             $output[] = array('value' => $remaining, 'label' => __('Free'));
         }
         // What if we are empty?
         if (count($output) == 0) {
             $output[] = array('label' => __('Empty'), 'value' => 0);
         }
         Theme::Set('libraryLimitSet', $libraryLimit);
         Theme::Set('libraryLimit', round((double) $libraryLimit / pow(1024, $base), 2) . ' ' . $suffixes[$base]);
         Theme::Set('librarySize', Kit::formatBytes($totalSize, 1));
         Theme::Set('librarySuffix', $suffixes[$base]);
         Theme::Set('libraryWidget', json_encode($output));
         // Also a display widget
         $sort_order = array('display');
         $displays = $this->user->DisplayList($sort_order);
         $rows = array();
         if (is_array($displays) && count($displays) > 0) {
             // Output a table showing the displays
             foreach ($displays as $row) {
                 $row['mediainventorystatus'] = $row['mediainventorystatus'] == 1 ? 'success' : ($row['mediainventorystatus'] == 2 ? 'danger' : 'warning');
                 // Assign this to the table row
                 $rows[] = $row;
             }
         }
         Theme::Set('display-widget-rows', $rows);
         // Get a count of users
         $sth = $dbh->prepare('SELECT IFNULL(COUNT(*), 0) AS count_users FROM `user`');
         $sth->execute();
         Theme::Set('countUsers', $sth->fetchColumn(0));
         // Get a count of active layouts
         $sth = $dbh->prepare('SELECT IFNULL(COUNT(*), 0) AS count_scheduled FROM `schedule_detail` WHERE :now BETWEEN FromDT AND ToDT');
         $sth->execute(array('now' => time()));
         Theme::Set('nowShowing', $sth->fetchColumn(0));
         // Latest news
         if (Config::GetSetting('DASHBOARD_LATEST_NEWS_ENABLED') == 1) {
             // Make sure we have the cache location configured
             Kit::ClassLoader('file');
             $file = new File($this->db);
             File::EnsureLibraryExists();
             // Use SimplePie to get the feed
             include_once '3rdparty/simplepie/autoloader.php';
             $feed = new SimplePie();
             $feed->set_cache_location($file->GetLibraryCacheUri());
             $feed->set_feed_url(Theme::GetConfig('latest_news_url'));
             $feed->set_cache_duration(86400);
             $feed->handle_content_type();
             $feed->init();
             $latestNews = array();
             if ($feed->error()) {
                 Debug::LogEntry('audit', 'Feed Error: ' . $feed->error(), get_class(), __FUNCTION__);
             } else {
                 // Store our formatted items
                 foreach ($feed->get_items() as $item) {
                     $latestNews[] = array('title' => $item->get_title(), 'description' => $item->get_description(), 'link' => $item->get_link());
                 }
             }
             Theme::Set('latestNews', $latestNews);
         } else {
             Theme::Set('latestNews', array(array('title' => __('Latest news not enabled.'), 'description' => '', 'link' => '')));
         }
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         // Show the error in place of the bandwidth chart
         Theme::Set('widget-error', 'Unable to get widget details');
     }
     // Do we have an embedded widget?
     Theme::Set('embedded-widget', html_entity_decode(Config::GetSetting('EMBEDDED_STATUS_WIDGET')));
     // Render the Theme and output
     Theme::Render('status_dashboard');
 }