Code Duplication    Length = 40-41 lines in 2 locations

sources/main.functions.php 2 locations

@@ 1649-1688 (lines=40) @@
1646
1647
    if (isset($_SESSION['settings']['enable_attachment_encryption']) && $_SESSION['settings']['enable_attachment_encryption'] === "1" && isset($image_status) && $image_status === "clear") {
1648
        // file needs to be encrypted
1649
        if (file_exists($_SESSION['settings']['path_to_upload_folder'].'/'.$image_code)) {
1650
            // make a copy of file
1651
            if (!copy(
1652
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$image_code,
1653
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$image_code.".copy"
1654
            )) {
1655
                exit;
1656
            } else {
1657
                // do a bck
1658
                copy(
1659
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$image_code,
1660
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$image_code.".bck"
1661
                );
1662
            }
1663
1664
            // Open the file
1665
            unlink($_SESSION['settings']['path_to_upload_folder'].'/'.$image_code);
1666
            $fp = fopen($_SESSION['settings']['path_to_upload_folder'].'/'.$image_code.".copy", "rb");
1667
            $out = fopen($_SESSION['settings']['path_to_upload_folder'].'/'.$image_code, 'wb');
1668
1669
            // ecnrypt
1670
            stream_filter_append($out, 'mcrypt.tripledes', STREAM_FILTER_WRITE, $opts);
1671
1672
            // read file and create new one
1673
            while (($line = fgets($fp)) !== false) {
1674
                fputs($out, $line);
1675
            }
1676
            fclose($fp);
1677
            fclose($out);
1678
1679
            // update table
1680
            DB::update(
1681
                prefix_table('files'),
1682
                array(
1683
                    'status' => 'encrypted'
1684
                    ),
1685
                "id=%i",
1686
                substr($_POST['uri'], 1)
1687
            );
1688
        }
1689
    } elseif (isset($_SESSION['settings']['enable_attachment_encryption']) && $_SESSION['settings']['enable_attachment_encryption'] === "0" && isset($image_status) && $image_status === "encrypted") {
1690
        // file needs to be decrypted
1691
        if (file_exists($_SESSION['settings']['path_to_upload_folder'].'/'.$image_code)) {
@@ 1691-1731 (lines=41) @@
1688
        }
1689
    } elseif (isset($_SESSION['settings']['enable_attachment_encryption']) && $_SESSION['settings']['enable_attachment_encryption'] === "0" && isset($image_status) && $image_status === "encrypted") {
1690
        // file needs to be decrypted
1691
        if (file_exists($_SESSION['settings']['path_to_upload_folder'].'/'.$image_code)) {
1692
            // make a copy of file
1693
            if (!copy(
1694
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$image_code,
1695
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$image_code.".copy"
1696
            )) {
1697
                $error = "Copy not possible";
1698
                exit;
1699
            } else {
1700
                // do a bck
1701
                copy(
1702
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$image_code,
1703
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$image_code.".bck"
1704
                );
1705
            }
1706
1707
            // Open the file
1708
            unlink($_SESSION['settings']['path_to_upload_folder'].'/'.$image_code);
1709
            $fp = fopen($_SESSION['settings']['path_to_upload_folder'].'/'.$image_code.".copy", "rb");
1710
            $out = fopen($_SESSION['settings']['path_to_upload_folder'].'/'.$image_code, 'wb');
1711
1712
            // ecnrypt
1713
            stream_filter_append($fp, 'mdecrypt.tripledes', STREAM_FILTER_READ, $opts);
1714
1715
            // read file and create new one
1716
            while (($line = fgets($fp)) !== false) {
1717
                fputs($out, $line);
1718
            }
1719
            fclose($fp);
1720
            fclose($out);
1721
1722
            // update table
1723
            DB::update(
1724
                prefix_table('files'),
1725
                array(
1726
                    'status' => 'clear'
1727
                    ),
1728
                "id=%i",
1729
                substr($_POST['uri'], 1)
1730
            );
1731
        }
1732
    }
1733
}
1734