Skip to content

Commit

Permalink
Merge pull request hubertusanton#25 from diede-dertig/master
Browse files Browse the repository at this point in the history
Great feature Diede!
Thanks a lot!
  • Loading branch information
hubertusanton committed May 6, 2015
2 parents a5cfc3c + f76e154 commit bc1a7ae
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Caution: The new master branch is not compatible with old releases see [this pul
Please use tag 1.1 in old sites with the old config and tag 2.0 for new projects, but updating to 2.0 will also fix google suggest and
has some other fixes.


## Screenshots

![ScreenShot](https://raw.github.com/hubertusanton/silverstripe-seo/master/images/screen2.png)
Expand Down
8 changes: 7 additions & 1 deletion _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ Page:
# Example of how to exclude extra page types from showing the SEO tab:
# SeoObjectExtension:
# excluded_page_types:
# - 'SomePage'
# - 'SomePage'

# Example of how to set content fields to be used for a page type
#NewPage:
# SeoContent:
# - 'ContentField1'
# - 'ContentField2'
51 changes: 36 additions & 15 deletions code/SeoObjectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ public function MetaTags(&$tags) {
*/
//$tags .= '<meta property="og:image" content="" />' . "\n";


}


Expand All @@ -230,6 +229,8 @@ public function getHTMLSimplePageSubjectTest() {

/**
* getSEOScoreCalculation.
* Do SEO score calculation and set class Array score_criteria 10 corresponding assoc values
* Also set class Integer seo_score with score 0-10 based on values which are true in score_criteria array
* Do SEO score calculation and set class Array score_criteria 11 corresponding assoc values
* Also set class Integer seo_score with score 0-11 based on values which are true in score_criteria array
*
Expand All @@ -255,9 +256,6 @@ public function getSEOScoreCalculation() {
$this->seo_score = intval(array_sum($this->score_criteria));
}




/**
* setSEOScoreTipsUL.
* Set SEO Score tips ul > li for SEO tips literal field, based on score_criteria
Expand All @@ -278,7 +276,6 @@ public function setSEOScoreTipsUL() {

}


/**
* checkPageSubjectInImageAlt.
* Checks if image alt tags contain page subject
Expand All @@ -288,7 +285,7 @@ public function setSEOScoreTipsUL() {
*/
public function checkPageSubjectInImageAltTags() {

$html = $this->owner->Content;
$html = $this->getContent();

// for newly created page
if ($html == '') {
Expand Down Expand Up @@ -321,7 +318,7 @@ public function checkPageSubjectInImageAltTags() {
*/
private function checkImageAltTags() {

$html = $this->owner->Content;
$html = $this->getContent();

// for newly created page
if ($html == '') {
Expand Down Expand Up @@ -357,7 +354,7 @@ private function checkImageAltTags() {
*/
private function checkImageTitleTags() {

$html = $this->owner->Content;
$html = $this->getContent();

// for newly created page
if ($html == '') {
Expand All @@ -384,8 +381,6 @@ private function checkImageTitleTags() {
return false;
}



/**
* checkPageSubjectDefined.
* Checks if SEOPageSubject is defined
Expand Down Expand Up @@ -425,7 +420,7 @@ public function checkPageSubjectInTitle() {
*/
public function checkPageSubjectInContent() {
if ($this->checkPageSubjectDefined()) {
if (preg_match('/' . preg_quote($this->owner->SEOPageSubject, '/') . '/i', $this->owner->Content)) {
if (preg_match('/' . preg_quote($this->owner->SEOPageSubject, '/') . '/i', $this->getContent())) {
return true;
}
else {
Expand Down Expand Up @@ -537,7 +532,7 @@ private function checkPageTitleLength() {
*/
private function checkContentHasLinks() {

$html = $this->owner->Content;
$html = $this->getContent();

// for newly created page
if ($html == '') {
Expand All @@ -561,7 +556,7 @@ private function checkContentHasLinks() {
*/
private function checkPageHasImages() {

$html = $this->owner->Content;
$html = $this->getContent();

// for newly created page
if ($html == '') {
Expand All @@ -583,7 +578,8 @@ private function checkPageHasImages() {
* @return boolean
*/
private function checkContentHasSubtitles() {
$html = $this->owner->Content;

$html = $this->getContent();

// for newly created page
if ($html == '') {
Expand All @@ -604,8 +600,9 @@ private function checkContentHasSubtitles() {
* @param none
* @return Integer Number of words in content
*/

public function getNumWordsContent() {
return str_word_count((Convert::xml2raw($this->owner->Content)));
return str_word_count((Convert::xml2raw($this->getContent())));
}

/**
Expand All @@ -619,4 +616,28 @@ public function getNumCharsTitle() {
return strlen($this->owner->Title);
}

/*
*
* getPageContent
* function to get page content based on config.yml file, to allow
* for different or multiple content fields
*
*/

public function getContent() {

$content = "";

$contentFields = Config::inst()->get($this->owner->getClassName(), "SeoContent");

if (!$contentFields)
$contentFields = array('Content');

foreach ($contentFields as $contentField => $value) {
$content .= $this->owner->getField($value);
}

return $content;
}

}

0 comments on commit bc1a7ae

Please sign in to comment.