Ejemplo n.º 1
0
 public static function get_instance()
 {
     if (!self::$instance) {
         self::$instance = new EPL_Init();
     }
     return self::$instance;
 }
function epl_activate()
{
    require_once dirname(__FILE__) . '/application/config/install_defaults.php';
    update_option('events_planner_version', EPL_PLUGIN_VERSION);
    update_option('events_planner_active', 1);
    global $default_vals, $wpdb;
    foreach ($default_vals as $key => $data) {
        /* check for option then update if necessary */
        if (!get_option($key)) {
            add_option($key, $data);
        }
    }
    //need to make WP aware of EP CPTs before flushing rules. Otherwise won't work.
    require_once 'system/epl-base.php';
    require_once 'system/epl-init.php';
    require_once 'application/helpers/common-helper.php';
    $init = new EPL_Init();
    $init->create_post_types();
    flush_rewrite_rules();
    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    $init->register_tables();
    $tables = $init->tables();
    foreach ($tables as $table) {
        dbDelta($table);
    }
    $uploads = wp_upload_dir();
    $epl_dir = $uploads['basedir'] . '/epl_uploads';
    if (!is_dir($epl_dir) && is_writable($uploads['basedir'])) {
        mkdir($epl_dir, 0755);
        file_put_contents($uploads['basedir'] . '/epl_uploads/.htaccess', 'deny from all');
        file_put_contents($uploads['basedir'] . '/epl_uploads/index.html', '');
    }
    //wp_schedule_event( time() + 100, 'hourly', 'epl_hourly_cron' );
}
function epl_hourly_cron()
{
    EPL_Init::get_instance()->cron();
}
Ejemplo n.º 4
0
 /**
  * Create a form field
  *
  * @param array $args (input_type,name, value, id, options, opt_key,opt_value, multiple, label, description, class, wrapper, size,readonly, multiple, size, $style)
  *
  * @return form field
  */
 function create_element($args = array(), $response_view = 0)
 {
     if (empty($args)) {
         return null;
     }
     $response_veiws = array('', 'common/form-table-row', 'common/form-table-cell');
     //views used for returning the fields
     $defaults = array('input_type' => '', 'input_name' => '', 'input_slug' => '', 'return' => 1, 'name' => '', 'key' => '', 'second_key' => '', 'auto_key' => false, 'value' => null, 'placeholder' => '', 'default_value' => null, 'default_checked' => false, 'force_uncheck' => false, 'id' => '', 'options' => '', 'empty_options_msg' => '', 'empty_row' => false, 'opt_key' => '', 'opt_value' => '', 'label' => '', 'description' => '', 'help_text' => '', 'help_icon_type' => '', 'class' => '', 'rel' => '', 'wrapper' => '', 'size' => '', 'readonly' => false, 'required' => 0, 'validation' => '', 'multiple' => false, 'style' => '', 'content' => '', 'display_inline' => false, 'overview' => 0, 'tmp_key' => '', 'data_type' => '', '__func' => '', 'weight' => 0, 'show_value_only' => false, 'data_id' => null, 'data_attr' => array());
     $args = wp_parse_args($args, $defaults);
     if (EPL_IS_ADMIN && epl_get_element_m('active', $args['input_slug'], $this->override_fields, 10) != 10) {
         return null;
     }
     $args['label'] = epl_get_element_m('label', $args['input_slug'], $this->override_fields, $args['label']);
     $args['help_text'] = epl_get_element_m('help_text', $args['input_slug'], $this->override_fields, $args['help_text']);
     extract($args);
     if ($return == 0) {
         return null;
     }
     $value = stripslashes_deep($value == '' && !is_null($default_value) ? $default_value : $value);
     //all the values come in as strings.  For cbox, radio and selects,
     //the options loop key is numeric.  I am doing a cast comparison so
     //string 0 != int 0, lots of issues.
     //NEW issue:  phone number is converted to int if it comes in 5557778888
     $value = is_numeric($value) && $value < 1000 && ($data_type == 'int' || $data_type != 'float') ? (int) $value : $value;
     $data = array('label' => '', 'description' => '', 'response_view' => $response_view, 'input_type' => $input_type, 'overview' => '', 'weight' => $weight);
     $name = $input_name != '' ? $input_name : $name;
     //Doing this for the very first key of the a new record.
     //Since we want to keep track of keys for registration purposes,
     //leaving [] will make the key assignment automatic, creating problems when deleting or adding.moving records.
     $name = ($input_type == 'text' || $input_type == 'hidden' || $input_type == 'select' || $input_type == 'textarea') && $key === '' ? str_replace("[]", "[{$tmp_key}]", $name) : $name;
     //if a text field has already been saved with a key, assign the key to the name
     if ($key !== '' && ($input_type == 'text' || $input_type == 'hidden' || $input_type == 'select' || $input_type == 'textarea')) {
         $name = str_replace("[", "[" . $key, $name);
         $value = html_entity_decode(epl_get_element($key, $value));
     }
     // TODO -  why stripslashes here and above?
     if (!is_numeric($value)) {
         $value = stripslashes_deep($value);
     }
     //echo "<pre class='prettyprint'>" . __LINE__ . '> ' . print_r($value, true). "</pre>";
     if ($readonly != false && !$overview) {
         $readonly = 'readonly="readonly"';
         if ($input_type == 'checkbox') {
             //$readonly .= ' disabled="disabled"';
             $style .= "visibility:hidden;";
         }
         if ($input_type == 'radio') {
             $readonly = ' disabled="disabled"';
             $style .= "visibility:hidden;";
         }
     }
     if ($size != '') {
         $size = "size='{$size}'";
     }
     if ($multiple != false) {
         $multiple = 'multiple="multiple"';
         $size = $size != '' ? "size='{$size}'" : "size='5'";
         //default size needed for wordpress
         $style .= " height:auto !important;";
         //override wp height
     }
     if ($required != 0) {
         $required = '<em>*</em>';
         $class .= ' required';
     } else {
         $required = '';
     }
     if ($validation != '') {
         $class .= ' ' . $validation;
     }
     if ($input_type == 'datepicker') {
         $class .= ' datepicker';
     }
     $data_attr = $this->make_data_attr($data_attr);
     //if ( $help_text != '' && $label != $help_text )
     //  $help_text = "class='help_tooltip_trigger' original-title='" . $help_text . "'";
     if ($label != '' || $response_view == 2) {
         $data['label_text'] = stripslashes_deep($label);
         $data['label'] = "<label for='{$id}'>" . $data['label_text'] . "{$required}</label>";
     }
     if ($description != '' || $response_view == 2) {
         $data['description'] = "<span class='description'>{$description}</span>";
     }
     if ($help_text != '') {
         $data['label'] .= "<img src='" . EPL_FULL_URL . "images/information-balloon{$help_icon_type}.png' class='help_tooltip_trigger' original-title='" . $help_text . "'>";
     }
     $class = trim($class);
     $data_id = epl_wrap($data_id, " data-id='", "'");
     $data['field'] = '';
     switch ($input_type) {
         case 'section':
             $data['response_view'] = 8;
             $data['field'] = "<div id=\"{$id}\"  class=\"{$class}\" style=\"font-size:16px;\">{$content}</div> \n";
             break;
         case 'datepicker':
             $input_type = 'text';
             EPL_Init::get_instance()->load_datepicker_files();
         case 'text':
             $data['overview'] = $value;
             $value = esc_attr($value);
         case 'hidden':
         case 'password':
         case 'submit':
             if ($__func != '') {
                 if (function_exists($__func)) {
                     $value = $__func($value);
                 }
             }
             $data['field'] = "<input type=\"{$input_type}\" id=\"{$id}\" name=\"{$name}\" class=\"{$class}\" rel=\"{$rel}\" placeholder=\"{$placeholder}\" style=\"{$style}\" {$size} value=\"{$value}\" {$readonly} {$data_id} {$data_attr} /> \n";
             $data['value'] = $value;
             break;
         case 'textarea':
             if ($__func != '') {
                 if (function_exists($__func)) {
                     $value = $__func($value);
                 }
             }
             $data['overview'] = $value;
             $value = esc_attr($value);
             $data['field'] = "<textarea cols = '60' rows='3' id='{$id}' name='{$name}'  class='{$class}'  style='{$style}' {$data_attr}>{$value}</textarea> \n";
             $data['value'] = $value;
             break;
             /* separated out cb and radio, easier to manage */
         /* separated out cb and radio, easier to manage */
         case 'table_checkbox':
             $data['response_view'] = 'table_checkbox';
         case 'checkbox':
             if ($default_checked == 1) {
                 $checked = ' checked = "checked"';
             }
             $display_inline = $display_inline ? '' : '<br />';
             $data['table_checkbox'] = array();
             if (is_array($options) && !empty($options)) {
                 foreach ($options as $k => $v) {
                     $v = stripslashes(html_entity_decode($v));
                     if (isset($this->override_fields[$args['input_slug']])) {
                         $v = epl_get_element_m($k, 'options', $this->override_fields[$args['input_slug']], $v);
                     }
                     $checked = '';
                     if ($default_checked == 1 && ($value === '' || is_null($value))) {
                         $checked = 'checked = "checked"';
                     } elseif ($k === $value || is_array($value) && in_array(strval($k), $value, true) || epl_is_multi_array($value) && in_array(strval($k), epl_get_element($key, $value, array()), true)) {
                         $checked = 'checked = "checked"';
                     }
                     if ($force_uncheck) {
                         $checked = '';
                     }
                     if ($checked != '') {
                         $data['overview'] .= " {$v}  \n" . $display_inline;
                     }
                     $_name = $name;
                     if (!$auto_key && strpos($name, '[') !== false) {
                         $_name = str_replace("[", "[" . ($key != '' ? $key : $tmp_key), $name);
                     }
                     if ($second_key != '') {
                         $second_key = "[{$k}]";
                     }
                     $data['field'] .= "<input type=\"checkbox\" id=\"{$id}\" name=\"{$_name}{$second_key}\"  class=\"{$class}\"  style='{$style}' value=\"{$k}\" {$checked} {$readonly} {$data_id} {$data_attr} /> {$v} \n" . $display_inline;
                     $data['table_checkbox'][$k]['f'] = "<input type=\"checkbox\" id=\"{$id}\" name=\"{$_name}{$second_key}\"  class=\"{$class}\"  style='{$style}' value=\"{$k}\" {$checked} {$readonly} {$data_id} {$data_attr}/> \n";
                     $data['table_checkbox'][$k]['l'] = "{$v} \n";
                 }
             } else {
                 $checked = isset($k) && $value == '' && in_array($k, (array) $value, true) ? 'checked = "checked"' : '';
                 $data['field'] .= "<input type=\"checkbox\" id=\"{$name}\" name=\"{$name}\"  class=\"{$class}\"  style='{$style}' value=\"1\" {$checked} {$data_id} {$data_attr} /> \n" . $display_inline;
                 $data['overview'] .= " {$value}  \n" . $display_inline;
             }
             break;
         case 'radio':
             $display_inline = $display_inline ? '' : '<br />';
             if (is_array($options) && !empty($options)) {
                 foreach ($options as $k => $v) {
                     $v = stripslashes(html_entity_decode($v));
                     if (isset($this->override_fields[$args['input_slug']])) {
                         $v = epl_get_element_m($k, 'options', $this->override_fields[$args['input_slug']], $v);
                     }
                     $checked = '';
                     if ($default_checked == 1 && ($value === '' || is_null($value))) {
                         $checked = 'checked = "checked"';
                     } elseif (is_array($value) && in_array((string) $k, $value, true) || !is_array($value) && (string) $value === (string) $k) {
                         $checked = 'checked = "checked"';
                     }
                     if ($checked != '') {
                         $data['overview'] = " {$v}  \n" . $display_inline;
                     }
                     $data['field'] .= "<input type=\"{$input_type}\" id=\"{$id}\" name=\"{$name}\"  class=\"{$class}\"  style='{$style}' value=\"{$k}\" {$checked} {$readonly} {$data_id} {$data_attr} /> {$v}  \n" . $display_inline;
                 }
             } else {
                 $checked = in_array($k, (array) $value, true) ? 'checked = "checked"' : '';
                 $data['field'] .= "<input type=\"{$input_type}\" id=\"{$name}\" name=\"{$name}\"  class=\"{$class}\"  style='{$style}' value=\"1\" {$checked} {$data_id} {$data_attr} /> \n" . $display_inline;
                 $data['overview'] .= " {$v}  \n" . $display_inline;
             }
             break;
         case 'radio-switch':
             //will investigate using this in dynamic table fields.
             //$tmp_key = $this->make_unique_id(7);
             $display_inline = '';
             //$display_inline ? '' : '<br />';
             if (is_array($options) && !empty($options)) {
                 $counter = 1;
                 foreach ($options as $k => $v) {
                     $v = stripslashes(html_entity_decode($v));
                     if (isset($this->override_fields[$args['input_slug']])) {
                         $v = epl_get_element_m($k, 'options', $this->override_fields[$args['input_slug']], $v);
                     }
                     $checked = '';
                     if ($default_checked == 1 && ($value === '' || is_null($value))) {
                         $checked = 'checked = "checked"';
                     } elseif ((string) $k === (string) $value || is_array($value) && in_array((string) $k, $value, true)) {
                         $checked = 'checked = "checked"';
                     }
                     if ($checked != '') {
                         $data['overview'] = " {$v}  \n" . $display_inline;
                     }
                     $id = $k . str_replace(array('[', ']'), '', $name) . $tmp_key;
                     //using tmp key for dynamic rows.
                     $data['field'] .= "<input type=\"radio\" id=\"{$id}\" name=\"{$name}\" value=\"{$k}\" {$checked} {$readonly} {$data_id} {$data_attr} /><label for=\"{$id}\" onclick=\"\">{$v}</label>";
                 }
             }
             $data['field'] = '<div class="switch-toggle candy yellow">' . $data['field'] . '<a></a></div>';
             break;
         case 'select':
             if (!epl_is_empty_array($options)) {
                 $select = "<select name = '{$name}' id = '{$id}' class='{$class}' style='{$style}' {$multiple} {$size} {$readonly} {$data_id} {$data_attr}>";
                 if ($empty_row) {
                     $select .= "<option></option>  \n";
                 }
                 foreach ((array) $options as $k => $v) {
                     $v = stripslashes(html_entity_decode($v));
                     if (isset($this->override_fields[$args['input_slug']])) {
                         $v = epl_get_element_m($k, 'options', $this->override_fields[$args['input_slug']], $v);
                     }
                     $selected = is_array($value) && in_array((string) $k, $value) || !is_array($value) && (string) $value === (string) $k ? "selected = 'selected'" : '';
                     if ($show_value_only && $selected == '') {
                         continue;
                     }
                     $select .= "<option value='{$k}' {$selected}>{$v}</option>";
                     if ($selected != '') {
                         $data['overview'] = " {$v}  \n";
                     }
                 }
                 $data['field'] = $select . "</select>";
             } else {
                 $data['field'] = $empty_options_msg;
             }
             $data['value'] = $v;
             break;
     }
     if ($overview) {
         //echo "<br />OVERVIEW2 " . $data['overview'] . "<br >";
         $data['field'] = "<div class='overview_value' style='{$style}'>" . $data['overview'] . '</div>';
         unset($data['overview']);
     }
     if ($data['response_view'] === 0 || $data['response_view'] == 'raw') {
         return $data;
     }
     $r = $this->epl->load_view('common/form-field-view', $data, true);
     return $r;
 }