Beispiel #1
0
function publications_user_new($args)
{
    extract($args);
    // Get parameters
    if (!xarVarFetch('ptid', 'id', $data['ptid'], xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('catid', 'str', $catid, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('itemtype', 'id', $itemtype, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    $data['items'] = array();
    $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types'));
    $pubtypeobject->getItem(array('itemid' => $data['ptid']));
    $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value));
    $data['properties'] = $data['object']->getProperties();
    if (!empty($data['ptid'])) {
        $template = $pubtypeobject->properties['template']->value;
    } else {
        // TODO: allow templates per category ?
        $template = null;
    }
    // Get the settings of the publication type we are using
    $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid']));
    return xarTplModule('publications', 'admin', 'new', $data, $template);
}
Beispiel #2
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;
}
Beispiel #3
0
function publications_admin_modify_pubtype($args)
{
    if (!xarSecurityCheck('AdminPublications')) {
        return;
    }
    extract($args);
    // Get parameters
    if (!xarVarFetch('itemid', 'isset', $data['itemid'], NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('returnurl', 'str:1', $data['returnurl'], 'view', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('name', 'str:1', $name, '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('tab', 'str:1', $data['tab'], '', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('confirm', 'bool', $data['confirm'], false, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (empty($name) && empty($itemid)) {
        return xarResponse::NotFound();
    }
    // Get our object
    $data['object'] = DataObjectMaster::getObject(array('name' => 'publications_types'));
    if (!empty($data['itemid'])) {
        $data['object']->getItem(array('itemid' => $data['itemid']));
    } else {
        $type_list = DataObjectMaster::getObjectList(array('name' => 'publications_types'));
        $where = 'name = ' . $name;
        $items = $type_list->getItems(array('where' => $where));
        $item = current($items);
        $data['object']->getItem(array('itemid' => $item['id']));
    }
    // Send the publication type and the object properties to the template
    $data['properties'] = $data['object']->getProperties();
    // Get the settings of the publication type we are using
    $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['itemid']));
    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('publications', 'admin', 'modify_pubtype', $data);
        } else {
            // Good data: create the item
            $itemid = $data['object']->updateItem(array('itemid' => $data['itemid']));
            // Jump to the next page
            xarController::redirect(xarModURL('publications', 'admin', 'view_pubtypes'));
            return true;
        }
    }
    return $data;
}
Beispiel #4
0
/**
 * get next article
 * Note : the following parameters are all optional (except id and ptid)
 *
 * @param $args['id'] the article ID we want to have the next article of
 * @param $args['ptid'] publication type ID (for news, sections, reviews, ...)
 * @param $args['sort'] sort order ('date','title','hits','rating',...)
 * @param $args['owner'] the ID of the author
 * @param $args['state'] array of requested status(es) for the publications
 * @param $args['enddate'] publications published before enddate
 *                         (unix timestamp format)
 * @return array of article fields, or false on failure
 */
function publications_userapi_getnext($args)
{
    // Get arguments from argument array
    extract($args);
    // Optional argument
    if (empty($sort)) {
        $sort = 'date';
    }
    if (!isset($state)) {
        // frontpage or approved
        $state = array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED);
    }
    // Default fields in publications (for now)
    $fields = array('id', 'title');
    // Security check
    if (!xarSecurityCheck('ViewPublications')) {
        return;
    }
    // Database information
    $dbconn = xarDB::getConn();
    // Get the field names and LEFT JOIN ... ON ... parts from publications
    // By passing on the $args, we can let leftjoin() create the WHERE for
    // the publications-specific columns too now
    $publicationsdef = xarModAPIFunc('publications', 'user', 'leftjoin', $args);
    // Create the query
    $query = "SELECT {$publicationsdef['id']}, {$publicationsdef['title']}, {$publicationsdef['pubtype_id']}, {$publicationsdef['owner']}\n                FROM {$publicationsdef['table']} WHERE ";
    // we rely on leftjoin() to create the necessary publications clauses now
    if (!empty($publicationsdef['where'])) {
        $query .= " {$publicationsdef['where']} AND ";
    }
    // Get current article
    $current = xarModAPIFunc('publications', 'user', 'get', array('id' => $id));
    // Create the ORDER BY part
    switch ($sort) {
        case 'title':
            $query .= $publicationsdef['title'] . ' > ' . $dbconn->qstr($current['title']) . ' ORDER BY ' . $publicationsdef['title'] . ' ASC, ' . $publicationsdef['id'] . ' ASC';
            break;
        case 'id':
            $query .= $publicationsdef['id'] . ' > ' . $current['id'] . ' ORDER BY ' . $publicationsdef['id'] . ' ASC';
            break;
        case 'data':
        default:
            $query .= $publicationsdef['pubdate'] . ' > ' . $dbconn->qstr($current['pubdate']) . ' ORDER BY ' . $publicationsdef['pubdate'] . ' ASC, ' . $publicationsdef['id'] . ' ASC';
    }
    // Run the query - finally :-)
    $result =& $dbconn->SelectLimit($query, 1, 0);
    if (!$result) {
        return;
    }
    $item = array();
    list($item['id'], $item['title'], $item['pubtype_id'], $item['owner']) = $result->fields;
    $result->Close();
    // TODO: grab categories & check against them too
    // check security - don't generate an exception here
    if (!xarSecurityCheck('ViewPublications', 0, 'Publication', "{$item['pubtype_id']}:All:{$item['owner']}:{$item['id']}")) {
        return array();
    }
    return $item;
}
Beispiel #5
0
/**
 * display waiting content as a hook
 */
function publications_admin_waitingcontent()
{
    // Get publication types
    unset($publinks);
    $publinks = xarModAPIFunc('publications', 'user', 'getpublinks', array('state' => array(0), 'typemod' => 'admin'));
    $data['loop'] = $publinks;
    return $data;
}
Beispiel #6
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;
}
Beispiel #7
0
 function galaxia_execute_activity($activity_id = 0, $iid = 0, $auto = 1)
 {
     $result = xarModAPIFunc('workflow', 'user', 'run_activity', array('activity_id' => $activity_id, 'iid' => $iid, 'auto' => $auto));
     if (empty($result)) {
         // TODO: clean this up
         echo xarExceptionRender('html');
         die;
     }
 }
 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;
 }
Beispiel #9
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 #10
0
/**
 * Get Random Publication(s)
 *
 * Note : the following parameters are all optional
 * @author Michel Dalle <*****@*****.**>
 * @param int    $args['numitems'] number of publications to get
 * @param int    $args['ptid'] publication type ID (for news, sections, reviews, ...)
 * @param array  $args['state'] array of requested status(es) for the publications
 * @param array  $args['cids'] array of category IDs for which to get publications (OR/AND)
 *                      (for all categories don?t set it)
 * @param bool   $args['andcids'] true means AND-ing categories listed in cids
 * @param array  $args['fields'] array with all the fields to return per article
 *                        Default list is : 'id','title','summary','owner',
 *                        'pubdate','pubtype_id','notes','state','body'
 *                        Optional fields : 'cids','author','counter','rating','dynamicdata'
 * @param string $args['locale'] language/locale (if not using multi-sites, categories etc.)
 * @param bool   $args['unique'] return unique results
 * @return array of publications, or false on failure
 */
