/** * Initialize WURFL * */ function wurfl_init($args = array()) { if (!isset($args['mode'])) { $args['mode'] = 'performance'; } sys::import('modules.wurfl.xarincludes.WURFL.Application'); $resourcesDir = sys::code() . 'modules/wurfl/xarincludes/resources'; $persistenceDir = $resourcesDir . '/storage/persistence'; $cacheDir = $resourcesDir . '/storage/cache'; // Create WURFL Configuration $wurflConfig = new WURFL_Configuration_InMemoryConfig(); // Set location of the WURFL File $wurflConfig->wurflFile($resourcesDir . '/wurfl.xml'); // Set the match mode for the API ('performance' or 'accuracy') $wurflConfig->matchMode($args['mode']); // Setup WURFL Persistence $wurflConfig->persistence('file', array('dir' => $persistenceDir)); // Setup Caching $wurflConfig->cache('file', array('dir' => $cacheDir, 'expiration' => 36000)); // Create a WURFL Manager Factory from the WURFL Configuration $wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig); // Create a WURFL Manager /* @var $wurflManager WURFL_WURFLManager */ $wurflManager = $wurflManagerFactory->create(); return $wurflManager; }
function publications_admin_templates_page($args) { if (!xarSecurityCheck('AdminPublications')) { return; } extract($args); if (!xarVarFetch('confirm', 'int', $confirm, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('ptid', 'id', $data['ptid'], 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('itemid', 'id', $data['itemid'], 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('file', 'str', $data['file'], 'summary', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('source_data', 'str', $data['source_data'], '', XARVAR_NOT_REQUIRED)) { return; } if (empty($data['itemid']) || empty($data['ptid'])) { return xarResponse::NotFound(); } $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $data['ptid'])); $pubtype = explode('_', $pubtypeobject->properties['name']->value); $pubtype = isset($pubtype[1]) ? $pubtype[1] : $pubtype[0]; $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value)); $basepath = sys::code() . "modules/publications/xartemplates/objects/" . $pubtype; $sourcefile = $basepath . "/" . $data['file'] . "_" . $data['itemid'] . ".xt"; $overridepath = "themes/" . xarModVars::get('themes', 'default_theme') . "/modules/publications/objects/" . $pubtype; $overridefile = $overridepath . "/" . $data['file'] . "-" . $data['itemid'] . ".xt"; // If we are saving, write the file now if ($confirm && !empty($data['source_data'])) { xarMod::apiFunc('publications', 'admin', 'write_file', array('file' => $overridefile, 'data' => $data['source_data'])); } // Let the template know what kind of file this is if (file_exists($overridefile)) { $data['filetype'] = 'theme'; $filepath = $overridefile; $data['writable'] = is_writable($overridefile); } else { $data['filetype'] = 'module'; $filepath = $sourcefile; $data['writable'] = is_writeable_dir($overridepath); } $data['source_data'] = trim(xarMod::apiFunc('publications', 'admin', 'read_file', array('file' => $filepath))); // Initialize the template if (empty($data['source_data'])) { $data['source_data'] = '<xar:template xmlns:xar="http://xaraya.com/2004/blocklayout">'; $data['source_data'] .= "\n"; $data['source_data'] .= "\n" . '</xar:template>'; } $data['files'] = array(array('id' => 'summary', 'name' => 'summary display'), array('id' => 'detail', 'name' => 'detail display')); return $data; }
function publications_admin_stylesheet_type($args) { if (!xarSecurityCheck('AdminPublications')) { return; } extract($args); if (!xarVarFetch('confirm', 'int', $confirm, 0, XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('ptid', 'id', $data['ptid'], xarModVars::get('publications', 'defaultpubtype'), XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('file', 'str', $data['file'], '', XARVAR_NOT_REQUIRED)) { return; } if (!xarVarFetch('source_data', 'str', $data['source_data'], '', XARVAR_NOT_REQUIRED)) { return; } $pubtypeobject = DataObjectMaster::getObject(array('name' => 'publications_types')); $pubtypeobject->getItem(array('itemid' => $data['ptid'])); $pubtype = explode('_', $pubtypeobject->properties['name']->value); $pubtype = isset($pubtype[1]) ? $pubtype[1] : $pubtype[0]; $data['object'] = DataObjectMaster::getObject(array('name' => $pubtypeobject->properties['name']->value)); $basepath = sys::code() . "modules/publications/xarstyles"; $sourcefile = $basepath . "/" . $data['file'] . ".css"; $overridepath = "themes/" . xarModVars::get('themes', 'default_theme') . "/modules/publications/style"; $overridefile = $overridepath . "/" . $data['file'] . ".css"; // If we are saving, write the file now if ($confirm && !empty($data['file']) && !empty($data['source_data'])) { xarMod::apiFunc('publications', 'admin', 'write_file', array('file' => $overridefile, 'data' => $data['source_data'])); } // Let the template know what kind of file this is if (empty($data['file'])) { $data['filetype'] = 'empty'; $filepath = ''; $data['writable'] = 0; } elseif (file_exists($overridefile)) { $data['filetype'] = 'theme'; $filepath = $overridefile; $data['writable'] = is_writable($overridefile); } elseif (file_exists($sourcefile)) { $data['filetype'] = 'module'; $filepath = $sourcefile; $data['writable'] = is_writeable_dir($overridepath); } else { $data['filetype'] = 'unknown'; $filepath = $overridefile; $data['writable'] = is_writeable_dir($overridepath); } $data['source_data'] = trim(xarMod::apiFunc('publications', 'admin', 'read_file', array('file' => $filepath))); return $data; }
/** * 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; }
/** * 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; }