Skip to content

Commit 52ba12a

Browse files
committed
First commit.
0 parents  commit 52ba12a

File tree

17 files changed

+576
-0
lines changed

17 files changed

+576
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DS_Store
2+
vendor
3+
node_modules

.php_cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
use Symfony\CS\Config\Config;
4+
use Symfony\CS\FixerInterface;
5+
use Symfony\CS\Finder\DefaultFinder;
6+
7+
$fixers = [
8+
'blankline_after_open_tag',
9+
'braces',
10+
'concat_without_spaces',
11+
'double_arrow_multiline_whitespaces',
12+
'duplicate_semicolon',
13+
'elseif',
14+
'empty_return',
15+
'encoding',
16+
'eof_ending',
17+
'extra_empty_lines',
18+
'function_call_space',
19+
'function_declaration',
20+
'include',
21+
'indentation',
22+
'join_function',
23+
'line_after_namespace',
24+
'linefeed',
25+
'list_commas',
26+
'logical_not_operators_with_successor_space',
27+
'lowercase_constants',
28+
'lowercase_keywords',
29+
'method_argument_space',
30+
'multiline_array_trailing_comma',
31+
'multiline_spaces_before_semicolon',
32+
'multiple_use',
33+
'namespace_no_leading_whitespace',
34+
'no_blank_lines_after_class_opening',
35+
'no_empty_lines_after_phpdocs',
36+
'object_operator',
37+
'operators_spaces',
38+
'parenthesis',
39+
'phpdoc_indent',
40+
'phpdoc_inline_tag',
41+
'phpdoc_no_access',
42+
'phpdoc_no_package',
43+
'phpdoc_scalar',
44+
'phpdoc_short_description',
45+
'phpdoc_to_comment',
46+
'phpdoc_trim',
47+
'phpdoc_type_to_var',
48+
'phpdoc_var_without_name',
49+
'remove_leading_slash_use',
50+
'remove_lines_between_uses',
51+
'return',
52+
'self_accessor',
53+
'short_array_syntax',
54+
'short_echo_tag',
55+
'short_tag',
56+
'single_array_no_trailing_comma',
57+
'single_blank_line_before_namespace',
58+
'single_line_after_imports',
59+
'single_quote',
60+
'spaces_before_semicolon',
61+
'spaces_cast',
62+
'standardize_not_equal',
63+
'ternary_spaces',
64+
'trailing_spaces',
65+
'trim_array_spaces',
66+
'unalign_equals',
67+
'unary_operators_spaces',
68+
'unused_use',
69+
'visibility',
70+
'whitespacy_lines',
71+
];
72+
73+
return Config::create()
74+
->finder(DefaultFinder::create()->in(__DIR__))
75+
->fixers($fixers)
76+
->level(FixerInterface::NONE_LEVEL)
77+
->setUsingCache(true);

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Version 0.9.0
2+
=============
3+
Keep track of changes to the package here.

LICENSE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2016 Oliver Green
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# concrete5.7+ SEO Update Service Notifier
2+
3+
A base to begin building your concrete5 package. The boilerplate includes demonstration core service providers and also provides a framework to use composer dependencies.
4+
5+
## Usage
6+
7+
Tutorial to follow.

assets/.gitkeep

Whitespace-only changes.

blocks/.gitkeep

Whitespace-only changes.

composer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "c5dev/package-boilerplate",
3+
"description": "A collection of boilerplate code which can be used as a base to begin building concrete5 packages.",
4+
"type": "concrete5-package",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Oliver Green",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"minimum-stability": "dev",
13+
"require": {
14+
"composer/installers": "dev-concrete5-installation-path-updates"
15+
}
16+
}

