Smart IP module - how to check what every country sees - drupal

Unfortunately i don't have too much experience with drupal so please feel free to ask for more information if needed and i will provide.
I am using Drupal 7.34 and i have a module installed called Smart IP. I have different blocks which are shown depending on the users IP/Location/Language.
For example, when editing a block, going to the Show block on specific pages -> Pages on which this PHP Code returns TRUE (experts only) with the below code :
<?php
$smart_ip_session = smart_ip_session_get('smart_ip');
if (isset($smart_ip_session['location']['country_code'])){
if ($smart_ip_session['location']['country_code'] =='GR' && drupal_is_front_page()){
return TRUE;
}
}
?>
The above block will be shown if it's a drupal_is_front_page()) and if country_code is GR.
Since i am from Greece, the specific block is going to be loaded. How can i check how the block of another country looks like?

A couple of options:
If you know already how you want this function to behave then use dependence injection to return a mocked version of this object.
This will allow you test the rest of the application using whatever country's settings you like.
Or, if it is this function itself you need to test then use a VPN to request the page from another country.
e.g. https://www.operavpn.com/ or https://chrome.google.com/webstore/detail/unlimited-free-vpn-hola/gkojfkhlekighikafcpjkiklfbnlmeio
Both free to use.

Related

Open direct links to AX-objects or datasets from external application

Is there a way to open a specified document, eg "production order 123" or form, eg "purchase orders" in Ax2012 from an external application directly?
In detail, I'm looking for something similiar like AXPath, but this doesn't work with versions greater then 2009.
Is there any ( maybe included ) way to achieve this?
There is! It's using AX's drilldown functionality which uses AxHLink.exe to handle dynamics:// URLs, which are passed to the Classes\SysStartupCmd function. You could also create some custom code there if you wanted to launch the AX client executable directly.
My question I asked some while back should have a great deal of useful information in it here:
What handles dynamics:// URLs?
Some more can be found: http://technet.microsoft.com/en-us/library/aa834337.aspx
EDIT:
It sounds like you are confused or the posts weren't clear enough. I think you have 3 basic options.
Dynamics:// URLs are handled by AxHLink.exe and they only seem to handle drilldown, viewalert, and viewalertrule. So if you want to use Dynamics:// URLs, you will need to hi-jack those somehow. There is a pastbin from Jan in that other stack post.
Create a custom URI handler and event poller (lot of work) see http://axcoder.blogspot.dk/2010/10/how-to-open-form-in-running-ax-from.html
Extend SysStartupCmd and then instead of using Dynamics:// URLs, just call Ax32.exe -startupCmd directly and a parameter can be passed to your custom class.

drupal add node_access hook to existing module (OG)

Please don't ask why do i need to or why am I such a pervert.
I have an Organic Groups module on drupal 6.
I need to add node_access hook to this module for some reason.
There is no preset node_access hook in "og.module" file or any file, connected to this module (i've checked this).
I've tried adding "og_node_access" function with following body: "echo '1111111';return true;" and it doesn't trigger anywhere (no echoes at all). I've tried to add it to og.module file.
P.S.:
Please do not reccomend any access expansions for OG - I have tried plenty of them. All I need is:(pseudocode)
if ($op=='view'){
if ($node->type == 'xxxx' || $node->type =='yyyyyyyy') {
SHOW THIS TYPE OF NODES ONLY TO ADMIN(S) OF THE GROUP (OR SITE) AND THE AUTHOR OF THE NODE, NOBODY ELSE (EVEN IN THE SAME GROUP) IS ALLOWED TO SEE IT OR TOUCH IT.
} else {
USE DEFAULT RULES (return IGNORE);
}
}
And I need it to be hardcoded, because Taxonomy access, Content Access and other "Acess" modules don't work properly (actually they don't work at all) with OG module.
P.P.S.:
I know, that OG is kind of sht and there are a couple of alternatives, but i just need this to be done in a described way.
So... node_grants hook (I've mistyped in my comment it's "node_grants" not "access_grants") solved my problem.
Unfortunately I've spent too much time (the whole day) googling and trying to understand a bit complicated grants system of drupal.
Anyway thank you (all) for your answer(s).

Wordpress variable

