I have problem with simple link function. On submission form, there is textbox where user can include url. This url is then taken and changed into working link and placed in post. This part works fine. If user include http/https in front of url it will work fine. But if they don't include http/https or only www, then it will open link as example below:
mysiteexample.com/UrlTheyPasted.com
mysiteexample.com/www.UrlTheyPasted.com
(This should open as link to Video/Image/Site,..)
Here is code:
$output .= '<DIV CLASS="'.$outerclass.'">';
$output .= '<DIV CLASS="'.$innertclass.'">'.$title.'</DIV>';
$output .= '<DIV CLASS="'.$innervclass.'">'.$value.'</DIV>';
$output .= '</DIV>';
Anyone know solution for this or why is this happening?
During the processing of the user input, use parse_url() to find out if they have put the protocol on or not and act accordingly.
$url = 'test.com';
$urlscheme = parse_url($url, PHP_URL_SCHEME);
if (empty($urlscheme)) {
$url = 'http://'.$url;
}
die('<pre>'.print_r($url,true));
so for instance, just before your code, put the example:
$scheme = parse_url($value, PHP_URL_SCHEME);
if (empty($scheme)) $value = 'http://'.$value;
$output .= '<DIV CLASS="'.$outerclass.'">';
$output .= '<DIV CLASS="'.$innertclass.'">'.$title.'</DIV>';
$output .= '<DIV CLASS="'.$innervclass.'">'.$value.'</DIV>';
$output .= '</DIV>';
Related
Hi I have a Api list that is been generated using php here is the code that is been used to generate the list
<html>
<title> API LIST</title>
<body>
<?php
$jsondata = file_get_contents("api_link");
$json = json_decode($jsondata, true);
$output = "<ul>";
foreach($output['A'] as $schools){
$output .= "<li>".$schools['name']."</li>";
}
$output .="</ul>";
echo $output;
?>
the list is populated successfully but how can i add a link to the list so that when a user click on one of the items it opens a particular linked page here are the ways i have tried
$output .= "<li ".$schools['name']."</li>";
$output .= "<li>".$schools['name']. "</li>";
$output .= "<li>".$schools['name']."</li>";
I don't know where or how to add the a href code
Use
$output .= '<li>'.$schools['name'].'</li>';
You just need some changes in your code.You can try for
$output .= '<a href=https://www.google.com'.$schools['name'].'><li>'.$schools['name'].'</li></a>';
As per the comments you can use . to concatenate(join) the string and variable in php.
I have a challenge that is bugging me.
The thing is - I'm creating a plugin that is doing an AJAX call to another file in this plugin. It seems Joomla is preventing me from accessing that file.
I need to POST to a file that returns data from a SOAP call.
I'm calling the file from this line:
$html .= '$.post("search.php", { address: $(\'#address\').val(), zipcode: $(\'#zipcode\').val() },';
I've tried both a relative, absolute and server path as well - Joomla doesn't like it. But I can't remember or find the correct way to do it.
The file is in the same folder as the plugin that outputs above code.
Here's the complete javascript function my plugin outputs:
$html .= '<script type="text/javascript">';
$html .= 'function searchParcels()';
$html .= '{';
$html .= '$.post("search.php", { address: $(\'#address\').val(), zipcode: $(\'#zipcode\').val() },';
$html .= 'function(data) {';
$html .= 'var shops = $.parseJSON(data);';
$html .= '$(\'#shops_output\').html(\'\');';
$html .= 'for(i in shops)';
$html .= '{';
$html .= 'var html = \'<p>\'';
$html .= '+ shops[i][\'CompanyName\'] + \'<br>\'';
$html .= '+ shops[i][\'Streetname\'] + \'<br>\'';
$html .= '+ shops[i][\'ZipCode\'] + \' \' + shops[i][\'CityName\'] + \'<br>\'';
$html .= '+ shops[i][\'Telephone\'] + \'<br>\'';
$html .= '+ \'</p>\';';
$html .= '$(\'#shops_output\').append(html);';
$html .= '}';
$html .= '});';
$html .= '}';
$html .= '</script>';
Any help is greatly appreciated :-)
Thanks.
Please check this post on how to use Joomla's ajax interface (it seems you are not using it). This is much easier and much cleaner (and much more standard) than the method you described. All you need to do is to create the module/plugin (make sure that you have a function name ending with "Ajax") and then issue the right call from anywhere on your Joomla website (make sure you use the URL pattern described on the website).
I want to insert this sortcode:
echo do_shortcode('[AUTHORIMAGE-CIRCLE]');
and replace it with the ua1 class on this php line:
$STRING .= $b_f.''.$CORE->_e(array('head','4')).''.$b_a;
This is the real code. the full one is:
if( $canShowBar ){
if(!$isTop){
$STRING .= "<div class='breadcrumb'>";
}
if(isset($userdata) && $userdata->ID){
if(isset($GLOBALS['CORE_THEME']['links'])){
// my account
$STRING .= $b_f.''.$CORE->_e(array('head','4')).''.$b_a;
}
}
}
when working on local host and try to modify the code, after refreshing the whole page is turning blank
we had a developer code something for a Custom Post Type in WordPress that we need to tweak just a touch. They're not available right now, but I think it's a pretty simple PHP issue if knowing the proper syntax. Unfortunately, I'm not completely PHP fluent, so hoping to get some help.
We have a posts landing page where we are just displaying a post thumbnail if there is one, and a link to the full post page (single) ONLY if an email address has been entered into the custom post type. If no email address was entered for the post, no link to the final post. Here's the main chunk of code that is currently working properly for this:
$team_query = new WP_Query($args);
while ($team_query->have_posts()) {
$team_query->the_post();
$member_email = get_post_meta(
get_the_ID(), '_base_team_email', true
);
$html .= '<div class="span-6 team-member">';
if (has_post_thumbnail()) {
$html .= '<div class="member-photo-wrap">'
. get_the_post_thumbnail(get_the_ID(), 'medium')
. '</div>';
}
if (!empty($member_email)) {
$html .= '<p class="member-email">'
. '<a class="linkIcon" href="' . get_permalink() . '#member-top">'
. 'Email & Bio »'
. '</a></p>';
}
$html .= '</div>';
}
All we need to do is tweak so that IF an email address has been entered, the same hyperlink is added around the thumbnail image so it can link to the final post along with the 'Email & Bio' text link. But if NO email address is found, the thumbnail image displays as-is (e.g, no link added).
THANKS!
This would add a link to the thumbnail as well, if the $member_email is not empty.
$team_query = new WP_Query($args);
while ($team_query->have_posts()) {
$team_query->the_post();
$member_email = get_post_meta(
get_the_ID(), '_base_team_email', true
);
// Create anchor tag to use when member email is not empty
$memberEmailAnchorStart = '';
$memberEmailAnchorEnd = '';
if (!empty($member_email)) {
$memberEmailAnchorStart =
'<a class="linkIcon" href="' . get_permalink() . '#member-top">';
$memberEmailAnchorEnd = '</a>';
}
$html .= '<div class="span-6 team-member">';
if (has_post_thumbnail()) {
$html .= '<div class="member-photo-wrap">'
. $memberEmailAnchorStart
. get_the_post_thumbnail(get_the_ID(), 'medium')
. $memberEmailAnchorEnd
. '</div>';
}
if (!empty($member_email)) {
$html .= '<p class="member-email">'
. $memberEmailAnchorStart
. 'Email & Bio »'
. $memberEmailAnchorEnd
. '</p>';
}
$html .= '</div>';
}
Depending on what the linkIcon class does, you might want to remove it from the thumbnail anchor tag.
I'm experiencing a 500, Internal Server error on my website. The error logs show the following error: "Premature end of script headers: cgi_wrapper", in my Joomla application.
It only occurs when one particular file is loaded. The rest of the application/website works as it should. There are no other related issues that show up in the error logs - no indication of a timeout or a permissions error.
The file that is causing the error is a template/layout file. Furthermore, I have identified a snippet of code that will cause the error, when this is commented out, the site loads just fine. Here it is:
if( $question->type == '1' || $question->type == '2' || $question->type == '3' )
{
//shuffle items
$shuffled_items = $this->shuffle_assoc($items);
$output = '';
$output .= '<table class="answer-table">';
$output .= '<tr>';
$output .= '<td>';
$output .= '<ul class="answers">';
foreach($shuffled_items as $item)
{
$output .= '<li num=' . $item->num . '>';
$output .= $item->item;
$output .= '</li>';
}
$output .= '</ul>';
$output .= '</td>';
$output .= '</tr>';
$output .= '</table>';
$output .= '<table class="answer-table correct-answer" style="display: none">';
$output .= '<tr>';
$output .= '<td>';
$output .= '<p class="question-instructions">Correct Answer:</p>';
$output .= '<ul class="answers correct-answer">';
foreach($items as $item)
{
$output .= '<li num=' . $item->num . '>';
$output .= $item->item;
$output .= '</li>';
}
$output .= '</ul>';
$output .= '</td>';
$output .= '</table>';
echo $output;
}
It uses a variable, $questions, that is set in the view.html.php file (for those who know Joomla). It is this variable that seems to be triggering the error. If I don't assign the $questions variable, then the template will load just fine.
Also, in the example above, it first tests the question type ($question->type). There are other sections of code that would be triggered, and still produce the error, if $question->type is not 1, 2, or 3. But I left out the other code for brevity, and because it only gets called when the relevant question type exists. When the code above alone gets run, it causes the error.
So, I'm lost here. What baffles me is that only this template file, and the $questions variable causes the error. Everything else works fine. It also runs fine on my local server.
Almost forgot, using Joomla 1.5.22, PHP 5.3.3, Apache 2.2.3, Cent OS 5.8. The server also runs Parallels Plesk Panel 10.
I hope someone can point me to a solution.
Thanks!
Check /var/log/httpd/suexec_log
and permissions on /var/www/cgi-bin/cgi_wrapper/cgi_wrapper
it should be
ls -la /var/www/cgi-bin/cgi_wrapper/cgi_wrapper
-rwxr-xr-x 1 root root 5288 Jul 14 2011 /var/www/cgi-bin/cgi_wrapper/cgi_wrapper