generate Text button started

git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@803 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
Evgeny Gryaznov 2010-05-02 17:44:38 +00:00
parent f069d8d9b6
commit a0d3403cb5
6 changed files with 323 additions and 77 deletions

View File

@ -0,0 +1,113 @@
<?php
/*
* This file is part of Mibew Messenger project.
*
* Copyright (c) 2005-2010 Mibew Messenger Community
* All rights reserved. The contents of this file are subject to the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and
* is available at http://www.eclipse.org/legal/epl-v10.html
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (the "GPL"), in which case
* the provisions of the GPL are applicable instead of those above. If you wish
* to allow use of your version of this file only under the terms of the GPL, and
* not to allow others to use your version of this file under the terms of the
* EPL, indicate your decision by deleting the provisions above and replace them
* with the notice and other provisions required by the GPL.
*
* Contributors:
* Evgeny Gryaznov - initial API and implementation
*/
function setup_getcode_tabs($active) {
global $page, $webimroot;
$page['tabselected'] = $active;
$page['tabs'] = array(
array('title'=> getlocal("page_getcode.tab.image"), 'link' => "$webimroot/operator/getcode.php"),
array('title'=> getlocal("page_getcode.tab.text"), 'link' => "$webimroot/operator/gettextcode.php"),
);
}
function generate_button($title,$locale,$style,$group,$inner,$showhost,$forcesecure,$modsecurity) {
$link = get_app_location($showhost,$forcesecure)."/client.php";
if($locale)
$link = append_query($link, "locale=$locale");
if($style)
$link = append_query($link, "style=$style");
if($group)
$link = append_query($link, "group=$group");
$modsecfix = $modsecurity ? ".replace('http://','').replace('https://','')" : "";
$jslink = append_query("'".$link,"url='+escape(document.location.href$modsecfix)+'&amp;referrer='+escape(document.referrer$modsecfix)");
$temp = get_popup($link, "$jslink",
$inner, $title, "webim", "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=640,height=480,resizable=1" );
return "<!-- mibew button -->".$temp."<!-- / mibew button -->";
}
function get_style_list($stylesfolder) {
$stylelist = array("" => getlocal("page.preview.style_default"));
if($handle = opendir($stylesfolder)) {
while (false !== ($file = readdir($handle))) {
if (preg_match("/^\w+$/", $file) && is_dir("$stylesfolder/$file")) {
$stylelist[$file] = $file;
}
}
closedir($handle);
}
return $stylelist;
}
function verifyparam_groupid($paramid) {
global $settings, $errors;
$groupid = "";
if($settings['enablegroups'] == '1') {
$groupid = verifyparam($paramid, "/^\d{0,8}$/", "");
if($groupid) {
$group = group_by_id($groupid);
if(!$group) {
$errors[] = getlocal("page.group.no_such");
$groupid = "";
}
}
}
return $groupid;
}
function get_groups_list() {
global $settings;
$result = array();
if($settings['enablegroups'] == '1') {
$link = connect();
$allgroups = get_all_groups($link);
mysql_close($link);
$result[] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group"));
foreach($allgroups as $g) {
$result[] = $g;
}
}
return $result;
}
function get_image_locales_map($localesdir) {
$imageLocales = array();
$allLocales = get_available_locales();
foreach($allLocales as $curr) {
$imagesDir = "$localesdir/$curr/button";
if($handle = @opendir($imagesDir)) {
while (false !== ($file = readdir($handle))) {
if (preg_match("/^(\w+)_on.gif$/", $file, $matches)
&& is_file("$imagesDir/".$matches[1]."_off.gif")) {
$image = $matches[1];
if( !isset($imageLocales[$image]) ) {
$imageLocales[$image] = array();
}
$imageLocales[$image][] = $curr;
}
}
closedir($handle);
}
}
return $imageLocales;
}
?>

View File

@ -279,6 +279,8 @@ page.gen_button.modsecurity=Compatibility with mod_security (modsecurity.org), t
page.gen_button.sample=Example page.gen_button.sample=Example
page.gen_button.secure_links=Use secure links (https) page.gen_button.secure_links=Use secure links (https)
page.gen_button.title=Button HTML code generation page.gen_button.title=Button HTML code generation
page_getcode.tab.image=Image
page_getcode.tab.text=Text
page.group.create_new=Here you can create new group. page.group.create_new=Here you can create new group.
page.group.duplicate_name=Please choose another name, because group with entered name already exists. page.group.duplicate_name=Please choose another name, because group with entered name already exists.
page.group.intro=On this page you can edit group details. page.group.intro=On this page you can edit group details.

View File

