function parse() { require_once PATH_CORE . '/classes/remotefile.class.php'; $rfObj = new remotePageProperty($this->url); $data = array(); $data['title'] = $this->cleanTitle($rfObj->getPageTitle()); $page = $rfObj->page_content; // to do - grab description from meta tag or story content if (preg_match('/<meta name="description"[^>]*content="([^"]+)"/i', $page, $match)) { $data['description'] = $match[1]; } else { $temp = $rfObj->getPageParagraphs(); require_once PATH_CORE . '/classes/utilities.class.php'; $utilObj = new utilities(); $temp = $utilObj->shorten($temp, LENGTH_LONG_CAPTION); $data['description'] = $temp; //$this->log('Caption from gPP: '.$temp); } $data['images'] = $this->parseImages($rfObj); // to do - grab content // to do - use my code to grab keywords using semantic library return $this->jsonData($data); }
function transmit($timestamp = 0, $limit = 25) { require_once 'utilities.class.php'; $utilObj = new utilities($this->db); // return serialized log info for synchronization $log = array(); /*** Transmit votes - req. ncUid and contentid ***/ $votes = array(); $x = 0; $page = 0; $q = $this->db->query("SELECT Log.*,User.ncUid,Content.contentid FROM Log,User,Content WHERE Log.itemid=Content.siteContentId AND contentid>0 AND User.ncUid<>0 AND Log.userid1=User.userid AND action='vote' AND status='pending' AND Content.isBlocked=0 AND User.isBlocked=0 ORDER BY Log.id DESC"); while ($data = $this->db->readQ($q)) { $votes[$x][contentid] = $data->contentid; $votes[$x][logid] = $data->id; // fetch newscloud id from userid1 $votes[$x][uid] = $data->ncUid; // $this->lookupUid($data->userid1); $x += 1; } $this->narrate('Transmitting votes'); $this->narrate($votes); $log['votes'] = $votes; /*** Transmit new users - req isVerifiedEmail=1 ***/ $newUsers = array(); $x = 0; require_once 'userRemoteSync.class.php'; $rsObj = new userRemoteSync($this->db); require_once PATH_CORE . '/classes/systemStatus.class.php'; $ssObj = new systemStatus($this->db); $partnerid = $ssObj->getState('partnerid'); $q = $rsObj->findUnlinkedAccounts(); while ($data = $this->db->readQ($q)) { $newUsers[$x][partnerid] = $partnerid; $newUsers[$x][userid] = $data->userid; $newUsers[$x][name] = $data->name; $newUsers[$x][email] = $data->email; $newUsers[$x][fbId] = $data->fbId; $newUsers[$x][city] = $data->city; $x += 1; } $log['newUsers'] = $newUsers; $this->narrate('New users to sync with NewsCloud'); $this->narrate($newUsers); // build for users to synchronize - changed bio, changed user level - to do : facebook image /*** Transmit users who change their user level ***/ $levelChanges = array(); $x = 0; require_once 'userRemoteSync.class.php'; $rsObj = new userRemoteSync($this->db); $q = $rsObj->findUserLevelIncreases($timestamp); while ($data = $this->db->readQ($q)) { $levelChanges[$x][logid] = $data->id; $levelChanges[$x][userid] = $data->userid; $levelChanges[$x][uid] = $data->ncUid; $levelChanges[$x][userlevel] = $data->itemid; $x += 1; } $log['levelChanges'] = $levelChanges; $this->narrate('User Level Increases'); $this->narrate($levelChanges); /*** Transmit read story records - req. ncUid and contentid ***/ $q = $this->db->query("SELECT Log.id,Content.contentid,User.ncUid FROM Log,Content,User WHERE action='readStory' AND status='pending' AND User.userid=Log.userid1 AND Log.itemid=Content.siteContentId AND User.ncUid>0 AND Content.contentid>0 AND Content.isBlocked=0 AND User.isBlocked=0 ORDER BY id DESC LIMIT {$limit};"); $readStory = array(); $x = 0; while ($data = $this->db->readQ($q)) { $readStory[$x][contentid] = $data->contentid; $readStory[$x][logid] = $data->id; $readStory[$x][uid] = $data->ncUid; $x += 1; } $log['readStory'] = $readStory; /*** Transmit published story to journal - req. ncUid and contentid ***/ $q = $this->db->query("SELECT Log.id,Content.contentid,User.ncUid FROM Log,Content,User WHERE action='publishStory' AND status='pending' AND User.userid=Log.userid1 AND Log.itemid=Content.siteContentId AND User.ncUid>0 AND Content.contentid>0 AND Content.isBlocked=0 AND User.isBlocked=0 ORDER BY id DESC LIMIT {$limit};"); $pubStory = array(); $x = 0; while ($data = $this->db->readQ($q)) { $pubStory[$x][contentid] = $data->contentid; $pubStory[$x][logid] = $data->id; $pubStory[$x][uid] = $data->ncUid; $x += 1; } $log['pubStory'] = $pubStory; /*** Transmit posted raw stories - req ncUid ***/ $q = $this->db->queryC("SELECT Log.id,Log.itemid,User.ncUid FROM Log,User WHERE action='publishWire' AND status='pending' AND User.userid=Log.userid1 AND User.ncUid>0 AND User.isBlocked=0 ORDER BY id DESC LIMIT {$limit};"); $pubWire = array(); $x = 0; while ($data = $this->db->readQ($q)) { $wireQuery = $this->db->queryC("SELECT * FROM Newswire WHERE id={$data->itemid};"); if ($wireQuery !== false) { $wi = $this->db->readQ($wireQuery); $pubWire[$x][logid] = $data->id; $pubWire[$x][uid] = $data->ncUid; // fetch wire story url $pubWire[$x][url] = $wi->url; $pubWire[$x][siteContentId] = $data->itemid2; $pubWire[$x][wireid] = $wi->wireid; switch ($wi->feedType) { default: // wire $pubWire[$x][feedType] = 'wire'; break; case 'blog': $pubWire[$x][feedType] = 'blog'; $pubWire[$x][title] = $wi->title; $pubWire[$x][date] = $wi->date; $pubWire[$x][caption] = $utilObj->shorten($wi->caption, 500); break; } $x += 1; } else { // story deleted from newswire $this->db->update("Log", "status='error'", "id={$data->id}"); } } $log['pubWire'] = $pubWire; /*** Transmit posted stories, a new user posted story - req ncUid ***/ $q = $this->db->queryC("SELECT Log.id,Log.itemid,User.ncUid FROM Log,User WHERE action='postStory' AND status='pending' AND User.userid=Log.userid1 AND User.ncUid>0 AND User.isBlocked=0 ORDER BY id DESC LIMIT {$limit};"); if ($q !== false) { //$this->db->log('inside poststory'); require_once PATH_CORE . '/classes/content.class.php'; $cObj = new content($this->db); $postStory = array(); $x = 0; while ($data = $this->db->readQ($q)) { $this->db->log($data->id); // fetch contentid from siteContentid $si = $cObj->getById($data->itemid); if ($si !== false) { $postStory[$x][logid] = $data->id; $postStory[$x][siteContentId] = $data->itemid; $postStory[$x][uid] = $data->ncUid; $postStory[$x][title] = $si->title; $postStory[$x][url] = $si->url; $postStory[$x][date] = $si->date; $postStory[$x][caption] = htmlentities($utilObj->shorten(strip_tags($si->caption), 500), ENT_QUOTES); $imageProps = $cObj->getImage($data->itemid); if ($imageProps !== false) { $postStory[$x][imageurl] = $imageProps->url; } $x += 1; } } $log['postStory'] = $postStory; } $this->narrate('Posting stories to NewsCloud'); $this->narrate($postStory); /*** Transmit comments - req. ncUid and contentid ***/ $comments = array(); $q = $this->db->query("SELECT Log.id,Comments.comments,Comments.siteCommentId,Content.contentid,User.ncUid FROM Log,Comments,Content,User WHERE Log.itemid=Comments.siteCommentId AND Comments.siteContentId=Log.itemid2 AND Content.siteContentId=Log.itemid2 AND Content.contentid>0 AND Log.userid1=User.userid AND User.ncUid>0 AND action='comment' AND status='pending' AND Content.isBlocked=0 AND User.isBlocked=0 AND Comments.videoid=0 ORDER BY id DESC LIMIT {$limit};"); $x = 0; while ($data = $this->db->readQ($q)) { $comments[$x][uid] = $data->ncUid; $comments[$x][contentid] = $data->contentid; $comments[$x][logid] = $data->id; $comments[$x][comments] = htmlentities($data->comments, ENT_QUOTES); $comments[$x][siteCommentId] = $data->siteCommentId; $x += 1; // fetch contentid from siteContentid //$contentid=$this->lookupContentId($data->itemid); //if ($contentid!==false AND $contentid<>0) { // fetch newscloud id from userid1 //$ncUid=$this->lookupUid($data->userid1); //if ($ncUid<>0) { //} //} } $log['comments'] = $comments; $this->narrate('Transmitting comments'); $this->narrate($comments); // send serialized array out return serialize($log); }
function loadStory($wire = null, $feed = null) { $this->db->log('entering loadStory '); $this->db->log($wire); // post a story from a feed to Content table for the user who owns the bookmark feed $this->psObj->refreshUrl($wire->url); // $id is feed id, $wire is serialized newswire object, $feed->userid is posted by userid // clean headlines $wire->title = $this->psObj->cleanTitle($wire->title); $this->db->log('clean title:' . $wire->title); // check for duplicates from final url or initial url or title $error = false; $cleanUrl = $this->psObj->cleanUrl($wire->url); $isDup = $this->db->queryC("SELECT siteContentId FROM Content WHERE url = '" . $wire->url . "' OR url = '" . $cleanUrl . "' OR title = '" . $wire->title . "'"); if ($isDup === false) { $wire->url = $cleanUrl; $this->psObj->log('Cleaned url: ' . $cleanUrl . ' <= ' . $wire->url); // load user wire record $this->db->log('not a dup'); require_once PATH_CORE . '/classes/user.class.php'; $userTable = new UserTable($this->db); $user = $userTable->getRowObject(); // to do if $feed->userid==0 use admin if ($feed->userid == 0) { $user->loadWhere("isAdmin=1"); } else { $user->load($feed->userid); } // create temporary content item, temp permalink require_once PATH_CORE . '/classes/utilities.class.php'; $utilObj = new utilities(); require_once PATH_CORE . '/classes/content.class.php'; $cObj = new content($this->db); // clean caption, strip tags, trim for length $wire->caption = $utilObj->shorten($wire->caption, LENGTH_LONG_CAPTION); $wire->source = $this->stripit(parse_url($wire->url, PHP_URL_HOST)); // create permalink $wire->permalink = $cObj->buildPermalink($wire->title); // get images, check size of each and pick most likely candidate with minimum require_once PATH_CORE . '/classes/remotefile.class.php'; $rfObj = new remotePageProperty($wire->url); $imgArr = $this->psObj->parseImages($rfObj, 7500); // 7500 is min jpg size for automatically selecting images // $this->db->log($imgArr); if (count($imgArr) > 0) { $wire->imageUrl = $imgArr[0]; } else { $wire->imageUrl = ''; } // serialize the content $isBlogEntry = 0; $story = $cObj->serialize(0, $wire->title, $wire->caption, $wire->source, $wire->url, $wire->permalink, $user->ncUid, $user->name, $user->userid, '', 1, 0, 0, $wire->imageUrl, 0, $isBlogEntry, 1); //$this->db->log($story); // add to content by this userid $siteContentId = $cObj->add($story); if ($siteContentId !== false) { require_once PATH_CORE . '/classes/log.class.php'; $this->logObj = new log($this->db); // add to user journal $logItem = $this->logObj->serialize(0, $user->userid, 'postStory', $siteContentId); $inLog = $this->logObj->update($logItem); if ($inLog) { $logItem = $this->logObj->serialize(0, $user->userid, 'vote', $siteContentId); $inLog = $this->logObj->update($logItem); } } // set new story loaded flag - so that features can be updated $this->newStoryLoaded = true; } else { $error = true; } }
function validate($option = 'link') { $this->setupLibraries(); $fData = new stdClass(); $fData->result = true; $fData->state = 'validate'; $fData->url = $_POST['url']; $fData->imageUrl = $_POST['imageUrl']; $fData->videoEmbed = $_POST['videoEmbed']; // Remove microsoft quotes $bad = array('`', '’', '„', '‘', '’', '´'); $good = array('\'', '\'', ',', '\'', '\'', '\''); $title = str_replace($bad, $good, $_POST['title']); $fData->title = stripslashes(strip_tags($title)); // took out mysql_real_escape $fData->tags = $_POST['tags']; $fData->mediatype = $_POST['mediatype']; if (isset($_POST['isFeatureCandidate']) and $_POST['isFeatureCandidate'] == 'on') { $fData->isFeatureCandidate = 1; } else { $fData->isFeatureCandidate = 0; } $fData->isBookmarklet = true; $fData->showPreview = false; $fData->alert = ''; $fData->title = stripslashes(strip_tags($_POST['title'])); $fData->caption = stripslashes($_POST['caption']); //$fData->title=mysql_real_escape_string(addslashes(stripslashes(strip_tags($_POST['title'])))); //$fData->caption=mysql_real_escape_string(stripslashes($_POST['caption']), $this->db->handle); // begin option specific code and error checking switch ($option) { default: $fData->caption = stripslashes(strip_tags($_POST['caption'])); if ($fData->url == '') { $fData->alert = 'Please provide a Web address (URL) for your story.'; $fData->result = false; } if ($fData->caption == '') { $fData->alert = 'Please provide a short caption for your entry.'; $fData->result = false; } if (strlen($fData->caption) > LENGTH_LONG_CAPTION + 5) { $fData->alert = 'Please shorten your caption to ' . LENGTH_LONG_CAPTION . ' characters. Current length: ' . strlen($fData->caption); $fData->result = false; } break; case 'blog': if (isset($_POST['blogid'])) { $fData->blogid = $_POST['blogid']; } $fData->status = 'draft'; // only allowable html, fbml $fData->entry = stripslashes(strip_tags($_POST['entry'], '<p><a><i><br><em><strong><img>')); // <fb:photo><fb:mp3><fb:swf><fb:flv><fb:silverlight> $fData->caption = stripslashes(strip_tags($_POST['caption'])); if ($fData->entry == '' or strlen($fData->entry) < MIN_BLOG_LENGTH) { $fData->alert = 'Please compose a blog post of at least ' . MIN_BLOG_LENGTH . ' characters (not counting HTML tags). Current length: ' . strlen($fData->entry); $fData->result = false; $lengthError = true; } else { $lengthError = false; } if (strlen($fData->entry) > MAX_BLOG_LENGTH) { $fData->alert = 'Please shorten your blog entry to ' . MAX_BLOG_LENGTH . ' characters. Current length: ' . strlen($fData->entry); $fData->result = false; } if ($fData->caption != '') { // if it exists already, then check that it meets the minimum length requirements if (strlen($fData->caption) > LENGTH_LONG_CAPTION + 5) { $temp = $utilObj->shorten($_POST['caption'], LENGTH_LONG_CAPTION); $fData->caption = $temp; } } else { // if it doesn't exist, create require_once PATH_CORE . '/classes/utilities.class.php'; $utilObj = new utilities($this->db); $temp = $utilObj->shorten($fData->entry, CAPTION_LENGTH); if (!$lengthError and strlen($temp) < 100) { $fData->alert = 'Please compose a blog entry for a caption of at least ' . MIN_BLOG_LENGTH . ' characters (not counting HTML tags). Current length: ' . strlen($temp); $fData->result = false; } $fData->caption = $temp; } break; } // tags /* if ($fData->tags=='') { $fData->alert='Please provide at least one tag.'; $fData->result=false; } * */ // check user has minimum # of friends - to prevent spam if (isset($_POST['fb_sig_friends']) and count(explode(',', $_POST['fb_sig_friends'])) < MIN_FRIENDS) { // suspiciously low # of friends to be posting $fData->alert = 'Please add more friends to your Facebook profile before you post stories here. This helps us minimize spam. Sorry for the inconvenience.'; $fData->result = false; } //title if (strcmp(strtoupper($fData->title), $fData->title) == 0) { $fData->title = $temp = ucwords(strtolower($fData->title)); $fData->alert = 'We\'ve modified your headline so that it\'s not all uppercase. Please check it.'; $fData->result = false; } if ($fData->title == '') { $fData->alert = 'Please provide a short headline for your entry.'; $fData->result = false; } if (strlen($fData->title) > $this->titleLimit) { $fData->alert = 'Please shorten your title to ' . $this->titleLimit . ' characters. Current length: ' . strlen($fData->title); $fData->result = false; } /* We might want this later if ($fData->imageUrl=='' ) { $fData->alert='Please provide a Web address (IMAGE URL) for your story image.'; $fData->result=false; } */ // url if ($fData->url != '') { $urlParts = parse_url($fData->url); // make sure url has http:// or other scheme in front of it if ($urlParts['scheme'] == '') { $fData->url = 'http://' . $fData->url; } if (($urlParts['path'] == '' or $urlParts['path'] == '/') and $urlParts['query'] == '') { $fData->alert = 'You seem to be writing about a Web site, not a particular story on a Web site. Please do not submit links to Web sites. Please only submit stories from Web sites and blogs.'; $fData->result = false; } if (preg_match('/^http:\\/\\/www.facebook.com\\/ext\\/share.php/', $fData->url)) { $fData->alert = 'You seem to be posting a shared story from facebook. Please go to the actual story page and post again from there.'; $fData->result = false; } } // Check for rate limits on post story if (!($this->session->u->isAdmin || $this->session->u->isModerator || $this->session->u->isSponser)) { $resp = $this->logObj->checkLimits($this->session->userid, "(action = 'postStory' OR action = 'postBlog')", 'posting'); if ($resp !== false) { $fData->alert = $resp['msg']; $fData->result = false; } } // validate the video if ($fData->videoEmbed != '') { require_once PATH_CORE . '/classes/video.class.php'; $videoURL = videos::getVideoURLFromEmbedCodeOrURL(stripslashes($fData->videoEmbed)); if (!videos::validateVideoURL($fData->videoEmbed)) { $fData->alert = 'Your video URL or embedding code is invalid. We only support Facebook and YouTube videos at this time.'; $fData->result = false; } } $this->fData =& $fData; return $fData; }