Пример #1
0
    /** ====================================================================================================================================================
     * The configuration page
     * 
     * @return void
     */
    function configuration_page()
    {
        global $wpdb;
        $table_name = $this->table_name;
        ?>
		<div class="plugin-titleSL">
			<h2><?php 
        echo $this->pluginName;
        ?>
</h2>
		</div>
		
		<div class="plugin-contentSL">		
			<?php 
        echo $this->signature;
        ?>
			
			<!--debut de personnalisation-->
		<?php 
        // Store the url if the user submit a file...
        if (isset($_POST['import'])) {
            if (is_file($_FILES['fileImport']['tmp_name'])) {
                $lines = @file($_FILES['fileImport']['tmp_name']);
                $success = true;
                $nb_import = 0;
                foreach ($lines as $l) {
                    $element = explode(",", $l);
                    $query = "INSERT INTO " . $this->table_name . " (id_post, nb_hits, short_url, url_externe, comment) VALUES('" . esc_sql($element[0]) . "','" . esc_sql($element[1]) . "','" . esc_sql($element[2]) . "','" . esc_sql($element[3]) . "','" . esc_sql($element[4]) . "');";
                    if ($wpdb->query($query) === FALSE) {
                        $success = false;
                    } else {
                        $nb_import++;
                    }
                }
                if ($success == false) {
                    if ($nb_import == 0) {
                        echo '<div class="error fade"><p>' . __('An error occurs when updating the database.', $this->pluginID) . '</p></div>';
                    } else {
                        echo '<div class="error fade"><p>' . sprintf(__('An error occurs when updating the database. Nevertheless %s sentences has been imported successfully.', $this->pluginID), $nb_import) . '</p></div>';
                    }
                } else {
                    echo '<div class="updated fade"><p>' . sprintf(__('%s short URL have been added to the database.', $this->pluginID), $nb_import) . '</p></div>';
                }
            }
        }
        // On verifie que les droits sont corrects
        $this->check_folder_rights(array());
        //==========================================================================================
        //
        // Mise en place du systeme d'onglet
        //		(bien mettre a jour les liens contenu dans les <li> qui suivent)
        //
        //==========================================================================================
        $tabs = new SLFramework_Tabs();
        // Mise en place de la barre de navigation
        ob_start();
        // on identifie la racine des short links
        echo '<script language="javascript">var site="' . $this->get_home_url() . '"</script>';
        $maxnb = 20;
        $table = new SLFramework_Table(0, $maxnb, true, true);
        // on construit le filtre pour la requete
        $filter = explode(" ", $table->current_filter());
        $paged = 1;
        $result = array();
        $nb_url = 0;
        while (true) {
            query_posts(array('post_type' => explode(',', $this->get_param('typepage')), 'posts_per_page' => 100, 'paged' => $paged));
            $nb_url += 100;
            if (!have_posts() || $nb_url >= $this->get_param('maxnb')) {
                break;
            }
            $paged++;
            while (have_posts()) {
                the_post();
                // we check if the title match the filter
                $match = true;
                $title = get_the_title();
                foreach ($filter as $fi) {
                    if ($fi != "") {
                        if (strpos($title, $fi) === FALSE) {
                            $match = false;
                            break;
                        }
                    }
                }
                if ($match) {
                    $result[] = array(get_the_ID(), $title, wp_get_shortlink(), get_post_type(), $wpdb->get_var("SELECT nb_hits FROM {$table_name} WHERE id_post='" . get_the_ID() . "'"));
                }
            }
        }
        if ($nb_url >= $this->get_param('maxnb')) {
            echo '<div class="updated">';
            echo '<p>' . sprintf(__('The number of displayed URL cannot exceed %s. Thus the number of url is limited to this number.', $this->pluginID), $this->get_param('maxnb')) . '</p>';
            echo '</div>';
        }
        $count = count($result);
        $table->set_nb_all_Items($count);
        $table->title(array(__('Title of your articles', $this->pluginID), __('Short URL', $this->pluginID), __('Type', $this->pluginID), __('Number of clicks', $this->pluginID)));
        // We order the posts page according to the choice of the user
        if ($table->current_orderdir() == "ASC") {
            $result = SLFramework_Utils::multicolumn_sort($result, $table->current_ordercolumn(), true);
        } else {
            $result = SLFramework_Utils::multicolumn_sort($result, $table->current_ordercolumn(), false);
        }
        // We limit the result to the requested zone
        $result = array_slice($result, ($table->current_page() - 1) * $maxnb, $maxnb);
        // lignes du tableau
        // boucle sur les differents elements
        $ligne = 0;
        foreach ($result as $r) {
            $ligne++;
            ob_start();
            ?>
					<b><?php 
            echo $r[1];
            ?>
</b>
					<img src="<?php 
            echo plugin_dir_url("/") . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__));
            ?>
