This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in ...
This is the error that I'm getting
<?php
function my_custom_js() {
echo " <script>" ;
echo " jQuery(document).ready(function(){
jQuery('#secondary-front .first h3').addClass('
<?php $options = get_option('mytheme_theme_options');
if(!empty($options['first_widget_icon'])) echo $options['first_widget_icon']?> ');
jQuery('#secondary-front .second h3').addClass('<?php $options = get_option('mytheme_theme_options');
if (!empty($options['second_widget_icon'])) echo $options['second_widget_icon'];?>');
jQuery('#secondary-front .third h3').addClass('<?php $options = get_option('mytheme_theme_options');
if (!empty($options['third_widget_icon'])) echo $options['third_widget_icon'];?>');
});
";
echo "</script> ";
}
add_action('wp_head', 'my_custom_js');
?>
I cannot get this code to escape correctly, i have php > jquery > php
The problem is your quotes (") don't weigh up on both sides. That said, when I've gone to investigate the problem, I've noticed worse things with your code, so I've rewritten it entirely for you:
<?php
function my_custom_js() {
$options = get_option('mytheme_theme_options');
echo "<script>
jQuery(document).ready(function(){
jQuery('#secondary-front .first h3').addClass('" . ($options['first_widget_icon'] ?: NULL) . "');
jQuery('#secondary-front .second h3').addClass('" . ($options['second_widget_icon'] ?: NULL) . "');
jQuery('#secondary-front .third h3').addClass('" . ($options['third_widget_icon'] ?: NULL) . "');
});
</script>";
}
add_action('wp_head', 'my_custom_js');
?>
One thing I've done is moved $options = get_option('mytheme_theme_options'); to the top. I've also removed the repeated calls to this. Also, that's had the knock-on effect that the echo can be made all in 1 statement, with clever use of the ternary operator.
echo ($something ?: NULL); means if $something exists, echo it, else echo nothing.
Using the ternary operator with the ?: shorthand requires PHP >= 5.3.0
For versions below this, simply fill in the middle part, i.e.:
// PHP >= 5.3.0
($options['first_widget_icon'] ?: NULL)
// PHP < 5.3.0
($options['first_widget_icon'] ? $options['first_widget_icon'] : NULL)
Of course, the code might need tweaking to your liking, but it should be a basis for improvement.
Related
This question is based on my previous one where my entire TYPO3 website didn't work.
Now, after adjusting the php-version (5.6.17) the website itself works, but one fe-plugin of my extbase extension doesn't work - even though it's identical to the one on a copy of the website where everything works. The other fe-plugin from the same extension directly worked out of the box.
I get the following error in the frontend whenever I call a page that contains this plugin and I don't know where to start searching for the cause.
(I changed my domain to <mydomain> and my plugin name to tx_myfeplugin_nameexte in the following error snippet):
#1: PHP Warning: rawurlencode() expects parameter 1 to be string, object given in /var/www/vhosts/<my-domain>/typo3/sysext/core/Classes/Utility/GeneralUtility.php line 1641 (More information)
TYPO3\CMS\Core\Error\Exception thrown in file
/var/www/vhosts/<my-domain>/typo3/sysext/core/Classes/Error/ErrorHandler.php in line 101.
49 TYPO3\CMS\Core\Error\ErrorHandler::handleError(2, "rawurlencode() expects parameter 1 to be string, object given", "/var/www/vhosts/<my-domain>…po3/sysext/core/Classes/Utility/GeneralUtility.php", 1641, array)
48 rawurlencode(TYPO3\CMS\Extbase\Persistence\Generic\QueryResult)
/var/www/vhosts/<my-domain>/typo3/sysext/core/Classes/Utility/GeneralUtility.php:
01639: } else {
01640: if (!$skipBlank || (string)$AVal !== '') {
01641: $str .= '&' . ($rawurlencodeParamName ? rawurlencode($thisKeyName) : $thisKeyName) . '=' . rawurlencode($AVal);
01642: }
01643: }
47 TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl("tx_myfeplugin_nameexte", array, "", boolean, boolean)
/var/www/vhosts/<my-domain>/typo3/sysext/core/Classes/Utility/GeneralUtility.php:
01636: $thisKeyName = $name ? $name . '[' . $Akey . ']' : $Akey;
01637: if (is_array($AVal)) {
01638: $str = self::implodeArrayForUrl($thisKeyName, $AVal, $str, $skipBlank, $rawurlencodeParamName);
01639: } else {
01640: if (!$skipBlank || (string)$AVal !== '') {
Did someone have the same error before or has an idea what I should try to do to fix this?
Thanks to the answer I guess I fixed it, because the error is not appearing any longer, by adding the following lines at line 1707 in file GeneralUtility.php:
if ($AVal instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult) {
$AVal = $AVal->toArray();
}
lets have a look to the source:
foreach ($theArray as $Akey => $AVal) {
$thisKeyName = $name ? $name . '[' . $Akey . ']' : $Akey;
if (is_array($AVal)) {
$str = self::implodeArrayForUrl($thisKeyName, $AVal, $str, $skipBlank, $rawurlencodeParamName);
} else {
if (!$skipBlank || (string)$AVal !== '') {
$str .= '&' . ($rawurlencodeParamName ? rawurlencode($thisKeyName) : $thisKeyName . '=' . rawurlencode($AVal);
}
}
}
The array you give has to be a multidimensional array as it represents the parts of the url. Every element is testet being an array, so you could debug $AVal being an object but an array.
I guess that there could be an stdObject from any conversion you made before. Debugging will help you.
Second, what is the reporting you set in the install tool. Set it to production, will ist work then?
I have a problem with Oracle DB.
<?php
require_once 'includes/conn.php';
function connect_db()
{
if ($c=oci_pconnect(uname,pwd, host,'AL32UTF8'))
return $c;
else
die( "ERROR");
}
$conn=connect_db();
$query = "BEGIN :ds_id :=DS.REG_DS1(:F_NAME);END;";
$stmt=oci_parse($conn,$query);
$f_name='John Doe';
$ds_id=-1;
oci_bind_by_name($stmt, ":ds_id", $ds_id);
oci_bind_by_name($stmt, ":F_NAME", $f_name);
if(oci_execute($stmt))
{
echo 'good';
}
else
print_r(oci_error($stmt));
?>
Here is function REG_DS1
FUNCTION REG_DS1(F_NAME IN VARCHAR) RETURN NUMBER AS
DS_ID NUMBER(8,0):=9988;
BEGIN
-- INSERT INTO TEST VALUES(F_NAME,SYSDATE);
RETURN DS_ID;
END REG_DS1;
When I try to execute this function from Sql Developer, it runs with no problem.
But if I execute from PHP script above, it gives me error:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 1 [offset] => 0 [sqltext] => BEGIN :ds_id :=DS.REG_DS1(:F_NAME);END; )
If i change DS_ID variable to another number less than 100, it works great from both. but if i set it to a number more than 99, it gets me error from php script.
What can be a problem?
--jst idea and this is not solutioN
variable decleration or some defination problem
oci_connect($ODBuser,$ODBpass,$ODBhost,$db_charset);
should try like this
not like
oci_pconnect(uname,pwd, host,'AL32UTF8')
sample code :
-- just idea
<?php
$file = "../script/param.CML";
$encryptObj = new cast128;
$encryptObj->setkey("SABBIllustrateKey");
$fp=fopen($file,'r');
$strContent = fread($fp, filesize($file));
fclose($fp);
$strContent=$encryptObj->decrypt($strContent);
$ArConnect=split(" ",$strContent);
$OraService=$ArConnect[8];
$OraUser=$ArConnect[9];
$OraDBpass=$ArConnect[10];
$db_charset = 'AL32UTF8';
$cursor=oci_connect($OraUser,$OraDBpass,$OraService,$db_charset);
if(!$cursor)
{
echo "<br>Error In connection:- reason<BR>";
$e = oci_error(); // For oci_connect errors pass no handle
}
?>
<?php
$file = "../script/param.CML";
$encryptObj = new cast128;
$encryptObj->setkey("SABBIllustrateKey");
$fp=fopen($file,'r');
$strContent = fread($fp, filesize($file));
fclose($fp);
$strContent=$encryptObj->decrypt($strContent);
$con=split(" ",$strContent);
$OraService=$con[8];
$OraUser=$con[9];
$OraDBpass=$con[10];
$db_charset = 'AL32UTF8';
$cursor=oci_connect($OraUser,$OraDBpass,$OraService,$db_charset);
if(!$cursor)
{
echo "<br>Error In connection:- reason<BR>";
$e = oci_error(); // For oci_connect errors pass no handle
}
?>
Thx guys, finally I solved problem myself.
The problem was in variable size of returning value
By changing
oci_bind_by_name($stmt, ":ds_id", $ds_id);
to
oci_bind_by_name($stmt, ":ds_id", $ds_id,10,SQLT_INT );
the problem was solved.
The framework offer LimitWordCount in StringField.php file. It's great but not totally perfect. Some tags et ponctuation needs the be corrected.
I would like :
Keep tags <sup><sub><em>
Correct ponctuation : «.» to «. », «,» to «, », «?» to «? » etc....
I have made my own LimitWordCount :
public function MyLimitWordCount($int) {
$text = strip_tags($this->owner->value, '<sup><sub><em>');
if (str_word_count($text, 0) > $int) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$int]) . '…';
}
$text = str_replace('.', '. ', $text );
$text = str_replace('!', '! ', $text );
$text = str_replace('…', '… ', $text );
$text = str_replace('?', '? ', $text );
return $text;
}
That not works totally. Some ponctuation are not corrected and video shortcodes [embed width="480...] made in an HTMLEditor fields are keep with my function. I dont' know what him doing wrong.
You'll continue to get the shortcodes in your text becuase you need to parse them first.
This is most easily resolved by using (string)$this->owner->dbObject('value') rather than $this->owner->value.
You can then manipulate the value where the shortcodes have been expanded.
I can't comment on why your punctuation is not being "corrected" in this instance as you haven't supplied much information on which punctuation and under what circumstances it isn't working.
I just want to ask a simple but really bugging problem, let's get tot the point
Why when I writing a require in an add_filter() it returning unwanted 1 integer in the end of the text? This is the code
function satufu_template( $satufu_content ){
if ( is_singular( 'satufu_projects' ) ){
$located = locate_template('satufu-template.php');
if ( !empty($located) ){
} else {
echo require plugin_dir_path(__FILE__) . 'template.php';
}
} else {
return $satufu_content;
}
}
add_filter('the_content','satufu_template');
This is the template file that I am requiring
typo<?php
echo $satufu_content;
this is the output
test
//SomeMyAwesomeContent
1
this is the output with var_dump() wrapper
test
//SomeMyAwesomeContent
int(1)
This is a simple 1 integer that ruin my life (well, I tried 2 days just for debugging this until I give up.
So thank you for the attention and really hope this awesome forum gonna kill this tiny bug :)
You don't have to use echo when you use require.
Simply change:
echo require plugin_dir_path(__FILE__) . 'template.php';
to:
require plugin_dir_path(__FILE__) . 'template.php';
Currently the "1" appears because you are echo-ing the result of the require, which is successful
(1 - true, 0 = false).
Refference: http://php.net/manual/en/function.require.php
I am tasked with i18n-ing our current CMS setup in Drupal.
The problem that I am facing is with use of module_invoke() to place blocks within nodes.
I have managed to string translate blocks, and that is working when a block is placed in a region (block content is successfully translated) using the UI.
However, when a block is injected into a node like such:
$block = module_invoke('block', 'block', 'view', 22); print $block['content'];
It is not getting translated, or even worse, not showing at all.
I have also tried this variation using t(). e.g.:
$block = module_invoke('block', 'block', 'view', 22); print t($block['content']);
to no avail.
Generally speaking I've having a bit of trouble with blocks for i18n. Does anyone have a recommended approach for dealing with blocks in drupal with regards to translating them? I would prefer not to create different blocks for each language.
So .. After digging around in the bowels of Drupal - and much hair pulling .. I've come up with an almost decent solution.
Basically, with this function, I can extract a translated version of a block:
function render_i18n_block($block_id, $region = "hidden"){
if ($list = block_list($region)) {
foreach ($list as $key => $block) {
// $key == <i>module</i>_<i>delta</i>
$key_str = "block_".$block_id;
if ($key_str == $key){
return theme('block', $block);
}
}
}
}
Then, in my node, I simple call:
<?php echo render_i18n_block(<block_id>,<region>); ?>
There can be some issues where your blocks might not be displaying in a region (and therefore you can't pass a region into block_list). For this case, I simply created a region called "hidden" which is not rendered anywhere in my template, but can be used to call block_list.
Finally (and this is the part that I still need to find a good solution for), I discovered that block_list() in: includes/blocks/block.inc has a bit of an issue.
It appears that $theme_key is not reliably set unless block_list() is being called from the theme() function (in includes/themes.inc) .. this causes the SQL to return an empty results set. The SQL looks like this:
$result = db_query(db_rewrite_sql("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.theme = '%s' AND b.status = 1 AND (r.rid IN (". db_placeholders($rids) .") OR r.rid IS NULL) ORDER BY b.region, b.weight, b.module", 'b', 'bid'), array_merge(array($theme_key), $rids));
As you can see, if theme_key is not set, then it will just return an empty result.
For now I am bypassing this by simply adding:
if (!isset($theme_key)){$theme_key="<my_theme_name>";}
in modules/blocks/block.inc::block_list() around line 429 .. I still need to work out a better way to do this.
10 for anyone with suggestions on how I could ensure that $theme_key is set before calling block_list :)
I had exactly the same problem as you, since I was using
$block = module_invoke('block', 'block_view', 'block_id');
print render($block['content']);
to inject the block into my nodes. However, looking up module_invoke in the Drupal reference, I found a comment titled "to render blocks in Drupal 7 better to use Block API", with this code:
function block_render($module, $block_id) {
$block = block_load($module, $block_id);
$block_content = _block_render_blocks(array($block));
$build = _block_get_renderable_array($block_content);
$block_rendered = drupal_render($build);
return $block_rendered;
}
I just un-functioned it to use directly, like so:
$block = block_load('block', 'block_id');
$block_content = _block_render_blocks(array($block));
$build = _block_get_renderable_array($block_content);
print render($build);
And for me it works like a charm. Be aware however that this method prints the block title as well, so maybe you'll want to set it to 'none' in the original language.
Create a function like this
<?php
function stg_allcontent2($allC, $level
= "1") {
global $language; $lang = $language->language;
foreach ($allC as $acKey => $ac) {
if($ac['link']['options']['langcode']
== $lang){ if ($level == "1")
$toR .= "";
if (is_array($ac['below']))
$class="expanded"; else
$class="leaf";
$toR .= "<li class=\"".$class."\">" . l($ac['link']['link_title'], $ac['link']['link_path']) . "</li>";
if ($level != "1") $toR .= ""; if (is_array($ac['below'])) $toR .= "<ul class=\"menu\">".stg_allcontent2($ac['below'], "2")."</ul>"; if ($level == "1") $toR .= ""; }
}
return $toR; } ?>
call like this
<?php echo '<ul class="menu">'; echo stg_allcontent2(menu_tree_all_data($menu_name
= 'menu-header', $item = NULL)); echo '</ul>'; ?>
This may help you: http://drupal-translation.com/content/translating-block-contents#
UPDATE: the t() function allows you to pass in the language code to use.