sunnysideup /
silverstripe-sharethis
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace SunnysideUp\ShareThis; |
||||||
| 4 | |||||||
| 5 | use \Page; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 6 | use SilverStripe\Assets\Image; |
||||||
| 7 | use SilverStripe\Security\Permission; |
||||||
| 8 | use SilverStripe\ORM\FieldType\DBField; |
||||||
| 9 | use SilverStripe\ORM\Filters\PartialMatchFilter; |
||||||
| 10 | use SilverStripe\CMS\Model\SiteTree; |
||||||
| 11 | use SilverStripe\Forms\LiteralField; |
||||||
| 12 | use SilverStripe\Forms\TreeDropdownField; |
||||||
| 13 | use SilverStripe\ORM\DataObject; |
||||||
| 14 | |||||||
| 15 | /** |
||||||
| 16 | * |
||||||
| 17 | *@author nicolaas[at]sunnysideup.co.nz |
||||||
| 18 | *@description: creates a list of places where people can follow you (e.g. twitter, your blog, etc...) |
||||||
| 19 | * |
||||||
| 20 | */ |
||||||
| 21 | class SocialNetworkingLinksDataObject extends DataObject |
||||||
| 22 | { |
||||||
| 23 | /** |
||||||
| 24 | * @var string |
||||||
| 25 | */ |
||||||
| 26 | private static $table_name = 'SocialNetworkingLinksDataObject'; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 27 | |||||||
| 28 | /** |
||||||
| 29 | * @var array |
||||||
| 30 | */ |
||||||
| 31 | private static $db = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 32 | 'URL' => 'Varchar(255)', |
||||||
| 33 | 'Title' => 'Varchar(255)', |
||||||
| 34 | 'Sort' => 'Int' |
||||||
| 35 | ]; |
||||||
| 36 | |||||||
| 37 | /** |
||||||
| 38 | * @var array |
||||||
| 39 | */ |
||||||
| 40 | private static $casting = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 41 | 'Code' => 'Varchar(255)', |
||||||
| 42 | 'Link' => 'Varchar(255)', |
||||||
| 43 | 'IconHTML' => 'HTMLText' |
||||||
| 44 | ]; |
||||||
| 45 | |||||||
| 46 | /** |
||||||
| 47 | * @var array |
||||||
| 48 | */ |
||||||
| 49 | private static $has_one = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 50 | 'Icon' => Image::class, |
||||||
| 51 | 'InternalLink' => Page::class |
||||||
| 52 | ]; |
||||||
| 53 | |||||||
| 54 | /** |
||||||
| 55 | * @var array |
||||||
| 56 | */ |
||||||
| 57 | private static $searchable_fields = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 58 | 'Title' => PartialMatchFilter::class |
||||||
| 59 | ]; |
||||||
| 60 | |||||||
| 61 | /** |
||||||
| 62 | * @return array |
||||||
| 63 | */ |
||||||
| 64 | private static $field_labels = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 65 | 'InternalLink' => 'Internal Link', |
||||||
| 66 | 'URL' => 'External Link (e.g. http://twitter.com/myname/) - will override internal link', |
||||||
| 67 | 'Title' => 'Title', |
||||||
| 68 | 'Sort' => 'Sort Index (lower numbers shown first)', |
||||||
| 69 | 'IconID' => 'Icon (preferably 32px X 32px)' |
||||||
| 70 | ]; |
||||||
| 71 | |||||||
| 72 | /** |
||||||
| 73 | * @var array |
||||||
| 74 | */ |
||||||
| 75 | private static $summary_fields = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 76 | 'Title' => 'Title', |
||||||
| 77 | 'IconHTML' => 'Icon' |
||||||
| 78 | ]; |
||||||
| 79 | |||||||
| 80 | /** |
||||||
| 81 | * @var string |
||||||
| 82 | */ |
||||||
| 83 | private static $default_sort = 'Sort ASC, Title ASC'; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 84 | |||||||
| 85 | /** |
||||||
| 86 | * @var string |
||||||
| 87 | */ |
||||||
| 88 | private static $singular_name = 'Join Us link'; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 89 | |||||||
| 90 | /** |
||||||
| 91 | * @var string |
||||||
| 92 | */ |
||||||
| 93 | private static $plural_name = 'Join Us links'; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 94 | |||||||
| 95 | /** |
||||||
| 96 | * @return boolean |
||||||
| 97 | */ |
||||||
| 98 | public function canView($member = null) |
||||||
| 99 | { |
||||||
| 100 | return Permission::checkMember($member, 'SOCIAL_MEDIA'); |
||||||
| 101 | } |
||||||
| 102 | |||||||
| 103 | /** |
||||||
| 104 | * @return boolean |
||||||
| 105 | */ |
||||||
| 106 | public function canCreate($member = null, $context = []) |
||||||
| 107 | { |
||||||
| 108 | return Permission::checkMember($member, 'SOCIAL_MEDIA'); |
||||||
| 109 | } |
||||||
| 110 | |||||||
| 111 | /** |
||||||
| 112 | * @return boolean |
||||||
| 113 | */ |
||||||
| 114 | public function canEdit($member = null) |
||||||
| 115 | { |
||||||
| 116 | return Permission::checkMember($member, 'SOCIAL_MEDIA'); |
||||||
| 117 | } |
||||||
| 118 | |||||||
| 119 | /** |
||||||
| 120 | * @return boolean |
||||||
| 121 | */ |
||||||
| 122 | public function canDelete($member = null) |
||||||
| 123 | { |
||||||
| 124 | return Permission::checkMember($member, 'SOCIAL_MEDIA'); |
||||||
| 125 | } |
||||||
| 126 | |||||||
| 127 | /** |
||||||
| 128 | * @return String - returns the title with all non-alphanumeric + spaces removed. |
||||||
| 129 | */ |
||||||
| 130 | public function Code() |
||||||
| 131 | { |
||||||
| 132 | return strtolower(preg_replace("/[^a-zA-Z0-9]/", '', $this->Title)); |
||||||
| 133 | } |
||||||
| 134 | |||||||
| 135 | /** |
||||||
| 136 | * @return DBField |
||||||
| 137 | */ |
||||||
| 138 | public function IconHTML() |
||||||
| 139 | { |
||||||
| 140 | return $this->getIconHTML(); |
||||||
| 141 | } |
||||||
| 142 | |||||||
| 143 | /** |
||||||
| 144 | * @return DBField / icon |
||||||
| 145 | */ |
||||||
| 146 | public function getIconHTML() |
||||||
| 147 | { |
||||||
| 148 | $icon = $this->Icon(); |
||||||
|
0 ignored issues
–
show
The method
Icon() does not exist on SunnysideUp\ShareThis\So...tworkingLinksDataObject. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 149 | if ($icon && $icon->exists()) { |
||||||
| 150 | $html = $icon->ScaleHeight(32); |
||||||
| 151 | } else { |
||||||
| 152 | $html = DBField::create_field("HTMLText", '<img src="/' . SS_SHARETHIS_DIR . "/images/icons/{$this->Code}.png\" alt=\"{$this->Code}\"/>"); |
||||||
|
0 ignored issues
–
show
The property
Code does not exist on SunnysideUp\ShareThis\So...tworkingLinksDataObject. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 153 | } |
||||||
| 154 | return $html; |
||||||
| 155 | } |
||||||
| 156 | |||||||
| 157 | /** |
||||||
| 158 | * Link |
||||||
| 159 | * |
||||||
| 160 | * @return string |
||||||
| 161 | */ |
||||||
| 162 | public function Link() |
||||||
| 163 | { |
||||||
| 164 | if ($this->URL) { |
||||||
|
0 ignored issues
–
show
The property
URL does not exist on SunnysideUp\ShareThis\So...tworkingLinksDataObject. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 165 | return $this->URL; |
||||||
| 166 | } elseif ($this->InternalLinkID) { |
||||||
|
0 ignored issues
–
show
The property
InternalLinkID does not exist on SunnysideUp\ShareThis\So...tworkingLinksDataObject. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 167 | $page = SiteTree::get()->byID($this->InternalLinkID); |
||||||
| 168 | if ($page->exists()) { |
||||||
| 169 | return $page->Link(); |
||||||
| 170 | } |
||||||
| 171 | } |
||||||
| 172 | } |
||||||
| 173 | |||||||
| 174 | /** |
||||||
| 175 | * @return FieldList $fields |
||||||
|
0 ignored issues
–
show
The type
SunnysideUp\ShareThis\FieldList was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 176 | */ |
||||||
| 177 | public function getCMSFields() |
||||||
| 178 | { |
||||||
| 179 | $fields = parent::getCMSFields(); |
||||||
| 180 | |||||||
| 181 | if ($this->ID) { |
||||||
| 182 | $fields->addFieldToTab('Root.Main', LiteralField::create('Code', "<p>Code: {$this->Code()}</p>")); |
||||||
| 183 | $fields->addFieldToTab('Root.Main', LiteralField::create('Link', "<p>Link: <a href=\"{$this->Link()}\">{$this->Link()}</a></p>")); |
||||||
| 184 | $fields->addFieldToTab('Root.Main', LiteralField::create('Link', "<p>{$this->IconHTML()}</p>")); |
||||||
| 185 | } |
||||||
| 186 | |||||||
| 187 | $fields->removeFieldFromTab('Root.Main', 'InternalLinkID'); |
||||||
| 188 | $fields->addFieldToTab('Root.Main', TreeDropdownField::create('InternalLinkID', 'Internal Link', SiteTree::class), 'URL'); |
||||||
| 189 | |||||||
| 190 | return $fields; |
||||||
| 191 | } |
||||||
| 192 | } |
||||||
| 193 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths