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
|
<?php
# -- BEGIN LICENSE BLOCK ---------------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK -----------------------------------------
if (!defined('DC_ADMIN_CONTEXT')) { return; }
/**
* @ingroup DC_CORE
* @brief Helper for admin list of modules.
* @since 2.6
* Provides an object to parse XML feed of modules from a repository.
*/
class adminModulesList
{
public $core; /**< @var object dcCore instance */
public $modules; /**< @var object dcModules instance */
public $store; /**< @var object dcStore instance */
public static $allow_multi_install = false; /**< @var boolean Work with multiple root directories */
public static $distributed_modules = array(); /**< @var array List of modules distributed with Dotclear */
protected $list_id = 'unknow'; /**< @var string Current list ID */
protected $data = array(); /**< @var array Current modules */
protected $config_module = ''; /**< @var string Module ID to configure */
protected $config_file = ''; /**< @var string Module path to configure */
protected $config_content = ''; /**< @var string Module configuration page content */
protected $path = false; /**< @var string Modules root directory */
protected $path_writable = false; /**< @var boolean Indicate if modules root directory is writable */
protected $path_pattern = false; /**< @var string Directory pattern to work on */
protected $page_url = 'plugins.php'; /**< @var string Page URL */
protected $page_qs = '?'; /**< @var string Page query string */
protected $page_tab = ''; /**< @var string Page tab */
protected $page_redir = ''; /**< @var string Page redirection */
public static $nav_indexes = 'abcdefghijklmnopqrstuvwxyz0123456789'; /**< @var string Index list */
protected $nav_list = array(); /**< @var array Index list with special index */
protected $nav_special = 'other'; /**< @var string Text for other special index */
protected $sort_field = 'sname'; /**< @var string Field used to sort modules */
protected $sort_asc = true; /**< @var boolean Sort order asc */
/**
* Constructor.
*
* Note that this creates dcStore instance.
*
* @param object $modules dcModules instance
* @param string $modules_root Modules root directories
* @param string $xml_url URL of modules feed from repository
*/
public function __construct(dcModules $modules, $modules_root, $xml_url)
{
$this->core = $modules->core;
$this->modules = $modules;
$this->store = new dcStore($modules, $xml_url);
$this->setPath($modules_root);
$this->setIndex(__('other'));
}
/**
* Begin a new list.
*
* @param string $id New list ID
* @return adminModulesList self instance
*/
public function setList($id)
{
$this->data = array();
$this->page_tab = '';
$this->list_id = $id;
return $this;
}
/**
* Get list ID.
*
* @return List ID
*/
public function getList()
{
return $this->list_id;
}
/// @name Modules root directory methods
//@{
/**
* Set path info.
*
* @param string $root Modules root directories
* @return adminModulesList self instance
*/
protected function setPath($root)
{
$paths = explode(PATH_SEPARATOR, $root);
$path = array_pop($paths);
unset($paths);
$this->path = $path;
if (is_dir($path) && is_writeable($path)) {
$this->path_writable = true;
$this->path_pattern = preg_quote($path,'!');
}
return $this;
}
/**
* Get modules root directory.
*
* @return Path to work on
*/
public function getPath()
{
return $this->path;
}
/**
* Check if modules root directory is writable.
*
* @return True if directory is writable
*/
public function isWritablePath()
{
return $this->path_writable;
}
/**
* Check if root directory of a module is deletable.
*
* @param string $root Module root directory
* @return True if directory is delatable
*/
public function isDeletablePath($root)
{
return $this->path_writable
&& (preg_match('!^'.$this->path_pattern.'!', $root) || defined('DC_DEV') && DC_DEV)
&& $this->core->auth->isSuperAdmin();
}
//@}
/// @name Page methods
//@{
/**
* Set page base URL.
*
* @param string $url Page base URL
* @return adminModulesList self instance
*/
public function setURL($url)
{
$this->page_qs = strpos('?', $url) ? '&' : '?';
$this->page_url = $url;
return $this;
}
/**
* Get page URL.
*
* @param string|array $queries Additionnal query string
* @param booleany $with_tab Add current tab to URL end
* @return Clean page URL
*/
public function getURL($queries='', $with_tab=true)
{
return $this->page_url.
(!empty($queries) ? $this->page_qs : '').
(is_array($queries) ? http_build_query($queries) : $queries).
($with_tab && !empty($this->page_tab) ? '#'.$this->page_tab : '');
}
/**
* Set page tab.
*
* @param string $tab Page tab
* @return adminModulesList self instance
*/
public function setTab($tab)
{
$this->page_tab = $tab;
return $this;
}
/**
* Get page tab.
*
* @return Page tab
*/
public function getTab()
{
return $this->page_tab;
}
/**
* Set page redirection.
*
* @param string $default Default redirection
* @return adminModulesList self instance
*/
public function setRedir($default='')
{
$this->page_redir = empty($_REQUEST['redir']) ? $default : $_REQUEST['redir'];
return $this;
}
/**
* Get page redirection.
*
* @return Page redirection
*/
public function getRedir()
{
return empty($this->page_redir) ? $this->getURL() : $this->page_redir;
}
//@}
/// @name Search methods
//@{
/**
* Get search query.
*
* @return Search query
*/
public function getSearch()
{
$query = !empty($_REQUEST['m_search']) ? trim($_REQUEST['m_search']) : null;
return strlen($query) > 2 ? $query : null;
}
/**
* Display searh form.
*
* @return adminModulesList self instance
*/
public function displaySearch()
{
$query = $this->getSearch();
if (empty($this->data) && $query === null) {
return $this;
}
echo
'<div class="modules-search">'.
'<form action="'.$this->getURL().'" method="get">'.
'<p><label for="m_search" class="classic">'.__('Search in repository:').' </label><br />'.
form::field(array('m_search','m_search'), 30, 255, html::escapeHTML($query)).
'<input type="submit" value="'.__('OK').'" /> ';
if ($query) {
echo
' <a href="'.$this->getURL().'" class="button">'.__('Reset search').'</a>';
}
echo
'</p>'.
'<p class="form-note">'.
__('Search is allowed on multiple terms longer than 2 chars, terms must be separated by space.').
'</p>'.
'</form>';
if ($query) {
echo
'<p class="message">'.sprintf(
__('Found %d result for search "%s":', 'Found %d results for search "%s":', count($this->data)),
count($this->data), html::escapeHTML($query)
).
'</p>';
}
echo '</div>';
return $this;
}
//@}
/// @name Navigation menu methods
//@{
/**
* Set navigation special index.
*
* @return adminModulesList self instance
*/
public function setIndex($str)
{
$this->nav_special = (string) $str;
$this->nav_list = array_merge(str_split(self::$nav_indexes), array($this->nav_special));
return $this;
}
/**
* Get index from query.
*
* @return Query index or default one
*/
public function getIndex()
{
return isset($_REQUEST['m_nav']) && in_array($_REQUEST['m_nav'], $this->nav_list) ? $_REQUEST['m_nav'] : $this->nav_list[0];
}
/**
* Display navigation by index menu.
*
* @return adminModulesList self instance
*/
public function displayIndex()
{
if (empty($this->data) || $this->getSearch() !== null) {
return $this;
}
# Fetch modules required field
$indexes = array();
foreach ($this->data as $id => $module) {
if (!isset($module[$this->sort_field])) {
continue;
}
$char = substr($module[$this->sort_field], 0, 1);
if (!in_array($char, $this->nav_list)) {
$char = $this->nav_special;
}
if (!isset($indexes[$char])) {
$indexes[$char] = 0;
}
$indexes[$char]++;
}
$buttons = array();
foreach($this->nav_list as $char) {
# Selected letter
if ($this->getIndex() == $char) {
$buttons[] = '<li class="active" title="'.__('current selection').'"><strong> '.$char.' </strong></li>';
}
# Letter having modules
elseif (!empty($indexes[$char])) {
$title = sprintf(__('%d result', '%d results', $indexes[$char]), $indexes[$char]);
$buttons[] = '<li class="btn" title="'.$title.'"><a href="'.$this->getURL('m_nav='.$char).'" title="'.$title.'"> '.$char.' </a></li>';
}
# Letter without modules
else {
$buttons[] = '<li class="btn no-link" title="'.__('no results').'"> '.$char.' </li>';
}
}
# Parse navigation menu
echo '<div class="pager">'.__('Browse index:').' <ul class="index">'.implode('',$buttons).'</ul></div>';
return $this;
}
//@}
/// @name Sort methods
//@{
/**
* Set default sort field.
*
* @return adminModulesList self instance
*/
public function setSort($field, $asc=true)
{
$this->sort_field = $field;
$this->sort_asc = (boolean) $asc;
return $this;
}
/**
* Get sort field from query.
*
* @return Query sort field or default one
*/
public function getSort()
{
return !empty($_REQUEST['m_sort']) ? $_REQUEST['m_sort'] : $this->sort_field;
}
/**
* Display sort field form.
*
* @note This method is not implemented yet
* @return adminModulesList self instance
*/
public function displaySort()
{
//
return $this;
}
//@}
/// @name Modules methods
//@{
/**
* Set modules and sanitize them.
*
* @return adminModulesList self instance
*/
public function setModules($modules)
{
$this->data = array();
if (!empty($modules) && is_array($modules)) {
foreach($modules as $id => $module) {
$this->data[$id] = self::sanitizeModule($id, $module);
}
}
return $this;
}
/**
* Get modules currently set.
*
* @return Array of modules
*/
public function getModules()
{
return $this->data;
}
/**
* Sanitize a module.
*
* This clean infos of a module by adding default keys
* and clean some of them, sanitize module can safely
* be used in lists.
*
* @return Array of the module informations
*/
public static function sanitizeModule($id, $module)
{
$label = empty($module['label']) ? $id : $module['label'];
$name = __(empty($module['name']) ? $label : $module['name']);
return array_merge(
# Default values
array(
'desc' => '',
'author' => '',
'version' => 0,
'current_version' => 0,
'root' => '',
'root_writable' => false,
'permissions' => null,
'parent' => null,
'priority' => 1000,
'standalone_config' => false,
'support' => '',
'section' => '',
'tags' => '',
'details' => '',
'sshot' => '',
'score' => 0,
'type' => null
),
# Module's values
$module,
# Clean up values
array(
'id' => $id,
'sid' => self::sanitizeString($id),
'label' => $label,
'name' => $name,
'sname' => self::sanitizeString($name)
)
);
}
/**
* Check if a module is part of the distribution.
*
* @param string $id Module root directory
* @return True if module is part of the distribution
*/
public static function isDistributedModule($id)
{
$distributed_modules = self::$distributed_modules;
return is_array($distributed_modules) && in_array($id, $distributed_modules);
}
/**
* Sort modules list by specific field.
*
* @param string $module Array of modules
* @param string $field Field to sort from
* @param bollean $asc Sort asc if true, else decs
* @return Array of sorted modules
*/
public static function sortModules($modules, $field, $asc=true)
{
$origin = $sorter = array();
foreach($modules as $id => $module) {
$origin[] = $module;
$sorter[] = isset($module[$field]) ? $module[$field] : $field;
}
array_multisort($sorter, $asc ? SORT_ASC : SORT_DESC, $origin);
foreach($origin as $module) {
$final[$module['id']] = $module;
}
return $final;
}
/**
* Display list of modules.
*
* @param array $cols List of colones (module field) to display
* @param array $actions List of predefined actions to show on form
* @param boolean $nav_limit Limit list to previously selected index
* @return adminModulesList self instance
*/
public function displayModules($cols=array('name', 'version', 'desc'), $actions=array(), $nav_limit=false)
{
echo
'<form action="'.$this->getURL().'" method="post" class="modules-form-actions">'.
'<div class="table-outer">'.
'<table id="'.html::escapeHTML($this->list_id).'" class="modules'.(in_array('expander', $cols) ? ' expandable' : '').'">'.
'<caption class="hidden">'.html::escapeHTML(__('Plugins list')).'</caption><tr>';
if (in_array('name', $cols)) {
$colspan = 1;
if (in_array('checkbox', $cols)) {
$colspan++;
}
if (in_array('icon', $cols)) {
$colspan++;
}
echo
'<th class="first nowrap"'.($colspan > 1 ? ' colspan="'.$colspan.'"' : '').'>'.__('Name').'</th>';
}
if (in_array('score', $cols) && $this->getSearch() !== null && defined('DC_DEBUG') && DC_DEBUG) {
echo
'<th class="nowrap">'.__('Score').'</th>';
}
if (in_array('version', $cols)) {
echo
'<th class="nowrap count" scope="col">'.__('Version').'</th>';
}
if (in_array('current_version', $cols)) {
echo
'<th class="nowrap count" scope="col">'.__('Current version').'</th>';
}
if (in_array('desc', $cols)) {
echo
'<th class="nowrap" scope="col">'.__('Details').'</th>';
}
if (in_array('distrib', $cols)) {
echo
'<th'.(in_array('desc', $cols) ? '' : ' class="maximal"').'></th>';
}
if (!empty($actions) && $this->core->auth->isSuperAdmin()) {
echo
'<th class="minimal nowrap">'.__('Action').'</th>';
}
echo
'</tr>';
$sort_field = $this->getSort();
# Sort modules by $sort_field (default sname)
$modules = $this->getSearch() === null ?
self::sortModules($this->data, $sort_field, $this->sort_asc) :
$this->data;
$count = 0;
foreach ($modules as $id => $module)
{
# Show only requested modules
if ($nav_limit && $this->getSearch() === null) {
$char = substr($module[$sort_field], 0, 1);
if (!in_array($char, $this->nav_list)) {
$char = $this->nav_special;
}
if ($this->getIndex() != $char) {
continue;
}
}
echo
'<tr class="line" id="'.html::escapeHTML($this->list_id).'_m_'.html::escapeHTML($id).'">';
$tds = 0;
if (in_array('checkbox', $cols)) {
$tds++;
echo
'<td class="module-icon nowrap">'.
form::checkbox(array('modules['.$count.']', html::escapeHTML($this->list_id).'_modules_'.html::escapeHTML($id)), html::escapeHTML($id)).
'</td>';
}
if (in_array('icon', $cols)) {
$tds++;
echo
'<td class="module-icon nowrap">'.sprintf(
'<img alt="%1$s" title="%1$s" src="%2$s" />',
html::escapeHTML($id), file_exists($module['root'].'/icon.png') ? 'index.php?pf='.$id.'/icon.png' : 'images/module.png'
).'</td>';
}
$tds++;
echo
'<td class="module-name nowrap" scope="row">';
if (in_array('checkbox', $cols)) {
if (in_array('expander', $cols)) {
echo
html::escapeHTML($module['name']);
}
else {
echo
'<label for="'.html::escapeHTML($this->list_id).'_modules_'.html::escapeHTML($id).'">'.
html::escapeHTML($module['name']).
'</label>';
}
}
else {
echo
html::escapeHTML($module['name']).
form::hidden(array('modules['.$count.']'), html::escapeHTML($id));
}
echo
$this->core->formNonce().
'</td>';
# Display score only for debug purpose
if (in_array('score', $cols) && $this->getSearch() !== null && defined('DC_DEBUG') && DC_DEBUG) {
$tds++;
echo
'<td class="module-version nowrap count"><span class="debug">'.$module['score'].'</span></td>';
}
if (in_array('version', $cols)) {
$tds++;
echo
'<td class="module-version nowrap count">'.html::escapeHTML($module['version']).'</td>';
}
if (in_array('current_version', $cols)) {
$tds++;
echo
'<td class="module-current-version nowrap count">'.html::escapeHTML($module['current_version']).'</td>';
}
if (in_array('desc', $cols)) {
$tds++;
echo
'<td class="module-desc maximal">'.html::escapeHTML(__($module['desc'])).'</td>';
}
if (in_array('distrib', $cols)) {
$tds++;
echo
'<td class="module-distrib">'.(self::isDistributedModule($id) ?
'<img src="images/dotclear_pw.png" alt="'.
__('Plugin from official distribution').'" title="'.
__('Plugin from official distribution').'" />'
: '').'</td>';
}
if (!empty($actions) && $this->core->auth->isSuperAdmin()) {
$buttons = $this->getActions($id, $module, $actions);
$tds++;
echo
'<td class="module-actions nowrap">'.
'<div>'.implode(' ', $buttons).'</div>'.
'</td>';
}
echo
'</tr>';
# Other informations
if (in_array('expander', $cols)) {
echo
'<tr class="module-more"><td colspan="'.$tds.'" class="expand">';
if (!empty($module['author']) || !empty($module['details']) || !empty($module['support'])) {
echo
'<div><ul class="mod-more">';
if (!empty($module['author'])) {
echo
'<li class="module-author">'.__('Author:').' '.html::escapeHTML($module['author']).'</li>';
}
$more = array();
if (!empty($module['details'])) {
$more[] = '<a class="module-details" href="'.$module['details'].'">'.__('Details').'</a>';
}
if (!empty($module['support'])) {
$more[] = '<a class="module-support" href="'.$module['support'].'">'.__('Support').'</a>';
}
if (!empty($more)) {
echo
'<li>'.implode(' - ', $more).'</li>';
}
echo
'</ul></div>';
}
$config = !empty($module['root']) && file_exists(path::real($module['root'].'/_config.php'));
if ($config || !empty($module['section']) || !empty($module['section'])) {
echo
'<div><ul class="mod-more">';
if ($config) {
echo
'<li><a class="module-config" href="'.$this->getURL('module='.$id.'&conf=1').'">'.__('Configure plugin').'</a></li>';
}
if (!empty($module['section'])) {
echo
'<li class="module-section">'.__('Section:').' '.html::escapeHTML($module['section']).'</li>';
}
if (!empty($module['section'])) {
echo
'<li class="module-tags">'.__('Tags:').' '.html::escapeHTML($module['tags']).'</li>';
}
echo
'</ul></div>';
}
echo
'</td></tr>';
}
$count++;
}
echo
'</table></div>';
if(!$count && $this->getSearch() === null) {
echo
'<p class="message">'.__('No plugins matched your search.').'</p>';
}
elseif ((in_array('checkbox', $cols) || $count > 1) && !empty($actions) && $this->core->auth->isSuperAdmin()) {
$buttons = $this->getGlobalActions($actions, in_array('checkbox', $cols));
if (!empty($buttons)) {
if (in_array('checkbox', $cols)) {
echo
'<p class="checkboxes-helpers"></p>';
}
echo
'<div>'.implode(' ', $buttons).'</div>';
}
}
echo
'</form>';
return $this;
}
/**
* Get action buttons to add to modules list.
*
* @param string $id Module ID
* @param array $module Module info
* @param array $actions Actions keys
* @return Array of actions buttons
*/
protected function getActions($id, $module, $actions)
{
$submits = array();
# Use loop to keep requested order
foreach($actions as $action) {
switch($action) {
# Deactivate
case 'activate': if ($this->core->auth->isSuperAdmin() && $module['root_writable']) {
$submits[] =
'<input type="submit" name="activate['.html::escapeHTML($id).']" value="'.__('Activate').'" />';
} break;
# Activate
case 'deactivate': if ($this->core->auth->isSuperAdmin() && $module['root_writable']) {
$submits[] =
'<input type="submit" name="deactivate['.html::escapeHTML($id).']" value="'.__('Deactivate').'" class="reset" />';
} break;
# Delete
case 'delete': if ($this->core->auth->isSuperAdmin() && $this->isDeletablePath($module['root'])) {
$dev = !preg_match('!^'.$this->path_pattern.'!', $module['root']) && defined('DC_DEV') && DC_DEV ? ' debug' : '';
$submits[] =
'<input type="submit" class="delete '.$dev.'" name="delete['.html::escapeHTML($id).']" value="'.__('Delete').'" />';
} break;
# Install (from store)
case 'install': if ($this->core->auth->isSuperAdmin() && $this->path_writable) {
$submits[] =
'<input type="submit" name="install['.html::escapeHTML($id).']" value="'.__('Install').'" />';
} break;
# Update (from store)
case 'update': if ($this->core->auth->isSuperAdmin() && $this->path_writable) {
$submits[] =
'<input type="submit" name="update['.html::escapeHTML($id).']" value="'.__('Update').'" />';
} break;
# Behavior
case 'behavior':
# --BEHAVIOR-- adminModulesListGetActions
$tmp = $this->core->callBehavior('adminModulesListGetActions', $this, $id, $module);
if (!empty($tmp)) {
$submits[] = $tmp;
}
break;
}
}
return $submits;
}
/**
* Get global action buttons to add to modules list.
*
* @param array $actions Actions keys
* @param boolean $with_selection Limit action to selected modules
* @return Array of actions buttons
*/
protected function getGlobalActions($actions, $with_selection=false)
{
$submits = array();
# Use loop to keep requested order
foreach($actions as $action) {
switch($action) {
# Deactivate
case 'activate': if ($this->core->auth->isSuperAdmin() && $this->path_writable) {
$submits[] =
'<input type="submit" name="activate" value="'.($with_selection ?
__('Activate selected plugins') :
__('Activate all plugins from this list')
).'" />';
} break;
# Activate
case 'deactivate': if ($this->core->auth->isSuperAdmin() && $this->path_writable) {
$submits[] =
'<input type="submit" name="deactivate" value="'.($with_selection ?
__('Deactivate selected plugins') :
__('Deactivate all plugins from this list')
).'" />';
} break;
# Update (from store)
case 'update': if ($this->core->auth->isSuperAdmin() && $this->path_writable) {
$submits[] =
'<input type="submit" name="update" value="'.($with_selection ?
__('Update selected plugins') :
__('Update all plugins from this list')
).'" />';
} break;
# Behavior
case 'behavior':
# --BEHAVIOR-- adminModulesListGetGlobalActions
$tmp = $this->core->callBehavior('adminModulesListGetGlobalActions', $this, $with_selection);
if (!empty($tmp)) {
$submits[] = $tmp;
}
break;
}
}
return $submits;
}
/**
* Execute POST action.
*
* @note Set a notice on success through dcPage::addSuccessNotice
* @throw Exception Module not find or command failed
* @return Null
*/
public function doActions()
{
if (empty($_POST) || !empty($_REQUEST['conf'])
|| !$this->isWritablePath()) {
return null;
}
$modules = !empty($_POST['modules']) && is_array($_POST['modules']) ? array_values($_POST['modules']) : array();
if ($this->core->auth->isSuperAdmin() && !empty($_POST['delete'])) {
if (is_array($_POST['delete'])) {
$modules = array_keys($_POST['delete']);
}
$list = $this->modules->getDisabledModules();
$failed = false;
$count = 0;
foreach($modules as $id)
{
if (!isset($list[$id])) {
if (!$this->modules->moduleExists($id)) {
throw new Exception(__('No such plugin.'));
}
$module = $this->modules->getModules($id);
$module['id'] = $id;
if (!$this->isDeletablePath($module['root'])) {
$failed = true;
continue;
}
# --BEHAVIOR-- moduleBeforeDelete
$this->core->callBehavior('pluginBeforeDelete', $module);
$this->modules->deleteModule($id);
# --BEHAVIOR-- moduleAfterDelete
$this->core->callBehavior('pluginAfterDelete', $module);
}
else {
$this->modules->deleteModule($id, true);
}
$count++;
}
if (!$count && $failed) {
throw new Exception(__("You don't have permissions to delete this plugin."));
}
elseif ($failed) {
dcPage::addWarningNotice(__('Some plugins have not been delete.'));
}
else {
dcPage::addSuccessNotice(
__('Plugin has been successfully deleted.', 'Plugins have been successuflly deleted.', $count)
);
}
http::redirect($this->getURL());
}
elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['install'])) {
if (is_array($_POST['install'])) {
$modules = array_keys($_POST['install']);
}
$list = $this->store->get();
if (empty($list)) {
throw new Exception(__('No such plugin.'));
}
$count = 0;
foreach($list as $id => $module) {
if (!in_array($id, $modules)) {
continue;
}
$dest = $this->getPath().'/'.basename($module['file']);
# --BEHAVIOR-- moduleBeforeAdd
$this->core->callBehavior('pluginBeforeAdd', $module);
$this->store->process($module['file'], $dest);
# --BEHAVIOR-- moduleAfterAdd
$this->core->callBehavior('pluginAfterAdd', $module);
$count++;
}
dcPage::addSuccessNotice(
__('Plugin has been successfully installed.', 'Plugins have been successuflly installed.', $count)
);
http::redirect($this->getURL());
}
elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['activate'])) {
if (is_array($_POST['activate'])) {
$modules = array_keys($_POST['activate']);
}
$list = $this->modules->getDisabledModules();
if (empty($list)) {
throw new Exception(__('No such plugin.'));
}
$count = 0;
foreach($list as $id => $module) {
if (!in_array($id, $modules)) {
continue;
}
# --BEHAVIOR-- moduleBeforeActivate
$this->core->callBehavior('pluginBeforeActivate', $id);
$this->modules->activateModule($id);
# --BEHAVIOR-- moduleAfterActivate
$this->core->callBehavior('pluginAfterActivate', $id);
$count++;
}
dcPage::addSuccessNotice(
__('Plugin has been successfully activated.', 'Plugins have been successuflly activated.', $count)
);
http::redirect($this->getURL());
}
elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['deactivate'])) {
if (is_array($_POST['deactivate'])) {
$modules = array_keys($_POST['deactivate']);
}
$list = $this->modules->getModules();
if (empty($list)) {
throw new Exception(__('No such plugin.'));
}
$failed = false;
$count = 0;
foreach($list as $id => $module) {
if (!in_array($id, $modules)) {
continue;
}
if (!$module['root_writable']) {
$failed = true;
continue;
}
$module[$id] = $id;
# --BEHAVIOR-- moduleBeforeDeactivate
$this->core->callBehavior('pluginBeforeDeactivate', $module);
$this->modules->deactivateModule($id);
# --BEHAVIOR-- moduleAfterDeactivate
$this->core->callBehavior('pluginAfterDeactivate', $module);
$count++;
}
if ($failed) {
dcPage::addWarningNotice(__('Some plugins have not been deactivated.'));
}
else {
dcPage::addSuccessNotice(
__('Plugin has been successfully deactivated.', 'Plugins have been successuflly deactivated.', $count)
);
}
http::redirect($this->getURL());
}
elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['update'])) {
if (is_array($_POST['update'])) {
$modules = array_keys($_POST['update']);
}
$list = $this->store->get(true);
if (empty($list)) {
throw new Exception(__('No such plugin.'));
}
$count = 0;
foreach($list as $module) {
if (!in_array($module['id'], $modules)) {
continue;
}
if (!self::$allow_multi_install) {
$dest = $module['root'].'/../'.basename($module['file']);
}
else {
$dest = $this->getPath().'/'.basename($module['file']);
if ($module['root'] != $dest) {
@file_put_contents($module['root'].'/_disabled', '');
}
}
# --BEHAVIOR-- moduleBeforeUpdate
$this->core->callBehavior('pluginBeforeUpdate', $module);
$this->store->process($module['file'], $dest);
# --BEHAVIOR-- moduleAfterUpdate
$this->core->callBehavior('pluginAfterUpdate', $module);
$count++;
}
$tab = $count && $count == count($list) ? '#plugins' : '#update';
dcPage::addSuccessNotice(
__('Plugin has been successfully updated.', 'Plugins have been successuflly updated.', $count)
);
http::redirect($this->getURL().$tab);
}
# Manual actions
elseif (!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file'])
|| !empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url']))
{
if (empty($_POST['your_pwd']) || !$this->core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY, $_POST['your_pwd']))) {
throw new Exception(__('Password verification failed'));
}
if (!empty($_POST['upload_pkg'])) {
files::uploadStatus($_FILES['pkg_file']);
$dest = $this->getPath().'/'.$_FILES['pkg_file']['name'];
if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'], $dest)) {
throw new Exception(__('Unable to move uploaded file.'));
}
}
else {
$url = urldecode($_POST['pkg_url']);
$dest = $this->getPath().'/'.basename($url);
$this->store->download($url, $dest);
}
# --BEHAVIOR-- moduleBeforeAdd
$this->core->callBehavior('pluginBeforeAdd', null);
$ret_code = $this->store->install($dest);
# --BEHAVIOR-- moduleAfterAdd
$this->core->callBehavior('pluginAfterAdd', null);
dcPage::addSuccessNotice($ret_code == 2 ?
__('Plugin has been successfully updated.') :
__('Plugin has been successfully installed.')
);
http::redirect($this->getURL().'#plugins');
}
else {
# --BEHAVIOR-- adminModulesListDoActions
$this->core->callBehavior('adminModulesListDoActions', $this, $modules, 'plugin');
}
return null;
}
/**
* Display tab for manual installation.
*
* @return adminModulesList self instance
*/
public function displayManualForm()
{
if (!$this->core->auth->isSuperAdmin() || !$this->isWritablePath()) {
return null;
}
# 'Upload module' form
echo
'<form method="post" action="'.$this->getURL().'" id="uploadpkg" enctype="multipart/form-data" class="fieldset">'.
'<h4>'.__('Upload a zip file').'</h4>'.
'<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Zip file path:').'</label> '.
'<input type="file" name="pkg_file" id="pkg_file" /></p>'.
'<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '.
form::password(array('your_pwd','your_pwd1'),20,255).'</p>'.
'<p><input type="submit" name="upload_pkg" value="'.__('Upload').'" />'.
$this->core->formNonce().'</p>'.
'</form>';
# 'Fetch module' form
echo
'<form method="post" action="'.$this->getURL().'" id="fetchpkg" class="fieldset">'.
'<h4>'.__('Download a zip file').'</h4>'.
'<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Zip file URL:').'</label> '.
form::field(array('pkg_url','pkg_url'),40,255).'</p>'.
'<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '.
form::password(array('your_pwd','your_pwd2'),20,255).'</p>'.
'<p><input type="submit" name="fetch_pkg" value="'.__('Download').'" />'.
$this->core->formNonce().'</p>'.
'</form>';
return $this;
}
//@}
/// @name Module configuration methods
//@{
/**
* Prepare module configuration.
*
* We need to get configuration content in three steps
* and out of this class to keep backward compatibility.
*
* if ($xxx->setConfiguration()) {
* include $xxx->includeConfiguration();
* }
* $xxx->getConfiguration();
* ... [put here page headers and other stuff]
* $xxx->displayConfiguration();
*
* @param string $id Module to work on or it gather through REQUEST
* @return True if config set
*/
public function setConfiguration($id=null)
{
if (empty($_REQUEST['conf']) || empty($_REQUEST['module']) && !$id) {
return false;
}
if (!empty($_REQUEST['module']) && empty($id)) {
$id = $_REQUEST['module'];
}
if (!$this->modules->moduleExists($id)) {
$this->core->error->add(__('Unknow plugin ID'));
return false;
}
$module = $this->modules->getModules($id);
$module = self::sanitizeModule($id, $module);
$file = path::real($module['root'].'/_config.php');
if (!file_exists($file)) {
$this->core->error->add(__('This plugin has no configuration file.'));
return false;
}
$this->config_module = $module;
$this->config_file = $file;
$this->config_content = '';
if (!defined('DC_CONTEXT_MODULE')) {
define('DC_CONTEXT_MODULE', true);
}
return true;
}
/**
* Get path of module configuration file.
*
* @note Required previously set file info
* @return Full path of config file or null
*/
public function includeConfiguration()
{
if (!$this->config_file) {
return null;
}
$this->setRedir($this->getURL().'#plugins');
ob_start();
return $this->config_file;
}
/**
* Gather module configuration file content.
*
* @note Required previously file inclusion
* @return True if content has been captured
*/
public function getConfiguration()
{
if ($this->config_file) {
$this->config_content = ob_get_contents();
}
ob_end_clean();
return !empty($this->file_content);
}
/**
* Display module configuration form.
*
* @note Required previously gathered content
* @return adminModulesList self instance
*/
public function displayConfiguration()
{
if ($this->config_file) {
if (!$this->config_module['standalone_config']) {
echo
'<form id="module_config" action="'.$this->getURL('conf=1').'" method="post" enctype="multipart/form-data">'.
'<h3>'.sprintf(__('Configure "%s"'), html::escapeHTML($this->config_module['name'])).'</h3>'.
'<p><a class="back" href="'.$this->getRedir().'">'.__('Back').'</a></p>';
}
echo $this->config_content;
if (!$this->config_module['standalone_config']) {
echo
'<p class="clear"><input type="submit" name="save" value="'.__('Save').'" />'.
form::hidden('module', $this->config_module['id']).
form::hidden('redir', $this->getRedir()).
$this->core->formNonce().'</p>'.
'</form>';
}
}
return $this;
}
//@}
/**
* Helper to sanitize a string.
*
* Used for search or id.
*
* @param string $str String to sanitize
* @return Sanitized string
*/
public static function sanitizeString($str)
{
return preg_replace('/[^A-Za-z0-9\@\#+_-]/', '', strtolower($str));
}
}
/**
* @ingroup DC_CORE
* @brief Helper to manage list of themes.
* @since 2.6
*/
class adminThemesList extends adminModulesList
{
protected $page_url = 'blog_theme.php';
public function displayModules($cols=array('name', 'config', 'version', 'desc'), $actions=array(), $nav_limit=false)
{
echo
'<form action="'.$this->getURL().'" method="post" class="modules-form-actions">'.
'<div id="'.html::escapeHTML($this->list_id).'" class="modules'.(in_array('expander', $cols) ? ' expandable' : '').' one-box">';
$sort_field = $this->getSort();
# Sort modules by id
$modules = $this->getSearch() === null ?
self::sortModules($this->data, $sort_field, $this->sort_asc) :
$this->data;
$res = '';
$count = 0;
foreach ($modules as $id => $module)
{
# Show only requested modules
if ($nav_limit && $this->getSearch() === null) {
$char = substr($module[$sort_field], 0, 1);
if (!in_array($char, $this->nav_list)) {
$char = $this->nav_special;
}
if ($this->getIndex() != $char) {
continue;
}
}
$current = $this->core->blog->settings->system->theme == $id && $this->modules->moduleExists($id);
$distrib = self::isDistributedModule($id) ? ' dc-box' : '';
$line =
'<div class="box '.($current ? 'medium current-theme' : 'theme').$distrib.'">';
if (in_array('name', $cols) && !$current) {
$line .=
'<h4 class="module-name">';
if (in_array('checkbox', $cols)) {
$line .=
'<label for="'.html::escapeHTML($this->list_id).'_modules_'.html::escapeHTML($id).'">'.
form::checkbox(array('modules['.$count.']', html::escapeHTML($this->list_id).'_modules_'.html::escapeHTML($id)), html::escapeHTML($id)).
html::escapeHTML($module['name']).
'</label>';
}
else {
$line .=
form::hidden(array('modules['.$count.']'), html::escapeHTML($id)).
html::escapeHTML($module['name']);
}
$line .=
$this->core->formNonce().
'</h4>';
}
# Display score only for debug purpose
if (in_array('score', $cols) && $this->getSearch() !== null && defined('DC_DEBUG') && DC_DEBUG) {
$line .=
'<p class="module-score debug">'.sprintf(__('Score: %s'), $module['score']).'</p>';
}
if (in_array('sshot', $cols)) {
# Screenshot from url
if (preg_match('#^http(s)?://#', $module['sshot'])) {
$sshot = $module['sshot'];
}
# Screenshot from installed module
elseif (file_exists($this->core->blog->themes_path.'/'.$id.'/screenshot.jpg')) {
$sshot = $this->getURL('shot='.rawurlencode($id));
}
# Default screenshot
else {
$sshot = 'images/noscreenshot.png';
}
$line .=
'<div class="module-sshot"><img src="'.$sshot.'" alt="'.
sprintf(__('%s screenshot.'), html::escapeHTML($module['name'])).'" /></div>';
}
$line .=
'<div class="module-infos toggle-bloc">';
if (in_array('name', $cols) && $current) {
$line .=
'<h4 class="module-name">';
if (in_array('checkbox', $cols)) {
$line .=
'<label for="'.html::escapeHTML($this->list_id).'_modules_'.html::escapeHTML($id).'">'.
form::checkbox(array('modules['.$count.']', html::escapeHTML($this->list_id).'_modules_'.html::escapeHTML($id)), html::escapeHTML($id)).
html::escapeHTML($module['name']).
'</label>';
}
else {
$line .=
form::hidden(array('modules['.$count.']'), html::escapeHTML($id)).
html::escapeHTML($module['name']);
}
$line .=
'</h4>';
}
$line .=
'<p>';
if (in_array('desc', $cols)) {
$line .=
'<span class="module-desc">'.html::escapeHTML(__($module['desc'])).'</span> ';
}
if (in_array('author', $cols)) {
$line .=
'<span class="module-author">'.sprintf(__('by %s'),html::escapeHTML($module['author'])).'</span> ';
}
if (in_array('version', $cols)) {
$line .=
'<span class="module-version">'.sprintf(__('version %s'),html::escapeHTML($module['version'])).'</span> ';
}
if (in_array('current_version', $cols)) {
$line .=
'<span class="module-current-version">'.sprintf(__('(current version %s)'),html::escapeHTML($module['current_version'])).'</span> ';
}
if (in_array('parent', $cols) && !empty($module['parent'])) {
if ($this->modules->moduleExists($module['parent'])) {
$line .=
'<span class="module-parent-ok">'.sprintf(__('(built on "%s")'),html::escapeHTML($module['parent'])).'</span> ';
}
else {
$line .=
'<span class="module-parent-missing">'.sprintf(__('(requires "%s")'),html::escapeHTML($module['parent'])).'</span> ';
}
}
$has_details = in_array('details', $cols) && !empty($module['details']);
$has_support = in_array('support', $cols) && !empty($module['support']);
if ($has_details || $has_support) {
$line .=
'<span class="mod-more">';
if ($has_details) {
$line .=
'<a class="module-details" href="'.$module['details'].'">'.__('Details').'</a>';
}
if ($has_support) {
$line .=
' - <a class="module-support" href="'.$module['support'].'">'.__('Support').'</a>';
}
$line .=
'</span>';
}
$line .=
'</p>'.
'</div>';
$line .=
'<div class="module-actions toggle-bloc">';
# Plugins actions
if ($current) {
# _GET actions
if (file_exists(path::real($this->core->blog->themes_path.'/'.$id).'/style.css')) {
$theme_url = preg_match('#^http(s)?://#', $this->core->blog->settings->system->themes_url) ?
http::concatURL($this->core->blog->settings->system->themes_url, '/'.$id) :
http::concatURL($this->core->blog->url, $this->core->blog->settings->system->themes_url.'/'.$id);
$line .=
'<p><a href="'.$theme_url.'/style.css">'.__('View stylesheet').'</a></p>';
}
$line .= '<div class="current-actions">';
if (file_exists(path::real($this->core->blog->themes_path.'/'.$id).'/_config.php')) {
$line .=
'<p><a href="'.$this->getURL('module='.$id.'&conf=1', false).'" class="button submit">'.__('Configure theme').'</a></p>';
}
# --BEHAVIOR-- adminCurrentThemeDetails
$line .=
$this->core->callBehavior('adminCurrentThemeDetails', $this->core, $id, $module);
$line .= '</div>';
}
# _POST actions
if (!empty($actions)) {
$line .=
'<p>'.implode(' ', $this->getActions($id, $module, $actions)).'</p>';
}
$line .=
'</div>';
$line .=
'</div>';
$count++;
$res = $current ? $line.$res : $res.$line;
}
echo
$res.
'</div>';
if(!$count && $this->getSearch() === null) {
echo
'<p class="message">'.__('No themes matched your search.').'</p>';
}
elseif ((in_array('checkbox', $cols) || $count > 1) && !empty($actions) && $this->core->auth->isSuperAdmin()) {
$buttons = $this->getGlobalActions($actions, in_array('checkbox', $cols));
if (!empty($buttons)) {
if (in_array('checkbox', $cols)) {
echo
'<p class="checkboxes-helpers"></p>';
}
echo '<div>'.implode(' ', $buttons).'</div>';
}
}
echo
'</form>';
return $this;
}
protected function getActions($id, $module, $actions)
{
$submits = array();
$this->core->blog->settings->addNamespace('system');
if ($id != $this->core->blog->settings->system->theme) {
# Select theme to use on curent blog
if (in_array('select', $actions) && $this->path_writable) {
$submits[] =
'<input type="submit" name="select['.html::escapeHTML($id).']" value="'.__('Use this one').'" />';
}
}
return array_merge(
$submits,
parent::getActions($id, $module, $actions)
);
}
protected function getGlobalActions($actions, $with_selection=false)
{
$submits = array();
foreach($actions as $action) {
switch($action) {
# Update (from store)
case 'update': if ($this->core->auth->isSuperAdmin() && $this->path_writable) {
$submits[] =
'<input type="submit" name="update" value="'.($with_selection ?
__('Update selected themes') :
__('Update all themes from this list')
).'" />';
} break;
# Behavior
case 'behavior':
# --BEHAVIOR-- adminModulesListGetGlobalActions
$tmp = $this->core->callBehavior('adminModulesListGetGlobalActions', $this);
if (!empty($tmp)) {
$submits[] = $tmp;
}
break;
}
}
return $submits;
}
public function doActions()
{
if (empty($_POST) || !empty($_REQUEST['conf']) || !$this->isWritablePath()) {
return null;
}
$modules = !empty($_POST['modules']) && is_array($_POST['modules']) ? array_values($_POST['modules']) : array();
if (!empty($_POST['select'])) {
# Can select only one theme at a time!
if (is_array($_POST['select'])) {
$modules = array_keys($_POST['select']);
$id = $modules[0];
if (!$this->modules->moduleExists($id)) {
throw new Exception(__('No such theme.'));
}
$this->core->blog->settings->addNamespace('system');
$this->core->blog->settings->system->put('theme',$id);
$this->core->blog->triggerBlog();
dcPage::addSuccessNotice(__('Theme has been successfully selected.'));
http::redirect($this->getURL().'#themes');
}
}
elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['activate'])) {
if (is_array($_POST['activate'])) {
$modules = array_keys($_POST['activate']);
}
$list = $this->modules->getDisabledModules();
if (empty($list)) {
throw new Exception(__('No such theme.'));
}
$count = 0;
foreach($list as $id => $module) {
if (!in_array($id, $modules)) {
continue;
}
# --BEHAVIOR-- themeBeforeActivate
$this->core->callBehavior('themeBeforeActivate', $id);
$this->modules->activateModule($id);
# --BEHAVIOR-- themeAfterActivate
$this->core->callBehavior('themeAfterActivate', $id);
$count++;
}
dcPage::addSuccessNotice(
__('Theme has been successfully activated.', 'Themes have been successuflly activated.', $count)
);
http::redirect($this->getURL());
}
elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['deactivate'])) {
if (is_array($_POST['deactivate'])) {
$modules = array_keys($_POST['deactivate']);
}
$list = $this->modules->getModules();
if (empty($list)) {
throw new Exception(__('No such theme.'));
}
$failed = false;
$count = 0;
foreach($list as $id => $module) {
if (!in_array($id, $modules)) {
continue;
}
if (!$module['root_writable']) {
$failed = true;
continue;
}
$module[$id] = $id;
# --BEHAVIOR-- themeBeforeDeactivate
$this->core->callBehavior('themeBeforeDeactivate', $module);
$this->modules->deactivateModule($id);
# --BEHAVIOR-- themeAfterDeactivate
$this->core->callBehavior('themeAfterDeactivate', $module);
$count++;
}
if ($failed) {
dcPage::addWarningNotice(__('Some themes have not been deactivated.'));
}
else {
dcPage::addSuccessNotice(
__('Theme has been successfully deactivated.', 'Themes have been successuflly deactivated.', $count)
);
}
http::redirect($this->getURL());
}
elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['delete'])) {
if (is_array($_POST['delete'])) {
$modules = array_keys($_POST['delete']);
}
$list = $this->modules->getDisabledModules();
$failed = false;
$count = 0;
foreach($modules as $id)
{
if (!isset($list[$id])) {
if (!$this->modules->moduleExists($id)) {
throw new Exception(__('No such theme.'));
}
$module = $this->modules->getModules($id);
$module['id'] = $id;
if (!$this->isDeletablePath($module['root'])) {
$failed = true;
continue;
}
# --BEHAVIOR-- themeBeforeDelete
$this->core->callBehavior('themeBeforeDelete', $module);
$this->modules->deleteModule($id);
# --BEHAVIOR-- themeAfterDelete
$this->core->callBehavior('themeAfterDelete', $module);
}
else {
$this->modules->deleteModule($id, true);
}
$count++;
}
if (!$count && $failed) {
throw new Exception(__("You don't have permissions to delete this theme."));
}
elseif ($failed) {
dcPage::addWarningNotice(__('Some themes have not been delete.'));
}
else {
dcPage::addSuccessNotice(
__('Theme has been successfully deleted.', 'Themes have been successuflly deleted.', $count)
);
}
http::redirect($this->getURL());
}
elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['install'])) {
if (is_array($_POST['install'])) {
$modules = array_keys($_POST['install']);
}
$list = $this->store->get();
if (empty($list)) {
throw new Exception(__('No such theme.'));
}
$count = 0;
foreach($list as $id => $module) {
if (!in_array($id, $modules)) {
continue;
}
$dest = $this->getPath().'/'.basename($module['file']);
# --BEHAVIOR-- themeBeforeAdd
$this->core->callBehavior('themeBeforeAdd', $module);
$this->store->process($module['file'], $dest);
# --BEHAVIOR-- themeAfterAdd
$this->core->callBehavior('themeAfterAdd', $module);
$count++;
}
dcPage::addSuccessNotice(
__('Theme has been successfully installed.', 'Themes have been successuflly installed.', $count)
);
http::redirect($this->getURL());
}
elseif ($this->core->auth->isSuperAdmin() && !empty($_POST['update'])) {
if (is_array($_POST['update'])) {
$modules = array_keys($_POST['update']);
}
$list = $this->store->get(true);
if (empty($list)) {
throw new Exception(__('No such theme.'));
}
$count = 0;
foreach($list as $module) {
if (!in_array($module['id'], $modules)) {
continue;
}
$dest = $module['root'].'/../'.basename($module['file']);
# --BEHAVIOR-- themeBeforeUpdate
$this->core->callBehavior('themeBeforeUpdate', $module);
$this->store->process($module['file'], $dest);
# --BEHAVIOR-- themeAfterUpdate
$this->core->callBehavior('themeAfterUpdate', $module);
$count++;
}
$tab = $count && $count == count($list) ? '#themes' : '#update';
dcPage::addSuccessNotice(
__('Theme has been successfully updated.', 'Themes have been successuflly updated.', $count)
);
http::redirect($this->getURL().$tab);
}
# Manual actions
elseif (!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file'])
|| !empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url']))
{
if (empty($_POST['your_pwd']) || !$this->core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY, $_POST['your_pwd']))) {
throw new Exception(__('Password verification failed'));
}
if (!empty($_POST['upload_pkg'])) {
files::uploadStatus($_FILES['pkg_file']);
$dest = $this->getPath().'/'.$_FILES['pkg_file']['name'];
if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'], $dest)) {
throw new Exception(__('Unable to move uploaded file.'));
}
}
else {
$url = urldecode($_POST['pkg_url']);
$dest = $this->getPath().'/'.basename($url);
$this->store->download($url, $dest);
}
# --BEHAVIOR-- themeBeforeAdd
$this->core->callBehavior('themeBeforeAdd', null);
$ret_code = $this->store->install($dest);
# --BEHAVIOR-- themeAfterAdd
$this->core->callBehavior('themeAfterAdd', null);
dcPage::addSuccessNotice($ret_code == 2 ?
__('Theme has been successfully updated.') :
__('Theme has been successfully installed.')
);
http::redirect($this->getURL().'#themes');
}
else {
# --BEHAVIOR-- adminModulesListDoActions
$this->core->callBehavior('adminModulesListDoActions', $this, $modules, 'theme');
}
return null;
}
}
|