@ -22,76 +22,27 @@
require_once('../libs/common.php'); require_once('../libs/common.php');
require_once('../libs/operator.php'); require_once('../libs/operator.php');
require_once('../libs/groups.php'); require_once('../libs/groups.php');
require_once('../libs/getcode.php');
function generate_button($title,$locale,$style,$group,$inner,$showhost,$forcesecure,$modsecurity) {
$link = get_app_location($showhost,$forcesecure)."/client.php";
if($locale)
$link = append_query($link, "locale=$locale");
if($style)
$link = append_query($link, "style=$style");
if($group)
$link = append_query($link, "group=$group");
$modsecfix = $modsecurity ? ".replace('http://','').replace('https://','')" : "";
$jslink = append_query("'".$link,"url='+escape(document.location.href$modsecfix)+'&amp;referrer='+escape(document.referrer$modsecfix)");
$temp = get_popup($link, "$jslink",
$inner, $title, "webim", "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=640,height=480,resizable=1" );
return "<!-- mibew button -->".$temp."<!-- / mibew button -->";
}
$operator = check_login(); $operator = check_login();
loadsettings(); loadsettings();
$imageLocales = array(); $imageLocales = get_image_locales_map("../locales");
$allLocales = get_available_locales();
foreach($allLocales as $curr) {
$imagesDir = "../locales/$curr/button";
if($handle = @opendir($imagesDir)) {
while (false !== ($file = readdir($handle))) {
if (preg_match("/^(\w+)_on.gif$/", $file, $matches)
&& is_file("$imagesDir/".$matches[1]."_off.gif")) {
$image = $matches[1];
if( !isset($imageLocales[$image]) ) {
$imageLocales[$image] = array();
}
$imageLocales[$image][] = $curr;
}
}
closedir($handle);
}
}
$image = verifyparam(isset($_GET['image']) ? "image" : "i", "/^\w+$/", "webim"); $image = verifyparam(isset($_GET['image']) ? "image" : "i", "/^\w+$/", "webim");
if(!isset($imageLocales[$image])) {
$errors[] = "Unknown image: $image";
$avail = array_keys($imageLocales);
$image = $avail[0];
}
$image_locales = $imageLocales[$image]; $image_locales = $imageLocales[$image];
$stylelist = array("" => getlocal("page.preview.style_default")); $stylelist = get_style_list("../styles");
$stylesfolder = "../styles";
if($handle = opendir($stylesfolder)) {
while (false !== ($file = readdir($handle))) {
if (preg_match("/^\w+$/", $file) && is_dir("$stylesfolder/$file")) {
$stylelist[$file] = $file;
}
}
closedir($handle);
}
$style = verifyparam("style","/^\w*$/", ""); $style = verifyparam("style","/^\w*$/", "");
if($style && !in_array($style, $stylelist)) { if($style && !in_array($style, $stylelist)) {
$style = ""; $style = "";
} }
$groupid = ""; $groupid = verifyparam_groupid("group");
if($settings['enablegroups'] == '1') {
$groupid = verifyparam( "group", "/^\d{0,8}$/", "");
if($groupid) {
$group = group_by_id($groupid);
if(!$group) {
$errors[] = getlocal("page.group.no_such");
$groupid = "";
}
}
}
$showhost = verifyparam("hostname","/^on$/", "") == "on"; $showhost = verifyparam("hostname","/^on$/", "") == "on";
$forcesecure = verifyparam("secure","/^on$/", "") == "on"; $forcesecure = verifyparam("secure","/^on$/", "") == "on";
$modsecurity = verifyparam("modsecurity","/^on$/", "") == "on"; $modsecurity = verifyparam("modsecurity","/^on$/", "") == "on";
@ -114,17 +65,7 @@ $page['buttonCode'] = generate_button("",$lang,$style,$groupid,$message,$showhos
$page['availableImages'] = array_keys($imageLocales); $page['availableImages'] = array_keys($imageLocales);
$page['availableLocales'] = $image_locales; $page['availableLocales'] = $image_locales;
$page['availableStyles'] = $stylelist; $page['availableStyles'] = $stylelist;
$page['groups'] = get_groups_list();
if($settings['enablegroups'] == '1') {
$link = connect();
$allgroups = get_all_groups($link);
mysql_close($link);
$page['groups'] = array();
$page['groups'][] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group"));
foreach($allgroups as $g) {
$page['groups'][] = $g;
}
}
$page['formgroup'] = $groupid; $page['formgroup'] = $groupid;
$page['formstyle'] = $style; $page['formstyle'] = $style;
@ -135,6 +76,7 @@ $page['formsecure'] = $forcesecure;
$page['formmodsecurity'] = $modsecurity; $page['formmodsecurity'] = $modsecurity;
prepare_menu($operator); prepare_menu($operator);
setup_getcode_tabs(0);
start_html_output(); start_html_output();
require('../view/getcode_image.php'); require('../view/getcode_image.php');
?> ?>

View File

@ -0,0 +1,66 @@
<?php
/*
* This file is part of Mibew Messenger project.
*
* Copyright (c) 2005-2010 Mibew Messenger Community
* All rights reserved. The contents of this file are subject to the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and
* is available at http://www.eclipse.org/legal/epl-v10.html
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (the "GPL"), in which case
* the provisions of the GPL are applicable instead of those above. If you wish
* to allow use of your version of this file only under the terms of the GPL, and
* not to allow others to use your version of this file under the terms of the
* EPL, indicate your decision by deleting the provisions above and replace them
* with the notice and other provisions required by the GPL.
*
* Contributors:
* Evgeny Gryaznov - initial API and implementation
*/
require_once('../libs/common.php');
require_once('../libs/operator.php');
require_once('../libs/groups.php');
require_once('../libs/getcode.php');
$operator = check_login();
loadsettings();
$stylelist = get_style_list("../styles");
$style = verifyparam("style","/^\w*$/", "");
if($style && !in_array($style, $stylelist)) {
$style = "";
}
$groupid = verifyparam_groupid("group");
$showhost = verifyparam("hostname","/^on$/", "") == "on";
$forcesecure = verifyparam("secure","/^on$/", "") == "on";
$modsecurity = verifyparam("modsecurity","/^on$/", "") == "on";
$allLocales = get_available_locales();
$lang = verifyparam("lang", "/^[\w-]{2,5}$/", "");
if( !$lang || !in_array($lang,$allLocales) )
$lang = in_array($current_locale,$allLocales) ? $current_locale : $allLocales[0];
$message = "Click to chat"; // TODO
$page = array();
$page['buttonCode'] = generate_button("",$lang,$style,$groupid,$message,$showhost,$forcesecure,$modsecurity);
$page['availableLocales'] = $allLocales;
$page['availableStyles'] = $stylelist;
$page['groups'] = get_groups_list();
$page['formgroup'] = $groupid;
$page['formstyle'] = $style;
$page['formlang'] = $lang;
$page['formhostname'] = $showhost;
$page['formsecure'] = $forcesecure;
$page['formmodsecurity'] = $modsecurity;
prepare_menu($operator);
setup_getcode_tabs(1);
start_html_output();
require('../view/getcode_text.php');
?>

View File

@ -20,6 +20,7 @@
*/ */
require_once("inc_menu.php"); require_once("inc_menu.php");
require_once("inc_tabbar.php");
$page['title'] = getlocal("page.gen_button.title"); $page['title'] = getlocal("page.gen_button.title");
$page['menuid'] = "getcode"; $page['menuid'] = "getcode";
@ -34,6 +35,8 @@ require_once('inc_errors.php');
?> ?>
<form name="buttonCodeForm" method="get" action="<?php echo $webimroot ?>/operator/getcode.php"> <form name="buttonCodeForm" method="get" action="<?php echo $webimroot ?>/operator/getcode.php">
<div>
<?php print_tabbar(); ?>
<div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner"> <div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner">
<div class="fieldForm"> <div class="fieldForm">
@ -45,14 +48,6 @@ require_once('inc_errors.php');
</div> </div>
</div> </div>
<div class="fieldinrow">
<div class="flabel"><?php echo getlocal("page.gen_button.choose_image") ?></div>
<div class="fvaluenodesc">
<select name="i" onchange="this.form.submit();"><?php foreach($page['availableImages'] as $k) { echo "<option value=\"".$k."\"".($k == form_value("image") ? " selected=\"selected\"" : "").">".$k."</option>"; } ?></select>
</div>
</div>
<br clear="all"/>
<?php if($page['showgroups']) { ?> <?php if($page['showgroups']) { ?>
<div class="fieldinrow"> <div class="fieldinrow">
<div class="flabel"><?php echo getlocal("page.gen_button.choose_group") ?></div> <div class="flabel"><?php echo getlocal("page.gen_button.choose_group") ?></div>
@ -61,6 +56,14 @@ require_once('inc_errors.php');
</div> </div>
</div> </div>
<?php } ?> <?php } ?>
<br clear="all"/>
<div class="fieldinrow">
<div class="flabel"><?php echo getlocal("page.gen_button.choose_image") ?></div>
<div class="fvaluenodesc">
<select name="i" onchange="this.form.submit();"><?php foreach($page['availableImages'] as $k) { echo "<option value=\"".$k."\"".($k == form_value("image") ? " selected=\"selected\"" : "").">".$k."</option>"; } ?></select>
</div>
</div>
<div class="fieldinrow"> <div class="fieldinrow">
<div class="flabel"><?php echo getlocal("page.gen_button.choose_style") ?></div> <div class="flabel"><?php echo getlocal("page.gen_button.choose_style") ?></div>
@ -113,6 +116,7 @@ require_once('inc_errors.php');
</div> </div>
</div><div class="formbottom"><div class="formbottomi"></div></div></div> </div><div class="formbottom"><div class="formbottomi"></div></div></div>
</div>
</form> </form>
<?php <?php

View File

@ -0,0 +1,119 @@
<?php
/*
* This file is part of Mibew Messenger project.
*
* Copyright (c) 2005-2010 Mibew Messenger Community
* All rights reserved. The contents of this file are subject to the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and
* is available at http://www.eclipse.org/legal/epl-v10.html
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (the "GPL"), in which case
* the provisions of the GPL are applicable instead of those above. If you wish
* to allow use of your version of this file only under the terms of the GPL, and
* not to allow others to use your version of this file under the terms of the
* EPL, indicate your decision by deleting the provisions above and replace them
* with the notice and other provisions required by the GPL.
*
* Contributors:
* Evgeny Gryaznov - initial API and implementation
*/
require_once("inc_menu.php");
require_once("inc_tabbar.php");
$page['title'] = getlocal("page.gen_button.title");
$page['menuid'] = "getcode";
function tpl_content() { global $page, $webimroot, $errors;
?>
<?php echo getlocal("page.gen_button.intro") ?>
<br />
<br />
<?php
require_once('inc_errors.php');
?>
<form name="buttonCodeForm" method="get" action="<?php echo $webimroot ?>/operator/gettextcode.php">
<div>
<?php print_tabbar(); ?>
<div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner">
<div class="fieldForm">
<div class="fieldinrow">
<div class="flabel"><?php echo getlocal("page.gen_button.choose_locale") ?></div>
<div class="fvaluenodesc">
<select name="lang" onchange="this.form.submit();"><?php foreach($page['availableLocales'] as $k) { echo "<option value=\"".$k."\"".($k == form_value("lang") ? " selected=\"selected\"" : "").">".$k."</option>"; } ?></select>
</div>
</div>
<?php if($page['showgroups']) { ?>
<div class="fieldinrow">
<div class="flabel"><?php echo getlocal("page.gen_button.choose_group") ?></div>
<div class="fvaluenodesc">
<select name="group" onchange="this.form.submit();"><?php foreach($page['groups'] as $k) { echo "<option value=\"".$k['groupid']."\"".($k['groupid'] == form_value("group") ? " selected=\"selected\"" : "").">".$k['vclocalname']."</option>"; } ?></select>
</div>
</div>
<?php } ?>
<br clear="all"/>
<div class="fieldinrow">
<div class="flabel"><?php echo getlocal("page.gen_button.choose_style") ?></div>
<div class="fvaluenodesc">
<select name="style" onchange="this.form.submit();"><?php foreach($page['availableStyles'] as $k => $v) { echo "<option value=\"".$k."\"".($k == form_value("style") ? " selected=\"selected\"" : "").">".$v."</option>"; } ?></select>
</div>
</div>
<br clear="all"/>
<div class="fieldinrow">
<div class="flabel"><?php echo getlocal("page.gen_button.include_site_name") ?></div>
<div class="fvaluenodesc">
<input type="checkbox" name="hostname" value="on"<?php echo form_value_cb('hostname') ? " checked=\"checked\"" : "" ?> onchange="this.form.submit();"/>
</div>
</div>
<?php if( $page['formhostname'] ) { ?>
<div class="fieldinrow">
<div class="flabel"><?php echo getlocal("page.gen_button.secure_links") ?></div>
<div class="fvaluenodesc">
<input type="checkbox" name="secure" value="on"<?php echo form_value_cb('secure') ? " checked=\"checked\"" : "" ?> onchange="this.form.submit();"/>
</div>
</div>
<?php } ?>
<br clear="all"/>
<div class="field">
<div class="flabel"><?php echo getlocal("page.gen_button.modsecurity") ?></div>
<div class="fvaluenodesc">
<input type="checkbox" name="modsecurity" value="on"<?php echo form_value_cb('modsecurity') ? " checked=\"checked\"" : "" ?> onchange="this.form.submit();"/>
</div>
</div>
<div class="field">
<div class="flabel"><?php echo getlocal("page.gen_button.code") ?></div>
<div class="fvaluewithta" dir="ltr">
<textarea cols="44" rows="15"><?php echo htmlspecialchars($page['buttonCode']) ?></textarea>
</div>
<div class="fdescr"><?php echo getlocal("page.gen_button.code.description") ?></div>
<br clear="all"/>
</div>
<div class="field">
<div class="flabel"><?php echo getlocal("page.gen_button.sample") ?></div>
<div class="fvaluenodesc">
<?php echo $page['buttonCode'] ?>
</div>
</div>
</div>
</div><div class="formbottom"><div class="formbottomi"></div></div></div>
</div>
</form>
<?php
} /* content */
require_once('inc_main.php');
?>