Unidentified Index Error - php

I am using a plugin for WordPRess called Easy Bootstrap Shortcodes to use Booystrap CSS within wordpress posts. Tabs are one feature I use a lot and when I use the tabs short code, it throws the following error:
Notice: Undefined index: tabs in /home/onedirec/public_html/tester/wp-content/plugins/easy-bootstrap-shortcodes/shortcode/tabs/plugin_shortcode.php on line 38
What's weird is that the tabs and all the information following is rendered apart from an indent that shouldn;t be there. You can see this in action here: http://onedirectionconnection.com/tester/?projects=take-me-home-tour
If anyone could help me figure out what the issue is, it would be greatly appreciated. Here's the code that's causing the error:
<?php
/* * *********************************************************
* jQuery UI Tabs
* ********************************************************* */
$_oscitas_tabs = array();
function osc_theme_tabs($params, $content = null) {
global $_oscitas_tabs;
extract(shortcode_atts(array(
'id' => count($_oscitas_tabs),
'class' => ''
), $params));
$_oscitas_tabs[$id] = array();
do_shortcode($content);
$scontent = '<ul class="nav nav-tabs " id="oscitas-tabs-' . $id . '">' . implode('', $_oscitas_tabs[$id]['tabs']) . '</ul><div
class="tab-content">' . implode('', $_oscitas_tabs[$id]['panes']) . '</div>';
if (trim($scontent) != "") {
$output = '<div class="' . $class . '">' . $scontent;
$output .= '</div>';
return $output;
} else {
return "";
}
}
add_shortcode('tabs', 'osc_theme_tabs');
function osc_theme_tab($params, $content = null) {
global $_oscitas_tabs;
extract(shortcode_atts(array(
'title' => 'title',
'active' => '',
), $params));
$index = count($_oscitas_tabs) - 1;
$pane_id = 'pane-' . $index . '-' . count($_oscitas_tabs[$index]['tabs']);
$_oscitas_tabs[$index]['tabs'][] = '<li class="' . $active . '"><a href="#' . $pane_id . '" data-toggle="tab">' . $title
. '</a></li>';
$_oscitas_tabs[$index]['panes'][] = '<div class="tab-pane ' . $active . '" id="'
. $pane_id . '">'
. do_shortcode
(trim($content)) . '</div>';
}
add_shortcode('tab', 'osc_theme_tab');
And here is line 38 on its own:
$pane_id = 'pane-' . $index . '-' . count($_oscitas_tabs[$index]['tabs']);
I know very little about PHP so if anyone can help me spot the error here, it would be greatly appreciated.

Well I'll just post the answer here since it worked in the comments.
Add this line just before line 38:
$_oscitas_tabs[$index]['tabs'] = array();
Right above this line:
$pane_id = 'pane-' . $index . '-' . count($_oscitas_tabs[$index]['tabs']);
That should stop the PHP notice from appearing.
You could try adding a # right before count()
$pane_id = 'pane-' . $index . '-' . #count($_oscitas_tabs[$index]['tabs']);
It keeps PHP from complaining.

Related

Dynamic link with absolute URI gets changed to localhost

