/**
 *
 * Render the output of the link-library-search shortcode
 *
 * @param $libraryoptions   Selected library settings array
 *
 * @return                  List of categories output for browser
 */
function RenderLinkLibrarySearchForm($libraryoptions)
{
    $libraryoptions = wp_parse_args($libraryoptions, ll_reset_options(1, 'list', 'return'));
    extract($libraryoptions);
    $output = '<form method="GET" id="llsearch"';
    if (!empty($searchresultsaddress)) {
        $output .= ' action="' . $searchresultsaddress . '"';
    }
    $output .= ">\n";
    $output .= "<div>\n";
    $output .= "<input type='text' onfocus=\"this.value=''\" value='" . $searchfieldtext . "' name='searchll' id='searchll' />";
    //$output .= "<input type='hidden' value='" . get_the_ID() . "' name='page_id' id='page_id' />";
    $output .= "<input type='submit' value='" . $searchlabel . "' />";
    $output .= "</div>\n";
    $output .= "</form>\n\n";
    $output .= "<script type='text/javascript'>\n";
    $output .= "jQuery(document).ready(function () {\n";
    $output .= "\tjQuery('#llsearch').submit(function () {\n";
    $output .= "\t\tif (jQuery('#searchll').val() == '" . $searchfieldtext . "') {\n";
    $output .= "\t\t\treturn false;\n";
    $output .= "\t\t}\n";
    $output .= "\t\telse {\n";
    $output .= "\t\t\treturn true;\n";
    $output .= "\t\t}\n";
    $output .= "\t});\n";
    $output .= "});\n";
    $output .= "</script>";
    return $output;
}
/**
 *
 * Render the output of the link-library-search shortcode
 *
 * @param $libraryoptions   Selected library settings array
 *
 * @return                  List of categories output for browser
 */
