コード例 #1
0
ファイル: factory.php プロジェクト: godboko/modules
/**
 *  Factory method that allows the creation of new objects
 *  @version $Id: factory.php,v 1.5 2003/06/24 21:30:30 roger Exp $
 *  @param string $class the name of the object to create
 *  @return object the created object
 */
function &calendar_userapi_factory($class)
{
    static $calobject;
    static $icalobject;
    static $eventobject;
    static $importobject;
    static $exportobject;
    static $alarmobject;
    static $modinfo;
    if (!isset($modinfo)) {
        $modInfo =& xarMod::getInfo(xarMod::getRegID('calendar'));
    }
    switch (strtolower($class)) {
        case 'calendar':
            if (!isset($calobject)) {
                sys::import("modules.{$modInfo['osdirectory']}.class.calendar");
                $calobject =& new Calendar();
            }
            return $calobject;
            break;
        case 'ical_parser':
            if (!isset($icalobject)) {
                sys::import("modules.{$modInfo['osdirectory']}.class.ical_parser");
                $icalobject =& new iCal_Parser();
            }
            return $icalobject;
            break;
        case 'event':
            if (!isset($eventobject)) {
                sys::import("modules.{$modInfo['osdirectory']}.class.event");
                $eventobject =& new Event();
            }
            return $eventobject;
            break;
            /*
            case 'import':
                break;
            
            case 'export':
                break;
            
            case 'alarm':
                break;
            */
        /*
        case 'import':
            break;
        
        case 'export':
            break;
        
        case 'alarm':
            break;
        */
        default:
            return;
            break;
    }
}
コード例 #2
0
ファイル: create_calendars.php プロジェクト: godboko/modules
/**
 * @returns int (calendar id on success, false on failure)
 */
function calendar_adminapi_create_calendars($args)
{
    extract($args);
    // argument check
    if (!isset($calname)) {
        $msg = xarML('Calendar name not specified', 'admin', 'create', 'calendar');
        throw new Exception($msg);
    }
    // TODO: should I move these two issets to the admin function
    // admin/create_calendars.php? --amoro
    if (!isset($mod_id)) {
        $module = xarController::$request->getInfo();
        $mod_id = xarMod::getRegID($module[0]);
    }
    if (!isset($role_id)) {
        $role_id = xarSession::getVar('role_id');
    }
    // Load up database details.
    $dbconn = xarDB::getConn();
    $xartable = xarDB::getTables();
    $caltable = $xartable['calendars'];
    // Insert instance details.
    $nextId = $dbconn->GenId($caltable);
    $query = 'INSERT INTO ' . $caltable . ' (
              xar_id,
              xar_role_id,
              xar_mod_id,
              xar_name
            ) VALUES (?, ?, ?, ?)';
    $result =& $dbconn->Execute($query, array($nextId, $role_id, $mod_id, $calname));
    if (!$result) {
        return;
    }
    // Get ID of row inserted.
    $calendid = $dbconn->PO_Insert_ID($caltable, 'xar_id');
    // If not database type also add file info
    // Allow duplicate files here, to make it easier to delete them
    // WARNING: if somebody changes this you should also change the
    // delete function to avoid major dataloss!!! --amoro
    if ($addtype != 'db') {
        $filestable = $xartable['calfiles'];
        $cal_filestable = $xartable['calendars_files'];
        $nextID = $dbconn->GenId($filestable);
        $query = 'INSERT INTO ' . $filestable . ' (
                  xar_id,
                  xar_path
                ) VALUES (?, ?)';
        $result =& $dbconn->Execute($query, array($nextID, $fileuri));
        // Get ID of row inserted.
        $fileid = $dbconn->PO_Insert_ID($filestable, 'xar_id');
        $query = 'INSERT INTO ' . $cal_filestable . ' (
                      xar_calendars_id,
                      xar_files_id
                    ) VALUES (?, ?)';
        $result =& $dbconn->Execute($query, array($calendid, $fileid));
    }
    return $calendid;
}
コード例 #3
0
ファイル: getpubcatcount.php プロジェクト: godboko/modules
/**
 * get the number of publications per publication type and category
 *
 * @param $args['state'] array of requested status(es) for the publications
 * @param $args['ptid'] publication type ID
 * @param $args['cids'] array of category IDs (OR/AND)
 * @param $args['andcids'] true means AND-ing categories listed in cids
 * @param $args['groupcids'] the number of categories you want items grouped by
 * @param $args['reverse'] default is ptid => cid, reverse (1) is cid => ptid
 * @return array array( $ptid => array( $cid => $count) ),
 *         or false on failure
 */
