Replace "operator/*_themes.php" with a controller

This commit is contained in:
Dmitriy Simushev 2014-06-03 12:44:52 +00:00
parent 7b6604fba2
commit b75f693454
13 changed files with 176 additions and 292 deletions

View File

@ -94,6 +94,9 @@ class CommonController extends AbstractController
$page['availableLocales'] = get_available_locales(); $page['availableLocales'] = get_available_locales();
$page['availableChatStyles'] = ChatStyle::getAvailableStyles(); $page['availableChatStyles'] = ChatStyle::getAvailableStyles();
$page['availablePageStyles'] = PageStyle::getAvailableStyles(); $page['availablePageStyles'] = PageStyle::getAvailableStyles();
$page['chatStylePreviewPath'] = $this->generateUrl('style_preview', array('type' => 'chat'));
$page['pageStylePreviewPath'] = $this->generateUrl('style_preview', array('type' => 'page'));
$page['invitationStylePreviewPath'] = $this->generateUrl('style_preview', array('type' => 'invitation'));
$page['stored'] = $request->query->has('stored'); $page['stored'] = $request->query->has('stored');
$page['enabletracking'] = Settings::get('enabletracking'); $page['enabletracking'] = Settings::get('enabletracking');
$page['cron_path'] = cron_get_uri($params['cron_key']); $page['cron_path'] = cron_get_uri($params['cron_key']);

View File

@ -0,0 +1,154 @@
<?php
/*
* Copyright 2005-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Mibew\Controller;
use Mibew\Settings;
use Mibew\Style\StyleInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Contains all actions which are related with styles.
*/
class StyleController extends AbstractController
{
const TYPE_CHAT = 'chat';
const TYPE_INVITATION = 'invitation';
const TYPE_PAGE = 'page';
/**
* Generates a page with style preview.
*
* @param Request $request Incoming request.
* @return string Rendered page content.
*/
public function previewAction(Request $request)
{
$operator = $this->getOperator();
$class_name = $this->resolveClassName($request->attributes->get('type'));
$style_list = call_user_func($class_name . '::getAvailableStyles');
$preview = $request->query->get('preview');
if (!in_array($preview, $style_list)) {
$style_names = array_keys($style_list);
$preview = $style_list[$style_names[0]];
}
$style = new $class_name($preview);
$screenshots = $this->buildScreenshotList($style);
$page['formpreview'] = $preview;
$page['formaction'] = $request->getBaseUrl() . $request->getPathInfo();
$page['availablePreviews'] = $style_list;
$page['screenshotsList'] = $screenshots;
$page['title'] = getlocal('page.preview.title');
$page['menuid'] = 'styles';
$page = array_merge($page, prepare_menu($operator));
$page['tabs'] = $this->buildTabs($request);
return $this->render('style_preview', $page);
}
/**
* Builds list of the styles tabs.
*
* @param Request $request Current request.
* @return array Tabs list. The keys of the array are tabs titles and the
* values are tabs URLs.
*/
protected function buildTabs(Request $request)
{
$tabs = array();
$type = $request->attributes->get('type');
$tabs[getlocal("page_settings.tab.page_themes")] = ($type != self::TYPE_PAGE)
? $this->generateUrl('style_preview', array('type' => self::TYPE_PAGE))
: '';
$tabs[getlocal("page_settings.tab.themes")] = ($type != self::TYPE_CHAT)
? $this->generateUrl('style_preview', array('type' => self::TYPE_CHAT))
: '';
if (Settings::get('enabletracking')) {
$tabs[getlocal("page_settings.tab.invitationthemes")] = ($type != self::TYPE_INVITATION)
? $this->generateUrl('style_preview', array('type' => self::TYPE_INVITATION))
: '';
}
return $tabs;
}
/**
* Builds a list of screenshots.
*
* @param StyleInterface $style A style for which screenshots list should be
* built.
* @return array List of available screenshots. Each element is an
* associative array with the following keys:
* - "name": string, name of the screenshot.
* - "file": string, URL of the screenshot.
* - "description" string, screenshots description.
*/
protected function buildScreenshotList(StyleInterface $style)
{
$base_url = $this->getRouter()->getContext()->getBaseUrl();
$style_config = $style->getConfigurations();
$screenshots = array();
foreach ($style_config['screenshots'] as $name => $desc) {
$screenshots[] = array(
'name' => $name,
'file' => ($base_url . '/'
. $style->getFilesPath() . '/screenshots/'
. $name . '.png'),
'description' => $desc,
);
}
return $screenshots;
}
/**
* Resolves style class name by style type.
*
* @param string $style_type Type of the style. Can be one of
* StyleController::TYPE_* constants.
* @return string Name of the style class
*/
protected function resolveClassName($style_type)
{
switch ($style_type) {
case self::TYPE_CHAT:
$class_name = '\\Mibew\\Style\\ChatStyle';
break;
case self::TYPE_INVITATION:
$class_name = '\\Mibew\\Style\\InvitationStyle';
break;
case self::TYPE_PAGE:
$class_name = '\\Mibew\\Style\\PageStyle';
break;
default:
throw new \RuntimeException('Style type cannot be resolved.');
break;
}
return $class_name;
}
}

