/** * Given an itemid, get the publication type * CHECKME: use get in place of this function? */ function publications_userapi_getitempubtype($args) { if (empty($args['itemid'])) { throw new MissingParameterException('itemid'); } sys::import('xaraya.structures.query'); $xartables = xarDB::getTables(); $q = new Query('SELECT', $xartables['publications']); $q->addfield('pubtype_id'); $q->eq('id', $args['itemid']); if (!$q->run()) { return; } $result = $q->row(); if (empty($result)) { return 0; } return $result['pubtype_id']; }
/** * Given an itemid, get the publication type * CHECKME: use get in place of this function? */ function publications_userapi_getpubtypeaccess($args) { if (empty($args['name'])) { throw new MissingParameterException('name'); } sys::import('xaraya.structures.query'); $xartables = xarDB::getTables(); $q = new Query('SELECT', $xartables['publications_types']); $q->addfield('access'); $q->eq('name', $args['name']); if (!$q->run()) { return; } $result = $q->row(); if (empty($result)) { return "a:0:{}"; } return $result['access']; }
/** * Publications Module * * @package modules * @subpackage publications module * @category Third Party Xaraya Module * @version 2.0.0 * @copyright (C) 2011 Netspan AG * @license GPL {@link http://www.gnu.org/licenses/gpl.html} * @author Marc Lutolf <*****@*****.**> */ function publications_userapi_gettranslationid($args) { if (!isset($args['id'])) { throw new BadParameterException('id'); } if (empty($args['id'])) { return 0; } // We can check on a full locale or just a partial one (excluding charset) if (empty($args['partiallocale'])) { $args['partiallocale'] = 0; } // We can look for a specific translation if (empty($args['locale'])) { $locale = xarUserGetNavigationLocale(); } else { $locale = $args['locale']; } sys::import('xaraya.structures.query'); if ($args['partiallocale']) { $parts = explode('.', $locale); $locale = $parts[0]; } $xartable = xarDB::getTables(); if (empty($args['locale'])) { // Return the id of the translation if it exists, or else the base document $q = new Query('SELECT', $xartable['publications']); $q->addfield('id'); $q->eq('locale', $locale); $c[] = $q->peq('id', $args['id']); $c[] = $q->peq('parent_id', $args['id']); $q->qor($c); if (!$q->run()) { return $args['id']; } $result = $q->row(); if (empty($result)) { return $args['id']; } return $result['id']; } elseif ($args['locale'] == xarUserGetNavigationLocale()) { // No need to look further return $args['id']; } elseif ($args['locale'] == xarModVars::get('publications', 'defaultlanguage')) { // Force getting the base document $q = new Query('SELECT', $xartable['publications']); $q->addfield('parent_id'); $q->eq('id', $args['id']); if (!$q->run()) { return $args['id']; } $result = $q->row(); if (empty($result)) { return $args['id']; } // If this was already the base document, return its ID if (empty($result['parent_id'])) { return $args['id']; } // Else return the parent ID return $result['parent_id']; } else { // Force getting another translation $q = new Query('SELECT'); $q->addtable($xartable['publications'], 'p1'); $q->addtable($xartable['publications'], 'p2'); $q->join('p2.parent_id', 'p1.parent_id'); $q->addfield('p2.id'); $q->eq('p2.locale', $locale); $q->eq('p1.id', $args['id']); if (!$q->run()) { return $args['id']; } $result = $q->row(); if (empty($result)) { return $args['id']; } return $result['id']; } if (xarUserGetVar('uname') == 'random') { $xartable = xarDB::getTables(); $q = new Query('SELECT'); $q->addtable($xartable['publications'], 'p1'); $q->addtable($xartable['publications'], 'p2'); $q->join('p2.id', 'p1.parent_id'); $q->addfield('p1.id'); $c[] = $q->peq('p1.id', $args['id']); $c[] = $q->peq('p1.parent_id', $args['id']); $c[] = $q->peq('p2.id', $args['id']); $q->qor($c); $d[] = $q->peq('p1.locale', $args['locale']); $d[] = $q->peq('p2.locale', $args['locale']); $q->qor($d); if (!$q->run()) { return $args['id']; } $q->qecho(); $result = $q->row(); if (empty($result)) { return $args['id']; } return $result['id']; } }
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); }