Example #1
0
 /**
  * Записывает видео в топ саммых папулярных видео если оно подходит по балам или видео в топе не привышает MAX_POPULAR_VIDEO_IN_CATEGORY
  * @param $videoId
  * @param $categoriesIds
  * @param $balls
  * @throws Exception
  */
 public function setPopularVideo($videoId, $categoriesIds, $balls)
 {
     if (!empty($categoriesIds)) {
         $categories = explode(',', $categoriesIds);
         foreach ($categories as $category) {
             // Если видео есть в списке популярных то в нем просто обновляются баллы
             $this->db->query("UPDATE video_popular SET balls = :balls WHERE video_id = :videoId AND category_id = :categoryId", ['videoId' => $videoId, 'categoryId' => $category, 'balls' => $balls]);
             if ($this->db->getConnect()->affected_rows < 1) {
                 // если нет видео, получается видео с самым меньшим колличеством баллов
                 $minBallsVideo = $this->db->fetchRow("SELECT SQL_CALC_FOUND_ROWS * FROM video_popular WHERE category_id = :categoryId ORDER BY balls ASC LIMIT 1", ['categoryId' => $category]);
                 $foundRows = $this->db->fetchOne("SELECT FOUND_ROWS();");
                 $insertVideo = false;
                 // если популярных видео в категории меньше чем значение это значит что мы можем просто добавить видео в популярные
                 if ($foundRows < self::MAX_POPULAR_VIDEO_IN_CATEGORY) {
                     $insertVideo = true;
                 } else {
                     if ($minBallsVideo['balls'] < $balls) {
                         // если у текущего видео балл выше чем у видео с наименьшим балом, то заменяем видео с наименьшим балом на текущее.
                         $insertVideo = true;
                         $this->db->query("DELETE FROM video_popular WHERE video_id = :videoId AND category_id = :categoryId", ['videoId' => $minBallsVideo['video_id'], 'categoryId' => $minBallsVideo['category_id']]);
                     }
                 }
                 if ($insertVideo) {
                     $this->db->query("INSERT INTO video_popular (video_id, category_id, balls) VALUES (:videoId, :categoryId, :balls)", ['videoId' => $videoId, 'categoryId' => $category, 'balls' => $balls]);
                 }
             }
         }
     }
 }
Example #2
0
 public static function pos($inmueble)
 {
     $pos = Db::fetchOne(Db::select(array('pos' => 'MAX(posicion)'), 'inmuebles_paginas', array('inmueble_id' => $inmueble)));
     if (empty($pos)) {
         $pos = 0;
     }
     return $pos;
 }
