Ejemplo n.º 1
0
 function index()
 {
     $conn = Db::get_connection();
     if (isset($_GET['software_name'])) {
         $software_factory = new Software();
         $softwares = $software_factory->find_all(array('where_clause' => "`name` = '{$conn->escape($_GET['software_name'])}' AND (`name` != 'guidatv' OR `type` = 'macosx')", 'limit' => 1));
         if (count($softwares) > 0) {
             $this->software = $softwares[0];
             $this->software->has_many('software_releases');
             // Sort releases
             $releases = $this->software->software_releases;
             usort($releases, array($releases[0], 'sort_releases'));
             $this->software->release = $releases[0];
             $this->software->release->has_many('software_artifacts');
             // Horrible hack to enable per-software caching.
             $_REQUEST['id'] = $this->software->id;
         }
     } else {
         if (isset($_GET['id'])) {
             $this->software = new Software();
             $this->software->find_by_id($_GET['id']);
             $this->software->has_many('software_releases');
             // Sort releases
             $releases = $this->software->software_releases;
             usort($releases, array($releases[0], 'sort_releases'));
             $this->software->release = $releases[0];
             $this->software->release->has_many('software_artifacts');
         } else {
             $this->render_error();
         }
     }
     Db::close_connection($conn);
 }
Ejemplo n.º 2
0
 protected function close_connection()
 {
     if (isset($this->conn)) {
         Db::close_connection($this->conn);
         unset($this->conn);
     }
 }
Ejemplo n.º 3
0
 public static function quantita_history($isin, $username, $month_from)
 {
     $conn = Db::get_connection();
     $transaction_factory = new Transaction();
     $transactions = $transaction_factory->find_all(array('where_clause' => "`utente` = '{$conn->escape($username)}' " . "AND `isin` = '{$conn->escape($isin)}' " . "AND `data` >= '{$conn->escape($month_from)}' ", 'order_by' => '`data` DESC'));
     // print_r($transactions);
     $portfolio_stock_factory = new PortfolioStock();
     $portfolio_stock = $portfolio_stock_factory->find_all(array('where_clause' => "`utente` = '{$conn->escape($username)}' " . "AND `isin` = '{$conn->escape($isin)}' "))[0];
     // print_r($portfolio_stock);
     $quantita_history = array();
     $quantita_history[date('Y-m-d')] = $q = $portfolio_stock->quantita;
     $i = 0;
     do {
         if ($transactions[$i]->azione == 'acquisto') {
             $q -= $transactions[$i]->quantita;
         } else {
             $q += $transactions[$i]->quantita;
         }
         $quantita_history[$transactions[$i]->data] = $q;
         $i++;
     } while ($transactions[$i]->data > $_REQUEST['month-from']);
     // print_r($quantita_history);
     Db::close_connection($conn);
     return $quantita_history;
 }
Ejemplo n.º 4
0
 /**
  *	@fn login
  *	@short Action method to perform a login.
  */
 function login()
 {
     if ($this->request->is_post()) {
         $conn = Db::get_connection();
         $user_factory = new User();
         $users = $user_factory->find_all(array('where_clause' => "`username` = '{$conn->escape($_POST['username'])}' AND `password` = '" . md5($_POST['password']) . "'", 'limit' => 1));
         if (count($users) > 0) {
             $user = $users[0];
             $expires = $_POST['leave_me_registered'] ? Time::next_year() : Time::tomorrow();
             Cookie::set('_u', $user->username, $expires, "/", FALSE);
             Cookie::set('_uid', md5(Login::magic_phrase . $user->password), $expires, "/", FALSE);
             // Annotates the login in the database
             $user_login = new UserLogin();
             $user_login->user_id = $user->id;
             $user_login->performed_at = date("Y-m-d H:i:s");
             $user_login->save();
             $this->flash(sprintf(l('Welcome, %s'), $user->first), 'info');
             // When login is required to access a particular action, we may store controller & action in a session,
             // perform login, then redirect to the action requested in the first place
             if (isset($_SESSION['redirect_to'])) {
                 $this->redirect_to(array('controller' => $_SESSION['redirect_to']['controller'], 'action' => $_SESSION['redirect_to']['action']));
             } else {
                 $this->redirect_to(array('controller' => 'home'));
             }
             Db::close_connection($conn);
         } else {
             $this->flash(l('Bad username / password'), 'error');
         }
     }
     $this->redirect_to(array('action' => 'index'));
 }