View File

@ -530,6 +530,16 @@ statistics:
requirements: requirements:
type: by-date|by-operator|by-page type: by-date|by-operator|by-page
## Styles
style_preview:
path: /operator/style/{type}/preview
defaults:
_controller: Mibew\Controller\StyleController::previewAction
_access_check: Mibew\AccessControl\Check\PermissionsCheck
_access_permissions: [CAN_ADMINISTRATE]
requirements:
type: chat|invitation|page
## Translation ## Translation
translation_edit: translation_edit:
path: /operator/translation/{string_id}/edit path: /operator/translation/{string_id}/edit

View File

@ -39,19 +39,7 @@ function setup_settings_tabs($active)
getlocal("page_settings.tab.performance") => ($active != 2 getlocal("page_settings.tab.performance") => ($active != 2
? (MIBEW_WEB_ROOT . "/operator/settings/performance") ? (MIBEW_WEB_ROOT . "/operator/settings/performance")
: ""), : ""),
getlocal("page_settings.tab.page_themes") => ($active != 3
? (MIBEW_WEB_ROOT . "/operator/page_themes.php")
: ""),
getlocal("page_settings.tab.themes") => ($active != 4
? (MIBEW_WEB_ROOT . "/operator/themes.php")
: ""),
); );
if (Settings::get('enabletracking')) {
$tabs[getlocal("page_settings.tab.invitationthemes")] = ($active != 5
? (MIBEW_WEB_ROOT . "/operator/invitationthemes.php")
: "");
}
return $tabs; return $tabs;
} }

View File

