FROM php:7.4-apache

########################################
# APT local cache
# work around because COPY failed if no source file
COPY .dummy .apt-mirror-confi[g] .proxy-confi[g] /
RUN cp /.proxy-config /etc/profile.d/proxy.sh 2> /dev/null || true
RUN if [ -f /.apt-mirror-config ] ; then . /.apt-mirror-config && sed -i \
	-e "s%s\?://deb.debian.org%://${APT_MIRROR_DEBIAN}%g" \
	-e "s%s\?://security.debian.org%://${APT_MIRROR_DEBIAN_SECURITY}%g" \
	-e "s%s\?://archive.ubuntu.com%://${APT_MIRROR_UBUNTU}%g" \
	-e "s%s\?://security.ubuntu.com%://${APT_MIRROR_UBUNTU_SECURITY}%g" \
	/etc/apt/sources.list; fi

########################################
RUN apt-get update --quiet && apt-get install -y \
    git wget zip patch \
    libicu-dev libpq-dev zlib1g-dev libicu-dev

RUN apt-get install -y locales locales-all
RUN sed -i '/fr_FR.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LC_ALL fr_FR.UTF-8
ENV LANG fr_FR.UTF-8
ENV LANGUAGE fr_FR:fr
RUN update-locale LANG=fr_FR.UTF-8

# install framadate
RUN mkdir /var/framadate
WORKDIR /var/framadate
COPY --chown=www-data git/framadate/ .
RUN cp php.ini /usr/local/etc/php/

# patch bad-e-mail
COPY dockers/framadate/patch/*.patch ./
RUN patch adminstuds.php adminstuds.php.patch
RUN patch create_classic_poll.php create_classic_poll.php.patch
RUN patch create_date_poll.php create_date_poll.php.patch
RUN patch find_polls.php find_polls.php.patch
RUN patch locale/en.json en.json.patch
RUN patch locale/fr.json fr.json.patch

# install composer setup script
COPY dockers/framadate/composer-setup.sh /usr/local/bin/
COPY dockers/framadate/kazdate.png /var/framadate/images/logo-framadate.png
COPY dockers/framadate/kazclassic.png /var/framadate/images/classic.png
COPY dockers/framadate/kazdates.png /var/framadate/images/date.png
RUN chmod +x /usr/local/bin/composer-setup.sh

# install internationalization libs
RUN docker-php-ext-configure intl
RUN docker-php-ext-install intl
RUN docker-php-ext-install -j$(nproc) pdo pdo_mysql

RUN /usr/local/bin/composer-setup.sh
RUN php composer.phar install

# patch : Kaz don't use TLS
RUN sed -e 's%$tls = true;%//XXX Kaz not use TLS // $tls = true;%' -i vendor/phpmailer/phpmailer/src/PHPMailer.php
RUN chown -R www-data.www-data /var/framadate/

RUN a2enmod rewrite
RUN cp htaccess.txt .htaccess

RUN mkdir /svg

VOLUME ["/var/framadate/app/inc", "/etc/apache2/sites-available/000-default"]
EXPOSE 80