_checkUserPerm ('', '', 'search')) { return $this->_no_access(); } switch ($type) { case 'msgs': case 'tlts': $a = $fdb->searchMessages ($text, $u, $forum, $type, ('posts' == $disp ? 1 : 0), $max_res); break; default: return '[L[Wrong search type]]'; } $ws = preg_split("/\s+/", $text); reset ($a); $s = ''; switch ($type) { case 'tlts': while ( list (,$r) = each ($a) ) { // search hightlight reset($ws); while (list (,$w) = each ($ws)) if ($w) $r['topic_title'] = preg_replace ("/($w)/i", "$w", $r['topic_title']); encode_post_text($r['cat_name']); encode_post_text($r['forum_title']); encode_post_text($r['topic_title'], 0, 1); $s .= << {$r['cat_name']} {$r['forum_title']} {$r['topic_title']} EOF; } break; case 'msgs': while ( list (,$r) = each ($a) ) { // search hightlight reset($ws); while (list (,$w) = each ($ws)) { if ($w) { $ind = eregi( "([^>]*<)", $r['post_text'], $ind ); // html tags? if ($ind) $r['post_text'] = preg_replace("/($w)(?=[^>]*<)/i", "$w", "
{$r['post_text']}
"); else $r['post_text'] = preg_replace ("/($w)/i", "$w", $r['post_text']); } } encode_post_text ($r['post_text']); reset($ws); while (list (,$w) = each ($ws)) $r['topic_title'] = preg_replace ("/($w)/i", "$w", $r['topic_title']); encode_post_text($r['cat_name']); encode_post_text($r['forum_title']); encode_post_text($r['topic_title'], 0, 1); $s .= << {$r['cat_name']} {$r['forum_title']} {$r['topic_title']}

{$r['post_text']}

EOF; } break; } $cu = $this->getUrlsXml (); encode_post_text($text, 0, 1); return "$cu$text$s"; } /** * returns search page XML */ function getSearchXML () { if (!$this->_checkUserPerm ('', '', 'search')) { return $this->_no_access(); } $fdb = new DbForum (); $a = $fdb->getCategs(); reset ($a); $c = ''; while ( list (,$r) = each ($a) ) { $c .= ""; encode_post_text($r['cat_name'], 0); $c .= "{$r['cat_name']}"; $c .= '' . $this->getForumsShortXML ($r['cat_id'], 0) . ''; $c .= ""; } $s = "$c"; $cu = $this->getUrlsXml (); return "$cu$s"; } /** * returns new topic page XML */ function getNewTopicXML ($forum_uri) { $fdb = new DbForum (); $f = $fdb->getForumByUri ($forum_uri); $forum_id = $f['forum_id']; if (!$this->_checkUserPerm ('', $f['forum_type'], 'post', $forum_id)) { return $this->_no_access(); } $sticky = 0; if ($this->_checkUserPerm ('', '', 'sticky', $forum_id)) { $sticky = 1; } encode_post_text ($f['forum_title'], 0); encode_post_text ($f['forum_desc'], 0); $x1 = << {$f['forum_id']} {$f['forum_uri']} {$f['forum_title']} {$f['forum_desc']} {$f['forum_type']} EOF; $cat = $fdb->getCat ($f['cat_id']); encode_post_text ($cat['cat_name'], 0); $x2 = << {$f['cat_id']} {$cat['cat_uri']} {$cat['cat_name']} EOF; $cu = $this->getUrlsXml (); return "$cu{$x2}{$x1}"; } /** * returns post reply page XML */ function getPostReplyXML ($forum_id, $topic_id) { $fdb = new DbForum (); $f = $fdb->getForum ($forum_id); $t = $fdb->getTopic ((int)$topic_id); if (!$this->_checkUserPerm ('', $f['forum_type'], 'post', (int)$forum_id) || $t['topic_locked']) { return $this->_no_access(); } encode_post_text ($f['forum_title'], 0); encode_post_text ($f['forum_desc'], 0); $x1 = << {$f['forum_id']} {$f['forum_uri']} {$f['forum_title']} {$f['forum_desc']} {$f['forum_type']} EOF; $cu = $this->getUrlsXml (); return "$cu$x1$topic_id"; } /** * returns single post XML * @param $post_id post id * @param $force_show force show hidden post */ function getHiddenPostXML ($post_id, $force_show) { global $gConf; $post_id = (int)$post_id; if (!$post_id) return false; $ui = array (); $fdb = new DbForum (); $t = $fdb->getTopicByPostId ($post_id); $topic_id = $t['topic_id']; $f = $fdb->getForum ($t['forum_id']); $forum_id = $f['forum_id']; // check user permission to read this topic posts $forum_type = $f['forum_type']; if (!$this->_checkUserPerm ('', $forum_type, 'read', $forum_id)) { return $this->_no_access(); } // check user permissions to delete or edit posts $gl_allow_edit = 0; $gl_allow_del = 0; if ($this->_checkUserPerm ('', $forum_type, 'edit', $forum_id)) $gl_allow_edit = 1; if ($this->_checkUserPerm ('', $forum_type, 'del', $forum_id)) $gl_allow_del = 1; $u = $this->_getLoginUser(); $r = $fdb->getPost($post_id, $u); // acquire user info if (!$ui[$r['user']]) { $aa = $this->_getUserInfo ($r['user']); $ui[$r['user']] = array ('posts' => (int)$fdb->getUserPosts($r['user']), 'avatar' => $aa['avatar'], 'url' => $aa['profile_url'], 'onclick' => $aa['profile_onclick']); } $allow_edit = $gl_allow_edit; $allow_del = $gl_allow_del; if (!$allow_edit && $r['user'] == $this->_getLoginUserName()) { if ($this->_checkUserPerm ($r['user'], 'own', 'edit', $forum_id)) $allow_edit = 1; } if (!$allow_del && $r['user'] == $this->_getLoginUserName()) { if ($this->_checkUserPerm ($r['user'], 'own', 'del', $forum_id)) $allow_del = 1; } $cu = $this->getUrlsXml (); encode_post_text ($r['post_text']); return << $cu {$f['forum_id']} {$f['forum_uri']} $topic_id {$t['topic_uri']} {$r['post_text']} {$r['when']} $allow_edit $allow_del {$r['votes']} {$r['vote_user_point']} {$ui[$r['user']]['avatar']} {$ui[$r['user']]['url']} {$ui[$r['user']]['onclick']} {$gConf['min_point']} EOF; } /** * returns topic posts XML * @param $topic_id * @param $wp return whole page XML */ function getPostsXML ($topic_uri, $wp) { global $gConf; $ui = array (); $fdb = new DbForum (); $u = $this->_getLoginUser(); $a = $fdb->getPostsByUri($topic_uri, $u); $topic_id = $a[0]['topic_id']; // check user permission to read this topic posts $f = $fdb->getForum ($a[0]['forum_id']); $forum_id = $f['forum_id']; $forum_type = $f['forum_type']; if (!$this->_checkUserPerm ($u, $forum_type, 'read', $forum_id)) { return $this->_no_access($wp); } $canPost = (string)(int)$this->_checkUserPerm ($u, $forum_type, 'post', $forum_id); $perm = "$canPost"; $this->setTrackTopic ($topic_id); // check user permissions to delete or edit posts $gl_allow_edit = 0; $gl_allow_del = 0; if ($this->_checkUserPerm ($u, $forum_type, 'edit', $forum_id)) $gl_allow_edit = 1; if ($this->_checkUserPerm ($u, $forum_type, 'del', $forum_id)) $gl_allow_del = 1; reset ($a); $p = ''; while ( list (,$r) = each ($a) ) { // acquire user info if (!$ui[$r['user']]) { $aa = $this->_getUserInfo ($r['user']); $ui[$r['user']] = array ('posts' => $fdb->getUserPosts($r['user']), 'avatar' => $aa['avatar'], 'url' => $aa['profile_url'], 'onclick' => $aa['profile_onclick']); } $allow_edit = $gl_allow_edit; $allow_del = $gl_allow_del; if (!$allow_edit && $r['user'] == $u) { if ($this->_checkUserPerm ($r['user'], 'own', 'edit', $forum_id)) $allow_edit = 1; } if (!$allow_del && $r['user'] == $u) { if ($this->_checkUserPerm ($r['user'], 'own', 'del', $forum_id)) $allow_del = 1; } encode_post_text ($r['post_text'], $wp, 1); $p .= << {$r['post_text']} {$r['when']} $allow_edit $allow_del {$r['votes']} {$r['vote_user_point']} {$ui[$r['user']]['avatar']} {$ui[$r['user']]['url']} {$ui[$r['user']]['onclick']} {$gConf['min_point']} EOF; $rr = $r; } $t = $fdb->getTopic ($rr['topic_id']); $cat = $fdb->getCat ($f['cat_id']); encode_post_text ($cat['cat_name'], $wp); $x0 = << {$cat['cat_id']} {$cat['cat_uri']} {$cat['cat_name']} EOF; encode_post_text ($t['forum_title'], $wp); encode_post_text ($t['forum_desc'], $wp); $x1 = << {$f['forum_id']} {$f['forum_uri']} {$t['forum_title']} {$t['forum_desc']} {$f['forum_type']} EOF; encode_post_text ($t['topic_title'], $wp, 1); $x2 = << {$t['topic_id']} {$t['topic_uri']} {$t['topic_title']} {$t['topic_locked']} EOF; if ($wp) { $li = $this->_getLoginInfo ($u); return $this->addHeaderFooter ($li, "{$perm}{$x0}{$x1}{$x2}{$p}"); } else { $cu = $this->getUrlsXml (); $li = $this->_getLoginInfo ($u); return "" . array2xml($li) . "$cu{$perm}{$x0}{$x1}{$x2}{$p}"; } } /** * returns my threads topics XML * @param $wp return whole page XML */ function getMyThreadsXML ($wp) { global $gConf; $user = $this->getLoginUser(); $fdb = new DbForum (); $f = $fdb->getForum ($forum_id); if (!$user) { return $this->_no_access($wp); } $x1 = << <![CDATA[[L[My Topics]]]]> EOF; $x2 = ''; $user_last_act = (int)$fdb->getUserLastActivity ($user); $a = $fdb->getMyThreadsTopics($user); reset ($a); $t = ''; while ( list (,$r) = each ($a) ) { $lp = $fdb->getTopicPost($r['topic_id'], 'last'); $fp = $fdb->getTopicPost($r['topic_id'], 'first'); $td = $fdb->getTopicDesc ($r['topic_id']); $this->_buld_topic_desc ($td); if (!$user) $new_topic = 0; else $new_topic = $this->isNewTopic ($r['topic_id'], $r['last_post_when'], $user_last_act) ? 1 : 0; encode_post_text ($r['topic_title'], $wp, 1); $t .= << {$r['topic_uri']} {$r['topic_title']} {$td} {$r['count_posts']} {$lp['user']} {$lp['when']} {$fp['user']} {$fp['when']} EOF; } $p = ''; $num = $fdb->getTopicsNum($forum_id); for ($i = 0 ; $i < $num ; $i += $gConf['topics_per_page']) $p .= '

' . ($i/$gConf['topics_per_page'] + 1) . '

'; if ($wp) { $li = $this->_getLoginInfo (); return $this->addHeaderFooter ($li, "$p{$x2}{$x1}{$t}"); } else { $cu = $this->getUrlsXml (); return "$cu$p{$x2}{$x1}{$t}"; } } /** * returns flagged topics XML * @param $wp return whole page XML */ function getMyFlagsXML ($wp) { global $gConf; $user = $this->getLoginUser(); $fdb = new DbForum (); $f = $fdb->getForum ($forum_id); if (!$user) { return $this->_no_access($wp); } $x1 = << <![CDATA[[L[Flagged topics]]]]> EOF; $x2 = ''; $user_last_act = (int)$fdb->getUserLastActivity ($user); $a = $fdb->getMyFlaggedTopics($user); reset ($a); $t = ''; while ( list (,$r) = each ($a) ) { $lp = $fdb->getTopicPost($r['topic_id'], 'last'); $fp = $fdb->getTopicPost($r['topic_id'], 'first'); $td = $fdb->getTopicDesc ($r['topic_id']); $this->_buld_topic_desc ($td); if (!$user) $new_topic = 0; else $new_topic = $this->isNewTopic ($r['topic_id'], $r['last_post_when'], $user_last_act) ? 1 : 0; encode_post_text ($r['topic_title'], $wp, 1); $t .= << {$r['topic_title']} {$r['topic_title']} {$td} {$r['count_posts']} {$lp['user']} {$lp['when']} {$fp['user']} {$fp['when']} EOF; } $p = ''; $num = $fdb->getTopicsNum($forum_id); for ($i = 0 ; $i < $num ; $i += $gConf['topics_per_page']) $p .= '

' . ($i/$gConf['topics_per_page'] + 1) . '

'; if ($wp) { $li = $this->_getLoginInfo (); return $this->addHeaderFooter ($li, "$p{$x2}{$x1}{$t}"); } else { $cu = $this->getUrlsXml (); return "$cu$p{$x2}{$x1}{$t}"; } } /** * returns forum topics XML * @param $forum_id forum id * @param $wp return whole page XML * @param $start record to start with */ function getTopicsXML ($forum_uri, $wp, $start = 0) { global $gConf; $fdb = new DbForum (); $f = $fdb->getForumByUri ($forum_uri); $forum_id = $f['forum_id']; $user = $this->getLoginUser(); if (!$this->_checkUserPerm ($user, $f['forum_type'], 'read', $forum_id)) { return $this->_no_access($wp); } $canPost = (string)(int)$this->_checkUserPerm ($user, $f['forum_type'], 'post', $forum_id); $perm = "$canPost"; encode_post_text ($f['forum_title'], $wp); encode_post_text ($f['forum_desc'], $wp); $x1 = << {$f['forum_id']} {$f['forum_uri']} {$f['forum_title']} {$f['forum_desc']} {$f['forum_type']} EOF; $cat = $fdb->getCat ($f['cat_id']); encode_post_text ($cat['cat_name'], $wp); $x2 = << {$cat['cat_id']} {$cat['cat_uri']} {$cat['cat_name']} EOF; $user_last_act = (int)$fdb->getUserLastActivity ($user); $a = $fdb->getTopics($forum_id, $start); reset ($a); $t = ''; while ( list (,$r) = each ($a) ) { $td = $fdb->getTopicDesc ($r['topic_id']); $this->_buld_topic_desc ($td); if (!$user) $new_topic = 0; else $new_topic = $this->isNewTopic ($r['topic_id'], $r['last_post_when'], $user_last_act) ? 1 : 0; encode_post_text ($r['topic_title'], $wp, 1); $t .= << {$r['topic_uri']} {$r['topic_title']} {$td} {$r['count_posts']} {$r['last_post_user']} {$r['last_when']} {$r['first_post_user']} {$r['first_when']} EOF; } $p = ''; $num = $fdb->getTopicsNum($forum_id); for ($i = 0 ; $i < $num ; $i += $gConf['topics_per_page']) $p .= '

' . ($i/$gConf['topics_per_page'] + 1) . '

'; if ($wp) { $li = $this->_getLoginInfo ($user); return $this->addHeaderFooter ($li, "$p{$perm}{$x2}{$x1}{$t}"); } else { $cu = $this->getUrlsXml (); return "$cu$p{$perm}{$x2}{$x1}{$t}"; } } /** * returns array with viewed topics */ function getTrackTopics () { $a = unserialize($_COOKIE['track_topics']); if (!is_array($a)) return array (); return $a; } /** * mark topic as viewed */ function setTrackTopic ($topic_id) { $a = unserialize($_COOKIE['track_topics']); if (!is_array($a)) $a = array (); $a[$topic_id] = time(); setcookie ('track_topics', serialize($a)); } /** * detect new topic by last topic update time and user activity and cookies * */ function isNewTopic ($topic_id, $topic_last_time, $user_last_time) { $a = $this->getTrackTopics (); if ($a[$topic_id] && $topic_last_time > $a[$topic_id]) return 1; else if ($a[$topic_id]) return 0; if (!$user_last_time) return 1; if ($topic_last_time > $user_last_time) return 1; return 0; } /** * returns forums XML */ function getForumsShortXML ($cat, $root) { $fdb = new DbForum (); if ($root) $c = ''; else $c = ''; $aa = $fdb->getForums ($cat); reset ($aa); while ( list (,$rr) = each ($aa) ) { encode_post_text($rr['forum_title'], 0); $c .= << {$rr['forum_uri']} {$rr['forum_title']} {$rr['forum_type']} EOF; } if ($root) return $c."\n"; else return $c; } /** * returns forums XML */ function getForumsXML ($cat, $root) { $fdb = new DbForum (); if ($root) $c = ''; else $c = ''; $aa = $fdb->getForumsByCatUri ($cat); reset ($aa); while ( list (,$rr) = each ($aa) ) { encode_post_text ($rr['forum_title'], $root); encode_post_text ($rr['forum_desc'], $root); $c .= << {$rr['forum_uri']} {$rr['forum_title']} {$rr['forum_desc']} {$rr['forum_type']} {$rr['forum_posts']} {$rr['forum_topics']} {$rr['forum_last']} EOF; } if ($root) { $cu = $this->getUrlsXml (); return '' . $cu . $c . "\n"; } else { return $c; } } /** * returns page XML */ function getPageXML ($first_load = 1, &$p) { global $gConf; $fdb = new DbForum (); $a = $fdb->getCategs(); reset ($a); $c = ''; while ( list (,$r) = each ($a) ) { $icon_url = $r['cat_icon'] ? $gConf['url']['icon'] . $r['cat_icon'] : ''; $c .= ""; encode_post_text ($r['cat_name'], 1); $c .= "{$r['cat_name']}"; if (( isset($p['cat']) && $p['cat'] == $r['cat_uri'] ) /*|| 1 == $r['cat_id'] */) { $c .= ''.$this->getForumsXML ($r['cat_uri'], 0) . ''; } $c .= ""; } $s = "$c"; if ($first_load && isset($p['action']) && 'goto' == $p['action'] && isset($p['forum_id'])) { $s .= "f.selectForum('" . $p['forum_id'] . "', 0)"; } if ($first_load && isset($p['action']) && 'goto' == $p['action'] && isset($p['topic_id'])) { $s .= "f.selectTopic('" . $p['topic_id'] . "')"; } // live tracker $lt = "" . $this->getLivePostsXML() . ""; $li = $this->_getLoginInfo (); eval($GLOBALS['l']('ICAgICAgICBpZiAoJGxpWydhZG1pbiddKQ0KICAgICAgICB7DQogICAgICAgICAgICAkb0FkbSA9IG5ldyBBZG1pbigpOw0KICAgICAgICAgICAgJGlDb2RlID0gJG9BZG0tPmdldENvZGUgKCRzTXNnKTsNCiAgICAgICAgICAgIGlmICgwICE9PSAkaUNvZGUgJiYgMTAgIT09ICRpQ29kZSkNCiAgICAgICAgICAgICAgICAkcyAuPSAnPGludmFsaWRfbGljZW5zZSAvPic7DQogICAgICAgICAgICBzZXRDb25maWdQYXJhbSgnZGlzYWJsZV9ib29uZXhfZm9vdGVycycsIDAgPT09ICRpQ29kZSA/IDEgOiAwKTsNCiAgICAgICAgfQ==')); if ($first_load) { return $this->addHeaderFooter ($li, $s.$lt); } else { $cu = $this->getUrlsXml (); return "$cu".array2xml($li)."{$s}{$lt}"; } } function getLivePostsXML ($count = 10, $ts = 0) { return ''; //turned off for groups global $gConf; $ret = ''; $fdb = new DbForum (); $a = $fdb->getLivePosts ($count, $ts); reset ($a); $ui = array (); while (list(,$r) = each ($a)) { // acquire user info if (!isset($ui[$r['user']])) { $aa = $this->_getUserInfo ($r['user']); $ui[$r['user']] = array ('avatar' => $aa['avatar'], 'url' => $aa['profile_url'], 'onclick' => $aa['profile_onclick']); } $this->_buld_topic_desc ($r['post_text']); encode_post_text($r['topic_title'], 0, 1); encode_post_text($r['forum_title'], 0); encode_post_text($r['cat_name'], 0); $r['when'] = $this->_format_when ($r['sec']); $ret .= << {$r['post_text']} {$r['user']} {$r['when']} {$ui[$r['user']]['avatar']} {$ui[$r['user']]['url']} {$ui[$r['user']]['onclick']} {$r['topic_title']} {$r['forum_title']} {$r['cat_name']} {$gConf['url']['base']} EOF; } return $ret; } /** * check if new posts are available * @param $ts timestamp of last post */ function isNewPost ($ts) { $db = new DbForum (); return '' . (int)$db->getNewPostTs ($ts) . ''; } /** * post reply * @param $p _post array */ function postReplyXML (&$p) { $fdb = new DbForum (); $f = $fdb->getForum ((int)$p['forum_id']); $t = $fdb->getTopic ((int)$p['topic_id']); if (!$this->_checkUserPerm ('', $f['forum_type'], 'post', (int)$p['forum_id']) || $t['topic_locked']) { return << EOF; } // post mesage here $p['forum_id'] = (int)$p['forum_id']; $p['topic_id'] = (int)$p['topic_id']; $user = $this->_getLoginUserName (); prepare_to_db($p['topic_text'], 1); $fdb->postReply ($p['forum_id'], $p['topic_id'], $p['topic_text'], $user); $t = $fdb->getTopic($p['topic_id']); return << EOF; } /** * xml for edit post * @param $post_id post id * @param $topic_id topic id */ function editPostXml ($post_id, $topic_id) { $cu = $this->getUrlsXml (); if (/*!$topic_id && */$post_id) { $db = new DbForum (); $a = $db->getTopicByPostId ($post_id); $t = $db->getTopic ($a['topic_id']); $topic_id = $t['topic_uri']; } return << $cu $post_id $topic_id EOS; } /** * edit post * @param $post_id post id * @param $topic_id topic id * @param $text new post text */ function editPost ($post_id, $topic_id, $text) { $no_access = true; $fdb = new DbForum (); //$f = $fdb->getForumByPostId ($post_id); $t = $fdb->getTopicByUri ($topic_id); if ($this->_checkUserPerm ('', $t['forum_type'], 'edit', $t['forum_id'])) $no_access = false; if ($no_access && $fdb->getPostUser((int)$post_id) == $this->_getLoginUserName()) if ($this->_checkUserPerm ('', 'own', 'edit', $t['forum_id'])) $no_access = false; if ($no_access) { return << EOF; } // edit post here prepare_to_db($text, 1); $fdb->editPost ($post_id, $text); return << EOF; } /** * delete post * @param $post_id post id * @param $topic_id topic id * @param $forum_id forum id */ function deletePostXML ($post_id, $topic_id, $forum_id) { $no_access = true; $fdb = new DbForum (); $f = $fdb->getForumByPostId ($post_id); if ($this->_checkUserPerm ('', $f['forum_type'], 'del', $f['forum_id'])) $no_access = false; if ($no_access && $fdb->getPostUser((int)$post_id) == $this->_getLoginUserName()) if ($this->_checkUserPerm ('', 'own', 'del', $f['forum_id'])) $no_access = false; if ($no_access) { return << EOF; } // delete post here $fdb->deletePost ($post_id); $aTopic = $fdb->getTopic ($topic_id); $exists = $aTopic ? 1 : 0; return << EOF; } /** * post new topic * @param $p _post array */ function postNewTopicXML ($p) { $fdb = new DbForum (); $f = $fdb->getForum ((int)$p['forum_id']); if (!$this->_checkUserPerm ('', $f['forum_type'], 'post', (int)$p['forum_id'])) { return << EOF; } if ($p['topic_sticky'] == 'on' && !$this->_checkUserPerm ('', '', 'sticky', (int)$p['forum_id'])) { return << EOF; } // post mesage here $user = $this->_getLoginUserName (); prepare_to_db($p['topic_subject'], 1); prepare_to_db($p['topic_text'], 1); $topic_uri = $this->uriGenerate ($p['topic_subject'], TF_FORUM_TOPIC, 'topic_uri'); $fdb->newTopic ((int)$p['forum_id'], $p['topic_subject'], $p['topic_text'], ($p['topic_sticky'] == 'on'), $user, $topic_uri); return << EOF; } function isAdmin () { $a = $this->_getUserInfo ($this->getLoginUser()); return $a['admin']; } /** * returns logged in user */ function getLoginUser () { return $this->_getLoginUser(); } /** * updates current user last activity time */ function updateCurrentUserActivity () { $u = $this->getLoginUser (); if (!$u) return; $db = new DbForum (); $db->updateUserActivity ($u); } function logout () { $u = $this->getLoginUser (); if (!$u) return '0'; setcookie('orca_pwd', 'orca_pwd', time() - 86400); setcookie('orca_user', 'orca_user', time() - 86400); setcookie('track_topics', 'track_topics', time() - 86400); $db = new DbForum (); $db->updateUserLastActivity ($u); return '1'; } /** * post voting * @param $post_id post id * @param $vote vote (1|-1) */ function votePost ($post_id, $vote) { $u = $this->getLoginUser (); if (!$u) return '0'; $db = new DbForum (); if (!$db->insertVote ((int)$post_id, $u, $vote)) return '0'; return '1'; } /** * report post * @param $post_id post id */ function report ($post_id) { if (!$post_id) return '0'; $u = $this->getLoginUser (); if (!$u) return '0'; $db = new DbForum (); if (!$db->report ((int)$post_id, $u)) return '0'; return '1'; } /** * flag/unflag topic * @param $topic_id topic id */ function flag ($topic_id) { if (!$topic_id) return '0'; $u = $this->getLoginUser (); if (!$u) return '0'; $db = new DbForum (); if ($db->isFlagged ((int)$topic_id, $u)) { if (!$db->unflag ((int)$topic_id, $u)) return '0'; return '-1'; } if (!$db->flag ((int)$topic_id, $u)) return '0'; return '1'; } /** * forum rss feed, 10 latest topics in the forum * @param $forum_id forum id */ function getRssForum ($forum_uri) { global $gConf; $gConf['topics_per_page'] = 10; $gConf['date_format'] = '%a, %e %b %Y %k:%i:%s GMT'; $fdb = new DbForum (); $f = $fdb->getForumByUri ($forum_uri); $forum_id = $f['forum_id']; if (!$f) exit; $a = $fdb->getTopics ($forum_id, 0); reset ($a); $items = ''; $lastBuildDate = ''; while ( list (,$r) = each ($a) ) { $lp = $fdb->getTopicPost($r['topic_id'], 'last'); $td = strip_tags($fdb->getTopicDesc($r['topic_id'])); if (!$lastBuildDate) $lastBuildDate = $lp['when']; $items .= " {$r['topic_title']} " . $gConf['url']['base'] . sprintf($gConf['rewrite']['topic'], $r['topic_uri']) . " $td {$lp['when']} " . $gConf['url']['base'] . sprintf($gConf['rewrite']['topic'], $r['topic_uri']) . " "; } return " {$f['forum_title']} " . $gConf['url']['base'] . sprintf($gConf['rewrite']['forum'], $f['forum_uri'], 0) . " {$f['forum_desc']} $lastBuildDate $items "; } /** * topic rss feed, 10 latest posts in the topic * @param $forum_id forum id */ function getRssTopic ($topic_uri) { global $gConf; $gConf['topics_per_page'] = 10; $gConf['date_format'] = '%a, %e %b %Y %k:%i:%s GMT'; $fdb = new DbForum (); $t = $fdb->getTopicByUri($topic_uri); $topic_id = (int)$t['topic_id']; if (!$t) exit; $a = $fdb->getPosts ($topic_id, 0); reset ($a); $items = ''; $lastBuildDate = ''; while ( list (,$r) = each ($a) ) { $lp = $fdb->getTopicPost($r['topic_id'], 'last'); $td = strip_tags(substr($r['post_text'], 0, 256)); if (strlen($td) == 256) $td .= '[...]'; $tt = substr($td, 0, 32); $lastBuildDate = $lp['when']; $items .= " {$tt} " . $gConf['url']['base'] . sprintf($gConf['rewrite']['topic'], $t['topic_uri']) . " $td {$lp['when']} " . $gConf['url']['base'] . sprintf($gConf['rewrite']['topic'], $t['topic_uri']) . "#{$r['post_id']} "; } return " {$t['topic_title']} " . $gConf['url']['base'] . sprintf($gConf['rewrite']['topic'], $t['topic_uri']) . " {$t['topic_title']} $lastBuildDate $items "; } /** * user posts rss feed, 10 latest posts of specified user * @param $user username * @param $sort sort : rnd | top | latest - default */ function getRssUser ($user, $sort) { global $gConf; $gConf['topics_per_page'] = 10; $gConf['date_format'] = '%a, %e %b %Y %k:%i:%s GMT'; $fdb = new DbForum (); $a = $fdb->getUserPostsList($user, $sort, $gConf['topics_per_page']); reset ($a); $items = ''; $lastBuildDate = ''; while ( list (,$r) = each ($a) ) { if (!$lastBuildDate) $lastBuildDate = $r['when']; $td = strip_tags($r['post_text']); if (strlen($td) == 256) $td .= '[...]'; $items .= " <![CDATA[{$r['topic_title']}]]> " . $gConf['url']['base'] . sprintf($gConf['rewrite']['topic'], $r['topic_uri']) . " {$r['when']} " . $gConf['url']['base'] . sprintf($gConf['rewrite']['topic'], $r['topic_uri']) . " "; } if ($sort == 'rnd' || $sort == 'top') $lastBuildDate = ''; $sTitle = sprintf("[L[%s's forum posts]]", $user); return " $sTitle {$gConf['url']['base']} $sTitle $lastBuildDate $items "; } /** * all posts rss feed, 10 latest posts * @param $user username * @param $sort sort : rnd | top | latest - default */ function getRssAll ($sort) { global $gConf; $gConf['topics_per_page'] = 10; $gConf['date_format'] = '%a, %e %b %Y %k:%i:%s GMT'; $fdb = new DbForum (); $a = $fdb->getAllPostsList($sort, $gConf['topics_per_page']); reset ($a); $items = ''; $lastBuildDate = ''; while ( list (,$r) = each ($a) ) { if (!$lastBuildDate) $lastBuildDate = $r['when']; $td = strip_tags($r['post_text']); if (strlen($td) == 256) $td .= '[...]'; $items .= " <![CDATA[{$r['topic_title']}]]> " . $gConf['url']['base'] . sprintf($gConf['rewrite']['topic'], $r['topic_uri']) . " {$r['when']} " . $gConf['url']['base'] . sprintf($gConf['rewrite']['topic'], $r['topic_uri']) . " "; } if ($sort == 'rnd' || $sort == 'top') $lastBuildDate = ''; return << [L[Forum Posts]] {$gConf['url']['base']} [L[Forum Posts]] $lastBuildDate $items EOF; } /** * profile xml * @param $u username * @param $wp return whole page XML */ function showProfile ($u, $wp) { $fdb = new DbForum (); $a = $this->_getUserInfo ($u); $as = $fdb->getUserStat ($u); $a['username'] = $u; $a['posts'] = (int)$as['posts']; $a['user_last_post'] = $as['user_last_post']; $a['last_online'] = $fdb->getUserLastOnlineTime ($u); $p = array2xml ($a); if ($wp) { $li = $this->_getLoginInfo (); return $this->addHeaderFooter ($li, "$p"); } else { $cu = $this->getUrlsXml (); return "$cu$p"; } } // private functions function _getLoginInfo ($user = '') { if (!strlen($user)) $user = $this->_getLoginUserName (); $a = $this->_getUserInfo ($user); $a['username'] = $user; return $a; } function _getUserInfo ($user) { global $gConf; $ret = array (); if (!$user) $user = $this->_getLoginUser(); if (!$user) return $ret; $action = 'user_info'; $integration_file = ''; include ($gConf['dir']['base'] . 'xml/url.php'); if (!$integration_file) return; $xml = $this->_read_integration_file ($integration_file); if (!$xml) return; if (((int)phpversion()) >= 5) { $d = new DomDocument(); $d->loadXML($xml); $up = $d->getElementsByTagName ('user_info'); $up = $up->item(0); $n = $up->firstChild; do { if ($n->nodeType != XML_ELEMENT_NODE) continue; $ret[$n->nodeName] = $n->textContent; } while ($n = $n->nextSibling); } else { if (!$d = domxml_open_mem($xml)) { $mk = new Mistake (); $mk->log ("Forum::_getUserInfo - can not parse xml: $xml"); $mk->displayError ("[L[Site is unavailable]]"); } $up = $d->get_elements_by_tagname ('user_info'); $up = $up[0]; $n = $up->first_child(); do { if ($n->node_type() != XML_ELEMENT_NODE) continue; $ret[$n->node_name ()] = $n->get_content (); } while ($n = $n->next_sibling()); } return $ret; } /** * check user perms * @param $user username * @param $f_type forum type private/public/own * @param $a_type access type read/post/edit/del */ function _checkUserPerm ($user, $f_type, $a_type, $forum_id = 0) { global $gConf; if (!$user) $user = $this->_getLoginUser(); $action = 'user_perm'; $integration_file = ''; include ($gConf['dir']['base'] . 'xml/url.php'); if (!$integration_file) return; $xml = $this->_read_integration_file ($integration_file); if (!$xml) return; if (((int)phpversion()) >= 5) { $d = new DomDocument(); $d->loadXML($xml); $up = $d->getElementsByTagName ('user_perm'); $up = $up->item(0); $n = $up->firstChild; do { if ($n->nodeType != XML_ELEMENT_NODE) continue; if ($n->nodeName == "{$a_type}_{$f_type}") return $n->textContent; } while ($n = $n->nextSibling); } else { if (!$d = domxml_open_mem($xml)) { $mk = new Mistake (); $mk->log ("Forum::_checkUserPerm - can not parse xml : $url"); $mk->displayError ("[L[Site is unavailable]]"); } $up = $d->get_elements_by_tagname ('user_perm'); $up = $up[0]; $n = $up->first_child(); do { if ($n->node_type() != XML_ELEMENT_NODE) continue; if ($n->node_name () == "{$a_type}_{$f_type}") return $n->get_content (); } while ($n = $n->next_sibling()); } return 0; } /** * returns loggen in user */ function _getLoginUserName () { return $this->_getLoginUser(); } /** * returns logged in user */ function _getLoginUser () { global $gConf; $action = 'login_user'; $integration_file = ''; include ($gConf['dir']['base'] . 'xml/url.php'); if (!$integration_file) return; $xml = $this->_read_integration_file ($integration_file); if (((int)phpversion()) >= 5) { $d = new DomDocument(); $d->loadXML($xml); $up = $d->getElementsByTagName ('login_user'); $up = $up->item(0); return $up->textContent; } else { if (!$d = @domxml_open_mem($xml)) { $mk = new Mistake (); $mk->log ("Forum::_getLoginUser - can not parse xml : $url"); $mk->displayError ("[L[Site is unavailable]]"); } $n = $d->get_elements_by_tagname ('login_user'); $n = $n[0]; return $n->get_content (); } } function _read_integration_file ($integration_file) { global $gConf; if ('url' == $gConf['integration']) { if (function_exists('curl_init')) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $integration_file); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); $xml = curl_exec($curl); curl_close($curl); if (true === $xml) $xml = ''; } elseif ($h = @fopen ($integration_file, "r")) { $xml = ''; while (!feof($h)) { $xml .= fread($h, 8192); } fclose($h); } else { $mk = new Mistake (); $mk->log ("Forum::_read_integration_file - can not open $integration_file for reading"); $mk->displayError ("[L[Site is unavailable]]"); } return $xml; } else { $orca_integration_xml = ''; $orca_integration_vars = $integration_file['vars']; include ($integration_file['file']); return $orca_integration_xml; } } function _format_when ($iSec) { $s = ''; if ($iSec < 3600) { $i = round($iSec/60); if (0 == $i || 1 == $i) $s .= '1 [L[Minute Ago]]'; else $s .= $i . ' [L[Minutes Ago]]'; } else if ($iSec < 86400) { $i = round($iSec/60/60); if (0 == $i || 1 == $i) $s .= '1 [L[Hour Ago]]'; else $s .= $i . ' [L[Hours Ago]]'; } else { $i = round($iSec/60/60/24); if (0 == $i || 1 == $i) $s .= '1 [L[Day Ago]]'; else $s .= $i . ' [L[Days Ago]]'; } return $s; } function _no_access ($wp = 0) { $xml = 'no'; if (!$wp) return $xml; $li = $this->_getLoginInfo (); return $this->addHeaderFooter ($li, $xml); } function _buld_topic_desc (&$s) { $s = str_replace(array(' ','&','>','<','"'), array(' ','&','>','<',"'"),strip_tags ($s)); validate_unicode ($s); if ($s == '') $s = ' '; $s = ''; } function uriGenerate ($s, $sTable, $sField, $iMaxLen = 255) { //$s = orca_mb_replace ('/([^\d^\w]+)/', '-', $s); // latin characters $s = orca_mb_replace ('/[^\pL^\pN]+/u', '-', $s); // unicode characters $s = orca_mb_replace ('/([-^]+)/', '-', $s); if (!$s) $s = '-'; if ($this->uriCheckUniq($s, $sTable, $sField)) return $s; // try to add date if (orca_mb_len($s) > 240) $s = orca_mb_substr ($s, 0, 240); $s .= '-' . date('Y-m-d'); if ($this->uriCheckUniq($s, $sTable, $sField)) return $s; // try to add number for ($i = 0 ; $i < 999 ; ++$i) { if ($this->uriCheckUniq($s . '-' . $i, $sTable, $sField)) { return ($s . '-' . $i); } } return rand(0, 999999999); } function uriCheckUniq ($s, $sTable, $sField) { $fdb = new DbForum (); return !$fdb->getOne("SELECT 1 FROM $sTable WHERE $sField = '$s' LIMIT 1"); } } function orca_mb_replace ($sPattern, $sReplace, $s) { return preg_replace ($sPattern, $sReplace, $s); } function orca_mb_len ($s) { if (function_exists('mb_strlen')) return mb_strlen ($s); else return strlen ($s); } function orca_mb_substr ($s, $iStart, $iLen) { if (function_exists('mb_substr')) return mb_substr ($s, $iStart, $iLen); else return substr ($s, $iStart, $iLen); } ?>