Drupal - Block visibility - drupal

I am using the below code in the block visibilty settings, to only show the block if the user is a member, and not the admin.
What can I add to further filter it down to type of Organic Group Node.
i.o.w Only display if the currnt group being viewed = Organic Group Node Type X
<?php
$in_og = FALSE;
if (module_exists('og')){
$in_og = FALSE;
$group_node = og_get_group_context();
$gid02 = $group_node->nid;
$gid = (int)$gid02;
if ($gid02 == null) $gid = 0;
if (og_is_group_member($group_node)) $in_og = TRUE;
if (og_is_group_admin($group_node)) $in_og = FALSE;
if ($gid == 0) $in_og = FALSE;
}
return $in_og;
thanks

Maybe something like"
<?php
$in_og = FALSE;
$right_group = FALSE;
if (module_exists('og')) {
// get OG $group_node
$group_node = og_get_group_context();
if ($group_node->type == 'type-x') {
// we have the correct group type
$right_group = TRUE;
}
$gid = $group_node->nid;
if (og_is_group_member($group_node)) {
// show to members
$in_og = TRUE;
}
if (og_is_group_admin($group_node)) {
// hide from admins
$in_og = FALSE;
}
}
return $in_og && $right_group;
?>

Related

javascript injected in tinymce editor by wordpress when gutenberg is desactivated

with a fresh install and up to date of wordpress (5.8.2), when I desactivate gutenberg editor, Wordpress add this javascript code in all TinyMCE editor (content, acf fields etc..)
I have no plugin and theme by default. I desactivate Gutenberg with code or with a plugin, no changes. Anyone have a tip ? thx
<script type="text/javascript">
var spector;
var captureOnLoad = false;
var captureOffScreen = false;
window.__SPECTOR_Canvases = [];
(function() {
var __SPECTOR_Origin_EXTENSION_GetContext = HTMLCanvasElement.prototype.getContext;
HTMLCanvasElement.prototype.__SPECTOR_Origin_EXTENSION_GetContext = __SPECTOR_Origin_EXTENSION_GetContext;
if (typeof OffscreenCanvas !== 'undefined') {
var __SPECTOR_Origin_EXTENSION_OffscreenGetContext = OffscreenCanvas.prototype.getContext;
OffscreenCanvas.prototype.__SPECTOR_Origin_EXTENSION_OffscreenGetContext = __SPECTOR_Origin_EXTENSION_OffscreenGetContext;
OffscreenCanvas.prototype.getContext = function () {
var context = null;
if (!arguments.length) {
return context;
}
if (arguments.length === 1) {
context = this.__SPECTOR_Origin_EXTENSION_OffscreenGetContext(arguments[0]);
if (context === null) {
return context;
}
}
else if (arguments.length === 2) {
context = this.__SPECTOR_Origin_EXTENSION_OffscreenGetContext(arguments[0], arguments[1]);
if (context === null) {
return context;
}
}
var contextNames = ["webgl", "experimental-webgl", "webgl2", "experimental-webgl2"];
if (contextNames.indexOf(arguments[0]) !== -1) {
// context.canvas.setAttribute("__spector_context_type", arguments[0]);
// Notify the page a canvas is available.
var myEvent = new CustomEvent("SpectorWebGLCanvasAvailableEvent");
document.dispatchEvent(myEvent);
this.id = "Offscreen";
window.__SPECTOR_Canvases.push(this);
if (captureOnLoad) {
// Ensures canvas is in the dom to capture the one we are currently tracking.
if (false) {
spector.captureContext(context, 500, false, false);
captureOnLoad = false;
}
}
}
return context;
}
}
HTMLCanvasElement.prototype.getContext = function () {
var context = null;
if (!arguments.length) {
return context;
}
if (arguments.length === 1) {
context = this.__SPECTOR_Origin_EXTENSION_GetContext(arguments[0]);
if (context === null) {
return context;
}
}
else if (arguments.length === 2) {
context = this.__SPECTOR_Origin_EXTENSION_GetContext(arguments[0], arguments[1]);
if (context === null) {
return context;
}
}
var contextNames = ["webgl", "experimental-webgl", "webgl2", "experimental-webgl2"];
if (contextNames.indexOf(arguments[0]) !== -1) {
context.canvas.setAttribute("__spector_context_type", arguments[0]);
// Notify the page a canvas is available.
var myEvent = new CustomEvent("SpectorWebGLCanvasAvailableEvent");
document.dispatchEvent(myEvent);
if (captureOffScreen) {
var found = false;
for (var i = 0; i < window.__SPECTOR_Canvases.length; i++) {
if (window.__SPECTOR_Canvases[i] === this) {
found = true;
break;
}
}
if (!found) {
window.__SPECTOR_Canvases.push(this);
}
}
if (captureOnLoad) {
// Ensures canvas is in the dom to capture the one we are currently tracking.
if (this.parentElement || false) {
spector.captureContext(context, 500, false, false);
captureOnLoad = false;
}
}
}
return context;
}
})()</script>
It is very likely added by the Spector.js extension : same behaviour with the Spector extension enabled on Firefox (when switching editor, or after save) => disabling the extension solved the issue.

