private function _set_custom_fields() { $WJ_Field = new WJ_Field(); $_custom_fields = $WJ_Field->get_all(); if (!empty($_custom_fields)) { foreach ($_custom_fields as $key => &$row) { $this->_custom_fields['cf_' . $row->id] = $row; } } }
function refresh_columns() { $WJ_Field = new WJ_Field(); $custom_fields = $WJ_Field->get_all(); if (!empty($custom_fields)) { foreach ($custom_fields as $row) { $this->columns['cf_' . $row->id] = array(); } } }
function getFields() { $fields = array(); // add custom fields $WJ_Field = new WJ_Field(); $custom_fields = $WJ_Field->get_all(); if (!empty($custom_fields)) { foreach ($custom_fields as $row) { $fields['cf_' . $row->id] = $row->name; } } return array_merge($this->defaults, $fields); }
function importmatch($data) { ?> <form class="form-valid" action="admin.php?page=wysija_subscribers&action=lists" id="wysija-edit" method="post" name="wysija-edit"> <div class="list" style="overflow:auto"> <table cellspacing="0" class="widefat fixed" > <thead> <tr class="thead"> <th id="first-row"><?php _e('Match data', WYSIJA); ?> </th> <?php $columns = array('nomatch' => __('Ignore column...', WYSIJA), 'email' => __('Email', WYSIJA), 'firstname' => __('First name', WYSIJA), 'lastname' => __('Last name', WYSIJA), 'ip' => __('IP address', WYSIJA), 'status' => __('Status', WYSIJA)); $WJ_Field = new WJ_Field(); $custom_fields = $WJ_Field->get_all(); $extended_columns = array(); if (!empty($custom_fields)) { foreach ($custom_fields as $row) { $extended_columns['cf_' . $row->id] = $row->name; } } $helper_form = WYSIJA::get('forms', 'helper'); $i = 0; $email_column_matched = false; $this->new_column_can_be_imported = array(); $data['csv'][0] = array_map('trim', $data['csv'][0]); foreach ($data['csv'][0] as $column_key => $column_name) { $selected = ''; $columns_array = $columns; // we make a key out of the column name $column_name_key = str_replace(array(' ', '-', '_'), '', strtolower($column_name)); // we try to automatically match columns with previous matches recorded in the past $import_fields = get_option('wysija_import_fields'); if (isset($import_fields[$column_name_key]) && substr($import_fields[$column_name_key], 0, 10) != 'new_field|') { $selected = $import_fields[$column_name_key]; } else { // we're making the matches dropdown with an extra value 'Import as "name of the column"' // since we didn't detect it in the previously matched columns $columns_array = array(); foreach ($columns as $col_key => $col_val) { // we need to put that extra value right after the ignore column value if (count($columns_array) === 1) { $column_name = preg_replace('|[^a-z0-9#_.-]|i', '', $column_name); $columns_array['new_field|input|' . $column_name] = sprintf(__('Import as "%1$s"', WYSIJA), $column_name); $columns_array['new_field|date|' . $column_name] = sprintf(__('Import "%1$s" as date field', WYSIJA), $column_name); $this->new_column_can_be_imported[$column_key] = true; } else { $columns_array[$col_key] = $col_val; } } } // if it is an email column we set it by default as email if (!$email_column_matched && isset($data['keyemail'][$column_key])) { $selected = 'email'; $email_column_matched = true; $columns_array = $columns; } $columns_array = array_map('trim', array_merge($columns_array, $extended_columns)); // we're building one dropdown per column $dropdown = '<div class="match-dropdown">' . $helper_form->dropdown(array('id' => 'column-match-' . $i, 'name' => 'wysija[match][' . $i . ']', 'class' => 'create_extra row-' . $column_key), $columns_array, $selected) . '</div>'; /** * We need to improve the import, fields come back to options for columns later on. if (isset($this->new_column_can_be_imported[$column_key])) { $dropdown .= '<div class="import-new-field" id="column-match-date-wrap-'.$i.'"><input id="column-match-date-'.$i.'" type="checkbox" name="wysija[ignore_invalid_date]['.$i.']"\><label for="column-match-date-'.$i.'">' . __('Ignore invalid dates', WYSIJA) . '</label></div>'; } */ echo '<th>' . $dropdown . '</th>'; $i++; } ?> </tr> </thead> <tbody class="list:<?php echo $this->model->table_name . ' ' . $this->model->table_name . '-list" id="wysija-' . $this->model->table_name . '"'; ?> > <?php $listingRows = ''; $alt = true; $i = 0; foreach ($data['csv'] as $columns) { $classRow = ''; if ($alt) { $classRow = ' class="alternate" '; } echo "<tr {$classRow}>"; if (isset($data['firstrowisdata'])) { $j = $i + 1; } else { $j = $i; } if ($i == 0) { $valuefrow = ''; if (isset($data['firstrowisdata'])) { $valuefrow = '1<input value="1" type="hidden" id="firstrowdata" name="firstrowisdata" />'; } echo '<td>' . $valuefrow . '</td>'; //echo '<td><label for="firstrowdata" class="title" title="'.__("This line is not a header description, it is data and needs to be inserted!",WYSIJA).'"><input '.$checked.' type="checkbox" id="firstrowdata" name="firstrowisdata" />'.__("Insert line!",WYSIJA).'</label></td>'; } else { echo '<td>' . $j . '</td>'; } foreach ($columns as $key_col => $val) { $val = esc_html($val); if ($i == 0 && !isset($data['firstrowisdata'])) { echo '<td><strong>' . $val . '</strong></td>'; } else { if (!empty($this->new_column_can_be_imported[$key_col])) { $timestamp = strtotime($val); if ($timestamp > 0) { $val_converted = '<span class="converted-field-to-date row-' . $key_col . '" title="' . __('Verify that the date in blue matches the original one.', WYSIJA) . '">' . date(get_option('date_format') . ' ' . get_option('time_format'), $timestamp) . '</span>'; } else { $val_converted = '<span class="converted-field-error row-' . $key_col . '" title="' . __('Do not match as a \'date field\' if most of the rows for that column return the same error.', WYSIJA) . '">' . __('Error matching date.', WYSIJA) . '</span>'; } $val = ' <span class="imported-field">' . $val . '</span>' . $val_converted; } echo '<td>' . $val . '</td>'; } } echo '</tr>'; $alt = !$alt; $i++; } if ($data['totalrows'] > 3) { ?> <tr class="alternate" > <?php echo '<td>...</td>'; foreach ($data['csv'][0] as $col) { echo '<td>...</td>'; } ?> </tr> <tr><td><?php echo $data['totalrows']; ?> </td> <?php foreach ($data['lastrow'] as $key_col => $val) { $val = esc_html($val); if (!empty($this->new_column_can_be_imported[$key_col])) { $timestamp = strtotime($val); if ($timestamp > 0) { $val_converted = '<span class="converted-field-to-date row-' . $key_col . '" title="' . __('Verify that the date in blue matches the original one.', WYSIJA) . '">' . date(get_option('date_format') . ' ' . get_option('time_format'), $timestamp) . '</span>'; } else { $val_converted = '<span class="converted-field-error row-' . $key_col . '" title="' . __('Do not match as a \'date field\' if most of the rows for that column return the same error.', WYSIJA) . '">' . __('Error matching date.', WYSIJA) . '</span>'; } $val = ' <span class="imported-field">' . $val . '</span>' . $val_converted; } echo '<td>' . $val . '</td>'; } ?> </tr> <?php } ?> </tbody> </table> </div> <?php if ($data['errormatch']) { } else { ?> <table class="form-table"> <tbody> <tr> <th scope="row"> <label for="name"><?php _e('Pick one or many lists', WYSIJA); ?> </label> <p class="description"><?php _e('Pick the lists you want to import those subscribers to.', WYSIJA); ?> </p> </th> <td> <?php //create an array of existing lists to import within $model_list = WYSIJA::get('list', 'model'); $lists = $model_list->get(array('name', 'list_id'), array('is_enabled' => 1)); //first value is to create new list $lists[] = array('name' => __('New list', WYSIJA), 'list_id' => 0); //create an array of active(status 99) follow_up emails aossicated to a list_id $helper_email = WYSIJA::get('email', 'helper'); $follow_ups_per_list = $helper_email->get_active_follow_ups(array('subject', 'params')); $follow_up_name_per_list = array(); foreach ($follow_ups_per_list as $list_id => $follow_ups) { if (!isset($follow_up_name_per_list[$list_id])) { $follow_up_name_per_list[$list_id] = array(); } foreach ($follow_ups as $follow_up) { $follow_up_name_per_list[$list_id][] = $follow_up['subject']; } } $helper_form = WYSIJA::get('forms', 'helper'); //field name for processing $field = 'list'; $fieldHTML = '<div>'; foreach ($lists as $list) { if ($list['list_id'] == 0) { $fieldHTML .= '<p><label for="' . $field . $list['list_id'] . '">'; $fieldHTML .= $helper_form->checkbox(array('class' => 'validate[minCheckbox[1]] checkbox', 'id' => $field . $list['list_id'], 'name' => "wysija[user_list][{$field}][]"), $list['list_id']) . '<span>' . $list['name'] . '</span>'; $fieldHTML .= '</label> '; $fieldHTML .= '<span id="blocknewlist">' . $helper_form->input(array('class' => 'validate[required]', 'id' => 'namenewlist', 'size' => 30, 'name' => 'wysija[list][newlistname]', 'value' => __('Type name of your new list', WYSIJA))) . '</span></p>'; } else { $fieldHTML .= '<p><label for="' . $field . $list['list_id'] . '">' . $helper_form->checkbox(array('class' => 'validate[minCheckbox[1]] checkbox', 'id' => $field . $list['list_id'], 'name' => "wysija[user_list][{$field}][]"), $list['list_id']) . $list['name']; if (isset($follow_up_name_per_list[$list['list_id']])) { $fieldHTML .= ' <span style="margin-left:10px;"><strong>' . __('Note:', WYSIJA) . ' </strong>' . sprintf(__('subscribers will receive "%1$s" after import.', WYSIJA), implode(', ', $follow_up_name_per_list[$list['list_id']])) . '</span>'; } $fieldHTML .= '</label></p>'; } } $fieldHTML .= '</div>'; echo $fieldHTML; ?> </td> </tr> </tbody> </table> <p class="submit"> <?php $this->secure(array('action' => 'import_save')); ?> <input type="hidden" value="<?php echo esc_attr($data['dataImport']); ?> " name="wysija[dataImport]" /> <input type="hidden" value="import_save" name="action" /> <input type="submit" value="<?php echo esc_attr(__('Import', WYSIJA)); ?> " class="button-primary wysija"> </p> <?php } ?> </form> <?php }
public static function get_all($user_id) { $fields = WJ_Field::get_all(); if (isset($fields) && !empty($fields)) { $collection = array(); foreach ($fields as $field) { $user_field = new self(); $user_field->user_id = $user_id; $user_field->field = $field; $collection[] = $user_field; } return $collection; } else { return null; } }
public function get_custom_fields() { if ($this->_fields === null) { // get available custom fields $custom_fields = WJ_Field::get_all(array('order_by' => 'name ASC')); $user_fields = array(); if (!empty($custom_fields)) { foreach ($custom_fields as $custom_field) { $user_fields[] = array('field_id' => $custom_field->id, 'name' => $custom_field->name, 'column_name' => $custom_field->user_column_name(), 'column_type' => $custom_field->type, 'params' => $custom_field->settings); } } // we need to figure out the default list for the "List selection" widget $lists = $this->get_lists(); // select default list $default_list = array(); if (!empty($lists)) { $default_list[] = array('list_id' => $lists[0]['list_id'], 'is_checked' => 0); } // extra widgets that can be added more than once $extra_fields = array(array('name' => __('Divider', WYSIJA), 'column_name' => 'divider', 'column_type' => 'divider'), array('name' => __('First name', WYSIJA), 'column_name' => 'firstname', 'column_type' => 'input'), array('name' => __('Last name', WYSIJA), 'column_name' => 'lastname', 'column_type' => 'input'), array('name' => __('List selection', WYSIJA), 'column_name' => 'list', 'column_type' => 'list', 'params' => array('label' => __('Select list(s):', WYSIJA), 'values' => $default_list)), array('name' => __('Random text or HTML', WYSIJA), 'column_name' => 'html', 'column_type' => 'html', 'params' => array('text' => __('Subscribe to our newsletter and join our [total_subscribers] subscribers.', WYSIJA)))); // set data to be passed to the view $this->_fields = array_merge($user_fields, $extra_fields); } return $this->_fields; }
private function using_custom_fields() { $fields = WJ_Field::get_all(); if ($fields != null) { $result = 'Yes'; } else { $result = 'No'; } return $result; }
/** * @see OptimizePress_Modules_Email_ProviderInterface::getListFields() */ public function getListFields($listId) { $fields = array('firstname' => __('First Name', 'optimizepress'), 'lastname' => __('Last Name', 'optimizepress')); $customFields = WJ_Field::get_all(array('order_by' => 'name ASC')); if (!empty($customFields)) { foreach ($customFields as $customField) { $fields[$customField->user_column_name()] = $customField->name; } } $this->logger->info("Fields (MailPoet): " . print_r($fields, true)); return $fields; }