Beispiel #1
0
function wurfl_admin_delete()
{
    if (!xarSecurityCheck('ManageWurfl')) {
        return;
    }
    if (!xarVarFetch('name', 'str:1', $name, 'wurfl_wurfl', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('itemid', 'int', $data['itemid'], '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('confirm', 'str:1', $data['confirm'], false, XARVAR_NOT_REQUIRED)) {
        return;
    }
    $data['object'] = DataObjectMaster::getObject(array('name' => $name));
    $data['object']->getItem(array('itemid' => $data['itemid']));
    $data['tplmodule'] = 'wurfl';
    $data['authid'] = xarSecGenAuthKey('wurfl');
    if ($data['confirm']) {
        // Check for a valid confirmation key
        if (!xarSecConfirmAuthKey()) {
            return;
        }
        // Delete the item
        $item = $data['object']->deleteItem();
        // Jump to the next page
        xarController::redirect(xarModURL('wurfl', 'admin', 'view'));
        return true;
    }
    return $data;
}
Beispiel #2
0
function calendar_admin_add_event()
{
    // Security check
    if (!xarSecurityCheck('Admincalendar')) {
        return;
    }
    // Generate a one-time authorisation code for this operation
    $data = xarMod::apiFunc('calendar', 'admin', 'get_calendars');
    $data['authid'] = xarSecGenAuthKey();
    $data['default_cal'] = unserialize(xarModVars::get('calendar', 'default_cal'));
    // Variables from phpIcalendar config.inc.php
    $data['updatebutton'] = xarVarPrepForDisplay(xarML('Create event'));
    //TODO: should I include this stuff? --amoro
    /*    $hooks = xarModCallHooks('module', 'modifyconfig', 'calendar',
            array('module' => 'calendar'));
        if (empty($hooks)) {
            $data['hooks'] = '';
        } elseif (is_array($hooks)) {
            $data['hooks'] = join('', $hooks);
        } else {
            $data['hooks'] = $hooks;
        }
    */
    // Return the template variables defined in this function
    return $data;
}
Beispiel #3
0
function wurfl_admin_modifyconfig()
{
    // 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'], 'general', XARVAR_NOT_REQUIRED)) {
        return;
    }
    $data['module_settings'] = xarMod::apiFunc('base', 'admin', 'getmodulesettings', array('module' => 'wurfl'));
    $data['module_settings']->setFieldList('items_per_page, use_module_alias, module_alias_name, enable_short_urls');
    $data['module_settings']->getItem();
    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':
                    $isvalid = $data['module_settings']->checkInput();
                    if (!$isvalid) {
                        return xarTplModule('wurfl', 'admin', 'modifyconfig', $data);
                    } else {
                        $itemid = $data['module_settings']->updateItem();
                    }
                    break;
                case 'tab2':
                    break;
                case 'tab3':
                    break;
                default:
                    break;
            }
            xarController::redirect(xarModURL('wurfl', 'admin', 'modifyconfig', array('tab' => $data['tab'])));
            // Return
            return true;
            break;
    }
    $data['authid'] = xarSecGenAuthKey();
    return $data;
}
Beispiel #4
0
/**
 * Import an object definition or an object item from XML
 */