function RenderLinkLibrarySearchForm($libraryoptions)
{
    $libraryoptions = wp_parse_args($libraryoptions, ll_reset_options(1, 'list', 'return'));
    extract($libraryoptions);
    if (empty($searchlabel)) {
        $searchlabel = __('Search', 'link-library');
    }
    $output = '<form method="get" id="llsearch"';
    if (!empty($searchresultsaddress)) {
        $output .= ' action="' . $searchresultsaddress . '"';
    }
    $output .= ">\n";
    $output .= "<div>\n";
    $output .= "<input type='text' onfocus=\"this.value=''\" value='" . $searchlabel . "...' name='searchll' id='searchll' />";
    $output .= "<input type='hidden' value='" . get_the_ID() . "' name='page_id' id='page_id' />";
    $output .= "<input type='submit' value='" . $searchlabel . "' />";
    $output .= "</div>\n";
    $output .= "</form>\n\n";
    return $output;
}
Esempio n. 3
0
function link_library_process_user_submission($my_link_library_plugin)
{
    check_admin_referer('LL_ADDLINK_FORM');
    require_once ABSPATH . '/wp-admin/includes/taxonomy.php';
    load_plugin_textdomain('link-library', false, dirname(plugin_basename(__FILE__)) . '/languages');
    global $wpdb;
    $settings = isset($_POST['settingsid']) ? $_POST['settingsid'] : 1;
    $settingsname = 'LinkLibraryPP' . $settings;
    $options = get_option($settingsname);
    $options = wp_parse_args($options, ll_reset_options(1, 'list', 'return'));
    $genoptions = get_option('LinkLibraryGeneral');
    $genoptions = wp_parse_args($genoptions, ll_reset_gen_settings('return'));
    $valid = true;
    $requiredcheck = true;
    $message = "";
    $captureddata = array();
    $captureddata['link_category'] = isset($_POST['link_category']) ? $_POST['link_category'] : '';
    $captureddata['link_user_category'] = isset($_POST['link_user_category']) ? $_POST['link_user_category'] : '';
    $captureddata['link_description'] = isset($_POST['link_description']) ? $_POST['link_description'] : '';
    $captureddata['link_textfield'] = isset($_POST['link_textfield']) ? $_POST['link_textfield'] : '';
    $captureddata['link_name'] = isset($_POST['link_name']) ? $_POST['link_name'] : '';
    $captureddata['link_url'] = isset($_POST['link_url']) ? $_POST['link_url'] : '';
    $captureddata['link_rss'] = isset($_POST['link_rss']) ? $_POST['link_rss'] : '';
    $captureddata['link_notes'] = isset($_POST['link_notes']) ? $_POST['link_notes'] : '';
    $captureddata['ll_secondwebaddr'] = isset($_POST['ll_secondwebaddr']) ? $_POST['ll_secondwebaddr'] : '';
    $captureddata['ll_telephone'] = isset($_POST['ll_telephone']) ? $_POST['ll_telephone'] : '';
    $captureddata['ll_email'] = isset($_POST['ll_email']) ? $_POST['ll_email'] : '';
    $captureddata['ll_reciprocal'] = isset($_POST['ll_reciprocal']) ? $_POST['ll_reciprocal'] : '';
    $captureddata['ll_submittername'] = isset($_POST['ll_submittername']) ? $_POST['ll_submittername'] : '';
    $captureddata['ll_submitteremail'] = isset($_POST['ll_submitteremail']) ? $_POST['ll_submitteremail'] : '';
    $captureddata['ll_submittercomment'] = isset($_POST['ll_submittercomment']) ? $_POST['ll_submittercomment'] : '';
    $captureddata['ll_customcaptchaanswer'] = isset($_POST['ll_customcaptchaanswer']) ? $_POST['ll_customcaptchaanswer'] : '';
    if ('required' == $options['showaddlinkrss'] && empty($captureddata['link_rss'])) {
        $requiredcheck = false;
        $message = 11;
    } else {
        if ('required' == $options['showaddlinkdesc'] && empty($captureddata['link_description'])) {
            $requiredcheck = false;
            $message = 12;
        } else {
            if ('required' == $options['showaddlinknotes'] && empty($captureddata['link_notes'])) {
                $requiredcheck = false;
                $message = 13;
            } else {
                if ('required' == $options['showaddlinkreciprocal'] && empty($captureddata['ll_reciprocal'])) {
                    $requiredcheck = false;
                    $message = 14;
                } else {
                    if ('required' == $options['showaddlinksecondurl'] && empty($captureddata['ll_secondwebaddr'])) {
                        $requiredcheck = false;
                        $message = 15;
                    } else {
                        if ('required' == $options['showaddlinktelephone'] && empty($captureddata['ll_telephone'])) {
                            $requiredcheck = false;
                            $message = 16;
                        } else {
                            if ('required' == $options['showaddlinkemail'] && empty($captureddata['ll_email'])) {
                                $requiredcheck = false;
                                $message = 17;
                            } else {
                                if ('required' == $options['showlinksubmittername'] && empty($captureddata['ll_submittername'])) {
                                    $requiredcheck = false;
                                    $message = 18;
                                } else {
                                    if ('required' == $options['showaddlinksubmitteremail'] && empty($captureddata['ll_submitteremail'])) {
                                        $requiredcheck = false;
                                        $message = 19;
                                    } else {
                                        if ('required' == $options['showlinksubmittercomment'] && empty($captureddata['ll_submittercomment'])) {
                                            $requiredcheck = false;
                                            $message = 20;
                                        } else {
                                            if ('required' == $options['showuserlargedescription'] && empty($captureddata['link_textfield'])) {
                                                $requiredcheck = false;
                                                $message = 21;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($captureddata['link_name'] != '' && $requiredcheck) {
        if (($options['addlinkakismet'] || $genoptions['addlinkakismet']) && ll_akismet_is_available()) {
            $c = array();
            $c['comment_author'] = $captureddata['ll_submittername'];
            $c['comment_author_email'] = $captureddata['ll_submitteremail'];
            $c['comment_author_url'] = $captureddata['link_url'];
            if ('required' == $options['showaddlinkdesc'] || 'show' == $options['showaddlinkdesc']) {
                $c['comment_content'] = $captureddata['link_description'];
            } elseif ('required' == $options['showaddlinknotes'] || 'show' == $options['showaddlinknotes']) {
                $c['comment_content'] = $captureddata['link_notes'];
            } elseif ('required' == $options['showuserlargedescription'] || 'show' == $options['showuserlargedescription']) {
                $c['comment_content'] = $captureddata['link_textfield'];
            }
            $c['blog'] = get_option('home');
            $c['blog_lang'] = get_locale();
            $c['blog_charset'] = get_option('blog_charset');
            $c['user_ip'] = $_SERVER['REMOTE_ADDR'];
            $c['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
            $c['referrer'] = $_SERVER['HTTP_REFERER'];
            $c['comment_type'] = 'link-library';
            $ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW');
            foreach ($_SERVER as $key => $value) {
                if (!in_array($key, (array) $ignore)) {
                    $c["{$key}"] = $value;
                }
            }
            if (ll_akismet_comment_check($c)) {
                $valid = false;
                $message = 22;
            } else {
                $valid = true;
            }
        } elseif (($options['addlinkakismet'] || $genoptions['addlinkakismet']) && !ll_akismet_is_available()) {
            echo 'Akismet has been selected but is not available';
            die;
        }
        if ($options['showcaptcha'] && $valid) {
            $message = apply_filters('link_library_verify_captcha', '');
            if ($message > 0) {
                $valid = false;
            } else {
                $valid = true;
            }
        }
        if ($options['showcustomcaptcha'] == 'show' && $valid) {
            if ($captureddata['ll_customcaptchaanswer'] == '') {
                $valid = false;
                $message = 5;
            } else {
                if (strtolower($captureddata['ll_customcaptchaanswer']) == strtolower($options['customcaptchaanswer'])) {
                    $valid = true;
                } else {
                    $valid = false;
                    $message = 6;
                }
            }
        }
        if ($valid || $options['showcaptcha'] == false && $options['showcustomcaptcha'] == 'hide' && $options['addlinkakismet'] == false) {
            $existinglinkquery = "SELECT * from " . $my_link_library_plugin->db_prefix() . "links l where l.link_name = '" . $captureddata['link_name'] . "' ";
            if ($options['addlinknoaddress'] == false || $options['addlinknoaddress'] == true && $captureddata['link_url'] != "") {
                $existinglinkquery .= " or l.link_url = 'http://" . $captureddata['link_url'] . "'";
            }
            $existinglink = $wpdb->get_var($existinglinkquery);
            if ($existinglink == "" && ($options['addlinknoaddress'] == false && $captureddata['link_url'] != "" || $options['addlinknoaddress'] == true)) {
                if ($captureddata['link_category'] == 'new' && $captureddata['link_user_category'] != '') {
                    $existingcatquery = "SELECT t.term_id FROM " . $my_link_library_plugin->db_prefix() . "terms t, " . $my_link_library_plugin->db_prefix() . "term_taxonomy tt ";
                    $existingcatquery .= "WHERE t.name = '" . $captureddata['link_user_category'] . "' AND t.term_id = tt.term_id AND tt.taxonomy = 'link_category'";
                    $existingcat = $wpdb->get_var($existingcatquery);
                    if (!$existingcat) {
                        $newlinkcatdata = array("cat_name" => $captureddata['link_user_category'], "category_description" => "", "category_nicename" => sanitize_text_field($captureddata['link_user_category']));
                        $newlinkcat = wp_insert_category($newlinkcatdata);
                        $newcatarray = array("term_id" => $newlinkcat);
                        $newcattype = array("taxonomy" => 'link_category');
                        $wpdb->update($my_link_library_plugin->db_prefix() . 'term_taxonomy', $newcattype, $newcatarray);
                        $newlinkcat = array($newlinkcat);
                    } else {
                        $newlinkcat = array($existingcat);
                    }
                    $message = 8;
                    $validcat = true;
                } elseif ($captureddata['link_category'] == 'new' && $captureddata['link_user_category'] == '') {
                    $message = 7;
                    $validcat = false;
                } else {
                    $newlinkcat = array($captureddata['link_category']);
                    $message = 8;
                    $validcat = true;
                }
                if ($validcat == true) {
                    if ($options['showuserlinks'] == false) {
                        if ($options['showifreciprocalvalid']) {
                            $reciprocal_return = $my_link_library_plugin->CheckReciprocalLink($genoptions['recipcheckaddress'], $captureddata['ll_reciprocal']);
                            if ($reciprocal_return == 'exists_found') {
                                $newlinkdesc = $captureddata['link_description'];
                                $newlinkvisibility = 'Y';
                                unset($message);
                            } else {
                                $newlinkdesc = '(LinkLibrary:AwaitingModeration:RemoveTextToApprove)' . $captureddata['link_description'];
                                $newlinkvisibility = 'N';
                            }
                        } else {
                            $newlinkdesc = '(LinkLibrary:AwaitingModeration:RemoveTextToApprove)' . $captureddata['link_description'];
                            $newlinkvisibility = 'N';
                        }
                    } else {
                        $newlinkdesc = $captureddata['link_description'];
                        $newlinkvisibility = 'Y';
                        unset($message);
                    }
                    $username = '';
                    if ($options['storelinksubmitter'] == true) {
                        global $current_user;
                        get_currentuserinfo();
                        if ($current_user) {
                            $username = $current_user->user_login;
                        }
                    }
                    $newlink = array("link_name" => esc_html(stripslashes($captureddata['link_name'])), "link_url" => esc_html(stripslashes($captureddata['link_url'])), "link_rss" => esc_html(stripslashes($captureddata['link_rss'])), "link_description" => esc_html(stripslashes($newlinkdesc)), "link_notes" => esc_html(stripslashes($captureddata['link_notes'])), "link_category" => $newlinkcat, "link_visible" => $newlinkvisibility, 'link_target' => $options['linktarget'], 'link_updated' => date("Y-m-d H:i", current_time('timestamp')));
                    $newlinkid = $my_link_library_plugin->link_library_insert_link($newlink, false, $options['addlinknoaddress']);
                    $extradatatable = $my_link_library_plugin->db_prefix() . "links_extrainfo";
                    $wpdb->insert($extradatatable, array('link_id' => $newlinkid, 'link_second_url' => $captureddata['ll_secondwebaddr'], 'link_telephone' => $captureddata['ll_telephone'], 'link_email' => $captureddata['ll_email'], 'link_reciprocal' => $captureddata['ll_reciprocal'], 'link_submitter' => isset($username) ? $username : null, 'link_submitter_name' => $captureddata['ll_submittername'], 'link_submitter_email' => $captureddata['ll_submitteremail'], 'link_textfield' => $captureddata['link_textfield'], 'link_no_follow' => '', 'link_featured' => '', 'link_manual_updated' => ''));
                    if ($options['emailnewlink']) {
                        if ($genoptions['moderatoremail'] != '') {
                            $adminmail = $genoptions['moderatoremail'];
                        } else {
                            $adminmail = get_option('admin_email');
                        }
                        $link_category_name = '';
                        if ($captureddata['link_category'] == 'new' && $captureddata['link_user_category'] != '') {
                            $link_category_name = $captureddata['link_user_category'];
                        } else {
                            if (!empty($captureddata['link_category'])) {
                                $find_cat_name_query = "SELECT t.name FROM " . $my_link_library_plugin->db_prefix() . "terms t, " . $my_link_library_plugin->db_prefix() . "term_taxonomy tt ";
                                $find_cat_name_query .= "WHERE t.term_id = '" . $captureddata['link_category'] . "' AND t.term_id = tt.term_id AND tt.taxonomy = 'link_category'";
                                $link_category_name = $wpdb->get_var($find_cat_name_query);
                            }
                        }
                        $headers = "MIME-Version: 1.0\r\n";
                        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
                        $emailmessage = __('A user submitted a new link to your Wordpress Link database.', 'link-library') . "<br /><br />";
                        $emailmessage .= __('Link Name', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_name'])) . "<br />";
                        $emailmessage .= __('Link Address', 'link-library') . ": <a href='" . esc_html(stripslashes($captureddata['link_url'])) . "'>" . esc_html(stripslashes($captureddata['link_url'])) . "</a><br />";
                        if ('show' == $options['showaddlinkrss'] || 'required' == $options['showaddlinkrss']) {
                            $emailmessage .= __('Link RSS', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_rss'])) . "<br />";
                        }
                        if ('show' == $options['showaddlinkdesc'] || 'required' == $options['showaddlinkdesc']) {
                            $emailmessage .= __('Link Description', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_description'])) . "<br />";
                        }
                        if ('show' == $options['showuserlargedescription'] || 'required' == $options['showuserlargedescription']) {
                            $emailmessage .= __('Link Large Description', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_textfield'])) . "<br />";
                        }
                        if ('show' == $options['showaddlinknotes'] || 'required' == $options['showaddlinknotes']) {
                            $emailmessage .= __('Link Notes', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_notes'])) . "<br />";
                        }
                        $emailmessage .= __('Link Category', 'link-library') . ": " . $link_category_name . " ( " . $captureddata['link_category'] . " )<br /><br />";
                        if ('show' == $options['showaddlinkreciprocal'] || 'required' == $options['showaddlinkreciprocal']) {
                            $emailmessage .= __('Reciprocal Link', 'link-library') . ": " . $captureddata['ll_reciprocal'] . "<br /><br />";
                        }
                        if ('show' == $options['showaddlinksecondurl'] || 'required' == $options['showaddlinksecondurl']) {
                            $emailmessage .= __('Link Secondary Address', 'link-library') . ": " . $captureddata['ll_secondwebaddr'] . "<br /><br />";
                        }
                        if ('show' == $options['showaddlinktelephone'] || 'required' == $options['showaddlinktelephone']) {
                            $emailmessage .= __('Link Telephone', 'link-library') . ": " . $captureddata['ll_telephone'] . "<br /><br />";
                        }
                        if ('show' == $options['showaddlinkemail'] || 'required' == $options['showaddlinkemail']) {
                            $emailmessage .= __('Link E-mail', 'link-library') . ": " . $captureddata['ll_email'] . "<br /><br />";
                        }
                        if ('show' == $options['showlinksubmittername'] || 'required' == $options['showlinksubmittername']) {
                            $emailmessage .= __('Link Submitter Name', 'link-library') . ": " . $captureddata['ll_submittername'] . "<br /><br />";
                        }
                        if ('show' == $options['showaddlinksubmitteremail'] || 'required' == $options['showaddlinksubmitteremail']) {
                            $emailmessage .= __('Link Submitter E-mail', 'link-library') . ": " . $captureddata['ll_submitteremail'] . "<br /><br />";
                        }
                        if ('show' == $options['showlinksubmittercomment'] || 'required' == $options['showlinksubmittercomment']) {
                            $emailmessage .= __('Link Comment', 'link-library') . ": " . $captureddata['ll_submittercomment'] . "<br /><br />";
                        }
                        if ($options['showuserlinks'] == false) {
                            $emailmessage .= '<a href="' . esc_url(add_query_arg('s', 'LinkLibrary%3AAwaitingModeration%3ARemoveTextToApprove', admin_url('link-manager.php'))) . '">Moderate new links</a>';
                        } elseif ($options['showuserlinks'] == true) {
                            $emailmessage .= '<a href="' . admin_url('link-manager.php') . '">View links</a>';
                        }
                        $emailmessage .= "<br /><br />" . __('Message generated by', 'link-library') . " <a href='http://ylefebvre.ca/wordpress-plugins/link-library/'>Link Library</a> for Wordpress";
                        if (!isset($emailtitle) || $emailtitle == '') {
                            $emailtitle = stripslashes($genoptions['moderationnotificationtitle']);
                            $emailtitle = str_replace('%linkname%', esc_html(stripslashes($captureddata['link_name'])), $emailtitle);
                        } else {
                            $emailtitle = htmlspecialchars_decode(get_option('blogname'), ENT_QUOTES) . " - " . __('New link added', 'link-library') . ": " . htmlspecialchars($captureddata['link_name']);
                        }
                        wp_mail($adminmail, $emailtitle, $emailmessage, $headers);
                    }
                    if ($options['emailsubmitter'] && !empty($captureddata['ll_submitteremail']) && is_email($captureddata['ll_submitteremail'])) {
                        $submitteremailheaders = "MIME-Version: 1.0\r\n";
                        $submitteremailheaders .= "Content-type: text/html; charset=iso-8859-1\r\n";
                        $submitteremailtitle = __('Link Submission Confirmation', 'link-library');
                        $submitteremailmessage = '<p>' . __('Thank you for your link submission on ', 'link-library');
                        $submitteremailmessage .= esc_html(get_bloginfo('name')) . '</p>';
                        if ($options['showuserlinks'] == false) {
                            $submitteremailmessage .= '<p>' . __('Your link will appear once approved by the site administrator.', 'link-library') . '</p>';
                        } elseif ($options['showuserlinks'] == true) {
                            $submitteremailmessage .= '<p>' . __('Your link will immediately be added to the site.', 'link-library') . '</p>';
                        }
                        $submitteremailmessage .= __('Link Name', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_name'])) . "<br />";
                        $submitteremailmessage .= __('Link Address', 'link-library') . ": <a href='" . esc_html(stripslashes($captureddata['link_url'])) . "'>" . esc_html(stripslashes($captureddata['link_url'])) . "</a><br />";
                        if ('show' == $options['showaddlinkrss'] || 'required' == $options['showaddlinkrss']) {
                            $submitteremailmessage .= __('Link RSS', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_rss'])) . "<br />";
                        }
                        if ('show' == $options['showaddlinkdesc'] || 'required' == $options['showaddlinkdesc']) {
                            $submitteremailmessage .= __('Link Description', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_description'])) . "<br />";
                        }
                        if ('show' == $options['showuserlargedescription'] || 'required' == $options['showuserlargedescription']) {
                            $submitteremailmessage .= __('Link Large Description', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_textfield'])) . "<br />";
                        }
                        if ('show' == $options['showaddlinknotes'] || 'required' == $options['showaddlinknotes']) {
                            $submitteremailmessage .= __('Link Notes', 'link-library') . ": " . esc_html(stripslashes($captureddata['link_notes'])) . "<br />";
                        }
                        $submitteremailmessage .= __('Link Category', 'link-library') . ": " . $link_category_name . " ( " . $captureddata['link_category'] . " )<br /><br />";
                        if ('show' == $options['showaddlinkreciprocal'] || 'required' == $options['showaddlinkreciprocal']) {
                            $submitteremailmessage .= __('Reciprocal Link', 'link-library') . ": " . $captureddata['ll_reciprocal'] . "<br /><br />";
                        }
                        if ('show' == $options['showaddlinksecondurl'] || 'required' == $options['showaddlinksecondurl']) {
                            $submitteremailmessage .= __('Link Secondary Address', 'link-library') . ": " . $captureddata['ll_secondwebaddr'] . "<br /><br />";
                        }
                        if ('show' == $options['showaddlinktelephone'] || 'required' == $options['showaddlinktelephone']) {
                            $submitteremailmessage .= __('Link Telephone', 'link-library') . ": " . $captureddata['ll_telephone'] . "<br /><br />";
                        }
                        if ('show' == $options['showaddlinkemail'] || 'required' == $options['showaddlinkemail']) {
                            $submitteremailmessage .= __('Link E-mail', 'link-library') . ": " . $captureddata['ll_email'] . "<br /><br />";
                        }
                        if ('show' == $options['showaddlinksubmittername'] || 'required' == $options['showaddlinksubmittername']) {
                            $submitteremailmessage .= __('Link Submitter Name', 'link-library') . ": " . $captureddata['ll_submittername'] . "<br /><br />";
                        }
                        if ('show' == $options['showaddlinksubmitteremail'] || 'required' == $options['showaddlinksubmitteremail']) {
                            $submitteremailmessage .= __('Link Submitter E-mail', 'link-library') . ": " . $captureddata['ll_submitteremail'] . "<br /><br />";
                        }
                        if ('show' == $options['showlinksubmittercomment'] || 'required' == $options['showlinksubmittercomment']) {
                            $submitteremailmessage .= __('Link Comment', 'link-library') . ": " . $captureddata['ll_submittercomment'] . "<br /><br />";
                        }
                        wp_mail($captureddata['ll_submitteremail'], $submitteremailtitle, $submitteremailmessage, $submitteremailheaders);
                    }
                }
            } elseif ($existinglink == "" && ($options['addlinknoaddress'] == false && $captureddata['link_url'] == "")) {
                $message = 9;
            } else {
                $message = 10;
            }
        }
    }
    $redirectaddress = '';
    if (isset($_POST['thankyouurl']) && $_POST['thankyouurl'] != '' && $requiredcheck && $valid) {
        $redirectaddress = $_POST['thankyouurl'];
    } else {
        if (isset($_POST['pageid']) && is_numeric($_POST['pageid'])) {
            $redirectaddress = get_permalink($_POST['pageid']);
        }
    }
    $redirectaddress = esc_url_raw(add_query_arg('addlinkmessage', $message, $redirectaddress));
    if ($valid == false && ($options['showcaptcha'] == true || $options['showcustomcaptcha'] == 'show')) {
        if (isset($_POST['link_name']) && $_POST['link_name'] != '') {
            $redirectaddress = add_query_arg('addlinkname', rawurlencode($captureddata['link_name']), $redirectaddress);
        }
        if (isset($_POST['link_url']) && $_POST['link_url'] != '') {
            $redirectaddress = add_query_arg('addlinkurl', rawurlencode($captureddata['link_url']), $redirectaddress);
        }
        if (isset($_POST['link_category']) && $_POST['link_category'] != '') {
            $redirectaddress = add_query_arg('addlinkcat', rawurlencode($captureddata['link_category']), $redirectaddress);
        }
        if (isset($_POST['link_user_category']) && $_POST['link_user_category'] != '') {
            $redirectaddress = add_query_arg('addlinkusercat', rawurlencode($captureddata['link_user_category']), $redirectaddress);
        }
        if (isset($_POST['link_description']) && $_POST['link_description'] != '') {
            $redirectaddress = add_query_arg('addlinkdesc', rawurlencode($captureddata['link_description']), $redirectaddress);
        }
        if (isset($_POST['link_textfield']) && $_POST['link_textfield'] != '') {
            $redirectaddress = add_query_arg('addlinktextfield', rawurlencode($captureddata['link_textfield']), $redirectaddress);
        }
        if (isset($_POST['link_rss']) && $_POST['link_rss'] != '') {
            $redirectaddress = add_query_arg('addlinkrss', rawurlencode($captureddata['link_rss']), $redirectaddress);
        }
        if (isset($_POST['link_notes']) && $_POST['link_notes'] != '') {
            $redirectaddress = add_query_arg('addlinknotes', rawurlencode($captureddata['link_notes']), $redirectaddress);
        }
        if (isset($_POST['ll_secondwebaddr']) && $_POST['ll_secondwebaddr'] != '') {
            $redirectaddress = add_query_arg('addlinksecondurl', rawurlencode($captureddata['ll_secondwebaddr']), $redirectaddress);
        }
        if (isset($_POST['ll_telephone']) && $_POST['ll_telephone'] != '') {
            $redirectaddress = add_query_arg('addlinktelephone', rawurlencode($captureddata['ll_telephone']), $redirectaddress);
        }
        if (isset($_POST['ll_email']) && $_POST['ll_email'] != '') {
            $redirectaddress = add_query_arg('addlinkemail', rawurlencode($captureddata['ll_email']), $redirectaddress);
        }
        if (isset($_POST['ll_reciprocal']) && $_POST['ll_reciprocal'] != '') {
            $redirectaddress = add_query_arg('addlinkreciprocal', rawurlencode($captureddata['ll_reciprocal']), $redirectaddress);
        }
        if (isset($_POST['ll_submittername']) && $_POST['ll_submittername'] != '') {
            $redirectaddress = add_query_arg('addlinksubmitname', rawurlencode($captureddata['ll_submittername']), $redirectaddress);
        }
        if (isset($_POST['ll_submitteremail']) && $_POST['ll_submitteremail'] != '') {
            $redirectaddress = add_query_arg('addlinksubmitemail', rawurlencode($captureddata['ll_submitteremail']), $redirectaddress);
        }
        if (isset($_POST['ll_submittercomment']) && $_POST['ll_submittercomment'] != '') {
            $redirectaddress = add_query_arg('addlinksubmitcomment', rawurlencode($captureddata['ll_submittercomment']), $redirectaddress);
        }
        if (isset($_POST['ll_customcaptchaanswer']) && $_POST['ll_customcaptchaanswer'] != '') {
            $redirectaddress = add_query_arg('addlinkcustomcaptcha', rawurlencode($captureddata['ll_customcaptchaanswer']), $redirectaddress);
        }
        $redirectaddress = esc_url_raw($redirectaddress);
    }
    wp_redirect($redirectaddress);
    exit;
}
Esempio n. 4
0
 function __construct()
 {
     // Functions to be called when plugin is activated and deactivated
     register_activation_hook(__FILE__, array($this, 'll_install'));
     register_deactivation_hook(__FILE__, array($this, 'll_uninstall'));
     $newoptions = get_option('LinkLibraryPP1', '');
     $genoptions = get_option('LinkLibraryGeneral', '');
     if (empty($newoptions)) {
         global $my_link_library_plugin_admin;
         if (empty($my_link_library_plugin_admin)) {
             require plugin_dir_path(__FILE__) . 'link-library-admin.php';
             $my_link_library_plugin_admin = new link_library_plugin_admin();
         }
         ll_reset_options(1, 'list', 'return_and_set');
         if (empty($genoptions)) {
             ll_reset_gen_settings('return_and_set');
         }
     }
     // Add short codes
     add_shortcode('link-library', array($this, 'link_library_func'));
     add_shortcode('link-library-cats', array($this, 'link_library_cats_func'));
     add_shortcode('cats-link-library', array($this, 'link_library_cats_func'));
     add_shortcode('link-library-search', array($this, 'link_library_search_func'));
     add_shortcode('search-link-library', array($this, 'link_library_search_func'));
     add_shortcode('link-library-addlink', array($this, 'link_library_addlink_func'));
     add_shortcode('addlink-link-library', array($this, 'link_library_addlink_func'));
     add_shortcode('link-library-addlinkcustommsg', array($this, 'link_library_addlink_func'));
     add_shortcode('addlinkcustommsg-link-library', array($this, 'link_library_addlink_func'));
     add_shortcode('link-library-count', array($this, 'link_library_count_func'));
     // Function to determine if Link Library is used on a page before printing headers
     // the_posts gets triggered before wp_head
     add_filter('the_posts', array($this, 'conditionally_add_scripts_and_styles'));
     // Function to print information in page header when plugin present
     add_action('wp_head', array($this, 'll_rss_link'));
     add_filter('wp_title', array($this, 'll_title_creator'));
     add_action('init', array($this, 'links_rss'));
     // Re-write rules filters to allow for custom permalinks
     add_filter('rewrite_rules_array', array($this, 'll_insertMyRewriteRules'));
     add_filter('query_vars', array($this, 'll_insertMyRewriteQueryVars'));
     add_action('template_redirect', array($this, 'll_template_redirect'));
     add_action('wp_ajax_link_library_tracker', array($this, 'link_library_ajax_tracker'));
     add_action('wp_ajax_nopriv_link_library_tracker', array($this, 'link_library_ajax_tracker'));
     add_action('wp_ajax_link_library_ajax_update', array($this, 'link_library_func'));
     add_action('wp_ajax_nopriv_link_library_ajax_update', array($this, 'link_library_func'));
     add_action('wp_ajax_link_library_generate_image', array($this, 'link_library_generate_image'));
     add_action('wp_ajax_nopriv_link_library_generate_image', array($this, 'link_library_generate_image'));
     add_action('wp_ajax_link_library_popup_content', array($this, 'll_popup_content'));
     add_action('wp_ajax_nopriv_link_library_popup_content', array($this, 'll_popup_content'));
     add_action('wp_enqueue_scripts', array($this, 'll_register_script'));
     // Load text domain for translation of admin pages and text strings
     load_plugin_textdomain('link-library', false, dirname(plugin_basename(__FILE__)) . '/languages');
     add_filter('kses_allowed_protocols', array($this, 'll_add_protocols'));
     global $wpdb;
     $wpdb->linkcategorymeta = $wpdb->get_blog_prefix() . 'linkcategorymeta';
 }
/**
 *
 * Render the output of the link-library shortcode
 *
 * @param $LLPluginClass    Link Library main plugin class
 * @param $generaloptions   General Plugin Settings
 * @param $libraryoptions   Selected library settings array
 * @param $settings         Settings ID
 * @return                  List of categories output for browser
 */
function RenderLinkLibrary($LLPluginClass, $generaloptions, $libraryoptions, $settings, $onlycount = 'false')
{
    global $wpdb;
    $generaloptions = wp_parse_args($generaloptions, ll_reset_gen_settings('return'));
    extract($generaloptions);
    $libraryoptions = wp_parse_args($libraryoptions, ll_reset_options(1, 'list', 'return'));
    extract($libraryoptions);
    /* This case will only happen if the user entered bad data in the admin page or if someone is trying to inject bad data in SQL query */
    if (!empty($categorylist)) {
        $categorylistarray = explode(',', $categorylist);
        if (true === array_filter($categorylistarray, 'is_int')) {
            return 'List of requested categories is invalid. Please go back to Link Library admin panel to correct.';
        }
    }
    if (!empty($excludecategorylist)) {
        $excludecategorylistarray = explode(',', $excludecategorylist);
        if (true === array_filter($excludecategorylistarray, 'is_int')) {
            return 'List of requested excluded categories is invalid. Please go back to Link Library admin panel to correct.';
        }
    }
    $validdirections = array('ASC', 'DESC');
    $linkeditoruser = current_user_can('manage_links');
    $output = "\n<!-- Beginning of Link Library Output -->\n\n";
    $currentcategory = 1;
    $categoryname = '';
    $mode = 'normal';
    if ($showonecatonly && 'AJAX' == $showonecatmode && isset($AJAXcatid) && empty($AJAXcatid)) {
        $AJAXnocatset = true;
    } else {
        $AJAXnocatset = false;
    }
    if ($showonecatonly && 'AJAX' == $showonecatmode && isset($AJAXcatid) && !empty($AJAXcatid) && (!isset($_GET['searchll']) || empty($_GET['searchll']))) {
        $categorylist = $AJAXcatid;
    } elseif ($showonecatonly && 'HTMLGET' == $showonecatmode && isset($_GET['cat_id']) && (!isset($_GET['searchll']) || isset($_GET['searchll']) && empty($_GET['searchll']))) {
        $categorylist = intval($_GET['cat_id']);
        $AJAXcatid = $categorylist;
    } elseif ($showonecatonly && 'HTMLGETSLUG' == $showonecatmode && isset($_GET['cat']) && (!isset($_GET['searchll']) || isset($_GET['searchll']) && empty($_GET['searchll']))) {
        $categorysluglist = $_GET['cat'];
    } elseif ($showonecatonly && 'HTMLGETCATNAME' == $showonecatmode && isset($_GET['catname']) && (!isset($_GET['searchll']) || isset($_GET['searchll']) && empty($_GET['searchll']))) {
        $categorynamelist = $_GET['catname'];
    } elseif ($showonecatonly && 'HTMLGETPERM' == $showonecatmode && empty($_GET['searchll'])) {
        global $wp_query;
        $categoryname = $wp_query->query_vars['cat_name'];
        $AJAXcatid = $categoryname;
    } elseif ($showonecatonly && (!isset($AJAXcatid) || empty($AJAXcatid)) && !empty($defaultsinglecat) && (!isset($_GET['searchll']) || isset($_GET['searchll']) && empty($_GET['searchll']))) {
        $categorylist = $defaultsinglecat;
        $AJAXcatid = $categorylist;
    } elseif ($showonecatonly && (!isset($AJAXcatid) || empty($AJAXcatid)) && empty($defaultsinglecat) && empty($_GET['searchll'])) {
        $catquery = 'SELECT distinct t.name, t.term_id ';
        $catquery .= 'FROM ' . $LLPluginClass->db_prefix() . 'terms t ';
        $catquery .= 'LEFT JOIN ' . $LLPluginClass->db_prefix() . 'term_taxonomy tt ON (t.term_id = tt.term_id) ';
        $catquery .= 'LEFT JOIN ' . $LLPluginClass->db_prefix() . 'term_relationships tr ON (tt.term_taxonomy_id = tr.term_taxonomy_id) ';
        $catquery .= 'LEFT JOIN ' . $LLPluginClass->db_prefix() . 'links l ON (tr.object_id = l.link_id) ';
        $catquery .= 'LEFT JOIN ' . $LLPluginClass->db_prefix() . 'links_extrainfo le ON (l.link_id = le.link_id) ';
        $catquery .= 'WHERE tt.taxonomy = "link_category" ';
        if ($hide_if_empty) {
            $catquery .= 'AND l.link_id is not NULL AND l.link_description not like "%LinkLibrary:AwaitingModeration:RemoveTextToApprove%" ';
        }
        if (!empty($categorylist)) {
            $catquery .= ' AND t.term_id in (' . $categorylist . ')';
        }
        if (!empty($excludecategorylist)) {
            $catquery .= ' AND t.term_id not in (' . $excludecategorylist . ')';
        }
        if (false == $showinvisible && (false == $showinvisibleadmin || true == $showinvisibleadmin && !$linkeditoruser)) {
            $catquery .= ' AND l.link_visible != "N"';
        }
        $mode = 'normal';
        $catquery .= ' ORDER by ';
        if (!$combineresults) {
            if ('name' == $order) {
                $catquery .= ' name ' . (in_array($direction, $validdirections) ? $direction : 'ASC');
            } elseif ('id' == $order) {
                $catquery .= ' t.term_id ' . (in_array($direction, $validdirections) ? $direction : 'ASC');
            } elseif ('order' == $order) {
                $catquery .= ' t.term_order ' . (in_array($direction, $validdirections) ? $direction : 'ASC');
            } elseif ('catlist' == $order) {
                $catquery .= ' FIELD(t.term_id,' . $categorylist . ') ';
            }
            $catquery .= ', ';
        }
        if (true == $featuredfirst) {
            $catquery .= ' le.link_featured DESC, ';
        }
        if ('name' == $linkorder) {
            $catquery .= 'link_name ' . (in_array($linkdirection, $validdirections) ? $direction : 'ASC');
        } elseif ('id' == $linkorder) {
            $catquery .= 'link_id ' . (in_array($linkdirection, $validdirections) ? $direction : 'ASC');
        } elseif ('order' == $linkorder) {
            $catquery .= 'link_order ' . (in_array($linkdirection, $validdirections) ? $direction : 'ASC');
        } elseif ('date' == $linkorder) {
            $catquery .= 'link_updated ' . (in_array($linkdirection, $validdirections) ? $direction : 'ASC');
        }
        $catitems = $wpdb->get_results($catquery);
        if ($debugmode) {
            $output .= "\n<!-- AJAX Default Category Query: " . print_r($catquery, TRUE) . "-->\n\n";
            $output .= "\n<!-- AJAX Default Category Results: " . print_r($catitems, TRUE) . "-->\n\n";
        }
        if ($catitems) {
            $categorylist = $catitems[0]->term_id;
            $AJAXcatid = $categorylist;
        }
    }
    $searchterms = '';
    if (isset($_GET['searchll']) && !empty($_GET['searchll']) && empty($singlelinkid)) {
        $searchterms = array();
        $searchstring = $_GET['searchll'];
        $offset = 0;
        while (false !== strpos($searchstring, '"', $offset)) {
            if (0 == $offset) {
                $offset = strpos($searchstring, '"');
            } else {
                $endpos = strpos($searchstring, '"', $offset + 1);
                $searchterms[] = substr($searchstring, $offset + 1, $endpos - $offset - 2);
                $strlength = $endpos + 1 - ($offset + 1);
                $searchstring = substr_replace($searchstring, '', $offset - 1, $endpos + 2 - $offset);
                $offset = 0;
            }
        }
        if (!empty($searchstring)) {
            $searchterms = array_merge($searchterms, explode(" ", $searchstring));
        }
        if (!empty($searchterms)) {
            $mode = 'search';
        }
    }
    $currentcatletter = '';
    if ($cat_letter_filter != 'no') {
        require_once plugin_dir_path(__FILE__) . 'render-link-library-alpha-filter.php';
        $result = RenderLinkLibraryAlphaFilter($LLPluginClass, $generaloptions, $libraryoptions, $settings, $mode);
        $currentcatletter = $result['currentcatletter'];
        if ('beforelinks' == $cat_letter_filter || 'beforecatsandlinks' == $cat_letter_filter) {
            $output .= $result['output'];
        }
    }
    $linkquery = 'SELECT distinct *, l.link_id as proper_link_id, UNIX_TIMESTAMP(l.link_updated) as link_date, ';
    $linkquery .= 'IF (DATE_ADD(l.link_updated, INTERVAL 120 MINUTE) >= NOW(), 1,0) as recently_updated ';
    $linkquery .= 'FROM ' . $LLPluginClass->db_prefix() . 'terms t ';
    $linkquery .= 'LEFT JOIN ' . $LLPluginClass->db_prefix() . 'term_taxonomy tt ON (t.term_id = tt.term_id) ';
    $linkquery .= 'LEFT JOIN ' . $LLPluginClass->db_prefix() . 'term_relationships tr ON (tt.term_taxonomy_id = tr.term_taxonomy_id) ';
    $linkquery .= 'LEFT JOIN ' . $LLPluginClass->db_prefix() . 'links l ON (tr.object_id = l.link_id) ';
    $linkquery .= 'LEFT JOIN ' . $LLPluginClass->db_prefix() . 'links_extrainfo le ON (l.link_id = le.link_id) ';
    $linkquery .= 'WHERE tt.taxonomy = "link_category" ';
    if ($hide_if_empty) {
        $linkquery .= 'AND l.link_id is not NULL AND l.link_description not like "%LinkLibrary:AwaitingModeration:RemoveTextToApprove%" ';
    }
    if (!empty($currentcatletter) && $cat_letter_filter != 'no') {
        $linkquery .= ' AND substring(t.name, 1, 1) = "' . $currentcatletter . '" ';
    }
    if ((!empty($categorylist) || isset($_GET['cat_id'])) && empty($singlelinkid)) {
        $linkquery .= ' AND t.term_id in (' . $categorylist . ')';
    }
    if ((!empty($categorysluglist) || isset($_GET['cat'])) && empty($singlelinkid)) {
        $linkquery .= ' AND t.slug in ("' . $categorysluglist . '")';
    }
    if ((!empty($categorynamelist) || isset($_GET['catname'])) && empty($singlelinkid)) {
        $linkquery .= ' AND t.name in ("' . urldecode($categorynamelist) . '")';
    }
    if (isset($categoryname) && !empty($categoryname) && 'HTMLGETPERM' == $showonecatmode && empty($singlelinkid)) {
        $linkquery .= ' AND t.slug = "' . $categoryname . '"';
    }
    if (!empty($excludecategorylist) && empty($singlelinkid)) {
        $linkquery .= ' AND t.term_id not in (' . $excludecategorylist . ')';
    }
    if (!empty($singlelinkid) && intval($singlelinkid)) {
        $linkquery .= ' AND l.link_id = ' . $singlelinkid . ' ';
    }
    if (false == $showinvisible && (false == $showinvisibleadmin || true == $showinvisibleadmin && !$linkeditoruser)) {
        $linkquery .= ' AND l.link_visible != "N"';
    }
    if (!empty($searchterms)) {
        $mode = 'search';
        $termnb = 1;
        foreach ($searchterms as $searchterm) {
            if (!empty($searchterm)) {
                $searchterm = str_replace('--', '', $searchterm);
                $searchterm = str_replace(';', '', $searchterm);
                $searchterm = esc_html(stripslashes($searchterm));
                if (true == $searchterm) {
                    if (1 == $termnb) {
                        $linkquery .= ' AND (link_name like "%' . $searchterm . '%" ';
                        $termnb++;
                    } else {
                        $linkquery .= ' OR link_name like "%' . $searchterm . '%" ';
                    }
                    if (false == $hidecategorynames) {
                        $linkquery .= ' OR name like "%' . $searchterm . '%" ';
                    }
                    if ($shownotes) {
                        $linkquery .= ' OR link_notes like "%' . $searchterm . '%" ';
                    }
                    if ($showdescription) {
                        $linkquery .= ' OR link_description like "%' . $searchterm . '%" ';
                    }
                    if ($showlargedescription) {
                        $linkquery .= ' OR link_textfield like "%' . $searchterm . '%" ';
                    }
                }
            }
        }
        $linkquery .= ')';
    }
    $linkquery .= ' ORDER by ';
    if (!$combineresults) {
        if ('name' == $order) {
            $linkquery .= ' name ' . (in_array($direction, $validdirections) ? $direction : 'ASC');
        } elseif ('id' == $order) {
            $linkquery .= ' t.term_id ' . (in_array($direction, $validdirections) ? $direction : 'ASC');
        } elseif ('order' == $order) {
            $linkquery .= ' t.term_order ' . (in_array($direction, $validdirections) ? $direction : 'ASC');
        } elseif ('catlist' == $order) {
            $linkquery .= ' FIELD(t.term_id,' . $categorylist . ') ';
        }
        $linkquery .= ', ';
    }
    if ($featuredfirst) {
        $linkquery .= ' link_featured DESC, ';
    }
    if ('name' == $linkorder || 'random' == $linkorder) {
        $linkquery .= 'l.link_name ' . (in_array($linkdirection, $validdirections) ? $linkdirection : 'ASC');
    } elseif ('id' == $linkorder) {
        $linkquery .= 'l.link_id ' . (in_array($linkdirection, $validdirections) ? $linkdirection : 'ASC');
    } elseif ('order' == $linkorder) {
        $linkquery .= 'l.link_order ' . (in_array($linkdirection, $validdirections) ? $linkdirection : 'ASC');
    } elseif ('date' == $linkorder) {
        $linkquery .= 'l.link_updated ' . (in_array($linkdirection, $validdirections) ? $linkdirection : 'ASC');
    }
    if ($pagination && 'search' != $mode) {
        $linkitemsforcount = $wpdb->get_results($linkquery);
        $numberoflinks = count($linkitemsforcount);
        $quantity = $linksperpage + 1;
        if (isset($_POST['linkresultpage']) || isset($_GET['linkresultpage'])) {
            if (isset($_POST['linkresultpage'])) {
                $pagenumber = $_POST['linkresultpage'];
            } elseif (isset($_GET['linkresultpage'])) {
                $pagenumber = $_GET['linkresultpage'];
            }
            $startingitem = ($pagenumber - 1) * $linksperpage;
            $linkquery .= ' LIMIT ' . $startingitem . ', ' . $quantity;
        } else {
            $pagenumber = 1;
            $linkquery .= ' LIMIT 0, ' . $quantity;
        }
    }
    if (true == $debugmode) {
        $linkquerystarttime = microtime(true);
    }
    $linkitems = $wpdb->get_results($linkquery, ARRAY_A);
    if ($debugmode) {
        $output .= "\n<!-- Link Query: " . print_r($linkquery, TRUE) . "-->\n\n";
        $output .= "\n<!-- Link Results: " . print_r($linkitems, TRUE) . "-->\n\n";
        $output .= "\n<!-- Link Query Execution Time: " . (microtime(true) - $linkquerystarttime) . "-->\n\n";
    }
    if ($pagination) {
        if ($linksperpage == 0 || empty($linksperpage)) {
            $linksperpage = 5;
        }
        if (count($linkitems) > $linksperpage) {
            array_pop($linkitems);
            $nextpage = true;
        } else {
            $nextpage = false;
        }
        if (isset($numberoflinks)) {
            $preroundpages = $numberoflinks / $linksperpage;
            $numberofpages = ceil($preroundpages * 1) / 1;
        }
    }
    if ('random' == $linkorder) {
        shuffle($linkitems);
    }
    if (!empty($maxlinks)) {
        if (is_numeric($maxlinks)) {
            array_splice($linkitems, $maxlinks);
        }
    }
    if ($debugmode) {
        echo '<!-- showonecatmode: ' . $showonecatonly . ', AJAXnocatset: ' . $AJAXnocatset . ', nocatonstartup: ' . $nocatonstartup . '-->';
    }
    // Display links
    if ($linkitems && $showonecatonly && $AJAXnocatset && $nocatonstartup && !isset($_GET['searchll']) || empty($linkitems) && $nocatonstartup && empty($_GET['searchll'])) {
        $output .= "<div id='linklist" . $settings . "' class='linklist'>\n";
        $output .= '</div>';
    } elseif ($linkitems && $onlycount) {
        return count($linkitems);
    } elseif ($linkitems && !$onlycount) {
        $output .= "<div id='linklist" . $settings . "' class='linklist'>\n";
        if ($pagination && $mode != "search" && 'BEFORE' == $paginationposition) {
            $previouspagenumber = $pagenumber - 1;
            $nextpagenumber = $pagenumber + 1;
            $pageID = get_the_ID();
            if (empty($AJAXcatid) && !empty($categorysluglist)) {
                $AJAXcatid = $categorysluglist;
            }
            if (empty($AJAXcatid) && !empty($categorynamelist)) {
                $AJAXcatid = $categorynamelist;
            }
            $output .= link_library_display_pagination($previouspagenumber, $nextpagenumber, $numberofpages, $pagenumber, $showonecatonly, $showonecatmode, $AJAXcatid, $settings, $pageID, $currentcatletter);
        }
        if ('search' == $mode) {
            $output .= '<div class="resulttitle">' . __('Search Results for', 'link-library') . ' "' . esc_html(stripslashes($_GET['searchll'])) . '"</div>';
        }
        $currentcategoryid = -1;
        $xpath = $LLPluginClass->relativePath(dirname(__FILE__), ABSPATH);
        $linkcount = 0;
        foreach ($linkitems as $linkitem) {
            if (true == $debugmode) {
                $linkstarttime = microtime(true);
            }
            if ($currentcategoryid != $linkitem['term_id']) {
                if (-1 != $currentcategoryid && $showonecatonly && empty($_GET['searchll']) && !$combineresults) {
                    break;
                }
                if (-1 != $currentcategoryid && !$combineresults) {
                    // Close the last category
                    if ($displayastable) {
                        $output .= "\t</table>\n";
                    } else {
                        $output .= "\t</ul>\n";
                    }
                    if (!empty($catlistwrappers)) {
                        $output .= '</div>';
                    }
                    if (!empty($beforefirstlink)) {
                        $output .= stripslashes($afterlastlink);
                    }
                    if ($showlinksonclick) {
                        $output .= '</div>';
                    }
                    $output .= '</div>';
                    $currentcategory = $currentcategory + 1;
                }
                if (!$combineresults) {
                    $currentcategoryid = $linkitem['term_id'];
                    $output .= '<div class="LinkLibraryCat LinkLibraryCat' . $currentcategoryid . '">';
                    $linkcount = 0;
                    $catlink = '';
                    $cattext = '';
                    $catenddiv = '';
                    if (1 == $catlistwrappers) {
                        $output .= '<div class="' . $beforecatlist1 . '">';
                    } else {
                        if ($catlistwrappers == 2) {
                            $remainder = $currentcategory % $catlistwrappers;
                            switch ($remainder) {
                                case 0:
                                    $output .= '<div class="' . $beforecatlist2 . '">';
                                    break;
                                case 1:
                                    $output .= '<div class="' . $beforecatlist1 . '">';
                                    break;
                            }
                        } else {
                            if (3 == $catlistwrappers) {
                                $remainder = $currentcategory % $catlistwrappers;
                                switch ($remainder) {
                                    case 0:
                                        $output .= '<div class="' . $beforecatlist3 . '">';
                                        break;
                                    case 2:
                                        $output .= '<div class="' . $beforecatlist2 . '">';
                                        break;
                                    case 1:
                                        $output .= '<div class="' . $beforecatlist1 . '">';
                                        break;
                                }
                            }
                        }
                    }
                    // Display the category name
                    if (!$hidecategorynames || empty($hidecategorynames)) {
                        $caturl = get_metadata('linkcategory', $linkitem['term_id'], 'linkcaturl', true);
                        if ($catanchor) {
                            $cattext = '<div id="' . $linkitem['slug'] . '">';
                        } else {
                            $cattext = '';
                        }
                        if (!$divorheader) {
                            if ('search' == $mode) {
                                foreach ($searchterms as $searchterm) {
                                    $linkitem['name'] = link_library_highlight_phrase($linkitem['name'], $searchterm, '<span class="highlight_word">', '</span>');
                                }
                            }
                            $catlink = '<div class="' . $catnameoutput . '">';
                            if ('right' == $catdescpos || empty($catdescpos)) {
                                if (!empty($caturl)) {
                                    $catlink .= '<a href="' . link_library_add_http($caturl) . '" ';
                                    if (!empty($linktarget)) {
                                        $catlink .= ' target="' . $linktarget . '"';
                                    }
                                    $catlink .= '>';
                                }
                                $catlink .= $linkitem['name'];
                                if (!empty($caturl)) {
                                    $catlink .= '</a>';
                                }
                            }
                            if ($showcategorydesclinks) {
                                $catlink .= '<span class="linklistcatnamedesc">';
                                $linkitem['description'] = str_replace('[', '<', $linkitem['description']);
                                $linkitem['description'] = str_replace(']', '>', $linkitem['description']);
                                $catlink .= $linkitem['description'];
                                $catlink .= '</span>';
                            }
                            if ('left' == $catdescpos) {
                                if (!empty($caturl)) {
                                    $catlink .= '<a href="' . link_library_add_http($caturl) . '" ';
                                    if (!empty($linktarget)) {
                                        $catlink .= ' target="' . $linktarget . '"';
                                    }
                                    $catlink .= '>';
                                }
                                $catlink .= $linkitem['name'];
                                if (!empty($caturl)) {
                                    $catlink .= '</a>';
                                }
                            }
                            if ($showlinksonclick) {
                                $catlink .= '<span class="expandlinks" id="LinksInCat' . $linkitem['term_id'] . '">';
                                $catlink .= '<img src="';
                                if (!empty($expandiconpath)) {
                                    $catlink .= $expandiconpath;
                                } else {
                                    $catlink .= plugins_url('icons/expand-32.png', __FILE__);
                                }
                                $catlink .= '" />';
                                $catlink .= '</span>';
                            }
                            $catlink .= '</div>';
                        } else {
                            if ($divorheader) {
                                if ('search' == $mode) {
                                    foreach ($searchterms as $searchterm) {
                                        $linkitem['name'] = link_library_highlight_phrase($linkitem['name'], $searchterm, '<span class="highlight_word">', '</span>');
                                    }
                                }
                                $catlink = '<' . $catnameoutput . '>';
                                if ('right' == $catdescpos || empty($catdescpos)) {
                                    if (!empty($caturl)) {
                                        $catlink .= '<a href="' . link_library_add_http($caturl) . '" ';
                                        if (!empty($linktarget)) {
                                            $catlink .= ' target="' . $linktarget . '"';
                                        }
                                        $catlink .= '>';
                                    }
                                    $catlink .= $linkitem['name'];
                                    if (!empty($caturl)) {
                                        $catlink .= '</a>';
                                    }
                                }
                                if ($showcategorydesclinks) {
                                    $catlink .= '<span class="linklistcatnamedesc">';
                                    $linkitem['description'] = str_replace('[', '<', $linkitem['description']);
                                    $linkitem['description'] = str_replace(']', '>', $linkitem['description']);
                                    $catlink .= $linkitem['description'];
                                    $catlink .= '</span>';
                                }
                                if ('left' == $catdescpos) {
                                    if (!empty($caturl)) {
                                        $catlink .= '<a href="' . link_library_add_http($caturl) . '" ';
                                        if (!empty($linktarget)) {
                                            $catlink .= ' target="' . $linktarget . '"';
                                        }
                                        $catlink .= '>';
                                    }
                                    $catlink .= $linkitem['name'];
                                    if (!empty($caturl)) {
                                        $catlink .= '</a>';
                                    }
                                }
                                if ($showlinksonclick) {
                                    $catlink .= '<span class="expandlinks" id="LinksInCat' . $linkitem['term_id'] . '">';
                                    $catlink .= '<img src="';
                                    if (!empty($expandiconpath)) {
                                        $catlink .= $expandiconpath;
                                    } else {
                                        $catlink .= plugins_url('icons/expand-32.png', __FILE__);
                                    }
                                    $catlink .= '" />';
                                    $catlink .= '</span>';
                                }
                                $catlink .= '</' . $catnameoutput . '>';
                            }
                        }
                        if ($catanchor) {
                            $catenddiv = '</div>';
                        } else {
                            $catenddiv = '';
                        }
                    }
                    $output .= $cattext . $catlink . $catenddiv;
                    if ($showlinksonclick) {
                        $output .= '<div class="LinksInCat' . $currentcategoryid . ' LinksInCat">';
                    }
                }
                if ($displayastable && (!$combineresults || $combineresults && $linkcount == 0)) {
                    $catstartlist = "\n\t<table class='linklisttable'>\n";
                    if ($showcolumnheaders) {
                        $catstartlist .= '<div class="linklisttableheaders"><tr>';
                        if (!empty($linkheader)) {
                            $catstartlist .= '<th><div class="linklistcolumnheader">' . $linkheader . '</div></th>';
                        }
                        if (!empty($descheader)) {
                            $catstartlist .= '<th><div class="linklistcolumnheader">' . $descheader . '</div></th>';
                        }
                        if (!empty($notesheader)) {
                            $catstartlist .= '<th><div class="linklistcolumnheader">' . $notesheader . '</div></th>';
                        }
                        $catstartlist .= "</tr></div>\n";
                    } else {
                        $catstartlist .= '';
                    }
                } elseif (!$combineresults || $combineresults && $linkcount == 0) {
                    $catstartlist = "\n\t<ul>\n";
                } else {
                    $catstartlist = '';
                }
                $output .= $catstartlist;
                if (!empty($beforefirstlink)) {
                    $output .= stripslashes($beforefirstlink);
                }
            }
            $between = "\n";
            if ($rssfeedinline) {
                include_once ABSPATH . WPINC . '/feed.php';
            }
            if ($showuserlinks || strpos($linkitem['link_description'], 'LinkLibrary:AwaitingModeration:RemoveTextToApprove') == false) {
                $linkcount = $linkcount + 1;
                if ($linkaddfrequency > 0) {
                    if (($linkcount - 1) % $linkaddfrequency == 0) {
                        $output .= stripslashes($addbeforelink);
                    }
                }
                if (!isset($linkitem['recently_updated'])) {
                    $linkitem['recently_updated'] = false;
                }
                $output .= stripslashes($beforeitem);
                if ($showupdated && $linkitem['recently_updated']) {
                    $output .= get_option('links_recently_updated_prepend');
                }
                $the_link = '#';
                if (!empty($linkitem['link_url'])) {
                    $the_link = esc_html($linkitem['link_url']);
                }
                $the_second_link = '#';
                if (!empty($linkitem['link_second_url'])) {
                    $the_second_link = esc_html(stripslashes($linkitem['link_second_url']));
                }
                $rel = $linkitem['link_rel'];
                if (!empty($rel) && !$nofollow && !$linkitem['link_no_follow']) {
                    $rel = ' rel="' . $rel . '"';
                } elseif (!empty($rel) && ($nofollow || $linkitem['link_no_follow'])) {
                    $rel = ' rel="' . $rel . ' nofollow"';
                } elseif (empty($rel) && ($nofollow || $linkitem['link_no_follow'])) {
                    $rel = ' rel="nofollow"';
                }
                if ($use_html_tags) {
                    $descnotes = $linkitem['link_notes'];
                    $descnotes = str_replace('[', '<', $descnotes);
                    $descnotes = str_replace(']', '>', $descnotes);
                    $desc = $linkitem['link_description'];
                    $desc = str_replace("[", "<", $desc);
                    $desc = str_replace("]", ">", $desc);
                    $textfield = stripslashes($linkitem['link_textfield']);
                    $textfield = str_replace('[', '<', $textfield);
                    $textfield = str_replace(']', '>', $textfield);
                } else {
                    $descnotes = esc_html($linkitem['link_notes'], ENT_QUOTES);
                    $desc = esc_html($linkitem['link_description'], ENT_QUOTES);
                    $textfield = stripslashes($linkitem['link_textfield']);
                }
                $cleandesc = $desc;
                $cleanname = esc_html($linkitem['link_name'], ENT_QUOTES);
                if ('search' == $mode) {
                    foreach ($searchterms as $searchterm) {
                        $descnotes = link_library_highlight_phrase($descnotes, $searchterm, '<span class="highlight_word">', '</span>');
                        $desc = link_library_highlight_phrase($desc, $searchterm, '<span class="highlight_word">', '</span>');
                        $name = link_library_highlight_phrase($linkitem['link_name'], $searchterm, '<span class="highlight_word">', '</span>');
                        $textfield = link_library_highlight_phrase($textfield, $searchterm, '<span class="highlight_word">', '</span>');
                    }
                } else {
                    $name = $cleanname;
                }
                if ('linkname' == $linktitlecontent) {
                    $title = $cleanname;
                } elseif ('linkdesc' == $linktitlecontent) {
                    $title = $cleandesc;
                }
                if ($showupdated) {
                    if (substr($linkitem['link_updated'], 0, 2) != '00') {
                        $title .= ' (' . __('Last updated', 'link-library') . '  ' . date_i18n(get_option('links_updated_date_format'), strtotime($linkitem['link_updated'])) . ')';
                    }
                }
                if (!empty($title)) {
                    $title = ' title="' . $title . '"';
                }
                $alt = ' alt="' . $cleanname . '"';
                $target = $linkitem['link_target'];
                if (!empty($target)) {
                    $target = ' target="' . $target . '"';
                } else {
                    $target = $linktarget;
                    if (!empty($target)) {
                        $target = ' target="' . $target . '"';
                    }
                }
                if (empty($dragndroporder)) {
                    $dragndroporder = '1,2,3,4,5,6,7,8,9,10';
                }
                $dragndroparray = explode(',', $dragndroporder);
                if ($dragndroparray) {
                    foreach ($dragndroparray as $arrayelements) {
                        switch ($arrayelements) {
                            case 1:
                                //------------------ Image Output --------------------
                                $imageoutput = '';
                                if ($show_images && !$shownameifnoimage || ($show_images && $shownameifnoimage && !empty($linkitem['link_image']) || $usethumbshotsforimages)) {
                                    $imageoutput .= stripslashes($beforeimage);
                                    if (!empty($linkitem['link_image']) || $usethumbshotsforimages) {
                                        if (true == $debugmode) {
                                            $starttimeimage = microtime(true);
                                        }
                                        $imageoutput .= '<a href="';
                                        if (!$enable_link_popup) {
                                            if ('primary' == $sourceimage || empty($sourceimage)) {
                                                $imageoutput .= $the_link;
                                            } elseif ('secondary' == $sourceimage) {
                                                $imageoutput .= $the_second_link;
                                            }
                                        } else {
                                            $imageoutput .= admin_url('admin-ajax.php' . '?action=link_library_popup_content&linkid=' . $linkitem['proper_link_id'] . '&settings=' . $settings . '&height=' . (empty($popup_height) ? 300 : $popup_height) . '&width=' . (empty($popup_width) ? 400 : $popup_width) . '&xpath=' . $xpath);
                                        }
                                        $imageoutput .= '" id="link-' . $linkitem['proper_link_id'] . '" class="' . ($enable_link_popup ? 'thickbox' : 'track_this_link') . ' ' . ($linkitem['link_featured'] ? 'featured' : '') . '" ' . $rel . $title . $target . '>';
                                        if ($usethumbshotsforimages && (!$uselocalimagesoverthumbshots || empty($uselocalimagesoverthumbshots) || $uselocalimagesoverthumbshots && empty($linkitem['link_image']))) {
                                            if ($thumbnailgenerator == 'robothumb') {
                                                $imageoutput .= '<img src="http://www.robothumb.com/src/?url=' . $the_link . '&size=' . $generaloptions['thumbnailsize'] . '"';
                                            } elseif ($thumbnailgenerator == 'thumbshots') {
                                                if (!empty($thumbshotscid)) {
                                                    $imageoutput .= '<img src="http://images.thumbshots.com/image.aspx?cid=' . rawurlencode($thumbshotscid) . '&v=1&w=120&url=' . $the_link . '"';
                                                }
                                            }
                                        } else {
                                            if (!$usethumbshotsforimages || $usethumbshotsforimages && $uselocalimagesoverthumbshots && !empty($linkitem['link_image'])) {
                                                if (strpos($linkitem['link_image'], 'http') !== false) {
                                                    $imageoutput .= '<img src="' . $linkitem['link_image'] . '"';
                                                } else {
                                                    // If it's a relative path
                                                    $imageoutput .= '<img src="' . get_option('siteurl') . $linkitem['link_image'] . '"';
                                                }
                                            }
                                        }
                                        if (!$usethumbshotsforimages || $usethumbshotsforimages && !empty($thumbshotscid) || $usethumbshotsforimages && $uselocalimagesoverthumbshots && !empty($linkitem['link_image'])) {
                                            $imageoutput .= $alt . $title;
                                            if (!empty($imageclass)) {
                                                $imageoutput .= ' class="' . $imageclass . '" ';
                                            }
                                            $imageoutput .= '/>';
                                            $imageoutput .= '</a>';
                                        }
                                        if (true == $debugmode) {
                                            $output .= '<!-- Time to render image section of link id ' . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimeimage) . " --> \n";
                                        }
                                    }
                                    $imageoutput .= stripslashes($afterimage);
                                    if ((!empty($imageoutput) || $usethumbshotsforimages && !empty($thumbshotscid)) && $show_images) {
                                        $output .= $imageoutput;
                                    }
                                    break;
                                }
                            case 2:
                                //------------------ Name Output --------------------
                                if ($showname && 2 == $arrayelements || $show_images && $shownameifnoimage && empty($linkitem['link_image']) && !$usethumbshotsforimages && 1 == $arrayelements) {
                                    if (true == $debugmode) {
                                        $starttimename = microtime(true);
                                    }
                                    $output .= stripslashes($beforelink);
                                    if ('primary' == $sourcename && $the_link != '#' || 'secondary' == $sourcename && $the_second_link != '#') {
                                        $output .= '<a href="';
                                        if (!$enable_link_popup) {
                                            if ('primary' == $sourcename || empty($sourcename)) {
                                                $output .= $the_link;
                                            } elseif ('secondary' == $sourcename) {
                                                $output .= $the_second_link;
                                            }
                                        } else {
                                            $output .= admin_url('admin-ajax.php' . '?action=link_library_popup_content&linkid=' . $linkitem['proper_link_id'] . '&settings=' . $settings . '&height=' . (empty($popup_height) ? 300 : $popup_height) . '&width=' . (empty($popup_width) ? 400 : $popup_width) . '&xpath=' . $xpath);
                                        }
                                        $output .= '" id="link-' . $linkitem['proper_link_id'] . '" class="' . ($enable_link_popup ? 'thickbox' : 'track_this_link') . ' ' . ($linkitem['link_featured'] ? ' featured' : '') . '" ' . $rel . $title . $target . '>';
                                    }
                                    $output .= $name;
                                    if ('primary' == $sourcename && $the_link != '#' || 'secondary' == $sourcename && $the_second_link != '#') {
                                        $output .= '</a>';
                                    }
                                    if ($showadmineditlinks && $linkeditoruser) {
                                        $output .= $between . '<span class="editlink"><a href="' . esc_url(add_query_arg(array('action' => 'edit', 'link_id' => $linkitem['proper_link_id']), admin_url('link.php'))) . '">(' . __('Edit', 'link-library') . ')</a></span>';
                                    }
                                    if ($showupdated && $linkitem['recently_updated']) {
                                        $output .= get_option('links_recently_updated_append');
                                    }
                                    $output .= stripslashes($afterlink);
                                    if (true == $debugmode) {
                                        $output .= "\n<!-- Time to render name section of link id " . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimename) . " --> \n";
                                    }
                                }
                                break;
                            case 3:
                                //------------------ Date Output --------------------
                                if ($showdate) {
                                    if (true == $debugmode) {
                                        $starttimedate = microtime(true);
                                    }
                                    $formatteddate = date_i18n(get_option('links_updated_date_format'), $linkitem['link_date']);
                                    $output .= $between . stripslashes($beforedate) . $formatteddate . stripslashes($afterdate);
                                    if (true == $debugmode) {
                                        $output .= "\n<!-- Time to render date section of link id " . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimedate) . " --> \n";
                                    }
                                }
                                break;
                            case 4:
                                //------------------ Description Output --------------------
                                if ($showdescription) {
                                    if (true == $debugmode) {
                                        $starttimedesc = microtime(true);
                                    }
                                    $output .= $between . stripslashes($beforedesc) . $desc . stripslashes($afterdesc);
                                    if (true == $debugmode) {
                                        $output .= "\n<!-- Time to render description section of link id " . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimedesc) . " --> \n";
                                    }
                                }
                                break;
                            case 5:
                                //------------------ Notes Output --------------------
                                if ($shownotes) {
                                    if (true == $debugmode) {
                                        $starttimenotes = microtime(true);
                                    }
                                    $output .= $between . stripslashes($beforenote) . $descnotes . stripslashes($afternote);
                                    if (true == $debugmode) {
                                        $output .= "\n<!-- Time to render notes section of link id " . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimenotes) . " --> \n";
                                    }
                                }
                                break;
                            case 6:
                                //------------------ RSS Icons Output --------------------
                                if ($show_rss || $show_rss_icon || $rsspreview) {
                                    if (true == $debugmode) {
                                        $starttimerssicon = microtime(true);
                                    }
                                    $output .= stripslashes($beforerss) . '<div class="rsselements">';
                                    if ($show_rss && !empty($linkitem['link_rss'])) {
                                        $output .= $between . '<a class="rss" href="' . $linkitem['link_rss'] . '">RSS</a>';
                                    }
                                    if ($show_rss_icon && !empty($linkitem['link_rss'])) {
                                        $output .= $between . '<a class="rssicon" href="' . $linkitem['link_rss'] . '"><img src="' . plugins_url('icons/feed-icon-14x14.png', __FILE__) . '" /></a>';
                                    }
                                    if ($rsspreview && !empty($linkitem['link_rss'])) {
                                        $output .= $between . '<a href="' . home_url() . '/?link_library_rss_preview=1&keepThis=true&linkid=' . $linkitem['proper_link_id'] . '&previewcount=' . $rsspreviewcount . 'height=' . (empty($rsspreviewwidth) ? 900 : $rsspreviewwidth) . '&width=' . (empty($rsspreviewheight) ? 700 : $rsspreviewheight) . '&xpath=' . urlencode($xpath) . '" title="' . __('Preview of RSS feed for', 'link-library') . ' ' . $cleanname . '" class="thickbox"><img src="' . plugins_url('icons/preview-16x16.png', __FILE__) . '" /></a>';
                                    }
                                    $output .= '</div>' . stripslashes($afterrss);
                                    if (true == $debugmode) {
                                        $output .= "\n<!-- Time to render RSS Icon section of link id " . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimerssicon) . " --> \n";
                                    }
                                }
                                if ($rssfeedinline && $linkitem['link_rss']) {
                                    if (true == $debugmode) {
                                        $starttimerssfeed = microtime(true);
                                    }
                                    $rss = fetch_feed($linkitem['link_rss']);
                                    if (!is_wp_error($rss)) {
                                        $maxitems = $rss->get_item_quantity($rssfeedinlinecount);
                                        $rss_items = $rss->get_items(0, $maxitems);
                                        if ($rss_items) {
                                            $output .= '<div id="ll_rss_results">';
                                            foreach ($rss_items as $item) {
                                                $output .= '<div class="chunk" style="padding:0 5px 5px;">';
                                                $output .= '<div class="rsstitle"><a target="feedwindow" href="' . $item->get_permalink() . '">' . $item->get_title() . '</a> - ' . $item->get_date('j F Y | g:i a') . '</div>';
                                                if ($rssfeedinlinecontent) {
                                                    $output .= '<div class="rsscontent">' . $item->get_description() . '</div>';
                                                }
                                                $output .= '</div>';
                                                $output .= '<br />';
                                            }
                                            $output .= '</div>';
                                        }
                                    }
                                    if (true == $debugmode) {
                                        $output .= "\n<!-- Time to render RSS Feed section of link id " . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimerssfeed) . " --> \n";
                                    }
                                }
                                break;
                            case 7:
                                //------------------ Web Link Output --------------------
                                if ('false' != $displayweblink) {
                                    if (true == $debugmode) {
                                        $starttimerweblink = microtime(true);
                                    }
                                    if ('addressonly' == $displayweblink) {
                                        $output .= $between . stripslashes($beforeweblink);
                                        $output .= $the_link;
                                        $output .= stripslashes($afterweblink);
                                    } else {
                                        $output .= $between . stripslashes($beforeweblink) . '<a href="';
                                        if ('primary' == $sourceweblink || empty($sourceweblink)) {
                                            $output .= $the_link;
                                        } elseif ('secondary' == $sourceweblink) {
                                            $output .= $the_second_link;
                                        }
                                        $output .= '" id="link-' . $linkitem['proper_link_id'] . '" class="track_this_link" ' . $target . '>';
                                        if ('address' == $displayweblink) {
                                            if (('primary' == $sourceweblink || empty($sourceweblink)) && !empty($the_link)) {
                                                $output .= $the_link;
                                            } elseif ('secondary' == $sourceweblink && !empty($the_second_link)) {
                                                $output .= $the_second_link;
                                            }
                                        } elseif ('label' == $displayweblink && !empty($weblinklabel)) {
                                            $output .= $weblinklabel;
                                        }
                                        $output .= '</a>' . stripslashes($afterweblink);
                                    }
                                    if (true == $debugmode) {
                                        $output .= "\n<!-- Time to render web link section of link id " . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimerweblink) . " --> \n";
                                    }
                                }
                                break;
                            case 8:
                                //------------------ Telephone Output --------------------
                                if ('false' != $showtelephone) {
                                    if (true == $debugmode) {
                                        $starttimertelephone = microtime(true);
                                    }
                                    $output .= $between . stripslashes($beforetelephone);
                                    if ('plain' != $showtelephone) {
                                        $output .= '<a href="';
                                        if (('primary' == $sourcetelephone || empty($sourcetelephone)) && !empty($the_link)) {
                                            $output .= $the_link;
                                        } elseif ('secondary' == $sourcetelephone && !empty($the_second_link)) {
                                            $output .= $the_second_link;
                                        }
                                        $output .= '" id="link-' . $linkitem['proper_link_id'] . '" class="track_this_link" >';
                                    }
                                    if ('link' == $showtelephone || 'plain' == $showtelephone) {
                                        $output .= $linkitem['link_telephone'];
                                    } elseif ('label' == $showtelephone) {
                                        $output .= $telephonelabel;
                                    }
                                    if ('plain' != $showtelephone) {
                                        $output .= '</a>';
                                    }
                                    $output .= stripslashes($aftertelephone);
                                    if (true == $debugmode) {
                                        $output .= "\n<!-- Time to render telephone section of link id " . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimertelephone) . " --> \n";
                                    }
                                }
                                break;
                            case 9:
                                //------------------ E-mail Output --------------------
                                if ('false' != $showemail) {
                                    if (true == $debugmode) {
                                        $starttimeremail = microtime(true);
                                    }
                                    $output .= $between . stripslashes($beforeemail);
                                    if ('plain' != $showemail) {
                                        $output .= '<a href="';
                                        if ('mailto' == $showemail || 'mailtolabel' == $showemail) {
                                            $output .= 'mailto:' . $linkitem['link_email'];
                                        } elseif ('command' == $showemail || 'commandlabel' == $showemail) {
                                            $newcommand = str_replace('#email', $linkitem['link_email'], $emailcommand);
                                            $cleanlinkname = str_replace(' ', '%20', $linkitem['link_name']);
                                            $newcommand = str_replace('#company', $cleanlinkname, $newcommand);
                                            $output .= $newcommand;
                                        }
                                        $output .= '">';
                                    }
                                    if ('plain' == $showemail || 'mailto' == $showemail || 'command' == $showemail) {
                                        $output .= $linkitem['link_email'];
                                    } elseif ('mailtolabel' == $showemail || 'commandlabel' == $showemail) {
                                        $output .= $emaillabel;
                                    }
                                    if ('plain' != $showemail) {
                                        $output .= '</a>';
                                    }
                                    $output .= stripslashes($afteremail);
                                    if (true == $debugmode) {
                                        $output .= "\n<!-- Time to render e-mail section of link id " . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimeremail) . " --> \n";
                                    }
                                }
                                break;
                            case 10:
                                //------------------ Link Hits Output --------------------
                                if ($showlinkhits) {
                                    if (true == $debugmode) {
                                        $starttimerhits = microtime(true);
                                    }
                                    $output .= $between . stripslashes($beforelinkhits);
                                    $output .= $linkitem['link_visits'];
                                    $output .= stripslashes($afterlinkhits);
                                    if (true == $debugmode) {
                                        $output .= "\n<!-- Time to render link hits section of link id " . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimerhits) . " --> \n";
                                    }
                                }
                                break;
                            case 11:
                                //------------------ Link Rating Output --------------------
                                if ($showrating) {
                                    if (true == $debugmode) {
                                        $starttimerrating = microtime(true);
                                    }
                                    $output .= $between . stripslashes($beforelinkrating);
                                    $output .= $linkitem['link_rating'];
                                    $output .= stripslashes($afterlinkrating);
                                    if (true == $debugmode) {
                                        $output .= "\n<!-- Time to render link rating section of link id " . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimerrating) . " --> \n";
                                    }
                                }
                                break;
                            case 12:
                                //------------------ Link Large Description Output --------------------
                                if ($showlargedescription) {
                                    if (true == $debugmode) {
                                        $starttimerlargedesc = microtime(true);
                                    }
                                    $output .= $between . stripslashes($beforelargedescription);
                                    $output .= $textfield;
                                    $output .= stripslashes($afterlargedescription);
                                    if (true == $debugmode) {
                                        $output .= "\n<!-- Time to render link large description section of link id " . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $starttimerlargedesc) . " --> \n";
                                    }
                                }
                                break;
                        }
                    }
                }
                $output .= stripslashes($afteritem) . "\n";
                if ($linkaddfrequency > 0) {
                    if (0 == $linkcount % $linkaddfrequency) {
                        $output .= stripslashes($addafterlink);
                    }
                }
            }
            if (true == $debugmode) {
                $output .= '<!-- Time to render link id ' . $linkitem['proper_link_id'] . ': ' . (microtime(true) - $linkstarttime) . " --> \n";
            }
        }
        // end while
        // Close the last category
        if ($displayastable) {
            $output .= "\t</table>\n";
        } else {
            $output .= "\t</ul>\n";
        }
        if (!empty($catlistwrappers) && !$combineresults) {
            $output .= '</div>';
        }
        if ($usethumbshotsforimages) {
            if ($thumbnailgenerator == 'robothumb') {
                $output .= '<div class="llthumbshotsnotice"><a href="http://www.robothumb.com">Screenshots par Robothumb</a></div>';
            } elseif ($thumbnailgenerator == 'thumbshots') {
                $output .= '<div class="llthumbshotsnotice"><a href="http://www.thumbshots.com" target="_blank" title="Thumbnails Screenshots by Thumbshots">Thumbnail Screenshots by Thumbshots</a></div>';
            }
        }
        if ($showlinksonclick) {
            $output .= '</div>';
        }
        if (!$combineresults) {
            $output .= '</div>';
        }
        if ($pagination && 'search' != $mode && ('AFTER' == $paginationposition || empty($pagination))) {
            $previouspagenumber = $pagenumber - 1;
            $nextpagenumber = $pagenumber + 1;
            $pageID = get_the_ID();
            $output .= link_library_display_pagination($previouspagenumber, $nextpagenumber, $numberofpages, $pagenumber, $showonecatonly, $showonecatmode, $AJAXcatid, $settings, $pageID, $currentcatletter);
        }
        $xpath = $LLPluginClass->relativePath(dirname(__FILE__), ABSPATH);
        $nonce = wp_create_nonce('ll_tracker');
        $output .= "<script type='text/javascript'>\n";
        $output .= "jQuery(document).ready(function()\n";
        $output .= "{\n";
        $output .= "jQuery('#linklist" . $settings . " a.track_this_link').click(function() {\n";
        $output .= "linkid = this.id;\n";
        $output .= "linkid = linkid.substring(5);";
        $output .= "path = '" . $xpath . "';";
        $output .= "jQuery.ajax( {" . "    type: 'POST'," . "    url: '" . admin_url('admin-ajax.php') . "', " . "    data: { action: 'link_library_tracker', " . "            _ajax_nonce: '" . $nonce . "', " . "            id:linkid, xpath:path } " . "    });\n";
        $output .= "return true;\n";
        $output .= "});\n";
        $output .= "jQuery('#linklist" . $settings . " .expandlinks').click(function() {\n";
        $output .= "target = '.' + jQuery(this).attr('id');\n";
        $output .= "if ( jQuery( target ).is(':visible') ) {\n";
        $output .= "jQuery(target).slideUp();\n";
        $output .= "jQuery(this).children('img').attr('src', '";
        if (!empty($expandiconpath)) {
            $output .= $expandiconpath;
        } else {
            $output .= plugins_url('icons/expand-32.png', __FILE__);
        }
        $output .= "');\n";
        $output .= "} else {\n";
        $output .= "jQuery(target).slideDown();\n";
        $output .= "jQuery(this).children('img').attr('src', '";
        if (!empty($collapseiconpath)) {
            $output .= $collapseiconpath;
        } else {
            $output .= plugins_url('icons/collapse-32.png', __FILE__);
        }
        $output .= "');\n";
        $output .= "}\n";
        $output .= "});\n";
        $output .= "});\n";
        $output .= "</script>";
        unset($xpath);
        $currentcategory = $currentcategory + 1;
        $output .= "</div>\n";
    } else {
        if (isset($_GET['searchll'])) {
            $output .= "<div id='linklist" . $settings . "' class='linklist'>\n";
            $output .= $searchnoresultstext . "\n";
            $output .= "</div>";
        } else {
            $output .= "<div id='linklist" . $settings . "' class='linklist'>\n";
            $output .= __('No links found', 'link-library') . ".\n";
            $output .= "</div>";
        }
    }
    $output .= "\n<!-- End of Link Library Output -->\n\n";
    return do_shortcode($output);
}
/**
 *
 * Render the output of the link-library-cats shortcode
 *
 * @param $LLPluginClass    Link Library main plugin class
 * @param $generaloptions   General Plugin Settings
 * @param $libraryoptions   Selected library settings array
 * @param $settings         Settings ID
 * @return                  List of categories output for browser
 */
function RenderLinkLibraryCategories($LLPluginClass, $generaloptions, $libraryoptions, $settings)
{
    global $wpdb;
    $generaloptions = wp_parse_args($generaloptions, ll_reset_gen_settings('return'));
    extract($generaloptions);
    $libraryoptions = wp_parse_args($libraryoptions, ll_reset_options(1, 'list', 'return'));
    extract($libraryoptions);
    /* This case will only happen if the user entered bad data in the admin page or if someone is trying to inject bad data in SQL query */
    if (!empty($categorylist)) {
        $categorylistarray = explode(',', $categorylist);
        if (true === array_filter($categorylistarray, 'is_int')) {
            return 'List of requested categories is invalid. Please go back to Link Library admin panel to correct.';
        }
    }
    if (!empty($excludecategorylist)) {
        $excludecategorylistarray = explode(',', $excludecategorylist);
        if (true === array_filter($excludecategorylistarray, 'is_int')) {
            return 'List of requested excluded categories is invalid. Please go back to Link Library admin panel to correct.';
        }
    }
    $output = '';
    $categoryid = '';
    if (isset($_GET['cat_id'])) {
        $categoryid = intval($_GET['cat_id']);
    } elseif (isset($_GET['catname'])) {
        $categoryterm = get_term_by('name', urldecode($_GET['catname']), 'link_category');
        $categoryid = $categoryterm->term_id;
    } elseif ($showonecatonly) {
        $categoryid = $defaultsinglecat;
    }
    if (!isset($_GET['searchll']) || true == $showcatonsearchresults) {
        $countcat = 0;
        $order = strtolower($order);
        $output .= "<!-- Link Library Categories Output -->\n\n";
        if ($showonecatonly && ('AJAX' == $showonecatmode || empty($showonecatmode))) {
            $nonce = wp_create_nonce('link_library_ajax_refresh');
            $output .= "<SCRIPT LANGUAGE=\"JavaScript\">\n";
            $output .= "var ajaxobject;\n";
            $output .= "function showLinkCat ( _incomingID, _settingsID, _pagenumber ) {\n";
            $output .= "if (typeof(ajaxobject) != \"undefined\") { ajaxobject.abort(); }\n";
            $output .= "\tjQuery('#contentLoading').toggle();" . "jQuery.ajax( {" . "    type: 'POST', " . "    url: '" . admin_url('admin-ajax.php') . "', " . "    data: { action: 'link_library_ajax_update', " . "            _ajax_nonce: '" . $nonce . "', " . "            id : _incomingID, " . "            settings : _settingsID, " . "            ajaxupdate : true, " . "            linkresultpage: _pagenumber }, " . "    success: function( data ){ " . "            jQuery('#linklist" . $settings . "').html( data ); " . "            jQuery('#contentLoading').toggle();\n" . "            } } ); ";
            $output .= "}\n";
            $output .= "</SCRIPT>\n\n";
        }
        // Handle link category sorting
        $direction = 'ASC';
        if ('_' == substr($order, 0, 1)) {
            $direction = 'DESC';
            $order = substr($order, 1);
        }
        $currentcatletter = '';
        if ($cat_letter_filter != 'no') {
            require_once plugin_dir_path(__FILE__) . 'render-link-library-alpha-filter.php';
            $result = RenderLinkLibraryAlphaFilter($LLPluginClass, $generaloptions, $libraryoptions, $settings, 'normal');
            $currentcatletter = $result['currentcatletter'];
            if ('beforecats' == $cat_letter_filter || 'beforecatsandlinks' == $cat_letter_filter) {
                $output .= $result['output'];
            }
        }
        $linkcatquery = 'SELECT ';
        if ($showcatlinkcount || $pagination) {
            $linkcatquery .= 'count(l.link_name) as linkcount, ';
        }
        $linkcatquery .= 't.name, t.term_id, t.slug as category_nicename, tt.description as category_description ';
        $linkcatquery .= 'FROM ' . $LLPluginClass->db_prefix() . 'terms t LEFT JOIN ' . $LLPluginClass->db_prefix() . 'term_taxonomy tt ON (t.term_id = tt.term_id)';
        $linkcatquery .= ' LEFT JOIN ' . $LLPluginClass->db_prefix() . 'term_relationships tr ON (tt.term_taxonomy_id = tr.term_taxonomy_id) ';
        $linkcatquery .= ' LEFT JOIN ' . $LLPluginClass->db_prefix() . 'links l on (tr.object_id = l.link_id';
        if (false == $showinvisible) {
            $linkcatquery .= ' AND l.link_visible != "N" ';
        }
        if (!$showuserlinks) {
            $linkcatquery .= ' AND l.link_description not like \'%LinkLibrary:AwaitingModeration:RemoveTextToApprove%\' ';
        }
        $linkcatquery .= ' ) ';
        $linkcatquery .= 'WHERE tt.taxonomy = "link_category"';
        if (!empty($currentcatletter)) {
            $linkcatquery .= ' AND substring(t.name, 1, 1) = "' . $currentcatletter . '"';
        }
        if (!empty($categorylist)) {
            $linkcatquery .= ' AND t.term_id in ( ' . $categorylist . ' )';
        }
        if (!empty($excludecategorylist)) {
            $linkcatquery .= ' AND t.term_id not in ( ' . $excludecategorylist . ' )';
        }
        if ($hide_if_empty) {
            $linkcatquery .= ' AND l.link_name != "" ';
        }
        $linkcatquery .= ' GROUP BY t.name ';
        $validdirections = array('ASC', 'DESC');
        if ('name' == $order) {
            $linkcatquery .= ' ORDER by t.name ' . (in_array($direction, $validdirections) ? $direction : 'ASC');
        } elseif ('id' == $order) {
            $linkcatquery .= ' ORDER by t.term_id ' . (in_array($direction, $validdirections) ? $direction : 'ASC');
        } elseif ('order' == $order) {
            $linkcatquery .= ' ORDER by t.term_order ' . (in_array($direction, $validdirections) ? $direction : 'ASC');
        } elseif ('catlist' == $order) {
            $linkcatquery .= ' ORDER by FIELD(t.term_id, ' . $categorylist . ' ) ';
        }
        $catnames = $wpdb->get_results($linkcatquery);
        if ($debugmode) {
            $output .= "\n<!-- Category Query: " . print_r($linkcatquery, TRUE) . "-->\n\n";
            $output .= "\n<!-- Category Results: " . print_r($catnames, TRUE) . "-->\n\n";
        }
        // Display each category
        if ($catnames) {
            $output .= '<div id="linktable" class="linktable">';
            if ('table' == $flatlist) {
                $output .= "<table width=\"" . $table_width . "%\">\n";
            } elseif ('unordered' == $flatlist) {
                $output .= "<ul class='menu'>\n";
            } elseif ('dropdown' == $flatlist || 'dropdowndirect' == $flatlist) {
                $output .= "<form name='catselect'><select ";
                if ('dropdowndirect' == $flatlist) {
                    $output .= "onchange='showcategory()' ";
                }
                $output .= "name='catdropdown' class='catdropdown'>";
            }
            $linkcount = 0;
            foreach ((array) $catnames as $catname) {
                $catfront = '';
                $cattext = '';
                $catitem = '';
                // Display the category name
                $countcat += 1;
                if ('table' == $flatlist && (1 == $countcat % $num_columns || 1 == $num_columns)) {
                    $output .= "<tr>\n";
                }
                if ('table' == $flatlist) {
                    $catfront = "\t<td>";
                } elseif ('unordered' == $flatlist) {
                    $catfront = "\t<li>";
                } elseif ('dropdown' == $flatlist || 'dropdowndirect' == $flatlist) {
                    $catfront = "\t<option ";
                    if (!empty($categoryid) && $categoryid == $catname->term_id) {
                        $catfront .= 'selected="selected" ';
                    }
                    $catfront .= 'value="';
                }
                if ($showonecatonly) {
                    if ('AJAX' == $showonecatmode || empty($showonecatmode)) {
                        if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                            $cattext = "<a href='#' onClick=\"showLinkCat('" . $catname->term_id . "', '" . $settings . "', 1);return false;\" >";
                        } elseif ('dropdown' == $flatlist || 'dropdowndirect' == $flatlist) {
                            $cattext = $catname->term_id;
                        }
                    } elseif ('HTMLGET' == $showonecatmode) {
                        if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                            $cattext = "<a href='";
                        }
                        if (!empty($cattargetaddress) && strpos($cattargetaddress, '?') != false) {
                            $cattext .= $cattargetaddress . '&cat_id=';
                        } elseif (!empty($cattargetaddress) && strpos($cattargetaddress, '?') == false) {
                            $cattext .= $cattargetaddress . '?cat_id=';
                        } elseif (empty($cattargetaddress)) {
                            $cattext .= '?cat_id=';
                        }
                        $cattext .= $catname->term_id;
                        if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                            $cattext .= "'>";
                        }
                    } elseif ('HTMLGETSLUG' == $showonecatmode) {
                        if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                            $cattext = "<a href='";
                        }
                        if (!empty($cattargetaddress) && strpos($cattargetaddress, '?') != false) {
                            $cattext .= $cattargetaddress . '&cat=';
                        } elseif (!empty($cattargetaddress) && strpos($cattargetaddress, '?') == false) {
                            $cattext .= $cattargetaddress . '?cat=';
                        } elseif (empty($cattargetaddress)) {
                            $cattext .= '?cat=';
                        }
                        $cattext .= $catname->category_nicename;
                        if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                            $cattext .= "'>";
                        }
                    } elseif ('HTMLGETCATNAME' == $showonecatmode) {
                        if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                            $cattext = "<a href='";
                        }
                        /* if ( !empty( $cattargetaddress ) && strpos( $cattargetaddress, '?' ) != false ) {
                               $cattext .= $cattargetaddress . '&catname=';
                           } elseif ( !empty( $cattargetaddress ) && strpos( $cattargetaddress, '?' ) == false ) {
                               $cattext .= $cattargetaddress . '?catname=';
                           } elseif ( empty( $cattargetaddress ) ) {
                               $cattext .= '?catname=';
                           } */
                        if (!empty($_GET)) {
                            $get_array = $_GET;
                        } else {
                            $get_array = array();
                        }
                        $get_array['catname'] = urlencode($catname->name);
                        $get_query = add_query_arg($get_array, $cattargetaddress);
                        $cattext .= $get_query;
                        if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                            $cattext .= "'>";
                        }
                    } elseif ('HTMLGETPERM' == $showonecatmode) {
                        if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                            $cattext = "<a href='";
                        }
                        $cattext .= '/' . $rewritepage . '/' . $catname->category_nicename;
                        if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                            $cattext .= "'>";
                        }
                    }
                } else {
                    if ($catanchor) {
                        if (!$pagination) {
                            if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                                $cattext = '<a href="';
                            }
                            $cattext .= '#' . $catname->category_nicename;
                            if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                                $cattext .= '">';
                            }
                        } elseif ($pagination) {
                            if (0 == $linksperpage || empty($linksperpage)) {
                                $linksperpage = 5;
                            }
                            $pageposition = ($linkcount + 1) / $linksperpage;
                            $ceilpageposition = ceil($pageposition);
                            if (0 == $ceilpageposition && !isset($_GET['linkresultpage'])) {
                                if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                                    $cattext = '<a href="';
                                }
                                $cattext .= get_permalink() . '#' . $catname->category_nicename;
                                if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                                    $cattext .= '">';
                                }
                            } else {
                                if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                                    $cattext = '<a href="';
                                }
                                $cattext .= '?linkresultpage=' . ($ceilpageposition == 0 ? 1 : $ceilpageposition) . '#' . $catname->category_nicename;
                                if ('dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                                    $cattext .= '">';
                                }
                            }
                            $linkcount = $linkcount + $catname->linkcount;
                        }
                    } else {
                        $cattext = '';
                    }
                }
                if ('dropdown' == $flatlist || 'dropdowndirect' == $flatlist) {
                    $cattext .= '">';
                }
                if ('right' == $catlistdescpos || empty($catlistdescpos)) {
                    $catitem .= '<div class="linkcatname">' . $catname->name . '</div>';
                    if ($showcatlinkcount) {
                        $catitem .= ' (' . $catname->linkcount . ')';
                    }
                }
                if ($showcategorydescheaders) {
                    $catname->category_description = esc_html($catname->category_description);
                    $catname->category_description = str_replace('[', '<', $catname->category_description);
                    $catname->category_description = str_replace(']', '>', $catname->category_description);
                    $catname->category_description = str_replace("&quot;", '"', $catname->category_description);
                    $catitem .= '<span class="linkcatdesc">' . $catname->category_description . '</span>';
                }
                if ('left' == $catlistdescpos) {
                    $catitem .= '<div class="linkcatname">' . $catname->name . '</div>';
                    if ($showcatlinkcount) {
                        $catitem .= ' (' . $catname->linkcount . ')';
                    }
                }
                if (($catanchor || $showonecatonly) && 'dropdown' != $flatlist && 'dropdowndirect' != $flatlist) {
                    $catitem .= '</a>';
                }
                $output .= $catfront . $cattext . $catitem;
                if ('table' == $flatlist) {
                    $catterminator = "</td>\n";
                } elseif ('unordered' == $flatlist) {
                    $catterminator = "</li>\n";
                } elseif ('dropdown' == $flatlist || 'dropdowndirect' == $flatlist) {
                    $catterminator = "</option>\n";
                }
                $output .= $catterminator;
                if ('table' == $flatlist and 0 == $countcat % $num_columns) {
                    $output .= "</tr>\n";
                }
            }
            if ('table' == $flatlist and 3 == $countcat % $num_columns) {
                $output .= "</tr>\n";
            }
            if ('table' == $flatlist && $catnames) {
                $output .= "</table>\n";
            } elseif ('unordered' == $flatlist && $catnames) {
                $output .= "</ul>\n";
            } elseif (('dropdown' == $flatlist || 'dropdowndirect' == $flatlist) && $catnames) {
                $output .= "</select>\n";
                if ('dropdown' == $flatlist) {
                    $output .= "<button type='button' onclick='showcategory()'>" . __('Go!', 'link-library') . "</button>";
                }
                $output .= '</form>';
            }
            $output .= "</div>\n";
            if ($showonecatonly && ('AJAX' == $showonecatmode || empty($showonecatmode))) {
                if (empty($loadingicon)) {
                    $loadingicon = '/icons/Ajax-loader.gif';
                }
                $output .= "<div class='contentLoading' id='contentLoading' style='display: none;'><img src='" . plugins_url($loadingicon, __FILE__) . "' alt='Loading data, please wait...'></div>\n";
            }
            if ('dropdown' == $flatlist || 'dropdowndirect' == $flatlist) {
                $output .= "<SCRIPT TYPE='text/javascript'>\n";
                $output .= "\tfunction showcategory(){\n";
                if ($showonecatonly && ('AJAX' == $showonecatmode || empty($showonecatmode))) {
                    $output .= 'catidvar = document.catselect.catdropdown.options[document.catselect.catdropdown.selectedIndex].value;';
                    $output .= "showLinkCat(catidvar, '" . $settings . "', 1);return false; }";
                } else {
                    $output .= "\t\tlocation=\n";
                    $output .= "document.catselect.catdropdown.options[document.catselect.catdropdown.selectedIndex].value }\n";
                }
                $output .= "</SCRIPT>\n";
            }
        } else {
            $output .= '<div>' . __('No categories found', 'link-library') . '.</div>';
        }
        $output .= "\n<!-- End of Link Library Categories Output -->\n\n";
    }
    return $output;
}
function RenderLinkLibraryAlphaFilter($LLPluginClass, $generaloptions, $libraryoptions, $settings, $searchmode)
{
    global $wpdb;
    $generaloptions = wp_parse_args($generaloptions, ll_reset_gen_settings('return'));
    extract($generaloptions);
    $libraryoptions = wp_parse_args($libraryoptions, ll_reset_options(1, 'list', 'return'));
    extract($libraryoptions);
    $linkcatquery = 'SELECT ';
    $linkcatquery .= 'distinct substring(t.name, 1, 1) as catletter ';
    $linkcatquery .= 'FROM ' . $LLPluginClass->db_prefix() . 'terms t LEFT JOIN ' . $LLPluginClass->db_prefix() . 'term_taxonomy tt ON (t.term_id = tt.term_id)';
    $linkcatquery .= ' LEFT JOIN ' . $LLPluginClass->db_prefix() . 'term_relationships tr ON (tt.term_taxonomy_id = tr.term_taxonomy_id) ';
    $linkcatquery .= ' LEFT JOIN ' . $LLPluginClass->db_prefix() . 'links l on (tr.object_id = l.link_id';
    if (false == $showinvisible) {
        $linkcatquery .= ' AND l.link_visible != "N" ';
    }
    if (!$showuserlinks) {
        $linkcatquery .= ' AND l.link_description not like \'%LinkLibrary:AwaitingModeration:RemoveTextToApprove%\' ';
    }
    $linkcatquery .= ' ) ';
    $linkcatquery .= 'WHERE tt.taxonomy = "link_category"';
    if (!empty($categorylist)) {
        $linkcatquery .= ' AND t.term_id in ( ' . $categorylist . ' )';
    }
    if (!empty($excludecategorylist)) {
        $linkcatquery .= ' AND t.term_id not in ( ' . $excludecategorylist . ' )';
    }
    if ($hide_if_empty) {
        $linkcatquery .= ' AND l.link_name != "" ';
    }
    $linkcatquery .= ' ORDER by catletter ASC';
    $catletters = $wpdb->get_col($linkcatquery);
    $output = '<div class="catalphafilter">';
    $output .= '<div class="catalphafiltertitle">' . $catfilterlabel . '</div>';
    $currentcatletter = '';
    if (isset($_GET['catletter']) && 'normal' == $searchmode) {
        if (isset($_GET['catletter']) && strlen($_GET['catletter']) == 1) {
            $currentcatletter = $_GET['catletter'];
        }
    } elseif ('normal' == $searchmode) {
        if ($cat_letter_filter_autoselect) {
            if (!empty($catletters)) {
                $currentcatletter = $catletters[0];
            }
        }
    }
    if (isset($_GET)) {
        $incomingget = $_GET;
        unset($incomingget['catletter']);
        unset($incomingget['searchll']);
    }
    global $post;
    foreach (range('A', 'Z') as $letter) {
        if (in_array($letter, $catletters)) {
            $output .= '<div class="';
            if ($currentcatletter == $letter) {
                $output .= 'catalphafilterselectedletter';
            } else {
                $output .= 'catalphafilterlinkedletter';
            }
            $argumentarray = array('catletter' => urlencode($letter));
            $argumentarray = array_merge($argumentarray, $incomingget);
            $targetaddress = esc_url(add_query_arg($argumentarray, get_permalink($post->ID)));
            $output .= '"><a href="' . $targetaddress . '">' . $letter . '</a></div>';
        } else {
            $output .= '<div class="catalphafilteremptyletter">' . $letter . '</div>';
        }
    }
    if ($cat_letter_filter_showalloption) {
        $output .= '<div class="';
        if (empty($currentcatletter)) {
            $output .= 'allcatalphafilterselectedletter catalphafilterselectedletter';
        } else {
            $output .= 'allcatalphafilterlinkedletter catalphafilterlinkedletter';
        }
        $argumentarray = array('catletter' => '');
        $argumentarray = array_merge($argumentarray, $incomingget);
        $targetaddress = esc_url(add_query_arg($argumentarray, get_permalink($post->ID)));
        $output .= '"><a href="' . $targetaddress . '">ALL</a></div>';
    }
    $output .= '</div>';
    $result['output'] = $output;
    $result['currentcatletter'] = $currentcatletter;
    return $result;
}
Esempio n. 8
0
    function on_show_page()
    {
        //we need the global screen column value to beable to have a sidebar in WordPress 2.8
        global $screen_layout_columns;
        $settings = isset($_GET['settings']) ? $_GET['settings'] : 1;
        // Retrieve general options
        $genoptions = get_option('LinkLibraryGeneral');
        // If general options don't exist, create them
        if ($genoptions == false) {
            $genoptions = ll_reset_gen_settings('return_and_set');
        } else {
            $genoptions = wp_parse_args($genoptions, ll_reset_gen_settings('return'));
        }
        $settingsname = 'LinkLibraryPP' . $settings;
        $options = get_option($settingsname);
        $options = wp_parse_args($options, ll_reset_options(1, 'list', 'return'));
        if (empty($options)) {
            $options = ll_reset_options($settings, 'list', 'return_and_set');
        }
        if (isset($_GET['genthumbs']) || isset($_GET['genfavicons']) || isset($_GET['genthumbsingle']) || isset($_GET['genfaviconsingle'])) {
            global $wpdb;
            if (isset($_GET['genthumbs']) || isset($_GET['genthumbsingle'])) {
                $filepath = "link-library-images";
            } elseif (isset($_GET['genfavicons']) || isset($_GET['genfaviconsingle'])) {
                $filepath = "link-library-favicons";
            }
            $uploads = wp_upload_dir();
            if (!file_exists($uploads['basedir'])) {
                echo "<div id='message' class='updated fade'><p><strong>" . __('Please create a folder called uploads under your Wordpress /wp-content/ directory with write permissions to use this functionality.', 'link-library') . "</strong></p></div>";
            } elseif (!is_writable($uploads['basedir'])) {
                echo "<div id='message' class='updated fade'><p><strong>" . __('Please make sure that the /wp-content/uploads/ directory has write permissions to use this functionality.', 'link-library') . "</strong></p></div>";
            } else {
                if (!file_exists($uploads['basedir'] . '/' . $filepath)) {
                    mkdir($uploads['basedir'] . '/' . $filepath);
                }
                if (isset($_GET['genthumbs']) || isset($_GET['genthumbsingle'])) {
                    $genmode = 'thumb';
                } elseif (isset($_GET['genfavicons']) || isset($_GET['genfaviconsingle'])) {
                    $genmode = 'favicon';
                }
                $linkquery = "SELECT distinct * ";
                $linkquery .= "FROM " . $this->db_prefix() . "terms t ";
                $linkquery .= "LEFT JOIN " . $this->db_prefix() . "term_taxonomy tt ON (t.term_id = tt.term_id) ";
                $linkquery .= "LEFT JOIN " . $this->db_prefix() . "term_relationships tr ON (tt.term_taxonomy_id = tr.term_taxonomy_id) ";
                $linkquery .= "LEFT JOIN " . $this->db_prefix() . "links l ON (tr.object_id = l.link_id) ";
                $linkquery .= "WHERE tt.taxonomy = 'link_category' ";
                if ($options['categorylist'] != "" && !isset($_GET['genthumbsingle']) && !isset($_GET['genfaviconsingle'])) {
                    $linkquery .= " AND t.term_id in (" . $options['categorylist'] . ")";
                }
                if (isset($_GET['genthumbsingle']) || isset($_GET['genfaviconsingle'])) {
                    $linkquery .= " AND l.link_id = " . $_GET['linkid'];
                }
                $linkitems = $wpdb->get_results($linkquery);
                if ($linkitems) {
                    $filescreated = 0;
                    $totallinks = count($linkitems);
                    foreach ($linkitems as $linkitem) {
                        if (!$options['uselocalimagesoverthumbshots'] || $options['uselocalimagesoverthumbshots'] && empty($linkitem->link_image)) {
                            $this->ll_get_link_image($linkitem->link_url, $linkitem->link_name, $genmode, $linkitem->link_id, $genoptions['thumbshotscid'], $filepath, $genoptions['imagefilepath'], $genoptions['thumbnailsize'], $genoptions['thumbnailgenerator']);
                        }
                        $linkname = $linkitem->link_name;
                    }
                    if (isset($_GET['genthumbs'])) {
                        echo "<div id='message' class='updated fade'><p><strong>" . __('Thumbnails successfully generated!', 'link-library') . "</strong></p></div>";
                    } elseif (isset($_GET['genfavicons'])) {
                        echo "<div id='message' class='updated fade'><p><strong>" . __('Favicons successfully generated!', 'link-library') . "</strong></p></div>";
                    } elseif (isset($_GET['genthumbsingle'])) {
                        echo "<div id='message' class='updated fade'><p><strong>" . __('Thumbnail successfully generated for', 'link-library') . " " . $linkname . ".</strong></p></div>";
                    } elseif (isset($_GET['genfaviconsingle'])) {
                        echo "<div id='message' class='updated fade'><p><strong>" . __('Favicon successfully generated for', 'link-library') . " " . $linkname . ".</strong></p></div>";
                    }
                }
            }
        }
        // Check for current page to set some page=specific variables
        if ($_GET['page'] == 'link-library') {
            if (isset($_GET['message']) && $_GET['message'] == '1') {
                echo "<div id='message' class='updated fade'><p><strong>" . __('General Settings Saved', 'link-library') . ".</strong></p></div>";
            } else {
                if (isset($_GET['message']) && $_GET['message'] == '2') {
                    $linksexportdir = wp_upload_dir();
                    echo "<div id='message' class='updated fade'><p><strong><a href='" . $linksexportdir['url'] . '/LinksExport.csv' . "'>" . __('Download exported links', 'link-library') . "</a></strong></p></div>";
                } else {
                    if (isset($_GET['message']) && $_GET['message'] == '3') {
                        echo "<div id='message' class='updated fade'><p><strong>" . __('Link Library plugin directory needs to be writable to perform this action', 'link-library') . "</strong></p></div>";
                    }
                }
            }
            $formvalue = 'save_link_library_general';
            $pagetitle = '';
        } elseif ($_GET['page'] == 'link-library-settingssets') {
            $formvalue = 'save_link_library_settingssets';
            if (isset($_GET['reset'])) {
                $options = ll_reset_options($settings, 'list', 'return_and_set');
            }
            if (isset($_GET['resettable'])) {
                $options = ll_reset_options($settings, 'table', 'return_and_set');
            }
            if (isset($_GET['copy'])) {
                $destination = $_GET['copy'];
                $source = $_GET['source'];
                $sourcesettingsname = 'LinkLibraryPP' . $source;
                $sourceoptions = get_option($sourcesettingsname);
                $destinationsettingsname = 'LinkLibraryPP' . $destination;
                update_option($destinationsettingsname, $sourceoptions);
                $settings = $destination;
            }
            if (isset($_GET['deletesettings'])) {
                check_admin_referer('link-library-delete');
                $settings = $_GET['deletesettings'];
                $deletesettingsname = 'LinkLibraryPP' . $settings;
                $options = delete_option($deletesettingsname);
                $settings = 1;
            }
            $pagetitle = __('Library', 'link-library') . ' #' . $settings . " - " . stripslashes($options['settingssetname']);
            if (isset($_GET['messages'])) {
                $categoryid = '';
                $messagelist = explode(",", $_GET['messages']);
                foreach ($messagelist as $message) {
                    switch ($message) {
                        case '1':
                            echo "<div id='message' class='updated fade'><p><strong>" . __('Library #', 'link-library') . $settings . " " . __('Updated', 'link-library') . "!</strong></p></div>";
                            break;
                        case '2':
                            echo '<br /><br />' . __('Included Category ID', 'link-library') . ' ' . $categoryid . ' ' . __('is invalid. Please check the ID in the Link Category editor.', 'link-library');
                            break;
                        case '3':
                            echo '<br /><br />' . __('Excluded Category ID', 'link-library') . ' ' . $categoryid . ' ' . __('is invalid. Please check the ID in the Link Category editor.', 'link-library');
                            break;
                        case '4':
                            echo "<div id='message' class='updated fade'><p><strong>" . __('Invalid column count for link on row. Compare against template.', 'link-library') . "</strong></p></div>";
                            break;
                        case '5':
                            $upload_dir = wp_upload_dir();
                            echo "<div id='message' class='updated fade'><p><strong>" . __('Library Settings Exported', 'link-library') . ". <a href='" . $upload_dir['url'] . '/SettingSet' . $settings . 'Export.csv' . "'>" . __('Download here', 'link-library') . "</a>.</strong></p></div>";
                            break;
                        case '6':
                            echo "<div id='message' class='updated fade'><p><strong>" . __('Link Library plugin directory needs to be writable to perform this action', 'link-library') . ".</strong></p></div>";
                            break;
                        case '7':
                            echo "<div id='message' class='updated fade'><p><strong>" . __('Library Settings imported successfully', 'link-library') . ".</strong></p></div>";
                            break;
                        case '8':
                            echo "<div id='message' class='updated fade'><p><strong>" . __('Library Settings Upload Failed', 'link-library') . "</strong></p></div>";
                            break;
                        case '9':
                            echo "<div id='message' class='updated fade'><p><strong>" . $_GET['importrowscount'] . " " . __('row(s) found', 'link-library') . ". " . (isset($_GET['successimportcount']) ? $_GET['successimportcount'] : '0') . " " . __('link(s) imported', 'link-library') . ", " . (isset($_GET['successupdatecount']) ? $_GET['successupdatecount'] : '0') . " " . __('link(s) updated', 'link-library') . ".</strong></p></div>";
                            break;
                        case '10':
                            echo "<div id='message' class='updated fade'><p><strong>" . __('Links are missing categories', 'link-library') . "</strong></p></div>";
                            break;
                    }
                }
            }
        } elseif ($_GET['page'] == 'link-library-moderate') {
            $formvalue = 'save_link_library_moderate';
            $pagetitle = '';
            if (isset($_GET['message']) && $_GET['message'] == '1') {
                echo "<div id='message' class='updated fade'><p><strong>" . __('Link(s) Approved', 'link-library') . "</strong></p></div>";
            } elseif (isset($_GET['message']) && $_GET['message'] == '2') {
                echo "<div id='message' class='updated fade'><p><strong>" . __('Link(s) Deleted', 'link-library') . "</strong></p></div>";
            }
            ?>

		<?php 
        } elseif ($_GET['page'] == 'link-library-stylesheet') {
            $formvalue = 'save_link_library_stylesheet';
            $pagetitle = '';
            if (isset($_GET['message']) && $_GET['message'] == '1') {
                echo "<div id='message' class='updated fade'><p><strong>" . __('Stylesheet updated', 'link-library') . ".</strong></p></div>";
            } elseif (isset($_GET['message']) && $_GET['message'] == '2') {
                echo "<div id='message' class='updated fade'><p><strong>" . __('Stylesheet reset to original state', 'link-library') . ".</strong></p></div>";
            }
        } elseif ($_GET['page'] == 'link-library-reciprocal') {
            $formvalue = 'save_link_library_reciprocal';
            $pagetitle = '';
            if (isset($_GET['message']) && $_GET['message'] == '1') {
                echo "<div id='message' class='updated fade'><p><strong>" . __('Settings updated', 'link-library') . ".</strong></p></div>";
            } elseif (isset($_GET['message']) && $_GET['message'] == '2') {
                echo "<div id='message' class='updated fade'><p>";
                echo $this->ReciprocalLinkChecker($genoptions['recipcheckaddress'], $genoptions['recipcheckdelete403'], 'reciprocal');
                echo "</p></div>";
            } elseif (isset($_GET['message']) && $_GET['message'] == '3') {
                echo "<div id='message' class='updated fade'><p>";
                echo $this->ReciprocalLinkChecker($genoptions['recipcheckaddress'], $genoptions['recipcheckdelete403'], 'broken');
                echo "</p></div>";
            }
        } elseif ($_GET['page'] == 'link-library-faq') {
            $formvalue = 'save_link_library_faq';
        }
        $data = array();
        $data['settings'] = $settings;
        $data['options'] = isset($options) ? $options : '';
        $data['genoptions'] = $genoptions;
        global $pagehooktop, $pagehookmoderate, $pagehookstylesheet, $pagehooksettingssets, $pagehookreciprocal, $pagehookfaq;
        ?>
		<div class="ll-content">
			<div class="ll-frame">
				<div class="header">
					<nav role="navigation" class="header-nav drawer-nav nav-horizontal">

						<ul class="main-nav">
							<li class="link-library-logo">
								<img src="<?php 
        echo plugins_url('icons/folder-beige-internet-icon32.png', __FILE__);
        ?>
" /><span>Link Library</span>
							</li>
							<li class="link-library-page">
								<a href="<?php 
        echo esc_url(add_query_arg(array('page' => 'link-library'), admin_url('admin.php')));
        ?>
" <?php 
        if (isset($_GET['page']) && $_GET['page'] == 'link-library') {
            echo 'class="current"';
        }
        ?>
><?php 
        _e('General Options', 'link-library');
        ?>
</a>
							</li>
							<li class="link-library-page">
								<a href="<?php 
        echo esc_url(add_query_arg(array('page' => 'link-library-settingssets'), admin_url('admin.php')));
        ?>
" <?php 
        if (isset($_GET['page']) && $_GET['page'] == 'link-library-settingssets') {
            echo 'class="current"';
        }
        ?>
><?php 
        _e('Library Settings', 'link-library');
        ?>
</a>
							</li>
							<li class="link-library-page">
								<a href="<?php 
        echo esc_url(add_query_arg(array('page' => 'link-library-moderate'), admin_url('admin.php')));
        ?>
" <?php 
        if (isset($_GET['page']) && $_GET['page'] == 'link-library-moderate') {
            echo 'class="current"';
        }
        ?>
><?php 
        _e('Moderate', 'link-library');
        ?>
</a>
							</li>
							<li class="link-library-page">
								<a href="<?php 
        echo esc_url(add_query_arg(array('page' => 'link-library-stylesheet'), admin_url('admin.php')));
        ?>
" <?php 
        if (isset($_GET['page']) && $_GET['page'] == 'link-library-stylesheet') {
            echo 'class="current"';
        }
        ?>
><?php 
        _e('Stylesheet', 'link-library');
        ?>
</a>
							</li>
							<li class="link-library-page">
								<a href="<?php 
        echo esc_url(add_query_arg(array('page' => 'link-library-reciprocal'), admin_url('admin.php')));
        ?>
" <?php 
        if (isset($_GET['page']) && $_GET['page'] == 'link-library-reciprocal') {
            echo 'class="current"';
        }
        ?>
><?php 
        _e('Reciprocal Check', 'link-library');
        ?>
</a>
							</li>
							<li class="link-library-page">
								<a href="<?php 
        echo esc_url(add_query_arg(array('page' => 'link-library-faq'), admin_url('admin.php')));
        ?>
" <?php 
        if (isset($_GET['page']) && $_GET['page'] == 'link-library-faq') {
            echo 'class="current"';
        }
        ?>
><?php 
        _e('FAQ', 'link-library');
        ?>
</a>
							</li>
							<?php 
        if (isset($genoptions['hidedonation']) && !$genoptions['hidedonation']) {
            ?>
								<li class="link-library-page">
									<a href="http://ylefebvre.ca/wordpress-plugins/link-library/"><img src="<?php 
            echo plugins_url('/icons/btn_donate_LG.gif', __FILE__);
            ?>
" /></a>
								</li>
							<?php 
        }
        ?>

						</ul>

					</nav>
				</div>
				<!-- .header -->
			</div>
		</div>
		<div id="link-library-general" class="wrap">
			<div class='icon32'>
				<img src="<?php 
        echo plugins_url('icons/folder-beige-internet-icon32.png', __FILE__);
        ?>
" />
			</div>
			<div><h2><?php 
        if (!empty($pagetitle)) {
            echo $pagetitle;
        }
        ?>
			</h2>
			</div>
			<div>
				<form name='linklibrary' enctype="multipart/form-data" action="admin-post.php" method="post">
					<input type="hidden" name="MAX_FILE_SIZE" value="100000" />

					<?php 
        wp_nonce_field('link-library');
        ?>
					<?php 
        wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
        ?>
					<?php 
        wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
        ?>
					<input type="hidden" name="action" value="<?php 
        echo $formvalue;
        ?>
" />

					<style type="text/css">
						#sortable {
							list-style-type: none;
							margin: 0;
							padding: 0;
							white-space: nowrap;
							list-style-type: none;
						}

						#sortable li {
							list-style: none;
							margin: 0 6px 4px 6px;
							padding: 10px 15px 10px 15px;
							border: #CCCCCC solid 1px;
							color: #fff;
							display: inline;
							width: 100px;
							height: 30px;
							cursor: move
						}

						#sortable li span {
							position: absolute;
							margin-left: -1.3em;
						}
					</style>

					<div id="poststuff" class="metabox-holder">
						<div id="post-body" class="has-sidebar">
							<div id="post-body-content" class="has-sidebar-content">
								<?php 
        if ($_GET['page'] == 'link-library') {
            $this->display_menu('general', $genoptions);
            $this->general_meta_box($data);
            $this->general_image_meta_box($data);
            $this->general_meta_bookmarklet_box($data);
            $this->general_moderation_meta_box($data);
            if (isset($genoptions['hidedonation']) && !$genoptions['hidedonation']) {
                $this->general_hide_donation_meta_box($data);
            }
            $this->general_save_meta_box();
        } elseif ($_GET['page'] == 'link-library-settingssets') {
            $this->settingssets_selection_meta_box($data);
            $this->display_menu('settingsset');
            $this->settingssets_usage_meta_box($data);
            $this->settingssets_common_meta_box($data);
            $this->settingssets_categories_meta_box($data);
            $this->settingssets_linkelement_meta_box($data);
            $this->settingssets_subfieldtable_meta_box($data);
            $this->settingssets_linkpopup_meta_box($data);
            $this->settingssets_rssconfig_meta_box($data);
            $this->settingssets_thumbnails_meta_box($data);
            $this->settingssets_rssgen_meta_box($data);
            $this->settingssets_search_meta_box($data);
            $this->settingssets_linksubmission_meta_box($data);
            $this->settingssets_importexport_meta_box($data);
            $this->general_save_meta_box($data);
            //do_meta_boxes( $pagehooksettingssets, 'normal', $data );
        } elseif ($_GET['page'] == 'link-library-moderate') {
            do_meta_boxes($pagehookmoderate, 'normal', $data);
        } elseif ($_GET['page'] == 'link-library-stylesheet') {
            do_meta_boxes($pagehookstylesheet, 'normal', $data);
        } elseif ($_GET['page'] == 'link-library-reciprocal') {
            do_meta_boxes($pagehookreciprocal, 'normal', $data);
        } elseif ($_GET['page'] == 'link-library-faq') {
            do_meta_boxes($pagehookfaq, 'normal', $data);
        }
        ?>
							</div>
						</div>
						<br class="clear" />
					</div>
				</form>
			</div>
		</div>
		<script type="text/javascript">
			//<![CDATA[
			jQuery(document).ready(function ($) {
				// close postboxes that should be closed
				$('.if-js-closed').removeClass('if-js-closed').addClass('closed');
				// postboxes setup
				postboxes.add_postbox_toggles('<?php 
        if ($_GET['page'] == 'link-library') {
            echo $pagehooktop;
        } elseif ($_GET['page'] == 'link-library-settingssets') {
            echo $pagehooksettingssets;
        } elseif ($_GET['page'] == 'link-library-moderate') {
            echo $pagehookmoderate;
        } elseif ($_GET['page'] == 'link-library-stylesheet') {
            echo $pagehookstylesheet;
        } elseif ($_GET['page'] == 'link-library-reciprocal') {
            echo $pagehookreciprocal;
        } elseif ($_GET['page'] == 'link-library-faq') {
            echo $pagehookfaq;
        }
        ?>
');
			});
			//]]>

			// Create the tooltips only on document load
			jQuery(document).ready(function () {
				jQuery('.lltooltip').each(function () {
						jQuery(this).tipTip();
					}
				);

				jQuery("#sortable").sortable({
					opacity: 0.6, cursor: 'move', update: function () {
						var order = jQuery("#sortable").sortable('toArray');
						stringorder = order.join(',')
						document.getElementById('dragndroporder').value = stringorder;
					}
				});

			});

		</script>

	<?php 
    }
