what is issue in my preg_replace for BB CODE? anyone can help me - preg-replace

Friend! check my code first one is not working but second is working why?
1=>
$value1 = "[b]PHP 2014[/b]";
$new1 = "/(\[)([bB])(\])/e";
$v1 = preg_replace($new1,"'<'.'h1'.'>'",$value1);
echo $v1;
/* RESULT::
PHP 2014[/b]
2=>
$value2 = "<b>PHP 2014</b>";
$new2 = "/(<)([bB])([^>*]>)/e";
$v2 = preg_replace($new2,"'\\1'.'h1'.'\\3'",$value2);
echo $v2;
/* RESULT::
PHP 2014 */

Just move the asterisk out of the character class:
$new2 = "/(<)([bB])([^>]*>)/";
// here __^
Also remove the e modifier because it is obsolete.

Related

Translation in extension fails when not logged into backend

I have an extbase extension that translates some variables on pages using this
if (is_array($row) && $row['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content && $GLOBALS['TSFE']->sys_language_contentOL) {
$row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($table, $row,$GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
}
But there's a strange bug. It only works, when I'm logged into the backend. As soon as I log out, I can only see the default language.
Using Typo3 8.7
Any ideas what this could cause?
This can happen if you have config.sys_language_overlay = 0 defined globaly on your page object within your Typoscript Setup.
There is a ticket entry in the Typo3 Forge that goes a bit deeper as to why this happens and provides some workarrounds if you need those.
So, I didn't figure out what the problem was, but found my own workaround for the problem. Here's the updated Code:
$table = 'tx_myExt';
$query = "SELECT * FROM ".$table." WHERE pid=".$pid;
$query .= ' AND (sys_language_uid IN (-1,0) OR (sys_language_uid = ' .$GLOBALS['TSFE']->sys_language_uid. ' AND l10n_parent = 0))';
$query .= " AND deleted=0 AND hidden=0";
$res = $GLOBALS['TYPO3_DB']->sql_query($query);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
//localization
// check for language overlay if:
// * row is valid
// * row language is different from currently needed language
// * sys_language_contentOL is set
if (is_array($row) && $row['sys_language_uid'] != $GLOBALS['TSFE']->sys_language_content && $GLOBALS['TSFE']->sys_language_contentOL) {
$query2 = "SELECT * FROM ".$table." WHERE pid=".$pid;
$query2 .= ' AND sys_language_uid = ' .$GLOBALS['TSFE']->sys_language_content;
$query2 .= ' AND l10n_parent = ' . $row['uid'];
$query2 .= " AND deleted=0 AND hidden=0";
$res2 = $GLOBALS['TYPO3_DB']->sql_query($query2);
$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res2);
//$row = $GLOBALS['TSFE']->sys_page->getRecordOverlay($table, $row,$GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
}
}
So, instead of using getRecordOverlay I'm just repeating the query, accessing the translated record directly. I did read somewhere that this is bad practice, but hey, it works for now, that's all that matters ;)
Still, if someone finds a solution to the original problem, I'd be happy to see that.

Joomla module not working

I made a module that display how many days ago a article was published
it looks like this.
{source}
<?php
$jinput = JFactory::getDocument()->input;
$option = $jinput->get('option');
$view = $jinput->get('view');
if ($option=="com_content" && $view=="article") {
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& $jinput->get("content");
$article->load($article_id);
$date = new JDate($article->get("publish_up"));
$currentTime = new JDate('now');
$interval = $date->diff($currentTime);
if($interval->d == 0) {
echo 'dzisiaj' . "<br>";
}
else if( $interval->d == 1) {
echo 'wczoraj' . "<br>";
}
else if( $interval->d > 1) {
echo $interval->format('%a dni temu') . "<br>";
}
}
?>
{/source}
And it works on my local joomla but when use it on custom template it doesnt work. I'm using Joomla 3.4.8.
The issue is you're trying to access the input values using Document Factory that's wrong you have to use
$jinput = JFactory::getApplication()->input;
Document Factory is used for other purpose like adding , styles or Js to the pages etc. read more about input here.
Hope it make sense.

