public function notifyNewArgument(Question $q, Argument $a)
 {
     global $sDB, $sTimer, $sTemplate;
     $sTimer->start("notifyNewArgument");
     $res = $sDB->exec("SELECT `notifications`.`userId`, `notifications`.`flags`, `users`.`email`, `users`.`userName` FROM `notifications`\n                           LEFT JOIN `users` ON `users`.`userId` = `notifications`.`userId`\n                           WHERE `questionId` = '" . i($q->questionId()) . "';");
     while ($row = mysql_fetch_object($res)) {
         // no notifications for our own arguments.
         /*if($a->userId() == $row->userId)
           {
               continue;
           }*/
         $uId = new BaseConvert($row->userId);
         $qId = new BaseConvert($q->questionId());
         $profileUrl = $sTemplate->getShortUrlBase() . "u" . $uId->val();
         $unfollowUrl = $sTemplate->getShortUrlBase() . "f" . $qId->val();
         $url = $a->shortUrl();
         if (!SHORTURL_BASE) {
             $profileUrl = $sTemplate->getRoot() . "user/" . $row->userId . "/";
             $unfollowUrl = $sTemplate->getRoot() . "unfollow.php?qId=" . $q->questionId();
             $url = $a->fullurl();
         }
         $subject = $sTemplate->getString("NOTIFICATION_NEW_ARGUMENT_SUBJECT");
         $message = $sTemplate->getString("NOTIFICATION_NEW_ARGUMENT_BODY", array("[USERNAME]", "[AUTHOR]", "[URL]", "[QUESTION]", "[ARGUMENT]", "[UNFOLLOW_URL]", "[PROFILE_URL]"), array($row->userName, $a->author(), $url, $q->title(), $a->headline(), $unfollowUrl, $profileUrl));
         $this->sendMail($row->email, "", $subject, $message);
     }
     $sTimer->stop("notifyNewArgument");
 }
    private function previousIntroductions()
    {
        $output = '';
        $introductionsQ = $this->db->prepare('SELECT i.id, i.introducer_id, introducer.name as introducer_name, i.introducee1_id, in1.name as introducee1_name, i.introducee2_id, in2.name as introducee2_name, i.time, i.link_password
			FROM introduction i
			LEFT JOIN person introducer ON introducer.id = i.introducer_id
			LEFT JOIN person in1 ON in1.id = i.introducee1_id
			LEFT JOIN person in2 ON in2.id = i.introducee2_id
			WHERE (i.introducer_id = :id OR i.introducee1_id = :id OR i.introducee2_id = :id)
			ORDER BY time DESC');
        $introductionsQ->execute(array(':id' => $this->userId));
        $introductions = $introductionsQ->fetchAll(PDO::FETCH_ASSOC);
        if (!empty($introductions)) {
            $you = (string) Content::c()->home->you;
            $youCapital = (string) Content::c()->home->you_capital;
            $story = (string) Content::c()->home->story;
            $output .= '<div id="previousIntroductions"><h2>' . Content::c()->home->history . '</h2>';
            foreach ($introductions as $introd) {
                $url = APP_URL . '/' . Content::l() . '/A' . $introd['link_password'] . BaseConvert::base10ToBase62($introd['id']);
                if ($this->userId == $introd['introducer_id']) {
                    $output .= '<p><a href="' . $url . '">' . str_replace('INTRODUCEE1_NAME', '<strong>' . $introd['introducee1_name'] . '</strong>', str_replace('INTRODUCEE2_NAME', '<strong>' . $introd['introducee2_name'] . '</strong>', str_replace('INTRODUCER_NAME', $youCapital, $story))) . '</a></p>';
                } elseif ($this->userId == $introd['introducee1_id']) {
                    $output .= '<p><a href="' . $url . '">' . str_replace('INTRODUCEE1_NAME', $you, str_replace('INTRODUCEE2_NAME', '<strong>' . $introd['introducee2_name'] . '</strong>', str_replace('INTRODUCER_NAME', '<strong>' . $introd['introducer_name'] . '</strong>', $story))) . '</a></p>';
                } else {
                    $output .= '<p><a href="' . $url . '">' . str_replace('INTRODUCEE1_NAME', $you, str_replace('INTRODUCEE2_NAME', '<strong>' . $introd['introducee1_name'] . '</strong>', str_replace('INTRODUCER_NAME', '<strong>' . $introd['introducer_name'] . '</strong>', $story))) . '</a></p>';
                }
                $output .= $this->formatTime(strtotime($introd['time']));
            }
            $output .= '</div>';
        }
        return $output;
    }
 public function __construct($introductionId, $introducee, $other)
 {
     $this->introductionId = $introductionId;
     $this->introducee = $introducee;
     $this->other = $other;
     $this->userId = SessionManager::getInstance()->getUserId();
     $this->db = Database::getInstance();
     // Get the introducee details
     $userDetailsQ = $this->db->prepare('SELECT p.name, f.id as facebook_id, f.access_token as facebook_access_token, l.id as linkedin_id, l.access_token as linkedin_access_token, t.id as twitter_id, t.access_token as twitter_access_token FROM person p LEFT JOIN facebook f ON p.id = f.person_id LEFT JOIN linkedin l ON p.id = l.person_id LEFT JOIN twitter t ON p.id = t.person_id WHERE p.id = :id');
     $userDetailsQ->execute(array(':id' => $this->userId));
     $this->userDetails = $userDetailsQ->fetch(PDO::FETCH_ASSOC);
     $this->userName = $this->userDetails['name'];
     // Get the personalised link for the introducee
     $linkQ = $this->db->prepare('SELECT id, link_password FROM link WHERE introduction_id = :introduction_id AND person_id = :person_id');
     $linkQ->execute(array(':introduction_id' => $this->introductionId, ':person_id' => $this->introducee->getId()));
     $link = $linkQ->fetch(PDO::FETCH_ASSOC);
     $this->introductionUrl = APP_URL . '/B' . $link['link_password'] . BaseConvert::base10ToBase62($link['id']);
 }
 public function __construct()
 {
     session_start();
     // Connect to the database
     $this->db = Database::getInstance();
     // Get the website user
     $userId = SessionManager::getInstance()->getUserId();
     if (empty($userId)) {
         Debug::l('No user logged in');
         header('Location: ' . APP_URL . '/' . Content::l() . '/');
         exit;
     }
     // Get the introduction that hasn't been sent yet
     $this->introductionQ = $this->db->prepare('SELECT id, introducee1_id, introducee2_id, introducee1_notified, introducee2_notified, link_password FROM introduction WHERE introducer_id = :id AND (introducee1_notified IS NULL OR introducee2_notified IS NULL) ORDER BY time DESC LIMIT 1');
     $this->introductionQ->execute(array(':id' => $userId));
     $this->introduction = $this->introductionQ->fetch(PDO::FETCH_ASSOC);
     if (empty($this->introduction)) {
         Debug::l('No unsent introductions found');
         header('Location: ' . APP_URL . '/' . Content::l() . '/');
         exit;
     }
     $introducee1 = new Person(array());
     $introducee1->getDataFromId($this->introduction['introducee1_id']);
     $introducee2 = new Person(array());
     $introducee2->getDataFromId($this->introduction['introducee2_id']);
     // Notify introducee 1
     if (empty($this->introduction['introducee1_notified'])) {
         $notifyManager = new NotifyManager($this->introduction['id'], $introducee1, $introducee2);
         $updateQ = $this->db->prepare('UPDATE introduction SET introducee1_notified = :method WHERE id = :id');
         $this->notifyPerson($notifyManager, $introducee1, $updateQ);
     }
     // Notify introducee 2
     if (empty($this->introduction['introducee2_notified'])) {
         $notifyManager = new NotifyManager($this->introduction['id'], $introducee2, $introducee1);
         $updateQ = $this->db->prepare('UPDATE introduction SET introducee2_notified = :method WHERE id = :id');
         $this->notifyPerson($notifyManager, $introducee2, $updateQ);
     }
     $base62 = BaseConvert::base10ToBase62($this->introduction['id']);
     // Redirect to introduction page
     header('Location: ' . APP_URL . '/' . Content::l() . '/A' . $this->introduction['link_password'] . $base62);
 }
 /**
  * 获取超长ID的字符串形式
  * @return string
  */
 public static function longIdStr()
 {
     $number = md5(time() . mt_rand(100000, 999999));
     $number = base_convert(substr($number, 8, 16), 16, 10);
     return BaseConvert::to62($number);
 }
 public function shortUrlCA()
 {
     global $sTemplate;
     $id = new BaseConvert($this->argumentId());
     return $sTemplate->getShortUrlBase() . "c" . $id->val();
 }
Exemple #7
0
 /**
  * 数字解码
  * @param $numStr
  * @return int|string
  */
 public static function NumberUndec($numStr)
 {
     $tagNo = '5';
     //没有补位
     $tagYes = '4';
     // 已经补位 ,补位后第二个字符为补位长度
     $tag = substr($numStr, 0, 1);
     if ($tag == $tagNo) {
         return BaseConvert::From62(substr($numStr, 1));
     }
     // 补位处理
     $len = intval(BaseConvert::From62(substr($numStr, 1, 1)));
     $num = BaseConvert::From62(substr($numStr, 2));
     return substr($num, $len);
 }
 public function shortUrlDetails()
 {
     global $sTemplate;
     $id = new BaseConvert($this->questionId());
     return $sTemplate->getShortUrlBase() . "d" . $id->val();
 }
 public function shortUrl()
 {
     global $sTemplate;
     $id = new BaseConvert($this->userId);
     return $sTemplate->getShortUrlBase() . "u" . $id->val();
 }
 public function __construct()
 {
     session_start();
     header('Content-type: text/json');
     // Get the website user
     $userId = SessionManager::getInstance()->getUserId();
     $json['result'] = 'true';
     // Make sure a user is logged in
     if (!isset($userId)) {
         $json['result'] = 'false';
         $json['title'] = (string) Content::c()->errors->session->title;
         $json['message'] = (string) Content::c()->errors->session->no_session;
         echo json_encode($json);
         exit;
     }
     // Validate input
     if (empty($_POST['introducee1Name']) || empty($_POST['introducee1FacebookId']) && empty($_POST['introducee1LinkedInId']) && empty($_POST['introducee1TwitterId']) || empty($_POST['introducee2Name']) || empty($_POST['introducee2FacebookId']) && empty($_POST['introducee2LinkedInId']) && empty($_POST['introducee2TwitterId'])) {
         $json['result'] = 'false';
         $json['title'] = (string) Content::c()->errors->input->title;
         $json['message'] = (string) Content::c()->errors->input->introduction_not_created;
         echo json_encode($json);
         exit;
     }
     // Make sure the introducees are unique
     if (!empty($_POST['introducee1FacebookId']) && !empty($_POST['introducee2FacebookId']) && $_POST['introducee1FacebookId'] == $_POST['introducee2FacebookId'] || !empty($_POST['introducee1LinkedInId']) && !empty($_POST['introducee2LinkedInId']) && $_POST['introducee1LinkedInId'] == $_POST['introducee2LinkedInId'] || !empty($_POST['introducee1TwitterId']) && !empty($_POST['introducee2TwitterId']) && $_POST['introducee1TwitterId'] == $_POST['introducee2TwitterId']) {
         $json['result'] = 'false';
         $json['title'] = (string) Content::c()->errors->input->title;
         $json['message'] = (string) Content::c()->errors->input->introduce_to_self;
         echo json_encode($json);
         exit;
     }
     // Connect to the database
     $db = Database::getInstance();
     $introducee1 = new Person(array('name' => $_POST['introducee1Name'], 'facebookId' => !empty($_POST['introducee1FacebookId']) ? $_POST['introducee1FacebookId'] : '', 'linkedInId' => !empty($_POST['introducee1LinkedInId']) ? $_POST['introducee1LinkedInId'] : null, 'twitterId' => !empty($_POST['introducee1TwitterId']) ? $_POST['introducee1TwitterId'] : null));
     $introducee2 = new Person(array('name' => $_POST['introducee2Name'], 'facebookId' => !empty($_POST['introducee2FacebookId']) ? $_POST['introducee2FacebookId'] : '', 'linkedInId' => !empty($_POST['introducee2LinkedInId']) ? $_POST['introducee2LinkedInId'] : null, 'twitterId' => !empty($_POST['introducee2TwitterId']) ? $_POST['introducee2TwitterId'] : null));
     // See if the introducees are already in our database, that would be nice!
     if (!empty($_POST['introducee1FacebookId'])) {
         $introducee1->getDataFromFacebookId($_POST['introducee1FacebookId']);
     } elseif (!empty($_POST['introducee1LinkedInId'])) {
         $introducee1->getDataFromLinkedInId($_POST['introducee1LinkedInId']);
     } elseif (!empty($_POST['introducee1TwitterId'])) {
         $introducee1->getDataFromTwitterId($_POST['introducee1TwitterId']);
     }
     if (!empty($_POST['introducee2FacebookId'])) {
         $introducee2->getDataFromFacebookId($_POST['introducee2FacebookId']);
     } elseif (!empty($_POST['introducee2LinkedInId'])) {
         $introducee2->getDataFromLinkedInId($_POST['introducee2LinkedInId']);
     } elseif (!empty($_POST['introducee2TwitterId'])) {
         $introducee2->getDataFromTwitterId($_POST['introducee2TwitterId']);
     }
     // Make sure the introducees are still unique
     if ($introducee1->getFacebookId() != null && $introducee1->getFacebookId() == $introducee2->getFacebookId() || $introducee1->getLinkedInId() != null && $introducee1->getLinkedInId() == $introducee2->getLinkedInId() || $introducee1->getTwitterId() != null && $introducee1->getTwitterId() == $introducee2->getTwitterId()) {
         $json['result'] = 'false';
         $json['title'] = (string) Content::c()->errors->input->title;
         $json['message'] = (string) Content::c()->errors->input->introduce_to_self;
         echo json_encode($json);
         exit;
     }
     // If the introducees aren't in the database yet, add them
     $introducee1->addToDatabase();
     $introducee2->addToDatabase();
     // If the introducees are on LinkedIn, add their public profile URL and picture to the DB
     if ($introducee1->getLinkedInId() != null || $introducee2->getLinkedInId() != null) {
         // Connect to LinkedIn API
         $sth = $db->prepare('SELECT id, access_token FROM linkedin WHERE person_id = :person_id');
         $sth->execute(array(':person_id' => $userId));
         $userDetails = $sth->fetch(PDO::FETCH_ASSOC);
         if (!empty($userDetails['access_token'])) {
             $linkedInAccessToken = $userDetails['access_token'];
             // Create LinkedIn object
             $API_CONFIG = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => '');
             $OBJ_linkedin = new LinkedIn($API_CONFIG);
             $OBJ_linkedin->setTokenAccess(unserialize($linkedInAccessToken));
             // Which introducees are on LinkedIn?
             $profilesToRequest = array();
             if ($introducee1->getLinkedInId() != null) {
                 $profilesToRequest[] = 'id=' . $introducee1->getLinkedInId();
             }
             if ($introducee2->getLinkedInId() != null) {
                 $profilesToRequest[] = 'id=' . $introducee2->getLinkedInId();
             }
             try {
                 $linkedInProfiles = $OBJ_linkedin->profileNew('::(' . implode(',', $profilesToRequest) . '):(id,public-profile-url,picture-url)');
             } catch (ErrorException $e) {
             }
             if ($linkedInProfiles['success'] === TRUE) {
                 $linkedInProfiles['linkedin'] = new SimpleXMLElement($linkedInProfiles['linkedin']);
                 if ($linkedInProfiles['linkedin']->getName() == 'people') {
                     foreach ($linkedInProfiles['linkedin']->person as $person) {
                         $id = (string) $person->id;
                         $url = (string) $person->{'public-profile-url'};
                         $pic = (string) $person->{'picture-url'};
                         if ($id && ($url || $pic)) {
                             $update = $db->prepare('REPLACE INTO temp_linkedin SET linkedin_id = :linkedin_id, time=NOW(), profile_url = :profile_url, picture_url = :picture_url');
                             $update->execute(array(':linkedin_id' => $id, ':profile_url' => $url, ':picture_url' => $pic));
                         }
                     }
                 }
             }
         }
     }
     // If the introducees are on Twitter, add their screen name and picture to the DB
     if ($introducee1->getTwitterId() != null || $introducee2->getTwitterId() != null) {
         // Which introducees are on Twitter?
         $profilesToRequest = array();
         if ($introducee1->getTwitterId() != null) {
             $profilesToRequest[] = $introducee1->getTwitterId();
         }
         if ($introducee2->getTwitterId() != null) {
             $profilesToRequest[] = $introducee2->getTwitterId();
         }
         // Connect to Twitter API
         $sth = $db->prepare('SELECT id, access_token FROM twitter WHERE person_id = :person_id');
         $sth->execute(array(':person_id' => $userId));
         $userDetails = $sth->fetch(PDO::FETCH_ASSOC);
         if (!empty($userDetails['access_token'])) {
             $twitterAccessToken = unserialize($userDetails['access_token']);
             try {
                 $twitter = new TwitterOAuth(TW_CONSUMER, TW_SECRET, $twitterAccessToken['oauth_token'], $twitterAccessToken['oauth_token_secret']);
                 $twitter->format = 'json';
                 $twitterProfiles = $twitter->get('users/lookup', array('user_id' => implode(',', $profilesToRequest)));
                 foreach ($twitterProfiles as $friend) {
                     $id = (string) $friend->id;
                     $screenName = (string) $friend->screen_name;
                     $pic = (string) $friend->profile_image_url;
                     $protected = (string) $friend->protected;
                     if ($id && ($screenName || $pic || $protected)) {
                         $update = $db->prepare('REPLACE INTO temp_twitter SET twitter_id = :twitter_id, time=NOW(), screen_name = :screen_name, picture_url = :picture_url, protected = :protected');
                         $update->execute(array(':twitter_id' => $id, ':screen_name' => $screenName, ':picture_url' => $pic, ':protected' => $protected));
                     }
                 }
             } catch (ErrorException $e) {
                 // Could not post to Twitter. Bad access token?
                 Debug::l('Error posting to Twitter ' . $e);
             }
         }
     }
     $linkPassword = BaseConvert::generatePassword();
     // Add the introduction to the database
     $insert = $db->prepare('INSERT INTO introduction (introducer_id, introducee1_id, introducee2_id, time, link_password) VALUES (:introducer_id, :introducee1_id, :introducee2_id, NOW(), :link_password)');
     $insert->execute(array(':introducer_id' => $userId, ':introducee1_id' => $introducee1->getId(), ':introducee2_id' => $introducee2->getId(), ':link_password' => $linkPassword));
     $introId = $db->lastInsertId();
     // Add the links for each introducee
     $linkPassword1 = BaseConvert::generatePassword();
     $linkPassword2 = BaseConvert::generatePassword();
     $insert = $db->prepare('INSERT INTO link (introduction_id, person_id, link_password) VALUES (:introduction_id, :person_id, :link_password)');
     $insert->execute(array(':introduction_id' => $introId, ':person_id' => $introducee1->getId(), ':link_password' => $linkPassword1));
     $insert->execute(array(':introduction_id' => $introId, ':person_id' => $introducee2->getId(), ':link_password' => $linkPassword2));
     // If there is a message, add it to the database
     if (!empty($_POST["message"])) {
         $message = htmlentities(trim($_POST['message']), ENT_QUOTES, 'UTF-8');
         if (!empty($message)) {
             $insert = $db->prepare('INSERT INTO message (body, time, introduction_id, writer_id) VALUES (:body, NOW(), :introduction_id, :writer_id)');
             $insert->execute(array(':body' => $message, ':introduction_id' => $introId, ':writer_id' => $userId));
         }
     }
     // Return the success message, which will tell the Javascript to redirect the user to the send-introduction page
     $json['result'] = 'true';
     $json['link'] = APP_URL . '/' . Content::l() . '/send-introduction/';
     $json['time'] = Debug::getInstance()->getTimeElapsed();
     echo json_encode($json);
 }
 *
 * Attribution Information
 * Attribution Phrase (not exceeding 10 words): Powered by Wikiarguments
 * Attribution URL: http://www.wikiarguments.net
 *
 * This display should be, at a minimum, the Attribution Phrase displayed in the
 * footer of the page and linked to the Attribution URL. The link to the Attribution
 * URL must not contain any form of 'nofollow' attribute.
 *
 * Display of Attribution Information is required in Larger Works which are
 * defined in the CPAL as a work which combines Covered Code or portions
 * thereof with code not governed by the terms of the CPAL.
 *******************************************************************************/
