コード例 #1
0
ファイル: xarinit.php プロジェクト: godboko/modules
function wurfl_init()
{
    xarRegisterMask('ViewWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_OVERVIEW');
    xarRegisterMask('ReadWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_READ');
    xarRegisterMask('CommentWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_COMMENT');
    xarRegisterMask('ModerateWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_MODERATE');
    xarRegisterMask('EditWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_EDIT');
    xarRegisterMask('AddWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_ADD');
    xarRegisterMask('ManageWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_DELETE');
    xarRegisterMask('AdminWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_ADMIN');
    # --------------------------------------------------------
    #
    # Set up privileges
    #
    xarRegisterPrivilege('ViewWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_OVERVIEW');
    xarRegisterPrivilege('ReadWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_READ');
    xarRegisterPrivilege('CommentWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_COMMENT');
    xarRegisterPrivilege('ModerateWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_MODERATE');
    xarRegisterPrivilege('EditWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_EDIT');
    xarRegisterPrivilege('AddWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_ADD');
    xarRegisterPrivilege('ManageWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_DELETE');
    xarRegisterPrivilege('AdminWurfl', 'All', 'wurfl', 'All', 'All', 'ACCESS_ADMIN');
    # --------------------------------------------------------
    #
    # Set up modvars
    #
    $module_settings = xarMod::apiFunc('base', 'admin', 'getmodulesettings', array('module' => 'wurfl'));
    $module_settings->initialize();
    // Add variables like this next one when creating utility modules
    // This variable is referenced in the xaradmin/modifyconfig-utility.php file
    // This variable is referenced in the xartemplates/includes/defaults.xd file
    xarModVars::set('wurfl', 'defaultmastertable', 'wurfl_wurfl');
    # --------------------------------------------------------
    #
    # Set up hooks
    #
    return true;
}
コード例 #2
0
ファイル: publish.php プロジェクト: godboko/modules
/**
 * Publish a calendar
 */
function calendar_user_publish($args)
{
    extract($args);
    xarVarFetch('calid', 'id', $calid, 0, XARVAR_NOT_REQUIRED);
    xarVarFetch('calname', 'str:1:', $calname, '', XARVAR_NOT_REQUIRED);
    // test
    xarModVars::set('calendar', 'SupportShortURLs', 1);
    // TODO: security et al.
    if (!empty($calid) || !empty($calname)) {
        /* TEST: protect remote calendar access with basic authentication
            // cfr. notes at http://www.php.net/features.http-auth for IIS or CGI support
                if (empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW']) ||
                    // is this a valid user/password ?
                    !xarUserLogIn($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) ||
                    // does this user have access to this calendar ?
                    !xarSecurityCheck('ViewCalendar',0,'All',$calname)) {
        
                    $realm = xarModVars::get('themes','SiteName');
                    header('WWW-Authenticate: Basic realm="'.$realm.'"');
                    //header('HTTP/1.0 401 Unauthorized');
                    header("Status: 401 Access Denied");
                    echo xarML('You must enter a valid username and password to access this calendar');
                    exit;
                 }
        */
        $calendars = xarMod::apiFunc('calendar', 'user', 'get', array('calid' => $calid, 'calname' => $calname));
        if (!isset($calendars)) {
            return;
        }
        // we found a calendar
        if (count($calendars) == 1) {
            if (empty($calendars[0]['cpath'])) {
                // TODO: retrieve entries from database and create ics file
            } else {
                $curdir = sys::varpath() . '/calendar';
                $curfile = $curdir . '/' . $calendars[0]['cpath'];
                if (file_exists($curfile) && filesize($curfile) > 0) {
                    if ($_SERVER['REQUEST_METHOD'] != 'PUT') {
                        // return the .ics file
                        header('Content-Type: text/calendar');
                        @readfile($curfile);
                        // TODO: use webdavserver instead ?
                        // Cfr. phpicalendar/calendars/publish.php (doesn't seem to work for PHP < 4.3)
                        // publishing
                    } else {
                        // get calendar data
                        $data = '';
                        if ($fp = fopen('php://input', 'r')) {
                            while ($chunk = fgets($fp, 4096)) {
                                $data .= $chunk;
                            }
                            /*
                            while(!@feof($fp))
                            {
                                $data .= fgets($fp,4096);
                            }
                            */
                            @fclose($fp);
                        } else {
                            xarLogMessage('failed opening standard input');
                        }
                        if (!empty($data)) {
                            //xarLogMessage($data);
                            // write to file
                            if ($fp = fopen($curfile, 'w+')) {
                                fputs($fp, $data, strlen($data));
                                @fclose($fp);
                            } else {
                                xarLogMessage('couldnt open file ' . $curfile);
                            }
                        } else {
                            xarLogMessage('failed getting any data');
                        }
                    }
                    // we're done here
                    exit;
                }
            }
        }
    }
    $data = array();
    $data['calendars'] = xarMod::apiFunc('calendar', 'user', 'getall');
    return $data;
}
コード例 #3
0
ファイル: updateconfig.php プロジェクト: godboko/modules
/**
 * This is a standard function to update the configuration parameters of the
 * module given the information passed back by the modification form
 */
