Example #1
0
 function zn_dynamic_list($element)
 {
     $output = "";
     $number_of_elements = 1;
     $group_id = $element['id'];
     if (isset($element['std']) && is_array($element['std'])) {
         $number_of_elements = count($element['std']);
     }
     /*	
     	echo '<pre>';
     	print_r($element['std']);
     	echo '</pre>';
     */
     $output .= '<div class="zn_dynamic_accordion">';
     // Start area options
     foreach ($element['options'] as $area_id => $area) {
         $output .= '<div class="zn_page_area">';
         $output .= '<div class="zn_pb_area_name"><h4>' . $area['area_name'] . '</h4>';
         if (!isset($area['limit'])) {
             $area['limit'] = '';
         }
         $output .= '<a href="#" data-pbarea="' . $area_id . '" data-limit="' . $area['limit'] . '" class="zn_slide_add_button zn-blue zn_inactive zn-gray">Add Element</a>';
         $output .= '<div class="select_wrapper">';
         $output .= '<select class="select zn_select_dynamic zn-input" >';
         $output .= '<option />Select an element</option>';
         asort($area['area_options']);
         foreach ($area['area_options'] as $select_ID => $option) {
             $output .= '<option id="' . $select_ID . '" value="' . $select_ID . '"  />' . $option . '</option>';
         }
         $output .= '</select>';
         $output .= '</div>';
         $output .= '<span class="zn_hider zn_add_type"></span>';
         $output .= '<div class="clear"></div>';
         $output .= '</div>';
         $output .= '<ul id="' . $area_id . '"  class="zn_dynamic_list_container">';
         if (!is_array($element['std'])) {
             $element['std'] = array();
         }
         foreach ($element['std'] as $key => $value) {
             if (isset($element['std'][$key]['pb_area']) && $element['std'][$key]['pb_area'] == $area_id) {
                 $new_element = $element['std'][$key]['dynamic_element_type'];
                 $option = zn_get_element_from_id($new_element);
                 $option['std'] = array();
                 $option['std'][] = $element['std'][$key];
                 $option['is_dynamic'] = true;
                 $option['pb_area'] = $area_id;
                 /*		
                 	echo '<pre>';
                 	print_r($option);
                 	echo '</pre>';
                 */
                 $output .= $this->zn_render_element($option);
             }
         }
         $output .= '</ul>';
         $output .= '</div>';
     }
     $output .= '<div class="clear"></div>';
     $output .= '</div>';
     return $output;
 }
Example #2
0
function zn_ajax_callback()
{
    $nonce = $_POST['security'];
    if (!wp_verify_nonce($nonce, 'zn_ajax_nonce')) {
        die('-1');
    }
    //get options array from db
    $all = get_option(OPTIONS);
    $save_type = $_POST['type'];
    if ($save_type == 'save') {
        $_POST = array_map('stripslashes_deep', $_POST);
        parse_str($_POST['data'], $data);
        unset($data['security']);
        unset($data['of_save']);
        $args = wp_parse_args($data, $all);
        update_option(OPTIONS, $args);
        generate_options_css($args);
        //generate static css file
        generate_options_js($args);
        //generate static js file
        echo '1';
    } elseif ($save_type == 'zn_restore_options') {
        $saved_backup = get_option($_POST['data']);
        update_option(OPTIONS, $saved_backup);
        generate_options_css($args);
        //generate static css file
        generate_options_js($args);
        //generate static js file
        ob_clean();
        echo '1';
    } elseif ($save_type == 'zn_delete_backup') {
        $saved_backup = delete_option($_POST['data']);
        ob_clean();
        echo '1';
    } elseif ($save_type == 'install_dummy') {
        locate_template(array('admin/dummy_content/zn_importer.php'), true, true);
        installDummy();
    } elseif ($save_type == 'zn_backup_options') {
        $_POST = array_map('stripslashes_deep', $_POST);
        parse_str($_POST['data'], $data);
        unset($data['security']);
        unset($data['of_save']);
        $args = wp_parse_args($data, $all);
        $date = date('Y m d H i s');
        $option_field = THEMENAME . '_backup_from_' . str_replace(' ', '_', $date);
        $option_field = strtolower($option_field);
        add_option($option_field, $args, '', 'no');
        ob_clean();
        echo $option_field;
    } elseif ($save_type == 'add_element') {
        //$what_element = $_POST['data'];
        $html = new zn_html();
        parse_str($_POST['data'], $data);
        // Make a check to see if the element is a subelement
        // All subelements options must be placed in the same array that is passed to zn_get_element_from_id() function in functions-zn-admin.php !!
        $full_id = $data['element_type'];
        if (preg_match('/\\[(\\d+)\\]/', $full_id, $matches)) {
            $split_element_type = preg_split('/\\[(\\d+)\\]/', $full_id);
            $number_of_ids = count($split_element_type) - 1;
            $string = str_replace('[', '', $split_element_type[$number_of_ids]);
            $string = str_replace(']', '', $string);
            $data['element_type'] = $string;
        }
        $option = zn_get_element_from_id($data['element_type']);
        if (isset($option['link'])) {
            $option['is_dynamic'] = true;
        }
        $option['id'] = $full_id;
        if (isset($data['pb_area']) && !empty($data['pb_area'])) {
            $option['pb_area'] = $data['pb_area'];
        }
        echo $html->zn_render_element($option);
        //print_r($option);
        unset($data['security']);
        unset($data['of_save']);
        die(1);
    }
    die;
}