include "commonHeaders.php";
$id62 = $sRequest->getString("id");
$id = new BaseConvert($id62, 62, 10);
$type = $sRequest->getString("type");
$url = false;
if ($type == "question") {
    $q = $sQuery->getQuestionById($id->val());
    if ($q) {
        $url = $q->url();
    }
} else {
    if ($type == "questionDetails") {
        $q = $sQuery->getQuestionById($id->val());
        if ($q) {
            $url = $q->urlDetails();
        }
    } else {
        if ($type == "argument" || $type == "counterArgument") {
Exemple #12
0
 *
 * Attribution Information
 * Attribution Phrase (not exceeding 10 words): Powered by Wikiarguments
 * Attribution URL: http://www.wikiarguments.net
 *
 * This display should be, at a minimum, the Attribution Phrase displayed in the
 * footer of the page and linked to the Attribution URL. The link to the Attribution
 * URL must not contain any form of 'nofollow' attribute.
 *
 * Display of Attribution Information is required in Larger Works which are
 * defined in the CPAL as a work which combines Covered Code or portions
 * thereof with code not governed by the terms of the CPAL.
 *******************************************************************************/
include "commonHeaders.php";
$id62 = $sRequest->getString("id");
$id = new BaseConvert($id62, 62, 10);
$type = $sRequest->getString("type");
$url = false;
if ($type == "question") {
    $q = $sQuery->getQuestionById($id->val());
    if ($q) {
        $url = $q->url();
    }
} else {
    if ($type == "questionDetails") {
        $q = $sQuery->getQuestionById($id->val());
        if ($q) {
            $url = $q->urlDetails();
        }
    } else {
        if ($type == "argument" || $type == "counterArgument") {
 private function validateIntroductionParams()
 {
     if (empty($_GET['base62IntroductionId']) && empty($_GET['base62LinkId'])) {
         Debug::l('No introduction id or link id');
         header('Location: ' . APP_URL . '/' . Content::l() . '/');
         exit;
     }
     if (!empty($_GET['base62IntroductionId'])) {
         // The page has been passed an introduction ID
         if (preg_match('/^[0-9a-zA-Z]+$/', $_GET['base62IntroductionId']) == 0) {
             Debug::l('Invalid introduction id. Not base 62 compatible.');
             header('Location: ' . APP_URL . '/' . Content::l() . '/');
             exit;
         }
         // Convert the ID from base 62 to base 10
         $password = substr($_GET['base62IntroductionId'], 0, 3);
         $this->id = BaseConvert::base62ToBase10(substr($_GET['base62IntroductionId'], 3));
         // Make sure this introduction ID exists and the password is correct
         $introDetailsQ = $this->db->prepare('SELECT link_password FROM introduction WHERE id = :id');
         $introDetailsQ->execute(array(':id' => $this->id));
         $introDetails = $introDetailsQ->fetch(PDO::FETCH_ASSOC);
         if (empty($introDetails['link_password']) || $introDetails['link_password'] != $password) {
             Debug::l("That introduction id '{$this->id}' does not exist or the password '{$password}' is incorrect.");
             header('Location: ' . APP_URL . '/' . Content::l() . '/');
             exit;
         }
     } else {
         // The page has been passed a base 62 encoded link ID
         if (preg_match('/^[0-9a-zA-Z]+$/', $_GET['base62LinkId']) == 0) {
             Debug::l('Invalid link id. Not base 62 compatible.');
             header('Location: ' . APP_URL . '/' . Content::l() . '/');
             exit;
         }
         // Convert the ID from base 62 to base 10
         $password = substr($_GET['base62LinkId'], 0, 3);
         $linkId = BaseConvert::base62ToBase10(substr($_GET['base62LinkId'], 3));
         // Make sure this link ID exists
         $introDetailsQ = $this->db->prepare('SELECT introduction_id, person_id, link_password FROM link WHERE id = :id');
         $introDetailsQ->execute(array(':id' => $linkId));
         $introDetails = $introDetailsQ->fetch(PDO::FETCH_ASSOC);
         if (empty($introDetails['link_password']) || $introDetails['link_password'] != $password) {
             Debug::l("That link id '{$linkId}' does not exist or the password '{$password}' is incorrect.");
             header('Location: ' . APP_URL . '/' . Content::l() . '/');
             exit;
         }
         $this->id = $introDetails['introduction_id'];
         $this->targetUser = $introDetails['person_id'];
     }
 }