Skip to content

Commit

Permalink
Added detection for a whole lot more urls I found stored as channel p…
Browse files Browse the repository at this point in the history
…references, bringing the average detected settings to about 35
  • Loading branch information
amacneil committed Oct 4, 2010
1 parent 58a4436 commit 23c9b90
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions language/english/lang.reelocate.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'reelocate_replacement_value' => 'Replacement Value', 'reelocate_replacement_value' => 'Replacement Value',


'reelocate_site_prefs' => 'Site Preferences', 'reelocate_site_prefs' => 'Site Preferences',
'reelocate_channel_prefs' => 'Channel Preferences',
'reelocate_upload_prefs' => 'Upload Preferences', 'reelocate_upload_prefs' => 'Upload Preferences',
'reelocate_current_value' => 'Current Value', 'reelocate_current_value' => 'Current Value',
'reelocate_new_value' => 'New Value', 'reelocate_new_value' => 'New Value',
Expand Down
49 changes: 49 additions & 0 deletions mcp.reelocate.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function preview()
$this->EE->cp->set_breadcrumb(BASE.AMP.REELOCATE_CP, lang('reelocate_module_name')); $this->EE->cp->set_breadcrumb(BASE.AMP.REELOCATE_CP, lang('reelocate_module_name'));
$this->EE->cp->set_variable('cp_page_title', lang('reelocate_preview_changes')); $this->EE->cp->set_variable('cp_page_title', lang('reelocate_preview_changes'));
$this->EE->lang->loadfile('admin'); $this->EE->lang->loadfile('admin');
$this->EE->lang->loadfile('admin_content');
$this->EE->lang->loadfile('design'); $this->EE->lang->loadfile('design');
$this->EE->lang->loadfile('tools'); $this->EE->lang->loadfile('tools');


Expand Down Expand Up @@ -98,6 +99,7 @@ function preview()
} }


$data['site_prefs'] = $this->_find_site_prefs($search, $replace); $data['site_prefs'] = $this->_find_site_prefs($search, $replace);
$data['channel_prefs'] = $this->_find_channel_prefs($search, $replace);
$data['upload_prefs'] = $this->_find_upload_prefs($search, $replace); $data['upload_prefs'] = $this->_find_upload_prefs($search, $replace);


return $this->EE->load->view('reelocate_preview', $data, TRUE); return $this->EE->load->view('reelocate_preview', $data, TRUE);
Expand Down Expand Up @@ -132,6 +134,39 @@ function _find_site_prefs($search, $replace)
return $results; return $results;
} }


function _find_channel_prefs($search, $replace)
{
if (!is_array($search) OR !is_array($replace)) return;
if (count($search) != count($replace)) return;

// search for upload preferences
$results = array();
$channel_prefs = $this->EE->db->get('channels')->result_array();
// loop through channels
foreach ($channel_prefs as $row)
{
// loop through find/replace strings
foreach ($search as $id => $search_str)
{
// loop through channel preference names
foreach (array('channel_url', 'channel_notify_emails', 'comment_url', 'search_results_url', 'ping_return_url', 'rss_url') as $upload_pref_name)
{
if (stripos($row[$upload_pref_name], $search_str) !== FALSE)
{
$key = 'channel_id_'.$row['channel_id'].'_'.$upload_pref_name;
$results[$key]['title'] = $row['channel_title'].': '.lang($upload_pref_name);
$results[$key]['current'] = $row[$upload_pref_name];
$results[$key]['current_html'] = preg_replace('/('.preg_quote($search_str, '/').')/i', '<strong>$1</strong>', $row[$upload_pref_name]);
$results[$key]['updated'] = str_ireplace($search_str, $replace[$id], $row[$upload_pref_name]);
}
}
}
}

ksort($results);
return $results;
}

function _find_upload_prefs($search, $replace) function _find_upload_prefs($search, $replace)
{ {
if (!is_array($search) OR !is_array($replace)) return; if (!is_array($search) OR !is_array($replace)) return;
Expand Down Expand Up @@ -177,6 +212,7 @@ function update()
} }


$site_prefs = array(); $site_prefs = array();
$channel_prefs = array();
$upload_prefs = array(); $upload_prefs = array();


// loop through the POST data // loop through the POST data
Expand All @@ -192,6 +228,12 @@ function update()
// standard site preference // standard site preference
$site_prefs[$setting_id] = $this->EE->input->post($setting_id, TRUE); $site_prefs[$setting_id] = $this->EE->input->post($setting_id, TRUE);
} }
elseif (strpos($setting_id, 'channel_id_') !== FALSE)
{
// channel preference
preg_match('/channel_id_([\d]+)_([\w]+)/i', $setting_id, $matches);
$channel_prefs[$matches[1]][$matches[2]] = $this->EE->input->post($setting_id, TRUE);
}
elseif (strpos($setting_id, 'upload_dir_') !== FALSE) elseif (strpos($setting_id, 'upload_dir_') !== FALSE)
{ {
// upload dir preference // upload dir preference
Expand All @@ -205,6 +247,13 @@ function update()
$this->EE->config->update_site_prefs($site_prefs); $this->EE->config->update_site_prefs($site_prefs);
$updated_count = count($site_prefs); $updated_count = count($site_prefs);


// update the channel prefs
foreach ($channel_prefs as $id => $data)
{
$this->EE->db->update('channels', $data, array('channel_id' => $id));
$updated_count += count($data);
}

// update the upload prefs // update the upload prefs
foreach ($upload_prefs as $id => $data) foreach ($upload_prefs as $id => $data)
{ {
Expand Down
2 changes: 1 addition & 1 deletion views/reelocate_preview.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


<?php <?php
$results = FALSE; $results = FALSE;
foreach (array('site_prefs', 'upload_prefs') as $pref_type) foreach (array('site_prefs', 'channel_prefs', 'upload_prefs') as $pref_type)
{ {
if (!empty($$pref_type)) if (!empty($$pref_type))
{ {
Expand Down

0 comments on commit 23c9b90

Please sign in to comment.