Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config update + extras #10

Merged
merged 5 commits into from
Dec 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ Name: 'seoextensions'
---
Page:
extensions:
0: 'SeoObjectExtension'
SeoConfig:
Page: true
ErrorPage: false
RedirectorPage: false
VirtualPage: false
- 'SeoObjectExtension'
# Example of how to exclude extra page types from showing the SEO tab:
# SeoObjectExtension:
# excluded_page_types:
# - 'SomePage'
79 changes: 16 additions & 63 deletions code/GoogleSuggestField.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,12 @@
* Field which gets suggestions from google search
*/
class GoogleSuggestField extends FormField {

public $google_suggest_results = array();

public $google_suggest_url = 'http://google.com/complete/search?output=toolbar&q=';

public static $url_handlers = array(
'$Action!/$ID' => '$Action'
);

public static $allowed_actions = array(
'gsuggest'
);

public function Field($properties = array()) {

$jsBaseURL = Director::absoluteBaseURL();



Requirements::customScript(<<<JS

(function($) {
(function($) {

$.entwine('ss', function($){

Expand All @@ -32,17 +17,27 @@ public function Field($properties = array()) {
onmatch : function() {

$( "#Form_EditForm_{$this->getName()}" ).autocomplete({
source: "{$jsBaseURL}admin/pages/edit/EditForm/field/{$this->getName()}/gsuggest/",
minLength: 2
source: function( request, response ) {
$.ajax({
url: "http://suggestqueries.google.com/complete/search",
dataType: "jsonp",
data: {
client: 'firefox',
q: request.term
},
success: function( data ) {
response( data[1] );
}
});
},
minLength: 3
});

},
});
});

})(jQuery);


JS
);

Expand All @@ -51,46 +46,4 @@ public function Field($properties = array()) {
return parent::Field($properties);

}



/**
*
* @param SS_HTTPRequest $request
* @return string
*/
public function gsuggest(SS_HTTPRequest $request) {

if(!$request->getVar('term')) {
return $this->httpError(403, 'No term provided');

}

$suggest_for = $request->getVar('term');

$this->get_google_suggest($suggest_for);

}

private function get_google_suggest ($suggest_for = '') {

$url = file_get_contents($this->google_suggest_url . urlencode($suggest_for));
$suggestions = Convert::xml2array($url);

if (!empty($suggestions)) {

foreach ($suggestions['CompleteSuggestion'] as $suggestion) {
$suggestion_record = array();
$suggestion_record['id'] = $suggestion['suggestion']['@attributes']['data'];
$suggestion_record['label'] = $suggestion['suggestion']['@attributes']['data'];
$suggestion_record['value'] = $suggestion['suggestion']['@attributes']['data'];

$this->google_suggest_results[] = $suggestion_record;
}
}

print (Convert::array2json($this->google_suggest_results));
}


}
22 changes: 19 additions & 3 deletions code/SeoObjectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
*/
class SeoObjectExtension extends SiteTreeExtension {

/**
* Specify page types that will not include the SEO tab
*
* @config
* @var array
*/
private static $excluded_page_types = array(
'ErrorPage',
'RedirectorPage',
'VirtualPage'
);

private static $db = array(
'SEOPageSubject' => 'Varchar(256)'
Expand Down Expand Up @@ -67,8 +78,8 @@ public function getSEOScoreTips() {
*/
public function updateCMSFields(FieldList $fields) {

// use SEO module only on classes which are set up to use it in seo.yml / config.yml
if (!Config::inst()->get("SeoConfig", $this->owner->getClassName())) {
// exclude SEO tab from some pages
if (in_array($this->owner->getClassName(), Config::inst()->get("SeoObjectExtension", "excluded_page_types"))) {
return;
}

Expand Down Expand Up @@ -117,7 +128,12 @@ public function updateCMSFields(FieldList $fields) {
)
);
$fields->addFieldsToTab('Root.SEO', array(
TextField::create("SEOPageSubject", _t('SEO.SEOPageSubjectTitle', 'Subject of this page (required to view this page SEO score)')),
GoogleSuggestField::create("SEOPageSubject", _t('SEO.SEOPageSubjectTitle', 'Subject of this page (required to view this page SEO score)')),
LiteralField::create('', '<div class="message notice"><p>' .
_t(
'SEO.SEOSaveNotice',
"After making changes save this page to view the updated SEO score"
) . '</p></div>'),
LiteralField::create('ScoreTitle', '<h4 class="seo_score">' . _t('SEO.SEOScore', 'SEO Score') . '</h4>'),
LiteralField::create('Score', $this->getHTMLStars()),
LiteralField::create('ScoreClear', '<div class="score_clear"></div>')
Expand Down
4 changes: 0 additions & 4 deletions javascript/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
onkeyup : function() {
set_preview_google_search_result();
},
});

$('.cms-edit-form').entwine({

onmatch: function() {
set_preview_google_search_result();
}
Expand Down