Esempio n. 1
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;
}
Esempio n. 2
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_adminapi_delete($args)
{
    // Get arguments from argument array
    extract($args);
    // Argument check
    if (!isset($itemid)) {
        $msg = xarML('Invalid #(1) for #(2) function #(3)() in module #(4)', 'publication ID', 'admin', 'delete', 'Publications');
        throw new BadParameterException(null, $msg);
    }
    $ids = !is_array($itemid) ? explode(',', $itemid) : $itemid;
    if (!isset($deletetype)) {
        $deletetype = 0;
    }
    sys::import('xaraya.structures.query');
    $table = xarDB::getTables();
    switch ($deletetype) {
        case 0:
        default:
            $q = new Query('UPDATE', $table['publications']);
            $q->addfield('state', 0);
            break;
        case 10:
            $q = new Query('DELETE', $table['publications']);
            break;
    }
    $q->in('id', $ids);
    if (!$q->run()) {
        return false;
    }
    return true;
}
Esempio n. 3
0
 /**
  * Modify Function to the Blocks Admin
  * @author Jason Judge
  * @param $blockinfo array containing title,content
  */
 public function modify(array $data = array())
 {
     $data = $this->getContent();
     // Get a list of all pages for the drop-downs.
     // Get the tree of all pages, without the DD for speed.
     $data['all_pages'] = xarMod::apiFunc('publications', 'user', 'getpagestree', array('dd_flag' => false, 'key' => 'pid'));
     // Implode the names for each page into a path for display.
     // TODO: move this into getpagestree
     foreach ($data['all_pages']['pages'] as $key => $page) {
         $data['all_pages']['pages'][$key]['slash_separated'] = '/' . implode('/', $page['namepath']);
     }
     // Get the descriptions together for the current root ids.
     // TODO: we could prune the 'add root page' list so it only includes
     // the pages which are not yet under one of the selected root pages.
     // That would just be an extra little usability touch.
     $data['root_ids'] = array_flip($data['root_ids']);
     foreach ($data['root_ids'] as $key => $value) {
         if (isset($data['all_pages']['pages'][$key])) {
             $data['root_ids'][$key] = $data['all_pages']['pages'][$key]['slash_separated'];
         } else {
             $data['root_ids'][$key] = xarML('Unknown');
         }
     }
     $data['prune_ids'] = array_flip($data['prune_ids']);
     foreach ($data['prune_ids'] as $key => $value) {
         if (isset($data['all_pages']['pages'][$key])) {
             $data['prune_ids'][$key] = $data['all_pages']['pages'][$key]['slash_separated'];
         } else {
             $data['prune_ids'][$key] = xarML('Unknown');
         }
     }
     //            $vars['bid'] = $blockinfo['bid'];
     return $data;
 }
Esempio n. 4
0
/**
 * view statistics
 */
function publications_admin_stats($args = array())
{
    if (!xarSecurityCheck('AdminPublications')) {
        return;
    }
    if (!xarVarFetch('group', 'isset', $group, array(), XARVAR_NOT_REQUIRED)) {
        return;
    }
    extract($args);
    if (!empty($group)) {
        $newgroup = array();
        foreach ($group as $field) {
            if (empty($field)) {
                continue;
            }
            $newgroup[] = $field;
        }
        $group = $newgroup;
    }
    if (empty($group)) {
        $group = array('pubtype_id', 'state', 'owner');
    }
    $data = array();
    $data['group'] = $group;
    $data['stats'] = xarModAPIFunc('publications', 'admin', 'getstats', array('group' => $group));
    $data['pubtypes'] = xarModAPIFunc('publications', 'user', 'get_pubtypes');
    $data['statelist'] = xarModAPIFunc('publications', 'user', 'getstates');
    $data['fields'] = array('pubtype_id' => xarML('Publication Type'), 'state' => xarML('Status'), 'owner' => xarML('Author'), 'pubdate_year' => xarML('Publication Year'), 'pubdate_month' => xarML('Publication Month'), 'pubdate_day' => xarML('Publication Day'), 'locale' => xarML('Language'));
    return $data;
}
Esempio n. 5
0
/**
 * utility function to pass individual item links to a caller
 *
 * @param $args['itemids'] array of item ids to get
 * @return array Array containing the itemlink(s) for the item(s).
 */
function publications_userapi_getitemlinks($args)
{
    $itemlinks = array();
    sys::import('xaraya.structures.query');
    $xartable = xarDB::getTables();
    $q = new Query('SELECT', $xartable['publications']);
    $q->addfield('id');
    $q->addfield('title');
    $q->addfield('description');
    $q->addfield('pubtype_id');
    $q->in('state', array(3, 4));
    if (!empty($args['itemids'])) {
        $itemids = explode(',', $args['itemids']);
        $q->in('id', $itemids);
    }
    $q->addorder('title');
    $q->run();
    $result = $q->output();
    if (empty($result)) {
        return $itemlinks;
    }
    foreach ($result as $item) {
        if (empty($item['title'])) {
            $item['title'] = xarML('Display Publication');
        }
        $itemlinks[$item['id']] = array('url' => xarModURL('publications', 'user', 'display', array('id' => $item['id'])), 'title' => $item['title'], 'label' => $item['description']);
    }
    return $itemlinks;
}
Esempio n. 6
0
/**
 *  Modify a customer
 */
