aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-01-27 21:51:24 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-01-27 21:51:24 +0100
commit7f51bf0d02b410c482fff60c39c4af532fbc683e (patch)
treefa1a418b0b1be15c8703fc211ac373c873561b5a /app/Models
parent4e4b0f717fe0a8378e2b751393a8c19d1ada6eb2 (diff)
parent16fffc16dd4cfddc15d3edb224c27147e7661e13 (diff)
Merge branch 'dev' into beta
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Configuration.php4
-rw-r--r--app/Models/Feed.php44
-rw-r--r--app/Models/StatsDAO.php205
3 files changed, 208 insertions, 45 deletions
diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php
index f3fb76e72..2a7fe95aa 100644
--- a/app/Models/Configuration.php
+++ b/app/Models/Configuration.php
@@ -48,7 +48,7 @@ class FreshRSS_Configuration {
'bottomline_link' => true,
'sharing' => array(
'shaarli' => '',
- 'poche' => '',
+ 'wallabag' => '',
'diaspora' => '',
'twitter' => true,
'g+' => true,
@@ -185,7 +185,7 @@ class FreshRSS_Configuration {
}
}
public function _sharing ($values) {
- $are_url = array ('shaarli', 'poche', 'diaspora');
+ $are_url = array ('shaarli', 'wallabag', 'diaspora');
foreach ($values as $key => $value) {
if (in_array($key, $are_url)) {
$is_url = (
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index df762c8fa..22c019080 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -187,54 +187,12 @@ class FreshRSS_Feed extends Minz_Model {
Minz_Exception::ERROR
);
} else {
- $feed = new SimplePie ();
- $feed->set_useragent(Minz_Translate::t ('freshrss') . '/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION);
$url = htmlspecialchars_decode ($this->url, ENT_QUOTES);
if ($this->httpAuth != '') {
$url = preg_replace ('#((.+)://)(.+)#', '${1}' . $this->httpAuth . '@${3}', $url);
}
-
+ $feed = customSimplePie();
$feed->set_feed_url ($url);
- $feed->set_cache_location (CACHE_PATH);
- $feed->set_cache_duration(1500);
- $feed->strip_htmltags (array (
- 'base', 'blink', 'body', 'doctype', 'embed',
- 'font', 'form', 'frame', 'frameset', 'html',
- 'input', 'marquee', 'meta', 'noscript',
- 'object', 'param', 'plaintext', 'script', 'style',
- ));
- $feed->strip_attributes(array_merge($feed->strip_attributes, array(
- 'autoplay', 'onload', 'onunload', 'onclick', 'ondblclick', 'onmousedown', 'onmouseup',
- 'onmouseover', 'onmousemove', 'onmouseout', 'onfocus', 'onblur',
- 'onkeypress', 'onkeydown', 'onkeyup', 'onselect', 'onchange', 'seamless')));
- $feed->add_attributes(array(
- 'img' => array('lazyload' => ''), //http://www.w3.org/TR/resource-priorities/
- 'audio' => array('preload' => 'none'),
- 'iframe' => array('postpone' => '', 'sandbox' => 'allow-scripts allow-same-origin'),
- 'video' => array('postpone' => '', 'preload' => 'none'),
- ));
- $feed->set_url_replacements(array(
- 'a' => 'href',
- 'area' => 'href',
- 'audio' => 'src',
- 'blockquote' => 'cite',
- 'del' => 'cite',
- 'form' => 'action',
- 'iframe' => 'src',
- 'img' => array(
- 'longdesc',
- 'src'
- ),
- 'input' => 'src',
- 'ins' => 'cite',
- 'q' => 'cite',
- 'source' => 'src',
- 'track' => 'src',
- 'video' => array(
- 'poster',
- 'src',
- ),
- ));
$feed->init ();
if ($feed->error ()) {
diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php
new file mode 100644
index 000000000..60cec7847
--- /dev/null
+++ b/app/Models/StatsDAO.php
@@ -0,0 +1,205 @@
+<?php
+
+class FreshRSS_StatsDAO extends Minz_ModelPdo {
+
+ /**
+ * Calculates entry repartition for all feeds and for main stream.
+ * The repartition includes:
+ * - total entries
+ * - read entries
+ * - unread entries
+ * - favorite entries
+ *
+ * @return type
+ */
+ public function calculateEntryRepartition() {
+ $repartition = array();
+
+ // Generates the repartition for the main stream of entry
+ $sql = <<<SQL
+SELECT COUNT(1) AS `total`,
+COUNT(1) - SUM(e.is_read) AS `unread`,
+SUM(e.is_read) AS `read`,
+SUM(e.is_favorite) AS `favorite`
+FROM {$this->prefix}entry AS e
+, {$this->prefix}feed AS f
+WHERE e.id_feed = f.id
+AND f.priority = 10
+SQL;
+ $stm = $this->bd->prepare($sql);
+ $stm->execute();
+ $res = $stm->fetchAll(PDO::FETCH_ASSOC);
+ $repartition['main_stream'] = $res[0];
+
+ // Generates the repartition for all entries
+ $sql = <<<SQL
+SELECT COUNT(1) AS `total`,
+COUNT(1) - SUM(e.is_read) AS `unread`,
+SUM(e.is_read) AS `read`,
+SUM(e.is_favorite) AS `favorite`
+FROM {$this->prefix}entry AS e
+SQL;
+ $stm = $this->bd->prepare($sql);
+ $stm->execute();
+ $res = $stm->fetchAll(PDO::FETCH_ASSOC);
+ $repartition['all_feeds'] = $res[0];
+
+ return $repartition;
+ }
+
+ /**
+ * Calculates entry count per day on a 30 days period.
+ * Returns the result as a JSON string.
+ *
+ * @return string
+ */
+ public function calculateEntryCount() {
+ $count = array();
+
+ // Generates a list of 30 last day to be sure we always have 30 days.
+ // If we do not do that kind of thing, we'll end up with holes in the
+ // days if the user do not have a lot of feeds.
+ $sql = <<<SQL
+SELECT - (tens.val + units.val + 1) AS day
+FROM (
+ SELECT 0 AS val
+ UNION ALL SELECT 1
+ UNION ALL SELECT 2
+ UNION ALL SELECT 3
+ UNION ALL SELECT 4
+ UNION ALL SELECT 5
+ UNION ALL SELECT 6
+ UNION ALL SELECT 7
+ UNION ALL SELECT 8
+ UNION ALL SELECT 9
+) AS units
+CROSS JOIN (
+ SELECT 0 AS val
+ UNION ALL SELECT 10
+ UNION ALL SELECT 20
+) AS tens
+ORDER BY day ASC
+SQL;
+ $stm = $this->bd->prepare($sql);
+ $stm->execute();
+ $res = $stm->fetchAll(PDO::FETCH_ASSOC);
+ foreach ($res as $value) {
+ $count[$value['day']] = 0;
+ }
+
+ // Get stats per day for the last 30 days and applies the result on
+ // the array created with the last query.
+ $sql = <<<SQL
+SELECT DATEDIFF(FROM_UNIXTIME(e.date), NOW()) AS day,
+COUNT(1) AS count
+FROM {$this->prefix}entry AS e
+WHERE FROM_UNIXTIME(e.date, '%Y%m%d') BETWEEN DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -30 DAY), '%Y%m%d') AND DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -1 DAY), '%Y%m%d')
+GROUP BY day
+ORDER BY day ASC
+SQL;
+ $stm = $this->bd->prepare($sql);
+ $stm->execute();
+ $res = $stm->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach ($res as $value) {
+ $count[$value['day']] = (int) $value['count'];
+ }
+
+ return $this->convertToSerie($count);
+ }
+
+ /**
+ * Calculates feed count per category.
+ * Returns the result as a JSON string.
+ *
+ * @return string
+ */
+ public function calculateFeedByCategory() {
+ $sql = <<<SQL
+SELECT c.name AS label
+, COUNT(f.id) AS data
+FROM {$this->prefix}category AS c,
+{$this->prefix}feed AS f
+WHERE c.id = f.category
+GROUP BY label
+ORDER BY data DESC
+SQL;
+ $stm = $this->bd->prepare($sql);
+ $stm->execute();
+ $res = $stm->fetchAll(PDO::FETCH_ASSOC);
+
+ return $this->convertToPieSerie($res);
+ }
+
+ /**
+ * Calculates entry count per category.
+ * Returns the result as a JSON string.
+ *
+ * @return string
+ */
+ public function calculateEntryByCategory() {
+ $sql = <<<SQL
+SELECT c.name AS label
+, COUNT(e.id) AS data
+FROM {$this->prefix}category AS c,
+{$this->prefix}feed AS f,
+{$this->prefix}entry AS e
+WHERE c.id = f.category
+AND f.id = e.id_feed
+GROUP BY label
+ORDER BY data DESC
+SQL;
+ $stm = $this->bd->prepare($sql);
+ $stm->execute();
+ $res = $stm->fetchAll(PDO::FETCH_ASSOC);
+
+ return $this->convertToPieSerie($res);
+ }
+
+ /**
+ * Calculates the 10 top feeds based on their number of entries
+ *
+ * @return array
+ */
+ public function calculateTopFeed() {
+ $sql = <<<SQL
+SELECT f.id AS id
+, MAX(f.name) AS name
+, MAX(c.name) AS category
+, COUNT(e.id) AS count
+FROM {$this->prefix}category AS c,
+{$this->prefix}feed AS f,
+{$this->prefix}entry AS e
+WHERE c.id = f.category
+AND f.id = e.id_feed
+GROUP BY id
+ORDER BY count DESC
+LIMIT 10
+SQL;
+ $stm = $this->bd->prepare($sql);
+ $stm->execute();
+ return $stm->fetchAll(PDO::FETCH_ASSOC);
+ }
+
+ private function convertToSerie($data) {
+ $serie = array();
+
+ foreach ($data as $key => $value) {
+ $serie[] = array($key, $value);
+ }
+
+ return json_encode($serie);
+ }
+
+ private function convertToPieSerie($data) {
+ $serie = array();
+
+ foreach ($data as $value) {
+ $value['data'] = array(array(0, (int) $value['data']));
+ $serie[] = $value;
+ }
+
+ return json_encode($serie);
+ }
+
+}