public function getListData()
 {
     if (!empty($this->searchData)) {
         $this->searchData = array_reindex($this->searchData, 'name');
     }
     $this->data['lists'] = $this->model->with('advertiser', 'sale', 'country')->search($this->searchData)->orderBy($this->defaultField, $this->defaultOrder)->paginate($this->showNumber);
 }
 public function getListData()
 {
     if (!empty($this->searchData)) {
         $this->searchData = array_reindex($this->searchData, 'name');
     }
     $this->data['lists'] = $this->model->searchAd($this->searchData)->where('status', 3)->orderBy($this->defaultField, $this->defaultOrder)->paginate($this->showNumber);
 }
Ejemplo n.º 3
0
/**
 * Reset array indexes while keep string indexes intact
 */
function array_reindex(&$array)
{
    // if this is a
    if (!is_array_assoc($array)) {
        $array = array_values($array);
    }
    if (is_array_deeper($array, 1)) {
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                array_reindex($array[$key]);
            }
        }
    }
}
Ejemplo n.º 4
0
 public function testArrayReindexMulti()
 {
     $data = array(array('country' => 'NL', 'city' => 'AMS', 'single' => true), array('country' => 'NL', 'city' => 'DHG', 'single' => true), array('country' => 'US', 'city' => 'LAX'));
     $test1 = array_reindex($data, function ($item) {
         return $item['country'];
     });
     $test2 = array_reindex($data, function ($item) {
         return $item['country'];
     }, true);
     $this->assertCount(2, $test1);
     $this->assertCount(2, $test1['NL']);
     $this->assertCount(1, $test1['US']);
     $this->assertCount(3, $test2['NL']);
     $this->assertCount(2, $test2['US']);
 }
/**
 * Validate the options by type before saving
 */
function spyropress_validate_setting($value, $type, $field_id, $section)
{
    // check for null
    if (!$value || !$type || !$field_id) {
        return $value;
    }
    // type = background
    if ('repeater' == $type) {
        // skip last dummy element
        array_pop($value);
        // reset array indexes
        array_reindex($value);
        // Validate Fields
        $new_values = array();
        $total = count($value);
        for ($i = 0; $i < $total; $i++) {
            $raw_value = $value[$i];
            foreach ($section['fields'] as $field) {
                if (isset($field['id']) && isset($raw_value[$field['id']]) && !in_array($field['type'], spyropress_exclude_option_types())) {
                    $key = trim($field['id']);
                    $type = $field['type'];
                    $new_value = $raw_value[$key];
                    $new_values[$i][$key] = spyropress_validate_setting($new_value, $type, $key, $field);
                }
            }
            $new_values[$i] = spyropress_clean_array($new_values[$i]);
        }
        $value = $new_values;
    } elseif ('background' == $type) {
        $value = spyropress_clean_array($value);
        if (isset($value['background-color'])) {
            $value['background-color'] = spyropress_validate_setting($value['background-color'], 'colorpicker', $field_id, $section);
        }
        if (isset($value['background-image']) || isset($value['background-pattern'])) {
            if (isset($value['background-image'])) {
                $value['background-image'] = spyropress_validate_setting($value['background-image'], 'upload', $field_id, $section);
            }
        }
    } elseif ('typography' == $type) {
        $value = spyropress_clean_array($value);
        // if using google fonts unset system fonts
        if (isset($value['use'])) {
            unset($value['font-family']);
            unset($value['font-style']);
            unset($value['font-weight']);
        } else {
            unset($value['font-google']);
            unset($value['font-google-variant']);
        }
        if (isset($value['color'])) {
            $value['color'] = spyropress_validate_setting($value['color'], 'colorpicker', $field_id, $section);
        }
        if (isset($value['font-size']) && $value['font-size'] == '0px') {
            unset($value['font-size']);
        }
        if (isset($value['line-height']) && $value['line-height'] == '0px') {
            unset($value['line-height']);
        }
        if (isset($value['letter-spacing']) && $value['letter-spacing'] == '0px') {
            unset($value['letter-spacing']);
        }
        if (!isset($value['text-shadowcolor']) || $value['text-shadowcolor'] == '') {
            unset($value['text-hshadow']);
            unset($value['text-vshadow']);
            unset($value['text-blur']);
            unset($value['text-shadowcolor']);
        }
    } elseif ('border' == $type) {
        $heads = array('top', 'right', 'bottom', 'left');
        foreach ($heads as $h) {
            // if empty unset
            if ($value[$h] == '0px' || empty($value[$h]) || empty($value[$h . '-style']) || empty($value[$h . '-color'])) {
                unset($value[$h]);
                unset($value[$h . '-style']);
                unset($value[$h . '-color']);
            } else {
                $value[$h . '-style'] = spyropress_validate_setting($value[$h . '-style'], 'text', $field_id, $section);
                $value[$h . '-color'] = spyropress_validate_setting($value[$h . '-color'], 'colorpicker', $field_id, $section);
            }
        }
    } elseif ('padder' == $type) {
        foreach ($value as $k => $v) {
            if ($v == '0px') {
                unset($value[$k]);
            }
        }
    } elseif ('colorpicker' == $type) {
        $value = stripslashes(sanitize_text_field($value));
        $value = str_replace('#', '', $value);
        if (!is_str_starts_with('rgb', $value)) {
            $value = '#' . $value;
        }
    } elseif ('textarea' == $type) {
        $value = stripslashes($value);
    } elseif (in_array($type, array('css', 'text', 'editor'))) {
        $value = stripslashes(wp_kses_post($value));
    } elseif (in_array($type, array('upload', 'datepicker', 'hidden', 'range_slider'))) {
        $value = stripslashes(sanitize_text_field($value));
    }
    return $value;
}