├── .gitignore ├── README.md └── TouchyPHP.php /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .settings/ 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Touchy™PHP 2 | --------------- 3 | 4 | Touchy™PHP is a simple PHP class used by the DoAT team in convergence with [Touchy™BP](https://github.com/doat/TouchyBP). 5 | 6 | USAGE 7 | --------------- 8 | TouchyPHP::getFile($filename [, forceInclude]) 9 | -------------------------------------------------------------------------------- /TouchyPHP.php: -------------------------------------------------------------------------------- 1 | OR 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 22 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | * 25 | * The views and conclusions contained in the software and documentation are those of the 26 | * authors and should not be interpreted as representing official policies, either expressed 27 | * or implied, of DoAT. 28 | */ 29 | 30 | class TouchyPHP { 31 | /** 32 | * constructor 33 | */ 34 | public function __construct() {} 35 | 36 | 37 | /** 38 | * Returns the contents of the css/js/image file 39 | * @param $filename 40 | * @param $forceInclude {optional} 41 | * If set to true or not set, the function returns manipulated content. 42 | * If set to false, the function returns original $filename (inside appropriate HTML tag) 43 | * @return 44 | */ 45 | public function getFile($filename, $forceInclude = null){ 46 | $value = $filename; 47 | 48 | // get file extension 49 | $format = pathinfo($filename, PATHINFO_EXTENSION); 50 | 51 | if ($forceInclude !== false){ 52 | switch ($format){ 53 | case 'css': 54 | case 'js': 55 | // get file content 56 | $content = file_get_contents($filename); 57 | 58 | // set content within '; 152 | } 153 | 154 | return str_replace('{$filename}', $filename, $template); 155 | } 156 | 157 | /** 158 | * Returns HTML tag according to format, including content 159 | * @param $format 160 | * @param $content 161 | * @return HTML tag 162 | */ 163 | private static function _getInternalTag($filename, $format, $content){ 164 | switch ($format){ 165 | case 'css': 166 | $template = ''; 167 | $content = self::_replaceImageUrls($filename, $content); 168 | break; 169 | case 'js': 170 | $template = ''; 171 | break; 172 | } 173 | 174 | return str_replace('{content}', $content, $template); 175 | } 176 | } --------------------------------------------------------------------------------