/** * Returns an array with all available items the Menu gadget can use * * @access public * @return array List of URLs */ function Execute() { $urls = array(); $urls[] = array('url' => $this->gadget->urlMap('Page'), 'title' => $this->gadget->title); $urls[] = array('url' => $this->gadget->urlMap('GroupsList'), 'title' => _t('STATICPAGE_GROUPS_LIST')); $urls[] = array('url' => $this->gadget->urlMap('PagesTree'), 'title' => _t('STATICPAGE_PAGES_TREE')); //Load model $max_size = 32; $pModel = $this->gadget->model->load('Page'); $gModel = $this->gadget->model->load('Group'); $groups = $gModel->GetGroups(true); foreach ($groups as $group) { if (!$this->gadget->GetPermission('AccessGroup', $group['id'])) { continue; } $url = $this->gadget->urlMap('GroupPages', array('gid' => empty($group['fast_url']) ? $group['id'] : $group['fast_url'])); $urls[] = array('url' => $url, 'title' => '\\' . $group['title'], 'title2' => Jaws_UTF8::strlen($group['title']) >= $max_size ? Jaws_UTF8::substr($group['title'], 0, $max_size) . '...' : $group['title']); $pages = $pModel->GetPages($group['id']); foreach ($pages as $page) { if ($page['published'] === true) { $url = $this->gadget->urlMap('Pages', array('gid' => empty($group['fast_url']) ? $group['id'] : $group['fast_url'], 'pid' => empty($page['fast_url']) ? $page['base_id'] : $page['fast_url'])); $urls[] = array('url' => $url, 'title' => '\\' . $group['title'] . '\\' . $page['title'], 'title2' => Jaws_UTF8::strlen($page['title']) >= $max_size ? Jaws_UTF8::substr($page['title'], 0, $max_size) . '...' : $page['title']); } } } return $urls; }
/** * Returns an array with all available items the Menu gadget * can use * * @access public * @return array URLs array */ function Execute() { $urls = array(); $urls[] = array('url' => $this->gadget->urlMap('AlbumList'), 'title' => $this->gadget->title); //Load model $model = $this->gadget->model->load('Albums'); $albums = $model->GetAlbums(); if (!Jaws_Error::IsError($albums) && !empty($albums)) { $max_size = 20; foreach ($albums as $a) { $url = $this->gadget->urlMap('ViewAlbum', array('id' => $a['id'])); $urls[] = array('url' => $url, 'title' => Jaws_UTF8::strlen($a['name']) > $max_size ? Jaws_UTF8::substr($a['name'], 0, $max_size) . '...' : $a['name']); } } //Load model $model = $this->gadget->model->load('Groups'); $groups = $model->GetGroups(); if (!Jaws_Error::IsError($groups) && !empty($groups)) { $max_size = 20; foreach ($groups as $group) { $url = $this->gadget->urlMap('AlbumList', array('group' => $group['fast_url'])); $urls[] = array('url' => $url, 'title' => Jaws_UTF8::strlen($group['name']) > $max_size ? Jaws_UTF8::substr($group['name'], 0, $max_size) . '...' : $group['name']); } } return $urls; }
/** * Returns an array with all available items the Menu gadget * can use * * @access public * @return array URLs array */ function Execute() { $items = array(); $items[] = array('url' => $this->gadget->urlMap('DefaultAction'), 'title' => $this->gadget->title); $items[] = array('url' => $this->gadget->urlMap('Archive'), 'title' => _t('BLOG_ARCHIVE')); $items[] = array('url' => $this->gadget->urlMap('CategoriesList'), 'title' => _t('BLOG_ACTIONS_CATEGORIESLIST'), 'title2' => _t('BLOG_CATEGORIES')); $items[] = array('url' => $this->gadget->urlMap('PopularPosts'), 'title' => _t('BLOG_POPULAR_POSTS')); $items[] = array('url' => $this->gadget->urlMap('PostsAuthors'), 'title' => _t('BLOG_POSTS_AUTHORS')); //Blog model $pModel = $this->gadget->model->load('Posts'); $cModel = $this->gadget->model->load('Categories'); $categories = $cModel->GetCategories(); if (!Jaws_Error::IsError($categories)) { $max_size = 32; foreach ($categories as $cat) { $url = $this->gadget->urlMap('ShowCategory', array('id' => empty($cat['fast_url']) ? $cat['id'] : $cat['fast_url'])); $items[] = array('url' => $url, 'title' => Jaws_UTF8::strlen($cat['name']) > $max_size ? Jaws_UTF8::substr($cat['name'], 0, $max_size) . '...' : $cat['name'], 'acl_key' => 'CategoryAccess', 'acl_subkey' => $cat['id']); } } $entries = $pModel->GetEntries(''); if (!Jaws_Error::IsError($entries)) { $max_size = 32; foreach ($entries as $entry) { $url = $this->gadget->urlMap('SingleView', array('id' => empty($entry['fast_url']) ? $entry['id'] : $entry['fast_url'])); $items[] = array('url' => $url, 'title' => Jaws_UTF8::strlen($entry['title']) > $max_size ? Jaws_UTF8::substr($entry['title'], 0, $max_size) . '...' : $entry['title']); } } return $items; }
/** * Displays list of recent updated topics ordered by date * * @access public * @param mixed $gid Group ID * @return string XHTML content */ function RecentTopics($gid = '', $recent_limit = 5) { $gModel = $this->gadget->model->load('Groups'); $group = $gModel->GetGroup($gid); if (Jaws_Error::IsError($group) || empty($group)) { $group = array(); $group['id'] = 0; $group['title'] = _t('FORUMS_GROUPS_ALL'); } $tpl = $this->gadget->template->load('RecentTopics.html'); $tModel = $this->gadget->model->load('Topics'); $topics = $tModel->GetRecentTopics($group['id'], $recent_limit); if (!Jaws_Error::IsError($topics)) { // date format $date_format = $this->gadget->registry->fetch('date_format'); $date_format = empty($date_format) ? 'DN d MN Y' : $date_format; // posts per page $posts_limit = $this->gadget->registry->fetch('posts_limit'); $posts_limit = empty($posts_limit) ? 10 : (int) $posts_limit; $max_size = 128; $objDate = Jaws_Date::getInstance(); $tpl->SetBlock('recenttopics'); // title $tpl->SetVariable('action_title', _t('FORUMS_LAYOUT_RECENT_POSTS')); $tpl->SetVariable('group_title', $group['title']); foreach ($topics as $topic) { $tpl->SetBlock('recenttopics/topic'); // topic subject/link $tpl->SetVariable('lbl_topic', $topic['subject']); $tpl->SetVariable('url_topic', $this->gadget->urlMap('Posts', array('fid' => $topic['fid'], 'tid' => $topic['id']))); // post author $tpl->SetVariable('lastpost_date', $objDate->Format($topic['last_post_time'], $date_format)); $tpl->SetVariable('lastpost_date_iso', $objDate->ToISO((int) $topic['last_post_time'])); $tpl->SetVariable('message', Jaws_UTF8::substr(strip_tags($this->gadget->ParseText($topic['message'], 'Forums', 'index')), 0, $max_size) . ' ...'); $tpl->SetVariable('lbl_postedby', _t('FORUMS_POSTEDBY')); $tpl->SetVariable('username', $topic['username']); $tpl->SetVariable('nickname', $topic['nickname']); // user's profile $tpl->SetVariable('url_user', $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $topic['username']))); // post url $url_params = array('fid' => $topic['fid'], 'tid' => $topic['id']); $last_post_page = floor(($topic['replies'] - 1) / $posts_limit) + 1; if ($last_post_page > 1) { $url_params['page'] = $last_post_page; } $tpl->SetVariable('lastpost_url', $this->gadget->urlMap('Posts', $url_params)); $tpl->ParseBlock('recenttopics/topic'); } $tpl->ParseBlock('recenttopics'); } return $tpl->Get(); }
/** * Displays list of user's posts ordered by date * * @access public * @return string XHTML content */ function UserPosts() { $rqst = jaws()->request->fetch(array('user', 'page'), 'get'); $user = $rqst['user']; if (empty($user)) { return false; } $userModel = new Jaws_User(); $user = $userModel->GetUser($user); $page = empty($rqst['page']) ? 1 : (int) $rqst['page']; // posts per page $posts_limit = $this->gadget->registry->fetch('posts_limit'); $posts_limit = empty($posts_limit) ? 10 : (int) $posts_limit; $tpl = $this->gadget->template->load('UserPosts.html'); $pModel = $this->gadget->model->load('Posts'); $posts = $pModel->GetUserPosts($user['id'], $posts_limit, ($page - 1) * $posts_limit); if (!Jaws_Error::IsError($posts)) { // date format $date_format = $this->gadget->registry->fetch('date_format'); $date_format = empty($date_format) ? 'DN d MN Y' : $date_format; $max_size = 128; $objDate = Jaws_Date::getInstance(); $tpl->SetBlock('userposts'); // title $tpl->SetVariable('action_title', _t('FORUMS_USER_POSTS', $user['nickname'])); foreach ($posts as $post) { $tpl->SetBlock('userposts/post'); // topic subject/link $tpl->SetVariable('lbl_topic', $post['subject']); $tpl->SetVariable('url_topic', $this->gadget->urlMap('Posts', array('fid' => $post['fid'], 'tid' => $post['tid']))); // post author $tpl->SetVariable('insert_time', $objDate->Format($post['insert_time'], $date_format)); $tpl->SetVariable('insert_time_iso', $objDate->ToISO((int) $post['insert_time'])); $tpl->SetVariable('message', Jaws_UTF8::substr(strip_tags($this->gadget->ParseText($post['message'], 'Forums', 'index')), 0, $max_size) . ' ...'); // post url $url_params = array('fid' => $post['fid'], 'tid' => $post['tid']); $last_post_page = floor(($post['topic_replies'] - 1) / $posts_limit) + 1; if ($last_post_page > 1) { $url_params['page'] = $last_post_page; } $tpl->SetVariable('url_post', $this->gadget->urlMap('Posts', $url_params)); $tpl->ParseBlock('userposts/post'); } $post_counts = $pModel->GetUserPostsCount($user['id']); // page navigation $this->GetPagesNavigation($tpl, 'userposts', $page, $posts_limit, $post_counts, _t('FORUMS_POSTS_COUNT', $post_counts), 'UserPosts', array('user' => $user['username'])); $tpl->ParseBlock('userposts'); } return $tpl->Get(); }
/** * Returns an array with all available items the Menu gadget can use * * @access public * @return array List of URLs */ function Execute() { $urls[] = array('url' => $this->gadget->urlMap('DisplayFeeds'), 'title' => $this->gadget->title); $model = $this->gadget->model->load('Feed'); $feeds = $model->GetFeeds(); if (!Jaws_Error::isError($feeds)) { $max_size = 20; foreach ($feeds as $feed) { $url = $this->gadget->urlMap('GetFeed', array('id' => $feed['id'])); $urls[] = array('url' => $url, 'title' => Jaws_UTF8::strlen($feed['title']) > $max_size ? Jaws_UTF8::substr($feed['title'], 0, $max_size) . '...' : $feed['title']); } } return $urls; }
/** * Returns an array with all available items the Menu gadget * can use * * @access public * @return array URLs array */ function Execute() { $urls = array(); //Blocks model $model = $this->gadget->model->load('Block'); $blocks = $model->GetBlocks(true); if (!Jaws_Error::IsError($blocks)) { $max_size = 20; foreach ($blocks as $block) { $url = $this->gadget->urlMap('Block', array('id' => $block['id'])); $urls[] = array('url' => $url, 'title' => Jaws_UTF8::strlen($block['title']) > $max_size ? Jaws_UTF8::substr($block['title'], 0, $max_size) . '...' : $block['title']); } } return $urls; }
/** * Returns an array with all available items the Menu gadget can use * * @access public * @return array List of URLs */ function Execute() { $urls = array(); $urls[] = array('url' => $this->gadget->urlMap('RecentQuotes'), 'title' => $this->gadget->title); $model = $this->gadget->model->load('Groups'); $groups = $model->GetGroups(); if (!Jaws_Error::isError($groups)) { $max_size = 20; foreach ($groups as $group) { $url = $this->gadget->urlMap('ViewGroupQuotes', array('id' => $group['id'])); $urls[] = array('url' => $url, 'title' => Jaws_UTF8::strlen($group['title']) > $max_size ? Jaws_UTF8::substr($group['title'], 0, $max_size) . '...' : $group['title']); } } return $urls; }
/** * Returns an array with all available items the Menu gadget * can use * * @access public * @return array URLs array */ function Execute() { $urls[] = array('url' => $this->gadget->urlMap('Poll'), 'title' => _t('POLL_LAYOUT_LAST')); $urls[] = array('url' => $this->gadget->urlMap('Polls'), 'title' => _t('POLL_ACTIONS_POLLS')); $model = $this->gadget->model->load('Poll'); $polls = $model->GetPolls(null, true); if (!Jaws_Error::isError($polls)) { $max_size = 20; foreach ($polls as $poll) { $url = $this->gadget->urlMap('ViewPoll', array('id' => $poll['id'])); $urls[] = array('url' => $url, 'title' => Jaws_UTF8::strlen($poll['question']) > $max_size ? Jaws_UTF8::substr($poll['question'], 0, $max_size) . '...' : $poll['question']); } } return $urls; }
/** * Returns an array with all available items the Menu gadget * can use * * @access public * @return array URLs array */ function Execute() { $urls = array(); $urls[] = array('url' => $this->gadget->urlMap('View'), 'title' => $this->gadget->title); //Load model $model = $this->gadget->model->load('Category'); $categories = $model->GetCategories(); if (!Jaws_Error::isError($categories)) { $max_size = 20; foreach ($categories as $category) { $url = $this->gadget->urlMap('ViewCategory', array('id' => $category['id'])); $urls[] = array('url' => $url, 'title' => Jaws_UTF8::strlen($category['category']) > $max_size ? Jaws_UTF8::substr($category['category'], 0, $max_size) . '...' : $category['category']); } } return $urls; }
/** * Returns an array with all available items the Menu gadget * can use * * @access public * @return array URLs array */ function Execute() { $urls[] = array('url' => $this->gadget->urlMap('Categories'), 'title' => $this->gadget->title); $model = $this->gadget->model->load('Groups'); $groups = $model->GetGroups(); if (!Jaws_Error::IsError($groups)) { $max_size = 32; foreach ($groups as $group) { $title = _t('LINKDUMP_LINKS_ARCHIVE') . ' - ' . $group['title']; $gid = empty($group['fast_url']) ? $group['id'] : $group['fast_url']; $url = $this->gadget->urlMap('Category', array('id' => $gid)); $urls[] = array('url' => $url, 'title' => Jaws_UTF8::strlen($title) > $max_size ? Jaws_UTF8::substr($title, 0, $max_size - 3) . '...' : $title); } } return $urls; }
function Get($email, $name) { $code = '<a href="' . $this->encText('mailto:', true) . $this->encText($email, true) . '">' . $name . '</a>'; $javacode = '<script language="JavaScript" type="text/JavaScript">'; $i = 0; $code_l = Jaws_UTF8::strlen($code); while ($i < $code_l) { //get next part of code with random length from 15 to 20 $len = rand(15, 20); if ($i + $len > $code_l) { $len = $code_l - $i; } $part = Jaws_UTF8::substr($code, $i, $len); $javacode .= "document.write('{$part}');"; $i += $len; } $javacode .= "</script>"; return $javacode; }
/** * Look for all the terms, order them and prints them all together * * @access public * @return string XHTML template Content */ function ViewTerms() { $tpl = $this->gadget->template->load('AlphabeticList.html'); $tpl->SetBlock('list'); $tpl->SetVariable('title', $this->gadget->title); $this->SetTitle($this->gadget->title); $model = $this->gadget->model->load('Term'); $terms = $model->GetTerms(); if (!Jaws_Error::IsError($terms)) { $last_letter = null; foreach ($terms as $term) { $letter = Jaws_UTF8::substr($term['term'], 0, 1); if ($letter !== $last_letter) { $last_letter = $letter; //close opened block if (!is_null($last_letter)) { $tpl->ParseBlock('list/letter'); } $tpl->SetBlock('list/letters'); $tpl->SetVariable('letter', $letter); $tpl->SetVariable('url', $this->gadget->urlMap('ViewTerms')); $tpl->ParseBlock('list/letters'); //open new block $tpl->SetBlock('list/letter'); $tpl->SetVariable('letter', $letter); } $tpl->SetBlock('list/letter/term'); $tpl->SetVariable('term', $term['term']); $tid = empty($term['fast_url']) ? $term['id'] : $term['fast_url']; $tpl->SetVariable('url', $this->gadget->urlMap('ViewTerm', array('term' => $tid))); $tpl->SetVariable('description', $this->gadget->ParseText($term['description'])); $tpl->ParseBlock('list/letter/term'); } } if (!empty($terms)) { $tpl->ParseBlock('list/letter'); } $tpl->ParseBlock('list'); return $tpl->Get(); }
/** * Checks if fast_url already exists in a table, if it doesn't then it returns * the original fast_url (the param value). However, if it already exists then * it starts looking for a 'valid' fast_url using the 'foobar-[1...n]' schema. * * @access protected * @param string $fast_url Fast URL * @param string $table DB table name (without [[ ]]) * @param bool $unique_check must be false in update methods * @param string $field Table field where fast_url is stored * @return string Correct fast URL */ public function GetRealFastURL($fast_url, $table, $unique_check = true, $field = 'fast_url') { if (is_numeric($fast_url)) { $fast_url = '-' . $fast_url . '-'; } $fast_url = Jaws_UTF8::trim(Jaws_XSS::defilter($fast_url)); $fast_url = preg_replace(array('#[^\\p{L}[:digit:]_\\.\\-\\s]#u', '#[\\s_\\-]#u', '#\\-\\+#u'), array('', '-', '-'), Jaws_UTF8::strtolower($fast_url)); $fast_url = Jaws_UTF8::substr($fast_url, 0, 90); if (!$unique_check) { return $fast_url; } $tblReg = Jaws_ORM::getInstance()->table($table); $result = $tblReg->select("count({$field})")->where($field, $fast_url . '%', 'like')->fetchOne(); if (Jaws_Error::IsError($result) || empty($result)) { return $fast_url; } return $fast_url . '-' . $result; }
/** * it starts looking for a 'valid' meta_title using the 'foobar-[1...n]' schema. * * @access protected * @param string $meta_title Meta title * @return string Correct fast URL */ public function GetMetaTitleURL($meta_title) { if (is_numeric($meta_title)) { $meta_title = '-' . $meta_title . '-'; } $meta_title = Jaws_UTF8::trim(Jaws_XSS::defilter($meta_title)); $meta_title = preg_replace(array('#[^\\p{L}[:digit:]_\\.\\-\\s]#u', '#[\\s_\\-]#u', '#\\-\\+#u'), array('', '-', '-'), Jaws_UTF8::strtolower($meta_title)); $fast_url = Jaws_UTF8::substr($meta_title, 0, 90); return $meta_title; }
/** * Displays the recent posts of a dynamic category * * @access public * @param int $cat Category ID * @param int $limit * @return string XHTML Template content */ function CategoryEntries($cat = null, $limit = 0) { $cModel = $this->gadget->model->load('Categories'); $pModel = $this->gadget->model->load('Posts'); if (is_null($cat)) { $title = _t('BLOG_RECENT_POSTS'); } else { $category = $cModel->GetCategory($cat); if (Jaws_Error::isError($category)) { return false; } if (array_key_exists('name', $category)) { $cat = $category['id']; $title = _t('BLOG_RECENT_POSTS_BY_CATEGORY', $category['name']); } else { $cat = null; $title = _t('BLOG_RECENT_POSTS_BY_CATEGORY'); } } $entries = $pModel->GetRecentEntries($cat, (int) $limit); if (Jaws_Error::IsError($entries) || empty($entries)) { return false; } $tpl = $this->gadget->template->load('RecentPosts.html'); $tpl->SetBlock('recent_posts'); $tpl->SetVariable('cat', empty($cat) ? '0' : $cat); $tpl->SetVariable('title', $title); $date = Jaws_Date::getInstance(); foreach ($entries as $e) { $tpl->SetBlock('recent_posts/item'); $id = empty($e['fast_url']) ? $e['id'] : $e['fast_url']; $perm_url = $this->gadget->urlMap('SingleView', array('id' => $id)); $summary = $e['summary']; $text = $e['text']; // for compatibility with old versions $more_pos = Jaws_UTF8::strpos($text, '[more]'); if ($more_pos !== false) { $summary = Jaws_UTF8::substr($text, 0, $more_pos); $text = Jaws_UTF8::str_replace('[more]', '', $text); // Update this entry to split summary and body of post $pModel->SplitEntry($e['id'], $summary, $text); } $summary = empty($summary) ? $text : $summary; $summary = $this->gadget->ParseText($summary); $text = $this->gadget->ParseText($text); if (Jaws_UTF8::trim($text) != '') { $tpl->SetBlock('recent_posts/item/read-more'); $tpl->SetVariable('url', $perm_url); $tpl->SetVariable('read_more', _t('BLOG_READ_MORE')); $tpl->ParseBlock('recent_posts/item/read-more'); } $tpl->SetVariable('url', $perm_url); $tpl->SetVariable('title', $e['title']); $tpl->SetVariable('text', $summary); $tpl->SetVariable('username', $e['username']); $tpl->SetVariable('posted_by', _t('BLOG_POSTED_BY')); $tpl->SetVariable('name', $e['nickname']); $tpl->SetVariable('author-url', $this->gadget->urlMap('ViewAuthorPage', array('id' => $e['username']))); $tpl->SetVariable('createtime', $date->Format($e['publishtime'])); $tpl->SetVariable('createtime-monthname', $date->Format($e['publishtime'], 'MN')); $tpl->SetVariable('createtime-month', $date->Format($e['publishtime'], 'm')); $tpl->SetVariable('createtime-day', $date->Format($e['publishtime'], 'd')); $tpl->SetVariable('createtime-year', $date->Format($e['publishtime'], 'Y')); $tpl->SetVariable('createtime-time', $date->Format($e['publishtime'], 'g:ia')); if (empty($e['image'])) { $tpl->SetVariable('image', _t('GLOBAL_NOIMAGE')); $tpl->SetVariable('url_image', 'data:image/png;base64,'); } else { $tpl->SetVariable('image', $e['image']); $tpl->SetVariable('url_image', $GLOBALS['app']->getDataURL() . 'blog/images/' . $e['image']); } $tpl->ParseBlock('recent_posts/item'); } $tpl->ParseBlock('recent_posts'); return $tpl->Get(); }
/** * Displays search results * * @access public * @return string XHTML content of search results */ function Results() { $tpl = $this->gadget->template->load('Results.html'); $tpl->SetBlock('results'); $tpl->SetVariable('title', _t('SEARCH_RESULTS')); $post = jaws()->request->fetch(array('gadgets', 'all', 'exact', 'least', 'exclude', 'date'), 'get'); $page = jaws()->request->fetch('page', 'get'); if (is_null($page) || !is_numeric($page) || $page <= 0) { $page = 1; } $searchable = false; $model = $this->gadget->model->load('Search'); $options = $model->parseSearch($post, $searchable); if ($searchable) { $items = $model->Search($options); } $query_string = '?gadget=Search&action=Results'; foreach ($post as $option => $value) { if (!empty($value)) { $query_string .= '&' . $option . '=' . $value; } } $query_string .= '&page='; $results_limit = (int) $this->gadget->registry->fetch('results_limit'); if (empty($results_limit)) { $results_limit = 10; } if (!$searchable) { $tpl->SetBlock('results/notfound'); $min_key_len = $this->gadget->registry->fetch('Search/min_key_len'); $tpl->SetVariable('message', _t('SEARCH_STRING_TOO_SHORT', $min_key_len)); $tpl->ParseBlock('results/notfound'); } elseif (count($items) > 1) { $tpl->SetVariable('navigation', $this->GetNumberedPageNavigation($page, $results_limit, $items['_totalItems'], $query_string)); if (count($items) > 2) { $tpl->SetBlock('results/subtitle'); $tpl->SetVariable('text', _t('SEARCH_RESULTS_SUBTITLE', $items['_totalItems'], $model->implodeSearch())); $tpl->ParseBlock('results/subtitle'); } unset($items['_totalItems']); $date = Jaws_Date::getInstance(); $max_result_len = (int) $this->gadget->registry->fetch('max_result_len'); if (empty($max_result_len)) { $max_result_len = 500; } $item_counter = 0; foreach ($items as $gadget => $result) { $tpl->SetBlock('results/gadget'); $info = Jaws_Gadget::getInstance($gadget); $tpl->SetVariable('gadget_result', _t('SEARCH_RESULTS_IN_GADGETS', count($result), $model->implodeSearch(), $info->title)); $tpl->ParseBlock('results/gadget'); foreach ($result as $item) { $item_counter++; if ($item_counter <= ($page - 1) * $results_limit || $item_counter > $page * $results_limit) { continue; } $tpl->SetBlock('results/item'); $tpl->SetVariable('title', $item['title']); $tpl->SetVariable('url', $item['url']); $tpl->SetVariable('target', isset($item['outer']) && $item['outer'] ? '_blank' : '_self'); $tpl->SetVariable('image', $item['image']); if (!isset($item['parse_text']) || $item['parse_text']) { $item['snippet'] = $this->gadget->ParseText($item['snippet'], $gadget); } if (!isset($item['strip_tags']) || $item['strip_tags']) { $item['snippet'] = strip_tags($item['snippet']); } $item['snippet'] = Jaws_UTF8::substr($item['snippet'], 0, $max_result_len); $tpl->SetVariable('snippet', $item['snippet']); $tpl->SetVariable('date', $date->Format($item['date'])); $tpl->ParseBlock('results/item'); } } } else { $tpl->SetBlock('results/notfound'); header(Jaws_XSS::filter($_SERVER['SERVER_PROTOCOL']) . " 404 Not Found"); $tpl->SetVariable('message', _t('SEARCH_NO_RESULTS', $model->implodeSearch())); $tpl->ParseBlock('results/notfound'); } $tpl->ParseBlock('results'); return $tpl->Get(); }
/** * Displays a block of pages belongs to the specified group * * @access public * @param string $gadget Gadget name * @param string $action Gadget action * @param int $reference * @param array $pagination_data * @param int $user User Id * @param int $perPage * @param int $orderBy * @internal param string $gadget * @internal param mixed $limit limit recent comments (int) * @return string XHTML content */ function ShowComments($gadget, $action, $reference, $pagination_data, $user = null, $perPage = null, $orderBy = 0) { $max_size = 52; $compactView = $GLOBALS['app']->requestedActionMode == ACTION_MODE_LAYOUT; $rqst = jaws()->request->fetch(array('order', 'page'), 'get'); $page = empty($rqst['page']) ? 1 : (int) $rqst['page']; if ($GLOBALS['app']->requestedActionMode == ACTION_MODE_NORMAL && !empty($rqst['order'])) { $orderBy = (int) $rqst['order']; } if (empty($perPage)) { $perPage = $this->gadget->registry->fetch('comments_per_page'); } $cModel = $this->gadget->model->load('Comments'); $comments = $cModel->GetComments($gadget, $action, $reference, '', Comments_Info::COMMENTS_STATUS_APPROVED, $perPage, ($page - 1) * $perPage, $orderBy, $user); $comments_count = $cModel->GetCommentsCount($gadget, $action, $reference, '', '', $user); $tpl = $this->gadget->template->load('Comments.html'); $block = 'comments'; if ($compactView == true) { $block = 'comments_compact'; } $tpl->SetBlock($block); $tpl->SetVariable('title', _t('COMMENTS_COMMENTS')); $tpl->SetVariable('gadget', strtolower($gadget)); $objDate = Jaws_Date::getInstance(); $usrModel = new Jaws_User(); if (!Jaws_Error::IsError($comments) && $comments != null) { foreach ($comments as $entry) { $tpl->SetBlock($block . '/entry'); $tpl->SetVariable('postedby_lbl', _t('COMMENTS_POSTEDBY')); if ($entry['user_registered_date']) { $tpl->SetBlock($block . '/entry/registered_date'); $tpl->SetVariable('registered_date_lbl', _t('COMMENTS_USERS_REGISTERED_DATE')); $tpl->SetVariable('registered_date', $objDate->Format($entry['user_registered_date'], 'd MN Y')); $tpl->ParseBlock($block . '/entry/registered_date'); } if (!empty($entry['username'])) { // user's profile $tpl->SetVariable('user_url', $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $entry['username']))); } else { $tpl->SetVariable('user_url', Jaws_XSS::filter($entry['url'])); } $nickname = empty($entry['nickname']) ? $entry['name'] : $entry['nickname']; $email = empty($entry['user_email']) ? $entry['email'] : $entry['user_email']; $tpl->SetVariable('nickname', Jaws_XSS::filter($nickname)); $tpl->SetVariable('email', Jaws_XSS::filter($email)); $tpl->SetVariable('username', Jaws_XSS::filter($entry['username'])); // user's avatar $tpl->SetVariable('avatar', $usrModel->GetAvatar($entry['avatar'], $entry['email'], 80)); $tpl->SetVariable('insert_time', $objDate->Format($entry['createtime'])); $tpl->SetVariable('insert_time_iso', $objDate->ToISO($entry['createtime'])); $tpl->SetVariable('message', $this->gadget->ParseText($entry['msg_txt'], 'Comments', 'index')); $tpl->SetVariable('message_abbr', Jaws_UTF8::strlen($entry['msg_txt']) >= $max_size ? Jaws_UTF8::substr($entry['msg_txt'], 0, $max_size) . '...' : $entry['msg_txt']); if (Jaws_UTF8::strlen($entry['msg_txt']) >= $max_size) { $tpl->SetBlock($block . '/entry/read_more'); $tpl->SetVariable('read_more', _t('COMMENTS_READ_MORE')); switch ($entry['gadget']) { case 'Blog': $url = $GLOBALS['app']->Map->GetURLFor('Blog', 'SingleView', array('id' => $entry['reference']), true); $url = $url . '#comment' . $entry['id']; break; case 'Phoo': $url = $GLOBALS['app']->Map->GetURLFor('Phoo', 'ViewImage', array('id' => $entry['reference']), true); $url = $url . '#comment' . $entry['id']; break; case 'Shoutbox': $url = $GLOBALS['app']->Map->GetURLFor('Shoutbox', 'Comments', array(), true); $url = $url . '#comment' . $entry['id']; break; case 'Comments': $url = $GLOBALS['app']->Map->GetURLFor('Comments', 'Guestbook', array(), true); $url = $url . '#comment' . $entry['id']; break; default: $url = ''; } $tpl->SetVariable('read_more_url', $url); $tpl->ParseBlock($block . '/entry/read_more'); } if (!empty($entry['reply'])) { $tpl->SetBlock($block . '/entry/reply'); $tpl->SetVariable('lbl_replier', _t('COMMENTS_REPLIER')); $tpl->SetVariable('replier', $entry['replier_nickname']); // user's profile $tpl->SetVariable('replier_url', $GLOBALS['app']->Map->GetURLFor('Users', 'Profile', array('user' => $entry['replier_username']))); $tpl->SetVariable('reply', $entry['reply']); $tpl->ParseBlock($block . '/entry/reply'); } $reply_url =& Piwi::CreateWidget('Link', _t('COMMENTS_REPLY_TO_COMMENT'), 'javascript:replyComment();'); $tpl->SetVariable('reply-link', $reply_url->Get()); $tpl->ParseBlock($block . '/entry'); } } if (!$compactView) { $pagination_data['params']['order'] = $orderBy; // page navigation $this->GetPagesNavigation($tpl, 'comments', $page, $perPage, $comments_count, _t('COMMENTS_COMMENTS_COUNT', $comments_count), $gadget, $pagination_data['action'], $pagination_data['params']); // feeds actions $tpl->SetVariable('lbl_feeds', _t('COMMENTS_COMMENTS_XML')); $tpl->SetVariable('atom_url', $this->gadget->urlMap('RecentCommentsAtom', array('gadgetname' => $gadget, 'actionname' => $action, 'reference' => $reference))); $tpl->SetVariable('rss_url', $this->gadget->urlMap('RecentCommentsRSS', array('gadgetname' => $gadget, 'actionname' => $action, 'reference' => $reference))); } $tpl->ParseBlock($block); return $tpl->Get(); }
/** * Save changes on an edited blog entry and shows the entries list on admin section * * @access public */ function SaveEditEntry() { $names = array('id', 'edit_timestamp:array', 'pubdate', 'categories:array', 'title', 'fasturl', 'meta_keywords', 'meta_desc', 'tags', 'deleteImage', 'allow_comments:array', 'published', 'trackback_to'); $post = jaws()->request->fetch($names, 'post'); $content = jaws()->request->fetch(array('summary_block', 'text_block'), 'post', 'strip_crlf'); $post['trackback_to'] = str_replace("\r\n", "\n", $post['trackback_to']); $pModel = $this->gadget->model->loadAdmin('Posts'); $tModel = $this->gadget->model->loadAdmin('Trackbacks'); $id = (int) $post['id']; $pubdate = null; if (isset($post['edit_timestamp']) && $post['edit_timestamp'][0] == 'yes') { $pubdate = $post['pubdate']; } $post['categories'] = !empty($post['categories']) ? $post['categories'] : array(); foreach ($post['categories'] as $cat) { if (!$this->gadget->GetPermission('CategoryManage', $cat)) { return Jaws_HTTPError::Get(403); } } // Upload blog image $image = false; if ($post['deleteImage'] == 'false') { $image = null; if (count($_FILES) > 0 && !empty($_FILES['image_file']['name'])) { $targetDir = JAWS_DATA . 'blog' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR; $res = Jaws_Utils::UploadFiles($_FILES, $targetDir, 'jpg,gif,png,jpeg,bmp', false); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse($res->getMessage(), RESPONSE_ERROR); } elseif (empty($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('GLOBAL_ERROR_UPLOAD_4'), RESPONSE_ERROR); } else { $image = $res['image_file'][0]['host_filename']; // Delete old image $model = $this->gadget->model->load('Posts'); $blogEntry = $model->GetEntry($id); if (!empty($blogEntry['image'])) { Jaws_Utils::Delete($targetDir . $blogEntry['image']); } } } } else { // Delete old image $model = $this->gadget->model->load('Posts'); $blogEntry = $model->GetEntry($id); if (!empty($blogEntry['image'])) { $targetDir = JAWS_DATA . 'blog' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR; Jaws_Utils::Delete($targetDir . $blogEntry['image']); } } $pModel->UpdateEntry($id, $post['categories'], $post['title'], $content['summary_block'], $content['text_block'], $image, $post['fasturl'], $post['meta_keywords'], $post['meta_desc'], $post['tags'], isset($post['allow_comments'][0]), $post['trackback_to'], $post['published'], $pubdate); if (!Jaws_Error::IsError($id)) { if ($this->gadget->registry->fetch('trackback') == 'true') { $to = explode("\n", $post['trackback_to']); $link = $this->gadget->urlMap('SingleView', array('id' => $id), true); $title = $post['title']; $text = $content['text_block']; if (Jaws_UTF8::strlen($text) > 250) { $text = Jaws_UTF8::substr($text, 0, 250) . '...'; } $tModel->SendTrackback($title, $text, $link, $to); } } Jaws_Header::Location(BASE_SCRIPT . '?gadget=Blog&action=EditEntry&id=' . $id); }
/** * Displays a given blog entry according to given parameters * * @access public * @param object $tpl Jaws_Template object * @param string $tpl_base_block Template block name * @param int $entry entry id * @param bool $show_summary Show post summary * @return string XHTML template content */ function ShowEntry(&$tpl, $tpl_base_block, $entry, $show_summary = true) { $tpl->SetBlock("{$tpl_base_block}/entry"); $tpl->SetVariablesArray($entry); $tpl->SetVariable('posted_by', _t('BLOG_POSTED_BY')); $tpl->SetVariable('author-url', $this->gadget->urlMap('ViewAuthorPage', array('id' => $entry['username']))); $date = Jaws_Date::getInstance(); $tpl->SetVariable('createtime-iso', $date->ToISO($entry['publishtime'])); $tpl->SetVariable('createtime', $date->Format($entry['publishtime'])); $tpl->SetVariable('createtime-monthname', $date->Format($entry['publishtime'], 'MN')); $tpl->SetVariable('createtime-monthabbr', $date->Format($entry['publishtime'], 'M')); $tpl->SetVariable('createtime-month', $date->Format($entry['publishtime'], 'm')); $tpl->SetVariable('createtime-dayname', $date->Format($entry['publishtime'], 'DN')); $tpl->SetVariable('createtime-dayabbr', $date->Format($entry['publishtime'], 'D')); $tpl->SetVariable('createtime-day', $date->Format($entry['publishtime'], 'd')); $tpl->SetVariable('createtime-year', $date->Format($entry['publishtime'], 'Y')); $tpl->SetVariable('createtime-time', $date->Format($entry['publishtime'], 'g:ia')); $tpl->SetVariable('entry-visits', _t('BLOG_ENTRY_VISITS', $entry['clicks'])); if (empty($entry['image'])) { $tpl->SetVariable('image', _t('GLOBAL_NOIMAGE')); $tpl->SetVariable('url_image', 'data:image/png;base64,'); } else { $tpl->SetVariable('image', $entry['image']); $tpl->SetVariable('url_image', $GLOBALS['app']->getDataURL() . 'blog/images/' . $entry['image']); } $id = empty($entry['fast_url']) ? $entry['id'] : $entry['fast_url']; $perm_url = $this->gadget->urlMap('SingleView', array('id' => $id)); $summary = $entry['summary']; $text = $entry['text']; // for compatibility with old versions $more_pos = Jaws_UTF8::strpos($text, '[more]'); if ($more_pos !== false) { $summary = Jaws_UTF8::substr($text, 0, $more_pos); $text = Jaws_UTF8::str_replace('[more]', '', $text); // Update this entry to split summary and body of post $model = $this->gadget->model->load('Posts'); $model->SplitEntry($entry['id'], $summary, $text); } $summary = empty($summary) ? $text : $summary; $summary = $this->gadget->ParseText($summary); $text = $this->gadget->ParseText($text); if ($show_summary) { if (Jaws_UTF8::trim($text) != '') { $tpl->SetBlock("{$tpl_base_block}/entry/read-more"); $tpl->SetVariable('url', $perm_url); $tpl->SetVariable('read_more', _t('BLOG_READ_MORE')); $tpl->ParseBlock("{$tpl_base_block}/entry/read-more"); } $tpl->SetVariable('text', $summary); } else { $GLOBALS['app']->Layout->AddHeadLink($this->gadget->urlMap('Atom'), 'alternate', 'application/atom+xml', 'Atom - All'); $GLOBALS['app']->Layout->AddHeadLink($this->gadget->urlMap('RSS'), 'alternate', 'application/rss+xml', 'RSS 2.0 - All'); $tpl->SetVariable('text', empty($text) ? $summary : $text); } $tpl->SetVariable('permanent-link', $perm_url); $pos = 1; $tpl->SetVariable('posted_in', _t('BLOG_POSTED_IN')); foreach ($entry['categories'] as $cat) { $tpl->SetBlock("{$tpl_base_block}/entry/category"); $tpl->SetVariable('id', $cat['id']); $tpl->SetVariable('name', $cat['name']); $cid = empty($cat['fast_url']) ? $cat['id'] : $cat['fast_url']; $tpl->SetVariable('url', $this->gadget->urlMap('ShowCategory', array('id' => $cid))); if ($pos == count($entry['categories'])) { $tpl->SetVariable('separator', ''); } else { $tpl->SetVariable('separator', ','); } $pos++; $tpl->ParseBlock("{$tpl_base_block}/entry/category"); } $commentsCount = 0; $comments = _t('BLOG_NO_COMMENT'); if (Jaws_Gadget::IsGadgetInstalled('Comments')) { $cModel = Jaws_Gadget::getInstance('Comments')->model->load('Comments'); $commentsCount = $cModel->GetCommentsCount('Blog', 'Post', $entry['id'], '', Comments_Info::COMMENTS_STATUS_APPROVED); if (!empty($commentsCount)) { $comments = _t('BLOG_HAS_N_COMMENTS', $commentsCount); } } if ($commentsCount != 0 || $entry['allow_comments'] === true && $this->gadget->registry->fetch('allow_comments') == 'true' && $this->gadget->registry->fetch('allow_comments', 'Comments') != 'false') { $tpl_block = $show_summary ? 'comment-link' : 'comments-statistic'; $tpl->SetBlock("{$tpl_base_block}/entry/{$tpl_block}"); $tpl->SetVariable('url', $perm_url); $tpl->SetVariable('text_comments', $comments); $tpl->SetVariable('num_comments', $commentsCount); $tpl->ParseBlock("{$tpl_base_block}/entry/{$tpl_block}"); } // Show Tags if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $tagsHTML = Jaws_Gadget::getInstance('Tags')->action->load('Tags'); $tagsHTML->loadReferenceTags('Blog', 'post', $entry['id'], $tpl, 'single_view/entry'); } // Show Rating if (Jaws_Gadget::IsGadgetInstalled('Rating')) { $ratingHTML = Jaws_Gadget::getInstance('Rating')->action->load('RatingTypes'); $ratingHTML->loadReferenceRating('Blog', 'post', $entry['id'], 0, $tpl, 'single_view/entry'); } $tpl->ParseBlock("{$tpl_base_block}/entry"); return $tpl->Get(); }
/** * metaWeblog.editPost * * @access public * @param array $params array of params * @return XML_RPC_Response object */ function metaWeblog_editPost($params) { $post_id = getScalarValue($params, 0); $user = getScalarValue($params, 1); $password = getScalarValue($params, 2); $userInfo = userAuthentication($user, $password); if (Jaws_Error::IsError($userInfo)) { return new XML_RPC_Response(0, $GLOBALS['XML_RPC_erruser'] + 4, _t('GLOBAL_ERROR_LOGIN_WRONG')); } if (!GetBlogPermission($user, 'AddEntries')) { return new XML_RPC_Response(0, $GLOBALS['XML_RPC_erruser'] + 3, _t('GLOBAL_ERROR_NO_PRIVILEGES')); } $struct = XML_RPC_decode($params->getParam(3)); $cats = $struct['categories']; $catsModel = Jaws_Gadget::getInstance('Blog')->model->load('Categories'); if (Jaws_Error::isError($catsModel)) { return new XML_RPC_Response(0, $GLOBALS['XML_RPC_erruser'] + 2, $catsModel->GetMessage()); } $categories = array(); foreach ($cats as $cat) { $catInfo = $catsModel->GetCategoryByName($cat); if (Jaws_Error::IsError($catInfo)) { return new XML_RPC_Response(0, $GLOBALS['XML_RPC_erruser'] + 2, $catInfo->GetMessage()); } if (isset($catInfo['id'])) { $categories[] = $catInfo['id']; } } $title = $struct['title']; if (!isset($struct['mt_text_more'])) { if (false !== ($more_pos = Jaws_UTF8::strpos($struct['description'], '<!--more-->'))) { $summary = Jaws_UTF8::substr($struct['description'], 0, $more_pos); $content = Jaws_UTF8::substr($struct['description'], $more_pos + 11); } else { $summary = $struct['description']; $content = ''; } } else { $summary = $struct['description']; $content = $struct['mt_text_more']; } $summary = parseContent($summary); $content = parseContent($content); // allow comments if (isset($struct['mt_allow_comments'])) { $allow_c = (bool) $struct['mt_allow_comments']; } else { $allow_c = (bool) $GLOBALS['app']->Registry->fetch('allow_comments'); } // published $publish = getScalarValue($params, 4); // tags $tags = isset($struct['mt_keywords']) ? $struct['mt_keywords'] : ''; // publish time $timestamp = null; if (isset($struct['date_created_gmt'])) { $date = date_parse_from_format('Ymd\\TH:i:s', $struct['date_created_gmt']); $date = mktime($date['hour'], $date['minute'], $date['second'], $date['month'], $date['day'], $date['year']); $timestamp = date('Y-m-d H:i:s', $date); } // trackbacks $trackbacks = ''; if (isset($struct['mt_tb_ping_urls'])) { $trackbacks = implode("\n", $struct['mt_tb_ping_urls']); } $postModel = Jaws_Gadget::getInstance('Blog')->model->loadAdmin('Posts'); $blog_result = $postModel->UpdateEntry($post_id, $categories, $title, $summary, $content, null, '', '', '', $tags, $allow_c, $trackbacks, $publish, $timestamp); if (Jaws_Error::IsError($blog_result)) { return new XML_RPC_Response(0, $GLOBALS['XML_RPC_erruser'] + 2, $blog_result->GetMessage()); } return new XML_RPC_Response(new XML_RPC_Value('1', 'boolean')); }
/** * Parses a search phrase to find the excluding matches, exact matches, * any matches and all other words * * @access public * @param string $phrase Phrase to parse * @param array $searchable List of searchable gadgets * @return array An array with the following indexes (and results): * - all, exact, least and exclude */ function parseSearch($options, &$searchable) { $phrase = $options['all']; if (!empty($phrase)) { $phrase .= chr(32); } $newOptions = array('all' => '', 'exact' => '', 'least' => '', 'exclude' => '', 'date' => ''); $size = Jaws_UTF8::strlen($phrase); $lastKey = ''; $tmpWord = ''; for ($i = 0; $i < $size; $i++) { $word = Jaws_UTF8::substr($phrase, $i, 1); $ord = Jaws_UTF8::ord($word); $tmpWord .= $word; switch ($ord) { case 34: // Quotes.. if ($lastKey == 'exact') { //Open exact was open, we are closing it $newOptions['exact'] .= Jaws_UTF8::substr($tmpWord, 1, Jaws_UTF8::strlen($tmpWord) - 2); $lastKey = ''; $tmpWord = ''; } else { if (empty($lastKey)) { $lastKey = 'exact'; //We open the exact match } } break; case 43: //Plus if ($lastKey != 'exact') { $lastKey = 'least'; } break; case 45: //Minus if ($lastKey != 'exclude') { $lastKey = 'exclude'; } break; case 32: //Space if ($lastKey != 'exact' && !empty($lastKey)) { if ($lastKey != 'all') { $substrCount = 1; if ($tmpWord[0] == ' ') { $substrCount = 2; } $newOptions[$lastKey] .= Jaws_UTF8::substr($tmpWord, $substrCount); } else { $newOptions[$lastKey] .= $tmpWord; } $lastKey = ''; $tmpWord = ''; } break; default: //Any other word opens all if (empty($lastKey)) { $lastKey = 'all'; } break; } } $options['all'] = ''; $min_key_len = $this->gadget->registry->fetch('min_key_len'); foreach (array_keys($newOptions) as $option) { if (!empty($newOptions[$option])) { $options[$option] = trim(isset($options[$option]) ? $options[$option] . ' ' . $newOptions[$option] : $newOptions[$option]); } $content = isset($options[$option]) ? $options[$option] : ''; $content = $content; $content = Jaws_UTF8::strtolower(Jaws_UTF8::trim($content)); if (Jaws_UTF8::strlen($content) >= $min_key_len) { $searchable = true; } $options[$option] = ''; switch ($option) { case 'exclude': case 'least': case 'all': $options[$option] = array_filter(explode(' ', $content)); break; case 'exact': $options[$option] = array($content); break; case 'date': if (in_array($content, array('past_1month', 'past_2month', 'past_3month', 'past_6month', 'past_1year', 'anytime'))) { $options[$option] = array($content); } else { $options[$option] = array('anytime'); } break; } } return $options; }
/** * This adds a recipient to the mail to send. * * @access public * @param string $recipients The recipients to add. * @param string $inform_type Inform type(To, Bcc, Cc) * @return bool True */ function AddRecipient($recipients = '', $inform_type = 'To') { $valid_recipients = array(); $recipients = array_filter(array_map('Jaws_UTF8::trim', explode(',', $recipients))); foreach ($recipients as $key => $recipient) { if (false !== ($ltPos = Jaws_UTF8::strpos($recipient, '<'))) { $ename = Jaws_UTF8::encode_mimeheader(Jaws_UTF8::substr($recipient, 0, $ltPos)); $email = Jaws_UTF8::substr($recipient, $ltPos + 1, -1); $recipients[$key] = $ename . "<{$email}>"; } else { $ename = ''; $email = $recipient; $recipients[$key] = $email; } // check blocked domains if (false !== strpos($this->blocked_domains, "\n" . substr(strrchr($email, '@'), 1))) { continue; } $valid_recipients[] = $recipients[$key]; } if (empty($valid_recipients)) { if (!empty($this->site_name)) { $valid_recipients[] = Jaws_UTF8::encode_mimeheader($this->site_name) . ' <' . $this->site_email . '>'; } else { $valid_recipients[] = $this->site_email; } } switch (strtolower($inform_type)) { case 'to': $this->headers['To'] = (array_key_exists('To', $this->headers) ? $this->headers['To'] . ',' : '') . implode(',', $valid_recipients); break; case 'cc': $this->headers['Cc'] = (array_key_exists('Cc', $this->headers) ? $this->headers['Cc'] . ',' : '') . implode(',', $valid_recipients); break; } $this->recipient = array_merge($this->recipient, $valid_recipients); return true; }
/** * Find length of initial segment matching mask * @see http://www.php.net/strspn */ static function strspn($str, $mask, $start = null, $length = null) { $mask = preg_replace('!([\\\\\\-\\]\\[/^])!', '\\\\${1}', $mask); if ($start !== null || $length !== null) { $str = Jaws_UTF8::substr($str, $start, $length); } preg_match('/^[' . $mask . ']+/u', $str, $matches); if (isset($matches[0])) { return Jaws_UTF8::strlen($matches[0]); } return 0; }
/** * Create ATOM struct of recent comments * * @access private * @param string $gadget Gadget name * @param string $action Action name * @param int $reference Reference Id * @param string $feed_type feed type * @return object Can return the Atom Object */ function GetRecentCommentsAtomStruct($gadget, $action = null, $reference = null, $feed_type = 'atom') { $max_title_size = 80; $cModel = $this->gadget->model->load('Comments'); $comments = $cModel->GetComments($gadget, $action, $reference, '', array(Comments_Info::COMMENTS_STATUS_APPROVED)); if (Jaws_Error::IsError($comments)) { return new Jaws_Error(_t('COMMENTS_ERROR_GETTING_COMMENTS_ATOMSTRUCT')); } $commentAtom = new Jaws_AtomFeed(); $siteURL = $GLOBALS['app']->GetSiteURL('/'); $params = array('gadgetname' => $gadget); if (!empty($action)) { $params['actionname'] = $action; } if (!empty($reference)) { $params['reference'] = $reference; } $url = $this->gadget->urlMap($feed_type == 'atom' ? 'RecentCommentsAtom' : 'RecentCommentsRSS', $params, true); $commentAtom->SetTitle($this->gadget->registry->fetch('site_name', 'Settings')); $commentAtom->SetLink($url); $commentAtom->SetId($siteURL); $commentAtom->SetAuthor($this->gadget->registry->fetch('site_author', 'Settings'), $GLOBALS['app']->GetSiteURL('/'), $this->gadget->registry->fetch('gate_email', 'Settings')); $commentAtom->SetGenerator('JAWS ' . $GLOBALS['app']->Registry->fetch('version')); $commentAtom->SetCopyright($this->gadget->registry->fetch('site_copyright', 'Settings')); $commentAtom->SetTagLine(_t('COMMENTS_RECENT_COMMENTS', _t(strtoupper($gadget) . '_TITLE'))); $objDate = Jaws_Date::getInstance(); $site = preg_replace('/(.*)\\/.*/i', '\\1', $commentAtom->Link->HRef); foreach ($comments as $c) { $entry_id = $c['reference']; $entry = new AtomEntry(); $entry->SetTitle(Jaws_UTF8::strlen($c['msg_txt']) >= $max_title_size ? Jaws_UTF8::substr($c['msg_txt'], 0, $max_title_size) . '...' : $c['msg_txt']); $entry->SetId("urn:gadget:{$gadget}:action:{$action}:reference:{$reference}:comment:{$c['id']}"); switch ($gadget) { case 'Blog': // So we can use the UrlMapping feature. $url = $GLOBALS['app']->Map->GetURLFor('Blog', 'SingleView', array('id' => $entry_id), true); $url = $url . htmlentities('#comment' . $c['id']); $entry->SetLink($url); break; case 'Phoo': $url = $GLOBALS['app']->Map->GetURLFor('Phoo', 'ViewImage', array('id' => $entry_id), true); $url = $url . htmlentities('#comment' . $c['id']); $entry->SetLink($url); break; case 'Shoutbox': $url = $GLOBALS['app']->Map->GetURLFor('Shoutbox', 'Comments', array(), true); $url = $url . htmlentities('#comment' . $c['id']); $entry->SetLink($url); break; } $content = Jaws_String::AutoParagraph($c['msg_txt']); $entry->SetSummary($content, 'html'); $entry->SetContent($content, 'html'); $entry->SetAuthor($c['name'], $commentAtom->Link->HRef, $c['email']); $entry->SetPublished($objDate->ToISO($c['insert_time'])); $entry->SetUpdated($objDate->ToISO($c['insert_time'])); $commentAtom->AddEntry($entry); if (!isset($last_modified)) { $last_modified = $c['insert_time']; } } if (isset($last_modified)) { $commentAtom->SetUpdated($objDate->ToISO($last_modified)); } else { $commentAtom->SetUpdated($objDate->ToISO(date('Y-m-d H:i:s'))); } return $commentAtom; }
/** * Create ATOM struct of a given category * * @access public * @param int $category Category ID * @param string $feed_type OPTIONAL feed type * @return mixed Can return the Atom Object or Jaws_Error on error */ function GetCategoryAtomStruct($category, $feed_type = 'atom') { $model = $this->gadget->model->load('Categories'); $catInfo = $model->GetCategory($category); if (Jaws_Error::IsError($catInfo)) { return new Jaws_Error(_t('BLOG_ERROR_GETTING_CATEGORIES_ATOMSTRUCT')); } $now = Jaws_DB::getInstance()->date(); $blogTable = Jaws_ORM::getInstance()->table('blog'); $blogTable->select('blog.id:integer', 'user_id:integer', 'blog_entrycat.category_id:integer', 'username', 'email', 'nickname', 'title', 'fast_url', 'summary', 'text', 'blog.publishtime', 'blog.updatetime', 'clicks:integer', 'comments:integer', 'allow_comments:boolean', 'published:boolean')->join('users', 'blog.user_id', 'users.id')->join('blog_entrycat', 'blog.id', 'blog_entrycat.entry_id'); $blogTable->where('published', true)->and()->where('blog.publishtime', $now, '<='); $blogTable->and()->where('blog_entrycat.category_id', $catInfo['id']); $result = $blogTable->orderby('blog.publishtime desc')->fetchAll(); if (Jaws_Error::IsError($result)) { return new Jaws_Error(_t('BLOG_ERROR_GETTING_CATEGORIES_ATOMSTRUCT')); } $cid = empty($catInfo['fast_url']) ? $catInfo['id'] : Jaws_XSS::filter($catInfo['fast_url']); $categoryAtom = new Jaws_AtomFeed(); $siteURL = $GLOBALS['app']->GetSiteURL('/'); $url = $this->gadget->urlMap($feed_type == 'atom' ? 'ShowAtomCategory' : 'ShowRSSCategory', array('id' => $cid), true); $categoryAtom->SetTitle($this->gadget->registry->fetch('site_name', 'Settings')); $categoryAtom->SetLink($url); $categoryAtom->SetId($siteURL); $categoryAtom->SetTagLine($catInfo['name']); $categoryAtom->SetAuthor($this->gadget->registry->fetch('site_author', 'Settings'), $siteURL, $this->gadget->registry->fetch('gate_email', 'Settings')); $categoryAtom->SetGenerator('JAWS ' . $GLOBALS['app']->Registry->fetch('version')); $categoryAtom->SetCopyright($this->gadget->registry->fetch('site_copyright', 'Settings')); $objDate = Jaws_Date::getInstance(); foreach ($result as $r) { $entry = new AtomEntry(); $entry->SetTitle($r['title']); $post_id = empty($r['fast_url']) ? $r['id'] : $r['fast_url']; $url = $this->gadget->urlMap('SingleView', array('id' => $post_id), true); $entry->SetLink($url); $entry->SetId($url); $summary = $r['summary']; $text = $r['text']; // for compatibility with old versions $more_pos = Jaws_UTF8::strpos($text, '[more]'); if ($more_pos !== false) { $summary = Jaws_UTF8::substr($text, 0, $more_pos); $text = Jaws_UTF8::str_replace('[more]', '', $text); // Update this entry to split summary and body of post $model = $this->gadget->model->load('Posts'); $model->SplitEntry($r['id'], $summary, $text); } $summary = empty($summary) ? $text : $summary; $summary = $this->gadget->ParseText($summary); $text = $this->gadget->ParseText($text); $entry->SetSummary($summary, 'html'); $entry->SetContent($text, 'html'); $email = $r['email']; $entry->SetAuthor($r['nickname'], $categoryAtom->Link->HRef, $email); $entry->SetPublished($objDate->ToISO($r['publishtime'])); $entry->SetUpdated($objDate->ToISO($r['updatetime'])); $categoryAtom->AddEntry($entry); if (!isset($last_modified)) { $last_modified = $r['updatetime']; } } if (isset($last_modified)) { $categoryAtom->SetUpdated($objDate->ToISO($last_modified)); } else { $categoryAtom->SetUpdated($objDate->ToISO(date('Y-m-d H:i:s'))); } return $categoryAtom; }
/** * Builds a list from textilized code * * @access private * @param string $block The Code to be parsed * @return string XHTML code */ function BuildList($block) { //remove newline at first and end of block $block = Jaws_UTF8::substr($block[0], 1, -1); //walk line by line $ret = "\n"; $lines = array_filter(preg_split("/\n/u", $block)); //build an item array $cnt = 0; $items = array(); foreach ($lines as $line) { //get intendion level $lvl = floor(strspn($line, ' ') / 2); $lvl += strspn($line, "\t"); //remove indents $line = preg_replace('/^[\\s|\\t]+/smu', '', $line); if (empty($line)) { continue; } //get type of list $type = $line[0] == '-' ? 'ol' : 'ul'; // remove bullet and following spaces $line = preg_replace('/^[\\*|\\-]\\s*/smu', '', $line); //add item to the list $items[$cnt]['level'] = $lvl; $items[$cnt]['type'] = $type; $items[$cnt]['text'] = $line; //increase counter $cnt++; } $level = -1; $opens = array(); foreach ($items as $item) { if ($item['level'] > $level) { //open new list $ret .= "\n<" . $item['type'] . ">\n"; array_push($opens, $item['type']); } else { if ($item['level'] < $level) { //close last item $ret .= "</li>\n"; for ($i = 0; $i < $level - $item['level']; $i++) { //close higher lists $ret .= '</' . array_pop($opens) . ">\n</li>\n"; } } else { if ($item['type'] != $opens[count($opens) - 1]) { //close last list and open new $ret .= '</' . array_pop($opens) . ">\n</li>\n"; $ret .= "\n<" . $item['type'] . ">\n"; array_push($opens, $item['type']); } else { //close last item $ret .= "</li>\n"; } } } //remember current level and type $level = $item['level']; //print item $ret .= '<li class="level' . $item['level'] . '">'; $ret .= '<span class="li">' . $item['text'] . '</span>'; } //close remaining items and lists while ($open = array_pop($opens)) { $ret .= "</li>\n"; $ret .= '</' . $open . ">\n"; } return $ret; }
/** * Build a new array with filtered data * * @access public * @param string $requester Requester gadget name * @param string $gadget Gadget name * @param string $term Search term * @param int $status Spam status (approved=1, waiting=2, spam=3) * @param mixed $offset Data offset (numeric/boolean) * @param int $orderBy Data order * @return array Filtered Comments */ function GetDataAsArray($requester, $gadget, $term, $status, $offset, $orderBy) { $data = array(); $cModel = $this->gadget->model->load('Comments'); $comments = $cModel->GetComments($gadget, '', '', $term, $status, 15, $offset, $orderBy); if (Jaws_Error::IsError($comments)) { return $data; } $date = Jaws_Date::getInstance(); $data = array(); foreach ($comments as $row) { $newRow = array(); $newRow['__KEY__'] = $row['id']; if ($requester == $this->gadget->name) { $newRow['gadget'] = _t(strtoupper($row['gadget']) . '_TITLE'); } $comment = Jaws_UTF8::strlen($row['msg_txt']) > 25 ? Jaws_UTF8::substr($row['msg_txt'], 0, 22) . '...' : $row['msg_txt']; $comment = "<abbr title='" . $row['msg_txt'] . "'>{$comment}</abbr>"; $link =& Piwi::CreateWidget('Link', $comment, "javascript:editComment(this, '{$row['id']}');"); $newRow['comment'] = $link->Get(); $newRow['name'] = $row['name']; $newRow['created'] = $date->Format($row['insert_time']); if ($row['status'] == Comments_Info::COMMENTS_STATUS_APPROVED) { $status = _t('COMMENTS_STATUS_APPROVED'); } elseif ($row['status'] == Comments_Info::COMMENTS_STATUS_WAITING) { $status = _t('COMMENTS_STATUS_WAITING'); } elseif ($row['status'] == Comments_Info::COMMENTS_STATUS_SPAM) { $status = _t('COMMENTS_STATUS_SPAM'); } elseif ($row['status'] == Comments_Info::COMMENTS_STATUS_PRIVATE) { $status = _t('COMMENTS_STATUS_PRIVATE'); } $newRow['status'] = $status; $data[] = $newRow; } return $data; }
/** * Displays entries by tags similarity * * @access public * @param string $gadget Gadget name * @param int $user Only show user tags? * @return string XHTML template content */ function TagsSimilarity($gadget, $user) { if (empty(self::$mainRequestTags)) { return false; } $model = $this->gadget->model->load('Tags'); $references = $model->GetSimilartyTags(self::$mainRequestTags, $gadget, $user); if (Jaws_Error::IsError($references) || empty($references)) { return false; } $gadgetReferences = array(); // grouping references by gadget/action for one time call hook per gadget foreach ($references as $reference) { if ($reference['gadget'] == self::$mainRequestReference['gadget'] && $reference['action'] == self::$mainRequestReference['action'] && $reference['reference'] == self::$mainRequestReference['reference']) { continue; } $gadgetReferences[$reference['gadget']][$reference['action']][] = $reference['reference']; } // call gadget hook foreach ($gadgetReferences as $gadget => $actions) { // load gadget $objGadget = Jaws_Gadget::getInstance($gadget); if (Jaws_Error::IsError($objGadget)) { continue; } // load hook $objHook = $objGadget->hook->load('Tags'); if (Jaws_Error::IsError($objHook)) { continue; } // communicate with gadget Tags hook foreach ($actions as $action => $action_references) { // call execute method $result = $objHook->Execute($action, $action_references); if (!Jaws_Error::IsError($result) && !empty($result)) { $gadgetReferences[$gadget][$action] = $result; } else { $gadgetReferences[$gadget][$action] = array(); } } } $objDate = Jaws_Date::getInstance(); $max_result_len = (int) $this->gadget->registry->fetch('max_result_len'); if (empty($max_result_len)) { $max_result_len = 500; } $tpl = $this->gadget->template->load('Similarity.html'); $tpl->SetBlock('similarity'); $tpl->SetVariable('title', _t('TAGS_SIMILARITY', $gadget)); // provide return result foreach ($references as $reference) { if (!@array_key_exists($reference['reference'], $gadgetReferences[$reference['gadget']][$reference['action']])) { continue; } $reference = $gadgetReferences[$reference['gadget']][$reference['action']][$reference['reference']]; $tpl->SetBlock('similarity/reference'); $tpl->SetVariable('title', $reference['title']); $tpl->SetVariable('url', $reference['url']); $tpl->SetVariable('target', @$reference['outer'] ? '_blank' : '_self'); $tpl->SetVariable('image', $reference['image']); if (!isset($reference['parse_text']) || $reference['parse_text']) { $reference['snippet'] = $this->gadget->ParseText($reference['snippet'], $gadget); } if (!isset($reference['strip_tags']) || $reference['strip_tags']) { $reference['snippet'] = strip_tags($reference['snippet']); } $reference['snippet'] = Jaws_UTF8::substr($reference['snippet'], 0, $max_result_len); $tpl->SetVariable('snippet', $reference['snippet']); $tpl->SetVariable('date', $objDate->Format($reference['date'])); $tpl->ParseBlock('similarity/reference'); } $tpl->ParseBlock('similarity'); return $tpl->Get(); }
/** * Display a Tag * * @access public * @return string XHTML template content */ function ViewTag() { $get = jaws()->request->fetch(array('tag', 'tagged_gadget', 'page', 'user'), 'get'); $tag = $get['tag']; $gadget = $get['tagged_gadget']; $user = (int) $get['user']; if (!empty($user) && $user != $GLOBALS['app']->Session->GetAttribute('user')) { return Jaws_HTTPError::Get(403); } $page = $get['page']; if (is_null($page) || !is_numeric($page) || $page <= 0) { $page = 1; } $limit = (int) $this->gadget->registry->fetch('tag_results_limit'); if (empty($limit)) { $limit = 10; } $tagsModel = $this->gadget->model->load('Tags'); // Fetch tag references count(for paging) $referencesCount = $tagsModel->GetTagsCount($gadget, $tag, $user); $references = array(); if ($referencesCount > 0) { // Fetch tag references $references = $tagsModel->GetTags($gadget, $tag, $user, $limit, ($page - 1) * $limit); if (Jaws_Error::IsError($references)) { return false; } } $gadgetReferences = array(); // grouping references by gadget for one time call hook per gadget foreach ($references as $reference) { $gadgetReferences[$reference['gadget']][$reference['action']][] = $reference['reference']; } $tpl = $this->gadget->template->load('Tag.html'); $tpl->SetBlock('tag'); $tpl->SetVariable('title', _t('TAGS_VIEW_TAG', $tag)); // page navigation $this->GetPagesNavigation($tpl, 'tag', $page, $limit, $referencesCount, _t('TAGS_TAG_ITEM_COUNT', $referencesCount), 'ViewTag', array('tag' => $tag)); if (count($references) > 2) { $tpl->SetBlock('tag/subtitle'); $tpl->SetVariable('text', _t('SEARCH_RESULTS_SUBTITLE', $referencesCount, $tag)); $tpl->ParseBlock('tag/subtitle'); } $objDate = Jaws_Date::getInstance(); $max_result_len = (int) $this->gadget->registry->fetch('max_result_len'); if (empty($max_result_len)) { $max_result_len = 500; } // call gadget hook foreach ($gadgetReferences as $gadget => $references) { // load gadget $objGadget = Jaws_Gadget::getInstance($gadget); if (Jaws_Error::IsError($objGadget)) { continue; } // load hook $objHook = $objGadget->hook->load('Tags'); if (Jaws_Error::IsError($objHook)) { continue; } // call execute method $result = $objHook->Execute($references); if (!Jaws_Error::IsError($result) && !empty($result)) { $tpl->SetBlock('tags/gadget'); $tpl->SetVariable('gadget_result', _t('SEARCH_RESULTS_IN_GADGETS', count($result), 'TEST', $objGadget->title)); $tpl->ParseBlock('tags/gadget'); foreach ($result as $reference) { $tpl->SetBlock('tag/tag_item'); $tpl->SetVariable('title', $reference['title']); $tpl->SetVariable('url', $reference['url']); $tpl->SetVariable('target', @$reference['outer'] ? '_blank' : '_self'); $tpl->SetVariable('image', $reference['image']); if (!isset($reference['parse_text']) || $reference['parse_text']) { $reference['snippet'] = $this->gadget->ParseText($reference['snippet'], $gadget); } if (!isset($reference['strip_tags']) || $reference['strip_tags']) { $reference['snippet'] = strip_tags($reference['snippet']); } $reference['snippet'] = Jaws_UTF8::substr($reference['snippet'], 0, $max_result_len); $tpl->SetVariable('snippet', $reference['snippet']); $tpl->SetVariable('date', $objDate->Format($reference['date'])); $tpl->ParseBlock('tag/tag_item'); } } } $tpl->ParseBlock('tag'); return $tpl->Get(); }