function processIdeaForm($userid = 0)
 {
     $resp = array();
     $resp['error'] = false;
     $idea = $_POST['idea'];
     $details = $_POST['details'];
     $tagid = $_POST['tagid'];
     if ($idea == '') {
         $resp['error'] = true;
         $resp['msg'] = 'Sorry, we did not get your idea. Please try again.';
     }
     if ($tagid == '' or $tagid == 0) {
         $resp['error'] = true;
         $resp['msg'] = 'Please specify a category. Please try again.';
     }
     if (isset($_POST['videoURL']) and $_POST['videoURL'] != '') {
         require_once PATH_CORE . '/classes/video.class.php';
         $videoURL = videos::getVideoURLFromEmbedCodeOrURL(stripslashes($_POST['videoURL']));
         if (videos::validateVideoURL($videoURL)) {
             $vt = new VideoTable($db);
             $videoid = $vt->createVideoForIdea($userid, $videoURL, "Idea video by {$userid}");
         } else {
             $resp['error'] = true;
             $resp['msg'] = 'Unsupported or invalid video URL';
         }
     } else {
         $videoid = 0;
     }
     if (!$resp['error']) {
         $isDup = $this->isDup($idea);
         if ($isDup !== false) {
             // it is a duplicate
             $resp['error'] = true;
             $resp['msg'] = 'Sorry, <a href="?p=ideas&o=view&id=' . $isDup . '">that idea has already been added here</a>.';
         } else {
             $iTable = new ideasTable($this->db);
             $ir = $iTable->getRowObject();
             $ir->idea = $idea;
             $ir->details = $details;
             $ir->tagid = $tagid;
             $ir->userid = $userid;
             $ir->dt = date('Y-m-d H:i:s', time());
             $ir->numLikes = 1;
             $ir->videoid = $videoid;
             $ir->insert();
             // add like for this idea when user posts
             require_once PATH_CORE . '/classes/log.class.php';
             $logObj = new log($this->db);
             $logItem = $logObj->serialize(0, $userid, 'likeIdea', $ir->id);
             $inLog = $logObj->update($logItem);
             $resp['id'] = $ir->id;
         }
     }
     return $resp;
 }
