drupal add node_access hook to existing module (OG) - drupal

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).

Related

Smart IP module - how to check what every country sees

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.

Drupal user permissions & odd content types

I have a permissions problem in Drupal. I want users to be able to create a certain node type, but there are two different paths I need to give them permissions for to let them do this. The type is content created by a module called isbn2node, and there are two ways to make content through it, each with different paths:
?=node/add/isbn2node-book
?=node/add/isbn2node_book/isbn2node
One has an underscore and the other one has a hyphen. The first path leads to a form that lets users enter information on a book manually; the second path lets them enter an ISBN, searches for it, and populates the form for them based on the results.
I've changed permissions in the People menu so they can add isbn2node-book content manually using the first path, but there isn't an option to let them use the second method. Aliasing the url so it didn't have node/add in the path didn't work either.
Creating a duplicate content type seems like an ugly solution to this; is there a more elegant way to let users access that second path?
A little code in a custom module using hook_node_access should do it.
$node is either a node object or the machine name of the content type on which to perform the access check (if the node is being created then the $node object is not available so it will be a string instead).
So this should do it:
function MY_MODULE_node_access($node, $op, $account) {
if ($op == 'create') {
$type = $node;
if($type == 'book' && $account->uid) return NODE_ACCESS_ALLOW;
}
}
I figured this out, and the issues I was having were specific to this content type. The ISBN2Node module requires users to have the Administer Nodes permission to use its lookup and bulk import features.
There is some extra code for the module's hook_permission and hook_menu sections submitted as a fix in the module's issues thread.

How do I CC someone when an order is placed?

I am using Ubercart with Drupal.
How do I CC someone when an order is placed? I will probably have to modify the code somewhere because it should only happen under a certain theme, but I'm not sure where to even edit this.
I went to admin/store/ca and created an action. I used the products as a condition and it works.
An easy solution is to use the hook_mail_alter() in a small stub module.
This hook will let you add add to the email generated by another module.
You will need to dig into the ubercart code to find the specific $mailkey for the email you want to change.
http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_mail_alter/6
function myhack_mail_alter(&$message)
{
if ($message['id'] == 'the ubercart mail key')
{
//$message['headers']['Bcc'] = 'myemail#example.com';
$message['headers']['cc'] = 'myemail#example.com';
}
}
One way to find the message key is to add the following to your function, then have the site send the email. This function will dump the keys to the dblog.
watchdog('MailKey', $message['id'], {}, WATCHDOG_INFO);

Drupal Panel Pages Pathauto

I have a Panel Page set up with the path node/%node/foo and all works fine when I visit a link such as node/6/foo. However, when I visit nodealias/foo it doesn't work at all. Is it possible to get panels to work with pathauto in this way?
I am thinking I may have to implement the hook hook_url_inbound_alter and change the url myself.
I also posted a support request in the panels module here: http://drupal.org/node/1219796
As Alexey answers panels doesn't care about aliases, it only sees node/%nid
Here's a good explanation that is valid still for D7:
http://drupal.org/node/211338
To summarize and bring it up to date for D7:
Export your variant for the panel you've created and import it into the panel that overrides the default node display in Drupal.
Add Criterias to the variant so the Panel/variant is only used for the type(s) of content you want to display with this variant.
Voila :) (read the discussion at the link, else the summary will be difficult to understand)
Hope this helps - I myself have spend some time googling and trying to understand this, and I was also confused by the fact that Views DOES care about aliases...
I fixed this using the following code, you would need to alter the pattern to match the pattern of your url aliases and alter the function name to match your module's name.
function brooklands_url_inbound_alter(&$path, $original_path, $path_language) {
$pattern = '#^works\/[A-Za-z0-9]+(-[A-Za-z0-9]+)*\/images(\/\d+)?$#';
if(preg_match($pattern, $original_path)) {
$snip = substr($original_path, 0, strrpos($original_path, '/images'));
$system_path = drupal_lookup_path('source', $snip);
if($system_path) {
$tail = substr($original_path, strrpos($original_path, '/images'));
$path = $system_path . $tail;
}
}
}
You can use this module Subpathauto
it automatically makes the alias to work with subpaths, such as: nodealias/foo
The nodealias is the full alias of your node with nid=6. The third argument (foo) is added through hook_menu() by panels module to the exact alias (node/%nid/%anythingelse) and it is NOT applied to your aliased URL, so you can not use nodealias/foo url to access your panel just because it is not 'hooked' by panels module.
Changing url manually is a good idea, I think.

How to work with hook_nodeapi after image thumbnail creation with ImageCache

A bit of a followup from a previous question.
As I mentioned in that question, my overall goal is to call a Ruby script after ImageCache does its magic with generating thumbnails and whatnot.
Sebi's suggestion from this question involved using hook_nodeapi.
Sadly, my Drupal knowledge of creating modules and/or hacking into existing modules is pretty limited.
So, for this question:
Should I create my own module or attempt to modify the ImageCache module?
How do I go about getting the generated thumbnail path (from ImageCache) to pass into my Ruby script?
edit
I found this question searching through SO...
Is it possible to do something similar in the _imagecache_cache function that would do what I want?
ie
function _imagecache_cache($presetname, $path) {
...
...
// check if deriv exists... (file was created between apaches request handler and reaching this code)
// otherwise try to create the derivative.
if (file_exists($dst) || imagecache_build_derivative($preset['actions'], $src, $dst)) {
imagecache_transfer($dst);
// call ruby script here
call('MY RUBY SCRIPT');
}
Don't hack into imagecache, remember every time you hack core/contrib modules god kills a kitten ;)
You should create a module that invokes hook_nodeapi, look at the api documentation to find the correct entry point for your script, nodeapi works on various different levels of the node process so you have to pick the correct one for you (it should become clear when you check the link out) http://api.drupal.org/api/function/hook_nodeapi
You won't be able to call the function you've shown because it is private so you'll have to find another route.
You could try and build the path up manually, you should be able to pull out the filename of the uploaded file and then append it to the directory structure, ugly but it should work. e.g.
If the uploaded file is called test123.jpg then it should be in /files/imagecache/thumbnails/test123/jpg (or something similar).
Hope it helps.

Resources