<?php

class AxcotoFontBirdFrontController {

    public function __construct() {
        
    }

    public function action_index() {
        $urlregex = '^(https?|ftp)\:\/\/([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?\$';
        
        $validCdn = array();
        $inValidCdn = array();
        if (!empty($_POST['save']) && $cdns = AxcotoUtil::g($_POST['cdns'], '')) {
            
            $cdns = explode("\n", $cdns);
            foreach ($cdns as $cdn) {
                $cdn = str_replace(array("\r", "\n", "\t"), '', $cdn);
                if (empty($cdn)) {
                    $inValidCdn[] = $cdn;
                    continue;
                }
                if (!AxcotoUtil::isValidUrl($cdn)) {
                    $inValidCdn[] = $cdn;
                    continue;
                }
                if (substr($cdn, strlen($cdn) - 1, 1) == '/') {

                } else {
                    $cdn = $cdn . '/';
                }
                $validCdn[] = $cdn;
            }
            $validCdn = (string) json_encode($validCdn);
            update_option(AxcotoEasyCdn::singleton()->optionName, $validCdn);
        }

        $cdns = get_option(AxcotoEasyCdn::singleton()->optionName, false);
        $cdns = json_decode($cdns);

        include AxcotoEasyCdn::singleton()->pluginPath . '/templates/front.php';
    }

}