I just think about that, easy to do in non cms site, but in wordpress site... i like to know YOUR approach to that problem
I have a BIG site (200 pages)... and at a lot of place, the info#something.com, the 000-000-0000 telephone and send your check to 123 easy street, Canada...
all that email, telephone, and address... should reside in one place (a post or a var) and when you need to insert it you should used the short code [tel] or [email].... but how...
is there a plusgin that can define var, or a tutorial to do that... do you only have to change it ONE for the whole site..
Any idea is welcome.... now, find and remplace is my friend !...
thanks in advance
You could try the Custom Config plugin:
http://wordpress.org/extend/plugins/custom-configs/
It will allow you to create custom global variables that are contained within the CMS (otherwise you'd be declaring these variables within the template config).
Usage to output a variable onto the page would be something like:
<?=get_config('myVariable','default')?>

Drupal - Getting node id from view to customise link in block

How can I build a block in Drupal which is able to show the node ID of the view page the block is currently sitting on?
I'm using views to build a large chunk of my site, but I need to be able to make "intelligent" blocks in PHP mode which will have dynamic content depending on what the view is displaying.
How can I find the $nid which a view is currently displaying?
Here is a more-robust way of getting the node ID:
<?php
// Check that the current URL is for a specific node:
if(arg(0) == 'node' && is_numeric(arg(1))) {
return arg(1); // Return the NID
}
else { // Whatever it is we're looking at, it's not a node
return NULL; // Return an invalid NID
}
?>
This method works even if you have a custom path for your node with the path and/or pathauto modules.
Just for reference, if you don't turn on the path module, the default URLs that Drupal generates are called "system paths" in the documentation. If you do turn on the path module, you are able to set custom paths which are called "aliases" in the documentation.
Since I always have the path module turned on, one thing that confused me at first was whether it was ever possible for the arg function to return part of an alias rather than part of system path.
As it turns out, the arg function will always return a system path because the arg function is based on $_GET['q']... After a bit of research it seems that $_GET['q'] will always return a system path.
If you want to get the path from the actual page request, you need to use $_REQUEST['q']. If the path module is enabled, $_REQUEST['q'] may return either an alias or a system path.
For a solution, especially one that involves a view argument in the midst of a path like department/%/list, see the blog post Node ID as View Argument from SEO-friendly URL Path.
In the end this snippet did the job - it just stripped the clean URL and reported back the very last argument.
<?php
$refer= $_SERVER ['REQUEST_URI'];
$nid = explode("/", $refer);
$nid = $nid[3];
?>
Given the comment reply, the above was probably reduced to this, using the Drupal arg() function to get a part of the request path:
<?php
$nid = arg(3);
?>
You should considder the panels module. It is a very big module and requires some work before you really can tap into it's potential. So take that into considderation.
You can use it to setup a page containing several views/blocks that can be placed in different regions. It uses a concept called context which can be anything related to what you are viewing. You can use that context to determine which node is being viewed and not only change blocks but also layout. It is also a bit more clean since you can move the PHP code away from admin interface.
On a side note, it's also written by the views author.
There are a couple of ways to go about this:
You can make your blocks with Views and pass the nid in through an argument.
You can manually pass in the nid by accessing the $view object using the code below. It's an array at $view->result. Each row in the view is an object in that array, and the nid is in that object for each one. So you could run a foreach on that and get all of the nid of all rows in the view pretty easily.
The first option is a lot easier, so if that suits your needs I would go with that.
New about Drupal 7: The correct way to get the node id is using the function menu_get_object();
Example:
$node = menu_get_object();
$contentType = node_type_get_name($node);
Drupal 8 has another method. Check this out:
arg() is deprecated

Drupal: retrieve data from multiple node types in views 2?

...or, in other words, how to create a simple join as I would do in SQL?
Suppose I want the following information:
Just as an example:
a person's full name
a person's hobbies.
His full name is in a (content profile) node type 'name_and_address' and his hobbies are in 'hobbies'.
In SQL, I would link them together by node.uid.
I've seen a bit about using relationships, but that goes with user-node-refs.
I just want the same user from one content-type and the other.
Now how could I get his name and his hobbies in 1 view?
There is a how to here does this do the job?
If not...
Views can be extended with custom joins, filters etc. If you are lucky there will be a module for this already. Some modules even provide their own views plugins.
You can write your own views plugins, although the documentation is a little fragmented.
The other thing that should be noted is that views isn't always the answer. Sometimes writing a custom query and display handler will do what you want with much less hassle.
Look at the relationships section of the view. This allows you to relate (ie join) different types of content (ie tables). It's not especially intuitive to someone used to SQL, but this video explains much of it. http://www.drupalove.com/drupal-video/demonstration-how-use-views-2s-relationships
You could use views_embed_view() in your template files to manually specify where they appear (and by extension render one view right below another).
You could override this function in a custom module (modulename_embed_view($name, $display_id)) in order to selectively edit what data is allowed out to the page.
Ex):
function modulename_embed_view($name, $display_id) {
if (strcmp($_GET['q'], 'node/123') === 0) {
$view = views_get_view($name);
$view2 = views_get_view('second view');
$output = $view['some element'] . $view2['element'];
}
return $output;
}
I know that this is very much a hack - I just wanted to show how one might use php to manually render and modify views in your template files.

Resources