* @category wallabag
* @author Nicolas LÅ“uillet <nicolas@loeuillet.org>
* @copyright 2013
- * @license http://www.wtfpl.net/ see COPYING file
+ * @license http://opensource.org/licenses/MIT see COPYING file
*/
class Database {
}
$this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $this->_checkTags();
Tools::logm('storage type ' . STORAGE);
}
return $this->handle;
}
- public function isInstalled() {
- $sql = "SELECT username FROM users";
- $query = $this->executeQuery($sql, array());
- if ($query == false) {
- die(STORAGE . ' database looks empty. You have to create it (you can find database structure in install folder).');
- }
- $hasAdmin = count($query->fetchAll());
-
- if ($hasAdmin == 0)
- return false;
-
- return true;
- }
-
- public function checkTags() {
+ private function _checkTags() {
if (STORAGE == 'sqlite') {
$sql = '
return $query;
}
-
- private function _getDomain($url)
- {
- return parse_url($url, PHP_URL_HOST);
- }
-
- private function _getReadingTime($text) {
- $word = str_word_count(strip_tags($text));
- $minutes = floor($word / 200);
- $seconds = floor($word % 200 / (200 / 60));
- $time = array('minutes' => $minutes, 'seconds' => $seconds);
-
- return $minutes;
- }
-
/**
*
* @param string $url
* @return integer $id of inserted record
*/
public function add($url, $title, $content, $user_id, $isFavorite=0, $isRead=0) {
- $readingTime = $this->_getReadingTime($content);
- $domainName = $this->_getDomain($url);
- $date = date('Y-m-d H:i:s');
+ $sql_action = 'INSERT INTO entries ( url, title, content, user_id, is_fav, is_read ) VALUES (?, ?, ?, ?, ?, ?)';
+ $params_action = array($url, $title, $content, $user_id, $isFavorite, $isRead);
- $sql_action = 'INSERT INTO entries ( url, title, content, user_id, is_fav, is_read, date, reading_time, domain_name ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)';
- $params_action = array($url, $title, $content, $user_id, $isFavorite, $isRead, $date, $readingTime, $domainName);
if ( !$this->executeQuery($sql_action, $params_action) ) {
$id = null;
}