Ejemplo n.º 1
0
 function wpquery_filter_personalize($query, $type, array $arguments)
 {
     global $user;
     $targetUser = $user;
     if (!$targetUser) {
         $targetUser = "******";
         // Invalid user name, make sure nothing matches
     }
     $subquery = $query->getSubQuery('personalize');
     $types = array_filter(array_map('trim', explode(',', $type)));
     if (in_array('self', $types)) {
         $subquery->filterContributors($targetUser);
         $subquery->filterContent($targetUser, 'user');
     }
     if (in_array('groups', $types)) {
         $part = new Search_Expr_Or(array_map(function ($group) {
             return new Search_Expr_Token($group, 'multivalue', 'user_groups');
         }, Perms::get()->getGroups()));
         $subquery->getExpr()->addPart(new Search_Expr_And(array($part, new Search_Expr_Not(new Search_Expr_Token($targetUser, 'identifier', 'user')))));
     }
     if (in_array('addongroups', $types)) {
         $api = new TikiAddons_Api_Group();
         $cats = $api->getOrganicGroupCatsForUser($targetUser);
         if (empty($cats)) {
             $subquery->filterCategory('impossible');
         } else {
             $subquery->filterCategory(implode(' ', $cats));
         }
     }
     if (in_array('follow', $types)) {
         $subquery->filterMultivalue($targetUser, 'user_followers');
     }
     $userId = TikiLib::lib('tiki')->get_user_id($targetUser);
     if (in_array('stream_critical', $types)) {
         $subquery->filterMultivalue("critical{$userId}", 'stream');
     }
     if (in_array('stream_high', $types)) {
         $subquery->filterMultivalue("high{$userId}", 'stream');
     }
     if (in_array('stream_low', $types)) {
         $subquery->filterMultivalue("low{$userId}", 'stream');
     }
 }