require_once 'install/upgradestep.class.php'; $page = 'upgrade'; if (Kit::GetParam('includes', _POST, _BOOL)) { $upgradeFrom = Kit::GetParam('upgradeFrom', _POST, _INT); $upgradeTo = Kit::GetParam('upgradeTo', _POST, _INT); for ($i = $upgradeFrom + 1; $i <= $upgradeTo; $i++) { if (file_exists('install/database/' . $i . '.php')) { include_once 'install/database/' . $i . '.php'; } } } } // Create a Session $session = new Session(); // Work out the location of this service $serviceLocation = Kit::GetXiboRoot(); // OAuth require_once 'lib/oauth.inc.php'; // Assign the page name to the session $session->set_page(session_id(), $page); // Create a user $user = new User($db); // Create Page try { $pageManager = new PageManager($db, $user, $page); $pageManager->Authenticate(); $pageManager->Render(); } catch (Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } die;
private function InstallFonts() { $media = new Media(); $fontTemplate = ' @font-face { font-family: \'[family]\'; src: url(\'[url]\'); } '; // Save a fonts.css file to the library for use as a module try { $dbh = PDOConnect::init(); $sth = $dbh->prepare('SELECT mediaID, name, storedAs FROM `media` WHERE type = :type AND IsEdited = 0 ORDER BY name'); $sth->execute(array('type' => 'font')); $fonts = $sth->fetchAll(); if (count($fonts) < 1) { return; } $css = ''; $localCss = ''; $ckeditorString = ''; foreach ($fonts as $font) { // Separate out the display name and the referenced name (referenced name cannot contain any odd characters or numbers) $displayName = $font['name']; $familyName = preg_replace('/\\s+/', ' ', preg_replace('/\\d+/u', '', $font['name'])); // Css for the client contains the actual stored as location of the font. $css .= str_replace('[url]', $font['storedAs'], str_replace('[family]', $displayName, $fontTemplate)); // Css for the local CMS contains the full download path to the font $relativeRoot = explode('://', Kit::GetXiboRoot()); $url = '//' . $relativeRoot[1] . '?p=module&mod=font&q=Exec&method=GetResource&download=1&downloadFromLibrary=1&mediaid=' . $font['mediaID']; $localCss .= str_replace('[url]', $url, str_replace('[family]', $familyName, $fontTemplate)); // CKEditor string $ckeditorString .= $displayName . '/' . $familyName . ';'; } file_put_contents('modules/preview/fonts.css', $css); // Install it (doesn't expire, is a system file, force update) $media->addModuleFile('modules/preview/fonts.css', 0, true, true); // Generate a fonts.css file for use locally (in the CMS) file_put_contents('modules/preview/fonts.css', $localCss); // Edit the CKEditor file $ckeditor = file_get_contents('theme/default/libraries/ckeditor/config.js'); $replace = "/*REPLACE*/ config.font_names = '" . $ckeditorString . "' + config.font_names; /*ENDREPLACE*/"; $ckeditor = preg_replace('/\\/\\*REPLACE\\*\\/.*?\\/\\*ENDREPLACE\\*\\//', $replace, $ckeditor); file_put_contents('theme/default/libraries/ckeditor/config.js', $ckeditor); } catch (Exception $e) { Debug::LogEntry('error', $e->getMessage(), get_class(), __FUNCTION__); if (!$this->IsError()) { $this->SetError(1, __('Unknown Error')); } return false; } }
/** * 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; }
public function __construct() { $this->serviceLocation = Kit::GetXiboRoot(); }
/** * Returns a string containing the required files xml for the requesting display * @param string $serverKey The Server Key * @param string $hardwareKey Display Hardware Key * @return string $requiredXml Xml Formatted String * @throws SoapFault */ function RequiredFiles($serverKey, $hardwareKey) { // Sanitize $serverKey = Kit::ValidateParam($serverKey, _STRING); $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING); $rfLookAhead = Kit::ValidateParam(Config::GetSetting('REQUIRED_FILES_LOOKAHEAD'), _INT); // 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'); } $libraryLocation = Config::GetSetting("LIBRARY_LOCATION"); // auth this request... if (!$this->AuthDisplay($hardwareKey)) { throw new SoapFault('Sender', 'This display is not licensed.'); } if ($this->isAuditing == 1) { Debug::Audit('hardwareKey = ' . $hardwareKey, $this->displayId); } // Remove all Nonces for this display $nonce = new Nonce(); $nonce->RemoveAllXmdsNonce($this->displayId); // Build a new RF $requiredFilesXml = new DOMDocument("1.0"); $fileElements = $requiredFilesXml->createElement("files"); $requiredFilesXml->appendChild($fileElements); // Hour to hour time bands for the query // Start at the current hour $fromFilter = time(); // Move forwards an hour and the rf look ahead $rfLookAhead = $fromFilter + 3600 + $rfLookAhead; // Dial both items back to the top of the hour $fromFilter = $fromFilter - $fromFilter % 3600; $toFilter = $rfLookAhead - $rfLookAhead % 3600; if ($this->isAuditing == 1) { Debug::Audit(sprintf('Required files date criteria. FromDT = %s. ToDt = %s', date('Y-m-d h:i:s', $fromFilter), date('Y-m-d h:i:s', $toFilter)), $this->displayId); } try { $dbh = PDOConnect::init(); // Get a list of all layout ids in the schedule right now. $SQL = " SELECT DISTINCT layout.layoutID "; $SQL .= " FROM `campaign` "; $SQL .= " INNER JOIN schedule ON schedule.CampaignID = campaign.CampaignID "; $SQL .= " INNER JOIN schedule_detail ON schedule_detail.eventID = schedule.eventID "; $SQL .= " INNER JOIN `lkcampaignlayout` ON lkcampaignlayout.CampaignID = campaign.CampaignID "; $SQL .= " INNER JOIN `layout` ON lkcampaignlayout.LayoutID = layout.LayoutID "; $SQL .= " INNER JOIN lkdisplaydg ON lkdisplaydg.DisplayGroupID = schedule_detail.DisplayGroupID "; $SQL .= " WHERE lkdisplaydg.DisplayID = :displayId "; $SQL .= " AND schedule_detail.FromDT < :fromdt AND schedule_detail.ToDT > :todt "; $SQL .= " AND layout.retired = 0 "; $sth = $dbh->prepare($SQL); $sth->execute(array('displayId' => $this->displayId, 'fromdt' => $toFilter, 'todt' => $fromFilter)); // Our layout list will always include the default layout $layouts = array(); $layouts[] = $this->defaultLayoutId; // Build up the other layouts into an array foreach ($sth->fetchAll() as $row) { $layouts[] = Kit::ValidateParam($row['layoutID'], _INT); } } catch (Exception $e) { Debug::Error('Error getting layout listing. ' . $e->getMessage(), $this->displayId); return new SoapFault('Sender', 'Unable to get a list of layouts'); } // Create a comma separated list to pass into the query which gets file nodes $layoutIdList = implode(',', $layouts); try { $dbh = PDOConnect::init(); // Add file nodes to the $fileElements $SQL = "\n SELECT 1 AS DownloadOrder, 'media' AS RecordType, storedAs AS path, media.mediaID AS id, media.`MD5`, media.FileSize, NULL AS xml\n FROM `media`\n WHERE media.type = 'font'\n OR (media.type = 'module' AND media.moduleSystemFile = 1)\n UNION\n "; $SQL .= " SELECT 4 AS DownloadOrder, 'layout' AS RecordType, layout.layoutID AS path, layout.layoutID AS id, MD5(layout.xml) AS `MD5`, NULL AS FileSize, layout.xml AS xml "; $SQL .= " FROM layout "; $SQL .= sprintf(" WHERE layout.layoutid IN (%s) ", $layoutIdList); $SQL .= " UNION "; $SQL .= " SELECT 3 AS DownloadOrder, 'media' AS RecordType, storedAs AS path, media.mediaID AS id, media.`MD5`, media.FileSize, NULL AS xml "; $SQL .= " FROM media "; $SQL .= " INNER JOIN lklayoutmedia "; $SQL .= " ON lklayoutmedia.MediaID = media.MediaID "; $SQL .= " INNER JOIN layout "; $SQL .= " ON layout.LayoutID = lklayoutmedia.LayoutID"; $SQL .= sprintf(" WHERE layout.layoutid IN (%s) ", $layoutIdList); $SQL .= "\n UNION\n SELECT 2 AS DownloadOrder, 'media' AS RecordType, storedAs AS path, media.mediaID AS id, media.`MD5`, media.FileSize, NULL AS xml\n FROM `media`\n INNER JOIN `lkmediadisplaygroup`\n ON lkmediadisplaygroup.mediaid = media.MediaID\n INNER JOIN lkdisplaydg\n ON lkdisplaydg.DisplayGroupID = lkmediadisplaygroup.DisplayGroupID\n "; $SQL .= " WHERE lkdisplaydg.DisplayID = :displayId "; $SQL .= " ORDER BY DownloadOrder, RecordType DESC"; $sth = $dbh->prepare($SQL); $sth->execute(array('displayId' => $this->displayId)); // Prepare a SQL statement in case we need to update the MD5 and FileSize on media nodes. $mediaSth = $dbh->prepare('UPDATE media SET `MD5` = :md5, FileSize = :size WHERE MediaID = :mediaid'); // What is the send file mode? $sendFileMode = Config::GetSetting('SENDFILE_MODE'); // Keep a list of path names added to RF to prevent duplicates $pathsAdded = array(); foreach ($sth->fetchAll() as $row) { $recordType = Kit::ValidateParam($row['RecordType'], _WORD); $path = Kit::ValidateParam($row['path'], _STRING); $id = Kit::ValidateParam($row['id'], _STRING); $md5 = Kit::ValidateParam($row['MD5'], _HTMLSTRING); $fileSize = Kit::ValidateParam($row['FileSize'], _INT); $xml = Kit::ValidateParam($row['xml'], _HTMLSTRING); $mediaNonce = ''; if ($recordType == 'layout') { // Check we haven't added this before if (in_array('layout_' . $id, $pathsAdded)) { continue; } // For layouts the MD5 column is the layout xml $fileSize = strlen($xml); if ($this->isAuditing == 1) { Debug::Audit('MD5 for layoutId ' . $id . ' is: [' . $md5 . ']', $this->displayId); } // Add nonce $nonce->AddXmdsNonce('layout', $this->displayId, NULL, $fileSize, NULL, $id); $pathsAdded[] = 'layout_' . $id; } else { if ($recordType == 'media') { // Check we haven't added this before if (in_array('media_' . $path, $pathsAdded)) { continue; } // If they are empty calculate them and save them back to the media. if ($md5 == '' || $fileSize == 0) { $md5 = md5_file($libraryLocation . $path); $fileSize = filesize($libraryLocation . $path); // Update the media record with this information $mediaSth->execute(array('md5' => $md5, 'size' => $fileSize, 'mediaid' => $id)); } // Add nonce $mediaNonce = $nonce->AddXmdsNonce('file', $this->displayId, $id, $fileSize, $path); $pathsAdded[] = 'media_' . $path; } else { continue; } } // Add the file node $file = $requiredFilesXml->createElement("file"); $file->setAttribute("type", $recordType); $file->setAttribute("id", $id); $file->setAttribute("size", $fileSize); $file->setAttribute("md5", $md5); if ($recordType == 'media' && $sendFileMode != 'Off') { // Serve a link instead (standard HTTP link) $file->setAttribute("path", Kit::GetXiboRoot() . '?file=' . $mediaNonce); $file->setAttribute("saveAs", $path); $file->setAttribute("download", 'http'); } else { $file->setAttribute("download", 'xmds'); $file->setAttribute("path", $path); } $fileElements->appendChild($file); } } catch (Exception $e) { Debug::Error('Unable to get a list of required files. ' . $e->getMessage(), $this->displayId); return new SoapFault('Sender', 'Unable to get a list of files'); } // Go through each layout and see if we need to supply any resource nodes. foreach ($layouts as $layoutId) { // Load the layout XML and work out if we have any ticker / text / data set media items $layout = new Layout(); $layoutInformation = $layout->LayoutInformation($layoutId); foreach ($layoutInformation['regions'] as $region) { foreach ($region['media'] as $media) { if ($media['render'] == 'html' || $media['mediatype'] == 'ticker' || $media['mediatype'] == 'text' || $media['mediatype'] == 'datasetview' || $media['mediatype'] == 'webpage' || $media['mediatype'] == 'embedded') { // Append this item to required files $file = $requiredFilesXml->createElement("file"); $file->setAttribute('type', 'resource'); $file->setAttribute('id', rand()); $file->setAttribute('layoutid', $layoutId); $file->setAttribute('regionid', $region['regionid']); $file->setAttribute('mediaid', $media['mediaid']); $file->setAttribute('updated', isset($media['updated']) ? $media['updated'] : 0); $fileElements->appendChild($file); $nonce->AddXmdsNonce('resource', $this->displayId, NULL, NULL, NULL, $layoutId, $region['regionid'], $media['mediaid']); } } } } // Add a blacklist node $blackList = $requiredFilesXml->createElement("file"); $blackList->setAttribute("type", "blacklist"); $fileElements->appendChild($blackList); try { $dbh = PDOConnect::init(); $sth = $dbh->prepare('SELECT MediaID FROM blacklist WHERE DisplayID = :displayid AND isIgnored = 0'); $sth->execute(array('displayid' => $this->displayId)); // Add a black list element for each file foreach ($sth->fetchAll() as $row) { $file = $requiredFilesXml->createElement("file"); $file->setAttribute("id", $row['MediaID']); $blackList->appendChild($file); } } catch (Exception $e) { Debug::Error('Unable to get a list of blacklisted files. ' . $e->getMessage(), $this->displayId); return new SoapFault('Sender', 'Unable to get a list of blacklisted files'); } // Phone Home? $this->PhoneHome(); if ($this->isAuditing == 1) { Debug::Audit($requiredFilesXml->saveXML(), $this->displayId); } // Return the results of requiredFiles() $requiredFilesXml->formatOutput = true; $output = $requiredFilesXml->saveXML(); // Log Bandwidth $this->LogBandwidth($this->displayId, Bandwidth::$RF, strlen($output)); return $output; }