function publications_userapi_getrandom($args)
{
    // 1. count the number of items that apply
    $count = xarModAPIFunc('publications', 'user', 'countitems', $args);
    if (empty($count)) {
        return array();
    }
    // 2. retrieve numitems random publications
    if (empty($args['numitems'])) {
        $numitems = 1;
    } else {
        $numitems = $args['numitems'];
    }
    $idlist = array();
    if (empty($args['unique'])) {
        $args['unique'] = false;
    } else {
        $args['unique'] = true;
    }
    $publications = array();
    mt_srand((double) microtime() * 1000000);
    if ($count <= $numitems) {
        unset($args['numitems']);
        // retrieve all publications and randomize the order
        $items = xarModAPIFunc('publications', 'user', 'getall', $args);
        $randomkeys = array_rand($items, $count);
        if (!is_array($randomkeys)) {
            $randomkeys = array($randomkeys);
        }
        foreach ($randomkeys as $key) {
            array_push($publications, $items[$key]);
        }
    } else {
        // retrieve numitems x 1 random article
        $args['numitems'] = 1;
        for ($i = 0; $i < $numitems; $i++) {
            $args['startnum'] = mt_rand(1, $count);
            if ($args['unique'] && in_array($args['startnum'], $idlist)) {
                $i--;
            } else {
                $idlist[] = $args['startnum'];
                $items = xarModAPIFunc('publications', 'user', 'getall', $args);
                if (empty($items)) {
                    break;
                }
                array_push($publications, array_pop($items));
            }
        }
    }
    return $publications;
}
Beispiel #11
0
function publications_admin_create()
{
    if (!xarVarFetch('ptid', 'id', $data['ptid'])) {
        return;
    }
    if (!xarVarFetch('new_cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('preview', 'str', $data['preview'], NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('save', 'str', $save, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Confirm authorisation code
    // This has been disabled for now
    // if (!xarSecConfirmAuthKey()) return;
    $data['items'] = array();
    $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types'));
    $pubtypeobject->getItem(array('itemid' => $data['ptid']));
    $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value));
    $isvalid = $data['object']->checkInput();
    $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid']));
    if ($data['preview'] || !$isvalid) {
        // Show debug info if called for
        if (!$isvalid && xarModVars::get('publications', 'debugmode') && in_array(xarUserGetVar('uname'), xarConfigVars::get(null, 'Site.User.DebugAdmins'))) {
            var_dump($data['object']->getInvalids());
        }
        // Preview or bad data: redisplay the form
        $data['properties'] = $data['object']->getProperties();
        if ($data['preview']) {
            $data['tab'] = 'preview';
        }
        return xarTplModule('publications', 'admin', 'new', $data);
    }
    // Create the object
    $id = $data['object']->createItem();
    // if we can edit publications, go to admin view, otherwise go to user view
    if (xarSecurityCheck('EditPublications', 0, 'Publication', $data['ptid'] . ':All:All:All')) {
        // Redirect if we came from somewhere else
        $cuurent_listview = xarSession::getVar('publications_current_listview');
        if (!empty($cuurent_listview)) {
            xarController::redirect($cuurent_listview);
        }
        xarController::redirect(xarModURL('publications', 'admin', 'view', array('ptid' => $data['ptid'])));
    } else {
        xarController::redirect(xarModURL('publications', 'user', 'view', array('ptid' => $data['ptid'])));
    }
    return true;
}
Beispiel #12
0
/**
 * count the number of items per month
 * @param $args['cids'] not supported here (yet ?)
 * @param $args['ptid'] publication type ID we're interested in
 * @param $args['state'] array of requested status(es) for the publications
 * @return array array(month => count), or false on failure
 */
function publications_userapi_getmonthcount($args)
{
    // Get database setup
    $dbconn = xarDB::getConn();
    // Get the field names and LEFT JOIN ... ON ... parts from publications
    // By passing on the $args, we can let leftjoin() create the WHERE for
    // the publications-specific columns too now
    $publicationsdef = xarModAPIFunc('publications', 'user', 'leftjoin', $args);
    // Bug 1590 - Create custom query supported by each database.
    $dbtype = xarDB::getType();
    switch ($dbtype) {
        case 'mysql':
            $query = "SELECT LEFT(FROM_UNIXTIME(start_date),7) AS mymonth, COUNT(*) FROM " . $publicationsdef['table'];
            //            echo $query;exit;
            break;
        case 'postgres':
            $query = "SELECT TO_CHAR(ABSTIME(pubdate),'YYYY-MM') AS mymonth, COUNT(*) FROM " . $publicationsdef['table'];
            break;
        case 'mssql':
            $query = "SELECT LEFT(CONVERT(VARCHAR,DATEADD(ss,pubdate,'1/1/1970'),120),7) as mymonth, COUNT(*) FROM " . $publicationsdef['table'];
            break;
            // TODO:  Add SQL queries for Oracle, etc.
        // TODO:  Add SQL queries for Oracle, etc.
        default:
            return;
    }
    if (!empty($publicationsdef['where'])) {
        $query .= ' WHERE ' . $publicationsdef['where'];
    }
    switch ($dbtype) {
        case 'mssql':
            $query .= " GROUP BY LEFT(CONVERT(VARCHAR,DATEADD(ss,pubdate,'1/1/1970'),120),7)";
            break;
        default:
            $query .= ' GROUP BY mymonth';
            break;
    }
    $result =& $dbconn->Execute($query);
    if (!$result) {
        return;
    }
    $months = array();
    while (!$result->EOF) {
        list($month, $count) = $result->fields;
        $months[$month] = $count;
        $result->MoveNext();
    }
    return $months;
}
Beispiel #13
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;
}
Beispiel #14
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');
}
Beispiel #15
0
/**
 * utility function to pass item field definitions to whoever
 *
 * @param $args['itemtype'] item type (optional)
 * @return array Array containing the item field definitions
 */
function publications_userapi_getitemfields($args)
{
    extract($args);
    $itemfields = array();
    $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
    if (!empty($itemtype) && !empty($pubtypes[$itemtype])) {
        $fields = $pubtypes[$itemtype]['config'];
    } else {
        $fields = xarModAPIFunc('publications', 'user', 'getpubfields');
    }
    foreach ($fields as $name => $info) {
        if (empty($info['label'])) {
            continue;
        }
        $itemfields[$name] = array('name' => $name, 'label' => $info['label'], 'type' => $info['format']);
    }
    return $itemfields;
}
Beispiel #16
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;
 }
