~ubuntu-branches/ubuntu/lucid/mahara/lucid-security

« back to all changes in this revision

Viewing changes to htdocs/search/internal/lib.php

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2009-11-27 22:09:03 UTC
  • mfrom: (6.3.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091127220903-aiigd3tr46z0rmcg
Tags: 1.2.0-2
Fix postrm script so that Mahara can be uninstalled

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/**
3
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
 
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
 
4
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 
5
 *                         http://wiki.mahara.org/Contributors
5
6
 *
6
7
 * This program is free software: you can redistribute it and/or modify
7
8
 * it under the terms of the GNU General Public License as published by
20
21
 * @subpackage search-internal
21
22
 * @author     Catalyst IT Ltd
22
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
23
 
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
 
24
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
24
25
 *
25
26
 */
26
27
 
32
33
 */
33
34
class PluginSearchInternal extends PluginSearch {
34
35
 
 
36
    public static function can_be_disabled() {
 
37
        return false;
 
38
    }
 
39
 
35
40
    /**
36
41
     * Implement user searching with SQL
37
42
     *
176
181
 
177
182
    public static function search_user_my($query_string, $limit, $offset, $data, $publicfields) {
178
183
        $fieldlist = "('" . join("','", $publicfields) . "')";
179
 
 
 
184
        $data = self::prepare_search_user_options($data);
180
185
        $sql = 'SELECT
181
186
                COUNT(DISTINCT u.id)
182
187
            FROM
244
249
                    AND ( ' . $namesql . '
245
250
                    )
246
251
                    ' . (isset($data['exclude']) ? 'AND u.id != ' . $data['exclude'] : '') . '
247
 
                ORDER BY u.firstname, u.lastname, u.id';
 
252
                ORDER BY ' . $data['orderby'];
248
253
            $data = get_records_sql_array($sql, $values, $offset, $limit);
249
254
            if ($data) {
250
255
                foreach ($data as &$item) {
833
838
 
834
839
 
835
840
    /**
 
841
     * Returns portfolio items (artefacts, views) owned by $owner and tagged
 
842
     * with $tag.
 
843
     *
 
844
     * @param string   $tag Tag
 
845
     * @param object   $owner: owner type (user,group,institution), and id
 
846
     * @param integer  $limit
 
847
     * @param integer  $offset
 
848
     * @param string   $sort
 
849
     * @param array    $types view/artefacttype filters
 
850
     * @param boolean  $returntags Return all the tags that have been attached to each result
 
851
     */
 
852
    public static function portfolio_search_by_tag($tag, $owner, $limit, $offset, $sort, $types, $returntags) {
 
853
        $viewfilter = is_null($types) || $types['view'] == true ? 'AND TRUE' : 'AND FALSE';
 
854
 
 
855
        if (is_null($types)) {
 
856
            $artefacttypefilter = '';
 
857
        }
 
858
        else if (!empty($types['artefact'])) {
 
859
            $artefacttypefilter = ' AND a.artefacttype IN (' . join(',', array_map('db_quote', $types['artefact'])) . ')';
 
860
        }
 
861
        else {
 
862
            $artefacttypefilter = ' AND FALSE';
 
863
        }
 
864
 
 
865
        if (!is_null($tag)) {
 
866
            $artefacttypefilter .= ' AND at.tag = ?';
 
867
            $viewfilter .= ' AND vt.tag = ?';
 
868
            $values = array($owner->id, $tag, $owner->id, $tag);
 
869
        }
 
870
        else {
 
871
            $values = array($owner->id, $owner->id);
 
872
        }
 
873
 
 
874
        $from = "FROM (
 
875
           (SELECT a.id, a.title, a.description, 'artefact' AS type, a.artefacttype, " . db_format_tsfield('a.ctime', 'ctime') . "
 
876
            FROM {artefact} a JOIN {artefact_tag} at ON (a.id = at.artefact)
 
877
            WHERE a.owner = ?" . $artefacttypefilter . ")
 
878
           UNION
 
879
           (SELECT v.id, v.title, v.description, 'view' AS type, NULL AS artefacttype, " . db_format_tsfield('v.ctime', 'ctime') . "
 
880
            FROM {view} v JOIN {view_tag} vt ON (v.id = vt.view)
 
881
            WHERE v.owner = ? " . $viewfilter . ")
 
882
        ) p";
 
883
 
 
884
        $result = (object) array(
 
885
            'tag'    => $tag,
 
886
            'owner'  => $owner,
 
887
            'offset' => $offset,
 
888
            'limit'  => $limit,
 
889
            'sort'   => $sort,
 
890
            'count'  => 0,
 
891
            'data'   => array(),
 
892
        );
 
893
 
 
894
        if ($count = count_records_sql('SELECT COUNT(*) ' . $from, $values, $offset, $limit)) {
 
895
            $result->count = $count;
 
896
            $sort = $sort == 'date' ? 'ctime DESC' : 'title ASC';
 
897
            if ($data = get_records_sql_assoc("SELECT type || ':' || id AS tid, p.* " . $from . ' ORDER BY ' . $sort, $values, $offset, $limit)) {
 
898
                if ($returntags) {
 
899
                    $ids = array('view' => array(), 'artefact' => array());
 
900
                    foreach ($data as &$d) {
 
901
                        $ids[$d->type][$d->id] = 1;
 
902
                    }
 
903
                    if (!empty($ids['view'])) {
 
904
                        if ($viewtags = get_records_select_array('view_tag', 'view IN (' . join(',', array_keys($ids['view'])) . ')')) {
 
905
                            foreach ($viewtags as &$vt) {
 
906
                                $data['view:' . $vt->view]->tags[] = $vt->tag;
 
907
                            }
 
908
                        }
 
909
                    }
 
910
                    if (!empty($ids['artefact'])) {
 
911
                        if ($artefacttags = get_records_select_array('artefact_tag', 'artefact IN (' . join(',', array_keys($ids['artefact'])) . ')')) {
 
912
                            foreach ($artefacttags as &$at) {
 
913
                                $data['artefact:' . $at->artefact]->tags[] = $at->tag;
 
914
                            }
 
915
                        }
 
916
                    }
 
917
                }
 
918
                $result->data = $data;
 
919
            }
 
920
        }
 
921
        return $result;
 
922
    }
 
923
 
 
924
 
 
925
    /**
836
926
     * Parses a query string into SQL fragments for searching. Supports 
837
927
     * phrases, AND/OR etc.
838
928
     *