Esempio n. 1
0
 public function read($fromid, $toid, $time, $pmid)
 {
     $ret = [];
     if (!is_numeric($fromid) || !is_numeric($toid) || !is_numeric($pmid) || !in_array($_SESSION['id'], array($fromid, $toid)) || !($res = Db::query(array('SELECT "message","to_read" FROM "pms" WHERE "from" = :from AND "to" = :to AND "pmid" = :pmid', array(':from' => $fromid, ':to' => $toid, ':pmid' => $pmid)), Db::FETCH_STMT))) {
         return false;
     }
     if ($o = $res->fetch(PDO::FETCH_OBJ)) {
         $from = User::getUsername($fromid);
         $ret['from4link_n'] = \NERDZ\Core\Utils::userLink($from);
         $ret['from_n'] = $from;
         $ret['datetime_n'] = $this->user->getDateTime($time);
         $ret['fromid_n'] = $fromid;
         $ret['toid_n'] = $toid;
         $ret['message_n'] = parent::bbcode($o->message);
         $ret['read_b'] = $o->to_read;
         $ret['pmid_n'] = $pmid;
         $ret['timestamp_n'] = $time;
     }
     return $ret;
 }
Esempio n. 2
0
 private static function getURLFromCid($hcid, $project = false)
 {
     $prefix = $project ? 'groups_' : '';
     if (!($o = Db::query(['SELECT p.to, p.pid FROM "' . $prefix . 'posts" p INNER JOIN "' . $prefix . 'comments" c ON c."hcid" = :hcid AND c.hpid = p.hpid', [':hcid' => $hcid]], Db::FETCH_OBJ))) {
         return System::getCurrentHostAddress();
     }
     return System::getCurrentHostAddress() . ($project ? Utils::projectLink(Project::getName($o->to)) : Utils::userLink(User::getUsername($o->to))) . $o->pid . '#c' . $hcid;
 }
Esempio n. 3
0
<?php

$vals = [];
$vals['logged_b'] = $user->isLogged();
if ($vals['logged_b']) {
    $vals['myusername_n'] = NERDZ\Core\User::getUsername();
    $vals['myusername4link_n'] = \NERDZ\Core\Utils::userLink($vals['myusername_n']);
}
$vals['tok_n'] = NERDZ\Core\Security::getCsrfToken();
$user->getTPL()->assign($vals);
$user->getTPL()->draw('base/header');
Esempio n. 4
0
<?php

