if (@txpinterface == 'admin') { register_callback('smd_writecat', 'article_ui', 'categories'); register_callback('smd_writecat_insert', 'article', 'edit', 1); register_callback('smd_writecat_insert', 'article', 'create', 1); } // ------------------------ function smd_writecat($evt, $stp, $dflt, $rs) { $catbox = graf(''.br.fInput('text', 'smd_category', '', '', '', '', '', '', 'smd_writecat'), ' class="category"'); return $dflt.$catbox; } // ------------------------ function smd_writecat_insert($evt, $stp) { $save = gps('save'); $publish = gps('publish'); if ($save || $publish) { $newcats = gps('smd_category'); if ($newcats) { $newcats = do_list($newcats); $ctr = 1; foreach ($newcats as $newcat) { if (!empty($newcat)) { $exists = safe_row('*', 'txp_category', "name='".doSlash($newcat)."'"); if ($exists) { $ret = true; $name = sanitizeForUrl($newcat); } else { $title = doSlash($newcat); $name = sanitizeForUrl($title); $ret = safe_insert('txp_category', "name='$name', type='article', parent='root', title='$title'"); } if ($ret && $ctr <= 2) { $_POST['Category'.$ctr] = $name; } } $ctr++; } rebuild_tree_full('article'); } } } // ------------------------ // Plugin-specific replacement strings - localise as required // TODO: make these into a textpack when plugin composer supports them function smd_writecat_gTxt($what, $atts = array()) { $lang = array( 'new_cat_label' => 'Or new categories', ); return strtr($lang[$what], $atts); }