Ejemplo n.º 5
0
 /**
  *	@fn is_blocked($ip_addr)
  *	@short Returns <tt>TRUE</tt> if <tt>ip_addr</tt> is in the blacklist,
  *	<tt>FALSE</tt> otherwise.
  *	@param ip_addr The IP address to test.
  */
 public static function is_blocked($ip_addr)
 {
     $conn = Db::get_connection();
     $bip_factory = new self();
     $ret = $bip_factory->find_all(array('where_clause' => "`ip_addr` = '{$conn->escape($ip_addr)}'"));
     Db::close_connection($conn);
     return count($ret) > 0;
 }
Ejemplo n.º 6
0
function delete_rows($table, $primary_key, $keys)
{
    $conn = Db::get_connection();
    foreach ($keys as $key) {
        $conn->prepare("DELETE FROM `{$conn->escape($table)}` WHERE `{$conn->escape($primary_key)}` = '{$conn->escape($key)}' LIMIT 1");
        $conn->exec();
    }
    Db::close_connection($conn);
}
Ejemplo n.º 7
0
 /**
  *	@fn check_spam_signature
  *	@short Checks whether the string of text has a recognized spam signature.
  *	@param $text The text that is used to calculate the spam signature.
  */
 public static function check_spam_signature($text)
 {
     $conn = Db::get_connection();
     $signature = self::get_spam_signature($text);
     $sig_factory = new SpamSignature();
     $matches = $sig_factory->find_all(array('where_clause' => "`signature` = '{$conn->escape($signature)}'"));
     Db::close_connection($conn);
     return count($matches) > 0;
 }
Ejemplo n.º 8
0
 /**
  *	@fn count_by_ip($the_ip)
  *	@short Returns the count of blocked visits for the desired IP address.
  *	@the_ip An IP address.
  */
 public static function count_by_ip($the_ip)
 {
     $conn = Db::get_connection();
     $conn->prepare("SELECT COUNT(*) FROM `{1}` WHERE `ip_addr` = '{2}'", $this->get_table_name(), $the_ip);
     $conn->exec();
     $ret = $conn->result(0);
     Db::close_connection($conn);
     return $ret;
 }
Ejemplo n.º 9
0
 public static function for_range_and_order($isin, $date_from, $date_to, $order_by, $sort_dir)
 {
     $conn = Db::get_connection();
     $quote = new Quote();
     $quotes = $quote->find_by_query('SELECT `id`, `quotazione` ' . 'FROM `creso_quotazioni` ' . "WHERE `isin` = '{$conn->escape($isin)}' " . "AND `data` > '{$conn->escape($date_from)}' " . "AND `data` < '{$conn->escape($date_to)}' " . "ORDER BY `{$conn->escape($order_by)}` {$conn->escape(strtoupper($sort_dir))} " . 'LIMIT 1');
     // print_r($quotes);
     Db::close_connection($conn);
     return $quotes[0];
 }
Ejemplo n.º 10
0
 /**
  *	@fn software
  *	@short Action method that generates the feed of software releases.
  */
 public function software()
 {
     $conn = Db::get_connection();
     $release_factory = new SoftwareRelease();
     if (isset($_GET['id']) && is_numeric($_GET['id'])) {
         $this->releases = $release_factory->find_all(array('where_clause' => '`released` = 1 ' . 'AND `software_id` = \'' . $conn->escape($_GET['id']) . '\' ', 'order_by' => '`date` DESC '));
     } else {
         $this->releases = $release_factory->find_by_query('SELECT MAX(`software_releases`.`id`) AS `id`, `software_releases`.`software_id`, MAX(`software_releases`.`version`) AS `version`, MAX(`software_releases`.`date`) AS `date` ' . 'FROM `softwares` ' . 'LEFT JOIN `software_releases` ON `softwares`.`id` = `software_releases`.`software_id` ' . 'WHERE `software_releases`.`released` = 1 ' . 'GROUP BY `softwares`.`id` ' . 'ORDER BY `date` DESC ');
     }
     Db::close_connection($conn);
 }
