mediatheque
This commit is contained in:
Executable
+41
@@ -0,0 +1,41 @@
|
||||
# Cache and logs (Symfony2)
|
||||
/app/cache/*
|
||||
/app/logs/*
|
||||
!app/cache/.gitkeep
|
||||
!app/logs/.gitkeep
|
||||
|
||||
# Email spool folder
|
||||
/app/spool/*
|
||||
|
||||
# Cache, session files and logs (Symfony3)
|
||||
/var/cache/*
|
||||
/var/logs/*
|
||||
/var/sessions/*
|
||||
!var/cache/.gitkeep
|
||||
!var/logs/.gitkeep
|
||||
!var/sessions/.gitkeep
|
||||
|
||||
# Parameters
|
||||
/app/config/parameters.yml
|
||||
/app/config/parameters.ini
|
||||
|
||||
# Managed by Composer
|
||||
/app/bootstrap.php.cache
|
||||
/var/bootstrap.php.cache
|
||||
/bin/*
|
||||
!bin/console
|
||||
!bin/symfony_requirements
|
||||
|
||||
# Assets and user uploads
|
||||
/web/bundles/
|
||||
/web/uploads/
|
||||
|
||||
# PHPUnit
|
||||
/app/phpunit.xml
|
||||
/phpunit.xml
|
||||
|
||||
# Build data
|
||||
/build/
|
||||
|
||||
# Backup entities generated with doctrine:generate:entities command
|
||||
**/Entity/*~
|
||||
Executable
+134
@@ -0,0 +1,134 @@
|
||||
# v1.4.0
|
||||
## 04/08/2022
|
||||
|
||||
1. []()
|
||||
* takeover release
|
||||
2. [](#bugfix)
|
||||
* do not crash on mbregex search failure in php_mbereg_replace_exec.
|
||||
|
||||
# v1.3.5
|
||||
## 01/26/2018
|
||||
|
||||
1. [](#bugfix)
|
||||
* fix release dates in changelog.
|
||||
|
||||
# v1.3.3
|
||||
## 01/26/2018
|
||||
|
||||
1. [](#bugfix)
|
||||
* replace meta title content by page title instead of page slug.
|
||||
|
||||
# v1.3.2
|
||||
## 01/10/2018
|
||||
|
||||
1. [](#bugfix)
|
||||
* The meta tag fields were wrongly named "property" instead of "name".
|
||||
|
||||
# v1.3.1
|
||||
## 08/03/2017
|
||||
|
||||
1. [](#improved)
|
||||
* Add Admin plugin dependency (Dávid Szabó <david.szabo97@gmail.com>)
|
||||
* Use Slug utility function (Dávid Szabó <david.szabo97@gmail.com)
|
||||
|
||||
# v1.3.0
|
||||
## 07/31/2017
|
||||
|
||||
1. [](#bugfix)
|
||||
* the metadata were not overridden if some of them were already set in the site settings
|
||||
* the content was not used when its length in words was less than the value of the "length" settings
|
||||
* rename the metadata "keyword" to "keywords" (its valid name !)
|
||||
2. [](#improved)
|
||||
* code optimizations
|
||||
* remove some code redundancies
|
||||
|
||||
# v1.2.6
|
||||
## 07/30/2017
|
||||
|
||||
1. [](#bugfix)
|
||||
* fix: plugin was not running as expected after the 1.3.1 grav update
|
||||
|
||||
# v1.2.5
|
||||
## 07/27/2017
|
||||
|
||||
1. [](#bugfix)
|
||||
* fix version numbering in changelog
|
||||
|
||||
# v1.2.4
|
||||
## 07/27/2017
|
||||
|
||||
1. [](#bugfix)
|
||||
* fix a bug in changelog that prevents auto upgrading
|
||||
|
||||
# v1.2.3
|
||||
## 07/27/2017
|
||||
|
||||
1. [](#bugfix)
|
||||
* fix a bug in changelog that prevents auto upgrading
|
||||
* remove useless dependency
|
||||
|
||||
# v1.2.2
|
||||
## 07/27/2017
|
||||
|
||||
1. [](#improved)
|
||||
* minor changes in config files
|
||||
* update readme and changelog files
|
||||
|
||||
# v1.2.1
|
||||
## 07/27/2017
|
||||
|
||||
1. [](#improved)
|
||||
* update readme file
|
||||
|
||||
# v1.2.0
|
||||
## 07/26/2017
|
||||
|
||||
1. [](#new)
|
||||
* add metadata for Facebook Open Graph (thanks to Victor Rosset for the Social Meta Tags plugin source code I used for this part)
|
||||
* add metadata for Twitter Cards Meta Tags (thanks to Victor Rosset for the Social Meta Tags plugin source code I used for this part)
|
||||
2. [](#improved)
|
||||
* heavy code refactoring
|
||||
|
||||
# v1.1.1
|
||||
## 07/04/2017
|
||||
|
||||
1. [](#improved)
|
||||
* update readme file
|
||||
|
||||
# v1.1.0
|
||||
## 07/04/2017
|
||||
|
||||
1. [](#improved)
|
||||
* simplify the plugin structure by removing subclasses and autoload
|
||||
2. [](#bugfix)
|
||||
* per-page configuration is now fully functional
|
||||
|
||||
# v1.0.2
|
||||
## 07/04/2017
|
||||
|
||||
1. [](#bugfix)
|
||||
* rename keywords.php to keyword.php
|
||||
|
||||
# v1.0.1
|
||||
## 07/04/2017
|
||||
|
||||
1. [](#improved)
|
||||
* change "keywords" to "keyword" in source files to avoid confusion
|
||||
* minor changes in blueprints.yaml
|
||||
* change date format in CHANGELOG.md
|
||||
2. [](#bugfix)
|
||||
* remove a forgotten "dump" line
|
||||
|
||||
# v1.0.0
|
||||
## 07/04/2017
|
||||
|
||||
1. [](#improved)
|
||||
* enable auto fill for keyword metadata
|
||||
2. [](#bugfix)
|
||||
* Fixed several issue before public release (see commit list for details)
|
||||
|
||||
# v0.1.0
|
||||
## 07/04/2017
|
||||
|
||||
1. [](#new)
|
||||
* ChangeLog started...
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at contact@steamlead.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
Executable
+113
@@ -0,0 +1,113 @@
|
||||
# Contributing to this plugin
|
||||
|
||||
:+1: First, thanks for your desire make improvements to this plugin :+1:
|
||||
|
||||
Please take a moment to review this document in order to make the contribution
|
||||
process easy and effective for everyone involved.
|
||||
|
||||
Following these guidelines helps to communicate that you respect the time of
|
||||
the developers managing and developing this open source project. In return,
|
||||
they should reciprocate that respect in addressing your issue or assessing
|
||||
patches and features.
|
||||
|
||||
## Using the issue tracker
|
||||
|
||||
The issue tracker is the preferred channel for [bug reports](#bugs),
|
||||
[features requests](#features) and [submitting pull
|
||||
requests](#pull-requests), but please respect the following restrictions:
|
||||
|
||||
* Please **do not** use the issue tracker for issues related to GRAV.
|
||||
Use the official Grav repo for that
|
||||
|
||||
<a name="bugs"></a>
|
||||
## Bug reports
|
||||
|
||||
A bug is a _demonstrable problem_ that is caused by the code in the repository.
|
||||
Good bug reports are extremely helpful - thank you!
|
||||
|
||||
Guidelines for bug reports:
|
||||
|
||||
1. **Check you satisfy the Grav requirements** — [http://learn.getgrav.org/basics/requirements](http://learn.getgrav.org/basics/requirements)
|
||||
|
||||
1. **Check this happens on a new Plugin install** — remove and re-install the plugin. Reset the plugin to its default configuration.
|
||||
|
||||
1. **Check this happens on a clean Grav install** — check if the issue happens on any Grav site, or just with a specific configuration of plugins / theme
|
||||
|
||||
1. **Use the GitHub issue search** — check if the issue has already been
|
||||
reported.
|
||||
|
||||
1. **Check if the issue is already being solved in a PR** — check the open Pull Requests to see if one already solves the problem you're having
|
||||
|
||||
1. **Check if the issue has been fixed** — try to reproduce it using the
|
||||
latest `develop` branch in the repository.
|
||||
|
||||
1. **Isolate the problem** — create a [reduced test
|
||||
case](http://css-tricks.com/reduced-test-cases/) and provide a step-by-step instruction set on how to recreate the problem. Include code samples, page snippets or yaml configurations if needed.
|
||||
|
||||
A good bug report shouldn't leave others needing to chase you up for more
|
||||
information. Please try to be as detailed as possible in your report.
|
||||
|
||||
What is your environment? Is it localhost, OSX, Linux, on a remote server? Same happening locally and or the server, or just locally or just on Linux?
|
||||
|
||||
What steps will reproduce the issue? What browser(s) and OS experience the problem?
|
||||
|
||||
What would you expect to be the outcome?
|
||||
|
||||
Did the problem start happening recently (e.g. after updating to a new version of this plugin) or was this always a problem?
|
||||
|
||||
If the problem started happening recently, can you reproduce the problem in an older version of this plugin ? What's the most recent version in which the problem doesn't happen? You can download older versions from the releases page on Github.
|
||||
|
||||
Can you reliably reproduce the issue? If not, provide details about how often the problem happens and under which conditions it normally happens.
|
||||
|
||||
|
||||
All these details will help people to fix any potential bugs.
|
||||
|
||||
Important: [include Code Samples in triple backticks](https://help.github.com/articles/github-flavored-markdown/#fenced-code-blocks) so that Github will provide a proper indentation. [Add the language name after the backticks](https://help.github.com/articles/github-flavored-markdown/#syntax-highlighting) to add syntax highlighting to the code snippets.
|
||||
|
||||
Example:
|
||||
|
||||
> Short and descriptive example bug report title
|
||||
>
|
||||
> A summary of the issue and the browser/OS environment in which it occurs. If
|
||||
> suitable, include the steps required to reproduce the bug.
|
||||
>
|
||||
> 1. This is the first step
|
||||
> 2. This is the second step
|
||||
> 3. Further steps, etc.
|
||||
>>
|
||||
> Any other information you want to share that is relevant to the issue being
|
||||
> reported. This might include the lines of code that you have identified as
|
||||
> causing the bug, and potential solutions (and your opinions on their
|
||||
> merits).
|
||||
|
||||
|
||||
<a name="features"></a>
|
||||
## Feature requests
|
||||
|
||||
Feature requests are welcome. But take a moment to find out whether your idea
|
||||
fits with the scope and aims of the project. It's up to *you* to make a strong
|
||||
case to convince the project's developers of the merits of this feature. Please
|
||||
provide as much detail and context as possible.
|
||||
|
||||
|
||||
<a name="pull-requests"></a>
|
||||
## Pull requests
|
||||
|
||||
Good pull requests - patches, improvements, new features - are a fantastic
|
||||
help. They should remain focused in scope and avoid containing unrelated
|
||||
commits.
|
||||
|
||||
Please adhere to the coding conventions used throughout the GRAV project (indentation,
|
||||
accurate comments, etc.) and any other requirements.
|
||||
**Please also respect the plugin specific conventions if any.**
|
||||
|
||||
See [Using Pull Request](https://help.github.com/articles/using-pull-requests/) and [Fork a Repo](https://help.github.com/articles/fork-a-repo/) if you're not familiar with Pull Requests.
|
||||
|
||||
Any pull request should be based on the `develop` branch. We will not consider pull requests made to master.
|
||||
|
||||
**IMPORTANT**: By submitting a patch, you agree to allow the project owner to
|
||||
license your work under the same license as that used by the project.
|
||||
|
||||
<a name="translations"></a>
|
||||
### Translations
|
||||
Translations for this plugin are managed by direct request. Just send me an mail with your translation file.
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Laurent Ongaro
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
Executable
+114
@@ -0,0 +1,114 @@
|
||||
# [Grav](http://getgrav.org) AutoSEO
|
||||
|
||||
This is the new home of AutoSEO.
|
||||
I tried to contact the original author (Laurent), but the email bounced back
|
||||
|
||||
|
||||
Grav AutoSEO is a plugin for Grav with which you can fill automatically the description and keywords metadata of a page using its content.
|
||||
It also adds Facebook Open Graph metadata and Twitter Cards Meta Tags (**New** feature since the 1.2 version).
|
||||
|
||||
If the plugin is enabled and **the description and keyword metadata of the page are not manually filled** (i.e. the page headers contains some metadata fields),
|
||||
the plugin will use the first words of the page summary to fill the description and its categories and tags to fill the keyword metadata.
|
||||
Facebook and twitter metadata will also be filled if they are enabled in settings and not manually filled in the page header.
|
||||
|
||||
## Installation
|
||||
|
||||
### Manual Installation
|
||||
|
||||
To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then rename the folder to `autoseo`.
|
||||
|
||||
You should now have all the plugin files under
|
||||
|
||||
`/your/site/grav/user/plugins/autoseo`
|
||||
|
||||
## Configuration
|
||||
|
||||
Here is the default configuration and an explanation of available options:
|
||||
|
||||
`autoseo.yaml:`
|
||||
|
||||
```yaml
|
||||
enabled: true # lets you turn the plugin off and on.
|
||||
description:
|
||||
enabled: true # lets you turn the plugin off and on for the "description" metadata.
|
||||
length: 30 # maximal number of words that will be used to fill the "description" metadata.
|
||||
keywords:
|
||||
enabled: true # lets you turn the plugin off and on for the "keywords" metadata.
|
||||
length: 20 # maximal number of words that will be used to fill the "keywords" metadata.
|
||||
facebook:
|
||||
enabled: true # Lets you turn the plugin ON and OFF for the "Facebook Open Graph" metadata.
|
||||
twitter:
|
||||
enabled: true # Lets you turn the plugin ON and OFF for the "Twitter Cards" metadata.
|
||||
```
|
||||
|
||||
* The first `enabled` field lets you turn the plugin on and off.
|
||||
* The `enabled` field in each metadata section lets you turn on and off the plugin for this metadata only.
|
||||
* `length` is the maximal count of words that will be used to fill the corresponding metadata.
|
||||
|
||||
If you need to change any value, then the best process is to copy the `autoseo.yaml` file into your `users/config/plugins/` folder (create it if it doesn't exist), and then modify there. This will override the default settings.
|
||||
|
||||
## Per-Page Configuration
|
||||
|
||||
If you want to alter the settings for one or a few pages only, you can do so by adding page specific configurations into your page headers, e.g.
|
||||
|
||||
```yaml
|
||||
autoseo: false
|
||||
```
|
||||
to disable the `AutoSeo` plugin just for this page.
|
||||
|
||||
Remember you can also override the general plugin settings for a specific page by adding settings in its header. For instance, adding the following lines in a page headers
|
||||
|
||||
```yaml
|
||||
autoseo:
|
||||
enabled: true
|
||||
description:
|
||||
enabled: true
|
||||
length: 10
|
||||
keywords:
|
||||
enabled: true
|
||||
length: 10
|
||||
facebook:
|
||||
enabled: true
|
||||
twitter:
|
||||
enabled: false
|
||||
```
|
||||
|
||||
will change the description and keyword lengths to 10 words for these page only, enable Facebook Open Graph metadata and disable Twitter Cards tags.
|
||||
|
||||
## Usage
|
||||
|
||||
There's not much to do with this plugin, simply install, enabled it and check its configuration to meet your needs.
|
||||
|
||||
No need to do anything else.
|
||||
|
||||
### Demo
|
||||
|
||||
The plugin is installed and enabled on the following blog : [http://www.gamecoderblog.com](http://www.gamecoderblog.com).
|
||||
|
||||
To see it in action, you have to inspect the meta of the page code source.
|
||||
**(Use a page other than the home page, because the metadata used in it are those set in the blog configuration)**
|
||||
|
||||
### Performances
|
||||
|
||||
As each page must be analyzed and its content filtered by the plugins, the impact on performance can be important when first access to a page.
|
||||
But as the result will be cached, once the first analysis is done, you will find no further negative performance impact.
|
||||
|
||||
To limit the impact on performance, **the content analyzed will always be truncated to the 1000 first characters for description metadata**, then the limit given by the `length` setting will be applied.
|
||||
|
||||
### Notes
|
||||
|
||||
`AutoSeo` will make a few cleaning but won't check the content used to auto fill the metadata.
|
||||
So be sure that the first words of your content (the summary) will be correct to be used as a description.
|
||||
In a same way, check that the tags and categories of the page are OK to be used as keyword.
|
||||
|
||||
### Bugs And TODO
|
||||
|
||||
Please send any comments or bug reports to the plugin's issue tracker.
|
||||
|
||||
#### TODO
|
||||
|
||||
* No new feature is planned for the moment.
|
||||
|
||||
### Authors
|
||||
|
||||
`AutoSeo` was developed and maintained by Laurent Ongaro and is now looked after by Nuno Costa.
|
||||
Executable
+247
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
namespace Grav\Plugin;
|
||||
|
||||
use Grav\Common\Plugin;
|
||||
|
||||
/**
|
||||
* Class AutoSeoPlugin
|
||||
* @package Grav\Plugin
|
||||
*/
|
||||
class AutoSeoPlugin extends Plugin
|
||||
{
|
||||
/**
|
||||
* Initialize plugin and subsequent events
|
||||
* @return array
|
||||
*/
|
||||
public static function getSubscribedEvents() {
|
||||
return [
|
||||
'onPluginsInitialized' => ['onPluginsInitialized', 0],
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Register events with Grav
|
||||
* @return void
|
||||
*/
|
||||
public function onPluginsInitialized()
|
||||
{
|
||||
// deactivate plugin in admin
|
||||
if ( !$this->isAdmin()
|
||||
and $this->config->get('plugins.autoseo.enabled')
|
||||
) {
|
||||
$this->enable([
|
||||
'onPageInitialized' => ['onPageInitialized', 0]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add content after page content was read into the system.
|
||||
*
|
||||
*/
|
||||
public function onPageInitialized()
|
||||
{
|
||||
$page = $this->grav['page'];
|
||||
$config = $this->mergeConfig($page);
|
||||
if ( !$config['enabled']) return;
|
||||
|
||||
$updateDescription = $config['description.enabled'];
|
||||
$updatekeywords = $config['keywords.enabled'];
|
||||
$updateFacebook = $config['facebook.enabled'];
|
||||
$updateTwitter = $config['twitter.enabled'];
|
||||
if (!$updateDescription && !$updatekeywords && !$updateFacebook && !$updateTwitter) return;
|
||||
|
||||
$meta = $page->metadata();
|
||||
|
||||
$metaSite = $this->config->get('site')['metadata'];
|
||||
|
||||
// limit the content size to reduce the performance impact
|
||||
$content = mb_substr(strip_tags($page->content()),0, 1000 );
|
||||
|
||||
$cleanContent = $this->cleanText ($content, $config); // here because we don't want to make this call several times
|
||||
$cleanTitle = $this->cleanString ($page->title()); // here because we don't want to make this call several times
|
||||
|
||||
if ($updateDescription) $meta = $this->getMetaDescription ($meta, $metaSite, $config, $cleanContent);
|
||||
if ($updatekeywords) $meta = $this->getMetaKeywords ($meta, $metaSite, $config);
|
||||
if ($updateFacebook) $meta = $this->getMetaOpenGraph ($meta, $metaSite, $config, $cleanContent, $cleanTitle);
|
||||
if ($updateTwitter) $meta = $this->getMetaTwitter ($meta, $metaSite, $config, $cleanContent, $cleanTitle);
|
||||
$page->metadata ($meta);
|
||||
}
|
||||
|
||||
// PROCESS for the description metadata
|
||||
private function getMetaDescription ($meta, $metaSite, $config, $cleanContent) {
|
||||
|
||||
if (array_key_exists('description', $metaSite)) { $metaSiteContent = htmlspecialchars($metaSite['description'], ENT_QUOTES, 'UTF-8'); } else { $metaSiteContent = ''; }
|
||||
// if the page has a meta that is different from the default one, we return its value
|
||||
if (!empty($meta['description']['content']) && $meta['description']['content'] != $metaSiteContent) return $meta;
|
||||
|
||||
$metaPageContent = $cleanContent;
|
||||
|
||||
if (empty($metaPageContent)) $metaPageContent = $metaSiteContent;
|
||||
|
||||
$meta['description'] = [ 'name' => 'description', 'content' => $metaPageContent];
|
||||
return $meta;
|
||||
}
|
||||
|
||||
// PROCESS for the keywords metadata
|
||||
private function getMetaKeywords ($meta, $metaSite, $config) {
|
||||
$page = $this->grav['page'];
|
||||
|
||||
if (array_key_exists('keywords', $metaSite)) { $metaSiteContent = htmlspecialchars($metaSite['keywords'], ENT_QUOTES, 'UTF-8'); } else { $metaSiteContent = ''; }
|
||||
|
||||
// if the page has a meta that is different from the default one, we return its value
|
||||
if (!empty($meta['keywords']['content']) && $meta['keywords']['content'] != $metaSiteContent) return $meta;
|
||||
$length = $config['keywords.length'];
|
||||
if ($length <=1 ) $length=20;
|
||||
|
||||
// we create a keywords list using the page tags and categories
|
||||
if (array_key_exists( 'category', $page->taxonomy() )) { $categories = $page->taxonomy()['category']; } else { $categories = []; }
|
||||
if (array_key_exists( 'tag', $page->taxonomy() )) { $tags = $page->taxonomy()['tag']; } else { $tags = []; }
|
||||
|
||||
$content = array_merge ($categories, $tags) ;
|
||||
$content = array_unique ($content);
|
||||
$content = array_slice($content, 0, $length);
|
||||
$content = join(',',$content);
|
||||
$content = $this->cleanString($content);
|
||||
$metaPageContent = $content;
|
||||
if (empty($metaPageContent)) $metaPageContent = $metaSiteContent;
|
||||
|
||||
$meta['keywords'] = [ 'name' => 'keywords', 'content' => $metaPageContent];
|
||||
return $meta;
|
||||
}
|
||||
|
||||
// PROCESS for the OpenGraph metadata
|
||||
private function getMetaOpenGraph ($meta, $metaSite, $config, $cleanContent, $cleanTitle) {
|
||||
$page = $this->grav['page'];
|
||||
|
||||
$meta['og:sitename']['name'] = 'og:sitename';
|
||||
$meta['og:sitename']['property'] = 'og:sitename';
|
||||
$meta['og:sitename']['content'] = $this->config->get('site.title');
|
||||
$meta['og:title']['name'] = 'og:title';
|
||||
$meta['og:title']['property'] = 'og:title';
|
||||
$meta['og:title']['content'] = $cleanTitle;
|
||||
$meta['og:type']['name'] = 'og:type';
|
||||
$meta['og:type']['property'] = 'og:type';
|
||||
$meta['og:type']['content'] = 'article';
|
||||
$meta['og:url']['name'] = 'og:url';
|
||||
$meta['og:url']['property'] = 'og:url';
|
||||
$meta['og:url']['content'] = $this->grav['uri']->url(true);
|
||||
$meta['og:description']['name'] = 'og:description';
|
||||
$meta['og:description']['property'] = 'og:description';
|
||||
if (empty($cleanContent)) $cleanContent = $meta['description']['content'];
|
||||
else {
|
||||
if (array_key_exists('description', $metaSite)) { $metaSiteContent = htmlspecialchars($metaSite['description'], ENT_QUOTES, 'UTF-8'); } else { $metaSiteContent = ''; }
|
||||
if ($meta['description']['content'] != $metaSiteContent) $cleanContent = $meta['description']['content'];
|
||||
}
|
||||
|
||||
$meta['og:description']['content'] = $cleanContent;
|
||||
|
||||
if (!empty($page->value('media.image'))) {
|
||||
$images = $page->media()->images();
|
||||
$image = array_shift($images);
|
||||
$meta['og:image']['name'] = 'og:image';
|
||||
$meta['og:image']['property'] = 'og:image';
|
||||
$meta['og:image']['content'] = $this->grav['uri']->base() . $image->url();
|
||||
}
|
||||
return $meta;
|
||||
}
|
||||
|
||||
// PROCESS for the twitter metadata
|
||||
private function getMetaTwitter ($meta, $metaSite, $config, $cleanContent, $cleanTitle) {
|
||||
$page = $this->grav['page'];
|
||||
|
||||
if (!isset($meta['twitter:card'])) {
|
||||
$meta['twitter:card']['name'] = 'twitter:card';
|
||||
$meta['twitter:card']['property'] = 'twitter:card';
|
||||
$meta['twitter:card']['content'] = 'summary_large_image';
|
||||
}
|
||||
|
||||
if (!isset($meta['twitter:title'])) {
|
||||
$meta['twitter:title']['name'] = 'twitter:title';
|
||||
$meta['twitter:title']['property'] = 'twitter:title';
|
||||
$meta['twitter:title']['content'] = $cleanTitle;
|
||||
}
|
||||
|
||||
if (!isset($meta['twitter:description'])) {
|
||||
$meta['twitter:description']['name'] = 'twitter:description';
|
||||
$meta['twitter:description']['property'] = 'twitter:description';
|
||||
if (empty($cleanContent))
|
||||
$cleanContent = $meta['description']['content'];
|
||||
else {
|
||||
if (array_key_exists('description', $metaSite)) { $metaSiteContent = htmlspecialchars($metaSite['description'], ENT_QUOTES, 'UTF-8'); } else { $metaSiteContent = ''; }
|
||||
if ($meta['description']['content'] != $metaSiteContent) $cleanContent = $meta['description']['content'];
|
||||
}
|
||||
$meta['twitter:description']['content'] = mb_substr($cleanContent,0,140);
|
||||
}
|
||||
|
||||
if (!isset($meta['twitter:image'])) {
|
||||
if (!empty($page->value('media.image'))) {
|
||||
$images = $page->media()->images();
|
||||
$image = array_shift($images);
|
||||
$meta['twitter:image']['name'] = 'twitter:image';
|
||||
$meta['twitter:image']['property'] = 'twitter:image';
|
||||
$meta['twitter:image']['content'] = $this->grav['uri']->base() . $image->url();
|
||||
}
|
||||
}
|
||||
return $meta;
|
||||
}
|
||||
|
||||
private function cleanMarkdown($text){
|
||||
$rules = array (
|
||||
'/(#+)(.*)/' => '\2', // headers
|
||||
'/(<|<)!--\n((.*|\n)*)\n--(>|\>)/' => '', // comments
|
||||
'/(\*|-|_){3}/' => '', // hr
|
||||
'/!\[([^\[]+)\]\(([^\)]+)\)/' => '', // images
|
||||
'/\[([^\[]+)\]\(([^\)]+)\)/' => '\1', // links
|
||||
'/(\*\*|__)(.*?)\1/' => '\2', // bold
|
||||
'/(\*|_)(.*?)\1/' => '\2', // emphasis
|
||||
'/\~\~(.*?)\~\~/' => '\1', // del
|
||||
'/\:\"(.*?)\"\:/' => '\1', // quote
|
||||
'/```(.*)\n((.*|\n)+)\n```/' => '\2', // fence code
|
||||
'/`(.*?)`/' => '\1', // inline code
|
||||
'/(\*|\+|-)(.*)/' => '\2', // ul lists
|
||||
'/\n[0-9]+\.(.*)/' => '\2', // ol lists
|
||||
'/(>|\>)+(.*)/' => '\2', // blockquotes
|
||||
);
|
||||
foreach ($rules as $regex => $replacement) {
|
||||
if (is_callable ( $replacement)) {
|
||||
$text = preg_replace_callback ($regex, $replacement, $text);
|
||||
} else {
|
||||
$text = preg_replace ($regex, $replacement, $text);
|
||||
}
|
||||
}
|
||||
$text=str_replace(".\n", '.', $text);
|
||||
$text=str_replace("\n", '.', $text);
|
||||
$text=str_replace('"', '', $text);
|
||||
|
||||
return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
private function cleanText ($content, $config) {
|
||||
try {
|
||||
|
||||
$length = $config['description.length'];
|
||||
if ($length <=1 ) $length=20;
|
||||
|
||||
$content = $this->cleanMarkdown($content);
|
||||
// truncate the content to the number of words set in config
|
||||
$contentSmall = mb_ereg_replace('((\w+\W*){'.$length.'}(\w+))(.*)', '\\1', $content); // beware if content is less than length words, it will be nulled
|
||||
if ($contentSmall == '' ) $contentSmall = $content;
|
||||
|
||||
return $contentSmall;
|
||||
} catch (\Throwable $e) {
|
||||
$this->grav['log']->addError($e->getMessage());
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
private function cleanString ($content) {
|
||||
// remove some annoying characters
|
||||
$content = str_replace(" ",' ',$content);
|
||||
$content = str_replace('"',"'",$content);
|
||||
$content = trim($content);
|
||||
// Removes special chars.
|
||||
// $content = \Grav\Plugin\Admin\Utils::slug($content);
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
enabled: true # lets you turn the plugin off and on.
|
||||
description:
|
||||
enabled: true # lets you turn the plugin off and on for the "description" metadata.
|
||||
length: 30 # maximal number of words that will be used to fill the "description" metadata.
|
||||
keywords:
|
||||
enabled: true # lets you turn the plugin off and on for the "keywords" metadata.
|
||||
length: 20 # maximal number of words that will be used to fill the "keywords" metadata.
|
||||
facebook:
|
||||
enabled: true # Lets you turn the plugin ON and OFF for the "Facebook Open Graph" metadata.
|
||||
twitter:
|
||||
enabled: true # Lets you turn the plugin ON and OFF for the "Twitter Cards" metadata.
|
||||
Executable
+107
@@ -0,0 +1,107 @@
|
||||
name: Auto SEO
|
||||
version: 1.4.0
|
||||
description: Grav AutoSEO is a plugin for Grav with which you can fill automatically the description and keywords metadata of a page using its content. It also adds Facebook Open Graph metadata and Twitter Cards Meta Tags.
|
||||
icon: magic
|
||||
author:
|
||||
name: Nuno Costa
|
||||
email: info@codehaha.com
|
||||
url: http://www.codehaha.com
|
||||
homepage: https://github.com/francodacosta/grav-plugin-autoseo
|
||||
keywords: plugin, seo, metadata extraction, auto fill
|
||||
bugs: https://github.com/francodacosta/grav-plugin-autoseo/issues
|
||||
docs: https://github.com/francodacosta/grav-plugin-autoseo/blob/master/README.md
|
||||
license: MIT
|
||||
dependencies:
|
||||
- { name: admin, version: '>=1.5.0' }
|
||||
|
||||
form:
|
||||
validation: strict
|
||||
fields:
|
||||
|
||||
global:
|
||||
type: section
|
||||
title: PLUGINS.AUTO_SEO.GLOBAL_CONFIG
|
||||
underline: 1
|
||||
|
||||
fields:
|
||||
enabled:
|
||||
type: toggle
|
||||
label: PLUGINS.AUTO_SEO.PLUGIN_STATUS
|
||||
highlight: 1
|
||||
default: 0
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
|
||||
metadata:
|
||||
type: section
|
||||
title: PLUGINS.AUTO_SEO.DEFAULT_CONFIG
|
||||
underline: 1
|
||||
|
||||
fields:
|
||||
description.enabled:
|
||||
type: toggle
|
||||
label: PLUGINS.AUTO_SEO.DESCRIPTION.ENABLED_LABEL
|
||||
help: PLUGINS.AUTO_SEO.DESCRIPTION.ENABLED_HELP
|
||||
highlight: 1
|
||||
default: 0
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
description.length:
|
||||
type: text
|
||||
size: x-small
|
||||
label: PLUGINS.AUTO_SEO.DESCRIPTION.LENGTH_LABEL
|
||||
help: PLUGINS.AUTO_SEO.DESCRIPTION.LENGTH_HELP
|
||||
default: 30
|
||||
validate:
|
||||
type: number
|
||||
min: 2
|
||||
max: 50
|
||||
keywords.enabled:
|
||||
type: toggle
|
||||
label: PLUGINS.AUTO_SEO.KEYWORDS.ENABLED_LABEL
|
||||
help: PLUGINS.AUTO_SEO.KEYWORDS.ENABLED_HELP
|
||||
highlight: 1
|
||||
default: 0
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
keywords.length:
|
||||
type: text
|
||||
size: x-small
|
||||
label: PLUGINS.AUTO_SEO.KEYWORDS.LENGTH_LABEL
|
||||
help: PLUGINS.AUTO_SEO.KEYWORDS.LENGTH_HELP
|
||||
default: 20
|
||||
validate:
|
||||
type: number
|
||||
min: 2
|
||||
max: 30
|
||||
facebook.enabled:
|
||||
type: toggle
|
||||
label: PLUGINS.AUTO_SEO.FACEBOOK.ENABLED_LABEL
|
||||
help: PLUGINS.AUTO_SEO.FACEBOOK.ENABLED_HELP
|
||||
highlight: 1
|
||||
default: 0
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
twitter.enabled:
|
||||
type: toggle
|
||||
label: PLUGINS.AUTO_SEO.TWITTER.ENABLED_LABEL
|
||||
help: PLUGINS.AUTO_SEO.TWITTER.ENABLED_HELP
|
||||
highlight: 1
|
||||
default: 0
|
||||
options:
|
||||
1: PLUGIN_ADMIN.ENABLED
|
||||
0: PLUGIN_ADMIN.DISABLED
|
||||
validate:
|
||||
type: bool
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
# English
|
||||
en:
|
||||
PLUGINS:
|
||||
AUTO_SEO:
|
||||
GLOBAL_CONFIG: Global configuration
|
||||
PLUGIN_STATUS: Plugin status
|
||||
DEFAULT_CONFIG: Default values for the plugin configuration
|
||||
PLUGIN_DEPENDENCY_FAILED: Auto SEO Plugin failed to load. Composer dependencies not met.
|
||||
DESCRIPTION:
|
||||
ENABLED_LABEL: Auto fill for "description" meta
|
||||
ENABLED_HELP: Lets you turn the plugin ON and OFF for the "description" metadata only.
|
||||
LENGTH_LABEL: Maximum word count for "description" meta
|
||||
LENGTH_HELP: The maximum count of words that will be used to fill the "description" metadata.
|
||||
KEYWORDS:
|
||||
ENABLED_LABEL: Auto fill for the "keywords" meta
|
||||
ENABLED_HELP: Lets you turn the plugin ON and OFF for the "keywords" metadata only.
|
||||
LENGTH_LABEL: Maximum word count for "keywords" meta.
|
||||
LENGTH_HELP: The maximum count of words that will be used to fill the "keyword" metadata.
|
||||
FACEBOOK:
|
||||
ENABLED_LABEL: Auto fill for the Open Graph tags (facebook)
|
||||
ENABLED_HELP: Lets you turn the plugin ON and OFF for the "Open Graph" metadata (facebook).
|
||||
TWITTER:
|
||||
ENABLED_LABEL: Auto fill for the Twitter tags
|
||||
ENABLED_HELP: Lets you turn the plugin ON and OFF for the "Twitter Cards" metadata.
|
||||
|
||||
# French
|
||||
fr:
|
||||
PLUGINS:
|
||||
AUTO_SEO:
|
||||
GLOBAL_CONFIG: Configuration globale
|
||||
PLUGIN_STATUS: Etat du plugin
|
||||
DEFAULT_CONFIG: Valeurs par défaut pour la configuration du plugin
|
||||
PLUGIN_DEPENDENCY_FAILED: le plug-in Auto SEO n'a pas pu être chargé. Les dépendances de Composer ne sont pas remplies.
|
||||
DESCRIPTION:
|
||||
ENABLED_LABEL: Remplissage automatique pour la méta "Description"
|
||||
ENABLED_HELP: Permet de mettre le plugin ON et OFF pour la métadonnée "Description" uniquement.
|
||||
LENGTH_LABEL: nombre maximal de mots pour la méta "Description"
|
||||
LENGTH_HELP: le nombre maximum de mots qui seront utilisés pour remplir la métadonnée "Description".
|
||||
KEYWORDS:
|
||||
ENABLED_LABEL: Remplissage automatique pour la méta "Keywords"
|
||||
ENABLED_HELP: Permet de mettre le plugin ON et OFF pour la métadonnée "Keywords" uniquement.
|
||||
LENGTH_LABEL: Nombre maximal de mots pour la méta "Keywords".
|
||||
LENGTH_HELP: Le nombre maximum de mots qui seront utilisés pour remplir la métadonnée "Keywords".
|
||||
FACEBOOK:
|
||||
ENABLED_LABEL: Remplissage automatique pour les tags Open Graph (facebook)
|
||||
ENABLED_HELP: Permet de mettre le plugin ON et OFF pour la métadonnée "Open Graph" (facebook).
|
||||
TWITTER:
|
||||
ENABLED_LABEL: Remplissage automatique pour les tags Twitter
|
||||
ENABLED_HELP: Permet de mettre le plugin ON et OFF pour la métadonnée "Twitter Cards".
|
||||
Reference in New Issue
Block a user