img/ajax-loader.gif" id="wait<?php 
            echo $r[0];
            ?>
" style="display: none;" />
					<?php 
            $cel1 = new adminCell(ob_get_clean());
            ob_start();
            ?>
					<span id="lien<?php 
            echo $r[0];
            ?>
" ><a href="<?php 
            echo $r[2];
            ?>
"><?php 
            echo $r[2];
            ?>
</a></span>
					<?php 
            $cel2 = new adminCell(ob_get_clean());
            $cel2->add_action(__("Reset", $this->pluginID), "resetLink");
            $cel2->add_action(__("Edit", $this->pluginID), "forceLink");
            if (get_post_status($r[0]) == "publish") {
                $cel3 = new adminCell($r[3]);
            } else {
                $cel3 = new adminCell($r[3] . " (" . get_post_status($r[0]) . ")");
            }
            $select = "SELECT nb_hits FROM {$table_name} WHERE id_post='" . $r[0] . "'";
            $nb_hits = $wpdb->get_var($select);
            $cel4 = new adminCell($nb_hits);
            $table->add_line(array($cel1, $cel2, $cel3, $cel4), $r[0]);
        }
        echo $table->flush();
        ob_start();
        ?>
					<form method='post' enctype='multipart/form-data' action='<?php 
        echo $_SERVER["REQUEST_URI"];
        ?>
'>
						<label for='fileImport'><?php 
        echo __('Select the file:', $this->pluginID);
        ?>
</label>
						<input name='fileImport' id='fileImport' type='file'/><br/>
						<div class="submit">
							<input type="submit" name="import" class='button-primary validButton' value="<?php 
        echo __('Import a file with shorturls', $this->pluginID);
        ?>
" />
							<input type="submit" name="export" class='button-primary validButton' value="<?php 
        echo __('Export the shorturls', $this->pluginID);
        ?>
" />
						</div>
					</form>
					<?php 
        $box = new SLFramework_Box(__('Import/Export Short URL', $this->pluginID), ob_get_clean());
        echo $box->flush();
        $tabs->add_tab(__('Internal Redirections', $this->pluginID), ob_get_clean());
        ob_start();
        if (isset($_POST['add'])) {
            $url_ext = str_replace("'", "", $_POST['url_externe']);
            $comment = str_replace("'", "", $_POST['comment']);
            if (!preg_match("/^http/i", $url_ext)) {
                $url_ext = "http://" . $url_ext;
            }
            $this->add_external_link($url_ext, $comment);
        }
        $maxnb = 20;
        $table = new SLFramework_Table($count, $maxnb, true, true);
        $table->title(array(__('External URL', $this->pluginID), __('Short URL', $this->pluginID), __('Comment', $this->pluginID), __('Number of clicks', $this->pluginID)));
        // on construit le filtre pour la requête
        $filter = explode(" ", $table->current_filter());
        $filter_words = "";
        foreach ($filter as $fi) {
            $filter_words .= " AND ";
            $filter_words .= "(url_externe like '%" . $fi . "%' OR comment like '%" . $fi . "%')";
        }
        $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $table_name . " WHERE id_post=0 " . $filter_words . " AND url_externe<>''; ");
        $table->set_nb_all_Items($count);
        if ($table->current_ordercolumn() == 1) {
            $orderby = " ORDER BY url_externe " . $table->current_orderdir();
        } else {
            if ($table->current_ordercolumn() == 2) {
                $orderby = " ORDER BY short_url " . $table->current_orderdir();
            } else {
                if ($table->current_ordercolumn() == 3) {
                    $orderby = " ORDER BY nb_hits " . $table->current_orderdir();
                }
            }
        }
        $res = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE id_post=0 " . $filter_words . " AND url_externe<>'' " . $orderby . " LIMIT " . $maxnb * ($table->current_page() - 1) . ", " . $maxnb . " ; ");
        foreach ($res as $r) {
            $id_temp = sha1($r->short_url);
            $cel1 = new adminCell("<a href='" . $r->url_externe . "'>" . $r->url_externe . "</a><img src='" . plugin_dir_url("/") . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . "img/ajax-loader.gif' id='wait_external" . $id_temp . "' style='display: none;' />");
            $cel1->add_action(__("Delete", $this->pluginID), "deleteLink_external('" . $id_temp . "')");
            $cel2 = new adminCell("<span id='lien_external" . $id_temp . "'><a href='" . $this->get_home_url() . "/" . $r->short_url . "'>" . $this->get_home_url() . "/" . $r->short_url . "</a></span>");
            $cel2->add_action(__("Reset", $this->pluginID), "resetLink_external('" . $id_temp . "')");
            $cel2->add_action(__("Edit", $this->pluginID), "forceLink_external('" . $id_temp . "')");
            $cel3 = new adminCell("<p>" . $r->comment . "</p>");
            $cel4 = new adminCell($r->nb_hits);
            $table->add_line(array($cel1, $cel2, $cel3, $cel4), $id_temp);
        }
        echo $table->flush();
        ob_start();
        ?>
					<form method='post' action='<?php 
        echo remove_query_arg("filter_" . $table->id, $_SERVER["REQUEST_URI"]);
        ?>