Ejemplo n.º 11
0
 static function is_logged_in()
 {
     if (!isset(Login::$logged_in)) {
         Login::$logged_in = FALSE;
         if (!empty($_COOKIE['username'])) {
             $conn = Db::get_connection();
             $user_factory = new User();
             $users = $user_factory->find_all(array('where_clause' => "`utente` = '{$conn->escape($_COOKIE['username'])}'", 'limit' => 1));
             if (count($users) > 0) {
                 $user = $users[0];
                 Login::$logged_in = md5($user->utente . self::magic_phrase) == @$_COOKIE['userID'];
             }
             Db::close_connection($conn);
         }
     }
     return Login::$logged_in;
 }
Ejemplo n.º 12
0
 public static function timeline($isin, $quantita, $month_from, $month_to)
 {
     $payments = array();
     $conn = Db::get_connection();
     $stock = new Stock();
     if (!$stock->find_by_id($isin)) {
         return;
     }
     $yields = PaymentsHelper::yields($isin, $month_from, $month_to);
     $refunds = PaymentsHelper::refunds($isin, $month_from, $month_to);
     $events = array_merge($yields, $refunds);
     $payments = array();
     foreach ($events as $event) {
         if (is_array($quantita)) {
             // reset() rewinds array's internal pointer to the first element and returns the value of the first array element, or FALSE if the array is empty.
             $q = reset($quantita);
             foreach ($quantita as $date => $value) {
                 if (strtotime($date) < $event->timestamp) {
                     break;
                 }
                 $q = $value;
             }
         } else {
             $q = $quantita;
         }
         if ($event->tipo == 'rimborso') {
             switch ($event->stock->tipo) {
                 case 'obbligazione':
                     $event->importo *= $q / 100;
                     break;
                 default:
                     $event->importo *= $q;
             }
         } else {
             $event->importo *= $q;
         }
         $event->quantita = $q;
         $payments[] = $event;
     }
     // print_r($payments);
     Db::close_connection($conn);
     return $payments;
 }
Ejemplo n.º 13
0
 /**
  *	@fn lookup_host_and_cache($ip_addr)
  *	@short Obtains the hostname for the given IP address.
  *	@param ip_addr The IP address.
  */
 private static function lookup_host_and_cache($ip_addr)
 {
     $conn = Db::get_connection();
     $hostname = $ip_addr;
     // Attempt to retrieve the hostname from the lookup table...
     $conn->prepare("SELECT `hostname` " . "FROM `hosts` " . "WHERE `ip_addr` = '{1}' " . "LIMIT 1", $ip_addr);
     $lookup_result = $conn->exec();
     if ($conn->num_rows() > 0) {
         // Got it
         $hostname = $conn->result(0);
     } else {
         // Resolve the host name with a call to gethostbyaddr
         $hostname = gethostbyaddr($ip_addr);
         // Store it in the lookup table for later
         $conn->prepare("INSERT INTO `hosts` (`ip_addr`,`hostname`,`last_update`) " . "VALUES ('{1}', '{2}', NOW())", $ip_addr, $hostname);
         $conn->exec();
     }
     Db::close_connection($conn);
     return $hostname;
 }
