<commit_before><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: site_links.php
| Author: <NAME> (Chan)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "../maincore.php";
require_once THEMES."templates/admin_header.php";

class SiteLinks_Admin extends PHPFusion\SiteLinks {

    private static $siteLinksAdmin_instance = NULL;
    private $data = array(
        'link_id' => 0,
        'link_name' => '',
        'link_url' => '',
        'link_icon' => '',
        'link_cat' => 0,
        'link_language' => LANGUAGE,
        'link_visibility' => 0,
        'link_status' => 0,
        'link_order' => 0,
        'link_position' => 1,
        'link_position_id' => 0,
        'link_window' => 0,
    );
    private $language_opts = array();
    private $link_index = array();
    private static $default_display = 16;
    private $form_action = '';

    private function __construct() {
        $this->aidlink = fusion_get_aidlink();
        $this->locale = fusion_get_locale("", LOCALE.LOCALESET."admin/sitelinks.php");
        $this->language_opts = fusion_get_enabled_languages();
        $this->link_index = dbquery_tree(DB_SITE_LINKS, 'link_id', 'link_cat');
        $_GET['link_id'] = isset($_GET['link_id']) && isnum($_GET['link_id']) ? $_GET['link_id'] : 0;
        $_GET['link_cat'] = isset($_GET['link_cat']) && isnum($_GET['link_cat']) ? $_GET['link_cat'] : 0;
        $_GET['action'] = isset($_GET['action']) ? $_GET['action'] : '';
        if (isset($_GET['action'])) {
            switch ($_GET['action']) {
                case 'edit':
                    $this->data = self::get_sitelinks($_GET['link_id']);
                    $this->data['link_position_id'] = 0;
                    if (!$this->data['link_id']) {
                        redirect(FUSION_SELF.$this->aidlink);
                    }
                    $this->form_action = FUSION_SELF.$this->aidlink."&amp;action=edit&amp;section=nform&amp;link_id=".$_GET['link_id']."&amp;link_cat=".$_GET['link_cat'];
                    \PHPFusion\BreadCrumbs::getInstance()->addBreadCrumb(['link' => $this->form_action, 'title' => $this->locale['SL_0011']]);
                    break;
                case 'delete':
                    $result = self::delete_sitelinks($_GET['link_id']);
                    if ($result) {
                        addNotice("success", $this->locale['SL_0017']);
                        redirect(FUSION_SELF.$this->aidlink);
                    }
                    break;
                default:
                    $this->form_action = FUSION_SELF.$this->aidlink."&amp;section=link_form";
                    \PHPFusion\BreadCrumbs::getInstance()->addBreadCrumb(['link' => $this->form_action, 'title' => (isset($_GET['ref']) && $_GET['ref'] == 'link_form' ? $this->locale['SL_0010'] : $this->locale['SL_0012'])]);
                    break;
            }
        }
        add_to_head("<script type='text/javascript' src='".INCLUDES."jquery/jquery-ui.js'></script>");
        add_to_jquery("
		$('#site-links').sortable({
			handle : '.handle',
			placeholder: 'state-highlight',
			connectWith: '.connected',
			scroll: true,
			axis: 'y',
			update: function () {
				var ul = $(this),
                order = ul.sortable('serialize'),
                i = 0;
                $.ajax({
			        url: '".ADMIN."includes/site_links_updater.php".$this->aidlink."',
                    type: 'GET',
                    dataType: 'json',
                    data : order,
                    success: function(e){
                        console.log(e);
                        if (e.status == 200) {
                        new PNotify({
                            title: '".fusion_get_locale('SL_0016', LOCALE.LOCALESET."admin/sitelinks.php")."',
                            text: '',
                            icon: 'notify_icon n-attention',
                            animation: 'fade',
                            width: 'auto',
                            delay: '3000'
                        });

                        ul.find('.num').each(function(i) {
					    $(this).text(i+1);
                        });
                        ul.find('li').removeClass('tbl2').removeClass('tbl1');
                        ul.find('li:odd').addClass('tbl2');
                        ul.find('li:even').addClass('tbl1');
                        window.setTimeout('closeDiv();',2500);
                        }
                    },
                    error: function(result) {
                        new PNotify({
                            title: '".fusion_get_locale('error_preview', LOCALE.LOCALESET."admin/html_buttons.php")."',
                            text: '".fusion_get_locale('error_preview_text', LOCALE.LOCALESET."admin/html_buttons.php")."',
                            icon: 'notify_icon n-attention',
                            animation: 'fade',
                            width: 'auto',
                            delay: '3000'
                        });
                    }
    			});
			}
		});

		function checkLinkPosition(val) {
            if (val == 4) {
                $('#link_position_id').prop('disabled', false).show();
            } else {
                $('#link_position_id').prop('disabled', true).hide();
            }
        }
		");

        /**
         * @silent upgrade Sitelinks for folks
         * @todo: remove after 9.02 releases
         */
        if (!column_exists(DB_SITE_LINKS, 'link_status')) {
            dbquery("ALTER TABLE ".DB_SITE_LINKS." ADD link_status TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' AFTER link_position");
            addNotice("success", "Your site links table is upgraded. This message will self destruct in 3 seconds.");
        }

    }

    public static function Administration() {
        if (empty(self::$siteLinksAdmin_instance)) {
            self::$siteLinksAdmin_instance = new SiteLinks_Admin();
        }

        return self::$siteLinksAdmin_instance;
    }

    public function display_administration_form() {
        pageAccess("SL");

        if (isset($_POST['cancel'])) {
            redirect(FUSION_SELF.$this->aidlink);
        }

        $title = $this->locale['SL_0001'];
        if (isset($_GET['ref']) && $_GET['ref'] == "link_form") {
            $title = isset($_GET['link_id']) && $this->verify_sitelinks($_GET['link_id']) ? $this->locale['SL_0011'] : $this->locale['SL_0010'];
        }

        $master_title['title'][] = $title;
        $master_title['id'][] = "links";
        $master_title['icon'][] = '';

        $master_title['title'][] = $this->locale['SL_0041'];<commit_msg>Close #1296 - removed Site Links upgrade script.<commit_after><?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) PHP-Fusion Inc
| https://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: site_links.php
| Author: <NAME> (Chan)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "../maincore.php";
require_once THEMES."templates/admin_header.php";

class SiteLinks_Admin extends PHPFusion\SiteLinks {

    private static $siteLinksAdmin_instance = NULL;
    private $data = array(
        'link_id' => 0,
        'link_name' => '',
        'link_url' => '',
        'link_icon' => '',
        'link_cat' => 0,
        'link_language' => LANGUAGE,
        'link_visibility' => 0,
        'link_status' => 0,
        'link_order' => 0,
        'link_position' => 1,
        'link_position_id' => 0,
        'link_window' => 0,
    );
    private $language_opts = array();
    private $link_index = array();
    private static $default_display = 16;
    private $form_action = '';

    private function __construct() {
        $this->aidlink = fusion_get_aidlink();
        $this->locale = fusion_get_locale("", LOCALE.LOCALESET."admin/sitelinks.php");
        $this->language_opts = fusion_get_enabled_languages();
        $this->link_index = dbquery_tree(DB_SITE_LINKS, 'link_id', 'link_cat');
        $_GET['link_id'] = isset($_GET['link_id']) && isnum($_GET['link_id']) ? $_GET['link_id'] : 0;
        $_GET['link_cat'] = isset($_GET['link_cat']) && isnum($_GET['link_cat']) ? $_GET['link_cat'] : 0;
        $_GET['action'] = isset($_GET['action']) ? $_GET['action'] : '';
        if (isset($_GET['action'])) {
            switch ($_GET['action']) {
                case 'edit':
                    $this->data = self::get_sitelinks($_GET['link_id']);
                    $this->data['link_position_id'] = 0;
                    if (!$this->data['link_id']) {
                        redirect(FUSION_SELF.$this->aidlink);
                    }
                    $this->form_action = FUSION_SELF.$this->aidlink."&amp;action=edit&amp;section=nform&amp;link_id=".$_GET['link_id']."&amp;link_cat=".$_GET['link_cat'];
                    \PHPFusion\BreadCrumbs::getInstance()->addBreadCrumb(['link' => $this->form_action, 'title' => $this->locale['SL_0011']]);
                    break;
                case 'delete':
                    $result = self::delete_sitelinks($_GET['link_id']);
                    if ($result) {
                        addNotice("success", $this->locale['SL_0017']);
                        redirect(FUSION_SELF.$this->aidlink);
                    }
                    break;
                default:
                    $this->form_action = FUSION_SELF.$this->aidlink."&amp;section=link_form";
                    \PHPFusion\BreadCrumbs::getInstance()->addBreadCrumb(['link' => $this->form_action, 'title' => (isset($_GET['ref']) && $_GET['ref'] == 'link_form' ? $this->locale['SL_0010'] : $this->locale['SL_0012'])]);
                    break;
            }
        }
        add_to_head("<script type='text/javascript' src='".INCLUDES."jquery/jquery-ui.js'></script>");
        add_to_jquery("
		$('#site-links').sortable({
			handle : '.handle',
			placeholder: 'state-highlight',
			connectWith: '.connected',
			scroll: true,
			axis: 'y',
			update: function () {
				var ul = $(this),
                order = ul.sortable('serialize'),
                i = 0;
                $.ajax({
			        url: '".ADMIN."includes/site_links_updater.php".$this->aidlink."',
                    type: 'GET',
                    dataType: 'json',
                    data : order,
                    success: function(e){
                        console.log(e);
                        if (e.status == 200) {
                        new PNotify({
                            title: '".fusion_get_locale('SL_0016', LOCALE.LOCALESET."admin/sitelinks.php")."',
                            text: '',
                            icon: 'notify_icon n-attention',
                            animation: 'fade',
                            width: 'auto',
                            delay: '3000'
                        });

                        ul.find('.num').each(function(i) {
					    $(this).text(i+1);
                        });
                        ul.find('li').removeClass('tbl2').removeClass('tbl1');
                        ul.find('li:odd').addClass('tbl2');
                        ul.find('li:even').addClass('tbl1');
                        window.setTimeout('closeDiv();',2500);
                        }
                    },
                    error: function(result) {
                        new PNotify({
                            title: '".fusion_get_locale('error_preview', LOCALE.LOCALESET."admin/html_buttons.php")."',
                            text: '".fusion_get_locale('error_preview_text', LOCALE.LOCALESET."admin/html_buttons.php")."',
                            icon: 'notify_icon n-attention',
                            animation: 'fade',
                            width: 'auto',
                            delay: '3000'
                        });
                    }
    			});
			}
		});

		function checkLinkPosition(val) {
            if (val == 4) {
                $('#link_position_id').prop('disabled', false).show();
            } else {
                $('#link_position_id').prop('disabled', true).hide();
            }
        }
		");
    }

    public static function Administration() {
        if (empty(self::$siteLinksAdmin_instance)) {
            self::$siteLinksAdmin_instance = new SiteLinks_Admin();
        }

        return self::$siteLinksAdmin_instance;
    }

    public function display_administration_form() {
        pageAccess("SL");

        if (isset($_POST['cancel'])) {
            redirect(FUSION_SELF.$this->aidlink);
        }

        $title = $this->locale['SL_0001'];
        if (isset($_GET['ref']) && $_GET['ref'] == "link_form") {
            $title = isset($_GET['link_id']) && $this->verify_sitelinks($_GET['link_id']) ? $this->locale['SL_0011'] : $this->locale['SL_0010'];
        }

        $master_title['title'][] = $title;
        $master_title['id'][] = "links";
        $master_title['icon'][] = '';

        $master_title['title'][] = $this->locale['SL_0041'];
{'fraction_non_alphanumeric': 0.18764188422247446, 'fraction_numerical': 0.010783200908059024, 'mean_word_length': 1.6633289249952767, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 97, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2986545', 'n_tokens_mistral': 4144, 'n_tokens_neox': 3837, 'n_words': 666}