public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     /* Clean up meta data */
     $this->owner->MetaDescription = $this->cleanData($this->owner->MetaDescription);
     $this->owner->MetaTitle = $this->cleanData($this->owner->MetaTitle);
     $this->owner->MetaKeywords = $this->tidyKeywords($this->owner->MetaKeywords);
     /* For users who may not alter the site structure */
     if ($this->owner->MetaTitle) {
         if ($this->owner->MetaTitle != $this->owner->Title) {
             // Meta title has changed
             $newMenuTitle = false;
             if ($this->owner->MenuTitle == $this->owner->Title) {
                 $newMenuTitle = $this->owner->MenuTitle;
             }
             $this->owner->Title = $this->owner->MetaTitle;
             if ($newMenuTitle) {
                 $this->owner->setMenuTitle($newMenuTitle);
             }
         } else {
             /* Reset to null if changed back */
             $this->owner->setMenuTitle($this->owner->MenuTitle);
         }
     }
 }
 public function onBeforeWrite()
 {
     if ($this->owner->Embargo["date"] && !$this->owner->Embargo["time"]) {
         $this->owner->Embargo["time"] = "00:00";
     }
     if ($this->owner->Expiry["date"] && !$this->owner->Expiry["time"]) {
         $this->owner->Expiry["time"] = "23:00";
     }
     parent::onBeforeWrite();
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $length = $this->owner->config()->MetaDescriptionLength ?: $this->MetaDescriptionLength;
     if (strlen($this->owner->MetaDescription) > $length) {
         /** @var Text $value */
         $value = $this->owner->dbObject('MetaDescription');
         $value = $value->LimitCharacters($length);
         $this->owner->MetaDescription = $value;
     }
 }
 /**
  * Update Metadata fields function
  */
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     if ($this->owner->ID && $this->owner->GenerateMetaData) {
         $this->owner->MetaTitle = strip_tags($this->owner->Title);
         $this->owner->MetaDescription = html_entity_decode(strip_tags($this->owner->Content), ENT_COMPAT, 'UTF-8');
         if (self::$meta_desc_length > 0 && strlen($this->owner->MetaDescription) > self::$meta_desc_length) {
             $this->owner->MetaDescription = substr($this->owner->MetaDescription, 0, self::$meta_desc_length) . "...";
         }
         // calculateKeywords
         $this->owner->MetaKeywords = MetaGenerator::generateKeywords($this->owner->Content, self::$min_word_char, self::$keyword_amount, self::$exclude_words);
     }
 }
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`";
     if ($this->classHasAdvertisements($this->owner->ClassName)) {
         $objects = array(0 => 0);
         $images = array(0 => 0);
         $dos1 = $this->advertisementsToShow();
         if ($dos1) {
             foreach ($dos1 as $obj) {
                 $images[$obj->ID] = $obj->AdvertisementImageID;
                 $objects[$obj->ID] = $obj->ID;
             }
         }
         //check for non-existing images and delete advertisements associated with it
         foreach ($images as $objectID => $imageID) {
             if (!Image::get()->byID($imageID)) {
                 $obj = Advertisement::get()->byID($objectID);
                 if ($obj) {
                     $obj->delete();
                     $obj->destroy();
                     unset($objects[$objectID]);
                 }
             }
         }
         //check if a folder has been set and create objects
         if ($this->owner->AdvertisementsFolderID) {
             $dos2 = Image::get()->where("\"File\".\"ParentID\" = " . $this->owner->AdvertisementsFolderID . " AND \"Advertisement\".\"AdvertisementImageID\" IS NULL ")->leftJoin("Advertisement", "\"Advertisement\".\"AdvertisementImageID\" = \"File\".\"ID\" ");
             if ($dos2->count()) {
                 $advertisementsToAdd = array();
                 foreach ($dos2 as $image) {
                     $newAdvertisement = new Advertisement();
                     $newAdvertisement->AdvertisementImageID = $image->ID;
                     $newAdvertisement->Title = $image->Title;
                     $newAdvertisement->AutoAdded = true;
                     $newAdvertisement->write();
                     $objects[$newAdvertisement->ID] = $newAdvertisement->ID;
                 }
                 $this->owner->Advertisements()->addMany($objects);
             }
         }
         if ($this->owner->AdvertisementStyleID) {
             if (!AdvertisementStyle::get()->byID($this->owner->AdvertisementStyleID)) {
                 $this->owner->AdvertisementStyleID = 0;
             }
         }
         //remove advdertisements if parent is being used...
         if ($this->owner->UseParentAdvertisements) {
             if ($this->advertisementParent()) {
                 $combos = $this->owner->Advertisements();
                 if ($combos) {
                     $combos->removeAll();
                 }
             } else {
                 $this->owner->UseParentAdvertisements = false;
             }
         }
     }
 }