$refPointer = $site_to_be_extracted . $a->href;
echo $refPointer . '<br>';
generates in output (Chrome browser):
http://www.hackingwithphp.com/1/1/0/is-this-book-for-you
You would expect the following line to generate a correct <a> tag. That is a correct link
print '<a href=' . $refPointer . '>' . $a . '</a>';
Instead it generates in output:
localhost/1/1/0/is-this-book-for-you
So both the protocol (HTTP) and the $site_to_be_extracted (www.hackingwithphp.com) are lost. And replaced by "localhost"
Why? What could be the problem
This is the function where it's all happening. Now it works fine
include('simple_html_dom.php');
.
.
function createChapterContent ($site_to_be_extracted, $chapter_to_be_extracted) {
$html = file_get_html($chapter_to_be_extracted);
$refPointer;
foreach($html->find('ol') as $ol) {
foreach($ol->find('li') as $li) {
// echo '<br>' . $li->innertext ;
foreach($li->find('a') as $a) {
// Original. Causing the reported problem
// $refPointer = $site_to_be_extracted . $a->href;
// echo $refPointer . '<br>';
// changed to (see below). Now the output is correct
// Why?
$a->href = $site_to_be_extracted . $a->href;
$refPointer = $a->href;
print '<a href=' . $refPointer . '>' . $li->innertext . '</a>' . '<br>';
break;
};
}
}

Magento - Enable HTML links in error/custom messages

I want to know if this is possible to enable HTML links in custom messages (ie: error messages).
Here is my example:
I've made an override for my needs of Mage_CatalogInventory_Model_Stock_Item/Item.php
Function checkQuoteItemQty :
if (!$this->checkQty($summaryQty) || !$this->checkQty($qty)) {
//$message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available.', $this->getProductName());
$message = Mage::helper('cataloginventory')->__('The requested quantity for "%s" is not available (max:%s).', $this->getProductName(), ($this->getQty() * 1));
$cat_id = $this->getProduct()->getCategoryIds();
if($cat_id){
$url = Mage::getModel('catalog/category')->load($cat_id[0])->getUrl();
$message .= Mage::helper('cataloginventory')->__('You might be interested in those products.', $url);
}
$result->setHasError(true)
->setMessage($message)
->setQuoteMessage($message)
->setQuoteMessageIndex('qty');
return $result;
}
But the HTML link I created in $message is not clickable and considered as text (because of the translation I guess...).
Is it possible to change this behavior?
Regards.
For those who would like to know, I had to override Mage_Core_Block_Messages, line 249 :
public function getGroupedHtml()
{
$types = array(
Mage_Core_Model_Message::ERROR,
Mage_Core_Model_Message::WARNING,
Mage_Core_Model_Message::NOTICE,
Mage_Core_Model_Message::SUCCESS
);
$html = '';
foreach ($types as $type) {
if ( $messages = $this->getMessages($type) ) {
if ( !$html ) {
$html .= '<' . $this->_messagesFirstLevelTagName . ' class="messages">';
}
$html .= '<' . $this->_messagesSecondLevelTagName . ' class="' . $type . '-msg">';
$html .= '<' . $this->_messagesFirstLevelTagName . '>';
foreach ( $messages as $message ) {
$html.= '<' . $this->_messagesSecondLevelTagName . '>';
$html.= '<' . $this->_messagesContentWrapperTagName . '>';
$html.= ($this->_escapeMessageFlag) ? $this->escapeHtml($message->getText()) : html_entity_decode($message->getText());
$html.= '</' . $this->_messagesContentWrapperTagName . '>';
$html.= '</' . $this->_messagesSecondLevelTagName . '>';
}
$html .= '</' . $this->_messagesFirstLevelTagName . '>';
$html .= '</' . $this->_messagesSecondLevelTagName . '>';
}
}
if ( $html) {
$html .= '</' . $this->_messagesFirstLevelTagName . '>';
}
return $html;
}
Adding a html_entity_decode at this line :
$html.= ($this->_escapeMessageFlag) ? $this->escapeHtml($message->getText()) : html_entity_decode($message->getText());
Just let me know if you find a better solution.
I'm not sure why, but in my case, by calling the obsolete method without "Message" solves the issue with the link.
Instead of using addNoticeMessage, I changed to addNotice, and the links appeared.
In my case:
$noticeMsg = __('You must be logged in or registered to purchase these products.',
$this->_storeManager->getStore()->getUrl('customer/account/login'),
$this->_storeManager->getStore()->getUrl('customer/account/create')
);
$this->_messageManager->addNotice($noticeMsg);

Print specific array value via function argument

$menu = array(
0 =>'top',
1 =>'photography',
2 =>'about'
);
<?php
function main_menu ($menu) {
$return = '<div class="menu_entry">' . PHP_EOL .'';
foreach( $menu as $key => $value)
{
$return .= '<a class="menu" href="index.php#' . $menu[$key] . '">' . $menu[$key] . '</a>' . PHP_EOL .'';
}
$return .= '</div>';
return $return;
}
?>
<?php echo main_menu($menu[1]); ?>
What i basically want to do is to pass a specific array value when i'm echoing out the menu.
I'm building a single page website with anchors and i want to pass value's so i can echo out the "top"-link.
I'm stuck at the point on how to pass the $key value trough the function.
**edit: I'm trying to print specific links. I want a function that is able to print out an link but i want to specify the link to print via the function argument.
for example:
<?php echo main_menu($key = '0'); ?>
result:
prints url: top
<?php echo main_menu($key = '2'); ?>
result:
prints url: photography
**
(A lack of jargon makes it a bit harder to explain and even harder to google.
I got my books in front of me but this is taking a lot more time than it should.)
You either need to pass the entire array and loop, or pass a single array item and not loop:
Single Item:
function main_menu ($menu) {
$return = '<div class="menu_entry">' . PHP_EOL .'';
$return .= '<a class="menu" href="index.php#' . $menu . '">' . $menu . '</a>' . PHP_EOL .'';
$return .= '</div>';
return $return;
}
echo main_menu($menu[1]);
Entire Array:
function main_menu ($menu) {
$return = '<div class="menu_entry">' . PHP_EOL .'';
foreach($menu as $value) {
$return .= '<a class="menu" href="index.php#' . $value . '">' . $value . '</a>' . PHP_EOL .'';
}
$return .= '</div>';
return $return;
}
echo main_menu($menu);
You don't need $menu[$key] just use the $value.
Should you not just be using $value inside your loop? And passing the entire array rather than one item of the $menu array?
$menu = array(
0 =>'top',
1 =>'photography',
2 =>'about'
);
<?php
function main_menu ($menu) {
$return = '<div class="menu_entry">' . PHP_EOL .'';
foreach( $menu as $key => $value)
{
$return .= '<a class="menu" href="index.php#' . $value . '">' . $value . '</a>' . PHP_EOL .'';
}
$return .= '</div>';
return $return;
}
?>
<?php echo main_menu($menu); ?>
Try:
echo main_menu($menu); // You will get your links printed
Instead of
echo main_menu($menu[1]); // In this case error is occured like : **Invalid argument supplied for foreach**
NOTE: You can use $value instead of $menu[$key]

How do I add these php tags to the <ul> tag?

I am modifying a wordpress function. I have the following code:
$output .= $r['link_before'] . '<ul><li class="bbp-forum-info">' . $title . '</li>' . $counts . '<li class="bbp-forum-freshness">' . $subfresh . '</li></ul>' . $r['link_after'];
And I need the ul tag to look like this:
<ul id="bbp-forum-<?php bbp_forum_id(); ?>" <?php bbp_forum_class(); ?>>
However, I don't know how to add those php tags inside of that code. I have tried it in a number of different ways, but haven't been able to get it to work. Any advice?
use the . to concatenate strings:
$c='a'.'b';
echo $c //outputs 'ab'
knowing that, just:
$output .= $r['link_before'] . '<ul id="bbp-forum-'.bbp_forum_id().'" '.bbp_forum_class().'><li class="bbp-forum-info">' . $title . '</li>' . $counts . '<li class="bbp-forum-freshness">' . $subfresh . '</li></ul>' . $r['link_after'];
if you are adding it correctly
$output .= $r['link_before'] . '<ul id="bbp-forum-<?php bbp_forum_id(); ?>" <?php bbp_forum_class(); ?>><li class="bbp-forum-info">' . $title . '</li>' . $counts . '<li class="bbp-forum-freshness">' . $subfresh . '</li></ul>' . $r['link_after'];
This is hard to answer without further knowlege of the system.
ensure bbp_forum_class(); echoes something along the lines of class="foo"
if that isnt your issue, your style may be overridden by the li class. ensure you dont have conflicting css!

Avatar appears outside of targeted area when adding it to a PHP messaging script

I use this micro message system script and I want to add an avatar to it, however, my lack of PHP knowledge is making this difficult.
The code I use to display an avatar is:
userphoto_thumbnail($user_info, $before = '', $after = '', $attributes = array(width => '40', height => '40'), $default_src = '')
And I want to inject this avatar to this part of the message script (inside a loop):
$r = $r . '<tr id="wpam-reply-' . $post->post_ID . '-' . $count . '" ' . $style . '>';
$r = $r . '<td style="padding:10px 0 10px 10px; width:40px;"><span title="' . $user_info->display_name . ' (' . $user_info->user_login . ')">' . userphoto_thumbnail($user_info, $before = '', $after = '', $attributes = array(width => '40', height => '40'), $default_src = '') . '</span></td>';
$r = $r . '<td>' . wpam_get_message($reply, $user_info, $options, 2) . '</td>';
$r = $r . '</tr>';
If you look at the second line, you will see how I added it there. However, this does not return the avatar where it should be. It appears outside everything else. Maybe because it returns a string rather than data? I am not sure as I am only just familiarising myself with PHP terminology.
I am certain that I have not added the avatar code to the script correctly, can you assist?
EDIT: Just to clarify, on the HTML output, the avatar images appear outside of the table, when they should be inside the <td style="padding:10px 0 10px 10px; width:40px;"> tag.
From the documentation, it looks like userphoto_thumbnails prints out the image. You're trying to concatenate it instead. When you call it, it's being printed out when you're creating the string, so it's appearing in the wrong place.
Try this:
echo '<tr id="wpam-reply-' . $post->post_ID . '-' . $count . '" ' . $style . '>';
echo '<td style="padding:10px 0 10px 10px; width:40px;"><span title="' . $user_info->display_name . ' (' . $user_info->user_login . ')">';
userphoto_thumbnail($user_info, $before = '', $after = '', $attributes = array(width => '40', height => '40'), $default_src = '');
echo . '</span></td>';
echo '<td>' . wpam_get_message($reply, $user_info, $options, 2) . '</td>';
echo '</tr>';
That will print everything out in the right place, though you're no longer creating the $r variable.

Categories