Remove .js file works but a warning persist - drupal

i would like to remove a .js file from a drupal module to override this .js one in my theme.
So, in my MYTHEME_preprocess_page() function I added the following code:
//Delete logintoboggan.js and replace by our own in .info file
$tmpJs = drupal_add_js();
if (isset($tmpJs['module']['sites/all/modules/logintoboggan/logintoboggan.js'])) unset($tmpJs['module']['sites/all/modules/logintoboggan/logintoboggan.js']);
$vars['scripts'] = drupal_get_js($tmpJs);
This for, but a warning message appear on the website:
warning: Illegal offset type in isset or empty in /home/mykitxen/public_html/example.com/includes/common.inc on line 2210.
What is wrong?

You're missing the first parameter of drupal_get_js() ($scope), which should be 'header' or NULL in your case (with NULL just triggering the default 'header'). So the last line of your code should be:
$vars['scripts'] = drupal_get_js('header', $tmpJs);
or
$vars['scripts'] = drupal_get_js(NULL, $tmpJs);
NOTE: This assumes Drupal 6. If you are using Drupal 7, you might want to take a look at hook_js_alter().

Related

Key binding by file type

Description
I'm trying to create a key binding that behaves differently based on the file type.
Ideally what id like to do is the following:
If the file type is .md then run the command markdown-preview-plus:toggle
else run the command script:run
I know it's something along the lines of:
file init.coffee :
editor.command('custom:command', e => {
if ( of file type .md) {
markdown-preview-plus:toggle
} else {
script:run
}
})
Then in the keymap.cson i have to add something like:
'atom-text-editor':
'cmd-i': 'custom:command'
But obviously this is pseudocode. I've tried reading the documentation specifically this
but there isn't enough information.
I was able to do this by adding the following to the keymap.cson file:
"atom-text-editor[data-grammar='source gfm']":
'cmd-i': 'markdown-preview-plus:toggle'
"atom-text-editor:not([data-grammar='source gfm'])":
'cmd-i': 'script:run'
For anyone trying to do something similar to this, I used this as reference:
Atom grammer syntax

SQLite: isolating the file extension from a path