function shop_admin_modifycustomer()
{
    if (!xarVarFetch('itemid', 'id', $data['itemid'], NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('confirm', 'bool', $data['confirm'], false, XARVAR_NOT_REQUIRED)) {
        return;
    }
    $objectname = 'shop_customers';
    $data['objectname'] = $objectname;
    // Check if we still have no id of the item to modify.
    if (empty($data['itemid'])) {
        $msg = xarML('Invalid #(1) for #(2) function #(3)() in module #(4)', 'item id', 'admin', 'modify', 'shop');
        throw new Exception($msg);
    }
    if (!xarSecurityCheck('AdminShop', 1, 'Item', $data['itemid'])) {
        return;
    }
    sys::import('modules.dynamicdata.class.objects.master');
    $object = DataObjectMaster::getObject(array('name' => $objectname));
    $data['object'] = $object;
    $data['label'] = $object->label;
    $object->getItem(array('itemid' => $data['itemid']));
    $values = $object->getFieldValues();
    foreach ($values as $name => $value) {
        $data[$name] = xarVarPrepForDisplay($value);
    }
    $rolesobject = DataObjectMaster::getObject(array('name' => 'roles_users'));
    $rolesobject->getItem(array('itemid' => $data['itemid']));
    if ($data['confirm']) {
        // Check for a valid confirmation key
        if (!xarSecConfirmAuthKey()) {
            return xarTplModule('privileges', 'user', 'errors', array('layout' => 'bad_author'));
        }
        // Get the data from the form
        $isvalid = $object->checkInput();
        if (!$isvalid) {
            // Bad data: redisplay the form with the data we picked up and with error messages
            return xarTplModule('shop', 'admin', 'modifycustomer', $data);
        } elseif (isset($data['preview'])) {
            // Show a preview, same thing as the above essentially
            return xarTplModule('shop', 'admin', 'modifycustomer', $data);
        } else {
            $first_name = $object->properties['first_name']->getValue();
            $last_name = $object->properties['last_name']->getValue();
            $rolesobject->properties['name']->setValue($first_name . ' ' . $last_name);
            $rolesobject->updateItem();
            $object->updateItem();
            // Jump to the next page
            xarResponse::redirect(xarModURL('shop', 'admin', 'modifycustomer', array('itemid' => $data['itemid'])));
            return $data;
        }
    } else {
        // Get that specific item of the object
        $object->getItem(array('itemid' => $data['itemid']));
    }
    // Return the template variables defined in this function
    return $data;
}
Esempio n. 7
0
/**
 * @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;
}
Esempio n. 8
0
/**
 * Create a new publication type
 *
 * @param $args['name'] name of the publication type
 * @param $args['descr'] description of the publication type
 * @param $args['config'] configuration of the publication type
 * @return int publication type ID on success, false on failure
 */
function publications_adminapi_createpubtype($args)
{
    // Get arguments from argument array
    extract($args);
    // Argument check - make sure that all required arguments are present
    // and in the right format, if not then set an appropriate error
    // message and return
    // Note : since we have several arguments we want to check here, we'll
    // report all those that are invalid at the same time...
    $invalid = array();
    if (!isset($name) || !is_string($name) || empty($name)) {
        $invalid[] = 'name';
    }
    if (!isset($config) || !is_array($config) || count($config) == 0) {
        $invalid[] = 'configuration';
    }
    if (count($invalid) > 0) {
        $msg = xarML('Invalid #(1) for #(2) function #(3)() in module #(4)', join(', ', $invalid), 'admin', 'createpubtype', 'Publications');
        throw new BadParameterException(null, $msg);
    }
    if (empty($descr)) {
        $descr = $name;
    }
    // Publication type names *must* be lower-case for now
    $name = strtolower($name);
    // Security check - we require ADMIN rights here
    if (!xarSecurityCheck('AdminPublications')) {
        return;
    }
    if (!xarModAPILoad('publications', 'user')) {
        return;
    }
    // Make sure we have all the configuration fields we need
    $pubfields = xarModAPIFunc('publications', 'user', 'getpubfields');
    foreach ($pubfields as $field => $value) {
        if (!isset($config[$field])) {
            $config[$field] = '';
        }
    }
    // Get database setup
    $dbconn = xarDB::getConn();
    $xartable = xarDB::getTables();
    $pubtypestable = $xartable['publication_types'];
    // Get next ID in table
    $nextId = $dbconn->GenId($pubtypestable);
    // Insert the publication type
    $query = "INSERT INTO {$pubtypestable} (pubtype_id, pubtypename,\n            pubtypedescr, pubtypeconfig)\n            VALUES (?,?,?,?)";
    $bindvars = array($nextId, $name, $descr, serialize($config));
    $result =& $dbconn->Execute($query, $bindvars);
    if (!$result) {
        return;
    }
    // Get ptid to return
    $ptid = $dbconn->PO_Insert_ID($pubtypestable, 'pubtype_id');
    // Don't call creation hooks here...
    //xarModCallHooks('item', 'create', $ptid, 'ptid');
    return $ptid;
}
Esempio n. 9
0
 function modify()
 {
     $data = $this->getContent();
     $data['fields'] = array('id', 'name');
     if (!is_array($data['pubstate'])) {
         $statearray = array($data['pubstate']);
     } else {
         $statearray = $data['pubstate'];
     }
     if (!empty($data['catfilter'])) {
         $cidsarray = array($data['catfilter']);
     } else {
         $cidsarray = array();
     }
     // Create array based on modifications
     $article_args = array();
     // Only include pubtype if a specific pubtype is selected
     if (!empty($data['pubtype_id'])) {
         $article_args['ptid'] = $data['pubtype_id'];
     }
     // If itemlimit is set to 0, then don't pass to getall
     if ($data['itemlimit'] != 0) {
         $article_args['numitems'] = $data['itemlimit'];
     }
     // Add the rest of the arguments
     $article_args['cids'] = $cidsarray;
     $article_args['enddate'] = time();
     $article_args['state'] = $statearray;
     $article_args['fields'] = $data['fields'];
     $article_args['sort'] = $data['toptype'];
     $data['filtereditems'] = xarModAPIFunc('publications', 'user', 'getall', $article_args);
     // Check for exceptions
     //    if (!isset($vars['filtereditems']) && xarCurrentErrorType() != XAR_NO_EXCEPTION)
     //        return; // throw back
     // Try to keep the additional headlines select list width less than 50 characters
     for ($idx = 0; $idx < count($data['filtereditems']); $idx++) {
         if (strlen($data['filtereditems'][$idx]['title']) > 50) {
             $data['filtereditems'][$idx]['title'] = substr($data['filtereditems'][$idx]['title'], 0, 47) . '...';
         }
     }
     $data['pubtypes'] = xarModAPIFunc('publications', 'user', 'get_pubtypes');
     $data['categorylist'] = xarModAPIFunc('categories', 'user', 'getcat');
     $data['stateoptions'] = array(array('id' => '', 'name' => xarML('All Published')), array('id' => '3', 'name' => xarML('Frontpage')), array('id' => '2', 'name' => xarML('Approved')));
     $data['sortoptions'] = array(array('id' => 'author', 'name' => xarML('Author')), array('id' => 'date', 'name' => xarML('Date')), array('id' => 'hits', 'name' => xarML('Hit Count')), array('id' => 'rating', 'name' => xarML('Rating')), array('id' => 'title', 'name' => xarML('Title')));
     //Put together the additional featured publications list
     for ($idx = 0; $idx < count($data['filtereditems']); ++$idx) {
         $data['filtereditems'][$idx]['selected'] = '';
         for ($mx = 0; $mx < count($data['moreitems']); ++$mx) {
             if ($data['moreitems'][$mx] == $data['filtereditems'][$idx]['id']) {
                 $data['filtereditems'][$idx]['selected'] = 'selected';
             }
         }
     }
     $data['morepublications'] = $data['filtereditems'];
     return $data;
 }
Esempio n. 10
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;
}
Esempio n. 11
0
/**
* get array of field formats for publication types
* @TODO : move this to some common place in Xaraya (base module ?)
* + replace with dynamic_propertytypes table
*
* + extend with other pre-defined formats
* @return array('static'  => xarML('Static Text'),
                'textbox' => xarML('Text Box'),
                ...);
*/
function publications_userapi_getpubfieldformats($args)
{
    $fieldlist = array('static' => xarML('Static Text'), 'textbox' => xarML('Text Box'), 'textarea' => xarML('Small Text Area'), 'textarea_medium' => xarML('Medium Text Area'), 'textarea_large' => xarML('Large Text Area'), 'dropdown' => xarML('Dropdown List'), 'textupload' => xarML('Text Upload'), 'fileupload' => xarML('File Upload'), 'url' => xarML('URL'), 'urltitle' => xarML('URL + Title'), 'image' => xarML('Image'), 'imagelist' => xarML('Image List'), 'calendar' => xarML('Calendar'), 'webpage' => xarML('HTML Page'), 'username' => xarML('Username'), 'userlist' => xarML('User List'), 'state' => xarML('Status'), 'locale' => xarML('Language List'));
    // Add  'text' dd properites that are dependent on module availability
    $extrafields = array();
    if (xarModIsAvailable('tinymce')) {
        $extrafields = array('tinymce' => xarML('TinyMCE GUI'));
        $fieldlist = array_merge($fieldlist, $extrafields);
    }
    return $fieldlist;
}
Esempio n. 12
0
function calendar_adminapi_hookcreate($data)
{
    if (!isset($data['extrainfo']) || !is_array($data['extrainfo'])) {
        $data['extrainfo'] = array();
    }
    // When called via hooks, modname will be empty, but we get it from the
    // extrainfo or the current module
    if (empty($data['module'])) {
        if (!empty($data['extrainfo']['module'])) {
            $data['module'] = $data['extrainfo']['module'];
        } else {
            $data['module'] = xarMod::getName();
        }
    }
    $data['module_id'] = xarMod::getID($data['module']);
    if (empty($data['module_id'])) {
        throw new IDNotFoundException("module id for " . $data['modname']);
    }
    if (!isset($data['itemtype']) || !is_numeric($data['itemtype'])) {
        if (isset($data['extrainfo']['itemtype']) && is_numeric($data['extrainfo']['itemtype'])) {
            $data['itemtype'] = $data['extrainfo']['itemtype'];
        } else {
            $data['itemtype'] = 0;
        }
    }
    if (!isset($data['itemid']) || !is_numeric($data['itemid'])) {
        if (isset($data['extrainfo']['item_id']) && is_numeric($data['extrainfo']['item_id'])) {
            $data['itemid'] = $data['extrainfo']['item_id'];
        } else {
            $data['itemid'] = 0;
        }
    }
    $data['extrainfo']['module_id'] = $data['module_id'];
    $data['extrainfo']['itemtype'] = $data['itemtype'];
    $data['extrainfo']['item_id'] = $data['itemid'];
    $data['extrainfo']['name'] = isset($data['extrainfo']['name']) ? $data['extrainfo']['name'] : xarML('Unknown Event');
    $data['extrainfo']['start_time'] = isset($data['extrainfo']['start_time']) ? $data['extrainfo']['start_time'] : time();
    $data['extrainfo']['duration'] = isset($data['extrainfo']['duration']) ? $data['extrainfo']['duration'] : 60;
    $data['extrainfo']['end_time'] = isset($data['extrainfo']['end_time']) ? $data['extrainfo']['end_time'] : $data['extrainfo']['start_time'] + $data['extrainfo']['duration'];
    $data['extrainfo']['recurring_code'] = isset($data['extrainfo']['recurring_code']) ? $data['extrainfo']['recurring_code'] : 0;
    $data['extrainfo']['recurring_span'] = isset($data['extrainfo']['recurring_span']) ? $data['extrainfo']['recurring_span'] : 0;
    $data['extrainfo']['start_location'] = isset($data['extrainfo']['start_location']) ? $data['extrainfo']['start_location'] : null;
    $data['extrainfo']['end_location'] = isset($data['extrainfo']['end_location']) ? $data['extrainfo']['end_location'] : null;
    $data['extrainfo']['object_id'] = isset($data['extrainfo']['object_id']) ? $data['extrainfo']['object_id'] : 0;
    $data['extrainfo']['role_id'] = isset($data['extrainfo']['role_id']) ? $data['extrainfo']['role_id'] : xarSession::getVar('role_id');
    $data['extrainfo']['return_link'] = isset($data['extrainfo']['return_link']) ? $data['extrainfo']['return_link'] : '';
    $data['extrainfo']['state'] = isset($data['extrainfo']['state']) ? $data['extrainfo']['state'] : 3;
    $data['extrainfo']['timestamp'] = isset($data['extrainfo']['timestamp']) ? $data['extrainfo']['timestamp'] : time();
    $data['extrainfo']['itemid'] = 0;
    $object = DataObjectMaster::getObject(array('name' => 'calendar_event'));
    $item = $object->createItem($data['extrainfo']);
    return $data['extrainfo'];
}
Esempio n. 13
0
/**
 * generate the common admin menu configuration
 */
