Quick theming a View with node types-tricks

Leave a comment

if your theme folder contains node.tpl.php you don’t care the rest of the article else

if you have problems to find the template page with name node-view-viewname.tpl.php,because  the theme system need base node.tpl.php  template for overriding.
heck this link for theming a view with node type:-http://kfalck.net/2008/11/28/drupal-node-view-xtplphp-requires-nodetplphp

Strange behaviour of drupal 6 triggers and CCK default values

Leave a comment

One of my drupal experience is to developing an application for a client.So i want to change the default behaviour of drupal after saving the post.I created a trigger which triggers after saving the post to Redirect the admin/content/node Url.But the bad behaviour is starts there.The application dont save default values,but after editing and save it saves the values.So i used a hook_nodeapi to get the values from submitted form and try to save it.But ‘mymodule_nodeapi’ not fires at all.Before that it redirect to the ‘triggered Url’.After many hours of  research, trial,  i found the redirect nature and Un assign the Trigger .Now it works perfectly.

Buti am not 100% sure if it only related to that trigger or some thing related to configuration of trigger.

i will update my further finding and experience of drupal as application frame work in future

How to call imagecache images using theme functions

Leave a comment

You can call your imagecache images like the code below

theme(‘imagecache’, ‘blog_Thumb’, drupal_get_path_alias($node->field_1_immagini[0][‘filepath’]), $alt = $altimg, $title = $titleimg, $attributes=null)

‘blog_Thumb’ is the preset name
drupal_get_path_alias($node->field_1_immagini[0][‘filepath’]) is the path of image

Template suggestions drupal

Leave a comment

How to change the template when we show a node using view

we have placed a view for show details of each node in drupal 6 with a path of the view as ‘node/%’.But web site contains a system of multiple blogs using advanced_blog and custom module for manage some extra functionality for blog pages according to the blog html template.i prefer to add a template for blog and named it as page-blog.tpl.php.and all path of the blog is aliased with ‘blog/’.Every thing is working fine until when i click link to view the detials of a blog entry.It fallbacks to default page.tpl.php for showing the details.But i want to remain on the page-blog page.So i used the follwing script with ‘path’ module
//put this script in template.php if exist preprocess_page then only //insert contents of function:
function phptemplate_preprocess_page(&$vars) {
if ($vars[‘is_front’] != 1) {
$vars[‘template_files’][] = ‘page-‘ . $vars[‘node’]->type;
if (module_exists(‘path’)) {
$alias = drupal_get_path_alias(str_replace(‘/edit’,”,$_GET[‘q’]));
if ($alias != $_GET[‘q’]) {
$template_filename = ‘page’;
foreach (explode(‘/’, $alias) as $path_part) {
$template_filename = $template_filename . ‘-‘ . $path_part;
$vars[‘template_files’][] = $template_filename;
}
}
}
}
}

this function creates all possible combinations of templates suggestions to drupal.And in that page i use module_invoke for getting the results

How to pass values to existing drupal filters

Leave a comment

‘nid’ is the field used in my view for filter and following is my code for give a value to filter
$BlogSelected contains blog id showed as first blog,the view shows rest of the blog items

$view = views_get_view(“View_Blog_User_Archivio”);
$display_id = ‘default’;
$view->set_display($display_id);
$item = $view->get_item($display_id, ‘filter’, ‘nid’);
$item[‘value’] = $BlogSelected;
$view->set_item($display_id, ‘filter’, ‘nid’, $item);
$view->is_cacheable = FALSE;

$view->execute();

$output = $view->render();

How to add CCK date field as filters in drupal view with default values

Leave a comment

create view and add fields,sort criteria etc