/**
 *
 * Render the output of the link-library-search shortcode
 *
 * @param $LLPluginClass    Link Library main plugin class
 * @param $generaloptions   General Plugin Settings
 * @param $libraryoptions   Selected library settings array
 * @param $settings         Settings ID
 * @param $code             Shortcode used in text that called this function
 * @return                  List of categories output for browser
 */
function RenderLinkLibraryAddLinkForm($LLPluginClass, $generaloptions, $libraryoptions, $settings, $code)
{
    global $wpdb;
    $output = '';
    $generaloptions = wp_parse_args($generaloptions, ll_reset_gen_settings('return'));
    extract($generaloptions);
    $libraryoptions = wp_parse_args($libraryoptions, ll_reset_options(1, 'list', 'return'));
    extract($libraryoptions);
    /* This case will only happen if the user entered bad data in the admin page or if someone is trying to inject bad data in SQL query */
    if (!empty($categorylist)) {
        $categorylistarray = explode(',', $categorylist);
        if (true === array_filter($categorylistarray, 'is_int')) {
            return 'List of requested categories is invalid. Please go back to Link Library admin panel to correct.';
        }
    }
    if (!empty($excludecategorylist)) {
        $excludecategorylistarray = explode(',', $excludecategorylist);
        if (true === array_filter($excludecategorylistarray, 'is_int')) {
            return 'List of requested excluded categories is invalid. Please go back to Link Library admin panel to correct.';
        }
    }
    if ('link-library-addlink' == $code || 'addlink-link-library' == $code || 'link-library-addlinkcustommsg' == $code || 'addlinkcustommsg-link-library' == $code) {
        if (isset($_GET['addlinkmessage'])) {
            if (1 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Confirm code not given', 'link-library') . '.</div>';
            } elseif (2 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Captcha code is wrong', 'link-library') . '.</div>';
            } elseif (3 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Captcha code is only valid for 5 minutes', 'link-library') . '.</div>';
            } elseif (4 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('No captcha cookie given. Make sure cookies are enabled', 'link-library') . '.</div>';
            } elseif (5 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Captcha answer was not provided.', 'link-library') . '</div>';
            } elseif (6 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Captcha answer is incorrect', 'link-library') . '.</div>';
            } elseif (7 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('User Category was not provided correctly. Link insertion failed.', 'link-library') . '</div>';
            } elseif (8 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $newlinkmsg;
                if (!$showuserlinks) {
                    $output .= ' ' . $moderatemsg;
                }
                $output .= '</div>';
            } elseif (9 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Error: Link does not have an address.', 'link-library') . '</div>';
            } elseif (10 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Error: Link already exists.', 'link-library') . '</div>';
            }
        }
    }
    if (('link-library-addlink' == $code || 'addlink-link-library' == $code) && ($addlinkreqlogin && current_user_can('read') || !$addlinkreqlogin)) {
        $output .= '<form method="post" id="lladdlink" action="">';
        $output .= wp_nonce_field('LL_ADDLINK_FORM', '_wpnonce', true, false);
        $output .= '<input type="hidden" name="thankyouurl" value="' . $linksubmissionthankyouurl . '" />';
        $output .= '<input type="hidden" name="link_library_user_link_submission" value="1" />';
        global $wp_query;
        $thePostID = $wp_query->post->ID;
        $output .= '<input type="hidden" name="pageid" value="' . $thePostID . '" />';
        $output .= '<input type="hidden" name="settingsid" value="' . $settings . '" />';
        $xpath = $LLPluginClass->relativePath(dirname(__FILE__), ABSPATH);
        $output .= '<input type="hidden" name="xpath" value="' . esc_attr($xpath) . '" />';
        unset($xpath);
        $output .= "<div class='lladdlink'>\n";
        if (empty($addnewlinkmsg)) {
            $addnewlinkmsg = __('Add new link', 'link-library');
        }
        $output .= '<div id="lladdlinktitle">' . $addnewlinkmsg . "</div>\n";
        $output .= "<table>\n";
        if (empty($linknamelabel)) {
            $linknamelabel = __('Link name', 'link-library');
        }
        $output .= '<tr><th>' . $linknamelabel . '</th><td><input type="text" name="link_name" id="link_name" value="' . (isset($_GET['addlinkname']) ? esc_html(stripslashes($_GET['addlinkname']), '1') : '') . "\" /></td></tr>\n";
        if (empty($linkaddrlabel)) {
            $linkaddrlabel = __('Link address', 'link-library');
        }
        $output .= '<tr><th>' . $linkaddrlabel . '</th><td><input type="text" name="link_url" id="link_url" value="' . (isset($_GET['addlinkurl']) ? esc_html(stripslashes($_GET['addlinkurl']), '1') : '') . "\" /></td></tr>\n";
        if ($showaddlinkrss) {
            if (empty($linkrsslabel)) {
                $linkrsslabel = __('Link RSS', 'link-library');
            }
            $output .= '<tr><th>' . $linkrsslabel . '</th><td><input type="text" name="link_rss" id="link_rss" value="' . (isset($_GET['addlinkrss']) ? esc_html(stripslashes($_GET['addlinkrss']), '1') : '') . "\" /></td></tr>\n";
        }
        $linkcatquery = 'SELECT distinct t.name, t.term_id, t.slug as category_nicename, tt.description as category_description ';
        $linkcatquery .= 'FROM ' . $LLPluginClass->db_prefix() . 'terms t ';
        $linkcatquery .= 'LEFT JOIN ' . $LLPluginClass->db_prefix() . 'term_taxonomy tt ON (t.term_id = tt.term_id) ';
        $linkcatquery .= 'LEFT JOIN ' . $LLPluginClass->db_prefix() . 'term_relationships tr ON (tt.term_taxonomy_id = tr.term_taxonomy_id) ';
        $linkcatquery .= 'WHERE tt.taxonomy = "link_category" ';
        if (!empty($categorylist)) {
            $linkcatquery .= ' AND t.term_id in (' . $categorylist . ')';
        }
        if (!empty($excludecategorylist)) {
            $linkcatquery .= ' AND t.term_id not in (' . $excludecategorylist . ')';
        }
        $linkcatquery .= ' ORDER by t.name ASC';
        $linkcats = $wpdb->get_results($linkcatquery);
        if ($debugmode) {
            $output .= "\n<!-- Category query for add link form:" . print_r($linkcatquery, TRUE) . "-->\n\n";
            $output .= "\n<!-- Results of Category query for add link form:" . print_r($linkcats, TRUE) . "-->\n";
        }
        if ($linkcats) {
            if ($showaddlinkcat) {
                if (empty($linkcatlabel)) {
                    $linkcatlabel = __('Link category', 'link-library');
                }
                $output .= '<tr><th>' . $linkcatlabel . '</th><td><SELECT name="link_category" id="link_category">';
                if (empty($linkcustomcatlistentry)) {
                    $linkcustomcatlistentry = __('User-submitted category (define below)', 'link-library');
                }
                foreach ($linkcats as $linkcat) {
                    $output .= '<OPTION VALUE="' . $linkcat->term_id . '" ';
                    if (isset($_GET['addlinkcat']) && $_GET['addlinkcat'] == $linkcat->term_id) {
                        $output .= "selected";
                    }
                    $output .= '>' . $linkcat->name;
                }
                if ($addlinkcustomcat) {
                    $output .= '<OPTION VALUE="new">' . stripslashes($linkcustomcatlistentry) . "\n";
                }
                $output .= "</SELECT></td></tr>\n";
            } else {
                $output .= '<input type="hidden" name="link_category" id="link_category" value="' . $linkcats[0]->term_id . '">';
            }
            if ($addlinkcustomcat) {
                $output .= '<tr><th>' . $linkcustomcatlabel . '</th><td><input type="text" name="link_user_category" id="link_user_category" value="' . (isset($_GET['addlinkusercat']) ? esc_html(stripslashes($_GET['addlinkusercat']), '1') : '') . "\" /></td></tr>\n";
            }
        }
        if ($showaddlinkdesc) {
            if (empty($linkdesclabel)) {
                $linkdesclabel = __('Link description', 'link-library');
            }
            $output .= '<tr><th>' . $linkdesclabel . '</th><td><input type="text" name="link_description" id="link_description" value="' . (isset($_GET['addlinkdesc']) ? esc_html(stripslashes($_GET['addlinkdesc']), '1') : '') . "\" /></td></tr>\n";
        }
        if ($showuserlargedescription) {
            if (empty($linklargedesclabel)) {
                $linklargedesclabel = __('Large description', 'link-library');
            }
            $output .= '<tr><th style="vertical-align: top">' . $linklargedesclabel . '</th><td><textarea name="link_textfield" id="link_textfield" cols="66">' . (isset($_GET['addlinktextfield']) ? esc_html(stripslashes($_GET['addlinktextfield']), '1') : '') . "</textarea></td></tr>\n";
        }
        if ($showaddlinknotes) {
            if (empty($linknoteslabel)) {
                $linknoteslabel = __('Link notes', 'link-library');
            }
            $output .= '<tr><th>' . $linknoteslabel . '</th><td>';
            if (!$usetextareaforusersubmitnotes || empty($usetextareaforusersubmitnotes)) {
                $output .= '<input type="text" name="link_notes" id="link_notes" value="';
            } elseif ($usetextareaforusersubmitnotes) {
                $output .= '<textarea name="link_notes" id="link_notes">';
            }
            $output .= isset($_GET['addlinknotes']) ? esc_html(stripslashes($_GET['addlinknotes']), '1') : '';
            if (!$usetextareaforusersubmitnotes || empty($usetextareaforusersubmitnotes)) {
                $output .= '" />';
            } elseif ($usetextareaforusersubmitnotes) {
                $output .= '</textarea>';
            }
            $output .= "</td></tr>\n";
        }
        if ($showaddlinkreciprocal) {
            if (empty($linkreciprocallabel)) {
                $linkreciprocallabel = __('Reciprocal Link', 'link-library');
            }
            $output .= '<tr><th>' . $linkreciprocallabel . '</th><td><input type="text" name="ll_reciprocal" id="ll_reciprocal" value="' . (isset($_GET['addlinkreciprocal']) ? esc_html(stripslashes($_GET['addlinkreciprocal']), '1') : '') . "\" /></td></tr>\n";
        }
        if ($showaddlinksecondurl) {
            if (empty($linksecondurllabel)) {
                $linksecondurllabel = __('Secondary Address', 'link-library');
            }
            $output .= '<tr><th>' . $linksecondurllabel . '</th><td><input type="text" name="ll_secondwebaddr" id="ll_secondwebaddr" value="' . (isset($_GET['addlinksecondurl']) ? esc_html(stripslashes($_GET['addlinksecondurl']), '1') : '') . "\" /></td></tr>\n";
        }
        if ($showaddlinktelephone) {
            if (empty($linktelephonelabel)) {
                $linktelephonelabel = __('Telephone', 'link-library');
            }
            $output .= '<tr><th>' . $linktelephonelabel . '</th><td><input type="text" name="ll_telephone" id="ll_telephone" value="' . (isset($_GET['addlinktelephone']) ? esc_html(stripslashes($_GET['addlinktelephone']), '1') : '') . "\" /></td></tr>\n";
        }
        if ($showaddlinkemail) {
            if (empty($linkemaillabel)) {
                $linkemaillabel = __('E-mail', 'link-library');
            }
            $output .= '<tr><th>' . $linkemaillabel . '</th><td><input type="text" name="ll_email" id="ll_email" value="' . (isset($_GET['addlinkemail']) ? esc_html(stripslashes($_GET['addlinkemail']), '1') : '') . "\" /></td></tr>\n";
        }
        if ($showlinksubmittername) {
            if (empty($linksubmitternamelabel)) {
                $linksubmitternamelabel = __('Submitter Name', 'link-library');
            }
            $output .= '<tr><th>' . $linksubmitternamelabel . '</th><td><input type="text" name="ll_submittername" id="ll_submittername" value="' . (isset($_GET['addlinksubmitname']) ? esc_html(stripslashes($_GET['addlinksubmitname']), '1') : '') . "\" /></td></tr>\n";
        }
        if ($showaddlinksubmitteremail) {
            if (empty($linksubmitteremaillabel)) {
                $linksubmitteremaillabel = __('Submitter E-mail', 'link-library');
            }
            $output .= '<tr><th>' . $linksubmitteremaillabel . '</th><td><input type="text" name="ll_submitteremail" id="ll_submitteremail" value="' . (isset($_GET['addlinksubmitemail']) ? esc_html(stripslashes($_GET['addlinksubmitemail']), '1') : '') . "\" /></td></tr>\n";
        }
        if ($showlinksubmittercomment) {
            if (empty($linksubmittercommentlabel)) {
                $linksubmittercommentlabel = __('Submitter Comment', 'link-library');
            }
            $output .= '<tr><th style="vertical-align: top;">' . $linksubmittercommentlabel . '</th><td><textarea name="ll_submittercomment" id="ll_submittercomment" cols="38">' . (isset($_GET['addlinksubmitcomment']) ? esc_html(stripslashes($_GET['addlinksubmitcomment']), '1') : '') . "</textarea></td></tr>\n";
        }
        if ($showcaptcha) {
            $output .= '<tr><td></td><td><span id="captchaimage"><img src="' . plugins_url('captcha/easycaptcha.php', __FILE__) . "\" /></span></td></tr>\n";
            $output .= '<tr><th>' . __('Enter code from above image', 'link-library') . "</th><td><input type='text' name='confirm_code' /></td></tr>\n";
        }
        if ($showcustomcaptcha) {
            if (empty($customcaptchaquestion)) {
                $customcaptchaquestion = __('Is boiling water hot or cold?', 'link-library');
            }
            $output .= '<tr><th style="vertical-align: top;">' . $customcaptchaquestion . '</th><td><input type="text" name="ll_customcaptchaanswer" id="ll_customcaptchaanswer" value="' . (isset($_GET['ll_customcaptchaanswer']) ? esc_html(stripslashes($_GET['ll_customcaptchaanswer']), '1') : '') . "\" /></td></tr>\n";
        }
        $output .= "</table>\n";
        if (empty($addlinkbtnlabel)) {
            $addlinkbtnlabel = __('Add link', 'link-library');
        }
        $output .= '<span style="border:0;" class="LLUserLinkSubmit"><input type="submit" name="submit" value="' . $addlinkbtnlabel . '" /></span>';
        $output .= "</div>\n";
        $output .= "</form>\n\n";
    }
    return $output;
}
/**
 *
 * Render the output of the link-library-search shortcode
 *
 * @param $LLPluginClass    Link Library main plugin class
 * @param $generaloptions   General Plugin Settings
 * @param $libraryoptions   Selected library settings array
 * @param $settings         Settings ID
 * @param $code             Shortcode used in text that called this function
 * @return                  List of categories output for browser
 */
