コード例 #1
0
ファイル: module.class.php プロジェクト: fignew/xibo-cms
 /**
  * Module constructor.
  * @param $db database
  * @param $user user
  */
 function __construct(database $db, user $user)
 {
     $this->db =& $db;
     $this->user =& $user;
     $mod = Kit::GetParam('mod', _REQUEST, _WORD);
     // If we have the module - create an instance of the module class
     // This will only be true when we are displaying the Forms
     if ($mod != '') {
         // Try to get the layout, region and media id's
         $layoutId = Kit::GetParam('layoutid', _REQUEST, _INT);
         $regionId = Kit::GetParam('regionid', _REQUEST, _STRING);
         $mediaId = Kit::GetParam('mediaid', _REQUEST, _STRING);
         $lkId = Kit::GetParam('lkid', _REQUEST, _INT);
         Debug::LogEntry('audit', 'Creating new module with MediaID: ' . $mediaId . ' LayoutID: ' . $layoutId . ' and RegionID: ' . $regionId);
         try {
             $this->module = ModuleFactory::load($mod, $layoutId, $regionId, $mediaId, $lkId, $this->db, $this->user);
         } catch (Exception $e) {
             trigger_error($e->getMessage(), E_USER_ERROR);
         }
     }
     return true;
 }
コード例 #2
0
ファイル: rest.class.php プロジェクト: fignew/xibo-cms
 /**
  * Delete media from a region
  * @return <XiboAPIResponse>
  */
 public function LayoutRegionMediaDelete()
 {
     if (!$this->user->PageAuth('layout')) {
         return $this->Error(1, 'Access Denied');
     }
     $layoutId = $this->GetParam('layoutId', _INT);
     $regionId = $this->GetParam('regionId', _STRING);
     $mediaId = $this->GetParam('mediaId', _STRING);
     $lkId = $this->GetParam('lkId', _INT);
     // Does the user have permissions to view this region?
     if (!$this->user->LayoutAuth($layoutId)) {
         return $this->Error(1, 'Access Denied');
     }
     // Check the user has permission
     Kit::ClassLoader('region');
     $region = new region();
     $ownerId = $region->GetOwnerId($layoutId, $regionId);
     $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $layoutId, $regionId, true);
     if (!$regionAuth->edit) {
         return $this->Error(1, 'Access Denied');
     }
     // Load the media information from the provided ids
     // Get the type from this media
     $entry = Media::Entries(null, array('mediaId' => $mediaId));
     if (count($entry) <= 0) {
         return $this->SetError(__('Error getting type from a media item.'));
     }
     // Create a module
     try {
         $module = ModuleFactory::load($entry[0]->mediaType, $layoutId, $regionId, $mediaId, $lkId, null, $this->user);
     } catch (Exception $e) {
         return $this->Error($e->getMessage());
     }
     if (!$module->auth->del) {
         return $this->Error(1, 'Access Denied');
     }
     // Delete the assignment from the region
     if (!$module->ApiDeleteRegionMedia($layoutId, $regionId, $mediaId)) {
         return $this->Error($module->errorMessage);
     }
     return $this->Respond($this->ReturnId('success', true));
 }