Ejemplo n.º 14
0
 static function chg2eur($divisa = 'USD', $date = NULL)
 {
     if ($date == NULL) {
         $date = date('Y-m-d H:i:s');
     }
     if (!isset(self::$cache[$date])) {
         $conn = Db::get_connection();
         $change_factory = new self();
         $changes = $change_factory->find_all(array('where_clause' => empty($date) ? '1' : "`data` <= '{$conn->escape($date)}'", 'order_by' => '`data` DESC', 'limit' => 1));
         $change = $changes[0];
         self::$cache[$date] = array('usd2eur' => $change->usd2eur, 'aud2eur' => $change->aud2eur, 'try2eur' => $change->try2eur, 'zar2eur' => $change->zar2eur, 'brl2eur' => $change->brl2eur, 'gbp2eur' => $change->gbp2eur, 'rub2eur' => $change->rub2eur);
         Db::close_connection($conn);
     }
     switch ($divisa) {
         case 'USD':
             return self::$cache[$date]['usd2eur'];
             break;
         case 'AUD':
             return self::$cache[$date]['aud2eur'];
             break;
         case 'TRY':
             return self::$cache[$date]['try2eur'];
             break;
         case 'ZAR':
             return self::$cache[$date]['zar2eur'];
             break;
         case 'BRL':
             return self::$cache[$date]['brl2eur'];
             break;
         case 'GBP':
             return self::$cache[$date]['gbp2eur'];
         case 'RUB':
             return self::$cache[$date]['rub2eur'];
     }
     return 1;
 }
Ejemplo n.º 15
0
 /**
  *	@fn _init_software
  *	@short Private method that initializes repetitive members of software product page actions.
  */
 private function _init_software()
 {
     $conn = Db::get_connection();
     if (isset($_REQUEST['software_name'])) {
         $software_factory = new Software();
         $softwares = $software_factory->find_all(array('where_clause' => '`name` = \'' . $conn->escape($_REQUEST['software_name']) . '\' AND `type` = \'' . $conn->escape($_REQUEST['software_type']) . '\'', 'limit' => 1));
         if (count($softwares) > 0) {
             $this->software = $softwares[0];
         } else {
             $softwares = $software_factory->find_by_query('SELECT `softwares`.`id` ' . 'FROM `softwares` ' . 'LEFT JOIN `software_typos` ON `softwares`.`id` = `software_typos`.`software_id` ' . 'WHERE `software_typos`.`typo` = \'' . $conn->escape($_REQUEST['software_name']) . '\' ' . 'LIMIT 1');
             if (count($softwares) > 0) {
                 $this->software = $softwares[0];
                 header(sprintf('Location: http://%s%s', $_SERVER['HTTP_HOST'], $this->software->url_to_detail($_REQUEST['subview'])));
                 exit;
             } else {
                 HTTP::error(404);
             }
         }
         $_REQUEST['id'] = $this->software->id;
     } else {
         if (isset($_GET['id'])) {
             $this->software = new Software();
             if ($this->software->find_by_id($_GET['id']) === FALSE) {
                 $this->flash(l('No such software product!'), 'error');
                 $this->redirect_to(array('action' => 'index'));
             }
         } else {
             HTTP::error(404);
         }
     }
     $this->software->has_many('software_releases', array('where_clause' => '`released` = \'1\''));
     $releases = $this->software->software_releases;
     usort($releases, array($releases[0], 'sort_releases'));
     $this->release = $releases[0];
     $this->software->software_releases = $releases;
     Db::close_connection($conn);
 }
Ejemplo n.º 16
0
 /**
  *	@fn _batch_moderate($table_name)
  *	@short Performs batch moderation operations on one or more items.
  *	@param table_name The name of the table we want to operate on.
  */
 private function _batch_moderate($table_name)
 {
     $conn = Db::get_connection();
     $has_deleted = FALSE;
     if ($this->request->is_post()) {
         $query_preamble = 'SELECT 1 ';
         if (isset($_POST['delete-selected'])) {
             $query_preamble = "DELETE FROM `{$table_name}` ";
             $has_deleted = TRUE;
         } else {
             if (isset($_POST['moderate-selected'])) {
                 $query_preamble = "UPDATE `{$table_name}` SET `approved` = 1 ";
             }
         }
         if (is_array($_POST['id'])) {
             $conn->prepare($query_preamble . "WHERE FIND_IN_SET(`id`, '{1}') " . 'LIMIT {2}', implode(',', $_POST['id']), count($_POST['id']));
             $conn->exec();
         } else {
             if (isset($_POST['id'])) {
                 $conn->prepare($query_preamble . "WHERE `id` = '{1}' " . 'LIMIT 1');
                 $conn->exec();
             }
         }
         if ($has_deleted) {
             $conn->prepare("OPTIMIZE TABLE `{$table_name}`");
             $conn->exec();
         }
     }
     Db::close_connection($conn);
 }
