+
+function common_valid_tag($tag) {
+ if (preg_match('/^tag:(.*?),(\d{4}(-\d{2}(-\d{2})?)?):(.*)$/', $tag, $matches)) {
+ return (Validate::email($matches[1]) ||
+ preg_match('/^([\w-\.]+)$/', $matches[1]));
+ }
+ return false;
+}
+
+# Does a little before-after block for next/prev page
+
+function common_pagination($have_before, $have_after, $page, $action, $args=NULL) {
+
+ if ($have_before || $have_after) {
+ common_element_start('div', array('id' => 'pagination'));
+ common_element_start('ul', array('id' => 'nav_pagination'));
+ }
+
+ if ($have_before) {
+ $pargs = array('page' => $page-1);
+ $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
+
+ common_element_start('li', 'before');
+ common_element('a', array('href' => common_local_url($action, $newargs)),
+ _t('« After'));
+ common_element_end('li');
+ }
+
+ if ($have_after) {
+ $pargs = array('page' => $page+1);
+ $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
+ common_element_start('li', 'after');
+ common_element('a', array('href' => common_local_url($action, $newargs)),
+ _t('Before »'));
+ common_element_end('li');
+ }
+
+ if ($have_before || $have_after) {
+ common_element_end('ul');
+ common_element_end('div');
+ }
+}
+
+/* Following functions are copied from MediaWiki GlobalFunctions.php
+ * and written by Evan Prodromou. */
+
+function common_accept_to_prefs($accept, $def = '*/*') {
+ # No arg means accept anything (per HTTP spec)
+ if(!$accept) {
+ return array($def => 1);
+ }
+
+ $prefs = array();
+
+ $parts = explode(',', $accept);
+
+ foreach($parts as $part) {
+ # FIXME: doesn't deal with params like 'text/html; level=1'
+ @list($value, $qpart) = explode(';', $part);
+ $match = array();
+ if(!isset($qpart)) {
+ $prefs[$value] = 1;
+ } elseif(preg_match('/q\s*=\s*(\d*\.\d+)/', $qpart, $match)) {
+ $prefs[$value] = $match[1];
+ }
+ }
+
+ return $prefs;
+}
+
+function common_mime_type_match($type, $avail) {
+ if(array_key_exists($type, $avail)) {
+ return $type;
+ } else {
+ $parts = explode('/', $type);
+ if(array_key_exists($parts[0] . '/*', $avail)) {
+ return $parts[0] . '/*';
+ } elseif(array_key_exists('*/*', $avail)) {
+ return '*/*';
+ } else {
+ return NULL;
+ }
+ }
+}
+
+function common_negotiate_type($cprefs, $sprefs) {
+ $combine = array();
+
+ foreach(array_keys($sprefs) as $type) {
+ $parts = explode('/', $type);
+ if($parts[1] != '*') {
+ $ckey = common_mime_type_match($type, $cprefs);
+ if($ckey) {
+ $combine[$type] = $sprefs[$type] * $cprefs[$ckey];
+ }
+ }
+ }
+
+ foreach(array_keys($cprefs) as $type) {
+ $parts = explode('/', $type);
+ if($parts[1] != '*' && !array_key_exists($type, $sprefs)) {
+ $skey = common_mime_type_match($type, $sprefs);
+ if($skey) {
+ $combine[$type] = $sprefs[$skey] * $cprefs[$type];
+ }
+ }
+ }
+
+ $bestq = 0;
+ $besttype = NULL;
+
+ foreach(array_keys($combine) as $type) {
+ if($combine[$type] > $bestq) {
+ $besttype = $type;
+ $bestq = $combine[$type];
+ }
+ }
+
+ return $besttype;
+}
+
+function common_config($main, $sub) {
+ global $config;
+ return $config[$main][$sub];
+}