Example #1
0
 /**
  * Gets additional resources for assigned media
  * @param string $serverKey
  * @param string $hardwareKey
  * @param int $layoutId
  * @param string $regionId
  * @param string $mediaId
  * @return mixed
  * @throws SoapFault
  */
 function GetResource($serverKey, $hardwareKey, $layoutId, $regionId, $mediaId)
 {
     // Sanitize
     $serverKey = Kit::ValidateParam($serverKey, _STRING);
     $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
     $layoutId = Kit::ValidateParam($layoutId, _INT);
     $regionId = Kit::ValidateParam($regionId, _STRING);
     $mediaId = Kit::ValidateParam($mediaId, _STRING);
     // 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");
     }
     // Validate the nonce
     $nonce = new Nonce();
     if (!$nonce->AllowedFile('resource', $this->displayId, NULL, $layoutId, $regionId, $mediaId)) {
         throw new SoapFault('Receiver', 'Requested an invalid file.');
     }
     // What type of module is this?
     $region = new region();
     $type = $region->GetMediaNodeType($layoutId, $regionId, $mediaId);
     if ($type == '') {
         throw new SoapFault('Receiver', 'Unable to get the media node type');
     }
     // Dummy User Object
     $user = new User();
     $user->userid = 0;
     $user->usertypeid = 1;
     // Initialise the theme (for global styles in GetResource)
     new Theme($user);
     Theme::SetPagename('module');
     // Get the resource from the module
     try {
         $module = ModuleFactory::load($type, $layoutId, $regionId, $mediaId, null, null, $user);
     } catch (Exception $e) {
         Debug::Error($e->getMessage(), $this->displayId);
         throw new SoapFault('Receiver', 'Cannot create module. Check CMS Log');
     }
     $resource = $module->GetResource($this->displayId);
     if (!$resource || $resource == '') {
         throw new SoapFault('Receiver', 'Unable to get the media resource');
     }
     // Log Bandwidth
     $this->LogBandwidth($this->displayId, Bandwidth::$GETRESOURCE, strlen($resource));
     return $resource;
 }
