Example #1
0
 /**
  * Edit Region on a layout
  * @return <XiboAPIResponse>
  */
 public function LayoutRegionEdit()
 {
     if (!$this->user->PageAuth('layout')) {
         return $this->Error(1, 'Access Denied');
     }
     $layoutId = $this->GetParam('layoutId', _INT);
     $regionId = $this->GetParam('regionId', _STRING);
     $width = $this->GetParam('width', _INT);
     $height = $this->GetParam('height', _INT);
     $top = $this->GetParam('top', _INT);
     $left = $this->GetParam('left', _INT);
     $name = $this->GetParam('name', _STRING);
     // Does the user have permissions to view this region?
     if (!$this->user->LayoutAuth($layoutId)) {
         return $this->Error(1, 'Access Denied');
     }
     // Create a region object
     Kit::ClassLoader('region');
     $region = new Region();
     // Region Assignment needs the Owner Id
     $ownerId = $region->GetOwnerId($layoutId, $regionId);
     $regionAuth = $this->user->RegionAssignmentAuth($ownerId, $layoutId, $regionId, true);
     if (!$regionAuth->edit) {
         return $this->Error(1, 'Access Denied');
     }
     // Edit the region
     if (!($regionId = $region->EditRegion($layoutId, $regionId, $width, $height, $top, $left, $name = ''))) {
         return $this->Error($region->GetErrorNumber(), $region->GetErrorMessage());
     }
     return $this->Respond($this->ReturnId('success', true));
 }
Example #2
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;
 }