here is my folder
index.php
smartyhere
-Smarty.class.php
admin
-index.php
-users.php
in index.php -> $smarty->display('index.tpl');
in admin/index.php -> $smarty->display('adminindex.tpl');
got error Smarty error: unable to read resource: "adminindex.tpl"
any idea ?
thx
try to understand code
which urlencode is doing path
<?php
print_r($file);
if (isset($file)) {
$var = explode("-", $file);
print_r($var);
$prefix = $var[0];
$script = $var[1];
} else {
$file = "c-home1";
$prefix = "c";
$script = "home";
$modid = 0;
}
if ($script=="") {
$script="prod_list";
}
/*
* following code finds out the modules from suffix
* and find out the script name
*/
switch ($prefix) {
case "c":
$module = "content";
break;
case "m":
$module = "myaccount";
break;
default:
$module = "content";
break;
}
$smarty->assign("module",$module);
/*
* following code finds out the modules from suffix and
* find out the script name
*/
$include_script .= $module."/".$script.".php";
if (file_exists($include_script)) {
include_once $include_script;
} else {
include_once "content/error.php";
}
if ($script!='home') {
if ($script == 'termsandcondition') {
$smarty->display("content/termsandcondition.tpl");
} else {
$smarty->display("template.tpl");
}
} else {
$smarty->display("template_home.tpl");
$smarty->assign("msg", $msg);
$smarty->assign("msglogin", $msglogin);
}
Related
I am trying to unlink files that were created the day before
I have a custom application > core > MY_Log.php file and it creates a log for each error level. For easier reading.
logs > DEBUG-04-08-2016.php
logs > ERROR-04-08-2016.php
logs > INFO-04-08-2016.php
logs > DEBUG-03-08-2016.php
logs > ERROR-03-08-2016.php
logs > INFO-03-08-2016.php
Question how am I able to modify the write_log so could delete / unlink files that were created the day before?
<?php
class MY_Log extends CI_Log {
public function write_log($level, $msg)
{
if ($this->_enabled === FALSE)
{
return FALSE;
}
$level = strtoupper($level);
if (( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
&& ! isset($this->_threshold_array[$this->_levels[$level]]))
{
return FALSE;
}
$filepath = $this->_log_path . $level .'-'. date('d-m-Y').'.'.$this->_file_ext;
$message = '';
if ( ! file_exists($filepath))
{
$newfile = TRUE;
// Only add protection to php files
if ($this->_file_ext === 'php')
{
$message .= "";
}
}
if ( ! $fp = #fopen($filepath, 'ab'))
{
return FALSE;
}
flock($fp, LOCK_EX);
// Instantiating DateTime with microseconds appended to initial date is needed for proper support of this format
if (strpos($this->_date_fmt, 'u') !== FALSE)
{
$microtime_full = microtime(TRUE);
$microtime_short = sprintf("%06d", ($microtime_full - floor($microtime_full)) * 1000000);
$date = new DateTime(date('d-m-Y H:i:s.'.$microtime_short, $microtime_full));
$date = $date->format($this->_date_fmt);
}
else
{
$date = date($this->_date_fmt);
}
$message .= $this->_format_line($level, $date, $msg);
for ($written = 0, $length = strlen($message); $written < $length; $written += $result)
{
if (($result = fwrite($fp, substr($message, $written))) === FALSE)
{
break;
}
}
flock($fp, LOCK_UN);
fclose($fp);
if (isset($newfile) && $newfile === TRUE)
{
chmod($filepath, $this->_file_permissions);
}
return is_int($result);
}
}
First of use
$config['log_threshold'] = 1;
For only error message, so there will be less number of files
Add below code just before $filepath; to delete previous date logs
$unlink_date = date('Y-m-d',strtotime("-1 days"));
$filepath_unlink = $this->_log_path . $level .'-'. $unlink_date.'.'.$this->_file_ext;
if ( file_exists($filepath_unlink))
{
unlink($filepath_unlink);
}
I use codeigniter 3.0.6 query string like
index.php?d=directoryt&c=controller
index.php?d=directory&c=controller&m=function
How ever having two get methods for directory and controller is a bit long.
Question Is there any way to modify the protected function
_set_routing() function using a MY_Router.php to get it so it will pick up the directory and controller by using one query only like example below.
index.php?route=directory/controller
// If need to get function
index.php?route=directory/controller&m=function
What have tried so far
<?php
class MY_Router extends CI_Router {
protected function _set_routing()
{
// Load the routes.php file. It would be great if we could
// skip this for enable_query_strings = TRUE, but then
// default_controller would be empty ...
if (file_exists(APPPATH.'config/routes.php'))
{
include(APPPATH.'config/routes.php');
}
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
}
// Validate & get reserved routes
if (isset($route) && is_array($route))
{
isset($route['default_controller']) && $this->default_controller = $route['default_controller'];
isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes'];
unset($route['default_controller'], $route['translate_uri_dashes']);
$this->routes = $route;
}
// Are query strings enabled in the config file? Normally CI doesn't utilize query strings
// since URI segments are more search-engine friendly, but they can optionally be used.
// If this feature is enabled, we will gather the directory/class/method a little differently
if ($this->enable_query_strings)
{
// If the directory is set at this time, it means an override exists, so skip the checks
if ( ! isset($this->directory))
{
$_route = isset($_GET['route']) ? trim($_GET['route'], " \t\n\r\0\x0B/") : '';
if ($_route !== '')
{
echo $_route;
$this->uri->filter_uri($_route);
$this->set_directory($_route);
}
}
// Routing rules don't apply to query strings and we don't need to detect
// directories, so we're done here
return;
}
// Is there anything to parse?
if ($this->uri->uri_string !== '')
{
$this->_parse_routes();
}
else
{
$this->_set_default_controller();
}
}
}
config.php
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
// Modifyed in MY_Router.php
$config['route'] = 'route';
I have it working
<?php
class MY_Router extends CI_Router {
protected function _set_routing() {
if (file_exists(APPPATH.'config/routes.php'))
{
include(APPPATH.'config/routes.php');
}
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
}
// Validate & get reserved routes
if (isset($route) && is_array($route))
{
isset($route['default_controller']) && $this->default_controller = $route['default_controller'];
isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes'];
unset($route['default_controller'], $route['translate_uri_dashes']);
$this->routes = $route;
}
if ($this->enable_query_strings) {
if ( ! isset($this->directory))
{
$route = isset($_GET['route']) ? trim($_GET['route'], " \t\n\r\0\x0B/") : '';
if ($route !== '')
{
$part = explode('/', $route);
$this->uri->filter_uri($part[0]);
$this->set_directory($part[0]);
if ( ! empty($part[1])) {
$this->uri->filter_uri($part[1]);
$this->set_class($part[1]);
// Testing function atm
if ( ! empty($_GET['function']))
{
$this->uri->filter_uri($_GET['function']);
$this->set_method($_GET['function']);
}
$this->uri->rsegments = array(
1 => $this->class,
2 => $this->method
);
}
} else {
$this->_set_default_controller();
}
}
// Routing rules don't apply to query strings and we don't need to detect
// directories, so we're done here
return;
}
// Is there anything to parse?
if ($this->uri->uri_string !== '')
{
$this->_parse_routes();
}
else
{
$this->_set_default_controller();
}
}
}
I want to use Dataflow-Advanced profile to import the csv from frontend. i have googled and find a stand-alone script for that, but problem is that now this script work only for fixed csv file. I want to change the csv file name on run time to import through stand-alone script. Please refer screen-shot link https://www.diigo.com/item/image/5hhy6/7pxw?size=o to more clear. Could anyone help me to get achieve this?
Here is sample script:
require_once 'app/Mage.php';
umask(0);
ini_set("memory_limit","1024M");
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_ADMINHTML,
Mage_Core_Model_App_Area::PART_TRANSLATE);
setlocale(LC_ALL, 'en_US');
$localeName = "en_US";
Mage::app()->getLocale()->setDefaultLocale($localeName);
Mage::app()->getLocale()->setLocale($localeName);
Mage::app()->getLocale()->setLocaleCode($localeName);
setlocale(LC_ALL, Mage::app()->getLocale()->getLocaleCode());
Mage::app()->setCurrentStore(0);
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_ADMINHTML, Mage_Core_Model_App_Area::PART_TRANSLATE);
Mage::app();
$profileId = 11; //put your profile id here
$logFileName= date("j-n-Y")."-import.log";
$recordCount = 0;
Mage::log("Import Started",null,$logFileName);
$profile = Mage::getModel('dataflow/profile');
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(0);
Mage::getSingleton('admin/session')->setUser($userModel);
if ($profileId) {
$profile->load($profileId);
if (!$profile->getId()) {
Mage::getSingleton('adminhtml/session')->addError('The profile you are trying to save no longer exists');
}
}
Mage::register('current_convert_profile', $profile);
$profile->run();
$batchModel = Mage::getSingleton('dataflow/batch');
if ($batchModel->getId()) {
if ($batchModel->getAdapter()) {
$batchId = $batchModel->getId();
$batchImportModel = $batchModel->getBatchImportModel();
$importIds = $batchImportModel->getIdCollection();
$batchModel = Mage::getModel('dataflow/batch')->load($batchId);
$adapter = Mage::getModel($batchModel->getAdapter());
$adapter->setBatchParams($batchModel->getParams());
foreach ($importIds as $importId) {
$recordCount++;
try{
$batchImportModel->load($importId);
if (!$batchImportModel->getId()) {
$errors[] = Mage::helper('dataflow')->__('Skip undefined row');
continue;
}
$importData = $batchImportModel->getBatchData();
try {
$adapter->saveRow($importData);
} catch (Exception $e) {
Mage::log($e->getMessage(),null,$logFileName);
continue;
}
if ($recordCount%20 == 0) {
Mage::log($recordCount . ' - Completed!!',null,$logFileName);
}
} catch(Exception $ex) {
Mage::log('Record# ' . $recordCount . ' - Error - ' . $ex->getMessage(),null,$logFileName);
}
}
foreach ($profile->getExceptions() as $e) {
Mage::log($e->getMessage(),null,$logFileName);
}
}
}
Mage::log("Import Completed",null,$logFileName);
Looking forward for positive response!
Thanks in advance!
I got the solution.
require_once 'app/Mage.php';
umask(0);
ini_set("memory_limit","1024M");
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_ADMINHTML,
Mage_Core_Model_App_Area::PART_TRANSLATE);
setlocale(LC_ALL, 'en_US');
$localeName = "en_US";
Mage::app()->getLocale()->setDefaultLocale($localeName);
Mage::app()->getLocale()->setLocale($localeName);
Mage::app()->getLocale()->setLocaleCode($localeName);
setlocale(LC_ALL, Mage::app()->getLocale()->getLocaleCode());
Mage::app()->setCurrentStore(0);
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_ADMINHTML, Mage_Core_Model_App_Area::PART_TRANSLATE);
Mage::app();
$profileId = 11; //put your profile id here
$logFileName= date("j-n-Y")."-import.log";
$recordCount = 0;
Mage::log("Import Started",null,$logFileName);
$profile = Mage::getModel('dataflow/profile');
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(0);
Mage::getSingleton('admin/session')->setUser($userModel);
if ($profileId) {
$profile->load($profileId);
if (!$profile->getId()) {
Mage::getSingleton('adminhtml/session')->addError('The profile you are trying to save no longer exists');
}
//code to change the csv file name :: START
//echo "<pre>"; print_r($profile->getData('actions_xml')); echo "</pre>";
$str = $profile->getData('actions_xml');
$newCsv = 'import_products_new.csv'; // put your logic to get new file name as per your requirement
$new_action_xml = str_replace('import_products_old.csv', $newCsv, $str); //'import_products_old.csv' using static, as we know filename in already saved profile
$profile->setActionsXml($new_action_xml);
//code to change the csv file name :: END
}
Mage::register('current_convert_profile', $profile);
$profile->run();
$batchModel = Mage::getSingleton('dataflow/batch');
if ($batchModel->getId()) {
if ($batchModel->getAdapter()) {
$batchId = $batchModel->getId();
$batchImportModel = $batchModel->getBatchImportModel();
$importIds = $batchImportModel->getIdCollection();
$batchModel = Mage::getModel('dataflow/batch')->load($batchId);
$adapter = Mage::getModel($batchModel->getAdapter());
$adapter->setBatchParams($batchModel->getParams());
foreach ($importIds as $importId) {
$recordCount++;
try{
$batchImportModel->load($importId);
if (!$batchImportModel->getId()) {
$errors[] = Mage::helper('dataflow')->__('Skip undefined row');
continue;
}
$importData = $batchImportModel->getBatchData();
try {
$adapter->saveRow($importData);
} catch (Exception $e) {
Mage::log($e->getMessage(),null,$logFileName);
continue;
}
if ($recordCount%20 == 0) {
Mage::log($recordCount . ' - Completed!!',null,$logFileName);
}
} catch(Exception $ex) {
Mage::log('Record# ' . $recordCount . ' - Error - ' . $ex->getMessage(),null,$logFileName);
}
}
foreach ($profile->getExceptions() as $e) {
Mage::log($e->getMessage(),null,$logFileName);
}
}
}
Mage::log("Import Completed",null,$logFileName);
Hope this helps someone!
Thanks!
I am working with magento and have a question in mind that why we use $this__("Some text") instead simple echo magento. can anyone ?
When you call
echo $this->__("some text");
You can start by looking at Mage_Core_Helper_Abstract
/**
* Translate
*
* #return string
*/
public function __()
{
$args = func_get_args();
$expr = new Mage_Core_Model_Translate_Expr(array_shift($args), $this->_getModuleName());
array_unshift($args, $expr);
return Mage::app()->getTranslator()->translate($args);
}
Next is Mage_Core_Model_App
/**
* Retrieve translate object
*
* #return Mage_Core_Model_Translate
*/
public function getTranslator()
{
if (!$this->_translator) {
$this->_translator = Mage::getSingleton('core/translate');
}
return $this->_translator;
}
Which is handed to Mage_Core_Model_Translate
/**
* Translate
*
* #param array $args
* #return string
*/
public function translate($args)
{
$text = array_shift($args);
if (is_string($text) && ''==$text
|| is_null($text)
|| is_bool($text) && false===$text
|| is_object($text) && ''==$text->getText()) {
return '';
}
if ($text instanceof Mage_Core_Model_Translate_Expr) {
$code = $text->getCode(self::SCOPE_SEPARATOR);
$module = $text->getModule();
$text = $text->getText();
$translated = $this->_getTranslatedString($text, $code);
}
else {
if (!empty($_REQUEST['theme'])) {
$module = 'frontend/default/'.$_REQUEST['theme'];
} else {
$module = 'frontend/default/default';
}
$code = $module.self::SCOPE_SEPARATOR.$text;
$translated = $this->_getTranslatedString($text, $code);
}
//array_unshift($args, $translated);
//$result = #call_user_func_array('sprintf', $args);
$result = #vsprintf($translated, $args);
if ($result === false) {
$result = $translated;
}
if ($this->_translateInline && $this->getTranslateInline()) {
if (strpos($result, '{{{')===false || strpos($result, '}}}')===false || strpos($result, '}}{{')===false) {
$result = '{{{'.$result.'}}{{'.$translated.'}}{{'.$text.'}}{{'.$module.'}}}';
}
}
return $result;
}
which returns the resulting text. This is a quick walkthrough of how everything would be handled, you should view the classes themselves to get a more in-depth understanding.
In simple when you call echo $this->__('some text') it look up same
text in CSV file which is located in
app>locale
or
app>design>frontend>YOUR_PACKAGE>YOUR_THEME_NAME>locale>translate.csv
file if the same word exist then it translate a word
means it is very useful in multi-language website
$this->__("Some text")
Used for translation purpose
I am using dataflow profile however this does not allow to export entity_id or product ID from magento. This is needed by us to integrate some remarketing code where I can't use SKU. Is there anyway to export entity_id with the dataflow profile.
Second I have to run the dataflow profile every 24 hours.
Regards,
Farrukh Khan
You can take the help from following url to export product id
http://www.vuleticd.com/2013/01/27/export-product-ids-with-magento-dataflow-advanced-profiles/
To run the dataflow profile you have to configure a script to run every 24 hrs.
Use the following code and you have to only change the profileId & csv file name.
<?php
require_once 'app/Mage.php';
umask(0);
Mage::app();
$profileId = 7; //put your profile id here
$filename = "cronimport.csv"; //file needs to be present in var/import directory
if (!isset($filename)) {
die("No file has been set!");
}
$logFileName= $filename.'_'.date('m_d_Y h_i_s_a', time()).'.log';
$recordCount = 0;
Mage::log("Import Started",null,$logFileName);
$profile = Mage::getModel('dataflow/profile');
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(1);
Mage::getSingleton('admin/session')->setUser($userModel);
if ($profileId) {
$profile->load($profileId);
if (!$profile->getId()) {
Mage::getSingleton('adminhtml/session')->addError('The profile you are trying to save no longer exists');
}
}
Mage::register('current_convert_profile', $profile);
$profile->run();
$batchModel = Mage::getSingleton('dataflow/batch');
if ($batchModel->getId())
{
if ($batchModel->getAdapter())
{
//#mail('EMAIL_ADDRESS','Cron started','Test','');
$batchId = $batchModel->getId();
$batchImportModel = $batchModel->getBatchImportModel();
$importIds = $batchImportModel->getIdCollection();
$batchModel = Mage::getModel('dataflow/batch')->load($batchId);
$adapter = Mage::getModel($batchModel->getAdapter());
foreach ($importIds as $importId) {
$recordCount++;
try{
$batchImportModel->load($importId);
if (!$batchImportModel->getId()) {
$errors[] = Mage::helper('dataflow')->__('Skip undefined row');
continue;
}
$importData = $batchImportModel->getBatchData();
try {
$adapter->saveRow($importData);
} catch (Exception $e) {
Mage::log($e->getMessage(),null,$logFileName);
continue;
}
if ($recordCount%20 == 0) {
//Mage::log($recordCount . ' - Completed!!',null,$logFileName);
}
} catch(Exception $ex) {
Mage::log('Record# ' . $recordCount . ' - SKU = ' . $importData['sku']. ' - Error - ' . $ex->getMessage(),null,$logFileName);
}
}
foreach ($profile->getExceptions() as $e) {
Mage::log($e->getMessage(),null,$logFileName);
}
}
}
echo 'Import Completed';
Mage::log("Import Completed",null,$logFileName);
//#mail('YOUR EMAIL','Cron Ended','Test','');
?>