/** * get a form * * @return array */ function Meetings_formsGet() { if (!isset($_SESSION['userdata'])) { return false; } return dbAll('select * from forms_nonpage'); }
/** * show ads * * @param array $params parameters * * @return ads HTML */ function Ads_widget($params) { if (!isset($params->{'ad-type'})) { return 'missing ad type'; } $type_id = (int) $params->{'ad-type'}; $howmany = (int) $params->{'how-many'}; $type = dbRow('select * from ads_types where id=' . $type_id); $ads = array(); $i = 0; if ($howmany > 1) { $sql = 'select id,image_url,target_type,poster from ads' . ' where type_id=' . $type_id . ' and is_active and cdate>date_add(now(), interval -2 day) order by rand()' . ' limit ' . $howmany; $adsNew = dbAll($sql); for (; $i < count($adsNew); ++$i) { $ads[] = $adsNew[$i]; } } $adsOld = dbAll('select id,image_url,target_type,poster from ads' . ' where type_id=' . $type_id . ' and is_active order by rand()' . ' limit ' . $howmany); for ($j = 0; $j < $howmany - $i && $j < count($adsOld); ++$j) { $ads[] = $adsOld[$j]; } $html = '<div class="ads-wrapper type-' . $type_id . '">'; foreach ($ads as $ad) { $html .= Ads_adShow($ad, $type); dbQuery('insert into ads_track set ad_id=' . $ad['id'] . ', view=1, cdate=now()'); } $html .= '</div>'; WW_addScript('ads/j/js.js'); WW_addCSS('/ww.plugins/ads/css.css'); return $html; }
function send_email($subject, $body, $type, $reply_to) { if ($subject == '' || $body == '') { return false; } $options = dbAll('select name,value from mailing_list_options'); foreach ($options as $option) { $OPT[$option['name']] = $option['value']; } $list = dbAll('select * from mailing_list where status="activated"'); $emails = ''; $num = ''; foreach ($list as $email) { $emails .= $email['email'] . ','; $num++; } $headers = 'From: ' . $OPT['email'] . "\r\n"; if ($repyl_to != '') { $headers .= 'Reply-To:' . $reply_to . "\r\n"; } if ($type == 'HTML') { $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; } else { $headers .= 'Content-Type: text/plain; charset=iso-8859-1' . "\r\n"; } if ($OPT['use_bcc'] == 1) { $headers .= 'Bcc: ' . $emails . "\r\n"; } else { $to = $emails; } $headers .= 'X-Mailer: PHP ' . phpversion(); $headers .= 'MIME-Version: 1.0' . "\n"; mail($to, $subject, $body, $headers); return $num; }
/** * blah * * @param int $id id of the banner * * @return null */ function BannerImage_drawForm($id = 0) { if (!$id) { $fdata = array('id' => 0, 'html' => '', 'name' => 'banner'); } else { $fdata = dbRow("select * from banners_images where id={$id}"); } echo '<form method="post" action="/ww.admin/plugin.php?_plugin=banner-ima' . 'ge&_page=index" enctype="multipart/form-data"><input type="hidden' . '" name="id" value="' . (int) $fdata['id'] . '" />'; echo '<table>'; // { echo '<tr><th>Name</th><td><input name="name" value="' . htmlspecialchars($fdata['name']) . '" /></td></tr>'; // } // { what pages should this be applied to echo '<tr><th>Pages</th><td>This banner will only be shown on the <select' . ' name="pages_' . $fdata['id'] . '[]" multiple="multiple" style="max-width' . ':200px;height:500px">'; $ps = dbAll('select * from banners_pages where bannerid=' . $fdata['id']); $pages = array(); if (count($ps)) { foreach ($ps as $p) { $pages[] = $p['pageid']; } } BannerImage_selectKiddies(0, 1, $pages); echo '</select> pages. <span style="color:red;font-weight:bold">If no pag' . 'es are specified, then the banner will be shown on all pages.</span><' . '/td></tr>'; // } // { show HTML form echo '<tr><th>Banner</th><td><div id="banner_image_html">' . ckeditor('html_' . $fdata['id'], Core_unfixImageResizes($fdata['html']), 0, '', 180) . '</div></td></tr>'; // } // { show submit button and end form echo '<tr><td><a href="./plugin.php?_plugin=banner-image&_page=index&dele' . 'te_banner=' . $fdata['id'] . '" onclick="return confirm(\'are you sure yo' . 'u want to remove this banner?\');" title="remove banner">[x]</a></td>' . '<td><input type="submit" name="save_banner" value="Update" /></td></tr>'; // } echo '</table></form>'; }
/** * get all ad types * * @return list of ad types */ function Ads_typesGet() { $sql = 'select * from ads_types'; if (isset($_REQUEST['not_for_sale'])) { $sql .= ' where not_for_sale=' . (int) $_REQUEST['not_for_sale']; } return dbAll($sql . ' order by name'); }
/** * retrieve a list of comments for the page * * @param object $page Page object * @param string $dir sort ascending or descending by date * @param int $num how many comments to get - 0=all * @param array $also array of comment ids to show whether valid or not * * @return array list of comments **/ function Comments_getListOfComments($page, $dir = '', $num = 0, $also = array()) { $query = 'select * from comments where objectid=' . $page->id . ' and (isvalid=1'; if (count($also)) { $query .= ' or id in (' . join(',', $also) . ')'; } $limit = $num ? ' limit 0,' . $num : ''; return dbAll($query . ') order by cdate ' . $dir . $limit); }
/** * DynamicSearch_catags * * @param array $catags categories * @param string $s search string * @param string $cat category to search * @param int $limit how many results to return * * @return array */ function DynamicSearch_catags($catags, $s, $cat, $limit) { if (!in_array($cat, $catags)) { die('Category does not exist.'); } $id = dbOne('select id from pages where name="' . $cat . '"', 'id'); $gd = getDescendants($id); $q = dbAll('select * from pages where (id=' . $id . ' ' . $gd . ') and (body like "%' . $s . '%" or name like "%' . $s . '%") order by edate limit ' . $limit); return $q; }
function show_banner($vars) { $banner = false; if (!is_array($vars) && @$vars->id) { $b = Core_cacheLoad('banner-images', 'id' . $vars->id); if ($b === false) { $b = dbRow('select * from banners_images where id=' . $vars->id); if ($b && count($b) && !$b['html']) { $b['html'] = BannerImage_getImgHtml($vars->id); dbQuery('update banners_pages set html="' . addslashes($b['html']) . '" where id=' . $vars->id); } Core_cacheSave('banner-images', 'id' . $vars->id, $b); } } elseif ($GLOBALS['PAGEDATA']->id) { $b = Core_cacheLoad('banner-images', 'bypage' . $GLOBALS['PAGEDATA']->id); if ($b === false) { $b = dbAll('select * from banners_pages,banners_images where pageid=' . $GLOBALS['PAGEDATA']->id . ' and bannerid=id'); Core_cacheSave('banner-images', 'bypage' . $GLOBALS['PAGEDATA']->id, $b); } $i = rand(0, count($b) - 1); $b = isset($b[$i]) ? $b[$i] : false; if ($b && count($b) && !$b['html']) { $b['html'] = BannerImage_getImgHtml($b['id']); dbQuery('update banners_pages set html="' . addslashes($b['html']) . '" where id=' . $b['id']); } } if (!isset($b) || $b === false || !count($b)) { $b = Core_cacheLoad('banner-image', 'all'); if ($b === false) { $b = dbAll('select * from banners_images'); Core_cacheSave('banner-image', 'all', $b); } $i = rand(0, count($b) - 1); $b = isset($b[$i]) ? $b[$i] : false; } if ($b && count($b)) { $banner = $b['html']; if (!$banner) { $banner = BannerImage_getImgHtml($vars->id); } } if (!$banner) { if (is_array($vars) && @$vars['default']) { $banner = $vars['default']; } else { $banner = ''; } } if (!$banner) { return ''; } return '<style type="text/css">#banner{background:none}</style>' . $banner; }
/** * retrieve list of search results * * @return string HTML list of search results */ function Search_showResults() { global $PLUGINS; // { variables global $PAGEDATA; $start = (int) @$_REQUEST['start']; $search = @$_REQUEST['search']; if (!$search) { return '<em id="searchResultsTitle">no search text entered</em>'; } $c = ''; // } // { pages $q = dbAll('select * from pages where (name like "%' . $search . '%" or body like "%' . $search . '%") order by edate desc limit ' . $start . ',20'); $n = count($q); if ($n > 0) { foreach ($q as $p) { Page::getInstance($p['id'], $p); } $q = array_slice($q, $start, 20); $c .= '<h2>Page Search Results</h2><em id="searchResultsTitle">'; if ($n == 1) { $c .= '1 result found'; } else { $c .= $n . ' results found'; } $c .= '</em> <div>'; if ($start > 0) { $c .= '[<a href="' . $PAGEDATA->getRelativeURL() . '?search=' . urlencode($search) . '&start=' . ($start - 20) . '">previous 20</a>] '; } if ($start + 20 < $n) { $c .= '[<a href="' . $PAGEDATA->getRelativeURL() . '?search=' . urlencode($search) . '&start=' . ($start + 20) . '">next 20</a>] '; } $c .= '<ol start="' . ($start + 1) . '" id="searchResults">'; foreach ($q as $r) { $title = $r['title'] == '' ? $r['name'] : $r['title']; $c .= '<li><h4>' . htmlspecialchars($title) . '</h4>' . '<p>' . substr(preg_replace('/<[^>]*>/', '', $r['body']), 0, 200) . '...<br /><a href="/' . urlencode($r['name']) . '?search=' . $search . '">/' . htmlspecialchars($r['name']) . '</a></p></li>'; } $c .= '</ol></div>'; } // } // { others foreach ($PLUGINS as $plugin) { if (@$plugin['search']) { $c .= $plugin['search'](); } } // } if (!$c) { return '<em id="searchResultsTitle">' . __('no results found', 'core') . '</em>'; } return $c; }
static function getByIds($ids = array()) { $ids = addslashes(join(',', $ids)); if (array_key_exists($ids, self::$instancesByIds)) { return self::$instancesByIds[$ids]; } self::$instancesByFilter[$ids] = array(); $rs = dbAll("select * from poll where id in ({$ids})"); foreach ($rs as $r) { self::$instancesByIds[$ids][] = Poll::getInstance($r['id'], $r); } return self::$instancesByIds[$ids]; }
function getGroups() { if (isset($this->groups)) { return $this->groups; } $byid = array(); $gs = dbAll('select groups_id from users_groups ' . 'where user_accounts_id=' . $this->id); foreach ($gs as $g) { $byid[] = $g['groups_id']; } $this->groups = $byid; return $this->groups; }
/** * get list of pages that have a common parent * * @param string $constraint the SQL constraint to use * @param boolean $filter whether to only show "published" pages * * @return object the Pages object */ function __construct($constraint, $filter = true) { global $isadmin; $filter = $isadmin || !$filter ? '' : ' && !(special&2)'; $rs = dbAll("select * from pages where {$constraint} {$filter} " . "order by special&2,ord,name"); if (!count($rs)) { $rs = array(); } foreach ($rs as $r) { $this->pages[] = Page::getInstance($r['id'], $r); } Pages::$instancesByParent[$constraint] =& $this; }
/** * check if a voucher is valid * * @param string $code the voucher to check * @param string $email the user's email address * * @return boolean */ function OnlineStore_voucherCheckValidity($code, $email) { if (isset($GLOBALS['OnlineStore_voucherInstance'])) { return $GLOBALS['OnlineStore_voucherInstance']; } $rs = dbAll('select * from online_store_vouchers where code="' . addslashes($code) . '"' . ' and start_date<now() and end_date>now()'); $valid = false; $error = __('invalid voucher code, or voucher has expired'); foreach ($rs as $voucher) { if ($voucher['user_constraints'] == 'userlist') { $voucher['users_list'] = json_decode($voucher['users_list'], true); // { if you're not on the guest-list, you're not coming in! if (!in_array($_SESSION['userdata']['id'], $voucher['users_list']['users']) && !in_array($email, $voucher['users_list']['emails'])) { $error = __('your email address is not associated with this voucher'); continue; } // } // { has the quota of voucher copies been used up? if ($voucher['usages_in_total'] && isset($voucher['users_list']['total_uses']) && $voucher['users_list']['total_uses'] >= $voucher['usages_in_total']) { $error = __('this voucher has been used up'); continue; } // } if ($voucher['usages_per_user']) { // { has this email address's quota been used up? $usesbyemail = (int) @$voucher['users_list']['uses_by_email'][$email]; if ($usesbyemail >= $voucher['usages_per_user']) { $error = __('you have used your quota of this voucher'); continue; } // } // { has the user account's quota been used up? $uid = (int) @$_SESSION['userdata']['id']; $usesbyuser = (int) @$voucher['users_list']['uses_by_user'][$uid]; if ($uid && $usesbyuser >= $voucher['usages_per_user']) { continue; } // } } } $valid = $voucher; break; } if (!$valid) { return array('error' => $error); } $GLOBALS['OnlineStore_voucherInstance'] = $valid; return $valid; }
/** * widget for blog stuff * * @param array $vars variables * * @return html */ function Blog_widget2($vars = null) { $c = ''; global $PAGEDATA; $entry_ids = array(); if ($vars->tag) { $rs = dbAll('select entry_id from blog_tags where tag="' . addslashes($vars->tag) . '"'); foreach ($rs as $r) { $entry_ids[] = $r['entry_id']; } } $blog_author = ''; $excerpts_offset = isset($vars->excerpts_offset) && $vars->excerpts_offset ? $vars->excerpts : 0; $excerpts_per_page = isset($vars->excerpts) && $vars->excerpts ? $vars->excerpts : 2; $links_prefix = $PAGEDATA->getRelativeURL(); if ($PAGEDATA->type != 'blog|blog') { $page = PAGE::getInstanceByType('blog'); $links_prefix = $page->getRelativeURL(); } /** @noinspection PhpUnusedLocalVariableInspection */ $excerpt_length = 100; /** @noinspection PhpUnusedLocalVariableInspection */ $nobottomlinks = true; if (!isset($vars->widgetType)) { $vars->widgetType = '0'; } switch ($vars->widgetType) { case '1': // { featured posts require dirname(__FILE__) . '/featured-posts.php'; break; // } // } default: // { if (isset($vars->imageSizeX) && $vars->imageSizeX) { /** @noinspection PhpUnusedLocalVariableInspection */ $excerptImageSizeX = (int) $vars->imageSizeX; } if (isset($vars->imageSizeY) && $vars->imageSizeY) { /** @noinspection PhpUnusedLocalVariableInspection */ $excerptImageSizeY = (int) $vars->imageSizeY; } require dirname(__FILE__) . '/excerpts.php'; break; //} } return $c; }
function showCategoriesRecursive($pid, $level, $sid) { $opts = array(); $cs = dbAll('select id,name from products_categories where parent_id=' . $pid . ' order by name', false, 'products_categories'); foreach ($cs as $c) { $opt = '<option value="' . $c['id'] . '"'; if ($c['id'] == $sid) { $opt .= ' selected="selected"'; } $opt .= '>' . str_repeat('» ', $level) . htmlspecialchars(__FromJson($c['name'])) . '</option>'; $opts[] = $opt; $opts[] = showCategoriesRecursive($c['id'], $level + 1, $sid); } return join('', $opts); }
function selectkiddies($i = 0, $n = 1, $id = 0) { $arr = array(); $q = dbAll('select name,id,alias from pages where parent="' . $i . '" and id!="' . $id . '" order by ord,name'); if (count($q) < 1) { return $arr; } foreach ($q as $r) { if ($r['id'] != '') { $arr[$r['id']] = str_repeat('» ', $n) . $r['name']; $arr = array_merge($arr, selectkiddies($r['id'], $n + 1, $id)); } } return $arr; }
/** * retrieve HTML summary for a set page * * @param int $id ID of the page * * @return string HTML summary for a set page */ function PageSummaries_getHtml($id) { $PAGEDATA = Page::getInstance($id); global $sitedomain; $r = dbRow('select * from page_summaries where page_id="' . $PAGEDATA->id . '"'); if (!count($r)) { return '<em>This page is marked as a page summary, but there is no ' . 'information on how to handle it.</em>'; } if ($r['rss']) { return PageSummaries_rssToHtml($r['rss']); } // { build rss $title = $PAGEDATA->title == '' ? $sitedomain : htmlspecialchars($PAGEDATA->title); $rss = '<' . '?xml version="1.0" ?' . '><rss version="2.0"><channel><title>' . $title . '</title>'; $rss .= '<link>' . $_SERVER['REQUEST_URI'] . '</link><description>RSS for ' . $PAGEDATA->name . '</description>'; $category = $PAGEDATA->category ? ' and category="' . $PAGEDATA->category . '"' : ''; $containedpages = PageSummaries_getContainedPages($r['parent_id']); if (count($containedpages)) { $q2 = dbAll('select edate,name,title,body from pages where id in (' . join(',', $containedpages) . ')' . $category . ' order by cdate desc limit 20'); foreach ($q2 as $r2) { $rss .= '<item>'; if (!$r2['title']) { $r2['title'] = $r2['name']; } $rss .= '<title>' . htmlspecialchars($r2['title']) . '</title>'; $rss .= '<pubDate>' . date_m2h($r2['edate']) . '</pubDate>'; // { build body if ($r['amount_to_show'] == 0 || $r['amount_to_show'] == 1) { $length = $r['amount_to_show'] == 0 ? 300 : 600; $body = str_replace(' ', ' ', preg_replace('/<[^>]*>/', ' ', str_replace(array('&', ' ', '‘'), array('&', ' ', '''), $r2['body']))); $body = substr($body, 0, $length) . '...'; } else { $body = $r2['body']; } $body = str_replace('€', '€', $body); // } $rss .= '<description>' . $body . '</description>'; $rss .= '<link>http://' . $_SERVER['HTTP_HOST'] . '/' . urlencode(str_replace(' ', '-', $r2['name'])) . '</link>'; $rss .= '</item>'; } } $rss .= '</channel></rss>'; dbQuery('update page_summaries set rss="' . addslashes($rss) . '" where page_id="' . $PAGEDATA->id . '"'); // } return PageSummaries_rssToHtml($rss); }
/** * This is the main function. * It figures out if a list of quizzes, questions * or results should be displayed and displays the correct thing * * @see displayQuizInfo * @see [QuizSession::]getScore() * * @return string $displayString The correct page HTML */ function getPageHtml() { // { datatables WW_addScript('http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/' . 'jquery.dataTables.min.js'); WW_addScript('/j/datatables-delay.js'); WW_addCSS('http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/' . 'jquery.dataTables.css'); WW_addCSS('http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/' . 'jquery.dataTables_themeroller.css'); // } // { The Script $displayString = '<script defer="defer">' . '$(function(){' . '$(\'#quizzesFrontend\').dataTable().fnSetFilteringDelay();' . '});' . '</script>'; // } $quizzes = dbAll("SELECT DISTINCT \n\t\t\tquiz_quizzes.id, \n\t\t\tname, \n\t\t\tquiz_quizzes.description \n\t\t\tFROM quiz_quizzes, quiz_questions \n\t\t\tWHERE quiz_quizzes.id=quiz_questions.quiz_id \n\t\t\tand quiz_quizzes.enabled=1"); $displayString = $displayString . '<form method="post">'; $displayString = $displayString . '<table id="quizzesFrontend" style="{width:100% postion:top}">'; $displayString = $displayString . '<thead><tr>'; $displayString = $displayString . '<th>Name</th>'; $displayString = $displayString . '<th>Description</th>'; $displayString = $displayString . '<th> </th>'; $displayString = $displayString . '</tr></thead>'; $displayString = $displayString . '<tbody>'; foreach ($quizzes as $quiz) { $quizId = $quiz['id']; $name = $quiz['name']; $topic = $quiz['description']; $id = $quiz['id']; $displayString = $displayString . '<tr>'; $displayString = $displayString . displayQuizInfo($name, $topic, $id); $displayString = $displayString . '</tr>'; } $displayString = $displayString . '</tbody></table>'; $displayString = $displayString . '</form>'; if (isset($_POST['take'])) { $id = $_POST['take']; $id = addSlashes($id); $quiz = new QuizSession($id); $_SESSION['id'] = $id; $quiz->chooseQuestions(); $displayString = $quiz->getQuestionPageHtml(); } if (isset($_POST['check'])) { $quiz = new QuizSession($_SESSION['id']); $displayString = $quiz->checkAnswers($_SESSION['questions'], $_POST); } return $displayString; }
function Core_getUserData() { if (!isset($_SESSION['userdata'])) { // not logged in return array('error' => 'you are not logged in'); } $user = dbRow('select id,name,email,phone,address,parent,extras,last_login,last_view,da' . 'te_created from user_accounts where id=' . $_SESSION['userdata']['id'] . ' limit 1'); $user['address'] = json_decode($user['address'], true); $user['extras'] = @$user['extras'] ? json_decode($user['extras'], true) : array(); $groups = dbAll('select groups_id from users_groups where user_accounts_id=' . $_SESSION['userdata']['id']); $g = array(); foreach ($groups as $group) { array_push($g, $group['groups_id']); } $user['groups'] = $g; return $user; }
/** * select list of sub-pages as select options * * @param int $i parent ID * @param int $n depth of child * @param array $s don't remember * @param int $id already selected page * @param int $prefix something or other * * @return string */ function Panels_selectChildPages($i = 0, $n = 1, $s = array(), $id = 0, $prefix = '') { $q = dbAll('select name,id from pages where parent="' . $i . '" and id!="' . $id . '" order by ord,name', false, 'pages'); if (count($q) < 1) { return ''; } $html = ''; foreach ($q as $r) { if ($r['id'] != '') { $html .= '<option value="' . $r['id'] . '" title="' . htmlspecialchars($r['name']) . '"'; $html .= in_array($r['id'], $s) ? ' selected="selected">' : '>'; $name = strtolower(str_replace(' ', '-', $r['name'])); $html .= htmlspecialchars($prefix . $name) . '</option>'; $html .= Panels_selectChildPages($r['id'], $n + 1, $s, $id, $name . '/'); } } return $html; }
function News_getHeadlinesMonth() { $y = (int) $_REQUEST['y']; $m = (int) $_REQUEST['m']; $p = (int) $_REQUEST['pid']; if ($y < 1000 || $y > 9999 || $m < 1 || $m > 12) { Core_quit(); } $m = sprintf('%02d', $m); $sql = 'select id from pages where parent=' . $p . ' and associated_date>"' . $y . '-' . $m . '-00" and associated_date<date_add("' . $y . '-' . $m . '-01", interval 1 month) order by associated_date'; $ps = dbAll($sql); $headlines = array(); foreach ($ps as $p) { $page = Page::getInstance($p['id']); $headlines[] = array('url' => $page->getRelativeURL(), 'adate' => $page->associated_date, 'headline' => htmlspecialchars($page->alias)); } return $headlines; }
function poll_display() { WW_addScript('polls'); $poll = dbRow('select * from poll where enabled limit 1'); if (!count($poll)) { return '<div class="polls-wrapper"><em>No polls available.</em></div>'; } $id = $poll['id']; $html = '<div class="polls-wrapper" poll-id="' . $id . '">'; $html .= '<div class="question">' . $poll['body'] . '</div><ul class="answers">'; $answers = dbAll("select * from poll_answer where poll_id={$id} order by num"); foreach ($answers as $answer) { $html .= '<li><input type="radio" name="poll_answer" value=' . '"' . $answer['num'] . '" />' . htmlspecialchars($answer['answer']) . '</li>'; } $html .= '</ul><input type="button" class="polls-vote" value="Vote" /><inpu' . 't type="button" class="polls-results" value="View Results" />'; $html .= '</div>'; return $html; }
/** * switches the reader to a translation if one exists * * @param object $PAGEDATA page object * * @return void */ function Translate_checkCurrentPage($PAGEDATA) { // { if this is a translation page, and no language is selected, select this one. if ($PAGEDATA->type == 'translate' && !isset($_SESSION['translate-lang'])) { $_SESSION['translate-lang'] = $PAGEDATA->vars['translate_language']; } // } // { if no language is selected, then return if (!isset($_SESSION['translate-lang']) || !$_SESSION['translate-lang']) { return; } // } // { various checks if this page is a translation one $page_to_translate = $PAGEDATA->id; if ($PAGEDATA->type == 'translate') { // { if this page's language is the selected one, return if ($PAGEDATA->vars['translate_language'] == $_SESSION['translate-lang']) { return; } // } $page_to_translate = (int) $PAGEDATA->vars['translate_page_id']; } $trs = dbAll('select page_id from page_vars where name="translate_page_id" and value=' . $page_to_translate, false, 'page_vars'); // { try to find a version of the current page in the selected language if ($trs === false || !count($trs)) { return; } $ids = array(); foreach ($trs as $tr) { $ids[] = $tr['page_id']; } $page_id = dbOne('select page_id from page_vars where name="translate_language" and value="' . addslashes($_SESSION['translate-lang']) . '" limit 1', 'page_id'); // { if none found, return if ($page_id === false) { return; } // } $page = Page::getInstance($page_id); if ($page->id) { redirect($page->getRelativeUrl()); } // } }
/** * show the news in Headline mode * * @param array $PAGEDATA the page object * * @return string HTML of the news */ function News_displayHeadlines($PAGEDATA) { $items_per_page = isset($PAGEDATA->vars['news_items']) ? $PAGEDATA->vars['news_items'] : 5; $p = isset($_REQUEST['news_page']) ? (int) $_REQUEST['news_page'] : 0; if ($p < 0) { $p = 0; } $arr = Core_cacheLoad('pages', 'news-' . $GLOBALS['id'] . '-' . $p . '-' . $items_per_page); if ($arr === false) { $order_by = isset($PAGEDATA->vars['news_order']) ? addslashes($PAGEDATA->vars['news_order']) : 'associated_date desc'; $rs = dbAll('select * from pages where parent=' . $GLOBALS['id'] . ' order by ' . $order_by . ',cdate desc limit ' . $p . ',' . $items_per_page); $num_stories = dbOne('select count(id) as num from pages where parent=' . $GLOBALS['id'], 'num'); Core_cacheSave('pages', 'news-' . $GLOBALS['id'] . '-' . $p . '-' . $items_per_page, array($num_stories, $rs)); } else { $num_stories = $arr[0]; $rs = $arr[1]; unset($arr); } $nextprev = array(); $nextprev[] = '<span class="page_n_of_n">' . __('page %1 of %2', array(1 + floor($p / $items_per_page), ceil($num_stories / $items_per_page)), 'core') . '</span>'; if ($p) { $nextprev[] = '<a class="prev" href="?news_page=' . ($p - $items_per_page) . '">' . __('Previous Page') . '</a>'; } if ($p + $items_per_page < $num_stories) { $nextprev[] = '<a class="next" href="?news_page=' . ($p + $items_per_page) . '">' . __('Next Page') . '</a>'; } $nextprev = '<div class="nextprev">' . join(' | ', $nextprev) . '</div>'; $html = $nextprev; $links = array(); foreach ($rs as $r) { $page = Page::getInstance($r['id'], $r); $content = isset($PAGEDATA->vars['news_display']) && $PAGEDATA->vars['news_display'] == 'full' ? $page->render() : substr(preg_replace('/<[^>]*>/', '', preg_replace('#<h1>[^<]*</h1>#', '', $page->render())), 0, 600); $date = isset($PAGEDATA->vars['news_title']) && $PAGEDATA->vars['news_title'] == 'yes' ? '<h2 class="news-header"><a href="' . $page->getRelativeURL() . '">' . htmlspecialchars($page->name) . '</a></h2>' . '<a class="news-date" href="' . $page->getRelativeURL() . '">' . __('posted on %1', array(Core_dateM2H($page->associated_date)), 'core') . '</a>' : ''; if (!isset($page->associated_date) || !$page->associated_date) { $page->associated_date = $page->cdate; } $links[] = $date . '<p class="news-paragraph">' . $content . '...</p>'; } $html .= join('<div class="news-break"></div>', $links); $html .= $nextprev; return $html; }
/** * build up a selectbox of pages and their child nodes * * @param int $i parent of the child nodes to show * @param int $n level of indentation to show * @param int $s currently selected page's ID (if any) * @param int $id page NOT to show in the list * * @return null */ function selectkiddies($i = 0, $n = 1, $s = 0, $id = 0) { $q = dbAll('select name,id,alias from pages where parent="' . $i . '" and id!="' . $id . '" order by ord,name'); if (count($q) < 1) { return; } foreach ($q as $r) { if ($r['id'] != '') { echo '<option value="' . $r['id'] . '" title="' . htmlspecialchars($r['name']) . '"'; echo $s == $r['id'] ? ' selected="selected">' : '>'; echo str_repeat('» ', $n); $name = $r['alias']; if (strlen($name) > 20) { $name = substr($name, 0, 17) . '...'; } echo htmlspecialchars($name) . '</option>'; selectkiddies($r['id'], $n + 1, $s, $id); } } }
static function precache($ids) { if (count($ids)) { $rs3 = dbAll('select * from pages where id in (' . join(',', $ids) . ')'); $pvars = dbAll('select * from page_vars where page_id in (' . join(',', $ids) . ')'); $rs2 = array(); foreach ($pvars as $p) { if (!isset($rs2[$p['page_id']])) { $rs2[$p['page_id']] = array(); } $rs2[$p['page_id']][] = $p; } foreach ($rs3 as $r) { if (isset($rs2[$r['id']])) { Page::getInstance($r['id'], $r, $rs2[$r['id']]); } else { Page::getInstance($r['id'], $r); } } } }
function showshortcuts($id, $parent) { $q = dbAll('select id,name from pages where parent="' . $parent . '" order by ord desc,name'); if (count($q)) { echo '<ul>'; foreach ($q as $r) { echo '<li>'; echo wInput('shortcuts[' . $r['id'] . ']', 'checkbox'); $r2 = dbRow('select id,name from pagelinks where fromid="' . $id . '" and toid="' . $r['id'] . '"'); if (count($r2)) { echo ' checked="checked"'; $r['name'] = $r2['name']; } echo ' />'; echo wInput('shortcutsName[' . $r['id'] . ']', 'text', htmlspecialchars($r['name'])); showshortcuts($id, $r['id']); echo '</li>'; } echo '</ul>'; } }
/** * widget for mailing lists * * @param array $vars parameters * * @return html */ function MailingLists_widget($vars) { $html = '<div id="mailinglists-subscribe">' . '<input type="email" placeholder="' . __('enter email address') . '"/>'; $sql = 'select * from mailinglists_lists'; $md5 = md5($sql); $lists = Core_cacheLoad('mailinglists', $md5, -1); if ($lists === -1) { $lists = dbAll($sql); Core_cacheSave('mailinglists', $md5, $lists); } if (count($lists) > 1) { $html .= '<select><option value="">' . __('Mailing List') . '</option>'; foreach ($lists as $list) { $html .= '<option value="' . $list['id'] . '">' . htmlspecialchars($list['name']) . '</option>'; } $html .= '</select>'; } $html .= '<button>' . __('Subscribe') . '</button></div>'; WW_addScript('mailinglists/js.js'); return $html; }
/** * The constructor function * * @param int $num The id of the quiz * * @return null if the id doesn't exist * The quiz otherwise * */ function __construct($num) { $this->id = (int) $num; $id = $this->id; $this->score = 0; $quiz = dbRow("SELECT * FROM quiz_quizzes WHERE id = '" . $id . "'"); $rows = dbAll("SELECT * \n\t\t\t\tFROM quiz_questions \n\t\t\t\tWHERE quiz_id = '{$id}' \n\t\t\t\tAND question IS NOT NULL"); if (count($rows) != 0) { // I want the questions to be in an indexed array $this->allQuestions = array(); $i = 0; foreach ($rows as $row) { $this->allQuestions[$i] = $row; $i++; } $this->numQuestionsToBeAnswered = $quiz['number_of_questions']; $this->numQuestions = count($rows); if ($this->numQuestionsToBeAnswered > $this->numQuestions) { $this->numQuestionsToBeAnswered = ceil($this->numQuestions / 2); } } else { return null; } }
function Menu_getChildren($parentid, $currentpage = 0, $isadmin = 0, $topParent = 0, $search_options = 0) { $md5 = md5($parentid . '|' . $currentpage . '|' . $isadmin . '|' . $topParent . '|' . $search_options); $cache = cache_load('menus', $md5); if ($cache) { return $cache; } $pageParentFound = 0; $PARENTDATA = Page::getInstance($parentid); $PARENTDATA->initValues(); $filter = $isadmin ? '' : '&& !(special&2)'; // { menu order $order = 'ord,name'; if (isset($PARENTDATA->vars['order_of_sub_pages'])) { switch ($PARENTDATA->vars['order_of_sub_pages']) { case 1: // { alphabetical $order = 'name'; if ($PARENTDATA->vars['order_of_sub_pages_dir']) { $order .= ' desc'; } break; // } // } case 2: // { associated_date $order = 'associated_date'; if ($PARENTDATA->vars['order_of_sub_pages_dir']) { $order .= ' desc'; } $order .= ',name'; break; // } // } default: // { by admin order $order = 'ord'; if ($PARENTDATA->vars['order_of_sub_pages_dir']) { $order .= ' desc'; } $order .= ',name'; // } } } // } $rs = dbAll('select id as subid,id,name,type,(select count(id) from pages where ' . "parent=subid {$filter}) as numchildren from pages where parent='" . $parentid . "' {$filter} order by {$order}"); $menuitems = array(); // { optimise db retrieval of pages $ids = array(); foreach ($rs as $r) { if (!isset(Page::$instances[$r['id']])) { $ids[] = $r['id']; } } Pages::precache($ids); // } $i = 0; foreach ($rs as $k => $r) { $PAGEDATA = Page::getInstance($r['id']); if (isset($PAGEDATA->banned) && $PAGEDATA->banned) { continue; } $c = array(); $c[] = $parentid == $topParent ? 'menuItemTop' : 'menuItem'; if (!$i++) { $c[] = 'first'; } if ($r['numchildren']) { $c[] = 'ajaxmenu_hasChildren'; } if ($r['id'] == $currentpage) { $c[] = 'ajaxmenu_currentPage'; $pageParentFound = 1; } else { if ($r['numchildren'] && !$pageParentFound && Menu_containsPage($currentpage, $r['id'])) { $c[] = 'ajaxmenu_containsCurrentPage'; $pageParentFound = 1; } } $rs[$k]['classes'] = join(' ', $c); $rs[$k]['link'] = $PAGEDATA->getRelativeURL(); $rs[$k]['name'] = $PAGEDATA->name; $rs[$k]['parent'] = $parentid; $menuitems[] = $rs[$k]; } cache_save('menus', $md5, $menuitems); return $menuitems; }