[ Index ] |
PHP Cross Reference of MyBB 1.8.38 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.8 4 * Copyright 2014 MyBB Group, All Rights Reserved 5 * 6 * Website: http://www.mybb.com 7 * License: http://www.mybb.com/about/license 8 * 9 */ 10 11 /** 12 * Find and replace a string in a particular template through every template set. 13 * 14 * @param string $title The name of the template 15 * @param string $find The regular expression to match in the template 16 * @param string $replace The replacement string 17 * @param int $autocreate Set to 1 to automatically create templates which do not exist for sets with SID > 0 (based off master) - defaults to 1 18 * @param mixed $sid Template SID to modify, false for every SID > 0 and SID = -1 19 * @param int $limit The maximum possible replacements for the regular expression 20 * @return boolean true if updated one or more templates, false if not. 21 */ 22 23 function find_replace_templatesets($title, $find, $replace, $autocreate=1, $sid=false, $limit=-1) 24 { 25 global $db, $mybb; 26 27 $return = false; 28 $template_sets = array(-2, -1); 29 30 // Select all templates with that title (including global) if not working on a specific template set 31 $sqlwhere = '>0 OR sid=-1'; 32 $sqlwhere2 = '>0'; 33 34 // Otherwise select just templates from that specific set 35 if($sid !== false) 36 { 37 $sid = (int)$sid; 38 $sqlwhere2 = $sqlwhere = "=$sid"; 39 } 40 41 // Select all other modified templates with that title 42 $query = $db->simple_select("templates", "tid, sid, template", "title = '".$db->escape_string($title)."' AND (sid{$sqlwhere})"); 43 while($template = $db->fetch_array($query)) 44 { 45 // Keep track of which templates sets have a modified version of this template already 46 $template_sets[] = $template['sid']; 47 48 // Update the template if there is a replacement term or a change 49 $new_template = preg_replace($find, $replace, $template['template'], $limit); 50 if($new_template == $template['template']) 51 { 52 continue; 53 } 54 55 // The template is a custom template. Replace as normal. 56 $updated_template = array( 57 "template" => $db->escape_string($new_template) 58 ); 59 $db->update_query("templates", $updated_template, "tid='{$template['tid']}'"); 60 61 $return = true; 62 } 63 64 // Add any new templates if we need to and are allowed to 65 if($autocreate != 0) 66 { 67 // Select our master template with that title 68 $query = $db->simple_select("templates", "title, template", "title='".$db->escape_string($title)."' AND sid='-2'", array('limit' => 1)); 69 $master_template = $db->fetch_array($query); 70 $master_template['new_template'] = preg_replace($find, $replace, $master_template['template'], $limit); 71 72 if($master_template['new_template'] != $master_template['template']) 73 { 74 // Update the rest of our template sets that are currently inheriting this template from our master set 75 $query = $db->simple_select("templatesets", "sid", "sid NOT IN (".implode(',', $template_sets).") AND (sid{$sqlwhere2})"); 76 while($template = $db->fetch_array($query)) 77 { 78 $insert_template = array( 79 "title" => $db->escape_string($master_template['title']), 80 "template" => $db->escape_string($master_template['new_template']), 81 "sid" => $template['sid'], 82 "version" => $mybb->version_code, 83 "status" => '', 84 "dateline" => TIME_NOW 85 ); 86 $db->insert_query("templates", $insert_template); 87 88 $return = true; 89 } 90 } 91 } 92 93 return $return; 94 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |