I am using libtidy with php. I am using xampp and it shows that tidy support is enabled. But when i use it in my code then it shows the following warning
repairString() [function.repairString]: Could not load configuration file tidy-file.php
i also tried using the object-oriented version but i again got the warning
tidy_repair_string() [function.tidy-repair-string]: Could not load configuration file tidy-file.php
i have kept the tidy code in a separate file called tidy-file.php. it looks like this
$options = array("output-xhtml" => true,"clean" => true, "drop-proprietary-attributes" => true,"drop-font-tags" => true,"drop-empty-paras" => true,"hide-comments" => true);
function getXHTML($html)
{
$xhtml=tidy_repair_string($html,$options);
return $xhtml;
}
what can be wrong
From what you've shown here, you're trying to use a variable that's defined outside the function. You need to pull it inside like so:
function getXHTML($html)
{
$options = array("output-xhtml" => true,"clean" => true, "drop-proprietary-attributes" => true,"drop-font-tags" => true,"drop-empty-paras" => true,"hide-comments" => true);
$xhtml=tidy_repair_string($html,$options);
return $xhtml;
}
Related
Goodmorning everyone,
I'm new in Drupal.
I hope don't ask a stupid question.
I'm working with Drupal 7 and I need to edit a custom module for my company developed by another developer.
This is a piece of code where I use "theme" function.
This code is under "sites/all/modules/gestione_attivita_attivita/gestione_attivita_attivita.module"
function gestione_attivita_attivita_block_search_attivita($tipo_ricerca) {
$block['subject'] = "";
$ricerca = gestione_attivita_ricerca_fetchAll($tipo_ricerca);
$block['content'] = theme('ricerca_attivita', array(
'items' => $ricerca,
'tipo_ricerca' => $tipo_ricerca
));
return $block;
}
I know that should exist "ricerca_attivita" hook declared somehere in my files.
I'v been looking for something like "['ricerca_attivita'] = array(" or similar words or sub-words in all my files of my site folder but it doesn't exist.
The only thing I know is that under :"sites/all/themes/customModuleOfmyCompany/templates" there are several tpl files and in particular one called "ricerca_attivita.tpl.php" that work and receives data from theme function but I don't know how this is possible.
I don't know who tell to theme call to go on another folder on another path and use "ricerca_attivita.tpl.php" and not foo.tpl.php for example.
Is there anyone that can help me?
Another thing:
Going under includes/theme.inc and debugginng it I have this printing hook info:
array (
'template' => 'ricerca_attivita',
'path' => 'sites/all/themes/customtheme/templates',
'type' => 'theme_engine',
'theme path' => 'sites/all/themes/customtheme',
'preprocess functions' =>
array (
0 => 'template_preprocess',
1 => 'contextual_preprocess',
),
'process functions' =>
array (
0 => 'template_process',
1 => 'ctools_process',
2 => 'rdf_process',
),
)
but I don't know who is that declare it
I think you should use the developer module for themers https://www.drupal.org/project/devel_themer
And about theming function, did you search for this function inside the themes folder?
Hope that helps.
I'm new to theming and I just inherited this code. I need to control where and how to print #output but it's always showing up at the top of the page, above the HTML tags. I looked at the renderable arrays API but I couldn't find anything specific to my problem.
In mytheme.module:
function mytheme_output_block() {
$content = array(
'#theme' => 'my_theme',
'#output' => function_that_returns_JSON();
...
function mytheme_hook_theme() {
return array(
'my_theme' => array(
'vars' => array(
'output' => '',
...
And in my_theme.tpl.php I tried:
<?php print $output; ?>
But it gets ignored. How do I control #output so I can style it?
not super sure but you might need to call the array element directly. Something like:
$theme = mytheme_hook_theme();
echo $theme['output'];
Hope it helps
Which Drupal you use? I assume D7.
Take a look at the documentation of hook_theme: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_theme/7.x
It's not vars - it's variables
You have missed the template key in your implementation
template: If specified, this theme implementation is a template, and this is the template file without an extension. Do not put .tpl.php on this file; that extension will be added automatically by the default rendering engine (which is PHPTemplate). If 'path', above, is specified, the template should also be in this path.
So what your hook should look like:
function mytheme_hook_theme() {
return array(
'my_theme' => array(
'variables' => array(
'output' => '',
),
'template' => 'my-theme',
...
Remember to clear the caches afterwards.
I am trying to update a sql database table using the data of an excel file (.csv) in Laravel using the Laravel Excel repository.
My Controller function gives back the content of the excel file, but just in an array of 2 (it should be 604).
Therefore, I think I would have to add 'line ending \t' to my function.But I do not know how.
Here is what I know so far:
The controller
public function uploadExcel()
{
Excel::load(Input::file('import_file'), function ($reader) {
foreach ($reader->toArray() as $value) {
$insert[] = [
'member_title' => $value->member_title,
'member_first_name' => $value->member_first_name,
'member_name_affix' => $value->member_name_affix,
'member_last_name' => $value->member_last_name,
'member_private_address' => $value->member_private_address,
'member_private_zip_code' => $value->member_private_zip_code,
'member_private_location' => $value->member_private_location,
'member_private_phone' => $value->member_private_phone,
'member_private_mobile' => $value->member_private_mobile,
'member_private_fax' => $value->member_private_fax,
'member_private_mail' => $value->member_private_mail,
'member_business_position' => $value->member_business_position,
'member_business_name' => $value->member_business_name,
'member_business_address' => $value->member_business_address,
'member_business_zip_code' => $value->member_business_zip_code,
'member_business_location' => $value->member_business_location,
'member_business_area_code' => $value->member_business_area_code,
'member_business_phone' => $value->member_business_phone,
'member_business_fax' => $value->member_business_fax,
'member_business_mobile' => $value->member_business_mobile,
'member_business_mail' => $value->member_business_mail,
'member_join_date' => $value->member_join_date,
'extra' => $value->extra
];
}
});
if(!empty($insert)) {
die(var_dump($insert)); <-- puts out the array for testing
DB::table('members')->insert($insert);
}
return redirect('index.index');
}
According to the official documentation I would have to add this to my project to recognize the correct line endings:
class UserListImport extends \Maatwebsite\Excel\Files\ExcelFile {
protected $lineEnding = '\t';
}
If my hunch is correct and this snippet from the documentation would solve my problem:
Where do I have to create this file, which contains the code from the documentation? And do I have to change anything else to make that file take affect?
I am really new to Laravel and I would be very thankful for any kind of help!!
UPDATE
Error message
Class App\UserListImport contains 1 abstract method and must therefore
be declared abstract or implement the remaining methods
(Maatwebsite\Excel\Files\ExcelFile::getFile)
app/UserListImport.php
namespace App;
class UserListImport extends \Maatwebsite\Excel\Files\ExcelFile {
protected $lineEnding = '\t';
public function loadExcel() {
Excel::load(Input::file('import_file'), function ($reader) {
foreach ($reader->toArray() as $value) {
$insert[] = [
'member_title' => $value->member_title,
'member_first_name' => $value->member_first_name,
'member_name_affix' => $value->member_name_affix,
'member_last_name' => $value->member_last_name,
'member_private_address' => $value->member_private_address,
'member_private_zip_code' => $value->member_private_zip_code,
'member_private_location' => $value->member_private_location,
'member_private_phone' => $value->member_private_phone,
'member_private_mobile' => $value->member_private_mobile,
'member_private_fax' => $value->member_private_fax,
'member_private_mail' => $value->member_private_mail,
'member_business_position' => $value->member_business_position,
'member_business_name' => $value->member_business_name,
'member_business_address' => $value->member_business_address,
'member_business_zip_code' => $value->member_business_zip_code,
'member_business_location' => $value->member_business_location,
'member_business_area_code' => $value->member_business_area_code,
'member_business_phone' => $value->member_business_phone,
'member_business_fax' => $value->member_business_fax,
'member_business_mobile' => $value->member_business_mobile,
'member_business_mail' => $value->member_business_mail,
'member_join_date' => $value->member_join_date,
'extra' => $value->extra
];
}
});
if(!empty($insert)) {
die(var_dump($insert));
DB::table('members')->insert($insert);
}
return redirect('index.index');
}
}
Controller
use Maatwebsite\Excel\Facades\Excel;
use App\UserListImport;
public function uploadExcel()
{
UserListImport::loadExcel();
}
The docs assumed you created a new custom class extending Excelfile.
class UserListImport extends \Maatwebsite\Excel\Files\ExcelFile
means exacly this.
I usually prefer to add my own application namespaced folders for anything that my application needs.
It this case I would extract anything out from the controller and call my own class to process Input::file('import_file'). That class is the place where to put that attribute to overwrite how the library interacts with the file.
This \t means tabulation(gap between words). For line endings the following combinations of chars are used '\n', '\r\n'. It depends on the operating system. '\n' is for Unix/Linux/Mac OS and '\r\n' is for Windows families.
I am using Laravel 4 and PHP to build a new application. It works fine on my dev server running PHP 5.4.x however my boss insist that it has to run version 5.3.2
I have spent the whole day fixing everything to work with 5.3.2 and almost have everything, so I thought, until I ran into an issue with the code below.
My problems start at this line...
DB::transaction(function($clock_in_webcam_image) use ($clock_in_webcam_image)
I believe this type of code might not work with this version of PHP? If that is the case, what are my options to run this same code or have it doing the same action?
Would appreciate any help with this. Very unfortunate that my boss told me straight out that no he will not allow us to update to a newer PHP so I am stuck in a hard spot right now
// Create a new time card record when a User Clocks In
public function createTimeCard($clock_in_webcam_image) {
// Create both Timecard and timecard record tables in a Transaction
DB::transaction(
function ($clock_in_webcam_image) use ($clock_in_webcam_image) {
$timeCard = DB::table('timeclock_timecard')->insertGetId(
array(
'user_id' => $this->user->user_id,
'clock_in_datetime' => $this->dateTime->format($this->dateFormat),
'clock_in_timestamp' => $this->dateTime->getTimestamp(),
'clock_in_webcam_image' => $clock_in_webcam_image
)
);
$timeCardPunchEntry = DB::table('timeclock_punch_entry')
->insertGetId(
array(
'timecard_id' => $timeCard,
'user_id' => $this->user->user_id,
'created_at_datetime' => $this->dateTime->format($this->dateFormat),
'created_at_timestamp' => $this->dateTime->getTimestamp(),
'clock_type' => 'clock_in',
'webcam_image' => $clock_in_webcam_image
)
);
return $timeCard;
}
);
}
UPDATE
In response to bansi's comment...is this what you mean to do...
DB::transaction(function() use($myModel){
$myModel->updateTable1();
$myModel->updateTable2();
})
Before PHP 5.4.0, you could not use $this inside an anonymous function. There is a simple workaround though where you can use the use construct to pass variables into the functions scope. Also, you are using the use construct incorrectly as $clock_in_webcam_image is not defined in the parent scope.
$user = $this->user;
$dateTime = $this->dateTime;
DB::transaction(function($clock_in_webcam_image) use ($user, $dateTime) {
// snip
array(
'user_id' => $user->user_id,
'clock_in_datetime' => $dateTime->format($this->dateFormat),
'clock_in_timestamp' => $dateTime->getTimestamp(),
'clock_in_webcam_image' => $clock_in_webcam_image
)
// snip
});
try this. please check you don't have another insertTimecard defined.
// Create a new time card record when a User Clocks In
public function createTimeCard($clock_in_webcam_image)
{
// Create both Timecard and timecard record tables in a Transaction
DB::transaction($this->insertTimecard($clock_in_webcam_image));
}
private function insertTimecard($clock_in_webcam_image)
{
$timeCard = DB::table('timeclock_timecard')->insertGetId(
array(
'user_id' => $this->user->user_id,
'clock_in_datetime' => $this->dateTime->format($this->dateFormat),
'clock_in_timestamp' => $this->dateTime->getTimestamp(),
'clock_in_webcam_image' => $clock_in_webcam_image
)
);
$timeCardPunchEntry = DB::table('timeclock_punch_entry')->insertGetId(
array(
'timecard_id' => $timeCard,
'user_id' => $this->user->user_id,
'created_at_datetime' => $this->dateTime->format($this->dateFormat),
'created_at_timestamp' => $this->dateTime->getTimestamp(),
'clock_type' => 'clock_in',
'webcam_image' => $clock_in_webcam_image
)
);
return $timeCard;
}
On a fresh 1.5.0.1 Magento install when choosing Catalog from the settings->settings menu I get the following error:
Fatal error: Undefined class constant 'RANGE_CALCULATION_AUTO' in
/my-install-dir/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Price/Step.php on line 33
Checked Step.php and it does not look damaged and contains the following:
class Mage_Adminhtml_Model_System_Config_Source_Price_Step
{
public function toOptionArray()
{
return array(
array(
'value' => Mage_Catalog_Model_Layer_Filter_Price::RANGE_CALCULATION_AUTO,
'label' => Mage::helper('adminhtml')->__('Automatic')
),
array(
'value' => Mage_Catalog_Model_Layer_Filter_Price::RANGE_CALCULATION_MANUAL,
'label' => Mage::helper('adminhtml')->__('Manual')
),
);
}
}`
Anyone know this error or how to fix it?
PHP is complaining that it can't find the constant on RANGE_CALCULATION_AUTO defined on the class Mage_Catalog_Model_Layer_Filter_Price
Based on your comments above, it sounds like you already checked the file at
app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php
to ensure is had the correct constant defined.
const RANGE_CALCULATION_AUTO = 'auto';
Based on that, my guess would be there's a different Price.php being loaded for this class. This can happen if
Someone's placed a different version in community or local
Someone's monkied with the include path beyond Magento's normal monkey business
Check for files at
app/community/core/Mage/Catalog/Model/Layer/Filter/Price.php
app/local/core/Mage/Catalog/Model/Layer/Filter/Price.php
If that doesn't work, add some temporary debugging code to
app/code/core/Mage/Adminhtml/Model/System/Config/Source/Price/Step.php
that uses reflection to figure out what file PHP is loading the class from
class Mage_Adminhtml_Model_System_Config_Source_Price_Step
{
public function toOptionArray()
{
//NEW LINES HERE
$r = new ReflectionClass('Mage_Catalog_Model_Layer_Filter_Price');
var_dump($r->getFileName());
//echo $r->getFileName(); // if too long for var_dump
exit("Bailing at line ".__LINE__." in ".__FILE__);
//END NEW LINES
return array(
array(
'value' => Mage_Catalog_Model_Layer_Filter_Price::RANGE_CALCULATION_AUTO,
'label' => Mage::helper('adminhtml')->__('Automatic')
),
array(
'value' => Mage_Catalog_Model_Layer_Filter_Price::RANGE_CALCULATION_MANUAL,
'label' => Mage::helper('adminhtml')->__('Manual')
),
);
}
}`
This will dump out a file path that points to the exact place PHP is loading the class from, which should get you where you need to go.