@ -256,6 +256,7 @@ menu.main=Main
menu.operator=You are {0} menu.operator=You are {0}
menu.profile.content=You can change your personal information on this page. menu.profile.content=You can change your personal information on this page.
menu.profile=Profile menu.profile=Profile
menu.styles=Styles
menu.translate=Localize menu.translate=Localize
menu.updates.content=Check for news and updates. menu.updates.content=Check for news and updates.
menu.updates=Updates menu.updates=Updates
@ -508,7 +509,7 @@ right.main=Main
right.other=Other right.other=Other
settings.chat.title.description=Name of your company for example. settings.chat.title.description=Name of your company for example.
settings.chat.title=Title in the chat window settings.chat.title=Title in the chat window
settings.chatstyle.description=A preview all pages for each style is available <a href="themes.php">here</a> settings.chatstyle.description=A preview all pages for each style is available <a href="{0}">here</a>
settings.chatstyle=Select a style for your chat windows settings.chatstyle=Select a style for your chat windows
settings.company.title.description=Enter your company title settings.company.title.description=Enter your company title
settings.company.title=Company title settings.company.title=Company title
@ -548,7 +549,7 @@ settings.host.description=Destination for your company name or logo link
settings.host=URL of your website settings.host=URL of your website
settings.invitationlifetime.description=Specify the lifetime of invitation in seconds. Default is 60 seconds. settings.invitationlifetime.description=Specify the lifetime of invitation in seconds. Default is 60 seconds.
settings.invitationlifetime=Invitation lifetime settings.invitationlifetime=Invitation lifetime
settings.invitationstyle.description=A preview for invitation style is available <a href="invitationthemes.php">here</a> settings.invitationstyle.description=A preview for invitation style is available <a href="{0}">here</a>
settings.invitationstyle=Select a style for your invitation settings.invitationstyle=Select a style for your invitation
settings.leavemessage_captcha.description=Protection against automated spam (captcha) settings.leavemessage_captcha.description=Protection against automated spam (captcha)
settings.leavemessage_captcha=Force visitor to enter a verification code when leaving message settings.leavemessage_captcha=Force visitor to enter a verification code when leaving message
@ -563,7 +564,7 @@ settings.onehostconnections.description=0 allows any number of connections
settings.onehostconnections=Max number of threads from one address settings.onehostconnections=Max number of threads from one address
settings.onlinetimeout.description=Set the number of seconds to show an operator as online. Default is 30 seconds. settings.onlinetimeout.description=Set the number of seconds to show an operator as online. Default is 30 seconds.
settings.onlinetimeout=Operator online time threshold settings.onlinetimeout=Operator online time threshold
settings.page_style.description=A preview for each style is available <a href="page_themes.php">here</a> settings.page_style.description=A preview for each style is available <a href="{0}">here</a>
settings.page_style=Select a style for your operator pages settings.page_style=Select a style for your operator pages
settings.popup_notification.description=Small dialog appears to attract your attention. settings.popup_notification.description=Small dialog appears to attract your attention.
settings.popup_notification=Enable "Popup dialog notification of the new visitor". settings.popup_notification=Enable "Popup dialog notification of the new visitor".

View File

