Strict Standards: convertDate() - joomla3.1

Strict Standards: Non-static method JoomleagueHelper::convertDate() should not be called statically, assuming $this from incompatible context in
<td class="center">
<?php
echo JHtml::calendar( JoomleagueHelper::convertDate($date),
'match_date'.$row->id,
'match_date'.$row->id,
'%d-%m-%Y',
'size="9" tabindex="2" ondblclick="copyValue(\'match_date\')" onchange="document.getElementById(\'cb'.$i.'\').checked=true"');
?>
</td>

If you are calling convertDate statically, then define it as a static method:
public static function convertDate() {}
If you are not the writer of the code, try setting your PHP error reporting level to something other than strict standards.

Related

Thymeleaf href to controller : Could not parse as expression

I am using Thymleaf href inside a loop.
<th:block th:each="study : ${studyList}">
<tr>
<td th:text="${study.patient.name}"></td>
<td th:text="${study.status}"></td>
<td th:text="${study.description}"></td>
<td><a th:href="#{/updateStudy/{studyId} (studyId=${study.id})}>"</a>Update</td>
</tr>
</th:block>
And my controller definition is
#RequestMapping(value = "/updateStudy/{studyId}")
public void updateStudy(#RequestParam("studyId") long studyId
) {
....
}
The page is not rendering as I am getting parsing exception:
Could not parse as expression: "#{/updateStudy/{studyId}
(studyId=${study.id})}>"
Also in the html page it is complianing : Undefined attribute name ((studyId).
What I am missing here ? Kindly help.
UPDATE:
Apparently the expression should have been
<td><a th:href="#{/updateStudy/{studyId} (studyId=${study.id})}" >Update</a></td>
Now at least the parsing error is resolved. But I am getting this:
There was an unexpected error (type=Bad Request, status=400).
Required long parameter 'studyId' is not present
Hopefully it is not related to the href expression.
SOLVED
Just to complete the answer, I have changed the controller definition to
#GetMapping("/updateStudy/{studyId}")
public String updateSchedulePage(#PathVariable Long studyId, Model model) {
..}
And now everything works fine.
Try with this:
<td><a th:href="#{/updateStudy/${study.id}}" >Update</a></td>
Here is another problem in controller:
#RequestParam will be `#PathVariable `
Change to it:
#RequestMapping(value = "/updateStudy/{studyId}")
public void updateStudy(#PathVariable ("studyId") long studyId
) {
....
}

Files included in wordpress header.php are not accessible of page templates even after calling get_header()

I am developing a custom wordpress template. I have a few page templates for the layout.I call get_header() and get_footer() at the top and bottom of my page templates respectively.
Now the issues is. I have used two or three require_once() in the header.php file to include php class file. And in one of the included file , I have created an object for the included class files. But when I call those objects in my pages files (-- where I used get_header()--) it says undefined variable.
This is my wordpress header.php
// THIS IS MY header.php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if(session_id() == '')
session_start();
date_default_timezone_set('Asia/Dubai');
require_once('risk-profiler/configuration.php'); // Config file
require_once('risk-profiler/dal.php'); // One class files
require_once('risk-profiler/bl.php'); // another class file
require_once('risk-profiler/form_handler.php'); // Were Objects for the classes are created
?>
form_handler.php
if (!isset($data))
$data = new DataAccessLayer(sql_server, sql_user, sql_password, sql_database);
if (!isset($bl))
$bl = new businessLogic;
$data is my object for the database class and $bl is an object of another class.
Now this is where I call get_header() risk_profile_questionnaire.php and I included two form (risk-profile-select-profiling-country.php & another.php) in this file(form) is where I call that object and it is not accessible.
risk_profile_questionnaire.php is as
<div class="form-group">
<label for="" class="col-md-4 control-label">Country : </label>
<div class="col-sm-8">
<select class="form-control input-lg" name="version_details">
<?php
$version_details = $data->get_version_list();
while ($row = mysqli_fetch_array($version_details)) {
echo"<option value='" . $row['country_code'] . "|" . $row['version'] . "'>" . $row['country_name'] . "</option>";
}
?>
</select>
</div>
</div>
Can anyone helpme on why my objects are not accessible at that point.
I can't test now, but my guess is that this is because of variables scope.
If you are going to use a global variable inside a function in PHP, you need to declare it as global at the beginning of the function.
Since you are including header.php (and the rest of files included from header.php) from the function "get_header", variables are limited by default to the scope of "get_header" function.
Try to declare the global variables you need to use at the beginning of header.php file, for example:
global $data;
Variables scopes in PHP: http://php.net/manual/en/language.variables.scope.php

Converting spaghetti code to Twig

Need to convert script with "spaghetti code" to Twig. Read Twig documentation and got basics working. However, I need advice on how to do everything properly, so no re-conversion is needed later. Let's say current script looks following:
file index.php:
<?php
$page_message="do it";
function display_dropdown($max)
{
for ($i=0; $i<$max; $i++)
{
echo "<option value='$i'>Option $i</option>";
}
}
?>
<!DOCTYPE html>
<html>
<body>
<h1><?php echo $page_message; ?></h1>
<form method="post" action="<?php echo basename($_SERVER["SCRIPT_FILENAME"]); ?>">
<select name="whatever"><?php display_dropdown(10); ?></select>
<input type="submit" value="go">
<?php include("footer.php");?>
</body>
</html>
footer.php looks:
<?php
$footer_text="blah blah";
?>
<footer><?php echo $footer_text; ?></footer>
As far I understand, my index.php should look like this when converted to Twig:
<?php
$page_message="do it";
function display_dropdown($max)
{
for ($i=0; $i<$max; $i++)
{
echo "<option value='$i'>Option $i</option>";
}
}
$twig_params_array=array("page_message"=>$page_message, "footer_text"=>"blah blah");
require_once("../lib/Twig/Autoloader.php");
Twig_Autoloader::register();
$loader=new Twig_Loader_Filesystem("templates");
$twig=new Twig_Environment($loader);
echo $twig->render("index_template.html", $twig_params_array);
?>
Then I should create index_template.html and footer_template.html (or whatever) with following code:
index_template.html
<!DOCTYPE html>
<html>
<body>
<h1>{{ page_message }}</h1>
<form method="post" action="{{ _self }}>">
<select name="whatever"><?php display_dropdown(10); ?></select>
<input type="submit" value="go">
{{ include('footer_template.html') }}
</body>
</html>
footer_template.html
<footer>{{ footer_text }}</footer>
If I understand right, it's also possible to "include" functions in Twig templates (with some tweaking in templates), so I don't need to rewrite existing PHP functions like display_dropdown(). Because dropdown is not displayed at the moment...
The thing that concerns me is array with variables (passed to Twig render function). Do I miss something, or is it really needed to manually define each variable (like $page_message and $footer_text) before Twig can work?
It seems like a lot of work to do, because in "spaghetti code" if I define variable somewhere, I can access it at any time just by using echo function. Now, it looks I need to view every single variable that exists in PHP code and manually pass it to Twig parameters array. Really?
Since no solution was provided, I found it myself. All you have to do is use such a line of code, so all the variables you have in your PHP file (counting included files) become available in Twig templates, and you don't need to re-write anything when new variables are added to PHP file later (they also automatically become available in Twig):
echo $twig->render("template_file_name.extension", get_defined_vars());
Mindaugas, just changing the technology you use to render views is not going to make the code less tangled.
I think you should go one step further and divide responsibilities, by using an MVC framework, like Symfony, which uses Twig as its default templating language.
Good luck!

Thymeleaf - custom attribute

I need to set custom attribute (data-validation-matches-message) value from messages resources.
<input data-validation-matches-message="Text from messages resources" />
I can receive and print messages resources value as:
<p th:text="#{user.notfound}"></p>
But how I can set this value for a custom attribute (data-validation-matches-message)?
UPD (I use this)
<input th:attr="data-validation-matches-message=#{user.notfound}"/>
Since Thymeleaf 2.1 you can do this:
<a data-th-attr="data-groupid=${somevalue}, data-groupname=${someothervalue}">...</a>
source
Try this:
<input th:attr="data-validation-matches-message='\'' + #{user.notfound}" + '\''"/>
Using 3.0.9.RELEASE:
<td th:text="${item.description}" th:attr="width=${isSplit} ? '44%' : '59%'" />
This will add width="44%" or width="59%according to a boolean set in the variables.
width might as well have been any other custom attribute.

Wordpress stripslashes issue

I'm passing the ABSPATH value from a wordpress theme options page to an external page which does not have access to ABSPATH. The problem is that once the value is received in the external file, the slashes are removed. How can I send the value and keep the slashes intact?
I'm passing the value for ABSPATH via a javascript window.open URL parameter like so...
<input type="button" id="templateUpload" value="Add New Template" onclick="window.open('../wp-content/themes/mytheme/myuploader.php?abspath=<?php echo ABSPATH ?>','popup','width=330,height=230,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no'); return false" />
The view source of the above executed wordpress theme options page reads...
?abspath=C:\xampplite\htdocs\wordpress/
Which is why I believe I'm having an issue
It is the lack of JavaScript string literal escaping that has tripped you up: \x and \h are escapes in strings, so you'd need \\ to get a real backslash.
But that's not all.
<input ... onclick="window.open('.../myuploader.php?abspath=<?php echo ABSPATH ?>',... />
Here you're outputting a value into:
a URL parameter, inside
a JavaScript string literal, inside
an HTML attribute
That means you need three levels of escaping:
$uri= '../wp-content/themes/mytheme/myuploader.php?abspath='.urlencode(ABSPATH);
$jsuri= json_encode($uri);
$htmljsuri= htmlspecialchars($jsuri);
<input ... onclick="window.open(<?php echo $htmljsuri; ?>, 'popup', 'features...')" />
You can reduce that by using the HEX_ options in json_encode to ensure HTML special characters are already escaped out of the way, in PHP 5.3+:
$uri= '../wp-content/themes/mytheme/myuploader.php?abspath='.urlencode(ABSPATH);
$jsuri= json_encode($uri, JSON_HEX_QUOT|JSON_HEX_TAG|JSON_HEX_AMP);
<input ... onclick="window.open(<?php echo $jsuri; ?>, 'popup', 'features...')" />
However, anything involving multiple levels of escaping like this is confusing and generally to be avoided. Kick the JavaScript and the variable out of the markup instead, then you have only one level of escaping to worry about at once:
<input type="button" id="templateUpload" value="Add New Template" />
<script type="text/javascript">
var ABSPATH= <?php echo json_encode(ABSPATH, JSON_HEX_TAG|JSON_HEX_AMP); ?>;
document.getElementById('templateUpload').onclick= function() {
var uri= '../wp-content/themes/mytheme/myuploader.php?abspath='+encodeURIComponent(ABSPATH);
window.open(uri, 'popup', 'width=330, height=230');
};
</script>
I omitted the return false as it isn't needed for a button, which has no default action to prevent. I also removed the stuff about removing browser chrome just due to finding it quite distasteful. ;-)

Resources