Zeile 14 | Zeile 14 |
---|
* @param string The name of the template * @param string The regular expression to match in the template * @param string The replacement string
|
* @param string The name of the template * @param string The regular expression to match in the template * @param string The replacement string
|
* @param int Set to 1 to automatically create templates which do not exist for that set (based off master) - Defaults to 1
| * @param int Set to 1 to automatically create templates which do not exist for that set (based off master) - defaults to 1 * @param mixed Template SID to modify, false for every SID > 0 * @param int The maximum possible replacements for the regular expression
|
* @return boolean true if updated one or more templates, false if not. */
|
* @return boolean true if updated one or more templates, false if not. */
|
function find_replace_templatesets($title, $find, $replace, $autocreate=1, $sid=false)
| function find_replace_templatesets($title, $find, $replace, $autocreate=1, $sid=false, $limit=-1)
|
{ global $db, $mybb;
|
{ global $db, $mybb;
|
$return = false;
| $return = false; $template_sets = array(-2, -1); // Select all templates with that title (including global) if not working on a specific template set $sqlwhere = '>0 OR sid=-1'; $sqlwhere2 = '>0';
|
|
|
$sqlwhere = '>\'0\'';
$template_sets = array(-2, -1);
// Select all global with that title if not working on a specific template set
| // Otherwise select just templates from that specific set
|
if($sid !== false) {
|
if($sid !== false) {
|
$sqlwhere = '=\''.(int)$sid.'\'';
$query = $db->simple_select("templates", "tid, template", "title = '".$db->escape_string($title)."' AND sid='-1'"); while($template = $db->fetch_array($query)) { // Update the template if there is a replacement term or a change $new_template = preg_replace($find, $replace, $template['template']); if($new_template == $template['template']) { continue; }
// The template is a custom template. Replace as normal. $updated_template = array( "template" => $db->escape_string($new_template) ); $db->update_query("templates", $updated_template, "tid='{$template['tid']}'"); }
| $sid = (int)$sid; $sqlwhere2 = $sqlwhere = "=$sid";
|
}
// Select all other modified templates with that title
| }
// Select all other modified templates with that title
|
Zeile 59 | Zeile 46 |
---|
$template_sets[] = $template['sid'];
// Update the template if there is a replacement term or a change
|
$template_sets[] = $template['sid'];
// Update the template if there is a replacement term or a change
|
$new_template = preg_replace($find, $replace, $template['template']);
| $new_template = preg_replace($find, $replace, $template['template'], $limit);
|
if($new_template == $template['template']) { continue;
| if($new_template == $template['template']) { continue;
|
Zeile 80 | Zeile 67 |
---|
// Select our master template with that title $query = $db->simple_select("templates", "title, template", "title='".$db->escape_string($title)."' AND sid='-2'", array('limit' => 1)); $master_template = $db->fetch_array($query);
|
// Select our master template with that title $query = $db->simple_select("templates", "title, template", "title='".$db->escape_string($title)."' AND sid='-2'", array('limit' => 1)); $master_template = $db->fetch_array($query);
|
$master_template['new_template'] = preg_replace($find, $replace, $master_template['template']);
| $master_template['new_template'] = preg_replace($find, $replace, $master_template['template'], $limit);
|
if($master_template['new_template'] != $master_template['template']) { // Update the rest of our template sets that are currently inheriting this template from our master set
|
if($master_template['new_template'] != $master_template['template']) { // Update the rest of our template sets that are currently inheriting this template from our master set
|
$query = $db->simple_select("templatesets", "sid", "sid NOT IN (".implode(',', $template_sets).") AND sid{$sqlwhere}");
| $query = $db->simple_select("templatesets", "sid", "sid NOT IN (".implode(',', $template_sets).") AND sid{$sqlwhere2}");
|
while($template = $db->fetch_array($query)) { $insert_template = array(
| while($template = $db->fetch_array($query)) { $insert_template = array(
|