Completed
Pull Request — master (#30)
by Robbie
02:19
created
src/PageTypes/NewsHolder.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -7,50 +7,50 @@
 block discarded – undo
7 7
 
8 8
 class NewsHolder extends DatedUpdateHolder
9 9
 {
10
-    private static $description = 'Container page for News Pages, provides news filtering and pagination';
11
-
12
-    private static $allowed_children = [
13
-        NewsPage::class,
14
-    ];
15
-
16
-    private static $default_child = NewsPage::class;
17
-
18
-    private static $update_name = 'News';
19
-
20
-    private static $update_class = NewsPage::class;
21
-
22
-    private static $icon = 'cwp/cwp:images/icons/sitetree_images/news_listing.png';
23
-
24
-    private static $singular_name = 'News Holder';
25
-
26
-    private static $plural_name = 'News Holders';
27
-
28
-    private static $table_name = 'NewsHolder';
29
-
30
-    /**
31
-     * Find all site's news items, based on some filters.
32
-     * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together.
33
-     *
34
-     * @param string $className The name of the class to fetch.
35
-     * @param int $parentID The ID of the holder to extract the news items from.
36
-     * @param int $tagID The ID of the tag to filter the news items by.
37
-     * @param string $dateFrom The beginning of a date filter range.
38
-     * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for.
39
-     * @param int $year Numeric value of the year to show.
40
-     * @param int $monthNumber Numeric value of the month to show.
41
-     *
42
-     * @returns DataList|PaginatedList
43
-     */
44
-    public static function AllUpdates(
45
-        $className = NewsPage::class,
46
-        $parentID = null,
47
-        $tagID = null,
48
-        $dateFrom = null,
49
-        $dateTo = null,
50
-        $year = null,
51
-        $monthNumber = null
52
-    ) {
53
-        return parent::AllUpdates($className, $parentID, $tagID, $dateFrom, $dateTo, $year, $monthNumber)
54
-            ->Sort('Date', 'DESC');
55
-    }
10
+	private static $description = 'Container page for News Pages, provides news filtering and pagination';
11
+
12
+	private static $allowed_children = [
13
+		NewsPage::class,
14
+	];
15
+
16
+	private static $default_child = NewsPage::class;
17
+
18
+	private static $update_name = 'News';
19
+
20
+	private static $update_class = NewsPage::class;
21
+
22
+	private static $icon = 'cwp/cwp:images/icons/sitetree_images/news_listing.png';
23
+
24
+	private static $singular_name = 'News Holder';
25
+
26
+	private static $plural_name = 'News Holders';
27
+
28
+	private static $table_name = 'NewsHolder';
29
+
30
+	/**
31
+	 * Find all site's news items, based on some filters.
32
+	 * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together.
33
+	 *
34
+	 * @param string $className The name of the class to fetch.
35
+	 * @param int $parentID The ID of the holder to extract the news items from.
36
+	 * @param int $tagID The ID of the tag to filter the news items by.
37
+	 * @param string $dateFrom The beginning of a date filter range.
38
+	 * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for.
39
+	 * @param int $year Numeric value of the year to show.
40
+	 * @param int $monthNumber Numeric value of the month to show.
41
+	 *
42
+	 * @returns DataList|PaginatedList
43
+	 */
44
+	public static function AllUpdates(
45
+		$className = NewsPage::class,
46
+		$parentID = null,
47
+		$tagID = null,
48
+		$dateFrom = null,
49
+		$dateTo = null,
50
+		$year = null,
51
+		$monthNumber = null
52
+	) {
53
+		return parent::AllUpdates($className, $parentID, $tagID, $dateFrom, $dateTo, $year, $monthNumber)
54
+			->Sort('Date', 'DESC');
55
+	}
56 56
 }
Please login to merge, or discard this patch.
src/PageTypes/EventHolderController.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -19,53 +19,53 @@
 block discarded – undo
19 19
  */
20 20
 class EventHolderController extends DatedUpdateHolderController
21 21
 {
22
-    public function getUpdateName()
23
-    {
24
-        $params = $this->parseParams();
25
-        if ($params['upcomingOnly']) {
26
-            return _t('CWP\\CWP\\PageTypes\\EventHolder.Upcoming', 'Upcoming events');
27
-        }
22
+	public function getUpdateName()
23
+	{
24
+		$params = $this->parseParams();
25
+		if ($params['upcomingOnly']) {
26
+			return _t('CWP\\CWP\\PageTypes\\EventHolder.Upcoming', 'Upcoming events');
27
+		}
28 28
 
29
-        return 'Events';
30
-    }
29
+		return 'Events';
30
+	}
31 31
 
32
-    /**
33
-     * Parse URL parameters.
34
-     *
35
-     * @param boolean $produceErrorMessages Set to false to omit session messages.
36
-     */
37
-    public function parseParams($produceErrorMessages = true)
38
-    {
39
-        $params = parent::parseParams($produceErrorMessages);
32
+	/**
33
+	 * Parse URL parameters.
34
+	 *
35
+	 * @param boolean $produceErrorMessages Set to false to omit session messages.
36
+	 */
37
+	public function parseParams($produceErrorMessages = true)
38
+	{
39
+		$params = parent::parseParams($produceErrorMessages);
40 40
 
41
-        // We need to set whether or not we're supposed to be displaying only upcoming events or all events.
42
-        $params['upcomingOnly'] = !($params['from'] || $params['to'] || $params['year'] || $params['month']);
41
+		// We need to set whether or not we're supposed to be displaying only upcoming events or all events.
42
+		$params['upcomingOnly'] = !($params['from'] || $params['to'] || $params['year'] || $params['month']);
43 43
 
44
-        return $params;
45
-    }
44
+		return $params;
45
+	}
46 46
 
47
-    /**
48
-     * Get the events based on the current query.
49
-     */
50
-    public function FilteredUpdates($pageSize = 20)
51
-    {
52
-        $params = $this->parseParams();
47
+	/**
48
+	 * Get the events based on the current query.
49
+	 */
50
+	public function FilteredUpdates($pageSize = 20)
51
+	{
52
+		$params = $this->parseParams();
53 53
 
54
-        $items = $this->Updates(
55
-            $params['tag'],
56
-            $params['from'],
57
-            $params['to'],
58
-            $params['year'],
59
-            $params['month']
60
-        );
54
+		$items = $this->Updates(
55
+			$params['tag'],
56
+			$params['from'],
57
+			$params['to'],
58
+			$params['year'],
59
+			$params['month']
60
+		);
61 61
 
62
-        if ($params['upcomingOnly']) {
63
-            $items = $items->filter(['Date:LessThan:Not' => DBDatetime::now()->Format('y-MM-dd')]);
64
-        }
62
+		if ($params['upcomingOnly']) {
63
+			$items = $items->filter(['Date:LessThan:Not' => DBDatetime::now()->Format('y-MM-dd')]);
64
+		}
65 65
 
66
-        // Apply pagination
67
-        $list = PaginatedList::create($items, $this->getRequest());
68
-        $list->setPageLength($pageSize);
69
-        return $list;
70
-    }
66
+		// Apply pagination
67
+		$list = PaginatedList::create($items, $this->getRequest());
68
+		$list->setPageLength($pageSize);
69
+		return $list;
70
+	}
71 71
 }
Please login to merge, or discard this patch.
src/PageTypes/EventPage.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -12,81 +12,81 @@
 block discarded – undo
12 12
 
13 13
 class EventPage extends DatedUpdatePage
14 14
 {
15
-    private static $description = 'Describes an event occurring on a specific date.';
16
-
17
-    private static $default_parent = EventHolder::class;
18
-
19
-    private static $can_be_root = false;
20
-
21
-    private static $icon = 'cwp/cwp:images/icons/sitetree_images/event_page.png';
22
-
23
-    private static $singular_name = 'Event Page';
24
-
25
-    private static $plural_name = 'Event Pages';
26
-
27
-    private static $db = [
28
-        'StartTime' => 'Time',
29
-        'EndTime' => 'Time',
30
-        'Location' => 'Text',
31
-    ];
32
-
33
-    private static $table_name = 'EventPage';
34
-
35
-    public function fieldLabels($includerelations = true)
36
-    {
37
-        $labels = parent::fieldLabels($includerelations);
38
-        $labels['StartTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.StartTimeFieldLabel', 'Start Time');
39
-        $labels['EndTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.EndTimeFieldLabel', 'End Time');
40
-        $labels['Location'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.LocationFieldLabel', 'Location');
41
-
42
-        return $labels;
43
-    }
44
-
45
-    /**
46
-     * Add the default for the Date being the current day.
47
-     */
48
-    public function populateDefaults()
49
-    {
50
-        if (!isset($this->Date) || $this->Date === null) {
51
-            $this->Date = DBDatetime::now()->Format('y-MM-dd');
52
-        }
53
-
54
-        if (!isset($this->StartTime) || $this->StartTime === null) {
55
-            $this->StartTime = '09:00:00';
56
-        }
57
-
58
-        if (!isset($this->EndTime) || $this->EndTime === null) {
59
-            $this->EndTime = '17:00:00';
60
-        }
61
-
62
-        parent::populateDefaults();
63
-    }
64
-
65
-    public function getCMSFields()
66
-    {
67
-        $this->beforeUpdateCMSFields(function (FieldList $fields) {
68
-            $fields->removeByName('Date');
69
-
70
-            $dateTimeFields = array();
71
-
72
-            $dateTimeFields[] = $dateField = DateField::create('Date', 'Date');
73
-            $dateTimeFields[] = $startTimeField = TimeField::create(
74
-                'StartTime',
75
-                '  ' . $this->fieldLabel('StartTime')
76
-            );
77
-            $dateTimeFields[] = $endTimeField = TimeField::create('EndTime', $this->fieldLabel('EndTime'));
78
-
79
-            $fields->addFieldsToTab('Root.Main', [
80
-                $dateTimeField = FieldGroup::create('Date and time', $dateTimeFields),
81
-                $locationField = TextareaField::create('Location', $this->fieldLabel('Location'))
82
-            ], 'Abstract');
83
-            $locationField->setRows(4);
84
-        });
85
-        return parent::getCMSFields();
86
-    }
87
-
88
-    public function NiceLocation()
89
-    {
90
-        return nl2br(Convert::raw2xml($this->Location), true);
91
-    }
15
+	private static $description = 'Describes an event occurring on a specific date.';
16
+
17
+	private static $default_parent = EventHolder::class;
18
+
19
+	private static $can_be_root = false;
20
+
21
+	private static $icon = 'cwp/cwp:images/icons/sitetree_images/event_page.png';
22
+
23
+	private static $singular_name = 'Event Page';
24
+
25
+	private static $plural_name = 'Event Pages';
26
+
27
+	private static $db = [
28
+		'StartTime' => 'Time',
29
+		'EndTime' => 'Time',
30
+		'Location' => 'Text',
31
+	];
32
+
33
+	private static $table_name = 'EventPage';
34
+
35
+	public function fieldLabels($includerelations = true)
36
+	{
37
+		$labels = parent::fieldLabels($includerelations);
38
+		$labels['StartTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.StartTimeFieldLabel', 'Start Time');
39
+		$labels['EndTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.EndTimeFieldLabel', 'End Time');
40
+		$labels['Location'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.LocationFieldLabel', 'Location');
41
+
42
+		return $labels;
43
+	}
44
+
45
+	/**
46
+	 * Add the default for the Date being the current day.
47
+	 */
48
+	public function populateDefaults()
49
+	{
50
+		if (!isset($this->Date) || $this->Date === null) {
51
+			$this->Date = DBDatetime::now()->Format('y-MM-dd');
52
+		}
53
+
54
+		if (!isset($this->StartTime) || $this->StartTime === null) {
55
+			$this->StartTime = '09:00:00';
56
+		}
57
+
58
+		if (!isset($this->EndTime) || $this->EndTime === null) {
59
+			$this->EndTime = '17:00:00';
60
+		}
61
+
62
+		parent::populateDefaults();
63
+	}
64
+
65
+	public function getCMSFields()
66
+	{
67
+		$this->beforeUpdateCMSFields(function (FieldList $fields) {
68
+			$fields->removeByName('Date');
69
+
70
+			$dateTimeFields = array();
71
+
72
+			$dateTimeFields[] = $dateField = DateField::create('Date', 'Date');
73
+			$dateTimeFields[] = $startTimeField = TimeField::create(
74
+				'StartTime',
75
+				'  ' . $this->fieldLabel('StartTime')
76
+			);
77
+			$dateTimeFields[] = $endTimeField = TimeField::create('EndTime', $this->fieldLabel('EndTime'));
78
+
79
+			$fields->addFieldsToTab('Root.Main', [
80
+				$dateTimeField = FieldGroup::create('Date and time', $dateTimeFields),
81
+				$locationField = TextareaField::create('Location', $this->fieldLabel('Location'))
82
+			], 'Abstract');
83
+			$locationField->setRows(4);
84
+		});
85
+		return parent::getCMSFields();
86
+	}
87
+
88
+	public function NiceLocation()
89
+	{
90
+		return nl2br(Convert::raw2xml($this->Location), true);
91
+	}
92 92
 }
Please login to merge, or discard this patch.
src/PageTypes/NewsPage.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -9,55 +9,55 @@
 block discarded – undo
9 9
 
10 10
 class NewsPage extends DatedUpdatePage
11 11
 {
12
-    private static $description = 'Describes an item of news';
12
+	private static $description = 'Describes an item of news';
13 13
 
14
-    private static $default_parent = 'NewsHolderPage';
14
+	private static $default_parent = 'NewsHolderPage';
15 15
 
16
-    private static $can_be_root = false;
16
+	private static $can_be_root = false;
17 17
 
18
-    private static $icon = 'cwp/cwp:images/icons/sitetree_images/news.png';
18
+	private static $icon = 'cwp/cwp:images/icons/sitetree_images/news.png';
19 19
 
20
-    private static $singular_name = 'News Page';
20
+	private static $singular_name = 'News Page';
21 21
 
22
-    private static $plural_name = 'News Pages';
22
+	private static $plural_name = 'News Pages';
23 23
 
24
-    private static $db = [
25
-        'Author' => 'Varchar(255)',
26
-    ];
24
+	private static $db = [
25
+		'Author' => 'Varchar(255)',
26
+	];
27 27
 
28
-    private static $has_one = [
29
-        'FeaturedImage' => Image::class,
30
-    ];
28
+	private static $has_one = [
29
+		'FeaturedImage' => Image::class,
30
+	];
31 31
 
32
-    private static $table_name = 'NewsPage';
32
+	private static $table_name = 'NewsPage';
33 33
 
34
-    public function fieldLabels($includerelations = true)
35
-    {
36
-        $labels = parent::fieldLabels($includerelations);
37
-        $labels['Author'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.AuthorFieldLabel', 'Author');
38
-        $labels['FeaturedImageID'] = _t(
39
-            'CWP\\CWP\\PageTypes\\DateUpdatePage.FeaturedImageFieldLabel',
40
-            'Featured Image'
41
-        );
34
+	public function fieldLabels($includerelations = true)
35
+	{
36
+		$labels = parent::fieldLabels($includerelations);
37
+		$labels['Author'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.AuthorFieldLabel', 'Author');
38
+		$labels['FeaturedImageID'] = _t(
39
+			'CWP\\CWP\\PageTypes\\DateUpdatePage.FeaturedImageFieldLabel',
40
+			'Featured Image'
41
+		);
42 42
 
43
-        return $labels;
44
-    }
43
+		return $labels;
44
+	}
45 45
 
46
-    public function getCMSFields()
47
-    {
48
-        $this->beforeUpdateCMSFields(function (FieldList $fields) {
49
-            $fields->addFieldToTab(
50
-                'Root.Main',
51
-                TextField::create('Author', $this->fieldLabel('Author')),
52
-                'Abstract'
53
-            );
46
+	public function getCMSFields()
47
+	{
48
+		$this->beforeUpdateCMSFields(function (FieldList $fields) {
49
+			$fields->addFieldToTab(
50
+				'Root.Main',
51
+				TextField::create('Author', $this->fieldLabel('Author')),
52
+				'Abstract'
53
+			);
54 54
 
55
-            $fields->addFieldToTab(
56
-                'Root.Main',
57
-                UploadField::create('FeaturedImage', $this->fieldLabel('FeaturedImageID')),
58
-                'Abstract'
59
-            );
60
-        });
61
-        return parent::getCMSFields();
62
-    }
55
+			$fields->addFieldToTab(
56
+				'Root.Main',
57
+				UploadField::create('FeaturedImage', $this->fieldLabel('FeaturedImageID')),
58
+				'Abstract'
59
+			);
60
+		});
61
+		return parent::getCMSFields();
62
+	}
63 63
 }
Please login to merge, or discard this patch.
tests/Tasks/CleanupGeneratedPdfDailyTaskTest.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -9,26 +9,26 @@
 block discarded – undo
9 9
 
10 10
 class CleanupGeneratedPdfDailyTaskTest extends SapphireTest
11 11
 {
12
-    /**
13
-     * @var CleanupGeneratedPdfDailyTask
14
-     */
15
-    protected $task;
12
+	/**
13
+	 * @var CleanupGeneratedPdfDailyTask
14
+	 */
15
+	protected $task;
16 16
 
17
-    protected function setUp()
18
-    {
19
-        parent::setUp();
17
+	protected function setUp()
18
+	{
19
+		parent::setUp();
20 20
 
21
-        if (!interface_exists(CronTask::class)) {
22
-            $this->markTestSkipped('Test class requires the silverstripe/crontask module to be installed');
23
-        }
21
+		if (!interface_exists(CronTask::class)) {
22
+			$this->markTestSkipped('Test class requires the silverstripe/crontask module to be installed');
23
+		}
24 24
 
25
-        $this->task = new CleanupGeneratedPdfDailyTask();
26
-    }
25
+		$this->task = new CleanupGeneratedPdfDailyTask();
26
+	}
27 27
 
28
-    public function testCronScheduleIsConfigurable()
29
-    {
30
-        Config::modify()->set(CleanupGeneratedPdfDailyTask::class, 'schedule', '* 1 2 3 *');
28
+	public function testCronScheduleIsConfigurable()
29
+	{
30
+		Config::modify()->set(CleanupGeneratedPdfDailyTask::class, 'schedule', '* 1 2 3 *');
31 31
 
32
-        $this->assertSame('* 1 2 3 *', $this->task->getSchedule());
33
-    }
32
+		$this->assertSame('* 1 2 3 *', $this->task->getSchedule());
33
+	}
34 34
 }
Please login to merge, or discard this patch.
src/Tasks/CleanupGeneratedPdfDailyTask.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use SilverStripe\CronTask\Interfaces\CronTask;
8 8
 
9 9
 if (!interface_exists(CronTask::class)) {
10
-    return;
10
+	return;
11 11
 }
12 12
 
13 13
 /**
@@ -15,36 +15,36 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class CleanupGeneratedPdfDailyTask implements CronTask
17 17
 {
18
-    use Configurable;
19
-
20
-    /**
21
-     * The cron schedule for this task (default: midnight every day)
22
-     *
23
-     * @config
24
-     * @var string
25
-     */
26
-    private static $schedule = '0 0 * * *';
27
-
28
-    /**
29
-     * Whether this task is enabled (default false)
30
-     *
31
-     * @config
32
-     * @return bool
33
-     */
34
-    private static $enabled = false;
35
-
36
-    public function getSchedule()
37
-    {
38
-        return $this->config()->get('schedule');
39
-    }
40
-
41
-    public function process()
42
-    {
43
-        if (!$this->config()->get('enabled')) {
44
-            return;
45
-        }
46
-
47
-        $task = Injector::inst()->create(CleanupGeneratedPdfBuildTask::class);
48
-        $task->run(null);
49
-    }
18
+	use Configurable;
19
+
20
+	/**
21
+	 * The cron schedule for this task (default: midnight every day)
22
+	 *
23
+	 * @config
24
+	 * @var string
25
+	 */
26
+	private static $schedule = '0 0 * * *';
27
+
28
+	/**
29
+	 * Whether this task is enabled (default false)
30
+	 *
31
+	 * @config
32
+	 * @return bool
33
+	 */
34
+	private static $enabled = false;
35
+
36
+	public function getSchedule()
37
+	{
38
+		return $this->config()->get('schedule');
39
+	}
40
+
41
+	public function process()
42
+	{
43
+		if (!$this->config()->get('enabled')) {
44
+			return;
45
+		}
46
+
47
+		$task = Injector::inst()->create(CleanupGeneratedPdfBuildTask::class);
48
+		$task->run(null);
49
+	}
50 50
 }
Please login to merge, or discard this patch.
src/Tasks/CleanupGeneratedPdfBuildTask.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -7,24 +7,24 @@
 block discarded – undo
7 7
 
8 8
 class CleanupGeneratedPdfBuildTask extends BuildTask
9 9
 {
10
-    protected $title = 'Cleanup generated PDFs';
10
+	protected $title = 'Cleanup generated PDFs';
11 11
 
12
-    protected $description = 'Removes generated PDFs on the site, forcing a regeneration of all exports to PDF '
13
-        . 'when users go to download them. This is most useful when templates have been changed so users should '
14
-        . 'receive a new copy';
12
+	protected $description = 'Removes generated PDFs on the site, forcing a regeneration of all exports to PDF '
13
+		. 'when users go to download them. This is most useful when templates have been changed so users should '
14
+		. 'receive a new copy';
15 15
 
16
-    public function run($request)
17
-    {
18
-        $path = sprintf('%s/%s', BASE_PATH, BasePage::config()->get('generated_pdf_path'));
19
-        if (!file_exists($path)) {
20
-            return false;
21
-        }
16
+	public function run($request)
17
+	{
18
+		$path = sprintf('%s/%s', BASE_PATH, BasePage::config()->get('generated_pdf_path'));
19
+		if (!file_exists($path)) {
20
+			return false;
21
+		}
22 22
 
23
-        exec(sprintf('if [ "$(ls -A %s 2> /dev/null)" != "" ]; then rm %s/*; fi', $path, $path), $output, $return_val);
23
+		exec(sprintf('if [ "$(ls -A %s 2> /dev/null)" != "" ]; then rm %s/*; fi', $path, $path), $output, $return_val);
24 24
 
25
-        // output any errors
26
-        if ($return_val != 0) {
27
-            user_error(sprintf('%s failed: ', get_class($this)) . implode("\n", $output), E_USER_ERROR);
28
-        }
29
-    }
25
+		// output any errors
26
+		if ($return_val != 0) {
27
+			user_error(sprintf('%s failed: ', get_class($this)) . implode("\n", $output), E_USER_ERROR);
28
+		}
29
+	}
30 30
 }
Please login to merge, or discard this patch.
src/PageTypes/SitemapPageController.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -7,42 +7,42 @@
 block discarded – undo
7 7
 
8 8
 class SitemapPageController extends PageController
9 9
 {
10
-    private static $allowed_actions = [
11
-        'showpage',
12
-    ];
13
-
14
-    private static $url_handlers = [
15
-        'page/$ID' => 'showpage',
16
-    ];
17
-
18
-    public function showpage($request)
19
-    {
20
-        $id = (int) $request->param('ID');
21
-        if (!$id) {
22
-            return false;
23
-        }
24
-        $page = SiteTree::get()->byId($id);
25
-
26
-        // does the page exist?
27
-        if (!($page && $page->exists())) {
28
-            return $this->httpError(404);
29
-        }
30
-
31
-        // can the page be viewed?
32
-        if (!$page->canView()) {
33
-            return $this->httpError(403);
34
-        }
35
-
36
-        $viewer = $this->customise([
37
-            'IsAjax' => $request->isAjax(),
38
-            'SelectedPage' => $page,
39
-            'Children' => $page->Children(),
40
-        ]);
41
-
42
-        if ($request->isAjax()) {
43
-            return $viewer->renderWith('SitemapNodeChildren');
44
-        }
45
-
46
-        return $viewer;
47
-    }
10
+	private static $allowed_actions = [
11
+		'showpage',
12
+	];
13
+
14
+	private static $url_handlers = [
15
+		'page/$ID' => 'showpage',
16
+	];
17
+
18
+	public function showpage($request)
19
+	{
20
+		$id = (int) $request->param('ID');
21
+		if (!$id) {
22
+			return false;
23
+		}
24
+		$page = SiteTree::get()->byId($id);
25
+
26
+		// does the page exist?
27
+		if (!($page && $page->exists())) {
28
+			return $this->httpError(404);
29
+		}
30
+
31
+		// can the page be viewed?
32
+		if (!$page->canView()) {
33
+			return $this->httpError(403);
34
+		}
35
+
36
+		$viewer = $this->customise([
37
+			'IsAjax' => $request->isAjax(),
38
+			'SelectedPage' => $page,
39
+			'Children' => $page->Children(),
40
+		]);
41
+
42
+		if ($request->isAjax()) {
43
+			return $viewer->renderWith('SitemapNodeChildren');
44
+		}
45
+
46
+		return $viewer;
47
+	}
48 48
 }
Please login to merge, or discard this patch.
src/PageTypes/BasePage.php 1 patch
Indentation   +298 added lines, -298 removed lines patch added patch discarded remove patch
@@ -28,302 +28,302 @@
 block discarded – undo
28 28
 
29 29
 class BasePage extends SiteTree
30 30
 {
31
-    private static $icon = 'cwp/cwp:images/icons/sitetree_images/page.png';
32
-
33
-    /**
34
-     * Hide this page type from the CMS. hide_ancestor is slightly misnamed, should really be just "hide"
35
-     *
36
-     * {@inheritDoc}
37
-     */
38
-    private static $hide_ancestor = BasePage::class;
39
-
40
-    /**
41
-     * @config
42
-     * @var bool
43
-     */
44
-    private static $pdf_export = false;
45
-
46
-    /**
47
-     * Domain to generate PDF's from, DOES not include protocol
48
-     * i.e. google.com not http://google.com
49
-     * @config
50
-     * @var string
51
-     */
52
-    private static $pdf_base_url = "";
53
-
54
-    /**
55
-     * Allow custom overriding of the path to the WKHTMLTOPDF binary, in cases
56
-     * where multiple versions of the binary are available to choose from. This
57
-     * should be the full path to the binary (e.g. /usr/local/bin/wkhtmltopdf)
58
-     * @see BasePage_Controller::generatePDF();
59
-     *
60
-     * @config
61
-     * @var string|null
62
-     */
63
-    private static $wkhtmltopdf_binary = null;
64
-
65
-    /**
66
-     * Where to store generated PDF files
67
-     *
68
-     * @config
69
-     * @var string
70
-     */
71
-    private static $generated_pdf_path = 'assets/_generated_pdfs';
72
-
73
-    private static $api_access = [
74
-        'view' => [
75
-            'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription',
76
-            'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID'
77
-        ],
78
-        'edit' => [
79
-            'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription',
80
-            'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID'
81
-        ],
82
-    ];
83
-
84
-    private static $table_name = 'BasePage';
85
-
86
-    /**
87
-     * @config
88
-     * @var string
89
-     */
90
-    private static $related_pages_title = 'Related pages';
91
-
92
-    private static $many_many = [
93
-        'Terms' => TaxonomyTerm::class,
94
-        'RelatedPages' => BasePage::class,
95
-    ];
96
-
97
-    private static $many_many_extraFields = [
98
-        'RelatedPages' => [
99
-            'SortOrder' => 'Int',
100
-        ],
101
-    ];
102
-
103
-    private static $plural_name = 'Base Pages';
104
-
105
-    /**
106
-     * Get the footer holder.
107
-     */
108
-    public function getFooter()
109
-    {
110
-        return FooterHolder::get_one(FooterHolder::class);
111
-    }
112
-
113
-    /**
114
-     * Return the full filename of the pdf file, including path & extension
115
-     */
116
-    public function getPdfFilename()
117
-    {
118
-        $baseName = sprintf('%s-%s', $this->URLSegment, $this->ID);
119
-
120
-        $folderPath = $this->config()->get('generated_pdf_path');
121
-        if ($folderPath[0] != '/') {
122
-            $folderPath = BASE_PATH . '/' . $folderPath;
123
-        }
124
-
125
-        return sprintf('%s/%s.pdf', $folderPath, $baseName);
126
-    }
127
-
128
-    /**
129
-     * Build pdf link for template.
130
-     */
131
-    public function PdfLink()
132
-    {
133
-        if (!$this->config()->get('pdf_export')) {
134
-            return false;
135
-        }
136
-
137
-        $path = $this->getPdfFilename();
138
-
139
-        if ((Versioned::get_stage() === Versioned::LIVE) && file_exists($path)) {
140
-            return Director::baseURL() . preg_replace('#^/#', '', Director::makeRelative($path));
141
-        }
142
-        return $this->Link('downloadpdf');
143
-    }
144
-
145
-    public function RelatedPages()
146
-    {
147
-        return $this->getManyManyComponents('RelatedPages')->sort('SortOrder');
148
-    }
149
-
150
-    public function RelatedPagesTitle()
151
-    {
152
-        return $this->config()->get('related_pages_title');
153
-    }
154
-
155
-    /**
156
-     * Remove linked pdf when publishing the page,
157
-     * as it would be out of date.
158
-     */
159
-    public function onAfterPublish()
160
-    {
161
-        $filepath = $this->getPdfFilename();
162
-        if (file_exists($filepath)) {
163
-            unlink($filepath);
164
-        }
165
-    }
166
-
167
-    /**
168
-     * Remove linked pdf when unpublishing the page,
169
-     * so it's no longer valid.
170
-     *
171
-     * @return boolean
172
-     */
173
-    public function doUnpublish()
174
-    {
175
-        if (!parent::doUnpublish()) {
176
-            return false;
177
-        }
178
-
179
-        $filepath = $this->getPdfFilename();
180
-        if (file_exists($filepath)) {
181
-            unlink($filepath);
182
-        }
183
-
184
-        return true;
185
-    }
186
-
187
-    public function getCMSFields()
188
-    {
189
-        $this->beforeUpdateCMSFields(function (FieldList $fields) {
190
-            // Related Pages
191
-            $components = GridFieldConfig_RelationEditor::create();
192
-            $components->removeComponentsByType(GridFieldAddNewButton::class);
193
-            $components->removeComponentsByType(GridFieldEditButton::class);
194
-            $components->removeComponentsByType(GridFieldFilterHeader::class);
195
-            $components->addComponent(new GridFieldSortableRows('SortOrder'));
196
-
197
-            /** @var GridFieldDataColumns $dataColumns */
198
-            $dataColumns = $components->getComponentByType(GridFieldDataColumns::class);
199
-            $dataColumns->setDisplayFields([
200
-                'Title' => _t(__CLASS__ . '.ColumnTitle', 'Title'),
201
-                'ClassName' => _t(__CLASS__ . '.ColumnPageType', 'Page Type')
202
-            ]);
203
-
204
-            $fields->findOrMakeTab(
205
-                'Root.RelatedPages',
206
-                _t(__CLASS__ . '.RelatedPages', 'Related pages')
207
-            );
208
-            $fields->addFieldToTab(
209
-                'Root.RelatedPages',
210
-                GridField::create(
211
-                    'RelatedPages',
212
-                    _t(__CLASS__ . '.RelatedPages', 'Related pages'),
213
-                    $this->RelatedPages(),
214
-                    $components
215
-                )
216
-            );
217
-
218
-            // Taxonomies - Unless they have their own 'Tags' field (such as in Blog, etc)
219
-            $hasMany = $this->hasMany();
220
-            $manyMany = $this->manyMany();
221
-            if (!isset($hasMany['Tags']) && !isset($manyMany['Tags'])) {
222
-                $components = GridFieldConfig_RelationEditor::create();
223
-                $components->removeComponentsByType(GridFieldAddNewButton::class);
224
-                $components->removeComponentsByType(GridFieldEditButton::class);
225
-
226
-                /** @var GridFieldAddExistingAutocompleter $autoCompleter */
227
-                $autoCompleter = $components->getComponentByType(GridFieldAddExistingAutocompleter::class);
228
-                $autoCompleter->setResultsFormat('$Name ($TaxonomyName)');
229
-
230
-                /** @var GridFieldDataColumns $dataColumns */
231
-                $dataColumns = $components->getComponentByType(GridFieldDataColumns::class);
232
-                $dataColumns->setDisplayFields([
233
-                    'Name' => _t(__CLASS__ . '.Term', 'Term'),
234
-                    'TaxonomyName' => _t(__CLASS__ . '.Taxonomy', 'Taxonomy')
235
-                ]);
236
-
237
-                $fields->findOrMakeTab('Root.Tags', _t(__CLASS__ . '.TagsTabTitle', 'Tags'));
238
-                $fields->addFieldToTab(
239
-                    'Root.Tags',
240
-                    TreeMultiselectField::create(
241
-                        'Terms',
242
-                        _t(__CLASS__ . '.Terms', 'Terms'),
243
-                        TaxonomyTerm::class
244
-                    )->setDescription(_t(__CLASS__ . '.TermsDescription', 'Click to search for additional terms'))
245
-                );
246
-            }
247
-        });
248
-        return parent::getCMSFields();
249
-    }
250
-
251
-    /**
252
-     * Provides data for translation navigation.
253
-     * Collects all site translations, marks the current one, and redirects
254
-     * to the translated home page if a. there is a translated homepage and b. the
255
-     * translation of the specific page is not available.
256
-     * @todo re-implement with Fluent
257
-     */
258
-    public function getAvailableTranslations()
259
-    {
260
-        if (!class_exists('Translatable')) {
261
-            return false;
262
-        }
263
-
264
-        $translations = new ArrayList();
265
-        $globalTranslations = Translatable::get_existing_content_languages();
266
-
267
-        foreach ($globalTranslations as $loc => $langName) {
268
-            // Find out the language name in native language.
269
-            $nativeLangName = i18n::get_language_name($loc, true);
270
-            if (!$nativeLangName) {
271
-                $nativeLangName = i18n::get_language_name(i18n::get_lang_from_locale($loc), true);
272
-            }
273
-            if (!$nativeLangName) {
274
-                // Fall back to the locale name.
275
-                $nativeLangName = $langName;
276
-            }
277
-
278
-            // Eliminate the part in brackets (e.g. [mandarin])
279
-            $nativeLangName = preg_replace('/ *[\(\[].*$/', '', $nativeLangName);
280
-
281
-            // Find out the link to the translated page.
282
-            $link = null;
283
-            $page = $this->getTranslation($loc);
284
-            if ($page) {
285
-                $link = $page->Link();
286
-            }
287
-            if (!$link) {
288
-                // Fall back to the home page
289
-                $link = Translatable::get_homepage_link_by_locale($loc);
290
-            }
291
-            if (!$link) {
292
-                continue;
293
-            }
294
-
295
-            // Assemble the table for the switcher.
296
-            $translations->push(new ArrayData(array(
297
-                'Locale' => i18n::convert_rfc1766($loc),
298
-                'LangName' => $nativeLangName,
299
-                'Link' => $link,
300
-                'Current' => (Translatable::get_current_locale()==$loc)
301
-            )));
302
-        }
303
-
304
-        if ($translations->count()>1) {
305
-            return $translations;
306
-        } else {
307
-            return null;
308
-        }
309
-    }
310
-
311
-    /**
312
-     * Returns the native language name for the selected locale/language, empty string if Translatable is not available
313
-     *
314
-     * @return string
315
-     * @todo re-implement with Fluent
316
-     */
317
-    public function getSelectedLanguage()
318
-    {
319
-        if (!class_exists('Translatable')) {
320
-            return '';
321
-        }
322
-
323
-        $language = explode('_', Translatable::get_current_locale());
324
-        $languageCode = array_shift($language);
325
-        $nativeName = i18n::get_language_name($languageCode, true);
326
-
327
-        return $nativeName;
328
-    }
31
+	private static $icon = 'cwp/cwp:images/icons/sitetree_images/page.png';
32
+
33
+	/**
34
+	 * Hide this page type from the CMS. hide_ancestor is slightly misnamed, should really be just "hide"
35
+	 *
36
+	 * {@inheritDoc}
37
+	 */
38
+	private static $hide_ancestor = BasePage::class;
39
+
40
+	/**
41
+	 * @config
42
+	 * @var bool
43
+	 */
44
+	private static $pdf_export = false;
45
+
46
+	/**
47
+	 * Domain to generate PDF's from, DOES not include protocol
48
+	 * i.e. google.com not http://google.com
49
+	 * @config
50
+	 * @var string
51
+	 */
52
+	private static $pdf_base_url = "";
53
+
54
+	/**
55
+	 * Allow custom overriding of the path to the WKHTMLTOPDF binary, in cases
56
+	 * where multiple versions of the binary are available to choose from. This
57
+	 * should be the full path to the binary (e.g. /usr/local/bin/wkhtmltopdf)
58
+	 * @see BasePage_Controller::generatePDF();
59
+	 *
60
+	 * @config
61
+	 * @var string|null
62
+	 */
63
+	private static $wkhtmltopdf_binary = null;
64
+
65
+	/**
66
+	 * Where to store generated PDF files
67
+	 *
68
+	 * @config
69
+	 * @var string
70
+	 */
71
+	private static $generated_pdf_path = 'assets/_generated_pdfs';
72
+
73
+	private static $api_access = [
74
+		'view' => [
75
+			'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription',
76
+			'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID'
77
+		],
78
+		'edit' => [
79
+			'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription',
80
+			'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID'
81
+		],
82
+	];
83
+
84
+	private static $table_name = 'BasePage';
85
+
86
+	/**
87
+	 * @config
88
+	 * @var string
89
+	 */
90
+	private static $related_pages_title = 'Related pages';
91
+
92
+	private static $many_many = [
93
+		'Terms' => TaxonomyTerm::class,
94
+		'RelatedPages' => BasePage::class,
95
+	];
96
+
97
+	private static $many_many_extraFields = [
98
+		'RelatedPages' => [
99
+			'SortOrder' => 'Int',
100
+		],
101
+	];
102
+
103
+	private static $plural_name = 'Base Pages';
104
+
105
+	/**
106
+	 * Get the footer holder.
107
+	 */
108
+	public function getFooter()
109
+	{
110
+		return FooterHolder::get_one(FooterHolder::class);
111
+	}
112
+
113
+	/**
114
+	 * Return the full filename of the pdf file, including path & extension
115
+	 */
116
+	public function getPdfFilename()
117
+	{
118
+		$baseName = sprintf('%s-%s', $this->URLSegment, $this->ID);
119
+
120
+		$folderPath = $this->config()->get('generated_pdf_path');
121
+		if ($folderPath[0] != '/') {
122
+			$folderPath = BASE_PATH . '/' . $folderPath;
123
+		}
124
+
125
+		return sprintf('%s/%s.pdf', $folderPath, $baseName);
126
+	}
127
+
128
+	/**
129
+	 * Build pdf link for template.
130
+	 */
131
+	public function PdfLink()
132
+	{
133
+		if (!$this->config()->get('pdf_export')) {
134
+			return false;
135
+		}
136
+
137
+		$path = $this->getPdfFilename();
138
+
139
+		if ((Versioned::get_stage() === Versioned::LIVE) && file_exists($path)) {
140
+			return Director::baseURL() . preg_replace('#^/#', '', Director::makeRelative($path));
141
+		}
142
+		return $this->Link('downloadpdf');
143
+	}
144
+
145
+	public function RelatedPages()
146
+	{
147
+		return $this->getManyManyComponents('RelatedPages')->sort('SortOrder');
148
+	}
149
+
150
+	public function RelatedPagesTitle()
151
+	{
152
+		return $this->config()->get('related_pages_title');
153
+	}
154
+
155
+	/**
156
+	 * Remove linked pdf when publishing the page,
157
+	 * as it would be out of date.
158
+	 */
159
+	public function onAfterPublish()
160
+	{
161
+		$filepath = $this->getPdfFilename();
162
+		if (file_exists($filepath)) {
163
+			unlink($filepath);
164
+		}
165
+	}
166
+
167
+	/**
168
+	 * Remove linked pdf when unpublishing the page,
169
+	 * so it's no longer valid.
170
+	 *
171
+	 * @return boolean
172
+	 */
173
+	public function doUnpublish()
174
+	{
175
+		if (!parent::doUnpublish()) {
176
+			return false;
177
+		}
178
+
179
+		$filepath = $this->getPdfFilename();
180
+		if (file_exists($filepath)) {
181
+			unlink($filepath);
182
+		}
183
+
184
+		return true;
185
+	}
186
+
187
+	public function getCMSFields()
188
+	{
189
+		$this->beforeUpdateCMSFields(function (FieldList $fields) {
190
+			// Related Pages
191
+			$components = GridFieldConfig_RelationEditor::create();
192
+			$components->removeComponentsByType(GridFieldAddNewButton::class);
193
+			$components->removeComponentsByType(GridFieldEditButton::class);
194
+			$components->removeComponentsByType(GridFieldFilterHeader::class);
195
+			$components->addComponent(new GridFieldSortableRows('SortOrder'));
196
+
197
+			/** @var GridFieldDataColumns $dataColumns */
198
+			$dataColumns = $components->getComponentByType(GridFieldDataColumns::class);
199
+			$dataColumns->setDisplayFields([
200
+				'Title' => _t(__CLASS__ . '.ColumnTitle', 'Title'),
201
+				'ClassName' => _t(__CLASS__ . '.ColumnPageType', 'Page Type')
202
+			]);
203
+
204
+			$fields->findOrMakeTab(
205
+				'Root.RelatedPages',
206
+				_t(__CLASS__ . '.RelatedPages', 'Related pages')
207
+			);
208
+			$fields->addFieldToTab(
209
+				'Root.RelatedPages',
210
+				GridField::create(
211
+					'RelatedPages',
212
+					_t(__CLASS__ . '.RelatedPages', 'Related pages'),
213
+					$this->RelatedPages(),
214
+					$components
215
+				)
216
+			);
217
+
218
+			// Taxonomies - Unless they have their own 'Tags' field (such as in Blog, etc)
219
+			$hasMany = $this->hasMany();
220
+			$manyMany = $this->manyMany();
221
+			if (!isset($hasMany['Tags']) && !isset($manyMany['Tags'])) {
222
+				$components = GridFieldConfig_RelationEditor::create();
223
+				$components->removeComponentsByType(GridFieldAddNewButton::class);
224
+				$components->removeComponentsByType(GridFieldEditButton::class);
225
+
226
+				/** @var GridFieldAddExistingAutocompleter $autoCompleter */
227
+				$autoCompleter = $components->getComponentByType(GridFieldAddExistingAutocompleter::class);
228
+				$autoCompleter->setResultsFormat('$Name ($TaxonomyName)');
229
+
230
+				/** @var GridFieldDataColumns $dataColumns */
231
+				$dataColumns = $components->getComponentByType(GridFieldDataColumns::class);
232
+				$dataColumns->setDisplayFields([
233
+					'Name' => _t(__CLASS__ . '.Term', 'Term'),
234
+					'TaxonomyName' => _t(__CLASS__ . '.Taxonomy', 'Taxonomy')
235
+				]);
236
+
237
+				$fields->findOrMakeTab('Root.Tags', _t(__CLASS__ . '.TagsTabTitle', 'Tags'));
238
+				$fields->addFieldToTab(
239
+					'Root.Tags',
240
+					TreeMultiselectField::create(
241
+						'Terms',
242
+						_t(__CLASS__ . '.Terms', 'Terms'),
243
+						TaxonomyTerm::class
244
+					)->setDescription(_t(__CLASS__ . '.TermsDescription', 'Click to search for additional terms'))
245
+				);
246
+			}
247
+		});
248
+		return parent::getCMSFields();
249
+	}
250
+
251
+	/**
252
+	 * Provides data for translation navigation.
253
+	 * Collects all site translations, marks the current one, and redirects
254
+	 * to the translated home page if a. there is a translated homepage and b. the
255
+	 * translation of the specific page is not available.
256
+	 * @todo re-implement with Fluent
257
+	 */
258
+	public function getAvailableTranslations()
259
+	{
260
+		if (!class_exists('Translatable')) {
261
+			return false;
262
+		}
263
+
264
+		$translations = new ArrayList();
265
+		$globalTranslations = Translatable::get_existing_content_languages();
266
+
267
+		foreach ($globalTranslations as $loc => $langName) {
268
+			// Find out the language name in native language.
269
+			$nativeLangName = i18n::get_language_name($loc, true);
270
+			if (!$nativeLangName) {
271
+				$nativeLangName = i18n::get_language_name(i18n::get_lang_from_locale($loc), true);
272
+			}
273
+			if (!$nativeLangName) {
274
+				// Fall back to the locale name.
275
+				$nativeLangName = $langName;
276
+			}
277
+
278
+			// Eliminate the part in brackets (e.g. [mandarin])
279
+			$nativeLangName = preg_replace('/ *[\(\[].*$/', '', $nativeLangName);
280
+
281
+			// Find out the link to the translated page.
282
+			$link = null;
283
+			$page = $this->getTranslation($loc);
284
+			if ($page) {
285
+				$link = $page->Link();
286
+			}
287
+			if (!$link) {
288
+				// Fall back to the home page
289
+				$link = Translatable::get_homepage_link_by_locale($loc);
290
+			}
291
+			if (!$link) {
292
+				continue;
293
+			}
294
+
295
+			// Assemble the table for the switcher.
296
+			$translations->push(new ArrayData(array(
297
+				'Locale' => i18n::convert_rfc1766($loc),
298
+				'LangName' => $nativeLangName,
299
+				'Link' => $link,
300
+				'Current' => (Translatable::get_current_locale()==$loc)
301
+			)));
302
+		}
303
+
304
+		if ($translations->count()>1) {
305
+			return $translations;
306
+		} else {
307
+			return null;
308
+		}
309
+	}
310
+
311
+	/**
312
+	 * Returns the native language name for the selected locale/language, empty string if Translatable is not available
313
+	 *
314
+	 * @return string
315
+	 * @todo re-implement with Fluent
316
+	 */
317
+	public function getSelectedLanguage()
318
+	{
319
+		if (!class_exists('Translatable')) {
320
+			return '';
321
+		}
322
+
323
+		$language = explode('_', Translatable::get_current_locale());
324
+		$languageCode = array_shift($language);
325
+		$nativeName = i18n::get_language_name($languageCode, true);
326
+
327
+		return $nativeName;
328
+	}
329 329
 }
Please login to merge, or discard this patch.