function calendar_adminapi_menu()
{
    // Initialise the array that will hold the menu configuration
    $menu = array();
    // Specify the menu title to be used in your blocklayout template
    $menu['menutitle'] = xarML('Calendar Administration');
    // Specify the menu labels to be used in your blocklayout template
    // Preset some status variable
    $menu['status'] = '';
    // Return the array containing the menu configuration
    return $menu;
}
Esempio n. 14
0
function calendar_admin_create_calendars()
{
    // Get parameters
    // TODO HELPNEEDED here: how do I handle this (e.g. missing calname should return a
    // message
    if (!xarVarFetch('add_calendar', 'isset', $add_calendar)) {
        return;
    }
    if (!xarVarFetch('calname', 'str:1:', $calname)) {
        return;
    }
    if (!xarVarFetch('addtype', 'str:1:', $addtype)) {
        return;
    }
    if (!xarVarFetch('location', 'str:1:', $location, '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('uri', 'str:1:', $uri, '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Confirm Auth Key
    if (!xarSecConfirmAuthKey()) {
        return;
    }
    // Security Check
    // TODO
    //    if(!xarSecurityCheck('AddCalendar', 0, 'Calendar')) {return;}
    // Check if module name has already been used.
    $checkname = xarMod::apiFunc('calendar', 'user', 'get', array('calname' => $calname));
    if (!empty($checkname)) {
        $msg = xarML('Calendar name "#(1)" already exists. Please go back and enter a
                      different name', $calname);
        throw new Exception($msg);
    }
    if ($addtype == 'db') {
        $fileuri = 'a';
    } elseif ($addtype == 'file') {
        $fileuri = $location;
    } elseif ($addtype == 'uri') {
        $fileuri = $uri;
    }
    // Pass to API
    $calid = xarMod::apiFunc('calendar', 'admin', 'create_calendars', array('calname' => $calname, 'fileuri' => $fileuri, 'addtype' => $addtype));
    if (!$calid) {
        return;
    }
    // Go on and edit the new instance
    xarController::redirect(xarModURL('calendar', 'admin', 'add_calendars', array('calid' => $calid, 'calname' => $calname)));
}
Esempio n. 15
0
function publications_adminapi_getpubtypeaccess($args)
{
    if (!isset($args['ptid'])) {
        throw new Exception(xarML('Missing ptid param in publications_adminapi_getpubtypeaccess'));
    }
    $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types'));
    if (null == $pubtypeobject) {
        return false;
    }
    $pubtypeobject->getItem(array('itemid' => $args['ptid']));
    if (empty($pubtypeobject->properties['access']->value)) {
        return "a:0:{}";
    }
    return $pubtypeobject->properties['access']->value;
}
Esempio n. 16
0
/**
 * Delete a publication type
 *
 * @param $args['ptid'] ID of the publication type
 * @return bool true on success, false on failure
 */
function publications_adminapi_deletepubtype($args)
{
    // Get arguments from argument array
    extract($args);
    // Argument check - make sure that all required arguments are present
    // and in the right format, if not then set an appropriate error
    // message and return
    if (!isset($ptid) || !is_numeric($ptid) || $ptid < 1) {
        $msg = xarML('Invalid #(1) for #(2) function #(3)() in module #(4)', 'publication type ID', 'admin', 'deletepubtype', 'Publications');
        throw new BadParameterException(null, $msg);
    }
    // Security check - we require ADMIN rights here
    if (!xarSecurityCheck('AdminPublications', 1, 'Publication', "{$ptid}:All:All:All")) {
        return;
    }
    // Load user API to obtain item information function
    if (!xarModAPILoad('publications', 'user')) {
        return;
    }
    // Get current publication types
    $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
    if (!isset($pubtypes[$ptid])) {
        $msg = xarML('Invalid #(1) for #(2) function #(3)() in module #(4)', 'publication type ID', 'admin', 'deletepubtype', 'Publications');
        throw new BadParameterException(null, $msg);
    }
    // Get database setup
    $dbconn = xarDB::getConn();
    $xartable = xarDB::getTables();
    $pubtypestable = $xartable['publication_types'];
    // Delete the publication type
    $query = "DELETE FROM {$pubtypestable}\n            WHERE pubtype_id = ?";
    $result =& $dbconn->Execute($query, array($ptid));
    if (!$result) {
        return;
    }
    $publicationstable = $xartable['publications'];
    // Delete all publications for this publication type
    $query = "DELETE FROM {$publicationstable}\n            WHERE pubtype_id = ?";
    $result =& $dbconn->Execute($query, array($ptid));
    if (!$result) {
        return;
    }
    // TODO: call some kind of itemtype delete hooks here, once we have those
    //xarModCallHooks('itemtype', 'delete', $ptid,
    //                array('module' => 'publications',
    //                      'itemtype' =>'ptid'));
    return true;
}
Esempio n. 17
0
/**
 * redirect to a site based on some URL field of the item
 */
function publications_user_redirect($args)
{
    // Get parameters from user
    if (!xarVarFetch('id', 'id', $id, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Override if needed from argument array
    extract($args);
    if (!isset($id) || !is_numeric($id) || $id < 1) {
        return xarML('Invalid publication ID');
    }
    // Load API
    if (!xarModAPILoad('publications', 'user')) {
        return;
    }
    // Get publication
    $publication = xarModAPIFunc('publications', 'user', 'get', array('id' => $id));
    if (!is_array($publication)) {
        $msg = xarML('Failed to retrieve publication in #(3)_#(1)_#(2).php', 'user', 'get', 'publications');
        throw new DataNotFoundException(null, $msg);
    }
    $ptid = $publication['pubtype_id'];
    // Get publication types
    $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
    // TODO: improve this e.g. when multiple URL fields are present
    // Find an URL field based on the pubtype configuration
    foreach ($pubtypes[$ptid]['config'] as $field => $value) {
        if (empty($value['label'])) {
            continue;
        }
        if ($value['format'] == 'url' && !empty($publication[$field]) && $publication[$field] != 'http://') {
            // TODO: add some verifications here !
            $hooks = xarModCallHooks('item', 'display', $id, array('module' => 'publications', 'itemtype' => $ptid), 'publications');
            xarController::redirect($article[$field]);
            return true;
        } elseif ($value['format'] == 'urltitle' && !empty($publication[$field]) && substr($publication[$field], 0, 2) == 'a:') {
            $array = unserialize($publication[$field]);
            if (!empty($array['link']) && $array['link'] != 'http://') {
                $hooks = xarModCallHooks('item', 'display', $id, array('module' => 'publications', 'itemtype' => $ptid), 'publications');
                xarController::redirect($array['link']);
                return true;
            }
        }
    }
    return xarML('Unable to find valid redirect field');
}
Esempio n. 18
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;
}
Esempio n. 19
0
 function modify()
 {
     $data = $this->getContent();
     if (!is_array($data['pubstate'])) {
         $statearray = array($data['pubstate']);
     } else {
         $statearray = $data['pubstate'];
     }
     // Only include pubtype if a specific pubtype is selected
     if (!empty($data['pubtype_id'])) {
         $article_args['ptid'] = $data['pubtype_id'];
     }
     // Add the rest of the arguments
     $article_args['state'] = $statearray;
     $data['filtereditems'] = xarModAPIFunc('publications', 'user', 'getall', $article_args);
     $data['pubtypes'] = xarModAPIFunc('publications', 'user', 'get_pubtypes');
     $data['stateoptions'] = array(array('id' => '', 'name' => xarML('All Published')), array('id' => '3', 'name' => xarML('Frontpage')), array('id' => '2', 'name' => xarML('Approved')));
     return $data;
 }
Esempio n. 20
0
/**
 * Display a product
 */
function shop_user_product($args)
{
    if (!xarVarFetch('itemid', 'id', $itemid, NULL, XARVAR_DONT_SET)) {
        return;
    }
    extract($args);
    if (!empty($objectid)) {
        $itemid = $objectid;
    }
    if (empty($itemid)) {
        $msg = xarML('Invalid #(1) for #(2) function #(3)() in module #(4)', 'item id', 'user', 'display', 'shop');
        throw new Exception($msg);
    }
    // Make sure user has read privileges for the item
    if (!xarSecurityCheck('ReadShop', 1, 'Item', $itemid)) {
        return;
    }
    // Load the DD master object class. This line will likely disappear in future versions
    sys::import('modules.dynamicdata.class.objects.master');
    // Get the object definition we'll be working with
    $object = DataObjectMaster::getObject(array('name' => 'shop_products'));
    $data['object'] = $object;
    //We don't really have the item until we call getItem()
    $some_id = $object->getItem(array('itemid' => $itemid));
    //Make sure we got something
    if (!isset($some_id) || $some_id != $itemid) {
        return;
    }
    //Get the property names and values for the item with the getFieldValues() method
    $values = $object->getFieldValues();
    $data['itemid'] = $itemid;
    //$values is an associative array of property names and values, so...
    foreach ($values as $name => $value) {
        $data[$name] = xarVarPrepForDisplay($value);
    }
    $data['editurl'] = '';
    if (xarSecurityCheck('EditShop', 1)) {
        $data['editurl'] = xarModURL('shop', 'admin', 'modify', array('itemid' => $itemid, 'name' => 'shop_products'));
    }
    return xarTplModule('shop', 'user', 'product', $data);
}
Esempio n. 21
0
 public function validateValue($value = null)
 {
     if (!parent::validateValue($value)) {
         return false;
     }
     if (!isset($value)) {
         $value = $this->value;
     }
     $value = ereg_replace('[^0-9]', '', $value);
     // Check if the number itself is valid
     if (!$this->validnumber($value)) {
         if (!empty($this->validation_ccnumber_invalid)) {
             $this->invalid = xarML($this->validation_ccnumber_invalid);
         } else {
             $this->invalid = xarML('#(1) #(2): is not a valid credit card', $this->name, $this->desc);
         }
         $this->value = null;
         return false;
     }
     return true;
 }
Esempio n. 22
0
/**
 * Publications Module
 *
 * @package modules
 * @subpackage publications module
 * @category Third Party Xaraya Module
 * @version 2.0.0
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @author mikespub
 */
function publications_adminapi_browse($args)
{
    // Get arguments from argument array
    extract($args);
    // Argument check - make sure that all required arguments are present
    // and in the right format, if not then set an appropriate error
    // message and return
    if (empty($basedir) || empty($filetype)) {
        $msg = xarML('Invalid #(1) for #(2) function #(3)() in module #(4)', 'base directory', 'admin', 'browse', 'Publications');
        throw new BadParameterException(null, $msg);
    }
    $filelist = array();
    // Security Check
    if (!xarSecurityCheck('SubmitPublications', 0)) {
        return $filelist;
    }
    // not supported under safe_mode
    @set_time_limit(120);
    $todo = array();
    $basedir = realpath($basedir);
    array_push($todo, $basedir);
    while (count($todo) > 0) {
        $curdir = array_shift($todo);
        if ($dir = @opendir($curdir)) {
            while (($file = @readdir($dir)) !== false) {
                $curfile = $curdir . '/' . $file;
                if (preg_match("/\\.{$filetype}\$/", $file) && is_file($curfile) && filesize($curfile) > 0) {
                    $curfile = preg_replace('#' . preg_quote($basedir, '#') . '/#', '', $curfile);
                    $filelist[] = $curfile;
                } elseif ($file != '.' && $file != '..' && is_dir($curfile)) {
                    array_push($todo, $curfile);
                }
            }
            closedir($dir);
        }
    }
    natsort($filelist);
    return $filelist;
}
Esempio n. 23
0
/**
 * Display a transaction
 */
function shop_admin_transaction($args)
{
    if (!xarVarFetch('itemid', 'id', $itemid, NULL, XARVAR_DONT_SET)) {
        return;
    }
    extract($args);
    if (empty($itemid)) {
        $msg = xarML('Invalid #(1) for #(2) function #(3)() in module #(4)', 'item id', 'user', 'display', 'shop');
        throw new Exception($msg);
    }
    // Make sure user has read privileges for the item
    if (!xarSecurityCheck('ReadShop', 1, 'Item', $itemid)) {
        return;
    }
    // Load the DD master object class. This line will likely disappear in future versions
    sys::import('modules.dynamicdata.class.objects.master');
    // Get the object definition we'll be working with
    $object = DataObjectMaster::getObject(array('name' => 'shop_transactions'));
    $data['properties'] = $object->getProperties();
    $data['object'] = $object;
    //We don't really have the item until we call getItem()
    $some_id = $object->getItem(array('itemid' => $itemid));
    //Make sure we got something
    if (!isset($some_id) || $some_id != $itemid) {
        return;
    }
    //Get the property names and values for the item with the getFieldValues() method
    $values = $object->getFieldValues();
    //We need to do this up here to avoid messing up the serialized array with xarVarPrepForDisplay
    $products = unserialize($values['products']);
    //$values is an associative array of property names and values, so...
    foreach ($values as $name => $value) {
        $data[$name] = xarVarPrepForDisplay($value);
    }
    $data['products'] = $products;
    return $data;
}
Esempio n. 24
0
 public function display(array $data = array())
 {
     $data = $this->getContent();
     // see if we're currently displaying an article
     if (xarVarIsCached('Blocks.publications', 'id')) {
         $curid = xarVarGetCached('Blocks.publications', 'id');
     } else {
         $curid = -1;
     }
     if (!empty($data['dynamictitle'])) {
         if ($data['toptype'] == 'rating') {
             $data['title'] = xarML('Top Rated');
         } elseif ($data['toptype'] == 'hits') {
             $data['title'] = xarML('Top');
         } else {
             $data['title'] = xarML('Latest');
         }
     }
     if (!empty($data['nocatlimit'])) {
         // don't limit by category
         $cid = 0;
         $cidsarray = array();
     } else {
         if (!empty($data['catfilter'])) {
             // use admin defined category
             $cidsarray = array($data['catfilter']);
             $cid = $data['catfilter'];
         } else {
             // use the current category
             // Jonn: this currently only works with one category at a time
             // it could be reworked to support multiple cids
             if (xarVarIsCached('Blocks.publications', 'cids')) {
                 $curcids = xarVarGetCached('Blocks.publications', 'cids');
                 if (!empty($curcids)) {
                     if ($curid == -1) {
                         //$cid = $curcids[0]['name'];
                         $cid = $curcids[0];
                         $cidsarray = array($curcids[0]);
                     } else {
                         $cid = $curcids[0];
                         $cidsarray = array($curcids[0]);
                     }
                 } else {
                     $cid = 0;
                     $cidsarray = array();
                 }
             } else {
                 // pull from all categories
                 $cid = 0;
                 $cidsarray = array();
             }
         }
         //echo $includechildren;
         if (!empty($data['includechildren']) && !empty($cidsarray[0]) && !strstr($cidsarray[0], '_')) {
             $cidsarray[0] = '_' . $cidsarray[0];
         }
         if (!empty($cid)) {
             // if we're viewing all items below a certain category, i.e. catid = _NN
             $cid = str_replace('_', '', $cid);
             $thiscategory = xarModAPIFunc('categories', 'user', 'getcat', array('cid' => $cid, 'return_itself' => 'return_itself'));
         }
         if (!empty($cidsarray) && isset($thiscategory[0]['name']) && !empty($data['dynamictitle'])) {
             $data['title'] .= ' ' . $thiscategory[0]['name'];
         }
     }
     // Get publication types
     // MarieA - moved to always get pubtypes.
     $publication_types = xarModAPIFunc('publications', 'user', 'get_pubtypes');
     if (!empty($data['nopublimit'])) {
         //don't limit by publication type
         $ptid = 0;
         if (!empty($data['dynamictitle'])) {
             $data['title'] .= ' ' . xarML('Content');
         }
     } else {
         // MikeC: Check to see if admin has specified that only a specific
         // Publication Type should be displayed.  If not, then default to original TopItems configuration.
         if ($data['pubtype_id'] == 0) {
             if (xarVarIsCached('Blocks.publications', 'ptid')) {
                 $ptid = xarVarGetCached('Blocks.publications', 'ptid');
             }
             if (empty($ptid)) {
                 // default publication type
                 $ptid = xarModVars::get('publications', 'defaultpubtype');
             }
         } else {
             // MikeC: Admin Specified a publication type, use it.
             $ptid = $data['pubtype_id'];
         }
         if (!empty($data['dynamictitle'])) {
             if (!empty($ptid) && isset($publication_types[$ptid]['description'])) {
                 $data['title'] .= ' ' . xarVarPrepForDisplay($publication_types[$ptid]['description']);
             } else {
                 $data['title'] .= ' ' . xarML('Content');
             }
         }
     }
     // frontpage or approved state
     if (empty($data['pubstate'])) {
         $statearray = array(2, 3);
     } elseif (!is_array($data['pubstate'])) {
         $statearray = preg_split('/,/', $data['pubstate']);
     } else {
         $statearray = $data['pubstate'];
     }
     // get cids for security check in getall
     $fields = array('id', 'title', 'pubtype_id', 'cids');
     if ($data['toptype'] == 'rating' && xarModIsHooked('ratings', 'publications', $ptid)) {
         array_push($fields, 'rating');
         $sort = 'rating';
     } elseif ($data['toptype'] == 'hits' && xarModIsHooked('hitcount', 'publications', $ptid)) {
         array_push($fields, 'counter');
         $sort = 'hits';
     } else {
         array_push($fields, 'create_date');
         $sort = 'date';
     }
     if (!empty($data['showsummary'])) {
         array_push($fields, 'summary');
     }
     if (!empty($data['showdynamic']) && xarModIsHooked('dynamicdata', 'publications', $ptid)) {
         array_push($fields, 'dynamicdata');
     }
     $publications = xarModAPIFunc('publications', 'user', 'getall', array('ptid' => $ptid, 'cids' => $cidsarray, 'andcids' => 'false', 'state' => $statearray, 'create_date' => time(), 'fields' => $fields, 'sort' => $sort, 'numitems' => $data['numitems']));
     if (!isset($publications) || !is_array($publications) || count($publications) == 0) {
         return;
     }
     $items = array();
     foreach ($publications as $article) {
         $article['title'] = xarVarPrepHTMLDisplay($article['title']);
         if ($article['id'] != $curid) {
             // Use the filtered category if set, and not including children
             $article['link'] = xarModURL('publications', 'user', 'display', array('itemid' => $article['id'], 'catid' => !empty($data['linkcat']) && !empty($data['catfilter']) ? $data['catfilter'] : NULL));
         } else {
             $article['link'] = '';
         }
         if (!empty($data['showvalue'])) {
             if ($data['toptype'] == 'rating') {
                 if (!empty($article['rating'])) {
                     $article['value'] = intval($article['rating']);
                 } else {
                     $article['value'] = 0;
                 }
             } elseif ($data['toptype'] == 'hits') {
                 if (!empty($article['counter'])) {
                     $article['value'] = $article['counter'];
                 } else {
                     $article['value'] = 0;
                 }
             } else {
                 // TODO: make user-dependent
                 if (!empty($article['create_date'])) {
                     //$article['value'] = strftime("%Y-%m-%d", $article['create_date']);
                     $article['value'] = xarLocaleGetFormattedDate('short', $article['create_date']);
                 } else {
                     $article['value'] = 0;
                 }
             }
         } else {
             $article['value'] = 0;
         }
         // MikeC: Bring the summary field back as $desc
         if (!empty($data['showsummary'])) {
             $article['summary'] = xarVarPrepHTMLDisplay($article['summary']);
             $article['transform'] = array('summary', 'title');
             $article = xarModCallHooks('item', 'transform', $article['id'], $article, 'publications');
         } else {
             $article['summary'] = '';
         }
         // MarieA: Bring the pubtype description back as $descr
         if (!empty($data['nopublimit'])) {
             $article['pubtypedescr'] = $publication_types[$article['pubtype_id']]['description'];
             //jojodee: while we are here bring the pubtype name back as well
             $article['pubtypename'] = $publication_types[$article['pubtype_id']]['name'];
         }
         // this will also pass any dynamic data fields (if any)
         $items[] = $article;
     }
     $data['items'] = $items;
     if (!empty($data['dynamictitle'])) {
         $this->setTitle($data['title']);
     }
     return $data;
 }
Esempio n. 25
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;
}
Esempio n. 26
0
/**
 * search publications (called as hook from search module, or directly with pager)
 *
 * @param $args['objectid'] could be the query ? (currently unused)
 * @param $args['extrainfo'] all other parameters ? (currently unused)
 * @return array output
 */
function publications_user_search($args)
{
    // pager stuff
    if (!xarVarFetch('startnum', 'int:0', $startnum, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // categories stuff
    if (!xarVarFetch('cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('andcids', 'str', $andcids, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('catid', 'str', $catid, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // single publication type when called via the pager
    if (!xarVarFetch('ptid', 'id', $ptid, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // multiple publication types when called via search hooks
    if (!xarVarFetch('ptids', 'array', $ptids, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // date stuff via forms
    if (!xarVarFetch('publications_startdate', 'str', $startdate, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('publications_enddate', 'str', $enddate, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // date stuff via URLs
    if (!xarVarFetch('start', 'int:0', $start, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('end', 'int:0', $end, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // search button was pressed
    if (!xarVarFetch('search', 'str', $search, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // select by article state (array or string)
    if (!xarVarFetch('state', 'isset', $state, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // yes, this is the query
    if (!xarVarFetch('q', 'str', $q, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('author', 'str', $author, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // filter by category
    if (!xarVarFetch('by', 'str', $by, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // can't use list enum here, because we don't know which sorts might be used
    if (!xarVarFetch('sort', 'regexp:/^[\\w,]*$/', $sort, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // boolean AND/OR for words (no longer used)
    //if(!xarVarFetch('bool',     'str',   $bool,   NULL, XARVAR_NOT_REQUIRED)) {return;}
    // search in specific fields
    if (!xarVarFetch('publications_fields', 'isset', $fields, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('searchtype', 'isset', $searchtype, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (isset($args['objectid'])) {
        $ishooked = 1;
    } else {
        $ishooked = 0;
        if (empty($fields)) {
            // search in specific fields via URLs
            if (!xarVarFetch('fields', 'isset', $fields, NULL, XARVAR_NOT_REQUIRED)) {
                return;
            }
        }
    }
    // TODO: could we need this someday ?
    if (isset($args['extrainfo'])) {
        extract($args['extrainfo']);
    }
    // TODO: clean up this copy & paste stuff :-)
    // Default parameters
    if (!isset($startnum)) {
        $startnum = 1;
    }
    if (!isset($numitems)) {
        $numitems = 20;
    }
    if (!xarModAPILoad('publications', 'user')) {
        return;
    }
    // Get publication types
    $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
    if (xarSecurityCheck('AdminPublications', 0)) {
        $isadmin = true;
    } else {
        $isadmin = false;
    }
    // frontpage or approved state
    if (!$isadmin || !isset($state)) {
        $state = array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED);
    } elseif (is_string($state)) {
        if (strpos($state, ' ')) {
            $state = explode(' ', $state);
        } elseif (strpos($state, '+')) {
            $state = explode('+', $state);
        } else {
            $state = array($state);
        }
    }
    $seenstate = array();
    foreach ($state as $that) {
        if (empty($that) || !is_numeric($that)) {
            continue;
        }
        $seenstate[$that] = 1;
    }
    $state = array_keys($seenstate);
    if (count($state) != 2 || !in_array(PUBLICATIONS_STATE_APPROVED, $state) || !in_array(PUBLICATIONS_STATE_FRONTPAGE, $state)) {
        $stateline = implode('+', $state);
    } else {
        $stateline = null;
    }
    if (!isset($sort)) {
        $sort = null;
    }
    // default publication type(s) to search in
    if (!empty($ptid) && isset($pubtypes[$ptid])) {
        $ptids = array($ptid);
        $settings = unserialize(xarModVars::get('publications', 'settings.' . $ptid));
        if (empty($settings['show_categories'])) {
            $show_categories = 0;
        } else {
            $show_categories = 1;
        }
    } elseif (!empty($ptids) && count($ptids) > 0) {
        foreach ($ptids as $curptid) {
            // default view doesn't apply here ?!
        }
        $show_categories = 1;
    } elseif (!isset($ptids)) {
        //    $ptids = array(xarModVars::get('publications','defaultpubtype'));
        $ptids = array();
        foreach ($pubtypes as $pubid => $pubtype) {
            $ptids[] = $pubid;
        }
        $show_categories = 1;
    } else {
        // TODO: rethink this when we're dealing with multi-pubtype categories
        $show_categories = 0;
    }
    // turn $catid into $cids array (and set $andcids flag)
    if (!empty($catid)) {
        if (strpos($catid, ' ')) {
            $cids = explode(' ', $catid);
            $andcids = true;
        } elseif (strpos($catid, '+')) {
            $cids = explode('+', $catid);
            $andcids = true;
        } else {
            $cids = explode('-', $catid);
            $andcids = false;
        }
    }
    $seencid = array();
    $catid = null;
    if (isset($cids) && is_array($cids)) {
        foreach ($cids as $cid) {
            if (empty($cid) || !preg_match('/^_?[0-9]+$/', $cid)) {
                continue;
            }
            $seencid[$cid] = 1;
        }
        $cids = array_keys($seencid);
        if ($andcids) {
            $catid = join('+', $cids);
        } else {
            $catid = join('-', $cids);
        }
    }
    $seenptid = array();
    if (isset($ptids) && is_array($ptids)) {
        foreach ($ptids as $curptid) {
            if (empty($curptid) || !isset($pubtypes[$curptid])) {
                continue;
            }
            $seenptid[$curptid] = 1;
        }
        $ptids = array_keys($seenptid);
    }
    /* Ensure whitespace alone not passed to api -causes errors */
    if (isset($q) && trim($q) === '') {
        $q = null;
    }
    // Find the id of the author we're looking for
    if (!empty($author)) {
        // Load API
        if (!xarModAPILoad('roles', 'user')) {
            return;
        }
        $user = xarModAPIFunc('roles', 'user', 'get', array('name' => $author));
        if (!empty($user['uid'])) {
            $owner = $user['uid'];
        } else {
            $owner = null;
            $author = null;
        }
    } else {
        $owner = null;
        $author = null;
    }
    if (isset($start) && is_numeric($start)) {
        $startdate = xarLocaleFormatDate("%Y-%m-%d %H:%M:%S", $start);
    }
    if (isset($end) && is_numeric($end)) {
        $enddate = xarLocaleFormatDate("%Y-%m-%d %H:%M:%S", $end);
    }
    if (empty($fields)) {
        $fieldlist = array('title', 'description', 'summary', 'body1');
    } else {
        $fieldlist = array_keys($fields);
        // don't pass fields via URLs if we stick to the default list
        if (count($fields) == 3 && isset($fields['title']) && isset($fields['description']) && isset($fields['summary']) && isset($fields['body1'])) {
            $fields = null;
        }
    }
    // Set default searchtype to 'fulltext' if necessary
    $fulltext = xarModVars::get('publications', 'fulltextsearch');
    if (!isset($searchtype) && !empty($fulltext)) {
        $searchtype = 'fulltext';
    }
    // FIXME: fulltext only supports searching in all configured text fields !
    if (empty($fields) && !empty($fulltext) && !empty($searchtype) && $searchtype == 'fulltext') {
        $fieldlist = explode(',', $fulltext);
    }
    $data = array();
    $data['results'] = array();
    $data['state'] = '';
    $data['ishooked'] = $ishooked;
    // TODO: MichelV: $ishooked is never empty, but either 0 or 1
    if (empty($ishooked)) {
        $data['q'] = isset($q) ? xarVarPrepForDisplay($q) : null;
        $data['author'] = isset($author) ? xarVarPrepForDisplay($author) : null;
        $data['searchtype'] = $searchtype;
    }
    if ($isadmin) {
        $states = xarModAPIFunc('publications', 'user', 'getstates');
        $data['statelist'] = array();
        foreach ($states as $id => $name) {
            $data['statelist'][] = array('id' => $id, 'name' => $name, 'checked' => in_array($id, $state));
        }
    }
    // TODO: show field labels when we're dealing with only 1 pubtype
    $data['fieldlist'] = array(array('id' => 'title', 'name' => xarML('title'), 'checked' => in_array('title', $fieldlist)), array('id' => 'description', 'name' => xarML('description'), 'checked' => in_array('description', $fieldlist)), array('id' => 'summary', 'name' => xarML('summary'), 'checked' => in_array('summary', $fieldlist)), array('id' => 'body1', 'name' => xarML('body1'), 'checked' => in_array('body1', $fieldlist)), array('id' => 'notes', 'name' => xarML('notes'), 'checked' => in_array('notes', $fieldlist)));
    $data['publications'] = array();
    foreach ($pubtypes as $pubid => $pubtype) {
        if (!empty($seenptid[$pubid])) {
            $checked = ' checked="checked"';
        } else {
            $checked = '';
        }
        $data['publications'][] = array('id' => $pubid, 'description' => xarVarPrepForDisplay($pubtype['description']), 'checked' => $checked);
    }
    $data['categories'] = array();
    if (!empty($by) && $by == 'cat') {
        $catarray = array();
        foreach ($ptids as $curptid) {
            // get root categories for this publication type
            $catlinks = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $curptid));
            foreach ($catlinks as $cat) {
                $catarray[$cat['category_id']] = $cat['name'];
            }
        }
        foreach ($catarray as $cid => $title) {
            $select = xarModAPIFunc('categories', 'visual', 'makeselect', array('cid' => $cid, 'return_itself' => true, 'select_itself' => true, 'values' => &$seencid, 'multiple' => 1));
            $data['categories'][] = array('cattitle' => $title, 'catselect' => $select);
        }
        $data['searchurl'] = xarModURL('search', 'user', 'main');
    } else {
        $data['searchurl'] = xarModURL('search', 'user', 'main', array('by' => 'cat'));
    }
    $now = time();
    if (empty($startdate)) {
        $startdate = null;
        $data['startdate'] = 'N/A';
    } else {
        if (!preg_match('/[a-zA-Z]+/', $startdate)) {
            $startdate .= ' GMT';
        }
        $startdate = strtotime($startdate);
        // adjust for the user's timezone offset
        $startdate -= xarMLS_userOffset() * 3600;
        if ($startdate > $now && !$isadmin) {
            $startdate = $now;
        }
        $data['startdate'] = $startdate;
    }
    if (empty($enddate)) {
        $enddate = $now;
        $data['enddate'] = 'N/A';
    } else {
        if (!preg_match('/[a-zA-Z]+/', $enddate)) {
            $enddate .= ' GMT';
        }
        $enddate = strtotime($enddate);
        // adjust for the user's timezone offset
        $enddate -= xarMLS_userOffset() * 3600;
        if ($enddate > $now && !$isadmin) {
            $enddate = $now;
        }
        $data['enddate'] = $enddate;
    }
    if (!empty($q) || !empty($author) && isset($owner) || !empty($search) || !empty($ptid) || !empty($startdate) || $enddate != $now || !empty($catid)) {
        $getfields = array('id', 'title', 'start_date', 'pubtype_id', 'cids');
        // Return the relevance when using MySQL full-text search
        //if (!empty($search) && !empty($searchtype) && substr($searchtype,0,8) == 'fulltext') {
        //    $getfields[] = 'relevance';
        //}
        $count = 0;
        // TODO: allow combination of searches ?
        foreach ($ptids as $curptid) {
            $publications = xarModAPIFunc('publications', 'user', 'getall', array('startnum' => $startnum, 'cids' => $cids, 'andcids' => $andcids, 'ptid' => $curptid, 'owner' => $owner, 'sort' => $sort, 'numitems' => $numitems, 'state' => $state, 'start_date' => $startdate, 'end_date' => $enddate, 'searchfields' => $fieldlist, 'searchtype' => $searchtype, 'search' => $q, 'fields' => $getfields));
            // TODO: re-use article output code from elsewhere (view / archive / admin)
            if (!empty($publications) && count($publications) > 0) {
                // retrieve the categories for each article
                $catinfo = array();
                if ($show_categories) {
                    $cidlist = array();
                    foreach ($publications as $article) {
                        if (!empty($article['cids']) && count($article['cids']) > 0) {
                            foreach ($article['cids'] as $cid) {
                                $cidlist[$cid] = 1;
                            }
                        }
                    }
                    if (count($cidlist) > 0) {
                        $catinfo = xarModAPIFunc('categories', 'user', 'getcatinfo', array('cids' => array_keys($cidlist)));
                        // get root categories for this publication type
                        $catroots = xarModAPIFunc('publications', 'user', 'getrootcats', array('ptid' => $curptid));
                        $catroots = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $curptid));
                    }
                    foreach ($catinfo as $cid => $info) {
                        $catinfo[$cid]['name'] = xarVarPrepForDisplay($info['name']);
                        $catinfo[$cid]['link'] = xarModURL('publications', 'user', 'view', array('ptid' => $curptid, 'catid' => $catid && $andcids ? $catid . '+' . $cid : $cid));
                        // only needed when sorting by root category id
                        $catinfo[$cid]['root'] = 0;
                        // means not found under a root category
                        // only needed when sorting by root category order
                        $catinfo[$cid]['order'] = 0;
                        // means not found under a root category
                        $rootidx = 1;
                        foreach ($catroots as $rootcat) {
                            // see if we're a child category of this rootcat (cfr. Celko model)
                            if ($info['left'] >= $rootcat['left_id'] && $info['left'] < $rootcat['right_id']) {
                                // only needed when sorting by root category id
                                $catinfo[$cid]['root'] = $rootcat['category_id'];
                                // only needed when sorting by root category order
                                $catinfo[$cid]['order'] = $rootidx;
                                break;
                            }
                            $rootidx++;
                        }
                    }
                }
                // needed for sort function below
                $GLOBALS['artsearchcatinfo'] = $catinfo;
                $items = array();
                foreach ($publications as $article) {
                    $count++;
                    $curptid = $article['pubtype_id'];
                    $link = xarModURL('publications', 'user', 'display', array('ptid' => $article['pubtype_id'], 'itemid' => $article['id']));
                    // publication date of article (if needed)
                    if (!empty($pubtypes[$curptid]['config']['startdate']['label']) && !empty($article['startdate'])) {
                        $date = xarLocaleFormatDate('%a, %d %B %Y %H:%M:%S %Z', $article['startdate']);
                        $startdate = $article['startdate'];
                    } else {
                        $date = '';
                        $startdate = 0;
                    }
                    if (empty($article['title'])) {
                        $article['title'] = xarML('(none)');
                    }
                    // categories this article belongs to
                    $categories = array();
                    if ($show_categories && !empty($article['cids']) && is_array($article['cids']) && count($article['cids']) > 0) {
                        $cidlist = $article['cids'];
                        // order cids by root category order
                        usort($cidlist, 'publications_search_sortbyorder');
                        // order cids by root category id
                        //usort($cidlist,'publications_search_sortbyroot');
                        // order cids by position in Celko tree
                        //usort($cidlist,'publications_search_sortbyleft');
                        $join = '';
                        foreach ($cidlist as $cid) {
                            $item = array();
                            if (!isset($catinfo[$cid])) {
                                // oops
                                continue;
                            }
                            $categories[] = array('cname' => $catinfo[$cid]['name'], 'clink' => $catinfo[$cid]['link'], 'cjoin' => $join);
                            if (empty($join)) {
                                $join = ' | ';
                            }
                        }
                    }
                    $items[] = array('title' => xarVarPrepHTMLDisplay($article['title']), 'link' => $link, 'date' => $date, 'startdate' => $startdate, 'relevance' => isset($article['relevance']) ? $article['relevance'] : null, 'categories' => $categories);
                }
                unset($publications);
                // Pager
                // TODO: make count depend on locale in the future
                sys::import('modules.base.class.pager');
                $pager = xarTplPager::getPager($startnum, xarModAPIFunc('publications', 'user', 'countitems', array('cids' => $cids, 'andcids' => $andcids, 'ptid' => $curptid, 'owner' => $owner, 'state' => $state, 'startdate' => $startdate, 'enddate' => $enddate, 'searchfields' => $fieldlist, 'searchtype' => $searchtype, 'search' => $q)), xarModURL('publications', 'user', 'search', array('ptid' => $curptid, 'catid' => $catid, 'q' => isset($q) ? $q : null, 'author' => isset($author) ? $author : null, 'start' => $startdate, 'end' => $enddate != $now ? $enddate : null, 'state' => $stateline, 'sort' => $sort, 'fields' => $fields, 'searchtype' => !empty($searchtype) ? $searchtype : null, 'startnum' => '%%')), $numitems);
                if (strlen($pager) > 5) {
                    if (!isset($sort) || $sort == 'date') {
                        $othersort = 'title';
                    } else {
                        $othersort = null;
                    }
                    $sortlink = xarModURL('publications', 'user', 'search', array('ptid' => $curptid, 'catid' => $catid, 'q' => isset($q) ? $q : null, 'author' => isset($author) ? $author : null, 'start' => $startdate, 'end' => $enddate != $now ? $enddate : null, 'state' => $stateline, 'fields' => $fields, 'searchtype' => !empty($searchtype) ? $searchtype : null, 'sort' => $othersort));
                    if (!isset($othersort)) {
                        $othersort = 'date';
                    }
                    $pager .= '&#160;&#160;<a href="' . $sortlink . '">' . xarML('sort by') . ' ' . xarML($othersort) . '</a>';
                }
                $data['results'][] = array('description' => xarVarPrepForDisplay($pubtypes[$curptid]['description']), 'items' => $items, 'pager' => $pager);
            }
        }
        unset($catinfo);
        unset($items);
        unset($GLOBALS['artsearchcatinfo']);
        if ($count > 0) {
            // bail out, we have what we needed
            return xarTplModule('publications', 'user', 'search', $data);
        }
        $data['state'] = xarML('No pages found matching this search');
    }
    return xarTplModule('publications', 'user', 'search', $data);
}
Esempio n. 27
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;
}
Esempio n. 28
0
/**
 * return an array with coded states
 * @return array
 */
function publications_userapi_getstates()
{
    // Simplistic getstates function
    // Obviously needs to be smarter along with the other state functions
    return array(0 => xarML('Deleted'), 1 => xarML('Inactive'), 2 => xarML('Draft'), 3 => xarML('Active'), 4 => xarML('Frontpage'), 5 => xarML('Empty'));
}
Esempio n. 29
0
/**
* get array of configurable fields for publication types
* @TODO : add dynamic fields here for .81+
* @return array('title'   => array('label'  => xarML('...'),
                                   'format' => '...',
                                   'input'  => 1),
                'summary' => array('label'  => xarML('...'),
                                   'format' => '...',
                                   'input'  => 1),
                ...);
*/
function publications_userapi_getpubfields($args)
{
    return array('title' => array('label' => xarML('Title'), 'format' => 'textbox', 'input' => 1), 'summary' => array('label' => xarML('Summary'), 'format' => 'textarea_medium', 'input' => 1), 'body' => array('label' => xarML('Body'), 'format' => 'textarea_large', 'input' => 1), 'notes' => array('label' => xarML('Notes'), 'format' => 'textarea', 'input' => 0), 'owner' => array('label' => xarML('Author'), 'format' => 'username', 'input' => 0), 'pubdate' => array('label' => xarML('Publication Date'), 'format' => 'calendar', 'input' => 0), 'state' => array('label' => xarML('Status'), 'format' => 'state', 'input' => 0));
}
Esempio n. 30
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;
}