Ob start: Some of the data is lost - php

Here parts data for lost in file system/engine/controller.php.
if (file_exists(DIR_TEMPLATE . $this->template)) {
extract($this->data);
/* Here found header.tpl, media.tpl(my module),
column_left.tpl(this show my module), column_right.tpl,
language.tpl, footer.tpl */
ob_start();
/* Here found header.tpl, language.tpl, footer.tpl */
require(DIR_TEMPLATE . $this->template);
$this->output = ob_get_contents();
ob_end_clean();
}
Why might this be? I use a Opencart framework, which you can add new modules. Made module can be found in the controller/common/column_left.php
Appendix 3 hours later:
I guess that this is due to the structure of Opencart Development. I imported across this problem is raised in a page that is different from OpenCart layout structure.
Opencart front-page layout is of such
product/category = category.php file in the directory controller/product.
I have here, this kind of layout:
line/page/path = in file controller/line/page.php, this method called "path".
Is one of the more detailed information about the structure of OpenCart is a problem with that? And if because of what editing brings the problem is ignored? OpenCart original code is easy to modify vqMod board with the block when I know what should be changed.

I do not understand the question but looking at your code you probably want to achieve this:
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/account.tpl')) {
$this->template = $this->config->get('config_template') . '/template/account/account.tpl';
} else {
$this->template = 'default/template/account/account.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
The first if-else is checking for custom template if present or loads the default one otherwise. $this->children part is enabling sub-templates. Last line is doing the rest - filling the template with data and rendering the output. If you are developing something new in OpenCart it is always best to look into files already there not only to find out how things work but also to follow the same coding standards.

Related

Whats the correct way of outputting html in a custom module in Drupal

I have worked on a few project with drupal, and the main suggestion I got when learning was to use Views to output your data, although this was fine for some items I found it cumbersome to achieve my projects requirements in the set time and to style it the controls were too limiting.
I want to know whats wrong with doing it like this, or whats right about doing it like this?
You run a query to get the specific data you want.
function custom_block_get_item($nid){
$result = db_query("SELECT `field_custom_item` FROM {field_data_field_custom_item} WHERE entity_id = :entity_id",
array(
':entity_id' => $nid,
));
return $result;
}
Then you loop through creating the html
function custom_block_display_blurb($nid){
$html='<div id="blurb_wrapper"><div id="recent_projects_blurb">';
$result=custom_block_get_blurb($nid);
while($row1 = $result->fetchAssoc()){
$a=check_markup($row1['field_custom_item'],'full_html','','');
$html.='
<span class="recent_project_text">'.
$a.'</span>';
}
$html.='</div></div>';
return $html;
}
Finally display it at the end
function custom_block_block_view($delta=''){
if (arg(0) == 'node' && is_numeric(arg(1))) $nodeid = arg(1);
switch($delta) {
case 'custom_block':
$block['content'] = custom_block_display_blurb($nodeid);
break;
}
return $block;
}
This seems like a kind of hacky way to do things, what is the correct drupal way?
Maybe you mean using the drupal theme layer? This allows for use of .tpl files and overriding. I have a simple block module that does it here Source here.
Here is some documentation on using the theme layer within a module.
Here is some official Drupal docs on themeing (mainly themes rather than using the theme layer in a module).

Check module position in OpenCart 2.0

I was using following code for Check module position. So, It is working fine in OpenCart 1.5.6. When module Enabled in Content left & right panel so I want to hide javascript code in OpenCart
but, it is not working in Opencart 2.0
How can be achieved in Opencart 2.0?
in .tpl file
<?php if ($module['position'] == 'content_bottom' || $module['position'] == 'content_top') { ?>
//add your code Here
<?php } ?>
add in .php file
$this->data['module'] = $setting;
I have found simple solution. This is working like charm.
Step 1
in .tpl file. (You want to that module. featured.tpl etc...)
<?php if ($module['position'] == 'content_bottom' || $module['position'] == 'content_top') { ?>
//add your code Here
<?php } ?>
Step 2
add in .php file (You want to that module. featured.php etc...)
$data['module'] = $setting;
Step 3 (if, You are used OpenCart 2.0.0.0 version)
catalog/controller/common/{content_top, content_bottom, content_right, content_left}.php,
Find the below code
if (isset($part[1]) && isset($setting[$part[1]])) {
and add the below code after
$setting[$part[1]]['position'] = basename(__FILE__, '.php');
Step 3 (if, You are used OpenCart 2.0.1.x. version)
catalog/controller/common/{content_top, content_bottom, content_right, content_left}.php,
Find the below code
$setting_info = $this->model_extension_module->getModule($part[1]);
and add the below code after
$setting_info['position'] = basename(__FILE__, '.php');
OC 2.0 is a major update so lots of things working on OC 1.5.X might not work on OC 2.X
Eg OC 1.5.x we used to add layout to module now in OC 2.0 we add Modules to layout So In 1.5.x we used to find Module and it's associated positions, Now we find
Positions and it's associated Modules.
Suppose you are working on \catalog\controller\common\content_top.php
After
$modules = $this->model_design_layout->getLayoutModules($layout_id, 'content_top');
Which fetches all the modules set on content_top of the particular layout
Add
$search_text = 'featured'; // name of the module you want to find
$matched_top = array_filter($modules, function($el) use ($search_text) {
return ( strpos($el['code'], $search_text) !== false );
});
if(!empty($matched_top)){
$data['truevalue'] = 1;
}
Now in content_top.tpl you can write script
if(isset($truevalue)){
//here goes script code
}
Similarly You can do the same for content_bottom as well

Opencart custom module not showing in frontend

I have just developed my first Opencart (1.5.6) plugin using the hostjars starter files.
The Admin section is working beautifully, and all the Frontend code has been placed. However, for some reason the module is not showing the on the webpage, even though the position has been defined in the Admin.
Below is the Frontend Controller code for reference (FYI, No errors are thrown which makes me think that perhaps the Controller is not being called or something):
<?php class ControllerModulebevyspecials extends Controller {
protected function index($setting) {
//Load the language file
$this->language->load('module/bevy_specials');
//Load the models
$this->load->model('module/bevy_specials');
//Get the title from the language file
$this->data['heading_title'] = $this->language->get('heading_title');
//Retrieve Checkout Special Products
$products = $this->model_module_bevy_specials->getBevySpecials();
if(Count($products)>0){
foreach ($products as $product) {
$product_info = $this->model_catalog_product->getProduct($product['product_id']);
$this->data['title'] = $product['title'];
if (isset($product_info)) {
$this->data['products'][] = array(
'product_id' => $product_info['product_id'],
'name' => $product_info['name'],
'discount' => $product['discount']
);
}
}
}
else{
$this->data['noRecord'] = true;
}
//Choose which template to display this module with
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/bevy_specials.tpl')) {
$this->template = $this->config->get('config_template') . '/template/module/bevy_specials.tpl';
} else {
$this->template = 'default/template/module/bevy_specials.tpl';
}
//Render the page with the chosen template
$this->render();
} } ?>
Am I missing any specific code that displays the module on the webpage?
Opencart documentation is quite minimal when it comes to module development, and I've tried searching on web for a solution but couldn't find a definitive answer.
Any inputs will be greatly appreciated. Thanks in advance!
MORE INFO:
One issue found though.....in admin panel when i add 2 or more Layouts for the module (e.g added to "Column-Left" for Contact page and "Content-Top" for Account page), the Frontend then shows the following error:
Warning: Invalid argument supplied for foreach() in D:\xampp171\htdocs\opencart\catalog\controller\common\column_left.php on line 49
Issue Resolved
Since i used the hostjars start files, i had to amend the code abit and the issue got fixed.
1) In the Admin Controller of the module, i removed the section under the comment:
"//This code handles the situation where you have multiple instances of this module, for different layouts."
2) In the Admin View .tpl file, for the layout position , i had to properly format the few html tag's. For example: the <select name="my_module_<?php echo $module_row; ?>_layout_id"> was replaced with the proper format <select name="banner_module[<?php echo $module_row; ?>][layout_id]">...... This ensures that multiple Layouts can be saved in Admin control panel. (there will be 8 places in the .tpl file where this needs to be done)
3) Last but not the least, if you do Step 2 correctly, then the Layouts will be properly serialized and saved in the database's oc_settings Table (previously my layout was not being stored in serialized form).
Hope the above helps others too.
Thank you!

