Skip to content
Permalink
Browse files
improvement: tags replace keywords. Better data model, less
limitations. Each image can be associated to as many tag as needed. Tags can
contain non ASCII characters. Oriented navigation with tags by association.


git-svn-id: http://piwigo.org/svn/trunk@1119 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Apr 2, 2006
1 parent 68ed2ea commit 42abf4c57664d2596872d437f70b95193f9a5d18
Showing 44 changed files with 1,848 additions and 353 deletions.
@@ -92,6 +92,7 @@
'U_COMMENTS'=> $link_start.'comments',
'U_RATING'=> $link_start.'rating',
'U_CADDIE'=> $link_start.'element_set&cat=caddie',
'U_TAGS'=> $link_start.'tags',
'U_THUMBNAILS'=> $link_start.'thumbnail',
'U_USERS'=> $link_start.'user_list',
'U_GROUPS'=> $link_start.'group_list',
@@ -43,40 +43,6 @@
// +-----------------------------------------------------------------------+
check_status(ACCESS_ADMINISTRATOR);

// +-----------------------------------------------------------------------+
// | functions |
// +-----------------------------------------------------------------------+

/**
* returns the list of uniq keywords among given elements
*
* @param array element_ids
*/
function get_elements_keywords($element_ids)
{
if (0 == count($element_ids))
{
return array();
}

$keywords = array();

$query = '
SELECT keywords
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $element_ids).')
;';
$result = pwg_query($query);
while ($row = mysql_fetch_array($result))
{
if (isset($row['keywords']) and !empty($row['keywords']))
{
$keywords = array_merge($keywords, explode(',', $row['keywords']));
}
}
return array_unique($keywords);
}

// +-----------------------------------------------------------------------+
// | global mode form submission |
// +-----------------------------------------------------------------------+
@@ -111,6 +77,22 @@ function get_elements_keywords($element_ids)
}
}

if (isset($_POST['add_tags']) and count($collection) > 0)
{
add_tags($_POST['add_tags'], $collection);
}

if (isset($_POST['del_tags']) and count($collection) > 0)
{
$query = '
DELETE
FROM '.IMAGE_TAG_TABLE.'
WHERE image_id IN ('.implode(',', $collection).')
AND tag_id IN ('.implode(',', $_POST['del_tags']).')
;';
pwg_query($query);
}

if ($_POST['associate'] != 0 and count($collection) > 0)
{
$datas = array();
@@ -192,11 +174,6 @@ function get_elements_keywords($element_ids)
$datas = array();
$dbfields = array('primary' => array('id'), 'update' => array());

if (!empty($_POST['add_keywords']) or $_POST['remove_keyword'] != '0')
{
array_push($dbfields['update'], 'keywords');
}

$formfields = array('author', 'name', 'date_creation');
foreach ($formfields as $formfield)
{
@@ -210,7 +187,7 @@ function get_elements_keywords($element_ids)
if (count($dbfields['update']) > 0 and count($collection) > 0)
{
$query = '
SELECT id, keywords
SELECT id
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $collection).')
;';
@@ -221,44 +198,6 @@ function get_elements_keywords($element_ids)
$data = array();
$data['id'] = $row['id'];

if (!empty($_POST['add_keywords']))
{
$data['keywords'] =
implode(
',',
array_unique(
array_merge(
get_keywords(empty($row['keywords']) ? '' : $row['keywords']),
get_keywords($_POST['add_keywords'])
)
)
);
}

if ($_POST['remove_keyword'] != '0')
{
if (!isset($data['keywords']))
{
$data['keywords'] = empty($row['keywords']) ? '' : $row['keywords'];
}

$data['keywords'] =
implode(
',',
array_unique(
array_diff(
get_keywords($data['keywords']),
array($_POST['remove_keyword'])
)
)
);

if ($data['keywords'] == '')
{
unset($data['keywords']);
}
}

if ('set' == $_POST['author_action'])
{
$data['author'] = $_POST['author'];
@@ -384,25 +323,36 @@ function get_elements_keywords($element_ids)
display_select_cat_wrapper($query, array(), $blockname, true);
}

$blockname = 'remove_keyword_option';

$template->assign_block_vars(
$blockname,
array('VALUE'=> 0,
'OPTION' => '------------'
));
// add tags
$template->assign_vars(
array(
'ADD_TAG_SELECTION' => get_html_tag_selection(get_all_tags(), 'add_tags'),
)
);

$keywords = get_elements_keywords($page['cat_elements_id']);
// remove tags
$query = '
SELECT tag_id, name, url_name, count(*) counter
FROM '.IMAGE_TAG_TABLE.'
INNER JOIN '.TAGS_TABLE.' ON tag_id = id
WHERE image_id IN ('.implode(',', $page['cat_elements_id']).')
GROUP BY tag_id
ORDER BY name ASC
;';
$result = pwg_query($query);

foreach ($keywords as $keyword)
$tags = array();
while($row = mysql_fetch_array($result))
{
$template->assign_block_vars(
$blockname,
array('VALUE'=> $keyword,
'OPTION' => $keyword
));
array_push($tags, $row);
}

$template->assign_vars(
array(
'DEL_TAG_SELECTION' => get_html_tag_selection($tags, 'del_tags'),
)
);

// creation date
$day =
empty($_POST['date_creation_day']) ? date('j') : $_POST['date_creation_day'];
@@ -103,25 +103,21 @@
{
$data{'date_creation'} = $row['date_creation'];
}

array_push($datas, $data);

$keywords = get_keywords($_POST['keywords-'.$row['id']]);
if (count($keywords) > 0)
{
$data{'keywords'} = implode(',', $keywords);
}
else
// tags management
if (isset($_POST[ 'tags-'.$row['id'] ]))
{
$data{'keywords'} = '';
set_tags($_POST[ 'tags-'.$row['id'] ], $row['id']);
}

array_push($datas, $data);
}

mass_updates(
IMAGES_TABLE,
array(
'primary' => array('id'),
'update' => array('name','author','comment','date_creation','keywords')
'update' => array('name','author','comment','date_creation')
),
$datas
);
@@ -192,11 +188,13 @@
);
$template->assign_vars(array('NAV_BAR' => $nav_bar));

// tags
$all_tags = get_all_tags();

$element_ids = array();

$query = '
SELECT id,path,tn_ext,name,date_creation,comment,keywords,author,file
SELECT id,path,tn_ext,name,date_creation,comment,author,file
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $page['cat_elements_id']).')
'.$conf['order_by'].'
@@ -210,6 +208,13 @@
array_push($element_ids, $row['id']);

$src = get_thumbnail_src($row['path'], @$row['tn_ext']);

$query = '
SELECT tag_id
FROM '.IMAGE_TAG_TABLE.'
WHERE image_id = '.$row['id'].'
;';
$selected_tags = array_from_query($query, 'tag_id');

// creation date
if (!empty($row['date_creation']))
@@ -237,7 +242,12 @@
'AUTHOR' => @$row['author'],
'DESCRIPTION' => @$row['comment'],
'DATE_CREATION_YEAR' => $year,
'KEYWORDS' => @$row['keywords']

'TAG_SELECTION' => get_html_tag_selection(
$all_tags,
'tags-'.$row['id'],
$selected_tags
),
)
);

0 comments on commit 42abf4c

Please sign in to comment.