/** * 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(); }
/** * Displays Tags Cloud * * @access public * @param string $gadget Gadget name * @param int $user Only show user tags? * @return string XHTML template content */ function TagCloud($gadget = null, $user = 0) { if (!empty($user) && !$GLOBALS['app']->Session->Logged()) { return false; } if ($GLOBALS['app']->requestedActionMode == ACTION_MODE_NORMAL) { $gadget = $this->gadget->request->fetch('tagged_gadget', 'get'); } $user = empty($user) ? 0 : (int) $GLOBALS['app']->Session->GetAttribute('user'); $model = $this->gadget->model->load('Tags'); $tags = $model->GenerateTagCloud($gadget, $user); if (Jaws_Error::IsError($tags) || empty($tags)) { return false; } // find minimum/maximum frequencies $frequencies = array_column($tags, 'howmany'); sort($frequencies); $minTagCount = log($frequencies[0]); $maxTagCount = log(end($frequencies)); unset($frequencies); // calculate font-size step if ($minTagCount == $maxTagCount) { $tagCountRange = 1; } else { $tagCountRange = $maxTagCount - $minTagCount; } $minFontSize = 0; $maxFontSize = 9; $fontSizeRange = $maxFontSize - $minFontSize; $tpl = $this->gadget->template->load('TagCloud.html'); $tpl->SetBlock('tagcloud'); if (!empty($gadget)) { $tpl->SetVariable('title', _t('TAGS_TAG_CLOUD', _t(strtoupper($gadget) . '_TITLE'))); } else { $tpl->SetVariable('title', _t('TAGS_TAG_CLOUD', _t('GLOBAL_ALL'))); } if ($user) { $tpl->SetVariable('menubar', $this->MenuBar('ManageTags', array('ManageTags'))); } foreach ($tags as $tag) { $count = $tag['howmany']; $fsize = $minFontSize + $fontSizeRange * (log($count) - $minTagCount) / $tagCountRange; $tpl->SetBlock('tagcloud/tag'); $tpl->SetVariable('size', (int) $fsize); $tpl->SetVariable('tagname', Jaws_UTF8::strtolower($tag['title'])); $tpl->SetVariable('frequency', $tag['howmany']); if (empty($gadget)) { $param = array('tag' => $tag['name']); } else { $param = array('tag' => $tag['name'], 'tagged_gadget' => $gadget); } if ($user) { $param['user'] = $user; } $tpl->SetVariable('url', $this->gadget->urlMap('ViewTag', $param)); $tpl->ParseBlock('tagcloud/tag'); } $tpl->ParseBlock('tagcloud'); return $tpl->Get(); }
/** * 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; }
/** * 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(); }
/** * 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(); }
/** * 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; }
/** * Get count of users * * @access public * @param mixed $group Group ID of users * @param mixed $superadmin Type of user(null = all types, true = superadmin, false = normal) * @param int $status user's status (null: all users, 0: disabled, 1: enabled, 2: not verified) * @param string $term Search term(searched in username, nickname and email) * @return int Returns users count */ function GetUsersCount($group = false, $superadmin = null, $status = null, $term = '') { $usersTable = Jaws_ORM::getInstance()->table('users'); $usersTable->select('count(users.id):integer'); if ($group !== false) { $usersTable->join('users_groups', 'users_groups.user_id', 'users.id'); $usersTable->where('group_id', (int) $group); } if (!is_null($superadmin)) { $usersTable->and()->where('superadmin', (bool) $superadmin); } if (!is_null($status)) { $usersTable->and()->where('status', (int) $status); } if (!empty($term)) { $term = Jaws_UTF8::strtolower($term); $usersTable->and()->openWhere('lower(username)', $term, 'like'); $usersTable->or()->where('lower(nickname)', $term, 'like'); $usersTable->or()->closeWhere('lower(email)', $term, 'like'); } $result = $usersTable->fetchOne(); if (Jaws_Error::IsError($result)) { return 0; } return (int) $result; }
/** * The callback function that prepares the code to be xhtml * * @access public * @param array $code_information Code Data(code and lang) * @return string XHTML code */ function PrepareCode($code_information) { $code = $code_information[2]; $lang = trim($code_information[1]); $lang = Jaws_UTF8::html_entity_decode($lang); $lang = preg_replace('/[\'\\"]/si', '', $lang); $lang = Jaws_UTF8::strtolower($lang); $valid_lang = array('php', 'actionscript', 'ada', 'apache', 'asm', 'asp', 'bash', 'applescript', 'caddcl', 'cadlisp', 'c', 'c#', 'cpp', 'css', 'delphi', 'ruby', 'html4strict', 'java', 'javascript', 'lisp', 'lua', 'nsis', 'oobas', 'pascal', 'perl', 'python', 'qbasic', 'sql', 'vb', 'visualfoxpro', 'xml'); if (in_array($lang, $valid_lang)) { //For some fscking reason, geshi applied htmlentities again, so a < will be &lt $htmltable = get_html_translation_table(HTML_ENTITIES); foreach ($htmltable as $key => $value) { $code = str_replace(addslashes($value), $key, $code); } require_once JAWS_PATH . 'libraries/geshi/geshi.php'; $geshi = new GeSHi($code, $lang, JAWS_PATH . 'libraries/geshi/geshi'); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->enable_keyword_links(false); $new_code = $geshi->parse_code(); $new_html = '<div class="code">' . $new_code . '</div>'; // $ndew_html = str_replace('<div>', '<div class="code">', // str_replace('</div>', '</div>', $geshi->parse_code())); unset($geshi); } else { $new_html = "<code>\n"; $new_html .= $code; $new_html .= "</code>\n"; } return $new_html; }
/** * Case-insensitive version of str_replace * @see http://www.php.net/str_ireplace */ static function str_ireplace($search, $replace, $str, $count = null) { if (!is_array($search)) { $slen = strlen($search); if ($slen == 0) { return $str; } $search = Jaws_UTF8::strtolower($search); $search = preg_quote($search); $lstr = Jaws_UTF8::strtolower($str); $i = 0; $matched = 0; while (preg_match('/(.*)' . $search . '/Us', $lstr, $matches)) { if ($i === $count) { break; } $mlen = strlen($matches[0]); $lstr = substr($lstr, $mlen); $str = substr_replace($str, $replace, $matched + strlen($matches[1]), $slen); $matched += $mlen; $i++; } return $str; } else { foreach (array_keys($search) as $k) { if (is_array($replace)) { if (array_key_exists($k, $replace)) { $str = Jaws_UTF8::str_ireplace($search[$k], $replace[$k], $str, $count); } else { $str = Jaws_UTF8::str_ireplace($search[$k], '', $str, $count); } } else { $str = Jaws_UTF8::str_ireplace($search[$k], $replace, $str, $count); } } return $str; } }
/** * 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; }
/** * 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; }