'>
						<label for='url_externe'><?php 
        echo __('External URL:', $this->pluginID);
        ?>
</label>
						<input name='url_externe' id='url_externe' type='text' value='' size='40'/><br/>
						<label for='comment'><?php 
        echo __('Comments:', $this->pluginID);
        ?>
</label>
						<input name='comment' id='comment' type='text' value='' size='40'/><br/>
						<div class="submit">
							<input type="submit" name="add" class='button-primary validButton' value="<?php 
        echo __('Add a new URL to shorten', $this->pluginID);
        ?>
" />
						</div>
					</form>
					<?php 
        $box = new SLFramework_Box(__('Add a new URL to shorten', $this->pluginID), ob_get_clean());
        echo $box->flush();
        ob_start();
        ?>
					<form method='post' enctype='multipart/form-data' action='<?php 
        echo $_SERVER["REQUEST_URI"];
        ?>
'>
						<label for='fileImport'><?php 
        echo __('Select the file:', $this->pluginID);
        ?>
</label>
						<input name='fileImport' id='fileImport' type='file'/><br/>
						<div class="submit">
							<input type="submit" name="import" class='button-primary validButton' value="<?php 
        echo __('Import a file with shorturls', $this->pluginID);
        ?>
" />
							<input type="submit" name="export" class='button-primary validButton' value="<?php 
        echo __('Export the shorturls', $this->pluginID);
        ?>
" />
						</div>
					</form>
					<?php 
        $box = new SLFramework_Box(__('Import/Export Short URL', $this->pluginID), ob_get_clean());
        echo $box->flush();
        $tabs->add_tab(__('External Redirections', $this->pluginID), ob_get_clean());
        // HOW To
        ob_start();
        echo "<p>" . __("This plugin helps you sharing your post with short-links.", $this->pluginID) . "</p>";
        $howto1 = new SLFramework_Box(__("Purpose of that plugin", $this->pluginID), ob_get_clean());
        ob_start();
        echo "<p>" . sprintf(__('When the function %s is called, this plugin replace the normal short links by a special crafted short links.', $this->pluginID), "<code>wp_get_shortlink</code>") . "</p>";
        echo "<p>" . sprintf(__('The short URL may be for instance %s of %s (the length of the short link may be configured).', $this->pluginID), "<code>http://domain.tld/Fh67aa</code>", "<code>http://domain.tld/ZhbaG</code>") . "</p>";
        echo "<p>" . __('.', $this->pluginID) . "</p>";
        $howto2 = new SLFramework_Box(__("How it works?", $this->pluginID), ob_get_clean());
        ob_start();
        echo "<p>" . __('To display the shorten URL, you just have to choose the position of the display (top, bottom, etc.) in the configuration tab.', $this->pluginID) . "</p>";
        echo "<p>" . sprintf(__('You may also display the shorten URL whereever you want by using the %s function (for instance in your theme).', $this->pluginID), "<code>wp_get_shortlink</code>", "<code>http://domain.tld/ZhbaG</code>") . "</p>";
        $howto3 = new SLFramework_Box(__("How to display the short URL?", $this->pluginID), ob_get_clean());
        ob_start();
        echo "<p>" . __('When your server see the request short URL, it will automatically redirect to the normal page.', $this->pluginID) . "</p>";
        echo "<p>" . __('You may also choose to redirect the short URL through an internal page:', $this->pluginID) . "</p>";
        echo "<ul style='list-style-type: disc;padding-left:40px;'>";
        echo "<li><p>" . __("You just have to choose a specially crafted page to display during the redirection;", $this->pluginID) . "</p></li>";
        echo "<li><p>" . sprintf(__("In the page, you may insert %s to display the number of seconds remaining;", $this->pluginID), "<code>[short_url_second]</code>") . "</p></li>";
        echo "<li><p>" . sprintf(__("You may also insert %s to display the URL of the page to where the redirection will be performed;", $this->pluginID), "<code>[short_url_url]</code>") . "</p></li>";
        echo "</ul>";
        $howto4 = new SLFramework_Box(__("How to redirect works?", $this->pluginID), ob_get_clean());
        ob_start();
        echo "<p>" . sprintf(__('Your WP install should not use default permalinks (i.e. %s) but instead any custom permalinks (i.e. %s or %s).', $this->pluginID), "<code>http://domain.tld/?p=453</code>", "<code>domain.tld/2015/02/12/sample-post/</code>", "<code>domain.tld/2015/sample-post/</code>") . "</p>";
        $howto5 = new SLFramework_Box(__("Requirements", $this->pluginID), ob_get_clean());
        ob_start();
        echo $howto1->flush();
        echo $howto2->flush();
        echo $howto3->flush();
        echo $howto4->flush();
        echo $howto5->flush();
        $tabs->add_tab(__('How To', $this->pluginID), ob_get_clean(), plugin_dir_url("/") . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . "core/img/tab_how.png");
        ob_start();
        ?>
					<h3 class="hide-if-js"><?php 
        echo __('Parameters', $this->pluginID);
        ?>
