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 requireDefaultRecords() { parent::requireDefaultRecords(); if (!$this->owner->config()->upgrade_on_build) { return; } // Perform migrations (the legacy field will be left in the DB by the ORM) $class = $this->owner->class; $baseclass = $this->ownerBaseClass; if ($baseclass == $class) { // if(in_array('FeaturedImageExtension', Config::inst()->get($class, 'extensions'))){ $rows = DB::query('SELECT * FROM "' . $baseclass . '"'); $altered = false; foreach ($rows as $page) { if (array_key_exists('FeaturedImageID', $page) && ($imageID = $page['FeaturedImageID'])) { DB::query('INSERT INTO "' . $baseclass . '_FeaturedImages" (' . $class . 'ID, ImageID) VALUES (' . $page['ID'] . ', ' . $page['FeaturedImageID'] . ')'); $altered = true; //$page->FeaturedImages()->add($imageID); //$page->FeaturedImageID = null; // leave as is... // $page->write(); } } // Now drop the legacy field if ($altered) { DB::query('ALTER TABLE "' . $baseclass . '" DROP "FeaturedImageID"'); DB::alteration_message('Migrated FeaturedImages to many_many on ' . $baseclass, 'changed'); } } }
/** * After publishing or updating a page, this function POSTS to let * blog services know your website has been updated. * Uses @webPingXML * Uses @doWebPing */ public function onAfterPublish(&$original) { // Get the XML to post $postString = $this->webPingXML($original); // Set the site configuration settings to $config $config = SiteConfig::current_site_config(); // Check if the user has entered any urls to ping if (!empty($config->pingUrls)) { $this->setPingUrls($config->pingUrls); } // Convert new lines to br tags and then replace any <br> tags with xhtml <br /> tags $pingUrls = str_replace("<br>", "<br />", nl2br($this->getPingUrls())); // Explode the $pingUrls into an array, removing any <br /> tags $pingUrls = explode("<br />", $pingUrls); // Check to make sure the $pingUrls have some value if (!empty($pingUrls)) { // Check if there is more than one url to ping if (is_array($pingUrls)) { // Loop through the urls foreach ($pingUrls as $url) { // Post the XML to the url $this->doWebPing($url, $postString); } } else { // Post the XML to the url $this->doWebPing($pingUrls, $postString); } } parent::onAfterPublish(&$original); }
public function updateCMSFields(\FieldList $fields) { parent::updateCMSFields($fields); // Make more sense of the base fields // $fields->insertBefore('Title', $fields->dataFieldByName('MenuTitle')); // $fields->insertBefore('Title', $fields->dataFieldByName('URLSegment')); // $fields->dataFieldByName('Title')->setTitle('Title'); }
/** * because we use this function you can NOT * use any statics in the file!!! * @return Array | null */ public static function get_extra_config($class, $extension, $args) { if (Config::inst()->get("MetaTagsContentControllerEXT", "use_separate_metatitle") == 1) { $array = array('db' => array("MetaTitle" => "Varchar(255)") + self::$db); } else { $array = array('db' => self::$db); } return (array) parent::get_extra_config($class, $extension, $args) + $array; }
public function __construct() { // TODO Re-enable before we release 3.0 beta, for now it "breaks" too many modules // user_error( // 'SiteTreeDecorator is deprecated, please use SiteTreeExtension instead.', // E_USER_NOTICE // ); parent::__construct(); }
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; } }
public function onAfterWrite() { parent::onAfterWrite(); foreach ($this->owner->Categories() as $category) { $category->HolderPageID = $this->owner->ParentID; $category->write(); } foreach ($this->owner->Tags() as $tag) { $tag->HolderPageID = $this->owner->ParentID; $tag->write(); } }
/** * 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 onAfterWrite() { parent::onAfterWrite(); $ID = $this->owner->ID; $className = $this->owner->ClassName; $subClasses = ClassInfo::dataClassesFor($className); $versionsToDelete = array(); $version_limit = Config::inst()->get('VersionTruncator', 'version_limit'); if (is_numeric($version_limit)) { $search = DB::query('SELECT "RecordID", "Version" FROM "SiteTree_versions" WHERE "RecordID" = ' . $ID . ' AND "ClassName" = \'' . $className . '\' AND "PublisherID" > 0 ORDER BY "LastEdited" DESC LIMIT ' . $version_limit . ', 200'); foreach ($search as $row) { array_push($versionsToDelete, array('RecordID' => $row['RecordID'], 'Version' => $row['Version'])); } } $draft_limit = Config::inst()->get('VersionTruncator', 'draft_limit'); if (is_numeric($draft_limit)) { $search = DB::query('SELECT "RecordID", "Version" FROM "SiteTree_versions" WHERE "RecordID" = ' . $ID . ' AND "ClassName" = \'' . $className . '\' AND "PublisherID" = 0 ORDER BY "LastEdited" DESC LIMIT ' . $draft_limit . ', 200'); foreach ($search as $row) { array_push($versionsToDelete, array('RecordID' => $row['RecordID'], 'Version' => $row['Version'])); } } $delete_old_page_types = Config::inst()->get('VersionTruncator', 'delete_old_page_types'); if ($delete_old_page_types) { $search = DB::query('SELECT "RecordID", "Version" FROM "SiteTree_versions" WHERE "RecordID" = ' . $ID . ' AND "ClassName" != \'' . $className . '\''); foreach ($search as $row) { array_push($versionsToDelete, array('RecordID' => $row['RecordID'], 'Version' => $row['Version'])); } } /* If versions to delete, start deleting */ if (count($versionsToDelete) > 0) { $affected_tables = array(); foreach ($subClasses as $subclass) { $versionsTable = $subclass . '_versions'; foreach ($versionsToDelete as $d) { DB::query('DELETE FROM "' . $versionsTable . '"' . ' WHERE "RecordID" = ' . $d['RecordID'] . ' AND "Version" = ' . $d['Version']); if (DB::affectedRows() == 1) { array_push($affected_tables, $versionsTable); } } } $this->vacuumTables($affected_tables); } }
public function __construct() { Deprecation::notice('3.0', 'Use SiteTreeExtension instead.'); parent::__construct(); }
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; } } } }
public function __construct($dataRecord = null) { $this->api = CheckfrontModule::api(); parent::__construct($dataRecord); }