I need to isolate the file extension from a path in SQLite. I've read the post here (SQLite: How to select part of string?), which gets 99% there.
However, the solution:
select distinct replace(column_name, rtrim(column_name, replace(column_name, '.', '' ) ), '') from table_name;
fails if a file has no extension (i.e. no '.' in the filename), for which it should return an empty string. Is there any way to trap this please?
Note the filename in this context is the bit after the final '\'- it shouldn't be searching for'.'s in the full path, as it does at moment too.
I think it should be possible to do it using further nested rtrims and replaces.
Thanks. Yes, you can do it like this:
1) create a scalar function called "extension" in QtScript in SQLiteStudio
2) The code is as follows:
if ( arguments[0].substring(arguments[0].lastIndexOf('\u005C')).lastIndexOf('.') == -1 )
{
return ("");
}
else
{
return arguments[0].substring(arguments[0].lastIndexOf('.'));
}
3) Then, in the SQL query editor you can use
select distinct extension(PATH) from DATA
... to itemise the distinct file extensions from the column called PATH in the table called DATA.
Note that the PATH field must contain a backslash ('\') in this implementation - i.e. it must be a full path.

How can i replace url from css

I'm trying to combine multiple css files into a single file (from many different folder in my host, and including external css files). I use the following short code:
Declare array:
$styles=array(
array(
'name'=>'style1.css',
'path'=>'http://mydomain.com/css/'
),
array(
'name'=>'camera.css',
'path'=>'http://mydomain.com/js/camera/'
),
array(
'name'=>'style3.css',
'path'=>'http://external.com/assets/css/'
));
Get content and replace url:
foreach ($styles as $style) {
echo preg_replace('/url\(\s*[\'"]?\/?(.+?)[\'"]?\s*\)/i', 'url('.$style['path'].'$1)', file_get_contents($style['path'].$style['name']));
}
After combined into one css file, i have some css background image url as follows:
url(ttp://mydomain.com/css/../image/background.png) //Internal path - Case 1A
url(http://mydomain.com/js/camera/../../image/background.png) //Internal path - Case 1B
url(http://external.com/assets/css/../../image/background.png) //External path - Case 2
Actual, the internal path (Case 1A, 1B) can display the background image (despite the lack of professionalism), but in the external path (Case 2) cannot display the background image, my question is:
How can i replace wrong path with correct path (REPAIR BASE ON CURRENT RESULTS) as:
url(http://mydomain.com/image/background.png) //Correct internal path
url(http://external.com/image/background.png) //Correct external path
(I understand the problem is if find a keyword containing '../' will remove keyword and remove 1 string before the keyword contain '*/', , but I can't figure out how to do this).
Thanks in advance.
(I have tried find out and tried searching for 1 week before ask new question).
additionally replace /up-level-directory/../ with /
that is '/([^\/]+)/../' with / globally
$correct_url = preg_replace('|/\w+/\.\./|', '/', $url);

UDK "Error, Unrecognized member 'OpenMenu' in class 'GameUISceneClient'"

Upon compiling, I am getting the following error:
C:\UDK\UDK-2010-03\Development\Src\FixIt\Classes\ZInteraction.uc(41) : Error, Unrecognized member 'OpenMenu' in class 'GameUISceneClient'
Line 41 is the following:
GetSceneClient().OpenMenu("ZInterface.ZNLGWindow");
But when I search for OpenMenu, I find that it is indeed defined in GameUISceneClient.uc of the UDK:
Line 1507: exec function OpenMenu( string MenuPath, optional int PlayerIndex=INDEX_NONE )
It looks like I have everything correct. So what's wrong? Why can't it find the OpenMenu function?
From the wiki page on Legacy:Exec Function:
Exec Functions are functions that a player or user can execute by typing its name in the console. Basically, they provide a way to define new console commands in UnrealScript code.
Okay, so OpenMenu has been converted to a console command. Great. But still, how do I execute it in code? The page doesn't say!
More searching revealed this odd documentation page, which contains the answer:
Now then, there is also a function
within class Console called 'bool
ConsoleCommand(coerce string s)'. to
call your exec'd function,
'myFunction' from code, you type:
* bool isFunctionThere; //optional
isFunctionThere = ConsoleCommand("myFunction myArgument");
So, I replaced my line with the following:
GetSceneClient().ConsoleCommand("OpenMenu ZInterface.ZNLGWindow");
Now this causes another error which I covered in my other question+answer a few minutes ago. But that's it!
Not sure if this is your intent, but if you are trying to create a UIScene based on an Archetype that has been created in the UI Editor, you want to do something like this:
UIScene openedScene;
UIScene mySceneArchetype;
mySceneArchetype = UIScene'Package.Scene';
GameSceneClient = class'UIRoot'.static.GetSceneClient();
//Open the Scene
if( GameSceneClient != none && MySceneArchetype != none )
{
GameSceneClient.OpenScene(mySceneArchetype,LocalPlayer(PlayerOwner.Player), openedScene);
}

Update configSource of XML element in web.config using Powershell by passing in Parameters

I am trying to figure out a way to update my web.config for different environments by updating the configSource for the appSettings element in the web.config.
Here are the way I know how to do it.
$xml.get_DocumentElement().appSettings.configSource = $replaced_test
The problem is that I want one base script where I can pass in different nodes to the script that I want to change and update but I am not sure how to do it.
For example, I want to be able to call a powershell script like this
changeWebConfig.ps1 nodeToChange newValueofNode
I hope this was clear enough.
This is the code I have now.
$webConfigPath = "C:\web.config"
# Get the content of the config file and cast it to XML
$xml = [xml](get-content $webConfigPath)
#this was the trick I had been looking for
$root = $xml.get_DocumentElement()."system.serviceModel".client.configSource = $replace
# Save it
$xml.Save($webConfigPath)
The problem I was having was the configuration node
I had to change it from
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
this to
<configuration>
I am not sure how to find the node with the configuration node in it's orginal state yet, but I'm getting closer.
function Set-ConfigAppSetting
([string]$PathToConfig=$(throw 'Configuration file is required'),
[string]$Key = $(throw 'No Key Specified'),
[string]$Value = $(throw 'No Value Specified'))
{
if (Test-Path $PathToConfig)
{
$x = [xml] (type $PathToConfig)
$node = $x.SelectSingleNode("//client[#configSource]")
$node.configSource = $Value
$x.Save($PathToConfig)
}
}
set-configappsetting "c:\web.config" CurrentTaxYear ".\private$\dinnernoworders" -confirm
Finally figured it out.
$root = $xml.get_DocumentElement().SelectSingleNode("//client[#configSource]").configSource = "test"
of course, I will replace "//client[#configSource]" with a variable so I can pass in different nodes as parameters to create my base script.
Im looking for a way to modify the code as well.
Here is a way you can view whats the node:
$path = 'c:\site\web.config'
$PublishState = (Select-Xml -Path $path -XPath "configuration/appSettings/add[#key='PublishState']/#value").Node.'#text'
$PublishState

Resources