Ejemplo n.º 17
0
 /**
  *	@fn read
  *	@short Action method that shows an article for reading.
  */
 public function read()
 {
     if (empty($_REQUEST['id'])) {
         $this->redirect_to(array('action' => 'index'));
     }
     $conn = Db::get_connection();
     /*
     // THIS SUCKS!!!
     $this->article = DiarioPost::find($_REQUEST['id'], 'DiarioPost');
     */
     $this->article = new DiarioPost();
     if ($this->article->find_by_id($_REQUEST['id']) === FALSE) {
         $this->flash(l('No such article'), 'error');
         $this->redirect_to(array('action' => 'index'));
     }
     if ($this->article->status != 'pubblicato') {
         HTTP::error(404);
     }
     // Annotates that the article has been read
     $this->article->readings++;
     $this->article->save();
     $this->render(array('layout' => 'diario_read'));
     Db::close_connection($conn);
 }
Ejemplo n.º 18
0
function end_amy_request()
{
    Db::close_connection();
}
Ejemplo n.º 19
0
 public static function yields($isin, $month_from, $month_to)
 {
     $payments = array();
     $conn = Db::get_connection();
     $stock = new Stock();
     if (!$stock->find_by_id($isin)) {
         return;
     }
     switch ($stock->tipo) {
         case 'azione':
             $dividend_factory = new Dividend();
             $dividend = $dividend_factory->find_all(array('where_clause' => "`isin` = '{$isin}'"))[0];
             $payment = new Payment();
             $payment->stock = $stock;
             $payment->dividend = $dividend;
             $payment->timestamp = strtotime($dividend->stacco);
             $payment->importo = $dividend->importo;
             $payment->tipo = 'dividendo';
             $payments[] = $payment;
             break;
         case 'obbligazione':
             $bond = new Bond();
             if (!$bond->find_by_id($isin)) {
                 return;
             }
             if ($bond->zero_coupon == 1) {
                 return;
             }
             if (!is_numeric($bond->cadenza)) {
                 return;
             }
             if ($bond->tasso == 0) {
                 return;
             }
             if ($bond->emissione == '0000-00-00' && $bond->stacco == '0000-00-00') {
                 return;
             }
             if (!empty($bond->stacco)) {
                 $stacco = strtotime($bond->stacco);
                 // FIXME: bug, se emissione è vuoto, il prossimo stacco utile può avvenire in una data precedente
                 if ($bond->emissione == '0000-00-00') {
                     $stacco_precedente = $stacco;
                     do {
                         $stacco = $stacco_precedente;
                         $stacco_precedente = mktime(0, 0, 0, date("m", $stacco) - $bond->cadenza, date("d", $stacco), date("Y", $stacco));
                     } while ($stacco_precedente >= strtotime($month_from));
                 }
                 while ($stacco < strtotime($month_from)) {
                     // Sommo i mesi di cadenza fino a giungere ad una data futura
                     $stacco = mktime(0, 0, 0, date("m", $stacco) + $bond->cadenza, date("d", $stacco), date("Y", $stacco));
                 }
                 if ($stacco > strtotime($bond->scadenza) || $stacco > strtotime($month_to)) {
                     break;
                 }
                 do {
                     $payment = new Payment();
                     $payment->stock = $stock;
                     $payment->bond = $bond;
                     $payment->timestamp = $stacco;
                     $payment->importo = $bond->tasso / (100 * $bond->cedole_per_anno());
                     $payment->tipo = 'cedola';
                     $payments[] = $payment;
                     $stacco = mktime(0, 0, 0, date("m", $stacco) + $bond->cadenza, date("d", $stacco), date("Y", $stacco));
                 } while ($stacco <= strtotime($bond->scadenza) && $stacco <= strtotime($month_to));
             }
             break;
     }
     Db::close_connection($conn);
     return $payments;
 }