How can set up the table correctly for receiving the string converted from dates?

I have a problem and don't know how to solve it. After i run the code i didn't receive corectly a period of time. I put the code here.
I think something is wrong with table from database (i use PhpMyAdmin 4.2.0 module from EasyPhp). I put an image too to see what happens. The dates marked with red need to be at the end of table.
<?php
function data_range($first, $last, $step = '+1 day', $output - format = 'd-m-Y')
{
$dates = array();
$current = strtotime($first);
$last = strtotime($last);
while ($current <= $last)
{
$dates[] = date($output_format, $current);
$current = strtotime($step, $current);
}
foreach($dates as $zile)
{
$krr = explode('-', $zile);
var_dump($krr);
$result2 = implode('/', $krr);
echo $result2 . "<br/>";
$sql4 = "INSERT INTO studenti3 (data) VALUES ('$result2')";
$rez4 = mysql_query($sql4);
}
var_dump($dates);
}
$first = "06-04-2015";
$last = "07-05-2015";
$step = "+1day";
$output_format = 'd-m-Y';
date_range($first, $last, $step, $output_format); ?>

Prepare content does not work for Sourcerer and DirectPHP

In my Joomla website, I need to execute some custom SQL queries, that have to select different titles from related categories.
Problem I have it works like option Prepare Content is turned off, so all of my content is outside HTML tags.
Module content looks like this:
{source}
<?php
$var_result = '';
$var_categories = array();
$var_category_list = array();
$db =& JFactory::getDBO();
$query = 'select * from jneg_categories where parent_id = 9';
$db->setQuery($query,0,300);
$res = $db->loadObjectList();
foreach ( $res as $row ) {
$var_categories[($row->id)] = $row->title;
$var_category_list[] = $row->id;
}
$var_category_list = implode($var_category_list, ', ');
$sql = "select * from jneg_content where catid IN (".$var_category_list.") order by `catid`";
$db->setQuery($sql,0,30000);
$res = $db->loadObjectList();
$var_current_cat = 0;
foreach ( $res as $row ) {
if ($current_cat != $row->catid) {
$current_cat = $row->catid;
echo '<h2>'.$categories[($row->catid)] . '</h2>';
echo '<br>';
}
echo $row->title;
echo '<br>';
}
?>
{/source}
Can you help me how to get proper HTML as a result of this code please.
Sourcer or other php rendering plugins don't run in html modules unless you go under the module 'options' and select 'prepare content'...
...or you can use this module and just include your php file directly:
https://github.com/idea34/mod_show
Ok, I did it with Jumi plugin - http://2glux.com/projects/jumi/usage-for-j15
Thank you anyway.

I can't get proper Name&Domain properties using Win32_Process::GetOwner call under Perl

I want to enumerate all running processes' name&domain propeties using Win32_Process::GetOwner method under Perl, my code was listed below:
use strict;
use warnings;
use Win32::OLE('in');
use Win32::OLE::Variant;
my $retval;
my $machine = ".";
my $outParam;
my $CLASS = "Winmgmts:{impersonationlevel=impersonate}!\\\\$machine\\root\\cimv2";
my $WMI = Win32::OLE->GetObject($CLASS) or die("GetObject:" . Win32::OLE->LastError());
my $process = $WMI->InstancesOf("Win32_Process");
my $vtName = Win32::OLE::Variant->new(VT_CY, VT_EMPTY);
my $vtDomain = Win32::OLE::Variant->new(VT_CY, VT_EMPTY);
foreach my $obj(in $process)
{
$retval = $obj->GetOwner($vtName, $vtDomain);
if($retval == 0){
print $vtName->Value() . "\t" . $vtDomain->Value() . "\n";
}
}
The script can run properly, but I got the "zero" echo string everytime:
Who can tell me what caused this problem and how to fix it?
Thank you!
Seems Karthik already has the code you're looking for:
my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\localhost\\root\\CIMV2");
my $sqry = "SELECT * FROM Win32_Process where Name = \"$processName\" ";`
Also seems someone else has the same issue where Perl issues a status code of 0 instead of the actual data:
http://code.activestate.com/lists/perl-win32-users/16230/