Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Site
lqdn_similar_nodes
Commits
93f080e8
Commit
93f080e8
authored
May 15, 2015
by
Mindiell
Browse files
First commit
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
lqdn_similar_nodes.info
0 → 100644
View file @
93f080e8
;
$
Id
$
name
=
"Similar nodes"
description
=
Provides
blocks
with
nodes
in
the
same
dossier
(
s
).
core
=
6.
x
package
=
"La Quadrature"
dependencies
[]
=
lqdn_dossiers
dependencies
[]
=
lqdn_latest_nodes
lqdn_similar_nodes.install
0 → 100644
View file @
93f080e8
<?php
// $Id$
lqdn_similar_nodes.module
0 → 100644
View file @
93f080e8
<?php
function
_lqdn_similar_nodes_get_tags
(
$_nid
)
{
// Tags of the node
$n_tags
=
array
();
$query
=
"SELECT td.`tid`, `name` FROM `term_data` td "
.
"LEFT JOIN `term_node` tn ON td.`tid`=tn.`tid` "
.
"LEFT JOIN `node` n ON tn.`vid`=n.`vid` "
.
"WHERE n.`nid`=%d AND td.`vid`=2"
;
$result
=
db_query
(
$query
,
$_nid
);
while
(
$data
=
db_fetch_object
(
$result
))
$n_tags
[]
=
$data
->
tid
;
return
$n_tags
;
}
function
_lqdn_similar_nodes_get_dossiers
(
$n_tags
)
{
global
$language
;
// List of dossiers with a same tag
$dossiers
=
array
();
$query
=
"SELECT `did`, `active`, `name`, `image`, `path`, `tags` "
.
"FROM `lqdn_dossiers_contents`"
.
"WHERE `active`=1 AND `language`='%s'"
.
"ORDER BY `archive`, `weight`"
;
$result
=
db_query
(
$query
,
$language
->
language
);
while
(
$data
=
db_fetch_object
(
$result
))
{
$d_tags
=
explode
(
','
,
$data
->
tags
);
$d_tags
=
array_map
(
'intval'
,
$d_tags
);
foreach
(
$d_tags
as
$d_tag
)
{
if
(
in_array
(
$d_tag
,
$n_tags
))
{
$dossiers
[]
=
$data
;
break
;
}
}
}
return
$dossiers
;
}
function
lqdn_similar_nodes_block
(
$op
=
'list'
,
$delta
=
0
,
$edit
=
array
())
{
global
$language
;
switch
(
$op
)
{
case
'list'
:
$blocks
=
array
();
$blocks
[
0
][
'info'
]
=
t
(
"Related dossiers"
);
$blocks
[
1
][
'info'
]
=
t
(
"Related quad'news"
);
$blocks
[
2
][
'info'
]
=
t
(
"Related press review"
);
$blocks
[
3
][
'info'
]
=
t
(
"Related content (quad'news + press review)"
);
return
$blocks
;
break
;
case
'view'
:
$block
=
array
();
// Does this page is a actualite node?
if
(
substr
(
$_GET
[
'q'
],
0
,
5
)
==
'node/'
)
{
$node
=
intval
(
substr
(
$_GET
[
'q'
],
5
));
$result
=
db_query
(
'SELECT `type` FROM `node` WHERE `nid`=%d'
,
$node
);
$data
=
db_fetch_object
(
$result
);
if
(
$data
->
type
!=
'actualite'
)
return
$block
;
}
else
return
$block
;
$n_tags
=
_lqdn_similar_nodes_get_tags
(
$node
);
$dossiers
=
_lqdn_similar_nodes_get_dossiers
(
$n_tags
);
$tags
=
$n_tags
;
// We initialize tags with tags from node
foreach
(
$dossiers
as
$dossier
)
$tags
[]
=
$dossier
->
tags
;
// We add tags from dossiers
$list_tags
.
=
implode
(
', '
,
$tags
);
// First block : dossiers
if
(
$delta
==
0
)
{
$content
=
''
;
foreach
(
$dossiers
as
$dossier
)
{
$options
[
'attributes'
]
=
array
(
//'class' => 'image-illustration', // CSS file not available here.
'style'
=>
'background-image: url('
.
htmlspecialchars
(
$dossier
->
image
)
.
'); '
.
'background-color:#FFFFFF; background-position:center center; '
.
'background-repeat:no-repeat; border:1px solid #DDD; display:block; '
.
'height:130px; overflow:hidden; margin: 5px auto; text-indent:-1000px; width:150px;'
,
);
$content
.
=
l
(
$dossier
->
name
,
$dossier
->
path
,
$options
)
.
"<br />
\n
"
;
}
$block
[
'subject'
]
=
t
(
'Related dossiers'
);
$block
[
'content'
]
=
empty
(
$content
)
?
''
:
$content
;
return
$block
;
}
// Second and third block
elseif
(
$delta
==
1
||
$delta
==
2
)
{
$type
=
(
$delta
==
1
)
?
'actu'
:
'rp'
;
$dossier
->
name
=
''
;
$dossier
->
tags
=
$list_tags
;
$content
=
lqdn_latest_nodes_list
(
$type
,
$dossier
);
if
(
!
empty
(
$content
))
{
$block
[
'subject'
]
=
(
$delta
==
1
)
?
t
(
"Related quad'news"
)
:
t
(
"Related press review"
);
$block
[
'content'
]
=
$content
;
}
return
$block
;
}
elseif
(
$delta
==
3
)
{
$dossier
->
name
=
''
;
$dossier
->
tags
=
$list_tags
;
$block
[
'subject'
]
=
''
;
$block
[
'content'
]
=
_lqdn_latest_nodes_latest_news_and_press_articles
(
$dossier
,
7
,
0
);
return
$block
;
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment