joomla blank space before module - joomla

I'm currently developing a custom module and for some reason it appends a blank space before anything I'm outputting.
My set up is like this:
main class is in helper .php,
logic is in mod_name .php,
output is in /tmpl/default .php
The strange thing is that if I have a method in my class that returns html. And then I call this method in my template everything's fine no extra lines are appended.
But if I try to write output, even plain text, in my template or mod_name.php I get this extra line.
Here's a screenshot:
Please let me know if anyone encountered anything like this before, I'd be much obliged!

Turned out that the problem was because I was including 2 files, each of them contained a separate class, for some reason when I was including only 1 file it all worked fine. The included file had no white-space and wasn't generating any output, it contained only the logic.
Thank You for your time and answers though.
EDIT:
Recently stumbled upon this issue again, turned out UTF-8 without BOM is the way to go, BUT MVC-wise, make sure that your components entry point "./com_helloworld/helloworld.php" is UTF-8 without BOM in the first place!

UTF-8 without BOM is the answer. I made 3 complex Joomla websites with conditional CSS to manage this problem before I found the cause.
I also found this script somewhere to put on the root of a Joomla website to recursively autosave UTF-8 no BOM php files.
It worked and saved me a lot of time:
<?php
// Tell me the root folder path.
// You can also try this one
// $HOME = $_SERVER["DOCUMENT_ROOT"];
// Or this
// dirname(__FILE__)
$HOME = dirname(__FILE__);
// Is this a Windows host ? If it is, change this line to $WIN = 1;
$WIN = 0;
// That's all I need
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>UTF8 BOM FINDER and REMOVER</title>
<style>
body { font-size: 10px; font-family: Arial, Helvetica, sans-serif; background: #FFF; color: #000; }
.FOUND { color: #F30; font-size: 14px; font-weight: bold; }
</style>
</head>
<body>
<?php
$BOMBED = array();
RecursiveFolder($HOME);
echo '<h2>These files had UTF8 BOM, but i cleaned them:</h2><p class="FOUND">';
foreach ($BOMBED as $utf) { echo $utf ."
\n"; }
echo '</p>';
// Recursive finder
function RecursiveFolder($sHOME) {
global $BOMBED, $WIN;
$win32 = ($WIN == 1) ? "\\" : "/";
$folder = dir($sHOME);
$foundfolders = array();
while ($file = $folder->read()) {
if($file != "." and $file != "..") {
if(filetype($sHOME . $win32 . $file) == "dir"){
$foundfolders[count($foundfolders)] = $sHOME . $win32 . $file;
} else {
$content = file_get_contents($sHOME . $win32 . $file);
$BOM = SearchBOM($content);
if ($BOM) {
$BOMBED[count($BOMBED)] = $sHOME . $win32 . $file;
// Remove first three chars from the file
$content = substr($content,3);
// Write to file
file_put_contents($sHOME . $win32 . $file, $content);
}
}
}
}
$folder->close();
if(count($foundfolders) > 0) {
foreach ($foundfolders as $folder) {
RecursiveFolder($folder, $win32);
}
}
}
// Searching for BOM in files
function SearchBOM($string) {
if(substr($string,0,3) == pack("CCC",0xef,0xbb,0xbf)) return true;
return false;
}
?>
</body>
</html>

I've encountered a similar problem today, and managed to solve it by encoding the module layout to "UTF-8 without BOM"

It looks to be a saved location for something set to hide. I at least have found this at times with print and rss icons turned off, but the container fails to go away. You can remove the whole thing, or make corrections in the database files if you can find the source. Looks like some sort of registration module so could you could look in the source files for any modules you might have like this if that rings a bell. Sorry not an exact answer, but hopefully gives a little direction.

Related

Line spacing in CKeditor

apologies but I am an absolute noob on this. I have implemented a CKeditor on my website using the below HTML:
<!doctype html>
<html>
<head>
<!--Define the character set for the HTML element -->
<meta charset="utf-8">
<!--Call the external script to use the CDN CKEditor in your page-->
<script src="//cdn.ckeditor.com/4.6.2/standard/ckeditor.js"></script>
<script type="text/javascript">
//Define an init function that sends the rich text editor contents to the page code
function init() {
//onMessage runs when the HTML element receives a message from the page code
window.onmessage = (event) => {
if (event.data == "x") {
CKEDITOR.instances.CK1.setData( '<p></p>' );
console.log(event.data,"ok");
} else {
//postMessage sends the contents of the CKEDITOR back to the page code
window.parent.postMessage(CKEDITOR.instances.CK1.getData(),"*");
console.log(event.data,"okd");
}
}
}
</script>
</head>
<body onload="init();">
<!--Define the HTML element as a textarea-->
<textarea name="editor1" id="CK1"></textarea>
<script>
//Use the CKEditor replace() function to turn our textarea into a CKEditor rich text editor
CKEDITOR.replace("editor1");
</script>
</body>
</html>
It works great but I have a line spacing issue where it looks like there is a line in between the paragraphs, but when it displays later on it is on top of each other. Is there anyway to reduce the spacing so the user realises they need to press enter again?
Image attached, first test is 1 press of enter after text (which looks like it has a line between but doesn't), second is 2 enters.
My issue is also that I am using Wix, so I can't host the config or whatever files to change. So it all needs to be from the html link.....
Thanks!
enter image description here
These lines of code will remove extra space
:host ::ng-deep .ck-editor__editable_inline p {
margin: 0;
}
Do you need to force the user to press Enter twice for a new paragraph? If so, try this:
CKEDITOR.addCss('.cke_editable p { margin: 0 !important; }');
CKEDITOR.replace('editor1');

HTA Self-Modifying Code?

I'd like to try to make an HTA that holds some data between sessions. The file might move from one computer to another, so I don't want to depend on cookies, and it won't have some remote server to save data to, so my hope is to find a way to use scripting like vbscript to write the save data back to the HTA itself, so that the next time the application runs, it already has the latest information.
What I'd likely do is dedicate a run of lines in the code as a list of variable declarations that will be used to initialize the application. There would be some kind of "save" button in the application that will read the current state of those variables and edit the hta file's source code, specifically on those lines and replace the values with whatever the current values are.
Since an HTA file is essentially just a text file with a different extension, I would assume there's a way to have the HTA edit itself like any other file...but I don't actually know how to do it, or how to isolate the lines of code where the variables will reside and edit them without having to load the entire file into memory and save the entire thing each time I want to save something... I'd like to keep things completely self-contained, so I don't want to depend on external files like an XML or CSV to store settings between sessions, so I'd like to be able to embed the data into the HTA.
You can indeed modify an HTA file while it's running because it's interpreted code. Same way you can modify an HTML file while you're viewing in your browser.
However, I would not do it that way unless there is some compelling reason you must keep everything in 1 file. If there is a problem writing to the HTA, you will end up with a blank file and lose everything. Therefore, I recommend using a plain text file to store your data and include that with your HTA.
MyApp.hta:
<!doctype html>
<HTA:APPLICATION
APPLICATIONNAME="MyApp"
SINGLEINSTANCE="yes"
CONTEXTMENU="no"
ICON=""
ID="HTA"
INNERBORDER="no"
NAVIGABLE="no"
SCROLL="yes"
SHOWINTASKBAR="yes"
VERSION="0.0.1"
/>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<title>MyApp</title>
<style type="text/css">
body { font-family: Calibri, Arial; font-size: 20px; }
label { font-weight: bold; }
.settings__container { position: relative; height: 200px; border: 2px dashed #ccc; overflow: hidden; padding-right: 2px; }
#settings { width: 100%; height: 100%; border: 0; }
</style>
</head>
<body>
<label>Settings:</label>
<div class="settings__container">
<textarea id="settings"></textarea>
</div>
<button id="save-settings__button">Save Now</button>
<script type="text/javascript">
(function() {
var settingsElement = document.getElementById('settings'),
settingsFile = "MyApp.settings.txt",
io = new ActiveXObject('Scripting.FileSystemObject');
function loadSettings() {
try {
var file = io.OpenTextFile(settingsFile, 1),
data = file.ReadAll();
file.Close();
settingsElement.value = data;
} catch(e) {
// Failed to load settings; settings file may not exist yet.
}
}
function saveSettings(data) {
var file = io.OpenTextFile(settingsFile, 2, true);
file.Write(data);
file.Close();
}
// Assuming IE9+
document.getElementById('save-settings__button').addEventListener('click', function(e) {
saveSettings(settingsElement.value);
});
// Load the settings file
addEventListener('load', function(e) {
loadSettings();
});
// Save the settings on exit
addEventListener('unload', function(e) {
saveSettings(settingsElement.value);
});
})();
</script>
</body>
</html>
Have a look at the FileSystemObject. If you're using vbscript, you would need to
Open the HTA file with OpenTextFile
Read the file
Modify the lines you want changed
Write the new contents to the file with CreateTextFile (Overwrite set to True)
For using Javascript the procedure is the same, the methods are slightly different.

Manually control <head> markup in Joomla

Is there a way to manually configure the contents of the <head> section of the site in Joomla 3.1? I want to use the templating system for the entire markup of the page, including everything between <html></html>.
I just read this: http://forum.joomla.org/viewtopic.php?f=466&t=230787 and I am astonished at the response. Surely this is template/data separation 101. Has this been fixed in the latest Joomla release?
If you are planning for a template development and you need all your template data get separated from Joomla libraries or core file (the head section).
Normally the head section include will works like
<jdoc:include type="head" />
it loads the content from libraries libraries\joomla\document\html\renderer\head.php
If you want to override the content of head you can make a module for your task.
Just create a module and include that module instead of this head make sure that have all required codes added to work $document Class otherwise it miss a lot off features of Joomla regarding document class
As explained by the answer from Jobin, normally, you would include the head data by using the <jdoc:include type="head" /> tag, but if you want more control over this, you can use the JDocument.
Example code in your template's PHP:
$doc = JFactory::getDocument();
$my_head_data = $doc->getHeadData();
This will give you an array of the data that JDocument would normally print, so that you can completely choose what to print and how.
To make jQuery load from CDN and get it on top of the script list, I made a little patch just after the $doc = JFactory::getDocument(); that manipulates the header array directly inside the $this object as follows:
$my_jquery = "//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js";
$my_jquery_ui = "//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js";
$my_jquery_cx = $this->baseurl."/media/jui/js/jquery-noconflict.js ";
foreach($this->_scripts as $k=>$v) {
// put own jquery.conflict && jquery-ui && jquery on top of list
if( strpos($k,'jquery.min.js')) {
unset($this->_scripts[$k]);
$r = array( $my_jquery_cx => $v);
$this->_scripts = $r + $this->_scripts;
$r = array( $my_jquery_ui => $v);
$this->_scripts = $r + $this->_scripts;
$r = array( $my_jquery => $v);
$this->_scripts = $r + $this->_scripts;
}
else if( strpos($k,'jquery.ui.min.js')) {
unset($this->_scripts[$k]);
}
else if( strpos($k,'jquery-noconflict.js')) {
unset($this->_scripts[$k]);
}
}
Replace $my_jquery_xxx with editable config parameters in your templateDetails.xml file

QueryPath changing iframe tags to self-closing?

I'm using QueryPath to wrap a <div> around embedded videos on a site that contains a mixture of <object> and <iframe> embeds.
I tried the following code:
$content = qp($content)
->find('object,iframe,a.evdPlayer')
->wrap('<div class="splashBack"></div>')
->top('body')->children()
->html(); // << It's wanting to remove the </iframe> Grrr.
return $content;
But it seems to want to change my <iframe></iframe> code to <iframe />, which is messing things up for some reason. Is there a way to keep it from changing the tags it's wrapping?
Thanks in advance!
the ->html method does not set the LIBXML_NOEMPTYTAG flag when using DOMDocument::saveXML, if you need the closing tags you should use ->xhtml instead which passes this flag. eg
$content = qp($content)
->find('object,iframe,a.evdPlayer')
->wrap('<div class="splashBack"></div>')
->top('body')->children()
->xhtml();
return $content;
Found a solution that seems to work. It turns out that by inserting some content between the ... querypath recognizes the need for the closing tag and leaves it alone. It's a hack, but it works for now!
$content = qp($content)
->find('object,iframe,a.evdPlayer')
->text('[ video embed ]')
->wrap('<div class="splashBack"></div>')
->top('body')->children()
->html(); // << It's wanting to remove the </iframe>
return $content;

CodeIgniter and layouts? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
What CodeIgniter library can provide this funcionality??
http://media.railscasts.com/videos/008_content_for.mov
It seems so simple on rails but I just cant find a simple way to achieve this on codeigniter.. please help.. I hate having to insert my styles or javascript in the body of the document
I hate templates like Smarty or http://williamsconcepts.com/ci/codeigniter/libraries/template/
Using my own implementation of Zend-like layout.
Add hook /application/hooks/Layout.php:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
/**
*
*/
class Layout {
function render() {
global $OUT;
$CI = & get_instance();
$output = $CI->output->get_output();
if (!isset($CI->layout)) {
$CI->layout = "default";
}
if ($CI->layout != false) {
if (!preg_match('/(.+).php$/', $CI->layout)) {
$CI->layout .= '.php';
}
$requested = BASEPATH . '../application/layouts/' . $CI->layout;
$default = BASEPATH . '../application/layouts/default.php';
if (file_exists($requested)) {
$layout = $CI->load->file($requested, true);
} else {
$layout = $CI->load->file($default, true);
}
$view = str_replace("{content}", $output, $layout);
$view = str_replace("{title}", $CI->title, $view);
$scripts = "";
$styles = "";
$metas = "";
if (count($CI->meta) > 0) { // Массив с мета-тегами
$metas = implode("\n", $CI->meta);
}
if (count($CI->scripts) > 0) { // Массив со скриптами
foreach ($CI->scripts as $script) {
$scripts .= "<script type='text/javascript' src='" . base_url() . "js/" . $script . ".js'></script>";
}
}
if (count($CI->styles) > 0) { // Массив со стилями
foreach ($CI->styles as $style) {
$styles .= "<link rel='stylesheet' type='text/css' href='" . base_url() . "css/" . $style . ".css' />";
}
}
if (count($CI->parts) > 0) { // Массив с частями страницы
foreach ($CI->parts as $name => $part) {
$view = str_replace("{" . $name . "}", $part, $view);
}
}
$view = str_replace("{metas}", $metas, $view);
$view = str_replace("{scripts}", $scripts, $view);
$view = str_replace("{styles}", $styles, $view);
$view = preg_replace("/{.*?}/ims", "", $view); // Подчищаем пустые неподгруженные части шаблона
} else {
$view = $output;
}
$OUT->_display($view);
}
}
?>
Then enable hooks in your /application/config/config.php:
$config['enable_hooks'] = TRUE;
After that add to /application/config/hooks.php:
$hook['display_override'][] = array('class' => 'Layout',
'function' => 'render',
'filename' => 'Layout.php',
'filepath' => 'hooks'
);
Create folder /application/layouts/
Create file /application/layouts/default.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>{title}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
{metas}
{scripts}
{styles}
<link rel="icon" href="<?= base_url() ?>favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="<?= base_url() ?>favicon.ico" type="image/x-icon" />
</head>
<body>
<div class="head">
{head}
</div>
<div class="content">
{content}
</div>
</body>
</html>
Use it from controller:
class main extends MY_Controller {
function __construct() {
parent::Controller();
$this->parts[head] = $this->load->view("frontend/global/header.php", null, true);
$this->scripts = array("JQuery/jquery-1.4.2.min", "JQuery/form", "Core", "Frontend");
$this->styles = array("style");
$this->title = "Blah blah";
}
function index() {
$this->load->view('frontend/index.php');
}
}
I've achieved this in the past using this Template Library. From the documentation:
The Template library, written for the
CodeIgniter PHP-framework, is a
wrapper for CI’s View implementation.
Template is a reaction to the numerous
questions from the CI community
regarding how one would display
multiple views for one controller, and
how to embed “views within views” in a
standardized fashion. In addition,
Template provides extra Views loading
capabilities, the ability to utilize
any template parser (like Smarty), and
shortcuts for including CSS,
JavaScript, and other common elements
in your final rendered HTML.
Specifically, check out the library's additional utilities. It allows you to put something like this in your controller:
$this->template->add_js('js/YourJavascriptFile.js');
or
$this->template->add_js('alert("Hello!");', 'embed');
Echo $_scripts in your template
(preferably in the <head> section) to
utilize JavaScript added via this
method.
Similarly, you can do the same with your CSS:
$this->template->add_css('css/main.css');
$this->template->add_css('#logo {display: block}', 'embed', 'print');
..and simply echo $_styles in your <head> section.
Hope that helps.
Check out Twig - it supports "inheritance" (instead of the traditional include header, include footer, etc)
http://www.twig-project.org/
CodeIgniter helper:
http://github.com/jamiepittock/codeigniter-twig
or
http://github.com/MaherSaif/codeigniter-twig
(haven't tried either, but looks like the latter is a fork w/the latest commits)
I had the same problem with finding a advance layout library as well,
so i wrote my own version which also fits your need (using YAML file).
Features
Manage layouts, page title, metas, css and js with YAML file for cleaner and lighter controllers.
Default configs can be overwritten in controller configs. So that you can split your css and js into smaller files for more flexible design.
Combine and minify css and js files in production mode for faster page loading.
Usage
// in the controller
$this->view->render();
This lib will get the layout, view, page title, css, js, metas from your YAML configs
Documentation
Please see this post for more detail
download
Download source code from Github

Resources