function dob_admin_jstree_ajax() { if (isset($_REQUEST)) { if (!isset($_REQUEST['nonce']) || !wp_verify_nonce($_REQUEST['nonce'], 'dob_admin_jstree_ajax' . DOBver)) { exit('error nonce'); return; } } $taxonomy = isset($_REQUEST['taxonomy']) ? $_REQUEST['taxonomy'] : ''; $ondrag = isset($_REQUEST['ondrag']); //$terms = $_REQUEST['terms']; if (isset($_GET['operation'])) { $tree = new jsTree(array('taxonomy' => $taxonomy)); try { $rslt = null; switch ($_GET['operation']) { case 'analyze': var_dump($tree->analyze(true)); die; break; case 'get_node': $node = isset($_GET['id']) && $_GET['id'] !== '#' ? (int) $_GET['id'] : 0; $temp = $tree->get_children($node); $rslt = array(); foreach ($temp as $v) { switch ($v['taxonomy']) { case 'hierarchy': $icon = 'dashicons dashicons-networking'; break; case 'topic': $icon = 'dashicons dashicons-editor-paste-text'; break; case 'group': $icon = 'dashicons dashicons-groups'; break; case 'category': default: $icon = 'dashicons dashicons-category'; } $a_attr = array('slug' => $v['slug'], 'pos' => $v['pos'], 'taxonomy' => $v['taxonomy']); if ($ondrag) { $a_attr['draggable'] = 'true'; $a_attr['ondragstart'] = 'drag(event)'; } $rslt[] = array('id' => $v['term_taxonomy_id'], 'text' => $v['name'] . '//' . $v['slug'], 'children' => $v['rgt'] - $v['lft'] > 1, 'icon' => $icon, 'li_attr' => array(), 'a_attr' => $a_attr); } break; case "get_content": $node = isset($_GET['id']) && $_GET['id'] !== '#' ? $_GET['id'] : 0; $node = explode(':', $node); if (count($node) > 1) { $rslt = array('content' => 'Multiple selected'); } else { $temp = $tree->get_node((int) $node[0], array('with_path' => true)); $content = 'Selected: /' . implode('/', array_map(function ($v) { return $v['name']; }, $temp['path'])) . '/' . $temp['name']; $rslt = array('content' => $content); } break; case 'create_node': $parent_id = isset($_GET['id']) && $_GET['id'] !== '#' ? (int) $_GET['id'] : 0; $position = isset($_GET['position']) ? (int) $_GET['position'] : 0; $text = trim($_GET['text']); if (strpos($text, '//') < 1) { $name = 'name-s-' . time(); $slug = 'slug-s-' . time(); } else { list($name, $slug) = explode('//', $text); } $temp = $tree->mk($parent_id, $position, array('name' => $name, 'slug' => $slug)); $rslt = array('id' => $temp); $tree->log2cache($_GET['operation'] . " name:{$name}, slug:{$slug}"); break; case 'rename_node': $node = isset($_GET['id']) && $_GET['id'] !== '#' ? (int) $_GET['id'] : 0; $text = trim($_GET['text']); if (1 <= strpos($text, '//')) { list($name, $slug) = explode('//', $text); $rslt = $tree->rn($node, array('name' => $name, 'slug' => $slug)); } break; case 'delete_node': $node = isset($_GET['id']) && $_GET['id'] !== '#' ? (int) $_GET['id'] : 0; $rslt = $tree->rm($node); $tree->log2cache($_GET['operation'] . " name:{$name}, slug:{$slug}"); break; case 'move_node': $node = isset($_GET['id']) && $_GET['id'] !== '#' ? (int) $_GET['id'] : 0; $parn = isset($_GET['parent']) && $_GET['parent'] !== '#' ? (int) $_GET['parent'] : 0; $rslt = $tree->mv($node, $parn, isset($_GET['position']) ? (int) $_GET['position'] : 0); $tree->log2cache($_GET['operation'] . " node:{$node}, parent:{$parn}"); break; case 'copy_node': $node = isset($_GET['id']) && $_GET['id'] !== '#' ? (int) $_GET['id'] : 0; $parn = isset($_GET['parent']) && $_GET['parent'] !== '#' ? (int) $_GET['parent'] : 0; $rslt = $tree->cp($node, $parn, isset($_GET['position']) ? (int) $_GET['position'] : 0); $tree->log2cache($_GET['operation'] . " node:{$node}, parent:{$parn}"); break; default: throw new Exception('Unsupported operation: ' . $_GET['operation']); break; } header('Content-Type: application/json; charset=utf-8'); echo json_encode($rslt, JSON_UNESCAPED_UNICODE); } catch (Exception $e) { header($_SERVER["SERVER_PROTOCOL"] . ' 500 Server Error'); header('Status: 500 Server Error'); echo $e->getMessage(); } die; } }
function dob_admin_page_user() { /*{{{*/ if (empty($_SESSION['LOGIN_IP'])) { exit('error login'); } $pid = empty($_GET['pid']) ? 0 : (int) $_GET['pid']; $rslt = array(); if ($pid) { $users = dob_admin_ajax_get_users($pid); foreach ($users as $v) { $rslt[] = array('id' => 'u' . $v->user_id, 'text' => $v->display_name, 'children' => false, 'icon' => 'dashicons dashicons-universal-access', 'li_attr' => array('chl' => $v->chl, 'taxonomy' => 'user', 'style' => 'display:inline; margin-left:0px;'), 'a_attr' => array('title' => $v->user_login)); } } $jstree = new jsTree(array('taxonomy' => 'hierarchy')); $branches = $jstree->get_children($pid); foreach ($branches as $v) { $ttid = (int) $v['term_taxonomy_id']; $users = dob_admin_ajax_get_users($ttid); if (empty($users) && empty($v['inf'])) { if (empty($v['chl'])) { continue; } $max_inf = dob_admin_ajax_check_child_users((int) $v['lft'], (int) $v['rgt']); if (empty($max_inf)) { continue; } } switch ($v['taxonomy']) { case 'hierarchy': $icon = 'dashicons dashicons-networking'; break; case 'group': $icon = 'dashicons dashicons-groups'; break; default: $icon = 'dashicons dashicons-category'; } $a_attr = array('slug' => $v['slug'], 'pos' => $v['pos'], 'taxonomy' => $v['taxonomy']); $rslt[] = array('id' => $ttid, 'text' => $v['name'] . '//' . $v['slug'] . ' (' . count($users) . ')', 'children' => 1 < $v['rgt'] - $v['lft'] || !empty($users), 'icon' => $icon, 'li_attr' => array(), 'a_attr' => $a_attr); } header('Content-Type: application/json; charset=utf-8'); exit(json_encode($rslt, JSON_UNESCAPED_UNICODE)); }
'desc' => __( 'add only, overwite if duplicated', $this->plugin_slug ), 'id' => $this->plugin_slug . '_bulk_category', 'type' => 'textarea', 'default' => 'hierarchy', ) ); $form = cmb2_get_metabox_form( $this->plugin_slug . '_bulk', $this->plugin_slug . '_bulk' ); */ /*}}}*/ $message = '[message] '; #$message = '<pre>'.print_r($_REQUEST,true).'</pre>'; #$message .= wp_verify_nonce( $_POST['dobalance_admin_bulk'], 'dobalance_admin_bulk' ) ? 'yes' : 'no'; #$message .= "\n<br>"; # add bulk process if (is_array($_POST) && isset($_POST['textarea_terms']) && isset($_POST['dobalance_admin_bulk']) && wp_verify_nonce($_POST['dobalance_admin_bulk'], 'dobalance_admin_bulk')) { include_once __DIR__ . "/../../includes/jstree.class.php"; $jstree = new jsTree(); $added = $updated = $skipped = 0; $current_lvl = 0; $lvl_ids = array(0 => 0); $lines = explode("\n", $_REQUEST['textarea_terms']); foreach ($lines as $line) { $a_line = trim(preg_replace("![\r\n]+!", '', $line)); if (empty($a_line)) { continue; } $splits = preg_split("/^\\-+/", $a_line); // split indent and category data $args = array(); $parent = 0; if (isset($splits[1])) { $sp_line = $splits[1];
* @link http://example.com * @copyright 2015 Your Name or Company Name */ $message = '[message] '; #$message = '<pre>'.print_r($_REQUEST,true).'</pre>'; #$message .= wp_verify_nonce( $_POST['dobalance_admin_bulk'], 'dobalance_admin_bulk' ) ? 'yes' : 'no'; #$message .= "\n<br>"; global $wpdb; $sql = "SELECT COLUMN_TYPE FROM information_schema.COLUMNS\n\tWHERE TABLE_NAME='{$wpdb->prefix}dob_user_category' AND COLUMN_NAME='taxonomy'"; $COLUMN_TYPE = $wpdb->get_var($sql); eval('$taxonomy_db = ' . str_replace('enum', 'array', $COLUMN_TYPE) . ';'); $taxonomy = isset($_REQUEST['taxonomy']) && in_array($_REQUEST['taxonomy'], $taxonomy_db) ? $_REQUEST['taxonomy'] : 'category'; # add bulk process if (is_array($_POST) && isset($_POST['textarea_terms']) && isset($_POST['dobalance_admin_bulk']) && wp_verify_nonce($_POST['dobalance_admin_bulk'], 'dobalance_admin_bulk')) { require_once DOBpath . 'includes/jstree.class.php'; $jstree = new jsTree(array('taxonomy' => $taxonomy)); $added = $updated = $skipped = 0; $current_lvl = 0; $lvl_ids = array(0 => 0); $lines = explode("\n", $_REQUEST['textarea_terms']); foreach ($lines as $line) { $a_line = trim(preg_replace("![\r\n]+!", '', $line)); if (empty($a_line)) { continue; } $splits = preg_split("/^\\-+/", $a_line); // split indent and category data $args = array('taxonomy' => $taxonomy); $parent = 0; if (isset($splits[1])) { $sp_line = $splits[1];