function _slug($field) { if ($this->edit_slug()) { return true; } if (!empty($this->slug) && $this->slug !== '__generate__') { return true; } $this->load->helper(array('url', 'text', 'string')); $slug = reduce_multiples(strtolower(url_title(convert_accented_characters($this->title), 'dash')), '-', true); if (empty($slug)) { $t = new Album(); $max = $t->select_max('id')->get(); $slug = $max->id + 1; } if (is_numeric($slug)) { $slug = "{$slug}-1"; } $s = new Slug(); while ($s->where('id', "album.{$slug}")->count() > 0) { $slug = increment_string($slug, '-'); } $this->db->query("INSERT INTO {$s->table}(id) VALUES ('album.{$slug}')"); $this->slug = $slug; }
public function name_to_url($name, $id) { /* BENCHMARK */ $this->benchmark->mark('func_name_to_url_start'); // convert, remove all chars apart from alphanumeric and hyphen, and do some other stuff $name_to_url = strtolower(str_replace("--", "-", str_replace(" ", "-", preg_replace("/[^0-9a-z ]+/i", "", trim(stripslashes($name)))))); // look for this url $query = $this->db->select('*')->from('node')->where(array('id !=' => $id, 'url' => $name_to_url)); $res = $query->get(); $result = $res->result_array(); // check if its unique, if not we need to add something if (count($result)) { // get all with this url $result = $this->node_model->get_nodes(array('name' => $name), null, 'url desc'); // add the suffix $this->load->helper('string'); $name_to_url = increment_string($result[0]['url']); } // remove a hiphen off the end if the replace stuff has left a trailing hyphen if (0 === strpos(strrev($name_to_url), '-')) { $name_to_url = substr($name_to_url, 0, -1); } return $name_to_url; /* BENCHMARK */ $this->benchmark->mark('func_name_to_url_end'); }
public function test_increment_string() { $this->assertEquals('my-test_1', increment_string('my-test')); $this->assertEquals('my-test-1', increment_string('my-test', '-')); $this->assertEquals('file_5', increment_string('file_4')); $this->assertEquals('file-5', increment_string('file-4', '-')); $this->assertEquals('file-5', increment_string('file-4', '-')); $this->assertEquals('file-1', increment_string('file', '-', '1')); $this->assertEquals(124, increment_string('123', '')); }
function _slug($field) { if ($this->edit_slug()) { return true; } if (!empty($this->old_slug)) { return true; } $this->load->helper(array('url', 'text', 'string')); if (empty($this->title)) { $info = pathinfo($this->filename); $base = $info['filename']; } else { $base = $this->title; } $slug = reduce_multiples(strtolower(url_title(convert_accented_characters($base), 'dash')), '-', true); if ($slug === $this->slug) { return true; } if (empty($slug)) { $t = new Content(); $max = $t->select_max('id')->get(); $slug = $max->id + 1; } if (is_numeric($slug)) { $slug = "{$slug}-1"; } $s = new Slug(); // Need to lock the table here to ensure that requests arriving at the same time // still get unique slugs if ($this->has_db_permission('lock tables')) { $this->db->query("LOCK TABLE {$s->table} WRITE"); $locked = true; } else { $locked = false; } while ($s->where('id', "content.{$slug}")->count() > 0) { $slug = increment_string($slug, '-'); } $this->db->query("INSERT INTO {$s->table}(id) VALUES ('content.{$slug}')"); if ($locked) { $this->db->query('UNLOCK TABLES'); } if (empty($this->old_slug)) { if (!empty($this->slug) && $this->slug !== '__generate__') { $this->old_slug = ',' . $this->slug . ','; } else { if (!empty($this->title)) { $this->old_slug = ',' . $slug . ','; } } } $this->slug = $slug; }
/** * Duplicate a page * * @param int $id The ID of the page * @param null $parent_id The ID of the parent page, if this is a recursive nested duplication */ public function duplicate($id, $parent_id = null) { $page = (array) $this->page_m->get($id); // Steal their children $children = $this->page_m->get_many_by('parent_id', $id); $new_slug = $page['slug']; // No parent around? Do what you like if (is_null($parent_id)) { do { // Turn "Foo" into "Foo 2" $page['title'] = increment_string($page['title'], ' ', 2); // Turn "foo" into "foo-2" $page['slug'] = increment_string($page['slug'], '-', 2); // Find if this already exists in this level $dupes = $this->page_m->count_by(array('slug' => $page['slug'], 'parent_id' => $page['parent_id'])); } while ($dupes > 0); } else { $page['parent_id'] = $parent_id; } $page['restricted_to'] = null; $page['navigation_group_id'] = 0; foreach ($page['chunks'] as $chunk) { $page['chunk_slug'][] = $chunk['slug']; $page['chunk_class'][] = $chunk['class']; $page['chunk_type'][] = $chunk['type']; $page['chunk_body'][] = $chunk['body']; } $new_page = $this->page_m->create($page); foreach ($children as $child) { $this->duplicate($child->id, $new_page); } redirect('admin/pages'); }
/** * Duplicate a page * @access public * @param int $id The ID of the page * @param int $id The ID of the parent page, if this is a recursive nested duplication * @return void */ public function duplicate($id, $parent_id = null) { $page = $this->page_m->get($id); // Steal their children $children = $this->page_m->get_many_by('parent_id', $id); $new_slug = $page->slug; // No parent around? Do what you like if (is_null($parent_id)) { do { // Turn "Foo" into "Foo 2" $page->title = increment_string($page->title, ' ', 2); // Turn "foo" into "foo-2" $page->slug = increment_string($page->slug, '-', 2); // Find if this already exists in this level $dupes = $this->page_m->count_by(array('slug' => $page->slug, 'parent_id' => $page->parent_id)); } while ($dupes > 0); } else { $page->parent_id = $parent_id; } $chunks = $this->db->get_where('page_chunks', array('page_id' => $page->id))->result(); $new_page_id = $this->page_m->insert((array) $page, $chunks); foreach ($children as $child) { $this->duplicate($child->id, $new_page_id); } if ($parent_id === NULL) { redirect('admin/pages/edit/' . $new_page_id); } }
/** * Duplicate a page * * @param int $id The ID of the page * @param null $parent_id The ID of the parent page, if this is a recursive nested duplication */ public function duplicate($id, $parent_id = null) { // We are going to get the page in a stripped down way since // we need to only get what is in the database, in order // to be able to duplicate it. $page_raw = $this->db->select('pages.*, page_types.stream_id as pt_stream_id')->join('page_types', 'page_types.id = pages.type_id')->limit(1)->where('pages.id', $id)->get('pages')->row_array(); $stream = $this->streams_m->get_stream($page_raw['pt_stream_id']); // Get entry $entry = $this->db->limit(1)->where('id', $page_raw['entry_id'])->get($stream->stream_prefix . $stream->stream_slug)->row_array(); unset($page_raw['pt_stream_id']); unset($page_raw['entry_id']); // We can merge because there are rules in place so no stream slugs // are the same as slugs in the pages table. $page = $page_raw + $entry; // Steal their children $children = $this->page_m->get_many_by('parent_id', $id); $new_slug = $page['slug']; // No parent around? Do what you like if (is_null($parent_id)) { do { // Turn "Foo" into "Foo 2" $page['title'] = increment_string($page['title'], ' ', 2); // Turn "foo" into "foo-2" $page['slug'] = increment_string($page['slug'], '-', 2); // Find if this already exists in this level $dupes = $this->page_m->count_by(array('slug' => $page['slug'], 'parent_id' => $page['parent_id'])); } while ($dupes > 0); } else { $page['parent_id'] = $parent_id; } $page['restricted_to'] = null; $page['navigation_group_id'] = 0; $page['is_home'] = false; $new_page = $this->page_m->create($page, $stream); foreach ($children as $child) { $this->duplicate($child->id, $new_page); } // only allow a redirect when everything is finished (only the top level page has a null parent_id) if (is_null($parent_id)) { redirect('admin/pages'); } }
/** * Create a new user, needs to interrupt the authentication flow to request specific details from the user * * @access public * @param object $access_token The users access token * @return void **/ protected function _create_user($access_token) { // Attempt the registration $_data = array(); $_data['email'] = $access_token->email; $_data['username'] = $access_token->email; $_data['password'] = NULL; $_data['li_id'] = $access_token->user_id; $_data['li_token'] = $access_token->access_token; $_data['auth_method_id'] = 'linkedin'; $_data['first_name'] = trim($access_token->first_name); $_data['last_name'] = trim($access_token->last_name); $_data['email_is_verified'] = TRUE; // Trust the email from LinkedIn // -------------------------------------------------------------------------- // Generate a username based on their name if (!empty($access_token->first_name) && !empty($access_token->last_name)) { // No handle, odd, try their name, keep trying it till it works $_data['username'] = url_title($access_token->first_name . ' ' . $access_token->last_name, '-', TRUE); $_user = $this->user_model->get_by_username($_data['username']); while ($_user) { $_data['username'] = increment_string(url_title($access_token->first_name . ' ' . $access_token->last_name, '-', TRUE), ''); $_user = $this->user_model->get_by_username($_data['username']); } } else { // Random string $_data['username'] = '******' . date('YmdHis'); $_user = $this->user_model->get_by_username($_data['username']); while ($_user) { $_data['username'] = increment_string($_data['username'], ''); $_user = $this->user_model->get_by_username($_data['username']); } } // -------------------------------------------------------------------------- // Handle referrals if ($this->session->userdata('referred_by')) { $_data['referred_by'] = $this->session->userdata('referred_by'); } // -------------------------------------------------------------------------- // Which group? // If there's a register_token set, use that if not fall back to the default if (!empty($this->_register_token['group'])) { $_data['group_id'] = $this->_register_token['group']; } else { $_data['group_id'] = $this->user_group_model->get_default_group_id(); } // Create new user $_new_user = $this->user_model->create($_data); if ($_new_user) { // Fetch group data $_group = $this->user_group_model->get_by_id($_data['group_id']); // -------------------------------------------------------------------------- // Send the user the welcome email (that is, if there is one) if ($_new_user->email) { $this->load->library('emailer'); $_email = new stdClass(); $_email->type = 'new_user_' . $_group->id; $_email->to_id = $_new_user->id; $_email->data = array(); $_email->data['method'] = 'linkedin'; if (!$this->emailer->send($_email, TRUE)) { // Failed to send using the group email, try using the generic email template $_email->type = 'new_user'; if (!$this->emailer->send($_email, TRUE)) { // Email failed to send, musn't exist, oh well. } } } // -------------------------------------------------------------------------- // Log the user in $this->user_model->set_login_data($_new_user->id); // -------------------------------------------------------------------------- // Create an event for this event create_event('did_register', $_new_user->id, 0, NULL, array('method' => 'linkedin')); // -------------------------------------------------------------------------- // Delete register token delete_cookie('liRegisterToken'); // -------------------------------------------------------------------------- // Redirect $this->session->set_flashdata('success', lang('auth_social_register_ok', $_new_user->first_name)); $this->session->set_flashdata('from_linkedin', TRUE); // Registrations will be forced to the registration redirect, regardless of // what else has been set if ($this->_register_use_return) { $_redirect = $this->_return_to; } else { $_redirect = $_group->registration_redirect ? $_group->registration_redirect : $_group->default_homepage; } $this->_redirect($_redirect); return; } }
function _slug($field) { if ($this->edit_slug()) { return true; } $this->load->helper(array('url', 'text', 'string')); $slug = reduce_multiples(strtolower(url_title(convert_accented_characters($this->title), 'dash')), '-', true); if (empty($slug)) { $t = new Text(); $max = $t->select_max('id')->get(); $slug = $max->id + 1; } if (is_numeric($slug)) { $slug = "{$slug}-1"; } if ($this->slug === $slug || !empty($this->slug) && $this->slug !== '__generate__') { return; } $s = new Slug(); // Need to lock the table here to ensure that requests arriving at the same time // still get unique slugs if ($this->has_db_permission('lock tables')) { $this->db->query("LOCK TABLE {$s->table} WRITE"); $locked = true; } else { $locked = false; } $page_type = is_numeric($this->page_type) ? $this->page_type : 0; $prefix = $page_type === 1 ? 'page' : 'essay'; while ($s->where('id', "{$prefix}.{$slug}")->count() > 0) { $slug = increment_string($slug, '-'); } $this->db->query("INSERT INTO {$s->table}(id) VALUES ('{$prefix}.{$slug}')"); if ($locked) { $this->db->query('UNLOCK TABLES'); } $this->slug = $slug; }
/** * Create a new user, needs to interrupt the authentication flow to request specific details from the user * * @access public * @param object $access_token The users access token * @return void **/ protected function _create_user($access_token) { // Fetch some information about this user $_me = (array) $this->tw->users_lookup('user_id=' . $access_token->user_id); // Try and determine the user's first name and surname if (isset($_me[0]->name)) { $this->data['first_name'] = trim(substr($_me[0]->name, 0, strpos($_me[0]->name, ' '))); $this->data['last_name'] = trim(substr($_me[0]->name, strpos($_me[0]->name, ' '))); } else { $this->data['first_name'] = ''; $this->data['last_name'] = ''; } // -------------------------------------------------------------------------- // Set the user's username as their Twitter handle, check it's available, if // it's not, try their name. If that fails stick a random number on the end // of their handle if (!empty($_me[0]->screen_name)) { // Check if their Twitter handle is available $this->data['username'] = url_title($_me[0]->screen_name, '-', TRUE); $_user = $this->user_model->get_by_username($this->data['username']); while ($_user) { $this->data['username'] = increment_string(url_title($_me[0]->screen_name, '-', TRUE), ''); $_user = $this->user_model->get_by_username($this->data['username']); } } elseif (!empty($_me[0]->name)) { // No handle, odd, try their name, keep trying it till it works $this->data['username'] = url_title($_me[0]->name, '-', TRUE); $_user = $this->user_model->get_by_username($this->data['username']); while ($_user) { $this->data['username'] = increment_string(url_title($_me[0]->name, '-', TRUE), ''); $_user = $this->user_model->get_by_username($this->data['username']); } } else { // Random string $this->data['username'] = '******' . date('YmdHis'); $_user = $this->user_model->get_by_username($this->data['username']); while ($_user) { $this->data['username'] = increment_string($this->data['username'], ''); $_user = $this->user_model->get_by_username($this->data['username']); } } // -------------------------------------------------------------------------- if ($this->input->post()) { // Validate the form and attempt the registration $this->load->library('form_validation'); // Set rules if (APP_NATIVE_LOGIN_USING == 'EMAIL') { $this->form_validation->set_rules('email', '', 'xss_clean|required|valid_email|is_unique[' . NAILS_DB_PREFIX . 'user_email.email]'); if ($this->input->post('username')) { $this->form_validation->set_rules('email', '', 'xss_clean|is_unique[' . NAILS_DB_PREFIX . 'user.username]'); } } elseif (APP_NATIVE_LOGIN_USING == 'USERNAME') { $this->form_validation->set_rules('username', '', 'xss_clean|required|is_unique[' . NAILS_DB_PREFIX . 'user.username]'); if ($this->input->post('email')) { $this->form_validation->set_rules('email', '', 'xss_clean|valid_email|is_unique[' . NAILS_DB_PREFIX . 'user_email.email]'); } } elseif (APP_NATIVE_LOGIN_USING == 'BOTH') { $this->form_validation->set_rules('email', '', 'xss_clean|required|valid_email|is_unique[' . NAILS_DB_PREFIX . 'user_email.email]'); $this->form_validation->set_rules('username', '', 'xss_clean|required|is_unique[' . NAILS_DB_PREFIX . 'user.username]'); } if (!$this->data['first_name'] || !$this->data['last_name']) { $this->form_validation->set_rules('first_name', '', 'xss_clean|required'); $this->form_validation->set_rules('last_name', '', 'xss_clean|required'); } // Set messages $this->form_validation->set_message('required', lang('fv_required')); if (APP_NATIVE_LOGIN_USING == 'EMAIL') { $this->form_validation->set_message('is_unique', lang('fv_email_already_registered', site_url('auth/forgotten_password'))); } elseif (APP_NATIVE_LOGIN_USING == 'USERNAME') { $this->form_validation->set_message('is_unique', lang('fv_username_already_registered', site_url('auth/forgotten_password'))); } elseif (APP_NATIVE_LOGIN_USING == 'BOTH') { $this->form_validation->set_message('is_unique', lang('fv_identity_already_registered', site_url('auth/forgotten_password'))); } // Execute if ($this->form_validation->run()) { $_data = array(); $_data['email'] = $this->input->post('email'); $_data['username'] = $this->input->post('username'); if (!$this->data['first_name'] || !$this->data['last_name']) { $_data['first_name'] = $this->input->post('first_name'); $_data['last_name'] = $this->input->post('last_name'); } else { $_data['first_name'] = $this->data['first_name']; $_data['last_name'] = $this->data['last_name']; } $_data['tw_id'] = $access_token->user_id; $_data['tw_token'] = $access_token->oauth_token; $_data['tw_secret'] = $access_token->oauth_token_secret; $_data['auth_method_id'] = 'twitter'; // -------------------------------------------------------------------------- // Handle referrals if ($this->session->userdata('referred_by')) { $_data['referred_by'] = $this->session->userdata('referred_by'); } // -------------------------------------------------------------------------- // Which group? // If there's a register_token set, use that if not fall back to the default if (isset($this->_register_token['group']) && $this->_register_token['group']) { $_data['group_id'] = $this->_register_token['group']; } else { $_data['group_id'] = $this->user_group_model->get_default_group_id(); } // Create new user $_new_user = $this->user_model->create($_data); if ($_new_user) { // Fetch group data $_group = $this->user_group_model->get_get_by_id($_data['group_id']); // -------------------------------------------------------------------------- // Send the user the welcome email (that is, if there is one) $this->load->library('emailer'); $_email = new stdClass(); $_email->type = 'new_user_' . $_group->id; $_email->to_id = $_new_user->id; $_email->data = array(); $_email->data['method'] = 'twitter'; if (!$this->emailer->send($_email, TRUE)) { // Failed to send using the group email, try using the generic email template $_email->type = 'new_user'; if (!$this->emailer->send($_email, TRUE)) { // Email failed to send, musn't exist, oh well. } } // -------------------------------------------------------------------------- // Log the user in $this->user_model->set_login_data($_new_user->id); // -------------------------------------------------------------------------- // Create an event for this event create_event('did_register', $_new_user->id, 0, NULL, array('method' => 'twitter')); // -------------------------------------------------------------------------- // Delete register token delete_cookie('twRegisterToken'); // -------------------------------------------------------------------------- // Redirect $this->session->set_flashdata('success', lang('auth_social_register_ok', $_new_user->first_name)); $this->session->set_flashdata('from_twitter', TRUE); // Registrations will be forced to the registration redirect, regardless of // what else has been set if ($this->_register_use_return) { $_redirect = $this->_return_to; } else { $_redirect = $_group->registration_redirect ? $_group->registration_redirect : $_group->default_homepage; } $this->_redirect($_redirect); return; } } else { $this->data['error'] = lang('fv_there_were_errors'); } } // -------------------------------------------------------------------------- // Store the access token in the Session so we can interrupt the auth flow cleanly $this->session->set_userdata('tw_access_token', $access_token); // -------------------------------------------------------------------------- // Set some view data $this->data['page'] = new stdClass(); $this->data['page']->title = lang('auth_register_extra_title'); $this->data['return_to'] = $this->_return_to; $this->data['return_to_fail'] = $this->_return_to_fail; $this->load->view('structure/header', $this->data); $this->load->view('auth/register/extra-info', $this->data); $this->load->view('structure/footer', $this->data); }
public function string_helper() { $this->load->helper('string'); $this->htmlp(random_string('alnum', 16)); $this->htmlp(increment_string('file', '_')); // "file_1" $this->htmlp(increment_string('file', '-', 2)); // "file-2" $this->htmlp(increment_string('file_4')); // "file_5" for ($i = 0; $i < 10; $i++) { $this->htmlp(alternator('one', 'two', 'three', 'four', 'five')); } $string = "|repeat"; $this->htmlp(repeater($string, 30)); // DEPRECATED $string = "http://example.com//index.php"; $this->htmlp(reduce_double_slashes($string)); // results in "http://example.com/index.php" $string = "/this/that/theother/"; $this->htmlp(trim_slashes($string)); // results in this/that/theother $string = "Fred, Bill,, Joe, Jimmy"; $string = reduce_multiples($string, ","); //results in "Fred, Bill, Joe, Jimmy" $this->htmlp($string); $string = ",Fred, Bill,, Joe, Jimmy,"; $string = reduce_multiples($string, ", ", TRUE); //results in "Fred, Bill, Joe, Jimmy" $this->htmlp($string); $string = "Joe's \"dinner\""; $string = quotes_to_entities($string); //results in "Joe's "dinner"" $this->htmlp($string); $string = "Joe's \"dinner\""; $string = strip_quotes($string); //results in "Joes dinner" $this->htmlp($string); }
/** * Create a new user from FB Details * * @access public * @param object $user The user's basic userobject * @return void **/ protected function _create_user($me) { // Attempt the registration $_data = array(); $_data['email'] = $me['email']; $_data['username'] = $me['username']; $_data['password'] = NULL; $_data['first_name'] = $me['first_name']; $_data['last_name'] = $me['last_name']; $_data['fb_id'] = $me['id']; $_data['fb_token'] = $this->fb->getAccessToken(); $_data['auth_method_id'] = 'facebook'; $_data['email_is_verified'] = TRUE; // Trust the email from Facebook // -------------------------------------------------------------------------- // Set username, ensure it's valid. if (!empty($_me[0]->screen_name)) { // Check if their Facebook username is available $_data['username'] = $me['username']; $_user = $this->user_model->get_by_username($_data['username']); while ($_user) { $_data['username'] = increment_string($me['username'], ''); $_user = $this->user_model->get_by_username($_data['username']); } } elseif (!empty($me['first_name']) && !empty($me['last_name'])) { // No handle, odd, try their name, keep trying it till it works $_data['username'] = url_title($me['first_name'] . ' ' . $me['last_name'], '-', TRUE); $_user = $this->user_model->get_by_username($_data['username']); while ($_user) { $_data['username'] = increment_string(url_title($me['first_name'] . ' ' . $me['last_name'], '-', TRUE), ''); $_user = $this->user_model->get_by_username($_data['username']); } } else { // Random string $_data['username'] = '******' . date('YmdHis'); $_user = $this->user_model->get_by_username($_data['username']); while ($_user) { $_data['username'] = increment_string($_data['username'], ''); $_user = $this->user_model->get_by_username($_data['username']); } } // -------------------------------------------------------------------------- // Use gender, if supplied if (isset($me['gender'])) { if ($me['gender'] == 'male') { $_data['gender'] = 'male'; } elseif ($me['gender'] == 'female') { $_data['gender'] = 'female'; } } // -------------------------------------------------------------------------- // Handle referrals if ($this->session->userdata('referred_by')) { $_data['referred_by'] = $this->session->userdata('referred_by'); } // -------------------------------------------------------------------------- // Which group? // If there's a register_token set, use that if not fall back to the default if (!empty($this->_register_token['group'])) { $_data['group_id'] = $this->_register_token['group']; } else { $_data['group_id'] = $this->user_group_model->get_default_group_id(); } // Create new user $_new_user = $this->user_model->create($_data); if ($_new_user) { // Fetch group data $_group = $this->user_group_model->get_by_id($_data['group_id']); // -------------------------------------------------------------------------- // Send the user the welcome email (that is, if there is one) if ($_new_user->email) { $this->load->library('emailer'); $_email = new stdClass(); $_email->type = 'new_user_' . $_group->id; $_email->to_id = $_new_user->id; $_email->data = array(); $_email->data['method'] = 'facebook'; if (!$this->emailer->send($_email, TRUE)) { // Failed to send using the group email, try using the generic email template $_email->type = 'new_user'; if (!$this->emailer->send($_email, TRUE)) { // Email failed to send, musn't exist, oh well. } } } // -------------------------------------------------------------------------- // Log the user in $this->user_model->set_login_data($_new_user->id); // -------------------------------------------------------------------------- // Create an event for this event create_event('did_register', $_new_user->id, 0, NULL, array('method' => 'facebook')); // -------------------------------------------------------------------------- // Redirect $this->session->set_flashdata('success', lang('auth_social_register_ok', $_new_user->first_name)); $this->session->set_flashdata('from_facebook', TRUE); // Registrations will be forced to the registration redirect, regardless of // what else has been set_error_handler if ($this->_register_use_return) { $_redirect = $this->_return_to; } else { $_redirect = $_group->registration_redirect ? $_group->registration_redirect : $_group->default_homepage; } $this->_redirect($_redirect); return; } }
function increment_exists($str, $data, $separator = '', $first = 1) { // get the integer in string //preg_match('!\d+!', $str, $matches); // get the string in string //preg_match('!\D+!', $str, $matches); if (in_array($str, $data)) { preg_match('!\\D+!', $str, $matches); $str = $matches[0]; do { $str = increment_string($str, $separator, $first); } while (in_array($str, $data)); return $str; } return $str; }