/** * 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() { $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; }
/** * Gets a list of Address Books * * @access public * @param int $user User ID * @param int $gid Group ID, AddressBook Items must be member of this Group ID * @param boolean $public If true show only public addressbooks * @param string $term Search term * @returns array of Address Books or Jaws_Error on error */ function GetAddressList($user, $gid, $public = false, $term = '', $limit = null, $offset = null) { $adrTable = Jaws_ORM::getInstance()->table('address_book'); $adrTable->select('*', 'address_book.id as address_id'); $adrTable->where('address_book.user', $user); if ($public) { $adrTable->and()->where('address_book.public', true); } if (!empty($limit)) { $adrTable->limit($limit, $offset); } if (!empty($gid) && $gid != 0) { $adrTable->join('address_book_group', 'address_book_group.address', 'address_book.id', 'left'); $adrTable->and()->where('address_book_group.group', $gid); } if (!empty($term)) { $term = Jaws_UTF8::strtolower($term); $adrTable->and()->openWhere('lower(name)', '%' . $term . '%', 'like'); $adrTable->or()->where('lower(nickname)', '%' . $term . '%', 'like'); $adrTable->or()->where('lower(title)', '%' . $term . '%', 'like'); $adrTable->or()->where('lower(tel_home)', '%' . $term . '%', 'like'); $adrTable->or()->where('lower(tel_work)', '%' . $term . '%', 'like'); $adrTable->or()->where('lower(tel_other)', '%' . $term . '%', 'like'); $adrTable->or()->where('lower(email_home)', '%' . $term . '%', 'like'); $adrTable->or()->where('lower(email_work)', '%' . $term . '%', 'like'); $adrTable->or()->where('lower(email_other)', '%' . $term . '%', 'like'); $adrTable->or()->closeWhere('lower(notes)', '%' . $term . '%', 'like'); } return $adrTable->fetchAll(); }
/** * 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; }
/** * Get groups * * @access public * @param $term Search term(searched in username, nickname and email) * @return array Returns an array of the available groups */ function GetGroups($term) { $groupsTable = Jaws_ORM::getInstance()->table('groups'); $groupsTable->select('id:integer', 'name', 'title', 'description', 'enabled:boolean'); $term = Jaws_UTF8::strtolower($term); $groupsTable->where('enabled', true); $groupsTable->and()->openWhere('lower(name)', '%' . $term . '%', 'like'); $groupsTable->or()->closeWhere('lower(title)', '%' . $term . '%', 'like'); $groupsTable->orderBy('name'); return $groupsTable->fetchAll(); }
/** * Get a category * * @access public * @param string $name category name * @return mixed A category array or Jaws_Error */ function GetCategoryByName($name) { $name = Jaws_UTF8::strtolower($name); $catTable = Jaws_ORM::getInstance()->table('blog_category'); $catTable->select('id:integer', 'name', 'description', 'fast_url', 'createtime', 'updatetime'); $result = $catTable->where($catTable->lower('name'), $name)->fetchRow(); if (Jaws_Error::IsError($result)) { return new Jaws_Error(_t('BLOG_ERROR_GETTING_CATEGORY')); } return $result; }
/** * Uploads attachment file * * @access public * @return string javascript script segment */ function UploadFile() { $file_num = jaws()->request->fetch('attachment_number', 'post'); $file = Jaws_Utils::UploadFiles($_FILES, Jaws_Utils::upload_tmp_dir(), '', null); if (Jaws_Error::IsError($file)) { $response = array('type' => 'error', 'message' => $file->getMessage()); } else { $response = array('type' => 'notice', 'file_info' => array('title' => $file['attachment' . $file_num][0]['user_filename'], 'filename' => $file['attachment' . $file_num][0]['host_filename'], 'filesize_format' => Jaws_Utils::FormatSize($file['attachment' . $file_num][0]['host_filesize']), 'filesize' => $file['attachment' . $file_num][0]['host_filesize'], 'filetype' => $file['attachment' . $file_num][0]['host_filetype'])); } $response = Jaws_UTF8::json_encode($response); return "<script type='text/javascript'>parent.onUpload({$response});</script>"; }
/** * 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(); }
/** * Uploads the avatar * * @access public * @return string XHTML content */ function UploadAvatar() { $this->gadget->CheckPermission('EditUserPersonal'); $res = Jaws_Utils::UploadFiles($_FILES, Jaws_Utils::upload_tmp_dir(), 'gif,jpg,jpeg,png'); if (Jaws_Error::IsError($res)) { $response = array('type' => 'error', 'message' => $res->getMessage()); } elseif (empty($res)) { $response = array('type' => 'error', 'message' => _t('GLOBAL_ERROR_UPLOAD_4')); } else { $response = array('type' => 'notice', 'message' => $res['upload_avatar'][0]['host_filename']); } $response = Jaws_UTF8::json_encode($response); return "<script type='text/javascript'>parent.onUpload({$response});</script>"; }
/** * 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(); }
/** * Display a tag cloud * * @access public * @return string XHTML template content */ function ShowTagCloud() { $model = $this->gadget->model->load('Tags'); $res = $model->CreateTagCloud(); $sortedTags = $res; sort($sortedTags); $minTagCount = log(isset($sortedTags[0]) ? $sortedTags[0]['howmany'] : 0); $maxTagCount = log(count($res) != 0 ? $sortedTags[count($res) - 1]['howmany'] : 0); unset($sortedTags); if ($minTagCount == $maxTagCount) { $tagCountRange = 1; } else { $tagCountRange = $maxTagCount - $minTagCount; } $minFontSize = 1; $maxFontSize = 10; $fontSizeRange = $maxFontSize - $minFontSize; $tpl = $this->gadget->template->load('CategoryCloud.html'); $tpl->SetBlock('tagcloud'); $tpl->SetVariable('title', _t('BLOG_TAGCLOUD')); foreach ($res as $key => $value) { if (!$this->gadget->GetPermission('CategoryAccess', $value['category_id'])) { continue; } $count = $value['howmany']; $fsize = $minFontSize + $fontSizeRange * (log($count) - $minTagCount) / $tagCountRange; $tpl->SetBlock('tagcloud/tag'); $tpl->SetVariable('size', (int) $fsize); $tpl->SetVariable('tagname', Jaws_UTF8::strtolower($value['name'])); $tpl->SetVariable('frequency', $value['howmany']); $cid = empty($value['fast_url']) ? $value['category_id'] : $value['fast_url']; $tpl->SetVariable('url', $this->gadget->urlMap('ShowCategory', array('id' => $cid))); $tpl->SetVariable('category', $value['category_id']); $tpl->ParseBlock('tagcloud/tag'); } $tpl->ParseBlock('tagcloud'); return $tpl->Get(); }
/** * 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; }
/** * 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; }
/** * 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(); }
/** * 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(); }
/** * 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; }
/** * 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; }
/** * 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')); }
/** * 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); }
/** * Update the info of a group * * @access public * @param int $id Group ID * @param array $gData Group information data * @param int $owner The owner of group * @return bool Returns true if group was sucessfully updated, false if not */ function UpdateGroup($id, $gData, $owner = 0) { // unset invalid keys $invalids = array_diff(array_keys($gData), array('name', 'title', 'description', 'enabled')); foreach ($invalids as $invalid) { unset($gData[$invalid]); } // name if (isset($gData['name'])) { $gData['name'] = trim($gData['name'], '-_.@'); if (!preg_match('/^[[:alnum:]-_.@]{3,32}$/', $gData['name'])) { return Jaws_Error::raiseError(_t('GLOBAL_ERROR_INVALID_GROUPNAME'), __FUNCTION__, JAWS_ERROR_NOTICE); } $gData['name'] = strtolower($gData['name']); } $gData['owner'] = (int) $owner; // title if (isset($gData['title'])) { $gData['title'] = Jaws_UTF8::trim($gData['title']); if (empty($gData['title'])) { return Jaws_Error::raiseError(_t('GLOBAL_ERROR_INCOMPLETE_FIELDS'), __FUNCTION__, JAWS_ERROR_NOTICE); } } if (isset($gData['enabled'])) { $gData['enabled'] = (bool) $gData['enabled']; } $groupsTable = Jaws_ORM::getInstance()->table('groups'); $result = $groupsTable->update($gData)->where('id', $id)->exec(); if (Jaws_Error::IsError($result)) { if (MDB2_ERROR_CONSTRAINT == $result->getCode()) { $result->SetMessage(_t('USERS_GROUPS_ALREADY_EXISTS', $gData['name'])); } return $result; } // Let everyone know a group has been updated $res = $GLOBALS['app']->Listener->Shout('Users', 'UpdateGroup', $id); if (Jaws_Error::IsError($res)) { //do nothing } return true; }
/** * 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(); }
/** * Uploads attachment file * * @access public * @return string javascript script segment */ function UploadFile() { $res = Jaws_Utils::UploadFiles($_FILES, Jaws_Utils::upload_tmp_dir()); if (Jaws_Error::IsError($res)) { $response = array('type' => 'error', 'message' => $res->getMessage()); } elseif (empty($res)) { $response = array('type' => 'error', 'message' => _t('GLOBAL_ERROR_UPLOAD_4')); } else { $response = array('type' => 'notice', 'filename' => $res['attachment'][0]['host_filename'], 'filesize' => Jaws_Utils::FormatSize($_FILES['attachment']['size'])); } $response = Jaws_UTF8::json_encode($response); return "<script type='text/javascript'>parent.onUpload({$response});</script>"; }