コード例 #3
0
ファイル: xmdssoap4.class.php プロジェクト: rovak73/xibo-cms
 /**
  * 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;
 }
コード例 #4
0
 /**
  * Upgrade a Layout between schema versions
  * @param int $layoutId
  * @param int $resolutionId
  * @param int $scaleContent
  * @return bool
  */
 public function upgrade($layoutId, $resolutionId, $scaleContent)
 {
     // Get the Layout XML
     $this->SetDomXml($layoutId);
     // Get the Schema Versions
     $layoutVersion = (int) $this->DomXml->documentElement->getAttribute('schemaVersion');
     $width = (int) $this->DomXml->documentElement->getAttribute('width');
     $height = (int) $this->DomXml->documentElement->getAttribute('height');
     $color = $this->DomXml->documentElement->getAttribute('bgcolor');
     $version = Config::Version('XlfVersion');
     // Get some more info about the layout
     try {
         $dbh = PDOConnect::init();
         $sth = $dbh->prepare('SELECT backgroundImageId FROM `layout` WHERE layoutId = :layoutId');
         $sth->execute(array('layoutId' => $layoutId));
         // Look up the bg image from the media id given
         if (!($row = $sth->fetch())) {
             $this->ThrowError(__('Unable to get the Layout information'));
         }
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(1, __('Unknown Error'));
         }
         return false;
     }
     Debug::Audit('Updating layoutId: ' . $layoutId . ' from version: ' . $layoutVersion . ' to: ' . $version);
     // Upgrade
     $this->delayFinalise = true;
     // Set the background
     $this->SetBackground($layoutId, $resolutionId, $color, $row['backgroundImageId']);
     // Get the Layout XML again (now that we have set the background)
     $this->SetDomXml($layoutId);
     // Get the Width and Height back out
     $updatedWidth = (int) $this->DomXml->documentElement->getAttribute('width');
     $updatedHeight = (int) $this->DomXml->documentElement->getAttribute('height');
     // Work out the ratio
     $ratio = min($updatedWidth / $width, $updatedHeight / $height);
     // Get all the regions.
     foreach ($this->GetRegionList($layoutId) as $region) {
         // New region object each time, because the region stores the layout xml
         $regionObject = new Region();
         $regionObject->delayFinalise = $this->delayFinalise;
         // Work out a new width and height
         $newWidth = $region['width'] * $ratio;
         $newHeight = $region['height'] * $ratio;
         $newTop = $region['top'] * $ratio;
         $newLeft = $region['left'] * $ratio;
         $regionObject->EditRegion($layoutId, $region['regionid'], $newWidth, $newHeight, $newTop, $newLeft, $region['name']);
         if ($scaleContent == 1) {
             Debug::Audit('Updating the scale of media in regionId ' . $region['regionid']);
             // Also update the width, height and font-size on each media item
             foreach ($regionObject->GetMediaNodeList($layoutId, $region['regionid']) as $mediaNode) {
                 // Run some regular expressions over each, to adjust the values by the ratio we have calculated.
                 // widths
                 $mediaId = $mediaNode->getAttribute('id');
                 $lkId = $mediaNode->getAttribute('lkid');
                 $mediaType = $mediaNode->getAttribute('type');
                 // Create a media module to handle all the complex stuff
                 $tmpModule = ModuleFactory::load($mediaType, $layoutId, $region['regionid'], $mediaId, $lkId);
                 // Get the XML
                 $mediaXml = $tmpModule->asXml();
                 // Replace widths
                 $mediaXml = preg_replace_callback('/width:(.*?)/', function ($matches) use($ratio) {
                     return "width:" . $matches[1] * $ratio;
                 }, $mediaXml);
                 // Replace heights
                 $mediaXml = preg_replace_callback('/height:(.*?)/', function ($matches) use($ratio) {
                     return "height:" . $matches[1] * $ratio;
                 }, $mediaXml);
                 // Replace fonts
                 $mediaXml = preg_replace_callback('/font-size:(.*?)px;/', function ($matches) use($ratio) {
                     return "font-size:" . $matches[1] * $ratio . "px;";
                 }, $mediaXml);
                 // Save this new XML
                 $tmpModule->SetMediaXml($mediaXml);
             }
         }
     }
     $this->delayFinalise = false;
     $this->SetValid($layoutId);
     return true;
 }