function calendar_admin_updateconfig()
{
    // Get parameters from whatever input we need.  All arguments to this
    // function should be obtained from xarVarFetch(), xarVarCleanFromInput
    // is a degraded function.  xarVarFetch allows the checking of the input
    // variables as well as setting default values if needed.  Getting vars
    // from other places such as the environment is not allowed, as that makes
    // assumptions that will not hold in future versions of Xaraya
    if (!xarVarFetch('shorturls', 'checkbox', $shorturls, false, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Variables from phpIcalendar config.inc.php
    if (!xarVarFetch('default_view', 'isset', $default_view, 'Week', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('minical_view', 'isset', $minical_view, 'Week', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('default_cal', 'isset', $default_cal, array(), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('cal_sdow', 'int:0:6', $cal_sdow, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('day_start', 'isset', $day_start, '0800', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('day_end', 'isset', $day_end, '2100', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('gridLength', 'int:0', $gridLength, 15, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('num_years', 'int:0', $num_years, 1, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('month_event_lines', 'int:0', $month_event_lines, 1, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('tomorrows_events_lines', 'int:0', $tomorrows_events_lines, 1, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('allday_week_lines', 'int:0', $allday_week_lines, 1, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('week_events_lines', 'int:0', $week_events_lines, 1, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('second_offset', 'int:0', $second_offset, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('bleed_time', 'int:0', $bleed_time, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('display_custom_goto', 'checkbox', $display_custom_goto, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('display_ical_list', 'checkbox', $display_ical_list, 1, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('allow_webcals', 'checkbox', $allow_webcals, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('this_months_events', 'checkbox', $this_months_events, 1, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('use_color_cals', 'checkbox', $use_color_cals, 1, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('daysofweek_dayview', 'checkbox', $daysofweek_dayview, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('enable_rss', 'checkbox', $enable_rss, 1, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('show_search', 'checkbox', $show_search, 1, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('allow_preferences', 'checkbox', $allow_preferences, 1, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('printview_default', 'checkbox', $printview_default, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('show_todos', 'checkbox', $show_todos, 1, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('show_completed', 'checkbox', $show_completed, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('allow_login', 'checkbox', $allow_login, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Confirm authorisation code.  This checks that the form had a valid
    // authorisation code attached to it.  If it did not then the function will
    // proceed no further as it is possible that this is an attempt at sending
    // in false data to the system
    if (!xarSecConfirmAuthKey()) {
        return;
    }
    // Update module variables.  Note that the default values are set in
    // xarVarFetch when recieving the incoming values, so no extra processing
    // is needed when setting the variables here.
    xarModVars::set('calendar', 'SupportShortURLs', $shorturls);
    // Variables from phpIcalendar config.inc.php
    xarModVars::set('calendar', 'default_view', $default_view);
    xarModVars::set('calendar', 'minical_view', $minical_view);
    xarModVars::set('calendar', 'default_cal', serialize($default_cal));
    xarModVars::set('calendar', 'cal_sdow', $cal_sdow);
    xarModVars::set('calendar', 'day_start', $day_start);
    xarModVars::set('calendar', 'day_end', $day_end);
    xarModVars::set('calendar', 'gridLength', $gridLength);
    xarModVars::set('calendar', 'num_years', $num_years);
    xarModVars::set('calendar', 'month_event_lines', $month_event_lines);
    xarModVars::set('calendar', 'tomorrows_events_lines', $tomorrows_events_lines);
    xarModVars::set('calendar', 'allday_week_lines', $allday_week_lines);
    xarModVars::set('calendar', 'week_events_lines', $week_events_lines);
    xarModVars::set('calendar', 'second_offset', $second_offset);
    xarModVars::set('calendar', 'bleed_time', $bleed_time);
    xarModVars::set('calendar', 'display_custom_goto', $display_custom_goto);
    xarModVars::set('calendar', 'display_ical_list', $display_ical_list);
    xarModVars::set('calendar', 'allow_webcals', $allow_webcals);
    xarModVars::set('calendar', 'this_months_events', $this_months_events);
    xarModVars::set('calendar', 'use_color_cals', $use_color_cals);
    xarModVars::set('calendar', 'daysofweek_dayview', $daysofweek_dayview);
    xarModVars::set('calendar', 'enable_rss', $enable_rss);
    xarModVars::set('calendar', 'show_search', $show_search);
    xarModVars::set('calendar', 'allow_preferences', $allow_preferences);
    xarModVars::set('calendar', 'printview_default', $printview_default);
    xarModVars::set('calendar', 'show_todos', $show_todos);
    xarModVars::set('calendar', 'show_completed', $show_completed);
    xarModVars::set('calendar', 'allow_login', $allow_login);
    xarModCallHooks('module', 'updateconfig', 'calendar', array('module' => 'calendar'));
    // This function generated no output, and so now it is complete we redirect
    // the user to an appropriate page for them to carry on their work
    xarController::redirect(xarModURL('calendar', 'admin', 'modifyconfig'));
    // Return
    return true;
}
コード例 #4
0
function mailer_admin_modifyconfig()
{
    // Security Check
    if (!xarSecurityCheck('AdminMailer')) {
        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'], 'general', XARVAR_NOT_REQUIRED)) {
        return;
    }
    switch (strtolower($phase)) {
        case 'modify':
        default:
            switch ($data['tab']) {
                case 'general':
                    break;
                case 'tab2':
                    break;
                case 'tab3':
                    break;
                default:
                    break;
            }
            break;
        case 'update':
            // Confirm authorisation code
            if (!xarSecConfirmAuthKey()) {
                return;
            }
            switch ($data['tab']) {
                case 'general':
                    if (!xarVarFetch('itemsperpage', 'int', $itemsperpage, xarModVars::get('mailer', 'itemsperpage'), XARVAR_NOT_REQUIRED, XARVAR_PREP_FOR_DISPLAY)) {
                        return;
                    }
                    if (!xarVarFetch('shorturls', 'checkbox', $shorturls, false, XARVAR_NOT_REQUIRED)) {
                        return;
                    }
                    if (!xarVarFetch('modulealias', 'checkbox', $useModuleAlias, xarModVars::get('mailer', 'useModuleAlias'), XARVAR_NOT_REQUIRED)) {
                        return;
                    }
                    if (!xarVarFetch('aliasname', 'str', $aliasname, xarModVars::get('mailer', 'aliasname'), XARVAR_NOT_REQUIRED)) {
                        return;
                    }
                    xarModVars::set('mailer', 'itemsperpage', $itemsperpage);
                    xarModVars::set('mailer', 'SupportShortURLs', $shorturls);
                    xarModVars::set('mailer', 'useModuleAlias', $useModuleAlias);
                    xarModVars::set('mailer', 'aliasname', $aliasname);
                    break;
                case 'tab2':
                    break;
                case 'tab3':
                    break;
                default:
                    break;
            }
            xarController::redirect(xarModURL('mailer', 'admin', 'modifyconfig', array('tab' => $data['tab'])));
            // Return
            return true;
            break;
    }
    $data['authid'] = xarSecGenAuthKey();
    return $data;
}
コード例 #5
0
ファイル: updateconfig.php プロジェクト: godboko/modules
function publications_admin_updateconfig()
{
    // Confirm authorisation code
    if (!xarSecConfirmAuthKey()) {
        return;
    }
    // Get parameters
    //A lot of these probably are bools, still might there be a need to change the template to return
    //'true' and 'false' to use those...
    if (!xarVarFetch('settings', 'array', $settings, array(), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('usetitleforurl', 'int', $usetitleforurl, xarModVars::get('publications', 'usetitleforurl'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('defaultstate', 'isset', $defaultstate, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('defaultsort', 'isset', $defaultsort, 'date', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('usealias', 'int', $usealias, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('ptid', 'isset', $ptid, xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('multilanguage', 'int', $multilanguage, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('tab', 'str:1:10', $data['tab'], 'global', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarSecurityCheck('AdminPublications', 1, 'Publication', "{$ptid}:All:All:All")) {
        return;
    }
    if ($data['tab'] == 'global') {
        if (!xarVarFetch('defaultpubtype', 'isset', $defaultpubtype, 1, XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('sortpubtypes', 'isset', $sortpubtypes, 'id', XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('defaultlanguage', 'str:1:100', $defaultlanguage, xarModVars::get('publications', 'defaultlanguage'), XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('debugmode', 'checkbox', $debugmode, xarModVars::get('publications', 'debugmode'), XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('defaultfrontpage', 'str', $defaultfrontpage, xarModVars::get('publications', 'defaultfrontpage'), XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('defaultbackpage', 'str', $defaultbackpage, xarModVars::get('publications', 'defaultbackpage'), XARVAR_NOT_REQUIRED)) {
            return;
        }
        xarModVars::set('publications', 'defaultpubtype', $defaultpubtype);
        xarModVars::set('publications', 'sortpubtypes', $sortpubtypes);
        xarModVars::set('publications', 'defaultlanguage', $defaultlanguage);
        xarModVars::set('publications', 'debugmode', $debugmode);
        xarModVars::set('publications', 'usealias', $usealias);
        xarModVars::set('publications', 'usetitleforurl', $usetitleforurl);
        xarModVars::set('publications', 'defaultfrontpage', $defaultfrontpage);
        xarModVars::set('publications', 'defaultbackpage', $defaultbackpage);
        // Allow multilanguage only if the languages property is present
        sys::import('modules.dynamicdata.class.properties.registration');
        $types = PropertyRegistration::Retrieve();
        if (isset($types[30039])) {
            xarModVars::set('publications', 'multilanguage', $multilanguage);
        } else {
            xarModVars::set('publications', 'multilanguage', 0);
        }
        // Get the special pages.
        foreach (array('defaultpage', 'errorpage', 'notfoundpage', 'noprivspage') as $special_name) {
            unset($special_id);
            if (!xarVarFetch($special_name, 'id', $special_id, 0, XARVAR_NOT_REQUIRED)) {
                return;
            }
            xarModVars::set('publications', $special_name, $special_id);
        }
        if (xarDB::getType() == 'mysql') {
            if (!xarVarFetch('fulltext', 'isset', $fulltext, '', XARVAR_NOT_REQUIRED)) {
                return;
            }
            $oldval = xarModVars::get('publications', 'fulltextsearch');
            $index = 'i_' . xarDB::getPrefix() . '_publications_fulltext';
            if (empty($fulltext) && !empty($oldval)) {
                // Get database setup
                $dbconn = xarDB::getConn();
                $xartable = xarDB::getTables();
                $publicationstable = $xartable['publications'];
                // Drop fulltext index on publications table
                $query = "ALTER TABLE {$publicationstable} DROP INDEX {$index}";
                $result =& $dbconn->Execute($query);
                if (!$result) {
                    return;
                }
                xarModVars::set('publications', 'fulltextsearch', '');
            } elseif (!empty($fulltext) && empty($oldval)) {
                $searchfields = array('title', 'description', 'summary', 'body1', 'notes');
                //                $searchfields = explode(',',$fulltext);
                // Get database setup
                $dbconn = xarDB::getConn();
                $xartable = xarDB::getTables();
                $publicationstable = $xartable['publications'];
                // Add fulltext index on publications table
                $query = "ALTER TABLE {$publicationstable} ADD FULLTEXT {$index} (" . join(', ', $searchfields) . ")";
                $result =& $dbconn->Execute($query);
                if (!$result) {
                    return;
                }
                xarModVars::set('publications', 'fulltextsearch', join(',', $searchfields));
            }
        }
        // Module settings
        $data['module_settings'] = xarMod::apiFunc('base', 'admin', 'getmodulesettings', array('module' => 'publications'));
        $data['module_settings']->setFieldList('items_per_page, use_module_alias, module_alias_name, enable_short_urls, user_menu_link', 'use_module_icons');
        $isvalid = $data['module_settings']->checkInput();
        if (!$isvalid) {
            return xarTplModule('base', 'admin', 'modifyconfig', $data);
        } else {
            $itemid = $data['module_settings']->updateItem();
        }
        // Pull the base category ids from the template and save them
        $picker = DataPropertyMaster::getProperty(array('name' => 'categorypicker'));
        $picker->checkInput('basecid');
    } elseif ($data['tab'] == 'pubtypes') {
        // Get the publication type for this display and save the settings to it
        $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types'));
        $pubtypeobject->getItem(array('itemid' => $ptid));
        $configsettings = $pubtypeobject->properties['configuration']->getValue();
        $checkbox = DataPropertyMaster::getProperty(array('name' => 'checkbox'));
        $boxes = array('show_hitount', 'show_ratings', 'show_keywords', 'show_comments', 'show_prevnext', 'show_archives', 'show_publinks', 'show_pubcount', 'show_map', 'prevnextart', 'dot_transform', 'title_transform', 'show_categories', 'show_catcount', 'show_prevnext', 'allow_translations');
        foreach ($boxes as $box) {
            $isvalid = $checkbox->checkInput($box);
            if ($isvalid) {
                $settings[$box] = $checkbox->value;
            }
        }
        //        foreach ($configsettings as $key => $value)
        //            if (!isset($settings[$key])) $settings[$key] = 0;
        $isvalid = true;
        // Get the default access rules
        $access = DataPropertyMaster::getProperty(array('name' => 'access'));
        $validprop = $access->checkInput("access_add");
        $addaccess = $access->value;
        $isvalid = $isvalid && $validprop;
        $validprop = $access->checkInput("access_display");
        $displayaccess = $access->value;
        $isvalid = $isvalid && $validprop;
        $validprop = $access->checkInput("access_modify");
        $modifyaccess = $access->value;
        $isvalid = $isvalid && $validprop;
        $validprop = $access->checkInput("access_delete");
        $deleteaccess = $access->value;
        $isvalid = $isvalid && $validprop;
        $allaccess = array('add' => $addaccess, 'display' => $displayaccess, 'modify' => $modifyaccess, 'delete' => $deleteaccess);
        $pubtypeobject->properties['access']->setValue(serialize($allaccess));
        $pubtypeobject->properties['configuration']->setValue(serialize($settings));
        $pubtypeobject->updateItem(array('itemid' => $ptid));
        $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
        if ($usealias) {
            xarModSetAlias($pubtypes[$ptid]['name'], 'publications');
        } else {
            xarModDelAlias($pubtypes[$ptid]['name'], 'publications');
        }
    } elseif ($data['tab'] == 'redirects') {
        $redirects = DataPropertyMaster::getProperty(array('name' => 'array'));
        $redirects->display_column_definition['value'] = array(array("From", "To"), array(2, 2), array("", ""), array("", ""));
        $isvalid = $redirects->checkInput("redirects");
        xarModVars::set('publications', 'redirects', $redirects->value);
    }
    xarController::redirect(xarModURL('publications', 'admin', 'modifyconfig', array('ptid' => $ptid, 'tab' => $data['tab'])));
    return true;
}
コード例 #6
0
ファイル: importpubtype.php プロジェクト: godboko/modules
/**
 * Import an object definition or an object item from XML
 */
function publications_adminapi_importpubtype($args)
{
    // Security check - we require ADMIN rights here
    if (!xarSecurityCheck('AdminPublications')) {
        return;
    }
    extract($args);
    if (empty($xml) && empty($file)) {
        $msg = xarML('Missing import file or XML content');
        throw new BadParameterException(null, $msg);
    } elseif (!empty($file) && (!file_exists($file) || !preg_match('/\\.xml$/', $file))) {
        $msg = xarML('Invalid import file');
        throw new BadParameterException(null, $msg);
    }
    $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
    $proptypes = DataPropertyMaster::getPropertyTypes();
    $name2id = array();
    foreach ($proptypes as $propid => $proptype) {
        $name2id[$proptype['name']] = $propid;
    }
    $prefix = xarDB::getPrefix();
    $prefix .= '_';
    if (!empty($file)) {
        $fp = @fopen($file, 'r');
        if (!$fp) {
            $msg = xarML('Unable to open import file');
            throw new BadParameterException(null, $msg);
        }
    } else {
        $lines = preg_split("/\r?\n/", $xml);
        $maxcount = count($lines);
    }
    $what = '';
    $count = 0;
    $ptid = 0;
    $objectname2objectid = array();
    $objectcache = array();
    $objectmaxid = array();
    while (!empty($file) && !feof($fp) || !empty($xml) && $count < $maxcount) {
        if (!empty($file)) {
            $line = fgets($fp, 4096);
        } else {
            $line = $lines[$count];
        }
        $count++;
        if (empty($what)) {
            if (preg_match('#<object name="(\\w+)">#', $line, $matches)) {
                // in case we import the object definition
                $object = array();
                $object['name'] = $matches[1];
                $what = 'object';
            } elseif (preg_match('#<items>#', $line)) {
                // in case we only import data
                $what = 'item';
            }
        } elseif ($what == 'object') {
            if (preg_match('#<([^>]+)>(.*)</\\1>#', $line, $matches)) {
                $key = $matches[1];
                $value = $matches[2];
                if (isset($object[$key])) {
                    if (!empty($file)) {
                        fclose($fp);
                    }
                    $msg = xarML('Duplicate definition for #(1) key #(2) on line #(3)', 'object', xarVarPrepForDisplay($key), $count);
                    throw new DuplicateException(null, $msg);
                }
                $object[$key] = $value;
            } elseif (preg_match('#<config>#', $line)) {
                if (isset($object['config'])) {
                    if (!empty($file)) {
                        fclose($fp);
                    }
                    $msg = xarML('Duplicate definition for #(1) key #(2) on line #(3)', 'object', 'config', $count);
                    throw new DuplicateException(null, $msg);
                }
                $config = array();
                $what = 'config';
            } elseif (preg_match('#<properties>#', $line)) {
                if (empty($object['name']) || empty($object['moduleid'])) {
                    if (!empty($file)) {
                        fclose($fp);
                    }
                    $msg = xarML('Missing keys in object definition');
                    throw new BadParameterException(null, $msg);
                }
                // make sure we drop the object id, because it might already exist here
                unset($object['objectid']);
                $properties = array();
                $what = 'property';
            } elseif (preg_match('#<items>#', $line)) {
                $what = 'item';
            } elseif (preg_match('#</object>#', $line)) {
                $what = '';
            } else {
                // multi-line entries not relevant here
            }
        } elseif ($what == 'config') {
            if (preg_match('#<([^>]+)>(.*)</\\1>#', $line, $matches)) {
                $key = $matches[1];
                $value = $matches[2];
                if (isset($config[$key])) {
                    if (!empty($file)) {
                        fclose($fp);
                    }
                    $msg = xarML('Duplicate definition for #(1) key #(2) on line #(3)', 'config', xarVarPrepForDisplay($key), $count);
                    throw new DuplicateException(null, $msg);
                }
                $config[$key] = $value;
            } elseif (preg_match('#</config>#', $line)) {
                // override default view if necessary
                $config['defaultview'] = 1;
                $object['config'] = serialize($config);
                $config = array();
                $what = 'object';
            } else {
                // multi-line entries not relevant here
            }
        } elseif ($what == 'property') {
            if (preg_match('#<property name="(\\w+)">#', $line, $matches)) {
                $property = array();
                $property['name'] = $matches[1];
            } elseif (preg_match('#</property>#', $line)) {
                if (empty($property['name']) || empty($property['type'])) {
                    if (!empty($file)) {
                        fclose($fp);
                    }
                    $msg = xarML('Missing keys in property definition');
                    throw new BadParameterException(null, $msg);
                }
                // make sure we drop the property id, because it might already exist here
                unset($property['id']);
                // TODO: watch out for multi-sites
                // replace default xar_* table prefix with local one
                $property['source'] = preg_replace("/^xar_/", $prefix, $property['source']);
                // add this property to the list
                $properties[] = $property;
            } elseif (preg_match('#<([^>]+)>(.*)</\\1>#', $line, $matches)) {
                $key = $matches[1];
                $value = $matches[2];
                if (isset($property[$key])) {
                    if (!empty($file)) {
                        fclose($fp);
                    }
                    $msg = xarML('Duplicate definition for #(1) key #(2) on line #(3)', 'property', xarVarPrepForDisplay($key), $count);
                    throw new DuplicateException(null, $msg);
                }
                $property[$key] = $value;
            } elseif (preg_match('#</properties>#', $line)) {
                // 1. make sure we have a unique pubtype name
                foreach ($pubtypes as $pubid => $pubtype) {
                    if ($object['name'] == $pubtype['name']) {
                        $object['name'] .= '_' . time();
                        break;
                    }
                }
                // 2. fill in the pubtype field config
                $fields = array();
                $extra = array();
                foreach ($properties as $property) {
                    $field = $property['name'];
                    switch ($field) {
                        case 'id':
                        case 'pubtype_id':
                            // skip these
                            break;
                        case 'title':
                        case 'summary':
                        case 'body':
                        case 'notes':
                        case 'owner':
                        case 'pubdate':
                        case 'state':
                            // convert property type to string if necessary
                            if (is_numeric($property['type'])) {
                                if (isset($proptypes[$property['type']])) {
                                    $property['type'] = $proptypes[$property['type']]['name'];
                                } else {
                                    $property['type'] = 'static';
                                }
                            }
                            // reset disabled field labels to empty
                            if (empty($property['state'])) {
                                $property['label'] = '';
                            }
                            if (!isset($property['validation'])) {
                                $property['validation'] = '';
                            }
                            $fields[$field] = array('label' => $property['label'], 'format' => $property['type'], 'input' => $property['input'], 'validation' => $property['validation']);
                            break;
                        default:
                            // convert property type to numeric if necessary
                            if (!is_numeric($property['type'])) {
                                if (isset($name2id[$property['type']])) {
                                    $property['type'] = $name2id[$property['type']];
                                } else {
                                    $property['type'] = 1;
                                }
                            }
                            $extra[] = $property;
                            break;
                    }
                }
                // 3. create the pubtype
                $ptid = xarModAPIFunc('publications', 'admin', 'createpubtype', array('name' => $object['name'], 'descr' => $object['label'], 'config' => $fields));
                if (empty($ptid)) {
                    return;
                }
                // 4. set the module variables
                xarModVars::set('publications', 'settings.' . $ptid, $object['config']);
                xarModVars::set('publications', 'number_of_categories.' . $ptid, 0);
                xarModVars::set('publications', 'mastercids.' . $ptid, '');
                // 5. create a dynamic object if necessary
                if (count($extra) > 0) {
                    $object['itemtype'] = $ptid;
                    $object['config'] = '';
                    $object['isalias'] = 0;
                    $objectid = xarModAPIFunc('dynamicdata', 'admin', 'createobject', $object);
                    if (!isset($objectid)) {
                        if (!empty($file)) {
                            fclose($fp);
                        }
                        return;
                    }
                    // 6. create the dynamic properties
                    foreach ($extra as $property) {
                        $property['objectid'] = $objectid;
                        $property['moduleid'] = $object['moduleid'];
                        $property['itemtype'] = $object['itemtype'];
                        $prop_id = xarModAPIFunc('dynamicdata', 'admin', 'createproperty', $property);
                        if (!isset($prop_id)) {
                            if (!empty($file)) {
                                fclose($fp);
                            }
                            return;
                        }
                    }
                    // 7. check if we need to enable DD hooks for this pubtype
                    if (!xarModIsHooked('dynamicdata', 'publications')) {
                        xarModAPIFunc('modules', 'admin', 'enablehooks', array('callerModName' => 'publications', 'callerItemType' => $ptid, 'hookModName' => 'dynamicdata'));
                    }
                }
                $properties = array();
                $what = 'object';
            } elseif (preg_match('#<items>#', $line)) {
                $what = 'item';
            } elseif (preg_match('#</object>#', $line)) {
                $what = '';
            } else {
                // multi-line entries not relevant here
            }
        } elseif ($what == 'item') {
            /* skip this for publications
                        if (preg_match('#<([^> ]+) itemid="(\d+)">#',$line,$matches)) {
                            // find out what kind of item we're dealing with
                            $objectname = $matches[1];
                            $itemid = $matches[2];
                            if (empty($objectname2objectid[$objectname])) {
                                $objectinfo = DataObjectMaster::getObjectInfo(array('name' => $objectname));
                                if (isset($objectinfo) && !empty($objectinfo['objectid'])) {
                                    $objectname2objectid[$objectname] = $objectinfo['objectid'];
                                } else {
                                    if (!empty($file)) fclose($fp);
                                    $msg = xarML('Unknown #(1) "#(2)" on line #(3)','object',xarVarPrepForDisplay($objectname),$count);
                                    throw new BadParameterException(null, $msg);
                                }
                            }
                            $objectid = $objectname2objectid[$objectname];
                            $item = array();
                            // don't save the item id for now...
                        // TODO: keep the item id if we set some flag
                            //$item['itemid'] = $itemid;
                            $closeitem = $objectname;
                            $closetag = 'N/A';
                        } elseif (preg_match("#</$closeitem>#",$line)) {
                            // let's create the item now...
                            if (!isset($objectcache[$objectid])) {
                                $objectcache[$objectid] = new DataObject(array('objectid' => $objectid));
                            }
                            // set the item id to 0
                        // TODO: keep the item id if we set some flag
                            $item['itemid'] = 0;
                            // create the item
                            $itemid = $objectcache[$objectid]->createItem($item);
                            if (empty($itemid)) {
                                if (!empty($file)) fclose($fp);
                                return;
                            }
                            // keep track of the highest item id
                            if (empty($objectmaxid[$objectid]) || $objectmaxid[$objectid] < $itemid) {
                                $objectmaxid[$objectid] = $itemid;
                            }
                            $closeitem = 'N/A';
                            $closetag = 'N/A';
                        } elseif (preg_match('#<([^>]+)>(.*)</\1>#',$line,$matches)) {
                            $key = $matches[1];
                            $value = $matches[2];
                            if (isset($item[$key])) {
                                if (!empty($file)) fclose($fp);
                                $msg = xarML('Duplicate definition for #(1) key #(2) on line #(3)','item',xarVarPrepForDisplay($key),$count);
                                throw new DuplicateException(null, $msg);
                            }
                            $item[$key] = $value;
                            $closetag = 'N/A';
                        } elseif (preg_match('#<([^/>]+)>(.*)#',$line,$matches)) {
                            // multi-line entries *are* relevant here
                            $key = $matches[1];
                            $value = $matches[2];
                            if (isset($item[$key])) {
                                if (!empty($file)) fclose($fp);
                                $msg = xarML('Duplicate definition for #(1) key #(2)','item',xarVarPrepForDisplay($key));
                                throw new DuplicateException(null, $msg);
                            }
                            $item[$key] = $value;
                            $closetag = $key;
                        } elseif (preg_match("#(.*)</$closetag>#",$line,$matches)) {
                            // multi-line entries *are* relevant here
                            $value = $matches[1];
                            if (!isset($item[$closetag])) {
                                if (!empty($file)) fclose($fp);
                                $msg = xarML('Undefined #(1) key #(2)','item',xarVarPrepForDisplay($closetag));
                                throw new BadParameterException(null, $msg);
                            }
                            $item[$closetag] .= $value;
                            $closetag = 'N/A';
                        } elseif ($closetag != 'N/A') {
                            // multi-line entries *are* relevant here
                            if (!isset($item[$closetag])) {
                                if (!empty($file)) fclose($fp);
                                $msg = xarML('Undefined #(1) key #(2)','item',xarVarPrepForDisplay($closetag));
                                throw new BadParameterException(null, $msg);
                            }
                            $item[$closetag] .= $line;
                        } elseif (preg_match('#</items>#',$line)) {
            skip this for publications */
            if (preg_match('#</items>#', $line)) {
                $what = 'object';
            } elseif (preg_match('#</object>#', $line)) {
                $what = '';
            } else {
            }
        } else {
        }
    }
    if (!empty($file)) {
        fclose($fp);
    }
    return $ptid;
}
コード例 #7
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;
}