function publications_admin_importpubtype($args)
{
    if (!xarSecurityCheck('AdminPublications')) {
        return;
    }
    if (!xarVarFetch('import', 'isset', $import, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('xml', 'isset', $xml, NULL, XARVAR_DONT_SET)) {
        return;
    }
    extract($args);
    $data = array();
    $data['menutitle'] = xarML('Dynamic Data Utilities');
    $data['warning'] = '';
    $data['options'] = array();
    $basedir = 'modules/publications';
    $filetype = 'xml';
    $files = xarModAPIFunc('dynamicdata', 'admin', 'browse', array('basedir' => $basedir, 'filetype' => $filetype));
    if (!isset($files) || count($files) < 1) {
        $files = array();
        $data['warning'] = xarML('There are currently no XML files available for import in "#(1)"', $basedir);
    }
    if (!empty($import) || !empty($xml)) {
        if (!xarSecConfirmAuthKey()) {
            return;
        }
        if (!empty($import)) {
            $found = '';
            foreach ($files as $file) {
                if ($file == $import) {
                    $found = $file;
                    break;
                }
            }
            if (empty($found) || !file_exists($basedir . '/' . $file)) {
                $msg = xarML('File not found');
                throw new BadParameterException(null, $msg);
            }
            $ptid = xarModAPIFunc('publications', 'admin', 'importpubtype', array('file' => $basedir . '/' . $file));
        } else {
            $ptid = xarModAPIFunc('publications', 'admin', 'importpubtype', array('xml' => $xml));
        }
        if (empty($ptid)) {
            return;
        }
        $data['warning'] = xarML('Publication type #(1) was successfully imported', $ptid);
    }
    natsort($files);
    array_unshift($files, '');
    foreach ($files as $file) {
        $data['options'][] = array('id' => $file, 'name' => $file);
    }
    $data['authid'] = xarSecGenAuthKey();
    return $data;
}
Beispiel #5
0
function calendar_admin_view_calendars()
{
    // Security check
    if (!xarSecurityCheck('Admincalendar')) {
        return;
    }
    // Generate a one-time authorisation code for this operation
    $data['authid'] = xarSecGenAuthKey();
    $data['default_cal'] = unserialize(xarModVars::get('calendar', 'default_cal'));
    // Return the template variables defined in this function
    $data['calendars'] = xarMod::apiFunc('calendar', 'user', 'getall');
    return $data;
}
Beispiel #6
0
function calendar_admin_add_calendars()
{
    // Security check
    //    if (!xarSecurityCheck('AddCalendar',0,'Calendar')) return;
    if (!xarVarFetch('calid', 'int:0:', $calid, '0', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('calname', 'str', $calname, '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    $data = xarMod::apiFunc('calendar', 'admin', 'get_calendars');
    // Generate a one-time authorisation code for this operation
    $data['authid'] = xarSecGenAuthKey();
    $data['default_cal'] = unserialize(xarModVars::get('calendar', 'default_cal'));
    $data['addbutton'] = xarVarPrepForDisplay(xarML('Add calendar'));
    $data['message'] = xarVarPrepForDisplay(xarML('Created calendar with name "#(1)", ID #(2)', $calname, $calid));
    $data['calid'] = $calid;
    return $data;
}
Beispiel #7
0
function wurfl_admin_new()
{
    if (!xarSecurityCheck('AddWurfl')) {
        return;
    }
    if (!xarVarFetch('name', 'str', $name, 'wurfl_wurfl', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('confirm', 'bool', $data['confirm'], false, XARVAR_NOT_REQUIRED)) {
        return;
    }
    $data['object'] = DataObjectMaster::getObject(array('name' => $name));
    $data['tplmodule'] = 'wurfl';
    $data['authid'] = xarSecGenAuthKey('wurfl');
    if ($data['confirm']) {
        // we only retrieve 'preview' from the input here - the rest is handled by checkInput()
        if (!xarVarFetch('preview', 'str', $preview, NULL, XARVAR_DONT_SET)) {
            return;
        }
        // Check for a valid confirmation key
        if (!xarSecConfirmAuthKey()) {
            return;
        }
        // Get the data from the form
        $isvalid = $data['object']->checkInput();
        if (!$isvalid) {
            // Bad data: redisplay the form with error messages
            return xarTplModule('wurfl', 'admin', 'new', $data);
        } else {
            // Good data: create the item
            $itemid = $data['object']->createItem();
            // Jump to the next page
            xarController::redirect(xarModURL('wurfl', 'admin', 'view'));
            return true;
        }
    }
    return $data;
}
Beispiel #8
0
function wurfl_admin_modify()
{
    if (!xarSecurityCheck('EditWurfl')) {
        return;
    }
    if (!xarVarFetch('name', 'str', $name, 'wurfl_wurfl', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('itemid', 'int', $data['itemid'], 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('confirm', 'bool', $data['confirm'], false, XARVAR_NOT_REQUIRED)) {
        return;
    }
    $data['object'] = DataObjectMaster::getObject(array('name' => $name));
    $data['object']->getItem(array('itemid' => $data['itemid']));
    $data['tplmodule'] = 'wurfl';
    $data['authid'] = xarSecGenAuthKey('wurfl');
    if ($data['confirm']) {
        // Check for a valid confirmation key
        if (!xarSecConfirmAuthKey()) {
            return;
        }
        // Get the data from the form
        $isvalid = $data['object']->checkInput();
        if (!$isvalid) {
            // Bad data: redisplay the form with error messages
            return xarTplModule('wurfl', 'admin', 'modify', $data);
        } else {
            // Good data: create the item
            $itemid = $data['object']->updateItem(array('itemid' => $data['itemid']));
            // Jump to the next page
            xarController::redirect(xarModURL('wurfl', 'admin', 'view'));
            return true;
        }
    }
    return $data;
}
Beispiel #9
0
/**
 * import pictures into publications
 */
function publications_admin_importpictures()
{
    if (!xarSecurityCheck('AdminPublications')) {
        return;
    }
    // Get parameters
    if (!xarVarFetch('basedir', 'isset', $basedir, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('baseurl', 'isset', $baseurl, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('thumbnail', 'isset', $thumbnail, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('filelist', 'isset', $filelist, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('refresh', 'isset', $refresh, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('ptid', 'isset', $ptid, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('title', 'isset', $title, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('summary', 'isset', $summary, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('content', 'isset', $content, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('usefilemtime', 'isset', $usefilemtime, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('cids', 'isset', $cids, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('test', 'isset', $test, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('import', 'isset', $import, NULL, XARVAR_DONT_SET)) {
        return;
    }
    // Initialise the template variables
    $data = array();
    if (!isset($baseurl)) {
        $data['baseurl'] = sys::code() . 'modules/publications/xarimages/';
    } else {
        $data['baseurl'] = $baseurl;
    }
    if (!isset($basedir)) {
        $data['basedir'] = realpath($data['baseurl']);
    } else {
        $data['basedir'] = realpath($basedir);
    }
    if (!isset($thumbnail)) {
        $data['thumbnail'] = 'tn_';
    } else {
        $data['thumbnail'] = $thumbnail;
    }
    $data['filelist'] = xarModAPIFunc('publications', 'admin', 'browse', array('basedir' => $data['basedir'], 'filetype' => '(gif|jpg|jpeg|png)'));
    // try to match the thumbnails with the pictures
    $data['thumblist'] = array();
    if (!empty($data['thumbnail'])) {
        foreach ($data['filelist'] as $file) {
            // for subdir/myfile.jpg
            $fileparts = pathinfo($file);
            // jpg
            $extension = $fileparts['extension'];
            // subdir
            $dirname = $fileparts['dirname'];
            // myfile
            $basename = $fileparts['basename'];
            $basename = preg_replace("/\\.{$extension}/", '', $basename);
            if (!empty($dirname) && $dirname != '.') {
                $thumb = $dirname . '/' . $data['thumbnail'] . $basename;
            } else {
                $thumb = $data['thumbnail'] . $basename;
            }
            // subdir/tn_file.jpg
            if (in_array($thumb . '.' . $extension, $data['filelist'])) {
                $data['thumblist'][$file] = $thumb . '.' . $extension;
                // subdir/tn_file_jpg.jpg
            } elseif (in_array($thumb . '_' . $extension . '.' . $extension, $data['filelist'])) {
                $data['thumblist'][$file] = $thumb . '_' . $extension . '.' . $extension;
                // subdir/tn_file.jpg.jpg
            } elseif (in_array($thumb . '.' . $extension . '.' . $extension, $data['filelist'])) {
                $data['thumblist'][$file] = $thumb . '.' . $extension . '.' . $extension;
            }
        }
        if (count($data['thumblist']) > 0) {
            $deletelist = array_values($data['thumblist']);
            $data['filelist'] = array_diff($data['filelist'], $deletelist);
        }
    }
    if (isset($refresh) || isset($test) || isset($import)) {
        // Confirm authorisation code
        if (!xarSecConfirmAuthKey()) {
            return;
        }
    }
    $data['authid'] = xarSecGenAuthKey();
    // Get current publication types
    $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
    // Set default pubtype to Pictures (if it exists)
    if (!isset($ptid) && isset($pubtypes[5])) {
        $ptid = 5;
        $title = 'title';
        $summary = 'summary';
        $content = 'body';
    }
    $data['pubtypes'] = $pubtypes;
    $data['fields'] = array();
    $data['cats'] = array();
    if (!empty($ptid)) {
        $data['ptid'] = $ptid;
        $pubfields = xarModAPIFunc('publications', 'user', 'getpubfields');
        $pubfieldtypes = xarModAPIFunc('publications', 'user', 'getpubfieldtypes');
        $pubfieldformats = xarModAPIFunc('publications', 'user', 'getpubfieldformats');
        foreach ($pubfields as $field => $dummy) {
            if (($pubfieldtypes[$field] == 'text' || $pubfieldtypes[$field] == 'string') && !empty($pubtypes[$ptid]['config'][$field]['label']) && $pubtypes[$ptid]['config'][$field]['format'] != 'fileupload') {
                $data['fields'][$field] = $pubtypes[$ptid]['config'][$field]['label'] . ' [' . $pubfieldformats[$pubtypes[$ptid]['config'][$field]['format']] . ']';
            }
        }
        $catlist = array();
        $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $ptid));
        foreach ($rootcats as $catid) {
            $catlist[$catid['category_id']] = 1;
        }
        $seencid = array();
        if (isset($cids) && is_array($cids)) {
            foreach ($cids as $catid) {
                if (!empty($catid)) {
                    $seencid[$catid] = 1;
                }
            }
        }
        $cids = array_keys($seencid);
        foreach (array_keys($catlist) as $catid) {
            $data['cats'][] = xarModAPIFunc('categories', 'visual', 'makeselect', array('cid' => $catid, 'return_itself' => true, 'select_itself' => true, 'values' => &$seencid, 'multiple' => 1));
        }
    }
    $data['selected'] = array();
    if (!isset($refresh) && isset($filelist) && is_array($filelist) && count($filelist) > 0) {
        foreach ($filelist as $file) {
            if (!empty($file) && in_array($file, $data['filelist'])) {
                $data['selected'][$file] = 1;
            }
        }
    }
    if (isset($title) && isset($data['fields'][$title])) {
        $data['title'] = $title;
    }
    if (isset($summary) && isset($data['fields'][$summary])) {
        $data['summary'] = $summary;
    }
    if (isset($content) && isset($data['fields'][$content])) {
        $data['content'] = $content;
    }
    if (empty($usefilemtime)) {
        $data['usefilemtime'] = 0;
    } else {
        $data['usefilemtime'] = 1;
    }
    if (isset($data['ptid']) && isset($data['content']) && count($data['selected']) > 0 && (isset($test) || isset($import))) {
        // TODO: allow changing the order of import + editing the titles etc. before creating the publications
        $data['logfile'] = '';
        foreach (array_keys($data['selected']) as $file) {
            $curfile = realpath($basedir . '/' . $file);
            if (!file_exists($curfile) || !is_file($curfile)) {
                continue;
            }
            $filename = $file;
            if (empty($baseurl)) {
                $imageurl = $file;
            } elseif (substr($baseurl, -1) == '/') {
                $imageurl = $baseurl . $file;
            } else {
                $imageurl = $baseurl . '/' . $file;
            }
            if (!empty($data['thumblist'][$file])) {
                if (empty($baseurl)) {
                    $thumburl = $data['thumblist'][$file];
                } elseif (substr($baseurl, -1) == '/') {
                    $thumburl = $baseurl . $data['thumblist'][$file];
                } else {
                    $thumburl = $baseurl . '/' . $data['thumblist'][$file];
                }
            } else {
                $thumburl = '';
            }
            $article = array('title' => ' ', 'summary' => '', 'body' => '', 'notes' => '', 'pubdate' => empty($usefilemtime) ? time() : filemtime($curfile), 'state' => 2, 'ptid' => $data['ptid'], 'cids' => $cids, 'pubtype_id' => $data['ptid'], 'owner' => xarUserGetVar('id'), 'id' => 0);
            if (!empty($data['title']) && !empty($filename)) {
                $article[$data['title']] = $filename;
            }
            if (!empty($data['summary']) && !empty($thumburl)) {
                $article[$data['summary']] = $thumburl;
            }
            if (!empty($data['content']) && !empty($imageurl)) {
                $article[$data['content']] = $imageurl;
            }
            if (isset($test)) {
                // preview the first file as a test
                $data['preview'] = xarModFunc('publications', 'user', 'display', array('article' => $article, 'preview' => true));
                break;
            } else {
                $id = xarModAPIFunc('publications', 'admin', 'create', $article);
                if (empty($id)) {
                    return;
                    // throw back
                } else {
                    $data['logfile'] .= xarML('File #(1) was imported as #(2) #(3)', $curfile, $pubtypes[$data['ptid']]['description'], $id);
                    $data['logfile'] .= '<br />';
                }
            }
        }
    }
    // Return the template variables defined in this function
    return $data;
}
Beispiel #10
0
/**
 * manage publication types (all-in-one function for now)
 */
function publications_admin_importpages()
{
    if (!xarSecurityCheck('AdminPublications')) {
        return;
    }
    // Get parameters
    if (!xarVarFetch('basedir', 'isset', $basedir, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('filelist', 'isset', $filelist, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('refresh', 'isset', $refresh, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('ptid', 'isset', $ptid, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('content', 'isset', $content, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('title', 'isset', $title, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('cids', 'isset', $cids, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('filterhead', 'isset', $filterhead, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('filtertail', 'isset', $filtertail, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('findtitle', 'isset', $findtitle, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('numrules', 'isset', $numrules, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('search', 'isset', $search, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('replace', 'isset', $replace, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('test', 'isset', $test, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('import', 'isset', $import, NULL, XARVAR_DONT_SET)) {
        return;
    }
    // Initialise the template variables
    $data = array();
    if (empty($basedir)) {
        $data['basedir'] = realpath(sys::code() . 'modules/publications');
    } else {
        $data['basedir'] = realpath($basedir);
    }
    $data['filelist'] = xarModAPIFunc('publications', 'admin', 'browse', array('basedir' => $data['basedir'], 'filetype' => 'html?'));
    if (isset($refresh) || isset($test) || isset($import)) {
        // Confirm authorisation code
        if (!xarSecConfirmAuthKey()) {
            return;
        }
    }
    $data['authid'] = xarSecGenAuthKey();
    // Get current publication types
    $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
    $data['pubtypes'] = $pubtypes;
    $data['fields'] = array();
    $data['cats'] = array();
    if (!empty($ptid)) {
        $data['ptid'] = $ptid;
        $pubfields = xarModAPIFunc('publications', 'user', 'getpubfields');
        $pubfieldtypes = xarModAPIFunc('publications', 'user', 'getpubfieldtypes');
        $pubfieldformats = xarModAPIFunc('publications', 'user', 'getpubfieldformats');
        foreach ($pubfields as $field => $dummy) {
            if (($pubfieldtypes[$field] == 'text' || $pubfieldtypes[$field] == 'string') && !empty($pubtypes[$ptid]['config'][$field]['label']) && $pubtypes[$ptid]['config'][$field]['format'] != 'fileupload') {
                $data['fields'][$field] = $pubtypes[$ptid]['config'][$field]['label'] . ' [' . $pubfieldformats[$pubtypes[$ptid]['config'][$field]['format']] . ']';
            }
        }
        $catlist = array();
        $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $ptid));
        foreach ($rootcats as $catid) {
            $catlist[$catid['category_id']] = 1;
        }
        $seencid = array();
        if (isset($cids) && is_array($cids)) {
            foreach ($cids as $catid) {
                if (!empty($catid)) {
                    $seencid[$catid] = 1;
                }
            }
        }
        $cids = array_keys($seencid);
        foreach (array_keys($catlist) as $catid) {
            $data['cats'][] = xarModAPIFunc('categories', 'visual', 'makeselect', array('cid' => $catid, 'return_itself' => true, 'select_itself' => true, 'values' => &$seencid, 'multiple' => 1));
        }
    }
    $data['selected'] = array();
    if (!isset($refresh) && isset($filelist) && is_array($filelist) && count($filelist) > 0) {
        foreach ($filelist as $file) {
            if (!empty($file) && in_array($file, $data['filelist'])) {
                $data['selected'][$file] = 1;
            }
        }
    }
    if (isset($title) && isset($data['fields'][$title])) {
        $data['title'] = $title;
    }
    if (isset($content) && isset($data['fields'][$content])) {
        $data['content'] = $content;
    }
    if (!isset($filterhead)) {
        $data['filterhead'] = '#^.*<body[^>]*>#is';
    } else {
        $data['filterhead'] = $filterhead;
    }
    if (!isset($filtertail)) {
        $data['filtertail'] = '#</body.*$#is';
    } else {
        $data['filtertail'] = $filtertail;
    }
    if (!isset($findtitle)) {
        $data['findtitle'] = '#<title>(.*?)</title>#is';
    } else {
        $data['findtitle'] = $findtitle;
    }
    if (!isset($numrules)) {
        $numrules = 3;
    }
    $data['search'] = array();
    $data['replace'] = array();
    for ($i = 0; $i < $numrules; $i++) {
        if (isset($search[$i])) {
            $data['search'][$i] = $search[$i];
            if (isset($replace[$i])) {
                $data['replace'][$i] = $replace[$i];
            } else {
                $data['replace'][$i] = '';
            }
        } else {
            $data['search'][$i] = '';
            $data['replace'][$i] = '';
        }
    }
    if (isset($data['ptid']) && isset($data['content']) && count($data['selected']) > 0 && (isset($test) || isset($import))) {
        $mysearch = array();
        $myreplace = array();
        for ($i = 0; $i < $numrules; $i++) {
            if (!empty($data['search'][$i])) {
                $mysearch[] = $data['search'][$i];
                if (!empty($data['replace'][$i])) {
                    $myreplace[] = $data['replace'][$i];
                } else {
                    $myreplace[] = '';
                }
            }
        }
        $data['logfile'] = '';
        foreach (array_keys($data['selected']) as $file) {
            $curfile = realpath($basedir . '/' . $file);
            if (!file_exists($curfile) || !is_file($curfile)) {
                continue;
            }
            $page = @join('', file($curfile));
            if (!empty($data['findtitle']) && preg_match($data['findtitle'], $page, $matches)) {
                $title = $matches[1];
            } else {
                $title = '';
            }
            if (!empty($data['filterhead'])) {
                $page = preg_replace($filterhead, '', $page);
            }
            if (!empty($data['filtertail'])) {
                $page = preg_replace($filtertail, '', $page);
            }
            if (count($mysearch) > 0) {
                $page = preg_replace($mysearch, $myreplace, $page);
            }
            $article = array('title' => ' ', 'summary' => '', 'body' => '', 'notes' => '', 'pubdate' => filemtime($curfile), 'state' => 2, 'ptid' => $data['ptid'], 'cids' => $cids, 'pubtype_id' => $data['ptid'], 'owner' => xarUserGetVar('id'), 'id' => 0);
            if (!empty($data['title']) && !empty($title)) {
                $article[$data['title']] = $title;
            }
            $article[$data['content']] = $page;
            if (isset($test)) {
                // preview the first file as a test
                $data['preview'] = xarModFunc('publications', 'user', 'display', array('article' => $article, 'preview' => true));
                break;
            } else {
                $id = xarModAPIFunc('publications', 'admin', 'create', $article);
                if (empty($id)) {
                    return;
                    // throw back
                } else {
                    $data['logfile'] .= xarML('File #(1) was imported as #(2) #(3)', $curfile, $pubtypes[$data['ptid']]['description'], $id);
                    $data['logfile'] .= '<br />';
                }
            }
        }
    }
    $data['filterhead'] = xarVarPrepForDisplay($data['filterhead']);
    $data['filtertail'] = xarVarPrepForDisplay($data['filtertail']);
    $data['findtitle'] = xarVarPrepForDisplay($data['findtitle']);
    for ($i = 0; $i < $numrules; $i++) {
        if (!empty($data['search'][$i])) {
            $data['search'][$i] = xarVarPrepForDisplay($data['search'][$i]);
        }
        if (!empty($data['replace'][$i])) {
            $data['replace'][$i] = xarVarPrepForDisplay($data['replace'][$i]);
        }
    }
    // Return the template variables defined in this function
    return $data;
}
Beispiel #11
0
/**
 * Publications Module
 *
 * @package modules
 * @subpackage publications module
 * @category Third Party Xaraya Module
 * @version 2.0.0
 * @copyright (C) 2011 Netspan AG
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @author Marc Lutolf <*****@*****.**>
 */
function publications_admin_delete_pubtype()
{
    if (!xarSecurityCheck('AdminPublications')) {
        return;
    }
    if (!xarVarFetch('confirmed', 'int', $confirmed, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('itemid', 'str', $itemid, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('idlist', 'str', $idlist, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('returnurl', 'str', $returnurl, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!empty($itemid)) {
        $idlist = $itemid;
    }
    $ids = explode(',', trim($idlist, ','));
    if (empty($idlist)) {
        if (isset($returnurl)) {
            xarController::redirect($returnurl);
        } else {
            xarController::redirect(xarModURL('publications', 'admin', 'view'));
        }
    }
    $data['message'] = '';
    $data['itemid'] = $itemid;
    /*------------- Ask for Confirmation.  If yes, action ----------------------------*/
    sys::import('modules.dynamicdata.class.objects.master');
    $pubtype = DataObjectMaster::getObject(array('name' => 'publications_types'));
    if (!isset($confirmed)) {
        $data['idlist'] = $idlist;
        if (count($ids) > 1) {
            $data['title'] = xarML("Delete Publication Types");
        } else {
            $data['title'] = xarML("Delete Publication Type");
        }
        $data['authid'] = xarSecGenAuthKey();
        $items = array();
        foreach ($ids as $i) {
            $pubtype->getItem(array('itemid' => $i));
            $item = $pubtype->getFieldValues();
            $items[] = $item;
        }
        $data['items'] = $items;
        $data['yes_action'] = xarModURL('publications', 'admin', 'delete_pubtype', array('idlist' => $idlist));
        return xarTplModule('publications', 'admin', 'delete_pubtype', $data);
    } else {
        if (!xarSecConfirmAuthKey()) {
            return;
        }
        foreach ($ids as $id) {
            $itemid = $pubtype->deleteItem(array('itemid' => $id));
            $data['message'] = "Publication Type deleted [ID {$id}]";
        }
        if (isset($returnurl)) {
            xarController::redirect($returnurl);
        } else {
            xarController::redirect(xarModURL('publications', 'admin', 'view_pubtypes', $data));
        }
        return true;
    }
    return true;
}
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;
}
Beispiel #13
0
/**
 * delete calendar from database
 */
function calendar_admin_delete_calendar()
{
    // Get parameters
    if (!xarVarFetch('calid', 'id', $calid)) {
        return;
    }
    if (!xarVarFetch('confirm', 'checkbox', $confirm, false, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Get calendar information
    $calendar = xarMod::apiFunc('calendar', 'user', 'get', array('calid' => $calid));
    if (!isset($calendar) || $calendar == false) {
        $msg = xarML('Unable to find #(1) item #(2)', 'Calendar', xarVarPrepForDisplay($calid));
        throw new Exception($msg);
    }
    // Security check
    $input = array();
    $input['calendar'] = $calendar;
    $input['mask'] = 'DeleteCalendars';
    /* TODO: security
        if (!xarMod::apiFunc('calendar','user','checksecurity',$input)) {
            $msg = xarML('You have no permission to delete item #(1)',
                         xarVarPrepForDisplay($calid));
            throw new Exception($msg);
        }
    */
    // Check for confirmation
    if (!$confirm) {
        $data = array();
        // Specify for which item you want confirmation
        $data['calid'] = $calid;
        // Use articles user GUI function (not API) for preview
        if (!xarMod::load('calendar', 'user')) {
            return;
        }
        $data['preview'] = xarMod::guiFunc('calendar', 'user', 'display', array('calid' => $calid));
        // Add some other data you'll want to display in the template
        $data['confirmtext'] = xarML('Confirm deleting this calendar');
        $data['confirmlabel'] = xarML('Confirm');
        // Generate a one-time authorisation code for this operation
        $data['authid'] = xarSecGenAuthKey();
        // Return the template variables defined in this function
        return $data;
    }
    // Confirmation present
    if (!xarSecConfirmAuthKey()) {
        return;
    }
    // Pass to API
    if (!xarMod::apiFunc('calendar', 'admin', 'delete_calendar', array('calid' => $calid))) {
        return;
    }
    // Success
    xarSession::setVar('statusmsg', xarML('Calendar Deleted'));
    // Return to the original admin view
    $lastview = xarSession::getVar('Calendar.LastView');
    if (isset($lastview)) {
        $lastviewarray = unserialize($lastview);
        if (!empty($lastviewarray['ptid']) && $lastviewarray['ptid'] == $ptid) {
            extract($lastviewarray);
            xarController::redirect(xarModURL('calendar', 'admin', 'view_calendars'));
            return true;
        }
    }
    xarController::redirect(xarModURL('calendar', 'admin', 'view_calendars'));
    return true;
}
Beispiel #14
0
/**
 * Publications Module
 *
 * @package modules
 * @subpackage publications module
 * @category Third Party Xaraya Module
 * @version 2.0.0
 * @copyright (C) 2011 Netspan AG
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @author Marc Lutolf <*****@*****.**>
 */
function publications_admin_clone()
{
    if (!xarSecurityCheck('ManagePublications')) {
        return;
    }
    if (!xarVarFetch('name', 'isset', $objectname, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('ptid', 'isset', $ptid, NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('itemid', 'isset', $data['itemid'], NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('confirm', 'int', $confirm, 0, XARVAR_DONT_SET)) {
        return;
    }
    if (empty($data['itemid'])) {
        return xarResponse::NotFound();
    }
    // If a pubtype ID was passed, get the name of the pub object
    if (isset($ptid)) {
        $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types'));
        $pubtypeobject->getItem(array('itemid' => $ptid));
        $objectname = $pubtypeobject->properties['name']->value;
    }
    if (empty($objectname)) {
        return xarResponse::NotFound();
    }
    sys::import('modules.dynamicdata.class.objects.master');
    $data['object'] = DataObjectMaster::getObject(array('name' => $objectname));
    if (empty($data['object'])) {
        return xarResponse::NotFound();
    }
    // Security
    if (!$data['object']->checkAccess('update')) {
        return xarResponse::Forbidden(xarML('Clone #(1) is forbidden', $object->label));
    }
    $data['object']->getItem(array('itemid' => $data['itemid']));
    $data['authid'] = xarSecGenAuthKey();
    $data['name'] = $data['object']->properties['name']->value;
    $data['label'] = $data['object']->label;
    xarTplSetPageTitle(xarML('Clone Publication #(1) in #(2)', $data['itemid'], $data['label']));
    if ($confirm) {
        if (!xarSecConfirmAuthKey()) {
            return;
        }
        // Get the name for the clone
        if (!xarVarFetch('newname', 'str', $newname, "", XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (empty($newname)) {
            $newname = $data['name'] . "_copy";
        }
        if ($newname == $data['name']) {
            $newname = $data['name'] . "_copy";
        }
        $newname = strtolower(str_ireplace(" ", "_", $newname));
        // Create the clone
        $data['object']->properties['name']->setValue($newname);
        $data['object']->properties['id']->setValue(0);
        $cloneid = $data['object']->createItem(array('itemid' => 0));
        // Create the clone's translations
        if (!xarVarFetch('clone_translations', 'int', $clone_translations, 0, XARVAR_NOT_REQUIRED)) {
            return;
        }
        if ($clone_translations) {
            // Get the info on all the objects to be cloned
            sys::import('xaraya.structures.query');
            $tables = xarDB::getTables();
            $q = new Query();
            $q->addtable($tables['publications'], 'p');
            $q->addtable($tables['publications_types'], 'pt');
            $q->join('p.pubtype_id', 'pt.id');
            $q->eq('parent_id', $data['itemid']);
            $q->addfield('p.id AS id');
            $q->addfield('pt.name AS name');
            $q->run();
            // Clone each one
            foreach ($q->output() as $item) {
                $object = DataObjectMaster::getObject(array('name' => $item['name']));
                $object->getItem(array('itemid' => $item['id']));
                $object->properties['parent']->value = $cloneid;
                $object->properties['id']->value = 0;
                $object->createItem(array('itemid' => 0));
            }
        }
        // Redirect if we came from somewhere else
        $current_listview = xarSession::getVar('publications_current_listview');
        if (!empty($return_url)) {
            xarController::redirect($return_url);
        } elseif (!empty($current_listview)) {
            xarController::redirect($current_listview);
        } else {
            xarController::redirect(xarModURL('publications', 'user', 'view'));
        }
        return true;
    }
    return $data;
}
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;
}