+
+function common_ensure_syslog() {
+ static $initialized = false;
+ if (!$initialized) {
+ global $config;
+ define_syslog_variables();
+ openlog($config['syslog']['appname'], 0, LOG_USER);
+ $initialized = true;
+ }
+}
+
+function common_log($priority, $msg, $filename=NULL) {
+ common_ensure_syslog();
+ syslog($priority, $msg);
+}
+
+function common_debug($msg, $filename=NULL) {
+ if ($filename) {
+ common_log(LOG_DEBUG, basename($filename).' - '.$msg);
+ } else {
+ common_log(LOG_DEBUG, $msg);
+ }
+}
+
+function common_valid_http_url($url) {
+ return Validate::uri($url, array('allowed_schemes' => array('http', 'https')));
+}
+
+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('« Before'));
+ 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('After »'));
+ common_element_end('li');
+ }
+
+ if ($have_before || $have_after) {
+ common_element_end('ul');
+ common_element_end('div');
+ }
+}