コード例 #5
0
ファイル: timeline.class.php プロジェクト: fignew/xibo-cms
 public function TimelineGridView()
 {
     $user =& $this->user;
     $response = new ResponseManager();
     $layoutId = Kit::GetParam('layoutid', _POST, _INT);
     $regionId = Kit::GetParam('regionid', _POST, _STRING);
     // Make sure we have permission to edit this region
     Kit::ClassLoader('region');
     $region = new Region();
     $ownerId = $region->GetOwnerId($layoutId, $regionId);
     $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $layoutId, $regionId, true);
     if (!$regionAuth->edit) {
         trigger_error(__('You do not have permissions to edit this region'), E_USER_ERROR);
     }
     // Load the XML for this layout and region, we need to get the media nodes.
     $region = new Region();
     $cols = array(array('name' => 'order', 'title' => __('Order')), array('name' => 'name', 'title' => __('Name')), array('name' => 'type', 'title' => __('Type')), array('name' => 'duration', 'title' => __('Duration')), array('name' => 'transition', 'title' => __('Transition')));
     Theme::Set('table_cols', $cols);
     $rows = array();
     $i = 0;
     foreach ($region->GetMediaNodeList($layoutId, $regionId) as $mediaNode) {
         // Construct an object containing all the layouts, and pass to the theme
         $row = array();
         // Put this node vertically in the region time line
         $mediaId = $mediaNode->getAttribute('id');
         $lkId = $mediaNode->getAttribute('lkid');
         $mediaType = $mediaNode->getAttribute('type');
         $mediaDuration = $mediaNode->getAttribute('duration');
         $ownerId = $mediaNode->getAttribute('userId');
         // Permissions for this assignment
         $auth = $user->MediaAssignmentAuth($ownerId, $layoutId, $regionId, $mediaId, true);
         // Skip over media assignments that we do not have permission to see
         if (!$auth->view) {
             continue;
         }
         $i++;
         // Create a media module to handle all the complex stuff
         $tmpModule = ModuleFactory::load($mediaType, $layoutId, $regionId, $mediaId, $lkId, $this->db, $this->user);
         $mediaName = $tmpModule->GetName();
         $row['order'] = $i;
         $row['name'] = $mediaName == '' ? __($tmpModule->displayType) : $mediaName;
         $row['type'] = __($tmpModule->displayType);
         $row['duration'] = sprintf('%d seconds', $mediaDuration);
         $row['transition'] = sprintf('%s / %s', $tmpModule->GetTransition('in'), $tmpModule->GetTransition('out'));
         if ($auth->edit) {
             $row['buttons'][] = array('id' => 'timeline_button_edit', 'url' => 'index.php?p=module&mod=' . $mediaType . '&q=Exec&method=EditForm&layoutid=' . $layoutId . '&regionid=' . $regionId . '&mediaid=' . $mediaId . '&lkid=' . $lkId . '"', 'text' => __('Edit'));
         }
         if ($auth->del) {
             $row['buttons'][] = array('id' => 'timeline_button_delete', 'url' => 'index.php?p=module&mod=' . $mediaType . '&q=Exec&method=DeleteForm&layoutid=' . $layoutId . '&regionid=' . $regionId . '&mediaid=' . $mediaId . '&lkid=' . $lkId . '"', 'text' => __('Remove'), 'multi-select' => true, 'dataAttributes' => array(array('name' => 'multiselectlink', 'value' => 'index.php?p=module&mod=' . $mediaType . '&q=Exec&method=DeleteMedia'), array('name' => 'rowtitle', 'value' => $row['name']), array('name' => 'layoutid', 'value' => $layoutId), array('name' => 'regionid', 'value' => $regionId), array('name' => 'mediaid', 'value' => $mediaId), array('name' => 'lkid', 'value' => $lkId), array('name' => 'options', 'value' => 'unassign')));
         }
         if ($auth->modifyPermissions) {
             $row['buttons'][] = array('id' => 'timeline_button_permissions', 'url' => 'index.php?p=module&mod=' . $mediaType . '&q=Exec&method=PermissionsForm&layoutid=' . $layoutId . '&regionid=' . $regionId . '&mediaid=' . $mediaId . '&lkid=' . $lkId . '"', 'text' => __('Permissions'));
         }
         if (count($this->user->TransitionAuth('in')) > 0) {
             $row['buttons'][] = array('id' => 'timeline_button_trans_in', 'url' => 'index.php?p=module&mod=' . $mediaType . '&q=Exec&method=TransitionEditForm&type=in&layoutid=' . $layoutId . '&regionid=' . $regionId . '&mediaid=' . $mediaId . '&lkid=' . $lkId . '"', 'text' => __('In Transition'));
         }
         if (count($this->user->TransitionAuth('out')) > 0) {
             $row['buttons'][] = array('id' => 'timeline_button_trans_in', 'url' => 'index.php?p=module&mod=' . $mediaType . '&q=Exec&method=TransitionEditForm&type=out&layoutid=' . $layoutId . '&regionid=' . $regionId . '&mediaid=' . $mediaId . '&lkid=' . $lkId . '"', 'text' => __('Out Transition'));
         }
         $rows[] = $row;
     }
     // Store the table rows
     Theme::Set('table_rows', $rows);
     Theme::Set('gridId', Kit::GetParam('gridId', _REQUEST, _STRING));
     // Initialise the theme and capture the output
     $output = Theme::RenderReturn('table_render');
     $response->SetGridResponse($output);
     $response->initialSortColumn = 1;
     $response->Respond();
 }