marquee shortcode for wordpress not working - marquee

I want to add marquee tag short code its not working.How to add it in the front end ?
function marquee_shortcode( $atts, $content = null )
{
return '<marqee>'.$content.'</marqee>';
}
add_shortcode( 'marquee', 'marquee_shortcode' );

add_shortcode( 'marquee', function ($content = null ) {
return (isset($content) && !empty($content))? ''.$content.'' : 'Please provide content';
});
will do the trick

Related

What I did wrong with Db::getInstance()->insert('product', $dimension)); not inserting data to database?

I am developing a module that would save a custom field from product admin.. but my code is not inserting data into database.. below is my code.
public function hookActionProductUpdate($params)
{
if(Tools::isSubmit('submitDimension'))
{
$name = Tools::getValue('name');
$length = Tools::getValue('custom_length');
$width = Tools::getValue('custom_width');
if(empty($name) || !Validate::isGenericName($name))
$this->errors[] = $this->module->l('Invalid name');
if(empty($length) || !Validate::isGenericName($length))
$this->errors[] = $this->module->l('Invalid length');
if(empty($width) || !Validate::isGenericName($width))
$this->errors[] = $this->module->l('Invalid width');
if(!$this->errors)
{
$dimension = array(
'name' => $name,
'custom_length' => $length,
'custom_width' => $width
);
if(!Db::getInstance()->insert('product', $dimension));
$this->errors[] = Tools::displayError('Error while updating database');
}
}
}
Anyone can help me please..
Here is my install function
function install()
{
if (!parent::install() ||
!$this->alterProductTable() ||
!$this->registerHook('extraright') ||
!$this->registerHook('displayAdminProductsExtra') ||
!$this->registerHook('actionProductSave') ||
!$this->registerHook('actionProductUpdate') ||
!$this->registerHook('header')
)
return false;
return true;
}
Here is my alter table function
private function alterProductTable($method = 'add')
{
if($method = 'add')
$sql = '
ALTER TABLE '._DB_PREFIX_.'product
ADD COLUMN `custom_length` decimal(20,6) NOT NULL,
ADD COLUMN `custom_width` decimal(20,6) NOT NULL,
ADD COLUMN `name` VARCHAR(64) NOT NULL';
if(!Db::getInstance()->Execute($sql))
return false;
return true;
}
.. the columns are there..
And here is my display admin hook
public function hookDisplayAdminProductsExtra($params)
{
$name = Db::getInstance()->getValue('SELECT `name` FROM '._DB_PREFIX_.'product WHERE id_product = '.Tools::getValue('id_product'));
$length = Db::getInstance()->getValue('SELECT custom_length FROM '._DB_PREFIX_.'product WHERE id_product = '.(int)Tools::getValue('id_product'));
$width = Db::getInstance()->getValue('SELECT custom_width FROM '._DB_PREFIX_.'product WHERE id_product = '.(int)Tools::getValue('id_product'));
$this->context->smarty->assign(array(
'name' => $name,
'length' => $length,
'width' => $width
));
return $this->display(__FILE__, 'views/templates/hook/adminProductsExtra.tpl');
}
I have been looking at this for 2 days.. and I cant seem to find what I did wrong.. I have gone to prestashop forum but no help so far.. I hope I can get something from good people here. thanks in advance!
Do you check the Prestashop db best practice guide if not than please check first.
This is not the correct way to insert data you also need to mention fields in which you want to insert data particular table.
Best Practices of the Db Class - Prestashop
All is wrong, you are trying to insert data in a table which have many other fields required, and you are trying also to insert data in columns that doesn't exist in that table. The best way to create new products by code is using their object, like this...
$product = new Product()
$product->id_tax_rules_group = 1;
$product->redirect_type = '404';
$product->name = array(
$id_lang => 'Product name in this lang',
$id_lang => 'Product name in this lang',
);
/*
* And so on all the mandatory fields
*/
$product->save();

how to add an image to product in prestashop

