@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * Automated Link Report is a report that lists all automated |
| 9 | 9 | * links and how they affect the website |
| 10 | 10 | */ |
| 11 | -class AutomatedLinkReport extends SS_Report{ |
|
| 11 | +class AutomatedLinkReport extends SS_Report { |
|
| 12 | 12 | |
| 13 | 13 | protected $title = 'Automated Link Report'; |
| 14 | 14 | protected $description = 'Shows a list of all automated links and how they affect the site'; |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | // Configs |
| 17 | 17 | private static $run_in_realtime = true; |
| 18 | 18 | |
| 19 | - public function Title(){ |
|
| 19 | + public function Title() { |
|
| 20 | 20 | return (string) $this->title; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - public function columns(){ |
|
| 23 | + public function columns() { |
|
| 24 | 24 | return array( |
| 25 | 25 | 'Title' => array( |
| 26 | 26 | 'title' => 'Page Title', |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | ); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - public function sourceRecords( $params, $sort, $limit ){ |
|
| 38 | - if( !Config::inst()->get( $this->class, 'run_in_realtime' ) ) { |
|
| 37 | + public function sourceRecords($params, $sort, $limit) { |
|
| 38 | + if (!Config::inst()->get($this->class, 'run_in_realtime')) { |
|
| 39 | 39 | return AutomatedLinkPageResult::get(); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $gridConfig->removeComponentsByType('GridFieldPrintButton'); |
| 54 | 54 | $gridConfig->removeComponentsByType('GridFieldExportButton'); |
| 55 | 55 | |
| 56 | - $gridConfig->addComponents ( |
|
| 56 | + $gridConfig->addComponents( |
|
| 57 | 57 | new GridFieldPrintAllAutomatedLinksButton('buttons-after-left'), |
| 58 | 58 | new GridFieldExportAllAutomatedLinksButton('buttons-after-left') |
| 59 | 59 | ); |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * Automated Link is a dataobject that contains all the data |
| 8 | 8 | * about a link that should be created automatically to a page |
| 9 | 9 | */ |
| 10 | -class AutomatedLink extends DataObject implements PermissionProvider{ |
|
| 10 | +class AutomatedLink extends DataObject implements PermissionProvider { |
|
| 11 | 11 | |
| 12 | 12 | private static $db = array( |
| 13 | 13 | 'Phrase' => 'VARCHAR(255)', |
@@ -31,37 +31,37 @@ discard block |
||
| 31 | 31 | 'Page' => 'SiteTree' |
| 32 | 32 | ); |
| 33 | 33 | |
| 34 | - private static $summary_fields = array( 'Phrase', 'PointsTo' ); |
|
| 35 | - private static $searchable_fields = array( 'Phrase' ); |
|
| 36 | - private static $singular_name = 'Automated Link'; |
|
| 34 | + private static $summary_fields = array('Phrase', 'PointsTo'); |
|
| 35 | + private static $searchable_fields = array('Phrase'); |
|
| 36 | + private static $singular_name = 'Automated Link'; |
|
| 37 | 37 | private static $plural_name = 'Automated Links'; |
| 38 | - private static $parsableFields = array(); |
|
| 38 | + private static $parsableFields = array(); |
|
| 39 | 39 | |
| 40 | - public function PointsTo(){ |
|
| 40 | + public function PointsTo() { |
|
| 41 | 41 | return $this->Page()->Link(); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public function Title(){ |
|
| 44 | + public function Title() { |
|
| 45 | 45 | return $this->Phrase; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function forTemplate(){ |
|
| 48 | + public function forTemplate() { |
|
| 49 | 49 | return $this->getHTML(); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - function canView( $member = false ){ |
|
| 52 | + function canView($member = false) { |
|
| 53 | 53 | return Permission::check('AUTOMATEDLINK_VIEW'); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - function canEdit( $member = false ){ |
|
| 56 | + function canEdit($member = false) { |
|
| 57 | 57 | return Permission::check('AUTOMATEDLINK_EDIT'); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - function canDelete( $member = false ){ |
|
| 60 | + function canDelete($member = false) { |
|
| 61 | 61 | return Permission::check('AUTOMATEDLINK_DELETE'); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - function canCreate( $member = false ){ |
|
| 64 | + function canCreate($member = false) { |
|
| 65 | 65 | return Permission::check('AUTOMATEDLINK_CREATE'); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | ); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function requireDefaultRecords(){ |
|
| 77 | + public function requireDefaultRecords() { |
|
| 78 | 78 | parent::requireDefaultRecords(); |
| 79 | 79 | |
| 80 | 80 | // Update all links to redirector pages during dev/build |
| 81 | - foreach( self::get() as $link ) $link->CheckAndUpdateDestination( true ); |
|
| 81 | + foreach (self::get() as $link) $link->CheckAndUpdateDestination(true); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -87,36 +87,36 @@ discard block |
||
| 87 | 87 | * @param String $originalPhrase |
| 88 | 88 | * @return String |
| 89 | 89 | */ |
| 90 | - public function getHTML( $originalPhrase = NULL ){ |
|
| 91 | - $link = ( $this->PageID ) ? $this->Page()->Link() : '#'; |
|
| 92 | - $title = ( $this->TitleTag ) ? "title='{$this->TitleTag}'" : ''; |
|
| 93 | - $nofollow = ( $this->NoFollow ) ? 'rel="nofollow"' : ''; |
|
| 94 | - $newtab = ( $this->NewWindow ) ? 'target="_blank"' : ''; |
|
| 95 | - $anchor = ( $originalPhrase ) ? $originalPhrase : $this->Phrase; |
|
| 96 | - $link = ( $this->AnchorTag ) ? rtrim( $link, '#' ).'#'.$this->AnchorTag : $link; |
|
| 90 | + public function getHTML($originalPhrase = NULL) { |
|
| 91 | + $link = ($this->PageID) ? $this->Page()->Link() : '#'; |
|
| 92 | + $title = ($this->TitleTag) ? "title='{$this->TitleTag}'" : ''; |
|
| 93 | + $nofollow = ($this->NoFollow) ? 'rel="nofollow"' : ''; |
|
| 94 | + $newtab = ($this->NewWindow) ? 'target="_blank"' : ''; |
|
| 95 | + $anchor = ($originalPhrase) ? $originalPhrase : $this->Phrase; |
|
| 96 | + $link = ($this->AnchorTag) ? rtrim($link, '#').'#'.$this->AnchorTag : $link; |
|
| 97 | 97 | return "<a href=\"$link\" $title $nofollow $newtab data-id=\"{$this->ID}\">{$anchor}</a>"; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - public function getCMSFields(){ |
|
| 101 | - $fields = FieldList::create( TabSet::create( 'Root' ) ); |
|
| 100 | + public function getCMSFields() { |
|
| 101 | + $fields = FieldList::create(TabSet::create('Root')); |
|
| 102 | 102 | |
| 103 | - $fields->addFieldsToTab( 'Root.LinkSettings', array( |
|
| 104 | - TextField::create( 'Phrase', 'Phrase to search for', $this->Phrase, 255 ), |
|
| 105 | - TextField::create( 'TitleTag', 'Title Tag', $this->TitleTag, 255 ), |
|
| 106 | - TextField::create( 'AnchorTag', 'Anchor Tag(#)', $this->AnchorTag, 255 ), |
|
| 103 | + $fields->addFieldsToTab('Root.LinkSettings', array( |
|
| 104 | + TextField::create('Phrase', 'Phrase to search for', $this->Phrase, 255), |
|
| 105 | + TextField::create('TitleTag', 'Title Tag', $this->TitleTag, 255), |
|
| 106 | + TextField::create('AnchorTag', 'Anchor Tag(#)', $this->AnchorTag, 255), |
|
| 107 | 107 | FieldGroup::create( |
| 108 | - CheckboxField::create( 'NoFollow' ), |
|
| 109 | - CheckboxField::create( 'NewWindow' ), |
|
| 110 | - CheckboxField::create( 'SelfLinking', 'Allow page to link to itself' ), |
|
| 111 | - CheckboxField::create( 'CaseSensitive', 'Match the case of the phrase' ) |
|
| 108 | + CheckboxField::create('NoFollow'), |
|
| 109 | + CheckboxField::create('NewWindow'), |
|
| 110 | + CheckboxField::create('SelfLinking', 'Allow page to link to itself'), |
|
| 111 | + CheckboxField::create('CaseSensitive', 'Match the case of the phrase') |
|
| 112 | 112 | ), |
| 113 | - NumericField::create( 'MaxLinksPerPage', 'Maximum amount of this link to be created on a single page( 0 = unlimited )' ), |
|
| 114 | - TreeDropdownField::create( 'PageID', 'Page to link to', 'SiteTree' ) |
|
| 115 | - ) ); |
|
| 113 | + NumericField::create('MaxLinksPerPage', 'Maximum amount of this link to be created on a single page( 0 = unlimited )'), |
|
| 114 | + TreeDropdownField::create('PageID', 'Page to link to', 'SiteTree') |
|
| 115 | + )); |
|
| 116 | 116 | |
| 117 | 117 | $settings = GlobalAutoLinkSettings::get_current(); |
| 118 | - if( $settings ){ |
|
| 119 | - $fields->addFieldsToTab( 'Root.Global', array( |
|
| 118 | + if ($settings) { |
|
| 119 | + $fields->addFieldsToTab('Root.Global', array( |
|
| 120 | 120 | NumericField::create( |
| 121 | 121 | 'Global_MaxLinksPerPage', |
| 122 | 122 | 'Maximum amount of links a single page can have ( 0 = unlimited )', |
@@ -136,14 +136,14 @@ discard block |
||
| 136 | 136 | 'Include Links into these fields ( comma seperated & field must support html injection )', |
| 137 | 137 | $settings->IncludeIn |
| 138 | 138 | ) |
| 139 | - ) ); |
|
| 139 | + )); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | return $fields; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - public function getCMSValidator(){ |
|
| 146 | - return new RequiredFields( array( 'Phrase', 'PageID' ) ); |
|
| 145 | + public function getCMSValidator() { |
|
| 146 | + return new RequiredFields(array('Phrase', 'PageID')); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -152,15 +152,15 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @return void |
| 154 | 154 | */ |
| 155 | - public function onBeforeWrite(){ |
|
| 155 | + public function onBeforeWrite() { |
|
| 156 | 156 | parent::onBeforeWrite(); |
| 157 | 157 | |
| 158 | 158 | $settings = GlobalAutoLinkSettings::get_current(); |
| 159 | - if( $settings ){ |
|
| 159 | + if ($settings) { |
|
| 160 | 160 | |
| 161 | - foreach( $this->getChangedFields() as $field => $value ){ |
|
| 162 | - if( strpos( $field, 'Global_' ) === 0 && isset( $value['after'] ) ){ |
|
| 163 | - $field = str_replace( 'Global_', '', $field ); |
|
| 161 | + foreach ($this->getChangedFields() as $field => $value) { |
|
| 162 | + if (strpos($field, 'Global_') === 0 && isset($value['after'])) { |
|
| 163 | + $field = str_replace('Global_', '', $field); |
|
| 164 | 164 | $settings->$field = $value['after']; |
| 165 | 165 | } |
| 166 | 166 | } |
@@ -178,15 +178,15 @@ discard block |
||
| 178 | 178 | * @Boolean $write - Write the changes if any |
| 179 | 179 | * @return void |
| 180 | 180 | */ |
| 181 | - public function CheckAndUpdateDestination( $write = false ){ |
|
| 181 | + public function CheckAndUpdateDestination($write = false) { |
|
| 182 | 182 | $this->extend('beforeCheckAndUpdateDestination', $write); |
| 183 | 183 | |
| 184 | - if( $this->PageID && $this->Page() && |
|
| 184 | + if ($this->PageID && $this->Page() && |
|
| 185 | 185 | $this->Page()->ClassName == 'RedirectorPage' && |
| 186 | - $this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' ) |
|
| 186 | + $this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal') |
|
| 187 | 187 | { |
| 188 | 188 | $this->PageID = $this->Page()->LinkToID; |
| 189 | - if( $write ) $this->write(); |
|
| 189 | + if ($write) $this->write(); |
|
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | |
@@ -198,15 +198,15 @@ discard block |
||
| 198 | 198 | * |
| 199 | 199 | * @return Boolean |
| 200 | 200 | */ |
| 201 | - public static function isFieldParsable( SiteTree $page, $field ){ |
|
| 202 | - if( !isset( self::$parsableFields[$page->ID] ) || !isset( self::$parsableFields[$page->ID][$field] ) ){ |
|
| 201 | + public static function isFieldParsable(SiteTree $page, $field) { |
|
| 202 | + if (!isset(self::$parsableFields[$page->ID]) || !isset(self::$parsableFields[$page->ID][$field])) { |
|
| 203 | 203 | $fields = array(); |
| 204 | 204 | |
| 205 | - foreach( ClassInfo::ancestry( $page->ClassName, true ) as $class ) |
|
| 206 | - $fields = array_merge( $fields, (array) DataObject::database_fields( $class ) ); |
|
| 205 | + foreach (ClassInfo::ancestry($page->ClassName, true) as $class) |
|
| 206 | + $fields = array_merge($fields, (array) DataObject::database_fields($class)); |
|
| 207 | 207 | |
| 208 | 208 | self::$parsableFields[$page->ID][$field] = |
| 209 | - (Boolean) array_key_exists( $field, $fields ) && strtolower( $fields[$field] ) === 'htmltext' && $page->$field; |
|
| 209 | + (Boolean) array_key_exists($field, $fields) && strtolower($fields[$field]) === 'htmltext' && $page->$field; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | return self::$parsableFields[$page->ID][$field]; |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @return Boolean |
| 222 | 222 | */ |
| 223 | - public function canBeAdded( ContentController $controller ){ |
|
| 224 | - return ( $this->SelfLinking || $controller->ID != $this->PageID ); |
|
| 223 | + public function canBeAdded(ContentController $controller) { |
|
| 224 | + return ($this->SelfLinking || $controller->ID != $this->PageID); |
|
| 225 | 225 | } |
| 226 | 226 | } |