Beispiel #1
0
function smarty_function_profile($params, $smarty)
{
    $params = new PlDict($params);
    $with_promo = $params->b('promo', false) || $params->b('cat', false);
    $with_sex = $params->b('sex', true);
    $with_link = $params->b('link', true);
    $with_dir = $params->b('directory', true);
    $with_groupperms = $params->b('groupperms', true);
    $raw = $params->b('raw', false);
    $user = $params->v('user');
    $profile = $params->v('profile');
    if (is_int($user) || ctype_digit($user)) {
        $user = User::getWithUID($user);
    }
    if ($with_dir) {
        $name = pl_entities($user->directoryName());
    } else {
        $name = pl_entities($user->fullName());
    }
    if ($with_promo) {
        $promo = $user->category();
        if ($promo) {
            $name .= ' (' . pl_entities($promo) . ')';
        }
    }
    if ($raw) {
        return $name;
    }
    if ($with_sex && $user->isFemale()) {
        $name = '•' . $name;
    }
    if ($with_link) {
        if (is_null($profile)) {
            $profile = $user->profile();
        }
        if ($profile) {
            $name = '<a href="profile/' . $profile->hrid() . '" class="popup2">' . $name . '</a>';
        }
    }
    if ($profile && $profile->isDead()) {
        $name .= ' &dagger;';
    } else {
        if ($user->lost) {
            $name .= ' <a href="https://www.polytechnique.org/marketing/broken/' . $user->hruid . '"><img src="images/icons/error.gif" alt="Patte cassée" /></a>';
        }
    }
    if ($with_groupperms && $user instanceof User && $user->group_perms == 'admin' && !empty($name)) {
        $name = '<strong>' . $name . '</strong>';
    }
    return $name;
}
function smarty_function_display_education($params, $smarty)
{
    $params = new PlDict($params);
    $edu = $params->v('edu');
    return display_education($edu->school_short == '' ? $edu->school : $edu->school_short, $edu->school_url, $edu->degree_short, $edu->grad_year, $edu->field, $edu->program, $params->b('full'));
}
Beispiel #3
0
 public static function fromExport(array $export)
 {
     $export = new PlDict($export);
     if (!$export->has('type')) {
         throw new Exception("Missing type in export");
     }
     $type = $export->s('type');
     $cond = null;
     switch ($type) {
         case 'and':
         case 'or':
         case 'not':
         case 'true':
         case 'false':
             $class = 'pfc_' . $type;
             $cond = new $class();
             break;
         case 'host':
             if ($export->has('ip')) {
                 $cond = new UFC_Ip($export->s('ip'));
             }
             break;
         case 'comment':
             if ($export->has('text') && $export->s('comparison') == self::OP_CONTAINS) {
                 $cond = new UFC_Comment($export->s('text'));
             }
             break;
         case 'promo':
             if ($export->has('promo') && self::isNumericComparison($export->s('comparison'))) {
                 $cond = new UFC_Promo($export->s('comparison'), $export->s('grade', UserFilter::DISPLAY), $export->s('promo'));
             }
             break;
         case 'lastname':
         case 'name':
         case 'firstname':
         case 'nickname':
         case 'pseudonym':
             if ($export->has('text')) {
                 $flag = self::xdbWildcardFromComparison($export->s('comparison'));
                 if ($export->b('search_in_variants')) {
                     $flag |= UFC_Name::VARIANTS;
                 }
                 if ($export->b('search_in_particle')) {
                     $flag |= UFC_Name::PARTICLE;
                 }
                 $cond = new UFC_Name($type, $export->s('text'), $flag);
             }
             break;
         case 'account_type':
         case 'account_perm':
         case 'hrpid':
         case 'hruid':
             $values = $export->v('values', array());
             $class = 'ufc_' . str_replace('_', '', $type);
             $cond = new $class($values);
             break;
         case 'school_id':
             $values = $export->v('values', array());
             $school_type = $export->s('school_type');
             $cond = new UFC_SchoolId($school_type, $values);
             break;
         case 'has_profile':
         case 'has_email_redirect':
         case 'has_valid_email':
             $class = 'ufc_' . str_replace('_', '', $type);
             $cond = new $class();
             break;
         default:
             throw new Exception("Unknown condition type: {$type}");
     }
     if (is_null($cond)) {
         throw new Exception("Unsupported {$type} definition");
     }
     if ($cond instanceof PFC_NChildren) {
         $children = $export->v('children', array());
         foreach ($children as $child) {
             $cond->addChild(self::fromExport($child));
         }
     } else {
         if ($cond instanceof PFC_OneChild) {
             if ($export->has('child')) {
                 $cond->setChild(self::fromExport($export->v('child')));
             }
         }
     }
     return $cond;
 }