function RenderLinkLibraryAddLinkForm($LLPluginClass, $generaloptions, $libraryoptions, $settings, $code)
{
    wp_enqueue_script('form-validator');
    global $wpdb;
    $output = '';
    $generaloptions = wp_parse_args($generaloptions, ll_reset_gen_settings('return'));
    extract($generaloptions);
    $libraryoptions = wp_parse_args($libraryoptions, ll_reset_options(1, 'list', 'return'));
    extract($libraryoptions);
    if ($libraryoptions['showaddlinkrss'] === false) {
        $libraryoptions['showaddlinkrss'] = 'hide';
    } elseif ($libraryoptions['showaddlinkrss'] === true) {
        $libraryoptions['showaddlinkrss'] = 'show';
    }
    if ($libraryoptions['showaddlinkdesc'] === false) {
        $libraryoptions['showaddlinkdesc'] = 'hide';
    } elseif ($libraryoptions['showaddlinkdesc'] === true) {
        $libraryoptions['showaddlinkdesc'] = 'show';
    }
    if ($libraryoptions['showaddlinkcat'] === false) {
        $libraryoptions['showaddlinkcat'] = 'hide';
    } elseif ($libraryoptions['showaddlinkcat'] === true) {
        $libraryoptions['showaddlinkcat'] = 'show';
    }
    if ($libraryoptions['showaddlinknotes'] === false) {
        $libraryoptions['showaddlinknotes'] = 'hide';
    } elseif ($libraryoptions['showaddlinknotes'] === true) {
        $libraryoptions['showaddlinknotes'] = 'show';
    }
    if ($libraryoptions['addlinkcustomcat'] === false) {
        $libraryoptions['addlinkcustomcat'] = 'hide';
    } elseif ($libraryoptions['addlinkcustomcat'] === true) {
        $libraryoptions['addlinkcustomcat'] = 'show';
    }
    if ($libraryoptions['showaddlinkreciprocal'] === false) {
        $libraryoptions['showaddlinkreciprocal'] = 'hide';
    } elseif ($libraryoptions['showaddlinkreciprocal'] === true) {
        $libraryoptions['showaddlinkreciprocal'] = 'show';
    }
    if ($libraryoptions['showaddlinksecondurl'] === false) {
        $libraryoptions['showaddlinksecondurl'] = 'hide';
    } elseif ($libraryoptions['showaddlinksecondurl'] === true) {
        $libraryoptions['showaddlinksecondurl'] = 'show';
    }
    if ($libraryoptions['showaddlinktelephone'] === false) {
        $libraryoptions['showaddlinktelephone'] = 'hide';
    } elseif ($libraryoptions['showaddlinktelephone'] === true) {
        $libraryoptions['showaddlinktelephone'] = 'show';
    }
    if ($libraryoptions['showaddlinkemail'] === false) {
        $libraryoptions['showaddlinkemail'] = 'hide';
    } elseif ($libraryoptions['showaddlinkemail'] === true) {
        $libraryoptions['showaddlinkemail'] = 'show';
    }
    if ($libraryoptions['showlinksubmittername'] === false) {
        $libraryoptions['showlinksubmittername'] = 'hide';
    } elseif ($libraryoptions['showlinksubmittername'] === true) {
        $libraryoptions['showlinksubmittername'] = 'show';
    }
    if ($libraryoptions['showaddlinksubmitteremail'] === false) {
        $libraryoptions['showaddlinksubmitteremail'] = 'hide';
    } elseif ($libraryoptions['showaddlinksubmitteremail'] === true) {
        $libraryoptions['showaddlinksubmitteremail'] = 'show';
    }
    if ($libraryoptions['showlinksubmittercomment'] === false) {
        $libraryoptions['showlinksubmittercomment'] = 'hide';
    } elseif ($libraryoptions['showlinksubmittercomment'] === true) {
        $libraryoptions['showlinksubmittercomment'] = 'show';
    }
    if ($libraryoptions['showcustomcaptcha'] === false) {
        $libraryoptions['showcustomcaptcha'] = 'hide';
    } elseif ($libraryoptions['showcustomcaptcha'] === true) {
        $libraryoptions['showcustomcaptcha'] = 'show';
    }
    if ($libraryoptions['showuserlargedescription'] === false) {
        $libraryoptions['showuserlargedescription'] = 'hide';
    } elseif ($libraryoptions['showuserlargedescription'] === true) {
        $libraryoptions['showuserlargedescription'] = 'show';
    }
    /* This case will only happen if the user entered bad data in the admin page or if someone is trying to inject bad data in SQL query */
    if (!empty($categorylist)) {
        $categorylistarray = explode(',', $categorylist);
        if (true === array_filter($categorylistarray, 'is_int')) {
            return 'List of requested categories is invalid. Please go back to Link Library admin panel to correct.';
        }
    }
    if (!empty($excludecategorylist)) {
        $excludecategorylistarray = explode(',', $excludecategorylist);
        if (true === array_filter($excludecategorylistarray, 'is_int')) {
            return 'List of requested excluded categories is invalid. Please go back to Link Library admin panel to correct.';
        }
    }
    if ('link-library-addlink' == $code || 'addlink-link-library' == $code || 'link-library-addlinkcustommsg' == $code || 'addlinkcustommsg-link-library' == $code) {
        if (isset($_GET['addlinkmessage'])) {
            if (1 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Confirm code not given', 'link-library') . '.</div>';
            } elseif (2 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Captcha code is wrong', 'link-library') . '.</div>';
            } elseif (3 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Captcha code is only valid for 5 minutes', 'link-library') . '.</div>';
            } elseif (4 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('No captcha cookie given. Make sure cookies are enabled', 'link-library') . '.</div>';
            } elseif (5 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Captcha answer was not provided.', 'link-library') . '</div>';
            } elseif (6 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Captcha answer is incorrect', 'link-library') . '.</div>';
            } elseif (7 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('User Category was not provided correctly. Link insertion failed.', 'link-library') . '</div>';
            } elseif (8 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $newlinkmsg;
                if (!$showuserlinks) {
                    $output .= ' ' . $moderatemsg;
                }
                $output .= '</div>';
            } elseif (9 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Error: Link does not have an address.', 'link-library') . '</div>';
            } elseif (10 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Error: Link already exists.', 'link-library') . '</div>';
            } elseif (11 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $libraryoptions['linkrsslabel'] . __(' is a required field', 'link-library') . '</div>';
            } elseif (12 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $libraryoptions['linkdesclabel'] . __(' is a required field', 'link-library') . '</div>';
            } elseif (13 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $libraryoptions['linknoteslabel'] . __(' is a required field', 'link-library') . '</div>';
            } elseif (14 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $libraryoptions['linkreciprocallabel'] . __(' is a required field', 'link-library') . '</div>';
            } elseif (15 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $libraryoptions['linksecondurllabel'] . __(' is a required field', 'link-library') . '</div>';
            } elseif (16 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $libraryoptions['linktelephonelabel'] . __(' is a required field', 'link-library') . '</div>';
            } elseif (17 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $libraryoptions['linkemaillabel'] . __(' is a required field', 'link-library') . '</div>';
            } elseif (18 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $libraryoptions['linksubmitternamelabel'] . __(' is a required field', 'link-library') . '</div>';
            } elseif (19 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $libraryoptions['linksubmitteremaillabel'] . __(' is a required field', 'link-library') . '</div>';
            } elseif (20 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $libraryoptions['linksubmittercommentlabel'] . __(' is a required field', 'link-library') . '</div>';
            } elseif (21 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . $libraryoptions['linklargedesclabel'] . __(' is a required field', 'link-library') . '</div>';
            } elseif (22 == $_GET['addlinkmessage']) {
                $output .= '<div class="llmessage">' . __('Link submission error', 'link-library') . '</div>';
            }
        }
    }
    if (('link-library-addlink' == $code || 'addlink-link-library' == $code) && ($addlinkreqlogin && current_user_can('read') || !$addlinkreqlogin)) {
        $output .= '<form method="post" id="lladdlink" action="">';
        $output .= wp_nonce_field('LL_ADDLINK_FORM', '_wpnonce', true, false);
        $output .= '<input type="hidden" name="thankyouurl" value="' . $linksubmissionthankyouurl . '" />';
        $output .= '<input type="hidden" name="link_library_user_link_submission" value="1" />';
        global $wp_query;
        $thePostID = $wp_query->post->ID;
        $output .= '<input type="hidden" name="pageid" value="' . $thePostID . '" />';
        $output .= '<input type="hidden" name="settingsid" value="' . $settings . '" />';
        $xpath = $LLPluginClass->relativePath(dirname(__FILE__), ABSPATH);
        $output .= '<input type="hidden" name="xpath" value="' . esc_attr($xpath) . '" />';
        unset($xpath);
        $output .= "<div class='lladdlink'>\n";
        if (empty($addnewlinkmsg)) {
            $addnewlinkmsg = __('Add new link', 'link-library');
        }
        $output .= '<div id="lladdlinktitle">' . $addnewlinkmsg . "</div>\n";
        $output .= "<table>\n";
        if (empty($linknamelabel)) {
            $linknamelabel = __('Link name', 'link-library');
        }
        $output .= '<tr><th>' . $linknamelabel . '</th><td><input data-validation="required length" data-validation-length="max255" data-validation-error-msg-required="' . __('Required field', 'link-library') . '" type="text" name="link_name" id="link_name" value="' . (isset($_GET['addlinkname']) ? esc_html(stripslashes($_GET['addlinkname']), '1') : '') . "\" /></td></tr>\n";
        if (empty($linkaddrlabel)) {
            $linkaddrlabel = __('Link address', 'link-library');
        }
        $output .= '<tr><th>' . $linkaddrlabel . '</th><td><input ';
        if (!$addlinknoaddress) {
            $output .= 'data-validation="required url length" data-validation-length="max255" data-validation-error-msg-required="' . __('Required field, URL', 'link-library') . '" ';
        }
        $output .= 'type="text" name="link_url" id="link_url" value="' . (isset($_GET['addlinkurl']) ? esc_html(stripslashes($_GET['addlinkurl']), '1') : '') . "\" /></td></tr>\n";
        if ('show' == $showaddlinkrss || 'required' == $showaddlinkrss) {
            if (empty($linkrsslabel)) {
                $linkrsslabel = __('Link RSS', 'link-library');
            }
            $output .= '<tr><th>' . $linkrsslabel . '</th><td><input ';
            if ('required' == $showaddlinkrss) {
                $requiredtext = ' required';
            } else {
                $requiredtext = '';
            }
            $output .= 'data-validation="length' . $requiredtext . '" data-validation-length="max255" data-validation-error-msg-required="' . __('Required field, 1-255 chars', 'link-library') . '" ';
            $output .= ' type="text" name="link_rss" id="link_rss" value="' . (isset($_GET['addlinkrss']) ? esc_html(stripslashes($_GET['addlinkrss']), '1') : '') . "\" /></td></tr>\n";
        }
        $linkcatquery = 'SELECT distinct t.name, t.term_id, t.slug as category_nicename, tt.description as category_description ';
        $linkcatquery .= 'FROM ' . $LLPluginClass->db_prefix() . 'terms t ';
        $linkcatquery .= 'LEFT JOIN ' . $LLPluginClass->db_prefix() . 'term_taxonomy tt ON (t.term_id = tt.term_id) ';
        $linkcatquery .= 'LEFT JOIN ' . $LLPluginClass->db_prefix() . 'term_relationships tr ON (tt.term_taxonomy_id = tr.term_taxonomy_id) ';
        $linkcatquery .= 'WHERE tt.taxonomy = "link_category" ';
        if (!empty($categorylist)) {
            $linkcatquery .= ' AND t.term_id in (' . $categorylist . ')';
        }
        if (!empty($excludecategorylist)) {
            $linkcatquery .= ' AND t.term_id not in (' . $excludecategorylist . ')';
        }
        $linkcatquery .= ' ORDER by t.name ASC';
        $linkcats = $wpdb->get_results($linkcatquery);
        if ($debugmode) {
            $output .= "\n<!-- Category query for add link form:" . print_r($linkcatquery, TRUE) . "-->\n\n";
            $output .= "\n<!-- Results of Category query for add link form:" . print_r($linkcats, TRUE) . "-->\n";
        }
        if ($linkcats) {
            if ('show' == $showaddlinkcat || 'required' == $showaddlinkcat) {
                if (empty($linkcatlabel)) {
                    $linkcatlabel = __('Link category', 'link-library');
                }
                $output .= '<tr><th>' . $linkcatlabel . '</th><td>';
                $output .= '<SELECT data-validation="required" data-validation-error-msg-required="' . __('Required field', 'link-library') . '" name="link_category" id="link_category">';
                if ('nodefaultcat' == $addlinkdefaultcat) {
                    $output .= '<option value="">' . __('Select a category', 'link-category') . '</option>';
                }
                if (empty($linkcustomcatlistentry)) {
                    $linkcustomcatlistentry = __('User-submitted category (define below)', 'link-library');
                }
                foreach ($linkcats as $linkcat) {
                    $output .= '<OPTION VALUE="' . $linkcat->term_id . '" ';
                    if (isset($_GET['addlinkcat']) && $_GET['addlinkcat'] == $linkcat->term_id) {
                        $output .= "selected";
                    } elseif ('nodefaultcat' != $addlinkdefaultcat && $linkcat->term_id == intval($addlinkdefaultcat)) {
                        $output .= "selected";
                    }
                    $output .= '>' . $linkcat->name;
                }
                if ('show' == $addlinkcustomcat) {
                    $output .= '<OPTION VALUE="new">' . stripslashes($linkcustomcatlistentry) . "\n";
                }
                $output .= "</SELECT></td></tr>\n";
            } else {
                $output .= '<input type="hidden" name="link_category" id="link_category" value="';
                if ('nodefaultcat' == $addlinkdefaultcat) {
                    $output .= $linkcats[0]->term_id;
                } else {
                    $output .= intval($addlinkdefaultcat);
                }
                $output .= '">';
            }
            if ('show' == $addlinkcustomcat) {
                $output .= '<tr class="customcatrow" style="display:none"><th>' . $linkcustomcatlabel . '</th><td><input type="text" name="link_user_category" id="link_user_category" value="' . (isset($_GET['addlinkusercat']) ? esc_html(stripslashes($_GET['addlinkusercat']), '1') : '') . "\" /></td></tr>\n";
            }
        }
        if ('show' == $showaddlinkdesc || 'required' == $showaddlinkdesc) {
            if (empty($linkdesclabel)) {
                $linkdesclabel = __('Link description', 'link-library');
            }
            $output .= '<tr><th>' . $linkdesclabel . '</th><td><input ';
            if ('required' == $showaddlinkrss) {
                $requiredtext = ' required';
            } else {
                $requiredtext = '';
            }
            $output .= 'data-validation="length' . $requiredtext . '" data-validation-length="max255" data-validation-error-msg-required="' . __('Required field, 1-255 chars', 'link-library') . '" ';
            $output .= ' type="text" name="link_description" id="link_description" value="' . (isset($_GET['addlinkdesc']) ? esc_html(stripslashes($_GET['addlinkdesc']), '1') : '') . "\" /></td></tr>\n";
        }
        if ('show' == $showuserlargedescription || 'required' == $showuserlargedescription) {
            if (empty($linklargedesclabel)) {
                $linklargedesclabel = __('Large description', 'link-library');
            }
            $output .= '<tr><th style="vertical-align: top">' . $linklargedesclabel . '</th><td><textarea ';
            if ('required' == $showuserlargedescription) {
                $output .= 'data-validation="required" data-validation-error-msg-required="' . __('Required field', 'link-library') . '" ';
            }
            $output .= ' name="link_textfield" id="link_textfield" cols="66">' . (isset($_GET['addlinktextfield']) ? esc_html(stripslashes($_GET['addlinktextfield']), '1') : '') . "</textarea></td></tr>\n";
        }
        if ('show' == $showaddlinknotes || 'required' == $showaddlinknotes) {
            if (empty($linknoteslabel)) {
                $linknoteslabel = __('Link notes', 'link-library');
            }
            $output .= '<tr><th>' . $linknoteslabel . '</th><td>';
            if (!$usetextareaforusersubmitnotes || empty($usetextareaforusersubmitnotes)) {
                $output .= '<input ';
                if ('required' == $showaddlinknotes) {
                    $output .= 'data-validation="required" data-validation-error-msg-required="' . __('Required field', 'link-library') . '" ';
                }
                $output .= 'type="text" name="link_notes" id="link_notes" value="';
            } elseif ($usetextareaforusersubmitnotes) {
                $output .= '<textarea ';
                if ('required' == $showaddlinknotes) {
                    $output .= 'data-validation="required" data-validation-error-msg-required="' . __('Required field', 'link-library') . '" ';
                }
                $output .= 'name="link_notes" id="link_notes">';
            }
            $output .= isset($_GET['addlinknotes']) ? esc_html(stripslashes($_GET['addlinknotes']), '1') : '';
            if (!$usetextareaforusersubmitnotes || empty($usetextareaforusersubmitnotes)) {
                $output .= '" />';
            } elseif ($usetextareaforusersubmitnotes) {
                $output .= '</textarea>';
            }
            $output .= "</td></tr>\n";
        }
        if ('show' == $showaddlinkreciprocal || 'required' == $showaddlinkreciprocal) {
            if (empty($linkreciprocallabel)) {
                $linkreciprocallabel = __('Reciprocal Link', 'link-library');
            }
            $output .= '<tr><th>' . $linkreciprocallabel . '</th><td><input ';
            if ('required' == $showaddlinkrss) {
                $requiredtext = ' required';
            } else {
                $requiredtext = '';
            }
            $output .= 'data-validation="length' . $requiredtext . '" data-validation-length="max255" data-validation-error-msg-required="' . __('Required field, 1-255 chars', 'link-library') . '" ';
            $output .= 'type="text" name="ll_reciprocal" id="ll_reciprocal" value="' . (isset($_GET['addlinkreciprocal']) ? esc_html(stripslashes($_GET['addlinkreciprocal']), '1') : '') . "\" /></td></tr>\n";
        }
        if ('show' == $showaddlinksecondurl || 'required' == $showaddlinksecondurl) {
            if (empty($linksecondurllabel)) {
                $linksecondurllabel = __('Secondary Address', 'link-library');
            }
            $output .= '<tr><th>' . $linksecondurllabel . '</th><td><input ';
            if ('required' == $showaddlinkrss) {
                $requiredtext = ' required';
            } else {
                $requiredtext = '';
            }
            $output .= 'data-validation="length' . $requiredtext . '" data-validation-length="max255" data-validation-error-msg-required="' . __('Required field', 'link-library') . '" ';
            $output .= 'type="text" name="ll_secondwebaddr" id="ll_secondwebaddr" value="' . (isset($_GET['addlinksecondurl']) ? esc_html(stripslashes($_GET['addlinksecondurl']), '1') : '') . "\" /></td></tr>\n";
        }
        if ('show' == $showaddlinktelephone || 'required' == $showaddlinktelephone) {
            if (empty($linktelephonelabel)) {
                $linktelephonelabel = __('Telephone', 'link-library');
            }
            $output .= '<tr><th>' . $linktelephonelabel . '</th><td><input ';
            if ('required' == $showaddlinkrss) {
                $requiredtext = ' required';
            } else {
                $requiredtext = '';
            }
            $output .= 'data-validation="length' . $requiredtext . '" data-validation-length="max128" data-validation-error-msg-required="' . __('Required field', 'link-library') . '" ';
            $output .= 'type="text" name="ll_telephone" id="ll_telephone" value="' . (isset($_GET['addlinktelephone']) ? esc_html(stripslashes($_GET['addlinktelephone']), '1') : '') . "\" /></td></tr>\n";
        }
        if ('show' == $showaddlinkemail || 'required' == $showaddlinkemail) {
            if (empty($linkemaillabel)) {
                $linkemaillabel = __('E-mail', 'link-library');
            }
            $output .= '<tr><th>' . $linkemaillabel . '</th><td><input ';
            if ('required' == $showaddlinkrss) {
                $requiredtext = ' required';
            } else {
                $requiredtext = '';
            }
            $output .= 'data-validation="email length' . $requiredtext . '" data-validation-length="max128" data-validation-error-msg-required="' . __('Required field, proper e-mail, 1-128 chars', 'link-library') . '" ';
            $output .= 'type="text" name="ll_email" id="ll_email" value="' . (isset($_GET['addlinkemail']) ? esc_html(stripslashes($_GET['addlinkemail']), '1') : '') . "\" /></td></tr>\n";
        }
        if ('show' == $showlinksubmittername || 'required' == $showlinksubmittername || is_user_logged_in()) {
            if (empty($linksubmitternamelabel)) {
                $linksubmitternamelabel = __('Submitter Name', 'link-library');
            }
            $name_field_value = '';
            if (isset($_GET['ll_submittername'])) {
                $name_field_value = esc_html(stripslashes($_GET['ll_submittername']));
            } elseif (is_user_logged_in()) {
                $user_data = wp_get_current_user();
                $name_field_value = $user_data->display_name;
            }
            $output .= '<tr';
            if ('show' != $showlinksubmittername && 'required' != $showlinksubmittername) {
                $output .= ' style="display:none"';
            }
            $output .= '><th>' . $linksubmitternamelabel . '</th><td><input ';
            if ('required' == $showaddlinkrss) {
                $requiredtext = ' required';
            } else {
                $requiredtext = '';
            }
            $output .= 'data-validation="length' . $requiredtext . '" data-validation-length="max128" data-validation-error-msg-required="' . __('Required field, 1-128 chars', 'link-library') . '" ';
            $output .= 'type="text" name="ll_submittername" id="ll_submittername" value="' . $name_field_value . "\" /></td></tr>\n";
        }
        if ('show' == $showaddlinksubmitteremail || 'required' == $showaddlinksubmitteremail || is_user_logged_in()) {
            if (empty($linksubmitteremaillabel)) {
                $linksubmitteremaillabel = __('Submitter E-mail', 'link-library');
            }
            $email_field_value = '';
            if (isset($_GET['ll_submitteremail'])) {
                $email_field_value = esc_html(stripslashes($_GET['ll_submitteremail']));
            } elseif (is_user_logged_in()) {
                $user_data = wp_get_current_user();
                $email_field_value = $user_data->user_email;
            }
            $output .= '<tr';
            if ('show' != $showaddlinksubmitteremail && 'required' != $showaddlinksubmitteremail) {
                $output .= ' style="display:none"';
            }
            $output .= '><th>' . $linksubmitteremaillabel . '</th><td><input ';
            if ('required' == $showaddlinkrss) {
                $requiredtext = ' required';
            } else {
                $requiredtext = '';
            }
            $output .= 'data-validation="email length' . $requiredtext . '" data-validation-length="max128" data-validation-error-msg-required="' . __('Required field, 1-128 chars', 'link-library') . '" ';
            $output .= 'type="text" name="ll_submitteremail" id="ll_submitteremail" value="' . $email_field_value . "\" /></td></tr>\n";
        }
        if ('show' == $showlinksubmittercomment || 'required' == $showlinksubmittercomment) {
            if (empty($linksubmittercommentlabel)) {
                $linksubmittercommentlabel = __('Submitter Comment', 'link-library');
            }
            $output .= '<tr><th style="vertical-align: top;">' . $linksubmittercommentlabel . '</th><td><textarea ';
            if ('required' == $showlinksubmittercomment) {
                $output .= 'data-validation="required" data-validation-error-msg-required="' . __('Required field', 'link-library') . '" ';
            }
            $output .= 'name="ll_submittercomment" id="ll_submittercomment" cols="38">' . (isset($_GET['addlinksubmitcomment']) ? esc_html(stripslashes($_GET['addlinksubmitcomment']), '1') : '') . "</textarea></td></tr>\n";
        }
        if ($showcaptcha) {
            $output .= apply_filters('link_library_generate_captcha', '');
        }
        if ('show' == $showcustomcaptcha) {
            if (empty($customcaptchaquestion)) {
                $customcaptchaquestion = __('Is boiling water hot or cold?', 'link-library');
            }
            $output .= '<tr><th style="vertical-align: top;">' . $customcaptchaquestion . '</th><td><input data-validation="required" data-validation-error-msg-required="' . __('Required field', 'link-library') . ' type="text" name="ll_customcaptchaanswer" id="ll_customcaptchaanswer" value="' . (isset($_GET['ll_customcaptchaanswer']) ? esc_html(stripslashes($_GET['ll_customcaptchaanswer']), '1') : '') . "\" /></td></tr>\n";
        }
        $output .= "</table>\n";
        if (empty($addlinkbtnlabel)) {
            $addlinkbtnlabel = __('Add link', 'link-library');
        }
        $output .= '<span style="border:0;" class="LLUserLinkSubmit"><input type="submit" name="submit" value="' . $addlinkbtnlabel . '" /></span>';
        $output .= "</div>\n";
        $output .= "</form>\n\n";
        $output .= "<script type='text/javascript'>\n";
        $output .= "\tjQuery( document ).ready( function() {\n";
        $output .= "\tvar LinkLibraryValidationLanguage = {\n";
        $output .= "\t\terrorTitle: '" . __('Form submission failed!', 'link-library') . "',\n";
        $output .= "\t\trequiredFields: '" . __('You have not answered all required fields', 'link-library') . "',\n";
        $output .= "\t\tbadTime: '" . __('You have not given a correct time', 'link-library') . "',\n";
        $output .= "\t\tbadEmail: '" . __('You have not given a correct e-mail address', 'link-library') . "',\n";
        $output .= "\t\tbadTelephone: '" . __('You have not given a correct phone number', 'link-library') . "',\n";
        $output .= "\t\tbadSecurityAnswer: '" . __('You have not given a correct answer to the security question', 'link-library') . "',\n";
        $output .= "\t\tbadDate: '" . __('You have not given a correct date', 'link-library') . "',\n";
        $output .= "\t\tlengthBadStart: '" . __('The input value must be between ', 'link-library') . "',\n";
        $output .= "\t\tlengthBadEnd: '" . __('characters', 'link-library') . "',\n";
        $output .= "\t\tlengthTooLongStart: '" . __('The input value is longer than ', 'link-library') . "',\n";
        $output .= "\t\tlengthTooShortStart: '" . __('The input value is shorter than ', 'link-library') . "',\n";
        $output .= "\t\tnotConfirmed: '" . __('Input values could not be confirmed', 'link-library') . "',\n";
        $output .= "\t\tbadDomain: '" . __('Incorrect domain value', 'link-library') . "',\n";
        $output .= "\t\tbadUrl: '" . __('The input value is not a correct URL', 'link-library') . "',\n";
        $output .= "\t\tbadCustomVal: '" . __('The input value is incorrect', 'link-library') . "',\n";
        $output .= "\t\tandSpaces: '" . __(' and spaces ', 'link-library') . "',\n";
        $output .= "\t\tbadInt: '" . __('The input value was not a correct number', 'link-library') . "',\n";
        $output .= "\t\tbadSecurityNumber: '" . __('Your social security number was incorrect', 'link-library') . "',\n";
        $output .= "\t\tbadUKVatAnswer: '" . __('Incorrect UK VAT Number', 'link-library') . "',\n";
        $output .= "\t\tbadStrength: '" . __('The password is not strong enough', 'link-library') . "',\n";
        $output .= "\t\tbadNumberOfSelectedOptionsStart: '" . __('You have to choose at least ', 'link-library') . "',\n";
        $output .= "\t\tbadNumberOfSelectedOptionsEnd: '" . __(' answers', 'link-library') . "',\n";
        $output .= "\t\tbadAlphaNumeric: '" . __('The input value can only contain alphanumeric characters ', 'link-library') . "',\n";
        $output .= "\t\tbadAlphaNumericExtra: '" . __(' and ', 'link-library') . "',\n";
        $output .= "\t\twrongFileSize: '" . __('The file you are trying to upload is too large (max %s)', 'link-library') . "',\n";
        $output .= "\t\twrongFileType: '" . __('Only files of type %s is allowed', 'link-library') . "',\n";
        $output .= "\t\tgroupCheckedRangeStart: '" . __('Please choose between ', 'link-library') . "',\n";
        $output .= "\t\tgroupCheckedTooFewStart: '" . __('Please choose at least ', 'link-library') . "',\n";
        $output .= "\t\tgroupCheckedTooManyStart: '" . __('Please choose a maximum of ', 'link-library') . "',\n";
        $output .= "\t\tgroupCheckedEnd: '" . __(' item(s)', 'link-library') . "',\n";
        $output .= "\t\tbadCreditCard: '" . __('The credit card number is not correct', 'link-library') . "',\n";
        $output .= "\t\tbadCVV: '" . __('The CVV number was not correct', 'link-library') . "',\n";
        $output .= "\t\twrongFileDim : '" . __('Incorrect image dimensions,', 'link-library') . "',\n";
        $output .= "\t\timageTooTall : '" . __('the image can not be taller than', 'link-library') . "',\n";
        $output .= "\t\timageTooWide : '" . __('the image can not be wider than', 'link-library') . "',\n";
        $output .= "\t\timageTooSmall : '" . __('the image was too small', 'link-library') . "',\n";
        $output .= "\t\tmin : '" . __('min', 'link-library') . "',\n";
        $output .= "\t\tmax : '" . __('max', 'link-library') . "',\n";
        $output .= "\t\timageRatioNotAccepted : '" . __('Image ratio is not accepted', 'link-library') . "'\n";
        $output .= "\t};\n";
        $output .= "\t\tjQuery.validate({\n";
        $output .= "\t\t\tmodules : 'location, date, security, file',\n";
        $output .= "\t\t\tlanguage : LinkLibraryValidationLanguage,\n";
        $output .= "\t\t});\n";
        $output .= "\t\tjQuery('#link_category').change(function() {\n";
        $output .= "\t\t\tif ( jQuery('#link_category').val() == 'new' ) {\n";
        $output .= "\t\t\t\tjQuery('.customcatrow').show();\n";
        $output .= "\t\t\t} else {\n";
        $output .= "\t\t\t\tjQuery('.customcatrow').hide();\n";
        $output .= "\t\t\t};\n";
        $output .= "\t\t});\n";
        $output .= "\t});\n";
        $output .= "</script>\n";
    }
    return $output;
}