<?php
/*
 * Copyright (c) 2013, webvariants GbR, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

class WV14_Util {
	public static function fixMediaInBackend($html) {
		$html = preg_replace('~<img((?![^>]*alt="[^>]*)[^>]*)/>~', '<img\1alt="" />', $html);

		if (sly_Core::isBackend()) {
			return strtr($html, array(
				'src="data/mediapool/'          => 'src="../data/mediapool/',
				'href="./data/mediapool/'       => 'href="../data/mediapool/',
				'src="sally/data/mediapool/'    => 'src="../data/mediapool/',  // fix 0.5 style URIs
				'href="./sally/data/mediapool/' => 'href="../data/mediapool/', // fix 0.5 style URIs
				'src="imageresize/'             => 'src="../imageresize/'
			));
		}

		return $html;
	}

	public static function getEditorDir() {
		return sly_Util_AddOn::publicDirectory('webvariants/wymeditor');
	}

	public static function getEditorURI() {
		return sly_Util_AddOn::assetBaseUri('webvariants/wymeditor');
	}
}
