require_plugin('soo_txp_obj');
@require_plugin('soo_plugin_pref'); global $soo_multidoc;
$soo_multidoc = array(
'custom_field' => '',
'init' => false,
'status' => false,
'collection' => '',
'noindex' => '',
'id_parent' => '',
'data' => '',
);
$soo_multidoc_prefs = function_exists('soo_plugin_pref_vals') ?
soo_plugin_pref_vals('soo_multidoc') : soo_multidoc_defaults();
foreach ( $soo_multidoc_prefs as $name => $val )
$soo_multidoc[$name] = is_array($val) ? $val['val'] : $val;
add_privs('plugin_prefs.soo_multidoc','1,2');
add_privs('plugin_lifecycle.soo_multidoc','1,2');
register_callback('soo_multidoc_prefs', 'plugin_prefs.soo_multidoc');
register_callback('soo_multidoc_prefs', 'plugin_lifecycle.soo_multidoc');
function soo_multidoc_prefs( $event, $step ) {
if ( function_exists('soo_plugin_pref') )
return soo_plugin_pref($event, $step, soo_multidoc_defaults());
if ( substr($event, 0, 12) == 'plugin_prefs' ) {
$plugin = substr($event, 12);
$message = '<p><br /><strong>' . gTxt('edit') . " $plugin " .
gTxt('edit_preferences') . ':</strong><br />' . gTxt('install_plugin') .
' <a href="http://ipsedixit.net/txp/92/soo_plugin_pref">soo_plugin_pref</a></p>';
pagetop(gTxt('edit_preferences') . " › $plugin", $message);
}
}
function soo_multidoc_defaults( ) {
return array(
'custom_field_name' => array(
'val' => 'Multidoc',
'html' => 'text_input',
'text' => 'Custom field name',
),
'dev_domain' => array(
'val' => '',
'html' => 'text_input',
'text' => 'Development domain (no http:// or closing slash)',
),
'list_all' => array(
'val' => 0,
'html' => 'yesnoradio',
'text' => 'Show Multidoc sub-pages in article lists?',
),
'posted_time' => array(
'val' => 'past',
'html' => 'text_input',
'text' => 'Show articles posted ‘past’, ‘future’, or ‘any’',
),
);
}
define('SOO_MULTIDOC_PREFIX', 'soo_mdoc');
global $soo_multidoc_strings;
$soo_multidoc_strings = array(
'start' => 'start',
'up' => 'up',
'next' => 'next',
'prev' => 'prev',
'recursion_error' => 'Recursion warning: initialization aborted',
'custom_field' => 'Custom field "',
'not_found' => '" not found',
'multiple_listings' => 'Multiple listings for at least one article. Start by checking articles ',
'invalid_id_1' => 'Invalid ID detected: Article ',
'invalid_id_2' => ' has a Multidoc listing for article ',
);
register_callback('soo_multidoc_enumerate_strings', 'l10n.enumerate_strings');
function soo_multidoc_enumerate_strings( $event, $step = '', $pre = 0 ) {
global $soo_multidoc_strings;
$r = array(
'owner' => 'soo_multidoc',
'prefix' => SOO_MULTIDOC_PREFIX,
'lang' => 'en-us',
'event' => 'public',
'strings' => $soo_multidoc_strings,
);
return $r;
}
function soo_multidoc_gTxt( $what , $args = array() ) {
global $textarray;
global $soo_multidoc_strings;
$key = SOO_MULTIDOC_PREFIX . '-' . $what;
$key = strtolower($key);
if(isset($textarray[$key]))
$str = $textarray[$key];
else {
$key = strtolower($what);
if( isset( $soo_multidoc_strings[$key] ) )
$str = $soo_multidoc_strings[$key];
else
$str = $what;
}
if( !empty($args) )
$str = strtr( $str , $args );
return $str;
}
class soo_multidoc_node extends soo_obj {
protected $id = '';
protected $link_type = '';
protected $title = '';
protected $children = '';
protected $next = '';
protected $prev = '';
protected $up = '';
public function __construct( $id ) {
$this->id = is_numeric($id) ? intval($id) : '';
}
public function get_link_type( $id = null ) {
return $this->get_sub_node_prop($id, 'link_type');
}
public function get_next( $id = null ) {
return $this->get_sub_node_prop($id, 'next');
}
public function get_prev( $id = null ) {
return $this->get_sub_node_prop($id, 'prev');
}
public function get_up( $id = null ) {
return $this->get_sub_node_prop($id, 'up');
}
public function set_next_by_id( $id, $next ) {
static $_soo_multidoc_failsafe;
$_soo_multidoc_failsafe ++;
if ( $_soo_multidoc_failsafe > 999 )
return soo_multidoc_gTxt('recursion_error');
if ( $id == $this->id ) {
$this->next = $next;
return $this->prev;
}
if ( ! is_array($this->children) )
return false;
foreach ( $this->children as $child ) {
$done = $child->set_next_by_id($id, $next);
if ( $done ) return $done;
}
return false;
}
public function youngest() {
if ( is_array($this->children) ) {
$my_children = $this->children;
$my_youngest = array_pop($my_children);
return $my_youngest->youngest();
}
else
return $this->id;
}
public function are_you_my_ancestor( $me, $you ) {
$my_parent = $this->get_up($me);
if ( $my_parent == $you ) return true;
if ( $my_parent )
return $this->are_you_my_ancestor($my_parent, $you);
}
public function get_id_by_link_type( $link_type ) {
if ( strtolower($link_type) == $this->link_type )
return $this->id;
if ( is_array($this->children ) ) {
foreach ( $this->children as $child ) {
if ( empty($out) )
$out = $child->get_id_by_link_type($link_type);
}
}
return isset($out) ? $out : false;
}
public function get_next_by_link_type( $id, $link_type ) {
$next = $this->get_next($id);
if ( $next )
return strtolower($this->get_link_type($next)) == $link_type ?
$next : $this->get_next_by_link_type($next, $link_type);
}
public function get_prev_by_link_type( $id, $link_type ) {
$prev = $this->get_prev($id);
if ( $prev )
return strtolower($this->get_link_type($prev)) == $link_type ?
$prev : $this->get_prev_by_link_type($prev, $link_type);
}
public function get_sub_node( $id ) {
if ( $this->id == $id or is_null($id) )
return $this;
if ( is_array($this->children) )
foreach ( $this->children as $child )
if ( empty($out) )
$out = $child->get_sub_node($id);
return isset($out) ? $out : false;
}
public function get_sub_node_prop( $id, $prop ) {
$node = &$this->get_sub_node($id);
return $node->$prop;
}
public function next_array() {
static $next_array_out;
global $soo_multidoc;
if ( isset($soo_multidoc['next_array']) )
return $soo_multidoc['next_array'];
$next_id = $this->get_next();
if ( $next_id ) {
$next_array_out[] = $next_id;
$next_node = $soo_multidoc['collection']->get_sub_node($next_id);
$next_node->next_array();
}
$soo_multidoc['next_array'] = $next_array_out;
return $next_array_out;
}
function toc( $type, $current_page, $active_class, $include_self ) {
global $soo_multidoc;
if ( is_array($this->children) ) {
if ( $type == 'ul' )
$out = new soo_html_ul;
elseif ( $type == 'ol' )
$out = new soo_html_ol;
else
return false;
if ( $include_self )
$out->contents(
new soo_html_li('',
new soo_html_anchor(
$soo_multidoc['data'][$this->id]['url'], $this->title)
));
$include_self = false;
foreach ( $this->children as $child ) {
if ( is_array($child->children) ) {
if ( $child->id == $current_page )
$item = new soo_html_span(
array('class' => $active_class)
);
else
$item = new soo_html_anchor(
$soo_multidoc['data'][$child->id]['url']
);
$item->contents($child->title);
}
$li = new soo_html_li('', isset($item) ? $item : null);
$li->contents($child->toc($type, $current_page, $active_class, false));
$out->contents($li);
unset($item);
unset($li);
}
}
else {
if ( $this->id == $current_page )
$out = new soo_html_span(array('class' => $active_class));
else
$out = new soo_html_anchor(
$soo_multidoc['data'][$this->id]['url']
);
$out->contents($this->title);
}
return isset($out) ? $out : false;
}
}
function soo_multidoc_link( $atts, $thing = null ) {
extract(lAtts(array(
'rel' => '',
'add_title' => '',
'html_id' => '',
'class' => '',
'active_class' => '',
'wraptag' => '',
), $atts));
global $soo_multidoc;
if ( ! ( _soo_multidoc_init() and $soo_multidoc['status'] ) ) return false;
$start = soo_multidoc_gTxt('start');
$up = soo_multidoc_gTxt('up');
$next = soo_multidoc_gTxt('next');
$prev = soo_multidoc_gTxt('prev');
global $thisarticle;
$collection = $soo_multidoc['collection'];
$thisid = $thisarticle['thisid'];
$rel = trim($rel);
if ( preg_match("/^($next|$prev)\s+(\w+)/i", $rel, $match) ) {
$rel_dir = strtolower($match[1]);
$rel_type = strtolower($match[2]);
if ( $rel_dir == 'next' )
$link_id = $collection->get_next_by_link_type($thisid, $rel_type);
elseif ( $rel_dir == 'prev' ) {
$link_id = $collection->get_prev_by_link_type($thisid, $rel_type);
if ( $collection->are_you_my_ancestor($thisid, $link_id) ) {
$next_link = $collection->get_prev_by_link_type($link_id, $rel_type);
if ( $next_link != $link_id and is_numeric($next_link) )
$link_id = $next_link;
else
unset($link_id);
}
}
}
elseif (preg_match("/^($next|$prev|$up|$start)$/i", $rel, $match) ) {
switch ( strtolower($match[0]) ) {
case $start:
$link_id = $collection->id;
break;
case $prev:
$link_id = $collection->get_prev($thisid);
break;
case $next:
$link_id = $collection->get_next($thisid);
break;
case $up:
$link_id = $collection->get_up($thisid);
break;
}
}
else
$link_id = $collection->get_id_by_link_type($rel);
if ( ! empty($link_id) )
$url = $soo_multidoc['data'][$link_id]['url'];
if ( ! isset($url) ) return false;
if ( $add_title )
$thing .= $collection->get_sub_node_prop($link_id, 'title');
if ( $link_id == $thisid )
$tag = new soo_html_span(array('class' => $active_class));
else
$tag = new soo_html_anchor(array('href' => $url, 'rel' => $rel));
$tag->contents( $thing ? $thing : $rel );
if ( $wraptag ) {
$tag_class = 'soo_html_' . $wraptag;
if ( class_exists($tag_class) ) {
$wraptag = new $tag_class;
return $wraptag->contents($tag)->class($class)->
id($html_id)->
tag();
}
}
else {
$tag->id($html_id);
if ( $link_id != $thisid )
$tag->class($class);
return $tag->tag();
}
}
function soo_multidoc_pager( $atts ) {
extract(lAtts(array(
'limit' => 0,
'placeholder' => ' … ',
'html_id' => '',
'class' => '',
'active_class' => '',
'wraptag' => '',
'wrapclass' => '',
'break' => '',
'breakclass' => '',
), $atts));
global $soo_multidoc;
if ( ! ( _soo_multidoc_init() and $soo_multidoc['status'] ) ) return false;
global $thisarticle;
$collection = $soo_multidoc['collection'];
$thisid = $thisarticle['thisid'];
$wraptag = trim(strtolower($wraptag));
if ( $wraptag == 'table' )
$break = 'td';
elseif ( $wraptag == 'ul' or $wraptag == 'ol' )
$break = 'li';
if ( $break ) {
$break_obj = 'soo_html_' . trim(strtolower($break));
if ( ! class_exists($break_obj) )
$break_obj = null;
else {
$break = '';
$test_obj = new $break_obj;
$empty_break = $test_obj->is_empty;
}
}
else
$break_obj = null;
$page_ids = $collection->next_array();
array_unshift($page_ids, $collection->id);
$total = count($page_ids);
$page_nums = array_combine($page_ids, range(1, $total));
$this_num = $page_nums[$thisid];
$w_start = max(1,
min($this_num - $limit, $total - ( $limit * 2 ) + 1));
$w_end = min($w_start + ( $limit * 2 ) - 1, $total);
$show_nums = array_unique(array_merge(
array(1), range($w_start, $w_end), array($total)
));
$objs = array();
while ( $show_nums ) {
$n = array_shift($show_nums);
if ( $n == $this_num )
$objs[] = new soo_html_span(array('class' => $active_class), $n);
else
$objs[] = new soo_html_anchor(array(
'href' => $soo_multidoc['data'][$page_ids[$n - 1]]['url'],
'class' => $class), $n)
;
$fill = $show_nums ?
( $show_nums[0] > $n + 1 ? $placeholder : $break ) : '';
if ( $fill )
$objs[] = new soo_html_span('', $fill);
}
if ( $break_obj ) {
if ( $empty_break ) {
while ( $objs ) {
$broken_objs[] = array_shift($objs);
$broken_objs[] = new $break_obj;
}
array_pop($broken_objs);
$objs = $broken_objs;
}
else
foreach ( $objs as $i => $obj )
$objs[$i] = new $break_obj('', $obj);
foreach ( $objs as $obj )
if ( $obj instanceof $break_obj )
$obj->class($breakclass);
}
if ( $wraptag == 'table' )
$wrap_obj = new soo_html_tr;
else {
$wrap_obj_class = 'soo_html_' . $wraptag;
if ( class_exists($wrap_obj_class) )
$wrap_obj = new $wrap_obj_class;
}
if ( isset($wrap_obj) ) {
$wrap_obj->class($wrapclass);
foreach ( $objs as $obj )
$wrap_obj->contents($obj);
if ( $wraptag == 'table' ) {
$table = new soo_html_table(array('id' => $html_id),
new soo_html_tbody('', $wrap_obj));
return $table->tag();
}
else
return $wrap_obj->id($html_id)->tag();
}
else {
$out = array();
foreach ( $objs as $obj )
$out[] = $obj->tag();
return implode("\n", $out);
}
}
function soo_multidoc_page_number( $atts ) {
extract(lAtts(array(
'html_id' => '',
'class' => '',
'wraptag' => 'span',
'format' => 'Page {page} of {total}',
), $atts));
global $soo_multidoc;
if ( ! ( _soo_multidoc_init() and $soo_multidoc['status'] ) ) return false;
global $thisarticle;
$collection = $soo_multidoc['collection'];
$thisid = $thisarticle['thisid'];
$page_ids = $collection->next_array();
array_unshift($page_ids, $collection->id);
$num_pages = count($page_ids);
$page_nums = array_flip($page_ids);
$this_page = $page_nums[$thisid] + 1;
$format = str_replace('{page}', $this_page, $format);
$format = str_replace('{total}', $num_pages, $format);
return doWrap(array($format), $wraptag, '', $class, '', '', '', $html_id);
}
function soo_multidoc_toc( $atts ) {
extract(lAtts(array(
'wraptag' => 'ul',
'root' => '',
'add_start' => false,
'html_id' => '',
'class' => '',
'active_class' => '',
), $atts));
global $soo_multidoc;
if ( ! ( _soo_multidoc_init() and $soo_multidoc['status'] ) ) return false;
global $thisarticle;
$collection = $soo_multidoc['collection'];
$thisid = $thisarticle['thisid'];
$wraptag = trim(strtolower($wraptag));
if ( $wraptag != 'ul' and $wraptag != 'ol' )
return false;
if ( $root ) {
if ( is_numeric($root) )
$start_id = intval($root);
else
$start_id = $thisarticle['thisid'];
$start_node = $collection->get_sub_node($start_id);
$out = $start_node->toc($wraptag, $thisid, $active_class, $add_start);
}
else
$out = $collection->toc($wraptag, $thisid, $active_class, $add_start);
return $out->class($class)->id($html_id)->tag();
}
function soo_multidoc_page_title( $atts ) {
extract(lAtts(array(
'separator' => ': ',
), $atts));
global $soo_multidoc, $sitename, $thisarticle;
if ( ! ( _soo_multidoc_init() and $soo_multidoc['status'] ) )
return page_title($atts);
$collection = $soo_multidoc['collection'];
$thisid = $thisarticle['thisid'];
return htmlspecialchars($sitename . $separator . $collection->title .
( $collection->id != $thisid ?
$separator . $collection->get_sub_node_prop($thisid, 'title')
: ''
)
);
}
function soo_multidoc_breadcrumbs( $atts ) {
extract(lAtts(array(
'separator' => ': ',
), $atts));
global $soo_multidoc, $thisarticle;
if ( ! ( _soo_multidoc_init() and $soo_multidoc['status'] ) )
return;
$collection = $soo_multidoc['collection'];
$this_node = $collection->get_sub_node($thisarticle['thisid']);
$crumbs[] = $this_node->title;
while ( $this_node->link_type != 'Start' ) {
$parent = $this_node->get_up();
$this_node = $collection->get_sub_node($parent);
$url = $soo_multidoc['data'][$parent]['url'];
$tag = new soo_html_anchor(array('href' => $url),
escape_title($this_node->title));
array_unshift($crumbs, $tag->tag());
}
return implode($separator, $crumbs);
}
function soo_if_multidoc( $atts, $thing ) {
extract(lAtts(array(
'start_id' => '',
), $atts));
global $soo_multidoc;
if ( ! ( _soo_multidoc_init() and $soo_multidoc['status'] ) )
return parse(EvalElse($thing, false));
$collection = $soo_multidoc['collection'];
$start_ids = do_list($start_id);
$ok = ( ! $start_id or in_array($collection->id, $start_ids) )
? true : false;
return parse(EvalElse($thing, $ok));
}
function _soo_multidoc_init() {
global $soo_multidoc, $is_article_list, $thisarticle, $prefs;
if ( $is_article_list ) return false;
if ( $soo_multidoc['init'] ) return true;
_soo_multidoc_ids_init();
assert_article();
if ( empty($thisarticle) )
return _soo_multidoc_debug();
$thisid = $thisarticle['thisid'];
$custom_field = _soo_multidoc_custom_field(); if ( empty($custom_field) )
return _soo_multidoc_debug();
if ( ! _soo_multidoc_data_init() )
return _soo_multidoc_debug();
extract($soo_multidoc);
if ( ! isset($id_parent[$thisid]) )
return _soo_multidoc_debug();
$start = isset($id_root[$thisid]) ? $id_root[$thisid] : $thisid;
$tree = _soo_multidoc_build_tree($start);
if ( ! is_array($tree) )
return _soo_multidoc_debug($tree);
$collection = new soo_multidoc_node($start);
$collection->link_type('Start')
->title($data[$start]['Title'])
->children($tree);
$next_node = array_shift($tree);
$collection->next($next_node->id);
unset($next_node);
$next = $collection->youngest();
$to_set = $collection->get_prev($next);
while ( is_numeric($to_set) and $to_set > 0 ) {
$next_to_set = $collection->set_next_by_id($to_set, $next);
$next = $to_set;
$to_set = $next_to_set;
}
if ( $to_set )
return _soo_multidoc_debug($to_set);
$soo_multidoc['collection'] = &$collection;
$soo_multidoc['init'] = true;
$soo_multidoc['status'] = true;
return true;
}
function _soo_multidoc_build_tree($start_id) {
global $soo_multidoc;
extract($soo_multidoc);
static $_soo_multidoc_failsafe;
static $_soo_multidoc_prev;
$_soo_multidoc_prev = $start_id;
$_soo_multidoc_failsafe ++;
if ( $_soo_multidoc_failsafe > 999 )
return soo_multidoc_gTxt('recursion_warning') . ": ID $start_id";
$out = array();
foreach ( $id_children[$start_id] as $child ) {
extract($data[$child]);
$node = new soo_multidoc_node($child);
$node->link_type($link_type)
->title($Title)
->up($parent); $node->prev($_soo_multidoc_prev);
$_soo_multidoc_prev = $child;
if ( isset($id_children[$child]) ) {
$result = _soo_multidoc_build_tree($child);
if ( ! is_array($result) ) return $result;
$node->children($result);
$out[$child] = $node;
}
else
$out[$child] = $node;
unset($node);
}
return $out;
}
function _soo_multidoc_custom_field() {
global $soo_multidoc, $prefs;
$f = $soo_multidoc['custom_field'];
if ( $f == -1 ) return false;
if ( $f ) return $f;
$name = $soo_multidoc['custom_field_name'];
foreach ( $prefs as $key => $value )
if ( preg_match('/^(custom_\d+)/i', $key, $match) )
if ( $value == $name ) {
$soo_multidoc['custom_field'] = $match[1]; return $match[1];
}
$soo_multidoc['custom_field'] = -1;
return _soo_multidoc_debug(
soo_multidoc_gTxt('custom_field') . $name . soo_multidoc_gTxt('not_found')
);
}
function _soo_multidoc_ids_init() {
global $soo_multidoc;
if ( is_array($soo_multidoc['noindex']) )
return true;
$noindex = array();
$id_parent = array();
$id_link_type = array();
$id_children = array();
$duplicates = array();
$custom_field = _soo_multidoc_custom_field(); if ( empty($custom_field) )
return false;
$query = new soo_txp_select('textpattern');
$query->select('ID')->where('Status', 3, '>'); if ( ! get_pref('publish_expired_articles') ) {
$query->where_clause('(now() <= Expires or Expires = ' .
NULLDATETIME . ')');
}
switch ( $soo_multidoc['posted_time'] ) {
case 'past':
$query->where_clause('Posted <= now()');
break;
case 'future':
$query->where_clause('Posted > now()');
break;
}
$all_ids = new soo_txp_rowset($query);
$all_ids = $all_ids->field_vals('ID');
$query = new soo_txp_select('textpattern');
$query->select(array('ID', $custom_field))
->regexp('[[:digit:]]', $custom_field);
$data = new soo_txp_rowset($query);
$data = $data->field_vals($custom_field, 'ID');
unset($query);
foreach ( $data as $parent => $field ) {
if ( in_array($parent, $all_ids) ) {
$groups = do_list(strtolower($field));
foreach ( $groups as $group ) {
preg_match_all('/\s(\d+)/', $group, $children);
foreach ( $children[1] as $i => $child )
if ( ! in_array($child, $all_ids) )
unset($children[1][$i]);
preg_match('/^\s*(\w+)\s/', $group, $link_type);
if ( isset($id_children[$parent]) ) {
foreach ( $children[1] as $child )
array_push($id_children[$parent], $child);
}
else
$id_children[$parent] = $children[1];
foreach ( $children[1] as $child ) {
if ( isset($noindex[$child]) ) {
$duplicates[] = $child;
$duplicates[] = $parent;
}
else {
$noindex[$child] = $parent;
$id_link_type[$child] = $link_type[1];
}
}
}
}
}
$duplicates = array_unique($duplicates);
if ( count($duplicates) ) {
_soo_multidoc_debug(
soo_multidoc_gTxt('multiple_listings') . implode(', ', $duplicates));
$soo_multidoc['status'] = false;
$soo_multidoc['noindex'] = array();
return false;
}
$id_parent = $noindex;
$start_ids = array_diff(array_keys($data), array_keys($noindex));
foreach ( $start_ids as $id ) {
$id_parent[$id] = 'start';
$id_link_type[$id] = 'start';
}
$id_root = array();
foreach ( $noindex as $id => $parent )
$id_root[$id] = _soo_multidoc_find_root($id, $id_parent);
$soo_multidoc['id_parent'] = $id_parent; $soo_multidoc['id_root'] = $id_root; $soo_multidoc['id_link_type'] = $id_link_type; $soo_multidoc['id_children'] = $id_children; $soo_multidoc['noindex'] = array_keys($noindex); return true;
}
function _soo_multidoc_find_root($id, $id_parent) {
if ( is_numeric($id_parent[$id]) )
return _soo_multidoc_find_root($id_parent[$id], $id_parent);
return $id;
}
function _soo_multidoc_data_init() {
global $soo_multidoc, $permlinks;
extract($soo_multidoc);
if ( is_array($data) )
return true;
if ( empty($id_parent) or $custom_field == '' or $custom_field == -1 )
return false;
$query = new soo_txp_select('textpattern');
$rs = $query->
select(array(
'ID',
'Title',
'url_title',
'Section',
'unix_timestamp(Posted) as posted',
$custom_field)
)->rows();
unset($query);
$out = array();
$all_ids = array();
foreach ( $rs as $r ) {
$id = $r['ID'];
$all_ids[$id] = $id;
if ( isset($id_parent[$id]) ) {
$r['root'] = isset($id_root[$id]) ? $id_root[$id] : $id;
$r['parent'] = $id_parent[$id];
$r['link_type'] = $id_link_type[$id];
$r['url'] = _soo_multidoc_url($r);
$out[$id] = $r;
}
}
$invalid_ids = array_diff(array_keys($id_parent), $all_ids);
if ( count($invalid_ids) ) {
foreach ( $invalid_ids as $i )
_soo_multidoc_debug(soo_multidoc_gTxt('invalid_id_1') . $id_parent[$i] .
soo_multidoc_gTxt('invalid_id_2') . $i);
return false;
}
$soo_multidoc['data'] = $out;
return true;
}
function _soo_multidoc_url( $article_array ) {
global $permlink_mode, $prefs;
if (isset($prefs['custom_url_func']) and is_callable($prefs['custom_url_func']))
return call_user_func($prefs['custom_url_func'], $article_array, PERMLINKURL);
if (empty($article_array)) return;
extract($article_array);
$Section = urlencode($Section);
$url_title = urlencode($url_title);
switch($permlink_mode) {
case 'section_id_title':
if ($prefs['attach_titles_to_permalinks'])
{
$out = hu."$Section/$ID/$url_title";
}else{
$out = hu."$Section/$ID/";
}
break;
case 'year_month_day_title':
list($y,$m,$d) = explode("-",date("Y-m-d",$posted));
$out = hu."$y/$m/$d/$url_title";
break;
case 'id_title':
if ($prefs['attach_titles_to_permalinks'])
{
$out = hu."$ID/$url_title";
}else{
$out = hu."$ID/";
}
break;
case 'section_title':
$out = hu."$Section/$url_title";
break;
case 'title_only':
$out = hu."$url_title";
break;
case 'messy':
$out = hu."index.php?id=$ID";
break;
}
return $out;
}
function _soo_multidoc_debug( $message = '' ) {
global $soo_multidoc;
$soo_multidoc['init'] = true;
if ( ! $message ) return false;
$prefix = 'soo_multidoc: ';
$postfix = n;
$domain = $_SERVER['HTTP_HOST'];
$is_dev_site = $domain == $soo_multidoc['dev_domain'] ? true : false;
if ( ! $is_dev_site ) {
$prefix = '<!-- ' . $prefix;
$postfix = ' -->' . $postfix;
}
else
$postfix = '<br />' . $postfix;
echo $prefix . $message . $postfix;
return false;
}
function _soo_multidoc_temp_table ( ) {
global $pretext, $is_article_list, $soo_multidoc;
if ( ! $is_article_list or
$pretext['q'] or
$soo_multidoc['list_all'] or
! _soo_multidoc_ids_init() or
empty($soo_multidoc['noindex'])
)
return;
$table = safe_pfx('textpattern');
safe_query(
"create temporary table $table select * from $table where ID not in ("
. implode(',', $soo_multidoc['noindex']) . ")");
}
register_callback('_soo_multidoc_temp_table', 'pretext_end');