Ejemplo n.º 20
0
 /**
  *	@short Deletes an object's database counterpart.
  *	@details This method performs a <tt>DELETE</tt> SQL statement on the 
  *	table bound to the receiver's class, requesting the deletion of the object whose
  *	primary key is equal to the receiver's primary key value. If the object has been
  *	created programmatically and lacks a primary key value, this method has no effect.
  *	@param bool cleanup Set to <tt>FALSE</tt> if you do not want the table to be optimized after deletion.
  */
 public function delete($optimize = TRUE)
 {
     $conn = Db::get_connection();
     if (!empty($this->values[$this->primary_key])) {
         $conn->prepare("DELETE FROM `{1}` WHERE `{$this->primary_key}` = '{2}' LIMIT 1", $this->get_table_name(), $this->values[$this->primary_key]);
         $conn->exec();
         // Clean up
         if ($optimize) {
             $conn->prepare("OPTIMIZE TABLE `{1}`", $this->get_table_name());
             $conn->exec();
         }
     }
     Db::close_connection($conn);
 }
Ejemplo n.º 21
0
function shutdown()
{
    if (class_exists('Db')) {
        Db::close_connection();
    }
}
Ejemplo n.º 22
0
 protected function ensure_multiple_isin()
 {
     $isins_from_request = isset($_REQUEST['id']) ? $_REQUEST['id'] : $_REQUEST['isin'];
     if (isset($isins_from_request)) {
         $isins = explode(',', $isins_from_request);
     } else {
         $conn = Db::get_connection();
         $stock_factory = new Stock();
         // $stocks = $stock_factory->find_all(array(
         //	 'where_clause' => "`tipo` = 'obbligazione' " .
         //		 'AND `attivo` = 1',
         //	 'order_by' => '`title` ASC',
         //	 'limit' => 57,
         //	 'start' => 0
         // ));
         if (!isset($_REQUEST['start'])) {
             $_REQUEST['start'] = 0;
         }
         $stocks = $stock_factory->find_by_query('SELECT `creso_titoli`.`isin` FROM `creso_titoli` ' . 'JOIN `creso_obbligazioni` ON `creso_titoli`.`isin` = `creso_obbligazioni`.`isin` ' . "WHERE `creso_titoli`.`tipo` = 'obbligazione' " . 'AND `creso_titoli`.`attivo` = 1 ' . 'AND `creso_obbligazioni`.`zero_coupon` = 0 ' . 'ORDER BY ' . '`creso_obbligazioni`.`tasso` DESC ' . ',' . '`creso_obbligazioni`.`scadenza` DESC ' . "LIMIT {$conn->escape($_REQUEST['start'])}, 170");
         $isins = array_map(function ($stock) {
             return $stock->isin;
         }, $stocks);
         Db::close_connection($conn);
         // $this->redirect_to(array('action' => 'compare', 'id' => implode(',', $isins)));
     }
     $this->isins = $isins;
 }
Ejemplo n.º 23
0
        define("VIEWPORT", 100);
        define("LABEL", "Intraday");
        define("STEP", 6);
        $sdata = mktime(0, 0, 0, $month, $day, $year);
        $edata = mktime(0, 0, 0, $month, $day, $year);
        $qdata = "`data` >= '" . date("Y-m-d", $sdata) . "' AND `data` <= '" . date("Y-m-d", $edata) . "'";
}
function f($val, $m, $n, $min)
{
    return floor(($val - $min) * $m) + $n;
}
$conn = Db::get_connection();
$conn->prepare("SELECT `quotazione`, `data`, `ora` FROM `creso_quotazioni` WHERE `quotazione` > 0 AND `isin` = '{1}' AND " . $qdata . " ORDER BY `data` ASC, `ora` ASC LIMIT {2}", @$_REQUEST['isin'], VIEWPORT);
$result = $conn->exec();
$len = min(VIEWPORT, $conn->num_rows());
Db::close_connection($conn);
// create image
$image = @imagecreatetruecolor(WIDTH, HEIGHT);
@imageantialias($image, true);
// some colors
$bg = @imagecolorallocate($image, 255, 255, 255);
$lblue = @imagecolorallocate($image, 202, 219, 243);
$llblue = @imagecolorallocate($image, 245, 248, 254);
$blue = @imagecolorallocate($image, 132, 179, 243);
$black = @imagecolorallocate($image, 0, 0, 0);
$dblue = @imagecolorallocate($image, 18, 86, 178);
$magenta = @imagecolorallocate($image, 255, 0, 128);
@imagefill($image, 0, 0, $bg);
$valore = array();
$data = array();
$ora = array();
Ejemplo n.º 24
0
 /**
  *	@fn next
  *	@short Returns the item that succeeds the receiver in the order.
  */
 public function next()
 {
     $conn = Db::get_connection();
     $factory = new self();
     $results = $factory->find_all(array('where_clause' => "`created_at` > '{$conn->escape($this->created_at)}' " . "AND `status` = 'pubblicato'", 'order_by' => '`created_at` ASC', 'limit' => 1));
     $ret = count($results) > 0 ? $results[0] : NULL;
     Db::close_connection($conn);
     return $ret;
 }