Beispiel #17
0
function publications_user_create()
{
    if (!xarVarFetch('ptid', 'id', $data['ptid'])) {
        return;
    }
    if (!xarVarFetch('new_cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('preview', 'str', $data['preview'], NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('save', 'str', $save, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Confirm authorisation code
    // This has been disabled for now
    //    if (!xarSecConfirmAuthKey()) return;
    $data['items'] = array();
    $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types'));
    $pubtypeobject->getItem(array('itemid' => $data['ptid']));
    $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value));
    $isvalid = $data['object']->checkInput();
    $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid']));
    if ($data['preview'] || $isvalid) {
        // Preview or bad data: redisplay the form
        $data['properties'] = $data['object']->getProperties();
        if ($data['preview']) {
            $data['tab'] = 'preview';
        }
        return xarTplModule('publications', 'user', 'new', $data);
    }
    // Create the object
    $id = $data['object']->createItem();
    // if we can edit publications, go to admin view, otherwise go to user view
    if (xarSecurityCheck('EditPublications', 0, 'Publication', $data['ptid'] . ':All:All:All')) {
        xarResponse::redirect(xarModURL('publications', 'admin', 'view', array('ptid' => $data['ptid'])));
    } else {
        xarResponse::redirect(xarModURL('publications', 'user', 'view', array('ptid' => $data['ptid'])));
    }
    return true;
}
Beispiel #18
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 #19
0
/**
 * count number of items depending on additional module criteria
 *
 * @param $args['catid'] string of category id(s) that we're counting in, or
 * @param $args['cids'] array of cids that we are counting in (OR/AND)
 * @param $args['andcids'] true means AND-ing categories listed in cids
 *
 * @param $args['owner'] the ID of the author
 * @param $args['ptid'] publication type ID (for news, sections, reviews, ...)
 * @param $args['state'] array of requested status(es) for the publications
 * @param $args['startdate'] publications published at startdate or later
 *                           (unix timestamp format)
 * @param $args['enddate'] publications published before enddate
 *                         (unix timestamp format)
 * @return int number of items
 */
function publications_userapi_countitems($args)
{
    // Database information
    $dbconn = xarDB::getConn();
    // Get the field names and LEFT JOIN ... ON ... parts from publications
    // By passing on the $args, we can let leftjoin() create the WHERE for
    // the publications-specific columns too now
    $publicationsdef = xarModAPIFunc('publications', 'user', 'leftjoin', $args);
    // TODO: make sure this is SQL standard
    // Start building the query
    if ($dbconn->databaseType == 'sqlite') {
        $query = 'SELECT COUNT(*)
                  FROM ( SELECT DISTINCT ' . $publicationsdef['field'] . '
                         FROM ' . $publicationsdef['table'];
        // WATCH OUT, UNBALANCED
    } else {
        $query = 'SELECT COUNT(DISTINCT ' . $publicationsdef['field'] . ')';
        $query .= ' FROM ' . $publicationsdef['table'];
    }
    if (!isset($args['cids'])) {
        $args['cids'] = array();
    }
    if (!isset($args['andcids'])) {
        $args['andcids'] = false;
    }
    if (count($args['cids']) > 0 || !empty($args['catid'])) {
        // Load API
        if (!xarModAPILoad('categories', 'user')) {
            return;
        }
        // Get the LEFT JOIN ... ON ...  and WHERE (!) parts from categories
        $args['modid'] = xarModGetIDFromName('publications');
        if (isset($args['ptid']) && !isset($args['itemtype'])) {
            $args['itemtype'] = $args['ptid'];
        }
        $categoriesdef = xarModAPIFunc('categories', 'user', 'leftjoin', $args);
        $query .= ' LEFT JOIN ' . $categoriesdef['table'];
        $query .= ' ON ' . $categoriesdef['field'] . ' = ' . $publicationsdef['id'];
        $query .= $categoriesdef['more'];
        $docid = 1;
    }
    // Create the WHERE part
    $where = array();
    // we rely on leftjoin() to create the necessary publications clauses now
    if (!empty($publicationsdef['where'])) {
        $where[] = $publicationsdef['where'];
    }
    if (!empty($docid)) {
        // we rely on leftjoin() to create the necessary categories clauses
        $where[] = $categoriesdef['where'];
    }
    if (count($where) > 0) {
        $query .= ' WHERE ' . join(' AND ', $where);
    }
    // Balance parentheses
    if ($dbconn->databaseType == 'sqlite') {
        $query .= ')';
    }
    // Run the query - finally :-)
    $result =& $dbconn->Execute($query);
    if (!$result) {
        return;
    }
    if ($result->EOF) {
        return;
    }
    $num = $result->fields[0];
    $result->Close();
    return $num;
}
Beispiel #20
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 #21
0
/**
 * get the number of publications per publication type and category
 *
 * @param $args['state'] array of requested status(es) for the publications
 * @param $args['ptid'] publication type ID
 * @param $args['cids'] array of category IDs (OR/AND)
 * @param $args['andcids'] true means AND-ing categories listed in cids
 * @param $args['groupcids'] the number of categories you want items grouped by
 * @param $args['reverse'] default is ptid => cid, reverse (1) is cid => ptid
 * @return array array( $ptid => array( $cid => $count) ),
 *         or false on failure
 */
function publications_userapi_getpubcatcount($args)
{
    /*
        static $pubcatcount = array();
    
        if (count($pubcatcount) > 0) {
            return $pubcatcount;
        }
    */
    $pubcatcount = array();
    // Get database setup
    $dbconn = xarDB::getConn();
    // Get the LEFT JOIN ... ON ...  and WHERE parts from publications
    $publicationsdef = xarModAPIFunc('publications', 'user', 'leftjoin', $args);
    // Load API
    if (!xarModAPILoad('categories', 'user')) {
        return;
    }
    $args['modid'] = xarMod::getRegID('publications');
    if (isset($args['ptid']) && !isset($args['itemtype'])) {
        $args['itemtype'] = $args['ptid'];
    }
    // Get the LEFT JOIN ... ON ...  and WHERE parts from categories
    $categoriesdef = xarModAPIFunc('categories', 'user', 'leftjoin', $args);
    // Get count
    $query = 'SELECT ' . $publicationsdef['pubtype_id'] . ', ' . $categoriesdef['category_id'] . ', COUNT(*)
            FROM ' . $publicationsdef['table'] . '
            LEFT JOIN ' . $categoriesdef['table'] . '
            ON ' . $categoriesdef['field'] . ' = ' . $publicationsdef['field'] . $categoriesdef['more'] . '
            WHERE ' . $categoriesdef['where'] . ' AND ' . $publicationsdef['where'] . '
            GROUP BY ' . $publicationsdef['pubtype_id'] . ', ' . $categoriesdef['category_id'];
    $result =& $dbconn->Execute($query);
    if (!$result) {
        return;
    }
    if ($result->EOF) {
        if (!empty($args['ptid']) && empty($args['reverse'])) {
            $pubcatcount[$args['ptid']] = array();
        }
        return $pubcatcount;
    }
    while (!$result->EOF) {
        // we may have 1 or more cid fields here, depending on what we're
        // counting (cfr. AND in categories)
        $fields = $result->fields;
        $ptid = array_shift($fields);
        $count = array_pop($fields);
        // TODO: use multi-level array for multi-category grouping ?
        $cid = join('+', $fields);
        if (empty($args['reverse'])) {
            $pubcatcount[$ptid][$cid] = $count;
        } else {
            $pubcatcount[$cid][$ptid] = $count;
        }
        $result->MoveNext();
    }
    foreach ($pubcatcount as $id1 => $val) {
        $total = 0;
        foreach ($val as $id2 => $count) {
            $total += $count;
        }
        $pubcatcount[$id1]['total'] = $total;
    }
    return $pubcatcount;
}
Beispiel #22
0
 public function display()
 {
     $vars = $this->getContent();
     // Trick : work with cached variables here (set by the module function)
     // Check if we've been through publications display
     if (!xarVarIsCached('Blocks.publications', 'current_id')) {
         return;
     }
     $links = 0;
     if ($vars['showpubtype']) {
         // Show publication type (for now)
         $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
         if (xarVarIsCached('Blocks.publications', 'ptid')) {
             $ptid = xarVarGetCached('Blocks.publications', 'ptid');
             if (!empty($ptid) && isset($pubtypes[$ptid]['description'])) {
                 $vars['pubtypelink'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid));
                 $vars['pubtypename'] = $pubtypes[$ptid]['description'];
                 $links++;
             }
         }
     }
     if ($vars['showcategory']) {
         // Show categories (for now)
         if (xarVarIsCached('Blocks.publications', 'cids')) {
             $cids = xarVarGetCached('Blocks.publications', 'cids');
             // TODO: add related links
         }
     }
     if ($vars['showauthor']) {
         // Show author (for now)
         if (xarVarIsCached('Blocks.publications', 'author')) {
             $author = xarVarGetCached('Blocks.publications', 'author');
             if (!empty($author)) {
                 $vars['authorlink'] = xarModURL('publications', 'user', 'view', array('ptid' => !empty($ptid) ? $ptid : null, 'owner' => $author));
                 $vars['authorid'] = $author;
                 if (!empty($vars['showvalue'])) {
                     $vars['authorcount'] = xarModAPIFunc('publications', 'user', 'countitems', array('ptid' => !empty($ptid) ? $ptid : null, 'owner' => $author, 'state' => array(2, 3), 'enddate' => time()));
                 }
                 $links++;
             }
         }
     }
     // Populate block info and pass to theme
     if ($links > 0) {
         return $vars;
     }
     return;
 }
