示例#1
0
 public static function conditional_replace_with_value($replace_with, $atts, $field, $tag)
 {
     $conditions = array('equals', 'not_equal', 'like', 'not_like', 'less_than', 'greater_than');
     if ($field && $field->type == 'data') {
         $old_replace_with = $replace_with;
         // Only get the displayed value if it hasn't been set yet
         if (is_numeric($replace_with) || is_numeric(str_replace(array(',', ' '), array('', ''), $replace_with)) || is_array($replace_with)) {
             $replace_with = FrmFieldsHelper::get_display_value($replace_with, $field, $atts);
             if ($old_replace_with == $replace_with) {
                 $replace_with = '';
             }
         }
     } else {
         if ($field && $field->type == 'user_id' || in_array($tag, array('updated_by', 'created_by'))) {
             // check if conditional is for current user
             if (isset($atts['equals']) && $atts['equals'] == 'current') {
                 $atts['equals'] = get_current_user_id();
             }
             if (isset($atts['not_equal']) && $atts['not_equal'] == 'current') {
                 $atts['not_equal'] = get_current_user_id();
             }
         } else {
             if (in_array($tag, array('created-at', 'created_at', 'updated-at', 'updated_at')) || $field && $field->type == 'date') {
                 foreach ($conditions as $att_name) {
                     if (isset($atts[$att_name]) && $atts[$att_name] != '' && !preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', trim($atts[$att_name]))) {
                         if ($atts[$att_name] == 'NOW') {
                             $atts[$att_name] = FrmProAppHelper::get_date('Y-m-d');
                         } else {
                             $atts[$att_name] = date_i18n('Y-m-d', strtotime($atts[$att_name]));
                         }
                     }
                     unset($att_name);
                 }
             }
         }
     }
     self::eval_conditions($conditions, $atts, $replace_with, $field);
     return $replace_with;
 }