// smd_tags by Stef Dawson // TODO: Tag paging next/prev // break out of context in tag list (show_all?) require_plugin('smd_tags_admin'); // ------------------------ // PUBLIC TAGS // ------------------------ // Check tags of a particular type, or those that have a specific property in context. //TODO: Think about checking logic, eg, name="business|pleasure" (OR) name="business+pleasure" (AND) function smd_if_tag ($atts, $thing) { global $smd_tags, $smd_tag_type, $smd_thistag; if (!smd_tags_table_exist()) { trigger_error(smd_tags_gTxt('not_available')); return; } extract(lAtts(array( 'type' => '', 'id' => '', 'name' => '', 'title' => '', 'parent' => '', 'count' => '', 'children' => '', 'level' => '', 'debug' => '0', ),$atts)); $ctxt = smd_tags_context(); $scope = $ctxt['scope']; $idlist = $ctxt['id']; $ctype = $ctxt['context']; // Validate atts $validTypes = array('article','image','file','link'); $ctxt = smd_tags_context(); $scope = $ctxt['scope']; $idlist = $ctxt['id']; $ctype = $ctxt['context']; $type = (in_array($type, $validTypes)) ? $type : ( ($ctxt['context']) ? $ctxt['context'] : ( ($smd_tag_type) ? $smd_tag_type : $validTypes[0] ) ); $eqtest = array(); $nutest = array(); $opRE = '/(\>|\>\=|\<|\<\=|\!)([0-9a-zA-Z- ]+)/'; $num = preg_match_all($opRE, $id, $parts); $eqtest['id'] = ($num<=0) ? $id : ''; if ($num>0) $nutest['id'] = array($parts[1][0] => $parts[2][0]); $num = preg_match_all($opRE, $name, $parts); $eqtest['name'] = ($num<=0) ? $name : ''; if ($num>0) $nutest['name'] = array($parts[1][0] => $parts[2][0]); $num = preg_match_all($opRE, $type, $parts); $eqtest['type'] = ($num<=0) ? $type : ''; if ($num>0) $nutest['type'] = array($parts[1][0] => $parts[2][0]); $num = preg_match_all($opRE, $title, $parts); $eqtest['title'] = ($num<=0) ? $title : ''; if ($num>0) $nutest['title'] = array($parts[1][0] => $parts[2][0]); $num = preg_match_all($opRE, $parent, $parts); $eqtest['parent'] = ($num<=0) ? $parent : ''; if ($num>0) $nutest['parent'] = array($parts[1][0] => $parts[2][0]); $num = preg_match_all($opRE, $count, $parts); $eqtest['count'] = ($num<=0) ? $count : ''; if ($num>0) $nutest['count'] = array($parts[1][0] => $parts[2][0]); $num = preg_match_all($opRE, $children, $parts); $eqtest['children'] = ($num<=0) ? $children : ''; if ($num>0) $nutest['children'] = array($parts[1][0] => $parts[2][0]); $num = preg_match_all($opRE, $level, $parts); $eqtest['level'] = ($num<=0) ? $level : ''; if ($num>0) $nutest['level'] = array($parts[1][0] => $parts[2][0]); if ($debug) { echo "++ IF_TAG TESTS ++"; dmp($eqtest); dmp($nutest); } // Init $out = $result = $numTests = 0; if (empty($smd_tags) && empty($smd_thistag)) { // not in scope } else { // Equality comparisons foreach ($eqtest as $tname => $tval) { if ($tval != "") { $numTests++; if ($smd_thistag) { // Local scope if ($smd_thistag['tag_'.$tname] == $tval) { $out++; } } else { // Global scope if ($tname == "type") { if ($smd_tag_type == $type || $ctype == $type) { $out++; } } if (isset($smd_tags[$type]['tag_'.$tname]) && in_array($tval, $smd_tags[$type]['tag_'.$tname])) { $out++; } } } } // Numeric comparisons foreach ($nutest as $tname => $tval) { $numTests++; $op = current(array_keys($tval)); $val = current($tval); if ($smd_thistag) { $comparison = $smd_thistag['tag_'.$tname]; } else { $comparison = $smd_tags[$type]['tag_'.$tname]; } switch ($op) { case '>': if (isset($comparison) && $comparison > $val) { $out++; } break; case '>=': if (isset($comparison) && $comparison >= $val) { $out++; } break; case '<': if (isset($comparison) && $comparison < $val) { $out++; } break; case '<=': if (isset($comparison) && $comparison <= $val) { $out++; } break; case '!': if (isset($comparison) && $comparison != $val) { $out++; } break; } } // Count how many successes there were if ($debug) { echo "++ NUM TESTS & RESULT++"; dmp($numTests); dmp($out); } if ($numTests == $out) { $result = 1; } } return parse(EvalElse($thing, $result)); } // ------------------------ function smd_if_tag_list ($atts, $thing) { global $smd_tag_type; return parse(EvalElse($thing, (!empty($smd_tag_type)))); } // ------------------------ // Return name/title of current tag function smd_tag_name($atts, $thing='') { global $smd_thistag, $permlink_mode; if (!smd_tags_table_exist()) { trigger_error(smd_tags_gTxt('not_available')); return; } extract(lAtts(array( 'title' => 0, 'link' => '', 'section' => '', 'parent' => 0, // not useful to print but good for URLs to nav back up the tree 'parentlabel' => 'Up a level', 'wraptag' => '', 'class' => __FUNCTION__, ),$atts)); $smdpref = smd_tags_pref_get(array('smd_tag_u_sec', 'smd_tag_u_pnam', 'smd_tag_u_ptyp'), 1); $section = ($section) ? $section : $smdpref['smd_tag_u_sec']['val']; $urlnam = $smdpref['smd_tag_u_pnam']['val']; $urltyp = $smdpref['smd_tag_u_ptyp']['val']; $label = ($parent) ? $parentlabel : (($title) ? $smd_thistag['tag_title'] : $smd_thistag['tag_name']); $tname = ($parent) ? $smd_thistag['tag_parent'] : $smd_thistag['tag_name']; $dest = ($permlink_mode == 'messy') ? pagelinkurl(array('s' => $section, $urlnam => $tname, $urltyp => $smd_thistag['tag_type'])) : '/'.$section.'/'.$smd_thistag['tag_type'].'/'.$tname; if ($thing) { $out = '