controller.php

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
<?php
2+
/**
3+
* SEO Update Service Notifier Controller File.
4+
*
5+
* @author Oliver Green <[email protected]>
6+
* @license See attached license file
7+
*/
8+
namespace Concrete\Package\SeoUpdateServiceNotifier;
9+
10+
use Core;
11+
use Concrete\Core\Foundation\Service\ProviderList;
12+
use Concrete\Core\Package\Package;
13+
use Illuminate\Filesystem\Filesystem;
14+
15+
defined('C5_EXECUTE') or die('Access Denied.');
16+
17+
/**
18+
* Package Controller Class.
19+
*
20+
* Start building standards complient concrete5 pacakges from me.
21+
*
22+
* @author Oliver Green <[email protected]>
23+
* @license See attached license file
24+
*/
25+
class Controller extends Package
26+
{
27+
/**
28+
* Minimum version of concrete5 required to use this package.
29+
*
30+
* @var string
31+
*/
32+
protected $appVersionRequired = '5.7.0';
33+
34+
/**
35+
* Does the package provide a full content swap?
36+
* This feature is often used in theme packages to install 'sample' content on the site.
37+
*
38+
* @see https://goo.gl/C4m6BG
39+
* @var bool
40+
*/
41+
protected $pkgAllowsFullContentSwap = false;
42+
43+
/**
44+
* Does the package provide thumbnails of the files
45+
* imported via the full content swap above?
46+
*
47+
* @see https://goo.gl/C4m6BG
48+
* @var bool
49+
*/
50+
protected $pkgContentProvidesFileThumbnails = false;
51+
52+
/**
53+
* Should we remove 'Src' from classes that are contained
54+
* ithin the packages 'src/Concrete' directory automatically?
55+
*
56+
* '\Concrete\Package\MyPackage\Src\MyNamespace' becomes '\Concrete\Package\MyPackage\MyNamespace'
57+
*
58+
* @see https://goo.gl/4wyRtH
59+
* @var bool
60+
*/
61+
protected $pkgAutoloaderMapCoreExtensions = false;
62+
63+
/**
64+
* Package class autoloader registrations
65+
* The package install helper class, included with this boilerplate,
66+
* is activated by default.
67+
*
68+
* @see https://goo.gl/4wyRtH
69+
* @var array
70+
*/
71+
protected $pkgAutoloaderRegistries = [
72+
//'src/MyVendor/Statistics' => '\MyVendor\ConcreteStatistics'
73+
];
74+
75+
/**
76+
* The packages handle.
77+
* Note that this must be unique in the
78+
* entire concrete5 package ecosystem.
79+
*
80+
* @var string
81+
*/
82+
protected $pkgHandle = 'seo_update_service_notifier';
83+
84+
/**
85+
* The packages version.
86+
*
87+
* @var string
88+
*/
89+
protected $pkgVersion = '0.9.0';
90+
91+
/**
92+
* The packages name.
93+
*
94+
* @var string
95+
*/
96+
protected $pkgName = 'SEO Update Service Notifier';
97+
98+
/**
99+
* The packages description.
100+
*
101+
* @var string
102+
*/
103+
protected $pkgDescription = 'Notify popular update services that you have updated your site.';
104+
105+
/**
106+
* Package service providers to register.
107+
*
108+
* @var array
109+
*/
110+
protected $providers = [
111+
// Register your concrete5 service providers here
112+
'Concrete\Package\SeoUpdateServiceNotifier\Src\Providers\UpdateServiceNotifierServiceProvider',
113+
];
114+
115+
/**
116+
* How often should we allow pinging?
117+
*
118+
* @var integer
119+
*/
120+
protected $rate_limit_ttl = 43200; // Every 12 hours
121+
122+
/**
123+
* Register the packages defined service providers.
124+
*
125+
* @return void
126+
*/
127+
protected function registerServiceProviders()
128+
{
129+
$list = new ProviderList(Core::getFacadeRoot());
130+
131+
foreach ($this->providers as $provider) {
132+
$list->registerProvider($provider);
133+
}
134+
}
135+
136+
/**
137+
* The packages on start hook that is fired as the CMS is booting up.
138+
*
139+
* @return void
140+
*/
141+
public function on_start()
142+
{
143+
// Register defined service providers
144+
$this->registerServiceProviders();
145+
146+
// Plugin the event listeners.
147+
$this->addEventListeners();
148+
}
149+
150+
/**
151+
* Get the list of update service URLs to ping.
152+
*
153+
* @return array
154+
*/
155+
protected function getUpdateServiceUrls()
156+
{
157+
return [
158+
'https://requestb.in/1i2ftut1'
159+
];
160+
}
161+
162+
/**
163+
* Checks to see whether we should ping the update services.
164+
* Currently this only checks that we are not above our rate limit.
165+
*
166+
* @return boolean
167+
*/
168+
protected function canPing()
169+
{
170+
$cache = Core::make('cache/expensive');
171+
$item = $cache->getItem('seo.update.notifier.expiry');
172+
173+
if ($item->isMiss()) {
174+
$item->set(time() + $this->rate_limit_ttl, $this->rate_limit_ttl);
175+
176+
return true;
177+
}
178+
179+
return false;
180+
}
181+
182+
/**
183+
* Notifys update services that a page has been added / updated
184+
* and should be (re)indexed.
185+
*
186+
* @param \Page $page [description]
187+
* @return boolean
188+
*/
189+
protected function pingPage(\Page $page)
190+
{
191+
if ($this->canPing()) {
192+
$notifier = \Core::make('seo.update.notifier');
193+
194+
return $notifier->ping(
195+
$this->getUpdateServiceUrls(),
196+
\Config::get('concrete.site'),
197+
\View::url('/'),
198+
\View::url($page->getCollectionPath())
199+
);
200+
}
201+
}
202+
203+
/**
204+
* Wires the page event listeners to the update service
205+
* notification service.
206+
*
207+
* @return void
208+
*/
209+
public function addEventListeners()
210+
{
211+
\Events::addListener('on_page_version_approve', function($event) {
212+
$page_id = $event->getCollectionVersionObject()->getCollectionID();
213+
$page = \Page::getById($page_id);
214+
$this->pingPage($page);
215+
});
216+
}
217+
218+
/**
219+
* The packages install routine.
220+
*
221+
* @return \Concrete\Core\Package\Package
222+
*/
223+
public function install()
224+
{
225+
// Add your custom logic here that needs to be executed BEFORE package install.
226+
227+
$pkg = parent::install();
228+
229+
// Add your custom logic here that needs to be executed AFTER package install.
230+
231+
return $pkg;
232+
}
233+
234+
/**
235+
* The packages upgrade routine.
236+
*
237+
* @return void
238+
*/
239+
public function upgrade()
240+
{
241+
// Add your custom logic here that needs to be executed BEFORE package install.
242+
243+
parent::upgrade();
244+
245+
// Add your custom logic here that needs to be executed AFTER package upgrade.
246+
}
247+
248+
/**
249+
* The packages uninstall routine.
250+
*
251+
* @return void
252+
*/
253+
public function uninstall()
254+
{
255+
// Add your custom logic here that needs to be executed BEFORE package uninstall.
256+
257+
parent::uninstall();
258+
259+
// Add your custom logic here that needs to be executed AFTER package uninstall.
260+
}
261+
}

controllers/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)