step 1 : select group as ‘Date’ then Date:node,add it to the filter by clicking the add
step 2: set Date form type: as text,granularity as day,from
‘Date field(s):’ select the CCK field you want and select method ‘AND or OR’,click update
step 3:Here is the trick
Operator: as you like (i am selected ‘is less than or equal to(for avoid post dated pubblications)’.
Attention for default value:
put your default value in ‘Date default:’ (i am used ‘now’ for current date,other values as ‘now +1 day’).

and update it .Now you have a view filterd by CCK date field

 

 

Inner join and subquery in sql server.Which one is more better?

Leave a comment

Today  i have an experince with sql server 2005 on our production server with 6000 records and almost 12000 records in category table.Inner join is goes wrong for me and sub query is run well in our production machine.If some thing wrong please correct me…
May be it gives a good idea to others to oraganize their query .
NB:I am using this query for creating text file  for Node import module of drupal.
query 1 never finished with in 1 minute:-
select distinct top 1 A.Idarticolo,Titolo,titoletto,autore,fonte,dbo.getOperatore(A.idoperatore) as IdOperatore,
(cast(day(data) as varchar(2))+’/’+cast(month(data) as varchar(2))+’/’+cast(year(data) as varchar(4)) + ‘ ‘ +ora)
datatime_,data,dbo.getTags(A.Idarticolo) as Tags from tab_articoli A inner join tab_merc_catearticoli B
on A.Idarticolo=B.Idarticolo where b.codi_cate_arti not in (63,58,61,48,49) order by data asc
query 1 modified with subquery:(finished in 0 seconds)
select distinct top 1 A.Idarticolo,Titolo,titoletto,autore,fonte,dbo.getOperatore(A.idoperatore) as IdOperatore,
(cast(day(data) as varchar(2))+’/’+cast(month(data) as varchar(2))+’/’+cast(year(data) as varchar(4)) + ‘ ‘ +ora)
datatime_,data,dbo.getTags(A.Idarticolo) as Tags from tab_articoli A where a.idarticolo not in(
select idarticolo from tab_merc_catearticoli  where codi_cate_arti not in (63,58,61,48,49)
)
order by data asc
functions :-

create FUNCTION getarticoli
(@idarticolo int)
RETURNS varchar(5000)
AS
BEGIN
declare @corelati varchar(5000)
SELECT @corelati= coalesce(@corelati + ‘$’, ”) + titolo from tab_articoli A inner join
TAB_MERC_ARTI_CORR B on
A.Idarticolo=B.IdArtCorr where a.Idarticolo=@Idarticolo
return @corelati
end


create FUNCTION getcategory
(@idarticolo int)
RETURNS varchar(1000)
AS
BEGIN
declare @CategoryList varchar(1000)
SELECT @CategoryList= coalesce(@CategoryList + ‘$’,”) + DESC_CATE_ARTI from TAB_MERC_CATE_ARTI A inner join  TAB_MERC_CATEARTICOLI B
on A.CODI_CATE_ARTI=B.CODI_CATE_ARTI where B.Idarticolo=@idarticolo
return @CategoryList
end

create FUNCTION getOperatore
(@Idoperatore int)
RETURNS int
AS
BEGIN
return case @Idoperatore
when 1 then 1
when 39 then 3
when 40 then 4
when 41 then 5
when 42 then 6
when 43 then 7
else 1
end
end
Alter FUNCTION getTags
(@idarticolo int)
RETURNS varchar(1000)
AS
BEGIN
declare @tagList varchar(1000)
SELECT @tagList= coalesce(@tagList + ‘$’,”) + Tag from Tab_TagCloud where Idarticolo=@idarticolo
return @tagList
end
print dbo.getTags(8817)

How to create custom tags in drupal(Like wordpress)

Leave a comment

Create a vocabulary with ‘tags’ checkbox checked(Terms are created by users when submitting posts by typing a comma separated list.).

And Follow this link-http://sudosys.be/?q=drupal_tag_cloud

Mongodb Querying

Leave a comment

With this post i want to explain some of my experiences with Mongodb and php mongo driver.

  • searching a  collection of Mongodb with a word we can use the code like this
$search = new MongoRegex(“/”.$str.”/i”);
$cursor = $collection->find(array(“Campo” => $search))
($str is the string for search,collection is the reference to db collection,Campo is the field to search)
(i will add more  later)

Syndication rules

Leave a comment

(Courtsy:http://blog.flameeyes.eu/2010/07/05/syndication-rules)

I have noticed that, beside Planet (and Universe) Gentoo and Linux-Planet — both of which I asked for my blog to be syndacated on, there are a number of other websites that seem to fetch and use my own posts, fetched from the atom feeds.

Some of these are community websites, other are “hubs” that supposedly focus content for users; quite a few though seem to be scams and websites that simply take others’ posts and snap a bunch of AdSense units over them. While I could go as far as pushing for DMCA violation for those – as often CC-BY-NC-ND is not respected – I’d rather not, and especially I’d rather go with technical solutions of some kind.

What I would like to do is to have different feeds depending on who’s requesting them; so have a “pure” feed, with the original unmangled content from Typo for the syndications I allow explicitly (with host-based detection is even better), one Flattr-enabled feed to provide to feed readers and Google, and one, eventually, with AdSense units to shove down the abusive websites.

Now, for the moment I set up the two most-subscribed feeds on Google’s FeedBurner; I’d still ask you to keep using my blog’s host URLs though, as that might not be a definitive solution; if I can find some software to deal with this, or even write a Typo plugin to handle this for me, I’ll drop FeedBurner again; I’m just not happy to have to outsource feeds handling for my own blog. I’ll call this an experiment. If you happen to subscribe to the FeedBurner feeds, don’t worry, I’ll make sure to keep them updated, and hopefully without mangling content if I do handle that on my side.

Now, the important information on this post relates to the “rules” for syndicating my content, so that it is clear whether you’ll get the Ad-encumbered feed or not. Obviously if I asked to be syndicated, as is the case for Planet Gentoo and Linux Planet, then you’ll get the absolutely clear feed: no ads, no flattr buttons, nothing else. If the website has no content, a lot of ads, and even worse no indication of where the content truly comes from, I’m going to consider technical means to hinder the syndication, such as pushing ads on the feed myself, or removing the content, or adding a footer making the author and the terms of the content’s license explicit.

For the rest of the websites, I’m generally not going to bother; if you’re a decent news aggregator, and don’t have advertisement as main content on your site, and you abide to the content’s license giving proper attribution rather than showing off my content as your own, I’ve got no problem. I’ll be happy if you were to flattr me and I might decide to push a Flattr button on the content pushed on.. if you wish to avoid that, you’re free to contact me and we can work out the details.. in general I have no objection to that as long as your aggregation software is decent enough to cache responses using If-None-Match and If-Modified-Since, and to use deflated (compressed) content transfer.

Older Entries