function publications_userapi_getpubcatcount($args)
{
    /*
        static $pubcatcount = array();
    
        if (count($pubcatcount) > 0) {
            return $pubcatcount;
        }
    */
    $pubcatcount = array();
    // Get database setup
    $dbconn = xarDB::getConn();
    // Get the LEFT JOIN ... ON ...  and WHERE parts from publications
    $publicationsdef = xarModAPIFunc('publications', 'user', 'leftjoin', $args);
    // Load API
    if (!xarModAPILoad('categories', 'user')) {
        return;
    }
    $args['modid'] = xarMod::getRegID('publications');
    if (isset($args['ptid']) && !isset($args['itemtype'])) {
        $args['itemtype'] = $args['ptid'];
    }
    // Get the LEFT JOIN ... ON ...  and WHERE parts from categories
    $categoriesdef = xarModAPIFunc('categories', 'user', 'leftjoin', $args);
    // Get count
    $query = 'SELECT ' . $publicationsdef['pubtype_id'] . ', ' . $categoriesdef['category_id'] . ', COUNT(*)
            FROM ' . $publicationsdef['table'] . '
            LEFT JOIN ' . $categoriesdef['table'] . '
            ON ' . $categoriesdef['field'] . ' = ' . $publicationsdef['field'] . $categoriesdef['more'] . '
            WHERE ' . $categoriesdef['where'] . ' AND ' . $publicationsdef['where'] . '
            GROUP BY ' . $publicationsdef['pubtype_id'] . ', ' . $categoriesdef['category_id'];
    $result =& $dbconn->Execute($query);
    if (!$result) {
        return;
    }
    if ($result->EOF) {
        if (!empty($args['ptid']) && empty($args['reverse'])) {
            $pubcatcount[$args['ptid']] = array();
        }
        return $pubcatcount;
    }
    while (!$result->EOF) {
        // we may have 1 or more cid fields here, depending on what we're
        // counting (cfr. AND in categories)
        $fields = $result->fields;
        $ptid = array_shift($fields);
        $count = array_pop($fields);
        // TODO: use multi-level array for multi-category grouping ?
        $cid = join('+', $fields);
        if (empty($args['reverse'])) {
            $pubcatcount[$ptid][$cid] = $count;
        } else {
            $pubcatcount[$cid][$ptid] = $count;
        }
        $result->MoveNext();
    }
    foreach ($pubcatcount as $id1 => $val) {
        $total = 0;
        foreach ($val as $id2 => $count) {
            $total += $count;
        }
        $pubcatcount[$id1]['total'] = $total;
    }
    return $pubcatcount;
}
コード例 #4
0
ファイル: xaruserapi.php プロジェクト: godboko/modules
    define('CALENDAR_FIRST_DAY_OF_WEEK', $cal_sdow);
} else {
    // set the first day of the week to the admin/user default
    define('CALENDAR_FIRST_DAY_OF_WEEK', 0);
}
//echo 'cal_sdow = '.CALENDAR_FIRST_DAY_OF_WEEK;
//======================================================================
// Define the location of the PEAR::Calendar files
//======================================================================
if (!defined('CALENDAR_ROOT')) {
    define('CALENDAR_ROOT', xarModVars::get('calendar', 'pearcalendar_root'));
}
//======================================================================
// Define directory locations for this module
//======================================================================
$modinfo = xarMod::getInfo(xarMod::getRegID('calendar'));
if (!defined('CALENDAR_MODULE_ROOT')) {
    define('CALENDAR_MODULE_ROOT', "code/modules/{$modinfo['directory']}/");
}
if (!defined('CALENDAR_MODULE_INCLUDES')) {
    define('CALENDAR_MODULE_INCLUDES', CALENDAR_MODULE_ROOT . 'xarincludes/');
}
/**
 *  Used to get the current view the calendar is in (Day, Week, Month, Year)
 */
