diff --git a/content/style.css b/content/style.css new file mode 100644 index 0000000..e85b1fa --- /dev/null +++ b/content/style.css @@ -0,0 +1,14 @@ +/** + * This is your custom stylesheet + * + * It overrides the default one + */ +#breadcrumb { + padding-left:0; +} +#breadcrumb li { + display:inline; +} +#breadcrumb li:not(:last-child)::after { + content: ' >'; +} diff --git a/domain.php b/domain.php index 42eb738..56f4604 100644 --- a/domain.php +++ b/domain.php @@ -1,67 +1,49 @@ . /* * This is the domain edit page */ // load framework require 'load.php'; // wanted domain list( $domain_name ) = url_parts( 1 ); // retrieve domain $domain = ( new DomainAPI() ) ->whereDomainName( $domain_name ) ->whereDomainIsEditable() ->queryRow(); // 404? $domain or PageNotFound::spawn(); // spawn header Header::spawn( [ - 'title' => sprintf( - __( "Domain: %s" ), - "" . esc_html( $domain_name ) . "" - ), + 'title-prefix' => __( "Domain" ), + 'title' => $domain_name, ] ); // spawn the domain template template( 'domain', [ - 'mailboxes' => - $domain->factoryMailbox() - ->select( [ - 'domain_name', - 'mailbox_username', - 'mailbox_receive', - ] ) - ->queryGenerator(), - - 'mailfowards' => - $domain->factoryMailfoward() - ->select( [ - 'domain_name', - 'mailfoward_source', - 'mailfoward_destination', - ] ) - ->queryGenerator() + 'domain' => $domain, ] ); // spawn the footer Footer::spawn(); diff --git a/include/class-Breadcrumb.php b/include/class-Breadcrumb.php new file mode 100644 index 0000000..80a326d --- /dev/null +++ b/include/class-Breadcrumb.php @@ -0,0 +1,71 @@ +. + +/** + * Handle a breadcrumb with the related microdata + * + * @url https://schema.org/BreadcrumbList + * @url https://developers.google.com/search/docs/data-types/breadcrumb + */ +class Breadcrumb { + + /** + * Spawn the breadcrumb + * + * @param $uid string|null Starting menu uid + * @param $title string|null Starting title + * @param $parent_uid string|null Parent menu uid + */ + public static function spawn( $breadcrumbs ) { + ?> + + url ? $entry->getSitePage() : null; + return self::link( $i, $url, $entry->name ); + } + + /** + * Spawn a link with microdata + */ + public static function link( $i, $url, $title ) { + echo '
  • '; + if( $url ) { + echo ''; + echo '' . esc_html( $title ) . ''; + echo ''; + } else { + echo '' . _esc_html( $title ) . ''; + } + echo ''; + echo "
  • \n"; + } + +} diff --git a/include/class-Domain.php b/include/class-Domain.php index bf65865..086de37 100644 --- a/include/class-Domain.php +++ b/include/class-Domain.php @@ -1,68 +1,77 @@ . /** * A domain handled by the user */ class Domain extends Queried { const T = 'domain'; const UID = 'domain_name'; public function __construct() { $this->integers( 'domain_ID' ); $this->booleans( 'domain_active' ); $this->dates( 'domain_born', 'domain_expiration' ); } /** * Get domain ID * * @return int */ public function getDomainID() { return $this->get( 'domain_ID' ); } + /** + * Get domain name + * + * @return string + */ + public function getDomainName() { + return $this->get( 'domain_name' ); + } + /** * Get the domain edit URl * * @return string */ public function getDomainPermalink( $absolute = false ) { return ROOT . '/domain.php/' . $this->get( 'domain_name' ); } /** * Factory mailbox from this domain * * @return MailboxFullAPI */ public function factoryMailbox() { return ( new MailboxFullAPI() )->whereDomain( $this ); } /** * Factory e-mail foward from this domain * * @return MailfowardFullAPI */ public function factoryMailfoward() { return ( new MailfowardFullAPI() )->whereDomain( $this ); } } diff --git a/include/class-Header.php b/include/class-Header.php index 5f0548a..e4e81aa 100644 --- a/include/class-Header.php +++ b/include/class-Header.php @@ -1,88 +1,91 @@ . /** * The header of the web page */ class Header { /** * Header arguments * * It's public because the Footer reads it. * * @var array */ public static $args; /** * Spawn the header to standard output * * @param $args mixed Can be the page UID, or arguments where: * uid: menu UID like 'home' * title: document title */ public static function spawn( $args = [] ) { // store arguments for future reads self::$args = & $args; // shortcut if( is_string( $args ) ) { $args = [ 'uid' => $args ]; } // eventually retrieve actual page UID if( ! isset( $args[ 'uid' ] ) ) { $args[ 'uid' ] = self::actualPageUID(); } // retrieve page informations $page = isset( $args[ 'uid' ] ) ? get_menu_entry( $args[ 'uid' ] ) : null; // populate the page informations if( $page ) { $args = array_replace( [ 'title' => $page->name, ], $args ); + } else { + $args[ 'uid' ] = null; } // populate default arguments $args = array_replace( [ - 'container' => true, - 'sidebar' => true, + 'container' => true, + 'sidebar' => true, + 'breadcrumb' => [], ], $args ); // charset is usually UTF-8 header( 'Content-Type: text/html; charset=' . CHARSET ); // spawn header template - template( 'header', $args ); + template( 'header', [ 'args' => $args ] ); } /** * Get the default page UID * * @return string */ public static function actualPageUID() { $page = basename( $_SERVER[ 'SCRIPT_NAME' ] ); return str_replace( '.php', '', $page ); } } diff --git a/include/functions.php b/include/functions.php index 1a2a758..f6f32ff 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,110 +1,138 @@ . /** * Require a certain page from the template directory * * @param $name string page name (to be sanitized) * @param $args mixed arguments to be passed to the page scope */ function template( $name, $args = [] ) { extract( $args ); require TEMPLATE_PATH . __ . "$name.php"; } /** * Print an e-mail (safe for bots) * * @param $email string */ function email_blur( $email ) { $dot = strip_tags( __( " dot " ) ); $at = strip_tags( __( " at " ) ); $email = esc_html( $email ); echo str_replace( [ '.', '@' ], [ $dot, $at ], $email ); } /** * Send an e-mail to someone * * @param $subject string E-mail subject * @param $message string E-mail message * @param $to string E-mail recipient (from current logged-in user as default) */ function send_email( $subject, $message, $to = false ) { if( ! $to ) { if( ! is_logged() ) { die( "can't retrieve e-mail address from anon user" ); } $to = get_user( 'user_email' ); } return SMTPMail::instance() ->to( $to ) ->message( $subject, $message ) ->disconnect(); } /** * Require a certain permission * * @param $permission string An internal permission like 'edit-all-user' * @param $redirect boolean Enable or disable the redirect */ function require_permission( $permission, $redirect = true ) { if( ! has_permission( $permission ) ) { if( is_logged() ) { Header::spawn( [ 'title' => __( "Permission denied" ), ] ); Footer::spawn(); exit; } else { $login = get_menu_entry( 'login' ); $url = $login->getSitePage( URL ); if( $redirect && isset( $_SERVER[ 'REQUEST_URI' ] ) ) { $url = http_build_get_query( $url, [ 'redirect' => $_SERVER[ 'REQUEST_URI' ], ] ); } http_redirect( $url, 307 ); } } } /** * Check the POST action * * @param $action string e.g. 'save-domain' * @return bool */ function is_action( $action ) { return isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] === $action; } /** * Get URL parts * * @param $n */ function url_parts( $n ) { $parts = explode( _, $_SERVER[ 'PATH_INFO' ] ); array_shift( $parts ); if( count( $parts ) !== $n ) { BadRequest::spawn(); } return $parts; } + +/** + * Link to an existing page from the menu + * + * @param $uid string E.g. 'index' + * @param $args mixed Arguments + */ +function the_menu_link( $uid ) { + $page = get_menu_entry( $uid ); + the_link( $page->getSitePage(), $page->name, $args ); +} + +/** + * Link to a whatever page + * + * P.S. link() is a reserved function + * + * @param $url string + * @param $title string + * @param $args mixed Arguments + */ +function the_link( $url, $title, $args = [] ) { + template( 'link', [ + 'title' => $title, + 'url' => $url, + 'args' => $args, + ] ); +} diff --git a/index.php b/index.php index dbc0b94..e6999eb 100644 --- a/index.php +++ b/index.php @@ -1,74 +1,76 @@ . /* * This is the homepage of your hosting panel */ // load framework require 'load.php'; // require read permissions require_permission( 'read' ); // spawn header -Header::spawn(); +Header::spawn( [ + 'breadcrumb' => false, +] ); // user domains $domains = ( new DomainAPI() ) ->select( [ 'domain.domain_ID', 'domain_name', 'domain_active', ] ) ->whereDomainIsEditable() ->orderBy( 'domain_name' ) ->queryGenerator(); ?>

    valid() ): ?>

    . // include path define_default( 'INCLUDE_PATH', ABSPATH . __ . 'include' ); // template path define_default( 'TEMPLATE_PATH', ABSPATH . __ . 'template' ); // autoload classes from the /include directory spl_autoload_register( function( $name ) { $path = INCLUDE_PATH . __ . "class-$name.php"; if( is_file( $path ) ) { require $path; } } ); // load common functions require INCLUDE_PATH . __ . 'functions.php'; // jquery URL // provided by the libjs-jquery package as default define_default( 'JQUERY_URL', '/javascript/jquery/jquery.min.js' ); // Bootstrap CSS/JavaScript files without trailing slash // provided by the libjs-bootstrap package as default define_default( 'BOOTSTRAP_DIR_URL', '/javascript/bootstrap' ); // path to the Net SMTP class // provided by the php-net-smtp package as default define_default( 'NET_SMTP', '/usr/share/php/Net/SMTP.php' ); // register JavaScript/CSS files -register_js( 'jquery', JQUERY_URL ); -register_js( 'bootstrap', BOOTSTRAP_DIR_URL . '/js/bootstrap.min.js' ); -register_css( 'bootstrap', BOOTSTRAP_DIR_URL . '/css/bootstrap.min.css' ); +register_js( 'jquery', JQUERY_URL ); +register_js( 'bootstrap', BOOTSTRAP_DIR_URL . '/js/bootstrap.min.js' ); +register_css( 'bootstrap', BOOTSTRAP_DIR_URL . '/css/bootstrap.min.css' ); +register_css( 'custom-css', ROOT . '/content/style.css' ); // GNU Gettext i18n define( 'GETTEXT_DOMAIN', 'reyboz-hosting-panel' ); define( 'GETTEXT_DIRECTORY', 'l10n' ); define( 'GETTEXT_DEFAULT_ENCODE', CHARSET ); // UTF-8 // common strings define_default( 'SITE_NAME', "Boz Libre Hosting Panel" ); define_default( 'CONTACT_EMAIL', 'support@' . DOMAIN ); define_default( 'REPO_URL', 'https://github.com/valerio-bozzolan/boz-libre-hosting-panel' ); // register web pages -call_user_func( function () { - $logged = is_logged(); - $show_to_user = $logged ? null : 'hidden'; - $show_to_anon = ! $logged ? null : 'hidden'; - add_menu_entries( [ - new MenuEntry( 'index', '', __( "Dashboard" ), $show_to_user ), - new MenuEntry( 'login', 'login.php', __( "Login" ), $show_to_anon ), - new MenuEntry( 'logout', 'logout.php', __( "Logout" ), $show_to_user ), - new MenuEntry( 'password-reset', 'password-reset.php', __( "Password reset" ), $show_to_anon ), - ] ); -} ); +add_menu_entries( [ + new MenuEntry( 'index', '/', __( "Dashboard" ) ), + new MenuEntry( 'login', 'login.php', __( "Login" ) ), + new MenuEntry( 'logout', 'logout.php', __( "Logout" ) ), + new MenuEntry( 'password-reset', 'password-reset.php', __( "Password reset" ) ), +] ); // permissions register_permissions( 'user', [ 'read', 'backend', ] ); inherit_permissions( 'admin', 'user', [ 'edit-user-all', 'edit-email-all', 'edit-domain-all', ] ); diff --git a/logout.php b/logout.php index 6510afe..e0459d8 100644 --- a/logout.php +++ b/logout.php @@ -1,47 +1,42 @@ . /* * This is the logout page */ // load framework require 'load.php'; // spawn header Header::spawn( [ 'title' => __( "Please confirm logout" ), ] ); // check login if( is_action( 'logout' ) ) { logout(); } // require to be logged, but do not redirect again here otherwise require_permission( 'read', false ); -?> -

    +// spawn the logout template +template( 'logout' ); -
    - -
    - -. /* * This is the mailbox edit page */ // load framework require 'load.php'; // wanted domain and mailbox username list( $domain_name, $mailbox_username ) = url_parts( 2 ); // retrieve domain $mailbox = ( new MailboxFullAPI() ) ->select( [ 'domain.domain_ID', 'domain.domain_name', 'domain.domain_active', 'mailbox_username', ] ) ->whereStr( 'domain_name', $domain_name ) ->whereStr( 'mailbox_username', $mailbox_username ) ->whereDomainIsEditable() ->queryRow(); // 404? $mailbox or PageNotFound::spawn(); $password = null; if( is_action( 'mailbox-password-reset' ) ) { $password = $mailbox->updateMailboxPassword(); } // spawn header Header::spawn( [ - 'title' => sprintf( - __( "Mailbox: %s" ), - "" . esc_html( $mailbox->getMailboxAddress() ) . "" - ), + 'title-prefix' => __( "Mailbox" ), + 'title' => $mailbox->getMailboxAddress(), + 'breadcrumb' => [ + new MenuEntry( null, $mailbox->getDomainPermalink(), $mailbox->getDomainName() ), + ], ] ); // spawn the page content template( 'mailbox', [ 'mailbox' => $mailbox, 'password' => $password, ] ); // spawn the footer Footer::spawn(); diff --git a/mailfoward.php b/mailfoward.php index 3539442..b2fd733 100644 --- a/mailfoward.php +++ b/mailfoward.php @@ -1,72 +1,73 @@ . /* * This is the single e-mail fowarding edit page */ // load framework require 'load.php'; // wanted domain and mail fowarding source list( $domain_name, $mailfoward_source ) = url_parts( 2 ); // retrieve domain $mailfoward = ( new MailfowardFullAPI ) ->select( [ 'domain.domain_ID', 'domain.domain_name', 'domain.domain_active', 'mailfoward_source', 'mailfoward_destination', ] ) ->whereDomainName( $domain_name ) ->whereMailfowardSource( $mailfoward_source ) ->whereDomainIsEditable() ->queryRow(); // 404? $mailfoward or PageNotFound::spawn(); // handle save destination action if( is_action( 'mailfoward-save-destination' ) ) { $destination = $_POST[ 'mailfoward_destination' ]; if( filter_var( $destination, FILTER_VALIDATE_EMAIL ) ) { $mailfoward->update( [ new DBCol( 'mailfoward_destination', $destination, 's' ), ] ); // POST/redirect/GET - http_redirect( URL . $_SERVER[ 'REQUEST_URI' ] ); + http_redirect( URL . $_SERVER[ 'REQUEST_URI' ], 303 ); } } // spawn header Header::spawn( [ - 'title' => sprintf( - _( "Mailfoward: %s" ), - "" . esc_html( $mailfoward->getMailfowardAddress() ) . "" - ), + 'title-prefix' => __( "Mail fowarding" ), + 'title' => $mailfoward->getMailfowardAddress(), + 'breadcrumb' => [ + new MenuEntry( null, $mailfoward->getDomainPermalink(), $mailfoward->getDomainName() ), + ], ] ); // spawn the page content template( 'mailfoward', [ 'mailfoward' => $mailfoward, ] ); // spawn the footer Footer::spawn(); diff --git a/template/sidebar.php b/template/breadcrumb.php similarity index 67% copy from template/sidebar.php copy to template/breadcrumb.php index c59da84..9e36951 100644 --- a/template/sidebar.php +++ b/template/breadcrumb.php @@ -1,36 +1,37 @@ . /* - * This is the template for the website sidebar + * This is the template for the website breadcrumb navigation menu * * Called from: - * template/footer.php + * template/header.php */ // unuseful when load directly defined( 'BOZ_PHP' ) or die; -?> - -

    - +// add home to the breadcrumb +array_unshift( $args[ 'breadcrumb' ], get_menu_entry( 'index' ) ); + +// add "this page" to the breadcrumb +if( $args[ 'uid' ] !== 'index' ) { + $args[ 'breadcrumb' ][] = new MenuEntry( null, null, $args[ 'title' ] ); +} +?> - + diff --git a/template/domain.php b/template/domain.php index 5e8b84d..5b80c6d 100644 --- a/template/domain.php +++ b/template/domain.php @@ -1,34 +1,32 @@ . /* * This is the template for the website domain dashboard page * * Called from: * domain.php */ // unuseful when load directly defined( 'BOZ_PHP' ) or die; // spawn the mailboxes list -template( 'mailboxes', [ 'mailboxes' => $mailboxes ] ); +template( 'mailboxes', [ 'domain' => $domain ] ); // spawn the mail fowardings list -template( 'mailfowards', [ 'mailfowards' => $mailfowards ] ); - - +template( 'mailfowards', [ 'domain' => $domain ] ); diff --git a/template/footer.php b/template/footer.php index 7aab1f5..9a5124f 100644 --- a/template/footer.php +++ b/template/footer.php @@ -1,77 +1,77 @@ . /* * This is the template for the website footer * * Called from: * include/class-Footer.php */ // unuseful when load directly defined( 'BOZ_PHP' ) or die; load_module( 'footer' ); ?> - +
    - +


    diff --git a/template/header.php b/template/header.php index 5b5875f..fe738dd 100644 --- a/template/header.php +++ b/template/header.php @@ -1,59 +1,69 @@ . /* * This is the template for the website header * * Called from: * include/class-Header.php */ // unuseful when load directly defined( 'BOZ_PHP' ) or die; // load Bootstrap stuff -enqueue_js( 'jquery' ); -enqueue_js( 'bootstrap' ); -enqueue_css( 'bootstrap' ); +enqueue_js( 'jquery' ); +enqueue_js( 'bootstrap' ); +enqueue_css( 'bootstrap' ); +enqueue_css( 'custom-css' ); ?> - <?php echo strip_tags( $title ) ?> - <?php echo strip_tags( SITE_NAME ) ?> + <?php echo strip_tags( $args[ 'title' ] ) ?> - <?php echo strip_tags( SITE_NAME ) ?>

    -

    + + +

    :

    + +

    + + + + $args ] ) ?> +
    - +
    - +
    diff --git a/template/domain.php b/template/link.php similarity index 73% copy from template/domain.php copy to template/link.php index 5e8b84d..4839ad7 100644 --- a/template/domain.php +++ b/template/link.php @@ -1,34 +1,33 @@ . /* - * This is the template for the website domain dashboard page + * This is the template for a link * - * Called from: - * domain.php + * Called from + * include/functions.php - the_link() function + * + * Available variables: + * $title string e.g. "Home" + * $href string e.g. "/" + * $args mixed */ // unuseful when load directly defined( 'BOZ_PHP' ) or die; -// spawn the mailboxes list -template( 'mailboxes', [ 'mailboxes' => $mailboxes ] ); - -// spawn the mail fowardings list -template( 'mailfowards', [ 'mailfowards' => $mailfowards ] ); - - +?> diff --git a/template/sidebar.php b/template/logout.php similarity index 72% copy from template/sidebar.php copy to template/logout.php index c59da84..e7817d0 100644 --- a/template/sidebar.php +++ b/template/logout.php @@ -1,36 +1,33 @@ . /* - * This is the template for the website sidebar + * This is the template for the logout page * - * Called from: - * template/footer.php + * Called from + * logout.php */ // unuseful when load directly defined( 'BOZ_PHP' ) or die; ?> - -

    - +

    - +
    + +
    diff --git a/template/mailboxes.php b/template/mailboxes.php index 390a033..753c945 100644 --- a/template/mailboxes.php +++ b/template/mailboxes.php @@ -1,50 +1,58 @@ . /* * This is the template for the mailboxes list * * Called from: * template/domain.php */ // unuseful when load directly defined( 'BOZ_PHP' ) or die; +// domain mailboxes +$mailboxes = $domain->factoryMailbox() + ->select( [ + 'domain_name', + 'mailbox_username', + 'mailbox_receive', + ] ) + ->queryGenerator(); ?> valid() ): ?>

    • getMailboxPermalink(), $mailbox->getMailboxAddress() ) ?>
    diff --git a/template/mailfoward.php b/template/mailfoward.php index d377b5f..cc22a7f 100644 --- a/template/mailfoward.php +++ b/template/mailfoward.php @@ -1,43 +1,43 @@ . /* * This is the template for a single e-mail fowarding * * Called from: * mailfoward.php */ // unuseful when load directly defined( 'BOZ_PHP' ) or die; ?>


    - getMailfowardDestination() ) ?> /> + getMailfowardDestination() ) ?> />

    diff --git a/template/mailfowards.php b/template/mailfowards.php index cdbdff9..6637bcd 100644 --- a/template/mailfowards.php +++ b/template/mailfowards.php @@ -1,49 +1,57 @@ . /* * This is the template for the mailboxes list * * Called from: * template/domain.php */ // unuseful when load directly defined( 'BOZ_PHP' ) or die; +// domain mail fowardings +$mailfowards = $domain->factoryMailfoward() + ->select( [ + 'domain_name', + 'mailfoward_source', + 'mailfoward_destination', + ] ) + ->queryGenerator(); ?> valid() ): ?>

    • getMailfowardPermalink(), $mailfoward->getMailfowardAddress() ) ?>
    diff --git a/template/sidebar.php b/template/sidebar.php index c59da84..d951844 100644 --- a/template/sidebar.php +++ b/template/sidebar.php @@ -1,36 +1,39 @@ . /* * This is the template for the website sidebar * * Called from: * template/footer.php */ // unuseful when load directly defined( 'BOZ_PHP' ) or die; ?>

    + + + + -