Page MenuHomeDevCentral

No OneTemporary

diff --git a/index.php b/index.php
new file mode 100644
index 0000000..d701d0c
--- /dev/null
+++ b/index.php
@@ -0,0 +1,50 @@
+<!-- Content -->
+<div id="content">
+ <h1 class="icoTitle"><img src="/_pict/ico/forms.png" alt="Tools - form generation"/>{{Lien web}}</h1>
+ <form method="post">
+ <label for="URL">URL: </label><input type="text" size="80" name="URL" id="URL" value="<?= $_REQUEST['URL'] ?>" />
+ </form>
+<?php
+if (array_key_exists('URL', $_REQUEST)) {
+ include('page.php');
+
+ $url = $_REQUEST['URL'];
+ setlocale(LC_TIME, 'fr_FR.UTF-8');
+ $page = Page::load($url);
+ if ($page->is_article()) {
+ echo "<h3>Note</h3><p>Cette URL pointe vers un article de revue, aussi le modèle {{Article}} est indiqué.</p>";
+ }
+
+ //Template
+ echo " <h3>Template</h3> \n <textarea id=\"template\" rows=20 cols=80>\n";
+ require('templates/template.php');
+ if ($page->is_article()) {
+ require('templates/wikipedia-fr/Article.php');
+ $template = ArticleTemplate::loadFromPage($page);
+ } else {
+ require('templates/wikipedia-fr/Lien_web.php');
+ $template = LienWebTemplate::loadFromPage($page);
+ }
+ echo $template, '</textarea>';
+
+ //Meta tags
+ echo "\n\n <h3>Meta tags</h3>\n <table cellpadding=8>\n <tr><th>Tag</th><th>Value</th></tr>";
+ foreach ($page->meta_tags as $key => $value) {
+ echo " <tr><td>$key</td><td>$value</td></tr>";
+ }
+ echo "\n </table>";
+}
+?>
+</div>
+
+<!-- left menu -->
+<div id="leftMenu">
+ <ul class="navMenu">
+ <li><a href="http://fr.wikipedia.org/wiki/Modèle:Lien web">{{Lien web}}</a></li>
+ <li><a href="http://fr.wikipedia.org/wiki/Modèle:Article">{{Article}}</a></li>
+ <li><a href="http://www.prismstandard.org/specifications/">PRISM</a></li>
+ <li><a href="http://dublincore.org/">Dublin Core</a></li>
+ <li><a href="http://scholar.google.com/intl/en/scholar/inclusion.html">Google
+Scholar</a></li>
+ </ul>
+</div>
diff --git a/page.php b/page.php
new file mode 100644
index 0000000..3f6b365
--- /dev/null
+++ b/page.php
@@ -0,0 +1,91 @@
+<?php
+
+define('LONG_DATE_FORMAT', '%e %B %Y');
+
+class Page {
+ public $url;
+
+ /**
+ * @var array Meta tags
+ */
+ public $meta_tags;
+
+ /**
+ * @var string The page content
+ */
+ public $data;
+
+ public $title;
+
+ function __construct ($url) {
+ $this->url = $url;
+ $this->data = file_get_contents($url);
+ $this->analyse();
+ }
+
+ static function load ($url) {
+ $pages = file('pages/index.dat', true);
+ foreach ($pages as $line) {
+ $page = explode("\t", $line);
+ if (substr($url, 0, strlen($page[0])) == $page[0]) {
+ $file = strtolower(trim($page[1])) . '.php';
+ $class = trim($page[1]) . 'Page';
+
+ require("pages/$file");
+ return new $class($url);
+ }
+ }
+ return new Page($url);
+ }
+
+ function analyse () {
+ $this->meta_tags = $this->get_meta_tags();
+ $this->title = $this->get_title();
+ }
+
+ function get_meta_tags () {
+ return get_meta_tags($this->url);
+ }
+
+ function get_all_meta_tags () {
+ //Thank you to Michael Knapp and Mariano
+ //See http://php.net/manual/en/function.get-meta-tags.php comments
+ preg_match_all('/<[\s]*meta[\s]*\b(name|property|itemprop)\b="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $this->data, $match);
+
+ if (isset($match) && is_array($match) && count($match) == 4)
+ {
+ $originals = $match[0];
+ $names = $match[2];
+ $values = $match[3];
+
+ if (count($originals) == count($names) && count($names) ==
+count($values))
+ {
+ $metaTags = array();
+
+ for ($i=0, $limiti=count($names); $i < $limiti; $i++)
+ {
+ $metaTags[$names[$i]] = $values[$i];
+ }
+ }
+ }
+
+ return $metaTags;
+ }
+
+ /**
+ * Gets title
+ *
+ * @return string The page title
+ */
+ function get_title () {
+ return (preg_match("#<title>(.+)<\/title>#iU", $this->data, $title)) ? trim($title[1]) : '';
+ }
+
+ function is_article () {
+ if (array_key_exists('dc_type', $this->meta_tags) && $this->meta_tags['dc_type'] == 'journalArticle') {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/pages/index.dat b/pages/index.dat
new file mode 100644
index 0000000..8cce940
--- /dev/null
+++ b/pages/index.dat
@@ -0,0 +1 @@
+http://www.rue89.com/ Rue89
diff --git a/pages/rue89.php b/pages/rue89.php
new file mode 100644
index 0000000..18f5c79
--- /dev/null
+++ b/pages/rue89.php
@@ -0,0 +1,38 @@
+<?php
+
+//Page analysis for www.rue89.com
+class Rue89Page extends Page {
+ function analyse () {
+ parent::analyse();
+
+ //Hardcoded known info
+ $this->site = "Rue 89";
+ $this->skipYMD = true;
+
+ //Gets date
+ // http://www.rue89.com/2011/02/26/
+ $yyyy = substr($this->url, 21, 4);
+ $mm = substr($this->url, 26, 2);
+ $dd = substr($this->url, 29, 2);
+ $this->date = strftime(LONG_DATE_FORMAT, mktime(0, 0, 0, $mm, $dd, $yyyy));
+
+ //Gets author
+ //TODO: ensure no article has more than one author
+ $pos1 = strpos($this->data, '<div class="authors">');
+ $pos1 = strpos($this->data, 'class="author">', $pos1) + 15;
+ $pos2 = strpos($this->data, '/a>', $pos1) - 1;
+ $this->author = substr($this->data, $pos1, $pos2 - $pos1);
+ }
+
+ function get_title () {
+ //Article title is the meta tag name, and not the page title
+ return $this->meta_tags['name'];
+ }
+
+ function get_meta_tags () {
+ //Rue89 doesn't always use <meta name="" value=""> but sometimes property= or itemprop=
+ return $this->get_all_meta_tags();
+ }
+}
+
+?>
diff --git a/templates/template.php b/templates/template.php
new file mode 100644
index 0000000..3629bd8
--- /dev/null
+++ b/templates/template.php
@@ -0,0 +1,28 @@
+<?php
+class template {
+ /**
+ * @var Array the template parameters
+ */
+ var $params;
+
+ /**
+ * @var string the template name
+ */
+ var $name;
+
+ /**
+ * Gets the wikicode string representation of the template
+ *
+ * @return string the template wikicode
+ */
+ function __toString () {
+ $template = '{{' . $this->name . "\n";
+ foreach ($this->params as $key => $value) {
+ $template .= " | $key = $value\n";
+ }
+ $template .= '}}';
+
+ return $template;
+ }
+}
+?>
diff --git a/templates/wikipedia-fr/Article.php b/templates/wikipedia-fr/Article.php
new file mode 100644
index 0000000..54f6ea0
--- /dev/null
+++ b/templates/wikipedia-fr/Article.php
@@ -0,0 +1,130 @@
+<?php
+setlocale(LC_TIME, 'fr_FR.UTF-8');
+
+class ArticleTemplate extends Template {
+ public $lang;
+ public $title;
+ public $periodique;
+ public $year;
+ public $accessdate;
+
+ function __construct () {
+ $this->name = "Article";
+ $this->accessdate = trim(strftime(LONG_DATE_FORMAT));
+ }
+
+ static function loadFromPage ($page) {
+ $template = new self();
+ $t = $page->meta_tags;
+
+ //Language
+ $template->lang = self::getMetaTag($t, 'dc_language', 'citation_language');
+
+ //Authors
+ if ($author = self::getMetaTag($t, 'author', 'dc_creator', 'citation_authors')) {
+ $template->authors[] = explode(', ', $author, 2);
+ }
+
+ //Title
+ if (!$template->title = self::getMetaTag($t, 'dc_title', 'citation_title')) {
+ $template->title = $page->title;
+ }
+
+ //Journal, publisher
+ $template->journal = self::getMetaTag($t, 'prism_publicationname', 'citation_journal_title');
+ $template->journalLink = $t['dc_source'];
+ $template->publisher = self::getMetaTag($t, 'dc_publisher', 'citation_publisher');
+
+ //Issue name and number
+ $template->issue = self::getMetaTag($t, 'prism_number', 'citation_issue');
+ if (
+ (!$template->issueName = $t['prism_issuename'])
+ &&
+ array_key_exists('dc_relation_ispartof', $t)
+ ) {
+ $template->issueName = $t['dc_relation_ispartof']
+ . " <!-- !!! paramètre à nettoyer !!! -->";
+ }
+
+ //Date
+ $date = self::getMetaTag($t, 'prism_publicationdate', 'dc_date', 'citation_date');
+ $template->yyyy = substr($date, 0, 4);
+ $template->mm = substr($date, 5, 2);
+ $template->dd = substr($date, 8, 2);
+
+ //Pages
+ $template->pageStart = self::getMetaTag($t, 'prism_startingpage' , 'citation_firstpage');
+ $template->pageEnd = self::getMetaTag($t, 'prism_endingpage', 'citation_lastpage');
+
+ //ISBN, ISSN, URL
+ $template->issn = self::getMetaTag($t, 'prism_issn', 'citation_issn');
+ $template->isbn = self::getMetaTag($t, 'citation_isbn');
+ $template->summary = self::getMetaTag($t, 'citation_abstract_html_url');
+ $template->url = $page->url;
+
+ return $template;
+ }
+
+ function __toString () {
+ //Langue
+ $this->params['langue'] = $this->lang;
+
+ //Authors
+ $k = 1;
+ foreach ($this->authors as $author) {
+ $this->params["prénom$k"] = $author[1];
+ $this->params["nom$k"] = $author[0];
+ $this->params["lien auteur$k"] = '';
+ $k++;
+ }
+
+ //Titre, périodique, éditeur, volume, etc.
+ $this->params['titre'] = $this->title;
+ $this->params['périodique'] = $this->journal;
+ $this->params['lien périodique'] = $this->journalLink;
+ $this->params['éditeur'] = $this->publisher;
+ $this->params['numéro'] = $this->issue;
+ $this->params['titre numéro'] = $this->issueName;
+
+ //Date
+ $date = mktime(12, 0, 0, $this->mm, $this->dd, $this->yyyy);
+ $this->params['jour'] = trim(strftime('%e', $date));
+ $this->params['mois'] = strftime('%B', $date);
+ $this->params['année'] = $this->yyyy;
+
+ //Pages, ISSN, ISBN, URL, consulté le
+ $this->params['pages'] = $this->pageEnd ? ($this->pageStart . '-' . $this->pageEnd) : $this->pageStart;
+ $this->params['ISSN'] = $this->issn;
+ $this->params['ISBN'] = $this->isbn;
+ $this->params['url texte'] = $this->url;
+ if ($this->summary != '' && $this->summary != $this->url) {
+ $this->params['résumé'] = $this->summary;
+ }
+ $this->params['consulté le'] = trim(strftime(LONG_DATE_FORMAT));
+
+ return parent::__toString();
+ }
+
+ /**
+ * Gets relevant metatag
+ *
+ * @param array the metatags
+ * @param string... the list of acceptable metatags
+ *
+ * @return string the first metatag value found
+ */
+ static function getMetaTag () {
+ $tags = func_get_args();
+ $metatags = array_shift($tags);
+
+ foreach ($tags as $tag) {
+ if (array_key_exists($tag, $metatags)) {
+ return $metatags[$tag];
+ }
+ }
+
+ return '';
+ }
+
+}
+?>
diff --git a/templates/wikipedia-fr/Lien_web.php b/templates/wikipedia-fr/Lien_web.php
new file mode 100644
index 0000000..4958538
--- /dev/null
+++ b/templates/wikipedia-fr/Lien_web.php
@@ -0,0 +1,57 @@
+<?php
+setlocale(LC_TIME, 'fr_FR.UTF-8');
+
+class LienWebTemplate extends Template {
+ public $author;
+ public $url;
+ public $title;
+ public $dd;
+ public $mm;
+ public $yyyy;
+ public $site;
+ public $publishdate;
+ public $accessdate;
+
+ /**
+ * @var bool Indicates if we've to remove jour/mois/année parameters
+ */
+ public $skipYMD = false;
+
+ function __construct () {
+ $this->name = "Lien web";
+ $this->accessdate = trim(strftime(LONG_DATE_FORMAT));
+ }
+
+ static function loadFromPage ($page) {
+ $template = new LienWebTemplate();
+
+ $template->author = $page->author;
+ $template->url = $page->url;
+ $template->title = $page->title;
+ $template->dd = $page->yyyy;
+ $template->mm = $page->yyyy;
+ $template->yyyy = $page->yyyy;
+ $template->site = $page->site;
+ $template->publishdate = $page->date;
+ $template->skipYMD = $page->skipYMD;
+
+ return $template;
+ }
+
+ function __toString () {
+ $this->params['auteur'] = $this->author;
+ $this->params['url'] = $this->url;
+ $this->params['titre'] = $this->title;
+ if (!$this->skipYMD) {
+ $this->params['jour'] = $this->mm;
+ $this->params['mois'] = $this->dd;
+ $this->params['année'] = $this->yyyy;
+ }
+ $this->params['site'] = $this->site;
+ $this->params['en ligne le'] = $this->publishdate;
+ $this->params['consulté le'] = $this->accessdate;
+
+ return parent::__toString();
+ }
+}
+?>

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 25, 19:40 (4 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260872
Default Alt Text
(12 KB)

Event Timeline