Beispiel #23
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);
}
Beispiel #24
0
 public function encode(xarRequest $request)
 {
     if ($request->getType() == 'admin') {
         return parent::encode($request);
     }
     $params = $request->getFunctionArgs();
     $path = array();
     switch ($request->getFunction()) {
         case 'search':
             $path[] = 'search';
             $path = array_merge($path, $params);
             break;
         case 'view':
             $path[] = 'view';
             if (isset($params['ptid'])) {
                 if (xarModVars::get('publications', 'usetitleforurl')) {
                     // Get all publication types present
                     if (empty($this->pubtypes)) {
                         $this->pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
                     }
                     // Match to the function token
                     foreach ($this->pubtypes as $id => $pubtype) {
                         if ($params['ptid'] == $id) {
                             $path[] = strtolower($pubtype['description']);
                             break;
                         }
                     }
                 } else {
                     $path[] = $params['ptid'];
                 }
             }
             unset($params['ptid']);
             break;
         case 'viewmap':
             $path[] = 'viewmap';
             $params = array();
             break;
         case 'display':
             if (isset($params['itemid'])) {
                 sys::import('xaraya.structures.query');
                 xarModLoad('publications');
                 $xartables = xarDB::getTables();
                 $q = new Query('SELECT', $xartables['publications']);
                 $q->eq('id', $params['itemid']);
                 $q->addfield('pubtype_id');
                 $q->addfield('name');
                 $q->addfield('id');
                 $q->run();
                 $result = $q->row();
                 if (xarModVars::get('publications', 'usetitleforurl')) {
                     // Get all publication types present
                     if (empty($this->pubtypes)) {
                         $this->pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
                     }
                     if (!empty($result['pubtype_id'])) {
                         $path[] = strtolower($this->pubtypes[$result['pubtype_id']]['description']);
                     }
                     if (!empty($result['name'])) {
                         $path[] = strtolower($result['name']);
                     }
                 } else {
                     if (!empty($result['id'])) {
                         $path[] = $result['id'];
                     }
                 }
             }
             $params = array();
             break;
         case 'main':
             // We need a page ID to continue, for now.
             // TODO: allow this to be expanded to page names.
             if (empty($params['pid'])) {
                 return;
             }
             static $pages = NULL;
             // The components of the path.
             //    $get = $args;
             // Get the page tree that includes this page.
             // TODO: Do some kind of cacheing on a tree-by-tree basis to prevent
             // fetching this too many times. Every time any tree is fetched, anywhere
             // in this module, it should be added to the cache so it can be used again.
             // For now we are going to fetch all pages, without DD, to cut down on
             // the number of queries, although we are making an assumption that the
             // number of pages is not going to get too high.
             if (empty($pages)) {
                 // Fetch all pages, with no DD required.
                 $pages = xarMod::apiFunc('publications', 'user', 'getpages', array('dd_flag' => false, 'key' => 'pid'));
             }
             // Check that the pid is a valid page.
             if (!isset($pages[$params['pid']])) {
                 return;
             }
             $use_shortest_paths = xarModVars::get('publications', 'shortestpath');
             // Consume the pid from the get parameters.
             $pid = $params['pid'];
             unset($params['pid']);
             // 'Consume' the function now we know we have enough information.
             //                unset($params['func']);
             // Follow the tree up to the root.
             $pid_follow = $pid;
             while ($pages[$pid_follow]['parent_key'] != 0) {
                 // TODO: could do with an API to get all aliases for a given module in one go.
                 if (!empty($use_shortest_paths) && xarModGetAlias($pages[$pid_follow]['name']) == 'publications') {
                     break;
                 }
                 array_unshift($path, $pages[$pid_follow]['name']);
                 $pid_follow = $pages[$pid_follow]['parent_key'];
             }
             // Do the final path part.
             array_unshift($path, $pages[$pid_follow]['name']);
             // If the base path component is not the module alias, then add the
             // module name to the start of the path.
             if (xarModGetAlias($pages[$pid_follow]['name']) != 'publications') {
                 //                    array_unshift($path, 'publications');
             }
             // Now we have the basic path, we can check if there are any custom
             // URL handlers to handle the remainder of the GET parameters.
             // The handler is placed into the xarencodeapi API directory, and will
             // return two arrays: 'path' with path components and 'get' with
             // any unconsumed (or new) get parameters.
             if (!empty($pages[$pid]['encode_url'])) {
                 $extra = xarMod::apiFunc('publications', 'encode', $pages[$pid]['encode_url'], $get, false);
                 if (!empty($extra)) {
                     // The handler has supplied some further short URL path components.
                     if (!empty($extra['path'])) {
                         $path = array_merge($path, $extra['path']);
                     }
                     // Assume it has consumed some GET parameters too.
                     // Take what is left (i.e. unconsumed).
                     if (isset($extra['get']) && is_array($extra['get'])) {
                         $get = $extra['get'];
                     }
                 }
             }
             break;
         default:
             return;
             break;
     }
     // Encode the processed params
     $request->setFunction($this->getFunction($path));
     // Send the unprocessed params back
     $request->setFunctionArgs($params);
     return parent::encode($request);
 }
