Changeset 17725
- Timestamp:
- Sep 3, 2012, 10:49:42 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.4/admin/include/functions.php
r17668 r17725 220 220 { 221 221 delete_element_derivatives($row); 222 $new_ids[] += $row['id'];222 $new_ids[] = $row['id']; 223 223 } 224 224 else … … 1321 1321 function set_tags($tags, $image_id) 1322 1322 { 1323 $query = ' 1324 DELETE 1325 FROM '.IMAGE_TAG_TABLE.' 1326 WHERE image_id = '.$image_id.' 1327 ;'; 1328 pwg_query($query); 1329 1330 if (count($tags) > 0) 1331 { 1332 $inserts = array(); 1333 foreach ($tags as $tag_id) 1334 { 1335 array_push( 1336 $inserts, 1337 array( 1338 'tag_id' => $tag_id, 1339 'image_id' => $image_id 1340 ) 1341 ); 1342 } 1343 mass_inserts( 1344 IMAGE_TAG_TABLE, 1345 array_keys($inserts[0]), 1346 $inserts 1347 ); 1348 } 1323 set_tags_of( array($image_id=>$tags) ); 1349 1324 } 1350 1325 … … 1376 1351 foreach ($images as $image_id) 1377 1352 { 1378 foreach ($tags as $tag_id) 1379 { 1380 array_push( 1381 $inserts, 1382 array( 1353 foreach ( array_unique($tags) as $tag_id) 1354 { 1355 $inserts[] = array( 1383 1356 'image_id' => $image_id, 1384 1357 'tag_id' => $tag_id, 1385 )1386 1358 ); 1387 1359 } … … 1434 1406 } 1435 1407 1436 // does the tag already exists?1408 // search existing by exact name 1437 1409 $query = ' 1438 1410 SELECT id … … 1440 1412 WHERE name = \''.$tag_name.'\' 1441 1413 ;'; 1442 $existing_tags = array_from_query($query, 'id'); 1443 1444 if (count($existing_tags) == 0) 1445 { 1446 mass_inserts( 1447 TAGS_TABLE, 1448 array('name', 'url_name'), 1449 array( 1450 array( 1451 'name' => $tag_name, 1452 'url_name' => trigger_event('render_tag_url', $tag_name), 1453 ) 1454 ) 1455 ); 1456 1457 $page['tag_id_from_tag_name_cache'][$tag_name] = pwg_db_insert_id(TAGS_TABLE); 1458 } 1459 else 1460 { 1461 $page['tag_id_from_tag_name_cache'][$tag_name] = $existing_tags[0]; 1462 } 1463 1414 if (count($existing_tags = array_from_query($query, 'id')) == 0) 1415 { 1416 // search existing by case insensitive name 1417 $query = ' 1418 SELECT id 1419 FROM '.TAGS_TABLE.' 1420 WHERE CONVERT(name, CHAR) = \''.$tag_name.'\' 1421 ;'; 1422 if (count($existing_tags = array_from_query($query, 'id')) == 0) 1423 { 1424 $url_name = trigger_event('render_tag_url', $tag_name); 1425 // search existing by url name 1426 $query = ' 1427 SELECT id 1428 FROM '.TAGS_TABLE.' 1429 WHERE url_name = \''.$url_name.'\' 1430 ;'; 1431 if (count($existing_tags = array_from_query($query, 'id')) == 0) 1432 { 1433 mass_inserts( 1434 TAGS_TABLE, 1435 array('name', 'url_name'), 1436 array( 1437 array( 1438 'name' => $tag_name, 1439 'url_name' => $url_name, 1440 ) 1441 ) 1442 ); 1443 $page['tag_id_from_tag_name_cache'][$tag_name] = pwg_db_insert_id(TAGS_TABLE); 1444 return $page['tag_id_from_tag_name_cache'][$tag_name]; 1445 } 1446 } 1447 } 1448 1449 $page['tag_id_from_tag_name_cache'][$tag_name] = $existing_tags[0]; 1464 1450 return $page['tag_id_from_tag_name_cache'][$tag_name]; 1465 1451 } … … 1480 1466 foreach ($tags_of as $image_id => $tag_ids) 1481 1467 { 1482 foreach ( $tag_idsas $tag_id)1468 foreach (array_unique($tag_ids) as $tag_id) 1483 1469 { 1484 array_push( 1485 $inserts, 1486 array( 1470 $inserts[] = array( 1487 1471 'image_id' => $image_id, 1488 1472 'tag_id' => $tag_id, 1489 )1490 1473 ); 1491 1474 } … … 2163 2146 if (preg_match('/^~~(\d+)~~$/', $raw_tag, $matches)) 2164 2147 { 2165 array_push($tag_ids, $matches[1]);2148 $tag_ids[] = $matches[1]; 2166 2149 } 2167 2150 elseif ($allow_create)
Note: See TracChangeset
for help on using the changeset viewer.