Source of file SocialNetworksSTE.php
Size: 4,304 Bytes - Last Modified: 2021-12-23T10:46:26+00:00
/var/www/docs.ssmods.com/process/src/src/Extension/SocialNetworksSTE.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 | <?php namespace SunnysideUp\ShareThis\Extension; use SilverStripe\CMS\Model\SiteTreeExtension; use SilverStripe\Core\Config\Config; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\HeaderField; use SilverStripe\Forms\LiteralField; use SilverStripe\View\Requirements; /** * Add a field to each SiteTree object and it's subclasses to enable "follow us on ...", this can be a blog, twitter, facebook or whatever else. * it uses the SocialNetworkingLinksDataObject to get a list of icons. * @author nicolaas [at] sunnysideup.co.nz * @todo fix populateDefaults to make sure SiteConfig table is built first */ class SocialNetworksSTE extends SiteTreeExtension { /** * Use the font-awesome icon collection? * @var boolean */ private static $use_font_awesome = false; /** * list of sitetree extending classnames where * the ShareThis functionality should be included * @var array */ private static $always_include_in = []; /** * list of sitetree extending classnames where * the ShareThis functionality should NEVER be included * @var array */ private static $never_include_in = []; /** * @var array */ private static $db = [ 'HasSocialNetworkingLinks' => 'Boolean', ]; /** * @param FieldList $fields * * @return FieldList */ public function updateCMSFields(FieldList $fields) { if ($this->applyToOwnerClass()) { $config = $this->owner->getSiteConfig(); if (! $config->AlwaysIncludeSocialNetworkingLinks) { $fields->addFieldToTab('Root.SocialMedia', HeaderField::create('SocialNetworksHeader', 'Ask visitors to JOIN YOU on your social media')); $fields->addFieldToTab('Root.SocialMedia', CheckboxField::create('HasSocialNetworkingLinks', 'Show Join Us on our Social Networks Links on this Page (e.g. follow us on Twitter) - make sure to specify social networking links!')); } $fields->addFieldToTab('Root.SocialMedia', LiteralField::create('LinkToSiteConfigSocialMedia', "<p>There are more social media settings in the <a href=\"{$config->CMSEditLink()}\">Site Config</a>.</p>")); } return $fields; } /** * @return boolean */ public function ShowSocialNetworks() { if ($this->applyToOwnerClass()) { $config = $this->owner->getSiteConfig(); if ($config->AlwaysIncludeSocialNetworkingLinks) { return true; } return $this->owner->HasSocialNetworkingLinks; } return false; } /** * @return SocialNetworkingLinksDataObject */ public function SocialNetworks() { Requirements::themedCSS('SocialNetworking', 'sharethis'); if (Config::inst()->get(SocialNetworksSTE::class, 'use_font_awesome')) { Requirements::css('//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css'); } return SocialNetworkingLinksDataObject::get(); } /** * @return boolean */ private function applyToOwnerClass() { $always = Config::inst()->get(SocialNetworksSTE::class, 'always_include_in'); $never = Config::inst()->get(SocialNetworksSTE::class, 'never_include_in'); if (count($always) === 0 && count($never) === 0) { return true; } if (count($never) && count($always) === 0) { if (in_array($this->owner->ClassName, $never, true)) { return false; } return true; } if (count($always) && count($never) === 0) { if (in_array($this->owner->ClassName, $always, true)) { return true; } return false; } if (count($never) && count($always)) { if (in_array($this->owner->ClassName, $never, true)) { return false; } if (in_array($this->owner->ClassName, $always, true)) { return true; } //exception... if dev sets both always and never //then the ones not set will be included by default. return true; } } } |