@ -1,59 +0,0 @@
<?php
/*
* Copyright 2005-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Import namespaces and classes of the core
use Mibew\Style\InvitationStyle;
use Mibew\Style\PageStyle;
// Initialize libraries
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
$operator = check_login();
$style_list = InvitationStyle::getAvailableStyles();
$preview = verify_param("preview", "/^\w+$/", "default");
if (!in_array($preview, $style_list)) {
$style_names = array_keys($style_list);
$preview = $style_list[0];
}
$invitation_style = new InvitationStyle($preview);
$style_config = $invitation_style->getConfigurations();
$screenshots = array();
foreach ($style_config['screenshots'] as $name => $desc) {
$screenshots[] = array(
'name' => $name,
'file' => (MIBEW_WEB_ROOT . '/' . $invitation_style->getFilesPath()
. '/screenshots/' . $name . '.png'),
'description' => $desc
);
}
$page['formpreview'] = $preview;
$page['availablePreviews'] = $style_list;
$page['screenshotsList'] = $screenshots;
$page['title'] = getlocal("page.preview.title");
$page['menuid'] = "settings";
$page = array_merge($page, prepare_menu($operator));
$page['tabs'] = setup_settings_tabs(5);
$page_style = new PageStyle(PageStyle::getCurrentStyle());
$page_style->render('invitation_themes', $page);

View File

@ -1,58 +0,0 @@
<?php
/*
* Copyright 2005-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Import namespaces and classes of the core
use Mibew\Style\PageStyle;
// Initialize libraries
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
$operator = check_login();
$style_list = PageStyle::getAvailableStyles();
$preview = verify_param("preview", "/^\w+$/", "default");
if (!in_array($preview, $style_list)) {
$style_names = array_keys($style_list);
$preview = $style_list[$style_names[0]];
}
$preview_style = new PageStyle($preview);
$style_config = $preview_style->getConfigurations();
$screenshots = array();
foreach ($style_config['screenshots'] as $name => $desc) {
$screenshots[] = array(
'name' => $name,
'file' => (MIBEW_WEB_ROOT . '/' . $preview_style->getFilesPath()
. '/screenshots/' . $name . '.png'),
'description' => $desc,
);
}
$page['formpreview'] = $preview;
$page['availablePreviews'] = $style_list;
$page['screenshotsList'] = $screenshots;
$page['title'] = getlocal("page.preview.title");
$page['menuid'] = "settings";
$page = array_merge($page, prepare_menu($operator));
$page['tabs'] = setup_settings_tabs(3);
$page_style = new PageStyle(PageStyle::getCurrentStyle());
$page_style->render('page_themes', $page);

View File

@ -1,60 +0,0 @@
<?php
/*
* Copyright 2005-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Import namespaces and classes of the core
use Mibew\Style\ChatStyle;
use Mibew\Style\PageStyle;
// Initialize libraries
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
$operator = check_login();
$style_list = ChatStyle::getAvailableStyles();
$preview = verify_param("preview", "/^\w+$/", "default");
if (!in_array($preview, $style_list)) {
$style_names = array_keys($style_list);
$preview = $style_list[$style_names[0]];
}
$chat_style = new ChatStyle($preview);
$style_config = $chat_style->getConfigurations();
$screenshots = array();
foreach ($style_config['screenshots'] as $name => $desc) {
$screenshots[] = array(
'name' => $name,
'file' => (MIBEW_WEB_ROOT . '/' . $chat_style->getFilesPath()
. '/screenshots/' . $name . '.png'),
'description' => $desc
);
}
$page['formpreview'] = $preview;
$page['availablePreviews'] = $style_list;
$page['screenshotsList'] = $screenshots;
$page['title'] = getlocal("page.preview.title");
$page['menuid'] = "settings";
$page = array_merge($page, prepare_menu($operator));
$page['tabs'] = setup_settings_tabs(4);
$page_style = new PageStyle(PageStyle::getCurrentStyle());
$page_style->render('themes', $page);

View File

@ -32,6 +32,7 @@
<li{{#ifEqual menuid "operators"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/operator">{{l10n "leftMenu.client_agents"}}</a></li> <li{{#ifEqual menuid "operators"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/operator">{{l10n "leftMenu.client_agents"}}</a></li>
<li{{#ifEqual menuid "groups"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/group">{{l10n "menu.groups"}}</a></li> <li{{#ifEqual menuid "groups"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/group">{{l10n "menu.groups"}}</a></li>
<li{{#ifEqual menuid "settings"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/settings">{{l10n "leftMenu.client_settings"}}</a></li> <li{{#ifEqual menuid "settings"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/settings">{{l10n "leftMenu.client_settings"}}</a></li>
<li{{#ifEqual menuid "styles"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/style/page/preview">{{l10n "menu.styles"}}</a></li>
<li{{#ifEqual menuid "translation"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/translation">{{l10n "menu.translate"}}</a></li> <li{{#ifEqual menuid "translation"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/translation">{{l10n "menu.translate"}}</a></li>
<li{{#ifEqual menuid "updates"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/updates">{{l10n "menu.updates"}}</a></li> <li{{#ifEqual menuid "updates"}} class="active"{{/ifEqual}}><a href="{{mibewRoot}}/operator/updates">{{l10n "menu.updates"}}</a></li>
{{/if}} {{/if}}

View File

@ -1,48 +0,0 @@
{{#extends "_layout"}}
{{#override "menu"}}{{> _menu}}{{/override}}
{{#override "content"}}
{{l10n "page.preview.intro"}}
<br />
<br />
<form name="preview" method="get" action="{{mibewRoot}}/operator/invitationthemes.php">
<div>
{{> _tabs}}
<div class="mform">
<div class="formtop">
<div class="formtopi"></div>
</div>
<div class="forminner">
<div class="fieldForm">
<div class="field">
<label for="preview" class="flabel">{{l10n "page.preview.choose"}}</label>
<div class="fvaluenodesc">
<select id="preview" name="preview" onchange="this.form.submit();">
{{#each availablePreviews}}
<option value="{{this}}"{{#ifEqual this ../formpreview}} selected="selected"{{/ifEqual}}>{{this}}</option>
{{/each}}
</select>
</div>
</div>
{{#each screenshotsList}}
<div class="field">
<div class="flabel">{{description}}</div>
<div class="fvalueframe">
<img class="screenshot" alt="{{name}}" src="{{file}}" />
</div>
</div>
{{/each}}
</div>
</div>
<div class="formbottom">
<div class="formbottomi"></div>
</div>
</div>
</div>
</form>
{{/override}}
{{/extends}}

View File

@ -1,48 +0,0 @@
{{#extends "_layout"}}
{{#override "menu"}}{{> _menu}}{{/override}}
{{#override "content"}}
{{l10n "page.preview.intro"}}
<br />
<br />
<form name="preview" method="get" action="{{mibewRoot}}/operator/page_themes.php">
<div>
{{> _tabs}}
<div class="mform">
<div class="formtop">
<div class="formtopi"></div>
</div>
<div class="forminner">
<div class="fieldForm">
<div class="field">
<label for="preview" class="flabel">{{l10n "page.preview.choose"}}</label>
<div class="fvaluenodesc">
<select id="preview" name="preview" onchange="this.form.submit();">
{{#each availablePreviews}}
<option value="{{this}}"{{#ifEqual this ../formpreview}} selected="selected"{{/ifEqual}}>{{this}}</option>
{{/each}}
</select>
</div>
</div>
{{#each screenshotsList}}
<div class="field">
<div class="flabel">{{description}}</div>
<div class="fvalueframe">
<img class="screenshot" alt="{{name}}" src="{{file}}" />
</div>
</div>
{{/each}}
</div>
</div>
<div class="formbottom">
<div class="formbottomi"></div>
</div>
</div>
</div>
</form>
{{/override}}
{{/extends}}

View File

@ -130,7 +130,7 @@
{{/each}} {{/each}}
</select> </select>
</div> </div>
<label for="page_style" class="fdescr"> &mdash; {{l10n "settings.page_style.description"}}</label> <label for="page_style" class="fdescr"> &mdash; {{l10n "settings.page_style.description" pageStylePreviewPath}}</label>
<br clear="all"/> <br clear="all"/>
</div> </div>
@ -143,7 +143,7 @@
{{/each}} {{/each}}
</select> </select>
</div> </div>
<label for="chat_style" class="fdescr"> &mdash; {{l10n "settings.chatstyle.description"}}</label> <label for="chat_style" class="fdescr"> &mdash; {{l10n "settings.chatstyle.description" chatStylePreviewPath}}</label>
<br clear="all"/> <br clear="all"/>
</div> </div>
@ -157,7 +157,7 @@
{{/each}} {{/each}}
</select> </select>
</div> </div>
<label for="invitation_style" class="fdescr"> &mdash; {{l10n "settings.invitationstyle.description"}}</label> <label for="invitation_style" class="fdescr"> &mdash; {{l10n "settings.invitationstyle.description" invitationStylePreviewPath}}</label>
<br clear="all"/> <br clear="all"/>
</div> </div>
{{/if}} {{/if}}

View File

@ -7,7 +7,7 @@
<br /> <br />
<br /> <br />
<form name="preview" method="get" action="{{mibewRoot}}/operator/themes.php"> <form name="preview" method="get" action="{{formaction}}">
<div> <div>
{{> _tabs}} {{> _tabs}}