//Variables avaiable in every page present in the root of nerdz (/home.php, /profile.php and so on)
if (!isset($user)) {
    die('$user required');
}
// use function to create variable scope and avoid conflicts
$func = function () use($user) {
    $commonvars = [];
    $commonvars['tok_n'] = NERDZ\Core\Security::getCsrfToken();
    $commonvars['myusername_n'] = NERDZ\Core\User::getUsername();
    $commonvars['myusername4link_n'] = \NERDZ\Core\Utils::userLink($commonvars['myusername_n']);
    $langKey = 'lang' . NERDZ\Core\Config\SITE_HOST;
    if (!($commonvars['langs_a'] = NERDZ\Core\Utils::apc_get($langKey))) {
        $commonvars['langs_a'] = NERDZ\Core\Utils::apc_set($langKey, function () {
            $ret = [];
            $i = 0;
            $longlangs = NERDZ\Core\System::getAvailableLanguages(1);
            foreach ($longlangs as $id => $val) {
                $ret[$i]['longlang_n'] = $val;
                $ret[$i]['shortlang_n'] = $id;
                ++$i;
            }
            return $ret;
        }, 3600);
    }
    $commonvars['mylang_n'] = $user->getLanguage();
    $commonvars['flagdir_n'] = NERDZ\Core\System::getResourceDomain() . '/static/images/flags/';
    $banners = (new NERDZ\Core\Banners())->getBanners();
    $commonvars['banners_a'] = [];
    shuffle($banners);
Esempio n. 5
0
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/class/autoload.php';
use NERDZ\Core\Db;
use NERDZ\Core\Utils;
if (!($o = Db::query('SELECT "username" FROM "users" ORDER BY "counter" DESC', Db::FETCH_OBJ))) {
    die('Db error');
}
die(header('Location: /' . Utils::userLink($o->username)));
Esempio n. 6
0
 public function getPost($dbPost, $options = [])
 {
     extract($options);
     $project = !empty($project);
     $truncate = !empty($truncate);
     if (is_object($dbPost)) {
         $dbPost = (array) $dbPost;
     } else {
         if (is_numeric($dbPost)) {
             $table = ($project ? 'groups_' : '') . 'posts';
             if (!($o = Db::query(['SELECT p.*, EXTRACT(EPOCH FROM p."time") AS time FROM "' . $table . '" p WHERE p."hpid" = :hpid', [':hpid' => $dbPost]], Db::FETCH_OBJ))) {
                 return new \StdClass();
             }
             $dbPost = (array) $o;
         }
     }
     $logged = $this->user->isLogged();
     if (!($from = User::getUsername($dbPost['from']))) {
         $from = '';
     }
     $toFunc = $project ? [__NAMESPACE__ . '\\Project', 'getName'] : [__NAMESPACE__ . '\\User', 'getUsername'];
     $toFuncLink = [__NAMESPACE__ . '\\Utils', ($project ? 'project' : 'user') . 'Link'];
     if (!($to = $toFunc($dbPost['to']))) {
         $to = '';
     }
     $ret = [];
     $ret['thumbs_n'] = $this->getThumbs($dbPost['hpid'], $project);
     $ret['revisions_n'] = $this->getRevisionsNumber($dbPost['hpid'], $project);
     $ret['uthumb_n'] = $this->getUserThumb($dbPost['hpid'], $project);
     $ret['pid_n'] = $dbPost['pid'];
     $ret['news_b'] = $dbPost['news'];
     $ret['language_n'] = $dbPost['lang'];
     $ret['from4link_n'] = Utils::userLink($from);
     $ret['to4link_n'] = $toFuncLink($to);
     $ret['fromid_n'] = $dbPost['from'];
     $ret['toid_n'] = $dbPost['to'];
     $ret['from_n'] = $from;
     $ret['to_n'] = $to;
     $ret['datetime_n'] = $this->user->getDateTime($dbPost['time']);
     $ret['timestamp_n'] = $dbPost['time'];
     $ret['canclosepost_b'] = $this->canClose($dbPost, $project);
     $ret['closed_b'] = $dbPost['closed'];
     $ret['canremovepost_b'] = $this->canRemove($dbPost, $project);
     $ret['caneditpost_b'] = $this->canEdit($dbPost, $project);
     $ret['canshowlock_b'] = $this->canShowLock($dbPost, $project);
     $ret['lock_b'] = $this->user->hasLocked($dbPost, $project);
     $ret['canshowlurk_b'] = $logged ? !$ret['canshowlock_b'] : false;
     $ret['lurk_b'] = $this->user->hasLurked($dbPost, $project);
     $ret['canshowbookmark_b'] = $logged;
     $ret['bookmark_b'] = $this->user->hasBookmarked($dbPost, $project);
     $ret['message_n'] = $this->bbcode($dbPost['message'], $truncate, $project ? 'g' : 'u', $ret['pid_n'], $ret['toid_n']);
     if (!$project && $dbPost['to'] == Config\USERS_NEWS) {
         $ret['message_n'] = $this->parseNews($ret['message_n']);
     }
     $ret['postcomments_n'] = $this->countComments($dbPost['hpid'], $project);
     $ret['hpid_n'] = $dbPost['hpid'];
     return $ret;
 }
Esempio n. 7
0
 public function getInteractions($id, $limit = 0)
 {
     if (!$this->isLogged()) {
         return [];
     }
     if ($limit) {
         $limit = Security::limitControl($limit, 20);
     }
     $objs = [];
     if (!($objs = Db::query(['SELECT "type", "from", "to", extract(epoch from time) as time, pid, post_to
             FROM user_interactions(:me, :id) AS
             f("type" text, "from" int8, "to" int8, "time" timestamp with time zone, pid int8, post_to int8)
             ORDER BY f.time DESC' . ($limit !== 0 ? " LIMIT {$limit}" : ''), [':me' => $_SESSION['id'], ':id' => $id]], Db::FETCH_OBJ, true))) {
         return [];
     }
     $ret = [];
     for ($i = 0, $count = count($objs); $i < $count; ++$i) {
         $ret[$i]['type_n'] = $objs[$i]->type;
         $ret[$i]['fromid_n'] = $objs[$i]->from;
         $ret[$i]['from_n'] = static::getUsername($objs[$i]->from);
         $ret[$i]['from4link_n'] = Utils::userLink($ret[$i]['from_n']);
         $ret[$i]['toid_n'] = $objs[$i]->to;
         $ret[$i]['to_n'] = static::getUsername($objs[$i]->to);
         $ret[$i]['to4link_n'] = Utils::userLink($ret[$i]['to_n']);
         $ret[$i]['datetime_n'] = $this->getDateTime($objs[$i]->time);
         $ret[$i]['pid_n'] = $objs[$i]->pid;
         $ret[$i]['postto_n'] = static::getUsername($objs[$i]->post_to);
         $ret[$i]['link_n'] = Utils::userLink($ret[$i]['postto_n']) . $objs[$i]->pid;
     }
     return $ret;
 }
Esempio n. 8
0
     $_list = null;
     if (isset($_POST['start']) && isset($_POST['num']) && is_numeric($_POST['start']) && is_numeric($_POST['num'])) {
         $_list = $comments->getLastComments($hpid, $_POST['num'], $_POST['start'], $prj);
     } else {
         if (isset($_POST['hcid']) && is_numeric($_POST['hcid'])) {
             $_list = $comments->getCommentsAfterHcid($hpid, $_POST['hcid'], $prj);
         } else {
             $_list = $comments->getAll($hpid, $prj);
         }
     }
     $doShowForm = !isset($_POST['hcid']) && (!isset($_POST['start']) || $_POST['start'] == 0) && !isset($_POST['forceNoForm']);
     if (empty($_list) && !$doShowForm) {
         die;
     }
     $vals = [];
     $vals['currentuserprofile_n'] = \NERDZ\Core\Utils::userLink($_SESSION['id']);
     $vals['currentusergravatar_n'] = $user->getGravatar($_SESSION['id']);
     $vals['currentusername_n'] = User::getUsername();
     $vals['onerrorimgurl_n'] = System::getResourceDomain() . '/static/images/red_x.png';
     $vals['list_a'] = $_list;
     $vals['showform_b'] = $doShowForm;
     $vals['hpid_n'] = $hpid;
     $vals['commentcount_n'] = (new Messages())->countComments($hpid, $prj);
     $vals['needmorebtn_b'] = $doShowForm && $vals['commentcount_n'] > 10;
     $vals['needeverycommentbtn_b'] = $doShowForm && $vals['commentcount_n'] > 20;
     $user->getTPL()->assign($vals);
     $user->getTPL()->draw(($prj ? 'project' : 'profile') . '/comments');
     break;
 default:
     die($user->lang('ERROR'));
     break;
Esempio n. 9
0
 $ida = [':id' => $info->counter];
 if (!($o = Db::query(['SELECT EXTRACT(EPOCH FROM "registration_time") AS registration_time from "users" WHERE "counter" = :id', $ida], Db::FETCH_OBJ))) {
     die($user->lang('ERROR'));
 }
 $userTpl = $user->getTemplate($info->counter);
 $templates = System::getAvailableTemplates();
 $vals['template_n'] = '';
 foreach ($templates as $pair) {
     if ($pair['number'] == $userTpl) {
         $vals['template_n'] = $pair['name'];
         break;
     }
 }
 $vals['registrationtime_n'] = $user->getDateTime($o->registration_time);
 $vals['username_n'] = $info->username;
 $vals['username4link_n'] = Utils::userLink($info->username);
 $vals['lang_n'] = $user->getLanguage($info->counter);
 $vals['online_b'] = $user->isOnline($info->counter);
 $vals['name_n'] = ucfirst($info->name);
 $vals['surname_n'] = ucfirst($info->surname);
 list($year, $month, $day) = explode('-', $info->birth_date);
 $vals['birthdate_n'] = $day . '/' . $month . '/' . $year;
 $apc_name = 'userstuff' . $info->counter . Config\SITE_HOST;
 if (!($stuff = Utils::apc_get($apc_name))) {
     $stuff = Utils::apc_set($apc_name, function () use($user, $ida) {
         if (!($o = Db::query(['SELECT COUNT("hcid") AS cc FROM "comments" WHERE "from" = :id', $ida], Db::FETCH_OBJ))) {
             die($user->lang('ERROR'));
         }
         $n = $o->cc;
         if (!($o = Db::query(['SELECT COUNT("hcid") AS cc FROM "groups_comments" WHERE "from" = :id', $ida], Db::FETCH_OBJ))) {
             die($user->lang('ERROR'));
Esempio n. 10
0
 usort($vals['members_a'], 'NERDZ\\Core\\Utils::sortByUsername');
 $fol = $project->getFollowers($info->counter);
 $vals['users_n'] = count($fol);
 $vals['users_a'] = [];
 $i = 0;
 foreach ($fol as $uid) {
     if (!($uname = User::getUsername($uid))) {
         continue;
     }
     $vals['users_a'][$i]['username_n'] = $uname;
     $vals['users_a'][$i]['username4link_n'] = \NERDZ\Core\Utils::userLink($uname);
     ++$i;
 }
 usort($vals['users_a'], 'NERDZ\\Core\\Utils::sortByUsername');
 $vals['owner_n'] = User::getUsername($project->getOwner());
 $vals['owner4link_n'] = \NERDZ\Core\Utils::userLink($vals['owner_n']);
 $vals['description_n'] = $messages->bbcode($info->description);
 $vals['goal_n'] = $messages->bbcode($info->goal);
 $vals['website_n'] = $vals['website4link_n'] = empty($info->website) ? 'http://' . Config\SITE_HOST . '/' : $info->website;
 $vals['openproject_b'] = $project->isOpen($info->counter);
 $vals['canifollow_b'] = $vals['logged_b'] && !in_array($_SESSION['id'], array_merge($mem, $fol));
 $vals['canshowmenu_b'] = $vals['logged_b'] && $_SESSION['id'] != $project->getOwner();
 if (!$vals['singlepost_b'] && !$vals['followers_b'] && !$vals['interactions_b'] && !$vals['members_b']) {
     $vals['canwrite_b'] = $vals['logged_b'] && ($project->isOpen($gid) || in_array($_SESSION['id'], $mem) || $_SESSION['id'] == $project->getOwner());
     $vals['canwriteissue_b'] = $vals['logged_b'] && $info->counter == Config\ISSUE_BOARD;
     $vals['canwritenews_b'] = !$vals['canwriteissue_b'] && $vals['logged_b'] && (in_array($_SESSION['id'], $mem) || $_SESSION['id'] == $project->getOwner());
 } else {
     // don't show textarea when in a singlepost
     $vals['canwritenews_b'] = $vals['canwrite_b'] = $vals['canwriteissue_b'] = false;
 }
 // single post handling
Esempio n. 11
0
use NERDZ\Core\Trend;
use NERDZ\Core\Utils;
use NERDZ\Core\Config;
use NERDZ\Core\User;
use NERDZ\Core\Project;
$vals = [];
$vals['querystring_n'] = $q;
$vals['type_n'] = !preg_match('/^#[a-z][a-z0-9]{0,33}$/i', $q) && isset($_GET['type']) ? $_GET['type'] == 'profile' ? 'profile' : 'project' : 'tag';
if ($vals['type_n'] == 'tag') {
    $vals['where_n'] = 'home';
    $vals['toid_n'] = $vals['to_n'] = $vals['to4link_n'] = '';
} else {
    $prj = $vals['type_n'] == 'project';
    $vals['where_n'] = isset($_GET['location']) ? $_GET['location'] == 'home' ? 'home' : ($_GET['location'] == 'profile' ? 'profile' : 'project') : 'home';
    $vals['toid_n'] = isset($_GET['id']) && is_numeric($_GET['id']) ? intval($_GET['id']) : false;
    if ($vals['toid_n']) {
        if ($prj) {
            $vals['to_n'] = Project::getName($vals['toid_n']);
            $vals['to4link_n'] = Utils::projectLink($vals['to_n']);
        } else {
            $vals['to_n'] = User::getUsername($vals['toid_n']);
            $vals['to4link_n'] = Utils::userLink($vals['to_n']);
        }
    } else {
        $vals['toid_n'] = $vals['to_n'] = $vals['to4link_n'] = '';
    }
}
require_once $_SERVER['DOCUMENT_ROOT'] . '/pages/common/trends.html.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/pages/common/vars.php';
$user->getTPL()->assign($vals);
$user->getTPL()->draw('search/layout');
Esempio n. 12
0
            ORDER BY cc DESC LIMIT 100', Db::FETCH_STMT);
        $rank = [];
        while ($o = $res->fetch(PDO::FETCH_OBJ)) {
            $gc = Db::query(['SELECT COUNT("hcid") AS cc FROM "groups_comments" WHERE "from" = :from ' . (!$mo ? $un_ti : ''), [':from' => $o->from]], Db::FETCH_OBJ);
            $us = User::getUsername($o->from);
            $n = $o->cc + $gc->cc;
            $rank[$us] = $n;
            $stupid = Stuff::stupid($n);
            $ss[$us] = $stupid['now'];
        }
        asort($rank);
        $rank = array_reverse($rank, true);
        $i = 0;
        $ret = [];
        foreach ($rank as $username => $val) {
            $ret[$i]['position_n'] = $i + 1;
            $ret[$i]['username4link_n'] = Utils::userLink($username);
            $ret[$i]['username_n'] = $username;
            $ret[$i]['comments_n'] = $val;
            $ret[$i]['stupidstuff_n'] = $ss[$username];
            ++$i;
        }
        return $ret;
    }, 3600);
}
$vals['list_a'] = $ret;
$vals['monthly_b'] = !$mo;
$vals['lastupdate_n'] = $user->getDateTime(Utils::apc_getLastModified($path));
require_once $_SERVER['DOCUMENT_ROOT'] . '/pages/common/vars.php';
$user->getTPL()->assign($vals);
$user->getTPL()->draw('base/rank');
Esempio n. 13
0
 private function get($params, $type)
 {
     extract($params);
     $post = !empty($post) ? $post : false;
     $row = !empty($row) ? $row : false;
     $ret = [];
     if (!$row) {
         return $ret;
     }
     $ret['fromid_n'] = $row->from;
     $ret['from_n'] = User::getUsername($row->from);
     $ret['from4link_n'] = Utils::userLink($ret['from_n']);
     $ret['type_n'] = $type;
     if ($post) {
         $ret['hpid_n'] = $row->hpid;
         $ret['pid_n'] = $post->pid;
         if ($this->isProject($type)) {
             $ret['to_n'] = Project::getName($post->to);
             $ret['to4link_n'] = Utils::projectLink($ret['to_n']) . $ret['pid_n'];
         } else {
             $ret['to_n'] = User::getUsername($post->to);
             $ret['to4link_n'] = Utils::userLink($ret['to_n']) . $ret['pid_n'];
         }
     } else {
         // followers - members
         $ret['toid_n'] = $row->to;
         if ($this->isProject($type)) {
             $ret['to_n'] = Project::getName($row->to);
             $ret['to4link_n'] = Utils::projectLink($ret['to_n']);
         } else {
             $ret['to_n'] = User::getUsername($row->to);
             $ret['to4link_n'] = Utils::userLink($ret['to_n']);
         }
     }
     $ret['datetime_n'] = $this->user->getDateTime($row->time);
     $ret['timestamp_n'] = $row->time;
     return $ret;
 }
Esempio n. 14
0
 // 1st step
 if (!$captcha) {
     die(NERDZ\Core\Utils::jsonResponse('error', $user->lang('MISSING') . ': ' . $user->lang('CAPTCHA')));
 }
 if (!$cptcka->check($captcha)) {
     die(NERDZ\Core\Utils::jsonResponse('error', $user->lang('WRONG_CAPTCHA')));
 }
 if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
     die(NERDZ\Core\Utils::jsonResponse('error', $user->lang('MAIL_NOT_VALID')));
 }
 if (!($obj = Db::query(['SELECT "username","counter" FROM "users" WHERE "email" = :email', [':email' => $email]], Db::FETCH_OBJ))) {
     die(NERDZ\Core\Utils::jsonResponse('error', $user->lang('USER_NOT_FOUND')));
 }
 $vals = [];
 $vals['username_n'] = $obj->username;
 $vals['usernamelink_n'] = 'http://' . Config\SITE_HOST . '/' . \NERDZ\Core\Utils::userLink($obj->username);
 $vals['account_n'] = "{$obj->username} - ID: {$obj->counter}";
 $vals['ip_n'] = $_SERVER['REMOTE_ADDR'];
 $token = md5(openssl_random_pseudo_bytes(rand(7, 21)));
 if (Db::NO_ERRNO != Db::query(['INSERT INTO reset_requests(remote_addr,token,"to") VALUES(:remote_addr,:token,:to)', [':remote_addr' => $_SERVER['REMOTE_ADDR'], ':token' => $token, ':to' => $obj->counter]], Db::FETCH_ERRNO)) {
     die(NERDZ\Core\Utils::jsonResponse('error', $user->lang('ERROR') . '(1): ' . $user->lang('TRY_LATER')));
 }
 if (!($key = Db::query(['SELECT counter FROM reset_requests WHERE token = :token AND "to" = :to AND remote_addr = :remote_addr', [':remote_addr' => $_SERVER['REMOTE_ADDR'], ':token' => $token, ':to' => $obj->counter]], Db::FETCH_OBJ))) {
     die(NERDZ\Core\Utils::jsonResponse('error', $user->lang('ERROR') . '(4): ' . $user->lang('TRY_LATER')));
 }
 $vals['reseturl_n'] = 'http://' . Config\SITE_HOST . '/reset.php?tok=' . $token . '&amp;id=' . $key->counter;
 require_once $_SERVER['DOCUMENT_ROOT'] . '/class/vendor/autoload.php';
 try {
     $mail = new PHPMailer();
     $mail->IsSMTP();
     $mail->SMTPAuth = true;