Example #3
0
if (!empty($_POST)) {
    $email = strtolower($_POST['email']);
    $password = $_POST['password'];
    $passwordagain = $_POST['passwordagain'];
    $captcha = strtolower($_POST['captcha']);
    if (!Session::captchaCompare('signup', $captcha)) {
        $error['captcha'] = true;
    }
    if (!isEmail($email)) {
        $error['email'] = true;
    }
    if (strlen($password) < 6) {
        $error['password'] = true;
    }
    if ($passwordagain != $password) {
        $error['passwordagain'] = true;
    }
    if (empty($error)) {
        $emailexists = Db::fetchOne("SELECT email FROM users\n             WHERE email = '{$email}'");
        if (!empty($emailexists)) {
            $error['email'] = true;
        }
    }
    if (empty($error)) {
        Db::insert('users', array('email' => $email, 'password' => md5($password)));
        $uid = Db::inserted();
        Db::update('projects_access', array('uid' => $uid), "email = '{$email}'");
        header("Location: {$config['root']}signin/?email={$email}");
    }
}
require_once "{$root}/themes/{$theme}/signup.php";
Example #4
0
include_once "{$root}/common.php";
$title = __('TLDsSuggest');
if (!empty($_POST)) {
    $domain = $_POST['domain'];
    $description = $_POST['description'];
    $captcha = strtolower($_POST['captcha']);
    if (substr($domain, 0, 1) == '.') {
        $domain = substr($domain, 1);
    }
    $domain = strtolower($domain);
    if (!Session::captchaCompare('tldssuggest', $captcha)) {
        $error['captcha'] = true;
    }
    if (strlen($domain) < 2 || !isTLD($domain)) {
        $error['domain'] = true;
    }
    if (!empty($description) && strlen($description) > 140) {
        $error['description'] = true;
    }
    if (empty($error)) {
        $tldexists = Db::fetchOne("SELECT domain FROM tlds\n             WHERE LCASE(domain) = '{$domain}'");
        if (!empty($tldexists)) {
            $error['domainexists'] = true;
        }
    }
    if (empty($error)) {
        Db::insert('tlds', array('domain' => $domain, 'description' => $description, 'suggest' => 1));
        header("Location: {$config['root']}tlds/");
    }
}
require_once "{$root}/themes/{$theme}/tldssuggest.php";
Example #5
0
include_once "{$root}/config.php";
include_once "{$root}/common.php";
if (Session::$logged) {
    header("Location: {$config['root']}dd/");
}
$title = __('RestoreTitle');
$error = array();
if (isset($_GET['email']) && isEmail($_GET['email'])) {
    $email = $_GET['email'];
}
if (!empty($_POST)) {
    $email = $_POST['email'];
    if (!isEmail($email)) {
        $error['email'] = true;
    } else {
        $uid = Db::fetchOne("SELECT uid FROM users\n             WHERE email = '{$email}'");
        if (empty($uid)) {
            $error['email'] = true;
        }
    }
    if (empty($error)) {
        $password = '';
        for ($i = 0; $i < 8; $i++) {
            $password .= rand(0, 9);
        }
        Db::update('users', array('password' => md5($password)), "uid = '{$uid}'");
        /**
         * @todo Send email.
         */
        header("Location: {$config['root']}signin/?email={$email}");
    }
Example #6
0
if (!empty($_POST)) {
    $name = $_POST['name'];
    $description = $_POST['description'];
    $public = $_POST['public'] ? 1 : 0;
    $domains = $_POST['domain'];
    if (strlen($name) < 3) {
        $error['name'] = true;
    }
    if (!empty($description) && strlen($description) > 140) {
        $error['description'] = true;
    }
    if (empty($error)) {
        if ($pid) {
            if (!empty($domains) && is_array($domains)) {
                foreach ($domains as $tid => $active) {
                    if (!$active) {
                        continue;
                    }
                    $tldexists = Db::fetchOne("SELECT tid FROM projects_tlds\n                         WHERE pid = '{$pid}' AND tid = '{$tid}'");
                    if (empty($tldexists)) {
                        Db::insert('projects_tlds', array('pid' => $pid, 'tid' => $tid));
                    }
                }
                Db::query("DELETE FROM projects_tlds\n                     WHERE pid = '{$pid}'\n                       AND tid NOT IN ( '" . implode("', '", array_keys($domains)) . "' )");
            }
            Db::update('projects', array('name' => $name, 'description' => $description, 'public' => $public), "pid = '{$pid}'");
        }
        header("Location: {$config['root']}dd/projects/");
    }
}
require_once "{$root}/themes/{$theme}/ddprojectsedit.php";
Example #7
0
 protected function getValue($name)
 {
     $this->autoload();
     if (isset($this->all[$name])) {
         return $this->all[$name];
     }
     $value = Db::fetchOne('SELECT option_value FROM `' . Common::prefixTable('option') . '` ' . 'WHERE option_name = ?', $name);
     if ($value === false) {
         return false;
     }
     $this->all[$name] = $value;
     return $value;
 }
Example #8
0
 /**
  * Devuelve la cantidad de registros en una tabla.
  *
  * @param string $table
  * @param string|array|null $where
  * @return integer
  */
 public static function count($table, $where = null)
 {
     $where = self::where($where);
     return Db::fetchOne("SELECT COUNT(*) FROM {$table}\n             WHERE {$where}");
 }
Example #9
0
<?php

$root = '.';
include_once "{$root}/config.php";
include_once "{$root}/common.php";
if (!Session::$logged) {
    header("Location: {$config['root']}signin/?next={$config['root']}dd/projects/");
}
$title = __('ProjectsTitle');
$count = Db::fetchOne("SELECT COUNT(*) FROM projects WHERE uid = '" . Session::_('uid') . "'");
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$start = ($page - 1) * $config['perpage'];
$projects = Db::fetchAssoc("SELECT pid, name, description\n     FROM projects\n     WHERE uid = '" . Session::_('uid') . "'\n     ORDER BY name\n     LIMIT {$start},{$config['perpage']}");
$pagination = pagination("{$config['root']}dd/projects/", $count, $config['perpage'], $page);
require_once "{$root}/themes/{$theme}/ddprojects.php";
Example #10
0
 protected function exists($id)
 {
     $exists = Db::fetchOne("SELECT COUNT(id_user)\n             FROM twcensus_users\n             WHERE id_user = '******'");
     return $exists > 0;
 }
Example #11
0
 /**
  * Get the SiteId from the given site url using mysql
  * driver.
  *
  * @param string $domain
  *
  * @return int $id
  */
 public function getSiteId($domain)
 {
     $parsedDomain = parse_url($domain);
     $domain = 'http://' . $parsedDomain['path'];
     $siteId = Db::fetchOne('SELECT idsite FROM piwik_site WHERE main_url=?', array($domain));
     if (!$siteId) {
         $siteId = Db::fetchOne('SELECT idsite FROM piwik_site_url WHERE url=?', array($domain));
     }
     return $siteId;
 }