/usr/share/drupal6/modules/imagefield_assist/imagefield_assist.module is in drupal6-mod-imagefield-assist 1.0~beta3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 | <?php
// $Id: imagefield_assist.module,v 1.1.2.13 2009/11/23 20:56:41 lourenzo Exp $
/**
* @file
* Imagefield Assist module
*
* Implements a javascript-driven user interface to upload images to a Drupal
* site and select a previously uploaded image for displaying inline in a
* content.
*/
/**
* Implementation of hook_help().
*/
function imagefield_assist_help($path, $arg) {
switch ($path) {
case 'admin/settings/imagefield_assist':
return t('If this site was moved or is planned to move to another domain or sub-directory, it might be needed to <a href="!empty-cache">empty the filter cache</a> to correct image paths that are pointing to the old address. Note that this will only work for images that have been inserted using filter tags.', array('!empty-cache' => url('imagefield_assist/cache/clear')));
case 'imagefield_assist/template':
return '<div class="%image-class"><a href="%link">%image</a><div class="caption">%caption</div></div>';
}
}
/**
* Implementation of hook_theme().
*/
function imagefield_assist_theme() {
return array(
'imagefield_assist_inline' => array(
'arguments' => array('node' => NULL, 'size' => NULL, 'attributes' => NULL),
),
'imagefield_assist_filter' => array(
'arguments' => array('text' => NULL),
),
'imagefield_assist_popup' => array(
'arguments' => array('content' => NULL, 'attributes' => NULL),
),
'imagefield_assist_page' => array(
'arguments' => array('content' => NULL, 'attributes' => NULL),
),
'imagefield_assist_legacy' => array(),
);
}
/**
* Implementation of hook_menu().
*/
function imagefield_assist_menu() {
$items = array();
$items['imagefield_assist/cache/clear'] = array(
'title' => t('Empty Cache'),
'page callback' => 'imagefield_assist_cache_clear',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['imagefield_assist/load'] = array(
'title' => 'ImageField assist',
'page callback' => 'imagefield_assist_loader',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
// Page callbacks called internally by imagefield_assist/load.
$items['imagefield_assist/header'] = array(
'title' => 'ImageField assist header',
'page callback' => 'imagefield_assist_header',
'page arguments' => array(2),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['imagefield_assist/thumbs'] = array(
'title' => 'ImageField assist thumbnails',
'page callback' => 'imagefield_assist_thumbs',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['imagefield_assist/upload'] = array(
'title' => 'ImageField assist upload',
'page callback' => 'imagefield_assist_upload',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['imagefield_assist/properties'] = array(
'title' => 'ImageField assist properties',
'page callback' => 'imagefield_assist_properties',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['imagefield_assist/preview'] = array(
'title' => t('Image Preview'),
'page callback' => 'imagefield_assist_preview',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['imagefield_assist/download'] = array(
'title' => t('Image Preview'),
'page callback' => 'imagefield_assist_download',
'page arguments' => array(2),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['imagefield_assist/imginfo'] = array(
'title' => t('Image Preview'),
'page callback' => 'imagefield_assist_image_info',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
// Popup images page.
$items['imagefield_assist/popup'] = array(
'title' => 'Popup image',
'page callback' => 'imagefield_assist_popup',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
// Insert callback (only for inserting HTML, not filter tag).
$items['imagefield_assist/insert_html'] = array(
'title' => 'Insert callback',
'page callback' => 'imagefield_assist_insert_html',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['admin/settings/imagefield_assist'] = array(
'title' => 'ImageField assist',
'description' => 'Change settings for the Image assist module.',
'page callback' => 'drupal_get_form',
'page arguments' => array('imagefield_assist_admin_settings'),
'access arguments' => array('administer site configuration'),
);
return $items;
}
/**
* Implementation of hook_init().
*/
function imagefield_assist_init() {
$path = drupal_get_path('module', 'imagefield_assist');
// Lightbox2 integration scripts
if (user_access('download original image')){
$orig_text = variable_get('lightbox2_download_link_text', t('Download Original') );
drupal_add_js(array('ifa_lightbox2_original' => "<br /><a target='_blank' id='download_link_text' href='". url('imagefield_assist/download') ."/!fid'>$orig_text</a>"), 'setting');
}
drupal_add_js($path .'/imagefield_assist_lightbox.js', 'module');
if (arg(0) == 'imagefield_assist') {
// Suppress Administration menu.
module_invoke('admin_menu', 'suppress');
drupal_add_css($path .'/imagefield_assist_popup.css', 'module', 'all', FALSE);
}
else {
drupal_add_js($path .'/imagefield_assist.js');
if (variable_get('imagefield_assist_page_styling', 'yes') == 'yes') {
drupal_add_css($path .'/imagefield_assist.css');
}
}
}
/**
* Implementation of hook_perm().
*/
function imagefield_assist_perm() {
return array('access imagefield_assist', 'access all images', 'upload images', 'access advanced options', 'use original size');
}
/**
* Implementation of hook_elements().
*/
function imagefield_assist_elements() {
$type['textarea'] = array(
'#process' => 'imagefield_assist_textarea'
);
return $type;
}
/**
* Preview image
* TODO: use drupal_redirect
* TODO: use imagecache_create_path
*/
function imagefield_assist_preview() {
if (!arg(2)) exit;
$image = current(imagefield_assist_load_imagefields( array('fid' => arg(2) )));
if (!empty($image)) {
if (arg(3) && arg(3) != 'fullsize') {
header('Location: '. url(file_directory_path() .'/imagecache/'. arg(3) .'/'. $image->path));
}
else {
header('Location: '. url(file_create_path($image->path)));
}
}
exit;
}
/**
* Download image
*/
function imagefield_assist_download($fid){
$image = $image = current(imagefield_assist_load_imagefields(array('fid' => $fid)));
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($image->path));
header( "Content-Description: File Transfer");
@readfile($image->path);
exit();
}
/**
* Ajax Image Default Size
*/
function imagefield_assist_image_info() {
if (!arg(2)) exit;
$image = current(imagefield_assist_load_imagefields( array('fid' => arg(2) )));
$info = image_get_info(file_create_path($image->path));
print drupal_to_js($info);
exit;
}
/**
* Add JavaScript settings for generating the image link underneath textareas.
*/
function imagefield_assist_textarea($element) {
static $initialized = FALSE;
if (!user_access('access imagefield_assist')) {
return $element;
}
$link = variable_get('imagefield_assist_link', 'icon');
if ($link == 'icon' || $link == 'text') {
if (_imagefield_assist_textarea_match($element['#id']) && _imagefield_assist_page_match() && !strstr($_GET['q'], 'imagefield_assist')) {
if (!$initialized) {
// Add settings.
$settings['link'] = $link;
if ($link == 'icon') {
$settings['icon'] = drupal_get_path('module', 'imagefield_assist') .'/add-image.jpg';
}
drupal_add_js(array('imagefield_assist' => $settings), 'setting');
$initialized = TRUE;
}
// Attach behavior.
// @todo Some browsers do not support underscores in CSS classes.
if (!isset($element['#attributes']['class'])) {
$element['#attributes']['class'] = 'imagefield_assist';
}
else {
$element['#attributes']['class'] .= ' imagefield_assist';
}
}
}
return $element;
}
/**
* Implementation of hook_block().
*
* Generates a block that references the other places the current image is used.
* The block is only visible when looking at the full view of an image.
*/
function imagefield_assist_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('Image reference');
return $blocks;
}
else if ($op == 'view') {
switch ($delta) {
case 0:
// Since blocks aren't passed node objects (which makes sense) we need
// to determine if we are viewing a node and grab its nid.
if (arg(0) == 'node' && is_numeric(arg(1))) {
$block['subject'] = t('This image appears in...');
$block['content'] = imagefield_assist_get_references(arg(1));
return $block;
}
break;
}
}
}
/**
* Implementation of hook_settings().
*/
function imagefield_assist_admin_settings() {
require_once drupal_get_path('module', 'imagefield_assist') .'/includes/imagefield_assist.token.inc';
// Access settings.
$form['access'] = array(
'#type' => 'fieldset',
'#title' => t('Access settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['access']['imagefield_assist_paths_type'] = array(
'#type' => 'radios',
'#title' => t('Display Image assist on paths'),
'#default_value' => variable_get('imagefield_assist_paths_type', 2),
'#options' => array(t('on specific paths'), t('not on specific paths'), t('all paths')),
);
$form['access']['imagefield_assist_paths'] = array(
'#type' => 'textarea',
'#title' => t('Paths'),
'#default_value' => variable_get('imagefield_assist_paths', "node/*\ncomment/*"),
'#cols' => 40,
'#rows' => 5,
'#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
);
$form['access']['imagefield_assist_textareas_type'] = array(
'#type' => 'radios',
'#title' => t('Display Image assist on text areas'),
'#default_value' => variable_get('imagefield_assist_textareas_type', 2),
'#options' => array(t('Show on every textarea except the listed textareas.'), t('Show on only the listed textareas.'), t('Show on all textareas.')),
);
$form['access']['imagefield_assist_textareas'] = array(
'#type' => 'textarea',
'#title' => t('Text areas'),
'#default_value' => variable_get('imagefield_assist_textareas', "edit-body\nedit-comment"),
'#cols' => 40,
'#rows' => 5,
'#description' => t("Enter one text area form-id per line. Form-id's are used by Drupal to typify them, which allows themers and coders to modify certain form fields, but not all. Find form-id's using this method: view the source of the webpage, then search for the string that's just above the text area and you'll see the form-id nearby. The '*' character is a wildcard. For example, you can specify all CCK fields as %cck-example.", array('%cck-example' => 'edit-field-*')),
);
$form['access']['imagefield_assist_link'] = array(
'#type' => 'select',
'#title' => t('Textarea image link'),
'#default_value' => variable_get('imagefield_assist_link', 'icon'),
'#options' => array('icon' => t('Show icon'), 'text' => t('Show text link'), 'none' => t('Do not show a link')),
'#description' => t('Choose what to show under the textareas for which Image assist is enabled.'),
);
if (module_exists('taxonomy')) {
$vocs = array(0 => '<'. t('none') .'>');
foreach (taxonomy_get_vocabularies() as $vid => $voc) {
$vocs[$vid] = $voc->name;
}
if (count($vocs) > 1) {
$form['access']['imagefield_assist_vocabs'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => t('Select the vocabularies to use for Image assist'),
'#default_value' => variable_get('imagefield_assist_vocabs', array()),
'#options' => $vocs,
'#description' => t('Select the vocabularies you want to be able to filter thumbnails by. This setting changes the behavior of Image assist at startup from loading all image thumbnails to displaying a list of image names until a filter is chosen.'),
);
}
}
// Presets selection
$form['presets'] = array(
'#type' => 'fieldset',
'#title' => t('Imagecache Presets'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$presets = imagecache_presets();
foreach($presets as $preset){
$form['presets']['imagefield_assist_'.$preset['presetid']] = array(
'#type' => 'checkbox',
'#title' => t($preset['presetname']),
'#default_value' => variable_get('imagefield_assist_'.$preset['presetid'], TRUE),
);
}
// Other properties.
$form['properties'] = array(
'#type' => 'fieldset',
'#title' => t('Image property dialog settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['properties']['imagefield_assist_default_link_behavior'] = array(
'#type' => 'select',
'#title' => t('Default link behavior'),
'#default_value' => variable_get('imagefield_assist_default_link_behavior', 'none'),
'#options' => array('none' => t('Not a link'), 'node' => t('Link to image page'), 'popup' => t('Open in popup window'), 'url' => t('Go to URL')),
'#description' => t('The link behavior can be overridden when inserting images by users with the proper permissions, but these defaults will still be used for everyone else.'),
);
$form['properties']['imagefield_assist_default_link_url'] = array(
'#type' => 'textfield',
'#title' => t('Default URL'),
'#default_value' => variable_get('imagefield_assist_default_link_url', 'http://'),
'#size' => 30,
'#maxlength' => 255,
'#description' => t('The default URL is used when Go to URL is choosen as the link behavior.'),
);
$form['properties']['imagefield_assist_default_insert_mode'] = array(
'#type' => 'select',
'#title' => t('Default insert mode'),
'#default_value' => variable_get('imagefield_assist_default_insert_mode', 'none'),
'#options' => array('filtertag' => t('Filter Tag'), 'html' => t('HTML Code')),
'#description' => t('The insert behavior can be overridden by users with the %permission permission when inserting images. <strong>Warning:</strong> If images are inserted as HTML, Image Assist is not able to correct a link or image URL afterwards. Please also note that users will not be able to edit already inserted images when using HTML code and the TinyMCE plugin.', array('%permission' => t('access advanced options'))),
);
// Image display settings.
$form['display'] = array(
'#type' => 'fieldset',
'#title' => t('Image display settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['display']['imagefield_assist_page_styling'] = array(
'#type' => 'select',
'#title' => t('Include imagefield_assist.css on all pages for styling inline images?'),
'#default_value' => variable_get('imagefield_assist_page_styling', 'yes'),
'#options' => array('yes' => t('yes'), 'no' => t('no')),
'#description' => t('Advanced users can customize their theme\'s CSS file so that inclusion of the imagefield_assist.css file will not be necessary. See notes at the bottom of imagefield_assist.css for details.'),
);
$form['lightbox'] = array(
'#type' => 'fieldset',
'#title' => t('Lightbox2 integration settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$presets = imagefield_assist_get_presets();
if (module_exists('lightbox2')) {
$form['lightbox']['imagefield_assist_lightbox_preset'] = array (
'#type' => 'select',
'#title' => t('ImageCache preset for Lightbox2 "full" view'),
'#options' => $presets,
'#default_value' => variable_get('imagefield_assist_lightbox_preset','fullsize'),
);
}
else {
$form['lightbox'][] = array ('#value' => t('This setting requires Lightbox2 module:') .
'<a href="http://www.drupal.org/lightbox2">
project page</a>');
}
return system_settings_form($form);
}
/**
* Implementation of hook_filter().
*/
function imagefield_assist_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(0 => t('Inline images'));
case 'description':
return t('Add images to your posts with Imagefield assist.');
case 'process':
$processed = FALSE;
foreach (imagefield_assist_get_macros($text) as $unexpanded_macro => $macro) {
$expanded_macro = imagefield_assist_render_image($macro);
$text = str_replace($unexpanded_macro, $expanded_macro, $text);
$processed = TRUE;
}
return $processed ? theme('imagefield_assist_filter', $text) : $text;
default:
return $text;
}
}
/**
* Implementation of hook_filter_tips().
*/
function imagefield_assist_filter_tips($delta, $format, $long = FALSE) {
return t('Images can be added to this post.');
}
/**
* Implementation of hook_nodeapi().
*
* - Clear input filter cache.
* - Keep track of where images are used.
* - Catch nids of recently uploaded images.
*/
function imagefield_assist_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
// @todo cleanup if source nodetype updated
//cache_clear_all(NULL, 'cache_filter');
}
/**
* Menu callback; clears relevant caches, redirecting to previous page
*/
function imagefield_assist_cache_clear() {
$core = array('cache_filter', 'cache_page');
foreach ($core as $table) {
cache_clear_all('*', $table, TRUE);
}
drupal_set_message(t('Cache cleared.'));
drupal_goto('admin/settings/imagefield_assist');
}
/**
* @defgroup imagefield_assist_pages Imagefield Assist Pages
* @{
* All but imagefield_assist_loader() are in frames.
*/
/**
* Output main imagefield_assist interface HTML.
*
* @todo Remove hard-coded TinyMCE integration.
*/
function imagefield_assist_loader() {
$path = drupal_get_path('module', 'imagefield_assist');
$caller = arg(2) ? arg(2) : 'textarea';
drupal_add_js($path .'/imagefield_assist_popup.js');
if (module_exists('wysiwyg') && ($editor = wysiwyg_get_editor($caller))) {
if ($editor['name'] == 'tinymce') {
drupal_add_js($editor['library path'] .'/tiny_mce_popup.js');
}
}
elseif (module_exists('tinymce') && $caller == 'tinymce') {
drupal_add_js(drupal_get_path('module', 'tinymce') .'/tinymce/jscripts/tiny_mce/tiny_mce_popup.js');
}
else {
$caller = 'textarea';
}
drupal_add_js($path .'/imagefield_assist_'. $caller .'.js');
$output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN">'."\n";
$output .= "<html>\n";
$output .= "<head>\n";
$output .= '<title>'. t('Add image') ."</title>\n";
$output .= drupal_get_js();
$output .= "</head>\n\n";
$output .= '<frameset rows="38, *" onload="initLoader()" frameborder="0" border="0" framespacing="0">'."\n";
$output .= '<frame name="imagefield_assist_header" src="" class="imagefield_assist_header" noresize="noresize" />'."\n";
$output .= '<frame name="imagefield_assist_main" src="" class="imagefield_assist_main" noresize="noresize" />'."\n";
$output .= "</frameset>\n";
$output .= "</html>\n";
echo $output;
exit;
}
/**
* Fetch the number of nodes for terms of given vocabulary ids.
*
* Note that this does not count nodes of subterms, as opposed to
* taxonomy_term_count_nodes().
*
* @param $vids
* An array of taxonomy vocabulary ids.
*
* @return
* An array keyed by term ids with the count of nodes for each term.
*/
function _imagefield_assist_term_count_nodes($vids) {
$count = array();
$result = db_query(db_rewrite_sql('SELECT t.tid, COUNT(n.nid) AS count FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid INNER JOIN {term_data} td ON td.tid = t.tid WHERE n.status = 1 AND td.vid IN ('. db_placeholders($vids) .') GROUP BY t.tid'), implode(',', $vids));
while ($term = db_fetch_object($result)) {
$count[$term->tid] = $term->count;
}
return $count;
}
function imagefield_assist_header($mode) {
// Mode may be 'uploading', 'properties' or 'browse'.
$output = drupal_get_form('imagefield_assist_header_form', $mode);
echo theme('imagefield_assist_page', $output, array('id' => 'imagefield_assist_header', 'onload' => 'parent.initHeader();', 'class' => 'imagefield_assist'));
exit;
}
function imagefield_assist_header_form(&$form_state, $mode) {
global $user;
// Upload image.
if ($mode == 'uploading') {
$form[] = array('#value' => '<div id="header-uploading">');
$form[] = array('#value' => '<strong>'. t('Upload: ') .'</strong>'. t('Fill in the form below to upload a new image.'));
$form[] = array('#value' => '</div><div id="header-startover">');
$form['startover'] = array(
'#type' => 'button',
'#value' => t('Start Over'),
'#button_type' => 'button',
'#attributes' => array('onclick' => 'parent.onClickStartOver();'),
);
$form[] = array('#value' => '</div>');
}
elseif ($mode == 'properties') {
$form[] = array('#value' => '<div id="header-properties">');
$form[] = array('#value' => '<strong>'. t('Properties: ') .'</strong>'. t('Change how the image is displayed.'));
$form[] = array('#value' => '</div><div id="header-startover">');
$form['startover'] = array(
'#type' => 'button',
'#value' => t('Start Over'),
'#button_type' => 'button',
'#attributes' => array('onclick' => 'parent.onClickStartOver()'),
);
$form[] = array('#value' => '</div>');
}
// Browse images.
else {
$form[] = array('#value' => '<div id="header-browse">');
// @todo : Filter images?
if (user_access('upload images')) {
$form['upload'] = array(
'#type' => 'button',
'#value' => t('Upload'),
'#suffix' => ' '. t('a new image'),
'#button_type' => 'button',
'#attributes' => array('onclick' => 'parent.onClickUpload()'),
);
}
$form[] = array('#value' => '</div><div id="header-cancel">');
$form['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
'#button_type' => 'button',
'#attributes' => array('onclick' => 'parent.cancelAction()'),
);
$form[] = array('#value' => '</div>');
}
return $form;
}
/**
* Interface for adding images. Uses the regular image node form.
*/
function imagefield_assist_upload() {
global $user;
module_load_include('inc', 'node', 'node.pages');
module_load_include('inc', 'content', 'includes/content.crud');
// Get all type and field info for this database.
$content_info = _content_type_info();
if ( ! in_array('ifa_upload', array_keys($content_info['content types']) )) {
$output = t('You must import the <strong>ifa_upload</strong> content file using CCK Content Copy import form.<br /> You can use the contents of the bundled <strong>ifa_upload_content_type</strong> file.');
}
else {
if (user_access('upload images')) {
drupal_add_js('$(document).ready(parent.initUpload);', 'inline');
// Define an empty node and fetch an image node form
$node = array(
'uid' => $user->uid,
'name' => $user->name,
'type' => 'ifa_upload',
'status' => 0,
'form_display_mode' => 'imagefield_assist'
);
$output .= drupal_get_form('ifa_upload_node_form', $node);
}
else {
$output = t('Your account does not have image uploading privileges.');
}
}
echo theme(
'imagefield_assist_page',
$output,
array('id' => 'imagefield_assist_upload', 'class' => 'imagefield_assist')
);
exit;
}
/**
* Implementation of hook_form_alter().
*
* Reroute submit button callback to our own handler to be able to redirect
* the user after saving the node.
*
* @see imagefield_assist_node_form_submit()
*/
function imagefield_assist_form_alter(&$form, &$form_state, $form_id) {
if ($form_id=='ifa_upload_node_form') {
// Remove unwanted Form Objects
$form['menu']['#access'] =
$form['revision_information']['#access'] =
$form['author']['#access'] =
$form['options']['#access'] =
$form['comment_settings']['#access'] =
$form['buttons']['preview']['#access'] =
$form['title']['#access'] =
$form['path']['#access'] =
FALSE;
// Override submit callback
$form['buttons']['submit']['#submit'] =
array('imagefield_assist_node_form_submit');
}
}
/**
* Submit callback for image_node_form.
*/
function imagefield_assist_node_form_submit($form, &$form_state) {
// Execute regular node submit handler.
$form_state['values']['title']=$form_state['values']['field_ifa_upload'][0]['filename'];
node_form_submit($form, $form_state);
if ($form_state['values']['field_ifa_upload'][0]['fid'] && $form_state['nid'] && isset($form['#node']->form_display_mode)) {
// Send to different url.
$form_state['redirect'] = 'imagefield_assist/properties/'. $form_state['values']['field_ifa_upload'][0]['fid'];
}
}
/**
* Implementation of hook_imagecache_default_presets().
*/
function imagefield_assist_imagecache_default_presets() {
$presets = array();
$presets['ifa_crop_100_75'] = array(
'presetname' => 'ifa_crop_100_75',
'title' => t('Scale and Crop 100x75'),
'actions' => array(
0 => array(
'weight' => '0',
'module' => 'imagecache',
'action' => 'imagecache_scale_and_crop',
'data' => array(
'width' => '100',
'height' => '75',
),
),
),
);
$presets['ifa_200'] = array(
'presetname' => 'ifa_200',
'title' => t('Scale to 200'),
'actions' => array(
0 => array(
'weight' => '0',
'module' => 'imagecache',
'action' => 'imagecache_scale',
'data' => array(
'width' => '200',
'height' => '200',
),
),
),
);
$presets['ifa_thumbnail'] = array(
'presetname' => 'ifa_thumbnail',
'title' => t('Scale to 100'),
'actions' => array(
0 => array(
'weight' => '0',
'module' => 'imagecache',
'action' => 'imagecache_scale',
'data' => array(
'width' => '100',
'height' => '100',
),
),
),
);
return $presets;
}
/**
* Detect ImageField Field instances and load Images
*
* @todo Caching
*
* @param $filters
* Keyed array of filters
* 'fid' - File ID
* 'node_types' - Node Types that can be used
* 'user' - Author of the containing node
* 'op' - AND / OR , defaults to AND
* @return
* Array of Image stdClass objects
*/
function imagefield_assist_load_imagefields( $filters=array() ) {
module_load_include('inc', 'content', 'includes/content.crud');
// Build an array of queries for each field instance
$queries=array();
// Find field instances of ImageField;
// @todo static, caching, performance?
$all_fields = content_fields();
foreach ($all_fields as $name=>$field) {
if (preg_match('_imagefield_', $field['widget']['module'])) {
$dbfield = content_database_info($field);
$queries[]=sprintf(
"SELECT nid,%s FROM {%s} WHERE %s",
$dbfield['columns']['fid']['column'] .' as fid, '. $dbfield['columns']['data']['column'] .' as data',
$dbfield['table'],
$dbfield['columns']['fid']['column'] .' IS NOT NULL'
);
}
}
$all_fields = NULL;
if (!empty($filters)) {
$_filters = array();
if (is_numeric($filters['fid'])) {
$_filters[] = sprintf('images.fid = %d', $filters['fid']);
}
if (is_numeric($filters['nid'])) {
$_filters[] = sprintf('n.nid = %d', $filters['nid']);
}
if (is_array($filters['node_types'])) {
$_filters[] = sprintf('n.type IN (\'%s\')', implode('\',\'', $filters['node_types']));
}
$_operator = ($filters['op']) ? $filters['op'] : ' AND ';
}
$qry_filters='';
if (!empty($_filters)) {
$qry_filters=sprintf("WHERE %s", implode($_operator, $_filters));
}
$images = array();
if (!empty($queries)) {
// The final query joining node and files tables
$query=sprintf(
"SELECT
DISTINCT(images.fid),
f.filepath as path,
n.nid,
images.data
FROM (%s) as images
LEFT JOIN {node} n ON n.nid = images.nid
LEFT JOIN {files} f on f.fid = images.fid
%s
ORDER BY n.changed DESC",
implode(" UNION ", $queries),
$qry_filters
);
if ($filters['count'] && $filters['count'] > 0) {
$result = pager_query($query,$filters['count']);
}
else {
$result = db_query($query);
}
while ($img = db_fetch_object($result)) {
$images[]=$img;
}
}
return $images;
}
/**
* Load the thumbnail display pane.
* TODO: use theme_table
*
*/
function imagefield_assist_thumbs() {
global $user;
$output = '';
$count = variable_get('imagefield_assist_count',4);
$images = imagefield_assist_load_imagefields(array('count' => $count));
if (!empty($images)) {
$output .="<table><tbody><tr>";
foreach ($images as $n => $img) {
$output .=
'<td>'.
l(
theme('imagecache', 'ifa_thumbnail', file_create_path($img->path)),
'imagefield_assist/properties/'. $img->fid,
array('html' => TRUE)
)
.'</td>';
// Line break
if ( ($n+1) % 4 == 0 ) $output .= '</tr><tr>';
}
$output .="</tr></tbody></table>";
}
else {
$output = t('No Images added yet. Click the upload button above to start.');
}
echo theme('imagefield_assist_page', $output, array('id' => 'imagefield_assist_thumbs', 'onload' => 'parent.initThumbs();', 'class' => 'imagefield_assist'));
if ($count > 0) {
echo theme('pager', variable_get('imagefield_assist_count',0));
}
exit;
}
/**
* Load the image properties pane.
*/
function imagefield_assist_properties() {
$fid = arg(2);
// Update is put into a hidden field so the javascript can see it.
$update = (arg(3)) ? 1 : 0;
$img = imagefield_assist_load_imagefields(array('fid' => $fid));
if (!empty($img)) {
$output = drupal_get_form('imagefield_assist_properties_form', $img[0] , $update);
}
else {
$output = t('Image not found');
}
echo theme('imagefield_assist_page', $output, array('id' => 'imagefield_assist_properties', 'onload' => 'parent.initProperties();', 'class' => 'imagefield_assist'));
exit;
}
/**
* Convert a node field value to text for usage in a textfield.
* @todo Check if this is needed
*/
function imagefield_assist_sanitize($text) {
return check_plain(trim(preg_replace("/[\r\n]+/", ' ', strip_tags($text))));
}
/**
* Imagecache presets for displaying image
* @todo add to settings form
* @todo reenable other when figured out how to do it
*/
function imagefield_assist_get_presets() {
$presets['fullsize']=t('None, use original size');
foreach ( imagecache_presets() as $preset) {
if(variable_get('imagefield_assist_'.$preset['presetid'],FALSE))
$presets[$preset['presetname']]= ($preset['title']) ? $preset['title'] : $preset['presetname'];
}
//$presets['other'] = t('Other');
return $presets;
}
/**
* Construct the image properties form.
*/
function imagefield_assist_properties_form($form_state, &$img, $update) {
require_once drupal_get_path('module', 'imagefield_assist') .'/includes/imagefield_assist.token.inc';
$image_info = image_get_info(file_create_path($img->path));
$image_info['aspect_ratio'] = $image_info['height'] / $image_info['width'];
$properties_image = theme('imagecache', 'ifa_thumbnail', file_create_path($img->path));
// Get actual image size.
$properties_size = array('width' => '100', 'height' => '75');//image_get_info($img->path);
// Create an array of image derivative choices
// @todo use imagecache profiles instead
// Add a choice for 'other' if the user has the proper permission to create
// custom sizes.
$derivatives=imagefield_assist_get_presets();
// Use 'preview' size by default.
$default_size = image_get_info(file_create_path($img->path));
$default_width = $default_size['width'];
$default_height = $default_size['height'];
// Calculate the aspect ratio to keep in a hidden field
//
// When 'other' is chosen, the custom size will always follow the aspect ratio.
// It doesn't really matter what this value is here because the actual custom
// image will be created when the filter tag is processed. The size, of course,
// is a bounding box. If it a user stretches an image placeholder out of
// proportion in the WYSIWYG editor, the image will never be out of proportion
// on the processed page.
$aspect_ratio = ($default_height > 0 ? round($default_width / $default_height, 6) : 1);
// Create the form.
$form[] = array('#value' => '<div id="properties">');
$form[] = array('#value' => '<table width="100%" border="0" cellspacing="0" cellpadding="0">');
$form[] = array('#value' => '<tr><td valign="top" rowspan="3" id="preview">');
$form[] = array('#value' => $properties_image);
$form[] = array('#value' => '<span id="caption" style="width: '. $properties_size['width'] .'px;">'. $node->title .'</span>');
// Image node properties fieldset.
$form['properties'] = array('#type' => 'fieldset', '#title' => t('Image properties'));
$form['properties'][] = array('#value' => '<div class="field field-type-text"><div class="field-label">'. t('Size') .': </div><div class="field-items"><div class="field-item">'. strtr('@widthx@height px', array('@width' => $image_info['width'], '@height' => $image_info['height'])) .'</div></div></div>');
$img_data = unserialize($img->data);
if (!empty($img_data)) {
$img_data_labels=array(
'title' => t('Title'),
'description' => t('Description'),
'alt' => t('Alternative text')
);
foreach ($img_data as $key => $data) {
if ($data) {
$form['properties'][] = array(
'#value' =>
'<div class="field field-type-text"><div class="field-label">'.
$img_data_labels[$key] .
': </div><div class="field-items"><div class="field-item">'.
$img_data[$key]
.'</div></div></div>');
}
}
//$form['properties'][] = array('#value' => '<pre>'. print_r($img_data,TRUE) .'</pre>');
}
#$form['properties'][] = array('#value' => '<pre>'. print_r(, TRUE) .'</pre>');
$form[] = array('#value' => '</td><td width="100%" colspan="2">');
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title (optional)'),
'#default_value' => isset($img_data['title']) ? $img_data['title'] : '',
'#size' => 50,
'#maxlength' => 255,
'#description' => NULL,
'#attributes' => array('onblur' => 'parent.updateCaption()'),
);
$form['desc'] = array(
'#type' => 'textfield',
'#title' => t('Description (optional)'),
'#default_value' => isset($img_data['description']) ? $img_data['description'] : '',
'#size' => 50,
'#maxlength' => 255,
'#description' => NULL,
'#attributes' => array('onblur' => 'parent.updateCaption()'),
);
// Size.
$form[] = array('#value' => '</td></tr><tr><td width="90%">');
$form[] = array('#value' => '<div class="form-item" id="edit-size">');
$form[] = array('#value' => '<label for="edit-size-label">'. t('ImageCache Preset') .'</label>');
$form['size_label'] = array(
'#type' => 'select',
'#options' => $derivatives,
'#attributes' => array('onchange' => 'parent.onChangeSizeLabel()'),
);
$form['default_size'] = array('#type' => 'hidden', '#value' => sprintf('%sx%s', $default_width, $default_height));
$form[] = array('#value' => '<div class="form-item" id="size-other">');
$form['width'] = array(
'#type' => 'textfield',
'#default_value' => $default_width,
'#size' => 4,
'#maxlength' => 4,
'#attributes' => array('onblur' => 'parent.onChangeWidth()'),
);
$form[] = array('#value' => ' x ');
$form['height'] = array(
'#type' => 'textfield',
'#default_value' => $default_height,
'#size' => 4,
'#maxlength' => 4,
'#attributes' => array('onblur' => 'parent.onChangeHeight()'),
);
$form[] = array('#value' => '</div></div>');
$form[] = array('#value' => '</td><td>');
// Alignment.
$form['align'] = array(
'#type' => 'select',
'#title' => t('Alignment'),
'#default_value' => variable_get('imagefield_assist_default_alignment', 'left'),
'#options' => array('left' => t('left'), 'right' => t('right'), 'none' => t('none'), 'center' => t('center')),
'#prefix' => '<div id="alignment">',
'#suffix' => '</div>',
);
$form[] = array('#value' => '</td></tr><tr><td colspan="2">');
// Link.
if (user_access('access advanced options')) {
$form[] = array('#value' => '<div class="form-item" id="link-group">');
$form['link'] = array(
'#type' => 'select',
'#title' => t('Link'),
'#default_value' => variable_get('imagefield_assist_default_link_behavior', 'none'),
'#options' => array('none' => t('Not a link'), 'node' => t('Link to image page'), 'popup' => t('Open in popup window'), 'url' => t('Go to URL')),
'#attributes' => array('onchange' => 'parent.onChangeLink()'),
);
$form['url'] = array(
'#type' => 'textfield',
'#default_value' => variable_get('imagefield_assist_default_link_url', 'http://'),
'#size' => 25,
'#maxlength' => 255,
'#description' => NULL,
);
$form['link_options_visible'] = array(
'#type' => 'hidden',
'#value' => 1,
);
$form[] = array('#value' => '</div>');
}
else {
$form['link'] = array(
'#type' => 'hidden',
'#value' => variable_get('imagefield_assist_default_link_behavior', 'none'),
);
$form['url'] = array(
'#type' => 'hidden',
'#value' => variable_get('imagefield_assist_default_link_url', 'http://'),
);
$form['link_options_visible'] = array(
'#type' => 'hidden',
'#value' => 0,
);
}
// Default link url is needed for JS to indicate if an url has been entered.
$form['default_url'] = array(
'#type' => 'hidden',
'#value' => variable_get('imagefield_assist_default_link_url', 'http://'),
);
// Support for Lightbox2
//$lightbox_enable = module_exists('lightbox2') ? TRUE : FALSE ;
$form['lightbox'] = array(
'#type' => 'checkbox',
'#title' => 'Lightbox2',
'#description' => t('Enable Lightbox2 to diplay nice frame when clicking. Requires Lightbox2 module'),
'#disabled' => module_exists('lightbox2') ? FALSE : TRUE,
'#return_value' => 'true',
);
// Insert Mode (HTML or Filter Tag).
if (user_access('access advanced options')) {
$form[] = array('#value' => '<div id="insertmode">');
$form['insertmode'] = array(
'#type' => 'select',
'#title' => t('Insert mode'),
'#default_value' => variable_get('imagefield_assist_default_insert_mode', 'filtertag'),
'#options' => array('filtertag' => t('Filter Tag'), 'html' => t('HTML Code')),
);
$form[] = array('#value' => '</div>');
}
else {
$form['insertmode'] = array(
'#type' => 'hidden',
'#value' => variable_get('imagefield_assist_default_insert_mode', 'filtertag'),
);
}
// Hidden Fields.
$form['fid'] = array(
'#type' => 'hidden',
'#value' => $img->fid,
);
$form['update'] = array(
'#type' => 'hidden',
'#value' => $update,
);
$form['aspect'] = array(
'#type' => 'hidden',
'#value' => $aspect_ratio,
);
// Buttons.
$form['buttons'] = array(
'#prefix' => '<div id="buttons">',
'#suffix' => '</div>',
);
$form['#attributes']['onsubmit'] = 'return parent.insertImage();';
$form['buttons']['insert'] = array(
'#type' => 'submit',
'#value' => ($update) ? t('Update') : t('Insert'),
'#attributes' => array('style' => 'float: left;'),
);
$form['buttons']['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
'#button_type' => 'button',
'#attributes' => array('onclick' => 'return parent.cancelAction();', 'style' => 'float: right;'),
);
$form[] = array('#value' => '</td></tr></table></div>');
$form['#attributes']['name'] = 'imagefield_assist';
return $form;
}
function imagefield_assist_properties_form_validate($form, &$form_state) {
$html = imagefield_assist_render_image($form_state['values']);
imagefield_assist_set_htmlcode($html);
drupal_goto('imagefield_assist/insert_html');
}
/**
* Store image tag or HTML in session.
*
* Used for saving HTML code so it can be inserted instead of the filter tags.
*
* @param string $htmlcode
* A filter tag or HTML code. If omitted, session variable is emptied.
*
* @return string
* A previously stored value in the user session.
*/
function imagefield_assist_set_htmlcode($htmlcode = NULL) {
if (isset($htmlcode)) {
$_SESSION['htmlcode'] = urlencode($htmlcode);
}
else {
$html = urldecode($_SESSION['htmlcode']);
$_SESSION['htmlcode'] = '';
return $html;
}
}
function imagefield_assist_insert_html() {
$output = drupal_get_form('imagefield_assist_insert_html_form');
echo theme('imagefield_assist_page', $output, array('id' => 'imagefield_assist_insert_html', 'onload' => 'parent.insertImage();', 'class' => 'imagefield_assist'));
// @todo fix this!
#drupal_set_message(theme('imagefield_assist_page', $output, array('id' => 'imagefield_assist_insert_html', 'onload' => 'parent.insertImage();', 'class' => 'imagefield_assist')));
#watchdog('debug_ifa', '<textarea>'. theme('imagefield_assist_page', $output, array('id' => 'imagefield_assist_insert_html', 'onload' => 'parent.insertImage();', 'class' => 'imagefield_assist')) .'</textarea>');
}
function imagefield_assist_insert_html_form() {
$htmlcode = imagefield_assist_set_htmlcode();
$form[] = array(
'#id' => 'finalhtmlcode',
'#type' => 'hidden',
'#value' => $htmlcode,
);
$form['insertmode'] = array(
'#type' => 'hidden',
'#value' => 'html2',
);
return $form;
}
/**
* @} End of "defgroup imagefield_assist_pages".
*/
/**
* @defgroup imagefield_assist_image Imagefield Assist Image Generation
* @{
* Functions used in image.module vs. imagefield_assist.module (simplified):
*
* image.module:
* - image_display()
* - is called for galleries, image nodes, image blocks, etc
* (everytime in image is shown)
* - returns <span ...><img ...></span>
* - can be passed a specific standard size only
* - may call _image_build_derivatives()
* - calls theme_image() to create the <img> tag
* _image_build_derivatives()
* - rebuilds all standard image sizes for a particular node
*
* imagefield_assist.module: (more complicated, but more flexible)
* - image_display()
* - is called for thumbnails browsing, inline images, etc (everytime in image is shown)
* - returns <span ...><img ...></span>
* - can be passed EITHER a specific standard size only OR a custom size
* - may call _image_build_derivatives()
* - calls theme_image() to create the <img> tag
* _image_build_derivatives()
* - rebuilds only a specfic image size (standard or custom size)
*/
/**
* Create an IMG tag for an image.
*
* This is nearly identical to image_display, but
* - it uses a more efficient regenerate images routine
* - the size attribute can be a custom size OR a standard size
*/
function imagefield_assist_display(&$node, $size = NULL, $attributes = array()) {
// Custom size should include values for label, width, and height.
if (is_array($size) && !empty($size['key']) && !empty($size['width']) && !empty($size['height'])) {
$label = $size['key'];
}
// Standard size.
elseif ($size) {
// Size can be an array without the width and/or height.
if (is_array($size)) {
// Size is no longer an array.
$size = $size['key'];
}
$label = $size;
}
// Assign preview size if no size specified.
else {
$label = IMAGE_THUMBNAIL;
}
// Regenerate images if necessary.
$regen = FALSE;
if (!isset($node->images[$label])) {
$regen = TRUE;
}
elseif (!is_file(file_create_path($node->images[$label]))) {
$regen = TRUE;
}
elseif (filemtime(file_create_path($node->images[$label])) < variable_get('image_updated', 0)) {
$regen = TRUE;
}
else {
// If $size is not an array, try to find the corresponding predefined size.
// _image_build_derivatives() blindly assigns the *original* image file to
// all derivative image sizes that are smaller than the original image size.
// Without re-assigning the actual derivative size definition, imagefield_assist
// would assume that this derivative size does not exist, delete the
// *original* file and subsequently fail to generate derivative images.
// Also, when one predefined size has changed, the derivative sizes need to
// be updated.
if (!is_array($size)) {
foreach (image_get_sizes() as $std_size) {
if (isset($std_size['key']) && $std_size['key'] == $label) {
$size = $std_size;
break;
}
}
}
if (is_array($size)) {
$info = image_get_info(file_create_path($node->images[$label]));
if (($info['width'] != $size['width']) && ($info['height'] != $size['height'])) {
$regen = TRUE;
}
}
}
if ($regen) {
_imagefield_assist_build_derivatives($node, $size);
}
return image_display($node, $label);
}
/**
* Generate a image derivative
*
* @see _image_build_derivatives() in image.module
* @todo remove
*
* @param $node
* @param $size
* An array containing the keys 'label', 'width', 'height'.
*/
function _imagefield_assist_build_derivatives(&$node, $size = NULL) {
// Verify the image module and toolkit settings.
/*if (!_image_check_settings()) {
return FALSE;
}*/
$info = image_get_info(file_create_path($node->images[IMAGE_ORIGINAL]));
// Custom size.
if (is_array($size) && !empty($size['key']) && !empty($size['width']) && !empty($size['height'])) {
$sizes = array($size['key'] => $size);
}
// Standard size.
elseif ($size) {
// Size can be an array without the width and/or height.
if (is_array($size)) {
$size = $size['key'];
}
$sizes = image_get_sizes();
$sizes = array($size => $sizes[$size]);
}
// No size given: rebuild derivatives for all standard sizes.
else {
$sizes = image_get_sizes();
}
foreach ($sizes as $key => $size) {
$size['key'] = $key;
_imagefield_assist_remove($node, $size);
if (is_array($size) && ($size['label']) && ($size['width']) && ($size['height'])) {
if ($info['width'] > $size['width'] || $info['height'] > $size['height']) {
$source = file_create_path($node->images[IMAGE_ORIGINAL]);
$destination = _image_filename(basename($source), $key, FALSE);
$destination_path = file_create_path($destination);
if (!image_scale($source, $destination_path, $size['width'], $size['height'])) {
drupal_set_message(t('Unable to create %label image', array('%label' => $size['label'])), 'error');
}
else {
// Set default file permissions for webserver-generated files.
@chmod($destination_path, 0664);
$node->images[$key] = $destination;
_image_insert($node, $key, $destination_path);
}
}
else {
$node->images[$key] = $node->images[IMAGE_ORIGINAL];
}
}
}
}
function _imagefield_assist_remove($node, $size) {
$result = db_query("SELECT * FROM {files} f INNER JOIN {image} i ON f.fid = i.fid WHERE i.nid = %d AND f.filename = '%s'", $node->nid, $size['key']);
while ($file = db_fetch_object($result)) {
// Never delete original image.
if ($file->filepath != $node->images[IMAGE_ORIGINAL]) {
// Delete image file.
file_delete(file_create_path($file->filepath));
// Delete file reference in database.
db_query("DELETE FROM {files} WHERE fid = %d AND filename = '%s'", $file->fid, $size['key']);
db_query("DELETE FROM {image} WHERE nid = %d AND fid = '%d'", $node->nid, $file->fid);
}
}
}
/**
* Return image HTML.
* @todo http://drupal.org/node/516982 : Title, Description, Link, Alignement not shown
*/
function imagefield_assist_render_image($attributes = array()) {
global $user;
if ($attributes['fid']) {
$image = current(imagefield_assist_load_imagefields(array('fid' => $attributes['fid'])));
if (!$image) return '';
$caption = '';
if ($attributes['title'] && $attributes['desc']) {
$caption = '<strong>'. $attributes['title'] .': </strong>'. $attributes['desc'];
}
elseif ($attributes['title']) {
$caption = '<strong>'. $attributes['title'] .'</strong>';
}
elseif ($attributes['desc']) {
$caption = $attributes['desc'];
}
// Always define an alignment class, even if it is 'none'.
$output = '<span class="inline inline-'. $attributes['align'] .'">';
// Get preset: comes from 'preset' attribute from filter and 'size_label' from html insert.
if (isset($attributes['preset'])) {
$preset = empty($attributes['preset']) ? 'fullsize' : $attributes['preset'];
}
else {
$preset = isset($attributes['size_label']) ? $attributes['size_label'] : 'fullsize';
}
$img_path = ($preset == 'fullsize')?
$img_path = file_create_url($image->path):
$img_path = imagecache_create_url($preset, $image->path);
if ($preset != 'fullsize' && isset($attributes['size_label'])) {
$width = $height = '';
}
else {
$width = 'width="' . $attributes['width'] . '"';
$height = 'height="' . $attributes['height'] . '"';
}
$img_tag = sprintf(
'<img src="%s" alt="%s" title="%s" %s %s />',
$img_path,
$attributes['alt'],
$attributes['title'],
$width,
$height
);
$link = $attributes['link'];
$url = '';
// Backwards compatibility: Also parse link/url in the format link=url,foo.
if (strpos($link, ',') !== FALSE) {
list($link, $url) = explode(',', $link, 2);
}
elseif (isset($attributes['url'])) {
$url = $attributes['url'];
}
if ($attributes['lightbox']['#checked']){
$preset = variable_get('imagefield_assist_lightbox_preset','fullsize');
if ($preset=='fullsize') {
$link = file_create_url($image->path);
}
else {
$link = imagecache_create_url($preset, $image->path);
}
// Lightbox Output code
$output .= <<<LINK
<a href="$link" class="ifa_lightbox" rel="{$attributes[fid]}" title="{$attributes[title]}">$img_tag</a>
LINK;
}
elseif ($link == 'node') {
$output .= l($img_tag, 'node/'.$image->nid, array('html' => TRUE));
}
elseif ($link == 'popup') {
$width = $attributes['width'] ? $attributes['width'] : 400;
$height = $attributes['height'] ? $attributes['height'] : 300;
$output .= l($img_tag, $img_path, array('attributes' => array('onclick' => 'launch_popup("'.$image->path.'", '. $width.', '.$height.'); return false;', 'target' => '_blank'), 'html' =>TRUE));
}
elseif ($link == 'url') {
$output .= l($img_tag, $url, array('html' => TRUE));
}
else {
$output .= $img_tag;
}
if ($caption) {
if ($attributes['align'] != 'center') {
// Reduce the caption width slightly so the variable width of the text
// doesn't ever exceed image width.
$width = $attributes['width'] - 2;
$output .= '<span class="caption" style="width: '. $width .'px;">'. $caption .'</span>';
}
else {
$output .= '<span class="caption">'. $caption .'</span>';
}
}
$output .= '</span>';
return $output;
}
}
function imagefield_assist_popup() {
$path = $_GET['q'];
$path = substr($path,44);
$path = file_create_url($path);
$content = '<img src="'.$path.'">';
$attributes = array('id' => 'imagefield_assist_popup');
echo theme('imagefield_assist_popup', $content, $attributes);
exit;
}
/**
* @} End of "defgroup imagefield_assist_image".
*/
/**
* @defgroup imagefield_assist_reference Imagefield Assist Image Referencing Routines
* @{
*/
/**
* Update the map table
*
* Look for any images linked in this content and keep a reference of them.
*/
function imagefield_assist_map_save($node) {
$content = $node->body;
// If CCK is used, image macros can be found in fields other than the body.
// Get all the fields that use text filtering and extract their content:
if (function_exists('content_types')) {
$type = content_types($node->type);
if (!empty($type['fields'])) {
foreach ($type['fields'] as $field) {
// Distinguish between plain text fields and filtered fields:
if (!empty($field['text_processing'])) {
if (count($node->{$field['field_name']})) {
foreach ($node->{$field['field_name']} as $field_instance) {
$content .= $field_instance['value'];
}
}
}
}
}
}
// Get all the macros from the content:
$macros = (array)imagefield_assist_get_macros($content);
// Save the image references:
db_query('DELETE FROM {imagefield_assist_map} WHERE nid = %d', $node->nid);
$nids = array();
foreach ($macros as $m) {
if (!isset($nids[$m['nid']]) && is_numeric($m['nid'])) {
db_query('INSERT INTO {imagefield_assist_map} (nid, iid) VALUES(%d, %d)', $node->nid, $m['nid']);
$nids[$m['nid']] = $m['nid'];
}
}
}
/**
* Delete references to a non-existant node.
*
* If a node is being deleted update the map table. The node can either be an
* image node or a node containing one ore more images. Note: nodes that link
* to image nodes that are deleted will still be broken.
*/
function imagefield_assist_map_delete($node) {
db_query('DELETE FROM {imagefield_assist_map} WHERE nid = %d OR iid = %d', $node->nid, $node->nid);
}
/**
* Load the image map for a given nid.
*/
function imagefield_assist_map_load($nid) {
$imagemap = array();
$result = db_query('SELECT * FROM {image} i INNER JOIN {imagefield_assist_map} iam ON i.nid = iam.iid WHERE i.nid = %d', $nid);
while ($data = db_fetch_object($result)) {
$imagemap[] = $data->nid;
}
return $imagemap;
}
/**
* Return a list of node links for a given nid.
*/
function imagefield_assist_get_references($nid, $limit = 10) {
$and_clause = array();
$images = imagefield_assist_map_load($nid);
foreach ($images as $id) {
$and_clause[] = 'n.nid = '. $id;
}
$and_clause = implode(' OR ', $and_clause);
if ($images) {
return node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n WHERE n.status = 1 AND $and_clause ORDER BY n.nid DESC"), 0, (int) $limit));
}
}
/**
* @} End of "defgroup imagefield_assist_reference".
*/
/**
* @defgroup imagefield_assist_macro Imagefield Assist Filter macro parsing
* @{
*/
/**
* Return all imagefield_assist macros as an array.
*/
function imagefield_assist_get_macros($text) {
$m = array();
preg_match_all('/ \[ ( [^\[\]]+ )* \] /x', $text, $matches);
// Don't process duplicates.
$tag_match = (array) array_unique($matches[1]);
foreach ($tag_match as $macro) {
$current_macro = '['. $macro .']';
$param = array_map('trim', explode('|', $macro));
// The first macro param is assumed to be the function name.
$func_name = array_shift($param);
if ($func_name == 'imagefield_assist') {
$vars = array();
foreach ($param as $p) {
$pos = strpos($p, '=');
$varname = trim(substr($p, 0, $pos));
$varvalue = substr($p, $pos + 1);
$vars[$varname] = trim($varvalue);
}
// The full unaltered filter string is the key for the array of filter
// attributes.
$m[$current_macro] = $vars;
}
}
return $m;
}
/**
* Determine if imagefield_assist can render the current page.
* @see block_list().
*
* @return
* TRUE if can render, FALSE if not allowed.
*/
function _imagefield_assist_page_match() {
$must_match = variable_get('imagefield_assist_paths_type', 2);
if ($must_match == 2) {
return TRUE;
}
else {
$paths = variable_get('imagefield_assist_paths', "node/*\ncomment/*");
$path = drupal_get_path_alias($_GET['q']);
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($paths, '/')) .')$/';
$match = preg_match($regexp, $path);
return $match != $must_match;
}
}
/**
* Determine if imagefield_assist can render the current textarea.
* @see block_list().
*
* @return
* TRUE if can render, FALSE if not allowed.
*/
function _imagefield_assist_textarea_match($formid) {
$must_match = variable_get('imagefield_assist_textareas_type', 2);
if ($must_match == 2) {
return TRUE;
}
else {
$formids = variable_get('imagefield_assist_textareas', "edit-body\nedit-comment");
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/'), array('|', '.*'), preg_quote($formids, '/')) .')$/';
// Compare with the form id.
$page_match = preg_match($regexp, $formid);
// When $must_match has a value of 0, imagefield_assist is displayed on
// all pages except those listed in imagefield_assist_textareas. When set to 1, it
// is displayed only on those textareas listed in imagefield_assist_textareas.
$page_match = !($must_match xor $page_match);
return $page_match;
}
}
/**
* @} End of "defgroup imagefield_assist_macro".
*/
/**
* @defgroup imagefield_assist_theme Imagefield Assist Theme functions
* @{
*
* @ingroup themeable
*/
function theme_imagefield_assist_inline($node, $size, $attributes) {
$caption = '';
if ($attributes['title'] && $attributes['desc']) {
$caption = '<strong>'. $attributes['title'] .': </strong>'. $attributes['desc'];
}
elseif ($attributes['title']) {
$caption = '<strong>'. $attributes['title'] .'</strong>';
}
elseif ($attributes['desc']) {
$caption = $attributes['desc'];
}
// Change the node title because imagefield_assist_display() uses the node title for
// alt and title.
$node->title = strip_tags($caption);
$img_tag = imagefield_assist_display($node, $size);
// Always define an alignment class, even if it is 'none'.
$output = '<span class="inline inline-'. $attributes['align'] .'">';
$link = $attributes['link'];
$url = '';
// Backwards compatibility: Also parse link/url in the format link=url,foo.
if (strpos($link, ',') !== FALSE) {
list($link, $url) = explode(',', $link, 2);
}
elseif (isset($attributes['url'])) {
$url = $attributes['url'];
}
if ($link == 'node') {
$output .= l($img_tag, 'node/'. $node->nid, array('html' => TRUE));
}
elseif ($link == 'popup') {
$popup_size = variable_get('imagefield_assist_popup_label', IMAGE_PREVIEW);
$info = image_get_info(file_create_path($node->images[$popup_size]));
$width = $info['width'];
$height = $info['height'];
$popup_url = file_create_url($node->images[variable_get('imagefield_assist_popup_label', IMAGE_PREVIEW)]);
$output .= l(
$img_tag,
$popup_url,
array(
'attributes' =>
array('onclick' => "launch_popup({$node->nid}, {$width}, {$height}); return false;",
'target' => '_blank'),
'html' => TRUE)
);
}
elseif ($link == 'url') {
$output .= l($img_tag, $url, array('html' => TRUE));
}
else {
$output .= $img_tag;
}
if ($caption) {
if ($attributes['align'] != 'center') {
$info = image_get_info(file_create_path($node->images[$size['key']]));
// Reduce the caption width slightly so the variable width of the text
// doesn't ever exceed image width.
$width = $info['width'] - 2;
$output .= '<span class="caption" style="width: '. $width .'px;">'. $caption .'</span>';
}
else {
$output .= '<span class="caption">'. $caption .'</span>';
}
}
$output .= '</span>';
return $output;
}
function theme_imagefield_assist_filter($text) {
// The div tag added to the end of each node is necessary to clear the
// floating properties of inline images immediately after a node's content.
return $text .'<div class="image-clear"></div>';
}
function theme_imagefield_assist_popup($content, $attributes = NULL) {
$title = drupal_get_title();
$output = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
$output .= "<html>\n";
$output .= "<head>\n";
$output .= '<title>'. $title ."</title>\n";
$output .= drupal_get_html_head();
$output .= drupal_get_css();
$output .= "</head>\n";
$output .= '<body'. drupal_attributes($attributes) .">\n";
$output .= "<!-- begin content -->\n";
$output .= l($content, '', array('attributes' => array('onclick' => 'javascript:window.close();'), 'html' => TRUE));
$output .= "<!-- end content -->\n";
$output .= '</body>';
$output .= '</html>';
return $output;
}
function theme_imagefield_assist_page($content, $attributes = NULL) {
$title = drupal_get_title();
$output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
$output .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'."\n";
$output .= "<head>\n";
$output .= '<title>'. $title ."</title>\n";
// Note on CSS files from Benjamin Shell:
// Stylesheets are a problem with image assist. Image assist works great as a
// TinyMCE plugin, so I want it to LOOK like a TinyMCE plugin. However, it's
// not always a TinyMCE plugin, so then it should like a themed Drupal page.
// Advanced users will be able to customize everything, even TinyMCE, so I'm
// more concerned about everyone else. TinyMCE looks great out-of-the-box so I
// want image assist to look great as well. My solution to this problem is as
// follows:
// If this image assist window was loaded from TinyMCE, then include the
// TinyMCE popups_css file (configurable with the initialization string on the
// page that loaded TinyMCE). Otherwise, load drupal.css and the theme's
// styles. This still leaves out sites that allow users to use the TinyMCE
// plugin AND the Add Image link (visibility of this link is now a setting).
// However, on my site I turned off the text link since I use TinyMCE. I think
// it would confuse users to have an Add Images link AND a button on the
// TinyMCE toolbar.
//
// Note that in both cases the imagefield_assist.css file is loaded last. This
// provides a way to make style changes to imagefield_assist independently of how it
// was loaded.
$output .= drupal_get_html_head();
$output .= drupal_get_js();
$output .= "\n<script type=\"text/javascript\"><!-- \n";
$output .= " if (parent.tinyMCE && parent.tinyMCEPopup && parent.tinyMCEPopup.getParam('popups_css')) {\n";
$output .= " document.write('<link href=\"' + parent.tinyMCEPopup.getParam('popups_css') + '\" rel=\"stylesheet\" type=\"text/css\">');\n";
$output .= " } else {\n";
foreach (drupal_add_css() as $media => $type) {
$paths = array_merge($type['module'], $type['theme']);
foreach (array_keys($paths) as $path) {
// Don't import imagefield_assist.css twice.
if (!strstr($path, 'imagefield_assist.css')) {
$output .= " document.write('<style type=\"text/css\" media=\"{$media}\">@import \"". base_path() . $path ."\";<\/style>');\n";
}
}
}
$output .= " }\n";
$output .= "--></script>\n";
// Ensure that imagefield_assist.js is imported last.
$path = drupal_get_path('module', 'imagefield_assist') .'/imagefield_assist_popup.css';
$output .= "<style type=\"text/css\" media=\"all\">@import \"". base_path() . $path ."\";</style>\n";
$output .= "</head>\n";
$output .= '<body'. drupal_attributes($attributes) .">\n";
$output .= theme_status_messages();
$output .= "<!-- begin content -->\n";
$output .= $content;
$output .= "<!-- end content -->\n";
$output .= '</body>';
$output .= '</html>';
return $output;
}
/**
* @} End of "defgroup imagefield_assist_theme".
*/
/**
* Implementation of hook_wysiwyg_plugin().
*/
function imagefield_assist_wysiwyg_plugin($editor, $version) {
switch ($editor) {
case 'tinymce':
if ($version > 3) {
return array(
'imagefield_assist' => array(
'path' => drupal_get_path('module', 'imagefield_assist') .'/drupalimage/editor_plugin.js',
'buttons' => array('imagefield_assist' => t('ImageField Assist')),
'url' => 'http://drupal.org/project/imagefield_assist',
'extended_valid_elements' => array('img[class|src|border=0|alt|title|width|height|align|name|style]'),
'load' => TRUE,
),
);
}
break;
}
}
/**
* @defgroup imagefield_assist_legacy Imagefield Assist Legacy functions
* @{
* Used for backwards compatibility with original imagefield_assist module.
*/
/**
* Load all images into a static array.
*/
function imagefield_assist_load_images($tid = NULL, $uid = NULL) {
static $image;
if ($tid) {
foreach ($tid as $key => $term) {
if ($term == 0) {
unset($tid[$key]);
}
}
$image = NULL;
}
$where = '';
if ($uid > 0) {
$image = NULL;
$where = 'AND n.uid = '. db_escape_string($uid);
}
if (!$image) {
$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, i.*, f.* FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid INNER JOIN {image} i ON n.nid = i.nid AND n.type = 'image' INNER JOIN {files} f ON f.fid = i.fid ". $where ." ORDER BY n.changed DESC"));
while ($node = db_fetch_object($result)) {
$node->filepath = file_create_path($node->filepath);
$dim = getimagesize($node->filepath, $info);
$node->width = $dim[0];
$node->height = $dim[1];
$image[$node->nid][$node->filename] = $node;
if ($tid) {
$tid2 = array();
foreach (taxonomy_node_get_terms($node) as $term) {
$tid2[] = $term->tid;
}
if (array_intersect($tid, $tid2) == $tid) {
$img[$node->nid][$node->filename] = $node;
}
}
}
$image = ($tid) ? $img : $image;
// Note: If we didn't use "LIKE 'image/%%'" here we could load other files.
// Might be interesting to expand on this someday.
if ($image) {
$result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, i.*, f.* FROM {image} i, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid INNER JOIN {files} f ON f.fid = i.fid WHERE i.nid = n.nid AND f.filemime LIKE 'image/%%' AND n.nid NOT IN (". implode(array_keys($image), ', ') .") ". $where ." ORDER BY n.changed DESC"));
while ($node = db_fetch_object($result)) {
$node->filepath = file_create_path($node->filepath);
$dim = getimagesize($node->filepath, $info);
$node->width = $dim[0];
$node->height = $dim[1];
$image[$node->nid][IMAGE_THUMBNAIL] = $node;
$image[$node->nid][IMAGE_ORIGINAL] = $node;
if ($tid) {
$tid2 = array();
foreach (taxonomy_node_get_terms($node) as $term) {
$tid2[] = $term->tid;
}
if (array_intersect($tid, $tid2) == $tid) {
$img[$node->nid][IMAGE_THUMBNAIL] = $node;
$img[$node->nid][IMAGE_ORIGINAL] = $node;
}
}
}
$image = ($tid) ? $img : $image;
}
}
return $image;
}
/**
* Load an image from the database.
*/
function imagefield_assist_load_image($id, $derivatives = TRUE) {
kpr(debug_backtrace());
$node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title, i.*, f.* FROM {image} i, {node} n INNER JOIN {files} f ON f.fid = i.fid WHERE f.nid = n.nid AND f.fid = %d'), $id));
$node->filepath = file_create_path($node->filepath);
if (!$derivatives) {
$dim = getimagesize($node->filepath, $info);
$node->width = $dim[0];
$node->height = $dim[1];
$image[$node->filename] = $node;
}
else {
$image_module_image = FALSE;
if (function_exists('image_get_sizes')) {
foreach (image_get_sizes() as $size) {
if ($size['label'] == $node->filename) {
$image_module_image = TRUE;
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, r.teaser, i.*, f.* FROM {image} i, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid INNER JOIN {files} f ON f.fid = i.fid WHERE i.nid = n.nid AND n.nid = %d'), $node->nid);
while ($node = db_fetch_object($result)) {
$node->filepath = file_create_path($node->filepath);
$dim = getimagesize($node->filepath, $info);
$node->width = $dim[0];
$node->height = $dim[1];
$image[$node->filename] = $node;
}
break;
}
}
}
if (!$image_module_image) {
$dim = getimagesize($node->filepath, $info);
$node->width = $dim[0];
$node->height = $dim[1];
$image[IMAGE_THUMBNAIL] = $node;
$image[IMAGE_ORIGINAL] = $node;
}
}
return $image;
}
/**
* Attach the thumbnail metadata to the image object.
*
* Unfortunately we have to query the database since the thumbnail can be named
* something entirely different from the original image.
*/
function _imagefield_assist_get_thumbnail(&$image) {
static $thumbs = array();
if ($thumbs[$image->nid] === NULL) {
$thumbpath = file_create_path(db_result(db_query("SELECT f.filepath FROM {image} i INNER JOIN {files} f ON f.fid = i.fid WHERE i.nid = %d AND f.filename = '%s'", $image->nid, IMAGE_THUMBNAIL)));
// In old versions of image.module thumbs were named 'thumb_filename.ext'.
if (!file_exists($thumbpath)) {
$pos = strrpos($image->filepath, '/') + 1;
$thumbpath = file_create_path(substr($image->filepath, 0, $pos) .'thumb_'. substr($image->filepath, $pos));
}
$img->thumbpath = is_file($thumbpath) && preg_match('|^'. variable_get('file_directory_path', 'files') .'\/'. variable_get('image_default_path', 'images') .'\/|', $image->filepath) ? $thumbpath : $image->filepath;
$dim = getimagesize($img->thumbpath, $info);
$img->thumbwidth = $dim[0];
$img->thumbheight = $dim[1];
$thumbs[$image->nid] = $img;
}
if ($thumbs[$image->nid]) {
foreach ($thumbs[$image->nid] as $key => $value) {
$image->$key = $value;
}
}
}
function theme_imagefield_assist_legacy() {
return '<div class="%image-class"><a href="%node-link"><img src="%src" width="%width" height="%height" alt="%alt" /></a><div class="caption">%caption</div></div>';
}
/**
* @} End of "defgroup imagefield_assist_legacy".
*/
|