@@ -9,55 +9,55 @@ |
||
| 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 | } |
@@ -9,26 +9,26 @@ |
||
| 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 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 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 |
||
| 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 | } |
@@ -7,24 +7,24 @@ |
||
| 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 | } |
@@ -7,42 +7,42 @@ |
||
| 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 | } |
@@ -26,137 +26,137 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class BaseHomePage extends Page |
| 28 | 28 | { |
| 29 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/home.png'; |
|
| 30 | - |
|
| 31 | - private static $hide_ancestor = BaseHomePage::class; |
|
| 32 | - |
|
| 33 | - private static $singular_name = 'Home Page'; |
|
| 34 | - |
|
| 35 | - private static $plural_name = 'Home Pages'; |
|
| 36 | - |
|
| 37 | - private static $table_name = 'BaseHomePage'; |
|
| 38 | - |
|
| 39 | - private static $db = [ |
|
| 40 | - 'FeatureOneTitle' => 'Varchar(255)', |
|
| 41 | - 'FeatureOneCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')", |
|
| 42 | - 'FeatureOneContent' => 'HTMLText', |
|
| 43 | - 'FeatureOneButtonText' => 'Varchar(255)', |
|
| 44 | - 'FeatureTwoTitle' => 'Varchar(255)', |
|
| 45 | - 'FeatureTwoCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')", |
|
| 46 | - 'FeatureTwoContent' => 'HTMLText', |
|
| 47 | - 'FeatureTwoButtonText' => 'Varchar(255)' |
|
| 48 | - ]; |
|
| 49 | - |
|
| 50 | - private static $has_one = [ |
|
| 51 | - 'LearnMorePage' => SiteTree::class, |
|
| 52 | - 'FeatureOneLink' => SiteTree::class, |
|
| 53 | - 'FeatureTwoLink' => SiteTree::class, |
|
| 54 | - ]; |
|
| 55 | - |
|
| 56 | - private static $has_many = [ |
|
| 57 | - 'Quicklinks' => Quicklink::class . '.Parent', |
|
| 58 | - ]; |
|
| 59 | - |
|
| 60 | - public function Quicklinks() |
|
| 61 | - { |
|
| 62 | - return $this->getComponents('Quicklinks')->sort('SortOrder'); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function getCMSFields() |
|
| 66 | - { |
|
| 67 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 68 | - // Main Content tab |
|
| 69 | - $fields->addFieldToTab( |
|
| 70 | - 'Root.Main', |
|
| 71 | - TreeDropdownField::create( |
|
| 72 | - 'LearnMorePageID', |
|
| 73 | - _t(__CLASS__ . '.LearnMoreLink', 'Page to link the "Learn More" button to:'), |
|
| 74 | - SiteTree::class |
|
| 75 | - ), |
|
| 76 | - 'Metadata' |
|
| 77 | - ); |
|
| 78 | - |
|
| 79 | - $gridField = GridField::create( |
|
| 80 | - 'Quicklinks', |
|
| 81 | - 'Quicklinks', |
|
| 82 | - $this->Quicklinks(), |
|
| 83 | - GridFieldConfig_RelationEditor::create() |
|
| 84 | - ); |
|
| 85 | - $gridConfig = $gridField->getConfig(); |
|
| 86 | - $gridConfig->getComponentByType(GridFieldAddNewButton::class)->setButtonName( |
|
| 87 | - _t(__CLASS__ . '.AddNewButton', 'Add new') |
|
| 88 | - ); |
|
| 89 | - |
|
| 90 | - $injector = Injector::inst(); |
|
| 91 | - |
|
| 92 | - $gridConfig->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
| 93 | - $gridConfig->removeComponentsByType(GridFieldDeleteAction::class); |
|
| 94 | - $gridConfig->addComponent($injector->create(GridFieldDeleteAction::class)); |
|
| 95 | - $gridConfig->addComponent($injector->create(GridFieldSortableRows::class, 'SortOrder')); |
|
| 96 | - $gridField->setModelClass(Quicklink::class); |
|
| 97 | - |
|
| 98 | - $fields->addFieldToTab('Root.Quicklinks', $gridField); |
|
| 99 | - |
|
| 100 | - $fields->removeByName('Import'); |
|
| 101 | - |
|
| 102 | - $fields->addFieldToTab( |
|
| 103 | - 'Root.Features', |
|
| 104 | - ToggleCompositeField::create( |
|
| 105 | - 'FeatureOne', |
|
| 106 | - _t(__CLASS__ . '.FeatureOne', 'Feature One'), |
|
| 107 | - array( |
|
| 108 | - TextField::create('FeatureOneTitle', _t(__CLASS__ . '.Title', 'Title')), |
|
| 109 | - $dropdownField = DropdownField::create( |
|
| 110 | - 'FeatureOneCategory', |
|
| 111 | - _t(__CLASS__ . '.FeatureCategoryDropdown', 'Category icon'), |
|
| 112 | - singleton(BaseHomePage::class)->dbObject('FeatureOneCategory')->enumValues() |
|
| 113 | - ), |
|
| 114 | - HTMLEditorField::create( |
|
| 115 | - 'FeatureOneContent', |
|
| 116 | - _t(__CLASS__ . '.FeatureContentFieldLabel', 'Content') |
|
| 117 | - ), |
|
| 118 | - TextField::create( |
|
| 119 | - 'FeatureOneButtonText', |
|
| 120 | - _t(__CLASS__ . '.FeatureButtonText', 'Button text') |
|
| 121 | - ), |
|
| 122 | - TreeDropdownField::create( |
|
| 123 | - 'FeatureOneLinkID', |
|
| 124 | - _t(__CLASS__ . '.FeatureLink', 'Page to link to'), |
|
| 125 | - SiteTree::class |
|
| 126 | - )->setDescription(_t(__CLASS__ . '.ButtonTextRequired', 'Button text must be filled in')) |
|
| 127 | - ) |
|
| 128 | - )->setHeadingLevel(3) |
|
| 129 | - ); |
|
| 130 | - $dropdownField->setEmptyString('none'); |
|
| 131 | - |
|
| 132 | - $fields->addFieldToTab('Root.Features', ToggleCompositeField::create( |
|
| 133 | - 'FeatureTwo', |
|
| 134 | - _t(__CLASS__ . '.FeatureTwo', 'Feature Two'), |
|
| 135 | - array( |
|
| 136 | - TextField::create('FeatureTwoTitle', _t(__CLASS__ . '.Title', 'Title')), |
|
| 137 | - $dropdownField = DropdownField::create( |
|
| 138 | - 'FeatureTwoCategory', |
|
| 139 | - _t(__CLASS__ . '.FeatureCategoryDropdown', 'Category icon'), |
|
| 140 | - singleton(BaseHomePage::class)->dbObject('FeatureTwoCategory')->enumValues() |
|
| 141 | - ), |
|
| 142 | - HTMLEditorField::create( |
|
| 143 | - 'FeatureTwoContent', |
|
| 144 | - _t(__CLASS__ . '.FeatureContentFieldLabel', 'Content') |
|
| 145 | - ), |
|
| 146 | - TextField::create( |
|
| 147 | - 'FeatureTwoButtonText', |
|
| 148 | - _t(__CLASS__ . '.FeatureButtonText', 'Button text') |
|
| 149 | - ), |
|
| 150 | - TreeDropdownField::create( |
|
| 151 | - 'FeatureTwoLinkID', |
|
| 152 | - _t(__CLASS__ . '.FeatureLink', 'Page to link to'), |
|
| 153 | - SiteTree::class |
|
| 154 | - )->setDescription(_t(__CLASS__ . '.ButtonTextRequired', 'Button text must be filled in')) |
|
| 155 | - ) |
|
| 156 | - )->setHeadingLevel(3)); |
|
| 157 | - $dropdownField->setEmptyString('none'); |
|
| 158 | - }); |
|
| 159 | - |
|
| 160 | - return parent::getCMSFields(); |
|
| 161 | - } |
|
| 29 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/home.png'; |
|
| 30 | + |
|
| 31 | + private static $hide_ancestor = BaseHomePage::class; |
|
| 32 | + |
|
| 33 | + private static $singular_name = 'Home Page'; |
|
| 34 | + |
|
| 35 | + private static $plural_name = 'Home Pages'; |
|
| 36 | + |
|
| 37 | + private static $table_name = 'BaseHomePage'; |
|
| 38 | + |
|
| 39 | + private static $db = [ |
|
| 40 | + 'FeatureOneTitle' => 'Varchar(255)', |
|
| 41 | + 'FeatureOneCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')", |
|
| 42 | + 'FeatureOneContent' => 'HTMLText', |
|
| 43 | + 'FeatureOneButtonText' => 'Varchar(255)', |
|
| 44 | + 'FeatureTwoTitle' => 'Varchar(255)', |
|
| 45 | + 'FeatureTwoCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')", |
|
| 46 | + 'FeatureTwoContent' => 'HTMLText', |
|
| 47 | + 'FeatureTwoButtonText' => 'Varchar(255)' |
|
| 48 | + ]; |
|
| 49 | + |
|
| 50 | + private static $has_one = [ |
|
| 51 | + 'LearnMorePage' => SiteTree::class, |
|
| 52 | + 'FeatureOneLink' => SiteTree::class, |
|
| 53 | + 'FeatureTwoLink' => SiteTree::class, |
|
| 54 | + ]; |
|
| 55 | + |
|
| 56 | + private static $has_many = [ |
|
| 57 | + 'Quicklinks' => Quicklink::class . '.Parent', |
|
| 58 | + ]; |
|
| 59 | + |
|
| 60 | + public function Quicklinks() |
|
| 61 | + { |
|
| 62 | + return $this->getComponents('Quicklinks')->sort('SortOrder'); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function getCMSFields() |
|
| 66 | + { |
|
| 67 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 68 | + // Main Content tab |
|
| 69 | + $fields->addFieldToTab( |
|
| 70 | + 'Root.Main', |
|
| 71 | + TreeDropdownField::create( |
|
| 72 | + 'LearnMorePageID', |
|
| 73 | + _t(__CLASS__ . '.LearnMoreLink', 'Page to link the "Learn More" button to:'), |
|
| 74 | + SiteTree::class |
|
| 75 | + ), |
|
| 76 | + 'Metadata' |
|
| 77 | + ); |
|
| 78 | + |
|
| 79 | + $gridField = GridField::create( |
|
| 80 | + 'Quicklinks', |
|
| 81 | + 'Quicklinks', |
|
| 82 | + $this->Quicklinks(), |
|
| 83 | + GridFieldConfig_RelationEditor::create() |
|
| 84 | + ); |
|
| 85 | + $gridConfig = $gridField->getConfig(); |
|
| 86 | + $gridConfig->getComponentByType(GridFieldAddNewButton::class)->setButtonName( |
|
| 87 | + _t(__CLASS__ . '.AddNewButton', 'Add new') |
|
| 88 | + ); |
|
| 89 | + |
|
| 90 | + $injector = Injector::inst(); |
|
| 91 | + |
|
| 92 | + $gridConfig->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
| 93 | + $gridConfig->removeComponentsByType(GridFieldDeleteAction::class); |
|
| 94 | + $gridConfig->addComponent($injector->create(GridFieldDeleteAction::class)); |
|
| 95 | + $gridConfig->addComponent($injector->create(GridFieldSortableRows::class, 'SortOrder')); |
|
| 96 | + $gridField->setModelClass(Quicklink::class); |
|
| 97 | + |
|
| 98 | + $fields->addFieldToTab('Root.Quicklinks', $gridField); |
|
| 99 | + |
|
| 100 | + $fields->removeByName('Import'); |
|
| 101 | + |
|
| 102 | + $fields->addFieldToTab( |
|
| 103 | + 'Root.Features', |
|
| 104 | + ToggleCompositeField::create( |
|
| 105 | + 'FeatureOne', |
|
| 106 | + _t(__CLASS__ . '.FeatureOne', 'Feature One'), |
|
| 107 | + array( |
|
| 108 | + TextField::create('FeatureOneTitle', _t(__CLASS__ . '.Title', 'Title')), |
|
| 109 | + $dropdownField = DropdownField::create( |
|
| 110 | + 'FeatureOneCategory', |
|
| 111 | + _t(__CLASS__ . '.FeatureCategoryDropdown', 'Category icon'), |
|
| 112 | + singleton(BaseHomePage::class)->dbObject('FeatureOneCategory')->enumValues() |
|
| 113 | + ), |
|
| 114 | + HTMLEditorField::create( |
|
| 115 | + 'FeatureOneContent', |
|
| 116 | + _t(__CLASS__ . '.FeatureContentFieldLabel', 'Content') |
|
| 117 | + ), |
|
| 118 | + TextField::create( |
|
| 119 | + 'FeatureOneButtonText', |
|
| 120 | + _t(__CLASS__ . '.FeatureButtonText', 'Button text') |
|
| 121 | + ), |
|
| 122 | + TreeDropdownField::create( |
|
| 123 | + 'FeatureOneLinkID', |
|
| 124 | + _t(__CLASS__ . '.FeatureLink', 'Page to link to'), |
|
| 125 | + SiteTree::class |
|
| 126 | + )->setDescription(_t(__CLASS__ . '.ButtonTextRequired', 'Button text must be filled in')) |
|
| 127 | + ) |
|
| 128 | + )->setHeadingLevel(3) |
|
| 129 | + ); |
|
| 130 | + $dropdownField->setEmptyString('none'); |
|
| 131 | + |
|
| 132 | + $fields->addFieldToTab('Root.Features', ToggleCompositeField::create( |
|
| 133 | + 'FeatureTwo', |
|
| 134 | + _t(__CLASS__ . '.FeatureTwo', 'Feature Two'), |
|
| 135 | + array( |
|
| 136 | + TextField::create('FeatureTwoTitle', _t(__CLASS__ . '.Title', 'Title')), |
|
| 137 | + $dropdownField = DropdownField::create( |
|
| 138 | + 'FeatureTwoCategory', |
|
| 139 | + _t(__CLASS__ . '.FeatureCategoryDropdown', 'Category icon'), |
|
| 140 | + singleton(BaseHomePage::class)->dbObject('FeatureTwoCategory')->enumValues() |
|
| 141 | + ), |
|
| 142 | + HTMLEditorField::create( |
|
| 143 | + 'FeatureTwoContent', |
|
| 144 | + _t(__CLASS__ . '.FeatureContentFieldLabel', 'Content') |
|
| 145 | + ), |
|
| 146 | + TextField::create( |
|
| 147 | + 'FeatureTwoButtonText', |
|
| 148 | + _t(__CLASS__ . '.FeatureButtonText', 'Button text') |
|
| 149 | + ), |
|
| 150 | + TreeDropdownField::create( |
|
| 151 | + 'FeatureTwoLinkID', |
|
| 152 | + _t(__CLASS__ . '.FeatureLink', 'Page to link to'), |
|
| 153 | + SiteTree::class |
|
| 154 | + )->setDescription(_t(__CLASS__ . '.ButtonTextRequired', 'Button text must be filled in')) |
|
| 155 | + ) |
|
| 156 | + )->setHeadingLevel(3)); |
|
| 157 | + $dropdownField->setEmptyString('none'); |
|
| 158 | + }); |
|
| 159 | + |
|
| 160 | + return parent::getCMSFields(); |
|
| 161 | + } |
|
| 162 | 162 | } |
@@ -19,53 +19,53 @@ |
||
| 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(__CLASS__ . '.Upcoming', 'Upcoming events'); |
|
| 27 | - } |
|
| 22 | + public function getUpdateName() |
|
| 23 | + { |
|
| 24 | + $params = $this->parseParams(); |
|
| 25 | + if ($params['upcomingOnly']) { |
|
| 26 | + return _t(__CLASS__ . '.Upcoming', 'Upcoming events'); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - return _t(__CLASS__ . '.Events', 'Events'); |
|
| 30 | - } |
|
| 29 | + return _t(__CLASS__ . '.Events', '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 | } |
@@ -11,117 +11,117 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Quicklink extends DataObject |
| 13 | 13 | { |
| 14 | - private static $db = [ |
|
| 15 | - 'Name' => 'Varchar(255)', |
|
| 16 | - 'ExternalLink' => 'Varchar(255)', |
|
| 17 | - 'SortOrder' => 'Int', |
|
| 18 | - ]; |
|
| 19 | - |
|
| 20 | - private static $has_one = [ |
|
| 21 | - 'Parent' => BaseHomePage::class, |
|
| 22 | - 'InternalLink' => SiteTree::class, |
|
| 23 | - ]; |
|
| 24 | - |
|
| 25 | - private static $summary_fields = [ |
|
| 26 | - 'Name' => 'Name', |
|
| 27 | - 'InternalLink.Title' => 'Internal Link', |
|
| 28 | - 'ExternalLink' => 'External Link', |
|
| 29 | - ]; |
|
| 30 | - |
|
| 31 | - private static $table_name = 'Quicklink'; |
|
| 32 | - |
|
| 33 | - public function fieldLabels($includerelations = true) |
|
| 34 | - { |
|
| 35 | - $labels = parent::fieldLabels($includerelations); |
|
| 36 | - $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name'); |
|
| 37 | - $labels['ExternalLink'] = _t(__CLASS__ . '.ExternalLinkLabel', 'External Link'); |
|
| 38 | - $labels['SortOrder'] = _t(__CLASS__ . '.SortOrderLabel', 'Sort Order'); |
|
| 39 | - $labels['ParentID'] = _t(__CLASS__ . '.ParentRelationLabel', 'Parent'); |
|
| 40 | - $labels['InternalLinkID'] = _t(__CLASS__ . '.InternalLinkLabel', 'Internal Link'); |
|
| 41 | - |
|
| 42 | - return $labels; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function getLink() |
|
| 46 | - { |
|
| 47 | - if ($this->ExternalLink) { |
|
| 48 | - $url = parse_url($this->ExternalLink); |
|
| 49 | - |
|
| 50 | - // if no scheme set in the link, default to http |
|
| 51 | - if (!isset($url['scheme'])) { |
|
| 52 | - return 'http://' . $this->ExternalLink; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return $this->ExternalLink; |
|
| 56 | - } elseif ($this->InternalLinkID) { |
|
| 57 | - return $this->InternalLink()->Link(); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - public function canCreate($member = null, $context = []) |
|
| 62 | - { |
|
| 63 | - return $this->Parent()->canCreate($member, $context); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - public function canEdit($member = null) |
|
| 67 | - { |
|
| 68 | - return $this->Parent()->canEdit($member); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - public function canDelete($member = null) |
|
| 72 | - { |
|
| 73 | - return $this->Parent()->canDelete($member); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function canView($member = null) |
|
| 77 | - { |
|
| 78 | - return $this->Parent()->canView($member); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function getCMSFields() |
|
| 82 | - { |
|
| 83 | - $fields = parent::getCMSFields(); |
|
| 84 | - |
|
| 85 | - $fields->removeByName('ParentID'); |
|
| 86 | - |
|
| 87 | - $externalLinkField = $fields->fieldByName('Root.Main.ExternalLink'); |
|
| 88 | - |
|
| 89 | - $fields->removeByName('ExternalLink'); |
|
| 90 | - $fields->removeByName('InternalLinkID'); |
|
| 91 | - $fields->removeByName('SortOrder'); |
|
| 92 | - $externalLinkField->addExtraClass('noBorder'); |
|
| 93 | - |
|
| 94 | - $fields->addFieldToTab('Root.Main', CompositeField::create( |
|
| 95 | - array( |
|
| 96 | - TreeDropdownField::create( |
|
| 97 | - 'InternalLinkID', |
|
| 98 | - $this->fieldLabel('InternalLinkID'), |
|
| 99 | - SiteTree::class |
|
| 100 | - ), |
|
| 101 | - $externalLinkField, |
|
| 102 | - $wrap = CompositeField::create( |
|
| 103 | - $extraLabel = LiteralField::create( |
|
| 104 | - 'NoteOverride', |
|
| 105 | - sprintf('<div class="message good notice">%s</div>', _t( |
|
| 106 | - __CLASS__ . '.Note', |
|
| 107 | - 'Note: If you specify an External Link, the Internal Link will be ignored.' |
|
| 108 | - )) |
|
| 109 | - ) |
|
| 110 | - ) |
|
| 111 | - ) |
|
| 112 | - )); |
|
| 113 | - $fields->insertBefore( |
|
| 114 | - 'Name', |
|
| 115 | - LiteralField::create( |
|
| 116 | - 'Note', |
|
| 117 | - sprintf('<p>%s</p>', _t( |
|
| 118 | - __CLASS__ . '.Note2', |
|
| 119 | - 'Use this to specify a link to a page either on this site ' |
|
| 120 | - . '(Internal Link) or another site (External Link).' |
|
| 121 | - )) |
|
| 122 | - ) |
|
| 123 | - ); |
|
| 124 | - |
|
| 125 | - return $fields; |
|
| 126 | - } |
|
| 14 | + private static $db = [ |
|
| 15 | + 'Name' => 'Varchar(255)', |
|
| 16 | + 'ExternalLink' => 'Varchar(255)', |
|
| 17 | + 'SortOrder' => 'Int', |
|
| 18 | + ]; |
|
| 19 | + |
|
| 20 | + private static $has_one = [ |
|
| 21 | + 'Parent' => BaseHomePage::class, |
|
| 22 | + 'InternalLink' => SiteTree::class, |
|
| 23 | + ]; |
|
| 24 | + |
|
| 25 | + private static $summary_fields = [ |
|
| 26 | + 'Name' => 'Name', |
|
| 27 | + 'InternalLink.Title' => 'Internal Link', |
|
| 28 | + 'ExternalLink' => 'External Link', |
|
| 29 | + ]; |
|
| 30 | + |
|
| 31 | + private static $table_name = 'Quicklink'; |
|
| 32 | + |
|
| 33 | + public function fieldLabels($includerelations = true) |
|
| 34 | + { |
|
| 35 | + $labels = parent::fieldLabels($includerelations); |
|
| 36 | + $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name'); |
|
| 37 | + $labels['ExternalLink'] = _t(__CLASS__ . '.ExternalLinkLabel', 'External Link'); |
|
| 38 | + $labels['SortOrder'] = _t(__CLASS__ . '.SortOrderLabel', 'Sort Order'); |
|
| 39 | + $labels['ParentID'] = _t(__CLASS__ . '.ParentRelationLabel', 'Parent'); |
|
| 40 | + $labels['InternalLinkID'] = _t(__CLASS__ . '.InternalLinkLabel', 'Internal Link'); |
|
| 41 | + |
|
| 42 | + return $labels; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function getLink() |
|
| 46 | + { |
|
| 47 | + if ($this->ExternalLink) { |
|
| 48 | + $url = parse_url($this->ExternalLink); |
|
| 49 | + |
|
| 50 | + // if no scheme set in the link, default to http |
|
| 51 | + if (!isset($url['scheme'])) { |
|
| 52 | + return 'http://' . $this->ExternalLink; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return $this->ExternalLink; |
|
| 56 | + } elseif ($this->InternalLinkID) { |
|
| 57 | + return $this->InternalLink()->Link(); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + public function canCreate($member = null, $context = []) |
|
| 62 | + { |
|
| 63 | + return $this->Parent()->canCreate($member, $context); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + public function canEdit($member = null) |
|
| 67 | + { |
|
| 68 | + return $this->Parent()->canEdit($member); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + public function canDelete($member = null) |
|
| 72 | + { |
|
| 73 | + return $this->Parent()->canDelete($member); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function canView($member = null) |
|
| 77 | + { |
|
| 78 | + return $this->Parent()->canView($member); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public function getCMSFields() |
|
| 82 | + { |
|
| 83 | + $fields = parent::getCMSFields(); |
|
| 84 | + |
|
| 85 | + $fields->removeByName('ParentID'); |
|
| 86 | + |
|
| 87 | + $externalLinkField = $fields->fieldByName('Root.Main.ExternalLink'); |
|
| 88 | + |
|
| 89 | + $fields->removeByName('ExternalLink'); |
|
| 90 | + $fields->removeByName('InternalLinkID'); |
|
| 91 | + $fields->removeByName('SortOrder'); |
|
| 92 | + $externalLinkField->addExtraClass('noBorder'); |
|
| 93 | + |
|
| 94 | + $fields->addFieldToTab('Root.Main', CompositeField::create( |
|
| 95 | + array( |
|
| 96 | + TreeDropdownField::create( |
|
| 97 | + 'InternalLinkID', |
|
| 98 | + $this->fieldLabel('InternalLinkID'), |
|
| 99 | + SiteTree::class |
|
| 100 | + ), |
|
| 101 | + $externalLinkField, |
|
| 102 | + $wrap = CompositeField::create( |
|
| 103 | + $extraLabel = LiteralField::create( |
|
| 104 | + 'NoteOverride', |
|
| 105 | + sprintf('<div class="message good notice">%s</div>', _t( |
|
| 106 | + __CLASS__ . '.Note', |
|
| 107 | + 'Note: If you specify an External Link, the Internal Link will be ignored.' |
|
| 108 | + )) |
|
| 109 | + ) |
|
| 110 | + ) |
|
| 111 | + ) |
|
| 112 | + )); |
|
| 113 | + $fields->insertBefore( |
|
| 114 | + 'Name', |
|
| 115 | + LiteralField::create( |
|
| 116 | + 'Note', |
|
| 117 | + sprintf('<p>%s</p>', _t( |
|
| 118 | + __CLASS__ . '.Note2', |
|
| 119 | + 'Use this to specify a link to a page either on this site ' |
|
| 120 | + . '(Internal Link) or another site (External Link).' |
|
| 121 | + )) |
|
| 122 | + ) |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + return $fields; |
|
| 126 | + } |
|
| 127 | 127 | } |
@@ -13,163 +13,163 @@ |
||
| 13 | 13 | |
| 14 | 14 | class BasePageController extends ContentController |
| 15 | 15 | { |
| 16 | - private static $allowed_actions = [ |
|
| 17 | - 'downloadpdf', |
|
| 18 | - ]; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Serve the page rendered as PDF. |
|
| 22 | - */ |
|
| 23 | - public function downloadpdf() |
|
| 24 | - { |
|
| 25 | - if (!Config::inst()->get(BasePage::class, 'pdf_export')) { |
|
| 26 | - return false; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - // We only allow producing live pdf. There is no way to secure the draft files. |
|
| 30 | - Versioned::set_stage(Versioned::LIVE); |
|
| 31 | - |
|
| 32 | - $path = $this->dataRecord->getPdfFilename(); |
|
| 33 | - if (!file_exists($path)) { |
|
| 34 | - $this->generatePDF(); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - return HTTPRequest::send_file(file_get_contents($path), basename($path), 'application/pdf'); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /* |
|
| 16 | + private static $allowed_actions = [ |
|
| 17 | + 'downloadpdf', |
|
| 18 | + ]; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Serve the page rendered as PDF. |
|
| 22 | + */ |
|
| 23 | + public function downloadpdf() |
|
| 24 | + { |
|
| 25 | + if (!Config::inst()->get(BasePage::class, 'pdf_export')) { |
|
| 26 | + return false; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + // We only allow producing live pdf. There is no way to secure the draft files. |
|
| 30 | + Versioned::set_stage(Versioned::LIVE); |
|
| 31 | + |
|
| 32 | + $path = $this->dataRecord->getPdfFilename(); |
|
| 33 | + if (!file_exists($path)) { |
|
| 34 | + $this->generatePDF(); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + return HTTPRequest::send_file(file_get_contents($path), basename($path), 'application/pdf'); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /* |
|
| 41 | 41 | * This will return either pdf_base_url from YML, CWP_SECURE_DOMAIN |
| 42 | 42 | * from _ss_environment, or blank. In that order of importance. |
| 43 | 43 | */ |
| 44 | - public function getPDFBaseURL() |
|
| 45 | - { |
|
| 46 | - //if base url YML is defined in YML, use that |
|
| 47 | - if (Config::inst()->get(BasePage::class, 'pdf_base_url')) { |
|
| 48 | - $pdfBaseUrl = Config::inst()->get(BasePage::class, 'pdf_base_url').'/'; |
|
| 49 | - //otherwise, if we are CWP use the secure domain |
|
| 50 | - } elseif (Environment::getEnv('CWP_SECURE_DOMAIN')) { |
|
| 51 | - $pdfBaseUrl = Environment::getEnv('CWP_SECURE_DOMAIN') . '/'; |
|
| 52 | - //or if neither, leave blank |
|
| 53 | - } else { |
|
| 54 | - $pdfBaseUrl = ''; |
|
| 55 | - } |
|
| 56 | - return $pdfBaseUrl; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /* |
|
| 44 | + public function getPDFBaseURL() |
|
| 45 | + { |
|
| 46 | + //if base url YML is defined in YML, use that |
|
| 47 | + if (Config::inst()->get(BasePage::class, 'pdf_base_url')) { |
|
| 48 | + $pdfBaseUrl = Config::inst()->get(BasePage::class, 'pdf_base_url').'/'; |
|
| 49 | + //otherwise, if we are CWP use the secure domain |
|
| 50 | + } elseif (Environment::getEnv('CWP_SECURE_DOMAIN')) { |
|
| 51 | + $pdfBaseUrl = Environment::getEnv('CWP_SECURE_DOMAIN') . '/'; |
|
| 52 | + //or if neither, leave blank |
|
| 53 | + } else { |
|
| 54 | + $pdfBaseUrl = ''; |
|
| 55 | + } |
|
| 56 | + return $pdfBaseUrl; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /* |
|
| 60 | 60 | * Don't use the proxy if the pdf domain is the CWP secure domain |
| 61 | 61 | * Or if we aren't on a CWP server |
| 62 | 62 | */ |
| 63 | - public function getPDFProxy($pdfBaseUrl) |
|
| 64 | - { |
|
| 65 | - if (!Environment::getEnv('CWP_SECURE_DOMAIN') |
|
| 66 | - || $pdfBaseUrl == Environment::getEnv('CWP_SECURE_DOMAIN') . '/' |
|
| 67 | - ) { |
|
| 68 | - $proxy = ''; |
|
| 69 | - } else { |
|
| 70 | - $proxy = ' --proxy ' . Environment::getEnv('SS_OUTBOUND_PROXY') |
|
| 71 | - . ':' . Environment::getEnv('SS_OUTBOUND_PROXY_PORT'); |
|
| 72 | - } |
|
| 73 | - return $proxy; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Render the page as PDF using wkhtmltopdf. |
|
| 78 | - */ |
|
| 79 | - public function generatePDF() |
|
| 80 | - { |
|
| 81 | - if (!Config::inst()->get(BasePage::class, 'pdf_export')) { |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - $binaryPath = Config::inst()->get(BasePage::class, 'wkhtmltopdf_binary'); |
|
| 86 | - if (!$binaryPath || !is_executable($binaryPath)) { |
|
| 87 | - if (Environment::getEnv('WKHTMLTOPDF_BINARY') |
|
| 88 | - && is_executable(Environment::getEnv('WKHTMLTOPDF_BINARY')) |
|
| 89 | - ) { |
|
| 90 | - $binaryPath = Environment::getEnv('WKHTMLTOPDF_BINARY'); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if (!$binaryPath) { |
|
| 95 | - user_error('Neither WKHTMLTOPDF_BINARY nor BasePage.wkhtmltopdf_binary are defined', E_USER_ERROR); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - if (Versioned::get_reading_mode() == 'Stage.Stage') { |
|
| 99 | - user_error('Generating PDFs on draft is not supported', E_USER_ERROR); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - set_time_limit(60); |
|
| 103 | - |
|
| 104 | - // prepare the paths |
|
| 105 | - $pdfFile = $this->dataRecord->getPdfFilename(); |
|
| 106 | - $bodyFile = str_replace('.pdf', '_pdf.html', $pdfFile); |
|
| 107 | - $footerFile = str_replace('.pdf', '_pdffooter.html', $pdfFile); |
|
| 108 | - |
|
| 109 | - // make sure the work directory exists |
|
| 110 | - if (!file_exists(dirname($pdfFile))) { |
|
| 111 | - Filesystem::makeFolder(dirname($pdfFile)); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - //decide the domain to use in generation |
|
| 115 | - $pdfBaseUrl = $this->getPDFBaseURL(); |
|
| 116 | - |
|
| 117 | - // Force http protocol on CWP - fetching from localhost without using the proxy, SSL terminates on gateway. |
|
| 118 | - if (Environment::getEnv('CWP_ENVIRONMENT')) { |
|
| 119 | - Config::modify()->set(Director::class, 'alternate_protocol', 'http'); |
|
| 120 | - //only set alternate protocol if CWP_SECURE_DOMAIN is defined OR pdf_base_url is |
|
| 121 | - if ($pdfBaseUrl) { |
|
| 122 | - Config::modify()->set(Director::class, 'alternate_base_url', 'http://' . $pdfBaseUrl); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $bodyViewer = $this->getViewer('pdf'); |
|
| 127 | - |
|
| 128 | - // write the output of this page to HTML, ready for conversion to PDF |
|
| 129 | - file_put_contents($bodyFile, $bodyViewer->process($this)); |
|
| 130 | - |
|
| 131 | - // get the viewer for the current template with _pdffooter |
|
| 132 | - $footerViewer = $this->getViewer('pdffooter'); |
|
| 133 | - |
|
| 134 | - // write the output of the footer template to HTML, ready for conversion to PDF |
|
| 135 | - file_put_contents($footerFile, $footerViewer->process($this)); |
|
| 136 | - |
|
| 137 | - //decide what the proxy should look like |
|
| 138 | - $proxy = $this->getPDFProxy($pdfBaseUrl); |
|
| 139 | - |
|
| 140 | - // finally, generate the PDF |
|
| 141 | - $command = $binaryPath . $proxy . ' --outline -B 40pt -L 20pt -R 20pt -T 20pt --encoding utf-8 ' |
|
| 142 | - . '--orientation Portrait --disable-javascript --quiet --print-media-type '; |
|
| 143 | - $retVal = 0; |
|
| 144 | - $output = array(); |
|
| 145 | - exec( |
|
| 146 | - $command . " --footer-html \"$footerFile\" \"$bodyFile\" \"$pdfFile\" &> /dev/stdout", |
|
| 147 | - $output, |
|
| 148 | - $retVal |
|
| 149 | - ); |
|
| 150 | - |
|
| 151 | - // remove temporary file |
|
| 152 | - unlink($bodyFile); |
|
| 153 | - unlink($footerFile); |
|
| 154 | - |
|
| 155 | - // output any errors |
|
| 156 | - if ($retVal != 0) { |
|
| 157 | - user_error('wkhtmltopdf failed: ' . implode("\n", $output), E_USER_ERROR); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - // serve the generated file |
|
| 161 | - return HTTPRequest::send_file(file_get_contents($pdfFile), basename($pdfFile), 'application/pdf'); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Provide current year. |
|
| 166 | - */ |
|
| 167 | - public function CurrentDatetime() |
|
| 168 | - { |
|
| 169 | - return DBDatetime::now(); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - public function getRSSLink() |
|
| 173 | - { |
|
| 174 | - } |
|
| 63 | + public function getPDFProxy($pdfBaseUrl) |
|
| 64 | + { |
|
| 65 | + if (!Environment::getEnv('CWP_SECURE_DOMAIN') |
|
| 66 | + || $pdfBaseUrl == Environment::getEnv('CWP_SECURE_DOMAIN') . '/' |
|
| 67 | + ) { |
|
| 68 | + $proxy = ''; |
|
| 69 | + } else { |
|
| 70 | + $proxy = ' --proxy ' . Environment::getEnv('SS_OUTBOUND_PROXY') |
|
| 71 | + . ':' . Environment::getEnv('SS_OUTBOUND_PROXY_PORT'); |
|
| 72 | + } |
|
| 73 | + return $proxy; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Render the page as PDF using wkhtmltopdf. |
|
| 78 | + */ |
|
| 79 | + public function generatePDF() |
|
| 80 | + { |
|
| 81 | + if (!Config::inst()->get(BasePage::class, 'pdf_export')) { |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + $binaryPath = Config::inst()->get(BasePage::class, 'wkhtmltopdf_binary'); |
|
| 86 | + if (!$binaryPath || !is_executable($binaryPath)) { |
|
| 87 | + if (Environment::getEnv('WKHTMLTOPDF_BINARY') |
|
| 88 | + && is_executable(Environment::getEnv('WKHTMLTOPDF_BINARY')) |
|
| 89 | + ) { |
|
| 90 | + $binaryPath = Environment::getEnv('WKHTMLTOPDF_BINARY'); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if (!$binaryPath) { |
|
| 95 | + user_error('Neither WKHTMLTOPDF_BINARY nor BasePage.wkhtmltopdf_binary are defined', E_USER_ERROR); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + if (Versioned::get_reading_mode() == 'Stage.Stage') { |
|
| 99 | + user_error('Generating PDFs on draft is not supported', E_USER_ERROR); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + set_time_limit(60); |
|
| 103 | + |
|
| 104 | + // prepare the paths |
|
| 105 | + $pdfFile = $this->dataRecord->getPdfFilename(); |
|
| 106 | + $bodyFile = str_replace('.pdf', '_pdf.html', $pdfFile); |
|
| 107 | + $footerFile = str_replace('.pdf', '_pdffooter.html', $pdfFile); |
|
| 108 | + |
|
| 109 | + // make sure the work directory exists |
|
| 110 | + if (!file_exists(dirname($pdfFile))) { |
|
| 111 | + Filesystem::makeFolder(dirname($pdfFile)); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + //decide the domain to use in generation |
|
| 115 | + $pdfBaseUrl = $this->getPDFBaseURL(); |
|
| 116 | + |
|
| 117 | + // Force http protocol on CWP - fetching from localhost without using the proxy, SSL terminates on gateway. |
|
| 118 | + if (Environment::getEnv('CWP_ENVIRONMENT')) { |
|
| 119 | + Config::modify()->set(Director::class, 'alternate_protocol', 'http'); |
|
| 120 | + //only set alternate protocol if CWP_SECURE_DOMAIN is defined OR pdf_base_url is |
|
| 121 | + if ($pdfBaseUrl) { |
|
| 122 | + Config::modify()->set(Director::class, 'alternate_base_url', 'http://' . $pdfBaseUrl); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $bodyViewer = $this->getViewer('pdf'); |
|
| 127 | + |
|
| 128 | + // write the output of this page to HTML, ready for conversion to PDF |
|
| 129 | + file_put_contents($bodyFile, $bodyViewer->process($this)); |
|
| 130 | + |
|
| 131 | + // get the viewer for the current template with _pdffooter |
|
| 132 | + $footerViewer = $this->getViewer('pdffooter'); |
|
| 133 | + |
|
| 134 | + // write the output of the footer template to HTML, ready for conversion to PDF |
|
| 135 | + file_put_contents($footerFile, $footerViewer->process($this)); |
|
| 136 | + |
|
| 137 | + //decide what the proxy should look like |
|
| 138 | + $proxy = $this->getPDFProxy($pdfBaseUrl); |
|
| 139 | + |
|
| 140 | + // finally, generate the PDF |
|
| 141 | + $command = $binaryPath . $proxy . ' --outline -B 40pt -L 20pt -R 20pt -T 20pt --encoding utf-8 ' |
|
| 142 | + . '--orientation Portrait --disable-javascript --quiet --print-media-type '; |
|
| 143 | + $retVal = 0; |
|
| 144 | + $output = array(); |
|
| 145 | + exec( |
|
| 146 | + $command . " --footer-html \"$footerFile\" \"$bodyFile\" \"$pdfFile\" &> /dev/stdout", |
|
| 147 | + $output, |
|
| 148 | + $retVal |
|
| 149 | + ); |
|
| 150 | + |
|
| 151 | + // remove temporary file |
|
| 152 | + unlink($bodyFile); |
|
| 153 | + unlink($footerFile); |
|
| 154 | + |
|
| 155 | + // output any errors |
|
| 156 | + if ($retVal != 0) { |
|
| 157 | + user_error('wkhtmltopdf failed: ' . implode("\n", $output), E_USER_ERROR); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + // serve the generated file |
|
| 161 | + return HTTPRequest::send_file(file_get_contents($pdfFile), basename($pdfFile), 'application/pdf'); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Provide current year. |
|
| 166 | + */ |
|
| 167 | + public function CurrentDatetime() |
|
| 168 | + { |
|
| 169 | + return DBDatetime::now(); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + public function getRSSLink() |
|
| 173 | + { |
|
| 174 | + } |
|
| 175 | 175 | } |