Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed May 30, 2016
2 parents 1cab9b9 + eac4890 commit 9b561f7
Show file tree
Hide file tree
Showing 52 changed files with 21,575 additions and 38 deletions.
8 changes: 8 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ The **SEO Keywords** field also allows you to extract keywords automatically fro

SEOmatic Meta FieldTypes also have default settings that allow you to control what the default settings should be for each meta field, and whether they can be changed by the person editing the entry.

## SEOmetrics during Live Preview

![Screenshot](resources/screenshots/seomatic05.png)

During Live Preview, a small SEOmatic icon is displayed in the lower-left corner of the Live Preview screen. If you click on it, it will run a variety of tests on your web page, and offer you analysis with helpful tips on how to correct the problem.

You can disable this feature by setting `displaySeoMetrics` to `false` in the `config.php`, should you wish to not have it displayed.

## Craft Commerce Product Microdata

![Screenshot](resources/screenshots/seomatic04.png)
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ Some things to do, and ideas for potential features:

## Changelog

### 1.1.18 -- 2016.05.30

* [Added] Added "SEOmetrics" displayed during Live Preview that analyizes your page, and generates helpful tips for improving SEO
* [Fixed] SEOmatic will now populate its FieldType with default values on `saveElement()`, which is triggered via import plugings and also via Settings → Edit My Section → hit Save
* [Fixed] Added 'logo' and 'image' to the list of keys that should be always run through getFullyQualifiedUrl()
* [Fixed] Fixed a CSS issue with the AdminCP UI and very large screens
* [Improved] Updated the README.md

### 1.1.17 -- 2016.05.09

* [Added] Added support for Google Sitelinks Search Box
Expand Down
2 changes: 1 addition & 1 deletion SeomaticPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getReleaseFeedUrl()

public function getVersion()
{
return '1.1.17';
return '1.1.18';
}

public function getSchemaVersion()
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"type": "craft-plugin",
"require": {
"crodas/text-rank" : "dev-master",
"davechild/textstatistics": "1.0.1",
"sunra/php-simple-html-dom-parser": "1.5.1",
"composer/installers": "~1.0"
}
}
201 changes: 198 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@
*/
"siteUrlOverride" => '',

/**
* Controls whether SEOmatic will display the SEOmetrics information during Live Preview.
*/
"displaySeoMetrics" => true,

);
101 changes: 100 additions & 1 deletion controllers/SeomaticController.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php
namespace Craft;

use \DaveChild\TextStatistics as TS;
use \Sunra\PhpSimple\HtmlDomParser;

class SeomaticController extends BaseController
{

protected $allowAnonymous = array('actionRenderHumans', 'actionRenderRobots');
protected $allowAnonymous = array('actionRenderHumans', 'actionRenderRobots', 'actionRenderMetrics');
protected $parsingDom = false;

/**
*/
Expand All @@ -18,6 +22,101 @@ public function actionEditSettings()
));
} /* -- actionEditSettings */

/* --------------------------------------------------------------------------------
Render the SEO Metrics
-------------------------------------------------------------------------------- */

public function actionRenderMetrics()
{

if (!$this->parsingDom)
{
$this->parsingDom = true;
$oldPath = method_exists(craft()->templates, 'getTemplatesPath') ? craft()->templates->getTemplatesPath() : craft()->path->getTemplatesPath();
$newPath = craft()->path->getPluginsPath().'seomatic/templates';
method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($newPath) : craft()->path->setTemplatesPath($newPath);

/* -- Render the SEOmatic display preview template */

$url = craft()->request->getParam('url');
$dom = HtmlDomParser::file_get_html($url);
if ($dom)
{
$textStatistics = new TS\TextStatistics;
$strippedDom = $dom->plaintext;
$htmlDom = $dom->outertext;

/* -- SEO statistics */

$titleTag = html_entity_decode($dom->find('title', 0)->plaintext);
$titleLength = strlen($titleTag);

$metaDescriptionTag = html_entity_decode($dom->find('meta[name=description]', 0)->content);
$metaDescriptionLength = strlen($metaDescriptionTag);

$emptyImageAlts = count($dom->find('img[!alt]'));

$h1Tags = count($dom->find('h1'));
$h2Tags = count($dom->find('h2'));
$h3Tags = count($dom->find('h3'));
$h4Tags = count($dom->find('h4'));
$h5Tags = count($dom->find('h5'));
$totalHTags = $h1Tags + $h2Tags + $h3Tags + $h4Tags + $h5Tags;
$effectiveHTags = true;
if ($h1Tags != 1)
$effectiveHTags = false;
if ($totalHTags < 6)
$effectiveHTags = false;
if ($h2Tags == 0 && ($h3Tags || $h4Tags || $h5Tags))
$effectiveHTags = false;
if ($h3Tags == 0 && ($h4Tags || $h5Tags))
$effectiveHTags = false;
if ($h4Tags == 0 && ($$h5Tags))
$effectiveHTags = false;

$textToHtmlRatio = (strlen($strippedDom) / strlen($htmlDom)) * 100;

/* -- Text statistics */

$wordCount = $textStatistics->wordCount($strippedDom);
$fleschKincaidReadingEase = $textStatistics->fleschKincaidReadingEase($strippedDom);
$fleschKincaidGradeLevel = $textStatistics->fleschKincaidGradeLevel($strippedDom);
$gunningFogScore = $textStatistics->gunningFogScore($strippedDom);
$colemanLiauIndex = $textStatistics->colemanLiauIndex($strippedDom);
$smogIndex = $textStatistics->smogIndex($strippedDom);
$automatedReadabilityIndex = $textStatistics->automatedReadabilityIndex($strippedDom);

$vars = array(
'titleTag' => $titleTag,
'titleLength' => $titleLength,
'metaDescriptionTag' => $metaDescriptionTag,
'metaDescriptionLength' => $metaDescriptionLength,
'emptyImageAlts' => $emptyImageAlts,
'h1Tags' => $h1Tags,
'h2Tags' => $h2Tags,
'h3Tags' => $h3Tags,
'h4Tags' => $h4Tags,
'h5Tags' => $h5Tags,
'effectiveHTags' => $effectiveHTags,
'textToHtmlRatio' => $textToHtmlRatio,
'wordCount' => $wordCount,
'fleschKincaidReadingEase' => $fleschKincaidReadingEase,
'fleschKincaidGradeLevel' => $fleschKincaidGradeLevel,
'gunningFogScore' => $gunningFogScore,
'colemanLiauIndex' => $colemanLiauIndex,
'smogIndex' => $smogIndex,
'automatedReadabilityIndex' => $automatedReadabilityIndex,
);

//$htmlText = craft()->templates->render('_seo_metrics.twig', $vars);
$this->renderTemplate('_seo_metrics.twig', $vars);
}

method_exists(craft()->templates, 'setTemplatesPath') ? craft()->templates->setTemplatesPath($oldPath) : craft()->path->setTemplatesPath($oldPath);
}
$this->parsingDom = false;
} /* -- actionRenderMetrics */

/* --------------------------------------------------------------------------------
Render the humans.txt template
-------------------------------------------------------------------------------- */
Expand Down
Loading

0 comments on commit 9b561f7

Please sign in to comment.