$modSearchString = "%" . $modSearchString; } if ($modSearchString[strlen($modSearchString) - 1] != "%") { $modSearchString = $modSearchString . "%"; } $searchobject = $steam->get_server_module("searching"); $search = new search_define(); if ($searchType == "searchUser") { $search->extendAttr("OBJ_NAME", search_define::like($modSearchString)); $resultItems = $searchobject->search($search, CLASS_USER); foreach ($resultItems as $r) { $id = $r->get_id(); $resultItemName[$id] = $r->get_name(1); } } elseif ($searchType == "searchGroup") { $search->extendAttr("GROUP_NAME", search_define::like($modSearchString)); $resultItems = $searchobject->search($search, CLASS_GROUP); foreach ($resultItems as $r) { $id = $r->get_id(); $resultItemName[$id] = $r->get_groupname(1); } } $result = $steam->buffer_flush(); foreach ($resultItems as $r) { $id = $r->get_id(); $resultItemName[$id] = $result[$resultItemName[$id]]; $searchResult[] = $resultItemName[$id]; } } } // sort favourites
/** * searches for objects on a sTeam-server * * @param $searchfor the phrase we want to search for (e.g. "test", "blah", ...) * @param $fulltext true if we want to do a fulltext-search, otherwise false. * @param $searchwhat defines if we want to search only for special types. possible values are * SEARCH_EVERYTHING, SEARCH_PORTALS, SEARCH_USERS, SEARCH_GROUPS * @param $steam_connector the connector to the sTeam-Server * @return array an array with some attributes of the object. The object-ids are the keys */ function search($searchfor, $fulltext, $searchwhat, $steam_connector) { $retval = array(); if ($searchfor[0] != "%") { $searchfor = "%" . $searchfor; } if ($searchfor[strlen($searchfor) - 1] != "%") { $searchfor = $searchfor . "%"; } $searchobject = $steam_connector->get_server_module("searching"); $search = new search_define(); $search->extendAttr("OBJ_NAME", search_define::like($searchfor)); $search->extendAttr("OBJ_DESC", search_define::like($searchfor)); if ($search == true) { $search->addFulltextSearch($searchfor); } $result = $searchobject->search($search); //I don't know why, but if we search for OBJ_NAME, OBJ_DESC and OBJ_KEYWORDS //together, some objects are not found if not their exact name is given. $keywordsearch = new search_define(); $keywordsearch->extendAttr("OBJ_KEYWORDS", search_define::like($searchfor)); $result = array_merge($result, $searchobject->search($keywordsearch)); //It seems this is not needed but I am *not* sure! /*if ($fulltext == true) { $fulltextsearch = new search_define(); $fulltextsearch->addFulltextSearch($searchfor); $result = array_merge ($result, $searchobject->search($fulltextsearch)); }*/ $bufferattributes = array(); $bufferacces = array(); //Get all the attributes and the read-access buffered - it's faster foreach ($result as $singleresult) { $attributes = $singleresult->get_attributes(array(OBJ_NAME, OBJ_DESC, OBJ_OWNER, OBJ_CREATION_TIME, OBJ_LAST_CHANGED, "bid:doctype", "bid:collectiontype", DOC_MIME_TYPE, "bid:hidden", USER_FULLNAME, USER_FIRSTNAME), 1); $bufferattributes[$singleresult->get_id()] = $attributes; $bufferacces[$singleresult->get_id()] = $singleresult->check_access_read($steam_connector->get_login_user(), 1); } $bufferresults = $steam_connector->buffer_flush(); foreach ($result as $singleresult) { //Check for files, the user is not allowed to read. if ($bufferresults[$bufferacces[$singleresult->get_id()]] != 1) { continue; } $attributes = $bufferresults[$bufferattributes[$singleresult->get_id()]]; if ($singleresult->get_type() == CLASS_USER) { $attributes["isuser"] = true; } if ($singleresult->get_type() == CLASS_GROUP) { $attributes["isgroup"] = true; } //Only search for users - so we can ignore the other results. if ($searchwhat == SEARCH_USERS) { if ($singleresult->get_type() == CLASS_USER) { $retval[$singleresult->get_id()] = $attributes; } continue; } //Only search for groups - so we can ignore the other results. if ($searchwhat == SEARCH_GROUPS) { if ($singleresult->get_type() == CLASS_GROUP) { $attributes["isgroup"] = true; $retval[$singleresult->get_id()] = $attributes; } continue; } //A portal consists of a lot of elements but we only want to find one portal //that's why we need to get the root element. //Unfortunatly, we can not buffer that... while ($attributes["bid:doctype"] === "portlet" || $attributes["bid:doctype"] === "portlet:msg" || $attributes["bid:doctype"] === "portlet:picture") { $singleresult = $singleresult->get_environment(); $attributes = $singleresult->get_attributes(array(OBJ_NAME, OBJ_DESC, OBJ_OWNER, OBJ_CREATION_TIME, OBJ_LAST_CHANGED, "bid:doctype", "bid:collectiontype", DOC_MIME_TYPE, "bid:hidden", USER_FULLNAME, USER_FIRSTNAME)); } //Only search for portals if ($searchwhat == SEARCH_PORTALS) { if ($attributes["bid:doctype"] === "portal") { $retval[$singleresult->get_id()] = $attributes; } continue; } //if we want to search for eveything if ($searchwhat == SEARCH_EVERYTHING) { $retval[$singleresult->get_id()] = $attributes; } } return $retval; }
public function execute(\FrameResponseObject $frameResponseObject) { //DEFINITION OF IGNORED USERS AND GROUPS $ignoredUser = array(0 => "postman", 1 => "root", 2 => "guest"); $ignoredGroups = array(0 => "sTeam", 1 => "admin"); $steam = $GLOBALS["STEAM"]; $action = isset($_POST["action"]) ? $_POST["action"] : ""; $searchString = isset($_POST["searchString"]) ? $_POST["searchString"] : ""; $searchType = isset($_POST["searchType"]) ? $_POST["searchType"] : "searchUser"; $steamUser = \lms_steam::get_current_user(); $searchResult = array(); $min_search_string_count = 4; if ($action != "") { $searchString = trim($searchString); if (strlen($searchString) < $min_search_string_count) { //$frameResponseObject->setProblemDescription(gettext("Search string too short")); $frameResponseObject->setProblemDescription("Länge der Suchanfrage zu klein! Eine Suchanfrage muss aus mindestens 4 Zeichen bestehen."); } else { /* prepare search string */ $modSearchString = $searchString; if ($modSearchString[0] != "%") { $modSearchString = "%" . $modSearchString; } if ($modSearchString[strlen($modSearchString) - 1] != "%") { $modSearchString = $modSearchString . "%"; } $searchModule = $steam->get_module("searching"); $searchobject = new \searching($searchModule); $search = new \search_define(); if ($searchType == "searchUser") { $search->extendAttr("OBJ_NAME", \search_define::like($modSearchString)); $resultItems = $searchobject->search($search, CLASS_USER); foreach ($resultItems as $r) { $id = $r->get_id(); $resultItemName[$id] = $r->get_name(1); } } elseif ($searchType == "searchGroup") { $search->extendAttr("GROUP_NAME", \search_define::like($modSearchString)); $resultItems = $searchobject->search($search, CLASS_GROUP); foreach ($resultItems as $r) { $id = $r->get_id(); $resultItemName[$id] = $r->get_groupname(1); } } elseif ($searchType == "searchUserFullname") { $cache = get_cache_function($steamUser->get_name(), 60); $resultUser = $cache->call("lms_steam::search_user", $searchString, "name"); $resultItems = array(); for ($i = 0; $i < count($resultUser); $i++) { $resultItems[$i] = \steam_factory::get_object($steam->get_id(), $resultUser[$i]["OBJ_ID"]); } foreach ($resultItems as $r) { $id = $r->get_id(); $resultItemName[$id] = $r->get_name(); } } if ($searchType != "searchUserFullname") { $result = $steam->buffer_flush(); } else { $result = array(); $counter = 0; foreach ($resultItems as $r) { $result[$r->get_name()] = $r->get_id(); $counter++; } } $helper = array(); foreach ($resultItems as $r) { $id = $r->get_id(); if ($r instanceof \steam_user) { $helper[$r->get_name()] = $id; } else { $helper[$r->get_groupname()] = $id; } $resultItemName[$id] = $result[$resultItemName[$id]]; $searchResult[] = $resultItemName[$id]; } } } // sort favourites natcasesort($searchResult); $content = \Favorite::getInstance()->loadTemplate("fav_search.html"); //$content->setVariable("TITLE", gettext("Search for favorites")); $content->setVariable("TITLE", "Favoritensuche"); //$content->setVariable("SEARCH",gettext("Search")); $content->setVariable("SEARCH", "Suche"); //$content->setVariable("BUTTON_LABEL", gettext("Search")); $content->setVariable("BUTTON_LABEL", "Suchen"); //$content->setVariable("GROUPS",gettext("Groups")); //$content->setVariable("USER_LOGIN",gettext("User (login)")); //$content->setVariable("USER_FULLNAME", gettext("User (fullname)")); $content->setVariable("GROUPS", "Gruppen"); $content->setVariable("USER_LOGIN", "Benutzer (Login)"); $content->setVariable("USER_FULLNAME", "Benutzer (Namen)"); if ($action != "") { //$content->setVariable("SEARCH_RESULTS", gettext("Search results")); $loopCount = 0; if ($searchType == "searchUser" || $searchType == "searchUserFullname") { $category = "user"; } else { $category = "group"; } foreach ($searchResult as $resultEntry) { $content->setVariable("SEARCH_RESULTS", "Suchergebnisse"); $b = false; if ($searchType != "searchUserFullname") { $urlId = $helper[$resultEntry]; } else { $urlId = $resultEntry; } if ($category == "user") { foreach ($ignoredUser as $ignore) { if ($ignore == $resultEntry) { $b = true; } } } if ($category == "group") { foreach ($ignoredGroups as $ignore) { if ($ignore == $resultEntry) { $b = true; } } } if (!$b) { if ($category == "user") { $content->setCurrentBlock("BLOCK_SEARCH_RESULTS"); $content->setVariable("BUDDY_NAME", PATH_URL . "profile/index/" . $resultEntry . "/"); //$content->setVariable("BUDDY_NAME1",$resultEntry); $resultUser = \steam_factory::get_object($GLOBALS["STEAM"]->get_id(), $urlId); $fullname = $resultUser->get_full_name(); $content->setVariable("BUDDY_NAME1", $fullname); $picId = $resultUser->get_attribute("OBJ_ICON")->get_id(); $content->setVariable("BUDDY_PIC_LINK", PATH_URL . "download/image/" . $picId . "/60/40/"); if ($steamUser->get_id() == $resultUser->get_id()) { //$content->setVariable("ALREADY_BUDDY",gettext("Your profile")); $content->setVariable("ALREADY_BUDDY", "Das bist Du!"); } elseif (!$steamUser->is_buddy($resultUser)) { //$content->setVariable("ADD_FAVORITE_BUDDY", gettext("Add favorite")); $content->setVariable("ADD_FAVORITE_BUDDY", "Favorit hinzufügen"); $content->setVariable("FAVORITE_BUDDY_LINK", PATH_URL . "favorite/add/" . $urlId . "/" . $category . "/"); } else { //$content->setVariable("ALREADY_BUDDY", gettext("Already your favorite")); $content->setVariable("ALREADY_BUDDY", "Bereits Teil der Favoritenliste"); } $content->parse("BLOCK_SEARCH_RESULTS"); $loopCount++; } else { if ($category == "group") { $content->setCurrentBlock("BLOCK_GROUP_LIST"); $content->setVariable("GROUP_NAME", $resultEntry); $resultGroup = \steam_factory::get_object($GLOBALS["STEAM"]->get_id(), $urlId); $groupDesc = $resultGroup->get_attribute("OBJ_DESC"); $content->setVariable("GROUP_DESC", $groupDesc); if (!$steamUser->is_buddy($resultGroup)) { $content->setVariable("ADD_FAVORITE_GROUP", "Favorit hinzufügen"); //$content->setVariable("ALREADY_BUDDY", "Bereits Teil der Favoritenliste"); $content->setVariable("FAVORITE_GROUP_LINK", PATH_URL . "favorite/add/" . $urlId . "/" . $category . "/"); } else { $content->setVariable("ALREADY_GROUP", "Bereits Teil der Favoritenliste"); } $content->parse("BLOCK_GROUP_LIST"); $loopCount++; } } } } if ($loopCount == 0 || count($searchResult) == 0) { $content->setVariable("NO_RESULT", "Suchanfrage ergab keinen Treffer"); } } $headline = new \Widgets\Breadcrumb(); //$headline->setData(array(array("name"=>gettext("Profile"), "link"=>PATH_URL."profile/index/"),array("name"=>" / ".gettext("Favorites"), "link"=>PATH_URL."favorite/index/"),array("name"=>" / ".gettext("Favorite search")))); $headline->setData(array(array("name" => "Profil", "link" => PATH_URL . "profile/index/"), array("name" => "Favoriten", "link" => PATH_URL . "favorite/index/"), array("name" => "Favoritensuche"))); $rawHtml = new \Widgets\RawHtml(); $rawHtml->setHtml($content->get()); $frameResponseObject->addWidget($headline); $frameResponseObject->addWidget($rawHtml); return $frameResponseObject; }