| Conditions | 66 |
| Paths | > 20000 |
| Total Lines | 488 |
| Lines | 210 |
| Ratio | 43.03 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 597 | public function download($data) |
||
| 598 | { |
||
| 599 | // The data could potentially be loaded from the file with $this->getItem() instead of using directly the data from the post |
||
| 600 | $app = JFactory::getApplication(); |
||
| 601 | |||
| 602 | // Prevent generating and downloading Master package |
||
| 603 | View Code Duplication | if (strpos($data['name'], 'master_') !== false) |
|
| 604 | { |
||
| 605 | $app->enqueueMessage(JText::sprintf('COM_LOCALISE_ERROR_MASTER_PACKAGE_DOWNLOAD_FORBIDDEN', $data['name']), 'warning'); |
||
| 606 | $app->redirect(JRoute::_('index.php?option=com_localise&view=package&layout=edit&id=' . $this->getState('package.id'), false)); |
||
| 607 | |||
| 608 | return false; |
||
| 609 | } |
||
| 610 | |||
| 611 | // Necessary variables if xx-XX.localise.php is not present in target language |
||
| 612 | $params = JComponentHelper::getParams('com_localise'); |
||
| 613 | $reftag = $params->get('reference'); |
||
| 614 | $refclassname = str_replace('-', '_', $reftag); |
||
| 615 | $refclassname = ucfirst($refclassname); |
||
| 616 | $langclassname = str_replace('-', '_', $data['language']); |
||
| 617 | $langclassname = ucfirst($langclassname); |
||
| 618 | $msg = null; |
||
| 619 | |||
| 620 | $administrator = array(); |
||
| 621 | $site = array(); |
||
| 622 | $main_package_files = array(); |
||
| 623 | |||
| 624 | // Delete old files |
||
| 625 | $delete = JFolder::files(JPATH_ROOT . '/tmp/', 'com_localise_', false, true); |
||
| 626 | |||
| 627 | View Code Duplication | if (!empty($delete)) |
|
| 628 | { |
||
| 629 | if (!JFile::delete($delete)) |
||
| 630 | { |
||
| 631 | // JFile::delete throws an error |
||
| 632 | $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ZIPDELETE')); |
||
| 633 | |||
| 634 | return false; |
||
| 635 | } |
||
| 636 | } |
||
| 637 | |||
| 638 | View Code Duplication | foreach ($data['translations'] as $translation) |
|
| 639 | { |
||
| 640 | if (preg_match('/^site_(.*)$/', $translation, $matches)) |
||
| 641 | { |
||
| 642 | $site[] = $matches[1]; |
||
| 643 | } |
||
| 644 | |||
| 645 | if (preg_match('/^administrator_(.*)$/', $translation, $matches)) |
||
| 646 | { |
||
| 647 | $administrator[] = $matches[1]; |
||
| 648 | } |
||
| 649 | } |
||
| 650 | |||
| 651 | $parts = explode('.', $data['version']); |
||
| 652 | $small_version = implode('.', array($parts[0],$parts[1])); |
||
| 653 | |||
| 654 | // Prepare text to save for the xml package description |
||
| 655 | $text = ''; |
||
| 656 | $text .= '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; |
||
| 657 | $text .= '<extension type="package" version="' . $small_version . '" method="upgrade">' . "\n"; |
||
| 658 | $text .= "\t" . '<name>' . $data['name'] . '</name>' . "\n"; |
||
| 659 | $text .= "\t" . '<packagename>' . $data['language'] . '</packagename>' . "\n"; |
||
| 660 | $text .= "\t" . '<version>' . $data['version'] . '.' . $data['packversion'] . '</version>' . "\n"; |
||
| 661 | $text .= "\t" . '<creationDate>' . date('d/m/Y') . '</creationDate>' . "\n"; |
||
| 662 | $text .= "\t" . '<author>' . $data['author'] . '</author>' . "\n"; |
||
| 663 | $text .= "\t" . '<authorEmail>' . $data['authoremail'] . '</authorEmail>' . "\n"; |
||
| 664 | $text .= "\t" . '<authorUrl>' . $data['authorurl'] . '</authorUrl>' . "\n"; |
||
| 665 | $text .= "\t" . '<copyright>' . $data['copyright'] . '</copyright>' . "\n"; |
||
| 666 | $text .= "\t" . '<license>' . $data['license'] . '</license>' . "\n"; |
||
| 667 | $text .= "\t" . '<url>' . $data['url'] . '</url>' . "\n"; |
||
| 668 | $text .= "\t" . '<packager>' . $data['packager'] . '</packager>' . "\n"; |
||
| 669 | $text .= "\t" . '<packagerurl>' . $data['packagerurl'] . '</packagerurl>' . "\n"; |
||
| 670 | $text .= "\t" . '<description><![CDATA[' . $data['description'] . ']]></description>' . "\n"; |
||
| 671 | $text .= "\t" . '<blockChildUninstall>' . $data['blockuninstall'] . '</blockChildUninstall>' . "\n"; |
||
| 672 | $text .= "\t" . '<files>' . "\n"; |
||
| 673 | |||
| 674 | if (count($site)) |
||
| 675 | { |
||
| 676 | $text .= "\t\t" . '<file type="language" client="site" id="' . $data['language'] . '">site_' . $data['language'] . '.zip</file>' . "\n"; |
||
| 677 | |||
| 678 | $path = JPATH_ROOT . '/language/' . $data['language'] . '/' . $data['language'] . '.xml'; |
||
| 679 | |||
| 680 | if (JFile::exists($path)) |
||
| 681 | { |
||
| 682 | $xmldata = file_get_contents($path); |
||
| 683 | |||
| 684 | // Fetch the language name for the install.xml |
||
| 685 | if (!empty($xmldata)) |
||
| 686 | { |
||
| 687 | $xml = simplexml_load_file($path); |
||
| 688 | $installName = (string) $xml->name; |
||
| 689 | } |
||
| 690 | } |
||
| 691 | |||
| 692 | View Code Duplication | if (!JFile::exists($path) || empty($xmldata)) |
|
| 693 | { |
||
| 694 | $app->enqueueMessage(JText::sprintf('COM_LOCALISE_ERROR_NO_XML', JText::_('JSITE'), $data['language'] . '.xml', 'error')); |
||
| 695 | $app->redirect(JRoute::_('index.php?option=com_localise&view=package&layout=edit&id=' . $this->getState('package.id'), false)); |
||
| 696 | |||
| 697 | return false; |
||
| 698 | } |
||
| 699 | |||
| 700 | // Generate site package |
||
| 701 | $site_package_files = array(); |
||
| 702 | |||
| 703 | $site_txt = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; |
||
| 704 | $site_txt .= '<extension version="' . $small_version . '" client="site" type="language" method="upgrade">' . "\n"; |
||
| 705 | $site_txt .= "\t" . '<name>' . $installName . '</name>' . "\n"; |
||
| 706 | $site_txt .= "\t" . '<tag>' . $data['language'] . '</tag>' . "\n"; |
||
| 707 | $site_txt .= "\t" . '<version>' . $data['version'] . '.' . $data['packversion'] . '</version>' . "\n"; |
||
| 708 | $site_txt .= "\t" . '<creationDate>' . date('d/m/Y') . '</creationDate>' . "\n"; |
||
| 709 | $site_txt .= "\t" . '<author>' . $data['author'] . '</author>' . "\n"; |
||
| 710 | $site_txt .= "\t" . '<authorEmail>' . $data['authoremail'] . '</authorEmail>' . "\n"; |
||
| 711 | $site_txt .= "\t" . '<authorUrl>' . $data['authorurl'] . '</authorUrl>' . "\n"; |
||
| 712 | $site_txt .= "\t" . '<copyright>' . $data['copyright'] . '</copyright>' . "\n"; |
||
| 713 | $site_txt .= "\t" . '<license>' . $data['license'] . '</license>' . "\n"; |
||
| 714 | $site_txt .= "\t" . '<description>' . $data['language'] . ' - Site language</description>' . "\n"; |
||
| 715 | $site_txt .= "\t" . '<files>' . "\n"; |
||
| 716 | |||
| 717 | // As this is a core package, the main joomla file xx-XX.ini should be in the package |
||
| 718 | $path = JPATH_ROOT . '/language/' . $data['language'] . '/' . $data['language'] . '.ini'; |
||
| 719 | |||
| 720 | if (JFile::exists($path)) |
||
| 721 | { |
||
| 722 | $file_data = file_get_contents($path); |
||
| 723 | } |
||
| 724 | |||
| 725 | View Code Duplication | if (JFile::exists($path) && !empty($file_data)) |
|
| 726 | { |
||
| 727 | $site = array_diff($site, array("joomla")); |
||
| 728 | $site_txt .= "\t\t" . '<filename>' . $data['language'] . '.ini</filename>' . "\n"; |
||
| 729 | $site_package_files[] = array('name' => $data['language'] . '.ini','data' => $file_data); |
||
| 730 | } |
||
| 731 | else |
||
| 732 | { |
||
| 733 | $msg .= JText::sprintf('COM_LOCALISE_MAINFILE_NOT_TRANSLATED', $data['language'] . '.ini', JText::_('JSITE')); |
||
| 734 | } |
||
| 735 | |||
| 736 | View Code Duplication | foreach ($site as $translation) |
|
| 737 | { |
||
| 738 | $path = JPATH_ROOT . '/language/' . $data['language'] . '/' . $data['language'] . '.' . $translation . '.ini'; |
||
| 739 | |||
| 740 | if (JFile::exists($path)) |
||
| 741 | { |
||
| 742 | $file_data = file_get_contents($path); |
||
| 743 | } |
||
| 744 | |||
| 745 | if (JFile::exists($path) && !empty($file_data)) |
||
| 746 | { |
||
| 747 | $site_txt .= "\t\t" . '<filename>' . $data['language'] . '.' . $translation . '.ini</filename>' . "\n"; |
||
| 748 | $site_package_files[] = array('name' => $data['language'] . '.' . $translation . '.ini', 'data' => $file_data); |
||
| 749 | } |
||
| 750 | elseif ($translation != 'joomla') |
||
| 751 | { |
||
| 752 | $msg .= JText::sprintf('COM_LOCALISE_FILE_NOT_TRANSLATED', $data['language'] . '.' . $translation . '.ini', JText::_('JSITE')); |
||
| 753 | } |
||
| 754 | } |
||
| 755 | |||
| 756 | $path = JPATH_ROOT . '/language/' . $data['language'] . '/' . $data['language'] . '.localise.php'; |
||
| 757 | |||
| 758 | View Code Duplication | if (JFile::exists($path)) |
|
| 759 | { |
||
| 760 | $language_data = file_get_contents($path); |
||
| 761 | } |
||
| 762 | |||
| 763 | // Create a basic xx-XX.localise.php if not present in target language |
||
| 764 | elseif (!JFile::exists($path) || empty($languagedata)) |
||
| 765 | { |
||
| 766 | $language_data = file_get_contents(JPATH_ROOT . '/language/' . $reftag . '/' . $reftag . '.localise.php'); |
||
| 767 | $language_data = str_replace($reftag, $data['language'], $language_data); |
||
| 768 | $language_data = str_replace($refclassname, $langclassname, $language_data); |
||
| 769 | } |
||
| 770 | |||
| 771 | $site_txt .= "\t\t" . '<filename>' . $data['language'] . '.localise.php</filename>' . "\n"; |
||
| 772 | $site_package_files[] = array('name' => $data['language'] . '.localise.php','data' => $language_data); |
||
| 773 | |||
| 774 | if ($msg) |
||
| 775 | { |
||
| 776 | $msg .= '<p>...</p>'; |
||
| 777 | } |
||
| 778 | |||
| 779 | $site_txt .= "\t\t" . '<filename file="meta">install.xml</filename>' . "\n"; |
||
| 780 | $site_txt .= "\t\t" . '<filename file="meta">' . $data['language'] . '.xml</filename>' . "\n"; |
||
| 781 | $site_txt .= "\t\t" . '<filename>index.html</filename>' . "\n"; |
||
| 782 | $site_txt .= "\t" . '</files>' . "\n"; |
||
| 783 | |||
| 784 | // Check if language has a custom calendar. The folder xx-XX should be present in the media folder |
||
| 785 | if (JFolder::exists(JPATH_ROOT . '/media/' . $data['language'])) |
||
| 786 | { |
||
| 787 | $site_txt .= "\n"; |
||
| 788 | $site_txt .= "\t" . '<media destination="' . $data['language'] . '">' . "\n"; |
||
| 789 | $site_txt .= "\t\t" . '<filename>index.html</filename>' . "\n"; |
||
| 790 | $path = JPATH_ROOT . '/media/' . $data['language'] . '/js/calendar-setup.js'; |
||
| 791 | |||
| 792 | if (JFile::exists($path)) |
||
| 793 | { |
||
| 794 | $file_data = file_get_contents($path); |
||
| 795 | } |
||
| 796 | |||
| 797 | View Code Duplication | if (JFile::exists($path) && !empty($file_data)) |
|
| 798 | { |
||
| 799 | $site_package_files[] = array('name' => 'js/calendar-setup.js','data' => $file_data); |
||
| 800 | $site_txt .= "\t\t" . '<filename>js/calendar-setup.js</filename>' . "\n"; |
||
| 801 | } |
||
| 802 | |||
| 803 | $path = JPATH_ROOT . '/media/' . $data['language'] . '/js/calendar-setup-uncompressed.js'; |
||
| 804 | |||
| 805 | if (JFile::exists($path)) |
||
| 806 | { |
||
| 807 | $file_data = file_get_contents($path); |
||
| 808 | } |
||
| 809 | |||
| 810 | View Code Duplication | if (JFile::exists($path) && !empty($file_data)) |
|
| 811 | { |
||
| 812 | $site_package_files[] = array('name' => 'js/calendar-setup-uncompressed.js','data' => $file_data); |
||
| 813 | $site_txt .= "\t\t" . '<filename>js/calendar-setup-uncompressed</filename>' . "\n"; |
||
| 814 | } |
||
| 815 | |||
| 816 | $path = JPATH_ROOT . '/media/' . $data['language'] . '/js/index.html'; |
||
| 817 | |||
| 818 | if (JFile::exists($path)) |
||
| 819 | { |
||
| 820 | $file_data = file_get_contents($path); |
||
| 821 | } |
||
| 822 | |||
| 823 | View Code Duplication | if (JFile::exists($path) && !empty($file_data)) |
|
| 824 | { |
||
| 825 | $site_package_files[] = array('name' => 'js/index.html','data' => $file_data); |
||
| 826 | $site_txt .= "\t\t" . '<filename>js/index.html</filename>' . "\n"; |
||
| 827 | } |
||
| 828 | |||
| 829 | $path = JPATH_ROOT . '/media/' . $data['language'] . '/js/calendar.js'; |
||
| 830 | |||
| 831 | if (JFile::exists($path)) |
||
| 832 | { |
||
| 833 | $file_data = file_get_contents($path); |
||
| 834 | } |
||
| 835 | |||
| 836 | View Code Duplication | if (JFile::exists($path) && !empty($file_data)) |
|
| 837 | { |
||
| 838 | $site_package_files[] = array('name' => 'js/calendar.js','data' => $file_data); |
||
| 839 | $site_txt .= "\t\t" . '<filename>js/calendar.js</filename>' . "\n"; |
||
| 840 | } |
||
| 841 | |||
| 842 | $path = JPATH_ROOT . '/media/' . $data['language'] . '/js/calendar-uncompressed.js'; |
||
| 843 | |||
| 844 | if (JFile::exists($path)) |
||
| 845 | { |
||
| 846 | $file_data = file_get_contents($path); |
||
| 847 | } |
||
| 848 | |||
| 849 | View Code Duplication | if (JFile::exists($path) && !empty($file_data)) |
|
| 850 | { |
||
| 851 | $site_package_files[] = array('name' => 'js/calendar-uncompressed.js','data' => $file_data); |
||
| 852 | $site_txt .= "\t\t" . '<filename>js/calendar-uncompressed.js</filename>' . "\n"; |
||
| 853 | } |
||
| 854 | |||
| 855 | $site_txt .= "\t" . '</media>' . "\n"; |
||
| 856 | } |
||
| 857 | |||
| 858 | $site_txt .= "\t" . '<params />' . "\n"; |
||
| 859 | $site_txt .= '</extension>' . "\n"; |
||
| 860 | $site_package_files[] = array('name' => 'install.xml','data' => $site_txt); |
||
| 861 | $language_data = file_get_contents(JPATH_ROOT . '/language/' . $data['language'] . '/' . $data['language'] . '.xml'); |
||
| 862 | $site_package_files[] = array('name' => $data['language'] . '.xml','data' => $language_data); |
||
| 863 | |||
| 864 | $language_data = file_get_contents(JPATH_ROOT . '/administrator/components/com_localise/models/index.html'); |
||
| 865 | $site_package_files[] = array('name' => 'index.html','data' => $language_data); |
||
| 866 | |||
| 867 | $site_zip_path = JPATH_ROOT . '/tmp/' . uniqid('com_localise_') . '.zip'; |
||
| 868 | |||
| 869 | View Code Duplication | if (!$packager = JArchive::getAdapter('zip')) |
|
| 870 | { |
||
| 871 | $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ADAPTER')); |
||
| 872 | |||
| 873 | return false; |
||
| 874 | } |
||
| 875 | else |
||
| 876 | { |
||
| 877 | if (!$packager->create($site_zip_path, $site_package_files)) |
||
| 878 | { |
||
| 879 | $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ZIPCREATE')); |
||
| 880 | |||
| 881 | return false; |
||
| 882 | } |
||
| 883 | } |
||
| 884 | |||
| 885 | $main_package_files[] = array('name' => 'site_' . $data['language'] . '.zip','data' => file_get_contents($site_zip_path)); |
||
| 886 | } |
||
| 887 | |||
| 888 | if (count($administrator)) |
||
| 889 | { |
||
| 890 | $text .= "\t\t" . '<file type="language" client="administrator" id="' . $data['language'] . '">admin_' . $data['language'] . '.zip</file>' . "\n"; |
||
| 891 | |||
| 892 | $path = JPATH_ROOT . '/administrator/language/' . $data['language'] . '/' . $data['language'] . '.xml'; |
||
| 893 | |||
| 894 | if (JFile::exists($path)) |
||
| 895 | { |
||
| 896 | $xmldata = file_get_contents($path); |
||
| 897 | } |
||
| 898 | |||
| 899 | View Code Duplication | if (!JFile::exists($path) || empty($xmldata)) |
|
| 900 | { |
||
| 901 | $app->enqueueMessage(JText::sprintf('COM_LOCALISE_ERROR_NO_XML', JText::_('JADMINISTRATOR'), $data['language'] . '.xml', 'error')); |
||
| 902 | $app->redirect(JRoute::_('index.php?option=com_localise&view=package&layout=edit&id=' . $this->getState('package.id'), false)); |
||
| 903 | |||
| 904 | return false; |
||
| 905 | } |
||
| 906 | |||
| 907 | // Generate administrator package |
||
| 908 | $admin_package_files = array(); |
||
| 909 | |||
| 910 | $admin_txt = '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; |
||
| 911 | $admin_txt .= '<extension version="' . $small_version . '" client="administrator" type="language" method="upgrade">' . "\n"; |
||
| 912 | $admin_txt .= "\t" . '<name>' . $installName . '</name>' . "\n"; |
||
| 913 | $admin_txt .= "\t" . '<tag>' . $data['language'] . '</tag>' . "\n"; |
||
| 914 | $admin_txt .= "\t" . '<version>' . $data['version'] . '.' . $data['packversion'] . '</version>' . "\n"; |
||
| 915 | $admin_txt .= "\t" . '<creationDate>' . date('d/m/Y') . '</creationDate>' . "\n"; |
||
| 916 | $admin_txt .= "\t" . '<author>' . $data['author'] . '</author>' . "\n"; |
||
| 917 | $admin_txt .= "\t" . '<authorEmail>' . $data['authoremail'] . '</authorEmail>' . "\n"; |
||
| 918 | $admin_txt .= "\t" . '<authorUrl>' . $data['authorurl'] . '</authorUrl>' . "\n"; |
||
| 919 | $admin_txt .= "\t" . '<copyright>' . $data['copyright'] . '</copyright>' . "\n"; |
||
| 920 | $admin_txt .= "\t" . '<license>' . $data['license'] . '</license>' . "\n"; |
||
| 921 | $admin_txt .= "\t" . '<description>' . $data['language'] . ' - Administration language</description>' . "\n"; |
||
| 922 | $admin_txt .= "\t" . '<files>' . "\n"; |
||
| 923 | |||
| 924 | // As this is a core package, the main joomla file xx-XX.ini should be in the package |
||
| 925 | $path = JPATH_ROOT . '/administrator/language/' . $data['language'] . '/' . $data['language'] . '.ini'; |
||
| 926 | |||
| 927 | if (JFile::exists($path)) |
||
| 928 | { |
||
| 929 | $file_data = file_get_contents($path); |
||
| 930 | } |
||
| 931 | |||
| 932 | View Code Duplication | if (JFile::exists($path) && !empty($file_data)) |
|
| 933 | { |
||
| 934 | $administrator = array_diff($administrator, array("joomla")); |
||
| 935 | $admin_txt .= "\t\t" . '<filename>' . $data['language'] . '.ini</filename>' . "\n"; |
||
| 936 | $admin_package_files[] = array('name' => $data['language'] . '.ini','data' => $file_data); |
||
| 937 | } |
||
| 938 | else |
||
| 939 | { |
||
| 940 | $msg .= JText::sprintf('COM_LOCALISE_MAINFILE_NOT_TRANSLATED', $data['language'] . '.ini', JText::_('JADMINISTRATOR')); |
||
| 941 | } |
||
| 942 | |||
| 943 | View Code Duplication | foreach ($administrator as $translation) |
|
| 944 | { |
||
| 945 | $path = JPATH_ROOT . '/administrator/language/' . $data['language'] . '/' . $data['language'] . '.' . $translation . '.ini'; |
||
| 946 | |||
| 947 | if (JFile::exists($path)) |
||
| 948 | { |
||
| 949 | $file_data = file_get_contents($path); |
||
| 950 | } |
||
| 951 | |||
| 952 | if (JFile::exists($path) && !empty($file_data)) |
||
| 953 | { |
||
| 954 | $admin_txt .= "\t\t" . '<filename>' . $data['language'] . '.' . $translation . '.ini</filename>' . "\n"; |
||
| 955 | $admin_package_files[] = array('name' => $data['language'] . '.' . $translation . '.ini','data' => $file_data); |
||
| 956 | } |
||
| 957 | elseif ($translation != 'joomla') |
||
| 958 | { |
||
| 959 | $msg .= JText::sprintf('COM_LOCALISE_FILE_NOT_TRANSLATED', $data['language'] . '.' . $translation . '.ini', JText::_('JADMINISTRATOR')); |
||
| 960 | } |
||
| 961 | } |
||
| 962 | |||
| 963 | $path = JPATH_ROOT . '/administrator/language/' . $data['language'] . '/' . $data['language'] . '.localise.php'; |
||
| 964 | |||
| 965 | View Code Duplication | if (JFile::exists($path)) |
|
| 966 | { |
||
| 967 | $language_data = file_get_contents($path); |
||
| 968 | } |
||
| 969 | |||
| 970 | // Create a basic xx-XX.localise.php if not present in target language |
||
| 971 | elseif (!JFile::exists($path) || empty($languagedata)) |
||
| 972 | { |
||
| 973 | $language_data = file_get_contents(JPATH_ROOT . '/administrator/language/' . $reftag . '/' . $reftag . '.localise.php'); |
||
| 974 | $language_data = str_replace($reftag, $data['language'], $language_data); |
||
| 975 | $language_data = str_replace($refclassname, $langclassname, $language_data); |
||
| 976 | } |
||
| 977 | |||
| 978 | $admin_txt .= "\t\t" . '<filename>' . $data['language'] . '.localise.php</filename>' . "\n"; |
||
| 979 | $admin_package_files[] = array('name' => $data['language'] . '.localise.php','data' => $language_data); |
||
| 980 | |||
| 981 | // Add the css file if present |
||
| 982 | $path = JPATH_ROOT . '/administrator/language/' . $data['language'] . '/' . $data['language'] . '.css'; |
||
| 983 | |||
| 984 | if (JFile::exists($path)) |
||
| 985 | { |
||
| 986 | $css_data = file_get_contents($path); |
||
| 987 | } |
||
| 988 | |||
| 989 | if (JFile::exists($path) && !empty($css_data)) |
||
| 990 | { |
||
| 991 | $admin_txt .= "\t\t" . '<filename>' . $data['language'] . '.css</filename>' . "\n"; |
||
| 992 | $admin_package_files[] = array('name' => $data['language'] . '.css','data' => $css_data); |
||
| 993 | } |
||
| 994 | |||
| 995 | View Code Duplication | if ($msg) |
|
| 996 | { |
||
| 997 | $msg .= '<p>...</p>'; |
||
| 998 | $msg .= JText::_('COM_LOCALISE_UNTRANSLATED'); |
||
| 999 | $app->enqueueMessage($msg, 'error'); |
||
| 1000 | $app->redirect(JRoute::_('index.php?option=com_localise&view=package&layout=edit&id=' . $this->getState('package.id'), false)); |
||
| 1001 | |||
| 1002 | return false; |
||
| 1003 | } |
||
| 1004 | |||
| 1005 | $admin_txt .= "\t\t" . '<filename file="meta">install.xml</filename>' . "\n"; |
||
| 1006 | $admin_txt .= "\t\t" . '<filename file="meta">' . $data['language'] . '.xml</filename>' . "\n"; |
||
| 1007 | $admin_txt .= "\t\t" . '<filename>index.html</filename>' . "\n"; |
||
| 1008 | $admin_txt .= "\t" . '</files>' . "\n"; |
||
| 1009 | $admin_txt .= "\t" . '<params />' . "\n"; |
||
| 1010 | $admin_txt .= '</extension>' . "\n"; |
||
| 1011 | $admin_package_files[] = array('name' => 'install.xml','data' => $admin_txt); |
||
| 1012 | $language_data = file_get_contents(JPATH_ROOT . '/administrator/language/' . $data['language'] . '/' . $data['language'] . '.xml'); |
||
| 1013 | $admin_package_files[] = array('name' => $data['language'] . '.xml','data' => $language_data); |
||
| 1014 | $language_data = file_get_contents(JPATH_ROOT . '/administrator/components/com_localise/models/index.html'); |
||
| 1015 | $admin_package_files[] = array('name' => 'index.html','data' => $language_data); |
||
| 1016 | |||
| 1017 | $admin_zip_path = JPATH_ROOT . '/tmp/' . uniqid('com_localise_') . '.zip'; |
||
| 1018 | |||
| 1019 | View Code Duplication | if (!$packager = JArchive::getAdapter('zip')) |
|
| 1020 | { |
||
| 1021 | $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ADAPTER')); |
||
| 1022 | |||
| 1023 | return false; |
||
| 1024 | } |
||
| 1025 | else |
||
| 1026 | { |
||
| 1027 | if (!$packager->create($admin_zip_path, $admin_package_files)) |
||
| 1028 | { |
||
| 1029 | $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ZIPCREATE')); |
||
| 1030 | |||
| 1031 | return false; |
||
| 1032 | } |
||
| 1033 | } |
||
| 1034 | |||
| 1035 | $main_package_files[] = array('name' => 'admin_' . $data['language'] . '.zip','data' => file_get_contents($admin_zip_path)); |
||
| 1036 | } |
||
| 1037 | |||
| 1038 | $text .= "\t" . '</files>' . "\n"; |
||
| 1039 | |||
| 1040 | View Code Duplication | if (!empty($data['serverurl'])) |
|
| 1041 | { |
||
| 1042 | $text .= "\t" . '<updateservers>' . "\n"; |
||
| 1043 | $text .= "\t\t" . '<server type="collection" priority="1" name="' . $data['servername'] . '">' . $data['serverurl'] . '</server>' . "\n"; |
||
| 1044 | $text .= "\t" . '</updateservers>' . "\n"; |
||
| 1045 | } |
||
| 1046 | |||
| 1047 | $text .= '</extension>' . "\n"; |
||
| 1048 | |||
| 1049 | $main_package_files[] = array('name' => 'pkg_' . $data['language'] . '.xml', 'data' => $text); |
||
| 1050 | |||
| 1051 | $ziproot = JPATH_ROOT . '/tmp/' . uniqid('com_localise_main_') . '.zip'; |
||
| 1052 | |||
| 1053 | // Run the packager |
||
| 1054 | View Code Duplication | if (!$packager = JArchive::getAdapter('zip')) |
|
| 1055 | { |
||
| 1056 | $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ADAPTER')); |
||
| 1057 | |||
| 1058 | return false; |
||
| 1059 | } |
||
| 1060 | else |
||
| 1061 | { |
||
| 1062 | if (!$packager->create($ziproot, $main_package_files)) |
||
| 1063 | { |
||
| 1064 | $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ZIPCREATE')); |
||
| 1065 | |||
| 1066 | return false; |
||
| 1067 | } |
||
| 1068 | } |
||
| 1069 | |||
| 1070 | ob_clean(); |
||
| 1071 | $zipdata = file_get_contents($ziproot); |
||
| 1072 | header("Expires: 0"); |
||
| 1073 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
||
| 1074 | header('Content-Type: application/zip'); |
||
| 1075 | header('Content-Disposition: attachment; filename="' |
||
| 1076 | . $data['language'] . '_joomla_lang_full_' |
||
| 1077 | . $data['version'] . 'v' . $data['packversion'] . '.zip"'); |
||
| 1078 | header('Content-Length: ' . strlen($zipdata)); |
||
| 1079 | header("Cache-Control: maxage=1"); |
||
| 1080 | header("Pragma: public"); |
||
| 1081 | header("Content-Transfer-Encoding: binary"); |
||
| 1082 | echo $zipdata; |
||
| 1083 | exit; |
||
| 1084 | } |
||
| 1085 | |||
| 1208 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.