Beispiel #25
0
/**
* check security for a particular article
*
* @param $args['mask'] the requested security mask
*
* @param $args['article'] the article array (if already retrieved)
* @param $args['id'] the article ID (if known, and article array not
                      already retrieved)
* @param $args['owner'] the user ID of the author (if not already included)
* @param $args['ptid'] the publication type ID (if not already included)
* @param $args['cids'] array of additional required category checks
*
* @return bool true if OK, false if not OK
*/
function publications_userapi_checksecurity($args)
{
    // Get arguments from argument array
    extract($args);
    // Compatibility mode with old API params - remove later
    if (isset($access) && !isset($mask)) {
        switch ($access) {
            case ACCESS_OVERVIEW:
                $mask = 'ViewPublications';
                break;
            case ACCESS_READ:
                $mask = 'ReadPublications';
                break;
            case ACCESS_COMMENT:
                $mask = 'SubmitPublications';
                break;
            case ACCESS_EDIT:
                $mask = 'EditPublications';
                break;
            case ACCESS_DELETE:
                $mask = 'ManagePublications';
                break;
            case ACCESS_ADMIN:
                $mask = 'AdminPublications';
                break;
            default:
                $mask = '';
        }
    }
    if (empty($mask)) {
        return false;
    }
    // Get article information
    if (!isset($publication) && !empty($id) && $mask != 'SubmitPublications') {
        $publication = xarModAPIFunc('publications', 'user', 'get', array('id' => $id, 'withcids' => true));
        if ($publication == false) {
            return false;
        }
    }
    if (empty($id) && isset($publication['id'])) {
        $id = $publication['id'];
    }
    if (!isset($id)) {
        $id = '';
    }
    // Get author ID
    if (isset($publication['owner']) && empty($owner)) {
        $owner = $publication['owner'];
    }
    // Get state
    if (isset($publication['state']) && !isset($state)) {
        $state = $publication['state'];
    }
    if (empty($state)) {
        $state = 0;
    }
    // reject reading access to unapproved publications
    if ($state < 2 && ($mask == 'ViewPublications' || $mask == 'ReadPublications')) {
        return false;
    }
    // Get publication type ID
    if (isset($publication['pubtype_id'])) {
        if (!isset($ptid)) {
            $ptid = $publication['pubtype_id'];
        } elseif ($ptid != $publication['pubtype_id'] && $mask != 'EditPublications') {
            return false;
        }
    }
    // Get root categories for this publication type
    if (!empty($ptid)) {
        $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $ptid));
    } else {
        $ptid = null;
    }
    if (!isset($rootcids)) {
        // TODO: handle cross-pubtype views better
        $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications'));
    }
    // Get category information for this article
    if (!isset($publication['cids']) && !empty($id)) {
        if (!xarModAPILoad('categories', 'user')) {
            return;
        }
        $info = xarMod::getBaseInfo('publications');
        $sysid = $info['systemid'];
        $publicationcids = xarModAPIFunc('categories', 'user', 'getlinks', array('iids' => array($id), 'itemtype' => $ptid, 'modid' => $sysid, 'reverse' => 0));
        if (is_array($publicationcids) && count($publicationcids) > 0) {
            $publication['cids'] = array_keys($publicationcids);
        }
    }
    if (!isset($publication['cids'])) {
        $publication['cids'] = array();
    }
    if (!isset($cids)) {
        $cids = array();
    }
    $jointcids = array();
    /* TODO: forget about parent/root cids for now
        foreach ($rootcids as $cid) {
            $jointcids[$cid] = 1;
        }
    */
    foreach ($publication['cids'] as $cid) {
        $jointcids[$cid] = 1;
    }
    // FIXME: the line within the foreach is known to give an illegal offset error, not sure how to properly
    // fix it. Only seen on using xmlrpc and bloggerapi.
    foreach ($cids as $cid) {
        if (empty($cid) || !is_numeric($cid)) {
            continue;
        }
        $jointcids[$cid] = 1;
    }
    // TODO 1: find a way to combine checking over several categories
    // TODO 2: find a way to check parent categories for privileges too
    // TODO 3: find a way to specify current user in privileges too
    // TODO 4: find a way to check parent groups of authors for privileges too ??
    if (empty($ptid)) {
        $ptid = 'All';
    }
    if (count($jointcids) == 0) {
        $jointcids['All'] = 1;
    }
    // TODO: check for anonymous publications
    if (!isset($owner)) {
        $owner = 'All';
    }
    if (empty($id)) {
        $id = 'All';
    }
    // Loop over all categories and check the different combinations
    $result = false;
    foreach (array_keys($jointcids) as $cid) {
        // TODO: do we want all-or-nothing access here, or is one access enough ?
        if (xarSecurityCheck($mask, 0, 'Publication', "{$ptid}:{$cid}:{$owner}:{$id}")) {
            $result = true;
        }
    }
    return $result;
}
Beispiel #26
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;
 }
Beispiel #27
0
 public function modify()
 {
     $vars = $this->getContent();
     // Pub type drop-down list values.
     $vars['pubtypes'] = xarModAPIFunc('publications', 'user', 'get_pubtypes');
     // Categories drop-down list values.
     $vars['categorylist'] = xarModAPIFunc('categories', 'user', 'getcat');
     // Defaults.
     if (empty($vars['ptid'])) {
         $vars['ptid'] = 0;
     }
     if (empty($vars['cid'])) {
         $vars['cid'] = 0;
     }
     if (empty($vars['paramname'])) {
         $vars['paramname'] = 'glossaryterm';
     }
     $vars['bid'] = $this->block_id;
     // Return output
     return $vars;
 }
