Example #1
0
	if (empty($vbulletin->GPC['confirmerrors']))
	{
		if (!empty($errors))
		{
			updatetemplate_print_error_page($template_un, construct_phrase($vbphrase['template_eval_error'], fetch_error_array($errors)));
			exit;
		}

		$errors = check_template_errors($vbulletin->GPC['template']);
		if (!empty($errors))
		{
			updatetemplate_print_error_page($template_un, construct_phrase($vbphrase['template_eval_error'], fetch_error_array($errors)));
			exit;
		}

		$errors = check_template_conflict_error($vbulletin->GPC['template']);
		if (!empty($errors))
		{
			updatetemplate_print_error_page($template_un, $errors);
			exit;
		}
	}

	$old_template = $db->query_first("
		SELECT title, styleid, dateline, username, template_un
		FROM " . TABLE_PREFIX . "template
		WHERE templateid = " . $vbulletin->GPC['templateid'] . "
	");
	 if (strtolower($vbulletin->GPC['title']) != strtolower($old_template['title']) AND $db->query_first("
		SELECT templateid
		FROM " . TABLE_PREFIX . "template
Example #2
0
 /**
  * Update a template
  *
  * @param integer $templateid Template ID to be updated
  * @param string $title Template name.
  * @param string $content Template content.
  * @param string $product The product ID which the template belongs to.
  * @param string $oldcontent The content of the template at the time it was loaded.  This is used to prevent
  *	cases where the template was changed while editing. Pass false to force an update.
  * @param boolean $savehistory Whether to save the change in template history.
  * @param string $histcomment Comment of the change to be saved to template history.
  * @param boolean $forcesaveonerror save the template even though there are errors.
  */
 public function update($templateid, $title, $content, $product, $oldcontent, $savehistory, $histcomment, $forcesaveonerror = false, $additional = array())
 {
     $templateid = intval($templateid);
     $title = trim($title);
     $content = trim($content);
     $product = trim($product);
     $histcomment = trim($histcomment);
     $userinfo = vB::getCurrentSession()->fetch_userinfo();
     $timenow = vB::getRequest()->getTimeNow();
     require_once DIR . '/includes/adminfunctions.php';
     require_once DIR . '/includes/adminfunctions_template.php';
     // Required for check_template_conflict_error()
     $style_lib = vB_Library::instance('Style');
     // Compile template
     if (!empty($additional['textonly'])) {
         $template = $content;
     } else {
         $template = $this->compile($content, $forcesaveonerror);
     }
     // TODO: Product API
     $full_product_info = fetch_product_list(true);
     if (!$forcesaveonerror) {
         $errors = check_template_conflict_error($template);
         if (!empty($errors)) {
             throw new vB_Exception_Api('template_conflict_errors', array($errors));
         }
     }
     $old_template = $this->fetchByID($templateid);
     // Test whether the template exists if new template title is not the same as old one's
     if (strtolower($title) != strtolower($old_template['title'])) {
         $result = vB::getDbAssertor()->assertQuery('template_fetchbystyleandtitle', array('styleid' => $old_template['styleid'], 'title' => $title));
         if ($result->valid()) {
             throw new vB_Exception_Api('invalidid', array('templateid'));
         }
     }
     if ($oldcontent === false) {
         $hash = md5($old_template['template_un']);
     } else {
         $hash = md5($oldcontent);
     }
     $result = $this->saveTemplate($title, $template, $content, $timenow, $userinfo['username'], $full_product_info[$product]['version'], $product, $templateid, $hash, $old_template['styleid'], $savehistory, $histcomment, $additional);
     if ($result == 0) {
         // we have an edit conflict
         throw new vB_Exception_Api('edit_conflict');
     } else {
         // Remove templatemerge record
         vB::getDbAssertor()->assertQuery('templatemerge', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_DELETE, 'templateid' => $templateid));
         // update any customized templates to reflect a change of product id
         if ($old_template['styleid'] == -1 and $product != $old_template['product']) {
             $result = vB::getDbAssertor()->assertQuery('template_updatecustom_product', array('product' => $product, 'title' => $title));
         }
         //we need to rebuild the style if a css template is changed, we may need to republish.
         if (preg_match('#\\.css$#i', $title)) {
             $style_lib->buildStyle($old_template['styleid'], $title, array('docss' => 0, 'dostylevars' => 0, 'doreplacements' => 0, 'doposteditor' => 0), false);
         }
         return true;
     }
 }