Exemple #1
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;
}
Exemple #2
0
/**
 *  Get products
 */
function shop_userapi_getproducts($args)
{
    $startnum = 1;
    extract($args);
    if (!xarSecurityCheck('ViewShop')) {
        return;
    }
    if (!isset($items_per_page)) {
        $items_per_page = xarModVars::get('shop', 'items_per_page');
    }
    $data['items_per_page'] = $items_per_page;
    // Load the DD master object class. This line will likely disappear in future versions
    sys::import('modules.dynamicdata.class.objects.master');
    sys::import('modules.dynamicdata.class.properties.master');
    // Get the object we'll be working with. Note this is a so called object list
    $mylist = DataObjectMaster::getObjectList(array('name' => 'shop_products'));
    $data['sort'] = xarMod::ApiFunc('shop', 'admin', 'sort', array('sortfield_fallback' => 'id', 'ascdesc_fallback' => 'ASC'));
    // We have some filters for the items
    $filters = array('startnum' => $startnum, 'status' => DataPropertyMaster::DD_DISPLAYSTATE_ACTIVE, 'sort' => $data['sort']);
    if (isset($where)) {
        $filters['where'] = $where;
    }
    // Get the items
    $products = $mylist->getItems($filters);
    // return the products
    $data['products'] = $products;
    // Return the template variables defined in this function
    return $data;
}
Exemple #3
0
/**
 * View items of the wurfl object
 *
 */
function wurfl_admin_view($args)
{
    if (!xarSecurityCheck('ManageWurfl')) {
        return;
    }
    $modulename = 'wurfl';
    // Define which object will be shown
    if (!xarVarFetch('objectname', 'str', $objectname, null, XARVAR_DONT_SET)) {
        return;
    }
    if (!empty($objectname)) {
        xarModUserVars::set($modulename, 'defaultmastertable', $objectname);
    }
    // Set a return url
    xarSession::setVar('ddcontext.' . $modulename, array('return_url' => xarServer::getCurrentURL()));
    // Get the available dropdown options
    $object = DataObjectMaster::getObjectList(array('objectid' => 1));
    $data['objectname'] = xarModUserVars::get($modulename, 'defaultmastertable');
    $items = $object->getItems();
    $options = array();
    foreach ($items as $item) {
        if (strpos($item['name'], $modulename) !== false) {
            $options[] = array('id' => $item['name'], 'name' => $item['name']);
        }
    }
    $data['options'] = $options;
    return $data;
}
Exemple #4
0
/**
 *  List the product attributes 
 */
function shop_admin_attributes()
{
    if (!xarVarFetch('startnum', 'isset', $data['startnum'], NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('user_id', 'isset', $user_id, NULL, XARVAR_DONT_SET)) {
        return;
    }
    $objectname = 'shop_attributes';
    $data['objectname'] = $objectname;
    // Security check - important to do this as early as possible to avoid
    // potential security holes or just too much wasted processing
    if (!xarSecurityCheck('AdminShop')) {
        return;
    }
    $data['items_per_page'] = xarModVars::get('shop', 'items_per_page');
    // Load the DD master object class. This line will likely disappear in future versions
    sys::import('modules.dynamicdata.class.objects.master');
    // Get the object label for the template
    $object = DataObjectMaster::getObject(array('name' => $objectname));
    $data['label'] = $object->label;
    // Get the fields to display in the admin interface
    $config = $object->configuration;
    if (!empty($config['adminfields'])) {
        $data['adminfields'] = $config['adminfields'];
    } else {
        $data['adminfields'] = array_keys($object->getProperties());
    }
    // Get the object we'll be working with. Note this is a so called object list
    $mylist = DataObjectMaster::getObjectList(array('name' => $objectname));
    // Load the DD master property class. This line will likely disappear in future versions
    sys::import('modules.dynamicdata.class.properties.master');
    $data['sort'] = xarMod::ApiFunc('shop', 'admin', 'sort', array('sortfield_fallback' => 'ID', 'ascdesc_fallback' => 'ASC'));
    // We have some filters for the items
    $filters = array('startnum' => $data['startnum'], 'status' => DataPropertyMaster::DD_DISPLAYSTATE_ACTIVE, 'sort' => $data['sort']);
    if (isset($user_id)) {
        $filters['where'] = 'user_id eq ' . $user_id;
    }
    // Get the items
    $items = $mylist->getItems($filters);
    if (isset($user_id)) {
        // Get the object we'll be working with. Note this is a so called object list
        $mylist2 = DataObjectMaster::getObjectList(array('name' => 'shop_customers'));
        $filters = array();
        if (isset($user_id)) {
            $filters['where'] = 'ID eq ' . $user_id;
        }
        $items2 = $mylist2->getItems($filters);
        $data['fname'] = $items2[$user_id]['FirstName'];
        $data['lname'] = $items2[$user_id]['LastName'];
    }
    $data['mylist'] = $mylist;
    // Return the template variables defined in this function
    return $data;
}
Exemple #5
0
/**
 *  Get all product attributes
 */
function shop_adminapi_getattributes()
{
    $objectname = 'shop_attributes';
    sys::import('modules.dynamicdata.class.objects.master');
    // Get the object we'll be working with. Note this is a so called object list
    $mylist = DataObjectMaster::getObjectList(array('name' => $objectname));
    // We have some filters for the items
    $filters = array('status' => DataPropertyMaster::DD_DISPLAYSTATE_ACTIVE);
    // Get the items
    $items = $mylist->getItems($filters);
    foreach ($items as $item) {
        $id = $item['id'];
        $array[$id] = $item['name'] . ' (ID: ' . $item['id'] . ')';
    }
    return $array;
}
/**
 *  Get just one set of attributes
 */
function shop_adminapi_getproductattributes($args)
{
    extract($args);
    $objectname = 'shop_attributes';
    sys::import('modules.dynamicdata.class.objects.master');
    // Get the object we'll be working with. Note this is a so called object list
    $mylist = DataObjectMaster::getObjectList(array('name' => $objectname));
    // We have some filters for the items
    $filters = array('status' => DataPropertyMaster::DD_DISPLAYSTATE_ACTIVE);
    $filters['where'] = 'id eq ' . $id;
    // Get the items
    $items = $mylist->getItems($filters);
    foreach ($items as $item) {
        $attributes = $item['options'];
    }
    return $attributes;
}
/**
 *  Get just one set of attributes
 */
function shop_adminapi_getattributeoptions($args)
{
    extract($args);
    $objectname = 'shop_attributes';
    sys::import('modules.dynamicdata.class.objects.master');
    // Get the object we'll be working with. Note this is a so called object list
    $mylist = DataObjectMaster::getObjectList(array('name' => $objectname));
    // We have some filters for the items
    $filters = array('status' => DataPropertyMaster::DD_DISPLAYSTATE_ACTIVE);
    $filters['where'] = 'id eq ' . $id;
    // Get the items
    $items = $mylist->getItems($filters);
    foreach ($items as $item) {
        $options = $item['options'];
    }
    $options = unserialize($options);
    if (isset($firstline)) {
        $array[] = $firstline;
    }
    foreach ($options as $key => $value) {
        $array[$value] = $key . $separator . $value;
    }
    return $array;
}
Exemple #8
0
/**
 *  Select existing payment method or create new one to use for this transaction
 */
function shop_user_paymentmethod()
{
    // Redirects at the start of the user functions are just a way to make sure someone isn't where they don't need to be
    $shippingaddress = xarSession::getVar('shippingaddress');
    if (empty($shippingaddress)) {
        xarResponse::redirect(xarModURL('shop', 'user', 'shippingaddress'));
        return true;
    }
    $shop = xarSession::getVar('shop');
    if (!xarUserIsLoggedIn() || empty($shop)) {
        xarResponse::redirect(xarModURL('shop', 'user', 'main'));
        return true;
    }
    if (!xarVarFetch('proceedsaved', 'str', $proceedsaved, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('proceednew', 'str', $proceednew, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('paymentmethod', 'str', $paymentmethod, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('remove', 'str', $remove, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    $cust = xarMod::APIFunc('shop', 'user', 'customerinfo');
    $data['cust'] = $cust;
    sys::import('modules.dynamicdata.class.objects.master');
    sys::import('modules.dynamicdata.class.properties.master');
    $shippingobject = DataObjectMaster::getObject(array('name' => 'shop_shippingaddresses'));
    $shippingobject->getItem(array('itemid' => xarSession::getVar('shippingaddress')));
    $shippingvals = $shippingobject->getFieldValues();
    $data['shippingvals'] = $shippingvals;
    // Get the saved payment methods, if any exist
    $mylist = DataObjectMaster::getObjectList(array('name' => 'shop_paymentmethods'));
    $filters = array('status' => DataPropertyMaster::DD_DISPLAYSTATE_ACTIVE, 'where' => 'customer eq ' . xarUserGetVar('id'));
    $paymentmethods = $mylist->getItems($filters);
    $data['paymentmethods'] = $paymentmethods;
    $data['paymentobject'] = DataObjectMaster::getObject(array('name' => 'shop_paymentmethods'));
    $data['paymentobject']->properties['name']->display_show_salutation = false;
    $data['paymentobject']->properties['name']->display_show_middlename = false;
    $data['paymentobject']->properties['address']->display_rows = 1;
    $data['paymentobject']->properties['address']->display_show_country = false;
    $data['properties'] = $data['paymentobject']->getProperties();
    if ($remove) {
        if ($remove == xarSession::getVar('paymentmethod')) {
            xarSession::delVar('paymentmethod');
        }
        $data['paymentobject']->getItem(array('itemid' => $remove));
        $data['paymentobject']->deleteItem();
        xarResponse::redirect(xarModURL('shop', 'user', 'paymentmethod'));
        return true;
    }
    $selectedpaymentmethod = xarSession::getVar('paymentmethod');
    if (!empty($selectedpaymentmethod)) {
        $data['paymentmethod'] = $selectedpaymentmethod;
    }
    // If we're using a saved payment method...
    if ($proceedsaved) {
        xarSession::setVar('paymentmethod', $paymentmethod);
        xarResponse::redirect(xarModURL('shop', 'user', 'order'));
        return true;
    } elseif ($proceednew) {
        // We're not using a saved payment method...
        $isvalid = $data['paymentobject']->checkInput();
        if (isset($exp_date)) {
            $exp_month = substr($exp_date, 0, 2);
            $exp_year = substr($exp_date, 2, 4);
            $reverse_date = $exp_year . $exp_month;
            $minimum_date = date('ym', time());
            if ($minimum_date > $reverse_date) {
                $errors['exp_date'] = true;
            }
        }
        if (isset($errors)) {
            xarSession::setVar('errors', $errors);
        }
        if (!$isvalid) {
            return xarTplModule('shop', 'user', 'paymentmethod', $data);
        } else {
            xarSession::setVar('paymentmethod', $data['paymentobject']->createItem());
            xarResponse::redirect(xarModURL('shop', 'user', 'order'));
            return true;
        }
    }
    return $data;
}
Exemple #9
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);
}
Exemple #10
0
function publications_user_view($args)
{
    // Get parameters
    if (!xarVarFetch('ptid', 'id', $ptid, xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('startnum', 'int:0', $startnum, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    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;
    }
    if (!xarVarFetch('itemtype', 'id', $itemtype, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // TODO: put the query string through a proper parser, so searches on multiple words can be done.
    if (!xarVarFetch('q', 'pre:trim:passthru:str:1:200', $q, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // can't use list enum here, because we don't know which sorts might be used
    // True - but we can provide some form of validation and normalisation.
    // The original 'regexp:/^[\w,]*$/' lets through *any* non-space character.
    // This validation will accept a list of comma-separated words, and will lower-case, trim
    // and strip out non-alphanumeric characters from each word.
    if (!xarVarFetch('sort', 'strlist:,:pre:trim:lower:alnum', $sort, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('numcols', 'int:0', $numcols, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('owner', 'id', $owner, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    if (!xarVarFetch('pubdate', 'str:1', $pubdate, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // This may not be set via user input, only e.g. via template tags, API calls, blocks etc.
    //    if(!xarVarFetch('startdate','int:0', $startdate, NULL, XARVAR_NOT_REQUIRED)) {return;}
    //    if(!xarVarFetch('enddate',  'int:0', $enddate,   NULL, XARVAR_NOT_REQUIRED)) {return;}
    //    if(!xarVarFetch('where',    'str',   $where,     NULL, XARVAR_NOT_REQUIRED)) {return;}
    // Added to impliment an Alpha Pager
    if (!xarVarFetch('letter', 'pre:lower:passthru:str:1:20', $letter, NULL, XARVAR_NOT_REQUIRED)) {
        return;
    }
    // Override if needed from argument array (e.g. ptid, numitems etc.)
    extract($args);
    $pubtypes = xarModAPIFunc('publications', 'user', 'get_pubtypes');
    // We need a valid pubtype number here
    if (!is_numeric($ptid) || !isset($pubtypes[$ptid])) {
        return xarResponse::NotFound();
    }
    // Constants used throughout.
    //
    // publications module ID
    $c_modid = xarMod::getID('publications');
    // state: front page or approved
    $c_posted = array(PUBLICATIONS_STATE_FRONTPAGE, PUBLICATIONS_STATE_APPROVED);
    // Default parameters
    if (!isset($startnum)) {
        $startnum = 1;
    }
    // Check if we want the default 'front page'
    if (!isset($catid) && !isset($cids) && empty($ptid) && !isset($owner)) {
        $ishome = true;
        // default publication type
        $ptid = xarModVars::get('publications', 'defaultpubtype');
        // frontpage state
        $state = array(PUBLICATIONS_STATE_FRONTPAGE);
    } else {
        $ishome = false;
        // frontpage or approved state
        $state = $c_posted;
    }
    // Get the publication type for this display
    $data['pubtypeobject'] = DataObjectMaster::getObject(array('name' => 'publications_types'));
    $data['pubtypeobject']->getItem(array('itemid' => $ptid));
    // Get the settings of this publication type
    $data['settings'] = xarMod::apiFunc('publications', 'user', 'getsettings', array('ptid' => $ptid));
    // Get the template for this publication type
    if ($ishome) {
        $data['template'] = 'frontpage';
    } else {
        $data['template'] = $data['pubtypeobject']->properties['template']->getValue();
    }
    $isdefault = 0;
    // check default view for this type of publications
    if (empty($catid) && empty($cids) && empty($owner) && empty($sort)) {
        if (substr($data['settings']['defaultview'], 0, 1) == 'c') {
            $catid = substr($data['settings']['defaultview'], 1);
        }
    }
    // Do not transform titles if we are not transforming output at all.
    if (empty($data['settings']['do_transform'])) {
        $data['settings']['dotitletransform'] = 0;
    }
    // Page template for frontpage or depending on publication type (optional)
    // Note : this cannot be overridden in templates
    if (!empty($data['settings']['page_template'])) {
        xarTplSetPageTemplateName($data['settings']['page_template']);
    }
    if (empty($data['settings']['defaultsort'])) {
        $defaultsort = 'date';
    } else {
        $defaultsort = $data['settings']['defaultsort'];
    }
    if (empty($sort)) {
        $sort = $defaultsort;
    }
    // TODO: show this *after* category list when we start from categories :)
    // Navigation links
    $data['publabel'] = xarML('Publication');
    $data['publinks'] = xarModAPIFunc('publications', 'user', 'getpublinks', array('ptid' => $ishome ? '' : $ptid, 'state' => $c_posted, 'count' => $data['settings']['show_pubcount']));
    $data['pager'] = '';
    // Add Sort to data passed to template so that we can automatically turn on alpha pager, if needed
    $data['sort'] = $sort;
    // Add current display letter, so that we can highlight the current filter in the alpha pager
    $data['letter'] = $letter;
    // Get the users requested number of stories per page.
    // If user doesn't care, use the site default
    if (xarUserIsLoggedIn()) {
        // TODO: figure how to let users specify their settings
        // COMMENT: if the settings were split into separate module variables,
        // then they could all be individually over-ridden by each user.
        //$numitems = xarModUserGetVar('items_per_page');
    }
    if (empty($numitems)) {
        if (!empty($settings['items_per_page'])) {
            $numitems = $settings['items_per_page'];
        } else {
            $numitems = 20;
        }
    }
    // 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;
        } elseif (strpos($catid, '-')) {
            $cids = explode('-', $catid);
            $andcids = false;
        } else {
            $cids = array($catid);
            if (strstr($catid, '_')) {
                $andcids = false;
                // don't combine with current category
            } else {
                $andcids = true;
            }
        }
    } else {
        if (empty($cids)) {
            $cids = array();
        }
        if (!isset($andcids)) {
            $andcids = true;
        }
    }
    // rebuild $catid in standard format again
    $catid = null;
    if (count($cids) > 0) {
        $seencid = array();
        foreach ($cids as $cid) {
            // make sure cids are numeric
            if (!empty($cid) && preg_match('/^_?[0-9]+$/', $cid)) {
                $seencid[$cid] = 1;
            }
        }
        $cids = array_keys($seencid);
        sort($cids, SORT_NUMERIC);
        if ($andcids) {
            $catid = join('+', $cids);
        } else {
            $catid = join('-', $cids);
        }
    }
    // every field you always wanted to know about but were afraid to ask for :)
    $extra = array();
    //    $extra[] = 'author';
    // Note: we always include cids for security checks now (= performance impact if show_categories was 0)
    $extra[] = 'cids';
    if ($data['settings']['show_hitcount']) {
        $extra[] = 'counter';
    }
    if ($data['settings']['show_ratings']) {
        $extra[] = 'rating';
    }
    $now = time();
    if (empty($startdate) || !is_numeric($startdate) || $startdate > $now) {
        $startdate = null;
    }
    if (empty($enddate) || !is_numeric($enddate) || $enddate > $now) {
        $enddate = $now;
    }
    if (empty($pubdate) || !preg_match('/^\\d{4}(-\\d+(-\\d+|)|)$/', $pubdate)) {
        $pubdate = null;
    }
    if (empty($where)) {
        $where = null;
    }
    // Modify the where clause if an Alpha filter has been specified.
    if (!empty($letter)) {
        // We will allow up to three initial letters, anything more than that is assumed to be 'Other'.
        // Need to also be very wary of SQL injection, since we are not using bind variables here.
        // TODO: take into account international characters.
        if (preg_match('/^[a-z]{1,3}$/i', $letter)) {
            $extrawhere = "title LIKE '{$letter}%'";
        } else {
            // Loop through the alphabet for the 'not in' part.
            $letterwhere = array();
            for ($i = ord('a'); $i <= ord('z'); $i++) {
                $letterwhere[] = "title NOT LIKE '" . chr($i) . "%'";
            }
            $extrawhere = implode(' and ', $letterwhere);
        }
        if ($where == null) {
            $where = $extrawhere;
        } else {
            $where .= $extrawhere;
        }
    }
    // Get publications
    $publications = xarModAPIFunc('publications', 'user', 'getall', array('startnum' => $startnum, 'cids' => $cids, 'andcids' => $andcids, 'ptid' => isset($ptid) ? $ptid : null, 'owner' => $owner, 'state' => $state, 'sort' => $sort, 'extra' => $extra, 'where' => $where, 'search' => $q, 'numitems' => $numitems, 'pubdate' => $pubdate, 'startdate' => $startdate, 'enddate' => $enddate));
    if (!is_array($publications)) {
        throw new Exception('Failed to retrieve publications');
    }
    // TODO : support different 'index' templates for different types of publications
    //        (e.g. News, Sections, ...), depending on what "view" the user
    //        selected (per category, per publication type, a combination, ...) ?
    if (!empty($owner)) {
        $data['author'] = xarUserGetVar('name', $owner);
        if (empty($data['author'])) {
            xarErrorHandled();
            $data['author'] = xarML('Unknown');
        }
    }
    if (!empty($pubdate)) {
        $data['pubdate'] = $pubdate;
    }
    // Save some variables to (temporary) cache for use in blocks etc.
    xarVarSetCached('Blocks.publications', 'ptid', $ptid);
    xarVarSetCached('Blocks.publications', 'cids', $cids);
    xarVarSetCached('Blocks.publications', 'owner', $owner);
    if (isset($data['author'])) {
        xarVarSetCached('Blocks.publications', 'author', $data['author']);
    }
    if (isset($data['pubdate'])) {
        xarVarSetCached('Blocks.publications', 'pubdate', $data['pubdate']);
    }
    // TODO: add this to publications configuration ?
    if ($ishome) {
        $data['ptid'] = null;
        if (xarSecurityCheck('SubmitPublications', 0)) {
            $data['submitlink'] = xarModURL('publications', 'admin', 'new');
        }
    } else {
        $data['ptid'] = $ptid;
        if (!empty($ptid)) {
            $curptid = $ptid;
        } else {
            $curptid = 'All';
        }
        if (count($cids) > 0) {
            foreach ($cids as $cid) {
                if (xarSecurityCheck('SubmitPublications', 0, 'Publication', "{$curptid}:{$cid}:All:All")) {
                    $data['submitlink'] = xarModURL('publications', 'admin', 'new', array('ptid' => $ptid, 'catid' => $catid));
                    break;
                }
            }
        } elseif (xarSecurityCheck('SubmitPublications', 0, 'Publication', "{$curptid}:All:All:All")) {
            $data['submitlink'] = xarModURL('publications', 'admin', 'new', array('ptid' => $ptid));
        }
    }
    $data['cids'] = $cids;
    $data['catid'] = $catid;
    xarVarSetCached('Blocks.categories', 'module', 'publications');
    xarVarSetCached('Blocks.categories', 'itemtype', $ptid);
    xarVarSetCached('Blocks.categories', 'cids', $cids);
    if (!empty($ptid) && !empty($pubtypes[$ptid]['description'])) {
        xarVarSetCached('Blocks.categories', 'title', $pubtypes[$ptid]['description']);
        // Note : this gets overriden by the categories navigation if necessary
        xarTplSetPageTitle(xarVarPrepForDisplay($pubtypes[$ptid]['description']));
    }
    // optional category count
    if ($data['settings']['show_catcount']) {
        if (!empty($ptid)) {
            $pubcatcount = xarModAPIFunc('publications', 'user', 'getpubcatcount', array('state' => $c_posted, 'ptid' => $ptid));
            if (isset($pubcatcount[$ptid])) {
                xarVarSetCached('Blocks.categories', 'catcount', $pubcatcount[$ptid]);
            }
            unset($pubcatcount);
        } else {
            $pubcatcount = xarModAPIFunc('publications', 'user', 'getpubcatcount', array('state' => $c_posted, 'reverse' => 1));
            if (isset($pubcatcount) && count($pubcatcount) > 0) {
                $catcount = array();
                foreach ($pubcatcount as $cat => $count) {
                    $catcount[$cat] = $count['total'];
                }
                xarVarSetCached('Blocks.categories', 'catcount', $catcount);
            }
            unset($pubcatcount);
        }
    } else {
        // xarVarSetCached('Blocks.categories','catcount',array());
    }
    // retrieve the number of comments for each article
    if (xarModIsAvailable('coments')) {
        if ($data['settings']['show_comments']) {
            $idlist = array();
            foreach ($publications as $article) {
                $idlist[] = $article['id'];
            }
            $numcomments = xarModAPIFunc('comments', 'user', 'get_countlist', array('modid' => $c_modid, 'objectids' => $idlist));
        }
    }
    // retrieve the keywords for each article
    if (xarModIsAvailable('coments')) {
        if ($data['settings']['show_keywords']) {
            $idlist = array();
            foreach ($publications as $article) {
                $idlist[] = $article['id'];
            }
            $keywords = xarModAPIFunc('keywords', 'user', 'getmultiplewords', array('modid' => $c_modid, 'objectids' => $idlist, 'itemtype' => $ptid));
        }
    }
    /* ------------------------------------------------------------
        // 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
                // get base categories for all if needed
                $catroots = xarModAPIFunc('publications', 'user', 'getrootcats',
                    array('ptid' => $ptid, 'all' => true)
                );
            }
            foreach ($catinfo as $cid => $info) {
                $catinfo[$cid]['name'] = xarVarPrepForDisplay($info['name']);
                $catinfo[$cid]['link'] = xarModURL('publications', 'user', 'view',
                    array('ptid' => $ptid, '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['catleft'] && $info['left'] < $rootcat['catright']) {
                        // only needed when sorting by root category id
                        $catinfo[$cid]['root'] = $rootcat['catid'];
                        // only needed when sorting by root category order
                        $catinfo[$cid]['order'] = $rootidx;
                        break;
                    }
                    $rootidx++;
                }
            }
            // needed for sort function below
            $GLOBALS['artviewcatinfo'] = $catinfo;
        }
    
        $number = 0;
        foreach ($publications as $article)
        {
            // TODO: don't include ptid and catid if we don't use short URLs
            // link to article
            $article['link'] = xarModURL('publications', 'user', 'display',
                // don't include pubtype id if we're navigating by category
                array(
                    'ptid' => empty($ptid) ? null : $article['pubtype_id'],
                    'catid' => $catid,
                    'id' => $article['id']
                )
            );
    
            // N words/bytes more in article
            if (!empty($article['body'])) {
                // note : this is only an approximate number
                $wordcount = count(preg_split("/\s+/", strip_tags($article['body']), -1, PREG_SPLIT_NO_EMPTY));
                $article['words'] = $wordcount;
    
                // byte-count is less CPU-intensive -> make configurable ?
                $article['bytes'] = strlen($article['body']);
            } else {
                $article['words'] = 0;
                $article['bytes'] = 0;
            }
    
            // current publication type
            $curptid = $article['pubtype_id'];
    
            // TODO: make configurable?
            $article['redirect'] = xarModURL('publications', 'user', 'redirect',
                array('ptid' => $curptid, 'id' => $article['id'])
            );
    
    
            // multi-column display (default from left to right, then from top to bottom)
            $article['number'] = $number;
            if (!empty($settings['number_of_columns'])) {
                $col = $number % $settings['number_of_columns'];
            } else {
                $col = 0;
            }
    
            // RSS Processing
            $current_theme = xarVarGetCached('Themes.name', 'CurrentTheme');
            if (($current_theme == 'rss') or ($current_theme == 'atom')){
                $article['rsstitle'] = htmlspecialchars($article['title']);
                //$article['rssdate'] = strtotime($article['date']);
                $article['rsssummary'] = preg_replace('<br />', "\n", $article['summary']);
                $article['rsssummary'] = xarVarPrepForDisplay(strip_tags($article['rsssummary']));
                $article['rsscomment'] = xarModURL('comments', 'user', 'display', array('modid' => $c_modid, 'objectid' => $article['id']));
                // $article['rsscname'] = htmlspecialchars($item['cname']);
                // <category>#$rsscname#</category>
            }
    
            // TODO: clean up depending on field format
            if ($do_transform) {
                $article['itemtype'] = $article['pubtype_id'];
                // TODO: what about transforming DD fields?
                if ($title_transform) {
                    $article['transform'] = array('title', 'summary', 'body', 'notes');
                } else {
                    $article['transform'] = array('summary', 'body', 'notes');
                }
                $article = xarModCallHooks('item', 'transform', $article['id'], $article, 'publications');
            }
    
            $data['titles'][$article['id']] = $article['title'];
    
            // fill in the summary template for this article
            $summary_template = $pubtypes[$article['pubtype_id']]['name'];
            $number++;echo $number;
        }
    ------------------------------------------------------------ */
    unset($publications);
    // TODO: verify for other URLs as well
    if ($ishome) {
        if (!empty($numcols) && $numcols > 1) {
            // if we're currently showing more than 1 column
            $data['showcols'] = 1;
        } else {
            $defaultcols = $data['settings']['number_of_columns'];
            if ($defaultcols > 1) {
                // if the default number of columns is more than 1
                $data['showcols'] = $defaultcols;
            }
        }
    }
    // Specific layout within a template (optional)
    if (isset($layout)) {
        $data['layout'] = $layout;
    }
    // Get the publications we want to view
    $data['object'] = DataObjectMaster::getObject(array('name' => $data['pubtypeobject']->properties['name']->value));
    $data['objectname'] = $data['pubtypeobject']->properties['name']->value;
    $data['ptid'] = $ptid;
    //    $object = DataObjectMaster::getObjectList(array('name' => $data['pubtypeobject']->properties['name']->value));
    //    $data['items'] = $object->getItems();
    $data['object'] = DataObjectMaster::getObjectList(array('name' => $data['pubtypeobject']->properties['name']->value));
    // Get the items here
    //    $items = $data['object']->getItems();
    /* We're doing this in the template now
        // Only show top level documents, not translations
        sys::import('xaraya.structures.query');
        $q = new Query();
        $q->eq('parent_id',0);
        $q->eq('pubtype_id',$ptid);
        $q->eq('state',3);
    
        // Suppress deleted items
        // Remove this once listing property works with dataobject access
        $q->ne('state',0);
        $data['conditions'] = $q;
    */
    // Set the page template if needed
    if (!empty($data['settings']['page_template'])) {
        $pagename = $data['settings']['page_template'];
        $position = strpos($pagename, '.');
        if ($position === false) {
            $pagetemplate = $pagename;
        } else {
            $pagetemplate = substr($pagename, 0, $position);
        }
        xarTpl::setPageTemplateName($pagetemplate);
    }
    // Throw all the relevant settings we are using into the cache
    //    $data['settings']['pubtypeobject'] = $data['pubtypeobject']->properties['configuration']->getValue();
    //    xarCore::setCached('publications', 'context' . $ptid, $data['settings']);
    return xarTplModule('publications', 'user', 'view', $data, $data['template']);
}
Exemple #11
0
function publications_userapi_get_pubtypes($args)
{
    $object = DataObjectMaster::getObjectList(array('name' => 'publications_types'));
    $items = $object->getItems();
    return $items;
}
Exemple #12
0
function publications_user_modify($args)
{
    if (!xarSecurityCheck('UserEditPublications')) {
        return;
    }
    extract($args);
    // Get parameters
    if (!xarVarFetch('itemid', 'isset', $data['itemid'], NULL, XARVAR_DONT_SET)) {
        return;
    }
    if (!xarVarFetch('ptid', 'isset', $ptid, 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 (empty($name) && empty($ptid)) {
        return xarResponse::NotFound();
    }
    if (!empty($ptid)) {
        $publication_type = DataObjectMaster::getObjectList(array('name' => 'publications_types'));
        $where = 'id = ' . $ptid;
        $items = $publication_type->getItems(array('where' => $where));
        $item = current($items);
        $name = $item['name'];
    }
    // Get our object
    $data['object'] = DataObjectMaster::getObject(array('name' => $name));
    $data['object']->getItem(array('itemid' => $data['itemid']));
    $data['ptid'] = $data['object']->properties['itemtype']->value;
    // 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['ptid']));
    // If creating a new translation get an empty copy
    if ($data['tab'] == 'newtranslation') {
        $data['object']->properties['id']->setValue(0);
        $data['object']->properties['parent']->setValue($data['itemid']);
        $data['items'][0] = $data['object']->getFieldValues(array(), 1);
        $data['tab'] = '';
    } else {
        $data['items'] = array();
    }
    // Get the base document. If this itemid is not the base doc,
    // then first find the correct itemid
    $data['object']->getItem(array('itemid' => $data['itemid']));
    $fieldvalues = $data['object']->getFieldValues(array(), 1);
    if (!empty($fieldvalues['parent'])) {
        $data['itemid'] = $fieldvalues['parent'];
        $data['object']->getItem(array('itemid' => $data['itemid']));
        $fieldvalues = $data['object']->getFieldValues(array(), 1);
    }
    $data['items'][$data['itemid']] = $fieldvalues;
    // Get any translations of the base document
    $data['objectlist'] = DataObjectMaster::getObjectList(array('name' => $name));
    $where = "parent = " . $id;
    $items = $data['objectlist']->getItems(array('where' => $where));
    foreach ($items as $key => $value) {
        $data['object']->getItem(array('itemid' => $key));
        $data['items'][$key] = $data['object']->getFieldValues(array(), 1);
    }
    if (!empty($ptid)) {
        $template = $item['name'];
    } else {
        // TODO: allow templates per category ?
        $template = null;
    }
    // Send the publication type and the object properties to the tempate
    $data['properties'] = $data['object']->getProperties();
    $data['ptid'] = $data['properties']['itemtype']->value;
    // Get the settings of the publication type we are using
    $data['settings'] = xarModAPIFunc('publications', 'user', 'getsettings', array('ptid' => $data['ptid']));
    return xarTplModule('publications', 'user', 'modify', $data, $template);
}