function getDisplayText($text = NULL, $postmode = NULL) { if (isset($text)) { $this->setText($text); } if (isset($postmode)) { $this->setPostmode($postmode); } if ($this->_postmode == 'plaintext') { $return = nl2br($this->_text); } elseif ($this->_postmode == 'wikitext') { $return = COM_renderWikiText($this->_editUnescape($this->_text)); } else { $return = $this->_text; } $return = PLG_replaceTags($this->_displayEscape($return)); return $return; }
/** * Provide access to story elements. For display. * * This is a peudo-property, implementing a getter for story * details as if as an associative array. Personally, I'd * rather be able to assign getters and setters to actual * properties to mask controlled access to private member * variables. But, you get what you get with PHP. So here it * is in all it's nastyness. * * @param string $item Item to fetch. * @return mixed The clean and ready to use value requested. */ function DisplayElements($item = 'title') { global $_CONF, $_TABLES; $return = ''; switch (strtolower($item)) { case 'introtext': if ($this->_postmode == 'plaintext') { $return = nl2br($this->_introtext); } elseif ($this->_postmode == 'wikitext') { $return = COM_renderWikiText($this->_editUnescape($this->_introtext)); } else { $return = $this->_introtext; } $return = PLG_replaceTags($this->_displayEscape($return)); break; case 'bodytext': if ($this->_postmode == 'plaintext' && !empty($this->_bodytext)) { $return = nl2br($this->_bodytext); } elseif ($this->_postmode == 'wikitext' && !empty($this->_bodytext)) { $return = COM_renderWikiText($this->_editUnescape($this->_bodytext)); } elseif (!empty($this->_bodytext)) { $return = $this->_displayEscape($this->_bodytext); } $return = PLG_replaceTags($return); break; case 'title': $return = $this->_displayEscape($this->_title); break; case 'meta_description': $return = $this->_meta_description; break; case 'meta_keywords': $return = $this->_meta_keywords; break; case 'shortdate': $return = strftime($_CONF['shortdate'], $this->_date); break; case 'dateonly': $return = strftime($_CONF['dateonly'], $this->_date); break; case 'date': $return = COM_getUserDateTimeFormat($this->_date); $return = $return[0]; break; case 'unixdate': $return = $this->_date; break; case 'hits': $return = COM_NumberFormat($this->_hits); break; case 'topic': $return = htmlspecialchars($this->_topic); break; case 'expire': if (empty($this->_expire)) { $return = time(); } else { $return = $this->_expire; } break; case 'commentcode': // check to see if comment_time has passed if ($this->_comment_expire != 0 && time() > $this->_comment_expire && $this->_commentcode == 0) { // if comment code is not 1, change it to 1 DB_query("UPDATE {$_TABLES['stories']} SET commentcode = '1' WHERE sid = '{$this->_sid}'"); $return = 1; } else { $return = $this->_commentcode; } break; default: $varname = '_' . $item; if (isset($this->{$varname})) { $return = $this->{$varname}; } break; } return $return; }
/** * This will email new stories in the topics that the user is interested in * * In account information the user can specify which topics for which they * will receive any new article for in a daily digest. * * @return void */ function COM_emailUserTopics() { global $_CONF, $_TABLES, $LANG04, $LANG08, $LANG24; if ($_CONF['emailstories'] == 0) { return; } $subject = strip_tags($_CONF['site_name'] . $LANG08[30] . strftime('%Y-%m-%d', time())); $authors = array(); // Get users who want stories emailed to them $usersql = "SELECT username,email,etids,{$_TABLES['users']}.uid AS uuid " . "FROM {$_TABLES['users']}, {$_TABLES['userindex']} " . "WHERE {$_TABLES['users']}.uid > 1 AND {$_TABLES['userindex']}.uid = {$_TABLES['users']}.uid AND (etids <> '-' OR etids IS NULL) ORDER BY {$_TABLES['users']}.uid"; $users = DB_query($usersql); $nrows = DB_numRows($users); $lastrun = DB_getItem($_TABLES['vars'], 'value', "name = 'lastemailedstories'"); // For each user, pull the stories they want and email it to them for ($x = 0; $x < $nrows; $x++) { $U = DB_fetchArray($users); $storysql = array(); $storysql['mysql'] = "SELECT sid,uid,date AS day,title,introtext,bodytext"; $storysql['pgsql'] = "SELECT sid,uid,date AS day,title,introtext,postmode"; $storysql['mssql'] = "SELECT sid,uid,date AS day,title,CAST(introtext AS text) AS introtext,CAST(bodytext AS text) AS introtext"; $commonsql = " FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW() AND date >= '{$lastrun}'"; $topicsql = "SELECT tid FROM {$_TABLES['topics']}" . COM_getPermSQL('WHERE', $U['uuid']); $tresult = DB_query($topicsql); $trows = DB_numRows($tresult); if ($trows == 0) { // this user doesn't seem to have access to any topics ... continue; } $TIDS = array(); for ($i = 0; $i < $trows; $i++) { $T = DB_fetchArray($tresult); $TIDS[] = $T['tid']; } if (!empty($U['etids'])) { $ETIDS = explode(' ', $U['etids']); $TIDS = array_intersect($TIDS, $ETIDS); } if (count($TIDS) > 0) { $commonsql .= " AND (tid IN ('" . implode("','", $TIDS) . "'))"; } $commonsql .= COM_getPermSQL('AND', $U['uuid']); $commonsql .= ' ORDER BY featured DESC, date DESC'; $storysql['mysql'] .= $commonsql; $storysql['mssql'] .= $commonsql; $storysql['pgsql'] .= $commonsql; $stories = DB_query($storysql); $nsrows = DB_numRows($stories); if ($nsrows == 0) { // If no new stories where pulled for this user, continue with next continue; } $mailtext = $LANG08[29] . strftime($_CONF['shortdate'], time()) . "\n"; for ($y = 0; $y < $nsrows; $y++) { // Loop through stories building the requested email message $S = DB_fetchArray($stories); $mailtext .= "\n------------------------------\n\n"; $mailtext .= "{$LANG08['31']}: " . COM_undoSpecialChars(stripslashes($S['title'])) . "\n"; if ($_CONF['contributedbyline'] == 1) { if (empty($authors[$S['uid']])) { $storyauthor = COM_getDisplayName($S['uid']); $authors[$S['uid']] = $storyauthor; } else { $storyauthor = $authors[$S['uid']]; } $mailtext .= "{$LANG24['7']}: " . $storyauthor . "\n"; } $mailtext .= "{$LANG08['32']}: " . strftime($_CONF['date'], strtotime($S['day'])) . "\n\n"; if ($_CONF['emailstorieslength'] > 0) { if ($S['postmode'] === 'wikitext') { $storytext = COM_undoSpecialChars(strip_tags(COM_renderWikiText(stripslashes($S['introtext'])))); } else { $storytext = COM_undoSpecialChars(strip_tags(PLG_replaceTags(stripslashes($S['introtext'])))); } if ($_CONF['emailstorieslength'] > 1) { $storytext = COM_truncate($storytext, $_CONF['emailstorieslength'], '...'); } $mailtext .= $storytext . "\n\n"; } $mailtext .= $LANG08[33] . ' ' . COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $S['sid']) . "\n"; } $mailtext .= "\n------------------------------\n"; $mailtext .= "\n{$LANG08['34']}\n"; $mailtext .= "\n------------------------------\n"; $mailto = $U['username'] . ' <' . $U['email'] . '>'; if ($_CONF['site_mail'] !== $_CONF['noreply_mail']) { $mailfrom = $_CONF['noreply_mail']; $mailtext .= LB . LB . $LANG04[159]; } else { $mailfrom = $_CONF['site_mail']; } COM_mail($mailto, $subject, $mailtext, $mailfrom); } DB_query("UPDATE {$_TABLES['vars']} SET value = NOW() WHERE name = 'lastemailedstories'"); }
/** * This will email new stories in the topics that the user is interested in * In account information the user can specify which topics for which they * will receive any new article for in a daily digest. * * @return void */ function COM_emailUserTopics() { global $_CONF, $_VARS, $_TABLES, $LANG04, $LANG08, $LANG24; if ($_CONF['emailstories'] == 0) { return; } $subject = strip_tags($_CONF['site_name'] . $LANG08[30] . strftime('%Y-%m-%d', time())); $authors = array(); // Get users who want stories emailed to them $userSql = "SELECT username,email,etids,{$_TABLES['users']}.uid AS uuid " . "FROM {$_TABLES['users']}, {$_TABLES['userindex']} " . "WHERE {$_TABLES['users']}.uid > 1 AND {$_TABLES['userindex']}.uid = {$_TABLES['users']}.uid AND " . "(etids <> '-' OR etids IS NULL) " . "ORDER BY {$_TABLES['users']}.uid"; $users = DB_query($userSql); $numRows = DB_numRows($users); $lastRun = $_VARS['lastemailedstories']; // For each user, pull the stories they want and email it to them for ($x = 0; $x < $numRows; $x++) { $U = DB_fetchArray($users); $storySql = array(); $storySql['mysql'] = "SELECT sid,uid,date AS day,title,introtext,bodytext"; $storySql['pgsql'] = "SELECT sid,uid,date AS day,title,introtext,postmode"; $commonSql = " FROM {$_TABLES['stories']}, {$_TABLES['topic_assignments']} ta\n WHERE draft_flag = 0 AND date <= NOW() AND date >= '{$lastRun}'\n AND ta.type = 'article' AND ta.id = sid "; $topicSql = "SELECT tid FROM {$_TABLES['topics']}" . COM_getPermSQL('WHERE', $U['uuid']); $topicResult = DB_query($topicSql); $numTopics = DB_numRows($topicResult); if ($numTopics == 0) { // this user doesn't seem to have access to any topics ... continue; } $TIDS = array(); for ($i = 0; $i < $numTopics; $i++) { $T = DB_fetchArray($topicResult); $TIDS[] = $T['tid']; } if (!empty($U['etids'])) { $ETIDS = explode(' ', $U['etids']); $TIDS = array_intersect($TIDS, $ETIDS); } if (count($TIDS) > 0) { // We have list of Daily Digest topic ids that user has access too and that the user wants a report on $commonSql .= " AND (ta.tid IN ('" . implode("','", $TIDS) . "'))"; } $commonSql .= COM_getPermSQL('AND', $U['uuid']); $commonSql .= ' GROUP BY sid ORDER BY featured DESC, date DESC'; $storySql['mysql'] .= $commonSql; $storySql['pgsql'] .= $commonSql; $stories = DB_query($storySql); $numArticles = DB_numRows($stories); if ($numArticles == 0) { // If no new articles where pulled for this user, continue with next continue; } $mailText = $LANG08[29] . strftime($_CONF['shortdate'], time()) . "\n"; for ($y = 0; $y < $numArticles; $y++) { // Loop through stories building the requested email message $S = DB_fetchArray($stories); $mailText .= "\n------------------------------\n\n"; $mailText .= "{$LANG08['31']}: " . COM_undoSpecialChars(stripslashes($S['title'])) . "\n"; if ($_CONF['contributedbyline'] == 1) { if (empty($authors[$S['uid']])) { $articleAuthor = COM_getDisplayName($S['uid']); $authors[$S['uid']] = $articleAuthor; } else { $articleAuthor = $authors[$S['uid']]; } $mailText .= "{$LANG24['7']}: " . $articleAuthor . "\n"; } $mailText .= "{$LANG08['32']}: " . strftime($_CONF['date'], strtotime($S['day'])) . "\n\n"; if ($_CONF['emailstorieslength'] > 0) { if ($S['postmode'] === 'wikitext') { $articleText = COM_undoSpecialChars(strip_tags(COM_renderWikiText(stripslashes($S['introtext'])))); } else { $articleText = COM_undoSpecialChars(strip_tags(PLG_replaceTags(stripslashes($S['introtext'])))); } if ($_CONF['emailstorieslength'] > 1) { $articleText = COM_truncate($articleText, $_CONF['emailstorieslength'], '...'); } $articleText = preg_replace_callback('/<a\\s+.*?href="(.*?)".*?>/i', 'COM_emailUserTopicsUrlRewriter', $articleText); $articleText = preg_replace_callback('/<img\\s+.*?src="(.*?)".*?>/i', 'COM_emailUserTopicsUrlRewriter', $articleText); $mailText .= $articleText . "\n\n"; } $mailText .= $LANG08[33] . ' ' . COM_buildURL($_CONF['site_url'] . '/article.php?story=' . $S['sid']) . "\n"; } $mailText .= "\n------------------------------\n"; $mailText .= "\n{$LANG08['34']}\n"; $mailText .= "\n------------------------------\n"; $mailTo = array($U['email'] => $U['username']); if ($_CONF['site_mail'] !== $_CONF['noreply_mail']) { $mailFrom = $_CONF['noreply_mail']; $mailText .= LB . LB . $LANG04[159]; } else { $mailFrom = $_CONF['site_mail']; } COM_mail($mailTo, $subject, $mailText, $mailFrom); } DB_query("UPDATE {$_TABLES['vars']} SET value = NOW() WHERE name = 'lastemailedstories'"); }