Asp.net Telerik script issue

I have a line of code which comes inside a Telerik.Web.UI.Webresource.axd file which breaks something in my custom code.
dataBind:function(){if(this._virtualization&&!this._virtualization._isDataBinding&&((this.get_allowPaging()&&this._dataSource.length>this.get_pageSize())||(!this.get_allowPaging()&&this._dataSource.length>this._virtualization._itemsPerView))){this._virtualization._startIndex=null;
this._virtualization.set_bindingType("Client");
this._virtualization.set_cachedData(this._dataSource);
this._virtualization.set_virtualItemCount(this._dataSource.length);
this._virtualization.select();
return;
}
**Array.forEach($telerik.getElementsByClassName(this.get_element().tBodies[0],"rgGroupHeader"),function(i){i.parentNode.removeChild(i)**;
});
I would like to know if it is possible to prevent the below line of code to be executed
Array.forEach($telerik.getElementsByClassName(this.get_element().tBodies[0],"rgGroupHeader"),function(i){i.parentNode.removeChild(i)**;
You can override the dataBind method of RadGrid which will allow you to customize it:
<script>
Telerik.Web.UI.GridClientSideBinding.prototype.dataBind = function () {
// Virtualization
if (this._virtualization && !this._virtualization._isDataBinding &&
((this.get_allowPaging() && this._dataSource.length > this.get_pageSize()) ||
(!this.get_allowPaging() && this._dataSource.length > this._virtualization._itemsPerView))) {
this._virtualization._startIndex = null;
this._virtualization.set_bindingType("Client");
this._virtualization.set_cachedData(this._dataSource);
this._virtualization.set_virtualItemCount(this._dataSource.length);
this._virtualization.select();
return;
}
Array.forEach($telerik.getElementsByClassName(this.get_element().tBodies[0], "rgGroupHeader"), function (element) {
element.parentNode.removeChild(element);
});
Array.forEach($telerik.getElementsByClassName(this.get_element().tBodies[0], "rgFooter"), function (element) {
element.parentNode.removeChild(element);
});
var noRecordsItem = $telerik.getElementByClassName(this.get_element(), "rgNoRecords");
if (noRecordsItem) {
if (this._dataSource.length > 0) {
noRecordsItem.style.display = "none";
} else {
noRecordsItem.style.display = "";
this._setPagerVisibility(this._data.PagerAlwaysVisible);
}
}
var dataItems = this.get_dataItems();
var columns = this.get_columns();
var i, l1, l2;
var tableElement = ($telerik.isOpera) ? this.get_element() : this.get_element().tBodies[0];
if (this._dataSource.length < dataItems.length || tableElement.rows.length == 1) {
for (i = 0, l1 = dataItems.length; i < l1; i++) {
dataItems[i].set_visible(false);
dataItems[i].get_element().style.display = "none";
}
this._cacheDataItems();
}
this._dataBind(this._dataSource);
var firstSelection = true;
// When YahooStyleScrolling is used in RadGrid and user
//scrolls down, select multiple rows using shift + down arrow key,
//the selection is not persisted on next page load
if (this._owner._keyboardNavigationProperties) {
firstSelection = this._owner._keyboardNavigationProperties.firstSelection;
}
var owner = $find(this._owner.get_id());
if (owner._getPositionedDataItems) {
owner._getPositionedDataItems(true);
}
if (this._owner._keyboardNavigationProperties) {
this._owner._keyboardNavigationProperties.firstSelection = firstSelection;
}
this._fixRowsClassNames();
this._owner.raise_dataBound(Sys.EventArgs.Empty);
for (i = 0, l2 = columns.length; i < l2; i++) {
var isVisible = false;
if (columns[i].get_element().style.visibility != "hidden" && (columns[i].Display == null || columns[i].Display == true) &&
(columns[i]._data.Display == null || columns[i]._data.Display)) {
isVisible = true;
}
if (!isVisible) {
this.hideColumn(i);
}
}
if (this.get_id() == this._owner._masterClientID) {
var grid = $find(this._owner.get_id());
if (grid._scrolling) {
this._owner._scrolling.setHeaderAndFooterDivsWidth();
grid._scrolling._initializeVirtualScrollPaging(true);
}
}
}
</script>

Manual Layout of children of a Tabbed Panel in ScriptUI

I'm writing a script in ExtendScript and need to have tons of checkboxes on a panel inside a tab, I can't split the panel into groups because I need to get the length property of the group.
I was wondering if anyone had experienced an issue with trying to use manual layout with Tabbed panels in ScriptUI.
Is there a way to align children of a tab panel manually?
Here's an example without tabs:
function MakeaPanel(this_obj_) {
var pan = (this_obj_ instanceof Panel)
? this_obj_
: new Window('palette', 'MainWindow',[449,210,831,576]);
CheckBGroup = pan.add('panel', [33,46,350,145], 'CheckBoxGroup', {borderStyle: "etched"});
ChkBox_1 = CheckBGroup.add('checkbox', [18,21,162,41], 'CheckBox1');
ChkBox_1.value = false;
ChkBox_2 = CheckBGroup.add('checkbox', [18,43,162,63], 'CheckBox2');
ChkBox_2.value = false;
ChkBox_3 = CheckBGroup.add('checkbox', [142,21,286,41], 'CheckBox3');
ChkBox_3.value = false;
ChkBox_4 = CheckBGroup.add('checkbox', [142,43,286,63], 'CheckBox4');
ChkBox_4.value = false;
return pan
}
var w = MakeaPanel(this);
if (w.toString() == "[object Panel]") {
w;
} else {
w.show();
}
And Here's an example with Tabs:
function MakeaPanel(this_obj_) {
var pan = (this_obj_ instanceof Panel)
? this_obj_
: new Window('palette', 'MainWindow', undefined); // [449,210,831,576]
var tpanel = pan.add ("tabbedpanel");
var MainTab = tpanel.add ("tab", undefined, "Main");
var OptionsTab = tpanel.add ("tab", undefined, "Options");
var OT_Panel = OptionsTab.add ("panel", undefined, "");
CheckBGroup = MainTab.add('panel', [33,46,350,200], 'CheckBoxGroup', {borderStyle: "etched"});
ChkBox_1 = CheckBGroup.add('checkbox', [18,21,162,41], 'CheckBox1');
ChkBox_1.value = false;
ChkBox_2 = CheckBGroup.add('checkbox', [18,43,162,63], 'CheckBox2');
ChkBox_2.value = false;
ChkBox_3 = CheckBGroup.add('checkbox', [142,21,286,41], 'CheckBox3');
ChkBox_3.value = false;
ChkBox_4 = CheckBGroup.add('checkbox', [142,43,286,63], 'CheckBox4');
ChkBox_4.value = false;
return pan
}
var w = MakeaPanel(this);
if (w.toString() == "[object Panel]") {
w;
} else {
w.show();
}

Unrealscript: how to add a weapon to the inventory only if your weapon's group is unique

I have been trying to get a custom inventory script working in unrealscript. I need to check on weapon pickup if the weapon you are picking up has a weapon group that matches one you already have or not. If so it swaps the weapons of the given group. If not you gain the new weapon. Currently we have 4 weapon groups. What i have tried to no avail to find is how to find the weapon group of a weapon being picked up. and how to check that against the other weapons. I have been working with the add inventory function.
NewItem is the item you just interacted with. And i need to find the other weapons in your current inventory and their weapon groups.
simulated function bool AddInventory(Inventory NewItem, optional bool bDoNotActivate)
{
local Inventory Item, LastItem;
// The item should not have been destroyed if we get here.
if( (NewItem != None) && !NewItem.bDeleteMe )
{
// if we don't have an inventory list, start here
if( InventoryChain == None )
{
InventoryChain = newItem;
}
else
{
// Skip if already in the inventory.
for (Item = InventoryChain; Item != None; Item = Item.Inventory)
{
if( Item == NewItem )
{
return FALSE;
}
LastItem = Item;
}
LastItem.Inventory = NewItem;
}
//Edited by Matt Kerns
`LogInv("adding" # NewItem # "bDoNotActivate:" # bDoNotActivate);
`Log ("Added to inventory!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
NewItem.SetOwner( Instigator );
NewItem.Instigator = Instigator;
NewItem.InvManager = Self;
NewItem.GivenTo( Instigator, bDoNotActivate);
// Trigger inventory event
Instigator.TriggerEventClass(class'SeqEvent_GetInventory', NewItem);
return TRUE;
}
return FALSE;
}
If you want write all code in InventoryManager it will be look like
simulated function bool AddInventory(Inventory NewItem, optional bool bDoNotActivate){
local Inventory Item, LastItem;
// The item should not have been destroyed if we get here.
if( (NewItem != None) && !NewItem.bDeleteMe )
{
//if weapon - work in personal weapon function
if(Weapon(NewItem) != none)
return AddItemWeapon(NewItem, bDoNotActivate);
// if we don't have an inventory list, start here
if( InventoryChain == None )
{
InventoryChain = newItem;
}
else
{
// Skip if already in the inventory.
for (Item = InventoryChain; Item != None; Item = Item.Inventory)
{
if( Item == NewItem )
{
return FALSE;
}
LastItem = Item;
}
LastItem.Inventory = NewItem;
}
//Edited by Matt Kerns
`LogInv("adding" # NewItem # "bDoNotActivate:" # bDoNotActivate);
`Log ("Added to inventory!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
NewItem.SetOwner( Instigator );
NewItem.Instigator = Instigator;
NewItem.InvManager = Self;
NewItem.GivenTo( Instigator, bDoNotActivate);
// Trigger inventory event
Instigator.TriggerEventClass(class'SeqEvent_GetInventory', NewItem);
return TRUE;
}
return FALSE;
}
simulated function AddItemWeapon(Inventory NewItem, optional bool bDoNotActivate)
{
local Inventory Item, LastItem;
local Weapon WeaponNewItem;
WeaponNewItem= Weapon(NewItem);
// The item should not have been destroyed if we get here.
if( (NewItem != None) && !NewItem.bDeleteMe )
{
// if we don't have an inventory list, start here
if( InventoryChain == None )
{
InventoryChain = newItem;
}
else
{
//look for our group
for (Item = InventoryChain; Item != None; Item = Item.Inventory){
if(Weapon(Item) != none && Weapon(Item).Group == WeaponNewItem.Group){
RemoveFromInventory(Item);
break;
}
}
// Skip if already in the inventory.
for (Item = InventoryChain; Item != None; Item = Item.Inventory)
{
if( Item == NewItem )
{
return FALSE;
}
LastItem = Item;
}
LastItem.Inventory = NewItem;
}
//Edited by Matt Kerns
`LogInv("adding" # NewItem # "bDoNotActivate:" # bDoNotActivate);
`Log ("Added to inventory!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
NewItem.SetOwner( Instigator );
NewItem.Instigator = Instigator;
NewItem.InvManager = Self;
NewItem.GivenTo( Instigator, bDoNotActivate);
// Trigger inventory event
Instigator.TriggerEventClass(class'SeqEvent_GetInventory', NewItem);
return TRUE;
}
return FALSE;
}
This is best way if your game use network and replicate inventory. If not, you can simple write something like
simulated function AddItemWeapon(Inventory NewItem, optional bool bDoNotActivate){
local Inventory Item, LastItem;
local Weapon WeaponNewItem;
local bool bAddNewWeapon;
bAddNewWeapon = true;
WeaponNewItem = Weapon(NewItem);
// The item should not have been destroyed if we get here.
if( (NewItem != None) && !NewItem.bDeleteMe )
{
// if we don't have an inventory list, start here
if( InventoryChain == None )
{
InventoryChain = newItem;
}
else
{
//look for our group
for (Item = InventoryChain; Item != None; Item = Item.Inventory){
if(Weapon(Item) != none && Weapon(Item).Group == WeaponNewItem.Group){
NewItem.Inventory = Item.Inventory;
bAddNewWeapon = false;
RemoveFromInventory(Item);
break;
}
LastItem = Item;
}
if(bAddNewWeapon){
for (Item = InventoryChain; Item != None; Item = Item.Inventory){
LastItem = Item;
}
}
LastItem.Inventory = NewItem;
}
But im sure that this is bad way. You should write class which will save all used weapon groups and use InventoryManager only as storage

Filtering LINQ query

I have problem that is bothering me last couple of days.
I need to filter LINQ query using comboboxes and textboxes. The problem is I can't manage to get the result and I always get the empty gridview (used for showing filtered data).
Can anyone help me why am I getting no results at all? I've checked the debugger and the data sent to query is valid, although, I'm not sure about "string.Empty" value.
Here is the code:
string naziv, nazivEn, adresa, tel, fax, mob, email, web, oib, tip, mjesto;
if (chkMjesto.Checked == true)
{
mjesto = cbMjesto.SelectedItem.Text;
}
else
{
mjesto = string.Empty;
}
if (chkTip.Checked == true)
{
tip = cbTip.SelectedItem.Text;
}
else
{
tip = string.Empty;
}
string tema;
if (chkTema.Checked == true)
{
tema = cbTema.SelectedItem.Text;
}
else
{
tema = string.Empty;
}
if (chkAdresa.Checked == true)
{
adresa = txtAdresa.Text;
}
else
{
adresa = string.Empty;
}
if (chkTelefon.Checked == true)
{
tel = txtTelefon.Text;
}
else
{
tel = string.Empty;
}
if (chkMobitel.Checked == true)
{
mob = txtMobitel.Text;
}
else
{
mob = string.Empty;
}
if (chkEmail.Checked == true)
{
email = txtEmail.Text;
}
else
{
email = string.Empty;
}
if (chkWeb.Checked == true)
{
web = txtWeb.Text;
}
else
{
web = string.Empty;
}
if (chkOIB.Checked == true)
{
oib = txtOIB.Text;
}
else
{
oib = string.Empty;
}
if (chkNaziv.Checked == true)
{
naziv = txtNaziv.Text;
}
else
{
naziv = string.Empty;
}
if (chkNazivEn.Checked == true)
{
nazivEn = txtNazivEn.Text;
}
else
{
nazivEn = string.Empty;
}
if (chkFax.Checked == true)
{
fax = txtFax.Text;
}
else
{
fax = string.Empty;
}
if (rblOrganizator.SelectedItem.Value == "Nije")
{
var pretraga = from t in db.tijeloes
where t.tijelo_naziv.Contains(naziv) && t.tijelo_adresa.Contains(adresa) && t.tip_tijela.tip_tijela_naziv.Contains(tip) && t.mjesto.mjesto_naziv.Contains(mjesto)
where t.tijelo_telefon.Contains(tel) && t.tijelo_fax.Contains(fax) && t.tijelo_email.Contains(email) && t.tijelo_mob.Contains(mob) && t.tijelo_web.Contains(web) && t.tijelo_oib.Contains(oib) && t.tijelo_naziv_en.Contains(nazivEn)
select new { t.tijelo_naziv, t.tijelo_oib,t.tip_tijela.tip_tijela_naziv,t.tijelo_adresa,t.mjesto.mjesto_naziv, t.mjesto.zupanija_drzava.zupanija_naziv};
gvTijelo.DataSource = pretraga;
gvTijelo.DataBind();
if (pretraga.Count() != 0)
{
gvTijelo.HeaderRow.Cells[0].Text = "Naziv";
gvTijelo.HeaderRow.Cells[1].Text = "OIB";
gvTijelo.HeaderRow.Cells[2].Text = "Tip tijela";
gvTijelo.HeaderRow.Cells[3].Text = "Adresa";
gvTijelo.HeaderRow.Cells[4].Text = "Mjesto";
gvTijelo.HeaderRow.Cells[5].Text = "Regionalni centar";
}
}
The string.Empty seems to the culprit. I would bet the SQL being generated is checking if a field contains '', which just won't likely work with data in that field.
Your best bet is to start the query before your conditionals, then append a where to it if the corresponding check box is checked.
var pretraga = db.tijeloes;
if (chkMjesto.Checked == true)
{
pretraga = pretraga.Where(t => t.tijelo_naziv.Contains(cbMjesto.SelectedItem.Text));
}
if (chkTip.Checked == true)
{
pretraga = pretraga.Where(t => t.tip_tijela.tip_tijela_naziv.Contains(cbTip.SelectedItem.Text));
}
...
pretraga = pretraga.Select(t => new { t.tijelo_naziv, t.tijelo_oib,t.tip_tijela.tip_tijela_naziv,t.tijelo_adresa,t.mjesto.mjesto_naziv, t.mjesto.zupanija_drzava.zupanija_naziv });
// Bind to pretraga.
...
If I were you I would declare all the variables at the top seperately like
string naziv = string.empty;
string whatever = string.empty; etc
Doing this will make your code smaller because you can get rid of the else statements as the variables are already set.
Sorry not a solution but might thin down the code for you a little :)

Resources