Commit 6e6e0c47 authored by lucha's avatar lucha Committed by lechuck
Browse files

Removing ComicPress companion: not used, not developed anymore

parent b91e7736
<?php
/*
Plugin Name: Theme Companion
Plugin URI: http://frumph.net/
Description: CSS Editor, Extra Options and Functions for themes.
Version: 0.3.4
Author: Philip M. Hofer (Frumph)
Author URI: http://frumph.net/
Copyright 2009-2012 Philip M. Hofer (Frumph) (email : philip@frumph.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if (is_admin()) {
@require_once(dirname (__FILE__) . '/companion_core.php');
}
add_action('wp_head', 'companion_html_header_load');
function companion_html_header_load() {
$wp_dirs = wp_upload_dir();
if (file_exists($wp_dirs['basedir'] . '/css/header.html')) {
$f = fopen($wp_dirs['basedir'] . '/css/header.html', 'r');
$companion_file_contents = fread($f, filesize($wp_dirs['basedir']. '/css/header.html'));
if (!empty($companion_file_contents)) {
echo $companion_file_contents;
}
}
if (file_exists($wp_dirs['basedir'] . '/css/custom_style.css')) { ?>
<link rel='stylesheet' id='custom_stylesheet' href='<?php echo $wp_dirs['baseurl']; ?>/css/custom_style.css' type='text/css' media='all' />
<?php
}
}
?>
\ No newline at end of file
<?php
add_action('admin_menu', 'companion_init_hooks');
add_action('admin_foot', 'companion_css_footer');
function companion_pluginfo($whichinfo = null) {
global $companion_pluginfo;
if (empty($comicpress_themeinfo) || $whichinfo == 'reset') {
// need to create this config. NOW.
$companion_pluginfo = '';
$companion_coreinfo = wp_upload_dir();
$companion_addinfo = array(
'themeurl' => get_template_directory_uri(),
'themepath' => get_template_directory(),
'styleurl' => get_stylesheet_directory_uri(),
'stylepath' => get_stylesheet_directory(),
'plugindir' => plugin_dir_url(dirname (__FILE__)) . 'comicpress-companion',
'pluginurl' => get_option('siteurl') . '/wp-content/plugins/comicpress-companion'
);
$companion_pluginfo = array_merge($companion_coreinfo, $companion_addinfo);
}
if ($whichinfo) return $companion_pluginfo[$whichinfo];
return $companion_pluginfo;
}
function companion_is_multisite() {
global $wpmu_version;
if (function_exists('is_multisite'))
if (is_multisite()) return true;
if (!empty($wpmu_version)) return true;
return false;
}
// Add menu page
function companion_init_hooks() {
$companion_hook = add_submenu_page('themes.php', 'companion', __('Companion', 'companion'), 'manage_options', 'companion', 'companion_admin_page');
add_action('admin_head-'.$companion_hook, 'companion_config_page_head');
add_action('admin_print_scripts-'.$companion_hook, 'companion_load_scripts');
add_action('admin_print_styles-'.$companion_hook, 'companion_load_styles');
}
function companion_load_scripts() {
wp_enqueue_script('jquery');
wp_enqueue_script('edit_area_full', companion_pluginfo('pluginurl') . '/edit_area/edit_area_full.js');
wp_enqueue_script('tabbed_pages', companion_pluginfo('pluginurl') . '/tabbed/tabbed_pages.js');
}
function companion_load_styles() {
global $is_IE;
if ($is_IE) {
wp_enqueue_style('tabbed_style_ie', companion_pluginfo('pluginurl') . '/tabbed/tabbed_pages_ie.css');
} else {
wp_enqueue_style('tabbed_style', companion_pluginfo('pluginurl') . '/tabbed/tabbed_pages.css');
}
}
function companion_config_page_head() { ?>
<script language="javascript" type="text/javascript">
editAreaLoader.init({
id : "newcontent" // textarea id
,syntax: "css" // syntax to be uses for highlighting
,start_highlight: true // to display with highlight mode on start-up
});
</script>
<?php
}
/**
* options page
*
*/
function companion_admin_page() {
global $is_iis7;
?>
<div class="wrap">
<h2 class="alignleft">Theme Companion</h2>
<br clear="all" />
<?php
if (isset($_REQUEST['file'])) {
switch ( stripslashes($_REQUEST['file']) ) {
case "style":
$edit_file = "custom_style";
break;
case "head":
$edit_file = "header";
break;
default:
$edit_file = "custom_style";
break;
}
} else $edit_file = "custom_style";
if ($edit_file == 'header') {
$companion_edit_type = 'html';
} else {
$companion_edit_type = 'css';
}
$companion_edit_file = companion_pluginfo('basedir') . '/css/' . $edit_file . '.' . $companion_edit_type;
$original = false;
if (isset($_REQUEST['file']) && ($_REQUEST['file'] == 'original')) {
$original = true;
$companion_edit_file = companion_pluginfo('themepath') . '/style.css';
}
if (isset($_REQUEST['newcontent'])) $companion_file_content = trim(stripslashes($_REQUEST['newcontent']));
?>
<?php
if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'update-options') ) {
if ('companion_css_save' == $_REQUEST['action'] ) {
$companion_file_content = trim(stripslashes($_REQUEST['newcontent']));
if (!file_exists($companion_edit_file)) wp_mkdir_p(dirname($companion_edit_file));
if (empty($companion_file_content)) {
// echo "Shows Empty";
if (file_exists($companion_edit_file)) {
unlink($companion_edit_file); ?>
<div class="updated fade"><p><strong>File Deleted!</strong></p></div>
<?php }
} else {
// echo "Shows having content.";
$ok = false;
if (($fh = @fopen($companion_edit_file, "w")) !== false) {
if (fwrite($fh, $companion_file_content) !== false) {
$ok = true;
}
fclose($fh);
}
if ($ok) { ?>
<div class="updated fade"><p><strong>Saved</strong></p></div>
<?php } else { ?>
<div class="updated fade"><p><strong>Fail: Could'nt Save the file.</strong></p></div>
<?php }
}
}
}
if (file_exists($companion_edit_file)) {
$f = fopen($companion_edit_file, 'r');
$companion_file_content = fread($f, filesize($companion_edit_file));
$companion_file_content = htmlspecialchars($companion_file_content);
} else {
global $current_theme, $themes;
if ($companion_edit_type == 'css') {
$companion_file_content = "/* Companion Custom CSS over-rides for [ ".get_bloginfo('name')." ]: $current_theme - ".$themes[$current_theme]['Version']." */\r\n";
} else {
$companion_file_content = "<!-- Companion Custom HTML Insert for [ ".get_bloginfo('name')." ]: $current_theme - ".$themes[$current_theme]['Version']." -->\r\n";
}
}
?>
<div id="ccadmin">
<div class="on" title="cceditor"><span>CSS Override Editor</span></div>
<div class="off" title="ccexamples"><span>Examples</span></div>
<div class="off" title="cchelp"><span>Help</span></div>
</div>
<div id="cceditor" class="show">
<div class="inside">
<form method="post" id="template" name="template" action="">
<?php wp_nonce_field('update-options') ?>
<table style="width: auto">
<tr>
<td valign="top">
<label>
<?php if (!$original) { ?>
Now editing: <?php echo basename($companion_edit_file); ?><br />
<?php } else { ?>
Now Viewing: style.css<br />
<?php } ?>
<?php
if (!$original) {
if ( $is_iis7 ) {
if (win_is_writable($companion_edit_file)) {
echo 'WIN: File exists and is writable.<br />';
} else {
wp_mkdir_p(dirname($companion_edit_file));
echo '<i>WIN: File '.basename($companion_edit_file).' does *not* exist or is not writable, try to save the file. If you still get this error check permissions.</i><br />';
}
} else {
if (is_writable($companion_edit_file)) {
echo 'NIX: File Exists and is writable.<br />';
} else {
wp_mkdir_p(dirname($companion_edit_file));
echo '<i>NIX: File '.basename($companion_edit_file).' does *not* exist or is not writable, try to save the file. If you still get this error check permissions.</i><br />';
}
}
} else {
echo 'Loading Original Style.CSS, it is NOT writable, you are to use the custom editor area to add changes that you want to make, and only changes.<br />';
}
$base = admin_url();
?>
[<a href="<?php echo $base; ?>themes.php?page=companion&amp;file=original">Show Original Style.CSS</a>] | [<a href="<?php echo $base; ?>themes.php?page=companion&amp;file=custom">Edit Custom Style</a>]
<?php if (!companion_is_multisite() || is_super_admin()) { ?>
| [<a href="<?php echo $base; ?>themes.php?page=companion&amp;file=head">Add HTML code to the &lt;head&gt; area</a>]<br />
<?php } ?>
<textarea class="codepress <?php echo $companion_edit_type; ?>" rows="25" style="width: 100%;" name="newcontent" id="newcontent"><?php echo $companion_file_content; ?></textarea><br />
<br />
</label>
</td>
</tr>
</table>
<?php if (!$original) { ?>
<input name="submit" type="submit" class="button-primary" value="Save Custom CSS Overrides" />
<input type="hidden" name="action" value="companion_css_save" />
<?php } ?>
</form>
</div>
</div>
<?php
require_once('includes/ccexamples.php');
require_once('includes/cchelp.php');
?>
<div style="float: left;">Theme Companion is made by <a href="http://frumph.net/">Philip M. Hofer (Frumph)</a>.
</div>
<div style="clear: both;"></div>
</div>
</div>
</div>
<?php
}
?>
\ No newline at end of file
/**
* Autocompletion class
*
* An auto completion box appear while you're writing. It's possible to force it to appear with Ctrl+Space short cut
*
* Loaded as a plugin inside editArea (everything made here could have been made in the plugin directory)
* But is definitly linked to syntax selection (no need to do 2 different files for color and auto complete for each syntax language)
* and add a too important feature that many people would miss if included as a plugin
*
* - init param: autocompletion_start
* - Button name: "autocompletion"
*/
var EditArea_autocompletion= {
/**
* Get called once this file is loaded (editArea still not initialized)
*
* @return nothing
*/
init: function(){
// alert("test init: "+ this._someInternalFunction(2, 3));
if(editArea.settings["autocompletion"])
this.enabled= true;
else
this.enabled= false;
this.current_word = false;
this.shown = false;
this.selectIndex = -1;
this.forceDisplay = false;
this.isInMiddleWord = false;
this.autoSelectIfOneResult = false;
this.delayBeforeDisplay = 100;
this.checkDelayTimer = false;
this.curr_syntax_str = '';
this.file_syntax_datas = {};
}
/**
* Returns the HTML code for a specific control string or false if this plugin doesn't have that control.
* A control can be a button, select list or any other HTML item to present in the EditArea user interface.
* Language variables such as {$lang_somekey} will also be replaced with contents from
* the language packs.
*
* @param {string} ctrl_name: the name of the control to add
* @return HTML code for a specific control or false.
* @type string or boolean
*/
/*,get_control_html: function(ctrl_name){
switch( ctrl_name ){
case 'autocompletion':
// Control id, button img, command
return parent.editAreaLoader.get_button_html('autocompletion_but', 'autocompletion.gif', 'toggle_autocompletion', false, this.baseURL);
break;
}
return false;
}*/
/**
* Get called once EditArea is fully loaded and initialised
*
* @return nothing
*/
,onload: function(){
if(this.enabled)
{
var icon= document.getElementById("autocompletion");
if(icon)
editArea.switchClassSticky(icon, 'editAreaButtonSelected', true);
}
this.container = document.createElement('div');
this.container.id = "auto_completion_area";
editArea.container.insertBefore( this.container, editArea.container.firstChild );
// add event detection for hiding suggestion box
parent.editAreaLoader.add_event( document, "click", function(){ editArea.plugins['autocompletion']._hide();} );
parent.editAreaLoader.add_event( editArea.textarea, "blur", function(){ editArea.plugins['autocompletion']._hide();} );
}
/**
* Is called each time the user touch a keyboard key.
*
* @param (event) e: the keydown event
* @return true - pass to next handler in chain, false - stop chain execution
* @type boolean
*/
,onkeydown: function(e){
if(!this.enabled)
return true;
if (EA_keys[e.keyCode])
letter=EA_keys[e.keyCode];
else
letter=String.fromCharCode(e.keyCode);
// shown
if( this._isShown() )
{
// if escape, hide the box
if(letter=="Esc")
{
this._hide();
return false;
}
// Enter
else if( letter=="Entrer")
{
var as = this.container.getElementsByTagName('A');
// select a suggested entry
if( this.selectIndex >= 0 && this.selectIndex < as.length )
{
as[ this.selectIndex ].onmousedown();
return false
}
// simply add an enter in the code
else
{
this._hide();
return true;
}
}
else if( letter=="Tab" || letter=="Down")
{
this._selectNext();
return false;
}
else if( letter=="Up")
{
this._selectBefore();
return false;
}
}
// hidden
else
{
}
// show current suggestion list and do autoSelect if possible (no matter it's shown or hidden)
if( letter=="Space" && CtrlPressed(e) )
{
//parent.console.log('SHOW SUGGEST');
this.forceDisplay = true;
this.autoSelectIfOneResult = true;
this._checkLetter();
return false;
}
// wait a short period for check that the cursor isn't moving
setTimeout("editArea.plugins['autocompletion']._checkDelayAndCursorBeforeDisplay();", editArea.check_line_selection_timer +5 );
this.checkDelayTimer = false;
return true;
}
/**
* Executes a specific command, this function handles plugin commands.
*
* @param {string} cmd: the name of the command being executed
* @param {unknown} param: the parameter of the command
* @return true - pass to next handler in chain, false - stop chain execution
* @type boolean
*/
,execCommand: function(cmd, param){
switch( cmd ){
case 'toggle_autocompletion':
var icon= document.getElementById("autocompletion");
if(!this.enabled)
{
if(icon != null){
editArea.restoreClass(icon);
editArea.switchClassSticky(icon, 'editAreaButtonSelected', true);
}
this.enabled= true;
}
else
{
this.enabled= false;
if(icon != null)
editArea.switchClassSticky(icon, 'editAreaButtonNormal', false);
}
return true;
}
return true;
}
,_checkDelayAndCursorBeforeDisplay: function()
{
this.checkDelayTimer = setTimeout("if(editArea.textarea.selectionStart == "+ editArea.textarea.selectionStart +") EditArea_autocompletion._checkLetter();", this.delayBeforeDisplay - editArea.check_line_selection_timer - 5 );
}
// hide the suggested box
,_hide: function(){
this.container.style.display="none";
this.selectIndex = -1;
this.shown = false;
this.forceDisplay = false;
this.autoSelectIfOneResult = false;
}
// display the suggested box
,_show: function(){
if( !this._isShown() )
{
this.container.style.display="block";
this.selectIndex = -1;
this.shown = true;
}
}
// is the suggested box displayed?
,_isShown: function(){
return this.shown;
}
// setter and getter
,_isInMiddleWord: function( new_value ){
if( typeof( new_value ) == "undefined" )
return this.isInMiddleWord;
else
this.isInMiddleWord = new_value;
}
// select the next element in the suggested box
,_selectNext: function()
{
var as = this.container.getElementsByTagName('A');
// clean existing elements
for( var i=0; i<as.length; i++ )
{
if( as[i].className )
as[i].className = as[i].className.replace(/ focus/g, '');
}
this.selectIndex++;
this.selectIndex = ( this.selectIndex >= as.length || this.selectIndex < 0 ) ? 0 : this.selectIndex;
as[ this.selectIndex ].className += " focus";
}
// select the previous element in the suggested box
,_selectBefore: function()
{
var as = this.container.getElementsByTagName('A');
// clean existing elements
for( var i=0; i<as.length; i++ )
{
if( as[i].className )
as[i].className = as[ i ].className.replace(/ focus/g, '');
}
this.selectIndex--;
this.selectIndex = ( this.selectIndex >= as.length || this.selectIndex < 0 ) ? as.length-1 : this.selectIndex;
as[ this.selectIndex ].className += " focus";
}
,_select: function( content )
{
cursor_forced_position = content.indexOf( '{@}' );
content = content.replace(/{@}/g, '' );
editArea.getIESelection();
// retrive the number of matching characters
var start_index = Math.max( 0, editArea.textarea.selectionEnd - content.length );
line_string = editArea.textarea.value.substring( start_index, editArea.textarea.selectionEnd + 1);
limit = line_string.length -1;
nbMatch = 0;
for( i =0; i<limit ; i++ )
{
if( line_string.substring( limit - i - 1, limit ) == content.substring( 0, i + 1 ) )
nbMatch = i + 1;
}
// if characters match, we should include them in the selection that will be replaced
if( nbMatch > 0 )
parent.editAreaLoader.setSelectionRange(editArea.id, editArea.textarea.selectionStart - nbMatch , editArea.textarea.selectionEnd);
parent.editAreaLoader.setSelectedText(editArea.id, content );
range= parent.editAreaLoader.getSelectionRange(editArea.id);
if( cursor_forced_position != -1 )
new_pos = range["end"] - (