Exemplo n.º 1
0
 /**
  * 根据各种条件的得到贴纸数据,目前扩展端,移动端使用【已废弃】
  * 
  * @deprecated v2 第二版本api使用的万能查询方法
  * 
  * @author Vincent Row <*****@*****.**>
  * 
  * @param Object $filters 过滤条件以及排序
  * 
  * @return array 返回数据集
  */
 function getNotesByFilters($uid, $filters)
 {
     /**
      * 不再支持通过modified拉取更新数据
      */
     if (isset($filters->modified)) {
         return [];
     }
     $papers = [];
     //设置默认值
     $sort = ' DESC ';
     $hits = 10;
     $keywords = null;
     $orderby = ' sortby ';
     $start = 0;
     $tags_condition = '';
     $publyc = '';
     $removed = '';
     $modified = '';
     $gt_modified = '';
     $lt_modified = '';
     $gt_time = '';
     $lt_time = '';
     //对参数进行处理
     //将关键字进行处理
     if (isset($filters->orderby) && isset(self::$order_fields[$filters->orderby])) {
         $orderby = $filters->orderby;
     }
     //将关键字进行处理
     if (isset($filters->sort) && (strtolower($filters->sort) == "asc" || strtolower($filters->sort) == "desc")) {
         $sort = $filters->sort;
     }
     if (isset($filters->removed) && $filters->removed == 1) {
         $removed = " AND removed = 1 ";
     }
     if (isset($filters->removed) && $filters->removed == 0) {
         $removed = " AND removed = 0 ";
     }
     if (isset($filters->publyc) && $filters->publyc == 0) {
         $publyc = " AND publyc = 0 ";
     }
     if (isset($filters->publyc) && $filters->publyc == 1) {
         $publyc = " AND publyc = 1 ";
     }
     if (isset($filters->start) && is_numeric($filters->start)) {
         $start = $filters->start;
     }
     if (isset($filters->hits) && is_numeric($filters->hits)) {
         $hits = $filters->hits;
     }
     if (isset($filters->modified)) {
         if (!is_numeric($filters->modified)) {
             $filters->modified = strtotime($filters->modified);
         }
         $modified = ' AND modified > \'' . $filters->modified . '\'';
     }
     if (isset($filters->gt_modified) && self::is_valid('modified', $filters->gt_modified)) {
         if (!is_numeric($filters->gt_modified)) {
             $filters->gt_modified = datetime_to_int($filters->gt_modified);
         }
         $gt_modified = ' AND modified > \'' . $filters->gt_modified . '\'';
     }
     if (isset($filters->lt_modified) && self::is_valid('modified', $filters->lt_modified)) {
         if (!is_numeric($filters->lt_modified)) {
             $filters->lt_modified = datetime_to_int($filters->lt_modified);
         }
         $lt_modified = ' AND modified < \'' . $filters->lt_modified . '\'';
     }
     if (isset($filters->gt_time)) {
         if (!is_numeric($filters->gt_time)) {
             $filters->gt_time = strtotime($filters->gt_time);
         }
         $gt_time = ' AND (modified > \'' . $filters->gt_time . '\' OR synced > \'' . $filters->gt_time . '\') ';
     }
     if (isset($filters->lt_time)) {
         if (!is_numeric($filters->lt_time)) {
             $filters->lt_time = strtotime($filters->lt_time);
         }
         $lt_time = ' AND (modified < \'' . $filters->lt_time . '\' OR synced < \'' . $filters->lt_time . '\') ';
     }
     //取某个标签下的贴纸
     $tagId = null;
     if (isset($filters->tag) && is_numeric($filters->tag)) {
         $tagId = $filters->tag;
     }
     //默认不取出被彻底删除的,除非请求时带上标志
     $expunged = " AND expunged=0 ";
     //如果需要取出被彻底删除的则将过滤条件去除
     if (isset($filters->with_expunged)) {
         $expunged = "";
     }
     if (!isset($filters->notag)) {
         if ($tagId > 0) {
             $sql = 'SELECT a.ntid AS id,a.sortby,a.title,a.summary,c.content,a.source,a.tags AS tags_list,a.tags,a.expunged,a.removed,a.publyc,FROM_UNIXTIME(a.modified) AS modified,FROM_UNIXTIME(a.synced) AS synced,FROM_UNIXTIME(a.created) AS created ' . ' FROM idlnote a INNER JOIN idlnote_tag b ON a.ntid=b.ntid INNER JOIN idlnote_content c ON a.ntid=c.ntid ' . ' WHERE ' . ' uid = ' . $uid . ' AND b.tid=' . $tagId . $publyc . $removed . $expunged . $modified . $gt_modified . $lt_modified . $gt_time . $lt_time . ' ORDER BY ' . $orderby . ' ' . $sort . ' LIMIT ' . $start . ' , ' . $hits;
         } else {
             $sql = 'SELECT a.ntid AS id,a.sortby,a.title,a.summary,c.content,a.source,a.tags AS tags_list,a.tags,a.expunged,a.removed,a.publyc,FROM_UNIXTIME(a.modified) AS modified,FROM_UNIXTIME(a.synced) AS synced,FROM_UNIXTIME(a.created) AS created ' . ' FROM idlnote a INNER JOIN idlnote_content c ON a.ntid=c.ntid ' . ' WHERE ' . ' uid = ' . $uid . $publyc . $removed . $expunged . $modified . $gt_modified . $lt_modified . $gt_time . $lt_time . ' ORDER BY ' . $orderby . ' ' . $sort . ' LIMIT ' . $start . ' , ' . $hits;
         }
     } else {
         //取回无标签数据
         $sql = 'SELECT a.ntid AS id,a.sortby,a.title,a.summary,c.content,a.source,a.tags AS tags_list,a.tags,a.expunged,a.removed,a.publyc,FROM_UNIXTIME(a.modified) AS modified,FROM_UNIXTIME(a.synced) AS synced,FROM_UNIXTIME(a.created) AS created ' . ' FROM idlnote a LEFT OUTER JOIN idlnote_tag b ON a.ntid=b.ntid INNER JOIN idlnote_content c ON a.ntid=c.ntid ' . ' WHERE ' . ' uid = ' . $uid . ' AND b.tid IS NULL ' . $publyc . $removed . $expunged . $modified . $gt_modified . $lt_modified . $gt_time . $lt_time . ' ORDER BY ' . $orderby . ' ' . $sort . ' LIMIT ' . $start . ' , ' . $hits;
     }
     $papers = $this->db('r')->query($sql)->result();
     return $papers;
 }