Beispiel #28
0
/**
 * view article map
 */
function publications_user_viewmap($args)
{
    // Get parameters
    if (!xarVarFetch('ptid', 'id', $ptid, xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('by', 'enum:pub:cat:grid', $by, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('go', 'str', $go, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('catid', 'str', $catid, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('cids', 'array', $cids, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Override if needed from argument array
    extract($args);
    $default = xarModVars::get('publications', 'defaultpubtype');
    if (empty($by)) {
        if (empty($default) && empty($ptid)) {
            $by = 'cat';
        } else {
            $by = 'pub';
        }
    }
    // 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();
    if (isset($cids) && is_array($cids)) {
        foreach ($cids as $cid) {
            // make sure cids are numeric
            if (!empty($cid) && is_numeric($cid)) {
                $seencid[$cid] = 1;
            }
        }
        $cids = array_keys($seencid);
        sort($cids, SORT_NUMERIC);
    }
    // Get publication types
    sys::import('modules.dynamicdata.class.objects.master');
    $object = DataObjectMaster::getObjectList(array('name' => 'publications_types'));
    $data['pubtypes'] = $object->getItems();
    // redirect to filtered view
    if (!empty($go) && (!empty($ptid) || $by == 'cat')) {
        if (is_array($cids) && count($cids) > 0) {
            $catid = join('+', $cids);
        } else {
            $catid = NULL;
        }
        $url = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $catid));
        xarController::redirect($url);
        return;
    }
    $data['catfilter'] = array();
    $data['cattree'] = array();
    $data['catgrid'] = array();
    $dump = '';
    $publinks = array();
    if ($by == 'cat') {
        $data['maplink'] = xarModURL('publications', 'user', 'viewmap', array('by' => 'cat'));
        // TODO: re-evaluate this after user feedback...
        // *trick* Use the 'default' categories here, instead of all rootcats
        $basecats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications'));
        $catlist = array();
        foreach ($basecats as $basecat) {
            $catlist[$basecat['category_id']] = 1;
        }
        $data['basecids'] = array_keys($catlist);
        // create the category tree for each root category
        // TODO: make sure permissions are taken into account here !
        foreach ($catlist as $cid => $val) {
            if (empty($val)) {
                continue;
            }
            $data['cattree'][$cid] = xarModAPIFunc('publications', 'user', 'getchildcats', array('state' => array(PUBLICATIONS_STATE_APPROVED, PUBLICATIONS_STATE_FRONTPAGE), 'cid' => $cid, 'ptid' => null, 'showcid' => true));
        }
    } elseif ($by == 'grid') {
        $data['catgrid'][0] = array();
        $data['catgrid'][0][0] = '';
        // Get the base categories
        if (!empty($ptid)) {
            $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => $ptid));
        } else {
            $rootcats = xarModAPIFunc('categories', 'user', 'getallcatbases', array('module' => 'publications', 'itemtype' => 0));
            $ptid = null;
        }
        if (count($rootcats) != 2) {
            $data['catgrid'][0][0] = xarML('You need 2 base categories in order to use this grid view');
        } else {
            $catlist = array();
            if (!empty($rootcats) && is_array($rootcats)) {
                foreach ($rootcats as $cid) {
                    $catlist[$catid['category_id']] = 1;
                }
            }
            $cattree = array();
            // Get the category tree for each base category
            foreach ($catlist as $cid => $val) {
                if (empty($val)) {
                    continue;
                }
                $cattree[$cid] = xarModAPIFunc('publications', 'user', 'getchildcats', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'cid' => $cid, 'ptid' => $ptid, 'showcid' => true));
            }
            // Find out which category tree is the shortest
            if (count($cattree[$rootcats[0]]) > count($cattree[$rootcats[1]])) {
                $rowcat = $rootcats[0];
                $colcat = $rootcats[1];
            } else {
                $rowcat = $rootcats[1];
                $colcat = $rootcats[0];
            }
            // Fill in the column headers
            $row = 0;
            $col = 1;
            $colcid = array();
            foreach ($cattree[$colcat] as $info) {
                $data['catgrid'][$row][$col] = '<a href="' . $info['link'] . '">' . $info['name'] . '</a>';
                $colcid[$info['id']] = $col;
                $col++;
            }
            $maxcol = $col;
            // Fill in the row headers
            $row = 1;
            $col = 0;
            $data['catgrid'][$row] = array();
            $rowcid = array();
            foreach ($cattree[$rowcat] as $info) {
                $data['catgrid'][$row][$col] = '<a href="' . $info['link'] . '">' . $info['name'] . '</a>';
                $rowcid[$info['id']] = $row;
                $row++;
            }
            $maxrow = $row;
            // Initialise the rest of the array
            for ($row = 1; $row < $maxrow; $row++) {
                if (!isset($data['catgrid'][$row])) {
                    $data['catgrid'][$row] = array();
                }
                for ($col = 1; $col < $maxcol; $col++) {
                    $data['catgrid'][$row][$col] = '';
                }
            }
            // Get the counts for all groups of (N) categories
            $pubcatcount = xarModAPIFunc('publications', 'user', 'getpubcatcount', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'ptid' => $ptid, 'groupcids' => 2, 'reverse' => 1));
            if (!empty($ptid)) {
                $what = $ptid;
            } else {
                $what = 'total';
            }
            // Fill in the count values
            foreach ($pubcatcount as $cids => $counts) {
                list($ca, $cb) = explode('+', $cids);
                if (isset($rowcid[$ca]) && isset($colcid[$cb])) {
                    $link = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $ca . '+' . $cb));
                    $data['catgrid'][$rowcid[$ca]][$colcid[$cb]] = '<a href="' . $link . '"> ' . $counts[$what] . ' </a>';
                }
                if (isset($rowcid[$cb]) && isset($colcid[$ca])) {
                    $link = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $cb . '+' . $ca));
                    $data['catgrid'][$rowcid[$cb]][$colcid[$ca]] = '<a href="' . $link . '"> ' . $counts[$what] . ' </a>';
                }
            }
        }
        if (!empty($ptid)) {
            $descr = $data['pubtypes'][$ptid]['description'];
        }
    } else {
        $data['maplink'] = xarModURL('publications', 'user', 'viewmap', array('by' => 'pub'));
        // get the links and counts for all publication types
        $publinks = xarModAPIFunc('publications', 'user', 'getpublinks', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'all' => 1));
        // build the list of root categories for all publication types
        // and save results in publinks as well
        $catlist = array();
        for ($i = 0; $i < count($publinks); $i++) {
            $pubid = $publinks[$i]['pubid'];
            $cidstring = xarModVars::get('publications', 'mastercids.' . $pubid);
            if (!empty($cidstring)) {
                $rootcats = explode(';', $cidstring);
                foreach ($rootcats as $cid) {
                    $catlist[$cid] = 1;
                }
                $publinks[$i]['rootcats'] = $rootcats;
            } else {
                $publinks[$i]['rootcats'] = array();
            }
        }
        // for all publication types
        for ($i = 0; $i < count($publinks); $i++) {
            $publinks[$i]['cats'] = array();
            $pubid = $publinks[$i]['pubid'];
            // for each root category of this publication type
            foreach ($publinks[$i]['rootcats'] as $cid) {
                // add the category tree to the list of categories to show
                $childcats = xarModAPIFunc('publications', 'user', 'getchildcats', array('state' => array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED), 'cid' => $cid, 'ptid' => $pubid, 'showcid' => true));
                $publinks[$i]['cats'][] = $childcats;
            }
        }
        $array = array();
        if (empty($ptid)) {
            $ptid = $default;
        }
        if (!empty($ptid)) {
            for ($i = 0; $i < count($publinks); $i++) {
                if ($ptid == $publinks[$i]['pubid']) {
                    $array = $publinks[$i]['rootcats'];
                }
            }
        }
        foreach ($publinks as $pub) {
            if ($pub['pubid'] == $ptid) {
                $descr = $pub['pubtitle'];
            }
        }
    }
    if (empty($descr)) {
        $descr = xarML('Publications');
        $data['descr'] = '';
    } else {
        $data['descr'] = $descr;
    }
    // Save some variables to (temporary) cache for use in blocks etc.
    xarVarSetCached('Blocks.publications', 'ptid', $ptid);
    //if ($shownavigation) {
    xarVarSetCached('Blocks.categories', 'module', 'publications');
    xarVarSetCached('Blocks.categories', 'itemtype', $ptid);
    if (!empty($descr)) {
        xarVarSetCached('Blocks.categories', 'title', $descr);
        xarTplSetPageTitle(xarML('Map'), xarVarPrepForDisplay($descr));
    }
    //}
    if (empty($ptid)) {
        $ptid = null;
    }
    $data['publinks'] = $publinks;
    $data['ptid'] = $ptid;
    $data['viewlabel'] = xarML('Back to') . ' ' . $descr;
    $data['viewlink'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid));
    $data['archivelabel'] = xarML('View Archives');
    $data['archivelink'] = xarModURL('publications', 'user', 'archive', array('ptid' => $ptid));
    $data['dump'] = $dump;
    if (count($data['catfilter']) == 2) {
    }
    if (!empty($ptid)) {
        $object = DataObjectMaster::getObject(array('name' => 'publications_types'));
        $object->getItem(array('itemid' => $ptid));
        $template = $object->properties['template']->value;
    } else {
        // TODO: allow templates per category ?
        $template = null;
    }
    // Pass the type of map to the template, so we can decide what links to show
    $data['by'] = $by;
    return xarTplModule('publications', 'user', 'viewmap', $data, $template);
}
Beispiel #29
0
function publications_admin_updateconfig()
{
    // Confirm authorisation code
    if (!xarSecConfirmAuthKey()) {
        return;
    }
    // Get parameters
    //A lot of these probably are bools, still might there be a need to change the template to return
    //'true' and 'false' to use those...
    if (!xarVarFetch('settings', 'array', $settings, array(), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('usetitleforurl', 'int', $usetitleforurl, xarModVars::get('publications', 'usetitleforurl'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('defaultstate', 'isset', $defaultstate, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('defaultsort', 'isset', $defaultsort, 'date', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('usealias', 'int', $usealias, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('ptid', 'isset', $ptid, xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('multilanguage', 'int', $multilanguage, 0, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('tab', 'str:1:10', $data['tab'], 'global', XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarSecurityCheck('AdminPublications', 1, 'Publication', "{$ptid}:All:All:All")) {
        return;
    }
    if ($data['tab'] == 'global') {
        if (!xarVarFetch('defaultpubtype', 'isset', $defaultpubtype, 1, XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('sortpubtypes', 'isset', $sortpubtypes, 'id', XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('defaultlanguage', 'str:1:100', $defaultlanguage, xarModVars::get('publications', 'defaultlanguage'), XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('debugmode', 'checkbox', $debugmode, xarModVars::get('publications', 'debugmode'), XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('defaultfrontpage', 'str', $defaultfrontpage, xarModVars::get('publications', 'defaultfrontpage'), XARVAR_NOT_REQUIRED)) {
            return;
        }
        if (!xarVarFetch('defaultbackpage', 'str', $defaultbackpage, xarModVars::get('publications', 'defaultbackpage'), XARVAR_NOT_REQUIRED)) {
            return;
        }
        xarModVars::set('publications', 'defaultpubtype', $defaultpubtype);
        xarModVars::set('publications', 'sortpubtypes', $sortpubtypes);
        xarModVars::set('publications', 'defaultlanguage', $defaultlanguage);
        xarModVars::set('publications', 'debugmode', $debugmode);
        xarModVars::set('publications', 'usealias', $usealias);
        xarModVars::set('publications', 'usetitleforurl', $usetitleforurl);
        xarModVars::set('publications', 'defaultfrontpage', $defaultfrontpage);
        xarModVars::set('publications', 'defaultbackpage', $defaultbackpage);
        // Allow multilanguage only if the languages property is present
        sys::import('modules.dynamicdata.class.properties.registration');
        $types = PropertyRegistration::Retrieve();
        if (isset($types[30039])) {
            xarModVars::set('publications', 'multilanguage', $multilanguage);
        } else {
            xarModVars::set('publications', 'multilanguage', 0);
        }
        // Get the special pages.
        foreach (array('defaultpage', 'errorpage', 'notfoundpage', 'noprivspage') as $special_name) {
            unset($special_id);
            if (!xarVarFetch($special_name, 'id', $special_id, 0, XARVAR_NOT_REQUIRED)) {
                return;
            }
            xarModVars::set('publications', $special_name, $special_id);
        }
        if (xarDB::getType() == 'mysql') {
            if (!xarVarFetch('fulltext', 'isset', $fulltext, '', XARVAR_NOT_REQUIRED)) {
                return;
            }
            $oldval = xarModVars::get('publications', 'fulltextsearch');
            $index = 'i_' . xarDB::getPrefix() . '_publications_fulltext';
            if (empty($fulltext) && !empty($oldval)) {
                // Get database setup
                $dbconn = xarDB::getConn();
                $xartable = xarDB::getTables();
                $publicationstable = $xartable['publications'];
                // Drop fulltext index on publications table
                $query = "ALTER TABLE {$publicationstable} DROP INDEX {$index}";
                $result =& $dbconn->Execute($query);
                if (!$result) {
                    return;
                }
                xarModVars::set('publications', 'fulltextsearch', '');
            } elseif (!empty($fulltext) && empty($oldval)) {
                $searchfields = array('title', 'description', 'summary', 'body1', 'notes');
                //                $searchfields = explode(',',$fulltext);
                // Get database setup
                $dbconn = xarDB::getConn();
                $xartable = xarDB::getTables();
                $publicationstable = $xartable['publications'];
                // Add fulltext index on publications table
                $query = "ALTER TABLE {$publicationstable} ADD FULLTEXT {$index} (" . join(', ', $searchfields) . ")";
                $result =& $dbconn->Execute($query);
                if (!$result) {
                    return;
                }
                xarModVars::set('publications', 'fulltextsearch', join(',', $searchfields));
            }
        }
        // Module settings
        $data['module_settings'] = xarMod::apiFunc('base', 'admin', 'getmodulesettings', array('module' => 'publications'));
        $data['module_settings']->setFieldList('items_per_page, use_module_alias, module_alias_name, enable_short_urls, user_menu_link', 'use_module_icons');
        $isvalid = $data['module_settings']->checkInput();
        if (!$isvalid) {
            return xarTplModule('base', 'admin', 'modifyconfig', $data);
        } else {
            $itemid = $data['module_settings']->updateItem();
        }
        // Pull the base category ids from the template and save them
        $picker = DataPropertyMaster::getProperty(array('name' => 'categorypicker'));
        $picker->checkInput('basecid');
    } elseif ($data['tab'] == 'pubtypes') {
        // Get the publication type for this display and save the settings to it
        $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types'));
        $pubtypeobject->getItem(array('itemid' => $ptid));
        $configsettings = $pubtypeobject->properties['configuration']->getValue();
        $checkbox = DataPropertyMaster::getProperty(array('name' => 'checkbox'));
        $boxes = array('show_hitount', 'show_ratings', 'show_keywords', 'show_comments', 'show_prevnext', 'show_archives', 'show_publinks', 'show_pubcount', 'show_map', 'prevnextart', 'dot_transform', 'title_transform', 'show_categories', 'show_catcount', 'show_prevnext', 'allow_translations');
        foreach ($boxes as $box) {
            $isvalid = $checkbox->checkInput($box);
            if ($isvalid) {
                $settings[$box] = $checkbox->value;
            }
        }
        //        foreach ($configsettings as $key => $value)
        //            if (!isset($settings[$key])) $settings[$key] = 0;
        $isvalid = true;
        // Get the default access rules
        $access = DataPropertyMaster::getProperty(array('name' => 'access'));
        $validprop = $access->checkInput("access_add");
        $addaccess = $access->value;
        $isvalid = $isvalid && $validprop;
        $validprop = $access->checkInput("access_display");
        $displayaccess = $access->value;
        $isvalid = $isvalid && $validprop;
        $validprop = $access->checkInput("access_modify");
        $modifyaccess = $access->value;
        $isvalid = $isvalid && $validprop;
        $validprop = $access->checkInput("access_delete");
        $deleteaccess = $access->value;
        $isvalid = $isvalid && $validprop;
        $allaccess = array('add' => $addaccess, 'display' => $displayaccess, 'modify' => $modifyaccess, 'delete' => $deleteaccess);
        $pubtypeobject->properties['access']->setValue(serialize($allaccess));
        $pubtypeobject->properties['configuration']->setValue(serialize($settings));
        $pubtypeobject->updateItem(array('itemid' => $ptid));
        $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
        if ($usealias) {
            xarModSetAlias($pubtypes[$ptid]['name'], 'publications');
        } else {
            xarModDelAlias($pubtypes[$ptid]['name'], 'publications');
        }
    } elseif ($data['tab'] == 'redirects') {
        $redirects = DataPropertyMaster::getProperty(array('name' => 'array'));
        $redirects->display_column_definition['value'] = array(array("From", "To"), array(2, 2), array("", ""), array("", ""));
        $isvalid = $redirects->checkInput("redirects");
        xarModVars::set('publications', 'redirects', $redirects->value);
    }
    xarController::redirect(xarModURL('publications', 'admin', 'modifyconfig', array('ptid' => $ptid, 'tab' => $data['tab'])));
    return true;
}
Beispiel #30
0
/**
 * get an array of root categories with links
 *
 * @param int $args['ptid'] publication type ID
 * @param $args['all'] boolean if we need to return all root categories when
 *                     ptid is empty (default false)
 * @return array
 * @TODO specify return format
 */
function publications_userapi_getrootcats($args)
{
    extract($args);
    if (empty($ptid) || !is_numeric($ptid)) {
        $ptid = null;
    }
    // see which root categories we need to handle
    $rootcats = array();
    if (!empty($ptid)) {
        $rootcats = unserialize(xarModUserVars::get('publications', 'basecids', $ptid));
    } elseif (empty($all)) {
        $rootcats = unserialize(xarModVars::get('publications', 'basecids'));
    } else {
        // Get publication types
        $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
        // get base categories for all publication types here
        $publist = array_keys($pubtypes);
        // add the defaults too, in case we have other base categories there
        $publist[] = '';
        // build the list of root categories for all required publication types
        $catlist = array();
        foreach ($publist as $pubid) {
            if (empty($pubid)) {
                $cidstring = xarModVars::get('publications', 'basecids');
            } else {
                $cidstring = xarModUserVars::get('publications', 'basecids', $pubid);
            }
            if (!empty($cidstring)) {
                $rootcats = unserialize($cidstring);
            } else {
                $rootcats = array();
            }
            foreach ($rootcats as $cid) {
                $catlist[$cid] = 1;
            }
        }
        if (count($catlist) > 0) {
            $rootcats = array_keys($catlist);
        }
    }
    if (empty($rootcats)) {
        $rootcats = array();
    }
    if (count($rootcats) < 1) {
        return array();
    }
    if (!xarModAPILoad('categories', 'user')) {
        return;
    }
    $isfirst = 1;
    $catlinks = array();
    $catlist = xarModAPIFunc('categories', 'user', 'getcatinfo', array('cids' => $rootcats));
    if (empty($catlist)) {
        return $catlinks;
    }
    // preserve order of root categories if possible
    foreach ($rootcats as $cid) {
        if (!isset($catlist[$cid])) {
            continue;
        }
        $info = $catlist[$cid];
        $item = array();
        $item['catid'] = $info['cid'];
        $item['cattitle'] = xarVarPrepForDisplay($info['name']);
        $item['catlink'] = xarModURL('publications', 'user', 'view', array('ptid' => $ptid, 'catid' => $info['cid']));
        if ($isfirst) {
            $item['catjoin'] = '';
            $isfirst = 0;
        } else {
            $item['catjoin'] = ' | ';
        }
        $item['catleft'] = $info['left'];
        $item['catright'] = $info['right'];
        $catlinks[] = $item;
    }
    return $catlinks;
}