Skip to content

Commit

Permalink
Some cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeichen32 committed Mar 18, 2015
1 parent 54797e1 commit b84d7ad
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 94 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ before_script:
- ./tests/travis/prepare.sh
- ./tests/travis/setup_webserver.sh

- export GENERATE_TRAVIS_YML_COMMAND="php ./console generate:travis-yml --plugin=\"CustomOptOut\""
- ./tests/travis/autoupdate_travis_yml.sh

- cd tests/PHPUnit

after_script:
Expand Down
115 changes: 60 additions & 55 deletions API.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,79 +21,84 @@
* @package CustomOptOut
* @method static \Piwik\Plugins\CustomOptOut\API getInstance()
*/
class API extends \Piwik\Plugin\API {
class API extends \Piwik\Plugin\API
{

/**
* Save the custom css and custom css file
*
* @param $siteId
* @param null $customCss
* @param null $customFile
*/
public function saveSite($siteId, $customCss = null, $customFile = null) {
/**
* Save the custom css and custom css file
*
* @param $siteId
* @param null $customCss
* @param null $customFile
*/
public function saveSite($siteId, $customCss = null, $customFile = null)
{

Piwik::checkUserHasAdminAccess($siteId);
Piwik::checkUserHasAdminAccess($siteId);

$query = "UPDATE " . Common::prefixTable("site") .
" SET custom_css = ?, custom_css_file = ?" .
" WHERE idsite = ?";
$query = "UPDATE ".Common::prefixTable("site") .
" SET custom_css = ?, custom_css_file = ?" .
" WHERE idsite = ?";

Db::query($query, array($customCss, $customFile, $siteId));
Db::query($query, array($customCss, $customFile, $siteId));

}
}

/**
* Returns the website information : id, custom css, custom css file
*
* @throws Exception If the site ID doesn't exist or the user doesn't have access to it
* @param int $idSite
* @return array
*/
public function getSiteDataId($idSite) {
/**
* Returns the website information : id, custom css, custom css file
*
* @throws Exception If the site ID doesn't exist or the user doesn't have access to it
* @param int $idSite
* @return array
*/
public function getSiteDataId($idSite)
{

$query = "SELECT idsite, custom_css, custom_css_file" .
" FROM " . Common::prefixTable("site") .
" WHERE idsite = ?";
$query = "SELECT idsite, custom_css, custom_css_file" .
" FROM ".Common::prefixTable("site") .
" WHERE idsite = ?";

$site = Db::get()->fetchRow($query, array($idSite));
$site = Db::get()->fetchRow($query, array($idSite));

return $site;
return $site;

}
}

/**
* Returns true if the css editor is enabled
*
* @return bool
*/
public function isCssEditorEnabled() {
/**
* Returns true if the css editor is enabled
*
* @return bool
*/
public function isCssEditorEnabled()
{

$settings = new Settings('CustomOptOut');
$value = (bool) $settings->enableEditor->getValue();
$settings = new Settings('CustomOptOut');
$value = (bool)$settings->enableEditor->getValue();

if ($value === false) {
return false;
}
if ($value === false) {
return false;
}

return true;
return true;

}
}

/**
* Return the current css editor theme
*
* @return string
*/
public function getEditorTheme() {
/**
* Return the current css editor theme
*
* @return string
*/
public function getEditorTheme()
{

$settings = new Settings('CustomOptOut');
$value = $settings->editorTheme->getValue();
$settings = new Settings('CustomOptOut');
$value = $settings->editorTheme->getValue();

if ($value == 'default') {
return 'default';
}
if ($value == 'default') {
return 'default';
}

return 'blackboard';
return 'blackboard';

}
}
}
36 changes: 22 additions & 14 deletions CustomOptOut.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
/**
* @package CustomOptOut
*/
class CustomOptOut extends \Piwik\Plugin {
class CustomOptOut extends \Piwik\Plugin
{

/**
* @see Piwik\Plugin::getListHooksRegistered
*/
public function getListHooksRegistered() {
public function getListHooksRegistered()
{

return array(
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
Expand All @@ -34,7 +36,8 @@ public function getListHooksRegistered() {
/**
* @param $jsFiles
*/
public function getJsFiles( &$jsFiles ) {
public function getJsFiles(&$jsFiles)
{

// CodeMirror
$jsFiles[] = "plugins/CustomOptOut/javascripts/codemirror/codemirror.js";
Expand All @@ -55,7 +58,8 @@ public function getJsFiles( &$jsFiles ) {
/**
* @param $stylesheets
*/
public function getStylesheetFiles( &$stylesheets ) {
public function getStylesheetFiles(&$stylesheets)
{

// CodeMirror CSS
$stylesheets[] = "plugins/CustomOptOut/stylesheets/codemirror/codemirror.css";
Expand All @@ -70,21 +74,23 @@ public function getStylesheetFiles( &$stylesheets ) {
*
* @throws \Exception
*/
public function install() {
public function install()
{

try {

$sql = sprintf(
"ALTER TABLE %s" .
" ADD COLUMN `custom_css` TEXT NULL AFTER `keep_url_fragment`," .
" ADD COLUMN `custom_css_file` VARCHAR(255) NULL AFTER `custom_css`;", Common::prefixTable( 'site' )
" ADD COLUMN `custom_css_file` VARCHAR(255) NULL AFTER `custom_css`;",
Common::prefixTable('site')
);

Db::exec( $sql );
Db::exec($sql);

} catch ( \Exception $exp ) {
} catch (\Exception $exp) {

if ( ! Db::get()->isErrNo( $exp, '1060' ) ) {
if (!Db::get()->isErrNo($exp, '1060')) {
throw $exp;
}

Expand All @@ -97,21 +103,23 @@ public function install() {
*
* @throws \Exception
*/
public function uninstall() {
public function uninstall()
{

try {

$sql = sprintf(
"ALTER TABLE %s" .
" DROP COLUMN `custom_css`," .
" DROP COLUMN `custom_css_file`;", Common::prefixTable( 'site' )
" DROP COLUMN `custom_css_file`;",
Common::prefixTable('site')
);

Db::exec( $sql );
Db::exec($sql);

} catch ( \Exception $exp ) {
} catch (\Exception $exp) {

if ( ! Db::get()->isErrNo( $exp, '1091' ) ) {
if (!Db::get()->isErrNo($exp, '1091')) {
throw $exp;
}

Expand Down
10 changes: 6 additions & 4 deletions Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
* To configure a menu (such as Admin Menu, Reporting Menu, User Menu...) simply call the corresponding methods as
* described in the API-Reference http://developer.piwik.org/api-reference/Piwik/Menu/MenuAbstract
*/
class Menu extends \Piwik\Plugin\Menu {
public function configureAdminMenu( MenuAdmin $menu ) {
if ( Piwik::isUserHasSomeAdminAccess() ) {
$menu->addSettingsItem( 'Custom OptOut', $this->urlForDefaultAction() );
class Menu extends \Piwik\Plugin\Menu
{
public function configureAdminMenu(MenuAdmin $menu)
{
if (Piwik::isUserHasSomeAdminAccess()) {
$menu->addSettingsItem('Custom OptOut', $this->urlForDefaultAction());
}
}
}
42 changes: 24 additions & 18 deletions Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
* $settings->metric->getValue();
*
*/
class Settings extends \Piwik\Plugin\Settings {
class Settings extends \Piwik\Plugin\Settings
{
/**
* @var UserSetting
*/
Expand All @@ -32,44 +33,49 @@ class Settings extends \Piwik\Plugin\Settings {
*/
public $editorTheme;

protected function init() {
$this->setIntroduction( 'Custom OptOut' );
protected function init()
{
$this->setIntroduction('Custom OptOut');

$this->createEnableEditorSetting();
$this->createThemeSetting();
}

private function createEnableEditorSetting() {
private function createEnableEditorSetting()
{

$this->enableEditor = new SystemSetting( 'enableEditor',
Piwik::translate( 'CustomOptOut_ShowEditorOptionName' ) );
$this->enableEditor = new SystemSetting(
'enableEditor',
Piwik::translate('CustomOptOut_ShowEditorOptionName')
);

$this->enableEditor->type = static::TYPE_BOOL;
$this->enableEditor->type = static::TYPE_BOOL;
$this->enableEditor->uiControlType = static::CONTROL_CHECKBOX;
$this->enableEditor->description = Piwik::translate( 'CustomOptOut_ShowEditorDescription' );
$this->enableEditor->defaultValue = true;
$this->enableEditor->description = Piwik::translate('CustomOptOut_ShowEditorDescription');
$this->enableEditor->defaultValue = true;

$this->addSetting( $this->enableEditor );
$this->addSetting($this->enableEditor);

}

private function createThemeSetting() {
private function createThemeSetting()
{

$this->editorTheme = new SystemSetting(
'editorTheme',
Piwik::translate( 'CustomOptOut_EditorThemeOptionName' )
Piwik::translate('CustomOptOut_EditorThemeOptionName')
);

$this->editorTheme->type = static::TYPE_STRING;
$this->editorTheme->uiControlType = static::CONTROL_SINGLE_SELECT;
$this->editorTheme->description = Piwik::translate( 'CustomOptOut_EditorThemeDescription' );
$this->editorTheme->defaultValue = 'default';
$this->editorTheme->type = static::TYPE_STRING;
$this->editorTheme->uiControlType = static::CONTROL_SINGLE_SELECT;
$this->editorTheme->description = Piwik::translate('CustomOptOut_EditorThemeDescription');
$this->editorTheme->defaultValue = 'default';
$this->editorTheme->availableValues = array(
'default' => 'Bright Theme',
'default' => 'Bright Theme',
'blackboard' => 'Dark Theme',
);

$this->addSetting( $this->editorTheme );
$this->addSetting($this->editorTheme);

}
}

0 comments on commit b84d7ad

Please sign in to comment.