</h3>
				
					<?php 
        $params = new SLFramework_Parameters($this, 'tab-parameters');
        $params->add_title(__('Do you want to use the following characters?', $this->pluginID));
        $params->add_comment(__('These parameters will be taken in account only for generation of new links', $this->pluginID));
        $params->add_param('low_char', __('Lower-case characters ([a-z]):', $this->pluginID));
        $params->add_param('upp_char', __('Upper-case characters ([A-Z]):', $this->pluginID));
        $params->add_param('num_char', __('Numeric characters ([0-9]):', $this->pluginID));
        $params->add_title(__('Do you want to use a prefix before your short URL?', $this->pluginID));
        $params->add_param('prefix', __('Prefix:', $this->pluginID), "@[^a-zA-Z0-9_]@");
        $params->add_title(__('What is the length of your short URL (without the prefix)?', $this->pluginID));
        $params->add_param('length', __('Length:', $this->pluginID));
        $params->add_title(__('What are the short links that are to be displayed?', $this->pluginID));
        $params->add_param('typepage', __('Types (separated with comma):', $this->pluginID));
        $args = array('public' => true);
        $output = 'names';
        // names or objects, note names is the default
        $operator = 'and';
        // 'and' or 'or'
        $post_types = get_post_types($args, $output, $operator);
        $exemple = "page,post";
        foreach ($post_types as $post_type) {
            $exemple .= "," . $post_type;
        }
        $params->add_comment(sprintf(__('For instance %s', $this->pluginID), "<code>" . $exemple . "</code>"));
        $params->add_comment(__('Note that ALL page will be shorten, but only this types will be displayed in the first tab of this plugin.', $this->pluginID));
        $params->add_title(__('Customize the short link URL', $this->pluginID));
        $params->add_param('removewww', __('Remove www:', $this->pluginID));
        $params->add_comment(sprintf(__('Therefore, the short URL will begin with %s', $this->pluginID), str_replace("://www.", "://", home_url())));
        $params->add_param('changeroot', __('Change the root URL of the short link:', $this->pluginID), "", "", array("!removewww", "changeroot_url"));
        $params->add_comment(__('If you have a shorter URL pointing to your Wordpress blog, you may configure it here by selecting this option', $this->pluginID));
        $params->add_param('changeroot_url', __('Your shorter domain URL:', $this->pluginID));
        $params->add_title(__('Do you want to automatically shorten links in article?', $this->pluginID));
        $params->add_param('catch_url', __('Automatic shorten links:', $this->pluginID), "", "", array('catch_url_filter'));
        $params->add_param('catch_url_filter', __('Regexp filter:', $this->pluginID));
        $params->add_comment(sprintf(__('The above regexp filter is to select the page in which the link urls are shorten. For instance, %s (or %s) configures the plugin to shorten all links, for instance, in pages %s and %s', $this->pluginID), "<code>.*cat_select.*</code>", "<code>cat_select</code>", "<code>http://domain.tld/cat_select/</code>", "<code>http://domain.tld/level/cat_select/child/</code>"));
        $params->add_comment(__('Please enter one regexp per line.', $this->pluginID));
        $params->add_comment(__('If no regexp is entered, links in all pages and posts will be shorten.', $this->pluginID));
        $params->add_title(__('Where to display the short URL?', $this->pluginID));
        $params->add_param('display_top_in_post', "" . __('At the top of posts:', $this->pluginID));
        $params->add_param('display_bottom_in_post', "" . __('At the bottom of posts:', $this->pluginID));
        $params->add_param('display_top_in_page', "" . __('At the top of pages:', $this->pluginID));
        $params->add_param('display_bottom_in_page', "" . __('At the bottom of pages:', $this->pluginID));
        $params->add_param('display_top_in_custom', "" . __('At the top of custom type article:', $this->pluginID));
        $params->add_param('display_bottom_in_custom', "" . __('At the bottom of custom type article:', $this->pluginID));
        $params->add_param('display_top_in_excerpt', "" . __('At the top of excerpt:', $this->pluginID));
        $params->add_param('display_bottom_in_excerpt', "" . __('At the bottom of excerpt:', $this->pluginID));
        $params->add_param('exclude', __('Page to be excluded:', $this->pluginID));
        $params->add_comment(sprintf(__("Please enter one entry per line. If the article %s is to be excluded, you may enter %s.", $this->pluginID), "<code>http://yourdomain.tld/contact/</code>", "<code>contact</code>"));
        $params->add_comment(sprintf(__("For instance, %s and %s will exclude the home page.", $this->pluginID), "<code>^\$</code>", "<code>^/\$</code>"));
        $params->add_title(__('Appearance of such display', $this->pluginID));
        $params->add_param('html', __('Displayed HTML:', $this->pluginID));
        $params->add_comment_default_value('html');
        $params->add_comment(sprintf(__('Note that %s will be automatically replaced by the shorten URL.', $this->pluginID), "<code>%short_url%</code>"));
        $params->add_comment(sprintf(__('In addition, %s will be replaced by the shorten URL withour any html link.', $this->pluginID), "<code>%short_url_without_link%</code>"));
        $params->add_param('css', __('CSS:', $this->pluginID));
        $params->add_comment_default_value('css');
        $params->add_title(__('Redirect first internally', $this->pluginID));
        $params->add_param('redirect_page', __('Redirect the short link before to an internal page:', $this->pluginID));
        $params->add_param('redirect_sec', __('Number of second before the redirection:', $this->pluginID));
        $params->add_param('redirect_only_external', __('Redirect through this internal page only the external redirection:', $this->pluginID));
        $params->add_title(__('Advanced options', $this->pluginID));
        $params->add_param('maxnb', __('Max number of displayed internal redirection:', $this->pluginID));
        $params->flush();
        $tabs->add_tab(__('Parameters', $this->pluginID), ob_get_clean(), plugin_dir_url("/") . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . "core/img/tab_param.png");
        ob_start();
        $plugin = str_replace("/", "", str_replace(basename(__FILE__), "", plugin_basename(__FILE__)));
        $trans = new SLFramework_Translation($this->pluginID, $plugin);
        $trans->enable_translation();
        $tabs->add_tab(__('Manage translations', $this->pluginID), ob_get_clean(), plugin_dir_url("/") . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . "core/img/tab_trad.png");
        ob_start();
        $plugin = str_replace("/", "", str_replace(basename(__FILE__), "", plugin_basename(__FILE__)));
        $trans = new SLFramework_Feedback($plugin, $this->pluginID);
        $trans->enable_feedback();
        $tabs->add_tab(__('Give feedback', $this->pluginID), ob_get_clean(), plugin_dir_url("/") . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . "core/img/tab_mail.png");
        ob_start();
        $trans = new SLFramework_OtherPlugins("sedLex", array('wp-pirates-search'));
        $trans->list_plugins();
        $tabs->add_tab(__('Other plugins', $this->pluginID), ob_get_clean(), plugin_dir_url("/") . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__)) . "core/img/tab_plug.png");
        echo $tabs->flush();
        echo $this->signature;
        ?>
		</div>
		<?php 
    }