Example #2
0
 /**
  * Replace media in all layouts.
  * @param <type> $oldMediaId
  * @param <type> $newMediaId
  */
 private function ReplaceMediaInAllLayouts($replaceInLayouts, $replaceBackgroundImages, $oldMediaId, $newMediaId)
 {
     $count = 0;
     Debug::LogEntry('audit', sprintf('Replacing mediaid %s with mediaid %s in all layouts', $oldMediaId, $newMediaId), 'module', 'ReplaceMediaInAllLayouts');
     try {
         $dbh = PDOConnect::init();
         // Some update statements to use
         $sth = $dbh->prepare('SELECT lklayoutmediaid, regionid FROM lklayoutmedia WHERE mediaid = :media_id AND layoutid = :layout_id');
         $sth_update = $dbh->prepare('UPDATE lklayoutmedia SET mediaid = :media_id WHERE lklayoutmediaid = :lklayoutmediaid');
         // Loop through a list of layouts this user has access to
         foreach ($this->user->LayoutList() as $layout) {
             $layoutId = $layout['layoutid'];
             // Does this layout use the old media id?
             $sth->execute(array('media_id' => $oldMediaId, 'layout_id' => $layoutId));
             $results = $sth->fetchAll();
             if (count($results) <= 0) {
                 continue;
             }
             Debug::LogEntry('audit', sprintf('%d linked media items for layoutid %d', count($results), $layoutId), 'module', 'ReplaceMediaInAllLayouts');
             // Create a region object for later use (new one each time)
             $layout = new Layout();
             $region = new region($this->db);
             // Loop through each media link for this layout
             foreach ($results as $row) {
                 // Get the LKID of the link between this layout and this media.. could be more than one?
                 $lkId = $row['lklayoutmediaid'];
                 $regionId = $row['regionid'];
                 if ($regionId == 'background') {
                     Debug::Audit('Replacing background image');
                     if (!$replaceBackgroundImages) {
                         continue;
                     }
                     // Straight swap this background image node.
                     if (!$layout->EditBackgroundImage($layoutId, $newMediaId)) {
                         return false;
                     }
                 } else {
                     if (!$replaceInLayouts) {
                         continue;
                     }
                     // Get the Type of this media
                     if (!($type = $region->GetMediaNodeType($layoutId, '', '', $lkId))) {
                         continue;
                     }
                     // Create a new media node use it to swap the nodes over
                     Debug::LogEntry('audit', 'Creating new module with MediaID: ' . $newMediaId . ' LayoutID: ' . $layoutId . ' and RegionID: ' . $regionId, 'region', 'ReplaceMediaInAllLayouts');
                     try {
                         $module = ModuleFactory::createForMedia($type, $newMediaId, $this->db, $this->user);
                     } catch (Exception $e) {
                         Debug::Error($e->getMessage());
                         return false;
                     }
                     // Sets the URI field
                     if (!$module->SetRegionInformation($layoutId, $regionId)) {
                         return false;
                     }
                     // Get the media xml string to use in the swap.
                     $mediaXmlString = $module->AsXml();
                     // Swap the nodes
                     if (!$region->SwapMedia($layoutId, $regionId, $lkId, $oldMediaId, $newMediaId, $mediaXmlString)) {
                         return false;
                     }
                 }
                 // Update the LKID with the new media id
                 $sth_update->execute(array('media_id' => $newMediaId, 'lklayoutmediaid' => $row['lklayoutmediaid']));
                 $count++;
             }
         }
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(1, __('Unknown Error'));
         }
         return false;
     }
     Debug::LogEntry('audit', sprintf('Replaced media in %d layouts', $count), 'module', 'ReplaceMediaInAllLayouts');
 }
Example #3
0
 /**
  * Gets additional resources for assigned media
  * @param <type> $serverKey
  * @param <type> $hardwareKey
  * @param <type> $layoutId
  * @param <type> $regionId
  * @param <type> $mediaId
  * @param <type> $version
  */
 function GetResource($serverKey, $hardwareKey, $layoutId, $regionId, $mediaId, $version)
 {
     $db =& $this->db;
     // Sanitize
     $serverKey = Kit::ValidateParam($serverKey, _STRING);
     $hardwareKey = Kit::ValidateParam($hardwareKey, _STRING);
     $layoutId = Kit::ValidateParam($layoutId, _INT);
     $regionId = Kit::ValidateParam($regionId, _STRING);
     $mediaId = Kit::ValidateParam($mediaId, _STRING);
     $version = Kit::ValidateParam($version, _STRING);
     // Make sure we are talking the same language
     if (!$this->CheckVersion($version)) {
         throw new SoapFault('Receiver', "Your client is not of the correct version for communication with this server.");
     }
     // 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");
     }
     // What type of module is this?
     Kit::ClassLoader('region');
     $region = new region($db);
     $type = $region->GetMediaNodeType($layoutId, $regionId, $mediaId);
     if ($type == '') {
         throw new SoapFault('Receiver', 'Unable to get the media node type');
     }
     // Dummy User Object
     $user = new User($db);
     $user->userid = 0;
     $user->usertypeid = 1;
     // Get the resource from the module
     require_once 'modules/' . $type . '.module.php';
     if (!($module = new $type($db, $user, $mediaId, $layoutId, $regionId))) {
         throw new SoapFault('Receiver', 'Cannot create module. Check CMS Log');
     }
     $resource = $module->GetResource($this->displayId);
     if (!$resource || $resource == '') {
         throw new SoapFault('Receiver', 'Unable to get the media resource');
     }
     // Log Bandwidth
     $this->LogBandwidth($this->displayId, 5, strlen($resource));
     return $resource;
 }