Exemplo n.º 2
0
             $error = true;
             $errorMsg = 'You have exceeded your rate limit for commenting. Please try again in one hour.';
         } else {
             if ($commentTotals['nickel'] >= $commentLimits['nickel']) {
                 $error = true;
                 $errorMsg = 'You have exceeded your rate limit for commenting. Please try again in 5 mins.';
             }
         }
     }
 }
 // TODO: grab videoURL, validate it, stuff it in to the $comment structure
 if (isset($_POST['videoURL']) and $_POST['videoURL'] != '') {
     require_once PATH_CORE . '/classes/video.class.php';
     $videoURL = videos::getVideoURLFromEmbedCodeOrURL(stripslashes($_POST['videoURL']));
     if (videos::validateVideoURL($videoURL)) {
         $vt = new VideoTable($db);
         $videoid = $vt->createVideoForComment($userid, $videoURL, "Video Comment on story {$cid}");
     } else {
         $error = true;
         $errorMsg = 'Unsupported or invalid video URL';
     }
 } else {
     if (isset($_POST['commentMsg']) and $_POST['commentMsg'] != '') {
         $commentMsg = preg_replace("/([\\w]+:\\/\\/[\\w-?&;#~=\\.\\/\\@]+[\\w\\/])/i", "<a target=\"_blank\" href=\"\$1\">\$1</a>", $_POST['commentMsg']);
         //$commentMsg = strip_tags($_POST['commentMsg'], '<a><i><b><p>');
         $commentMsg = strip_tags($commentMsg, '<a><i><b><p>');
         $commentMsg = nl2br($commentMsg);
         // TODO: GET THIS WORKING.
         //$comments = mysql_real_escape_string($_POST['commentMsg'], $db->handle);
     } else {
         $error = true;
 function createStoryContent($userinfo = NULL, $info = NULL, $mode = 'link')
 {
     // post a story from the post story form
     // build source from domain - to do : improve this with source objects table
     $urlParts = parse_url($info->url);
     $info->source = $urlParts['host'];
     // create permalink
     $info->permalink = $this->buildPermalink($info->title);
     //$this->db->log($info->permalink);
     // serialize the content
     // mode = link for third party web site story link and blog for blog posts
     if ($mode == 'link') {
         $isBlogEntry = 0;
     } else {
         $isBlogEntry = 1;
     }
     $story = $this->serialize(0, $info->title, $info->caption, $info->source, $info->url, $info->permalink, $userinfo->ncUid, $userinfo->u->name, $userinfo->userid, '', $userinfo->votePower, 0, 0, $info->imageUrl, 0, $isBlogEntry, $info->isFeatureCandidate);
     // post wire story to content
     $siteContentId = $this->add($story);
     if ($info->videoEmbed != '') {
         // add video if it exists
         require_once PATH_CORE . '/classes/video.class.php';
         $videoURL = videos::getVideoURLFromEmbedCodeOrURL(stripslashes($info->videoEmbed));
         if (videos::validateVideoURL($videoURL)) {
             $vt = new VideoTable($this->db);
             // create new video
             $videoid = $vt->createVideoForContent($userinfo->userid, $videoURL, "Video for story {$siteContentId}");
             if (is_numeric($videoid)) {
                 $this->db->update("Content", "videoid={$videoid}", "siteContentId={$siteContentId}");
             }
             // store video id in content table
         } else {
             // error on video, should have been picked up by validate
         }
     }
     return $siteContentId;
 }
 function getVideoIntro($videoIntroId = 0)
 {
     if ($videoIntroId > 0) {
         require_once PATH_CORE . '/classes/video.class.php';
         $videoTable = new VideoTable($this->db);
         $video = $videoTable->getRowObject();
         $video->load($videoIntroId);
         $str = '<div class="videoIntro">' . videos::buildPlayerFromLink($video->embedCode, 320, 240) . '</div><!-- end videoIntro -->';
         return $str;
     } else {
         return '';
     }
 }
 function buildVideos($completedid)
 {
     //require_once(PATH_CORE.'/classes/challenges.class.php');
     require_once PATH_CORE . '/classes/video.class.php';
     $videoTable = new VideoTable($this->db);
     $video = $videoTable->getRowObject();
     $videoids = $videoTable->getVideosForCompletedChallenge($completedid);
     foreach ($videoids as $id) {
         if ($video->load($id)) {
             $code .= $this->buildVideoplayer($video->embedCode);
         }
     }
     return $code;
 }
$manageObj->addTable("fbSessions", "id", "BIGINT(20) unsigned NOT NULL auto_increment", "MyISAM");
$manageObj->addColumn("fbSessions", "userid", "BIGINT(20) default 0");
$manageObj->addColumn("fbSessions", "fbId", "BIGINT(20) default 0");
$manageObj->addColumn("fbSessions", "fb_sig_session_key", "varchar(255) default ''");
$manageObj->addColumn("fbSessions", "fb_sig_time", "DATETIME");
$manageObj->addColumn("fbSessions", "fb_sig_expires", "DATETIME");
$manageObj->addColumn("fbSessions", "fb_sig_profile_update_time", "DATETIME");
if ($manageObj->modifyLibrary(PATH_CORE . '/classes/', 'prizes.class.php')) {
    require_once PATH_CORE . '/classes/prizes.class.php';
    PrizeTable::createTable($manageObj);
    $prizeTable = new PrizeTable($manageObj->db);
}
if ($manageObj->modifyLibrary(PATH_CORE . '/classes/', 'video.class.php')) {
    // create video table
    require_once PATH_CORE . '/classes/video.class.php';
    VideoTable::createTable($manageObj);
}
if ($manageObj->modifyLibrary(PATH_CORE . '/classes/', 'photo.class.php')) {
    // create photo table
    require_once PATH_CORE . '/classes/photo.class.php';
    PhotoTable::createTable($manageObj);
}
if ($manageObj->modifyLibrary(PATH_CORE . '/classes/', 'challenges.class.php')) {
    require_once PATH_CORE . '/classes/challenges.class.php';
    ChallengeTable::createTable($manageObj);
    ChallengeCompletedTable::createTable($manageObj);
    $challengeTable = new ChallengeTable($manageObj->db);
    $challengeTable->populateCommonChallenges();
}
if ($manageObj->modifyLibrary(PATH_CORE . '/classes/', 'scores.class.php')) {
    require_once PATH_CORE . '/classes/scores.class.php';
 static function processChallengeSubmit(&$code, &$passback)
 {
     //$debug = $_POST['debugSubmit']; // NEVER TURN ON FOR LIVE SITE
     echo '<h2>Processing, please wait...</h2>';
     if ($debug) {
         echo "POST<pre>" . print_r($_POST, true) . "</pre>";
     }
     // TODO: grab session keys from post, validate session
     $passback .= "&text={$_POST['text']}";
     $passback .= "&embedCode={$_POST['embedCode']}";
     if ($debug) {
         echo $passback;
     }
     if (isset($_POST['challengeid']) && $_POST['challengeid']) {
         $challengeid = $_POST['challengeid'];
     } else {
         $code = "There was no challenge id present in your submission";
         return false;
     }
     if (isset($_POST['text'])) {
         $evidence = $_POST['text'];
     } else {
         $evidence = '';
         /*$code = "Your text submission was empty."; return false;*/
     }
     if (isset($_POST['userid']) && $_POST['userid']) {
         $userid = $_POST['userid'];
     } else {
         $code = 'Either you aren\'t a registered user or your session is expired. Please return to the home page or sign in to facebook again.';
         return false;
     }
     require_once PATH_CORE . '/classes/db.class.php';
     $db = new cloudDatabase();
     // create a CompletedChallenges object
     //$userid = $this->page->session->userid;
     /*	if (!$userid)
     		{
     			echo "<pre>" . print_r($this->page->session, true) . "</pre>";	
     			
     			return "Could not get userid from session."; 
     		}*/
     require_once PATH_CORE . '/classes/user.class.php';
     require_once PATH_CORE . '/classes/challenges.class.php';
     $challengeTable = new ChallengeTable($db);
     $userTable = new UserTable($db);
     $userInfoTable = new UserInfoTable($db);
     $completedTable = new ChallengeCompletedTable($db);
     $user = $userTable->getRowObject();
     $userInfo = $userInfoTable->getRowObject();
     $challenge = $challengeTable->getRowObject();
     $completed = $completedTable->getRowObject();
     dbRowObject::$debug = $debug;
     $user->load($userid);
     $userInfo->load($userid);
     $challenge->load($challengeid);
     // validate challenge submission info
     // validate eligibility, date, membership
     if ($challenge->remainingCompletions <= 0 && $challenge->initialCompletions > 0) {
         $code = 'This challenge can no longer be completed for credit.';
         return false;
     }
     if (!ChallengeTable::userIsEligible($challenge->eligibility, $user->eligibility)) {
         $code = 'We\'re sorry, you are not eligible to receive credit for this challenge.';
         return false;
     }
     if (preg_match("/text/i", $challenge->requires) && !($evidence != '')) {
         $code = 'Sorry, you need to convince us you actually did this!';
         return false;
     }
     //if () //  TODO: now is between date start and end
     $now = time();
     $dateStart = strtotime($challenge->dateStart);
     $dateEnd = strtotime($challenge->dateEnd);
     if ($now > $dateEnd) {
         $code = 'Sorry, you are too late to receive credit for this challenge!';
         return false;
     }
     if ($now < $dateStart) {
         $code = 'Sorry, you can\'t receive credit for this challenge yet -- try again later!';
         return false;
     }
     // if () TODO: check user maximum by querying order histor
     // more...
     // everythings ok:
     $challenge->remainingCompletions--;
     $completed->userid = $user->userid;
     $completed->challengeid = $challenge->id;
     $phpnow = time();
     $completed->dateSubmitted = date('Y-m-d H:i:s', $phpnow);
     $completed->status = 'submitted';
     $completed->evidence = $evidence;
     $completed->comments = $evidence;
     // editors will review these later
     /*
      * The following code is a bit tricky. There are two things going on. The first is that photos
      * or videos are being checked for and their records are being created, but we have 
      * tentatively created a CompleteChallenge record first so they can back-reference it
      * 
      * If a required photo or video turns out not to have appeared, we have to then return an error 
      * and delete the CC record.
      * 
      * An extra wrinkle is that if both video and photo are in the requires field, we can accept 
      * one or the other.
      * 
      */
     // Create the completed to attach to the media records...
     if (!$completed->insert()) {
         $code = 'Internal error submitting your evidence, please try again.';
         return false;
     }
     if (preg_match("/photo/i", $challenge->requires) || preg_match("/optionalphoto/i", $challenge->requires)) {
         if ($photoFilename = self::processChallengeSubmitPhoto($userid, $completed->id)) {
             if (!preg_match("/\\.(jpg|png|gif|jpeg?)\$/i", $photoFilename)) {
                 $msg = 'Sorry, your photo did not appear to be of type jpg, png, or gif.';
                 $error = true;
             } else {
                 // create photo in our db
                 require_once PATH_CORE . '/classes/photo.class.php';
                 $photoTable = new PhotoTable($db);
                 $photoTable->createPhotoForCompletedChallenge($userid, $completed->id, $photoFilename, 'Photo submitted for ' . $challenge->title);
                 $photoSubmitted = true;
                 // indicate that a photo was found
             }
         } else {
             if (!preg_match("/optionalphoto/i", $challenge->requires)) {
                 $msg = 'No photo submitted';
                 $error = true;
             }
         }
     }
     //$passback .= "&photo1={$photoFilename}"; // wont be correct filename, actually quite complicated to make this work properly
     //echo $passback;
     if (preg_match("/video/i", $challenge->requires)) {
         if ($videoEmbedCode = self::processChallengeSubmitVideo($userid, $completed->id)) {
             // create photo in our db
             require_once PATH_CORE . '/classes/video.class.php';
             $videoTable = new VideoTable($db);
             $videoTable->createVideoForCompletedChallenge($userid, $completed->id, $videoEmbedCode, 'Video submitted for ' . $challenge->title);
             $videoSubmitted = true;
             // indicate video found
         } else {
             $msg = 'You must enter a YouTube video url.';
             $error = true;
         }
     }
     // HACK: now handle the case where both photo and video boxes appeared, and only one was entered
     if ($photoSubmitted or $videoSubmitted) {
         $error = false;
     }
     // set the $error flag set by the other one to false if one of them was sucessfully created
     if ($error) {
         $completed->delete();
         // delete the temporary CC record
         $code = $msg;
         return false;
     }
     $challenge->update();
     require_once PATH_CORE . '/classes/template.class.php';
     $code .= 'We have received your submission for the challenge <b>' . $challenge->title . '</b>  (reference number #' . $completed->id . ')';
     dbRowObject::$debug = 0;
     // NEVER TURN ON FOR LIVE SITE
     // for testing purposes -- approve free points right away
     if ($challenge->shortName == 'testPoints10k') {
         $code2 = '';
         if (!$completedTable->approveChallenge($completed->id, $challenge->pointValue, &$code2, false)) {
             $code = $code2;
             return false;
         } else {
             $code = 'Free points awarded!';
         }
     }
     return true;
 }