function rewrite_host($url, $origin, $dest) { if (is_array($url)) { // some recursions $ret = array(); foreach ($url as $single_url) { $ret[] = $this->rewrite_host($single_url, $origin, $dest); } return $ret; } if (strpos($url, $origin) !== 0) { return $url; } $rewritten_url = CDN_Rewrites_Helper::str_replace_once($origin, $dest, $url); $options = $this->option_obj->get(); if ($options['debug']) { // if we are in debug mode, just show the changes, just collect $this->debug_result[$url] = $rewritten_url; // don't apply it return $url; } // CDN_Rewrites_Helper::log("$url written into $rewritten_url"); return $rewritten_url; }
function edit($is_updating = false) { global $wpdb; $id = intval($_POST['id']); if (!$is_updating) { $sql = "SELECT * FROM `{$this->config['profiles_table_name']}` WHERE `id`={$id}"; $p = $wpdb->get_row($sql); if (empty($p)) { CDN_Rewrites_Helper::ajax_error(); } $p->apply = explode(',', $p->apply); $p->excludes = unserialize($p->excludes); printf(' <form action="index.php" method="post" class="cdnr_ajax" autocomplete="off" ftype="edit"> <label for="nameE">Give this profile a name</label><br /> <input type="text" name="name" style="width: 250px" id="nameE" value="%s" /> <h3>Rewrite Rule</h3> %s Rewrite static contents URL\'s that start with<br /> <input style="width: 250px;" type="text" name="origin" value="%s" /><br /> into this host<br /> <input style="width: 250px;" type="text" name="dest" value="%s" /> <h3>Apply the above rule on these contents</h3> <ul> <li><input %s type="checkbox" name="apply[css]" id="applyCssE"><label for="applyCssE">External CSS includes (<code><link rel="stylesheet" tyle="text/css" href="<strong>link/to/style.css</strong>" /></code>)</label></li> <li><input %s type="checkbox" name="apply[js]" id="applyJSE"><label for="applyJSE">External JavaScript includes (<code><script type="text/javascript" src="<strong>link/to/javascript.js</strong>"></script></code>)</label></li> <li><input %s type="checkbox" name="apply[img]" id="applyImgE"><label for="applyImgE">Images (<code><img alt="alternate text" src="<strong>link/to/photo.jpg</strong>" /></code>)</label></li> <li><input %s type="checkbox" name="apply[bgr]" id="applyBgrE"><label for="applyBgrE">Inline background images (<code><div style="background:url(\'<strong>link/to/background.png</strong>\') top left repeat-y"></div></code>)</label></li> <li><input %s type="checkbox" name="apply[embed]" id="applyEmbedE"><label for="applyEmbedE">Embeded contents (<code><param filename="<strong>link/to/track.mp3</strong>" /></code> and <code><object src="<strong>link/to/flash.swf</strong>" /></code>)</label></li> <li> <label for="excludesE">Exclude these URL\'s or those start with one of them (one per line)</label><br /> <textarea name="excludes" id="excludesE" style="width: 600px; height: 100px">%s</textarea> </li> <li><input %s type="checkbox" name="enabled" id="enabledE"><label for="enabledE">This profile is Active</label></li> </ul> <input type="hidden" name="id" value="%s" /> <input type="hidden" name="_nonce" value="%s" /> <input type="hidden" name="cdnr_action" value="update" /> <p class="submit"> <input class="button-primary" type="submit" value="Save Changes" name="submit"/> <input class="button-secondary" type="button" value="Cancel" name="cancel"/> </p> </form> ', addslashes(stripslashes($p->name)), CDN_Rewrites_Helper::rule_instructs(), $p->origin, $p->dest, in_array('css', $p->apply) ? 'checked="checked"' : '', in_array('js', $p->apply) ? 'checked="checked"' : '', in_array('img', $p->apply) ? 'checked="checked"' : '', in_array('bgr', $p->apply) ? 'checked="checked"' : '', in_array('embed', $p->apply) ? 'checked="checked"' : '', is_array($p->excludes) ? implode("\n", $p->excludes) : '', $p->enabled ? 'checked="checked"' : '', $p->id, wp_create_nonce($this->config['plugin_name'])); die; } $msg = $this->validate(); if (!empty($msg)) { CDN_Rewrites_Helper::ajax_error('<p>Profile NOT saved.</p><ul><li>' . implode('</li><li>', $msg) . '</li></ul>'); } list($name, $origin, $dest, $apply, $excludes, $enabled) = $this->parse_post_data(); global $wpdb; $sql = $wpdb->prepare("UPDATE `{$this->config['profiles_table_name']}`\r\n SET `name`=%s, `origin`=%s, `dest`=%s, `apply`=%s, `excludes`=%s, `enabled`=%d\r\n WHERE `id`=%d", $name, $origin, $dest, $apply, $excludes, $enabled, $id); // CDN_Rewrites_Helper::log($sql); $wpdb->query($sql); echo $this->format_html($id, $name, $origin, $dest, $apply, $enabled); }