Changeset 6950 for extensions/AMetaData/amd_ajax.php
- Timestamp:
- Sep 16, 2010, 8:55:20 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/AMetaData/amd_ajax.php
r6920 r6950 84 84 $_REQUEST['ajaxfct']=='admin.userDefined.deleteTag' or 85 85 $_REQUEST['ajaxfct']=='admin.tag.getValues' or 86 $_REQUEST['ajaxfct']=='admin.tags.getKeywords' or 87 $_REQUEST['ajaxfct']=='admin.tags.convertKeywords' or 86 88 87 89 $_REQUEST['ajaxfct']=='public.makeStats.doPictureAnalyze')) $_REQUEST['ajaxfct']=''; … … 317 319 } 318 320 321 /* 322 * check admin.tags.convertKeywords values 323 */ 324 if($_REQUEST['ajaxfct']=="admin.tags.convertKeywords") 325 { 326 if(!isset($_REQUEST['keywords'])) $_REQUEST['keywords']=array(); 327 if(!is_array($_REQUEST['keywords'])) $_REQUEST['keywords']=array(); 328 if(count($_REQUEST['keywords'])==0) $_REQUEST['ajaxfct']=''; 329 } 330 331 319 332 320 333 … … 401 414 case 'admin.tag.getValues': 402 415 $result=$this->ajax_amd_admin_tagGetValues($_REQUEST['id']); 416 break; 417 case 'admin.tags.getKeywords': 418 $result=$this->ajax_amd_admin_tagsGetKeywords(); 419 break; 420 case 'admin.tags.convertKeywords': 421 $result=$this->ajax_amd_admin_tagsConvertKeywords($_REQUEST['keywords']); 403 422 break; 404 423 … … 942 961 'name' => L10n::get($row['name']), 943 962 'numId' => $row['numId'], 944 'nbItems' => $row['numOfImg'],945 'pct' => ($ numOfPictures==0)?"0":sprintf("%.2f", 100*$row['numOfImg']/$numOfPictures)963 'nbItems' => ($this->config['amd_InterfaceMode']=='advanced')?$row['numOfImg']:'', 964 'pct' => ($this->config['amd_InterfaceMode']=='advanced')?(($numOfPictures==0)?"0":sprintf("%.2f", 100*$row['numOfImg']/$numOfPictures)):'' 946 965 ); 947 966 } … … 1340 1359 $result=pwg_query($sql); 1341 1360 */ 1361 1362 if($this->config['amd_InterfaceMode']=='basic') 1363 { 1364 $sql="INSERT INTO ".$this->tables['selected_tags']." VALUES ('".$properties['tagId']."', 0, -1);"; 1365 pwg_query($sql); 1366 } 1342 1367 } 1343 1368 else … … 1371 1396 foreach($properties['rules'] as $rule) 1372 1397 { 1373 print_r($rule['value']);1398 //print_r($rule['value']); 1374 1399 $inserts[]="('$id', '".$rule['defId']."', '".$rule['parentId']."', '".$rule['order']."', '".$rule['type']."', '".$rule['value']."', '".$rule['conditionType']."', '".$rule['conditionValue']."')"; 1375 1400 } … … 1378 1403 $result=pwg_query($sql); 1379 1404 1380 $nbImg=$this->buildUserDefinedTags($id); 1405 if($this->config['amd_InterfaceMode']=='advanced') 1406 { 1407 $nbImg=$this->buildUserDefinedTags($id); 1408 } 1409 else 1410 { 1411 $nbImg=0; 1412 } 1381 1413 1382 1414 $this->makeStatsConsolidation(); … … 1463 1495 1464 1496 /** 1497 * return an html list of found keywords in the images_tags table 1498 * 1499 * @return String : html formatted list 1500 */ 1501 private function ajax_amd_admin_tagsGetKeywords() 1502 { 1503 global $template; 1504 1505 $returned=array(); 1506 $keywordsList=array(); 1507 $sql="SELECT pait.value, pait.imageId, paut.numId 1508 FROM (".$this->tables['images_tags']." pait 1509 JOIN ".$this->tables['used_tags']." paut ON pait.numId = paut.numId) 1510 1511 WHERE (paut.tagId = 'xmp.dc:subject' OR 1512 paut.tagId = 'xmp.digiKam:tagsList' OR 1513 paut.tagId = 'iptc.Keywords');"; 1514 $result=pwg_query($sql); 1515 if($result) 1516 { 1517 while($row=pwg_db_fetch_assoc($result)) 1518 { 1519 if(preg_match('/^a:\d+:{/', $row['value'])) 1520 { 1521 /* 1522 * if value is a serialized string, unserialize and process it 1523 */ 1524 $tmp=unserialize($row['value']); 1525 foreach($tmp['values'] as $val) 1526 { 1527 $keywordsList[]="('".mysql_escape_string($val)."', ".$row['imageId'].")"; 1528 } 1529 } 1530 else 1531 { 1532 $keywordsList[]="('".mysql_escape_string($row['value'])."', ".$row['imageId'].")"; 1533 } 1534 } 1535 $sql="CREATE TEMPORARY TABLE amd_temp_tags ( 1536 `value` CHAR(255) default '', 1537 `imageId` mediumint(8) unsigned NOT NULL default '0', 1538 PRIMARY KEY USING BTREE (`value`,`imageId`) 1539 ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; 1540 if(pwg_query($sql)) 1541 { 1542 $sql="INSERT IGNORE INTO amd_temp_tags 1543 VALUES ".implode(',', $keywordsList); 1544 if(pwg_query($sql)) 1545 { 1546 $sql="SELECT att.value AS value, 1547 COUNT(DISTINCT att.imageId) AS nbPictures, 1548 IF(ptt.name IS NULL, 'n', 'y') AS tagExists, 1549 COUNT(DISTINCT pit.image_id) AS nbPicturesTagged 1550 FROM (amd_temp_tags att LEFT JOIN ".TAGS_TABLE." ptt ON att.value = ptt.name) 1551 LEFT JOIN ".IMAGE_TAG_TABLE." pit ON pit.tag_id = ptt.id 1552 GROUP BY att.value 1553 HAVING nbPicturesTagged < nbPictures"; 1554 $result=pwg_query($sql); 1555 if($result) 1556 { 1557 $i=0; 1558 while($row=pwg_db_fetch_assoc($result)) 1559 { 1560 $row['id']=$i; 1561 $returned[]=$row; 1562 $i++; 1563 } 1564 } 1565 } 1566 } 1567 } 1568 1569 $template->set_filename('keywordsList', 1570 dirname($this->getFileLocation()).'/admin/amd_metadata_tags_iKeywordsList.tpl'); 1571 1572 $template->assign('datas', $returned); 1573 return($template->parse('keywordsList', true)); 1574 } 1575 1576 1577 /** 1578 * convert given keywords into tags, and associate them to pictures 1579 * 1580 * @param Array $keywords : an array of strings 1581 * @return String : ok or ko 1582 */ 1583 private function ajax_amd_admin_tagsConvertKeywords($keywords) 1584 { 1585 global $template; 1586 1587 $returned='ko'; 1588 1589 /* 1590 * 1/ build a temp table with all couple of keywords/imageId 1591 */ 1592 $keywordsList=array(); 1593 $sql="SELECT pait.value, pait.imageId, paut.numId 1594 FROM (".$this->tables['images_tags']." pait 1595 JOIN ".$this->tables['used_tags']." paut ON pait.numId = paut.numId) 1596 1597 WHERE (paut.tagId = 'xmp.dc:subject' OR 1598 paut.tagId = 'xmp.digiKam:tagsList' OR 1599 paut.tagId = 'iptc.Keywords');"; 1600 $result=pwg_query($sql); 1601 if($result) 1602 { 1603 while($row=pwg_db_fetch_assoc($result)) 1604 { 1605 if(preg_match('/^a:\d+:{/', $row['value'])) 1606 { 1607 /* 1608 * if value is a serialized string, unserialize and process it 1609 */ 1610 $tmp=unserialize($row['value']); 1611 foreach($tmp['values'] as $val) 1612 { 1613 $keywordsList[]="('".mysql_escape_string($val)."', ".$row['imageId'].")"; 1614 } 1615 } 1616 else 1617 { 1618 $keywordsList[]="('".mysql_escape_string($row['value'])."', ".$row['imageId'].")"; 1619 } 1620 } 1621 $sql="CREATE TEMPORARY TABLE amd_temp_tags ( 1622 `value` CHAR(255) default '', 1623 `imageId` mediumint(8) unsigned NOT NULL default '0', 1624 PRIMARY KEY USING BTREE (`value`,`imageId`) 1625 ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; 1626 if(pwg_query($sql)) 1627 { 1628 $sql="INSERT IGNORE INTO amd_temp_tags 1629 VALUES ".implode(',', $keywordsList); 1630 if(pwg_query($sql)) 1631 { 1632 foreach($keywords as $key => $val) 1633 { 1634 $keywords[$key]="(att.value LIKE '".mysql_escape_string($val)."')"; 1635 } 1636 /* 1637 * 2/ join temp table with piwigo tags table, found the keywords 1638 * that don't have a corresponding keyword 1639 */ 1640 $sql="SELECT DISTINCT att.value 1641 FROM amd_temp_tags att LEFT JOIN ".TAGS_TABLE." ptt ON att.value = ptt.name 1642 WHERE ptt.id IS NULL 1643 AND".implode(' OR ', $keywords); 1644 $result=pwg_query($sql); 1645 if($result) 1646 { 1647 $sql=array(); 1648 while($row=pwg_db_fetch_assoc($result)) 1649 { 1650 $sql[]="('', '".mysql_escape_string($row['value'])."', '".mysql_escape_string(str2url($row['value']))."')"; 1651 } 1652 if(count($sql)>0) 1653 { 1654 $sql="INSERT INTO ".TAGS_TABLE." VALUES ".implode(',', $sql); 1655 pwg_query($sql); 1656 } 1657 } 1658 1659 /* 1660 * 3/ join temp table with piwigo tags table, associate piwigo tagId 1661 * to the keywords (at this step, all keyword can be associated 1662 * with a piwigo tagId) 1663 */ 1664 $sql="INSERT IGNORE INTO ".IMAGE_TAG_TABLE." 1665 SELECT DISTINCT att.imageId, ptt.id 1666 FROM amd_temp_tags att LEFT JOIN ".TAGS_TABLE." ptt ON att.value = ptt.name 1667 WHERE ".implode(' OR ', $keywords); 1668 $result=pwg_query($sql); 1669 $returned='ok'; 1670 } 1671 } 1672 } 1673 1674 return($returned); 1675 } 1676 1677 1678 /** 1465 1679 * set value(s) for option(s) 1466 1680 *
Note: See TracChangeset
for help on using the changeset viewer.