function calendar_userapi_currentView()
{
    xarVarFetch('func', 'str::', $func, 'main', XARVAR_NOT_REQUIRED);
    $valid = array('day', 'week', 'month', 'year');
    $func = strtolower($func);
    if (!in_array($func, $valid)) {
コード例 #5
0
ファイル: getall.php プロジェクト: godboko/modules
/**
 * get overview of all publications
 * Note : the following parameters are all optional
 *
 * @param $args['numitems'] number of publications to get
 * @param $args['sort'] sort order ('create_date','title','hits','rating','author','id','summary','notes',...)
 * @param $args['startnum'] starting article number
 * @param $args['ids'] array of article ids to get
 * @param $args['owner'] the ID of the author
 * @param $args['ptid'] publication type ID (for news, sections, reviews, ...)
 * @param $args['state'] array of requested status(es) for the publications
 * @param $args['search'] search parameter(s)
 * @param $args['searchfields'] array of fields to search in
 * @param $args['searchtype'] start, end, like, eq, gt, ... (TODO)
 * @param $args['cids'] array of category IDs for which to get publications (OR/AND)
 *                      (for all categories don?t set it)
 * @param $args['andcids'] true means AND-ing categories listed in cids
 * @param $args['create_date'] publications published in a certain year (YYYY), month (YYYY-MM) or day (YYYY-MM-DD)
 * @param $args['startdate'] publications published at startdate or later
 *                           (unix timestamp format)
 * @param $args['enddate'] publications published before enddate
 *                         (unix timestamp format)
 * @param $args['fields'] array with all the fields to return per publication
 *                        Default list is : 'id','title','summary','owner',
 *                        'create_date','pubtype_id','notes','state','body1'
 *                        Optional fields : 'cids','author','counter','rating','dynamicdata'
 * @param $args['extra'] array with extra fields to return per article (in addition
 *                       to the default list). So you can EITHER specify *all* the
 *                       fields you want with 'fields', OR take all the default
 *                       ones and add some optional fields with 'extra'
 * @param $args['where'] additional where clauses (e.g. myfield gt 1234)
 * @param $args['locale'] language/locale (if not using multi-sites, categories etc.)
 * @return array Array of publications, or false on failure
 */
function publications_userapi_getall($args)
{
    // Get arguments from argument array
    extract($args);
    // Optional argument
    if (!isset($startnum)) {
        $startnum = 1;
    }
    if (empty($cids)) {
        $cids = array();
    }
    if (!isset($andcids)) {
        $andcids = false;
    }
    if (empty($ptid)) {
        $ptid = null;
    }
    // Default fields in publications (for now)
    $columns = array('id', 'name', 'title', 'description', 'summary', 'body1', 'owner', 'pubtype_id', 'notes', 'state', 'start_date');
    // Optional fields in publications (for now)
    // + 'cids' = list of categories an article belongs to
    // + 'author' = user name of owner
    // + 'counter' = number of times this article was displayed (hitcount)
    // + 'rating' = rating for this article (ratings)
    // + 'dynamicdata' = dynamic data fields for this article (dynamicdata)
    // + 'relevance' = relevance for this article (MySQL full-text search only)
    // $optional = array('cids','author','counter','rating','dynamicdata','relevance');
    if (!isset($fields)) {
        $fields = $columns;
    }
    if (isset($extra) && is_array($extra) && count($extra) > 0) {
        $fields = array_merge($fields, $extra);
    }
    if (empty($sort)) {
        if (!empty($search) && !empty($searchtype) && substr($searchtype, 0, 8) == 'fulltext') {
            if ($searchtype == 'fulltext boolean' && !in_array('relevance', $fields)) {
                // add the relevance to the field list for sorting
                $fields[] = 'relevance';
            }
            // let the database sort by relevance (= default for fulltext)
            $sortlist = array();
        } else {
            // default sort by create_date
            $sortlist = array('create_date');
        }
    } elseif (is_array($sort)) {
        $sortlist = $sort;
    } else {
        $sortlist = explode(',', $sort);
    }
    $publications = array();
    // Security check
    if (!xarSecurityCheck('ViewPublications')) {
        return;
    }
    // Fields requested by the calling function
    $required = array();
    foreach ($fields as $field) {
        $required[$field] = 1;
    }
    // mandatory fields for security
    $required['id'] = 1;
    $required['title'] = 1;
    $required['pubtype_id'] = 1;
    $required['create_date'] = 1;
    $required['owner'] = 1;
    // not to be confused with author (name) :-)
    // force cids as required when categories are given
    if (count($cids) > 0) {
        $required['cids'] = 1;
    }
    // TODO: put all this in dynamic data and retrieve everything via there (including hooked stuff)
    // Database information
    $dbconn = xarDB::getConn();
    // Get the field names and LEFT JOIN ... ON ... parts from publications
    // By passing on the $args, we can let leftjoin() create the WHERE for
    // the publications-specific columns too now
    $publicationsdef = xarModAPIFunc('publications', 'user', 'leftjoin', $args);
    // TODO : how to handle the case where name is empty, but uname isn't
    if (!empty($required['owner'])) {
        // Load API
        if (!xarModAPILoad('roles', 'user')) {
            return;
        }
        // Get the field names and LEFT JOIN ... ON ... parts from users
        $usersdef = xarModAPIFunc('roles', 'user', 'leftjoin');
        if (empty($usersdef)) {
            return;
        }
    }
    $regid = xarMod::getRegID('publications');
    if (!empty($required['cids'])) {
        // Load API
        if (!xarModAPILoad('categories', 'user')) {
            return;
        }
        // Get the LEFT JOIN ... ON ...  and WHERE (!) parts from categories
        $categoriesdef = xarModAPIFunc('categories', 'user', 'leftjoin', array('cids' => $cids, 'andcids' => $andcids, 'itemtype' => isset($ptid) ? $ptid : null, 'modid' => $regid));
        if (empty($categoriesdef)) {
            return;
        }
    }
    if (!empty($required['counter']) && xarModIsHooked('hitcount', 'publications', $ptid)) {
        // Load API
        if (!xarModAPILoad('hitcount', 'user')) {
            return;
        }
        // Get the LEFT JOIN ... ON ...  and WHERE (!) parts from hitcount
        $hitcountdef = xarModAPIFunc('hitcount', 'user', 'leftjoin', array('modid' => $regid, 'itemtype' => isset($ptid) ? $ptid : null));
    }
    if (!empty($required['rating']) && xarModIsHooked('ratings', 'publications', $ptid)) {
        // Load API
        if (!xarModAPILoad('ratings', 'user')) {
            return;
        }
        // Get the LEFT JOIN ... ON ...  and WHERE (!) parts from ratings
        $ratingsdef = xarModAPIFunc('ratings', 'user', 'leftjoin', array('modid' => $regid, 'itemtype' => isset($ptid) ? $ptid : null));
    }
    // Create the SELECT part
    $select = array();
    foreach ($required as $field => $val) {
        // we'll handle this later
        if ($field == 'cids') {
            continue;
        } elseif ($field == 'dynamicdata') {
            continue;
        } elseif ($field == 'owner') {
            $select[] = $usersdef['name'];
        } elseif ($field == 'counter') {
            if (!empty($hitcountdef['hits'])) {
                $select[] = $hitcountdef['hits'];
            }
        } elseif ($field == 'rating') {
            if (!empty($ratingsdef['rating'])) {
                $select[] = $ratingsdef['rating'];
            }
        } else {
            $select[] = $publicationsdef[$field];
        }
    }
    // FIXME: <rabbitt> PostgreSQL requires that all fields in an 'Order By' be in the SELECT
    //        this has been added to remove the error that not having it creates
    // FIXME: <mikespub> Oracle doesn't allow having the same field in a query twice if you
    //        don't specify an alias (at least in sub-queries, which is what SelectLimit uses)
    //    if (!in_array($publicationsdef['create_date'], $select)) {
    //        $select[] = $publicationsdef['create_date'];
    //    }
    // we need distinct for multi-category OR selects where publications fit in more than 1 category
    if (count($cids) > 0) {
        $query = 'SELECT DISTINCT ' . join(', ', $select);
    } else {
        $query = 'SELECT ' . join(', ', $select);
    }
    // Create the FROM ... [LEFT JOIN ... ON ...] part
    $from = $publicationsdef['table'];
    $addme = 0;
    if (!empty($required['owner'])) {
        // Add the LEFT JOIN ... ON ... parts from users
        $from .= ' LEFT JOIN ' . $usersdef['table'];
        $from .= ' ON ' . $usersdef['field'] . ' = ' . $publicationsdef['owner'];
        $addme = 1;
    }
    if (!empty($required['counter']) && isset($hitcountdef)) {
        // add this for SQL compliance when there are multiple JOINs
        // bug 4429: sqlite doesnt like the parentheses
        if ($addme && $dbconn->databaseType != 'sqlite') {
            $from = '(' . $from . ')';
        }
        // Add the LEFT JOIN ... ON ... parts from hitcount
        $from .= ' LEFT JOIN ' . $hitcountdef['table'];
        $from .= ' ON ' . $hitcountdef['field'] . ' = ' . $publicationsdef['id'];
        $addme = 1;
    }
    if (!empty($required['rating']) && isset($ratingsdef)) {
        // add this for SQL compliance when there are multiple JOINs
        // bug 4429: sqlite doesnt like the parentheses
        if ($addme && $dbconn->databaseType != 'sqlite') {
            $from = '(' . $from . ')';
        }
        // Add the LEFT JOIN ... ON ... parts from ratings
        $from .= ' LEFT JOIN ' . $ratingsdef['table'];
        $from .= ' ON ' . $ratingsdef['field'] . ' = ' . $publicationsdef['id'];
        $addme = 1;
    }
    if (count($cids) > 0) {
        // add this for SQL compliance when there are multiple JOINs
        // bug 4429: sqlite doesnt like the parentheses
        if ($addme && $dbconn->databaseType != 'sqlite') {
            $from = '(' . $from . ')';
        }
        // Add the LEFT JOIN ... ON ... parts from categories
        $from .= ' LEFT JOIN ' . $categoriesdef['table'];
        $from .= ' ON ' . $categoriesdef['field'] . ' = ' . $publicationsdef['id'];
        if (!empty($categoriesdef['more']) && $dbconn->databaseType != 'sqlite') {
            $from = '(' . $from . ')';
            $from .= $categoriesdef['more'];
        }
    }
    $query .= ' FROM ' . $from;
    // TODO: check the order of the conditions for brain-dead databases ?
    // Create the WHERE part
    $where = array();
    // we rely on leftjoin() to create the necessary publications clauses now
    if (!empty($publicationsdef['where'])) {
        $where[] = $publicationsdef['where'];
    }
    if (!empty($required['counter']) && !empty($hitcountdef['where'])) {
        $where[] = $hitcountdef['where'];
    }
    if (!empty($required['rating']) && !empty($ratingsdef['where'])) {
        $where[] = $ratingsdef['where'];
    }
    if (count($cids) > 0) {
        // we rely on leftjoin() to create the necessary categories clauses
        $where[] = $categoriesdef['where'];
    }
    if (count($where) > 0) {
        $query .= ' WHERE ' . join(' AND ', $where);
    }
    // TODO: support other non-publications fields too someday ?
    // Create the ORDER BY part
    if (count($sortlist) > 0) {
        $sortparts = array();
        $seenid = 0;
        foreach ($sortlist as $criteria) {
            // ignore empty sort criteria
            if (empty($criteria)) {
                continue;
            }
            // split off trailing ASC or DESC
            if (preg_match('/^(.+)\\s+(ASC|DESC)\\s*$/i', $criteria, $matches)) {
                $criteria = trim($matches[1]);
                $sortorder = strtoupper($matches[2]);
            } else {
                $sortorder = '';
            }
            if ($criteria == 'title') {
                $sortparts[] = $publicationsdef['title'] . ' ' . (!empty($sortorder) ? $sortorder : 'ASC');
                //            } elseif ($criteria == 'create_date' || $criteria == 'date') {
                //                $sortparts[] = $publicationsdef['create_date'] . ' ' . (!empty($sortorder) ? $sortorder : 'DESC');
            } elseif ($criteria == 'hits' && !empty($hitcountdef['hits'])) {
                $sortparts[] = $hitcountdef['hits'] . ' ' . (!empty($sortorder) ? $sortorder : 'DESC');
            } elseif ($criteria == 'rating' && !empty($ratingsdef['rating'])) {
                $sortparts[] = $ratingsdef['rating'] . ' ' . (!empty($sortorder) ? $sortorder : 'DESC');
            } elseif ($criteria == 'owner' && !empty($usersdef['name'])) {
                $sortparts[] = $usersdef['name'] . ' ' . (!empty($sortorder) ? $sortorder : 'ASC');
            } elseif ($criteria == 'relevance' && !empty($publicationsdef['relevance'])) {
                $sortparts[] = 'relevance' . ' ' . (!empty($sortorder) ? $sortorder : 'DESC');
            } elseif ($criteria == 'id') {
                $sortparts[] = $publicationsdef['id'] . ' ' . (!empty($sortorder) ? $sortorder : 'ASC');
                $seenid = 1;
                // other publications fields, e.g. summary, notes, ...
            } elseif (!empty($publicationsdef[$criteria])) {
                $sortparts[] = $publicationsdef[$criteria] . ' ' . (!empty($sortorder) ? $sortorder : 'ASC');
            } else {
                // ignore unknown sort fields
            }
        }
        // add sorting by id for unique sort order
        if (count($sortparts) < 2 && empty($seenid)) {
            $sortparts[] = $publicationsdef['id'] . ' DESC';
        }
        $query .= ' ORDER BY ' . join(', ', $sortparts);
    } elseif (!empty($search) && !empty($searchtype) && substr($searchtype, 0, 8) == 'fulltext') {
        // For fulltext, let the database return the publications by relevance here (= default)
        // For fulltext in boolean mode, add MATCH () ... AS relevance ... ORDER BY relevance DESC (cfr. leftjoin)
        if (!empty($required['relevance']) && $searchtype == 'fulltext boolean') {
            $query .= ' ORDER BY relevance DESC, ' . $publicationsdef['create_date'] . ' DESC, ' . $publicationsdef['id'] . ' DESC';
        }
    } else {
        // default is 'create_date'
        $query .= ' ORDER BY ' . $publicationsdef['create_date'] . ' DESC, ' . $publicationsdef['id'] . ' DESC';
    }
    //echo $query;
    // Run the query - finally :-)
    if (isset($numitems) && is_numeric($numitems)) {
        $result =& $dbconn->SelectLimit($query, $numitems, $startnum - 1);
    } else {
        $result =& $dbconn->Execute($query);
    }
    if (!$result) {
        return;
    }
    $itemids_per_type = array();
    // Put publications into result array
    for (; !$result->EOF; $result->MoveNext()) {
        $data = $result->fields;
        $item = array();
        // loop over all required fields again
        foreach ($required as $field => $val) {
            if ($field == 'cids' || $field == 'dynamicdata' || $val != 1) {
                continue;
            }
            $value = array_shift($data);
            if ($field == 'rating') {
                $value = intval($value);
            }
            $item[$field] = $value;
        }
        // check security - don't generate an exception here
        if (empty($required['cids']) && !xarSecurityCheck('ViewPublications', 0, 'Publication', "{$item['pubtype_id']}:All:{$item['owner']}:{$item['id']}")) {
            continue;
        }
        $publications[] = $item;
        if (!empty($required['dynamicdata'])) {
            $pubtype = $item['pubtype_id'];
            if (!isset($itemids_per_type[$pubtype])) {
                $itemids_per_type[$pubtype] = array();
            }
            $itemids_per_type[$pubtype][] = $item['id'];
        }
    }
    $result->Close();
    if (!empty($required['cids']) && count($publications) > 0) {
        // Get all the categories at once
        $ids = array();
        foreach ($publications as $article) {
            $ids[] = $article['id'];
        }
        // Load API
        if (!xarModAPILoad('categories', 'user')) {
            return;
        }
        // Get the links for the Array of iids we have
        $cids = xarModAPIFunc('categories', 'user', 'getlinks', array('iids' => $ids, 'reverse' => 1, 'modid' => $regid));
        // Inserting the corresponding Category ID in the Publication Description
        $delete = array();
        $cachesec = array();
        foreach ($publications as $key => $article) {
            if (isset($cids[$article['id']]) && count($cids[$article['id']]) > 0) {
                $publications[$key]['cids'] = $cids[$article['id']];
                foreach ($cids[$article['id']] as $cid) {
                    if (!xarSecurityCheck('ViewPublications', 0, 'Publication', "{$article['pubtype_id']}:{$cid}:{$article['owner']}:{$article['id']}")) {
                        $delete[$key] = 1;
                        break;
                    }
                    if (!isset($cachesec[$cid])) {
                        // TODO: combine with ViewCategoryLink check when we can combine module-specific
                        // security checks with "parent" security checks transparently ?
                        $cachesec[$cid] = xarSecurityCheck('ReadCategories', 0, 'Category', "All:{$cid}");
                    }
                    if (!$cachesec[$cid]) {
                        $delete[$key] = 1;
                        break;
                    }
                }
            } else {
                if (!xarSecurityCheck('ViewPublications', 0, 'Publication', "{$article['pubtype_id']}:All:{$article['owner']}:{$article['id']}")) {
                    $delete[$key] = 1;
                    continue;
                }
            }
        }
        if (count($delete) > 0) {
            foreach ($delete as $key => $val) {
                unset($publications[$key]);
            }
        }
    }
    if (!empty($required['dynamicdata']) && count($publications) > 0) {
        foreach ($itemids_per_type as $pubtype => $itemids) {
            if (!xarModIsHooked('dynamicdata', 'publications', $pubtype)) {
                continue;
            }
            list($properties, $items) = xarModAPIFunc('dynamicdata', 'user', 'getitemsforview', array('module' => 'publications', 'itemtype' => $pubtype, 'itemids' => $itemids, 'state' => 1));
            if (empty($properties) || count($properties) == 0) {
                continue;
            }
            foreach ($publications as $key => $article) {
                // otherwise publications (of different pub types) with dd properties having the same
                // names reset previously set values to empty string for each iteration based on the pubtype
                if ($article['pubtype_id'] != $pubtype) {
                    continue;
                }
                foreach (array_keys($properties) as $name) {
                    if (isset($items[$article['id']]) && isset($items[$article['id']][$name])) {
                        $value = $items[$article['id']][$name];
                    } else {
                        $value = $properties[$name]->default;
                    }
                    $publications[$key][$name] = $value;
                    // TODO: clean up this temporary fix
                    if (!empty($value)) {
                        $publications[$key][$name . '_output'] = $properties[$name]->showOutput(array('value' => $value));
                    }
                }
            }
        }
    }
    return $publications;
}
コード例 #6
0
function wurfl_admin_modifyconfig_utility()
{
    // Security Check
    if (!xarSecurityCheck('AdminWurfl')) {
        return;
    }
    if (!xarVarFetch('phase', 'str:1:100', $phase, 'modify', XARVAR_NOT_REQUIRED, XARVAR_PREP_FOR_DISPLAY)) {
        return;
    }
    if (!xarVarFetch('tab', 'str:1:100', $data['tab'], 'wurfl_general', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('tabmodule', 'str:1:100', $tabmodule, 'wurfl', XARVAR_NOT_REQUIRED)) {
        return;
    }
    $hooks = xarModCallHooks('module', 'getconfig', 'wurfl');
    if (!empty($hooks) && isset($hooks['tabs'])) {
        foreach ($hooks['tabs'] as $key => $row) {
            $configarea[$key] = $row['configarea'];
            $configtitle[$key] = $row['configtitle'];
            $configcontent[$key] = $row['configcontent'];
        }
        array_multisort($configtitle, SORT_ASC, $hooks['tabs']);
    } else {
        $hooks['tabs'] = array();
    }
    $regid = xarMod::getRegID($tabmodule);
    switch (strtolower($phase)) {
        case 'modify':
        default:
            switch ($data['tab']) {
                case 'wurfl_general':
                    break;
                case 'tab2':
                    break;
                case 'tab3':
                    break;
                default:
                    break;
            }
            break;
        case 'update':
            // Confirm authorisation code
            if (!xarSecConfirmAuthKey()) {
                return;
            }
            if (!xarVarFetch('items_per_page', 'int', $items_per_page, xarModVars::get('wurfl', 'items_per_page'), XARVAR_NOT_REQUIRED, XARVAR_PREP_FOR_DISPLAY)) {
                return;
            }
            if (!xarVarFetch('shorturls', 'checkbox', $shorturls, false, XARVAR_NOT_REQUIRED)) {
                return;
            }
            if (!xarVarFetch('modulealias', 'checkbox', $use_module_alias, xarModVars::get('wurfl', 'use_module_alias'), XARVAR_NOT_REQUIRED)) {
                return;
            }
            if (!xarVarFetch('module_alias_name', 'str', $module_alias_name, xarModVars::get('wurfl', 'module_alias_name'), XARVAR_NOT_REQUIRED)) {
                return;
            }
            if (!xarVarFetch('defaultmastertable', 'str', $defaultmastertable, xarModVars::get('wurfl', 'defaultmastertable'), XARVAR_NOT_REQUIRED)) {
                return;
            }
            if (!xarVarFetch('bar', 'str:1', $bar, 'Bar', XARVAR_NOT_REQUIRED)) {
                return;
            }
            $modvars = array('defaultmastertable', 'bar');
            if ($data['tab'] == 'wurfl_general') {
                xarModVars::set('wurfl', 'items_per_page', $items_per_page);
                xarModVars::set('wurfl', 'supportshorturls', $shorturls);
                xarModVars::set('wurfl', 'use_module_alias', $use_module_alias);
                xarModVars::set('wurfl', 'module_alias_name', $module_alias_name);
                foreach ($modvars as $var) {
                    if (isset(${$var})) {
                        xarModVars::set('wurfl', $var, ${$var});
                    }
                }
            }
            foreach ($modvars as $var) {
                if (isset(${$var})) {
                    xarModItemVars::set('wurfl', $var, ${$var}, $regid);
                }
            }
            xarController::redirect(xarModURL('wurfl', 'admin', 'modifyconfig', array('tabmodule' => $tabmodule, 'tab' => $data['tab'])));
            // Return
            return true;
            break;
    }
    $data['hooks'] = $hooks;
    $data['tabmodule'] = $tabmodule;
    $data['authid'] = xarSecGenAuthKey();
    return $data;
}