Skip to content

Commit

Permalink
[Added] Added PageWeight as a metric in SEOmetrics
Browse files Browse the repository at this point in the history
[Added] Added the headings to the SEOmetrics display to improve its readability
[Improved] SEOmetrics now does a better job displaying Top Keywords on pages with very little text
  • Loading branch information
khalwat committed Sep 4, 2016
1 parent 14a5f62 commit f3a02d4
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 42 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ Some things to do, and ideas for potential features:
* [Improved] Do more sanity checking when building the breadcrumbs
* [Improved] We don't swap in the element->title for mainEntityOfPage anymore
* [Added] Added a variable for craft.seomatic.getTemplateMeta()
* [Improved] Protocol-relative URLs are now allowed in Schema
* [Improved] Protocol-relative URLs are now allowed in the Schema
* [Added] Added `PageWeight` as a metric in SEOmetrics
* [Added] Added the headings to the SEOmetrics display to improve its readability
* [Improved] SEOmetrics now does a better job displaying Top Keywords on pages with very little text
* [Improved] Updated the README.md

### 1.1.32 -- 2016.08.25
Expand Down
34 changes: 31 additions & 3 deletions controllers/SeomaticController.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,29 @@ public function actionRenderMetrics()
curl_setopt($ch, CURLOPT_URL, $pagespeedDesktopUrl);
$pagespeedDesktopResult = curl_exec($ch);
curl_close($ch);
$pageSpeedPageStats = array();
if ($pagespeedDesktopResult)
{
$pagespeedJson = json_decode($pagespeedDesktopResult, true);
if ($pagespeedJson)
{
$pageSpeedPageStats = $pagespeedJson['pageStats'];
if (empty($pageSpeedPageStats['htmlResponseBytes']))
$pageSpeedPageStats['htmlResponseBytes'] = 0;
if (empty($pageSpeedPageStats['cssResponseBytes']))
$pageSpeedPageStats['cssResponseBytes'] = 0;
if (empty($pageSpeedPageStats['imageResponseBytes']))
$pageSpeedPageStats['imageResponseBytes'] = 0;
if (empty($pageSpeedPageStats['javascriptResponseBytes']))
$pageSpeedPageStats['javascriptResponseBytes'] = 0;
if (empty($pageSpeedPageStats['otherResponseBytes']))
$pageSpeedPageStats['otherResponseBytes'] = 0;
$pageSpeedPageStats['totalResponseBytes'] = $pageSpeedPageStats['htmlResponseBytes'] +
$pageSpeedPageStats['cssResponseBytes'] +
$pageSpeedPageStats['imageResponseBytes'] +
$pageSpeedPageStats['javascriptResponseBytes'] +
$pageSpeedPageStats['otherResponseBytes'];

if (isset($pagespeedJson['responseCode']) && ($pagespeedJson['responseCode'] == "200" || $pagespeedJson['responseCode'] == "301" || $pagespeedJson['responseCode'] == "302"))
{
if (isset($pagespeedJson['ruleGroups']['SPEED']['score']))
Expand Down Expand Up @@ -237,9 +255,10 @@ public function actionRenderMetrics()
foreach($dom->find('script') as $element)
$element->outertext = '';
$strippedDom = html_entity_decode($dom->plaintext);
$strippedDom = preg_replace('@[^0-9a-z\.\!]+@i', ', ', $strippedDom);
// $strippedDom = preg_replace('@[^0-9a-z\.\!]+@i', ', ', $strippedDom);
$strippedDom = stripslashes($strippedDom);
$htmlDom = html_entity_decode($dom->outertext);
$htmlDom = preg_replace('@[^0-9a-z\.\!]+@i', '', $htmlDom);
// $htmlDom = preg_replace('@[^0-9a-z\.\!]+@i', '', $htmlDom);

/* -- SEO statistics */

Expand Down Expand Up @@ -292,8 +311,16 @@ public function actionRenderMetrics()

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

$strippedDom = preg_replace('/\s+/', ' ', $strippedDom);

/* -- Extract the page keywords, and clean them up a bit */

$pageKeywords = craft()->seomatic->extractKeywords($strippedDom);
$pageKeywords = str_replace(",",", ", $pageKeywords);

$pageKeywords = str_replace(",,",",", $pageKeywords);
$pageKeywords = str_replace(" ,",",", $pageKeywords);
$pageKeywords = str_replace(" .",".", $pageKeywords);
$pageKeywords = preg_replace('/,+/', ',', $pageKeywords);

/* -- Focus keywords */

Expand Down Expand Up @@ -357,6 +384,7 @@ public function actionRenderMetrics()
'validatorStatus' => $validatorStatus,
'validatorErrors' => $validatorErrors,
'validatorWarnings' => $validatorWarnings,
'pageSpeedPageStats' => $pageSpeedPageStats,
'pagespeedDesktopScore' => $pagespeedDesktopScore,
'pagespeedDesktopUrl' => $pagespeedDesktopUrl,
'pagespeedMobileScore' => $pagespeedMobileScore,
Expand Down
5 changes: 4 additions & 1 deletion releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"[Improved] Do more sanity checking when building the breadcrumbs",
"[Improved] We don't swap in the element->title for mainEntityOfPage anymore",
"[Added] Added a variable for craft.seomatic.getTemplateMeta()",
"[Improved] Protocol-relative URLs are now allowed in Schema",
"[Improved] Protocol-relative URLs are now allowed in the Schema",
"[Added] Added `PageWeight` as a metric in SEOmetrics",
"[Added] Added the headings to the SEOmetrics display to improve its readability",
"[Improved] SEOmetrics now does a better job displaying Top Keywords on pages with very little text",
"[Improved] Updated the README.md"
]
},
Expand Down
18 changes: 18 additions & 0 deletions services/SeomaticService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2976,6 +2976,24 @@ public function extractSummary($text = null, $limit = null, $withoutStopWords =
return $summary;
} /* -- extractSummary */

/* --------------------------------------------------------------------------------
Return a human-readable file size
-------------------------------------------------------------------------------- */

public function humanFileSize($size)
{
if ($size >= 1073741824) {
$fileSize = round($size / 1024 / 1024 / 1024,1) . 'GB';
} elseif ($size >= 1048576) {
$fileSize = round($size / 1024 / 1024,1) . 'MB';
} elseif($size >= 1024) {
$fileSize = round($size / 1024,1) . 'KB';
} else {
$fileSize = $size . ' bytes';
}
return $fileSize;
} /* -- humanFileSize */

/* --------------------------------------------------------------------------------
Sanitize the passed in array recursively
-------------------------------------------------------------------------------- */
Expand Down
Loading

0 comments on commit f3a02d4

Please sign in to comment.