Ejemplo n.º 25
0
 /**
  *	@fn total_downloads
  *	@short Returns the total number of downloads for all software artifacts.
  */
 public static function total_downloads()
 {
     $conn = Db::get_connection();
     $conn->prepare('SELECT SUM(`downloads`) FROM `software_artifacts` WHERE 1');
     $conn->exec();
     $ret = $conn->result(0);
     Db::close_connection($conn);
     return $ret;
 }
Ejemplo n.º 26
0
 /**
  *	@fn update_versiontracker_ratings
  *	@short Action method that updates the VersionTracker ratings for software products.
  */
 public function update_versiontracker_ratings()
 {
     $conn = Db::get_connection();
     error_reporting(E_ALL | E_STRICT);
     $sw = new Software();
     $softwares = $sw->find_all();
     foreach ($softwares as $software) {
         $software->has_one('version_tracker_entries');
         if ($software->version_tracker_entry && $software->version_tracker_entry->vt_id != 0) {
             $vt = new VTRatingsParser($software->version_tracker_entry->vt_id);
             $vt->parse();
             $software->version_tracker_entry->rating = $vt->rating;
             $software->version_tracker_entry->save();
         }
     }
     $this->render(NULL);
     Db::close_connection($conn);
 }
Ejemplo n.º 27
0
 /**
  *	@fn attribute_visits
  *	@short Action method to attribute a visit to a person.
  *	@details This method is designed to be called with AJAX, and does not render anything.
  *	It assigns a visit object to a person object.
  */
 public function attribute_visits()
 {
     $conn = Db::get_connection();
     $visit_factory = new Visit();
     $visits = $visit_factory->find_all(array('where_clause' => "`date` >= '{$conn->escape(date("Y-m-d H:i:s", Time::ago(@$_REQUEST['t'])))}' " . "AND (`ip_addr` = '{$conn->escape(@$_REQUEST['ip'])}' " . "OR `params` LIKE '%Apache'' => ''{$conn->escape(@$_REQUEST['ip'])}%')"));
     if (count($visits) > 0) {
         foreach ($visits as $visit) {
             $visit->person_id = @$_REQUEST['person_id'];
             $visit->save();
         }
     }
     Db::close_connection($conn);
     $this->render(NULL);
 }
Ejemplo n.º 28
0
 /**
  *	@fn last_n_visits
  *	@short Action method that shows the last <em>N</em> hosts that have visited the website.
  */
 public function last_n_visits($n)
 {
     $conn = Db::get_connection();
     $conn->prepare("SELECT `ip_addr`, `params`, COUNT(*) AS `weight` " . "FROM `visits` " . "GROUP BY CONCAT(`ip_addr`, `user_agent`) " . "ORDER BY `date` DESC " . "LIMIT {1}", $n * 3);
     $conn->exec();
     $this->hosts = array();
     if ($conn->num_rows() > 0) {
         $i = 0;
         while ($line = $conn->fetch_assoc()) {
             $host = Geoip::by_ip_addr($line['ip_addr'], $line['params']);
             $host->weight = $line['weight'];
             if (!(empty($host->latitude) && empty($host->longitude))) {
                 $this->hosts[] = $host;
                 $i++;
             }
             if ($i >= $n) {
                 break;
             }
         }
     }
     Db::close_connection($conn);
     $this->render(array('action' => 'hits_by_host'));
 }