Exemplo n.º 2
0
function qwp_validate_data(&$f, &$rules, &$filters = null, $just_unset_when_failed = false)
{
    $msg_base = L('Invalid form data');
    $valid_fields = array();
    $predefined_rules = get_input_rules();
    foreach ($rules as $field_name => &$rule) {
        $field_value = isset($f[$field_name]) ? $f[$field_name] : null;
        $valid_fields[$field_name] = true;
        if (isset($rule['_msg'])) {
            $msg =& $rule['_msg'];
        } else {
            $msg =& $msg_base;
        }
        if (isset($rule['required'])) {
            if ($field_value === null || $field_value === '') {
                if ($just_unset_when_failed) {
                    unset($f[$field_name]);
                    continue;
                }
                return $msg . '. ' . L('Current value is empty!');
            }
        } else {
            if (isset($rule['optional'])) {
                if ($field_value === null || $field_value === '') {
                    continue;
                }
            }
        }
        foreach ($rule as $key => $item) {
            if (substr($key, 0, 1) == '_') {
                if ($key == '_avoidSqlInj') {
                    $f[$field_name] = mysql_real_escape_string($field_value);
                }
                continue;
            }
            if ($key == 'required' || $key == 'optional') {
                continue;
            }
            if ($key == 'date') {
                if (!date_to_int($field_value)) {
                    if ($just_unset_when_failed) {
                        unset($f[$field_name]);
                        continue;
                    }
                    return qwp_validate_get_error($msg, $field_value);
                }
            } else {
                if ($key == 'datetime') {
                    if (!datetime_to_int($field_value)) {
                        if ($just_unset_when_failed) {
                            unset($f[$field_name]);
                            continue;
                        }
                        return qwp_validate_get_error($msg, $field_value);
                    }
                } else {
                    if ($key == 'digits') {
                        if (!is_digits($field_value)) {
                            if ($just_unset_when_failed) {
                                unset($f[$field_name]);
                                continue;
                            }
                            return qwp_validate_get_error($msg, $field_value);
                        }
                    } else {
                        if ($key == 'minlength') {
                            $len = mb_strlen($field_value, 'utf8');
                            if ($len < $item) {
                                if ($just_unset_when_failed) {
                                    unset($f[$field_name]);
                                    continue;
                                }
                                return qwp_validate_get_error($msg, $field_value);
                            }
                        } else {
                            if ($key == 'maxlength') {
                                $len = mb_strlen($field_value, 'utf8');
                                if ($len > $item) {
                                    if ($just_unset_when_failed) {
                                        unset($f[$field_name]);
                                        continue;
                                    }
                                    return qwp_validate_get_error($msg, $field_value);
                                }
                            } else {
                                if ($key == 'rangelength') {
                                    $len = mb_strlen($field_value, 'utf8');
                                    if ($len < $item[0] || $len > $item[1]) {
                                        if ($just_unset_when_failed) {
                                            unset($f[$field_name]);
                                            continue;
                                        }
                                        return qwp_validate_get_error($msg, $field_value);
                                    }
                                } else {
                                    if ($key == 'min') {
                                        if ($field_value < $item) {
                                            if ($just_unset_when_failed) {
                                                unset($f[$field_name]);
                                                continue;
                                            }
                                            return qwp_validate_get_error($msg, $field_value);
                                        }
                                    } else {
                                        if ($key == 'max') {
                                            if ($field_value > $item) {
                                                if ($just_unset_when_failed) {
                                                    unset($f[$field_name]);
                                                    continue;
                                                }
                                                return qwp_validate_get_error($msg, $field_value);
                                            }
                                        } else {
                                            if ($key == 'range' || $key == '[]') {
                                                if ($field_value < $item[0] || $field_value > $item[1]) {
                                                    if ($just_unset_when_failed) {
                                                        unset($f[$field_name]);
                                                        continue;
                                                    }
                                                    return qwp_validate_get_error($msg, $field_value);
                                                }
                                            } else {
                                                if ($key == 'equalTo' || $key == '=') {
                                                    $equal_item = isset($f[$item[1]]) ? $f[$item[1]] : null;
                                                    if ($field_value != $equal_item) {
                                                        if ($just_unset_when_failed) {
                                                            unset($f[$field_name]);
                                                            continue;
                                                        }
                                                        return qwp_validate_get_error($msg, $field_value);
                                                    }
                                                } else {
                                                    if ($key == 'in') {
                                                        if (!in_array($field_value, $item)) {
                                                            if ($just_unset_when_failed) {
                                                                unset($f[$field_name]);
                                                                continue;
                                                            }
                                                            return qwp_validate_get_error($msg, $field_value);
                                                        }
                                                    } else {
                                                        if ($key == '[)') {
                                                            if ($field_value < $item[0] || $field_value >= $item[1]) {
                                                                if ($just_unset_when_failed) {
                                                                    unset($f[$field_name]);
                                                                    continue;
                                                                }
                                                                return qwp_validate_get_error($msg, $field_value);
                                                            }
                                                        } else {
                                                            if ($key == '(]') {
                                                                if ($field_value <= $item[0] || $field_value > $item[1]) {
                                                                    if ($just_unset_when_failed) {
                                                                        unset($f[$field_name]);
                                                                        continue;
                                                                    }
                                                                    return qwp_validate_get_error($msg, $field_value);
                                                                }
                                                            } else {
                                                                if ($key == '()') {
                                                                    if ($field_value <= $item[0] || $field_value >= $item[1]) {
                                                                        if ($just_unset_when_failed) {
                                                                            unset($f[$field_name]);
                                                                            continue;
                                                                        }
                                                                        return qwp_validate_get_error($msg, $field_value);
                                                                    }
                                                                } else {
                                                                    $fn_ret = is_valid_input($field_value, $key, $predefined_rules);
                                                                    if ($fn_ret !== -1 && !$fn_ret) {
                                                                        if ($just_unset_when_failed) {
                                                                            unset($f[$field_name]);
                                                                            continue;
                                                                        }
                                                                        return qwp_validate_get_error($msg, $field_value);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($filters) {
        qwp_filter_form_values($f, $filters);
    }
    remove_unwanted_data($f, $valid_fields);
    return true;
}