i have a pragmatically added product in my code , the product is added to presta correctly but not about its image .
here is some part of my code that i used :
$url= "localhost\prestashop\admin7988\Hydrangeas.jpg" ;
$id_productt = $object->id;
$shops = Shop::getShops(true, null, true);
$image = new Image();
$image->id_product = $id_productt ;
$image->position = Image::getHighestPosition($id_productt) + 1 ;
$image->cover = true; // or false;echo($godyes[$dt][0]['image']);
if (($image->validateFields(false, true)) === true &&
($image->validateFieldsLang(false, true)) === true && $image->add())
{
$image->associateTo($shops);
if (! self::copyImg($id_productt, $image->id, $url, 'products', false))
{
$image->delete();
}
}
but my product have not any image yet
the problem is in copyImg method ...
here is my copyImg function :
function copyImg($id_entity, $id_image = null, $url, $entity = 'products')
{
$tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
$watermark_types = explode(',', Configuration::get('WATERMARK_TYPES'));
switch ($entity)
{
default:
case 'products':
$image_obj = new Image($id_image);
$path = $image_obj->getPathForCreation();
break;
case 'categories':
$path = _PS_CAT_IMG_DIR_.(int)$id_entity;
break;
}
$url = str_replace(' ' , '%20', trim($url));
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
if (!ImageManager::checkImageMemoryLimit($url))
return false;
// 'file_exists' doesn't work on distant file, and getimagesize make the import slower.
// Just hide the warning, the traitment will be the same.
if (#copy($url, $tmpfile))
{
ImageManager::resize($tmpfile, $path.'.jpg');
$images_types = ImageType::getImagesTypes($entity);
foreach ($images_types as $image_type)
ImageManager::resize($tmpfile, $path.'-'.stripslashes($image_type['name']).'.jpg', $image_type['width'],
$image_type['height']);
if (in_array($image_type['id_image_type'], $watermark_types))
Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity));
}
else
{
unlink($tmpfile);
return false;
}
unlink($tmpfile);
return true;
}
can anybody help me ?
You have 2 issues:
You are passing 5th parameter (with value) to copyImg, while the function does not have such.
Your foreach ($images_types as $image_type) loop must include the Hook as well (add open/close curly braces).
foreach ($images_types as $image_type)
{
ImageManager::resize($tmpfile, $path.'-'.stripslashes($image_type['name']).'.jpg', $image_type['width'], $image_type['height']);
if (in_array($image_type['id_image_type'], $watermark_types))
Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity));
}
You should also check if the product is imported correctly, expecially the "link_rewrite" and if the image is phisically uploaded in the /img/ folder.

header function is not working on online server

I have been having problem with header(); This script was generated by dreamweaver login. why will it work on some hosting company and do not work on the company i m hosting?
I have notice that header() do not work on my hosting company at all on all my pages. why do i have this problem?
if (PHP_VERSION >= 5.2) {
session_regenerate_id(true);
} else {
session_regenerate_id();
}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess ); }
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
It looks like there is a problem with the brackets around the header() calls:
if (PHP_VERSION >= 5.2) {
session_regenerate_id(true);
} else {
session_regenerate_id();
}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
// changes made below <------
if (isset($_SESSION['PrevUrl']) && false) { <--- && false needs fixing
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
header("Location: " . $MM_redirectLoginSuccess );
} else {
header("Location: " . $MM_redirectLoginFailed );
}
Edit - the && false in the if statement will also always fail, this needs to be resolved.
add that code below after <body>
ob_start();
add that code below before </body>
ob_end_flush();
and voola problem solved. ^_^

Prestashop custom tab in Back Office