Wordpress url rewriting

I have a problem concerning url-rewriting in wordpress. I am currently working on a language plugin (nearly finished also) and as a last thing, I would like to see every url altered so that it contains the current language that has been selected by the user (or a default language if the user hasn't changed the language).
I don't have a problem altering the links, the problem lies with the rewriting done by the server. Below you can find how I change the links.
public function register_filters()
{
add_filter('page_link', array(get_class(),'alter_permalink'));
add_filter('post_link', array(get_class(),'alter_permalink'));
}
public function alter_permalink($permalink)
{
$permalink = str_replace(get_option('home'), '', $permalink);
$permalink = trim($permalink, '/');
//The next line is actually a method that is being called,
//but it will return a string like this.
$lang = 'EN';
return get_option('home') . '/' . $lang . '/' . $permalink;
//This returns a link that looks something like this:
//http://somedomain.com/EN/permalink-structure
}
So as you can see, I have no problems creating the links, the problem lies with the url-rewriting on the server itself.
I have tried this method: http://shibashake.com/wordpress-theme/wordpress-permalink-add
but I didn't get that one to work either. The problem is that I just don't seem to understand how these rewriting-rules work and that I can't seem to find a decent tutorial on the subject either.
Any help would be greatly appreciated.
the filter to listen to for handling url is request.
function request_handler($vars) {
//modified $vars here
return $vars;
}
add_filter('request', 'request_handler', 11);
i have written a plugin for customize url in wp. check out the source and see how i handle it.
http://wordpress.org/extend/plugins/auto-url/

How to display a Drupal 6.20 menu in WordPress?

Is is possible to display (via php) the main menu of a Drupal 6.20 site in a WordPress theme template file located in a subdirectory on the same domain?
Right now, I'm displaying the menu by copying the static html from the Drupal site and adding it to header.php in the WordPress template in the site located in mydomain.com/blog/. But of course that's not going to work when another menu item is added to the Drupal site, or the Drupal menu is changed in any way.
So is there a Drupal php function that will pull the menu into the WP file?
Failing that, is there a way with php to parse a Drupal page for the html of the menu (yes, this would be ugly) and display it in WP?
The first part of the challenge is to output only the menu, with as little (or none) of the surrounding HTML as possible, so you have as little work to do in parsing the HTML as possible.
The second part is to take that output from Drupal and actually display it on your WordPress site.
You could add the Drupal database as a secondary database in WordPress using the a new instance of the $wpdb object, write the query to get the right content from the tables, and format the results. That could work, but might be overkill.
An alternative workable option may be to use JSON to format the output of the primary links, using the drupal_json function in Drupal, then consume the JSON feed in Wordpress.
I'm assuming:
you have admin access to login to the Drupal site, which you'll need to create nodes, and clear the theme cache
you want to output the Primary Links menu, which 90%+ of Drupal sites use. This is probably true, but it is possible your site uses custom menus. If so, this is still possible, you'd just write slightly different code in step 3.
The steps would be:
Create a Drupal node (you can call it anything, it's just a placeholder)
Get the node id of your dummy page (ie., node/234). From the node id, create a one-off page template in your Drupal site's themes folder. It should be called page-node-xxxx.tpl.php, with xxxx being your node id
Add this code to page-node-xxxx.tpl.php:
<?php
drupal_json(menu_navigation_links(variable_get('menu_primary_links_source', 'primary-links')));
?>
This will create a JSON feed of your menu items.
Clear the theme cache of your Drupal site by visiting http://yoursite.com/admin/build/themes and visit http://yoursite.com/node/xxxx to see the raw JSON feed.
You should now be able to use a jQuery method like $.getJSON or $.ajax in your Wordpress theme to consume and display the JSON feed, or possibly use json_decode and curl to output your array as HTML.
A good thing about Drupal's drupal_json function is that it already sends the correct JSON headers, so now all you have to do is write the jQuery or PHP that does what you need.
I'm assumed you are more of a Wordpress specialist and have a working knowledge of Drupal but maybe not a lot of familiarity with its inner workings. So, sorry if it seemed too basic (or not basic enough :).
The Drupal theming engine is very modular - you may be able to make an appropriate PHP call into Drupal to get just the menu rendered, then emit that HTML as a part of your WordPress page.
g_thom's answer is very good and if you wish to create a very simple module to output the main navigation you can write something like this:
<?php
function getmenus_help($path, $arg) {
// implementing the help hook ... well, not doing anything with it just now actually
}
function getmenus_all() {
$page_content = '';
$page_content = json_encode(menu_navigation_links(variable_get('menu_primary_links_source', 'primary-links')));
// fill $page_content with the menu html
print $page_content;
return NULL;
}
function getmenus_menu() {
$items = array();
$items['getmenus'] = array(
'title' => 'Get Menus',
'page callback' => 'getmenus_all',
'access arguments' => array('access getmenus'),
'type' => MENU_CALLBACK,
);
return $items;
}
// permissions
function getmenus_perm() {
return array('access getmenus');
}
In your PHP code you can then write something like:
function primary_links() {
$primary_links = file_get_contents(SITE_URL . '/getmenus');
$primary_links = json_decode($primary_links);
$primary_links = (array)$primary_links;
$i = 0;
$last = count($primary_links);
$output = '';
foreach ($primary_links as $pm) {
$href = $pm->href;
if (strpos($pm->href, 'http://') === FALSE) {
if ($pm->href == '<front>') {
$href = SITE_URL . '/';
} else {
$href = SITE_URL . '/' . $pm->href;
}
}
$output .= '
<li>
'.$pm->title.'</li>';
$i++;
}
return $output;
}
I hope this helps!
PS: Make sure you update the module's permissions to allow anonymous users to have access to the path you set in your module - otherwise you will get a 403 Permission Denied.

Categories