function serveEntry($matches) { global $serendipity; $serendipity['view'] = 'entry'; $uri = $_SERVER['REQUEST_URI']; if (isset($serendipity['GET']['id'])) { $matches[1] = (int) $serendipity['GET']['id']; } elseif (isset($_GET['p'])) { $matches[1] = $_GET['p']; } else { $matches[1] = serendipity_searchPermalink($serendipity['permalinkStructure'], $uri, !empty($matches[2]) ? $matches[2] : $matches[1], 'entry'); } serendipity_rememberComment(); if (!empty($serendipity['POST']['submit']) && !isset($_REQUEST['serendipity']['csuccess'])) { $comment['url'] = $serendipity['POST']['url']; $comment['comment'] = trim($serendipity['POST']['comment']); $comment['name'] = $serendipity['POST']['name']; $comment['email'] = $serendipity['POST']['email']; $comment['subscribe'] = $serendipity['POST']['subscribe']; $comment['parent_id'] = $serendipity['POST']['replyTo']; if (!empty($comment['comment'])) { if (serendipity_saveComment($serendipity['POST']['entry_id'], $comment, 'NORMAL')) { $sc_url = ($_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . (strstr($_SERVER['REQUEST_URI'], '?') ? '&' : '?') . 'serendipity[csuccess]=' . (isset($serendipity['csuccess']) ? $serendipity['csuccess'] : 'true'); if (serendipity_isResponseClean($sc_url)) { header('Status: 302 Found'); header('Location: ' . $sc_url); } exit; } else { $serendipity['messagestack']['comments'][] = COMMENT_NOT_ADDED; } } else { $serendipity['messagestack']['comments'][] = sprintf(EMPTY_COMMENT, '', ''); } } $id = (int) $matches[1]; if ($id === 0) { $id = false; } $_GET['serendipity']['action'] = 'read'; $_GET['serendipity']['id'] = $id; $title = serendipity_db_query("SELECT title FROM {$serendipity['dbPrefix']}entries WHERE id={$id} AND isdraft = 'false' " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND timestamp <= " . serendipity_db_time() : ''), true); if (is_array($title)) { $serendipity['head_title'] = serendipity_specialchars($title[0]); $serendipity['head_subtitle'] = serendipity_specialchars($serendipity['blogTitle']); } else { $serendipity['view'] = '404'; $serendipity['viewtype'] = '404_1'; header('HTTP/1.0 404 Not found'); header('Status: 404 Not found'); } include S9Y_INCLUDE_PATH . 'include/genpage.inc.php'; }
/** * Store the comment made by a visitor in the database * * @access public * @param int The ID of an entry * @param array An array that holds the input data from the visitor * @param string The type of a comment (normal/trackback) * @param string Where did a comment come from? (internal|trackback|plugin) * @param string Additional plugin data (spamblock plugin etc.) * @return boolean Returns true if the comment could be added */ function serendipity_insertComment($id, $commentInfo, $type = 'NORMAL', $source = 'internal', $ca = array()) { global $serendipity; if (!empty($ca['status'])) { $commentInfo['status'] = $ca['status']; } $title = serendipity_db_escape_string(isset($commentInfo['title']) ? $commentInfo['title'] : ''); $comments = $commentInfo['comment']; $ip = serendipity_db_escape_string(isset($commentInfo['ip']) ? $commentInfo['ip'] : $_SERVER['REMOTE_ADDR']); $commentsFixed = serendipity_db_escape_string($commentInfo['comment']); $name = serendipity_db_escape_string($commentInfo['name']); $url = serendipity_db_escape_string($commentInfo['url']); $email = serendipity_db_escape_string($commentInfo['email']); $parentid = isset($commentInfo['parent_id']) && is_numeric($commentInfo['parent_id']) ? $commentInfo['parent_id'] : 0; $status = serendipity_db_escape_string(isset($commentInfo['status']) ? $commentInfo['status'] : (serendipity_db_bool($ca['moderate_comments']) ? 'pending' : 'approved')); $t = serendipity_db_escape_string(isset($commentInfo['time']) ? $commentInfo['time'] : time()); $referer = substr(isset($_SESSION['HTTP_REFERER']) ? serendipity_db_escape_string($_SESSION['HTTP_REFERER']) : '', 0, 200); $query = "SELECT a.email, e.title, a.mail_comments, a.mail_trackbacks\n FROM {$serendipity['dbPrefix']}entries AS e\n LEFT OUTER JOIN {$serendipity['dbPrefix']}authors AS a\n ON a.authorid = e.authorid\n WHERE e.id = '" . (int) $id . "'\n AND e.isdraft = 'false'"; if (!serendipity_db_bool($serendipity['showFutureEntries'])) { $query .= " AND e.timestamp <= " . serendipity_db_time(); } $row = serendipity_db_query($query, true); // Get info on author/entry if (!is_array($row) || empty($id)) { // No associated entry found. if ($GLOBALS['tb_logging']) { $fp = fopen('trackback2.log', 'a'); fwrite($fp, '[' . date('d.m.Y H:i') . '] entry reference not found: ' . $query . "\n"); fclose($fp); } return false; } $send_optin = false; if (isset($commentInfo['subscribe'])) { if (!isset($serendipity['allowSubscriptionsOptIn']) || $serendipity['allowSubscriptionsOptIn']) { $subscribe = 'false'; $send_optin = true; } else { $subscribe = 'true'; } } else { $subscribe = 'false'; } $dbhash = md5(uniqid(rand(), true)); if ($status == 'confirm') { $dbstatus = 'confirm' . $dbhash; } elseif ($status == 'confirm1') { $auth = serendipity_db_query("SELECT *\n FROM {$serendipity['dbPrefix']}options\n WHERE okey = 'mail_confirm'\n AND name = '" . $email . "'\n AND value = '" . $name . "'", true); if (!is_array($auth)) { serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}options (okey, name, value)\n VALUES ('mail_confirm{$dbhash}', '{$email}', '{$name}')"); $dbstatus = 'confirm' . $dbhash; } else { $serendipity['csuccess'] = 'true'; $status = $dbstatus = 'approved'; } } else { $dbstatus = $status; } $query = "INSERT INTO {$serendipity['dbPrefix']}comments (entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer)"; $query .= " VALUES ('" . (int) $id . "', '{$parentid}', '{$ip}', '{$name}', '{$email}', '{$url}', '{$commentsFixed}', '{$type}', '{$t}', '{$title}', '{$subscribe}', '{$dbstatus}', '{$referer}')"; if ($GLOBALS['tb_logging']) { $fp = fopen('trackback2.log', 'a'); fwrite($fp, '[' . date('d.m.Y H:i') . '] SQL: ' . $query . "\n"); } serendipity_db_query($query); $cid = serendipity_db_insert_id('comments', 'id'); // Send mail to the author if he chose to receive these mails, or if the comment is awaiting moderation if ($status != 'confirm' && (serendipity_db_bool($ca['moderate_comments']) || $type == 'NORMAL' && serendipity_db_bool($row['mail_comments']) || $type == 'TRACKBACK' && serendipity_db_bool($row['mail_trackbacks']))) { serendipity_sendComment($cid, $row['email'], $name, $email, $url, $id, $row['title'], $comments, $type, serendipity_db_bool($ca['moderate_comments'])); } // Approve with force, if moderation is disabled if ($GLOBALS['tb_logging']) { fwrite($fp, '[' . date('d.m.Y H:i') . '] status: ' . $status . ', moderate: ' . $ca['moderate_comments'] . "\n"); } if ($status != 'confirm' && (empty($ca['moderate_comments']) || serendipity_db_bool($ca['moderate_comments']) == false)) { if ($GLOBALS['tb_logging']) { fwrite($fp, '[' . date('d.m.Y H:i') . '] Approving...' . "\n"); } serendipity_approveComment($cid, $id, true); } elseif ($GLOBALS['tb_logging']) { fwrite($fp, '[' . date('d.m.Y H:i') . '] No need to approve...' . "\n"); } if ($status == 'confirm') { $subject = sprintf(NEW_COMMENT_TO_SUBSCRIBED_ENTRY, $row['title']); $message = sprintf(CONFIRMATION_MAIL_ALWAYS, $name, $row['title'], $commentsFixed, $serendipity['baseURL'] . 'comment.php?c=' . $cid . '&hash=' . $dbhash); serendipity_sendMail($email, $subject, $message, $serendipity['blogMail']); } elseif ($status == 'confirm1') { $subject = sprintf(NEW_COMMENT_TO_SUBSCRIBED_ENTRY, $row['title']); $message = sprintf(CONFIRMATION_MAIL_ONCE, $name, $row['title'], $commentsFixed, $serendipity['baseURL'] . 'comment.php?c=' . $cid . '&hash=' . $dbhash); serendipity_sendMail($email, $subject, $message, $serendipity['blogMail']); } if ($send_optin) { $dupe_check = serendipity_db_query("SELECT count(entry_id) AS counter\n FROM {$serendipity['dbPrefix']}comments\n WHERE entry_id = " . (int) $id . "\n AND email = '{$email}'\n AND subscribed = 'true'", true); if (!is_array($dupe_check) || $dupe_check['counter'] < 1) { serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}options (okey, name, value)\n VALUES ('commentsub_{$dbhash}', '" . time() . "', '{$cid}')"); $subject = sprintf(NEW_COMMENT_TO_SUBSCRIBED_ENTRY, $row['title']); $message = sprintf(CONFIRMATION_MAIL_SUBSCRIPTION, $name, $row['title'], serendipity_archiveURL($id, $row['title'], 'baseURL'), $serendipity['baseURL'] . 'comment.php?optin=' . $dbhash); serendipity_sendMail($email, $subject, $message, $serendipity['blogMail']); } } serendipity_purgeEntry($id, $t); if ($GLOBALS['tb_logging']) { fclose($fp); } return $cid; }
} else { $serendipity['messagestack']['comments'][] = COMMENT_NOT_ADDED; } } else { $serendipity['messagestack']['comments'][] = sprintf(EMPTY_COMMENT, '', ''); } } $id = (int) $matches[1]; if ($id === 0) { $id = false; } serendipity_track_referrer($id); $track_referer = false; $_GET['serendipity']['action'] = 'read'; $_GET['serendipity']['id'] = $id; $title = serendipity_db_query("SELECT title FROM {$serendipity['dbPrefix']}entries WHERE id={$id} AND isdraft = 'false' " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND timestamp <= " . serendipity_db_time() : ''), true); if (is_array($title)) { $serendipity['head_title'] = htmlspecialchars($title[0]); $serendipity['head_subtitle'] = htmlspecialchars($serendipity['blogTitle']); } else { $serendipity['view'] = '404'; $serendipity['viewtype'] = '404_1'; header('HTTP/1.0 404 Not found'); header('Status: 404 Not found'); } ob_start(); include S9Y_INCLUDE_PATH . 'include/genpage.inc.php'; $data = ob_get_contents(); ob_end_clean(); if (isset($serendipity['pregenerate']) && $serendipity['pregenerate']) { $fp = fopen($serendipity['serendipityPath'] . PATH_ARCHIVES . '/' . $id, 'w');
/** * Get total count for specific objects * * @access public * @param string The type of count to show: "entries", "trackbacks", "comments" * @return string The number */ function serendipity_getTotalCount($what) { global $serendipity; switch ($what) { case 'comments': $res = serendipity_db_query("SELECT SUM(e.comments) AS sum\n FROM {$serendipity['dbPrefix']}entries AS e\n WHERE e.isdraft = 'false'\n " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . serendipity_db_time() : ''), true, 'assoc'); return $res['sum']; case 'trackbacks': $res = serendipity_db_query("SELECT SUM(e.trackbacks) AS sum\n FROM {$serendipity['dbPrefix']}entries AS e\n WHERE e.isdraft = 'false'\n " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . serendipity_db_time() : ''), true, 'assoc'); return $res['sum']; case 'entries': $res = serendipity_db_query("SELECT COUNT(e.id) AS sum\n FROM {$serendipity['dbPrefix']}entries AS e\n WHERE e.isdraft = 'false'\n " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . serendipity_db_time() : ''), true, 'assoc'); return $res['sum']; } }
function generate_content(&$title) { global $serendipity; $title = $this->get_config('title'); $smarty = serendipity_db_bool($this->get_config('smarty', false)); $which_category = $this->get_config('authorid'); $sort = $this->get_config('sort_order'); if ($sort == 'none') { $sort = ''; } else { $sort .= ' ' . $this->get_config('sort_method'); } $is_form = serendipity_db_bool($this->get_config('allow_select')); if ($which_category === "login") { $which_category = (int) $serendipity['authorid']; if ($which_category === 0) { $which_category = -1; // Set to -1 for anonymous authors to get a proper match. } } $categories = serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category, '', $sort, 'read'); $cat_count = array(); if (serendipity_db_bool($this->get_config('show_count'))) { $cat_sql = "SELECT c.categoryid, c.category_name, count(e.id) as postings\n FROM {$serendipity['dbPrefix']}entrycat ec,\n {$serendipity['dbPrefix']}category c,\n {$serendipity['dbPrefix']}entries e\n WHERE ec.categoryid = c.categoryid\n AND ec.entryid = e.id\n AND e.isdraft = 'false'\n " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . serendipity_db_time() : '') . "\n GROUP BY c.categoryid, c.category_name\n ORDER BY postings DESC"; $category_rows = serendipity_db_query($cat_sql); if (is_array($category_rows)) { foreach ($category_rows as $cat) { $cat_count[$cat['categoryid']] = $cat['postings']; } } } $html = ''; if (!$smarty && $is_form) { $html .= '<form action="' . $serendipity['baseURL'] . $serendipity['indexFile'] . '?frontpage" method="post"> <div id="serendipity_category_form_content">'; } if (!$smarty) { $html .= '<ul id="serendipity_categories_list" style="list-style: none; margin: 0px; padding: 0px">'; } $image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif')); $image = $image == "'none'" || $image == 'none' ? '' : $image; $use_parent = $this->get_config('parent_base'); $hide_parent = serendipity_db_bool($this->get_config('hide_parent')); $parentdepth = 0; $hide_parallel = serendipity_db_bool($this->get_config('hide_parallel')); $hidedepth = 0; if (is_array($categories) && count($categories)) { $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED); foreach ($categories as $cid => $cat) { // Hide parents not wanted if ($use_parent && $use_parent != 'all') { if ($parentdepth == 0 && $cat['parentid'] != $use_parent && $cat['categoryid'] != $use_parent) { unset($categories[$cid]); continue; } else { if ($hide_parent && $cat['categoryid'] == $use_parent) { unset($categories[$cid]); continue; } if ($cat['depth'] < $parentdepth) { $parentdepth = 0; unset($categories[$cid]); continue; } if ($parentdepth == 0) { $parentdepth = $cat['depth']; } } } // Hide parents outside of our tree if ($hide_parallel && $serendipity['GET']['category']) { if ($hidedepth == 0 && $cat['parentid'] != $serendipity['GET']['category'] && $cat['categoryid'] != $serendipity['GET']['category']) { unset($categories[$cid]); continue; } else { if ($cat['depth'] < $hidedepth) { $hidedepth = 0; unset($categories[$cid]); continue; } if ($hidedepth == 0) { $hidedepth = $cat['depth']; } } } $categories[$cid]['feedCategoryURL'] = serendipity_feedCategoryURL($cat, 'serendipityHTTPPath'); $categories[$cid]['categoryURL'] = serendipity_categoryURL($cat, 'serendipityHTTPPath'); $categories[$cid]['paddingPx'] = $cat['depth'] * 6; $categories[$cid]['catdepth'] = $cat['depth']; if (!empty($cat_count[$cat['categoryid']])) { $categories[$cid]['true_category_name'] = $cat['category_name']; $categories[$cid]['category_name'] .= ' (' . $cat_count[$cat['categoryid']] . ')'; $categories[$cid]['article_count'] = $cat_count[$cat['categoryid']]; } if (!$smarty) { $html .= '<li class="category_depth' . $cat['depth'] . ' category_' . $cat['categoryid'] . '" style="display: block;">'; if ($is_form) { $html .= '<input style="width: 15px" type="checkbox" name="serendipity[multiCat][]" value="' . $cat['categoryid'] . '" />'; } if (!empty($image)) { $html .= '<a class="serendipity_xml_icon" href="' . $categories[$cid]['feedCategoryURL'] . '"><img src="' . $image . '" alt="XML" style="border: 0px" /></a> '; } $html .= '<a href="' . $categories[$cid]['categoryURL'] . '" title="' . htmlspecialchars($cat['category_description']) . '" style="padding-left: ' . $categories[$cid]['paddingPx'] . 'px">' . htmlspecialchars($categories[$cid]['category_name']) . '</a>'; $html .= '</li>' . "\n"; } } } if (!$smarty) { $html .= '</ul>'; } if (!$smarty && $is_form) { $html .= '<div class="category_submit"><br /><input type="submit" name="serendipity[isMultiCat]" value="' . GO . '" /></div>'; } if (!$smarty) { $html .= sprintf('<div class="category_link_all"><br /><a href="%s" title="%s">%s</a></div>', $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?frontpage', ALL_CATEGORIES, ALL_CATEGORIES); } if (!$smarty && $is_form) { $html .= '</div></form>'; } if (!$smarty) { echo $html; } else { $plugin_categories_data = array('is_form' => $is_form, 'category_image' => $image, 'form_url' => $serendipity['baseURL'] . $serendipity['indexFile'] . '?frontpage', 'categories' => is_array($categories) ? $categories : array()); $serendipity['smarty']->assign($plugin_categories_data); echo serendipity_smarty_fetch('CATEGORIES', 'plugin_categories.tpl'); } }
function generate_content(&$title) { global $serendipity; $title = $this->title; // Usage of serendipity_serverOffsetHour is as follow: // * Whenever a date to display needs to be set, apply the timezone offset // * Whenever we USE the date anywhere in the database, subtract the timezone offset // * Whenever we DISPLAY the date, we do not apply additional timezone addition to it. if (!isset($serendipity['GET']['calendarZoom'])) { if (!isset($serendipity['range'])) { $serendipity['GET']['calendarZoom'] = serendipity_serverOffsetHour(time()); } else { $serendipity['GET']['calendarZoom'] = serendipity_serverOffsetHour($serendipity['range'][0]); } } $month = date('m', serendipity_serverOffsetHour($serendipity['GET']['calendarZoom'], true)); $year = date('Y', serendipity_serverOffsetHour($serendipity['GET']['calendarZoom'], true)); $bow = (int) $this->get_config('beginningOfWeek', 1); // Check for faulty input, is so - run the default if ($bow > 6) { $bow = 1; } // Catch faulty month $month = (int) $month; if ($month < 1) { $month = 1; } switch ($serendipity['calendar']) { default: case 'gregorian': // How many days does the month have? $ts = strtotime($year . '-' . sprintf('%02d', $month) . '-01'); $now = serendipity_serverOffsetHour(time()); $nrOfDays = date('t', $ts); $firstDayWeekDay = date('w', $ts); $firstts = $ts; $endts = mktime(0, 0, 0, $month + 1, 1, $year); break; case 'persian-utf8': require_once S9Y_INCLUDE_PATH . 'include/functions_calendars.inc.php'; list(, $jy, $jm, $jd) = $serendipity['uriArguments']; if (isset($jd) && $jd) { list($gy, $gm, $gd) = p2g($jy, $jm, $jd); } elseif (isset($jm) && $jm) { list($gy, $gm, $gd) = p2g($jy, $jm, 1); } else { $gy = $year; $gm = $month; $gd = (int) date('d'); } list($year, $month, $day) = g2p($gy, $gm, $gd); // How many days does the month have? $ts = strtotime($gy . '-' . sprintf('%02d', $gm) . '-' . sprintf('%02d', $gd)); $now = serendipity_serverOffsetHour(time()); $nrOfDays = persian_strftime_utf('%m', $ts); $j_days_in_month = array(0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); if ($year % 4 == 3 && $nrOfDays == 12) { $nrOfDays = $j_days_in_month[(int) $nrOfDays] + 1; } else { $nrOfDays = $j_days_in_month[(int) $nrOfDays]; } // Calculate first timestamp of the month list($firstgy, $firstgm, $firstgd) = p2g($year, $month, 1); $firstts = mktime(0, 0, 0, $firstgm, $firstgd, $firstgy); // Calculate first persian day, week day name $firstDayWeekDay = date('w', $firstts); // Calculate end timestamp of the month list($end_year, $end_month, $end_day) = p2g($year, $month + 1, 1); $endts = mktime(0, 0, 0, $end_month, $end_day, $end_year); break; } // end switch // Calculate the first day of the week, based on the beginning of the week ($bow) if ($bow > $firstDayWeekDay) { $firstDayWeekDay = $firstDayWeekDay + 7 - $bow; } elseif ($bow < $firstDayWeekDay) { $firstDayWeekDay = $firstDayWeekDay - $bow; } else { $firstDayWeekDay = 0; } // Calculate the number of next/previous month if ($month > 1) { $previousMonth = $month - 1; $previousYear = $year; } else { $previousMonth = 12; $previousYear = $year - 1; } if ($month < 12) { $nextMonth = $month + 1; $nextYear = $year; } else { $nextMonth = 1; $nextYear = $year + 1; } // Get first and last entry $minmax = serendipity_db_query("SELECT MAX(timestamp) AS max, MIN(timestamp) AS min FROM {$serendipity['dbPrefix']}entries"); if (!is_array($minmax) || !is_array($minmax[0]) || $minmax[0]['min'] < 1 || $minmax[0]['max'] < 1) { // If no entry is available yet, allow scrolling a year back and forth $minmax = array('0' => array('min' => mktime(0, 0, 0, 1, 1, date('Y', $now) - 1), 'max' => mktime(0, 0, 0, 1, 1, date('Y', $now) + 1))); } // Find out about diary entries $add_query = ''; $base_query = ''; $cond = array(); $cond['and'] = "WHERE e.timestamp >= " . serendipity_serverOffsetHour($firstts, true) . "\n AND e.timestamp <= " . serendipity_serverOffsetHour($endts, true) . "\n " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . serendipity_db_time() : '') . "\n AND e.isdraft = 'false'"; serendipity_plugin_api::hook_event('frontend_fetchentries', $cond, array('noCache' => false, 'noSticky' => false, 'source' => 'calendar')); // Event Calendar $cat = $this->get_config('category', 'all'); if ($cat != 'all') { $catid = (int) $cat; } elseif (isset($serendipity['GET']['category'])) { $catid = (int) $serendipity['GET']['category']; } else { $catid = false; } if ($catid) { $base_query = 'C' . $catid; $add_query = '/' . $base_query; $querystring = "SELECT timestamp\n FROM {$serendipity['dbPrefix']}category c,\n {$serendipity['dbPrefix']}entrycat ec,\n {$serendipity['dbPrefix']}entries e\n {$cond['joins']}\n {$cond['and']}\n AND e.id = ec.entryid\n AND c.categoryid = ec.categoryid\n AND (" . serendipity_getMultiCategoriesSQL($catid) . ")"; } if (!isset($querystring)) { $querystring = "SELECT id, timestamp\n FROM {$serendipity['dbPrefix']}entries e\n {$cond['joins']}\n {$cond['and']}"; } $rows = serendipity_db_query($querystring); switch ($serendipity['calendar']) { default: case 'gregorian': $activeDays = array(); if (is_array($rows)) { foreach ($rows as $row) { $row['timestamp'] = serendipity_serverOffsetHour($row['timestamp']); $activeDays[date('j', $row['timestamp'])] = $row['timestamp']; } } $today_day = date('j', $now); $today_month = date('m', $now); $today_year = date('Y', $now); break; case 'persian-utf8': $activeDays = array(); if (is_array($rows)) { foreach ($rows as $row) { $row['timestamp'] = serendipity_serverOffsetHour($row['timestamp']); $activeDays[(int) persian_date_utf('j', $row['timestamp'])] = $row['timestamp']; } } $today_day = persian_date_utf('j', $now); $today_month = persian_date_utf('m', $now); $today_year = persian_date_utf('Y', $now); break; } // end switch $externalevents = array(); if (serendipity_db_bool($this->get_config('enableExtEvents', 'false'))) { serendipity_plugin_api::hook_event('frontend_calendar', $externalevents, array('Month' => $month, 'Year' => $year, 'TS' => $ts, 'EndTS' => $endts)); } // Print the calendar $currDay = 1; $nrOfRows = ceil(($nrOfDays + $firstDayWeekDay) / 7); for ($x = 0; $x < 6; $x++) { // Break out if we are out of days if ($currDay > $nrOfDays) { break; } // Prepare row for ($y = 0; $y < 7; $y++) { $cellProps = array(); $printDay = ''; $link = ''; if ($x == 0) { $cellProps['FirstRow'] = 1; } if ($y == 0) { $cellProps['FirstInRow'] = 1; } if ($y == 6) { $cellProps['LastInRow'] = 1; } if ($x == $nrOfRows - 1) { $cellProps['LastRow'] = 1; } // If it's not a blank day, we print the day if (($x > 0 || $y >= $firstDayWeekDay) && $currDay <= $nrOfDays) { $printDay = $currDay; if ($today_day == $currDay && $today_month == $month && $today_year == $year) { $cellProps['Today'] = 1; } if (isset($externalevents[$currDay])) { if (isset($externalevents[$currDay]['Class'])) { $cellProps[$externalevents[$currDay]['Class']] = 1; } if (isset($externalevents[$currDay]['Title'])) { $cellProps['Title'] = serendipity_specialchars($externalevents[$currDay]['Title']); } if (isset($externalevents[$currDay]['Extended'])) { foreach ($externalevents[$currDay]['Extended'] as $ext_key => $ext_val) { $cellProps[$ext_key] = $ext_val; } } } if (isset($activeDays[$currDay]) && $activeDays[$currDay] > 1) { $cellProps['Active'] = 1; $cellProps['Link'] = serendipity_archiveDateUrl(sprintf('%4d/%02d/%02d', $year, $month, $currDay) . $add_query); } $currDay++; } $smartyRows[$x]['days'][] = array('name' => $printDay, 'properties' => $cellProps, 'classes' => implode(' ', array_keys($cellProps))); } // end for } // end for $serendipity['smarty']->assignByRef('plugin_calendar_weeks', $smartyRows); $dow = array(); for ($i = 1; $i <= 7; $i++) { $dow[] = array('date' => mktime(0, 0, 0, 3, $bow + $i - 1, 2004)); } $serendipity['smarty']->assignByRef('plugin_calendar_dow', $dow); $plugin_calendar_data = array('month_date' => $ts, 'uri_previous' => serendipity_archiveDateUrl(sprintf('%04d/%02d', $previousYear, $previousMonth) . $add_query), 'uri_month' => serendipity_archiveDateUrl(sprintf('%04d/%02d', $year, $month) . $add_query), 'uri_next' => serendipity_archiveDateUrl(sprintf('%04d/%02d', $nextYear, $nextMonth) . $add_query), 'minScroll' => $minmax[0]['min'], 'maxScroll' => $minmax[0]['max']); $serendipity['smarty']->assignByRef('plugin_calendar_head', $plugin_calendar_data); echo serendipity_smarty_fetch('CALENDAR', 'plugin_calendar.tpl'); }
/** * Creates a DHTML menu of serendipity categories. * * The menu is echoed out. * * @param string $title (Serves as the top level menu item if present) * @return void * @see http://pear.php.net/HTML_TreeMenu PEAR::HTML_TreeMenu */ function generate_content(&$title) { global $serendipity; $title = $this->get_config('title', $this->title); // may want to put this in bundled_libs or a sub directory of this directory $pear = false; if (@(include_once 'HTML/TreeMenu.php')) { $pear = true; } elseif (@(include_once 'HTML_TreeMenu/TreeMenu.php')) { $pear = true; } if ($pear) { $which_category = $this->get_config('authorid'); // build an accessible array of categories foreach (serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category) as $cat) { if (!is_array($cat) || !isset($cat['categoryid'])) { continue; } $categories[$cat['categoryid']] = $cat; } // create an array of numbers of entries per category $cat_count = array(); if (serendipity_db_bool($this->get_config('show_count'))) { $cat_sql = "SELECT c.categoryid, c.category_name, count(e.id) as postings\n FROM {$serendipity['dbPrefix']}entrycat ec,\n {$serendipity['dbPrefix']}category c,\n {$serendipity['dbPrefix']}entries e\n WHERE ec.categoryid = c.categoryid\n AND ec.entryid = e.id\n AND e.isdraft = 'false'\n " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp <= " . serendipity_db_time() : '') . "\n GROUP BY c.categoryid, c.category_name\n ORDER BY postings DESC"; $category_rows = serendipity_db_query($cat_sql); if (is_array($category_rows)) { foreach ($category_rows as $cat) { $cat_count[$cat['categoryid']] = $cat['postings']; } } } $image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif')); $image = $image == "'none'" || $image == 'none' ? '' : $image; // create nodes foreach ($categories as $cid => $cat) { if (function_exists('serendipity_categoryURL')) { $link = serendipity_categoryURL($cat, 'serendipityHTTPPath'); } else { $link = serendipity_rewriteURL(PATH_CATEGORIES . '/' . serendipity_makePermalink(PERM_CATEGORIES, array('id' => $cat['categoryid'], 'title' => $cat['category_name'])), 'serendipityHTTPPath'); } if (!empty($cat_count[$cat['categoryid']])) { // $categories[$cid]['true_category_name'] = $cat['category_name']; $cat['category_name'] .= ' (' . $cat_count[$cat['categoryid']] . ')'; // $categories[$cid]['article_count'] = $cat_count[$cat['categoryid']]; } if (!empty($image)) { $feedURL = serendipity_feedCategoryURL($cat, 'serendipityHTTPPath'); $feed = '<a class="serendipity_xml_icon" href="' . $feedURL . '"><img src="' . $image . '" alt="XML" style="border: 0px;vertical-align:middle"/></a> '; $link = '<a href="' . $link . '" target="_self"><span>' . $cat['category_name'] . '</span></a>'; // work around a problem in HTML_TreeNode: when there is a href in 'text', 'link' is not converted to a link. $cat_nodes[$cat['categoryid']] = new HTML_TreeNode(array('text' => $feed . $link)); } else { $cat_nodes[$cat['categoryid']] = new HTML_TreeNode(array('text' => $feed . $cat['category_name'], 'link' => $link)); } } // create a top level for "all categories" // this serves as the title $cat_nodes[0] = new HTML_TreeNode(array('text' => ALL_CATEGORIES, 'link' => $serendipity['baseURL'])); // nest nodes (thanks to PHP references) foreach ($categories as $category) { $cat_nodes[$category['parentid']]->addItem($cat_nodes[$category['categoryid']]); } // nest the "all categories" category $menu = new HTML_TreeMenu(); $menu->addItem($cat_nodes[0]); $tree = new HTML_TreeMenu_DHTML($menu, array('images' => $serendipity['baseURL'] . $this->get_config('image_path'))); // Add heading for block #$output = '<h2 class="serendipitySideBarTitle" style="font-weight: bold;">'.$title.'</h2><br />'; // Put inside a div with "overflow:hidden" to avoid items of the sidebar plugin running outside the blog // Maybe we can put a config setting to choose if the block should be displayed with or without overflow setting. $output .= '<div style="overflow: hidden;">'; $output .= $tree->toHTML(); $output .= '</div>'; echo '<script type="text/javascript" src="' . $serendipity['baseURL'] . $this->get_config('script_path') . '"></script>'; } else { $output .= "Please install PEAR package HTML_TreeMenu to enable this plugin."; } echo $output; }
function workComment($id, $commentInfo, $type = 'NORMAL', $source = 'internal') { global $serendipity; $query = "SELECT id, allow_comments, moderate_comments, last_modified, timestamp, title FROM {$serendipity['dbPrefix']}entries WHERE id = '" . (int) $id . "'"; $ca = serendipity_db_query($query, true); $commentInfo['type'] = $type; $commentInfo['source'] = $source; // serendipity_plugin_api::hook_event('frontend_saveComment', $ca, $commentInfo); if (!is_array($ca) || serendipity_db_bool($ca['allow_comments'])) { $title = serendipity_db_escape_string(isset($commentInfo['title']) ? $commentInfo['title'] : ''); $comments = $commentInfo['comment']; $ip = serendipity_db_escape_string(isset($commentInfo['ip']) ? $commentInfo['ip'] : $_SERVER['REMOTE_ADDR']); $commentsFixed = serendipity_db_escape_string($commentInfo['comment']); $name = serendipity_db_escape_string($commentInfo['name']); $url = serendipity_db_escape_string($commentInfo['url']); $email = serendipity_db_escape_string($commentInfo['email']); $parentid = isset($commentInfo['parent_id']) && is_numeric($commentInfo['parent_id']) ? $commentInfo['parent_id'] : 0; $status = serendipity_db_escape_string(isset($commentInfo['status']) ? $commentInfo['status'] : (serendipity_db_bool($ca['moderate_comments']) ? 'pending' : 'approved')); $t = serendipity_db_escape_string(isset($commentInfo['time']) ? $commentInfo['time'] : time()); $referer = substr(isset($_SESSION['HTTP_REFERER']) ? serendipity_db_escape_string($_SESSION['HTTP_REFERER']) : '', 0, 200); $query = "SELECT a.email, e.title, a.mail_comments, a.mail_trackbacks\n FROM {$serendipity['dbPrefix']}entries e, {$serendipity['dbPrefix']}authors a\n WHERE e.id = '" . (int) $id . "'\n AND e.isdraft = 'false'\n AND e.authorid = a.authorid"; if (!serendipity_db_bool($serendipity['showFutureEntries'])) { $query .= " AND e.timestamp <= " . serendipity_db_time(); } $row = serendipity_db_query($query, true); // Get info on author/entry if (!is_array($row) || empty($id)) { // No associated entry found. return false; } if (isset($commentInfo['subscribe'])) { $subscribe = 'true'; } else { $subscribe = 'false'; } $query = "INSERT INTO {$serendipity['dbPrefix']}comments (entry_id, parent_id, ip, author, email, url, body, type, timestamp, title, subscribed, status, referer)"; $query .= " VALUES ('" . (int) $id . "', '{$parentid}', '{$ip}', '{$name}', '{$email}', '{$url}', '{$commentsFixed}', '{$type}', '{$t}', '{$title}', '{$subscribe}', '{$status}', '{$referer}')"; serendipity_db_query($query); $cid = serendipity_db_insert_id('comments', 'id'); // Send mail to the author if he chose to receive these mails, or if the comment is awaiting moderation if (serendipity_db_bool($ca['moderate_comments']) || $type == 'NORMAL' && serendipity_db_bool($row['mail_comments']) || $type == 'TRACKBACK' && serendipity_db_bool($row['mail_trackbacks'])) { serendipity_sendComment($cid, $row['email'], $name, $email, $url, $id, $row['title'], $comments, $type, serendipity_db_bool($ca['moderate_comments'])); } serendipity_approveComment($cid, $id, true); serendipity_purgeEntry($id, $t); return $cid; } else { return false; } }
/** * Wikifies: * [[ENTRY|DESC]] is an internal link * ((ENTRY|DESC)) is a staticpage link. */ function _wikify($buffer) { global $serendipity; $debug = true; $admin_url = false; $cidx = 2; if ($buffer[1] == '((') { $type = $otype = 'staticpage'; } elseif ($buffer[1] == '{{') { $type = $otype = 'mixed'; } else { $type = $otype = 'internal'; } $parts = explode('|', $buffer[$cidx]); if (isset($parts[1])) { $desc = $parts[1]; $ltitle = $parts[0]; } else { $desc = $ltitle = $buffer[$cidx]; } // ltitle might contain entities, convert them: $ltitle = @html_entity_decode($ltitle, ENT_COMPAT, LANG_CHARSET); $sql = ''; if ($type == 'staticpage') { $entry = serendipity_db_query("SELECT id, permalink FROM {$serendipity['dbPrefix']}staticpages WHERE headline = '" . serendipity_db_escape_string($ltitle) . "'" . " ORDER BY timestamp DESC LIMIT 1", true, 'assoc'); } elseif ($type == 'mixed') { $entry = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}entries WHERE title = '" . serendipity_db_escape_string($ltitle) . "'" . " ORDER BY timestamp DESC LIMIT 1", true, 'assoc'); $type = 'internal'; if (!is_array($entry)) { $entry = serendipity_db_query("SELECT id, permalink FROM {$serendipity['dbPrefix']}staticpages WHERE headline = '" . serendipity_db_escape_string($ltitle) . "'" . " ORDER BY timestamp DESC LIMIT 1", true, 'assoc'); $type = 'staticpage'; } } else { $entry = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}entries WHERE title = '" . serendipity_db_escape_string($ltitle) . "'" . " ORDER BY timestamp DESC LIMIT 1", true, 'assoc'); } if (is_array($entry)) { // The entry exists. // check, wether we don't want draft or future links: //if (serendipity_db_bool($this->get_config('generate_draft_links', false)) || !$entry['isdraft']){ if (serendipity_db_bool($this->get_config('generate_future_links', false)) || $entry['timestamp'] <= serendipity_db_time()) { if ($type == 'staticpage') { $entry_url = $entry['permalink']; } else { $entry_url = serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp'])); } } if (serendipity_userLoggedIn()) { $mode = 'edit'; if ($type == 'staticpage') { $admin_url = $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[adminModule]=event_display&serendipity[adminAction]=staticpages&serendipity[staticid]=' . $entry['id']; $admin_title = PLUGIN_EVENT_WIKILINKS_EDIT_STATICPAGE; } else { $admin_url = $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[action]=admin&serendipity[adminModule]=entries&serendipity[adminAction]=edit&serendipity[id]=' . $entry['id']; $admin_title = PLUGIN_EVENT_WIKILINKS_EDIT_INTERNAL; } } } else { // The entry does not yet exist. $entry_url = ''; if (serendipity_userLoggedIn()) { $mode = 'create'; $title = urlencode($ltitle); $body = '<h1>' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($ltitle) : htmlspecialchars($ltitle, ENT_COMPAT, LANG_CHARSET)) . '</h1>'; $admin_url2 = $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[adminModule]=event_display&serendipity[adminAction]=staticpages&serendipity[pre][headline]=' . $title . '&serendipity[pre][content]=' . $body . '&serendipity[pre][pagetitle]=' . $title; if ($otype == 'staticpage') { $admin_url = $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[adminModule]=event_display&serendipity[adminAction]=staticpages&serendipity[staticpagecategory]=pages&serendipity[pre][headline]=' . $title . '&serendipity[pre][content]=' . $body . '&serendipity[pre][pagetitle]=' . $title; $admin_title = PLUGIN_EVENT_WIKILINKS_CREATE_STATICPAGE; } elseif ($otype == 'mixed') { $admin_url = $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[adminModule]=entries&serendipity[adminAction]=new&serendipity[title]=' . $title . '&serendipity[body]=' . $body; $admin_title = PLUGIN_EVENT_WIKILINKS_CREATE_INTERNAL; } else { $admin_url = $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[adminModule]=entries&serendipity[adminAction]=new&serendipity[title]=' . $title . '&serendipity[body]=' . $body; $admin_title = PLUGIN_EVENT_WIKILINKS_CREATE_INTERNAL; } } else { $ltitle .= '?'; } } $out = '<span class="serendipity_wikilink_' . $type . '">'; if ($entry_url) { $out .= '<a class="serendipity_wikilink_visitor" href="' . $entry_url . '">'; } $out .= $desc; if ($entry_url) { $out .= '</a>'; } if ($admin_url) { if ($otype == 'mixed') { $imgurl = $this->get_config('imgpath') . $mode . '_internal.png'; $img1 = '<img style="border: 0px" alt="?" src="' . $imgurl . '" width="16" height="16" />'; $out .= '<a title="' . $admin_title . '" class="serendipity_wikilink_editor_internal" href="' . $admin_url . '">' . $img1 . '</a>'; if ($admin_url2) { $imgurl = $this->get_config('imgpath') . $mode . '_staticpage.png'; $img2 = '<img style="border: 0px" alt="?" src="' . $imgurl . '" width="16" height="16" />'; $out .= '<a title="' . PLUGIN_EVENT_WIKILINKS_CREATE_STATICPAGE . '" class="serendipity_wikilink_editor_staticpage" href="' . $admin_url2 . '">' . $img2 . '</a>'; } } else { $imgurl = $this->get_config('imgpath') . $mode . '_' . $type . '.png'; $img = '<img style="border: 0px" alt="?" src="' . $imgurl . '" width="16" height="16" />'; $out .= '<a title="' . $admin_title . '" class="serendipity_wikilink_editor_' . $type . '" href="' . $admin_url . '">' . $img . '</a>'; } } $out .= '</span>'; return $out; }