I'm developing a module for prestashop 1.5.3. I need to create a custom admin tab during the module installation. I make the install like this
public function install()
{
if( (parent::install() == false)||(!$this->_createTab()) )
return false;
return true;
}
And the _createTab method is:
private function _createTab()
{
$tab = new Tab();
$tab->id_parent = 7; // Modules tab
$tab->class_name='AdminWarranty';
$tab->module='fruitwarranty';
$tab->name[(int)(Configuration::get('PS_LANG_DEFAULT'))] = $this->l('Warranty');
$tab->active=1;
if(!$tab->save()) return false;
return true;
}
And nothing happens.. What am I doing wrong.. and where to find good prestashop developer reference.?
To create a custom tab for a module during installation you can use the following code.
Note: I am considering a test module called News.
private function _createTab()
{
/* define data array for the tab */
$data = array(
'id_tab' => '',
'id_parent' => 7,
'class_name' => 'AdminNews',
'module' => 'news',
'position' => 1, 'active' => 1
);
/* Insert the data to the tab table*/
$res = Db::getInstance()->insert('tab', $data);
//Get last insert id from db which will be the new tab id
$id_tab = Db::getInstance()->Insert_ID();
//Define tab multi language data
$data_lang = array(
'id_tab' => $id_tab,
'id_lang' => Configuration::get('PS_LANG_DEFAULT'),
'name' => 'News'
);
// Now insert the tab lang data
$res &= Db::getInstance()->insert('tab_lang', $data_lang);
return true;
} /* End of createTab*/
I hope the above code will help
Thanks
Well, I'm myself developing a PrestaShop module so in case someone lands here, the proper way.
For root tabs:
$rootTab = new Tab();
$rootTab->active = 1;
$rootTab->class_name = 'YourAdminControllerName';
$rootTab->name = array();
foreach (Language::getLanguages(true) as $lang) {
$rootTab->name[$lang['id_lang']] = $this->l("Root tab");
}
$rootTab->id_parent = 0; // No parent
$rootTab->module = $this->name;
$rootTab->add();
Note for version 1.5: When creating a root tab, the system will look for a YourAdminControllerName.gif in your module's folder as the tab icon. Also please note that root tabs don't work as links, despite them requiring a class_name.
For non-root tabs:
$tab = new Tab();
$tab->active = 1;
$tab->class_name = 'YourAdminControllerName';
$tab->name = array();
foreach (Language::getLanguages(true) as $lang) {
$tab->name[$lang['id_lang']] = $this->l("Non-root tab");
}
$tab->id_parent = $rootTab->id; // Set the root tab we just created as parent
$tab->module = $this->name;
$tab->add();
If you want to set an existing tab as parent, you can use the getIdFromClassName function. For example, in your case:
$tab->id_parent = (int)Tab::getIdFromClassName('AdminModules');
The add() function returns false if it fails, so you can use it in the if() as you were trying to do with the save() function.
Sadly PrestaShop is by far the worst documented CMS system I've had to work with, and the only way to really code for it is reading code, so I hope it helps someone.

Is there a way to get the last error in php4

PHP 5 has error_get_last. Is there any way to completely or at least partially replicate the same functionality in PHP4.3?
Ripped from the PHP manual (courtesy of php at joert dot net):
<?php
if( !function_exists('error_get_last') ) {
set_error_handler(
create_function(
'$errno,$errstr,$errfile,$errline,$errcontext',
'
global $__error_get_last_retval__;
$__error_get_last_retval__ = array(
\'type\' => $errno,
\'message\' => $errstr,
\'file\' => $errfile,
\'line\' => $errline
);
return false;
'
)
);
function error_get_last() {
global $__error_get_last_retval__;
if( !isset($__error_get_last_retval__) ) {
return null;
}
return $__error_get_last_retval__;
}
}
?>
Yes it is, but you will have to do some programming, you need to attach error handler
$er_handler = set_error_handler("myErrorHandler");
but before this you need to write your "myErrorHandler"
function myErrorHandler($errNumber, $errString, $errFile, $errLine)
{
/*now add it to session so you can access it from anywhere, or if you have class with the static variable you can save it there */
$_SESSION["Error.LastError"] = $errNumber . '<br>' . $errString . '<br>' . $errFile . '<br>' . $errLine;
}
Now when error is occured you can get it by
if(isset($_SESSION["Error.LastError"]))
$str = $_SESSION["Error.LastError"];
now to replicate your method you need to create function
function get_last_error()
{
$str = "";
if(isset($_SESSION["Error.LastError"]))
$str = $_SESSION["Error.LastError"];
return $str;
}