From 472bca2a571fcf9400cbb0d4466c960994ad999a Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Fri, 10 Oct 2014 21:54:19 +0200 Subject: [PATCH 01/30] Updating app-folder to PSR-2 --- app/config/app.php | 210 ++++++++++++++++++------------------- app/config/cache.php | 140 ++++++++++++------------- app/config/database.php | 208 ++++++++++++++++++------------------ app/config/mail.php | 204 +++++++++++++++++------------------ app/config/queue.php | 2 +- app/config/session.php | 206 ++++++++++++++++++------------------ app/config/testing/cms.php | 4 +- app/config/view.php | 44 ++++---- app/filters.php | 37 +++---- app/start/artisan.php | 1 - app/start/global.php | 8 +- 11 files changed, 527 insertions(+), 537 deletions(-) diff --git a/app/config/app.php b/app/config/app.php index 4297620f2..a2adb5332 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -2,132 +2,132 @@ return array( - /* - |-------------------------------------------------------------------------- - | Application Debug Mode - |-------------------------------------------------------------------------- - | - | When your application is in debug mode, detailed error messages with - | stack traces will be shown on every error that occurs within your - | application. If disabled, a simple generic error page is shown. - | - */ + /* + |-------------------------------------------------------------------------- + | Application Debug Mode + |-------------------------------------------------------------------------- + | + | When your application is in debug mode, detailed error messages with + | stack traces will be shown on every error that occurs within your + | application. If disabled, a simple generic error page is shown. + | + */ - 'debug' => true, + 'debug' => true, - /* - |-------------------------------------------------------------------------- - | Application URL - |-------------------------------------------------------------------------- - | - | This URL is used by the console to properly generate URLs when using - | the Artisan command line tool. You should set this to the root of - | your application so that it is used when running Artisan tasks. - | - */ + /* + |-------------------------------------------------------------------------- + | Application URL + |-------------------------------------------------------------------------- + | + | This URL is used by the console to properly generate URLs when using + | the Artisan command line tool. You should set this to the root of + | your application so that it is used when running Artisan tasks. + | + */ - 'url' => 'http://localhost', + 'url' => 'http://localhost', - /* - |-------------------------------------------------------------------------- - | Application Timezone - |-------------------------------------------------------------------------- - | - | Here you may specify the default timezone for your application, which - | will be used by the PHP date and date-time functions. We have gone - | ahead and set this to a sensible default for you out of the box. - | - */ + /* + |-------------------------------------------------------------------------- + | Application Timezone + |-------------------------------------------------------------------------- + | + | Here you may specify the default timezone for your application, which + | will be used by the PHP date and date-time functions. We have gone + | ahead and set this to a sensible default for you out of the box. + | + */ - 'timezone' => 'UTC', + 'timezone' => 'UTC', - /* - |-------------------------------------------------------------------------- - | Application Locale Configuration - |-------------------------------------------------------------------------- - | - | The application locale determines the default locale that will be used - | by the translation service provider. You are free to set this value - | to any of the locales which will be supported by the application. - | - */ + /* + |-------------------------------------------------------------------------- + | Application Locale Configuration + |-------------------------------------------------------------------------- + | + | The application locale determines the default locale that will be used + | by the translation service provider. You are free to set this value + | to any of the locales which will be supported by the application. + | + */ - 'locale' => 'en', + 'locale' => 'en', - /* - |-------------------------------------------------------------------------- - | Application Fallback Locale - |-------------------------------------------------------------------------- - | - | The fallback locale determines the locale to use when the current one - | is not available. You may change the value to correspond to any of - | the language folders that are provided through your application. - | - */ + /* + |-------------------------------------------------------------------------- + | Application Fallback Locale + |-------------------------------------------------------------------------- + | + | The fallback locale determines the locale to use when the current one + | is not available. You may change the value to correspond to any of + | the language folders that are provided through your application. + | + */ - 'fallback_locale' => 'en', + 'fallback_locale' => 'en', - /* - |-------------------------------------------------------------------------- - | Encryption Key - |-------------------------------------------------------------------------- - | - | This key is used by the Illuminate encrypter service and should be set - | to a random, 32 character string, otherwise these encrypted strings - | will not be safe. Please do this before deploying an application! - | - */ + /* + |-------------------------------------------------------------------------- + | Encryption Key + |-------------------------------------------------------------------------- + | + | This key is used by the Illuminate encrypter service and should be set + | to a random, 32 character string, otherwise these encrypted strings + | will not be safe. Please do this before deploying an application! + | + */ - 'key' => 'CHANGE_ME!!!', + 'key' => 'CHANGE_ME!!!', - 'cipher' => MCRYPT_RIJNDAEL_128, + 'cipher' => MCRYPT_RIJNDAEL_128, - /* - |-------------------------------------------------------------------------- - | Autoloaded Service Providers - |-------------------------------------------------------------------------- - | - | The service providers listed here will be automatically loaded on the - | request to your application. Feel free to add your own services to - | this array to grant expanded functionality to your applications. - | - */ + /* + |-------------------------------------------------------------------------- + | Autoloaded Service Providers + |-------------------------------------------------------------------------- + | + | The service providers listed here will be automatically loaded on the + | request to your application. Feel free to add your own services to + | this array to grant expanded functionality to your applications. + | + */ - 'providers' => array_merge(include(base_path().'/modules/system/providers.php'), array( + 'providers' => array_merge(include(base_path().'/modules/system/providers.php'), array( - // 'Illuminate\Html\HtmlServiceProvider', // Example + // 'Illuminate\Html\HtmlServiceProvider', // Example - 'System\ServiceProvider', - )), + 'System\ServiceProvider', + )), - /* - |-------------------------------------------------------------------------- - | Service Provider Manifest - |-------------------------------------------------------------------------- - | - | The service provider manifest is used by Laravel to lazy load service - | providers which are not needed for each request, as well to keep a - | list of all of the services. Here, you may set its storage spot. - | - */ + /* + |-------------------------------------------------------------------------- + | Service Provider Manifest + |-------------------------------------------------------------------------- + | + | The service provider manifest is used by Laravel to lazy load service + | providers which are not needed for each request, as well to keep a + | list of all of the services. Here, you may set its storage spot. + | + */ - 'manifest' => storage_path().'/meta', + 'manifest' => storage_path().'/meta', - /* - |-------------------------------------------------------------------------- - | Class Aliases - |-------------------------------------------------------------------------- - | - | This array of class aliases will be registered when this application - | is started. However, feel free to register as many as you wish as - | the aliases are "lazy" loaded so they don't hinder performance. - | - */ + /* + |-------------------------------------------------------------------------- + | Class Aliases + |-------------------------------------------------------------------------- + | + | This array of class aliases will be registered when this application + | is started. However, feel free to register as many as you wish as + | the aliases are "lazy" loaded so they don't hinder performance. + | + */ - 'aliases' => array_merge(include(base_path().'/modules/system/aliases.php'), array( + 'aliases' => array_merge(include(base_path().'/modules/system/aliases.php'), array( - // 'Str' => 'Illuminate\Support\Str', // Example + // 'Str' => 'Illuminate\Support\Str', // Example - )), + )), ); diff --git a/app/config/cache.php b/app/config/cache.php index ce8984239..c5e0d96b7 100644 --- a/app/config/cache.php +++ b/app/config/cache.php @@ -2,88 +2,88 @@ return array( - /* - |-------------------------------------------------------------------------- - | Default Cache Driver - |-------------------------------------------------------------------------- - | - | This option controls the default cache "driver" that will be used when - | using the Caching library. Of course, you may use other drivers any - | time you wish. This is the default when another is not specified. - | - | Supported: "file", "database", "apc", "memcached", "redis", "array" - | - */ + /* + |-------------------------------------------------------------------------- + | Default Cache Driver + |-------------------------------------------------------------------------- + | + | This option controls the default cache "driver" that will be used when + | using the Caching library. Of course, you may use other drivers any + | time you wish. This is the default when another is not specified. + | + | Supported: "file", "database", "apc", "memcached", "redis", "array" + | + */ - 'driver' => 'file', + 'driver' => 'file', - /* - |-------------------------------------------------------------------------- - | File Cache Location - |-------------------------------------------------------------------------- - | - | When using the "file" cache driver, we need a location where the cache - | files may be stored. A sensible default has been specified, but you - | are free to change it to any other place on disk that you desire. - | - */ + /* + |-------------------------------------------------------------------------- + | File Cache Location + |-------------------------------------------------------------------------- + | + | When using the "file" cache driver, we need a location where the cache + | files may be stored. A sensible default has been specified, but you + | are free to change it to any other place on disk that you desire. + | + */ - 'path' => storage_path().'/cache', + 'path' => storage_path().'/cache', - /* - |-------------------------------------------------------------------------- - | Database Cache Connection - |-------------------------------------------------------------------------- - | - | When using the "database" cache driver you may specify the connection - | that should be used to store the cached items. When this option is - | null the default database connection will be utilized for cache. - | - */ + /* + |-------------------------------------------------------------------------- + | Database Cache Connection + |-------------------------------------------------------------------------- + | + | When using the "database" cache driver you may specify the connection + | that should be used to store the cached items. When this option is + | null the default database connection will be utilized for cache. + | + */ - 'connection' => null, + 'connection' => null, - /* - |-------------------------------------------------------------------------- - | Database Cache Table - |-------------------------------------------------------------------------- - | - | When using the "database" cache driver we need to know the table that - | should be used to store the cached items. A default table name has - | been provided but you're free to change it however you deem fit. - | - */ + /* + |-------------------------------------------------------------------------- + | Database Cache Table + |-------------------------------------------------------------------------- + | + | When using the "database" cache driver we need to know the table that + | should be used to store the cached items. A default table name has + | been provided but you're free to change it however you deem fit. + | + */ - 'table' => 'cache', + 'table' => 'cache', - /* - |-------------------------------------------------------------------------- - | Memcached Servers - |-------------------------------------------------------------------------- - | - | Now you may specify an array of your Memcached servers that should be - | used when utilizing the Memcached cache driver. All of the servers - | should contain a value for "host", "port", and "weight" options. - | - */ + /* + |-------------------------------------------------------------------------- + | Memcached Servers + |-------------------------------------------------------------------------- + | + | Now you may specify an array of your Memcached servers that should be + | used when utilizing the Memcached cache driver. All of the servers + | should contain a value for "host", "port", and "weight" options. + | + */ - 'memcached' => array( + 'memcached' => array( - array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100), + array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100), - ), + ), - /* - |-------------------------------------------------------------------------- - | Cache Key Prefix - |-------------------------------------------------------------------------- - | - | When utilizing a RAM based store such as APC or Memcached, there might - | be other applications utilizing the same cache. So, we'll specify a - | value to get prefixed to all our keys so we can avoid collisions. - | - */ + /* + |-------------------------------------------------------------------------- + | Cache Key Prefix + |-------------------------------------------------------------------------- + | + | When utilizing a RAM based store such as APC or Memcached, there might + | be other applications utilizing the same cache. So, we'll specify a + | value to get prefixed to all our keys so we can avoid collisions. + | + */ - 'prefix' => 'laravel', + 'prefix' => 'laravel', ); diff --git a/app/config/database.php b/app/config/database.php index fa82fbbf3..a56fb1e56 100644 --- a/app/config/database.php +++ b/app/config/database.php @@ -2,126 +2,126 @@ return array( - /* - |-------------------------------------------------------------------------- - | PDO Fetch Style - |-------------------------------------------------------------------------- - | - | By default, database results will be returned as instances of the PHP - | stdClass object; however, you may desire to retrieve records in an - | array format for simplicity. Here you can tweak the fetch style. - | - */ + /* + |-------------------------------------------------------------------------- + | PDO Fetch Style + |-------------------------------------------------------------------------- + | + | By default, database results will be returned as instances of the PHP + | stdClass object; however, you may desire to retrieve records in an + | array format for simplicity. Here you can tweak the fetch style. + | + */ - 'fetch' => PDO::FETCH_CLASS, + 'fetch' => PDO::FETCH_CLASS, - /* - |-------------------------------------------------------------------------- - | Default Database Connection Name - |-------------------------------------------------------------------------- - | - | Here you may specify which of the database connections below you wish - | to use as your default connection for all database work. Of course - | you may use many connections at once using the Database library. - | - */ + /* + |-------------------------------------------------------------------------- + | Default Database Connection Name + |-------------------------------------------------------------------------- + | + | Here you may specify which of the database connections below you wish + | to use as your default connection for all database work. Of course + | you may use many connections at once using the Database library. + | + */ - 'default' => 'mysql', + 'default' => 'mysql', - /* - |-------------------------------------------------------------------------- - | Database Connections - |-------------------------------------------------------------------------- - | - | Here are each of the database connections setup for your application. - | Of course, examples of configuring each database platform that is - | supported by Laravel is shown below to make development simple. - | - | - | All database work in Laravel is done through the PHP PDO facilities - | so make sure you have the driver for your particular database of - | choice installed on your machine before you begin development. - | - */ + /* + |-------------------------------------------------------------------------- + | Database Connections + |-------------------------------------------------------------------------- + | + | Here are each of the database connections setup for your application. + | Of course, examples of configuring each database platform that is + | supported by Laravel is shown below to make development simple. + | + | + | All database work in Laravel is done through the PHP PDO facilities + | so make sure you have the driver for your particular database of + | choice installed on your machine before you begin development. + | + */ - 'connections' => array( + 'connections' => array( - 'sqlite' => array( - 'driver' => 'sqlite', - 'database' => 'database/production.sqlite', - 'prefix' => '', - ), + 'sqlite' => array( + 'driver' => 'sqlite', + 'database' => 'database/production.sqlite', + 'prefix' => '', + ), - 'mysql' => array( - 'driver' => 'mysql', - 'host' => 'localhost', - 'port' => '', - 'database' => 'database', - 'username' => 'root', - 'password' => '', - 'charset' => 'utf8', - 'collation' => 'utf8_unicode_ci', - 'prefix' => '', - ), + 'mysql' => array( + 'driver' => 'mysql', + 'host' => 'localhost', + 'port' => '', + 'database' => 'database', + 'username' => 'root', + 'password' => '', + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', + 'prefix' => '', + ), - 'pgsql' => array( - 'driver' => 'pgsql', - 'host' => 'localhost', - 'port' => '', - 'database' => 'database', - 'username' => 'root', - 'password' => '', - 'charset' => 'utf8', - 'prefix' => '', - 'schema' => 'public', - ), + 'pgsql' => array( + 'driver' => 'pgsql', + 'host' => 'localhost', + 'port' => '', + 'database' => 'database', + 'username' => 'root', + 'password' => '', + 'charset' => 'utf8', + 'prefix' => '', + 'schema' => 'public', + ), - 'sqlsrv' => array( - 'driver' => 'sqlsrv', - 'host' => 'localhost', - 'port' => '', - 'database' => 'database', - 'username' => 'root', - 'password' => '', - 'prefix' => '', - ), + 'sqlsrv' => array( + 'driver' => 'sqlsrv', + 'host' => 'localhost', + 'port' => '', + 'database' => 'database', + 'username' => 'root', + 'password' => '', + 'prefix' => '', + ), - ), + ), - /* - |-------------------------------------------------------------------------- - | Migration Repository Table - |-------------------------------------------------------------------------- - | - | This table keeps track of all the migrations that have already run for - | your application. Using this information, we can determine which of - | the migrations on disk have not actually be run in the databases. - | - */ + /* + |-------------------------------------------------------------------------- + | Migration Repository Table + |-------------------------------------------------------------------------- + | + | This table keeps track of all the migrations that have already run for + | your application. Using this information, we can determine which of + | the migrations on disk have not actually be run in the databases. + | + */ - 'migrations' => 'migrations', + 'migrations' => 'migrations', - /* - |-------------------------------------------------------------------------- - | Redis Databases - |-------------------------------------------------------------------------- - | - | Redis is an open source, fast, and advanced key-value store that also - | provides a richer set of commands than a typical key-value systems - | such as APC or Memcached. Laravel makes it easy to dig right in. - | - */ + /* + |-------------------------------------------------------------------------- + | Redis Databases + |-------------------------------------------------------------------------- + | + | Redis is an open source, fast, and advanced key-value store that also + | provides a richer set of commands than a typical key-value systems + | such as APC or Memcached. Laravel makes it easy to dig right in. + | + */ - 'redis' => array( + 'redis' => array( - 'cluster' => true, + 'cluster' => true, - 'default' => array( - 'host' => '127.0.0.1', - 'port' => 6379, - 'database' => 0, - ), + 'default' => array( + 'host' => '127.0.0.1', + 'port' => 6379, + 'database' => 0, + ), - ), + ), ); diff --git a/app/config/mail.php b/app/config/mail.php index 0c675ef81..1a9f4e8ac 100644 --- a/app/config/mail.php +++ b/app/config/mail.php @@ -2,123 +2,123 @@ return array( - /* - |-------------------------------------------------------------------------- - | Mail Driver - |-------------------------------------------------------------------------- - | - | Laravel supports both SMTP and PHP's "mail" function as drivers for the - | sending of e-mail. You may specify which one you're using throughout - | your application here. By default, Laravel is setup for SMTP mail. - | - | Supported: "smtp", "mail", "sendmail" - | - */ + /* + |-------------------------------------------------------------------------- + | Mail Driver + |-------------------------------------------------------------------------- + | + | Laravel supports both SMTP and PHP's "mail" function as drivers for the + | sending of e-mail. You may specify which one you're using throughout + | your application here. By default, Laravel is setup for SMTP mail. + | + | Supported: "smtp", "mail", "sendmail" + | + */ - 'driver' => 'smtp', + 'driver' => 'smtp', - /* - |-------------------------------------------------------------------------- - | SMTP Host Address - |-------------------------------------------------------------------------- - | - | Here you may provide the host address of the SMTP server used by your - | applications. A default option is provided that is compatible with - | the Postmark mail service, which will provide reliable delivery. - | - */ + /* + |-------------------------------------------------------------------------- + | SMTP Host Address + |-------------------------------------------------------------------------- + | + | Here you may provide the host address of the SMTP server used by your + | applications. A default option is provided that is compatible with + | the Postmark mail service, which will provide reliable delivery. + | + */ - 'host' => 'smtp.mailgun.org', + 'host' => 'smtp.mailgun.org', - /* - |-------------------------------------------------------------------------- - | SMTP Host Port - |-------------------------------------------------------------------------- - | - | This is the SMTP port used by your application to delivery e-mails to - | users of your application. Like the host we have set this value to - | stay compatible with the Postmark e-mail application by default. - | - */ + /* + |-------------------------------------------------------------------------- + | SMTP Host Port + |-------------------------------------------------------------------------- + | + | This is the SMTP port used by your application to delivery e-mails to + | users of your application. Like the host we have set this value to + | stay compatible with the Postmark e-mail application by default. + | + */ - 'port' => 587, + 'port' => 587, - /* - |-------------------------------------------------------------------------- - | Global "From" Address - |-------------------------------------------------------------------------- - | - | You may wish for all e-mails sent by your application to be sent from - | the same address. Here, you may specify a name and address that is - | used globally for all e-mails that are sent by your application. - | - */ + /* + |-------------------------------------------------------------------------- + | Global "From" Address + |-------------------------------------------------------------------------- + | + | You may wish for all e-mails sent by your application to be sent from + | the same address. Here, you may specify a name and address that is + | used globally for all e-mails that are sent by your application. + | + */ - 'from' => array('address' => 'noreply@site.com', 'name' => 'October'), + 'from' => array('address' => 'noreply@site.com', 'name' => 'October'), - /* - |-------------------------------------------------------------------------- - | E-Mail Encryption Protocol - |-------------------------------------------------------------------------- - | - | Here you may specify the encryption protocol that should be used when - | the application send e-mail messages. A sensible default using the - | transport layer security protocol should provide great security. - | - */ + /* + |-------------------------------------------------------------------------- + | E-Mail Encryption Protocol + |-------------------------------------------------------------------------- + | + | Here you may specify the encryption protocol that should be used when + | the application send e-mail messages. A sensible default using the + | transport layer security protocol should provide great security. + | + */ - 'encryption' => 'tls', + 'encryption' => 'tls', - /* - |-------------------------------------------------------------------------- - | SMTP Server Username - |-------------------------------------------------------------------------- - | - | If your SMTP server requires a username for authentication, you should - | set it here. This will get used to authenticate with your server on - | connection. You may also set the "password" value below this one. - | - */ + /* + |-------------------------------------------------------------------------- + | SMTP Server Username + |-------------------------------------------------------------------------- + | + | If your SMTP server requires a username for authentication, you should + | set it here. This will get used to authenticate with your server on + | connection. You may also set the "password" value below this one. + | + */ - 'username' => null, + 'username' => null, - /* - |-------------------------------------------------------------------------- - | SMTP Server Password - |-------------------------------------------------------------------------- - | - | Here you may set the password required by your SMTP server to send out - | messages from your application. This will be given to the server on - | connection so that the application will be able to send messages. - | - */ + /* + |-------------------------------------------------------------------------- + | SMTP Server Password + |-------------------------------------------------------------------------- + | + | Here you may set the password required by your SMTP server to send out + | messages from your application. This will be given to the server on + | connection so that the application will be able to send messages. + | + */ - 'password' => null, + 'password' => null, - /* - |-------------------------------------------------------------------------- - | Sendmail System Path - |-------------------------------------------------------------------------- - | - | When using the "sendmail" driver to send e-mails, we will need to know - | the path to where Sendmail lives on this server. A default path has - | been provided here, which will work well on most of your systems. - | - */ + /* + |-------------------------------------------------------------------------- + | Sendmail System Path + |-------------------------------------------------------------------------- + | + | When using the "sendmail" driver to send e-mails, we will need to know + | the path to where Sendmail lives on this server. A default path has + | been provided here, which will work well on most of your systems. + | + */ - 'sendmail' => '/usr/sbin/sendmail -bs', + 'sendmail' => '/usr/sbin/sendmail -bs', - /* - |-------------------------------------------------------------------------- - | Mail "Pretend" - |-------------------------------------------------------------------------- - | - | When this option is enabled, e-mail will not actually be sent over the - | web and will instead be written to your application's logs files so - | you may inspect the message. This is great for local development. - | - */ + /* + |-------------------------------------------------------------------------- + | Mail "Pretend" + |-------------------------------------------------------------------------- + | + | When this option is enabled, e-mail will not actually be sent over the + | web and will instead be written to your application's logs files so + | you may inspect the message. This is great for local development. + | + */ - 'pretend' => false, + 'pretend' => false, -); \ No newline at end of file +); diff --git a/app/config/queue.php b/app/config/queue.php index 429c03ada..7e30a5364 100644 --- a/app/config/queue.php +++ b/app/config/queue.php @@ -83,4 +83,4 @@ return array( ), -); \ No newline at end of file +); diff --git a/app/config/session.php b/app/config/session.php index 16ba003c7..5213400fe 100644 --- a/app/config/session.php +++ b/app/config/session.php @@ -2,126 +2,126 @@ return array( - /* - |-------------------------------------------------------------------------- - | Default Session Driver - |-------------------------------------------------------------------------- - | - | This option controls the default session "driver" that will be used on - | requests. By default, we will use the lightweight native driver but - | you may specify any of the other wonderful drivers provided here. - | - | Supported: "native", "cookie", "database", "apc", - | "memcached", "redis", "array" - | - */ + /* + |-------------------------------------------------------------------------- + | Default Session Driver + |-------------------------------------------------------------------------- + | + | This option controls the default session "driver" that will be used on + | requests. By default, we will use the lightweight native driver but + | you may specify any of the other wonderful drivers provided here. + | + | Supported: "native", "cookie", "database", "apc", + | "memcached", "redis", "array" + | + */ - 'driver' => 'native', + 'driver' => 'native', - /* - |-------------------------------------------------------------------------- - | Session Lifetime - |-------------------------------------------------------------------------- - | - | Here you may specify the number of minutes that you wish the session - | to be allowed to remain idle for it is expired. If you want them - | to immediately expire when the browser closes, set it to zero. - | - */ + /* + |-------------------------------------------------------------------------- + | Session Lifetime + |-------------------------------------------------------------------------- + | + | Here you may specify the number of minutes that you wish the session + | to be allowed to remain idle for it is expired. If you want them + | to immediately expire when the browser closes, set it to zero. + | + */ - 'lifetime' => 120, + 'lifetime' => 120, - 'expire_on_close' => false, + 'expire_on_close' => false, - /* - |-------------------------------------------------------------------------- - | Session File Location - |-------------------------------------------------------------------------- - | - | When using the native session driver, we need a location where session - | files may be stored. A default has been set for you but a different - | location may be specified. This is only needed for file sessions. - | - */ + /* + |-------------------------------------------------------------------------- + | Session File Location + |-------------------------------------------------------------------------- + | + | When using the native session driver, we need a location where session + | files may be stored. A default has been set for you but a different + | location may be specified. This is only needed for file sessions. + | + */ - 'files' => storage_path().'/sessions', + 'files' => storage_path().'/sessions', - /* - |-------------------------------------------------------------------------- - | Session Database Connection - |-------------------------------------------------------------------------- - | - | When using the "database" session driver, you may specify the database - | connection that should be used to manage your sessions. This should - | correspond to a connection in your "database" configuration file. - | - */ + /* + |-------------------------------------------------------------------------- + | Session Database Connection + |-------------------------------------------------------------------------- + | + | When using the "database" session driver, you may specify the database + | connection that should be used to manage your sessions. This should + | correspond to a connection in your "database" configuration file. + | + */ - 'connection' => null, + 'connection' => null, - /* - |-------------------------------------------------------------------------- - | Session Database Table - |-------------------------------------------------------------------------- - | - | When using the "database" session driver, you may specify the table we - | should use to manage the sessions. Of course, a sensible default is - | provided for you; however, you are free to change this as needed. - | - */ + /* + |-------------------------------------------------------------------------- + | Session Database Table + |-------------------------------------------------------------------------- + | + | When using the "database" session driver, you may specify the table we + | should use to manage the sessions. Of course, a sensible default is + | provided for you; however, you are free to change this as needed. + | + */ - 'table' => 'sessions', + 'table' => 'sessions', - /* - |-------------------------------------------------------------------------- - | Session Sweeping Lottery - |-------------------------------------------------------------------------- - | - | Some session drivers must manually sweep their storage location to get - | rid of old sessions from storage. Here are the chances that it will - | happen on a given request. By default, the odds are 2 out of 100. - | - */ + /* + |-------------------------------------------------------------------------- + | Session Sweeping Lottery + |-------------------------------------------------------------------------- + | + | Some session drivers must manually sweep their storage location to get + | rid of old sessions from storage. Here are the chances that it will + | happen on a given request. By default, the odds are 2 out of 100. + | + */ - 'lottery' => array(2, 100), + 'lottery' => array(2, 100), - /* - |-------------------------------------------------------------------------- - | Session Cookie Name - |-------------------------------------------------------------------------- - | - | Here you may change the name of the cookie used to identify a session - | instance by ID. The name specified here will get used every time a - | new session cookie is created by the framework for every driver. - | - */ + /* + |-------------------------------------------------------------------------- + | Session Cookie Name + |-------------------------------------------------------------------------- + | + | Here you may change the name of the cookie used to identify a session + | instance by ID. The name specified here will get used every time a + | new session cookie is created by the framework for every driver. + | + */ - 'cookie' => 'october_session', + 'cookie' => 'october_session', - /* - |-------------------------------------------------------------------------- - | Session Cookie Path - |-------------------------------------------------------------------------- - | - | The session cookie path determines the path for which the cookie will - | be regarded as available. Typically, this will be the root path of - | your application but you are free to change this when necessary. - | - */ + /* + |-------------------------------------------------------------------------- + | Session Cookie Path + |-------------------------------------------------------------------------- + | + | The session cookie path determines the path for which the cookie will + | be regarded as available. Typically, this will be the root path of + | your application but you are free to change this when necessary. + | + */ - 'path' => '/', + 'path' => '/', - /* - |-------------------------------------------------------------------------- - | Session Cookie Domain - |-------------------------------------------------------------------------- - | - | Here you may change the domain of the cookie used to identify a session - | in your application. This will determine which domains the cookie is - | available to in your application. A sensible default has been set. - | - */ + /* + |-------------------------------------------------------------------------- + | Session Cookie Domain + |-------------------------------------------------------------------------- + | + | Here you may change the domain of the cookie used to identify a session + | in your application. This will determine which domains the cookie is + | available to in your application. A sensible default has been set. + | + */ - 'domain' => null, + 'domain' => null, ); diff --git a/app/config/testing/cms.php b/app/config/testing/cms.php index ed586eb9a..b53589f52 100644 --- a/app/config/testing/cms.php +++ b/app/config/testing/cms.php @@ -100,7 +100,7 @@ return array( | */ - 'enableAssetCache' => false, + 'enableAssetCache' => false, /* |-------------------------------------------------------------------------- @@ -109,4 +109,4 @@ return array( */ 'twigNoCache' => true, -); \ No newline at end of file +); diff --git a/app/config/view.php b/app/config/view.php index 34b8f3873..c0da05402 100644 --- a/app/config/view.php +++ b/app/config/view.php @@ -2,30 +2,30 @@ return array( - /* - |-------------------------------------------------------------------------- - | View Storage Paths - |-------------------------------------------------------------------------- - | - | Most templating systems load templates from disk. Here you may specify - | an array of paths that should be checked for your views. Of course - | the usual Laravel view path has already been registered for you. - | - */ + /* + |-------------------------------------------------------------------------- + | View Storage Paths + |-------------------------------------------------------------------------- + | + | Most templating systems load templates from disk. Here you may specify + | an array of paths that should be checked for your views. Of course + | the usual Laravel view path has already been registered for you. + | + */ - 'paths' => array(__DIR__.'/../views'), + 'paths' => array(__DIR__.'/../views'), - /* - |-------------------------------------------------------------------------- - | Pagination View - |-------------------------------------------------------------------------- - | - | This view will be used to render the pagination link output, and can - | be easily customized here to show any view you like. A clean view - | compatible with Twitter's Bootstrap is given to you by default. - | - */ + /* + |-------------------------------------------------------------------------- + | Pagination View + |-------------------------------------------------------------------------- + | + | This view will be used to render the pagination link output, and can + | be easily customized here to show any view you like. A clean view + | compatible with Twitter's Bootstrap is given to you by default. + | + */ - 'pagination' => 'pagination::slider-3', + 'pagination' => 'pagination::slider-3', ); diff --git a/app/filters.php b/app/filters.php index 083631db4..777b3ba6a 100644 --- a/app/filters.php +++ b/app/filters.php @@ -11,15 +11,13 @@ | */ -App::before(function($request) -{ - // +App::before(function ($request) { + // }); -App::after(function($request, $response) -{ - // +App::after(function ($request, $response) { + // }); /* @@ -33,15 +31,13 @@ App::after(function($request, $response) | */ -Route::filter('auth', function() -{ -// if (Auth::guest()) return Redirect::guest('login'); +Route::filter('auth', function () { +// if (Auth::guest()) return Redirect::guest('login'); }); -Route::filter('auth.basic', function() -{ -// return Auth::basic(); +Route::filter('auth.basic', function () { +// return Auth::basic(); }); /* @@ -55,9 +51,8 @@ Route::filter('auth.basic', function() | */ -Route::filter('guest', function() -{ -// if (Auth::check()) return Redirect::to('/'); +Route::filter('guest', function () { +// if (Auth::check()) return Redirect::to('/'); }); /* @@ -71,10 +66,8 @@ Route::filter('guest', function() | */ -Route::filter('csrf', function() -{ - if (Session::token() != Input::get('_token')) - { - throw new Illuminate\Session\TokenMismatchException; - } -}); \ No newline at end of file +Route::filter('csrf', function () { + if (Session::token() != Input::get('_token')) { + throw new Illuminate\Session\TokenMismatchException; + } +}); diff --git a/app/start/artisan.php b/app/start/artisan.php index 1df850bc9..409e9adb6 100644 --- a/app/start/artisan.php +++ b/app/start/artisan.php @@ -10,4 +10,3 @@ | the console gets access to each of the command object instances. | */ - diff --git a/app/start/global.php b/app/start/global.php index 1241255d8..554c0a6ac 100644 --- a/app/start/global.php +++ b/app/start/global.php @@ -46,8 +46,7 @@ Log::useFiles(storage_path().'/logs/system.log'); | */ -App::error(function(Exception $exception, $code) -{ +App::error(function (Exception $exception, $code) { /* * October uses a custom error handler, see * System\Classes\ErrorHandler::handleException @@ -65,8 +64,7 @@ App::error(function(Exception $exception, $code) | */ -App::down(function() -{ +App::down(function () { return Response::make("Be right back!", 503); }); @@ -81,4 +79,4 @@ App::down(function() | */ -require app_path().'/filters.php'; \ No newline at end of file +require app_path().'/filters.php'; From bf515bfa9ad54321bbcfcf467793770913fabf78 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Fri, 10 Oct 2014 21:58:29 +0200 Subject: [PATCH 02/30] Updating bootstrap folder to PSR-2 --- bootstrap/autoload.php | 5 +-- bootstrap/paths.php | 88 +++++++++++++++++++++--------------------- bootstrap/start.php | 18 ++++----- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php index 88c8dc8ec..739a31813 100644 --- a/bootstrap/autoload.php +++ b/bootstrap/autoload.php @@ -27,9 +27,8 @@ require __DIR__.'/../vendor/autoload.php'; | */ -if (file_exists($compiled = __DIR__.'/compiled.php')) -{ - require $compiled; +if (file_exists($compiled = __DIR__.'/compiled.php')) { + require $compiled; } /* diff --git a/bootstrap/paths.php b/bootstrap/paths.php index 010e8b60c..6e2e2154d 100644 --- a/bootstrap/paths.php +++ b/bootstrap/paths.php @@ -2,56 +2,56 @@ return array( - /* - |-------------------------------------------------------------------------- - | Application Path - |-------------------------------------------------------------------------- - | - | Here we just defined the path to the application directory. Most likely - | you will never need to change this value as the default setup should - | work perfectly fine for the vast majority of all our applications. - | - */ + /* + |-------------------------------------------------------------------------- + | Application Path + |-------------------------------------------------------------------------- + | + | Here we just defined the path to the application directory. Most likely + | you will never need to change this value as the default setup should + | work perfectly fine for the vast majority of all our applications. + | + */ - 'app' => __DIR__.'/../app', + 'app' => __DIR__.'/../app', - /* - |-------------------------------------------------------------------------- - | Public Path - |-------------------------------------------------------------------------- - | - | The public path contains the assets for your web application, such as - | your JavaScript and CSS files, and also contains the primary entry - | point for web requests into these applications from the outside. - | - */ + /* + |-------------------------------------------------------------------------- + | Public Path + |-------------------------------------------------------------------------- + | + | The public path contains the assets for your web application, such as + | your JavaScript and CSS files, and also contains the primary entry + | point for web requests into these applications from the outside. + | + */ - 'public' => __DIR__.'/..', + 'public' => __DIR__.'/..', - /* - |-------------------------------------------------------------------------- - | Base Path - |-------------------------------------------------------------------------- - | - | The base path is the root of the Laravel installation. Most likely you - | will not need to change this value. But, if for some wild reason it - | is necessary you will do so here, just proceed with some caution. - | - */ + /* + |-------------------------------------------------------------------------- + | Base Path + |-------------------------------------------------------------------------- + | + | The base path is the root of the Laravel installation. Most likely you + | will not need to change this value. But, if for some wild reason it + | is necessary you will do so here, just proceed with some caution. + | + */ - 'base' => __DIR__.'/..', + 'base' => __DIR__.'/..', - /* - |-------------------------------------------------------------------------- - | Storage Path - |-------------------------------------------------------------------------- - | - | The storage path is used by Laravel to store cached Blade views, logs - | and other pieces of information. You may modify the path here when - | you want to change the location of this directory for your apps. - | - */ + /* + |-------------------------------------------------------------------------- + | Storage Path + |-------------------------------------------------------------------------- + | + | The storage path is used by Laravel to store cached Blade views, logs + | and other pieces of information. You may modify the path here when + | you want to change the location of this directory for your apps. + | + */ - 'storage' => __DIR__.'/../app/storage', + 'storage' => __DIR__.'/../app/storage', ); diff --git a/bootstrap/start.php b/bootstrap/start.php index 37b7e7d9a..b26e4d01a 100644 --- a/bootstrap/start.php +++ b/bootstrap/start.php @@ -24,8 +24,8 @@ $app = new Illuminate\Foundation\Application; | */ -$env = $app->detectEnvironment(function(){ - return isset($_SERVER['CMS_ENV']) ? $_SERVER['CMS_ENV'] : 'production'; +$env = $app->detectEnvironment(function () { + return isset($_SERVER['CMS_ENV']) ? $_SERVER['CMS_ENV'] : 'production'; }); /* @@ -63,13 +63,13 @@ require $framework.'/Illuminate/Foundation/start.php'; */ if (!isset($unitTesting) || !$unitTesting) { - header('Cache-Control: no-store, private, no-cache, must-revalidate'); // HTTP/1.1 - header('Cache-Control: pre-check=0, post-check=0, max-age=0, max-stale = 0', false); // HTTP/1.1 - header('Pragma: public'); - header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past - header('Expires: 0', false); - header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); - header('Pragma: no-cache'); + header('Cache-Control: no-store, private, no-cache, must-revalidate'); // HTTP/1.1 + header('Cache-Control: pre-check=0, post-check=0, max-age=0, max-stale = 0', false); // HTTP/1.1 + header('Pragma: public'); + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past + header('Expires: 0', false); + header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + header('Pragma: no-cache'); } /* From d2d9f89117e3a2e9f16c4e9346e5872adfce42bd Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Fri, 10 Oct 2014 22:06:55 +0200 Subject: [PATCH 03/30] Removing extra blank lines --- bootstrap/autoload.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/bootstrap/autoload.php b/bootstrap/autoload.php index 739a31813..085e654fd 100644 --- a/bootstrap/autoload.php +++ b/bootstrap/autoload.php @@ -68,5 +68,3 @@ October\Rain\Support\ClassLoader::addDirectories(array(__DIR__.'/../modules', __ */ Illuminate\Support\ClassLoader::register(); - - From b01d3e540f0f336a534ccb4e6078bb4dfd284647 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Fri, 10 Oct 2014 22:34:57 +0200 Subject: [PATCH 04/30] Updating backend/behaviours --- modules/backend/behaviors/FormController.php | 125 +++++++++++----- modules/backend/behaviors/ListController.php | 112 ++++++++++----- .../backend/behaviors/RelationController.php | 136 +++++++++++------- .../behaviors/UserPreferencesModel.php | 16 ++- 4 files changed, 260 insertions(+), 129 deletions(-) diff --git a/modules/backend/behaviors/FormController.php b/modules/backend/behaviors/FormController.php index e87683a2c..d03fbe204 100644 --- a/modules/backend/behaviors/FormController.php +++ b/modules/backend/behaviors/FormController.php @@ -84,19 +84,19 @@ class FormController extends ControllerBehavior */ $this->formWidget = $this->makeWidget('Backend\Widgets\Form', $config); - $this->formWidget->bindEvent('form.extendFieldsBefore', function() { + $this->formWidget->bindEvent('form.extendFieldsBefore', function () { $this->controller->formExtendFieldsBefore($this->formWidget); }); - $this->formWidget->bindEvent('form.extendFields', function() { + $this->formWidget->bindEvent('form.extendFields', function () { $this->controller->formExtendFields($this->formWidget); }); - $this->formWidget->bindEvent('form.beforeRefresh', function($saveData) { + $this->formWidget->bindEvent('form.beforeRefresh', function ($saveData) { return $this->controller->formExtendRefreshData($this->formWidget, $saveData); }); - $this->formWidget->bindEvent('form.refresh', function($result) { + $this->formWidget->bindEvent('form.refresh', function ($result) { return $this->controller->formExtendRefreshResults($this->formWidget, $result); }); @@ -105,8 +105,9 @@ class FormController extends ControllerBehavior /* * Detected Relation controller behavior */ - if ($this->controller->isClassExtendedWith('Backend.Behaviors.RelationController')) + if ($this->controller->isClassExtendedWith('Backend.Behaviors.RelationController')) { $this->controller->initRelation($model); + } } // @@ -122,13 +123,15 @@ class FormController extends ControllerBehavior { try { $this->context = strlen($context) ? $context : $this->getConfig('create[context]', 'create'); - $this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang('create[title]', 'backend::lang.form.create_title'); + $this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang( + 'create[title]', + 'backend::lang.form.create_title' + ); $model = $this->controller->formCreateModelObject(); $this->initForm($model); $this->controller->vars['formModel'] = $model; - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->controller->handleError($ex); } } @@ -156,8 +159,9 @@ class FormController extends ControllerBehavior Flash::success($this->getLang('create[flashSave]', 'backend::lang.form.create_success')); - if ($redirect = $this->makeRedirect('create', $model)) + if ($redirect = $this->makeRedirect('create', $model)) { return $redirect; + } } // @@ -174,13 +178,15 @@ class FormController extends ControllerBehavior { try { $this->context = strlen($context) ? $context : $this->getConfig('update[context]', 'update'); - $this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang('update[title]', 'backend::lang.form.update_title'); + $this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang( + 'update[title]', + 'backend::lang.form.update_title' + ); $model = $this->controller->formFindModelObject($recordId); $this->initForm($model); $this->controller->vars['formModel'] = $model; - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->controller->handleError($ex); } } @@ -209,8 +215,9 @@ class FormController extends ControllerBehavior Flash::success($this->getLang('update[flashSave]', 'backend::lang.form.update_success')); - if ($redirect = $this->makeRedirect('update', $model)) + if ($redirect = $this->makeRedirect('update', $model)) { return $redirect; + } } /** @@ -230,8 +237,9 @@ class FormController extends ControllerBehavior Flash::success($this->getLang('update[flashDelete]', 'backend::lang.form.delete_success')); - if ($redirect = $this->makeRedirect('delete', $model)) + if ($redirect = $this->makeRedirect('delete', $model)) { return $redirect; + } } // @@ -248,13 +256,15 @@ class FormController extends ControllerBehavior { try { $this->context = strlen($context) ? $context : $this->getConfig('preview[context]', 'preview'); - $this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang('preview[title]', 'backend::lang.form.preview_title'); + $this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang( + 'preview[title]', + 'backend::lang.form.preview_title' + ); $model = $this->controller->formFindModelObject($recordId); $this->initForm($model); $this->controller->vars['formModel'] = $model; - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->controller->handleError($ex); } } @@ -270,8 +280,9 @@ class FormController extends ControllerBehavior */ public function formRender($options = []) { - if (!$this->formWidget) + if (!$this->formWidget) { throw new ApplicationException(Lang::get('backend::lang.form.behavior_not_ready')); + } return $this->formWidget->render($options); } @@ -307,14 +318,17 @@ class FormController extends ControllerBehavior public function makeRedirect($context = null, $model = null) { $redirectUrl = null; - if (post('close') && !ends_with($context, '-close')) + if (post('close') && !ends_with($context, '-close')) { $context .= '-close'; + } - if (post('redirect', true)) + if (post('redirect', true)) { $redirectUrl = Backend::url($this->getRedirectUrl($context)); + } - if ($model && $redirectUrl) + if ($model && $redirectUrl) { $redirectUrl = RouterHelper::parseValues($model, array_keys($model->getAttributes()), $redirectUrl); + } return ($redirectUrl) ? Redirect::to($redirectUrl) : null; } @@ -336,8 +350,9 @@ class FormController extends ControllerBehavior 'preview' => $this->getConfig('preview[redirect]', ''), ]; - if (!isset($redirects[$context])) + if (!isset($redirects[$context])) { return $redirects['default']; + } return $redirects[$context]; } @@ -444,43 +459,57 @@ class FormController extends ControllerBehavior * Called before the creation or updating form is saved. * @param Model */ - public function formBeforeSave($model) {} + public function formBeforeSave($model) + { + } /** * Called after the creation or updating form is saved. * @param Model */ - public function formAfterSave($model) {} + public function formAfterSave($model) + { + } /** * Called before the creation form is saved. * @param Model */ - public function formBeforeCreate($model) {} + public function formBeforeCreate($model) + { + } /** * Called after the creation form is saved. * @param Model */ - public function formAfterCreate($model) {} + public function formAfterCreate($model) + { + } /** * Called before the updating form is saved. * @param Model */ - public function formBeforeUpdate($model) {} + public function formBeforeUpdate($model) + { + } /** * Called after the updating form is saved. * @param Model */ - public function formAfterUpdate($model) {} + public function formAfterUpdate($model) + { + } /** * Called after the form model is deleted. * @param Model */ - public function formAfterDelete($model) {} + public function formAfterDelete($model) + { + } /** @@ -528,14 +557,18 @@ class FormController extends ControllerBehavior * @param Backend\Widgets\Form $host The hosting form widget * @return void */ - public function formExtendFieldsBefore($host) {} + public function formExtendFieldsBefore($host) + { + } /** * Called after the form fields are defined. * @param Backend\Widgets\Form $host The hosting form widget * @return void */ - public function formExtendFields($host) {} + public function formExtendFields($host) + { + } /** * Called before the form is refreshed, should return an array of additional save data. @@ -543,7 +576,9 @@ class FormController extends ControllerBehavior * @param array $saveData Current save data * @return array */ - public function formExtendRefreshData($host, $saveData) {} + public function formExtendRefreshData($host, $saveData) + { + } /** * Called after the form is refreshed, should return an array of additional result parameters. @@ -551,7 +586,9 @@ class FormController extends ControllerBehavior * @param array $result Current result parameters. * @return array */ - public function formExtendRefreshResults($host, $result) {} + public function formExtendRefreshResults($host, $result) + { + } /** * Extend supplied model used by create and update actions, the model can @@ -570,7 +607,9 @@ class FormController extends ControllerBehavior * @param October\Rain\Database\Builder $query * @return void */ - public function formExtendQuery($query) {} + public function formExtendQuery($query) + { + } /** * Static helper for extending form fields. @@ -580,8 +619,10 @@ class FormController extends ControllerBehavior public static function extendFormFields($callback) { $calledClass = self::getCalledExtensionClass(); - Event::listen('backend.form.extendFields', function($widget) use ($calledClass, $callback) { - if (!is_a($widget->getController(), $calledClass)) return; + Event::listen('backend.form.extendFields', function ($widget) use ($calledClass, $callback) { + if (!is_a($widget->getController(), $calledClass)) { + return; + } $callback($widget, $widget->model, $widget->getContext()); }); } @@ -607,15 +648,21 @@ class FormController extends ControllerBehavior { $this->modelsToSave[] = $model; - if (!is_array($saveData)) + if (!is_array($saveData)) { return; + } $singularTypes = ['belongsTo', 'hasOne', 'morphOne']; foreach ($saveData as $attribute => $value) { - if (is_array($value) && $model->hasRelation($attribute) && in_array($model->getRelationType($attribute), $singularTypes)) + if ( + is_array($value) && + $model->hasRelation($attribute) && + in_array($model->getRelationType($attribute), $singularTypes) + ) { $this->setModelAttributes($model->{$attribute}, $value); - else + } else { $model->{$attribute} = $value; + } } } } diff --git a/modules/backend/behaviors/ListController.php b/modules/backend/behaviors/ListController.php index 608d166dc..36ab6823f 100644 --- a/modules/backend/behaviors/ListController.php +++ b/modules/backend/behaviors/ListController.php @@ -68,8 +68,7 @@ class ListController extends ControllerBehavior if (is_array($controller->listConfig)) { $this->listDefinitions = $controller->listConfig; $this->primaryDefinition = key($this->listDefinitions); - } - else { + } else { $this->listDefinitions = ['list' => $controller->listConfig]; $this->primaryDefinition = 'list'; } @@ -99,8 +98,9 @@ class ListController extends ControllerBehavior */ public function makeList($definition = null) { - if (!$definition || !isset($this->listDefinitions[$definition])) + if (!$definition || !isset($this->listDefinitions[$definition])) { $definition = $this->primaryDefinition; + } $listConfig = $this->makeConfig($this->listDefinitions[$definition], $this->requiredConfig); @@ -117,39 +117,59 @@ class ListController extends ControllerBehavior $columnConfig = $this->makeConfig($listConfig->list); $columnConfig->model = $model; $columnConfig->alias = $definition; - if (isset($listConfig->recordUrl)) $columnConfig->recordUrl = $listConfig->recordUrl; - if (isset($listConfig->recordOnClick)) $columnConfig->recordOnClick = $listConfig->recordOnClick; - if (isset($listConfig->recordsPerPage)) $columnConfig->recordsPerPage = $listConfig->recordsPerPage; - if (isset($listConfig->noRecordsMessage)) $columnConfig->noRecordsMessage = $listConfig->noRecordsMessage; - if (isset($listConfig->defaultSort)) $columnConfig->defaultSort = $listConfig->defaultSort; - if (isset($listConfig->showSorting)) $columnConfig->showSorting = $listConfig->showSorting; - if (isset($listConfig->showSetup)) $columnConfig->showSetup = $listConfig->showSetup; - if (isset($listConfig->showCheckboxes)) $columnConfig->showCheckboxes = $listConfig->showCheckboxes; - if (isset($listConfig->showTree)) $columnConfig->showTree = $listConfig->showTree; - if (isset($listConfig->treeExpanded)) $columnConfig->treeExpanded = $listConfig->treeExpanded; + if (isset($listConfig->recordUrl)) { + $columnConfig->recordUrl = $listConfig->recordUrl; + } + if (isset($listConfig->recordOnClick)) { + $columnConfig->recordOnClick = $listConfig->recordOnClick; + } + if (isset($listConfig->recordsPerPage)) { + $columnConfig->recordsPerPage = $listConfig->recordsPerPage; + } + if (isset($listConfig->noRecordsMessage)) { + $columnConfig->noRecordsMessage = $listConfig->noRecordsMessage; + } + if (isset($listConfig->defaultSort)) { + $columnConfig->defaultSort = $listConfig->defaultSort; + } + if (isset($listConfig->showSorting)) { + $columnConfig->showSorting = $listConfig->showSorting; + } + if (isset($listConfig->showSetup)) { + $columnConfig->showSetup = $listConfig->showSetup; + } + if (isset($listConfig->showCheckboxes)) { + $columnConfig->showCheckboxes = $listConfig->showCheckboxes; + } + if (isset($listConfig->showTree)) { + $columnConfig->showTree = $listConfig->showTree; + } + if (isset($listConfig->treeExpanded)) { + $columnConfig->treeExpanded = $listConfig->treeExpanded; + } $widget = $this->makeWidget('Backend\Widgets\Lists', $columnConfig); $widget->bindToController(); /* * Extensibility helpers */ - $widget->bindEvent('list.extendQueryBefore', function($query) use ($definition) { + $widget->bindEvent('list.extendQueryBefore', function ($query) use ($definition) { $this->controller->listExtendQueryBefore($query, $definition); }); - $widget->bindEvent('list.extendQuery', function($query) use ($definition) { + $widget->bindEvent('list.extendQuery', function ($query) use ($definition) { $this->controller->listExtendQuery($query, $definition); }); - $widget->bindEvent('list.injectRowClass', function($record) use ($definition) { + $widget->bindEvent('list.injectRowClass', function ($record) use ($definition) { return $this->controller->listInjectRowClass($record, $definition); }); - $widget->bindEvent('list.overrideColumnValue', function($record, $column, $value) use ($definition) { + $widget->bindEvent('list.overrideColumnValue', function ($record, $column, $value) use ($definition) { return $this->controller->listOverrideColumnValue($record, $column->columnName, $definition); }); - $widget->bindEvent('list.overrideHeaderValue', function($column, $value) use ($definition) { + $widget->bindEvent('list.overrideHeaderValue', function ($column, $value) use ($definition) { return $this->controller->listOverrideHeaderValue($column->columnName, $definition); }); @@ -167,7 +187,7 @@ class ListController extends ControllerBehavior * Link the Search Widget to the List Widget */ if ($searchWidget = $toolbarWidget->getSearchWidget()) { - $searchWidget->bindEvent('search.submit', function() use ($widget, $searchWidget) { + $searchWidget->bindEvent('search.submit', function () use ($widget, $searchWidget) { $widget->setSearchTerm($searchWidget->getActiveTerm()); return $widget->onRefresh(); }); @@ -193,7 +213,7 @@ class ListController extends ControllerBehavior /* * Filter the list when the scopes are changed */ - $filterWidget->bindEvent('filter.update', function() use ($widget, $filterWidget){ + $filterWidget->bindEvent('filter.update', function () use ($widget, $filterWidget) { $widget->addFilter([$filterWidget, 'applyAllScopesToQuery']); return $widget->onRefresh(); }); @@ -213,7 +233,10 @@ class ListController extends ControllerBehavior */ public function index() { - $this->controller->pageTitle = $this->controller->pageTitle ?: trans($this->getConfig('title', 'backend::lang.list.default_title')); + $this->controller->pageTitle = $this->controller->pageTitle ?: trans($this->getConfig( + 'title', + 'backend::lang.list.default_title' + )); $this->controller->bodyClass = 'slim-container'; $this->makeLists(); } @@ -225,19 +248,23 @@ class ListController extends ControllerBehavior */ public function listRender($definition = null) { - if (!count($this->listWidgets)) + if (!count($this->listWidgets)) { throw new SystemException(Lang::get('backend::lang.list.behavior_not_ready')); + } - if (!$definition || !isset($this->listDefinitions[$definition])) + if (!$definition || !isset($this->listDefinitions[$definition])) { $definition = $this->primaryDefinition; + } $collection = []; - if (isset($this->toolbarWidgets[$definition])) + if (isset($this->toolbarWidgets[$definition])) { $collection[] = $this->toolbarWidgets[$definition]->render(); + } - if (isset($this->filterWidgets[$definition])) + if (isset($this->filterWidgets[$definition])) { $collection[] = $this->filterWidgets[$definition]->render(); + } $collection[] = $this->listWidgets[$definition]->render(); @@ -251,11 +278,13 @@ class ListController extends ControllerBehavior */ public function listRefresh($definition = null) { - if (!count($this->listWidgets)) + if (!count($this->listWidgets)) { $this->makeLists(); + } - if (!$definition || !isset($this->listDefinitions[$definition])) + if (!$definition || !isset($this->listDefinitions[$definition])) { $definition = $this->primaryDefinition; + } return $this->listWidgets[$definition]->onRefresh(); } @@ -279,14 +308,18 @@ class ListController extends ControllerBehavior * before the default query is processed. * @param October\Rain\Database\Builder $query */ - public function listExtendQueryBefore($query, $definition = null) {} + public function listExtendQueryBefore($query, $definition = null) + { + } /** * Controller override: Extend the query used for populating the list * after the default query is processed. * @param October\Rain\Database\Builder $query */ - public function listExtendQuery($query, $definition = null) {} + public function listExtendQuery($query, $definition = null) + { + } /** * Returns a CSS class name for a list row (). @@ -294,7 +327,9 @@ class ListController extends ControllerBehavior * @param string $definition List definition (optional) * @return string HTML view */ - public function listInjectRowClass($record, $definition = null) {} + public function listInjectRowClass($record, $definition = null) + { + } /** * Replace a table column value (...) @@ -303,7 +338,9 @@ class ListController extends ControllerBehavior * @param string $definition List definition (optional) * @return string HTML view */ - public function listOverrideColumnValue($record, $columnName, $definition = null) {} + public function listOverrideColumnValue($record, $columnName, $definition = null) + { + } /** * Replace the entire table header contents (...) with custom HTML @@ -311,7 +348,9 @@ class ListController extends ControllerBehavior * @param string $definition List definition (optional) * @return string HTML view */ - public function listOverrideHeaderValue($columnName, $definition = null) {} + public function listOverrideHeaderValue($columnName, $definition = null) + { + } /** * Static helper for extending form fields. @@ -321,10 +360,11 @@ class ListController extends ControllerBehavior public static function extendListColumns($callback) { $calledClass = self::getCalledExtensionClass(); - Event::listen('backend.list.extendColumns', function($widget) use ($calledClass, $callback) { - if (!is_a($widget->getController(), $calledClass)) return; + Event::listen('backend.list.extendColumns', function ($widget) use ($calledClass, $callback) { + if (!is_a($widget->getController(), $calledClass)) { + return; + } $callback($widget, $widget->model); }); } - -} \ No newline at end of file +} diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index a53fff7a5..15a768a27 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -158,24 +158,35 @@ class RelationController extends ControllerBehavior */ public function initRelation($model, $field = null) { - if ($field == null) + if ($field == null) { $field = post(self::PARAM_FIELD); + } $this->config = $this->originalConfig; $this->model = $model; $this->field = $field; - if ($field == null) + if ($field == null) { return; + } - if (!$this->model) - throw new ApplicationException(Lang::get('backend::lang.relation.missing_model', ['class'=>get_class($this->controller)])); + if (!$this->model) { + throw new ApplicationException(Lang::get( + 'backend::lang.relation.missing_model', + ['class'=>get_class($this->controller)] + )); + } - if (!$this->model instanceof Model) - throw new ApplicationException(Lang::get('backend::lang.model.invalid_class', ['model'=>get_class($this->model), 'class'=>get_class($this->controller)])); + if (!$this->model instanceof Model) { + throw new ApplicationException(Lang::get( + 'backend::lang.model.invalid_class', + ['model'=>get_class($this->model), 'class'=>get_class($this->controller)] + )); + } - if (!$this->getConfig($field)) + if (!$this->getConfig($field)) { throw new ApplicationException(Lang::get('backend::lang.relation.missing_definition', compact('field'))); + } $this->alias = camel_case('relation ' . $field); $this->config = $this->makeConfig($this->getConfig($field), $this->requiredRelationProperties); @@ -196,27 +207,31 @@ class RelationController extends ControllerBehavior /* * Toolbar widget */ - if ($this->toolbarWidget = $this->makeToolbarWidget()) + if ($this->toolbarWidget = $this->makeToolbarWidget()) { $this->toolbarWidget->bindToController(); + } /* * View widget */ - if ($this->viewWidget = $this->makeViewWidget()) + if ($this->viewWidget = $this->makeViewWidget()) { $this->viewWidget->bindToController(); + } /* * Manage widget */ - if ($this->manageWidget = $this->makeManageWidget()) + if ($this->manageWidget = $this->makeManageWidget()) { $this->manageWidget->bindToController(); + } /* * Pivot widget */ if ($this->manageMode == 'pivot') { - if ($this->pivotWidget = $this->makePivotWidget()) + if ($this->pivotWidget = $this->makePivotWidget()) { $this->pivotWidget->bindToController(); + } } } @@ -268,15 +283,18 @@ class RelationController extends ControllerBehavior { $field = $this->validateField($field); - if (is_string($options)) $options = ['sessionKey' => $options]; + if (is_string($options)) { + $options = ['sessionKey' => $options]; + } $this->prepareVars(); /* * Session key */ - if (isset($options['sessionKey'])) + if (isset($options['sessionKey'])) { $this->sessionKey = $options['sessionKey']; + } /* * Determine the partial to use based on the supplied section option @@ -334,11 +352,13 @@ class RelationController extends ControllerBehavior { $field = $field ?: post(self::PARAM_FIELD); - if ($field && $field != $this->field) + if ($field && $field != $this->field) { $this->initRelation($this->model, $field); + } - if (!$field && !$this->field) + if (!$field && !$this->field) { throw new ApplicationException(Lang::get('backend::lang.relation.missing_definition', compact('field'))); + } return $field ?: $this->field; } @@ -368,8 +388,9 @@ class RelationController extends ControllerBehavior */ protected function beforeAjax() { - if ($this->initialized) + if ($this->initialized) { return; + } $this->controller->pageAction(); $this->validateField(); @@ -386,8 +407,9 @@ class RelationController extends ControllerBehavior public function relationMakePartial($partial, $params = []) { $contents = $this->controller->makePartial('relation_'.$partial, $params + $this->vars, false); - if (!$contents) + if (!$contents) { $contents = $this->makePartial($partial, $params); + } return $contents; } @@ -400,11 +422,13 @@ class RelationController extends ControllerBehavior public function relationGetId($suffix = null) { $id = class_basename($this); - if ($this->field) + if ($this->field) { $id .= '-' . $this->field; + } - if ($suffix !== null) + if ($suffix !== null) { $id .= '-' . $suffix; + } return $this->controller->getId($id); } @@ -420,8 +444,9 @@ class RelationController extends ControllerBehavior ->getBaseQuery() ->select($foreignKeyName); - if ($checkIds !== null && is_array($checkIds) && count($checkIds)) + if ($checkIds !== null && is_array($checkIds) && count($checkIds)) { $results = $results->whereIn($foreignKeyName, $checkIds); + } return $results->lists($foreignKeyName); } @@ -434,8 +459,9 @@ class RelationController extends ControllerBehavior { $this->beforeAjax(); - if ($this->manageMode == 'pivot' && $this->manageId) + if ($this->manageMode == 'pivot' && $this->manageId) { return $this->onRelationManagePivotForm(); + } // The form should not share its session key with the parent $this->vars['newSessionKey'] = str_random(40); @@ -480,8 +506,9 @@ class RelationController extends ControllerBehavior if (($checkedIds = post('checked')) && is_array($checkedIds)) { foreach ($checkedIds as $relationId) { - if (!$obj = $this->relationObject->find($relationId)) + if (!$obj = $this->relationObject->find($relationId)) { continue; + } $obj->delete(); } @@ -497,8 +524,9 @@ class RelationController extends ControllerBehavior { $this->beforeAjax(); - if ($this->viewMode != 'multi') + if ($this->viewMode != 'multi') { throw new ApplicationException(Lang::get('backend::lang.relation.invalid_action_single')); + } if (($checkedIds = post('checked')) && is_array($checkedIds)) { /* @@ -511,10 +539,11 @@ class RelationController extends ControllerBehavior $models = $this->relationModel->whereIn($foreignKeyName, $checkedIds)->get(); foreach ($models as $model) { - if ($this->model->exists) + if ($this->model->exists) { $this->relationObject->add($model); - else + } else { $this->relationObject->add($model, $this->relationGetSessionKey()); + } } } @@ -528,8 +557,9 @@ class RelationController extends ControllerBehavior { $this->beforeAjax(); - if ($this->viewMode != 'multi') + if ($this->viewMode != 'multi') { throw new ApplicationException(Lang::get('backend::lang.relation.invalid_action_single')); + } if (($checkedIds = post('checked')) && is_array($checkedIds)) { $this->relationObject->detach($checkedIds); @@ -560,8 +590,9 @@ class RelationController extends ControllerBehavior $foreignKeyName = $this->relationModel->getKeyName(); $existing = $this->relationObject->where($foreignKeyName, $foreignId)->count(); - if (!$existing) + if (!$existing) { $this->relationObject->add($foreignModel, null, $saveData); + } return ['#'.$this->relationGetId('view') => $this->relationRenderView()]; } @@ -593,8 +624,9 @@ class RelationController extends ControllerBehavior protected function makeToolbarWidget() { - if ($this->readOnly) + if ($this->readOnly) { return; + } $defaultConfig = [ 'buttons' => '@/modules/backend/behaviors/relationcontroller/partials/_toolbar.htm', @@ -631,18 +663,23 @@ class RelationController extends ControllerBehavior $config->recordsPerPage = $this->getConfig('view[recordsPerPage]'); if (!$this->readOnly) { - $config->recordOnClick = sprintf("$.oc.relationBehavior.clickManageListRecord(:id, '%s', '%s')", $this->field, $this->relationGetSessionKey()); + $config->recordOnClick = sprintf( + "$.oc.relationBehavior.clickManageListRecord(:id, '%s', '%s')", + $this->field, + $this->relationGetSessionKey() + ); $config->showCheckboxes = true; } - if ($emptyMessage = $this->getConfig('emptyMessage')) + if ($emptyMessage = $this->getConfig('emptyMessage')) { $config->noRecordsMessage = $emptyMessage; + } /* * Constrain the query by the relationship and deferred items */ $widget = $this->makeWidget('Backend\Widgets\Lists', $config); - $widget->bindEvent('list.extendQuery', function($query) { + $widget->bindEvent('list.extendQuery', function ($query) { $this->relationObject->setQuery($query); if ($this->model->exists) { $this->relationObject->addConstraints(); @@ -657,7 +694,7 @@ class RelationController extends ControllerBehavior */ if ($this->toolbarWidget && $this->getConfig('view[showSearch]')) { if ($searchWidget = $this->toolbarWidget->getSearchWidget()) { - $searchWidget->bindEvent('search.submit', function() use ($widget, $searchWidget) { + $searchWidget->bindEvent('search.submit', function () use ($widget, $searchWidget) { $widget->setSearchTerm($searchWidget->getActiveTerm()); return $widget->onRefresh(); }); @@ -665,11 +702,10 @@ class RelationController extends ControllerBehavior $searchWidget->setActiveTerm(null); } } - } /* * Single (belongs to, has one) */ - elseif ($this->viewMode == 'single') { + } elseif ($this->viewMode == 'single') { $config = $this->makeConfig($this->config->form); $config->model = $this->relationModel; $config->arrayName = class_basename($this->relationModel); @@ -693,13 +729,16 @@ class RelationController extends ControllerBehavior $config->model = $this->relationModel; $config->alias = $this->alias . 'ManagePivotList'; $config->showSetup = false; - $config->recordOnClick = sprintf("$.oc.relationBehavior.clickManagePivotListRecord(:id, '%s', '%s')", $this->field, $this->relationGetSessionKey()); + $config->recordOnClick = sprintf( + "$.oc.relationBehavior.clickManagePivotListRecord(:id, '%s', '%s')", + $this->field, + $this->relationGetSessionKey() + ); $widget = $this->makeWidget('Backend\Widgets\Lists', $config); - } /* * List */ - elseif ($this->manageMode == 'list' && isset($this->config->list)) { + } elseif ($this->manageMode == 'list' && isset($this->config->list)) { $config = $this->makeConfig($this->config->list); $config->model = $this->relationModel; $config->alias = $this->alias . 'ManageList'; @@ -716,19 +755,17 @@ class RelationController extends ControllerBehavior if ($this->getConfig('manage[showSearch]')) { $this->searchWidget = $this->makeSearchWidget(); $this->searchWidget->bindToController(); - $this->searchWidget->bindEvent('search.submit', function() use ($widget) { + $this->searchWidget->bindEvent('search.submit', function () use ($widget) { $widget->setSearchTerm($this->searchWidget->getActiveTerm()); return $widget->onRefresh(); }); $this->searchWidget->setActiveTerm(null); } - - } /* * Form */ - elseif ($this->manageMode == 'form' && isset($this->config->form)) { + } elseif ($this->manageMode == 'form' && isset($this->config->form)) { $config = $this->makeConfig($this->config->form); $config->model = $this->relationModel; $config->arrayName = class_basename($this->relationModel); @@ -750,14 +787,15 @@ class RelationController extends ControllerBehavior $widget = $this->makeWidget('Backend\Widgets\Form', $config); } - if (!$widget) + if (!$widget) { return null; + } /* * Exclude existing relationships */ if ($this->manageMode == 'pivot' || $this->manageMode == 'list') { - $widget->bindEvent('list.extendQuery', function($query) { + $widget->bindEvent('list.extendQuery', function ($query) { /* * Where not in the current list of related records @@ -806,16 +844,18 @@ class RelationController extends ControllerBehavior */ public function relationGetSessionKey($force = false) { - if ($this->sessionKey && !$force) + if ($this->sessionKey && !$force) { return $this->sessionKey; + } - if (post('_relation_session_key')) + if (post('_relation_session_key')) { return $this->sessionKey = post('_relation_session_key'); + } - if (post('_session_key')) + if (post('_session_key')) { return $this->sessionKey = post('_session_key'); + } return $this->sessionKey = FormHelper::getSessionKey(); } - -} \ No newline at end of file +} diff --git a/modules/backend/behaviors/UserPreferencesModel.php b/modules/backend/behaviors/UserPreferencesModel.php index c88e61afa..6fcf861d9 100644 --- a/modules/backend/behaviors/UserPreferencesModel.php +++ b/modules/backend/behaviors/UserPreferencesModel.php @@ -35,8 +35,9 @@ class UserPreferencesModel extends SettingsModel */ public function instance() { - if (isset(self::$instances[$this->recordCode])) + if (isset(self::$instances[$this->recordCode])) { return self::$instances[$this->recordCode]; + } $item = UserPreferences::forUser(); $item = $item->scopeFindRecord($this->model, $this->recordCode, $item->userContext)->first(); @@ -44,10 +45,11 @@ class UserPreferencesModel extends SettingsModel if (!$item) { $this->model->initSettingsData(); - if (method_exists($this->model, 'forceSave')) + if (method_exists($this->model, 'forceSave')) { $this->model->forceSave(); - else + } else { $this->model->save(); + } $this->model->reload(); $item = $this->model; @@ -77,8 +79,9 @@ class UserPreferencesModel extends SettingsModel $this->model->namespace = $namespace; $this->model->user_id = $preferences->userContext->id; - if ($this->fieldValues) + if ($this->fieldValues) { $this->model->value = $this->fieldValues; + } } /** @@ -90,9 +93,10 @@ class UserPreferencesModel extends SettingsModel /* * Let the core columns through */ - if ($key == 'namespace' || $key == 'group') + if ($key == 'namespace' || $key == 'group') { return true; + } return parent::isKeyAllowed($key); } -} \ No newline at end of file +} From 7dc24cfff163ef981273268d61db4fe1f9618278 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Fri, 10 Oct 2014 23:12:50 +0200 Subject: [PATCH 05/30] Updating backend/classes --- modules/backend/classes/AuthManager.php | 22 +-- modules/backend/classes/BackendController.php | 24 ++- modules/backend/classes/BackendHelper.php | 6 +- modules/backend/classes/Controller.php | 140 +++++++++++------- .../backend/classes/ControllerBehavior.php | 16 +- modules/backend/classes/FilterScope.php | 50 +++++-- modules/backend/classes/FormField.php | 107 +++++++++---- modules/backend/classes/FormWidgetBase.php | 18 ++- modules/backend/classes/ListColumn.php | 44 ++++-- modules/backend/classes/NavigationManager.php | 59 +++++--- modules/backend/classes/ReportWidgetBase.php | 2 +- modules/backend/classes/Skin.php | 8 +- modules/backend/classes/WidgetBase.php | 48 ++++-- modules/backend/classes/WidgetManager.php | 29 ++-- 14 files changed, 383 insertions(+), 190 deletions(-) diff --git a/modules/backend/classes/AuthManager.php b/modules/backend/classes/AuthManager.php index 41b992f76..66f2645f6 100644 --- a/modules/backend/classes/AuthManager.php +++ b/modules/backend/classes/AuthManager.php @@ -78,12 +78,12 @@ class AuthManager extends RainAuthManager * @param string $owner Specifies the menu items owner plugin or module in the format Vendor/Module. * @param array $definitions An array of the menu item definitions. */ - public function registerPermissions($owner, array $definitions) + public function registerPermissions($owner, array $definitions) { - foreach ($definitions as $code=>$definition) { + foreach ($definitions as $code => $definition) { $permission = (object)array_merge(self::$permissionDefaults, array_merge($definition, [ - 'code'=>$code, - 'owner'=>$owner + 'code' => $code, + 'owner' => $owner ])); $this->permissions[] = $permission; @@ -96,8 +96,9 @@ class AuthManager extends RainAuthManager */ public function listPermissions() { - if ($this->permissionCache !== false) + if ($this->permissionCache !== false) { return $this->permissionCache; + } /* * Load module items @@ -113,8 +114,9 @@ class AuthManager extends RainAuthManager foreach ($plugins as $id => $plugin) { $items = $plugin->registerPermissions(); - if (!is_array($items)) + if (!is_array($items)) { continue; + } $this->registerPermissions($id, $items); } @@ -122,14 +124,14 @@ class AuthManager extends RainAuthManager /* * Sort permission items */ - usort($this->permissions, function($a, $b) { - if ($a->order == $b->order) + usort($this->permissions, function ($a, $b) { + if ($a->order == $b->order) { return 0; + } return $a->order > $b->order ? 1 : -1; }); return $this->permissionCache = $this->permissions; } - -} \ No newline at end of file +} diff --git a/modules/backend/classes/BackendController.php b/modules/backend/classes/BackendController.php index 03942a713..323a6cf2a 100644 --- a/modules/backend/classes/BackendController.php +++ b/modules/backend/classes/BackendController.php @@ -46,8 +46,9 @@ class BackendController extends ControllerBase self::$action = $action = isset($params[2]) ? $this->parseAction($params[2]) : 'index'; self::$params = $controllerParams = array_slice($params, 3); $controllerClass = '\\'.$module.'\Controllers\\'.$controller; - if ($controllerObj = $this->findController($controllerClass, $action, '/modules')) + if ($controllerObj = $this->findController($controllerClass, $action, '/modules')) { return $controllerObj->run($action, $controllerParams); + } /* * Look for a Plugin controller @@ -58,8 +59,13 @@ class BackendController extends ControllerBase self::$action = $action = isset($params[3]) ? $this->parseAction($params[3]) : 'index'; self::$params = $controllerParams = array_slice($params, 4); $controllerClass = '\\'.$author.'\\'.$plugin.'\Controllers\\'.$controller; - if ($controllerObj = $this->findController($controllerClass, $action, Config::get('cms.pluginsDir', '/plugins'))) + if ($controllerObj = $this->findController( + $controllerClass, + $action, + Config::get('cms.pluginsDir', '/plugins') + )) { return $controllerObj->run($action, $controllerParams); + } } /* @@ -83,17 +89,20 @@ class BackendController extends ControllerBase if (!class_exists($controller)) { $controller = Str::normalizeClassName($controller); $controllerFile = PATH_BASE.$dirPrefix.strtolower(str_replace('\\', '/', $controller)) . '.php'; - if ($controllerFile = File::existsInsensitive($controllerFile)) + if ($controllerFile = File::existsInsensitive($controllerFile)) { include_once($controllerFile); + } } - if (!class_exists($controller)) + if (!class_exists($controller)) { return false; + } $controllerObj = App::make($controller); - if ($controllerObj->actionExists($action)) + if ($controllerObj->actionExists($action)) { return $controllerObj; + } return false; } @@ -105,9 +114,10 @@ class BackendController extends ControllerBase */ protected function parseAction($actionName) { - if (strpos($actionName, '-') !== false) + if (strpos($actionName, '-') !== false) { return camel_case($actionName); + } return $actionName; } -} \ No newline at end of file +} diff --git a/modules/backend/classes/BackendHelper.php b/modules/backend/classes/BackendHelper.php index 60dfd700e..e48701bfe 100644 --- a/modules/backend/classes/BackendHelper.php +++ b/modules/backend/classes/BackendHelper.php @@ -40,11 +40,11 @@ class BackendHelper $backendUri = Config::get('cms.backendUri'); $baseUrl = Request::getBaseUrl(); - if ($path === null) + if ($path === null) { return $baseUrl . '/' . $backendUri; + } $path = RouterHelper::normalizeUrl($path); return $baseUrl . '/' . $backendUri . $path; } - -} \ No newline at end of file +} diff --git a/modules/backend/classes/Controller.php b/modules/backend/classes/Controller.php index 88d6557df..b95f7150c 100644 --- a/modules/backend/classes/Controller.php +++ b/modules/backend/classes/Controller.php @@ -94,7 +94,15 @@ class Controller extends Extendable /** * @var array Default methods which cannot be called as actions. */ - public $hiddenActions = ['run', 'actionExists', 'pageAction', 'getId', 'setStatusCode', 'handleError', 'makeHintPartial']; + public $hiddenActions = [ + 'run', + 'actionExists', + 'pageAction', + 'getId', + 'setStatusCode', + 'handleError', + 'makeHintPartial' + ]; /** * @var array Controller specified methods which cannot be called as actions. @@ -164,14 +172,16 @@ class Controller extends Extendable // Not logged in, redirect to login screen or show ajax error if (!BackendAuth::check()) { - return Request::ajax() + return Request::ajax() { ? Response::make(Lang::get('backend::lang.page.access_denied.label'), 403) : Redirect::guest(Backend::url('backend/auth')); + } } // Check his access groups against the page definition - if ($this->requiredPermissions && !$this->user->hasAnyAccess($this->requiredPermissions)) + if ($this->requiredPermissions && !$this->user->hasAnyAccess($this->requiredPermissions)) { return Response::make(View::make('backend::access_denied'), 403); + } } /* @@ -179,8 +189,7 @@ class Controller extends Extendable */ if (Session::has('locale')) { App::setLocale(Session::get('locale')); - } - elseif ($this->user && $locale = BackendPreferences::get('locale')) { + } elseif ($this->user && $locale = BackendPreferences::get('locale')) { Session::put('locale', $locale); App::setLocale($locale); } @@ -188,22 +197,29 @@ class Controller extends Extendable /* * Execute AJAX event */ - if ($ajaxResponse = $this->execAjaxHandlers()) + if ($ajaxResponse = $this->execAjaxHandlers()) { return $ajaxResponse; + } /* * Execute postback handler */ - if (($handler = post('_handler')) && ($handlerResponse = $this->runAjaxHandler($handler)) && $handlerResponse !== true) + if ( + ($handler = post('_handler')) && + ($handlerResponse = $this->runAjaxHandler($handler)) && + $handlerResponse !== true + ) { return $handlerResponse; + } /* * Execute page action */ $result = $this->execPageAction($action, $params); - if (!is_string($result)) + if (!is_string($result)) { return $result; + } return Response::make($result, $this->statusCode); } @@ -218,12 +234,14 @@ class Controller extends Extendable */ public function actionExists($name, $internal = false) { - if (!strlen($name) || substr($name, 0, 1) == '_' || !$this->methodExists($name)) + if (!strlen($name) || substr($name, 0, 1) == '_' || !$this->methodExists($name)) { return false; + } foreach ($this->hiddenActions as $method) { - if (strtolower($name) == strtolower($method)) + if (strtolower($name) == strtolower($method)) { return false; + } } $ownMethod = method_exists($this, $name); @@ -231,15 +249,18 @@ class Controller extends Extendable if ($ownMethod) { $methodInfo = new \ReflectionMethod($this, $name); $public = $methodInfo->isPublic(); - if ($public) + if ($public) { return true; + } } - if ($internal && (($ownMethod && $methodInfo->isProtected()) || !$ownMethod)) + if ($internal && (($ownMethod && $methodInfo->isProtected()) || !$ownMethod)) { return true; + } - if (!$ownMethod) + if (!$ownMethod) { return true; + } return false; } @@ -250,8 +271,9 @@ class Controller extends Extendable */ public function pageAction() { - if (!$this->action) + if (!$this->action) { return; + } $this->suppressView = true; $this->execPageAction($this->action, $this->params); @@ -267,14 +289,20 @@ class Controller extends Extendable { $result = null; - if (!$this->actionExists($actionName)) - throw new SystemException(sprintf("Action %s is not found in the controller %s", $actionName, get_class($this))); + if (!$this->actionExists($actionName)) { + throw new SystemException(sprintf( + "Action %s is not found in the controller %s", + $actionName, + get_class($this) + )); + } // Execute the action $result = call_user_func_array([$this, $actionName], $parameters); - if ($result instanceof RedirectResponse) + if ($result instanceof RedirectResponse) { return $result; + } // Translate the page title $this->pageTitle = $this->pageTitle @@ -282,8 +310,9 @@ class Controller extends Extendable : Lang::get('backend::lang.page.untitled'); // Load the view - if (!$this->suppressView && is_null($result)) + if (!$this->suppressView && is_null($result)) { return $this->makeView($actionName); + } return $this->makeViewContent($result); } @@ -299,8 +328,9 @@ class Controller extends Extendable /* * Validate the handler name */ - if (!preg_match('/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/', $handler)) + if (!preg_match('/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/', $handler)) { throw new SystemException(Lang::get('cms::lang.ajax_handler.invalid_name', ['name'=>$handler])); + } /* * Validate the handler partial list @@ -310,11 +340,14 @@ class Controller extends Extendable // @todo Do we need to validate backend partials? // foreach ($partialList as $partial) { - // if (!preg_match('/^(?:\w+\:{2}|@)?[a-z0-9\_\-\.\/]+$/i', $partial)) - // throw new SystemException(Lang::get('cms::lang.partial.invalid_name', ['name'=>$partial])); + // if (!preg_match('/^(?:\w+\:{2}|@)?[a-z0-9\_\-\.\/]+$/i', $partial)) { + // throw new SystemException(Lang::get( + // 'cms::lang.partial.invalid_name', + // ['name' => $partial] + // )); + // } // } - } - else { + } else { $partialList = []; } @@ -323,23 +356,26 @@ class Controller extends Extendable /* * Execute the handler */ - if (!$result = $this->runAjaxHandler($handler)) + if (!$result = $this->runAjaxHandler($handler)) { throw new ApplicationException(Lang::get('cms::lang.ajax_handler.not_found', ['name'=>$handler])); + } /* * If the handler returned an array, we should add it to output for rendering. * If it is a string, add it to the array with the key "result". */ - if (is_array($result)) + if (is_array($result)) { $responseContents = array_merge($responseContents, $result); - elseif (is_string($result)) + } elseif (is_string($result)) { $responseContents['result'] = $result; + } /* * Render partials and return the response as array that will be converted to JSON automatically. */ - foreach ($partialList as $partial) + foreach ($partialList as $partial) { $responseContents[$partial] = $this->makePartial($partial); + } /* * If the handler returned a redirect, process it so framework.js knows to redirect @@ -347,11 +383,10 @@ class Controller extends Extendable */ if ($result instanceof RedirectResponse) { $responseContents['X_OCTOBER_REDIRECT'] = $result->getTargetUrl(); - } /* * No redirect is used, look for any flash messages */ - else if (Flash::check()) { + } elseif (Flash::check()) { $responseContents['#layout-flash-messages'] = $this->makeLayoutPartial('flash_messages'); } @@ -363,8 +398,7 @@ class Controller extends Extendable } return Response::make()->setContent($responseContents); - } - catch (ValidationException $ex) { + } catch (ValidationException $ex) { /* * Handle validation error gracefully */ @@ -373,15 +407,18 @@ class Controller extends Extendable $responseContents['#layout-flash-messages'] = $this->makeLayoutPartial('flash_messages'); $responseContents['X_OCTOBER_ERROR_FIELDS'] = $ex->getFields(); return Response::make($responseContents, 406); - } - catch (MassAssignmentException $ex) { - return Response::make(Lang::get('backend::lang.model.mass_assignment_failed', ['attribute' => $ex->getMessage()]), 500); - } - catch (ApplicationException $ex) { + } catch (MassAssignmentException $ex) { + return Response::make( + Lang::get('backend::lang.model.mass_assignment_failed', ['attribute' => $ex->getMessage()]), + 500 + ); + } catch (ApplicationException $ex) { return Response::make($ex->getMessage(), 500); - } - catch (Exception $ex) { - return Response::make(sprintf('"%s" on line %s of %s', $ex->getMessage(), $ex->getLine(), $ex->getFile()), 500); + } catch (Exception $ex) { + return Response::make( + sprintf('"%s" on line %s of %s', $ex->getMessage(), $ex->getLine(), $ex->getFile()), + 500 + ); } } @@ -406,20 +443,21 @@ class Controller extends Extendable */ $this->pageAction(); - if ($this->fatalError) + if ($this->fatalError) { throw new SystemException($this->fatalError); + } - if (!isset($this->widget->{$widgetName})) + if (!isset($this->widget->{$widgetName})) { throw new SystemException(Lang::get('backend::lang.widget.not_bound', ['name'=>$widgetName])); + } if (($widget = $this->widget->{$widgetName}) && method_exists($widget, $handlerName)) { $result = call_user_func_array([$widget, $handlerName], $this->params); return ($result) ?: true; } - } - else { + } else { /* - * Process page specific handler (index_onSomething) + * Process page specific handler (index_onSomething) { */ $pageHandler = $this->action . '_' . $handler; @@ -429,7 +467,7 @@ class Controller extends Extendable } /* - * Process page global handler (onSomething) + * Process page global handler (onSomething) { */ if ($this->methodExists($handler)) { $result = call_user_func_array([$this, $handler], $this->params); @@ -459,8 +497,9 @@ class Controller extends Extendable public function getId($suffix = null) { $id = class_basename(get_called_class()) . '-' . $this->action; - if ($suffix !== null) + if ($suffix !== null) { $id .= '-' . $suffix; + } return $id; } @@ -498,8 +537,9 @@ class Controller extends Extendable */ public function makeHintPartial($name, $partial = null, array $params = []) { - if (!$partial) + if (!$partial) { $partial = $name; + } return $this->makeLayoutPartial('hint', [ 'hintName' => $name, @@ -515,8 +555,9 @@ class Controller extends Extendable */ public function onHideBackendHint() { - if (!$name = post('name')) + if (!$name = post('name')) { throw new ApplicationException('Missing a hint name.'); + } $preferences = UserPreferences::forUser(); $hiddenHints = $preferences->get('backend::hints.hidden', []); @@ -535,5 +576,4 @@ class Controller extends Extendable $hiddenHints = UserPreferences::forUser()->get('backend::hints.hidden', []); return array_key_exists($name, $hiddenHints); } - -} \ No newline at end of file +} diff --git a/modules/backend/classes/ControllerBehavior.php b/modules/backend/classes/ControllerBehavior.php index 8d137bccc..ddd4d8fd4 100644 --- a/modules/backend/classes/ControllerBehavior.php +++ b/modules/backend/classes/ControllerBehavior.php @@ -45,7 +45,10 @@ class ControllerBehavior extends ExtensionBase // Option A: (@todo Determine which is faster by benchmark) // $relativePath = strtolower(str_replace('\\', '/', get_called_class())); - // $this->viewPath = $this->configPath = ['modules/' . $relativePath . '/partials', 'plugins/' . $relativePath . '/partials']; + // $this->viewPath = $this->configPath = [ + // 'modules/' . $relativePath . '/partials', + // 'plugins/' . $relativePath . '/partials' + // ]; // $this->assetPath = ['modules/' . $relativePath . '/assets', 'plugins/' . $relativePath . '/assets']; // Option B: @@ -93,8 +96,9 @@ class ControllerBehavior extends ExtensionBase * First part will be the field name, pop it off */ $fieldName = array_shift($keyParts); - if (!isset($this->config->{$fieldName})) + if (!isset($this->config->{$fieldName})) { return $default; + } $result = $this->config->{$fieldName}; @@ -102,8 +106,9 @@ class ControllerBehavior extends ExtensionBase * Loop the remaining key parts and build a result */ foreach ($keyParts as $key) { - if (!array_key_exists($key, $result)) + if (!array_key_exists($key, $result)) { return $default; + } $result = $result[$key]; } @@ -121,8 +126,9 @@ class ControllerBehavior extends ExtensionBase */ protected function hideAction($methodName) { - if (!is_array($methodName)) + if (!is_array($methodName)) { $methodName = [$methodName]; + } $this->controller->hiddenActions = array_merge($this->controller->hiddenActions, $methodName); } @@ -148,4 +154,4 @@ class ControllerBehavior extends ExtensionBase { return method_exists($this->controller, $methodName); } -} \ No newline at end of file +} diff --git a/modules/backend/classes/FilterScope.php b/modules/backend/classes/FilterScope.php index d7e76a3a2..29d0f78a9 100644 --- a/modules/backend/classes/FilterScope.php +++ b/modules/backend/classes/FilterScope.php @@ -113,18 +113,39 @@ class FilterScope */ protected function evalConfig($config) { - if (isset($config['options'])) $this->options($config['options']); - if (isset($config['context'])) $this->context = $config['context']; - if (isset($config['default'])) $this->defaults = $config['default']; - if (isset($config['conditions'])) $this->conditions = $config['conditions']; - if (isset($config['scope'])) $this->scope = $config['scope']; - if (isset($config['cssClass'])) $this->cssClass = $config['cssClass']; - if (isset($config['nameFrom'])) $this->nameFrom = $config['nameFrom']; - if (isset($config['descriptionFrom'])) $this->descriptionFrom = $config['descriptionFrom']; + if (isset($config['options'])) { + $this->options($config['options']); + } + if (isset($config['context'])) { + $this->context = $config['context']; + } + if (isset($config['default'])) { + $this->defaults = $config['default']; + } + if (isset($config['conditions'])) { + $this->conditions = $config['conditions']; + } + if (isset($config['scope'])) { + $this->scope = $config['scope']; + } + if (isset($config['cssClass'])) { + $this->cssClass = $config['cssClass']; + } + if (isset($config['nameFrom'])) { + $this->nameFrom = $config['nameFrom']; + } + if (isset($config['descriptionFrom'])) { + $this->descriptionFrom = $config['descriptionFrom']; + } - /* @todo Remove line if year >= 2015 */ if (isset($config['nameColumn'])) $this->nameFrom = $config['nameColumn']; + // @todo Remove line if year >= 2015 + if (isset($config['nameColumn'])) { + $this->nameFrom = $config['nameColumn']; + } - if (array_key_exists('disabled', $config)) $this->disabled = $config['disabled']; + if (array_key_exists('disabled', $config)) { + $this->disabled = $config['disabled']; + } return $config; } @@ -136,13 +157,14 @@ class FilterScope $id = 'scope'; $id .= '-'.$this->scopeName; - if ($suffix) + if ($suffix) { $id .= '-'.$suffix; + } - if ($this->idPrefix) + if ($this->idPrefix) { $id = $this->idPrefix . '-' . $id; + } return Str::evalHtmlId($id); } - -} \ No newline at end of file +} diff --git a/modules/backend/classes/FormField.php b/modules/backend/classes/FormField.php index 942abfaf4..6a831d26e 100644 --- a/modules/backend/classes/FormField.php +++ b/modules/backend/classes/FormField.php @@ -193,15 +193,13 @@ class FormField if ($value === null) { if (is_array($this->options)) { return $this->options; - } - elseif (is_callable($this->options)) { + } elseif (is_callable($this->options)) { $callable = $this->options; return $callable(); } return []; - } - else { + } else { $this->options = $value; } @@ -233,28 +231,67 @@ class FormField */ protected function evalConfig($config) { - if (isset($config['options'])) $this->options($config['options']); - if (isset($config['span'])) $this->span($config['span']); - if (isset($config['context'])) $this->context = $config['context']; - if (isset($config['size'])) $this->size($config['size']); - if (isset($config['tab'])) $this->tab($config['tab']); - if (isset($config['commentAbove'])) $this->comment($config['commentAbove'], 'above'); - if (isset($config['comment'])) $this->comment($config['comment']); - if (isset($config['placeholder'])) $this->placeholder = $config['placeholder']; - if (isset($config['default'])) $this->defaults = $config['default']; - if (isset($config['cssClass'])) $this->cssClass = $config['cssClass']; - if (isset($config['attributes'])) $this->attributes($config['attributes']); - if (isset($config['containerAttributes'])) $this->attributes($config['containerAttributes'], 'container'); - if (isset($config['depends'])) $this->depends = $config['depends']; - if (isset($config['path'])) $this->path = $config['path']; + if (isset($config['options'])) { + $this->options($config['options']); + } + if (isset($config['span'])) { + $this->span($config['span']); + } + if (isset($config['context'])) { + $this->context = $config['context']; + } + if (isset($config['size'])) { + $this->size($config['size']); + } + if (isset($config['tab'])) { + $this->tab($config['tab']); + } + if (isset($config['commentAbove'])) { + $this->comment($config['commentAbove'], 'above'); + } + if (isset($config['comment'])) { + $this->comment($config['comment']); + } + if (isset($config['placeholder'])) { + $this->placeholder = $config['placeholder']; + } + if (isset($config['default'])) { + $this->defaults = $config['default']; + } + if (isset($config['cssClass'])) { + $this->cssClass = $config['cssClass']; + } + if (isset($config['attributes'])) { + $this->attributes($config['attributes']); + } + if (isset($config['containerAttributes'])) { + $this->attributes($config['containerAttributes'], 'container'); + } + if (isset($config['depends'])) { + $this->depends = $config['depends']; + } + if (isset($config['path'])) { + $this->path = $config['path']; + } - if (array_key_exists('required', $config)) $this->required = $config['required']; - if (array_key_exists('disabled', $config)) $this->disabled = $config['disabled']; - if (array_key_exists('hidden', $config)) $this->hidden = $config['hidden']; - if (array_key_exists('stretch', $config)) $this->stretch = $config['stretch']; + if (array_key_exists('required', $config)) { + $this->required = $config['required']; + } + if (array_key_exists('disabled', $config)) { + $this->disabled = $config['disabled']; + } + if (array_key_exists('hidden', $config)) { + $this->hidden = $config['hidden']; + } + if (array_key_exists('stretch', $config)) { + $this->stretch = $config['stretch']; + } - if (isset($config['valueFrom'])) $this->valueFrom = $config['valueFrom']; - else $this->valueFrom = $this->fieldName; + if (isset($config['valueFrom'])) { + $this->valueFrom = $config['valueFrom']; + } else { + $this->valueFrom = $this->fieldName; + } return $config; } @@ -284,8 +321,9 @@ class FormField */ public function attributes($items, $position = 'field') { - if (!is_array($items)) + if (!is_array($items)) { return; + } $multiArray = array_filter($items, 'is_array'); if (!$multiArray) { @@ -316,13 +354,15 @@ class FormField */ public function getName($arrayName = null) { - if ($arrayName === null) + if ($arrayName === null) { $arrayName = $this->arrayName; + } - if ($arrayName) + if ($arrayName) { return $arrayName.'['.implode('][', Str::evalHtmlArray($this->fieldName)).']'; - else + } else { return $this->fieldName; + } } /** @@ -331,17 +371,20 @@ class FormField public function getId($suffix = null) { $id = 'field'; - if ($this->arrayName) + if ($this->arrayName) { $id .= '-'.$this->arrayName; + } $id .= '-'.$this->fieldName; - if ($suffix) + if ($suffix) { $id .= '-'.$suffix; + } - if ($this->idPrefix) + if ($this->idPrefix) { $id = $this->idPrefix . '-' . $id; + } return Str::evalHtmlId($id); } -} \ No newline at end of file +} diff --git a/modules/backend/classes/FormWidgetBase.php b/modules/backend/classes/FormWidgetBase.php index 5d430958b..7ffee815b 100644 --- a/modules/backend/classes/FormWidgetBase.php +++ b/modules/backend/classes/FormWidgetBase.php @@ -61,16 +61,23 @@ abstract class FormWidgetBase extends WidgetBase $this->valueFrom = $formField->valueFrom; $this->model = $model; - /* @todo Remove line if year >= 2015 */ $this->columnName = $formField->valueFrom; + // @todo Remove line if year >= 2015 + $this->columnName = $formField->valueFrom; - if (isset($configuration->sessionKey)) $this->sessionKey = $configuration->sessionKey; - if (isset($configuration->previewMode)) $this->previewMode = $configuration->previewMode; + if (isset($configuration->sessionKey)) { + $this->sessionKey = $configuration->sessionKey; + } + if (isset($configuration->previewMode)) { + $this->previewMode = $configuration->previewMode; + } /* * Form fields originally passed their configuration via the options index. * This step should be removed if year >= 2015. */ - if (isset($configuration->options)) $configuration = array_merge($configuration->options, (array)$configuration); + if (isset($configuration->options)) { + $configuration = array_merge($configuration->options, (array)$configuration); + } parent::__construct($controller, $configuration); } @@ -125,5 +132,4 @@ abstract class FormWidgetBase extends WidgetBase return [$model, $last]; } - -} \ No newline at end of file +} diff --git a/modules/backend/classes/ListColumn.php b/modules/backend/classes/ListColumn.php index f7f1eaeca..6cf0a32bb 100644 --- a/modules/backend/classes/ListColumn.php +++ b/modules/backend/classes/ListColumn.php @@ -108,19 +108,39 @@ class ListColumn */ protected function evalConfig($config) { - if (isset($config['cssClass'])) $this->cssClass = $config['cssClass']; - if (isset($config['searchable'])) $this->searchable = $config['searchable']; - if (isset($config['sortable'])) $this->sortable = $config['sortable']; - if (isset($config['invisible'])) $this->invisible = $config['invisible']; - if (isset($config['valueFrom'])) $this->valueFrom = $config['valueFrom']; - if (isset($config['select'])) $this->sqlSelect = $config['select']; - if (isset($config['relation'])) $this->relation = $config['relation']; - if (isset($config['format'])) $this->format = $config['format']; - if (isset($config['path'])) $this->path = $config['path']; + if (isset($config['cssClass'])) { + $this->cssClass = $config['cssClass']; + } + if (isset($config['searchable'])) { + $this->searchable = $config['searchable']; + } + if (isset($config['sortable'])) { + $this->sortable = $config['sortable']; + } + if (isset($config['invisible'])) { + $this->invisible = $config['invisible']; + } + if (isset($config['valueFrom'])) { + $this->valueFrom = $config['valueFrom']; + } + if (isset($config['select'])) { + $this->sqlSelect = $config['select']; + } + if (isset($config['relation'])) { + $this->relation = $config['relation']; + } + if (isset($config['format'])) { + $this->format = $config['format']; + } + if (isset($config['path'])) { + $this->path = $config['path']; + } - /* @todo Remove line if year >= 2015 */ if (isset($config['nameFrom'])) $this->valueFrom = $config['nameFrom']; + // @todo Remove lines if year >= 2015 + if (isset($config['nameFrom'])) { + $this->valueFrom = $config['nameFrom']; + } return $config; } - -} \ No newline at end of file +} diff --git a/modules/backend/classes/NavigationManager.php b/modules/backend/classes/NavigationManager.php index 8b21c68f4..7f9d284ea 100644 --- a/modules/backend/classes/NavigationManager.php +++ b/modules/backend/classes/NavigationManager.php @@ -83,8 +83,9 @@ class NavigationManager foreach ($plugins as $id => $plugin) { $items = $plugin->registerNavigation(); - if (!is_array($items)) + if (!is_array($items)) { continue; + } $this->registerMenuItems($id, $items); } @@ -97,9 +98,10 @@ class NavigationManager /* * Sort menu items */ - usort($this->items, function($a, $b) { - if ($a->order == $b->order) + usort($this->items, function ($a, $b) { + if ($a->order == $b->order) { return 0; + } return $a->order > $b->order ? 1 : -1; }); @@ -111,8 +113,9 @@ class NavigationManager $this->items = $this->filterItemPermissions($user, $this->items); foreach ($this->items as $item) { - if (!$item->sideMenu || !count($item->sideMenu)) + if (!$item->sideMenu || !count($item->sideMenu)) { continue; + } $item->sideMenu = $this->filterItemPermissions($user, $item->sideMenu); } @@ -161,8 +164,9 @@ class NavigationManager */ public function registerMenuItems($owner, array $definitions) { - if (!$this->items) + if (!$this->items) { $this->items = []; + } foreach ($definitions as $code => $definition) { $item = (object) array_merge(self::$mainItemDefaults, array_merge($definition, [ @@ -192,8 +196,9 @@ class NavigationManager */ public function addMainMenuItems($owner, array $definitions) { - foreach ($definitions as $code => $definition) + foreach ($definitions as $code => $definition) { $this->addMainMenuItem($owner, $code, $definition); + } } /** @@ -207,8 +212,9 @@ class NavigationManager $sideMenu = isset($definition['sideMenu']) ? $definition['sideMenu'] : null; $itemKey = $this->makeItemKey($owner, $code); - if (isset($this->items[$itemKey])) + if (isset($this->items[$itemKey])) { $definition = array_merge((array) $this->items[$itemKey], $definition); + } $item = (object) array_merge(self::$mainItemDefaults, array_merge($definition, [ 'code' => $code, @@ -217,8 +223,9 @@ class NavigationManager $this->items[$itemKey] = $item; - if ($sideMenu !== null) + if ($sideMenu !== null) { $this->addSideMenuItems($sideMenu); + } } /** @@ -229,8 +236,9 @@ class NavigationManager */ public function addSideMenuItems($owner, $code, array $definitions) { - foreach ($definitions as $sideCode => $definition) + foreach ($definitions as $sideCode => $definition) { $this->addSideMenuItem($owner, $code, $sideCode, $definition); + } } /** @@ -243,12 +251,14 @@ class NavigationManager public function addSideMenuItem($owner, $code, $sideCode, array $definition) { $itemKey = $this->makeItemKey($owner, $code); - if (!isset($this->items[$itemKey])) + if (!isset($this->items[$itemKey])) { return false; + } $mainItem = $this->items[$itemKey]; - if (isset($mainItem->sideMenu[$sideCode])) + if (isset($mainItem->sideMenu[$sideCode])) { $definition = array_merge((array) $mainItem->sideMenu[$sideCode], $definition); + } $item = (object) array_merge(self::$sideItemDefaults, $definition); $this->items[$itemKey]->sideMenu[$sideCode] = $item; @@ -260,8 +270,9 @@ class NavigationManager */ public function listMainMenuItems() { - if ($this->items === null) + if ($this->items === null) { $this->loadItems(); + } return $this->items; } @@ -281,14 +292,16 @@ class NavigationManager } } - if (!$activeItem) + if (!$activeItem) { return []; + } $items = $activeItem->sideMenu; foreach ($items as $item) { - if ($item->counter !== null && is_callable($item->counter)) + if ($item->counter !== null && is_callable($item->counter)) { $item->counter = call_user_func($item->counter, $item); + } } return $items; @@ -339,7 +352,7 @@ class NavigationManager return (object)[ 'mainMenuCode' => $this->contextMainMenuItemCode, 'sideMenuCode' => $this->contextSideMenuItemCode, - 'owner' => $this->contextOwner + 'owner' => $this->contextOwner ]; } @@ -369,8 +382,9 @@ class NavigationManager public function getActiveMainMenuItem() { foreach ($this->listMainMenuItems() as $item) { - if ($this->isMainMenuItemActive($item)) + if ($this->isMainMenuItemActive($item)) { return $item; + } } return null; @@ -399,7 +413,9 @@ class NavigationManager } /** - * Returns the side navigation partial for a specific main menu previously registered with the registerContextSidenavPartial() method. + * Returns the side navigation partial for a specific main menu previously registered + * with the registerContextSidenavPartial() method. + * * @param string $owner Specifies the navigation owner in the format Vendor/Module. * @param string $mainMenuItemCode Specifies the main menu item code. * @return mixed Returns the partial name or null. @@ -408,7 +424,7 @@ class NavigationManager { $key = $owner.$mainMenuItemCode; - return array_key_exists($key, $this->contextSidenavPartials) ? + return array_key_exists($key, $this->contextSidenavPartials) ? $this->contextSidenavPartials[$key] : null; } @@ -421,9 +437,10 @@ class NavigationManager */ protected function filterItemPermissions($user, array $items) { - $items = array_filter($items, function($item) use ($user) { - if (!$item->permissions || !count($item->permissions)) + $items = array_filter($items, function ($item) use ($user) { + if (!$item->permissions || !count($item->permissions)) { return true; + } return $user->hasAnyAccess($item->permissions); }); @@ -440,4 +457,4 @@ class NavigationManager { return strtoupper($owner).'.'.strtoupper($code); } -} \ No newline at end of file +} diff --git a/modules/backend/classes/ReportWidgetBase.php b/modules/backend/classes/ReportWidgetBase.php index ea1b91015..8d5b7086d 100644 --- a/modules/backend/classes/ReportWidgetBase.php +++ b/modules/backend/classes/ReportWidgetBase.php @@ -17,4 +17,4 @@ class ReportWidgetBase extends WidgetBase parent::__construct($controller); } -} \ No newline at end of file +} diff --git a/modules/backend/classes/Skin.php b/modules/backend/classes/Skin.php index f2041ec8b..efa1219a4 100644 --- a/modules/backend/classes/Skin.php +++ b/modules/backend/classes/Skin.php @@ -79,8 +79,7 @@ abstract class Skin return $isPublic ? $this->publicSkinPath . $path : $this->skinPath . $path; - } - else { + } else { return $isPublic ? $this->defaultPublicSkinPath . $path : $this->defaultSkinPath . $path; @@ -101,11 +100,12 @@ abstract class Skin */ public static function getActive() { - if (self::$skinCache !== null) + if (self::$skinCache !== null) { return self::$skinCache; + } $skinClass = Config::get('cms.backendSkin'); $skinObject = new $skinClass(); return self::$skinCache = $skinObject; } -} \ No newline at end of file +} diff --git a/modules/backend/classes/WidgetBase.php b/modules/backend/classes/WidgetBase.php index cab703203..763f6ed72 100644 --- a/modules/backend/classes/WidgetBase.php +++ b/modules/backend/classes/WidgetBase.php @@ -52,7 +52,10 @@ abstract class WidgetBase // Option A: (@todo Determine which is faster by benchmark) // $relativePath = strtolower(str_replace('\\', '/', get_called_class())); - // $this->viewPath = $this->configPath = ['modules/' . $relativePath . '/partials', 'plugins/' . $relativePath . '/partials']; + // $this->viewPath = $this->configPath = [ + // 'modules/' . $relativePath . '/partials', + // 'plugins/' . $relativePath . '/partials' + // ]; // $this->assetPath = ['modules/' . $relativePath . '/assets', 'plugins/' . $relativePath . '/assets']; // Option B: @@ -62,16 +65,18 @@ abstract class WidgetBase /* * Apply configuration values to a new config object. */ - if (!$configuration) + if (!$configuration) { $configuration = []; + } $this->config = $this->makeConfig($configuration); /* * If no alias is set by the configuration. */ - if (!isset($this->alias)) + if (!isset($this->alias)) { $this->alias = (isset($this->config->alias)) ? $this->config->alias : $this->defaultAlias; + } /* * Prepare assets used by this widget. @@ -81,28 +86,35 @@ abstract class WidgetBase /* * Initialize the widget. */ - if (!$this->getConfig('noInit', false)) + if (!$this->getConfig('noInit', false)) { $this->init(); + } } /** * Initialize the widget, called by the constructor and free from its parameters. * @return void */ - public function init(){} + public function init() + { + } /** * Renders the widgets primary contents. * @return string HTML markup supplied by this widget. */ - public function render(){} + public function render() + { + } /** * Adds widget specific asset files. Use $this->addJs() and $this->addCss() * to register new assets to include on the page. * @return void */ - protected function loadAssets(){} + protected function loadAssets() + { + } /** * Binds a widget to the controller for safe use. @@ -110,8 +122,9 @@ abstract class WidgetBase */ public function bindToController() { - if ($this->controller->widget === null) + if ($this->controller->widget === null) { $this->controller->widget = new \stdClass(); + } $this->controller->widget->{$this->alias} = $this; } @@ -125,11 +138,13 @@ abstract class WidgetBase { $id = class_basename(get_called_class()); - if ($this->alias != $this->defaultAlias) + if ($this->alias != $this->defaultAlias) { $id .= '-' . $this->alias; + } - if ($suffix !== null) + if ($suffix !== null) { $id .= '-' . $suffix; + } return Str::evalHtmlId($id); } @@ -161,8 +176,9 @@ abstract class WidgetBase * First part will be the field name, pop it off */ $fieldName = array_shift($keyParts); - if (!isset($this->config->{$fieldName})) + if (!isset($this->config->{$fieldName})) { return $default; + } $result = $this->config->{$fieldName}; @@ -170,8 +186,9 @@ abstract class WidgetBase * Loop the remaining key parts and build a result */ foreach ($keyParts as $key) { - if (!array_key_exists($key, $result)) + if (!array_key_exists($key, $result)) { return $default; + } $result = $result[$key]; } @@ -218,11 +235,13 @@ abstract class WidgetBase $sessionId = $this->makeSessionId(); $currentStore = []; - if (Session::has($sessionId)) + if (Session::has($sessionId)) { $currentStore = unserialize(Session::get($sessionId)); + } - if ($key === null) + if ($key === null) { return $currentStore; + } return isset($currentStore[$key]) ? $currentStore[$key] : $default; } @@ -247,5 +266,4 @@ abstract class WidgetBase $sessionId = $this->makeSessionId(); Session::forget($sessionId); } - } diff --git a/modules/backend/classes/WidgetManager.php b/modules/backend/classes/WidgetManager.php index 827c7aa56..c7f65a4d2 100644 --- a/modules/backend/classes/WidgetManager.php +++ b/modules/backend/classes/WidgetManager.php @@ -84,8 +84,9 @@ class WidgetManager /* * Build configuration */ - if ($configuration === null) + if ($configuration === null) { $configuration = []; + } /* * Create widget object @@ -125,11 +126,13 @@ class WidgetManager $plugins = $this->pluginManager->getPlugins(); foreach ($plugins as $plugin) { - if (!is_array($widgets = $plugin->registerFormWidgets())) + if (!is_array($widgets = $plugin->registerFormWidgets())) { continue; + } - foreach ($widgets as $className => $widgetInfo) + foreach ($widgets as $className => $widgetInfo) { $this->registerFormWidget($className, $widgetInfo); + } } } @@ -145,8 +148,9 @@ class WidgetManager public function registerFormWidget($className, $widgetInfo = null) { $widgetAlias = isset($widgetInfo['alias']) ? $widgetInfo['alias'] : null; - if (!$widgetAlias) + if (!$widgetAlias) { $widgetAlias = Str::getClassId($className); + } $this->formWidgets[$className] = $widgetInfo; $this->formWidgetAliases[$widgetAlias] = $className; @@ -175,17 +179,20 @@ class WidgetManager */ public function resolveFormWidget($name) { - if ($this->formWidgets === null) + if ($this->formWidgets === null) { $this->listFormWidgets(); + } $aliases = $this->formWidgetAliases; - if (isset($aliases[$name])) + if (isset($aliases[$name])) { return $aliases[$name]; + } $_name = Str::normalizeClassName($name); - if (isset($this->formWidgets[$_name])) + if (isset($this->formWidgets[$_name])) { return $_name; + } return $name; } @@ -216,11 +223,13 @@ class WidgetManager $plugins = $this->pluginManager->getPlugins(); foreach ($plugins as $plugin) { - if (!is_array($widgets = $plugin->registerReportWidgets())) + if (!is_array($widgets = $plugin->registerReportWidgets())) { continue; + } - foreach ($widgets as $className => $widgetInfo) + foreach ($widgets as $className => $widgetInfo) { $this->registerReportWidget($className, $widgetInfo); + } } } @@ -251,4 +260,4 @@ class WidgetManager { $this->reportWidgetCallbacks[] = $definitions; } -} \ No newline at end of file +} From e66f6d5820e663ad5d082b6565313b455c3928e5 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Fri, 10 Oct 2014 23:16:22 +0200 Subject: [PATCH 06/30] Updating single files in backend --- modules/backend/ServiceProvider.php | 21 +++++++++++++-------- modules/backend/routes.php | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/modules/backend/ServiceProvider.php b/modules/backend/ServiceProvider.php index 0ee23b327..b80a871f3 100644 --- a/modules/backend/ServiceProvider.php +++ b/modules/backend/ServiceProvider.php @@ -24,7 +24,7 @@ class ServiceProvider extends ModuleServiceProvider /* * Register widgets */ - WidgetManager::instance()->registerFormWidgets(function($manager){ + WidgetManager::instance()->registerFormWidgets(function ($manager) { $manager->registerFormWidget('Backend\FormWidgets\CodeEditor', [ 'label' => 'Code editor', 'alias' => 'codeeditor' @@ -59,7 +59,7 @@ class ServiceProvider extends ModuleServiceProvider /* * Register navigation */ - BackendMenu::registerCallback(function($manager) { + BackendMenu::registerCallback(function ($manager) { $manager->registerMenuItems('October.Backend', [ 'dashboard' => [ 'label' => 'backend::lang.dashboard.menu_label', @@ -74,7 +74,7 @@ class ServiceProvider extends ModuleServiceProvider /* * Register settings */ - SettingsManager::instance()->registerCallback(function($manager){ + SettingsManager::instance()->registerCallback(function ($manager) { $manager->registerSettingItems('October.Backend', [ 'editor' => [ 'label' => 'backend::lang.editor.menu_label', @@ -119,17 +119,23 @@ class ServiceProvider extends ModuleServiceProvider /* * Register permissions */ - BackendAuth::registerCallback(function($manager) { + BackendAuth::registerCallback(function ($manager) { $manager->registerPermissions('October.Backend', [ - 'backend.access_dashboard' => ['label' => 'system::lang.permissions.view_the_dashboard', 'tab' => 'System'], - 'backend.manage_users' => ['label' => 'system::lang.permissions.manage_other_administrators', 'tab' => 'System'], + 'backend.access_dashboard' => [ + 'label' => 'system::lang.permissions.view_the_dashboard', + 'tab' => 'System' + ], + 'backend.manage_users' => [ + 'label' => 'system::lang.permissions.manage_other_administrators', + 'tab' => 'System' + ], ]); }); /* * Register mail templates */ - MailTemplate::registerCallback(function($template){ + MailTemplate::registerCallback(function ($template) { $template->registerMailTemplates([ 'backend::mail.invite' => 'Invitation for newly created administrators.', 'backend::mail.restore' => 'Password reset instructions for backend-end administrators.', @@ -146,5 +152,4 @@ class ServiceProvider extends ModuleServiceProvider { parent::boot('backend'); } - } diff --git a/modules/backend/routes.php b/modules/backend/routes.php index 708689594..56ef8a3e1 100644 --- a/modules/backend/routes.php +++ b/modules/backend/routes.php @@ -3,12 +3,12 @@ /* * Register Backend routes before all user routes. */ -App::before(function($request) { +App::before(function ($request) { /* * Other pages */ - Route::group(['prefix' => Config::get('cms.backendUri', 'backend')], function() { + Route::group(['prefix' => Config::get('cms.backendUri', 'backend')], function () { Route::any('{slug}', 'Backend\Classes\BackendController@run')->where('slug', '(.*)?'); }); From 92aa3fc18d822b6b084177eae9c1fe726b195357 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Fri, 10 Oct 2014 23:26:57 +0200 Subject: [PATCH 07/30] Updating backend/controllers --- modules/backend/controllers/AccessLogs.php | 3 +- modules/backend/controllers/Auth.php | 46 +++++++++++-------- .../backend/controllers/EditorPreferences.php | 2 +- modules/backend/controllers/Groups.php | 5 +- modules/backend/controllers/Index.php | 37 ++++++++++++--- modules/backend/controllers/Users.php | 17 ++++--- 6 files changed, 73 insertions(+), 37 deletions(-) diff --git a/modules/backend/controllers/AccessLogs.php b/modules/backend/controllers/AccessLogs.php index 19961285b..6dd8dc476 100644 --- a/modules/backend/controllers/AccessLogs.php +++ b/modules/backend/controllers/AccessLogs.php @@ -37,5 +37,4 @@ class AccessLogs extends Controller BackendMenu::setContext('October.System', 'system', 'settings'); SettingsManager::setContext('October.Backend', 'access_logs'); } - -} \ No newline at end of file +} diff --git a/modules/backend/controllers/Auth.php b/modules/backend/controllers/Auth.php index 8015d892f..9e7edab67 100644 --- a/modules/backend/controllers/Auth.php +++ b/modules/backend/controllers/Auth.php @@ -47,12 +47,12 @@ class Auth extends Controller $this->bodyClass = 'signin'; try { - if (post('postback')) + if (post('postback')) { return $this->signin_onSubmit(); - else + } else { $this->bodyClass .= ' preload'; - } - catch (Exception $ex) { + } + } catch (Exception $ex) { Flash::error($ex->getMessage()); } } @@ -65,8 +65,9 @@ class Auth extends Controller ]; $validation = Validator::make(post(), $rules); - if ($validation->fails()) + if ($validation->fails()) { throw new ValidationException($validation); + } // Authenticate user $user = BackendAuth::authenticate([ @@ -99,10 +100,10 @@ class Auth extends Controller public function restore() { try { - if (post('postback')) + if (post('postback')) { return $this->restore_onSubmit(); - } - catch (Exception $ex) { + } + } catch (Exception $ex) { Flash::error($ex->getMessage()); } } @@ -114,8 +115,9 @@ class Auth extends Controller ]; $validation = Validator::make(post(), $rules); - if ($validation->fails()) + if ($validation->fails()) { throw new ValidationException($validation); + } $user = BackendAuth::findUserByLogin(post('login')); if (!$user) { @@ -134,8 +136,7 @@ class Auth extends Controller 'link' => $link, ]; - Mail::send('backend::mail.restore', $data, function($message) use ($user) - { + Mail::send('backend::mail.restore', $data, function ($message) use ($user) { $message->to($user->email, $user->full_name)->subject(trans('backend::lang.account.password_reset')); }); @@ -148,13 +149,14 @@ class Auth extends Controller public function reset($userId = null, $code = null) { try { - if (post('postback')) + if (post('postback')) { return $this->reset_onSubmit(); + } - if (!$userId || !$code) + if (!$userId || !$code) { throw new ApplicationException(trans('backend::lang.account.reset_error')); - } - catch (Exception $ex) { + } + } catch (Exception $ex) { Flash::error($ex->getMessage()); } @@ -164,25 +166,29 @@ class Auth extends Controller public function reset_onSubmit() { - if (!post('id') || !post('code')) + if (!post('id') || !post('code')) { throw new ApplicationException(trans('backend::lang.account.reset_error')); + } $rules = [ 'password' => 'required|min:2' ]; $validation = Validator::make(post(), $rules); - if ($validation->fails()) + if ($validation->fails()) { throw new ValidationException($validation); + } $code = post('code'); $user = BackendAuth::findUserById(post('id')); - if (!$user->checkResetPasswordCode($code)) + if (!$user->checkResetPasswordCode($code)) { throw new ApplicationException(trans('backend::lang.account.reset_error')); + } - if (!$user->attemptResetPassword($code, post('password'))) + if (!$user->attemptResetPassword($code, post('password'))) { throw new ApplicationException(trans('backend::lang.account.reset_fail')); + } $user->clearResetPassword(); @@ -190,4 +196,4 @@ class Auth extends Controller return Redirect::to(Backend::url('backend/auth/signin')); } -} \ No newline at end of file +} diff --git a/modules/backend/controllers/EditorPreferences.php b/modules/backend/controllers/EditorPreferences.php index e73c695de..e5feec297 100644 --- a/modules/backend/controllers/EditorPreferences.php +++ b/modules/backend/controllers/EditorPreferences.php @@ -68,4 +68,4 @@ class EditorPreferences extends Controller { return EditorPreferencesModel::instance(); } -} \ No newline at end of file +} diff --git a/modules/backend/controllers/Groups.php b/modules/backend/controllers/Groups.php index 740c9c65d..1ec3ff8c7 100644 --- a/modules/backend/controllers/Groups.php +++ b/modules/backend/controllers/Groups.php @@ -45,12 +45,13 @@ class Groups extends Controller 'type' => 'checkbox', ]; - if (isset($permission->tab)) + if (isset($permission->tab)) { $fieldConfig['tab'] = $permission->tab; + } $permissionFields[$fieldName] = $fieldConfig; } $host->addTabFields($permissionFields); } -} \ No newline at end of file +} diff --git a/modules/backend/controllers/Index.php b/modules/backend/controllers/Index.php index 8f422c1f3..c63955d55 100644 --- a/modules/backend/controllers/Index.php +++ b/modules/backend/controllers/Index.php @@ -28,11 +28,36 @@ class Index extends Controller BackendMenu::setContextOwner('October.Backend'); new ReportContainer($this); - /* @todo Remove line if year >= 2015 */ if (\Schema::hasColumn('backend_users', 'activated')) \Schema::table('backend_users', function($table) { $table->renameColumn('activated', 'is_activated'); }); - /* @todo Remove line if year >= 2015 */ if (\Schema::hasColumn('backend_user_throttle', 'suspended')) \Schema::table('backend_user_throttle', function($table) { $table->renameColumn('suspended', 'is_suspended'); }); - /* @todo Remove line if year >= 2015 */ if (\Schema::hasColumn('backend_user_throttle', 'banned')) \Schema::table('backend_user_throttle', function($table) { $table->renameColumn('banned', 'is_banned'); }); - /* @todo Remove line if year >= 2015 */ if (\Schema::hasColumn('deferred_bindings', 'bind')) \Schema::table('deferred_bindings', function($table) { $table->renameColumn('bind', 'is_bind'); }); - /* @todo Remove line if year >= 2015 */ if (\Schema::hasColumn('system_files', 'public')) \Schema::table('system_files', function($table) { $table->renameColumn('public', 'is_public'); }); + /* @todo Remove line if year >= 2015 */ + if (\Schema::hasColumn('backend_users', 'activated')) { + \Schema::table('backend_users', function ($table) { + $table->renameColumn('activated', 'is_activated'); + }); + } + /* @todo Remove line if year >= 2015 */ + if (\Schema::hasColumn('backend_user_throttle', 'suspended')) { + \Schema::table('backend_user_throttle', function ($table) { + $table->renameColumn('suspended', 'is_suspended'); + }); + } + /* @todo Remove line if year >= 2015 */ + if (\Schema::hasColumn('backend_user_throttle', 'banned')) { + \Schema::table('backend_user_throttle', function ($table) { + $table->renameColumn('banned', 'is_banned'); + }); + } + /* @todo Remove line if year >= 2015 */ + if (\Schema::hasColumn('deferred_bindings', 'bind')) { + \Schema::table('deferred_bindings', function ($table) { + $table->renameColumn('bind', 'is_bind'); + }); + } + /* @todo Remove line if year >= 2015 */ + if (\Schema::hasColumn('system_files', 'public')) { + \Schema::table('system_files', function ($table) { + $table->renameColumn('public', 'is_public'); + }); + } } public function index() @@ -40,4 +65,4 @@ class Index extends Controller $this->pageTitle = trans('backend::lang.dashboard.menu_label'); BackendMenu::setContextMainMenu('dashboard'); } -} \ No newline at end of file +} diff --git a/modules/backend/controllers/Users.php b/modules/backend/controllers/Users.php index 5db153b3d..4e0d022ad 100644 --- a/modules/backend/controllers/Users.php +++ b/modules/backend/controllers/Users.php @@ -33,8 +33,9 @@ class Users extends Controller { parent::__construct(); - if ($this->action == 'myaccount') + if ($this->action == 'myaccount') { $this->requiredPermissions = null; + } BackendMenu::setContext('October.System', 'system', 'users'); SettingsManager::setContext('October.System', 'administrators'); @@ -46,8 +47,9 @@ class Users extends Controller public function update($recordId, $context = null) { // Users cannot edit themselves, only use My Settings - if ($context != 'myaccount' && $recordId == $this->user->id) + if ($context != 'myaccount' && $recordId == $this->user->id) { return Redirect::to(Backend::url('backend/users/myaccount')); + } return $this->asExtension('FormController')->update($recordId, $context); } @@ -75,8 +77,9 @@ class Users extends Controller */ $loginChanged = $this->user->login != post('User[login]'); $passwordChanged = strlen(post('User[password]')); - if ($loginChanged || $passwordChanged) + if ($loginChanged || $passwordChanged) { BackendAuth::login($this->user->reload(), true); + } return $result; } @@ -86,8 +89,9 @@ class Users extends Controller */ protected function formExtendFields($form) { - if ($form->getContext() == 'myaccount') + if ($form->getContext() == 'myaccount') { return; + } $permissionFields = []; foreach (BackendAuth::listPermissions() as $permission) { @@ -110,12 +114,13 @@ class Users extends Controller 'span' => 'auto', ]; - if (isset($permission->tab)) + if (isset($permission->tab)) { $fieldConfig['tab'] = $permission->tab; + } $permissionFields[$fieldName] = $fieldConfig; } $form->addTabFields($permissionFields); } -} \ No newline at end of file +} From 7148341b800c6afddaa8bab95801f13c97905386 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Fri, 10 Oct 2014 23:34:34 +0200 Subject: [PATCH 08/30] Updating backend/database --- .../migrations/2013_10_01_000001_Db_Backend_Users.php | 5 +---- .../2013_10_01_000002_Db_Backend_User_Groups.php | 5 +---- .../2013_10_01_000003_Db_Backend_Users_Groups.php | 5 +---- .../2013_10_01_000004_Db_Backend_User_Throttle.php | 5 +---- .../2014_01_04_000005_Db_Backend_User_Preferences.php | 3 +-- .../migrations/2014_10_01_000006_Db_Backend_Access_Log.php | 5 +---- modules/backend/database/seeds/DatabaseSeeder.php | 3 +-- modules/backend/database/seeds/SeedSetupAdmin.php | 7 ++++--- 8 files changed, 11 insertions(+), 27 deletions(-) diff --git a/modules/backend/database/migrations/2013_10_01_000001_Db_Backend_Users.php b/modules/backend/database/migrations/2013_10_01_000001_Db_Backend_Users.php index e55b11e8b..cce09225c 100644 --- a/modules/backend/database/migrations/2013_10_01_000001_Db_Backend_Users.php +++ b/modules/backend/database/migrations/2013_10_01_000001_Db_Backend_Users.php @@ -5,11 +5,9 @@ use Illuminate\Database\Migrations\Migration; class DbBackendUsers extends Migration { - public function up() { - Schema::create('backend_users', function(Blueprint $table) - { + Schema::create('backend_users', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->string('first_name')->nullable(); @@ -32,5 +30,4 @@ class DbBackendUsers extends Migration { Schema::dropIfExists('backend_users'); } - } diff --git a/modules/backend/database/migrations/2013_10_01_000002_Db_Backend_User_Groups.php b/modules/backend/database/migrations/2013_10_01_000002_Db_Backend_User_Groups.php index 886acca48..d9f05faf6 100644 --- a/modules/backend/database/migrations/2013_10_01_000002_Db_Backend_User_Groups.php +++ b/modules/backend/database/migrations/2013_10_01_000002_Db_Backend_User_Groups.php @@ -5,11 +5,9 @@ use Illuminate\Database\Migrations\Migration; class DbBackendUserGroups extends Migration { - public function up() { - Schema::create('backend_user_groups', function($table) - { + Schema::create('backend_user_groups', function ($table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->string('name')->unique(); @@ -22,5 +20,4 @@ class DbBackendUserGroups extends Migration { Schema::dropIfExists('backend_user_groups'); } - } diff --git a/modules/backend/database/migrations/2013_10_01_000003_Db_Backend_Users_Groups.php b/modules/backend/database/migrations/2013_10_01_000003_Db_Backend_Users_Groups.php index 1b8c9640a..4e786e7cf 100644 --- a/modules/backend/database/migrations/2013_10_01_000003_Db_Backend_Users_Groups.php +++ b/modules/backend/database/migrations/2013_10_01_000003_Db_Backend_Users_Groups.php @@ -5,11 +5,9 @@ use Illuminate\Database\Migrations\Migration; class DbBackendUsersGroups extends Migration { - public function up() { - Schema::create('backend_users_groups', function($table) - { + Schema::create('backend_users_groups', function ($table) { $table->engine = 'InnoDB'; $table->integer('user_id')->unsigned(); $table->integer('user_group_id')->unsigned(); @@ -21,5 +19,4 @@ class DbBackendUsersGroups extends Migration { Schema::dropIfExists('backend_users_groups'); } - } diff --git a/modules/backend/database/migrations/2013_10_01_000004_Db_Backend_User_Throttle.php b/modules/backend/database/migrations/2013_10_01_000004_Db_Backend_User_Throttle.php index f37dc9f5b..6618d8d55 100644 --- a/modules/backend/database/migrations/2013_10_01_000004_Db_Backend_User_Throttle.php +++ b/modules/backend/database/migrations/2013_10_01_000004_Db_Backend_User_Throttle.php @@ -5,11 +5,9 @@ use Illuminate\Database\Migrations\Migration; class DbBackendUserThrottle extends Migration { - public function up() { - Schema::create('backend_user_throttle', function($table) - { + Schema::create('backend_user_throttle', function ($table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->integer('user_id')->unsigned(); @@ -27,5 +25,4 @@ class DbBackendUserThrottle extends Migration { Schema::dropIfExists('backend_user_throttle'); } - } diff --git a/modules/backend/database/migrations/2014_01_04_000005_Db_Backend_User_Preferences.php b/modules/backend/database/migrations/2014_01_04_000005_Db_Backend_User_Preferences.php index 12c00407a..dace239de 100644 --- a/modules/backend/database/migrations/2014_01_04_000005_Db_Backend_User_Preferences.php +++ b/modules/backend/database/migrations/2014_01_04_000005_Db_Backend_User_Preferences.php @@ -7,8 +7,7 @@ class DbBackendUserPreferences extends Migration { public function up() { - Schema::create('backend_user_preferences', function($table) - { + Schema::create('backend_user_preferences', function ($table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->integer('user_id')->unsigned(); diff --git a/modules/backend/database/migrations/2014_10_01_000006_Db_Backend_Access_Log.php b/modules/backend/database/migrations/2014_10_01_000006_Db_Backend_Access_Log.php index 84980f211..3462cea11 100644 --- a/modules/backend/database/migrations/2014_10_01_000006_Db_Backend_Access_Log.php +++ b/modules/backend/database/migrations/2014_10_01_000006_Db_Backend_Access_Log.php @@ -5,11 +5,9 @@ use Illuminate\Database\Migrations\Migration; class DbBackendAccessLog extends Migration { - public function up() { - Schema::create('backend_access_log', function(Blueprint $table) - { + Schema::create('backend_access_log', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->integer('user_id')->unsigned(); @@ -22,5 +20,4 @@ class DbBackendAccessLog extends Migration { Schema::dropIfExists('backend_access_log'); } - } diff --git a/modules/backend/database/seeds/DatabaseSeeder.php b/modules/backend/database/seeds/DatabaseSeeder.php index d815e2834..ce9b9dfe1 100644 --- a/modules/backend/database/seeds/DatabaseSeeder.php +++ b/modules/backend/database/seeds/DatabaseSeeder.php @@ -17,5 +17,4 @@ class DatabaseSeeder extends Seeder $this->call('Backend\Database\Seeds\SeedSetupAdmin'); } - -} \ No newline at end of file +} diff --git a/modules/backend/database/seeds/SeedSetupAdmin.php b/modules/backend/database/seeds/SeedSetupAdmin.php index c571b7ca8..dcaceaa7e 100644 --- a/modules/backend/database/seeds/SeedSetupAdmin.php +++ b/modules/backend/database/seeds/SeedSetupAdmin.php @@ -15,7 +15,9 @@ class SeedSetupAdmin extends Seeder public function setDefaults($values) { - if (!is_array($values)) return; + if (!is_array($values)) { + return; + } foreach ($values as $attribute => $value) { static::$$attribute = $value; } @@ -40,5 +42,4 @@ class SeedSetupAdmin extends Seeder $user->addGroup($group); } - -} \ No newline at end of file +} From ae1c9e95c224be22c7cedfbbca6ba21890110ead Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Fri, 10 Oct 2014 23:36:04 +0200 Subject: [PATCH 09/30] Updating backend/facades --- modules/backend/facades/Backend.php | 5 ++++- modules/backend/facades/BackendAuth.php | 5 ++++- modules/backend/facades/BackendMenu.php | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/backend/facades/Backend.php b/modules/backend/facades/Backend.php index eee6bbdba..43781c7ac 100644 --- a/modules/backend/facades/Backend.php +++ b/modules/backend/facades/Backend.php @@ -12,5 +12,8 @@ class Backend extends Facade * * @return string */ - protected static function getFacadeAccessor() { return 'backend.helper'; } + protected static function getFacadeAccessor() + { + return 'backend.helper'; + } } diff --git a/modules/backend/facades/BackendAuth.php b/modules/backend/facades/BackendAuth.php index c7500dd8f..2d676fd8b 100644 --- a/modules/backend/facades/BackendAuth.php +++ b/modules/backend/facades/BackendAuth.php @@ -12,5 +12,8 @@ class BackendAuth extends Facade * * @return string */ - protected static function getFacadeAccessor() { return 'backend.auth'; } + protected static function getFacadeAccessor() + { + return 'backend.auth'; + } } diff --git a/modules/backend/facades/BackendMenu.php b/modules/backend/facades/BackendMenu.php index 6bdc6987e..8ec2a431a 100644 --- a/modules/backend/facades/BackendMenu.php +++ b/modules/backend/facades/BackendMenu.php @@ -12,5 +12,8 @@ class BackendMenu extends Facade * * @return string */ - protected static function getFacadeAccessor() { return 'backend.menu'; } + protected static function getFacadeAccessor() + { + return 'backend.menu'; + } } From f29151100ba47bc0df763f200b8123a995b4f0f8 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Fri, 10 Oct 2014 23:50:05 +0200 Subject: [PATCH 10/30] Updating modules/backend/formwidgets --- modules/backend/formwidgets/CodeEditor.php | 3 +- modules/backend/formwidgets/DataGrid.php | 22 +++++++----- modules/backend/formwidgets/Datepicker.php | 7 ++-- modules/backend/formwidgets/FileUpload.php | 28 +++++++++------ modules/backend/formwidgets/RecordFinder.php | 31 +++++++++++----- modules/backend/formwidgets/Relation.php | 38 +++++++++++++------- modules/backend/formwidgets/RichEditor.php | 2 +- 7 files changed, 84 insertions(+), 47 deletions(-) diff --git a/modules/backend/formwidgets/CodeEditor.php b/modules/backend/formwidgets/CodeEditor.php index 89419b9cf..a12a9ad71 100644 --- a/modules/backend/formwidgets/CodeEditor.php +++ b/modules/backend/formwidgets/CodeEditor.php @@ -118,5 +118,4 @@ class CodeEditor extends FormWidgetBase $this->addJs('vendor/ace/ace.js', 'core'); $this->addJs('js/codeeditor.js', 'core'); } - -} \ No newline at end of file +} diff --git a/modules/backend/formwidgets/DataGrid.php b/modules/backend/formwidgets/DataGrid.php index 2dfdeda5d..a67f8d1fc 100644 --- a/modules/backend/formwidgets/DataGrid.php +++ b/modules/backend/formwidgets/DataGrid.php @@ -99,16 +99,19 @@ class DataGrid extends FormWidgetBase { $methodName = 'get'.studly_case($this->fieldName).'AutocompleteValues'; - if (!$this->model->methodExists($methodName) && !$this->model->methodExists('getGridAutocompleteValues')) + if (!$this->model->methodExists($methodName) && !$this->model->methodExists('getGridAutocompleteValues')) { throw new ApplicationException('Model :model does not contain a method getGridAutocompleteValues()'); + } - if ($this->model->methodExists($methodName)) + if ($this->model->methodExists($methodName)) { $result = $this->model->$methodName($field, $value, $data); - else + } else { $result = $this->model->getGridAutocompleteValues($this->fieldName, $field, $value, $data); + } - if (!is_array($result)) + if (!is_array($result)) { $result = []; + } return $result; } @@ -122,16 +125,19 @@ class DataGrid extends FormWidgetBase { $methodName = 'get'.studly_case($this->fieldName).'DataSourceValues'; - if (!$this->model->methodExists($methodName) && !$this->model->methodExists('getGridDataSourceValues')) + if (!$this->model->methodExists($methodName) && !$this->model->methodExists('getGridDataSourceValues')) { throw new ApplicationException('Model :model does not contain a method getGridDataSourceValues()'); + } - if ($this->model->methodExists($methodName)) + if ($this->model->methodExists($methodName)) { $result = $this->model->$methodName(); - else + } else { $result = $this->model->getGridDataSourceValues($this->fieldName); + } - if (!is_array($result)) + if (!is_array($result)) { $result = []; + } return $result; } diff --git a/modules/backend/formwidgets/Datepicker.php b/modules/backend/formwidgets/Datepicker.php index b443542cf..dba596a5e 100644 --- a/modules/backend/formwidgets/Datepicker.php +++ b/modules/backend/formwidgets/Datepicker.php @@ -60,10 +60,11 @@ class Datepicker extends FormWidgetBase $value = $this->getLoadData(); if ($this->mode != 'datetime' && $value) { - if (is_string($value)) + if (is_string($value)) { $value = substr($value, 0, 10); - elseif (is_object($value)) + } elseif (is_object($value)) { $value = $value->toDateString(); + } } $this->vars['value'] = $value ?: ''; @@ -92,4 +93,4 @@ class Datepicker extends FormWidgetBase { return strlen($value) ? $value : null; } -} \ No newline at end of file +} diff --git a/modules/backend/formwidgets/FileUpload.php b/modules/backend/formwidgets/FileUpload.php index 975d5f212..e7b09460f 100644 --- a/modules/backend/formwidgets/FileUpload.php +++ b/modules/backend/formwidgets/FileUpload.php @@ -39,7 +39,10 @@ class FileUpload extends FormWidgetBase { $this->imageHeight = $this->getConfig('imageHeight', 100); $this->imageWidth = $this->getConfig('imageWidth', 100); - $this->previewNoFilesMessage = $this->getConfig('previewNoFilesMessage', 'backend::lang.form.preview_no_files_message'); + $this->previewNoFilesMessage = $this->getConfig( + 'previewNoFilesMessage', + 'backend::lang.form.preview_no_files_message' + ); $this->checkUploadPostback(); } @@ -87,8 +90,9 @@ class FileUpload extends FormWidgetBase { $mode = $this->getConfig('mode', 'image'); - if (str_contains($mode, '-')) + if (str_contains($mode, '-')) { return $mode; + } $relationType = $this->getRelationType(); $mode .= ($relationType == 'attachMany' || $relationType == 'morphMany') ? '-multi' : '-single'; @@ -171,8 +175,7 @@ class FileUpload extends FormWidgetBase } throw new SystemException('Unable to find file, it may no longer exist'); - } - catch (Exception $ex) { + } catch (Exception $ex) { return json_encode(['error' => $ex->getMessage()]); } } @@ -200,8 +203,9 @@ class FileUpload extends FormWidgetBase */ protected function checkUploadPostback() { - if (!($uniqueId = post('X_OCTOBER_FILEUPLOAD')) || $uniqueId != $this->getId()) + if (!($uniqueId = post('X_OCTOBER_FILEUPLOAD')) || $uniqueId != $this->getId()) { return; + } try { $uploadedFile = Input::file('file_data'); @@ -209,19 +213,22 @@ class FileUpload extends FormWidgetBase $isImage = starts_with($this->getDisplayMode(), 'image'); $validationRules = ['max:'.File::getMaxFilesize()]; - if ($isImage) + if ($isImage) { $validationRules[] = 'mimes:jpg,jpeg,bmp,png,gif'; + } $validation = Validator::make( ['file_data' => $uploadedFile], ['file_data' => $validationRules] ); - if ($validation->fails()) + if ($validation->fails()) { throw new ValidationException($validation); + } - if (!$uploadedFile->isValid()) + if (!$uploadedFile->isValid()) { throw new SystemException('File is not valid'); + } $fileRelation = $this->getRelationObject(); @@ -235,11 +242,10 @@ class FileUpload extends FormWidgetBase $file->thumb = $file->getThumb($this->imageWidth, $this->imageHeight, ['mode' => 'crop']); $result = $file; - } - catch (Exception $ex) { + } catch (Exception $ex) { $result = json_encode(['error' => $ex->getMessage()]); } die($result); } -} \ No newline at end of file +} diff --git a/modules/backend/formwidgets/RecordFinder.php b/modules/backend/formwidgets/RecordFinder.php index 314f41afa..45db4ff90 100644 --- a/modules/backend/formwidgets/RecordFinder.php +++ b/modules/backend/formwidgets/RecordFinder.php @@ -84,11 +84,21 @@ class RecordFinder extends FormWidgetBase $this->nameFrom = $this->getConfig('nameFrom', $this->nameFrom); $this->descriptionFrom = $this->getConfig('descriptionFrom', $this->descriptionFrom); - /* @todo Remove line if year >= 2015 */ if ($this->getConfig('nameColumn')) $this->nameFrom = $this->getConfig('nameColumn'); - /* @todo Remove line if year >= 2015 */ if ($this->getConfig('descriptionColumn')) $this->descriptionFrom = $this->getConfig('descriptionColumn'); + /* @todo Remove lines if year >= 2015 */ + if ($this->getConfig('nameColumn')) { + $this->nameFrom = $this->getConfig('nameColumn'); + } + /* @todo Remove lines if year >= 2015 */ + if ($this->getConfig('descriptionColumn')) { + $this->descriptionFrom = $this->getConfig('descriptionColumn'); + } - if (!$this->model->hasRelation($this->relationName)) - throw new SystemException(Lang::get('backend::lang.model.missing_relation', ['class'=>get_class($this->controller), 'relation'=>$this->relationName])); + if (!$this->model->hasRelation($this->relationName)) { + throw new SystemException(Lang::get('backend::lang.model.missing_relation', [ + 'class' => get_class($this->controller), + 'relation' => $this->relationName + ])); + } if (post('recordfinder_flag')) { $this->listWidget = $this->makeListWidget(); @@ -100,7 +110,7 @@ class RecordFinder extends FormWidgetBase /* * Link the Search Widget to the List Widget */ - $this->searchWidget->bindEvent('search.submit', function() { + $this->searchWidget->bindEvent('search.submit', function () { $this->listWidget->setSearchTerm($this->searchWidget->getActiveTerm()); return $this->listWidget->onRefresh(); }); @@ -162,24 +172,27 @@ class RecordFinder extends FormWidgetBase public function getKeyValue() { - if (!$this->relationModel) + if (!$this->relationModel) { return null; + } return $this->relationModel->{$this->keyFrom}; } public function getNameValue() { - if (!$this->relationModel || !$this->nameFrom) + if (!$this->relationModel || !$this->nameFrom) { return null; + } return $this->relationModel->{$this->nameFrom}; } public function getDescriptionValue() { - if (!$this->relationModel || !$this->descriptionFrom) + if (!$this->relationModel || !$this->descriptionFrom) { return null; + } return $this->relationModel->{$this->descriptionFrom}; } @@ -226,4 +239,4 @@ class RecordFinder extends FormWidgetBase $widget->cssClasses[] = 'recordfinder-search'; return $widget; } -} \ No newline at end of file +} diff --git a/modules/backend/formwidgets/Relation.php b/modules/backend/formwidgets/Relation.php index 575275ceb..e0e218b47 100644 --- a/modules/backend/formwidgets/Relation.php +++ b/modules/backend/formwidgets/Relation.php @@ -61,11 +61,21 @@ class Relation extends FormWidgetBase $this->descriptionFrom = $this->getConfig('descriptionFrom', $this->descriptionFrom); $this->emptyOption = $this->getConfig('emptyOption'); - /* @todo Remove line if year >= 2015 */ if ($this->getConfig('nameColumn')) $this->nameFrom = $this->getConfig('nameColumn'); - /* @todo Remove line if year >= 2015 */ if ($this->getConfig('descriptionColumn')) $this->descriptionFrom = $this->getConfig('descriptionColumn'); + /* @todo Remove lines if year >= 2015 */ + if ($this->getConfig('nameColumn')) { + $this->nameFrom = $this->getConfig('nameColumn'); + } + /* @todo Remove lines if year >= 2015 */ + if ($this->getConfig('descriptionColumn')) { + $this->descriptionFrom = $this->getConfig('descriptionColumn'); + } - if (!$this->model->hasRelation($this->relationName)) - throw new SystemException(Lang::get('backend::lang.model.missing_relation', ['class'=>get_class($this->controller), 'relation'=>$this->relationName])); + if (!$this->model->hasRelation($this->relationName)) { + throw new SystemException(Lang::get( + 'backend::lang.model.missing_relation', + ['class'=>get_class($this->controller), 'relation'=>$this->relationName] + )); + } } /** @@ -90,7 +100,7 @@ class Relation extends FormWidgetBase */ protected function makeRenderFormField() { - return $this->renderFormField = RelationBase::noConstraints(function() { + return $this->renderFormField = RelationBase::noConstraints(function () { $field = clone $this->formField; @@ -100,13 +110,12 @@ class Relation extends FormWidgetBase if (in_array($this->relationType, ['belongsToMany', 'morphToMany', 'morphedByMany'])) { $field->type = 'checkboxlist'; - } - else if ($this->relationType == 'belongsTo') { + } elseif ($this->relationType == 'belongsTo') { $field->type = 'dropdown'; $field->placeholder = $this->emptyOption; } - // It is safe to assume that if the model and related model are of + // It is safe to assume that if the model and related model are of // the exact same class, then it cannot be related to itself if ($model->exists && (get_class($model) == get_class($relatedObj))) { $query->where($relatedObj->getKeyName(), '<>', $model->getKey()); @@ -117,10 +126,11 @@ class Relation extends FormWidgetBase $query->getQuery()->getQuery()->joins = []; $treeTraits = ['October\Rain\Database\Traits\NestedTree', 'October\Rain\Database\Traits\SimpleTree']; - if (count(array_intersect($treeTraits, class_uses($relatedObj))) > 0) + if (count(array_intersect($treeTraits, class_uses($relatedObj))) > 0) { $field->options = $query->listsNested($this->nameFrom, $relatedObj->getKeyName()); - else + } else { $field->options = $query->lists($this->nameFrom, $relatedObj->getKeyName()); + } return $field; }); @@ -131,12 +141,14 @@ class Relation extends FormWidgetBase */ public function getSaveData($value) { - if (is_string($value) && !strlen($value)) + if (is_string($value) && !strlen($value)) { return null; + } - if (is_array($value) && !count($value)) + if (is_array($value) && !count($value)) { return null; + } return $value; } -} \ No newline at end of file +} diff --git a/modules/backend/formwidgets/RichEditor.php b/modules/backend/formwidgets/RichEditor.php index 4167a0432..5e626f7a6 100644 --- a/modules/backend/formwidgets/RichEditor.php +++ b/modules/backend/formwidgets/RichEditor.php @@ -61,4 +61,4 @@ class RichEditor extends FormWidgetBase $this->addJs('js/richeditor.js', 'core'); } -} \ No newline at end of file +} From 6ccf49bdd9c3e4993f5a16a1789011fde7653c33 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Fri, 10 Oct 2014 23:58:23 +0200 Subject: [PATCH 11/30] Updating modules/backend/lang --- modules/backend/lang/de/lang.php | 2 +- modules/backend/lang/fa/lang.php | 504 +++++++++++++++---------------- modules/backend/lang/sv/lang.php | 2 +- modules/backend/lang/tr/lang.php | 2 +- 4 files changed, 255 insertions(+), 255 deletions(-) diff --git a/modules/backend/lang/de/lang.php b/modules/backend/lang/de/lang.php index c9a1b0796..833d46a3a 100644 --- a/modules/backend/lang/de/lang.php +++ b/modules/backend/lang/de/lang.php @@ -166,7 +166,7 @@ return [ 'concurrency-file-changed-title' => 'Datei wurde geändert', 'concurrency-file-changed-description' => 'Die Datei, welche Sie bearbeiten, wurde auf von einem anderen Benutzer geändert. Sie können die Datei entweder erneut laden, wodurch Ihre Änderungen verloren gehen oder Sie überschreiben die Datei auf dem Server', 'reload' => 'Erneut laden', - ], + ], 'relation' => [ 'missing_definition' => "Verhalten (behaviour) der Verbindung umfasst keine Definition für ':field'.", 'missing_model' => "Verhalten (behaviour) der Verbindung, die in :class benutzt wird, hat kein definiertes Model", diff --git a/modules/backend/lang/fa/lang.php b/modules/backend/lang/fa/lang.php index 96571f99d..4ca8d61c8 100644 --- a/modules/backend/lang/fa/lang.php +++ b/modules/backend/lang/fa/lang.php @@ -1,256 +1,256 @@ [ - 'invalid_type' => 'نوع فیلد :type نا معتبر می باشد.', - 'options_method_not_exists' => 'کلاس مدل :model باید شامل متد :method() باشد و گزینه های مورد نیاز ":field" را بازگرداند.', - ], - 'widget' => [ - 'not_registered' => "کلاس مربوط به ابزارک ':name' به سیستم معرفی نشده است", - 'not_bound' => "ابزارکی تعریف شده در کلاس با نام ':name' به هیچ کنترلری ارتباط داده نشده است", - ], - 'page' => [ - 'untitled' => "بدون عنوان", - 'access_denied' => [ - 'label' => "شما مجوز دسترسی ندارید", - 'help' => "شما مجوز لازم براس دسترسی به این صفحه را ندارید.", - 'cms_link' => "بازگشت به مدیریت", - ], - ], - 'partial' => [ - 'not_found' => "بخشی با نام ':name' یافت نشد.", - ], - 'account' => [ - 'sign_out' => 'خروج', - 'login' => 'ورود', - 'reset' => 'تنظیم مجدد', - 'restore' => 'بازگرداندن', - 'login_placeholder' => 'ورود', - 'password_placeholder' => 'کلمه عبور', - 'forgot_password' => "کلمه عبور خود را فراموش کرده اید؟", - 'enter_email' => "پست الکترونیکی خود را وارد نمایید", - 'enter_login' => "نام کاربری خود را وارد نمایید", - 'email_placeholder' => "پست الکترونیکی", - 'enter_new_password' => "کلمه عبور جدید را وارد نمایید", - 'password_reset' => "بازگرداندن کلمه عبور", - 'restore_success' => "یک نامه به پست الکترونیکی شما جهت شروع عملیات بارگرداندن کلمه عبور ارسال شد.", - 'restore_error' => "کاربری با نام کاریری ':login' یافت نشد.", - 'reset_success' => "کلمه عبور شما بارگردانی شد و شما هم اکنون میتوانید وارد سیستم شوید.", - 'reset_error' => "اطلاعات رمز عبور نا معتبر است , لطفا مجددا تلاش نمایید!", - 'reset_fail' => "عدم توانایی در بازگرداندن کلمه عبور شما!", - 'apply' => 'اعمال کردن', - 'cancel' => 'انصراف', - 'delete' => 'حذف', - 'ok' => 'تایید', - ], - 'dashboard' => [ - 'menu_label' => 'میز کار', - 'widget_label' => 'ابزارک', - 'widget_width' => 'عرض', - 'full_width' => 'عرض کامل', - 'add_widget' => 'افزودن ابزارک', - 'widget_inspector_title' => 'تنظیمات ابزارک', - 'widget_inspector_description' => 'پیکر بندی ابزارک گزارشگیری', - 'widget_columns_label' => 'عرض :columns', - 'widget_columns_description' => 'عرض ابزارک باید عددی مابین 1 تا 10 باشد.', - 'widget_columns_error' => 'لطفا عرض ابزارک را عددی مابین 1 تا 10 وارد نمایید.', - 'columns' => '{1} ستون|[2,Inf] ستون ها', - 'widget_new_row_label' => 'تحمیل سطر جدید', - 'widget_new_row_description' => 'افزودن ابزارک در سطر جدید.', - 'widget_title_label' => 'عنوان ابزارک', - 'widget_title_error' => 'گزینه "عنوان ابزارک" حتما باید وارد شود.', - 'status' => [ - 'widget_title_default' => 'وضعیت سیستم', - 'online' => 'online', - 'update_available' => '{0} به روز رسانی موجود است!|{1} به روز رسانی موجود است!|[2,Inf] به روز رسانی موجود است!', - ] - ], - 'user' => [ - 'name' => 'مدیریت', - 'menu_label' => 'مدیران', - 'menu_description' => 'مدیریت کاربران , گروه ها و دسترسی های مدیران.', - 'list_title' => 'مدیریت مدیران', - 'new' => 'مدیر جدید', - 'login' => "ورود", - 'first_name' => "نام", - 'last_name' => "نام خانوادگی", - 'full_name' => "نام کامل", - 'email' => "پست الکترونیکی", - 'groups' => "گروه ها", - 'groups_comment' => "مختص گروهی که این شخص به آن تعلق دارد.", - 'avatar' => "نمایه", - 'password' => "کلمه عبور", - 'password_confirmation' => "تکرار کلمه عبور", - 'superuser' => "کاربر ممتاز", - 'superuser_comment' => "اگر میخواهید این شخص به تمام قسمت ها دسترسی داشته باشد این گزینه را فعال نمایید.", - 'send_invite' => 'دعوت نامه توسط پست الکترونیکی ارسال شود', - 'send_invite_comment' => 'جهت ارسال دعوت نامه به پست الکترونیکی این شخص این گزینه را فعال نمایید', - 'delete_confirm' => 'آیا از حذف این مدیر اطمینان دارید؟', - 'return' => 'بازگشت به لیست مدیران', - 'allow' => 'اجازه دسترسی', - 'inherit' => 'ارث بری', - 'deny' => 'عدم دسترسی', - 'group' => [ - 'name' => 'گروه', - 'name_field' => 'نام', - 'menu_label' => 'گروه ها', - 'list_title' => 'مدیریت گروه ها', - 'new' => 'گروه مدیریت جدید', - 'delete_confirm' => 'آیا از حذف این گروه از مدیران اطمینان دارید?', - 'return' => 'بازگشت به لیست گروه ها', - ], - 'preferences' => [ - 'not_authenticated' => 'هیچ کاربر ثبت شده ای جهت بارگذاری یا ذخیره تنظیمات وجود ندارد.' - ] - ], - 'list' => [ - 'default_title' => 'لیست', - 'search_prompt' => 'جستجو...', - 'no_records' => 'چیزی یافت نشد.', - 'missing_model' => 'هیچ مدلی برای لیست استفاده شده در کلاس :class تعریف نشده است.', - 'missing_column' => 'ستونی برای :columns تعریف نشده است.', - 'missing_columns' => 'ستونی برای لیست عریف شده در :class موجود نیست.', - 'missing_definition' => "در لیست تعریف شده ستونی برای ':field' موجود نیست.", - 'behavior_not_ready' => 'لسیت مقدار دهی اولیه شده است ، لطفا بررسی نمایید که متد makeLists() در کنترلر خود فراخوانی کرده باشید.', - 'invalid_column_datetime' => "ستون ':column' از نوع شی تاریخ نمی باشد ، لطفا بررسی نمایید که این ستون در مدل از نوع تاریخ تعریف شده باشد.", - 'pagination' => 'نمایش :from تا :to از :total مورد', - 'prev_page' => 'صفحه قبل', - 'next_page' => 'صفحه بعد', - 'loading' => 'در حال بارگذاری...', - 'setup_title' => 'راه اندازی لیست', - 'setup_help' => 'ستون هایی را که میخواهید مشاهده نمایید را انتخاب نمایید. میتوانید محل قرار گیری ستونها را با جابجا نمودن آنها به .', - 'records_per_page' => 'مورد در هر صفحه', - 'records_per_page_help' => 'تعداد موارد نمایش داده شده در هر صفحه را انتخاب نمایید. لطفا توجه نمایید نمایش تعداد زیادی از موارد در هر صفحه از کارایی سیستم میکاهد.' - ], - 'fileupload' => [ - 'attachment' => 'فایل ضمیمه', - 'help' => 'برای فایل ضمیمه عنوان و توضیح مختصری وارد نمایید.', - 'title_label' => 'عنوان', - 'description_label' => 'توضیحات' - ], - 'form' => [ - 'create_title' => ":name جدید", - 'update_title' => "ویرایش :name", - 'preview_title' => "پیش نمایش :name", - 'create_success' => ':name با موفقیت ایجاد شد.', - 'update_success' => ':name با موفقیت به روز رسانی شد.', - 'delete_success' => ':name با موفقیت حذف شد.', - 'missing_id' => "رکورد مشخصه (ID) برای فرم انتخاب نشده است.", - 'missing_model' => 'مدلی برای فرن تعریف شده در کلاس :class مشخص نشده است.', - 'missing_definition' => "فرم مورد نظر شامل فیلدی برای ':field' نمی باشد.", - 'not_found' => 'فرمی با مشخصه :id یافت نشد.', - 'create' => 'ایجاد', - 'create_and_close' => 'ایجاد و خروج', - 'creating' => 'در حال ایجاد...', - 'save' => 'ذخیره', - 'save_and_close' => 'ذخیره و خروج', - 'saving' => 'در حال ذخیره...', - 'delete' => 'حذف', - 'deleting' => 'در حال حذف...', - 'undefined_tab' => 'متفرقه', - 'field_off' => 'خاموش', - 'field_on' => 'روشن', - 'add' => 'افزودن', - 'apply' => 'اعمال', - 'cancel' => 'انصراف', - 'close' => 'خروج', - 'ok' => 'تایید', - 'or' => 'یا', - 'confirm_tab_close' => 'در صورت بستن این پنجره موارد ذخیره نشده از بین خواهند رفت. آیا از حذف شدن این پنجره اطمینان دارید؟', - 'behavior_not_ready' => 'فرم مور نظر مقدار دهی اولیه نشده است ، بررسی کنید که متد initForm() در کنترلر فرتخوانی شده باشد.', - 'preview_no_files_message' => 'فایل ها ارسال نشدند', - 'select' => 'انتخاب', - 'select_all' => 'همه', - 'select_none' => 'هیچ', - 'select_placeholder' => 'لطفا انتخاب نمایید', - 'insert_row' => 'افزودن سطر', - 'delete_row' => 'حذف سطر', - 'concurrency-file-changed-title' => 'فایل تغییر کرد', - 'concurrency-file-changed-description' => 'فایلی که شما ویرایش کردید توسط کاربر دیگری تغییر یافته و ذخیره شده است. شما میتوانید فایل را مجددا بارگذاری نمایید و تغییراتی که اعمال کرده اید را از دست بدهید و یا تغییرات اعمال شده توسط آن کاربر را بین برده و فایل را بازنویسی نمایید.', - 'reload' => 'بارگذاری مجدد', - ], - 'relation' => [ - 'missing_definition' => "در ارتباط مورد نظر فیلد ':field' وجود ندارد.", - 'missing_model' => "مدلی برای ارتباط موجود در :class وجود ندارد.", - 'invalid_action_single' => "این عمل در ارتباط یک تعرفه نمبتواند اعمال شود.", - 'invalid_action_multi' => "این عمل در ارتباط چند طرفه نمیتواند اعمال شود.", - 'help' => "بر روی یک گزینه کلیک کنید تا افزوده شود", - 'related_data' => "اعلاعات :name مرتبط", - 'add' => "افزودن", - 'add_selected' => "افرودن انتخاب شده ها", - 'add_a_new' => ":name جدید", - 'cancel' => "انصراف", - 'add_name' => "افزودن :name", - 'create' => "ایجاد", - 'create_name' => "ایجاد :name", - 'update' => "بروز رسانی", - 'update_name' => "بروز رسانی :name", - 'remove' => "حذف", - 'remove_name' => "حذف :name", - 'delete' => "حذف", - 'delete_name' => "حذف :name", - 'delete_confirm' => "آیا اطمینان دارید؟", - ], - 'model' => [ - 'name' => "مدل", - 'not_found' => "مدل ':class' با مشخصه ی :id یافت نشد", - 'missing_id' => "مشخصه ای برای مودل مورد نظر یافت نشد.", - 'missing_relation' => "مدل ':class' شامل تعریفی از ':relation'.", - 'invalid_class' => "مدل :model استفاده شده در :class معتبر نمی باشد، این مدل باید از کلاس \Model ارث برده باشد.", - 'mass_assignment_failed' => "Mass assignment failed for Model attribute ':attribute'.", - ], - 'warnings' => [ - 'tips' => 'راهنمایی پیکر بندی سیستم', - 'tips_description' => 'مشکلاتی در پیکربندی سیستم وجود دارد، شما باید تنظیمات زیر را بررسی نمایید.', - 'permissions' => 'پوشه :name یا یکی از زیر پوشه های آن برای PHP قابل نوشتن نیستند. لطفا تنظیمات این پوشه را تعییر دهید.', - 'extension' => 'افزونه PHP با نام :name نصب نشده است. لطفن این افزونه را نصب کرده و فعال نمایید.' - ], - 'editor' => [ - 'menu_label' => 'تنظیمات ویرایشگر کد', - 'menu_description' => 'سفارشی سازی ویرایشگر کد، مانند اندازه فونت و رنگ بندی آن.', - 'font_size' => 'اندازه فونت', - 'tab_size' => 'اندازه کاراکتر TAB', - 'use_hard_tabs' => 'فاصله گذاری با استفاده از TAB', - 'code_folding' => 'بلاک بندی کدها', - 'word_wrap' => 'چیدمان کلمات', - 'highlight_active_line' => 'مشخص نودن خط فعال', - 'show_invisibles' => 'نمایش کاراکتر های مخفی', - 'show_gutter' => 'نمایش نشانگر', - 'theme' => 'رنگ بندی', - ], - 'tooltips' => [ - 'preview_website' => 'پیش نماسش وب سایت' - ], - 'mysettings' => [ - 'menu_label' => 'تنظیمات من', - 'menu_description' => 'تنظیمات مربوط به حساب کاربری شما', - ], - 'myaccount' => [ - 'menu_label' => 'حساب کاربری من', - 'menu_description' => 'به روز رسانی اطلاعات حساب کار بری شما مانند نام و کلمه عبور و ... .', - 'menu_keywords' => 'ورود امن' - ], - 'backend_preferences' => [ - 'menu_label' => 'تنظیمات مدیریت', - 'menu_description' => 'تنظیمات مربوط به زبان مربوط به قسمت مدیریت.', - 'locale' => 'زبان', - 'locale_comment' => 'زبان مورد نظر خود را انتخاب نمایید.', - ], - 'access_log' => [ - 'hint' => 'این لیست نشاندهنده ورود کاربران مدیر به سیستم می باشد. موارد برای مدت :days روز نگهداری می شوند.', - 'menu_label' => 'ثبت دسترسی ها', - 'menu_description' => 'نمایش لیست ورود موفقیت آمیز کاربران مدیر.', - 'created_at' => 'زمان و تاریخ', - 'login' => 'ورود', - 'ip_address' => 'آدرس آی پی', - 'first_name' => 'نام', - 'last_name' => 'نام خوانوادگی', - 'email' => 'پست الکترونیکی', - ], - 'filter' => [ - 'all' => 'همه' - ], - 'layout' => [ - 'direction' => 'rtl' - ] + 'field' => [ + 'invalid_type' => 'نوع فیلد :type نا معتبر می باشد.', + 'options_method_not_exists' => 'کلاس مدل :model باید شامل متد :method() باشد و گزینه های مورد نیاز ":field" را بازگرداند.', + ], + 'widget' => [ + 'not_registered' => "کلاس مربوط به ابزارک ':name' به سیستم معرفی نشده است", + 'not_bound' => "ابزارکی تعریف شده در کلاس با نام ':name' به هیچ کنترلری ارتباط داده نشده است", + ], + 'page' => [ + 'untitled' => "بدون عنوان", + 'access_denied' => [ + 'label' => "شما مجوز دسترسی ندارید", + 'help' => "شما مجوز لازم براس دسترسی به این صفحه را ندارید.", + 'cms_link' => "بازگشت به مدیریت", + ], + ], + 'partial' => [ + 'not_found' => "بخشی با نام ':name' یافت نشد.", + ], + 'account' => [ + 'sign_out' => 'خروج', + 'login' => 'ورود', + 'reset' => 'تنظیم مجدد', + 'restore' => 'بازگرداندن', + 'login_placeholder' => 'ورود', + 'password_placeholder' => 'کلمه عبور', + 'forgot_password' => "کلمه عبور خود را فراموش کرده اید؟", + 'enter_email' => "پست الکترونیکی خود را وارد نمایید", + 'enter_login' => "نام کاربری خود را وارد نمایید", + 'email_placeholder' => "پست الکترونیکی", + 'enter_new_password' => "کلمه عبور جدید را وارد نمایید", + 'password_reset' => "بازگرداندن کلمه عبور", + 'restore_success' => "یک نامه به پست الکترونیکی شما جهت شروع عملیات بارگرداندن کلمه عبور ارسال شد.", + 'restore_error' => "کاربری با نام کاریری ':login' یافت نشد.", + 'reset_success' => "کلمه عبور شما بارگردانی شد و شما هم اکنون میتوانید وارد سیستم شوید.", + 'reset_error' => "اطلاعات رمز عبور نا معتبر است , لطفا مجددا تلاش نمایید!", + 'reset_fail' => "عدم توانایی در بازگرداندن کلمه عبور شما!", + 'apply' => 'اعمال کردن', + 'cancel' => 'انصراف', + 'delete' => 'حذف', + 'ok' => 'تایید', + ], + 'dashboard' => [ + 'menu_label' => 'میز کار', + 'widget_label' => 'ابزارک', + 'widget_width' => 'عرض', + 'full_width' => 'عرض کامل', + 'add_widget' => 'افزودن ابزارک', + 'widget_inspector_title' => 'تنظیمات ابزارک', + 'widget_inspector_description' => 'پیکر بندی ابزارک گزارشگیری', + 'widget_columns_label' => 'عرض :columns', + 'widget_columns_description' => 'عرض ابزارک باید عددی مابین 1 تا 10 باشد.', + 'widget_columns_error' => 'لطفا عرض ابزارک را عددی مابین 1 تا 10 وارد نمایید.', + 'columns' => '{1} ستون|[2,Inf] ستون ها', + 'widget_new_row_label' => 'تحمیل سطر جدید', + 'widget_new_row_description' => 'افزودن ابزارک در سطر جدید.', + 'widget_title_label' => 'عنوان ابزارک', + 'widget_title_error' => 'گزینه "عنوان ابزارک" حتما باید وارد شود.', + 'status' => [ + 'widget_title_default' => 'وضعیت سیستم', + 'online' => 'online', + 'update_available' => '{0} به روز رسانی موجود است!|{1} به روز رسانی موجود است!|[2,Inf] به روز رسانی موجود است!', + ] + ], + 'user' => [ + 'name' => 'مدیریت', + 'menu_label' => 'مدیران', + 'menu_description' => 'مدیریت کاربران , گروه ها و دسترسی های مدیران.', + 'list_title' => 'مدیریت مدیران', + 'new' => 'مدیر جدید', + 'login' => "ورود", + 'first_name' => "نام", + 'last_name' => "نام خانوادگی", + 'full_name' => "نام کامل", + 'email' => "پست الکترونیکی", + 'groups' => "گروه ها", + 'groups_comment' => "مختص گروهی که این شخص به آن تعلق دارد.", + 'avatar' => "نمایه", + 'password' => "کلمه عبور", + 'password_confirmation' => "تکرار کلمه عبور", + 'superuser' => "کاربر ممتاز", + 'superuser_comment' => "اگر میخواهید این شخص به تمام قسمت ها دسترسی داشته باشد این گزینه را فعال نمایید.", + 'send_invite' => 'دعوت نامه توسط پست الکترونیکی ارسال شود', + 'send_invite_comment' => 'جهت ارسال دعوت نامه به پست الکترونیکی این شخص این گزینه را فعال نمایید', + 'delete_confirm' => 'آیا از حذف این مدیر اطمینان دارید؟', + 'return' => 'بازگشت به لیست مدیران', + 'allow' => 'اجازه دسترسی', + 'inherit' => 'ارث بری', + 'deny' => 'عدم دسترسی', + 'group' => [ + 'name' => 'گروه', + 'name_field' => 'نام', + 'menu_label' => 'گروه ها', + 'list_title' => 'مدیریت گروه ها', + 'new' => 'گروه مدیریت جدید', + 'delete_confirm' => 'آیا از حذف این گروه از مدیران اطمینان دارید?', + 'return' => 'بازگشت به لیست گروه ها', + ], + 'preferences' => [ + 'not_authenticated' => 'هیچ کاربر ثبت شده ای جهت بارگذاری یا ذخیره تنظیمات وجود ندارد.' + ] + ], + 'list' => [ + 'default_title' => 'لیست', + 'search_prompt' => 'جستجو...', + 'no_records' => 'چیزی یافت نشد.', + 'missing_model' => 'هیچ مدلی برای لیست استفاده شده در کلاس :class تعریف نشده است.', + 'missing_column' => 'ستونی برای :columns تعریف نشده است.', + 'missing_columns' => 'ستونی برای لیست عریف شده در :class موجود نیست.', + 'missing_definition' => "در لیست تعریف شده ستونی برای ':field' موجود نیست.", + 'behavior_not_ready' => 'لسیت مقدار دهی اولیه شده است ، لطفا بررسی نمایید که متد makeLists() در کنترلر خود فراخوانی کرده باشید.', + 'invalid_column_datetime' => "ستون ':column' از نوع شی تاریخ نمی باشد ، لطفا بررسی نمایید که این ستون در مدل از نوع تاریخ تعریف شده باشد.", + 'pagination' => 'نمایش :from تا :to از :total مورد', + 'prev_page' => 'صفحه قبل', + 'next_page' => 'صفحه بعد', + 'loading' => 'در حال بارگذاری...', + 'setup_title' => 'راه اندازی لیست', + 'setup_help' => 'ستون هایی را که میخواهید مشاهده نمایید را انتخاب نمایید. میتوانید محل قرار گیری ستونها را با جابجا نمودن آنها به .', + 'records_per_page' => 'مورد در هر صفحه', + 'records_per_page_help' => 'تعداد موارد نمایش داده شده در هر صفحه را انتخاب نمایید. لطفا توجه نمایید نمایش تعداد زیادی از موارد در هر صفحه از کارایی سیستم میکاهد.' + ], + 'fileupload' => [ + 'attachment' => 'فایل ضمیمه', + 'help' => 'برای فایل ضمیمه عنوان و توضیح مختصری وارد نمایید.', + 'title_label' => 'عنوان', + 'description_label' => 'توضیحات' + ], + 'form' => [ + 'create_title' => ":name جدید", + 'update_title' => "ویرایش :name", + 'preview_title' => "پیش نمایش :name", + 'create_success' => ':name با موفقیت ایجاد شد.', + 'update_success' => ':name با موفقیت به روز رسانی شد.', + 'delete_success' => ':name با موفقیت حذف شد.', + 'missing_id' => "رکورد مشخصه (ID) برای فرم انتخاب نشده است.", + 'missing_model' => 'مدلی برای فرن تعریف شده در کلاس :class مشخص نشده است.', + 'missing_definition' => "فرم مورد نظر شامل فیلدی برای ':field' نمی باشد.", + 'not_found' => 'فرمی با مشخصه :id یافت نشد.', + 'create' => 'ایجاد', + 'create_and_close' => 'ایجاد و خروج', + 'creating' => 'در حال ایجاد...', + 'save' => 'ذخیره', + 'save_and_close' => 'ذخیره و خروج', + 'saving' => 'در حال ذخیره...', + 'delete' => 'حذف', + 'deleting' => 'در حال حذف...', + 'undefined_tab' => 'متفرقه', + 'field_off' => 'خاموش', + 'field_on' => 'روشن', + 'add' => 'افزودن', + 'apply' => 'اعمال', + 'cancel' => 'انصراف', + 'close' => 'خروج', + 'ok' => 'تایید', + 'or' => 'یا', + 'confirm_tab_close' => 'در صورت بستن این پنجره موارد ذخیره نشده از بین خواهند رفت. آیا از حذف شدن این پنجره اطمینان دارید؟', + 'behavior_not_ready' => 'فرم مور نظر مقدار دهی اولیه نشده است ، بررسی کنید که متد initForm() در کنترلر فرتخوانی شده باشد.', + 'preview_no_files_message' => 'فایل ها ارسال نشدند', + 'select' => 'انتخاب', + 'select_all' => 'همه', + 'select_none' => 'هیچ', + 'select_placeholder' => 'لطفا انتخاب نمایید', + 'insert_row' => 'افزودن سطر', + 'delete_row' => 'حذف سطر', + 'concurrency-file-changed-title' => 'فایل تغییر کرد', + 'concurrency-file-changed-description' => 'فایلی که شما ویرایش کردید توسط کاربر دیگری تغییر یافته و ذخیره شده است. شما میتوانید فایل را مجددا بارگذاری نمایید و تغییراتی که اعمال کرده اید را از دست بدهید و یا تغییرات اعمال شده توسط آن کاربر را بین برده و فایل را بازنویسی نمایید.', + 'reload' => 'بارگذاری مجدد', + ], + 'relation' => [ + 'missing_definition' => "در ارتباط مورد نظر فیلد ':field' وجود ندارد.", + 'missing_model' => "مدلی برای ارتباط موجود در :class وجود ندارد.", + 'invalid_action_single' => "این عمل در ارتباط یک تعرفه نمبتواند اعمال شود.", + 'invalid_action_multi' => "این عمل در ارتباط چند طرفه نمیتواند اعمال شود.", + 'help' => "بر روی یک گزینه کلیک کنید تا افزوده شود", + 'related_data' => "اعلاعات :name مرتبط", + 'add' => "افزودن", + 'add_selected' => "افرودن انتخاب شده ها", + 'add_a_new' => ":name جدید", + 'cancel' => "انصراف", + 'add_name' => "افزودن :name", + 'create' => "ایجاد", + 'create_name' => "ایجاد :name", + 'update' => "بروز رسانی", + 'update_name' => "بروز رسانی :name", + 'remove' => "حذف", + 'remove_name' => "حذف :name", + 'delete' => "حذف", + 'delete_name' => "حذف :name", + 'delete_confirm' => "آیا اطمینان دارید؟", + ], + 'model' => [ + 'name' => "مدل", + 'not_found' => "مدل ':class' با مشخصه ی :id یافت نشد", + 'missing_id' => "مشخصه ای برای مودل مورد نظر یافت نشد.", + 'missing_relation' => "مدل ':class' شامل تعریفی از ':relation'.", + 'invalid_class' => "مدل :model استفاده شده در :class معتبر نمی باشد، این مدل باید از کلاس \Model ارث برده باشد.", + 'mass_assignment_failed' => "Mass assignment failed for Model attribute ':attribute'.", + ], + 'warnings' => [ + 'tips' => 'راهنمایی پیکر بندی سیستم', + 'tips_description' => 'مشکلاتی در پیکربندی سیستم وجود دارد، شما باید تنظیمات زیر را بررسی نمایید.', + 'permissions' => 'پوشه :name یا یکی از زیر پوشه های آن برای PHP قابل نوشتن نیستند. لطفا تنظیمات این پوشه را تعییر دهید.', + 'extension' => 'افزونه PHP با نام :name نصب نشده است. لطفن این افزونه را نصب کرده و فعال نمایید.' + ], + 'editor' => [ + 'menu_label' => 'تنظیمات ویرایشگر کد', + 'menu_description' => 'سفارشی سازی ویرایشگر کد، مانند اندازه فونت و رنگ بندی آن.', + 'font_size' => 'اندازه فونت', + 'tab_size' => 'اندازه کاراکتر TAB', + 'use_hard_tabs' => 'فاصله گذاری با استفاده از TAB', + 'code_folding' => 'بلاک بندی کدها', + 'word_wrap' => 'چیدمان کلمات', + 'highlight_active_line' => 'مشخص نودن خط فعال', + 'show_invisibles' => 'نمایش کاراکتر های مخفی', + 'show_gutter' => 'نمایش نشانگر', + 'theme' => 'رنگ بندی', + ], + 'tooltips' => [ + 'preview_website' => 'پیش نماسش وب سایت' + ], + 'mysettings' => [ + 'menu_label' => 'تنظیمات من', + 'menu_description' => 'تنظیمات مربوط به حساب کاربری شما', + ], + 'myaccount' => [ + 'menu_label' => 'حساب کاربری من', + 'menu_description' => 'به روز رسانی اطلاعات حساب کار بری شما مانند نام و کلمه عبور و ... .', + 'menu_keywords' => 'ورود امن' + ], + 'backend_preferences' => [ + 'menu_label' => 'تنظیمات مدیریت', + 'menu_description' => 'تنظیمات مربوط به زبان مربوط به قسمت مدیریت.', + 'locale' => 'زبان', + 'locale_comment' => 'زبان مورد نظر خود را انتخاب نمایید.', + ], + 'access_log' => [ + 'hint' => 'این لیست نشاندهنده ورود کاربران مدیر به سیستم می باشد. موارد برای مدت :days روز نگهداری می شوند.', + 'menu_label' => 'ثبت دسترسی ها', + 'menu_description' => 'نمایش لیست ورود موفقیت آمیز کاربران مدیر.', + 'created_at' => 'زمان و تاریخ', + 'login' => 'ورود', + 'ip_address' => 'آدرس آی پی', + 'first_name' => 'نام', + 'last_name' => 'نام خوانوادگی', + 'email' => 'پست الکترونیکی', + ], + 'filter' => [ + 'all' => 'همه' + ], + 'layout' => [ + 'direction' => 'rtl' + ] ]; diff --git a/modules/backend/lang/sv/lang.php b/modules/backend/lang/sv/lang.php index f9b2a011f..968916ef5 100644 --- a/modules/backend/lang/sv/lang.php +++ b/modules/backend/lang/sv/lang.php @@ -164,4 +164,4 @@ return [ 'show_gutter' => 'Show gutter', 'theme' => 'Color scheme', ], -]; \ No newline at end of file +]; diff --git a/modules/backend/lang/tr/lang.php b/modules/backend/lang/tr/lang.php index d5b310e25..ccc657d75 100644 --- a/modules/backend/lang/tr/lang.php +++ b/modules/backend/lang/tr/lang.php @@ -164,4 +164,4 @@ return [ 'show_gutter' => 'Show gutter', 'theme' => 'Color scheme', ], -]; \ No newline at end of file +]; From 07a0a7e428b3f3c3a240ddc06d95cfbc7e86c11a Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 00:04:51 +0200 Subject: [PATCH 12/30] Updating modules/backend/models --- modules/backend/models/AccessLog.php | 3 +-- modules/backend/models/EditorPreferences.php | 2 +- modules/backend/models/User.php | 20 ++++++++++++-------- modules/backend/models/UserPreferences.php | 3 ++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/backend/models/AccessLog.php b/modules/backend/models/AccessLog.php index 1399988b3..060530b99 100644 --- a/modules/backend/models/AccessLog.php +++ b/modules/backend/models/AccessLog.php @@ -37,5 +37,4 @@ class AccessLog extends Model return $record; } - -} \ No newline at end of file +} diff --git a/modules/backend/models/EditorPreferences.php b/modules/backend/models/EditorPreferences.php index 695aa9d63..6ba12eafe 100644 --- a/modules/backend/models/EditorPreferences.php +++ b/modules/backend/models/EditorPreferences.php @@ -73,4 +73,4 @@ class EditorPreferences extends Model asort($themes); return [static::DEFAULT_THEME => ucwords(static::DEFAULT_THEME)] + $themes; } -} \ No newline at end of file +} diff --git a/modules/backend/models/User.php b/modules/backend/models/User.php index 30af0514f..219a24580 100644 --- a/modules/backend/models/User.php +++ b/modules/backend/models/User.php @@ -66,8 +66,9 @@ class User extends UserBase // return parent::getPersistCode(); // Option B: - if (!$this->persist_code) + if (!$this->persist_code) { return parent::getPersistCode(); + } return $this->persist_code; } @@ -77,18 +78,23 @@ class User extends UserBase */ public function getAvatarThumb($size = 25, $default = null) { - if ($this->avatar) + if ($this->avatar) { return $this->avatar->getThumb($size, $size); - else - return '//www.gravatar.com/avatar/' . md5(strtolower(trim($this->email))) . '?s='.$size.'&d='.urlencode($default); + } else { + return '//www.gravatar.com/avatar/'. + md5(strtolower(trim($this->email))) . + '?s='. $size . + '&d='. urlencode($default); + } } public function afterCreate() { $this->restorePurgedValues(); - if ($this->send_invite) + if ($this->send_invite) { $this->sendInvitation(); + } } public function sendInvitation() @@ -100,10 +106,8 @@ class User extends UserBase 'link' => Backend::url('backend'), ]; - Mail::send('backend::mail.invite', $data, function($message) - { + Mail::send('backend::mail.invite', $data, function ($message) { $message->to($this->email, $this->full_name); }); } - } diff --git a/modules/backend/models/UserPreferences.php b/modules/backend/models/UserPreferences.php index 181e267ff..3e812deca 100644 --- a/modules/backend/models/UserPreferences.php +++ b/modules/backend/models/UserPreferences.php @@ -31,8 +31,9 @@ class UserPreferences extends PreferencesBase public function resolveUser($user) { $user = BackendAuth::getUser(); - if (!$user) + if (!$user) { throw new SystemException(trans('backend::lang.user.preferences.not_authenticated')); + } return $user; } From 75510ed4de659078a6e8481ca718480850019348 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 00:05:35 +0200 Subject: [PATCH 13/30] Updating modules/backend/skins --- modules/backend/skins/Standard.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/backend/skins/Standard.php b/modules/backend/skins/Standard.php index 4e5a7dadf..cef01de75 100644 --- a/modules/backend/skins/Standard.php +++ b/modules/backend/skins/Standard.php @@ -54,5 +54,4 @@ class Standard extends Skin { return [$this->skinPath.'/layouts']; } - -} \ No newline at end of file +} From aa68d163a088d01bc4d7d8be69f84cab9f90e552 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 00:07:30 +0200 Subject: [PATCH 14/30] Updating modules/backend/traits --- modules/backend/traits/CollapsableWidget.php | 11 +++++++---- modules/backend/traits/InspectableContainer.php | 16 ++++++++++------ modules/backend/traits/SearchableWidget.php | 8 +++++--- modules/backend/traits/SelectableWidget.php | 11 +++++++---- modules/backend/traits/WidgetMaker.php | 2 +- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/modules/backend/traits/CollapsableWidget.php b/modules/backend/traits/CollapsableWidget.php index bab12cf07..737ec4a13 100644 --- a/modules/backend/traits/CollapsableWidget.php +++ b/modules/backend/traits/CollapsableWidget.php @@ -26,12 +26,14 @@ trait CollapsableWidget protected function getGroupStatuses() { - if ($this->groupStatusCache !== false) + if ($this->groupStatusCache !== false) { return $this->groupStatusCache; + } $groups = $this->getSession('groups', []); - if (!is_array($groups)) + if (!is_array($groups)) { return $this->groupStatusCache = []; + } return $this->groupStatusCache = $groups; } @@ -47,9 +49,10 @@ trait CollapsableWidget protected function getGroupStatus($group) { $statuses = $this->getGroupStatuses(); - if (array_key_exists($group, $statuses)) + if (array_key_exists($group, $statuses)) { return $statuses[$group]; + } return true; } -} \ No newline at end of file +} diff --git a/modules/backend/traits/InspectableContainer.php b/modules/backend/traits/InspectableContainer.php index 3b6eb64ca..e24f6b3e9 100644 --- a/modules/backend/traits/InspectableContainer.php +++ b/modules/backend/traits/InspectableContainer.php @@ -17,24 +17,28 @@ trait InspectableContainer public function onInspectableGetOptions() { $property = trim(Request::input('inspectorProperty')); - if (!$property) + if (!$property) { throw new ApplicationException('The property name is not specified.'); + } $className = trim(Request::input('inspectorClassName')); - if (!$className) + if (!$className) { throw new ApplicationException('The inspectable class name is not specified.'); + } $traitFound = in_array('System\Traits\PropertyContainer', class_uses_recursive($className)); - if (!$traitFound) + if (!$traitFound) { throw new ApplicationException('The options cannot be loaded for the specified class.'); + } $obj = new $className(null); $methodName = 'get'.ucfirst($property).'Options'; - if (method_exists($obj, $methodName)) + if (method_exists($obj, $methodName)) { $options = $obj->$methodName(); - else + } else { $options = $obj->getPropertyOptions($property); + } /* * Convert to array to retain the sort order in JavaScript @@ -48,4 +52,4 @@ trait InspectableContainer 'options' => $optionsArray ]; } -} \ No newline at end of file +} diff --git a/modules/backend/traits/SearchableWidget.php b/modules/backend/traits/SearchableWidget.php index c0cee99f7..50fe79da9 100644 --- a/modules/backend/traits/SearchableWidget.php +++ b/modules/backend/traits/SearchableWidget.php @@ -33,13 +33,15 @@ trait SearchableWidget { foreach ($words as $word) { $word = trim($word); - if (!strlen($word)) + if (!strlen($word)) { continue; + } - if (Str::contains(Str::lower($text), $word)) + if (Str::contains(Str::lower($text), $word)) { return true; + } } return false; } -} \ No newline at end of file +} diff --git a/modules/backend/traits/SelectableWidget.php b/modules/backend/traits/SelectableWidget.php index 855dbc2ea..a46ff130e 100644 --- a/modules/backend/traits/SelectableWidget.php +++ b/modules/backend/traits/SelectableWidget.php @@ -28,12 +28,14 @@ trait SelectableWidget protected function getSelectedItems() { - if ($this->selectedItemsCache !== false) + if ($this->selectedItemsCache !== false) { return $this->selectedItemsCache; + } $items = $this->getSession('selected', []); - if (!is_array($items)) + if (!is_array($items)) { return $this->selectedItemsCache = []; + } return $this->selectedItemsCache = $items; } @@ -54,9 +56,10 @@ trait SelectableWidget protected function isItemSelected($itemId) { $selectedItems = $this->getSelectedItems(); - if (!is_array($selectedItems) || !isset($selectedItems[$itemId])) + if (!is_array($selectedItems) || !isset($selectedItems[$itemId])) { return false; + } return $selectedItems[$itemId]; } -} \ No newline at end of file +} diff --git a/modules/backend/traits/WidgetMaker.php b/modules/backend/traits/WidgetMaker.php index e5a70ea89..d67540746 100644 --- a/modules/backend/traits/WidgetMaker.php +++ b/modules/backend/traits/WidgetMaker.php @@ -29,4 +29,4 @@ trait WidgetMaker $widget = $manager->makeWidget($class, $controller, $configuration); return $widget; } -} \ No newline at end of file +} From b64a744498ae580b03bf1481770ea54443f4e733 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 00:39:34 +0200 Subject: [PATCH 15/30] Updating modules/backend/widgets --- modules/backend/widgets/Filter.php | 57 +++-- modules/backend/widgets/Form.php | 241 ++++++++++++------- modules/backend/widgets/Grid.php | 33 ++- modules/backend/widgets/Lists.php | 246 +++++++++++++------- modules/backend/widgets/ReportContainer.php | 54 +++-- modules/backend/widgets/Search.php | 27 ++- modules/backend/widgets/Toolbar.php | 11 +- 7 files changed, 433 insertions(+), 236 deletions(-) diff --git a/modules/backend/widgets/Filter.php b/modules/backend/widgets/Filter.php index 4dc0a3776..4f3417bdb 100644 --- a/modules/backend/widgets/Filter.php +++ b/modules/backend/widgets/Filter.php @@ -102,8 +102,9 @@ class Filter extends WidgetBase { $this->defineFilterScopes(); - if (!$scope = post('scopeName')) + if (!$scope = post('scopeName')) { return; + } $scope = $this->getScope($scope); @@ -124,8 +125,9 @@ class Filter extends WidgetBase */ $params = func_get_args(); $result = $this->fireEvent('filter.update', [$params]); - if ($result && is_array($result)) + if ($result && is_array($result)) { return Util::arrayMerge($result); + } } /** @@ -137,8 +139,9 @@ class Filter extends WidgetBase $this->defineFilterScopes(); $searchQuery = post('search'); - if (!$scopeName = post('scopeName')) + if (!$scopeName = post('scopeName')) { return; + } $scope = $this->getScope($scopeName); $activeKeys = $scope->value ? array_keys($scope->value) : []; @@ -188,8 +191,9 @@ class Filter extends WidgetBase { $active = []; foreach ($availableOptions as $id => $option) { - if (!in_array($id, $activeKeys)) + if (!in_array($id, $activeKeys)) { continue; + } $active[$id] = $option; unset($availableOptions[$id]); @@ -204,8 +208,9 @@ class Filter extends WidgetBase protected function getOptionsFromModel($scope, $searchQuery = null) { $model = $this->scopeModels[$scope->scopeName]; - if (!$searchQuery) + if (!$searchQuery) { return $model->all(); + } $searchFields = [$model->getKeyName(), $this->getScopeNameColumn($scope)]; return $model->searchWhere($searchQuery, $searchFields)->get(); @@ -216,8 +221,9 @@ class Filter extends WidgetBase */ protected function defineFilterScopes() { - if ($this->scopesDefined) + if ($this->scopesDefined) { return; + } /* * Extensibility @@ -228,8 +234,9 @@ class Filter extends WidgetBase /* * All scopes */ - if (!isset($this->config->scopes) || !is_array($this->config->scopes)) + if (!isset($this->config->scopes) || !is_array($this->config->scopes)) { $this->config->scopes = []; + } $this->addScopes($this->config->scopes); @@ -256,8 +263,9 @@ class Filter extends WidgetBase */ if ($scopeObj->context !== null) { $context = (is_array($scopeObj->context)) ? $scopeObj->context : [$scopeObj->context]; - if (!in_array($this->getContext(), $context)) + if (!in_array($this->getContext(), $context)) { continue; + } } /* @@ -318,11 +326,13 @@ class Filter extends WidgetBase */ public function applyScopeToQuery($scope, $query) { - if (is_string($scope)) + if (is_string($scope)) { $scope = $this->getScope($scope); + } - if (!$scope->value) + if (!$scope->value) { return; + } $value = is_array($scope->value) ? array_keys($scope->value) : $scope->value; @@ -331,11 +341,10 @@ class Filter extends WidgetBase */ if ($scopeConditions = $scope->conditions) { if (is_array($value)) { - $filtered = implode(',', array_build($value, function($key, $_value){ + $filtered = implode(',', array_build($value, function ($key, $_value) { return [$key, Db::getPdo()->quote($_value)]; })); - } - else { + } else { $filtered = Db::getPdo()->quote($value); } @@ -361,8 +370,9 @@ class Filter extends WidgetBase */ public function getScopeValue($scope, $default = null) { - if (is_string($scope)) + if (is_string($scope)) { $scope = $this->getScope($scope); + } $cacheKey = 'scope-'.$scope->scopeName; return $this->getSession($cacheKey, $default); @@ -373,8 +383,9 @@ class Filter extends WidgetBase */ public function setScopeValue($scope, $value) { - if (is_string($scope)) + if (is_string($scope)) { $scope = $this->getScope($scope); + } $cacheKey = 'scope-'.$scope->scopeName; $this->putSession($cacheKey, $value); @@ -398,8 +409,9 @@ class Filter extends WidgetBase */ public function getScope($scope) { - if (!isset($this->allScopes[$scope])) + if (!isset($this->allScopes[$scope])) { throw new ApplicationException('No definition for scope ' . $scope); + } return $this->allScopes[$scope]; } @@ -411,8 +423,9 @@ class Filter extends WidgetBase */ public function getScopeNameColumn($scope) { - if (is_string($scope)) + if (is_string($scope)) { $scope = $this->getScope($scope); + } return $scope->nameFrom; } @@ -451,14 +464,16 @@ class Filter extends WidgetBase protected function optionsFromAjax($options) { $processed = []; - if (!is_array($options)) + if (!is_array($options)) { return $processed; + } foreach ($options as $option) { - if (!$id = array_get($option, 'id')) continue; + if (!$id = array_get($option, 'id')) { + continue; + } $processed[$id] = array_get($option, 'name'); } return $processed; } - -} \ No newline at end of file +} diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 458f5872d..1cd753b24 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -140,9 +140,15 @@ class Form extends WidgetBase */ public function render($options = []) { - if (isset($options['preview'])) $this->previewMode = $options['preview']; - if (!isset($options['useContainer'])) $options['useContainer'] = true; - if (!isset($options['section'])) $options['section'] = null; + if (isset($options['preview'])) { + $this->previewMode = $options['preview']; + } + if (!isset($options['useContainer'])) { + $options['useContainer'] = true; + } + if (!isset($options['section'])) { + $options['section'] = null; + } $extraVars = []; $targetPartial = 'form'; @@ -153,10 +159,17 @@ class Form extends WidgetBase if ($section = $options['section']) { switch (strtolower($section)) { + case 'outside': + $sectionPartial = 'section_outside-fields'; + break; + case 'primary': + $sectionPartial = 'section_primary-tabs'; + break; + case 'secondary': + $sectionPartial = 'section_secondary-tabs'; + break; default: - case 'outside': $sectionPartial = 'section_outside-fields'; break; - case 'primary': $sectionPartial = 'section_primary-tabs'; break; - case 'secondary': $sectionPartial = 'section_secondary-tabs'; break; + break; } $targetPartial = $sectionPartial; @@ -180,13 +193,19 @@ class Form extends WidgetBase public function renderField($field, $options = []) { if (is_string($field)) { - if (!isset($this->fields[$field])) - throw new ApplicationException(Lang::get('backend::lang.form.missing_definition', compact('field'))); + if (!isset($this->fields[$field])) { + throw new ApplicationException(Lang::get( + 'backend::lang.form.missing_definition', + compact('field') + )); + } $field = $this->fields[$field]; } - if (!isset($options['useContainer'])) $options['useContainer'] = true; + if (!isset($options['useContainer'])) { + $options['useContainer'] = true; + } $targetPartial = $options['useContainer'] ? 'field-container' : 'field'; $this->prepareVars(); @@ -209,8 +228,12 @@ class Form extends WidgetBase { $this->model = $this->getConfig('model'); - if (!$this->model) - throw new ApplicationException(Lang::get('backend::lang.form.missing_model', ['class'=>get_class($this->controller)])); + if (!$this->model) { + throw new ApplicationException(Lang::get( + 'backend::lang.form.missing_model', + ['class'=>get_class($this->controller)] + )); + } $this->data = (object) $this->getConfig('data', $this->model); @@ -236,8 +259,9 @@ class Form extends WidgetBase */ public function setFormValues($data = null) { - if ($data == null) + if ($data == null) { $data = $this->getSaveData(); + } $this->model->fill($data); $this->data = (object) array_merge((array) $this->data, (array) $data); @@ -260,9 +284,12 @@ class Form extends WidgetBase /* * Extensibility */ - $eventResults = $this->fireEvent('form.beforeRefresh', [$saveData]) + Event::fire('backend.form.beforeRefresh', [$this, $saveData]); - foreach ($eventResults as $eventResult) + $eventResults = $this->fireEvent('form.beforeRefresh', [$saveData]) + + Event::fire('backend.form.beforeRefresh', [$this, $saveData]); + + foreach ($eventResults as $eventResult) { $saveData = $eventResult + $saveData; + } /* * Set the form variables and prepare the widget @@ -276,8 +303,9 @@ class Form extends WidgetBase if (($updateFields = post('fields')) && is_array($updateFields)) { foreach ($updateFields as $field) { - if (!isset($this->fields[$field])) + if (!isset($this->fields[$field])) { continue; + } $fieldObject = $this->fields[$field]; $result['#' . $fieldObject->getId('group')] = $this->makePartial('field', ['field' => $fieldObject]); @@ -287,15 +315,19 @@ class Form extends WidgetBase /* * Update the whole form */ - if (empty($result)) + if (empty($result)) { $result = ['#'.$this->getId() => $this->makePartial('form')]; + } /* * Extensibility */ - $eventResults = $this->fireEvent('form.refresh', [$result]) + Event::fire('backend.form.refresh', [$this, $result]); - foreach ($eventResults as $eventResult) + $eventResults = $this->fireEvent('form.refresh', [$result]) + + Event::fire('backend.form.refresh', [$this, $result]); + + foreach ($eventResults as $eventResult) { $result = $eventResult + $result; + } return $result; } @@ -306,8 +338,9 @@ class Form extends WidgetBase */ protected function defineFormFields() { - if ($this->fieldsDefined) + if ($this->fieldsDefined) { return; + } /* * Extensibility @@ -318,24 +351,27 @@ class Form extends WidgetBase /* * Outside fields */ - if (!isset($this->config->fields) || !is_array($this->config->fields)) + if (!isset($this->config->fields) || !is_array($this->config->fields)) { $this->config->fields = []; + } $this->addFields($this->config->fields); /* * Primary Tabs + Fields */ - if (!isset($this->config->tabs['fields']) || !is_array($this->config->tabs['fields'])) + if (!isset($this->config->tabs['fields']) || !is_array($this->config->tabs['fields'])) { $this->config->tabs['fields'] = []; + } $this->addFields($this->config->tabs['fields'], 'primary'); /* * Secondary Tabs + Fields */ - if (!isset($this->config->secondaryTabs['fields']) || !is_array($this->config->secondaryTabs['fields'])) + if (!isset($this->config->secondaryTabs['fields']) || !is_array($this->config->secondaryTabs['fields'])) { $this->config->secondaryTabs['fields'] = []; + } $this->addFields($this->config->secondaryTabs['fields'], 'secondary'); @@ -350,18 +386,21 @@ class Form extends WidgetBase */ $this->processAutoSpan($this->outsideFields); - foreach ($this->primaryTabs as $fields) + foreach ($this->primaryTabs as $fields) { $this->processAutoSpan($fields); + } - foreach ($this->secondaryTabs as $fields) + foreach ($this->secondaryTabs as $fields) { $this->processAutoSpan($fields); + } /* * Bind all form widgets to controller */ foreach ($this->fields as $field) { - if ($field->type != 'widget') + if ($field->type != 'widget') { continue; + } $widget = $this->makeFormWidget($field); $widget->bindToController(); @@ -379,10 +418,11 @@ class Form extends WidgetBase $prevSpan = null; foreach ($fields as $field) { if (strtolower($field->span) == 'auto') { - if ($prevSpan == 'left') + if ($prevSpan == 'left') { $field->span = 'right'; - else + } else { $field->span = 'left'; + } } $prevSpan = $field->span; @@ -397,12 +437,13 @@ class Form extends WidgetBase foreach ($fields as $name => $config) { $defaultTab = Lang::get('backend::lang.form.undefined_tab'); - if (!is_array($config)) + if (!is_array($config)) { $tab = $defaultTab; - elseif (!isset($config['tab'])) + } elseif (!isset($config['tab'])) { $tab = $config['tab'] = $defaultTab; - else + } else { $tab = $config['tab']; + } $fieldObj = $this->makeFormField($name, $config); @@ -411,8 +452,9 @@ class Form extends WidgetBase */ if ($fieldObj->context !== null) { $context = (is_array($fieldObj->context)) ? $fieldObj->context : [$fieldObj->context]; - if (!in_array($this->getContext(), $context)) + if (!in_array($this->getContext(), $context)) { continue; + } } $this->fields[$name] = $fieldObj; @@ -428,7 +470,6 @@ class Form extends WidgetBase $this->outsideFields[$name] = $fieldObj; break; } - } } @@ -451,7 +492,9 @@ class Form extends WidgetBase list($fieldName, $fieldContext) = $this->getFieldName($name); $field = new FormField($fieldName, $label); - if ($fieldContext) $field->context = $fieldContext; + if ($fieldContext) { + $field->context = $fieldContext; + } $field->arrayName = $this->arrayName; $field->idPrefix = $this->getId(); @@ -459,20 +502,22 @@ class Form extends WidgetBase * Simple field type */ if (is_string($config)) { - - if ($this->isFormWidget($config) !== false) + if ($this->isFormWidget($config) !== false) { $field->displayAs('widget', ['widget' => $config]); - else + } else { $field->displayAs($config); - } + } /* * Defined field type */ - else { - + } else { $fieldType = isset($config['type']) ? $config['type'] : null; - if (!is_string($fieldType) && !is_null($fieldType)) - throw new ApplicationException(Lang::get('backend::lang.field.invalid_type', ['type'=>gettype($fieldType)])); + if (!is_string($fieldType) && !is_null($fieldType)) { + throw new ApplicationException(Lang::get( + 'backend::lang.field.invalid_type', + ['type'=>gettype($fieldType)] + )); + } /* * Widget with configuration @@ -493,8 +538,9 @@ class Form extends WidgetBase /* * Check model if field is required */ - if (!$field->required && $this->model && method_exists($this->model, 'isAttributeRequired')) + if (!$field->required && $this->model && method_exists($this->model, 'isAttributeRequired')) { $field->required = $this->model->isAttributeRequired($field->fieldName); + } /* * Get field options from model @@ -505,7 +551,7 @@ class Form extends WidgetBase /* * Defer the execution of option data collection */ - $field->options(function() use ($field, $config) { + $field->options(function () use ($field, $config) { $fieldOptions = (isset($config['options'])) ? $config['options'] : null; $fieldOptions = $this->getOptionsFromModel($field, $fieldOptions); return $fieldOptions; @@ -522,19 +568,23 @@ class Form extends WidgetBase */ protected function isFormWidget($fieldType) { - if ($fieldType === null) + if ($fieldType === null) { return false; + } - if (strpos($fieldType, '\\')) + if (strpos($fieldType, '\\')) { return true; + } $widgetClass = $this->widgetManager->resolveFormWidget($fieldType); - if (!class_exists($widgetClass)) + if (!class_exists($widgetClass)) { return false; + } - if (is_subclass_of($widgetClass, 'Backend\Classes\FormWidgetBase')) + if (is_subclass_of($widgetClass, 'Backend\Classes\FormWidgetBase')) { return true; + } return false; } @@ -544,11 +594,13 @@ class Form extends WidgetBase */ protected function makeFormWidget($field) { - if ($field->type != 'widget') + if ($field->type != 'widget') { return null; + } - if (isset($this->formWidgets[$field->fieldName])) + if (isset($this->formWidgets[$field->fieldName])) { return $this->formWidgets[$field->fieldName]; + } $widgetConfig = $this->makeConfig($field->config); $widgetConfig->alias = $this->alias . studly_case(Str::evalHtmlId($field->fieldName)); @@ -557,9 +609,10 @@ class Form extends WidgetBase $widgetName = $widgetConfig->widget; $widgetClass = $this->widgetManager->resolveFormWidget($widgetName); if (!class_exists($widgetClass)) { - throw new ApplicationException(Lang::get('backend::lang.widget.not_registered', [ - 'name' => $widgetClass - ])); + throw new ApplicationException(Lang::get( + 'backend::lang.widget.not_registered', + ['name' => $widgetClass] + )); } $widget = new $widgetClass($this->controller, $this->model, $field, $widgetConfig); @@ -611,8 +664,9 @@ class Form extends WidgetBase */ public function getFieldName($field) { - if (strpos($field, '@') === false) + if (strpos($field, '@') === false) { return [$field, null]; + } return explode('@', $field); } @@ -623,8 +677,12 @@ class Form extends WidgetBase public function getFieldValue($field) { if (is_string($field)) { - if (!isset($this->fields[$field])) - throw new ApplicationException(Lang::get('backend::lang.form.missing_definition', compact('field'))); + if (!isset($this->fields[$field])) { + throw new ApplicationException(Lang::get( + 'backend::lang.form.missing_definition', + compact('field') + )); + } $field = $this->fields[$field]; } @@ -647,17 +705,20 @@ class Form extends WidgetBase foreach ($keyParts as $key) { if ($result instanceof Model && $result->hasRelation($key)) { - if ($key == $lastField) + if ($key == $lastField) { $result = $result->getRelationValue($key) ?: $defaultValue; - else + } else { $result = $result->{$key}; - } - elseif (is_array($result)) { - if (!array_key_exists($key, $result)) return $defaultValue; + } + } elseif (is_array($result)) { + if (!array_key_exists($key, $result)) { + return $defaultValue; + } $result = $result[$key]; - } - else { - if (!isset($result->{$key})) return $defaultValue; + } else { + if (!isset($result->{$key})) { + return $defaultValue; + } $result = $result->{$key}; } @@ -674,8 +735,9 @@ class Form extends WidgetBase */ public function getFieldDepends($field) { - if (!$field->depends) + if (!$field->depends) { return; + } $depends = is_array($field->depends) ? $field->depends : [$field->depends]; $depends = htmlspecialchars(json_encode($depends), ENT_QUOTES, 'UTF-8'); @@ -689,17 +751,18 @@ class Form extends WidgetBase { $data = ($this->arrayName) ? post($this->arrayName) : post(); - if (!$data) + if (!$data) { $data = []; + } /* * Boolean fields (checkbox, switch) won't be present value FALSE * Number fields should be converted to integers */ foreach ($this->fields as $field) { - - if (!in_array($field->type, ['switch', 'checkbox', 'number'])) + if (!in_array($field->type, ['switch', 'checkbox', 'number'])) { continue; + } /* * Handle HTML array, eg: item[key][another] @@ -722,8 +785,9 @@ class Form extends WidgetBase : null; $data[$field] = $widget->getSaveData($widgetValue); - if ($data[$field] === FormWidgetBase::NO_SAVE_DATA) + if ($data[$field] === FormWidgetBase::NO_SAVE_DATA) { unset($data[$field]); + } } /* @@ -731,8 +795,9 @@ class Form extends WidgetBase */ $remappedFields = []; foreach ($this->fields as $field) { - if ($field->fieldName == $field->valueFrom) + if ($field->fieldName == $field->valueFrom) { continue; + } /* * Get the value, remove it from the data collection @@ -776,21 +841,31 @@ class Form extends WidgetBase */ if (!is_array($fieldOptions) && !$fieldOptions) { $methodName = 'get'.studly_case($field->fieldName).'Options'; - if (!$this->methodExists($this->model, $methodName) && !$this->methodExists($this->model, 'getDropdownOptions')) - throw new ApplicationException(Lang::get('backend::lang.field.options_method_not_exists', ['model'=>get_class($this->model), 'method'=>$methodName, 'field'=>$field->fieldName])); + if ( + !$this->methodExists($this->model, $methodName) && + !$this->methodExists($this->model, 'getDropdownOptions') + ) { + throw new ApplicationException(Lang::get( + 'backend::lang.field.options_method_not_exists', + ['model'=>get_class($this->model), 'method'=>$methodName, 'field'=>$field->fieldName] + )); + } - if ($this->methodExists($this->model, $methodName)) + if ($this->methodExists($this->model, $methodName)) { $fieldOptions = $this->model->$methodName($field->value); - else + } else { $fieldOptions = $this->model->getDropdownOptions($field->fieldName, $field->value); - } - + } /* * Field options are an explicit method reference */ - elseif (is_string($fieldOptions)) { - if (!$this->methodExists($this->model, $fieldOptions)) - throw new ApplicationException(Lang::get('backend::lang.field.options_method_not_exists', ['model'=>get_class($this->model), 'method'=>$fieldOptions, 'field'=>$field->fieldName])); + } elseif (is_string($fieldOptions)) { + if (!$this->methodExists($this->model, $fieldOptions)) { + throw new ApplicationException(Lang::get( + 'backend::lang.field.options_method_not_exists', + ['model'=>get_class($this->model), 'method'=>$fieldOptions, 'field'=>$field->fieldName] + )); + } $fieldOptions = $this->model->$fieldOptions($field->value, $field->fieldName); } @@ -803,11 +878,13 @@ class Form extends WidgetBase */ public function getSessionKey() { - if ($this->sessionKey) + if ($this->sessionKey) { return $this->sessionKey; + } - if (post('_session_key')) + if (post('_session_key')) { return $this->sessionKey = post('_session_key'); + } return $this->sessionKey = FormHelper::getSessionKey(); } @@ -828,10 +905,10 @@ class Form extends WidgetBase */ protected function methodExists($object, $method) { - if (method_exists($object, 'methodExists')) + if (method_exists($object, 'methodExists')) { return $object->methodExists($method); + } return method_exists($object, $method); } - } diff --git a/modules/backend/widgets/Grid.php b/modules/backend/widgets/Grid.php index ec65235b8..4e42fd664 100644 --- a/modules/backend/widgets/Grid.php +++ b/modules/backend/widgets/Grid.php @@ -117,8 +117,9 @@ class Grid extends WidgetBase protected function makeToolbarWidget() { - if ($this->disableToolbar) + if ($this->disableToolbar) { return; + } $defaultConfig = [ 'buttons' => $this->getViewPath('_toolbar.htm'), @@ -148,8 +149,9 @@ class Grid extends WidgetBase public function onDataChanged() { - if (!$this->monitorChanges) + if (!$this->monitorChanges) { return; + } /* * Changes array, each array item will contain: @@ -168,16 +170,19 @@ class Grid extends WidgetBase public function onDataSource() { - if (!$this->useDataSource) + if (!$this->useDataSource) { return; + } $result = []; - if ($_result = $this->fireEvent('grid.dataSource', [], true)) + if ($_result = $this->fireEvent('grid.dataSource', [], true)) { $result = $_result; + } - if (!is_array($result)) + if (!is_array($result)) { $result = []; + } return ['result' => $result]; } @@ -188,8 +193,9 @@ class Grid extends WidgetBase protected function getColumnHeaders() { - if (!$this->showHeader) + if (!$this->showHeader) { return false; + } $headers = []; foreach ($this->columns as $key => $column) { @@ -214,8 +220,9 @@ class Grid extends WidgetBase $item = []; $item['data'] = $key; - if (isset($column['readOnly'])) + if (isset($column['readOnly'])) { $item['readOnly'] = $column['readOnly']; + } $item = $this->evalColumnType($column, $item); $definitions[] = $item; @@ -225,8 +232,9 @@ class Grid extends WidgetBase protected function evalColumnType($column, $item) { - if (!isset($column['type'])) + if (!isset($column['type'])) { return $item; + } switch ($column['type']) { case 'number': @@ -244,8 +252,12 @@ class Grid extends WidgetBase case 'autocomplete': $item['type'] = 'autocomplete'; - if (isset($column['options'])) $item['source'] = $column['options']; - if (isset($column['strict'])) $item['strict'] = $column['strict']; + if (isset($column['options'])) { + $item['source'] = $column['options']; + } + if (isset($column['strict'])) { + $item['strict'] = $column['strict']; + } break; } @@ -266,5 +278,4 @@ class Grid extends WidgetBase $this->addJs('vendor/handsontable/jquery.handsontable.js', 'core'); $this->addJs('js/datagrid.js', 'core'); } - } diff --git a/modules/backend/widgets/Lists.php b/modules/backend/widgets/Lists.php index 463ca2dff..ac3c3e68a 100644 --- a/modules/backend/widgets/Lists.php +++ b/modules/backend/widgets/Lists.php @@ -152,7 +152,10 @@ class Lists extends WidgetBase */ $this->recordUrl = $this->getConfig('recordUrl', $this->recordUrl); $this->recordOnClick = $this->getConfig('recordOnClick', $this->recordOnClick); - $this->recordsPerPage = $this->getSession('per_page', $this->getConfig('recordsPerPage', $this->recordsPerPage)); + $this->recordsPerPage = $this->getSession( + 'per_page', + $this->getConfig('recordsPerPage', $this->recordsPerPage) + ); $this->noRecordsMessage = $this->getConfig('noRecordsMessage', $this->noRecordsMessage); $this->defaultSort = $this->getConfig('defaultSort', $this->defaultSort); $this->showSorting = $this->getConfig('showSorting', $this->showSorting); @@ -206,8 +209,7 @@ class Lists extends WidgetBase $this->vars['pageLast'] = $this->records->getLastPage(); $this->vars['pageFrom'] = $this->records->getFrom(); $this->vars['pageTo'] = $this->records->getTo(); - } - else { + } else { $this->vars['recordTotal'] = $this->records->count(); $this->vars['pageCurrent'] = 1; } @@ -239,11 +241,19 @@ class Lists extends WidgetBase { $this->model = $this->getConfig('model'); - if (!$this->model) - throw new ApplicationException(Lang::get('backend::lang.list.missing_model', ['class'=>get_class($this->controller)])); + if (!$this->model) { + throw new ApplicationException(Lang::get( + 'backend::lang.list.missing_model', + ['class'=>get_class($this->controller)] + )); + } - if (!$this->model instanceof Model) - throw new ApplicationException(Lang::get('backend::lang.model.invalid_class', ['model'=>get_class($this->model), 'class'=>get_class($this->controller)])); + if (!$this->model instanceof Model) { + throw new ApplicationException(Lang::get( + 'backend::lang.model.invalid_class', + ['model'=>get_class($this->model), 'class'=>get_class($this->controller)] + )); + } return $this->model; } @@ -295,11 +305,10 @@ class Lists extends WidgetBase : $table . '.' . $column->valueFrom; $relationSearchable[$column->relation][] = $columnName; - } /* * Primary */ - else { + } else { $columnName = isset($column->sqlSelect) ? DbDongle::raw($this->parseTableName($column->sqlSelect, $primaryTable)) : $primaryTable . '.' . $column->columnName; @@ -314,11 +323,13 @@ class Lists extends WidgetBase */ foreach ($this->getVisibleListColumns() as $column) { - if (!$this->isColumnRelated($column) || (!isset($column->sqlSelect) && !isset($column->valueFrom))) + if (!$this->isColumnRelated($column) || (!isset($column->sqlSelect) && !isset($column->valueFrom))) { continue; + } - if (isset($column->valueFrom)) + if (isset($column->valueFrom)) { $withs[] = $column->relation; + } $joins[] = $column->relation; } @@ -335,7 +346,7 @@ class Lists extends WidgetBase $columnsToSearch = array_get($relationSearchable, $join, []); if (count($columnsToSearch) > 0) { - $query->whereHas($join, function($_query) use ($columnsToSearch) { + $query->whereHas($join, function ($_query) use ($columnsToSearch) { $_query->searchWhere($this->searchTerm, $columnsToSearch); }); } @@ -353,8 +364,9 @@ class Lists extends WidgetBase * Custom select queries */ foreach ($this->getVisibleListColumns() as $column) { - if (!isset($column->sqlSelect)) + if (!isset($column->sqlSelect)) { continue; + } $alias = Db::getQueryGrammar()->wrap($column->columnName); @@ -379,11 +391,10 @@ class Lists extends WidgetBase $joinSql = $countQuery->select($joinSql)->toSql(); $selects[] = Db::raw("(".$joinSql.") as ".$alias); - } /* * Primary column */ - else { + } else { $sqlSelect = $this->parseTableName($column->sqlSelect, $primaryTable); $selects[] = DbDongle::raw($sqlSelect . ' as '. $alias); } @@ -393,7 +404,7 @@ class Lists extends WidgetBase * Apply a supplied search term for primary columns */ if (count($primarySearchable) > 0) { - $query->orWhere(function($innerQuery) use ($primarySearchable) { + $query->orWhere(function ($innerQuery) use ($primarySearchable) { $innerQuery->searchWhere($this->searchTerm, $primarySearchable); }); } @@ -402,8 +413,9 @@ class Lists extends WidgetBase * Apply sorting */ if ($sortColumn = $this->getSortColumn()) { - if (($column = array_get($this->columns, $sortColumn)) && $column->sqlSelect) + if (($column = array_get($this->columns, $sortColumn)) && $column->sqlSelect) { $sortColumn = $column->sqlSelect; + } $query->orderBy($sortColumn, $this->sortDirection); } @@ -437,12 +449,12 @@ class Lists extends WidgetBase { if ($this->showTree) { $records = $this->model->getAllRoot(); - } - else { + } else { $model = $this->prepareModel(); $records = ($this->showPagination) ? $model->paginate($this->recordsPerPage) : $model->get(); + } return $this->records = $records; @@ -455,11 +467,13 @@ class Lists extends WidgetBase */ public function getRecordUrl($record) { - if (isset($this->recordOnClick)) + if (isset($this->recordOnClick)) { return 'javascript:;'; + } - if (!isset($this->recordUrl)) + if (!isset($this->recordUrl)) { return null; + } $columns = array_keys($record->getAttributes()); $url = RouterHelper::parseValues($record, $columns, $this->recordUrl); @@ -473,8 +487,9 @@ class Lists extends WidgetBase */ public function getRecordOnClick($record) { - if (!isset($this->recordOnClick)) + if (!isset($this->recordOnClick)) { return null; + } $columns = array_keys($record->getAttributes()); $recordOnClick = RouterHelper::parseValues($record, $columns, $this->recordOnClick); @@ -511,27 +526,32 @@ class Lists extends WidgetBase /* * Supplied column list */ - if ($this->columnOverride === null) + if ($this->columnOverride === null) { $this->columnOverride = $this->getSession('visible', null); + } if ($this->columnOverride && is_array($this->columnOverride)) { $invalidColumns = array_diff($this->columnOverride, array_keys($definitions)); - if (!count($definitions)) - throw new ApplicationException(Lang::get('backend::lang.list.missing_column', ['columns'=>implode(',', $invalidColumns)])); + if (!count($definitions)) { + throw new ApplicationException(Lang::get( + 'backend::lang.list.missing_column', + ['columns'=>implode(',', $invalidColumns)] + )); + } foreach ($this->columnOverride as $columnName) { $definitions[$columnName]->invisible = false; $columns[$columnName] = $definitions[$columnName]; } - } /* * Use default column list */ - else { + } else { foreach ($definitions as $columnName => $column) { - if ($column->invisible) + if ($column->invisible) { continue; + } $columns[$columnName] = $definitions[$columnName]; } @@ -545,8 +565,12 @@ class Lists extends WidgetBase */ protected function defineListColumns() { - if (!isset($this->config->columns) || !is_array($this->config->columns) || !count($this->config->columns)) - throw new ApplicationException(Lang::get('backend::lang.list.missing_columns', ['class'=>get_class($this->controller)])); + if (!isset($this->config->columns) || !is_array($this->config->columns) || !count($this->config->columns)) { + throw new ApplicationException(Lang::get( + 'backend::lang.list.missing_columns', + ['class'=>get_class($this->controller)] + )); + } $this->addColumns($this->config->columns); @@ -589,12 +613,13 @@ class Lists extends WidgetBase */ protected function makeListColumn($name, $config) { - if (is_string($config)) + if (is_string($config)) { $label = $config; - elseif (isset($config['label'])) + } elseif (isset($config['label'])) { $label = $config['label']; - else + } else { $label = studly_case($name); + } $columnType = isset($config['type']) ? $config['type'] : null; @@ -612,8 +637,12 @@ class Lists extends WidgetBase { $columns = $this->visibleColumns ?: $this->getVisibleListColumns(); $total = count($columns); - if ($this->showCheckboxes) $total++; - if ($this->showSetup) $total++; + if ($this->showCheckboxes) { + $total++; + } + if ($this->showSetup) { + $total++; + } return $total; } @@ -627,11 +656,13 @@ class Lists extends WidgetBase /* * Extensibility */ - if ($response = Event::fire('backend.list.overrideHeaderValue', [$this, $column, $value], true)) + if ($response = Event::fire('backend.list.overrideHeaderValue', [$this, $column, $value], true)) { $value = $response; + } - if ($response = $this->fireEvent('list.overrideHeaderValue', [$column, $value], true)) + if ($response = $this->fireEvent('list.overrideHeaderValue', [$column, $value], true)) { $value = $response; + } return $value; } @@ -648,38 +679,42 @@ class Lists extends WidgetBase * Handle taking name from model attribute. */ if ($column->valueFrom) { - if (!array_key_exists($columnName, $record->getRelations())) + if (!array_key_exists($columnName, $record->getRelations())) { $value = null; - elseif ($this->isColumnRelated($column, true)) + } elseif ($this->isColumnRelated($column, true)) { $value = implode(', ', $record->{$columnName}->lists($column->valueFrom)); - elseif ($this->isColumnRelated($column)) + } elseif ($this->isColumnRelated($column)) { $value = $record->{$columnName}->{$column->valueFrom}; - else + } else { $value = $record->{$column->valueFrom}; - } + } /* * Otherwise, if the column is a relation, it will be a custom select, * so prevent the Model from attempting to load the relation * if the value is NULL. */ - else { - if ($record->hasRelation($columnName) && array_key_exists($columnName, $record->attributes)) + } else { + if ($record->hasRelation($columnName) && array_key_exists($columnName, $record->attributes)) { $value = $record->attributes[$columnName]; - else + } else { $value = $record->{$columnName}; + } } - if (method_exists($this, 'eval'. studly_case($column->type) .'TypeValue')) + if (method_exists($this, 'eval'. studly_case($column->type) .'TypeValue')) { $value = $this->{'eval'. studly_case($column->type) .'TypeValue'}($record, $column, $value); + } /* * Extensibility */ - if ($response = Event::fire('backend.list.overrideColumnValue', [$this, $record, $column, $value], true)) + if ($response = Event::fire('backend.list.overrideColumnValue', [$this, $record, $column, $value], true)) { $value = $response; + } - if ($response = $this->fireEvent('list.overrideColumnValue', [$record, $column, $value], true)) + if ($response = $this->fireEvent('list.overrideColumnValue', [$record, $column, $value], true)) { $value = $response; + } return $value; } @@ -696,11 +731,13 @@ class Lists extends WidgetBase /* * Extensibility */ - if ($response = Event::fire('backend.list.injectRowClass', [$this, $record], true)) + if ($response = Event::fire('backend.list.injectRowClass', [$this, $record], true)) { $value = $response; + } - if ($response = $this->fireEvent('list.injectRowClass', [$record], true)) + if ($response = $this->fireEvent('list.injectRowClass', [$record], true)) { $value = $response; + } return $value; } @@ -738,13 +775,15 @@ class Lists extends WidgetBase */ protected function evalDatetimeTypeValue($record, $column, $value) { - if ($value === null) + if ($value === null) { return null; + } $value = $this->validateDateTimeValue($value, $column); - if ($column->format !== null) + if ($column->format !== null) { return $value->format($column->format); + } return $value->toDayDateTimeString(); } @@ -754,13 +793,15 @@ class Lists extends WidgetBase */ protected function evalTimeTypeValue($record, $column, $value) { - if ($value === null) + if ($value === null) { return null; + } $value = $this->validateDateTimeValue($value, $column); - if ($column->format === null) + if ($column->format === null) { $column->format = 'g:i A'; + } return $value->format($column->format); } @@ -770,13 +811,15 @@ class Lists extends WidgetBase */ protected function evalDateTypeValue($record, $column, $value) { - if ($value === null) + if ($value === null) { return null; + } $value = $this->validateDateTimeValue($value, $column); - if ($column->format !== null) + if ($column->format !== null) { return $value->format($column->format); + } return $value->toFormattedDateString(); } @@ -786,8 +829,9 @@ class Lists extends WidgetBase */ protected function evalTimesinceTypeValue($record, $column, $value) { - if ($value === null) + if ($value === null) { return null; + } $value = $this->validateDateTimeValue($value, $column); @@ -799,11 +843,16 @@ class Lists extends WidgetBase */ protected function validateDateTimeValue($value, $column) { - if ($value instanceof DateTime) + if ($value instanceof DateTime) { $value = Carbon::instance($value); + } - if (!$value instanceof Carbon) - throw new ApplicationException(Lang::get('backend::lang.list.invalid_column_datetime', ['column' => $column->columnName])); + if (!$value instanceof Carbon) { + throw new ApplicationException(Lang::get( + 'backend::lang.list.invalid_column_datetime', + ['column' => $column->columnName] + )); + } return $value; } @@ -830,8 +879,7 @@ class Lists extends WidgetBase { if (empty($term)) { $this->showTree = $this->getConfig('showTree', $this->showTree); - } - else { + } else { $this->showTree = false; } @@ -848,8 +896,9 @@ class Lists extends WidgetBase $searchable = []; foreach ($columns as $column) { - if (!$column->searchable) + if (!$column->searchable) { continue; + } $searchable[] = $column; } @@ -873,10 +922,11 @@ class Lists extends WidgetBase */ $sortOptions = ['column' => $this->getSortColumn(), 'direction' => $this->sortDirection]; - if ($column != $sortOptions['column'] || $sortOptions['direction'] == 'asc') + if ($column != $sortOptions['column'] || $sortOptions['direction'] == 'asc') { $this->sortDirection = $sortOptions['direction'] = 'desc'; - else + } else { $this->sortDirection = $sortOptions['direction'] = 'asc'; + } $this->sortColumn = $sortOptions['column'] = $column; @@ -896,11 +946,13 @@ class Lists extends WidgetBase */ protected function getSortColumn() { - if (!$this->isSortable()) + if (!$this->isSortable()) { return false; + } - if ($this->sortColumn !== null) + if ($this->sortColumn !== null) { return $this->sortColumn; + } /* * User preference @@ -908,18 +960,19 @@ class Lists extends WidgetBase if ($this->showSorting && ($sortOptions = $this->getSession('sort'))) { $this->sortColumn = $sortOptions['column']; $this->sortDirection = $sortOptions['direction']; - } + /* * Supplied default */ - else { + } else { if (is_string($this->defaultSort)) { $this->sortColumn = $this->defaultSort; $this->sortDirection = 'desc'; - } - elseif (is_array($this->defaultSort) && isset($this->defaultSort['column'])) { + } elseif (is_array($this->defaultSort) && isset($this->defaultSort['column'])) { $this->sortColumn = $this->defaultSort['column']; - $this->sortDirection = (isset($this->defaultSort['direction'])) ? $this->defaultSort['direction'] : 'desc'; + $this->sortDirection = (isset($this->defaultSort['direction'])) ? + $this->defaultSort['direction'] : + 'desc'; } } @@ -940,10 +993,11 @@ class Lists extends WidgetBase */ protected function isSortable($column = null) { - if ($column === null) + if ($column === null) { return (count($this->getSortableColumns()) > 0); - else + } else { return array_key_exists($column, $this->getSortableColumns()); + } } /** @@ -951,15 +1005,17 @@ class Lists extends WidgetBase */ protected function getSortableColumns() { - if ($this->sortableColumns !== null) + if ($this->sortableColumns !== null) { return $this->sortableColumns; + } $columns = $this->getColumns(); $sortable = []; foreach ($columns as $column) { - if (!$column->sortable) + if (!$column->sortable) { continue; + } $sortable[$column->columnName] = $column; } @@ -1003,8 +1059,9 @@ class Lists extends WidgetBase protected function getSetupPerPageOptions() { $perPageOptions = [20, 40, 80, 100, 120]; - if (!in_array($this->recordsPerPage, $perPageOptions)) + if (!in_array($this->recordsPerPage, $perPageOptions)) { $perPageOptions[] = $this->recordsPerPage; + } sort($perPageOptions); return $perPageOptions; @@ -1036,15 +1093,23 @@ class Lists extends WidgetBase */ public function validateTree() { - if (!$this->showTree) return; + if (!$this->showTree) { + return; + } $this->showSorting = $this->showPagination = false; - if (!$this->model->methodExists('getChildren')) - throw new ApplicationException('To display list as a tree, the specified model must have a method "getChildren"'); + if (!$this->model->methodExists('getChildren')) { + throw new ApplicationException( + 'To display list as a tree, the specified model must have a method "getChildren"' + ); + } - if (!$this->model->methodExists('getChildCount')) - throw new ApplicationException('To display list as a tree, the specified model must have a method "getChildCount"'); + if (!$this->model->methodExists('getChildCount')) { + throw new ApplicationException( + 'To display list as a tree, the specified model must have a method "getChildCount"' + ); + } } /** @@ -1080,14 +1145,20 @@ class Lists extends WidgetBase */ protected function isColumnRelated($column, $multi = false) { - if (!isset($column->relation)) + if (!isset($column->relation)) { return false; + } - if (!$this->model->hasRelation($column->relation)) - throw new ApplicationException(Lang::get('backend::lang.model.missing_relation', ['class'=>get_class($this->model), 'relation'=>$column->relation])); + if (!$this->model->hasRelation($column->relation)) { + throw new ApplicationException(Lang::get( + 'backend::lang.model.missing_relation', + ['class'=>get_class($this->model), 'relation'=>$column->relation] + )); + } - if (!$multi) + if (!$multi) { return true; + } $relationType = $this->model->getRelationType($column->relation); @@ -1101,5 +1172,4 @@ class Lists extends WidgetBase 'hasManyThrough' ]); } - -} \ No newline at end of file +} diff --git a/modules/backend/widgets/ReportContainer.php b/modules/backend/widgets/ReportContainer.php index 7da6f9b87..1356ae967 100644 --- a/modules/backend/widgets/ReportContainer.php +++ b/modules/backend/widgets/ReportContainer.php @@ -62,9 +62,10 @@ class ReportContainer extends WidgetBase if (File::isFile($path)) { $config = $this->makeConfig($configFile); - foreach ($config as $field=>$value) { - if (property_exists($this, $field)) + foreach ($config as $field => $value) { + if (property_exists($this, $field)) { $this->$field = $value; + } } } } @@ -116,8 +117,9 @@ class ReportContainer extends WidgetBase public function onLoadAddPopup() { $sizes = []; - for ($i = 1; $i <= 10; $i++) + for ($i = 1; $i <= 10; $i++) { $sizes[$i] = $i < 10 ? $i : $i.' (' . Lang::get('backend::lang.dashboard.full_width') . ')'; + } $this->vars['sizes'] = $sizes; $this->vars['widgets'] = WidgetManager::instance()->listReportWidgets(); @@ -130,15 +132,18 @@ class ReportContainer extends WidgetBase $className = trim(Request::input('className')); $size = trim(Request::input('size')); - if (!$className) + if (!$className) { throw new ApplicationException('Please select a widget to add.'); + } - if (!class_exists($className)) + if (!class_exists($className)) { throw new ApplicationException('The selected class doesn\'t exist.'); + } $widget = new $className($this->controller); - if (!($widget instanceof \Backend\Classes\ReportWidgetBase)) + if (!($widget instanceof \Backend\Classes\ReportWidgetBase)) { throw new ApplicationException('The selected class is not a report widget.'); + } $widgetInfo = $this->addWidget($widget, $size); @@ -162,8 +167,9 @@ class ReportContainer extends WidgetBase } while (array_key_exists($alias, $widgets)); $sortOrder = 0; - foreach ($widgets as $widgetInfo) + foreach ($widgets as $widgetInfo) { $sortOrder = max($sortOrder, $widgetInfo['sortOrder']); + } $sortOrder++; @@ -184,22 +190,26 @@ class ReportContainer extends WidgetBase $aliases = trim(Request::input('aliases')); $orders = trim(Request::input('orders')); - if (!$aliases) + if (!$aliases) { throw new ApplicationException('Invalid aliases string.'); + } - if (!$orders) + if (!$orders) { throw new ApplicationException('Invalid orders string.'); + } $aliases = explode(',', $aliases); $orders = explode(',', $orders); - if (count($aliases) != count($orders)) + if (count($aliases) != count($orders)) { throw new ApplicationException('Invalid data posted.'); + } $widgets = $this->getWidgetsFromUserPreferences(); - foreach ($aliases as $index=>$alias) { - if (isset($widgets[$alias])) + foreach ($aliases as $index => $alias) { + if (isset($widgets[$alias])) { $widgets[$alias]['sortOrder'] = $orders[$index]; + } } $this->setWidgetsToUserPreferences($widgets); @@ -219,8 +229,9 @@ class ReportContainer extends WidgetBase $configuration['alias'] = $alias; $className = $widgetInfo['class']; - if (!class_exists($className)) + if (!class_exists($className)) { continue; + } $widget = new $className($this->controller, $configuration); $widget->bindToController(); @@ -228,7 +239,7 @@ class ReportContainer extends WidgetBase $result[$alias] = ['widget' => $widget, 'sortOrder' => $widgetInfo['sortOrder']]; } - uasort($result, function($a, $b){ + uasort($result, function ($a, $b) { return $a['sortOrder'] - $b['sortOrder']; }); @@ -238,7 +249,9 @@ class ReportContainer extends WidgetBase protected function getWidgetsFromUserPreferences() { $widgets = UserPreferences::forUser()->get($this->getUserPreferencesKey(), $this->defaultWidgets); - if (!is_array($widgets)) return []; + if (!is_array($widgets)) { + return []; + } return $widgets; } @@ -262,8 +275,9 @@ class ReportContainer extends WidgetBase { $widgets = $this->getWidgetsFromUserPreferences(); - if (isset($widgets[$alias])) + if (isset($widgets[$alias])) { unset($widgets[$alias]); + } $this->setWidgetsToUserPreferences($widgets); } @@ -271,8 +285,9 @@ class ReportContainer extends WidgetBase protected function findWidgetByAlias($alias) { $widgets = $this->loadWidgets(); - if (!isset($widgets[$alias])) + if (!isset($widgets[$alias])) { throw new ApplicationException('The specified widget is not found.'); + } return $widgets[$alias]['widget']; } @@ -320,8 +335,9 @@ class ReportContainer extends WidgetBase ]; foreach ($params as $name => $value) { - if (isset($property[$name])) + if (isset($property[$name])) { continue; + } $property[$name] = !is_array($value) ? Lang::get($value) : $value; } @@ -351,4 +367,4 @@ class ReportContainer extends WidgetBase { return 'backend::reportwidgets.'.$this->context; } -} \ No newline at end of file +} diff --git a/modules/backend/widgets/Search.php b/modules/backend/widgets/Search.php index eab206c52..039a0ed71 100644 --- a/modules/backend/widgets/Search.php +++ b/modules/backend/widgets/Search.php @@ -53,22 +53,26 @@ class Search extends WidgetBase /* * Process configuration */ - if (isset($this->config->prompt)) + if (isset($this->config->prompt)) { $this->placeholder = trans($this->config->prompt); + } - if (isset($this->config->partial)) + if (isset($this->config->partial)) { $this->customPartial = $this->config->partial; + } - if (isset($this->config->growable)) + if (isset($this->config->growable)) { $this->growable = $this->config->growable; + } /* * Add CSS class styles */ $this->cssClasses[] = 'icon search'; - if ($this->growable) + if ($this->growable) { $this->cssClasses[] = 'growable'; + } } /** @@ -78,10 +82,11 @@ class Search extends WidgetBase { $this->prepareVars(); - if ($this->customPartial) + if ($this->customPartial) { return $this->controller->makePartial($this->customPartial); - else + } else { return $this->makePartial('search'); + } } /** @@ -109,8 +114,9 @@ class Search extends WidgetBase */ $params = func_get_args(); $result = $this->fireEvent('search.submit', [$params]); - if ($result && is_array($result)) + if ($result && is_array($result)) { return Util::arrayMerge($result); + } } /** @@ -126,10 +132,11 @@ class Search extends WidgetBase */ public function setActiveTerm($term) { - if (strlen($term)) + if (strlen($term)) { $this->putSession('term', $term); - else + } else { $this->resetSession(); + } $this->activeTerm = $term; } @@ -142,4 +149,4 @@ class Search extends WidgetBase { return $this->alias . '[term]'; } -} \ No newline at end of file +} diff --git a/modules/backend/widgets/Toolbar.php b/modules/backend/widgets/Toolbar.php index eefd498ac..7305675f0 100644 --- a/modules/backend/widgets/Toolbar.php +++ b/modules/backend/widgets/Toolbar.php @@ -43,10 +43,10 @@ class Toolbar extends WidgetBase */ if (isset($this->config->search)) { - if (is_string($this->config->search)) + $searchConfig = $this->makeConfig($this->config->search); + if (is_string($this->config->search)) { $searchConfig = $this->makeConfig(['partial' => $this->config->search]); - else - $searchConfig = $this->makeConfig($this->config->search); + } $searchConfig->alias = $this->alias . 'Search'; $this->searchWidget = $this->makeWidget('Backend\Widgets\Search', $searchConfig); @@ -80,9 +80,10 @@ class Toolbar extends WidgetBase public function makeControlPanel() { - if (!isset($this->config->buttons)) + if (!isset($this->config->buttons)) { return false; + } return $this->controller->makePartial($this->config->buttons, $this->vars); } -} \ No newline at end of file +} From 202e8869b13a1c957fa1f6ad8487a60643778cfc Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 01:22:03 +0200 Subject: [PATCH 16/30] Updating modules/cms/classes --- modules/cms/classes/Asset.php | 4 +- modules/cms/classes/CmsCompoundObject.php | 90 ++++--- modules/cms/classes/CmsException.php | 40 ++- modules/cms/classes/CmsObject.php | 114 +++++--- modules/cms/classes/CmsObjectCollection.php | 2 +- modules/cms/classes/CmsObjectQuery.php | 14 +- modules/cms/classes/CmsPropertyHelper.php | 7 +- modules/cms/classes/CodeBase.php | 21 +- modules/cms/classes/CodeParser.php | 26 +- modules/cms/classes/CombineAssets.php | 80 +++--- modules/cms/classes/ComponentBase.php | 32 ++- modules/cms/classes/ComponentHelpers.php | 13 +- modules/cms/classes/ComponentManager.php | 59 +++-- modules/cms/classes/ComponentPartial.php | 3 +- modules/cms/classes/Content.php | 6 +- modules/cms/classes/Controller.php | 275 ++++++++++++-------- modules/cms/classes/FileHelper.php | 33 ++- modules/cms/classes/Layout.php | 4 +- modules/cms/classes/LayoutCode.php | 6 +- modules/cms/classes/ObjectMemoryCache.php | 2 +- modules/cms/classes/Page.php | 20 +- modules/cms/classes/PageCode.php | 2 +- modules/cms/classes/Router.php | 45 ++-- modules/cms/classes/SectionParser.php | 29 ++- modules/cms/classes/Theme.php | 55 ++-- modules/cms/classes/UnknownComponent.php | 2 +- modules/cms/classes/ViewBag.php | 7 +- 27 files changed, 637 insertions(+), 354 deletions(-) diff --git a/modules/cms/classes/Asset.php b/modules/cms/classes/Asset.php index 1ba30e70b..569e8fbb3 100644 --- a/modules/cms/classes/Asset.php +++ b/modules/cms/classes/Asset.php @@ -41,8 +41,9 @@ class Asset extends CmsObject $defaultTypes = ['css','js','less','sass','scss']; $configTypes = Config::get('cms.editableAssetTypes'); - if (!$configTypes) + if (!$configTypes) { return $defaultTypes; + } return $configTypes; } @@ -64,5 +65,4 @@ class Asset extends CmsObject { return null; } - } diff --git a/modules/cms/classes/CmsCompoundObject.php b/modules/cms/classes/CmsCompoundObject.php index 634595ed3..3a5fb25ce 100644 --- a/modules/cms/classes/CmsCompoundObject.php +++ b/modules/cms/classes/CmsCompoundObject.php @@ -67,8 +67,9 @@ class CmsCompoundObject extends CmsObject */ public static function load($theme, $fileName) { - if (($obj = parent::load($theme, $fileName)) === null) + if (($obj = parent::load($theme, $fileName)) === null) { return null; + } CmsException::mask($obj, 200); $parsedData = SectionParser::parse($obj->content); @@ -89,8 +90,9 @@ class CmsCompoundObject extends CmsObject */ public function __get($name) { - if (is_array($this->settings) && array_key_exists($name, $this->settings)) + if (is_array($this->settings) && array_key_exists($name, $this->settings)) { return $this->settings[$name]; + } return parent::__get($name); } @@ -103,8 +105,9 @@ class CmsCompoundObject extends CmsObject */ public function __isset($key) { - if (parent::__isset($key) === true) + if (parent::__isset($key) === true) { return true; + } return isset($this->settings[$key]); } @@ -124,8 +127,9 @@ class CmsCompoundObject extends CmsObject public function runComponents() { foreach ($this->components as $component) { - if ($result = $component->onRun()) + if ($result = $component->onRun()) { return $result; + } } } @@ -139,13 +143,15 @@ class CmsCompoundObject extends CmsObject $manager = ComponentManager::instance(); $components = []; foreach ($this->settings as $setting => $value) { - if (!is_array($value)) + if (!is_array($value)) { continue; + } $settingParts = explode(' ', $setting); $settingName = $settingParts[0]; - // if (!$manager->hasComponent($settingName)) + // if (!$manager->hasComponent($settingName)) { // continue; + // } $components[$setting] = $value; unset($this->settings[$setting]); @@ -182,25 +188,29 @@ class CmsCompoundObject extends CmsObject $this->code = trim($this->code); $this->markup = trim($this->markup); - $trim = function(&$values) use (&$trim) { + $trim = function (&$values) use (&$trim) { foreach ($values as &$value) { - if (!is_array($value)) + if (!is_array($value)) { $value = trim($value); - else $trim($value); + } else { + $trim($value); + } } }; $trim($this->settings); - if (array_key_exists('components', $this->settings) && count($this->settings['components']) == 0) + if (array_key_exists('components', $this->settings) && count($this->settings['components']) == 0) { unset($this->settings['components']); + } $this->validate(); $content = []; - if ($this->settings) + if ($this->settings) { $content[] = FileHelper::formatIniString($this->settings); + } if ($this->code) { $code = preg_replace('/^\<\?php/', '', $this->code); @@ -224,8 +234,9 @@ class CmsCompoundObject extends CmsObject */ public function getViewBag() { - if ($this->viewBagCache !== false) + if ($this->viewBagCache !== false) { return $this->viewBagCache; + } $componentName = 'viewBag'; @@ -248,13 +259,15 @@ class CmsCompoundObject extends CmsObject */ public function getComponent($componentName) { - if (!$this->hasComponent($componentName)) + if (!$this->hasComponent($componentName)) { return null; + } return ComponentManager::instance()->makeComponent( - $componentName, - null, - $this->settings['components'][$componentName]); + $componentName, + null, + $this->settings['components'][$componentName] + ); } /** @@ -283,31 +296,35 @@ class CmsCompoundObject extends CmsObject $cached = Cache::get($key, false); $unserialized = $cached ? @unserialize($cached) : false; $objectComponentMap = $unserialized ? $unserialized : []; - if ($objectComponentMap) + if ($objectComponentMap) { self::$objectComponentPropertyMap = $objectComponentMap; + } } $objectCode = $this->getBaseFileName(); if (array_key_exists($objectCode, $objectComponentMap)) { - if (array_key_exists($componentName, $objectComponentMap[$objectCode])) + if (array_key_exists($componentName, $objectComponentMap[$objectCode])) { return $objectComponentMap[$objectCode][$componentName]; + } return []; } - if (!isset($this->settings['components'])) + if (!isset($this->settings['components'])) { $objectComponentMap[$objectCode] = []; - else { - foreach ($this->settings['components'] as $componentName=>$componentSettings) { + } else { + foreach ($this->settings['components'] as $componentName => $componentSettings) { $component = $this->getComponent($componentName); - if (!$component) + if (!$component) { continue; + } $componentProperties = []; $propertyDefinitions = $component->defineProperties(); - foreach ($propertyDefinitions as $propertyName=>$propertyInfo) + foreach ($propertyDefinitions as $propertyName => $propertyInfo) { $componentProperties[$propertyName] = $component->property($propertyName); + } $objectComponentMap[$objectCode][$componentName] = $componentProperties; } @@ -317,8 +334,9 @@ class CmsCompoundObject extends CmsObject Cache::put($key, serialize($objectComponentMap), Config::get('cms.parsedPageCacheTTL', 10)); - if (array_key_exists($componentName, $objectComponentMap[$objectCode])) + if (array_key_exists($componentName, $objectComponentMap[$objectCode])) { return $objectComponentMap[$objectCode][$componentName]; + } return []; } @@ -338,7 +356,9 @@ class CmsCompoundObject extends CmsObject * the content of the $settings property after the object * is loaded from a file. */ - protected function parseSettings() {} + protected function parseSettings() + { + } /** * Initializes the object properties from the cached data. @@ -368,14 +388,24 @@ class CmsCompoundObject extends CmsObject */ protected function validate() { - $validation = Validator::make($this->settings, $this->settingsValidationRules, $this->settingsValidationMessages); - if ($validation->fails()) + $validation = Validator::make( + $this->settings, + $this->settingsValidationRules, + $this->settingsValidationMessages + ); + if ($validation->fails()) { throw new ValidationException($validation); + } if ($this->viewBagValidationRules && isset($this->settings['viewBag'])) { - $validation = Validator::make($this->settings['viewBag'], $this->viewBagValidationRules, $this->viewBagValidationMessages); - if ($validation->fails()) + $validation = Validator::make( + $this->settings['viewBag'], + $this->viewBagValidationRules, + $this->viewBagValidationMessages + ); + if ($validation->fails()) { throw new ValidationException($validation); + } } } -} \ No newline at end of file +} diff --git a/modules/cms/classes/CmsException.php b/modules/cms/classes/CmsException.php index 3dec87b0f..b8f5d5d50 100644 --- a/modules/cms/classes/CmsException.php +++ b/modules/cms/classes/CmsException.php @@ -50,8 +50,9 @@ class CmsException extends ApplicationException $message = ''; } - if (isset(static::$errorCodes[$code])) + if (isset(static::$errorCodes[$code])) { $this->errorType = static::$errorCodes[$code]; + } parent::__construct($message, $code, $previous); } @@ -104,9 +105,15 @@ class CmsException extends ApplicationException /* * Expecting: syntax error, unexpected '!' in Unknown on line 4 */ - if (!starts_with($message, 'syntax error')) return false; - if (strpos($message, 'Unknown') === false) return false; - if (strpos($exception->getFile(), 'SectionParser.php') === false) return false; + if (!starts_with($message, 'syntax error')) { + return false; + } + if (strpos($message, 'Unknown') === false) { + return false; + } + if (strpos($exception->getFile(), 'SectionParser.php') === false) { + return false; + } /* * Line number from parse_ini_string() error. @@ -143,23 +150,28 @@ class CmsException extends ApplicationException $check = false; // Expected: */modules/cms/classes/CodeParser.php(165) : eval()'d code line 7 - if (strpos($exception->getFile(), 'CodeParser.php')) $check = true; + if (strpos($exception->getFile(), 'CodeParser.php')) { + $check = true; + } - // Expected: */app/storage/cache/39/05/home.htm.php - if (strpos($exception->getFile(), $this->compoundObject->getFileName() . '.php')) $check = true; + // Expected: */app/storage/cache/39/05/home.htm.php + if (strpos($exception->getFile(), $this->compoundObject->getFileName() . '.php')) { + $check = true; + } - if (!$check) + if (!$check) { return false; - } + } /* * Errors occurring the PHP code base class (Cms\Classes\CodeBase) */ - else { + } else { $trace = $exception->getTrace(); if (isset($trace[1]['class'])) { $class = $trace[1]['class']; - if (!is_subclass_of($class, 'Cms\Classes\CodeBase')) + if (!is_subclass_of($class, 'Cms\Classes\CodeBase')) { return false; + } } } @@ -187,8 +199,9 @@ class CmsException extends ApplicationException protected function processTwig(Exception $exception) { // Must be a Twig related exception - if (!$exception instanceof Twig_Error) + if (!$exception instanceof Twig_Error) { return false; + } $this->message = $exception->getRawMessage(); $this->line = $exception->getTemplateLine(); @@ -220,5 +233,4 @@ class CmsException extends ApplicationException return; } } - -} \ No newline at end of file +} diff --git a/modules/cms/classes/CmsObject.php b/modules/cms/classes/CmsObject.php index 28a567264..85a13214c 100644 --- a/modules/cms/classes/CmsObject.php +++ b/modules/cms/classes/CmsObject.php @@ -80,27 +80,32 @@ class CmsObject implements ArrayAccess */ public static function loadCached($theme, $fileName) { - if (!FileHelper::validatePath($fileName, static::getMaxAllowedPathNesting())) + if (!FileHelper::validatePath($fileName, static::getMaxAllowedPathNesting())) { throw new SystemException(Lang::get('cms::lang.cms_object.invalid_file', ['name'=>$fileName])); + } - if (!strlen(File::extension($fileName))) + if (!strlen(File::extension($fileName))) { $fileName .= '.'.static::$defaultExtension; + } $filePath = static::getFilePath($theme, $fileName); - if (array_key_exists($filePath, ObjectMemoryCache::$cache)) + if (array_key_exists($filePath, ObjectMemoryCache::$cache)) { return ObjectMemoryCache::$cache[$filePath]; + } $key = self::getObjectTypeDirName().crc32($filePath); clearstatcache($filePath); $cached = Cache::get($key, false); if ($cached !== false && ($cached = @unserialize($cached)) !== false) { - if ($cached['mtime'] != @File::lastModified($filePath)) + if ($cached['mtime'] != @File::lastModified($filePath)) { $cached = false; + } } - if ($cached && !File::isFile($filePath)) + if ($cached && !File::isFile($filePath)) { $cached = false; + } if ($cached !== false) { /* @@ -151,19 +156,23 @@ class CmsObject implements ArrayAccess */ public static function load($theme, $fileName) { - if (!FileHelper::validatePath($fileName, static::getMaxAllowedPathNesting())) + if (!FileHelper::validatePath($fileName, static::getMaxAllowedPathNesting())) { throw new SystemException(Lang::get('cms::lang.cms_object.invalid_file', ['name'=>$fileName])); + } - if (!strlen(File::extension($fileName))) + if (!strlen(File::extension($fileName))) { $fileName .= '.'.static::$defaultExtension; + } $fullPath = static::getFilePath($theme, $fileName); - if (!File::isFile($fullPath)) + if (!File::isFile($fullPath)) { return null; + } - if (($content = @File::get($fullPath)) === false) + if (($content = @File::get($fullPath)) === false) { return null; + } $obj = new static($theme); $obj->fileName = $fileName; @@ -209,8 +218,9 @@ class CmsObject implements ArrayAccess public function getBaseFileName() { $pos = strrpos($this->fileName, '.'); - if ($pos === false) + if ($pos === false) { return $this->fileName; + } return substr($this->fileName, 0, $pos); } @@ -258,8 +268,9 @@ class CmsObject implements ArrayAccess ]); } - if (!strlen(File::extension($fileName))) + if (!strlen(File::extension($fileName))) { $fileName .= '.htm'; + } $this->fileName = $fileName; return $this; @@ -298,15 +309,20 @@ class CmsObject implements ArrayAccess */ public function fill(array $attributes) { - foreach ($attributes as $key=>$value) { - if (!in_array($key, static::$fillable)) - throw new ApplicationException(Lang::get('cms::lang.cms_object.invalid_property', ['name'=>$key])); + foreach ($attributes as $key => $value) { + if (!in_array($key, static::$fillable)) { + throw new ApplicationException(Lang::get( + 'cms::lang.cms_object.invalid_property', + ['name' => $key] + )); + } $methodName = 'set'.ucfirst($key); - if (method_exists($this, $methodName)) + if (method_exists($this, $methodName)) { $this->$methodName($value); - else + } else { $this->$key = $value; + } } } @@ -317,31 +333,48 @@ class CmsObject implements ArrayAccess { $fullPath = static::getFilePath($this->theme, $this->fileName); - if (File::isFile($fullPath) && $this->originalFileName !== $this->fileName) - throw new ApplicationException(Lang::get('cms::lang.cms_object.file_already_exists', ['name'=>$this->fileName])); + if (File::isFile($fullPath) && $this->originalFileName !== $this->fileName) { + throw new ApplicationException(Lang::get( + 'cms::lang.cms_object.file_already_exists', + ['name'=>$this->fileName] + )); + } $dirPath = rtrim(static::getFilePath($this->theme, ''), '/'); if (!file_exists($dirPath) || !is_dir($dirPath)) { - if (!File::makeDirectory($dirPath, 0777, true, true)) - throw new ApplicationException(Lang::get('cms::lang.cms_object.error_creating_directory', ['name'=>$dirPath])); + if (!File::makeDirectory($dirPath, 0777, true, true)) { + throw new ApplicationException(Lang::get( + 'cms::lang.cms_object.error_creating_directory', + ['name'=>$dirPath] + )); + } } if (($pos = strpos($this->fileName, '/')) !== false) { $dirPath = static::getFilePath($this->theme, dirname($this->fileName)); - if (!is_dir($dirPath) && !File::makeDirectory($dirPath, 0777, true, true)) - throw new ApplicationException(Lang::get('cms::lang.cms_object.error_creating_directory', ['name'=>$dirPath])); + if (!is_dir($dirPath) && !File::makeDirectory($dirPath, 0777, true, true)) { + throw new ApplicationException(Lang::get( + 'cms::lang.cms_object.error_creating_directory', + ['name'=>$dirPath] + )); + } } $newFullPath = $fullPath; - if (@File::put($fullPath, $this->content) === false) - throw new ApplicationException(Lang::get('cms::lang.cms_object.error_saving', ['name'=>$this->fileName])); + if (@File::put($fullPath, $this->content) === false) { + throw new ApplicationException(Lang::get( + 'cms::lang.cms_object.error_saving', + ['name'=>$this->fileName] + )); + } if (strlen($this->originalFileName) && $this->originalFileName !== $this->fileName) { $fullPath = static::getFilePath($this->theme, $this->originalFileName); - if (File::isFile($fullPath)) + if (File::isFile($fullPath)) { @unlink($fullPath); + } } clearstatcache(); @@ -378,24 +411,27 @@ class CmsObject implements ArrayAccess */ public static function listInTheme($theme, $skipCache = false) { - if (!$theme) + if (!$theme) { throw new ApplicationException(Lang::get('cms::lang.theme.active.not_set')); + } $dirPath = $theme->getPath().'/'.static::getObjectTypeDirName(); $result = []; - if (!File::isDirectory($dirPath)) + if (!File::isDirectory($dirPath)) { return $result; + } $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirPath)); $it->setMaxDepth(1); // Support only a single level of subdirectories $it->rewind(); - while($it->valid()) { + while ($it->valid()) { if ($it->isFile() && in_array($it->getExtension(), static::$allowedExtensions)) { $filePath = $it->getBasename(); - if ($it->getDepth() > 0) + if ($it->getDepth() > 0) { $filePath = basename($it->getPath()).'/'.$filePath; + } $page = $skipCache ? static::load($theme, $filePath) : static::loadCached($theme, $filePath); $result[] = $page; @@ -426,8 +462,9 @@ class CmsObject implements ArrayAccess public function __get($name) { $methodName = 'get'.ucfirst($name); - if (method_exists($this, $methodName)) + if (method_exists($this, $methodName)) { return $this->$methodName(); + } return null; } @@ -440,8 +477,9 @@ class CmsObject implements ArrayAccess public function __isset($key) { $methodName = 'get'.ucfirst($key); - if (method_exists($this, $methodName)) + if (method_exists($this, $methodName)) { return true; + } return false; } @@ -540,18 +578,24 @@ class CmsObject implements ArrayAccess * Initializes the object properties from the cached data. * @param array $cached The cached data array. */ - protected function initFromCache($cached) {} + protected function initFromCache($cached) + { + } /** * Initializes a cache item. * @param array &$item The cached item array. */ - protected function initCacheItem(&$item) {} + protected function initCacheItem(&$item) + { + } /** * Returns the directory name corresponding to the object type. * For pages the directory name is "pages", for layouts - "layouts", etc. * @return string */ - public static function getObjectTypeDirName() {} -} \ No newline at end of file + public static function getObjectTypeDirName() + { + } +} diff --git a/modules/cms/classes/CmsObjectCollection.php b/modules/cms/classes/CmsObjectCollection.php index 7a358ffc2..85c4f72ca 100644 --- a/modules/cms/classes/CmsObjectCollection.php +++ b/modules/cms/classes/CmsObjectCollection.php @@ -11,4 +11,4 @@ use System\Classes\ApplicationException; */ class CmsObjectCollection extends CollectionBase { -} \ No newline at end of file +} diff --git a/modules/cms/classes/CmsObjectQuery.php b/modules/cms/classes/CmsObjectQuery.php index 529f6ee28..da069f81f 100644 --- a/modules/cms/classes/CmsObjectQuery.php +++ b/modules/cms/classes/CmsObjectQuery.php @@ -69,13 +69,15 @@ class CmsObjectQuery */ public function find($fileName) { - if (!$this->theme) + if (!$this->theme) { $this->inEditTheme(); + } - if ($this->useCache) + if ($this->useCache) { return forward_static_call([$this->cmsObject, 'loadCached'], $this->theme, $fileName); - else + } else { return forward_static_call([$this->cmsObject, 'load'], $this->theme, $fileName); + } } /** @@ -84,8 +86,9 @@ class CmsObjectQuery */ public function all() { - if (!$this->theme) + if (!$this->theme) { $this->inEditTheme(); + } $collection = forward_static_call([$this->cmsObject, 'listInTheme'], $this->theme, !$this->useCache); $collection = new CmsObjectCollection($collection); @@ -108,5 +111,4 @@ class CmsObjectQuery $className = get_class($this); throw new \BadMethodCallException("Call to undefined method {$className}::{$method}()"); } - -} \ No newline at end of file +} diff --git a/modules/cms/classes/CmsPropertyHelper.php b/modules/cms/classes/CmsPropertyHelper.php index d38154d74..8a5916c73 100644 --- a/modules/cms/classes/CmsPropertyHelper.php +++ b/modules/cms/classes/CmsPropertyHelper.php @@ -27,7 +27,10 @@ class CmsPropertyHelper */ public static function listPages() { - Flash::warning("CmsPropertyHelper::listPages() is deprecated, use Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName') instead."); + Flash::warning( + "CmsPropertyHelper::listPages() is deprecated, use Page::sortBy('baseFileName')->lists('baseFileName', + 'baseFileName') instead." + ); return Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName'); } -} \ No newline at end of file +} diff --git a/modules/cms/classes/CodeBase.php b/modules/cms/classes/CodeBase.php index 90436a464..8744c057b 100644 --- a/modules/cms/classes/CodeBase.php +++ b/modules/cms/classes/CodeBase.php @@ -45,19 +45,25 @@ class CodeBase extends Extendable implements ArrayAccess * This event is triggered when all components are initialized and before AJAX is handled. * The layout's onInit method triggers before the page's onInit method. */ - public function onInit() {} + public function onInit() + { + } /** * This event is triggered in the beginning of the execution cycle. * The layout's onStart method triggers before the page's onStart method. */ - public function onStart() {} + public function onStart() + { + } /** * This event is triggered in the end of the execution cycle, but before the page is displayed. * The layout's onEnd method triggers after the page's onEnd method. */ - public function onEnd() {} + public function onEnd() + { + } /** * ArrayAccess implementation @@ -99,8 +105,9 @@ class CodeBase extends Extendable implements ArrayAccess */ public function __call($method, $parameters) { - if (method_exists($this, $method)) + if (method_exists($this, $method)) { return call_user_func_array([$this, $method], $parameters); + } return call_user_func_array([$this->controller, $method], $parameters); } @@ -115,11 +122,13 @@ class CodeBase extends Extendable implements ArrayAccess */ public function __get($name) { - if (($value = $this->page->{$name}) !== null) + if (($value = $this->page->{$name}) !== null) { return $value; + } - if (array_key_exists($name, $this->controller->vars)) + if (array_key_exists($name, $this->controller->vars)) { return $this[$name]; + } return null; } diff --git a/modules/cms/classes/CodeParser.php b/modules/cms/classes/CodeParser.php index 866d02424..af0318d10 100644 --- a/modules/cms/classes/CodeParser.php +++ b/modules/cms/classes/CodeParser.php @@ -99,13 +99,15 @@ class CodeParser $body = preg_replace($pattern, '', $body); $parentClass = $this->object->getCodeClassParent(); - if ($parentClass !== null) + if ($parentClass !== null) { $parentClass = ' extends '.$parentClass; + } $fileContents = 'validate($fileContents); $dir = dirname($path); - if (!File::isDirectory($dir) && !@File::makeDirectory($dir, 0777, true)) + if (!File::isDirectory($dir) && !@File::makeDirectory($dir, 0777, true)) { throw new SystemException(Lang::get('system::lang.directory.create_fail', ['name'=>$dir])); + } - if (!@File::put($path, $fileContents)) + if (!@File::put($path, $fileContents)) { throw new SystemException(Lang::get('system::lang.file.create_fail', ['name'=>$dir])); + } $cached = $this->getCachedInfo(); - if (!$cached) + if (!$cached) { $cached = []; + } $result['className'] = $className; $result['source'] = 'parser'; @@ -148,8 +153,9 @@ class CodeParser { $data = $this->parse(); - if (!class_exists($data['className'])) + if (!class_exists($data['className'])) { require_once $data['filePath']; + } $className = $data['className']; return new $className($page, $layout, $controller); @@ -186,8 +192,9 @@ class CodeParser protected function getCachedInfo() { $cached = Cache::get($this->dataCacheKey, false); - if ($cached !== false && ($cached = @unserialize($cached)) !== false) + if ($cached !== false && ($cached = @unserialize($cached)) !== false) { return $cached; + } return null; } @@ -200,10 +207,11 @@ class CodeParser { $cached = $this->getCachedInfo(); if ($cached !== null) { - if (array_key_exists($this->filePath, $cached)) + if (array_key_exists($this->filePath, $cached)) { return $cached[$this->filePath]; + } } return null; } -} \ No newline at end of file +} diff --git a/modules/cms/classes/CombineAssets.php b/modules/cms/classes/CombineAssets.php index 952b1e049..b1d1841b0 100644 --- a/modules/cms/classes/CombineAssets.php +++ b/modules/cms/classes/CombineAssets.php @@ -115,8 +115,9 @@ class CombineAssets */ public static function combine($assets = [], $path = null) { - if (static::$instance === null) + if (static::$instance === null) { static::$instance = new self(); + } return static::$instance->prepareRequest($assets, $path); } @@ -128,8 +129,9 @@ class CombineAssets public function getContents($cacheId) { $cacheInfo = $this->getCache($cacheId); - if (!$cacheInfo) + if (!$cacheInfo) { throw new CmsException(Lang::get('cms::lang.combiner.not_found', ['name'=>$cacheId])); + } $this->path = $cacheInfo['path']; $this->storagePath = storage_path().'/combiner/cms'; @@ -157,8 +159,9 @@ class CombineAssets { $extension = strtolower($extension); - if (!isset($this->aliases[$extension])) + if (!isset($this->aliases[$extension])) { $this->aliases[$extension] = []; + } $this->aliases[$extension][$alias] = $file; @@ -172,10 +175,11 @@ class CombineAssets */ public function resetAliases($extension = null) { - if ($extension === null) + if ($extension === null) { $this->aliases = []; - else + } else { $this->aliases[$extension] = []; + } return $this; } @@ -187,12 +191,13 @@ class CombineAssets */ public function getAliases($extension = null) { - if ($extension === null) + if ($extension === null) { return $this->aliases; - elseif (isset($this->aliases[$extension])) + } elseif (isset($this->aliases[$extension])) { return $this->aliases[$extension]; - else + } else { return null; + } } /** @@ -212,11 +217,13 @@ class CombineAssets $extension = strtolower($extension); - if (!isset($this->filters[$extension])) + if (!isset($this->filters[$extension])) { $this->filters[$extension] = []; + } - if ($filter !== null) + if ($filter !== null) { $this->filters[$extension][] = $filter; + } return $this; } @@ -228,10 +235,11 @@ class CombineAssets */ public function resetFilters($extension = null) { - if ($extension === null) + if ($extension === null) { $this->filters = []; - else + } else { $this->filters[$extension] = []; + } return $this; } @@ -243,12 +251,13 @@ class CombineAssets */ public function getFilters($extension = null) { - if ($extension === null) + if ($extension === null) { return $this->filters; - elseif (isset($this->filters[$extension])) + } elseif (isset($this->filters[$extension])) { return $this->filters[$extension]; - else + } else { return null; + } } /** @@ -260,14 +269,16 @@ class CombineAssets */ protected function prepareRequest(array $assets, $path = null) { - if (substr($path, -1) != '/') + if (substr($path, -1) != '/') { $path = $path.'/'; + } $this->path = public_path().$path; $this->storagePath = storage_path().'/combiner/cms'; - if (!is_array($assets)) + if (!is_array($assets)) { $assets = [$assets]; + } /* * Split assets in to groups. @@ -304,8 +315,7 @@ class CombineAssets if (count($combineCss) > count($combineJs)) { $extension = 'css'; $assets = $combineCss; - } - else { + } else { $extension = 'js'; $assets = $combineJs; } @@ -315,12 +325,14 @@ class CombineAssets */ if ($aliasMap = $this->getAliases($extension)) { foreach ($assets as $key => $asset) { - if (substr($asset, 0, 1) !== '@') + if (substr($asset, 0, 1) !== '@') { continue; + } $_asset = substr($asset, 1); - if (isset($aliasMap[$_asset])) + if (isset($aliasMap[$_asset])) { $assets[$key] = $aliasMap[$_asset]; + } } } @@ -358,10 +370,11 @@ class CombineAssets $combineAction = 'Cms\Classes\Controller@combine'; $actionExists = Route::getRoutes()->getByAction($combineAction) !== null; - if ($actionExists) + if ($actionExists) { return URL::action($combineAction, [$outputFilename], false); - else + } else { return Request::getBasePath().'/combine/'.$outputFilename; + } } /** @@ -408,8 +421,9 @@ class CombineAssets $path = $baseUri.'/combine'; } - if (strpos($path, '/') === 0) + if (strpos($path, '/') === 0) { $path = substr($path, 1); + } $path = str_replace('.', '-', $path).'/'; return $path; @@ -426,8 +440,9 @@ class CombineAssets { $cacheId = 'combiner.'.$cacheId; - if (Cache::has($cacheId)) + if (Cache::has($cacheId)) { return false; + } $this->putCacheIndex($cacheId); Cache::forever($cacheId, serialize($cacheInfo)); @@ -443,8 +458,9 @@ class CombineAssets { $cacheId = 'combiner.'.$cacheId; - if (!Cache::has($cacheId)) + if (!Cache::has($cacheId)) { return false; + } return unserialize(Cache::get($cacheId)); } @@ -465,8 +481,9 @@ class CombineAssets */ public static function resetCache() { - if (!Cache::has('combiner.index')) + if (!Cache::has('combiner.index')) { return; + } $index = unserialize(Cache::get('combiner.index')); foreach ($index as $cacheId) { @@ -486,16 +503,17 @@ class CombineAssets { $index = []; - if (Cache::has('combiner.index')) + if (Cache::has('combiner.index')) { $index = unserialize(Cache::get('combiner.index')); + } - if (in_array($cacheId, $index)) + if (in_array($cacheId, $index)) { return false; + } $index[] = $cacheId; Cache::forever('combiner.index', serialize($index)); return true; } - -} \ No newline at end of file +} diff --git a/modules/cms/classes/ComponentBase.php b/modules/cms/classes/ComponentBase.php index 8225d10b4..67e3a705b 100644 --- a/modules/cms/classes/ComponentBase.php +++ b/modules/cms/classes/ComponentBase.php @@ -113,19 +113,29 @@ abstract class ComponentBase extends Extendable /** * Executed when this component is first initialized, before AJAX requests. */ - public function init() {} - public function onInit() {} // Deprecated: Remove ithis line if year >= 2015 + public function init() + { + } + + // @deprecated: Remove this line if year >= 2015 + public function onInit() + { + } /** * Executed when this component is bound to a page or layout, part of * the page life cycle. */ - public function onRun() {} + public function onRun() + { + } /** * Executed when this component is rendered on a page or layout. */ - public function onRender() {} + public function onRender() + { + } /** * Dynamically handle calls into the controller instance. @@ -135,11 +145,13 @@ abstract class ComponentBase extends Extendable */ public function __call($method, $parameters) { - if (method_exists($this, $method)) + if (method_exists($this, $method)) { return call_user_func_array([$this, $method], $parameters); + } - if (method_exists($this->controller, $method)) + if (method_exists($this->controller, $method)) { return call_user_func_array([$this->controller, $method], $parameters); + } throw new CmsException(Lang::get('cms::lang.component.method_not_found', [ 'name' => get_class($this), @@ -161,12 +173,13 @@ abstract class ComponentBase extends Extendable * @param $default A default value to return if no value is found. * @return string */ - public function propertyOrParam($name, $default = null) + public function propertyOrParam($name, $default = null) { $value = $this->property($name, $default); - if (substr($value, 0, 1) == ':') + if (substr($value, 0, 1) == ':') { return $this->param(substr($value, 1), $default); + } return $value; } @@ -202,5 +215,4 @@ abstract class ComponentBase extends Extendable // return $this->pageUrl($page, $params); // } - -} \ No newline at end of file +} diff --git a/modules/cms/classes/ComponentHelpers.php b/modules/cms/classes/ComponentHelpers.php index 9e0189940..ba4b87e2d 100644 --- a/modules/cms/classes/ComponentHelpers.php +++ b/modules/cms/classes/ComponentHelpers.php @@ -38,7 +38,9 @@ class ComponentHelpers ]; foreach ($params as $name => $value) { - if (isset($property[$name])) continue; + if (isset($property[$name])) { + continue; + } $property[$name] = $value; } @@ -47,7 +49,9 @@ class ComponentHelpers */ $translate = ['title', 'description']; foreach ($property as $name => $value) { - if (!in_array($name, $translate)) continue; + if (!in_array($name, $translate)) { + continue; + } $property[$name] = Lang::get($value); } @@ -69,8 +73,9 @@ class ComponentHelpers $result['oc.alias'] = $component->alias; $properties = $component->defineProperties(); - foreach ($properties as $name => $params) + foreach ($properties as $name => $params) { $result[$name] = $component->property($name); + } return json_encode($result); } @@ -104,4 +109,4 @@ class ComponentHelpers return Lang::get($name); } -} \ No newline at end of file +} diff --git a/modules/cms/classes/ComponentManager.php b/modules/cms/classes/ComponentManager.php index e3792f4ce..fa69c98be 100644 --- a/modules/cms/classes/ComponentManager.php +++ b/modules/cms/classes/ComponentManager.php @@ -61,8 +61,9 @@ class ComponentManager foreach ($plugins as $plugin) { $components = $plugin->registerComponents(); - if (!is_array($components)) + if (!is_array($components)) { continue; + } foreach ($components as $className => $code) { $this->registerComponent($className, $code, $plugin); @@ -91,23 +92,31 @@ class ComponentManager */ public function registerComponent($className, $code = null, $plugin = null) { - if (!$this->classMap) + if (!$this->classMap) { $this->classMap = []; + } - if (!$this->codeMap) + if (!$this->codeMap) { $this->codeMap = []; + } - if (!$code) + if (!$code) { $code = Str::getClassId($className); + } - if ($code == 'viewBag' && $className != 'Cms\Classes\ViewBag') - throw new SystemException(sprintf('The component code viewBag is reserved. Please use another code for the component class %s.', $className)); + if ($code == 'viewBag' && $className != 'Cms\Classes\ViewBag') { + throw new SystemException(sprintf( + 'The component code viewBag is reserved. Please use another code for the component class %s.', + $className + )); + } $className = Str::normalizeClassName($className); $this->codeMap[$code] = $className; $this->classMap[$className] = $code; - if ($plugin !== null) + if ($plugin !== null) { $this->pluginMap[$className] = $plugin; + } } /** @@ -116,8 +125,9 @@ class ComponentManager */ public function listComponents() { - if ($this->codeMap === null) + if ($this->codeMap === null) { $this->loadComponents(); + } return $this->codeMap; } @@ -128,8 +138,9 @@ class ComponentManager */ public function listComponentDetails() { - if ($this->detailsCache !== null) + if ($this->detailsCache !== null) { return $this->detailsCache; + } $details = []; foreach ($this->listComponents() as $componentAlias => $componentClass) { @@ -148,12 +159,14 @@ class ComponentManager { $codes = $this->listComponents(); - if (isset($codes[$name])) + if (isset($codes[$name])) { return $codes[$name]; + } $name = Str::normalizeClassName($name); - if (isset($this->classMap[$name])) + if (isset($this->classMap[$name])) { return $name; + } return null; } @@ -166,8 +179,9 @@ class ComponentManager public function hasComponent($name) { $className = $this->resolve($name); - if (!$className) + if (!$className) { return false; + } return isset($this->classMap[$className]); } @@ -182,11 +196,19 @@ class ComponentManager public function makeComponent($name, $cmsObject = null, $properties = []) { $className = $this->resolve($name); - if (!$className) - throw new SystemException(sprintf('Class name is not registered for the component %s. Check the component plugin.', $name)); + if (!$className) { + throw new SystemException(sprintf( + 'Class name is not registered for the component %s. Check the component plugin.', + $name + )); + } - if (!class_exists($className)) - throw new SystemException(sprintf('Component class not found %s.Check the component plugin.', $className)); + if (!class_exists($className)) { + throw new SystemException(sprintf( + 'Component class not found %s.Check the component plugin.', + $className + )); + } $component = new $className($cmsObject, $properties); $component->name = $name; @@ -202,9 +224,10 @@ class ComponentManager public function findComponentPlugin($component) { $className = Str::normalizeClassName(get_class($component)); - if (isset($this->pluginMap[$className])) + if (isset($this->pluginMap[$className])) { return $this->pluginMap[$className]; + } return null; } -} \ No newline at end of file +} diff --git a/modules/cms/classes/ComponentPartial.php b/modules/cms/classes/ComponentPartial.php index 7e6238c29..d93b2fc2d 100644 --- a/modules/cms/classes/ComponentPartial.php +++ b/modules/cms/classes/ComponentPartial.php @@ -59,8 +59,9 @@ class ComponentPartial extends CmsObject if (!File::isFile($path)) { $sharedDir = dirname($component->getPath()).'/partials'; $sharedPath = $sharedDir.'/'.$fileName; - if (File::isFile($sharedPath)) + if (File::isFile($sharedPath)) { return $sharedPath; + } } return $path; diff --git a/modules/cms/classes/Content.php b/modules/cms/classes/Content.php index 3aeaaf536..a3393ffab 100644 --- a/modules/cms/classes/Content.php +++ b/modules/cms/classes/Content.php @@ -37,8 +37,9 @@ class Content extends CmsCompoundObject */ public static function load($theme, $fileName) { - if ($obj = parent::load($theme, $fileName)) + if ($obj = parent::load($theme, $fileName)) { $obj->parsedMarkup = $obj->parseMarkup(); + } return $obj; } @@ -70,8 +71,9 @@ class Content extends CmsCompoundObject { $result = $this->markup; - if (strtolower(File::extension($this->fileName)) == 'md') + if (strtolower(File::extension($this->fileName)) == 'md') { $result = Markdown::parse($this->markup); + } return $result; } diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index 82d16e2fc..4f74e3398 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -107,8 +107,9 @@ class Controller extends BaseController public function __construct($theme = null) { $this->theme = $theme ? $theme : Theme::getActiveTheme(); - if (!$this->theme) + if (!$this->theme) { throw new CmsException(Lang::get('cms::lang.theme.active.not_found')); + } $this->assetPath = Config::get('cms.themesDir').'/'.$this->theme->getDirName(); $this->router = new Router($this->theme); @@ -137,29 +138,34 @@ class Controller extends BaseController */ public function run($url = '/') { - if ($url === null) + if ($url === null) { $url = Request::path(); + } - if (!strlen($url)) + if (!strlen($url)) { $url = '/'; + } /* * Handle hidden pages */ $page = $this->router->findByUrl($url); if ($page && $page->hidden) { - if (!BackendAuth::getUser()) + if (!BackendAuth::getUser()) { $page = null; + } } /* * Extensibility */ - if ($event = $this->fireEvent('page.beforeDisplay', [$url, $page], true)) + if ($event = $this->fireEvent('page.beforeDisplay', [$url, $page], true)) { return $event; + } - if ($event = Event::fire('cms.page.beforeDisplay', [$this, $url, $page], true)) + if ($event = Event::fire('cms.page.beforeDisplay', [$this, $url, $page], true)) { return $event; + } /* * If the page was not found, render the 404 page - either provided by the theme or the built-in one. @@ -168,11 +174,13 @@ class Controller extends BaseController $this->setStatusCode(404); // Log the 404 request - if (!App::runningUnitTests()) + if (!App::runningUnitTests()) { RequestLog::add(); + } - if (!$page = $this->router->findByUrl('/404')) + if (!$page = $this->router->findByUrl('/404')) { return Response::make(View::make('cms::404'), $this->statusCode); + } } $this->page = $page; @@ -181,10 +189,11 @@ class Controller extends BaseController * If the page doesn't refer any layout, create the fallback layout. * Otherwise load the layout specified in the page. */ - if (!$page->layout) + if (!$page->layout) { $layout = Layout::initFallback($this->theme); - elseif (($layout = Layout::loadCached($this->theme, $page->layout)) === null) + } elseif (($layout = Layout::loadCached($this->theme, $page->layout)) === null) { throw new CmsException(Lang::get('cms::lang.layout.not_found', ['name'=>$page->layout])); + } $this->layout = $layout; @@ -223,29 +232,38 @@ class Controller extends BaseController /* * Extensibility */ - if ($event = $this->fireEvent('page.init', [$url, $page], true)) + if ($event = $this->fireEvent('page.init', [$url, $page], true)) { return $event; + } - if ($event = Event::fire('cms.page.init', [$this, $url, $page], true)) + if ($event = Event::fire('cms.page.init', [$this, $url, $page], true)) { return $event; + } /* * Execute AJAX event */ - if ($ajaxResponse = $this->execAjaxHandlers()) + if ($ajaxResponse = $this->execAjaxHandlers()) { return $ajaxResponse; + } /* * Execute postback handler */ - if (($handler = post('_handler')) && ($handlerResponse = $this->runAjaxHandler($handler)) && $handlerResponse !== true) + if ( + ($handler = post('_handler')) && + ($handlerResponse = $this->runAjaxHandler($handler)) && + $handlerResponse !== true + ) { return $handlerResponse; + } /* * Execute page lifecycle */ - if ($cycleResponse = $this->execPageCycle()) + if ($cycleResponse = $this->execPageCycle()) { return $cycleResponse; + } /* * Render the page @@ -268,14 +286,17 @@ class Controller extends BaseController /* * Extensibility */ - if ($event = $this->fireEvent('page.display', [$url, $page], true)) + if ($event = $this->fireEvent('page.display', [$url, $page], true)) { return $event; + } - if ($event = Event::fire('cms.page.display', [$this, $url, $page], true)) + if ($event = Event::fire('cms.page.display', [$this, $url, $page], true)) { return $event; + } - if (!is_string($result)) + if (!is_string($result)) { return $result; + } return Response::make($result, $this->statusCode); } @@ -295,15 +316,17 @@ class Controller extends BaseController 'auto_reload' => true, 'debug' => $isDebugMode, ]; - if (!Config::get('cms.twigNoCache')) + if (!Config::get('cms.twigNoCache')) { $options['cache'] = storage_path().'/twig'; + } $this->twig = new Twig_Environment($this->loader, $options); $this->twig->addExtension(new CmsTwigExtension($this)); $this->twig->addExtension(new SystemTwigExtension); - if ($isDebugMode) + if ($isDebugMode) { $this->twig->addExtension(new DebugExtension($this)); + } } /** @@ -335,13 +358,15 @@ class Controller extends BaseController { if (!$this->layout->isFallBack()) { foreach ($this->layout->settings['components'] as $component => $properties) { - list($name, $alias) = strpos($component, ' ') ? explode(' ', $component) : array($component, $component); + list($name, $alias) = strpos($component, ' ') ? + explode(' ', $component) : array($component, $component); $this->addComponent($name, $alias, $properties, true); } } foreach ($this->page->settings['components'] as $component => $properties) { - list($name, $alias) = strpos($component, ' ') ? explode(' ', $component) : array($component, $component); + list($name, $alias) = strpos($component, ' ') ? + explode(' ', $component) : array($component, $component); $this->addComponent($name, $alias, $properties); } } @@ -359,15 +384,16 @@ class Controller extends BaseController $manager = ComponentManager::instance(); if ($addToLayout) { - if (!$componentObj = $manager->makeComponent($name, $this->layoutObj, $properties)) + if (!$componentObj = $manager->makeComponent($name, $this->layoutObj, $properties)) { throw new CmsException(Lang::get('cms::lang.component.not_found', ['name'=>$name])); + } $componentObj->alias = $alias; $this->vars[$alias] = $this->layout->components[$alias] = $componentObj; - } - else { - if (!$componentObj = $manager->makeComponent($name, $this->pageObj, $properties)) + } else { + if (!$componentObj = $manager->makeComponent($name, $this->pageObj, $properties)) { throw new CmsException(Lang::get('cms::lang.component.not_found', ['name'=>$name])); + } $componentObj->alias = $alias; $this->vars[$alias] = $this->page->components[$alias] = $componentObj; @@ -389,8 +415,9 @@ class Controller extends BaseController /* * Validate the handler name */ - if (!preg_match('/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/', $handler)) + if (!preg_match('/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/', $handler)) { throw new CmsException(Lang::get('cms::lang.ajax_handler.invalid_name', ['name'=>$handler])); + } /* * Validate the handler partial list @@ -399,11 +426,11 @@ class Controller extends BaseController $partialList = explode('&', $partialList); foreach ($partialList as $partial) { - if (!preg_match('/^(?:\w+\:{2}|@)?[a-z0-9\_\-\.\/]+$/i', $partial)) + if (!preg_match('/^(?:\w+\:{2}|@)?[a-z0-9\_\-\.\/]+$/i', $partial)) { throw new CmsException(Lang::get('cms::lang.partial.invalid_name', ['name'=>$partial])); + } } - } - else { + } else { $partialList = []; } @@ -412,23 +439,26 @@ class Controller extends BaseController /* * Execute the handler */ - if (!$result = $this->runAjaxHandler($handler)) + if (!$result = $this->runAjaxHandler($handler)) { throw new CmsException(Lang::get('cms::lang.ajax_handler.not_found', ['name'=>$handler])); + } /* * If the handler returned an array, we should add it to output for rendering. * If it is a string, add it to the array with the key "result". */ - if (is_array($result)) + if (is_array($result)) { $responseContents = array_merge($responseContents, $result); - elseif (is_string($result)) + } elseif (is_string($result)) { $responseContents['result'] = $result; + } /* * Render partials and return the response as array that will be converted to JSON automatically. */ - foreach ($partialList as $partial) + foreach ($partialList as $partial) { $responseContents[$partial] = $this->renderPartial($partial); + } /* * If the handler returned a redirect, process it so framework.js knows to redirect @@ -439,27 +469,28 @@ class Controller extends BaseController } return Response::make()->setContent($responseContents); - } - catch (ValidationException $ex) { + } catch (ValidationException $ex) { /* * Handle validation errors */ $responseContents['X_OCTOBER_ERROR_FIELDS'] = $ex->getFields(); $responseContents['X_OCTOBER_ERROR_MESSAGE'] = $ex->getMessage(); return Response::make($responseContents, 406); - } - catch (ApplicationException $ex) { + } catch (ApplicationException $ex) { return Response::make($ex->getMessage(), 500); - } - catch (Exception $ex) { + } catch (Exception $ex) { /* * Display a "dumbed down" error if custom page is activated * otherwise display a more detailed error. */ - if (Config::get('cms.customErrorPage', false)) + if (Config::get('cms.customErrorPage', false)) { return Response::make($ex->getMessage(), 500); + } - return Response::make(sprintf('"%s" on line %s of %s', $ex->getMessage(), $ex->getLine(), $ex->getFile()), 500); + return Response::make( + sprintf('"%s" on line %s of %s', $ex->getMessage(), $ex->getLine(), $ex->getFile()), + 500 + ); } } @@ -486,11 +517,10 @@ class Controller extends BaseController $result = $componentObj->$handlerName(); return ($result) ?: true; } - } /* * Process code section handler */ - else { + } else { if (method_exists($this->pageObj, $handler)) { $result = $this->pageObj->$handler(); return ($result) ?: true; @@ -533,11 +563,13 @@ class Controller extends BaseController /* * Extensibility */ - if ($event = $this->fireEvent('page.start', [], true)) + if ($event = $this->fireEvent('page.start', [], true)) { return $event; + } - if ($event = Event::fire('cms.page.start', [$this], true)) + if ($event = Event::fire('cms.page.start', [$this], true)) { return $event; + } /* * Run layout functions @@ -549,7 +581,9 @@ class Controller extends BaseController || ($result = $this->layoutObj->onBeforePageStart())) ? $result: null; CmsException::unmask(); - if ($response) return $response; + if ($response) { + return $response; + } } /* @@ -561,7 +595,9 @@ class Controller extends BaseController || ($result = $this->pageObj->onEnd())) ? $result : null; CmsException::unmask(); - if ($response) return $response; + if ($response) { + return $response; + } /* * Run remaining layout functions @@ -575,11 +611,13 @@ class Controller extends BaseController /* * Extensibility */ - if ($event = $this->fireEvent('page.end', [], true)) + if ($event = $this->fireEvent('page.end', [], true)) { return $event; + } - if ($event = Event::fire('cms.page.end', [$this], true)) + if ($event = Event::fire('cms.page.end', [$this], true)) { return $event; + } return $response; } @@ -595,11 +633,13 @@ class Controller extends BaseController /* * Extensibility */ - if ($event = $this->fireEvent('page.render', [$contents], true)) + if ($event = $this->fireEvent('page.render', [$contents], true)) { return $event; + } - if ($event = Event::fire('cms.page.render', [$this, $contents], true)) + if ($event = Event::fire('cms.page.render', [$this, $contents], true)) { return $event; + } return $contents; } @@ -617,8 +657,9 @@ class Controller extends BaseController /* * Alias @ symbol for :: */ - if (substr($name, 0, 1) == '@') + if (substr($name, 0, 1) == '@') { $name = '::' . substr($name, 1); + } /* * Process Component partial @@ -633,23 +674,23 @@ class Controller extends BaseController if (!strlen($componentAlias)) { if ($this->componentContext !== null) { $componentObj = $this->componentContext; - } - elseif (($componentObj = $this->findComponentByPartial($partialName)) === null) { - if ($throwException) + } elseif (($componentObj = $this->findComponentByPartial($partialName)) === null) { + if ($throwException) { throw new CmsException(Lang::get('cms::lang.partial.not_found', ['name'=>$name])); - else + } else { return false; + } } - } /* * Component alias is supplied */ - else { + } else { if (($componentObj = $this->findComponentByName($componentAlias)) === null) { - if ($throwException) + if ($throwException) { throw new CmsException(Lang::get('cms::lang.component.not_found', ['name'=>$componentAlias])); - else + } else { return false; + } } } @@ -667,31 +708,33 @@ class Controller extends BaseController /* * Check the component partial */ - if ($partial === null) + if ($partial === null) { $partial = ComponentPartial::loadCached($componentObj, $partialName); + } if ($partial === null) { - if ($throwException) + if ($throwException) { throw new CmsException(Lang::get('cms::lang.partial.not_found', ['name'=>$name])); - else + } else { return false; + } } /* * Set context for self access */ $this->vars['__SELF__'] = $componentObj; - } - else { + } else { /* * Process theme partial */ if (($partial = Partial::loadCached($this->theme, $name)) === null) { - if ($throwException) + if ($throwException) { throw new CmsException(Lang::get('cms::lang.partial.not_found', ['name'=>$name])); - else + } else { return false; + } } } @@ -714,28 +757,29 @@ class Controller extends BaseController /* * Extensibility */ - if ($event = $this->fireEvent('page.beforeRenderContent', [$name], true)) + if ($event = $this->fireEvent('page.beforeRenderContent', [$name], true)) { $content = $event; - - elseif ($event = Event::fire('cms.page.beforeRenderContent', [$this, $name], true)) + } elseif ($event = Event::fire('cms.page.beforeRenderContent', [$this, $name], true)) { $content = $event; - /* * Load content from theme */ - elseif (($content = Content::loadCached($this->theme, $name)) === null) + } elseif (($content = Content::loadCached($this->theme, $name)) === null) { throw new CmsException(Lang::get('cms::lang.content.not_found', ['name'=>$name])); + } $fileContent = $content->parsedMarkup; /* * Extensibility */ - if ($event = $this->fireEvent('page.renderContent', [$name, $fileContent], true)) + if ($event = $this->fireEvent('page.renderContent', [$name, $fileContent], true)) { return $event; + } - if ($event = Event::fire('cms.page.renderContent', [$this, $name, $fileContent], true)) + if ($event = Event::fire('cms.page.renderContent', [$this, $name, $fileContent], true)) { return $event; + } return $fileContent; } @@ -749,8 +793,9 @@ class Controller extends BaseController if ($componentObj = $this->findComponentByName($name)) { $componentObj->id = uniqid($name); $componentObj->setProperties(array_merge($componentObj->getProperties(), $parameters)); - if ($result = $componentObj->onRender()) + if ($result = $componentObj->onRender()) { return $result; + } } return $this->renderPartial($name.'::default', [], false); @@ -823,8 +868,9 @@ class Controller extends BaseController */ public function pageUrl($name, $parameters = [], $routePersistence = true, $absolute = true) { - if (!$name) + if (!$name) { return null; + } /* * Second parameter can act as third @@ -834,14 +880,17 @@ class Controller extends BaseController $parameters = []; } - if ($routePersistence) + if ($routePersistence) { $parameters = array_merge($this->router->getParameters(), $parameters); + } - if (!$url = $this->router->findByFile($name, $parameters)) + if (!$url = $this->router->findByFile($name, $parameters)) { return null; + } - if (substr($url, 0, 1) == '/') + if (substr($url, 0, 1) == '/') { $url = substr($url, 1); + } return URL::action('Cms\Classes\Controller@run', ['slug' => $url], $absolute); } @@ -867,10 +916,11 @@ class Controller extends BaseController if (is_array($url)) { $_url = Request::getBaseUrl(); $_url .= CombineAssets::combine($url, $themePath); - } - else { + } else { $_url = Request::getBasePath().$themePath; - if ($url !== null) $_url .= '/'.$url; + if ($url !== null) { + $_url .= '/'.$url; + } } return $_url; @@ -894,19 +944,17 @@ class Controller extends BaseController */ public function combine($name) { - try { - if (!strpos($name, '-')) - throw new CmsException(Lang::get('cms::lang.combiner.not_found', ['name'=>$name])); - - $parts = explode('-', $name); - $cacheId = $parts[0]; - - $combiner = new CombineAssets; - return $combiner->getContents($cacheId); - } - catch (Exception $ex) { - return '/* '.$ex->getMessage().' */'; - } + try { + if (!strpos($name, '-')) { + throw new CmsException(Lang::get('cms::lang.combiner.not_found', ['name'=>$name])); + } + $parts = explode('-', $name); + $cacheId = $parts[0]; + $combiner = new CombineAssets; + return $combiner->getContents($cacheId); + } catch (Exception $ex) { + return '/* '.$ex->getMessage().' */'; + } } /** @@ -915,11 +963,13 @@ class Controller extends BaseController */ protected function findComponentByName($name) { - if (isset($this->page->components[$name])) + if (isset($this->page->components[$name])) { return $this->page->components[$name]; + } - if (isset($this->layout->components[$name])) + if (isset($this->layout->components[$name])) { return $this->layout->components[$name]; + } return null; } @@ -931,13 +981,15 @@ class Controller extends BaseController protected function findComponentByHandler($handler) { foreach ($this->page->components as $component) { - if (method_exists($component, $handler)) + if (method_exists($component, $handler)) { return $component; + } } foreach ($this->layout->components as $component) { - if (method_exists($component, $handler)) + if (method_exists($component, $handler)) { return $component; + } } return null; @@ -951,20 +1003,24 @@ class Controller extends BaseController { foreach ($this->page->components as $component) { $fileName = ComponentPartial::getFilePath($component, $partial); - if (!strlen(File::extension($fileName))) + if (!strlen(File::extension($fileName))) { $fileName .= '.htm'; + } - if (File::isFile($fileName)) + if (File::isFile($fileName)) { return $component; + } } foreach ($this->layout->components as $component) { $fileName = ComponentPartial::getFilePath($component, $partial); - if (!strlen(File::extension($fileName))) + if (!strlen(File::extension($fileName))) { $fileName .= '.htm'; + } - if (File::isFile($fileName)) + if (File::isFile($fileName)) { return $component; + } } return null; @@ -985,7 +1041,10 @@ class Controller extends BaseController // if (($page = Page::loadCached($theme, $page)) && isset($page->settings['components'])) { // foreach ($page->settings['components'] as $component => $properties) { - // list($name, $alias) = strpos($component, ' ') ? explode(' ', $component) : array($component, $component); + // list($name, $alias) = strpos($component, ' ') ? + // explode(' ', $component) : + // array($component, $component) + // ; // if ($manager->resolve($name) == $class) { // $componentObj->setProperties($properties); // $componentObj->alias = $alias; @@ -999,7 +1058,10 @@ class Controller extends BaseController // $layout = $page->settings['layout']; // if (($layout = Layout::loadCached($theme, $layout)) && isset($layout->settings['components'])) { // foreach ($layout->settings['components'] as $component => $properties) { - // list($name, $alias) = strpos($component, ' ') ? explode(' ', $component) : array($component, $component); + // list($name, $alias) = strpos($component, ' ') ? + // explode(' ', $component) : + // array($component, $component) + // ; // if ($manager->resolve($name) == $class) { // $componentObj->setProperties($properties); // $componentObj->alias = $alias; @@ -1011,5 +1073,4 @@ class Controller extends BaseController // return null; // } - } diff --git a/modules/cms/classes/FileHelper.php b/modules/cms/classes/FileHelper.php index c95786525..97766725c 100644 --- a/modules/cms/classes/FileHelper.php +++ b/modules/cms/classes/FileHelper.php @@ -30,8 +30,9 @@ class FileHelper public static function validateExtension($fileName, $allowedExtensions, $allowEmpty = true) { $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); - if (!strlen($extension)) + if (!strlen($extension)) { return $allowEmpty; + } return in_array($extension, $allowedExtensions); } @@ -46,19 +47,24 @@ class FileHelper */ public static function validatePath($filePath, $maxNesting = 2) { - if (strpos($filePath, '..') !== false) + if (strpos($filePath, '..') !== false) { return false; + } - if (strpos($filePath, './') !== false || strpos($filePath, '//') !== false) + if (strpos($filePath, './') !== false || strpos($filePath, '//') !== false) { return false; + } $segments = explode('/', $filePath); - if ($maxNesting !== null && count($segments) > $maxNesting) + if ($maxNesting !== null && count($segments) > $maxNesting) { return false; + } - foreach ($segments as $segment) - if (!self::validateName($segment)) + foreach ($segments as $segment) { + if (!self::validateName($segment)) { return false; + } + } return true; } @@ -74,20 +80,23 @@ class FileHelper $content = null; $sections = []; - foreach ($data as $key=>$value) { + foreach ($data as $key => $value) { if (is_array($value)) { - if ($level == 1) + if ($level == 1) { $sections[$key] = self::formatIniString($value, $level+1); - else { - foreach ($value as $val) + } else { + foreach ($value as $val) { $content .= $key.'[] = "'.self::escapeIniString($val).'"'.PHP_EOL; + } } - } elseif (strlen($value)) + } elseif (strlen($value)) { $content .= $key.' = "'.self::escapeIniString($value).'"'.PHP_EOL; + } } - foreach ($sections as $key=>$section) + foreach ($sections as $key => $section) { $content .= PHP_EOL.'['.$key.']'.PHP_EOL.$section.PHP_EOL; + } return trim($content); } diff --git a/modules/cms/classes/Layout.php b/modules/cms/classes/Layout.php index 267de82d2..eeec4e785 100644 --- a/modules/cms/classes/Layout.php +++ b/modules/cms/classes/Layout.php @@ -10,7 +10,9 @@ class Layout extends CmsCompoundObject { const FALLBACK_FILE_NAME = 'fallback'; - protected function parseSettings() {} + protected function parseSettings() + { + } /** * Returns the directory name corresponding to the object type. diff --git a/modules/cms/classes/LayoutCode.php b/modules/cms/classes/LayoutCode.php index 9beaab5b6..18c737d58 100644 --- a/modules/cms/classes/LayoutCode.php +++ b/modules/cms/classes/LayoutCode.php @@ -12,5 +12,7 @@ class LayoutCode extends CodeBase * This event is triggered after the layout components are executed, * but before the page's onStart event. */ - public function onBeforePageStart() {} -} \ No newline at end of file + public function onBeforePageStart() + { + } +} diff --git a/modules/cms/classes/ObjectMemoryCache.php b/modules/cms/classes/ObjectMemoryCache.php index 4b5a92a47..341fd6636 100644 --- a/modules/cms/classes/ObjectMemoryCache.php +++ b/modules/cms/classes/ObjectMemoryCache.php @@ -9,4 +9,4 @@ class ObjectMemoryCache { public static $cache = []; -} \ No newline at end of file +} diff --git a/modules/cms/classes/Page.php b/modules/cms/classes/Page.php index 50e767432..c6811a910 100644 --- a/modules/cms/classes/Page.php +++ b/modules/cms/classes/Page.php @@ -31,7 +31,9 @@ class Page extends CmsCompoundObject ]; } - protected function parseSettings() {} + protected function parseSettings() + { + } /** * Returns the directory name corresponding to the object type. @@ -59,8 +61,9 @@ class Page extends CmsCompoundObject */ public function getLayoutOptions() { - if (!($theme = Theme::getEditTheme())) + if (!($theme = Theme::getEditTheme())) { throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_found')); + } $layouts = Layout::listInTheme($theme, true); $result = []; @@ -101,8 +104,9 @@ class Page extends CmsCompoundObject * request processing. */ $controller = Controller::getController(); - if (!$controller) + if (!$controller) { $controller = new Controller; + } return $controller->pageUrl($page, $params, true, $absolute); } @@ -119,8 +123,8 @@ class Page extends CmsCompoundObject * false if omitted. * - dynamicItems - Boolean value indicating whether the item type could generate new menu items. * Optional, false if omitted. - * - cmsPages - a list of CMS pages (objects of the Cms\Classes\Page class), if the item type requires a CMS page reference to - * resolve the item URL. + * - cmsPages - a list of CMS pages (objects of the Cms\Classes\Page class), if the item type requires + * a CMS page reference to resolve the item URL. * @param string $type Specifies the menu item type * @return array Returns an array */ @@ -132,8 +136,9 @@ class Page extends CmsCompoundObject $theme = Theme::getActiveTheme(); $pages = self::listInTheme($theme, true); - foreach ($pages as $page) + foreach ($pages as $page) { $references[$page->getBaseFileName()] = $page->title; + } $result = [ 'references' => $references, @@ -167,8 +172,9 @@ class Page extends CmsCompoundObject $result = null; if ($item->type == 'cms-page') { - if (!$item->reference) + if (!$item->reference) { return; + } $pageUrl = self::url($item->reference); diff --git a/modules/cms/classes/PageCode.php b/modules/cms/classes/PageCode.php index 483422538..36b614acc 100644 --- a/modules/cms/classes/PageCode.php +++ b/modules/cms/classes/PageCode.php @@ -8,4 +8,4 @@ */ class PageCode extends CodeBase { -} \ No newline at end of file +} diff --git a/modules/cms/classes/Router.php b/modules/cms/classes/Router.php index d3e86432f..13c2fb950 100644 --- a/modules/cms/classes/Router.php +++ b/modules/cms/classes/Router.php @@ -18,7 +18,8 @@ use October\Rain\Router\Helper as RouterHelper; * add the question mark after its name: *
/blog/post/:post_id?
* By default parameters in the middle of the URL are required, for example: - *
/blog/:post_id?/comments - although the :post_id parameter is marked as optional, it will be processed as required.
+ *
/blog/:post_id?/comments - although the :post_id parameter is marked as optional,
+ * it will be processed as required.
* Optional parameters can have default values which are used as fallback values in case if the real * parameter value is not presented in the URL. Default values cannot contain the pipe symbols and question marks. * Specify the default value after the question mark: @@ -74,16 +75,21 @@ class Router $url = RouterHelper::normalizeUrl($url); $apiResult = Event::fire('cms.router.beforeRoute', [$url], true); - if ($apiResult !== null) + if ($apiResult !== null) { return $apiResult; + } for ($pass = 1; $pass <= 2; $pass++) { $fileName = null; $urlList = []; - $cacheable = Config::get('cms.enableRoutesCache') && in_array(Config::get('cache.driver'), ['apc', 'memcached', 'redis', 'array']); - if ($cacheable) + $cacheable = Config::get('cms.enableRoutesCache') && in_array( + Config::get('cache.driver'), + ['apc', 'memcached', 'redis', 'array'] + ); + if ($cacheable) { $fileName = $this->getCachedUrlFileName($url, $urlList); + } /* * Find the page by URL and cache the route @@ -96,8 +102,9 @@ class Router $fileName = $router->matchedRoute(); if ($cacheable) { - if (!$urlList || !is_array($urlList)) + if (!$urlList || !is_array($urlList)) { $urlList = []; + } $urlList[$url] = $fileName; @@ -140,8 +147,9 @@ class Router */ public function findByFile($fileName, $parameters = []) { - if (!strlen(File::extension($fileName))) + if (!strlen(File::extension($fileName))) { $fileName .= '.htm'; + } $router = $this->getRouterObject(); return $router->url($fileName, $parameters); @@ -153,8 +161,9 @@ class Router */ protected function getRouterObject() { - if (self::$routerObj !== null) + if (self::$routerObj !== null) { return self::$routerObj; + } /* * Load up each route rule @@ -178,8 +187,9 @@ class Router */ protected function getUrlMap() { - if (!count(self::$urlMap)) + if (!count(self::$urlMap)) { $this->loadUrlMap(); + } return self::$urlMap; } @@ -196,10 +206,11 @@ class Router $key = $this->getCacheKey('page-url-map'); $cacheable = Config::get('cms.enableRoutesCache'); - if ($cacheable) + if ($cacheable) { $cached = Cache::get($key, false); - else + } else { $cached = false; + } if (!$cached || ($unserialized = @unserialize($cached)) === false) { /* @@ -208,15 +219,17 @@ class Router $pages = $this->theme->listPages(); $map = []; foreach ($pages as $page) { - if (!$page->url) + if (!$page->url) { continue; + } $map[] = ['file' => $page->getFileName(), 'pattern' => $page->url]; } self::$urlMap = $map; - if ($cacheable) + if ($cacheable) { Cache::put($key, serialize($map), Config::get('cms.urlCacheTtl', 1)); + } return false; } @@ -259,8 +272,9 @@ class Router */ public function getParameter($name, $default = null) { - if (isset($this->parameters[$name]) && !empty($this->parameters[$name])) + if (isset($this->parameters[$name]) && !empty($this->parameters[$name])) { return $this->parameters[$name]; + } return $default; } @@ -296,10 +310,11 @@ class Router $urlList = Cache::get($key, false); if ($urlList && ($urlList = @unserialize($urlList)) && is_array($urlList)) { - if (array_key_exists($url, $urlList)) + if (array_key_exists($url, $urlList)) { return $urlList[$url]; + } } return null; } -} \ No newline at end of file +} diff --git a/modules/cms/classes/SectionParser.php b/modules/cms/classes/SectionParser.php index 90da6efbf..11bee8b22 100644 --- a/modules/cms/classes/SectionParser.php +++ b/modules/cms/classes/SectionParser.php @@ -33,8 +33,9 @@ class SectionParser { $sections = preg_split('/^={2,}\s*/m', $content, -1); $count = count($sections); - foreach ($sections as &$section) + foreach ($sections as &$section) { $section = trim($section); + } $result = [ 'settings' => [], @@ -51,13 +52,12 @@ class SectionParser $result['code'] = preg_replace('/\?\>\s*$/', '', $result['code']); $result['markup'] = $sections[2]; - } - elseif ($count == 2) { + } elseif ($count == 2) { $result['settings'] = parse_ini_string($sections[0], true); $result['markup'] = $sections[1]; - } - elseif ($count == 1) + } elseif ($count == 1) { $result['markup'] = $sections[0]; + } return $result; } @@ -83,12 +83,10 @@ class SectionParser $result['settings'] = self::adjustLinePosition($content); $result['code'] = self::calculateLinePosition($content); $result['markup'] = self::calculateLinePosition($content, 2); - } - elseif ($count == 2) { + } elseif ($count == 2) { $result['settings'] = self::adjustLinePosition($content); $result['markup'] = self::calculateLinePosition($content); - } - elseif ($count == 1) { + } elseif ($count == 1) { $result['markup'] = 1; } @@ -106,11 +104,13 @@ class SectionParser $count = 0; $lines = explode(PHP_EOL, $content); foreach ($lines as $number => $line) { - if (trim($line) == self::SECTION_SEPARATOR) + if (trim($line) == self::SECTION_SEPARATOR) { $count++; + } - if ($count == $instance) + if ($count == $instance) { return static::adjustLinePosition($content, $number); + } } return null; @@ -150,10 +150,11 @@ class SectionParser } /* - * PHP namespaced line (use x;) + * PHP namespaced line (use x;) { * Don't increase the line count, it will be rewritten by Cms\Classes\CodeParser */ - if (preg_match_all('/(use\s+[a-z0-9_\\\\]+;\n?)/mi', $line) == 1) { + if (preg_match_all('/(use\s+[a-z0-9_\\\\]+; + }\n?)/mi', $line) == 1) { continue; } @@ -163,4 +164,4 @@ class SectionParser // Line 0 does not exist. return ++$startLine; } -} \ No newline at end of file +} diff --git a/modules/cms/classes/Theme.php b/modules/cms/classes/Theme.php index f6c10ec19..43040f319 100644 --- a/modules/cms/classes/Theme.php +++ b/modules/cms/classes/Theme.php @@ -60,8 +60,9 @@ class Theme */ public function getPath($dirName = null) { - if (!$dirName) + if (!$dirName) { $dirName = $this->getDirName(); + } return base_path().Config::get('cms.themesDir').'/'.$dirName; } @@ -108,8 +109,9 @@ class Theme */ public static function getActiveTheme() { - if (self::$activeThemeCache !== false) + if (self::$activeThemeCache !== false) { return self::$activeThemeCache; + } $activeTheme = Config::get('cms.activeTheme'); @@ -119,21 +121,25 @@ class Theme ->pluck('value') ; - if ($dbResult !== null) + if ($dbResult !== null) { $activeTheme = $dbResult; + } } $apiResult = Event::fire('cms.activeTheme', [], true); - if ($apiResult !== null) + if ($apiResult !== null) { $activeTheme = $apiResult; + } - if (!strlen($activeTheme)) + if (!strlen($activeTheme)) { throw new SystemException(Lang::get('cms::lang.theme.active.not_set')); + } $theme = new static; $theme->load($activeTheme); - if (!File::isDirectory($theme->getPath())) + if (!File::isDirectory($theme->getPath())) { return self::$activeThemeCache = null; + } return self::$activeThemeCache = $theme; } @@ -160,24 +166,29 @@ class Theme */ public static function getEditTheme() { - if (self::$editThemeCache !== false) + if (self::$editThemeCache !== false) { return self::$editThemeCache; + } $editTheme = Config::get('cms.editTheme'); - if (!$editTheme) + if (!$editTheme) { $editTheme = static::getActiveTheme()->getDirName(); + } $apiResult = Event::fire('cms.editTheme', [], true); - if ($apiResult !== null) + if ($apiResult !== null) { $editTheme = $apiResult; + } - if (!strlen($editTheme)) + if (!strlen($editTheme)) { throw new SystemException(Lang::get('cms::lang.theme.edit.not_set')); + } $theme = new static; $theme->load($editTheme); - if (!File::isDirectory($theme->getPath())) + if (!File::isDirectory($theme->getPath())) { return self::$editThemeCache = null; + } return self::$editThemeCache = $theme; } @@ -195,8 +206,9 @@ class Theme $result = []; foreach ($it as $fileinfo) { - if (!$fileinfo->isDir() || $fileinfo->isDot()) + if (!$fileinfo->isDir() || $fileinfo->isDot()) { continue; + } $theme = new static; $theme->load($fileinfo->getFilename()); @@ -212,12 +224,14 @@ class Theme */ public function getConfig() { - if ($this->configCache !== null) + if ($this->configCache !== null) { return $this->configCache; + } $path = $this->getPath().'/theme.yaml'; - if (!File::exists($path)) + if (!File::exists($path)) { return $this->configCache = []; + } return $this->configCache = Yaml::parseFile($path); } @@ -225,14 +239,16 @@ class Theme /** * Returns a value from the theme configuration file by its name. * @param string $name Specifies the configuration parameter name. - * @param mixed $default Specifies the default value to return in case if the parameter doesn't exist in the configuration file. + * @param mixed $default Specifies the default value to return in case if the parameter + * doesn't exist in the configuration file. * @return mixed Returns the parameter value or a default value - */ - public function getConfigValue($name, $default = null) + */ + public function getConfigValue($name, $default = null) { $config = $this->getConfig(); - if (isset($config[$name])) + if (isset($config[$name])) { return $config[$name]; + } return $default; } @@ -246,8 +262,9 @@ class Theme { $previewPath = '/assets/images/theme-preview.png'; $path = $this->getPath().$previewPath; - if (!File::exists($path)) + if (!File::exists($path)) { return URL::asset('modules/cms/assets/images/default-theme-preview.png'); + } return URL::asset('themes/'.$this->getDirName().$previewPath); } diff --git a/modules/cms/classes/UnknownComponent.php b/modules/cms/classes/UnknownComponent.php index 5d9c9c5ed..44469f2a1 100644 --- a/modules/cms/classes/UnknownComponent.php +++ b/modules/cms/classes/UnknownComponent.php @@ -26,4 +26,4 @@ class UnknownComponent extends ComponentBase 'description' => $this->errorMessage ]; } -} \ No newline at end of file +} diff --git a/modules/cms/classes/ViewBag.php b/modules/cms/classes/ViewBag.php index 02b42ec6e..26c451212 100644 --- a/modules/cms/classes/ViewBag.php +++ b/modules/cms/classes/ViewBag.php @@ -28,8 +28,9 @@ class ViewBag extends ComponentBase public function __call($method, $parameters) { - if (array_key_exists($method, $this->properties) && !method_exists($this, $method)) + if (array_key_exists($method, $this->properties) && !method_exists($this, $method)) { return $this->properties[$method]; + } return parent::__call($method, $parameters); } @@ -38,7 +39,7 @@ class ViewBag extends ComponentBase { $result = []; - foreach ($this->properties as $name=>$value) { + foreach ($this->properties as $name => $value) { $result[$name] = [ 'title' => $name, 'type' => 'string' @@ -47,4 +48,4 @@ class ViewBag extends ComponentBase return $result; } -} \ No newline at end of file +} From e9ce6f5d5494ed0874e282bdaa7fe08e1acbc51d Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 01:27:52 +0200 Subject: [PATCH 17/30] Updating modules/cms/controllers --- modules/cms/controllers/Index.php | 83 ++++++++++++++++++------------ modules/cms/controllers/Themes.php | 3 +- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/modules/cms/controllers/Index.php b/modules/cms/controllers/Index.php index 8800f20e1..7860cc1b2 100644 --- a/modules/cms/controllers/Index.php +++ b/modules/cms/controllers/Index.php @@ -51,32 +51,32 @@ class Index extends Controller BackendMenu::setContext('October.Cms', 'cms', 'pages'); try { - if (!($theme = Theme::getEditTheme())) + if (!($theme = Theme::getEditTheme())) { throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_found')); + } $this->theme = $theme; - new TemplateList($this, 'pageList', function() use ($theme) { + new TemplateList($this, 'pageList', function () use ($theme) { return Page::listInTheme($theme, true); }); - new TemplateList($this, 'partialList', function() use ($theme) { + new TemplateList($this, 'partialList', function () use ($theme) { return Partial::listInTheme($theme, true); }); - new TemplateList($this, 'layoutList', function() use ($theme) { + new TemplateList($this, 'layoutList', function () use ($theme) { return Layout::listInTheme($theme, true); }); - new TemplateList($this, 'contentList', function() use ($theme) { + new TemplateList($this, 'contentList', function () use ($theme) { return Content::listInTheme($theme, true); }); new ComponentList($this, 'componentList'); new AssetList($this, 'assetList'); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->handleError($ex); } } @@ -97,8 +97,9 @@ class Index extends Controller $this->addJs('/modules/backend/formwidgets/codeeditor/assets/vendor/ace/ace.js', 'core'); $aceModes = ['markdown', 'plain_text', 'html', 'less', 'css', 'scss', 'sass', 'javascript']; - foreach ($aceModes as $mode) + foreach ($aceModes as $mode) { $this->addJs('/modules/backend/formwidgets/codeeditor/assets/vendor/ace/mode-'.$mode.'.js', 'core'); + } $this->bodyClass = 'compact-container side-panel-not-fixed'; $this->pageTitle = Lang::get('cms::lang.cms.menu_label'); @@ -142,13 +143,15 @@ class Index extends Controller $settings = $this->upgradeSettings($settings); $templateData = []; - if ($settings) + if ($settings) { $templateData['settings'] = $settings; + } $fields = ['markup', 'code', 'fileName', 'content']; foreach ($fields as $field) { - if (array_key_exists($field, $_POST)) + if (array_key_exists($field, $_POST)) { $templateData[$field] = Request::input($field); + } } if (!empty($templateData['markup']) && Config::get('cms.convertLineEndings', false) === true) { @@ -156,8 +159,9 @@ class Index extends Controller } if (!Request::input('templateForceSave') && $template->mtime) { - if (Request::input('templateMtime') != $template->mtime) + if (Request::input('templateMtime') != $template->mtime) { throw new ApplicationException('mtime-mismatch'); + } } $template->fill($templateData); @@ -197,8 +201,9 @@ class Index extends Controller $type = Request::input('type'); $template = $this->createTemplate($type); - if ($type == 'asset') + if ($type == 'asset') { $template->setInitialPath($this->widget->assetList->getCurrentRelativePath()); + } $widget = $this->makeTemplateFormWidget($type, $template); @@ -225,14 +230,13 @@ class Index extends Controller $deleted = []; try { - foreach ($templates as $path=>$selected) { + foreach ($templates as $path => $selected) { if ($selected) { $this->loadTemplate($type, $path)->delete(); $deleted[] = $path; } } - } - catch (Exception $ex) { + } catch (Exception $ex) { $error = $ex->getMessage(); } @@ -276,21 +280,26 @@ class Index extends Controller public function onExpandMarkupToken() { - if (!$alias = post('tokenName')) + if (!$alias = post('tokenName')) { throw new ApplicationException(trans('cms::lang.component.no_records')); + } // Can only expand components at this stage - if ((!$type = post('tokenType')) && $type != 'component') + if ((!$type = post('tokenType')) && $type != 'component') { return; + } - if (!($names = (array) post('component_names')) || !($aliases = (array) post('component_aliases'))) + if (!($names = (array) post('component_names')) || !($aliases = (array) post('component_aliases'))) { throw new ApplicationException(trans('cms::lang.component.not_found', ['name' => $alias])); + } - if (($index = array_get(array_flip($aliases), $alias, false)) === false) + if (($index = array_get(array_flip($aliases), $alias, false)) === false) { throw new ApplicationException(trans('cms::lang.component.not_found', ['name' => $alias])); + } - if (!$componentName = array_get($names, $index)) + if (!$componentName = array_get($names, $index)) { throw new ApplicationException(trans('cms::lang.component.not_found', ['name' => $alias])); + } $manager = ComponentManager::instance(); $componentObj = $manager->makeComponent($componentName); @@ -306,8 +315,9 @@ class Index extends Controller protected function validateRequestTheme() { - if ($this->theme->getDirName() != Request::input('theme')) + if ($this->theme->getDirName() != Request::input('theme')) { throw new ApplicationException(trans('cms::lang.theme.edit.not_match')); + } } protected function resolveTypeClassName($type) @@ -320,8 +330,9 @@ class Index extends Controller 'asset' => '\Cms\Classes\Asset', ]; - if (!array_key_exists($type, $types)) + if (!array_key_exists($type, $types)) { throw new ApplicationException(trans('cms::lang.template.invalid_type')); + } return $types[$type]; } @@ -330,8 +341,9 @@ class Index extends Controller { $class = $this->resolveTypeClassName($type); - if (!($template = call_user_func(array($class, 'load'), $this->theme, $path))) + if (!($template = call_user_func(array($class, 'load'), $this->theme, $path))) { throw new ApplicationException(trans('cms::lang.template.not_found')); + } return $template; } @@ -340,8 +352,9 @@ class Index extends Controller { $class = $this->resolveTypeClassName($type); - if (!($template = new $class($this->theme))) + if (!($template = new $class($this->theme))) { throw new ApplicationException(trans('cms::lang.template.not_found')); + } return $template; } @@ -350,16 +363,18 @@ class Index extends Controller { if ($type == 'page') { $result = $template->title ?: $template->getFileName(); - if (!$result) + if (!$result) { $result = trans('cms::lang.page.new'); + } return $result; } if ($type == 'partial' || $type == 'layout' || $type == 'content' || $type == 'asset') { $result = in_array($type, ['asset', 'content']) ? $template->getFileName() : $template->getBaseFileName(); - if (!$result) + if (!$result) { $result = trans('cms::lang.'.$type.'.new'); + } return $result; } @@ -377,8 +392,9 @@ class Index extends Controller 'asset' => '@/modules/cms/classes/asset/fields.yaml', ]; - if (!array_key_exists($type, $formConfigs)) + if (!array_key_exists($type, $formConfigs)) { throw new ApplicationException(trans('cms::lang.template.not_found')); + } $widgetConfig = $this->makeConfig($formConfigs[$type]); $widgetConfig->model = $template; @@ -391,23 +407,27 @@ class Index extends Controller protected function upgradeSettings($settings) { - if (!array_key_exists('component_properties', $_POST)) + if (!array_key_exists('component_properties', $_POST)) { return $settings; + } - if (!array_key_exists('component_names', $_POST) || !array_key_exists('component_aliases', $_POST)) + if (!array_key_exists('component_names', $_POST) || !array_key_exists('component_aliases', $_POST)) { throw new ApplicationException(trans('cms::lang.component.invalid_request')); + } $count = count($_POST['component_properties']); - if (count($_POST['component_names']) != $count || count($_POST['component_aliases']) != $count) + if (count($_POST['component_names']) != $count || count($_POST['component_aliases']) != $count) { throw new ApplicationException(trans('cms::lang.component.invalid_request')); + } for ($index = 0; $index < $count; $index ++) { $componentName = $_POST['component_names'][$index]; $componentAlias = $_POST['component_aliases'][$index]; $section = $componentName; - if ($componentAlias != $componentName) + if ($componentAlias != $componentName) { $section .= ' '.$componentAlias; + } $properties = json_decode($_POST['component_properties'][$index], true); unset($properties['oc.alias']); @@ -431,5 +451,4 @@ class Index extends Controller $markup = str_replace("\r", "\n", $markup); return $markup; } - } diff --git a/modules/cms/controllers/Themes.php b/modules/cms/controllers/Themes.php index a1c0b98fa..e4d99cff5 100644 --- a/modules/cms/controllers/Themes.php +++ b/modules/cms/controllers/Themes.php @@ -37,7 +37,6 @@ class Themes extends Controller public function index() { - } public function index_onSetActiveTheme() @@ -48,4 +47,4 @@ class Themes extends Controller '#theme-list' => $this->makePartial('theme_list') ]; } -} \ No newline at end of file +} From 2f04fcd52431a744e7d01c3db0a065a972bf2d6c Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 01:29:22 +0200 Subject: [PATCH 18/30] Updating modules/cms/formwidgets --- modules/cms/formwidgets/Components.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/cms/formwidgets/Components.php b/modules/cms/formwidgets/Components.php index a3f6014c0..13b6111ef 100644 --- a/modules/cms/formwidgets/Components.php +++ b/modules/cms/formwidgets/Components.php @@ -30,8 +30,9 @@ class Components extends FormWidgetBase { $result = []; - if (!isset($this->model->settings['components'])) + if (!isset($this->model->settings['components'])) { return $result; + } $manager = ComponentManager::instance(); $manager->listComponents(); @@ -47,11 +48,11 @@ class Components extends FormWidgetBase $plugin = $manager->findComponentPlugin($componentObj); if ($plugin) { $pluginDetails = $plugin->pluginDetails(); - if (isset($pluginDetails['icon'])) + if (isset($pluginDetails['icon'])) { $componentObj->pluginIcon = $pluginDetails['icon']; + } } - } - catch (Exception $ex) { + } catch (Exception $ex) { $componentObj = new UnknownComponent(null, $properties, $ex->getMessage()); $componentObj->alias = $alias; $componentObj->pluginIcon = 'icon-bug'; @@ -82,4 +83,4 @@ class Components extends FormWidgetBase { return ComponentHelpers::getComponentPropertyValues($component); } -} \ No newline at end of file +} From e114f29582bb71ffa4c67ff1bf1f2beb5202b76f Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 01:32:11 +0200 Subject: [PATCH 19/30] Updating modules/cms/lang --- modules/cms/lang/de/lang.php | 2 +- modules/cms/lang/en/lang.php | 2 +- modules/cms/lang/fa/lang.php | 2 +- modules/cms/lang/fr/lang.php | 2 +- modules/cms/lang/nl/lang.php | 2 +- modules/cms/lang/pt-br/lang.php | 2 +- modules/cms/lang/ro/lang.php | 2 +- modules/cms/lang/sv/lang.php | 2 +- modules/cms/lang/tr/lang.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/cms/lang/de/lang.php b/modules/cms/lang/de/lang.php index 4bbabe6a3..a47478bfc 100644 --- a/modules/cms/lang/de/lang.php +++ b/modules/cms/lang/de/lang.php @@ -149,4 +149,4 @@ return [ 'not_found' => "Das angeforderte Template wurde nicht gefunden.", 'saved'=> "Das Template wurde erfolgreich gespeichert." ] -]; \ No newline at end of file +]; diff --git a/modules/cms/lang/en/lang.php b/modules/cms/lang/en/lang.php index f29007641..db70e162f 100644 --- a/modules/cms/lang/en/lang.php +++ b/modules/cms/lang/en/lang.php @@ -170,4 +170,4 @@ return [ 'manage_partials' => 'Manage partials', 'manage_themes' => 'Manage themes' ] -]; \ No newline at end of file +]; diff --git a/modules/cms/lang/fa/lang.php b/modules/cms/lang/fa/lang.php index 2645b8e12..5a94e251a 100644 --- a/modules/cms/lang/fa/lang.php +++ b/modules/cms/lang/fa/lang.php @@ -170,4 +170,4 @@ return [ 'manage_partials' => 'مدیریت بخش ها', 'manage_themes' => 'مدیریت قالب ها' ] -]; \ No newline at end of file +]; diff --git a/modules/cms/lang/fr/lang.php b/modules/cms/lang/fr/lang.php index 21edf845a..68bde0398 100644 --- a/modules/cms/lang/fr/lang.php +++ b/modules/cms/lang/fr/lang.php @@ -157,4 +157,4 @@ return [ 'not_found' => "Le template demandé est introuvable.", 'saved'=> "Le template demandé a été sauvegardé avec succès." ] -]; \ No newline at end of file +]; diff --git a/modules/cms/lang/nl/lang.php b/modules/cms/lang/nl/lang.php index dbe4a82cd..ad6eb69b2 100644 --- a/modules/cms/lang/nl/lang.php +++ b/modules/cms/lang/nl/lang.php @@ -170,4 +170,4 @@ return [ 'manage_partials' => 'Beheer sjablonen', 'manage_themes' => 'Beheer thema\'s' ] -]; \ No newline at end of file +]; diff --git a/modules/cms/lang/pt-br/lang.php b/modules/cms/lang/pt-br/lang.php index a4cb9cdaa..dd8566adf 100644 --- a/modules/cms/lang/pt-br/lang.php +++ b/modules/cms/lang/pt-br/lang.php @@ -170,4 +170,4 @@ return [ 'manage_partials' => 'Gerenciar blocos', 'manage_themes' => 'Gerenciar temas' ] -]; \ No newline at end of file +]; diff --git a/modules/cms/lang/ro/lang.php b/modules/cms/lang/ro/lang.php index 2af6f1c6c..59c791520 100644 --- a/modules/cms/lang/ro/lang.php +++ b/modules/cms/lang/ro/lang.php @@ -167,4 +167,4 @@ return [ 'manage_partials' => 'Gestioneaza componente partiale', 'manage_themes' => 'Gestioneaza teme' ] -]; \ No newline at end of file +]; diff --git a/modules/cms/lang/sv/lang.php b/modules/cms/lang/sv/lang.php index b8dab98a1..e029a0c3f 100644 --- a/modules/cms/lang/sv/lang.php +++ b/modules/cms/lang/sv/lang.php @@ -149,4 +149,4 @@ return [ 'not_found' => "Den angivna mallen kunde ej hittas", 'saved'=> "Mallen har sparats" ] -]; \ No newline at end of file +]; diff --git a/modules/cms/lang/tr/lang.php b/modules/cms/lang/tr/lang.php index 7aa0d65ae..7e5a765f7 100644 --- a/modules/cms/lang/tr/lang.php +++ b/modules/cms/lang/tr/lang.php @@ -149,4 +149,4 @@ return [ 'not_found' => "İstenilen şablon bulunamadı.", 'saved'=> "Şablon başarıyla kaydedildi." ] -]; \ No newline at end of file +]; From 9c1dcb0dba89aeb51cd7785de6840c64d6711d05 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 01:42:04 +0200 Subject: [PATCH 20/30] Updating modules/cms/twig --- modules/cms/twig/ComponentNode.php | 2 +- modules/cms/twig/ComponentTokenParser.php | 8 +- modules/cms/twig/ContentNode.php | 2 +- modules/cms/twig/ContentTokenParser.php | 2 +- modules/cms/twig/DebugExtension.php | 104 +++++++++++++------- modules/cms/twig/DefaultNode.php | 2 +- modules/cms/twig/DefaultTokenParser.php | 2 +- modules/cms/twig/Extension.php | 8 +- modules/cms/twig/FlashNode.php | 5 +- modules/cms/twig/FlashTokenParser.php | 5 +- modules/cms/twig/FrameworkNode.php | 11 ++- modules/cms/twig/FrameworkTokenParser.php | 2 +- modules/cms/twig/Loader.php | 2 +- modules/cms/twig/PageNode.php | 2 +- modules/cms/twig/PageTokenParser.php | 2 +- modules/cms/twig/PartialNode.php | 2 +- modules/cms/twig/PartialTokenParser.php | 8 +- modules/cms/twig/PlaceholderNode.php | 5 +- modules/cms/twig/PlaceholderTokenParser.php | 2 +- modules/cms/twig/PutNode.php | 4 +- modules/cms/twig/PutTokenParser.php | 2 +- modules/cms/twig/ScriptsNode.php | 2 +- modules/cms/twig/ScriptsTokenParser.php | 2 +- modules/cms/twig/StylesNode.php | 2 +- modules/cms/twig/StylesTokenParser.php | 2 +- 25 files changed, 116 insertions(+), 74 deletions(-) diff --git a/modules/cms/twig/ComponentNode.php b/modules/cms/twig/ComponentNode.php index ce18c2c39..a7c0c11c8 100644 --- a/modules/cms/twig/ComponentNode.php +++ b/modules/cms/twig/ComponentNode.php @@ -43,4 +43,4 @@ class ComponentNode extends Twig_Node $compiler->write("unset(\$context['__cms_component_params']);\n"); } -} \ No newline at end of file +} diff --git a/modules/cms/twig/ComponentTokenParser.php b/modules/cms/twig/ComponentTokenParser.php index f090b1516..8c2726ccd 100644 --- a/modules/cms/twig/ComponentTokenParser.php +++ b/modules/cms/twig/ComponentTokenParser.php @@ -49,7 +49,11 @@ class ComponentTokenParser extends Twig_TokenParser break; default: - throw new Twig_Error_Syntax(sprintf('Invalid syntax in the partial tag. Line %s', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename()); + throw new Twig_Error_Syntax( + sprintf('Invalid syntax in the partial tag. Line %s', $lineno), + $stream->getCurrent()->getLine(), + $stream->getFilename() + ); break; } } @@ -66,4 +70,4 @@ class ComponentTokenParser extends Twig_TokenParser { return 'component'; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/ContentNode.php b/modules/cms/twig/ContentNode.php index 33e01e179..b64a75a7b 100644 --- a/modules/cms/twig/ContentNode.php +++ b/modules/cms/twig/ContentNode.php @@ -31,4 +31,4 @@ class ContentNode extends Twig_Node ->write(");\n") ; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/ContentTokenParser.php b/modules/cms/twig/ContentTokenParser.php index b675041df..ee9973f65 100644 --- a/modules/cms/twig/ContentTokenParser.php +++ b/modules/cms/twig/ContentTokenParser.php @@ -39,4 +39,4 @@ class ContentTokenParser extends Twig_TokenParser { return 'content'; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/DebugExtension.php b/modules/cms/twig/DebugExtension.php index 9546fbd5b..bfe0dde5c 100644 --- a/modules/cms/twig/DebugExtension.php +++ b/modules/cms/twig/DebugExtension.php @@ -35,7 +35,15 @@ class DebugExtension extends Twig_Extension */ protected $commentMap = []; - protected $blockMethods = ['componentDetails', 'defineProperties', 'getPropertyOptions', 'offsetExists', 'offsetGet', 'offsetSet', 'offsetUnset']; + protected $blockMethods = [ + 'componentDetails', + 'defineProperties', + 'getPropertyOptions', + 'offsetExists', + 'offsetGet', + 'offsetSet', + 'offsetUnset' + ]; /** * Creates the extension instance. @@ -54,7 +62,11 @@ class DebugExtension extends Twig_Extension public function getFunctions() { return array( - new Twig_SimpleFunction('dump', [$this, 'runDump'], array('is_safe' => ['html'], 'needs_context' => true, 'needs_environment' => true)), + new Twig_SimpleFunction('dump', [$this, 'runDump'], array( + 'is_safe' => ['html'], + 'needs_context' => true, + 'needs_environment' => true + )), ); } @@ -84,8 +96,7 @@ class DebugExtension extends Twig_Extension } $result .= $this->dump($vars, static::PAGE_CAPTION); - } - else { + } else { $this->variablePrefix = false; for ($i = 2; $i < $count; $i++) { $var = func_get_arg($i); @@ -124,19 +135,21 @@ class DebugExtension extends Twig_Extension $info = []; if (!is_array($variables)) { - if ($variables instanceof Paginator) + if ($variables instanceof Paginator) { $variables = $this->paginatorToArray($variables); - elseif (is_object($variables)) + } elseif (is_object($variables)) { $variables = $this->objectToArray($variables); - else + } else { $variables = [$variables]; + } } $output = []; $output[] = ''; - if ($caption) + if ($caption) { $output[] = $this->makeTableHeader($caption); + } foreach ($variables as $key => $item) { $output[] = $this->makeTableRow($key, $item); @@ -185,15 +198,12 @@ class DebugExtension extends Twig_Extension { if ($this->variablePrefix === true) { $output = '{{ %s }}'; - } - elseif (is_array($this->variablePrefix)) { + } elseif (is_array($this->variablePrefix)) { $prefix = implode('.', $this->variablePrefix); $output = '{{ '.$prefix.'.%s }}'; - } - elseif ($this->variablePrefix) { + } elseif ($this->variablePrefix) { $output = '{{ '.$this->variablePrefix.'.%s }}'; - } - else { + } else { $output = '%s'; } @@ -228,8 +238,9 @@ class DebugExtension extends Twig_Extension protected function getType($variable) { $type = gettype($variable); - if ($type == 'string' && substr($variable, 0, 12) == '___METHOD___') + if ($type == 'string' && substr($variable, 0, 12) == '___METHOD___') { return 'method'; + } return $type; } @@ -244,17 +255,15 @@ class DebugExtension extends Twig_Extension $class = get_class($variable); $label = class_basename($variable); - if ($variable instanceof ComponentBase) + if ($variable instanceof ComponentBase) { $label = 'Component'; - - elseif ($variable instanceof Collection) + } elseif ($variable instanceof Collection) { $label = 'Collection('.$variable->count().')'; - - elseif ($variable instanceof Paginator) + } elseif ($variable instanceof Paginator) { $label = 'Paged Collection('.$variable->count().')'; - - elseif ($variable instanceof Model) + } elseif ($variable instanceof Model) { $label = 'Model'; + } return ''.$label.''; } @@ -268,17 +277,21 @@ class DebugExtension extends Twig_Extension { $type = $this->getType($variable); - if ($type == 'method') + if ($type == 'method') { return $this->evalMethodDesc($variable); + } - if (isset($this->commentMap[$key])) + if (isset($this->commentMap[$key])) { return $this->commentMap[$key]; + } - if ($type == 'array') + if ($type == 'array') { return $this->evalArrDesc($variable); + } - if ($type == 'object') + if ($type == 'object') { return $this->evalObjDesc($variable); + } return ''; } @@ -291,8 +304,9 @@ class DebugExtension extends Twig_Extension protected function evalMethodDesc($variable) { $parts = explode('|', $variable); - if (count($parts) < 2) + if (count($parts) < 2) { return null; + } $method = $parts[1]; return isset($this->commentMap[$method]) ? $this->commentMap[$method] : null; @@ -370,13 +384,25 @@ class DebugExtension extends Twig_Extension $methods = []; foreach ($info->getMethods() as $method) { - if (!$method->isPublic()) continue; // Only public - if ($method->class != $class) continue; // Only locals + if (!$method->isPublic()) { + continue; // Only public + } + if ($method->class != $class) { + continue; // Only locals + } $name = $method->getName(); - if (in_array($name, $this->blockMethods)) continue; // Blocked methods - if (preg_match('/^on[A-Z]{1}[\w+]*$/', $name)) continue; // AJAX methods - if (preg_match('/^get[A-Z]{1}[\w+]*Options$/', $name)) continue; // getSomethingOptions - if (substr($name, 0, 1) == '_') continue; // Magic/hidden method + if (in_array($name, $this->blockMethods)) { + continue; // Blocked methods + } + if (preg_match('/^on[A-Z]{1}[\w+]*$/', $name)) { + continue; // AJAX methods + } + if (preg_match('/^get[A-Z]{1}[\w+]*Options$/', $name)) { + continue; // getSomethingOptions + } + if (substr($name, 0, 1) == '_') { + continue; // Magic/hidden method + } $name .= '()'; $methods[$name] = '___METHOD___|'.$name; $this->commentMap[$name] = $this->evalDocBlock($method); @@ -384,8 +410,12 @@ class DebugExtension extends Twig_Extension $vars = []; foreach ($info->getProperties() as $property) { - if (!$property->isPublic()) continue; // Only public - if ($property->class != $class) continue; // Only locals + if (!$property->isPublic()) { + continue; // Only public + } + if ($property->class != $class) { + continue; // Only locals + } $name = $property->getName(); $vars[$name] = $object->{$name}; $this->commentMap[$name] = $this->evalDocBlock($property); @@ -426,8 +456,9 @@ class DebugExtension extends Twig_Extension ]; $type = gettype($variable); - if ($type == 'NULL') + if ($type == 'NULL') { $css['color'] = '#999'; + } return $this->arrayToCss($css); } @@ -484,5 +515,4 @@ class DebugExtension extends Twig_Extension return join('; ', $strings); } - } diff --git a/modules/cms/twig/DefaultNode.php b/modules/cms/twig/DefaultNode.php index 9c501b968..1578b5262 100644 --- a/modules/cms/twig/DefaultNode.php +++ b/modules/cms/twig/DefaultNode.php @@ -28,4 +28,4 @@ class DefaultNode extends Twig_Node ->write("echo '';\n") ; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/DefaultTokenParser.php b/modules/cms/twig/DefaultTokenParser.php index 4fac9037d..9303f5fb0 100644 --- a/modules/cms/twig/DefaultTokenParser.php +++ b/modules/cms/twig/DefaultTokenParser.php @@ -41,4 +41,4 @@ class DefaultTokenParser extends Twig_TokenParser { return 'default'; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/Extension.php b/modules/cms/twig/Extension.php index 3b78af578..66158ce41 100644 --- a/modules/cms/twig/Extension.php +++ b/modules/cms/twig/Extension.php @@ -151,8 +151,9 @@ class Extension extends Twig_Extension */ public function placeholderFunction($name, $default = null) { - if (($result = Block::get($name)) === null) + if (($result = Block::get($name)) === null) { return null; + } $result = str_replace('', trim($default), $result); return $result; @@ -199,8 +200,9 @@ class Extension extends Twig_Extension */ public function displayBlock($name, $default = null) { - if (($result = Block::placeholder($name)) === null) + if (($result = Block::placeholder($name)) === null) { return null; + } $result = str_replace('', trim($default), $result); return $result; @@ -213,4 +215,4 @@ class Extension extends Twig_Extension { Block::endBlock($append); } -} \ No newline at end of file +} diff --git a/modules/cms/twig/FlashNode.php b/modules/cms/twig/FlashNode.php index fc53f3319..fae4a48f1 100644 --- a/modules/cms/twig/FlashNode.php +++ b/modules/cms/twig/FlashNode.php @@ -43,8 +43,7 @@ class FlashNode extends Twig_Node ->outdent() ->write('}'.PHP_EOL) ; - } - else { + } else { $compiler ->addDebugInfo($this) ->write('$context["type"] = ') @@ -66,4 +65,4 @@ class FlashNode extends Twig_Node ->write('$context["message"] = $_message;') ; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/FlashTokenParser.php b/modules/cms/twig/FlashTokenParser.php index a13b6f806..69faba566 100644 --- a/modules/cms/twig/FlashTokenParser.php +++ b/modules/cms/twig/FlashTokenParser.php @@ -27,8 +27,7 @@ class FlashTokenParser extends Twig_TokenParser if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) { $name = $token->getValue(); - } - else { + } else { $name = 'all'; } $stream->expect(Twig_Token::BLOCK_END_TYPE); @@ -53,4 +52,4 @@ class FlashTokenParser extends Twig_TokenParser { return 'flash'; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/FrameworkNode.php b/modules/cms/twig/FrameworkNode.php index e07044f93..2ca246181 100644 --- a/modules/cms/twig/FrameworkNode.php +++ b/modules/cms/twig/FrameworkNode.php @@ -28,14 +28,17 @@ class FrameworkNode extends Twig_Node $compiler ->addDebugInfo($this) - ->write("echo ''.PHP_EOL;" . PHP_EOL) + ->write("echo ''.PHP_EOL;" . PHP_EOL) ; if ($includeExtras) { $compiler - ->write("echo ''.PHP_EOL;" . PHP_EOL) - ->write("echo ''.PHP_EOL;" . PHP_EOL) + ->write("echo ''.PHP_EOL;" . PHP_EOL) + ->write("echo ''.PHP_EOL;" . PHP_EOL) ; } } -} \ No newline at end of file +} diff --git a/modules/cms/twig/FrameworkTokenParser.php b/modules/cms/twig/FrameworkTokenParser.php index 56ef5b8f1..300f5320d 100644 --- a/modules/cms/twig/FrameworkTokenParser.php +++ b/modules/cms/twig/FrameworkTokenParser.php @@ -45,4 +45,4 @@ class FrameworkTokenParser extends Twig_TokenParser { return 'framework'; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/Loader.php b/modules/cms/twig/Loader.php index 501d29e7f..243da96e4 100644 --- a/modules/cms/twig/Loader.php +++ b/modules/cms/twig/Loader.php @@ -39,4 +39,4 @@ class Loader implements Twig_LoaderInterface { return $this->obj->isLoadedFromCache(); } -} \ No newline at end of file +} diff --git a/modules/cms/twig/PageNode.php b/modules/cms/twig/PageNode.php index ba3dcaf1c..64338f120 100644 --- a/modules/cms/twig/PageNode.php +++ b/modules/cms/twig/PageNode.php @@ -28,4 +28,4 @@ class PageNode extends Twig_Node ->write("echo \$this->env->getExtension('CMS')->pageFunction();\n") ; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/PageTokenParser.php b/modules/cms/twig/PageTokenParser.php index a43dfdf4c..72908dd84 100644 --- a/modules/cms/twig/PageTokenParser.php +++ b/modules/cms/twig/PageTokenParser.php @@ -34,4 +34,4 @@ class PageTokenParser extends Twig_TokenParser { return 'page'; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/PartialNode.php b/modules/cms/twig/PartialNode.php index 297446e93..e2b779b4b 100644 --- a/modules/cms/twig/PartialNode.php +++ b/modules/cms/twig/PartialNode.php @@ -43,4 +43,4 @@ class PartialNode extends Twig_Node $compiler->write("unset(\$context['__cms_partial_params']);\n"); } -} \ No newline at end of file +} diff --git a/modules/cms/twig/PartialTokenParser.php b/modules/cms/twig/PartialTokenParser.php index 5c7d7e0fc..e1cebad2d 100644 --- a/modules/cms/twig/PartialTokenParser.php +++ b/modules/cms/twig/PartialTokenParser.php @@ -53,7 +53,11 @@ class PartialTokenParser extends Twig_TokenParser break; default: - throw new Twig_Error_Syntax(sprintf('Invalid syntax in the partial tag. Line %s', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename()); + throw new Twig_Error_Syntax( + sprintf('Invalid syntax in the partial tag. Line %s', $lineno), + $stream->getCurrent()->getLine(), + $stream->getFilename() + ); break; } } @@ -70,4 +74,4 @@ class PartialTokenParser extends Twig_TokenParser { return 'partial'; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/PlaceholderNode.php b/modules/cms/twig/PlaceholderNode.php index 6b25e4235..26c5c04f1 100644 --- a/modules/cms/twig/PlaceholderNode.php +++ b/modules/cms/twig/PlaceholderNode.php @@ -15,8 +15,9 @@ class PlaceholderNode extends Twig_Node public function __construct($name, $body, $lineno, $tag = 'placeholder') { $nodes = []; - if ($body) + if ($body) { $nodes['default'] = $body; + } parent::__construct($nodes, ['name'=>$name], $lineno, $tag); } @@ -62,4 +63,4 @@ class PlaceholderNode extends Twig_Node ->raw("'".$varId."'") ->raw("]);"); } -} \ No newline at end of file +} diff --git a/modules/cms/twig/PlaceholderTokenParser.php b/modules/cms/twig/PlaceholderTokenParser.php index c66502680..37eff2435 100644 --- a/modules/cms/twig/PlaceholderTokenParser.php +++ b/modules/cms/twig/PlaceholderTokenParser.php @@ -60,4 +60,4 @@ class PlaceholderTokenParser extends Twig_TokenParser { return 'placeholder'; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/PutNode.php b/modules/cms/twig/PutNode.php index 30ad241b2..a48eb5365 100644 --- a/modules/cms/twig/PutNode.php +++ b/modules/cms/twig/PutNode.php @@ -40,6 +40,6 @@ class PutNode extends Twig_Node ->write("echo \$this->env->getExtension('CMS')->endBlock(") ->raw($isOverwrite ? 'false' : 'true') ->write(");\n") - ; + ; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/PutTokenParser.php b/modules/cms/twig/PutTokenParser.php index 3fc39354d..63494fc32 100644 --- a/modules/cms/twig/PutTokenParser.php +++ b/modules/cms/twig/PutTokenParser.php @@ -63,4 +63,4 @@ class PutTokenParser extends Twig_TokenParser { return 'put'; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/ScriptsNode.php b/modules/cms/twig/ScriptsNode.php index 6545d5ab3..b40104c24 100644 --- a/modules/cms/twig/ScriptsNode.php +++ b/modules/cms/twig/ScriptsNode.php @@ -29,4 +29,4 @@ class ScriptsNode extends Twig_Node ->write("echo \$this->env->getExtension('CMS')->displayBlock('scripts');\n") ; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/ScriptsTokenParser.php b/modules/cms/twig/ScriptsTokenParser.php index a66088af6..d8c0a498b 100644 --- a/modules/cms/twig/ScriptsTokenParser.php +++ b/modules/cms/twig/ScriptsTokenParser.php @@ -38,4 +38,4 @@ class ScriptsTokenParser extends Twig_TokenParser { return 'scripts'; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/StylesNode.php b/modules/cms/twig/StylesNode.php index 5dc26ed8f..3c38a2590 100644 --- a/modules/cms/twig/StylesNode.php +++ b/modules/cms/twig/StylesNode.php @@ -29,4 +29,4 @@ class StylesNode extends Twig_Node ->write("echo \$this->env->getExtension('CMS')->displayBlock('styles');\n") ; } -} \ No newline at end of file +} diff --git a/modules/cms/twig/StylesTokenParser.php b/modules/cms/twig/StylesTokenParser.php index 4a3a729e9..5946cdd5a 100644 --- a/modules/cms/twig/StylesTokenParser.php +++ b/modules/cms/twig/StylesTokenParser.php @@ -38,4 +38,4 @@ class StylesTokenParser extends Twig_TokenParser { return 'styles'; } -} \ No newline at end of file +} From 634865e42e0b6a21e7e564230dc481d0fe1c2d26 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 01:53:40 +0200 Subject: [PATCH 21/30] Updating modules/cms/widgets --- modules/cms/widgets/AssetList.php | 267 ++++++++++++++++++-------- modules/cms/widgets/ComponentList.php | 68 ++++--- modules/cms/widgets/TemplateList.php | 82 +++++--- 3 files changed, 285 insertions(+), 132 deletions(-) diff --git a/modules/cms/widgets/AssetList.php b/modules/cms/widgets/AssetList.php index e9eb20127..53c894427 100644 --- a/modules/cms/widgets/AssetList.php +++ b/modules/cms/widgets/AssetList.php @@ -53,7 +53,24 @@ class AssetList extends WidgetBase * @var array A list of default allowed file types. * This parameter can be overridden with the cms.allowedAssetTypes configuration option. */ - public $allowedAssetTypes = ['jpg','jpeg','bmp','png','gif','css','js','woff','svg','ttf','eot','json','md','less','sass','scss']; + public $allowedAssetTypes = [ + 'jpg', + 'jpeg', + 'bmp', + 'png', + 'gif', + 'css', + 'js', + 'woff', + 'svg', + 'ttf', + 'eot', + 'json', + 'md', + 'less', + 'sass', + 'scss' + ]; public function __construct($controller, $alias) { @@ -103,12 +120,14 @@ class AssetList extends WidgetBase public function onOpenDirectory() { $path = Input::get('path'); - if (!$this->validatePath($path)) + if (!$this->validatePath($path)) { throw new ApplicationException(Lang::get('cms::lang.asset.invalid_path')); + } $delay = Input::get('delay'); - if ($delay) + if ($delay) { usleep(1000000*$delay); + } $this->putSession('currentPath', $path); return [ @@ -141,23 +160,36 @@ class AssetList extends WidgetBase try { $assetsPath = $this->getAssetsPath(); - foreach ($fileList as $path=>$selected) { + foreach ($fileList as $path => $selected) { if ($selected) { - if (!$this->validatePath($path)) + if (!$this->validatePath($path)) { throw new ApplicationException(Lang::get('cms::lang.asset.invalid_path')); + } $fullPath = $assetsPath.'/'.$path; if (File::exists($fullPath)) { if (!File::isDirectory($fullPath)) { - if (!@File::delete($fullPath)) - throw new ApplicationException(Lang::get('cms::lang.asset.error_deleting_file', ['name'=>$path])); + if (!@File::delete($fullPath)) { + throw new ApplicationException(Lang::get( + 'cms::lang.asset.error_deleting_file', + ['name'=>$path] + )); + } } else { $empty = File::isDirectoryEmpty($fullPath); - if ($empty === false) - throw new ApplicationException(Lang::get('cms::lang.asset.error_deleting_dir_not_empty', ['name'=>$path])); + if ($empty === false) { + throw new ApplicationException(Lang::get( + 'cms::lang.asset.error_deleting_dir_not_empty', + ['name'=>$path] + )); + } - if (!@rmdir($fullPath)) - throw new ApplicationException(Lang::get('cms::lang.asset.error_deleting_dir', ['name'=>$path])); + if (!@rmdir($fullPath)) { + throw new ApplicationException(Lang::get( + 'cms::lang.asset.error_deleting_dir', + ['name'=>$path] + )); + } } $deleted[] = $path; @@ -165,8 +197,7 @@ class AssetList extends WidgetBase } } } - } - catch (Exception $ex) { + } catch (Exception $ex) { $error = $ex->getMessage(); } @@ -182,8 +213,9 @@ class AssetList extends WidgetBase $this->validateRequestTheme(); $path = Input::get('renamePath'); - if (!$this->validatePath($path)) + if (!$this->validatePath($path)) { throw new ApplicationException(Lang::get('cms::lang.asset.invalid_path')); + } $this->vars['originalPath'] = $path; $this->vars['name'] = basename($path); @@ -195,29 +227,36 @@ class AssetList extends WidgetBase $this->validateRequestTheme(); $newName = trim(Input::get('name')); - if (!strlen($newName)) + if (!strlen($newName)) { throw new ApplicationException(Lang::get('cms::lang.asset.name_cant_be_empty')); + } - if (!$this->validatePath($newName)) + if (!$this->validatePath($newName)) { throw new ApplicationException(Lang::get('cms::lang.asset.invalid_path')); + } - if (!$this->validateName($newName)) + if (!$this->validateName($newName)) { throw new ApplicationException(Lang::get('cms::lang.asset.invalid_name')); + } $originalPath = Input::get('originalPath'); - if (!$this->validatePath($originalPath)) + if (!$this->validatePath($originalPath)) { throw new ApplicationException(Lang::get('cms::lang.asset.invalid_path')); + } $originalFullPath = $this->getFullPath($originalPath); - if (!file_exists($originalFullPath)) + if (!file_exists($originalFullPath)) { throw new ApplicationException(Lang::get('cms::lang.asset.original_not_found')); + } $newFullPath = $this->getFullPath(dirname($originalPath).'/'.$newName); - if (file_exists($newFullPath) && $newFullPath !== $originalFullPath) + if (file_exists($newFullPath) && $newFullPath !== $originalFullPath) { throw new ApplicationException(Lang::get('cms::lang.asset.already_exists')); + } - if (!@rename($originalFullPath, $newFullPath)) + if (!@rename($originalFullPath, $newFullPath)) { throw new ApplicationException(Lang::get('cms::lang.asset.error_renaming')); + } return [ '#'.$this->getId('asset-list') => $this->makePartial('items', ['items'=>$this->getData()]) @@ -236,21 +275,29 @@ class AssetList extends WidgetBase $this->validateRequestTheme(); $newName = trim(Input::get('name')); - if (!strlen($newName)) + if (!strlen($newName)) { throw new ApplicationException(Lang::get('cms::lang.asset.name_cant_be_empty')); + } - if (!$this->validatePath($newName)) + if (!$this->validatePath($newName)) { throw new ApplicationException(Lang::get('cms::lang.asset.invalid_path')); + } - if (!$this->validateName($newName)) + if (!$this->validateName($newName)) { throw new ApplicationException(Lang::get('cms::lang.asset.invalid_name')); + } $newFullPath = $this->getCurrentPath().'/'.$newName; - if (file_exists($newFullPath)) + if (file_exists($newFullPath)) { throw new ApplicationException(Lang::get('cms::lang.asset.already_exists')); + } - if (!@mkdir($newFullPath)) - throw new ApplicationException(Lang::get('cms::lang.cms_object.error_creating_directory', ['name'=>$newName])); + if (!@mkdir($newFullPath)) { + throw new ApplicationException(Lang::get( + 'cms::lang.cms_object.error_creating_directory', + ['name' => $newName] + )); + } return [ '#'.$this->getId('asset-list') => $this->makePartial('items', ['items'=>$this->getData()]) @@ -264,7 +311,7 @@ class AssetList extends WidgetBase $fileList = Request::input('file'); $directories = []; - $selectedList = array_filter($fileList, function($value){ + $selectedList = array_filter($fileList, function ($value) { return $value == 1; }); @@ -280,49 +327,74 @@ class AssetList extends WidgetBase $this->validateRequestTheme(); $selectedList = Input::get('selectedList'); - if (!strlen($selectedList)) + if (!strlen($selectedList)) { throw new ApplicationException(Lang::get('cms::lang.asset.selected_files_not_found')); + } $destinationDir = Input::get('dest'); - if (!strlen($destinationDir)) + if (!strlen($destinationDir)) { throw new ApplicationException(Lang::get('cms::lang.asset.select_destination_dir')); + } $destinationFullPath = $this->getFullPath($destinationDir); - if (!file_exists($destinationFullPath) || !is_dir($destinationFullPath)) + if (!file_exists($destinationFullPath) || !is_dir($destinationFullPath)) { throw new ApplicationException(Lang::get('cms::lang.asset.destination_not_found')); + } $list = @unserialize($selectedList); - if ($list === false) + if ($list === false) { throw new ApplicationException(Lang::get('cms::lang.asset.selected_files_not_found')); + } foreach ($list as $path) { - if (!$this->validatePath($path)) + if (!$this->validatePath($path)) { throw new ApplicationException(Lang::get('cms::lang.asset.invalid_path')); + } $basename = basename($path); $originalFullPath = $this->getFullPath($path); $newFullPath = rtrim($destinationFullPath, '/').'/'.$basename; $safeDir = $this->getAssetsPath(); - if ($originalFullPath == $newFullPath) + if ($originalFullPath == $newFullPath) { continue; + } if (is_file($originalFullPath)) { - if (!@File::move($originalFullPath, $newFullPath)) - throw new ApplicationException(Lang::get('cms::lang.asset.error_moving_file', ['file'=>$basename])); - } - elseif (is_dir($originalFullPath)) { - if (!@File::copyDirectory($originalFullPath, $newFullPath)) - throw new ApplicationException(Lang::get('cms::lang.asset.error_moving_directory', ['dir'=>$basename])); + if (!@File::move($originalFullPath, $newFullPath)) { + throw new ApplicationException(Lang::get( + 'cms::lang.asset.error_moving_file', + ['file'=>$basename] + )); + } + } elseif (is_dir($originalFullPath)) { + if (!@File::copyDirectory($originalFullPath, $newFullPath)) { + throw new ApplicationException(Lang::get( + 'cms::lang.asset.error_moving_directory', + ['dir'=>$basename] + )); + } - if (strpos($originalFullPath, '../') !== false) - throw new ApplicationException(Lang::get('cms::lang.asset.error_deleting_directory', ['dir'=>$basename])); + if (strpos($originalFullPath, '../') !== false) { + throw new ApplicationException(Lang::get( + 'cms::lang.asset.error_deleting_directory', + ['dir'=>$basename] + )); + } - if (strpos($originalFullPath, $safeDir) !== 0) - throw new ApplicationException(Lang::get('cms::lang.asset.error_deleting_directory', ['dir'=>$basename])); + if (strpos($originalFullPath, $safeDir) !== 0) { + throw new ApplicationException(Lang::get( + 'cms::lang.asset.error_deleting_directory', + ['dir'=>$basename] + )); + } - if (!@File::deleteDirectory($originalFullPath, $directory)) - throw new ApplicationException(Lang::get('cms::lang.asset.error_deleting_directory', ['dir'=>$basename])); + if (!@File::deleteDirectory($originalFullPath, $directory)) { + throw new ApplicationException(Lang::get( + 'cms::lang.asset.error_deleting_directory', + ['dir'=>$basename] + )); + } } } @@ -348,8 +420,12 @@ class AssetList extends WidgetBase $assetsPath = $this->getAssetsPath(); if (!file_exists($assetsPath) || !is_dir($assetsPath)) { - if (!@mkdir($assetsPath)) - throw new ApplicationException(Lang::get('cms::lang.cms_object.error_creating_directory', ['name'=>$assetsPath])); + if (!@mkdir($assetsPath)) { + throw new ApplicationException(Lang::get( + 'cms::lang.cms_object.error_creating_directory', + ['name'=>$assetsPath] + )); + } } $searchTerm = Str::lower($this->getSearchTerm()); @@ -378,11 +454,13 @@ class AssetList extends WidgetBase { $path = $this->getSession('currentPath', '/'); - if (!$this->validatePath($path)) + if (!$this->validatePath($path)) { return null; + } - if ($path == '.') + if ($path == '.') { return null; + } return ltrim($path, '/'); } @@ -392,8 +470,9 @@ class AssetList extends WidgetBase $assetsPath = $this->getAssetsPath(); $path = $assetsPath.'/'.$this->getCurrentRelativePath(); - if (!is_dir($path)) + if (!is_dir($path)) { return $assetsPath; + } return $path; } @@ -402,8 +481,9 @@ class AssetList extends WidgetBase { $prefix = $this->getAssetsPath(); - if (substr($path, 0, strlen($prefix)) == $prefix) + if (substr($path, 0, strlen($prefix)) == $prefix) { $path = substr($path, strlen($prefix)); + } return $path; } @@ -415,22 +495,26 @@ class AssetList extends WidgetBase protected function validatePath($path) { - if (!preg_match('/^[0-9a-z\.\s_\-\/]+$/i', $path)) + if (!preg_match('/^[0-9a-z\.\s_\-\/]+$/i', $path)) { return false; + } - if (strpos($path, '..') !== false || strpos($path, './') !== false) + if (strpos($path, '..') !== false || strpos($path, './') !== false) { return false; + } return true; } protected function validateName($name) { - if (!preg_match('/^[0-9a-z\.\s_\-]+$/i', $name)) + if (!preg_match('/^[0-9a-z\.\s_\-]+$/i', $name)) { return false; + } - if (strpos($name, '..') !== false) + if (strpos($name, '..') !== false) { return false; + } return true; } @@ -443,8 +527,9 @@ class AssetList extends WidgetBase $files = []; foreach ($dir as $node) { - if (substr($node->getFileName(), 0, 1) == '.') + if (substr($node->getFileName(), 0, 1) == '.') { continue; + } if ($node->isDir() && !$node->isDot()) { $result[$node->getFilename()] = (object)[ @@ -453,8 +538,7 @@ class AssetList extends WidgetBase 'name' => $node->getFilename(), 'editable' => false ]; - } - elseif ($node->isFile()) { + } elseif ($node->isFile()) { $files[] = (object)[ 'type' => 'file', 'path' => File::normalizePath($this->getRelativePath($node->getPathname())), @@ -464,8 +548,9 @@ class AssetList extends WidgetBase } } - foreach ($files as $file) + foreach ($files as $file) { $result[] = $file; + } return $result; } @@ -481,14 +566,16 @@ class AssetList extends WidgetBase $dirs = new DirectoryIterator($startDir); foreach ($dirs as $node) { - if (substr($node->getFileName(), 0, 1) == '.') + if (substr($node->getFileName(), 0, 1) == '.') { continue; + } if ($node->isDir() && !$node->isDot()) { $fullPath = $node->getPathname(); $relativePath = $this->getRelativePath($fullPath); - if (array_key_exists($relativePath, $excludeList)) + if (array_key_exists($relativePath, $excludeList)) { continue; + } $result[$relativePath] = str_repeat(' ', $level*4).$node->getFilename(); @@ -514,12 +601,14 @@ class AssetList extends WidgetBase protected function getSelectedFiles() { - if ($this->selectedFilesCache !== false) + if ($this->selectedFilesCache !== false) { return $this->selectedFilesCache; + } $files = $this->getSession($this->getThemeSessionKey('selected'), []); - if (!is_array($files)) + if (!is_array($files)) { return $this->selectedFilesCache = []; + } return $this->selectedFilesCache = $files; } @@ -527,8 +616,9 @@ class AssetList extends WidgetBase protected function isFileSelected($item) { $selectedFiles = $this->getSelectedFiles(); - if (!is_array($selectedFiles) || !isset($selectedFiles[$item->path])) + if (!is_array($selectedFiles) || !isset($selectedFiles[$item->path])) { return false; + } return $selectedFiles[$item->path]; } @@ -536,8 +626,9 @@ class AssetList extends WidgetBase protected function getUpPath() { $path = $this->getCurrentRelativePath(); - if (!strlen(rtrim(ltrim($path, '/'), '/'))) + if (!strlen(rtrim(ltrim($path, '/'), '/'))) { return null; + } return dirname($path); } @@ -561,8 +652,9 @@ class AssetList extends WidgetBase protected function validateRequestTheme() { - if ($this->theme->getDirName() != Request::input('theme')) + if ($this->theme->getDirName() != Request::input('theme')) { throw new ApplicationException(trans('cms::lang.theme.edit.not_match')); + } } /** @@ -576,35 +668,45 @@ class AssetList extends WidgetBase try { $uploadedFile = Input::file('file_data'); - if (!is_object($uploadedFile)) + if (!is_object($uploadedFile)) { return; + } $fileName = $uploadedFile->getClientOriginalName(); // Don't rely on Symfony's mime guessing implementation, it's not accurate enough. // Use the simple extension validation. - $allowedAssetTypes = Config::get('cms.allowedAssetTypes'); - if (!$allowedAssetTypes) + $allowedAssetTypes = Config::get('cms.allowedAssetTypes'); + if (!$allowedAssetTypes) { $allowedAssetTypes = $this->allowedAssetTypes; + } $maxSize = UploadedFile::getMaxFilesize(); - if ($uploadedFile->getSize() > $maxSize) - throw new ApplicationException(Lang::get('cms::lang.asset.too_large', ['max_size'=>File::sizeToString($maxSize)])); + if ($uploadedFile->getSize() > $maxSize) { + throw new ApplicationException(Lang::get( + 'cms::lang.asset.too_large', + ['max_size '=> File::sizeToString($maxSize)] + )); + } $ext = strtolower(pathinfo($uploadedFile->getClientOriginalName(), PATHINFO_EXTENSION)); - if (!in_array($ext, $allowedAssetTypes)) - throw new ApplicationException(Lang::get('cms::lang.asset.type_not_allowed', ['allowed_types'=>implode(', ', $allowedAssetTypes)])); + if (!in_array($ext, $allowedAssetTypes)) { + throw new ApplicationException(Lang::get( + 'cms::lang.asset.type_not_allowed', + ['allowed_types' => implode(', ', $allowedAssetTypes)] + )); + } - if (!$uploadedFile->isValid()) + if (!$uploadedFile->isValid()) { throw new ApplicationException(Lang::get('cms::lang.asset.file_not_valid')); + } $uploadedFile->move($this->getCurrentPath(), $uploadedFile->getClientOriginalName()); die('success'); - } - catch (Exception $ex) { + } catch (Exception $ex) { $message = $fileName !== null - ? Lang::get('cms::lang.asset.error_uploading_file', ['name'=>$fileName, 'error'=>$ex->getMessage()]) + ? Lang::get('cms::lang.asset.error_uploading_file', ['name' => $fileName, 'error' => $ex->getMessage()]) : $ex->getMessage(); die($message); @@ -632,8 +734,9 @@ class AssetList extends WidgetBase $result = []; foreach ($iterator as $item) { if (!$item->isDir()) { - if (substr($item->getFileName(), 0, 1) == '.') + if (substr($item->getFileName(), 0, 1) == '.') { continue; + } $path = $this->getRelativePath($item->getPathname()); @@ -655,11 +758,13 @@ class AssetList extends WidgetBase { foreach ($words as $word) { $word = trim($word); - if (!strlen($word)) + if (!strlen($word)) { continue; + } - if (!Str::contains(Str::lower($path), $word)) + if (!Str::contains(Str::lower($path), $word)) { return false; + } } return true; diff --git a/modules/cms/widgets/ComponentList.php b/modules/cms/widgets/ComponentList.php index b0eca1de5..20556bf0c 100644 --- a/modules/cms/widgets/ComponentList.php +++ b/modules/cms/widgets/ComponentList.php @@ -47,7 +47,9 @@ class ComponentList extends WidgetBase /** * Returns information about this widget, including name and description. */ - public function widgetDetails() {} + public function widgetDetails() + { + } /* * Event handlers @@ -73,8 +75,9 @@ class ComponentList extends WidgetBase { $searchTerm = Str::lower($this->getSearchTerm()); $searchWords = []; - if (strlen($searchTerm)) + if (strlen($searchTerm)) { $searchWords = explode(' ', $searchTerm); + } $pluginManager = PluginManager::instance(); $plugins = $pluginManager->getPlugins(); @@ -84,13 +87,20 @@ class ComponentList extends WidgetBase $items = []; foreach ($plugins as $plugin) { $components = $this->getPluginComponents($plugin); - if (!is_array($components)) + if (!is_array($components)) { continue; + } $pluginDetails = $plugin->pluginDetails(); - $pluginName = isset($pluginDetails['name']) ? $pluginDetails['name'] : Lang::get('system::lang.plugin.unnamed'); - $pluginIcon = isset($pluginDetails['icon']) ? $pluginDetails['icon'] : 'icon-puzzle-piece'; - $pluginDescription = isset($pluginDetails['description']) ? $pluginDetails['description'] : null; + $pluginName = isset($pluginDetails['name']) ? + $pluginDetails['name'] : + Lang::get('system::lang.plugin.unnamed'); + $pluginIcon = isset($pluginDetails['icon']) ? + $pluginDetails['icon'] : + 'icon-puzzle-piece'; + $pluginDescription = isset($pluginDetails['description']) ? + $pluginDetails['description'] : + null; $pluginClass = get_class($plugin); $pluginItems = []; @@ -110,11 +120,14 @@ class ComponentList extends WidgetBase 'className' => get_class($component), 'pluginIcon' => $pluginIcon, 'alias' => $alias, - 'name' => $componentInfo->duplicateAlias ? $componentInfo->className : $componentInfo->alias + 'name' => $componentInfo->duplicateAlias ? + $componentInfo->className : + $componentInfo->alias ]; - if ($searchWords && !$this->itemMatchesSearch($searchWords, $item)) + if ($searchWords && !$this->itemMatchesSearch($searchWords, $item)) { continue; + } if (!array_key_exists($pluginClass, $items)) { $group = (object)[ @@ -131,15 +144,16 @@ class ComponentList extends WidgetBase $pluginItems[] = $item; } - usort($pluginItems, function($a, $b) { + usort($pluginItems, function ($a, $b) { return strcmp($a->title, $b->title); }); - if (isset($items[$pluginClass])) + if (isset($items[$pluginClass])) { $items[$pluginClass]->items = $pluginItems; + } } - uasort($items, function($a, $b) { + uasort($items, function ($a, $b) { return strcmp($a->title, $b->title); }); @@ -154,8 +168,9 @@ class ComponentList extends WidgetBase $componentList = []; foreach ($plugins as $plugin) { $components = $plugin->registerComponents(); - if (!is_array($components)) + if (!is_array($components)) { continue; + } foreach ($components as $className => $alias) { $duplicateAlias = false; @@ -183,8 +198,9 @@ class ComponentList extends WidgetBase $result = array(); $pluginClass = get_class($plugin); foreach ($this->pluginComponentList as $componentInfo) { - if ($componentInfo->pluginClass == $pluginClass) + if ($componentInfo->pluginClass == $pluginClass) { $result[] = $componentInfo; + } } return $result; @@ -210,11 +226,13 @@ class ComponentList extends WidgetBase { foreach ($words as $word) { $word = trim($word); - if (!strlen($word)) + if (!strlen($word)) { continue; + } - if (!$this->itemContainsWord($word, $item)) + if (!$this->itemContainsWord($word, $item)) { return false; + } } return true; @@ -222,26 +240,31 @@ class ComponentList extends WidgetBase protected function itemContainsWord($word, $item) { - if (Str::contains(Str::lower($item->title), $word)) + if (Str::contains(Str::lower($item->title), $word)) { return true; + } - if (Str::contains(Str::lower($item->description), $word) && strlen($item->description)) + if (Str::contains(Str::lower($item->description), $word) && strlen($item->description)) { return true; + } - if (Str::contains(Str::lower($item->plugin), $word) && strlen($item->plugin)) + if (Str::contains(Str::lower($item->plugin), $word) && strlen($item->plugin)) { return true; + } return false; } protected function getGroupStatuses() { - if ($this->groupStatusCache !== false) + if ($this->groupStatusCache !== false) { return $this->groupStatusCache; + } $groups = $this->getSession('groups'); - if (!is_array($groups)) + if (!is_array($groups)) { return $this->groupStatusCache = []; + } return $this->groupStatusCache = $groups; } @@ -258,9 +281,10 @@ class ComponentList extends WidgetBase protected function getGroupStatus($group) { $statuses = $this->getGroupStatuses(); - if (array_key_exists($group, $statuses)) + if (array_key_exists($group, $statuses)) { return $statuses[$group]; + } return false; } -} \ No newline at end of file +} diff --git a/modules/cms/widgets/TemplateList.php b/modules/cms/widgets/TemplateList.php index 73b36debf..7ba791d9b 100644 --- a/modules/cms/widgets/TemplateList.php +++ b/modules/cms/widgets/TemplateList.php @@ -46,7 +46,7 @@ class TemplateList extends WidgetBase /** * @var string Message to display when there are no records in the list. */ - public $noRecordsMessage = 'No records found'; + public $noRecordsMessage = 'No records found'; /** * @var string Message to display when the Delete button is clicked. @@ -70,15 +70,17 @@ class TemplateList extends WidgetBase parent::__construct($controller, []); - if (!Request::isXmlHttpRequest()) + if (!Request::isXmlHttpRequest()) { $this->resetSelection(); + } $configFile = 'config_' . snake_case($alias) .'.yaml'; $config = $this->makeConfig($configFile); - foreach ($config as $field=>$value) { - if (property_exists($this, $field)) + foreach ($config as $field => $value) { + if (property_exists($this, $field)) { $this->$field = $value; + } } $this->bindToController(); @@ -134,10 +136,11 @@ class TemplateList extends WidgetBase $items = call_user_func($this->dataSource); $normalizedItems = []; - foreach ($items as $item) + foreach ($items as $item) { $normalizedItems[] = $this->normalizeItem($item); + } - usort($normalizedItems, function($a, $b) { + usort($normalizedItems, function ($a, $b) { return strcmp($a->title, $b->title); }); @@ -150,11 +153,13 @@ class TemplateList extends WidgetBase $words = explode(' ', $searchTerm); foreach ($normalizedItems as $item) { - if ($this->itemMatchesSearch($words, $item)) + if ($this->itemMatchesSearch($words, $item)) { $filteredItems[] = $item; + } } - } else + } else { $filteredItems = $normalizedItems; + } // Group the items $result = []; @@ -174,12 +179,14 @@ class TemplateList extends WidgetBase } $foundGroups[$group]->items[] = $itemData; - } else + } else { $result[] = $itemData; + } } - foreach ($foundGroups as $group) + foreach ($foundGroups as $group) { $result[] = $group; + } return $result; } @@ -187,13 +194,15 @@ class TemplateList extends WidgetBase protected function normalizeItem($item) { $description = null; - if ($descriptionProperty = $this->descriptionProperty) + if ($descriptionProperty = $this->descriptionProperty) { $description = $item->$descriptionProperty; + } $descriptions = []; - foreach ($this->descriptionProperties as $property=>$title) { - if ($item->$property) + foreach ($this->descriptionProperties as $property => $title) { + if ($item->$property) { $descriptions[$title] = $item->$property; + } } $result = [ @@ -210,8 +219,9 @@ class TemplateList extends WidgetBase { $titleProperty = $this->titleProperty; - if ($titleProperty) + if ($titleProperty) { return $item->$titleProperty ?: $item->getFileName(); + } return $item->getFileName(); } @@ -236,11 +246,13 @@ class TemplateList extends WidgetBase { foreach ($words as $word) { $word = trim($word); - if (!strlen($word)) + if (!strlen($word)) { continue; + } - if (!$this->itemContainsWord($word, $item)) + if (!$this->itemContainsWord($word, $item)) { return false; + } } return true; @@ -249,18 +261,24 @@ class TemplateList extends WidgetBase protected function itemContainsWord($word, $item) { if (strlen($item->title)) { - if (Str::contains(Str::lower($item->title), $word)) + if (Str::contains(Str::lower($item->title), $word)) { return true; - } else - if (Str::contains(Str::lower($item->fileName), $word)) + } + } else { + if (Str::contains(Str::lower($item->fileName), $word)) { return true; + } + } - if (Str::contains(Str::lower($item->description), $word) && strlen($item->description)) + if (Str::contains(Str::lower($item->description), $word) && strlen($item->description)) { return true; + } - foreach ($item->descriptions as $value) - if (Str::contains(Str::lower($value), $word) && strlen($value)) + foreach ($item->descriptions as $value) { + if (Str::contains(Str::lower($value), $word) && strlen($value)) { return true; + } + } return false; } @@ -268,8 +286,9 @@ class TemplateList extends WidgetBase protected function getGroupStatus($group) { $statuses = $this->getGroupStatuses(); - if (array_key_exists($group, $statuses)) + if (array_key_exists($group, $statuses)) { return $statuses[$group]; + } return false; } @@ -281,12 +300,14 @@ class TemplateList extends WidgetBase protected function getGroupStatuses() { - if ($this->groupStatusCache !== false) + if ($this->groupStatusCache !== false) { return $this->groupStatusCache; + } $groups = $this->getSession($this->getThemeSessionKey('groups'), []); - if (!is_array($groups)) + if (!is_array($groups)) { return $this->groupStatusCache = []; + } return $this->groupStatusCache = $groups; } @@ -301,12 +322,14 @@ class TemplateList extends WidgetBase protected function getSelectedTemplates() { - if ($this->selectedTemplatesCache !== false) + if ($this->selectedTemplatesCache !== false) { return $this->selectedTemplatesCache; + } $templates = $this->getSession($this->getThemeSessionKey('selected'), []); - if (!is_array($templates)) + if (!is_array($templates)) { return $this->selectedTemplatesCache = []; + } return $this->selectedTemplatesCache = $templates; } @@ -327,9 +350,10 @@ class TemplateList extends WidgetBase protected function isTemplateSelected($item) { $selectedTemplates = $this->getSelectedTemplates(); - if (!is_array($selectedTemplates) || !isset($selectedTemplates[$item->fileName])) + if (!is_array($selectedTemplates) || !isset($selectedTemplates[$item->fileName])) { return false; + } return $selectedTemplates[$item->fileName]; } -} \ No newline at end of file +} From 40640d1923dd9cd5c7e7cd6f0af83dbbb75d8023 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 01:56:53 +0200 Subject: [PATCH 22/30] Updating single files in modules/cms --- modules/cms/ServiceProvider.php | 25 +++++++++++++------------ modules/cms/routes.php | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/modules/cms/ServiceProvider.php b/modules/cms/ServiceProvider.php index a59e25ff8..3c156c53c 100644 --- a/modules/cms/ServiceProvider.php +++ b/modules/cms/ServiceProvider.php @@ -25,7 +25,7 @@ class ServiceProvider extends ModuleServiceProvider /* * Register navigation */ - BackendMenu::registerCallback(function($manager) { + BackendMenu::registerCallback(function ($manager) { $manager->registerMenuItems('October.Cms', [ 'cms' => [ 'label' => 'cms::lang.cms.menu_label', @@ -86,7 +86,7 @@ class ServiceProvider extends ModuleServiceProvider /* * Register permissions */ - BackendAuth::registerCallback(function($manager) { + BackendAuth::registerCallback(function ($manager) { $manager->registerPermissions('October.Cms', [ 'cms.manage_content' => ['label' => 'cms::lang.permissions.manage_content', 'tab' => 'Cms'], 'cms.manage_assets' => ['label' => 'cms::lang.permissions.manage_assets', 'tab' => 'Cms'], @@ -100,14 +100,14 @@ class ServiceProvider extends ModuleServiceProvider /* * Register widgets */ - WidgetManager::instance()->registerFormWidgets(function($manager){ + WidgetManager::instance()->registerFormWidgets(function ($manager) { $manager->registerFormWidget('Cms\FormWidgets\Components'); }); /* * Register settings */ - SettingsManager::instance()->registerCallback(function($manager){ + SettingsManager::instance()->registerCallback(function ($manager) { $manager->registerSettingItems('October.Cms', [ 'theme' => [ 'label' => 'cms::lang.theme.settings_menu', @@ -123,7 +123,7 @@ class ServiceProvider extends ModuleServiceProvider /* * Register components */ - ComponentManager::instance()->registerComponents(function($manager){ + ComponentManager::instance()->registerComponents(function ($manager) { $manager->registerComponent('Cms\Classes\ViewBag', 'viewBag'); }); } @@ -137,21 +137,22 @@ class ServiceProvider extends ModuleServiceProvider { parent::boot('cms'); - Event::listen('pages.menuitem.listTypes', function() { + Event::listen('pages.menuitem.listTypes', function () { return [ - 'cms-page'=>'CMS Page ' + 'cms-page' => 'CMS Page ' ]; }); - Event::listen('pages.menuitem.getTypeInfo', function($type) { - if ($type == 'cms-page') + Event::listen('pages.menuitem.getTypeInfo', function ($type) { + if ($type == 'cms-page') { return CmsPage::getMenuTypeInfo($type); + } }); - Event::listen('pages.menuitem.resolveItem', function($type, $item, $url, $theme) { - if ($type == 'cms-page') + Event::listen('pages.menuitem.resolveItem', function ($type, $item, $url, $theme) { + if ($type == 'cms-page') { return CmsPage::resolveMenuItem($item, $url, $theme); + } }); } - } diff --git a/modules/cms/routes.php b/modules/cms/routes.php index 45a8295ff..27520fe9a 100644 --- a/modules/cms/routes.php +++ b/modules/cms/routes.php @@ -3,7 +3,7 @@ /* * Register CMS routes before all user routes. */ -App::before(function($request) { +App::before(function ($request) { /* * Combine JavaScript and StyleSheet assets From 4fa6db3bd58da3aa548577378da682276fb5315e Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 12:15:02 +0200 Subject: [PATCH 23/30] Fixing minor issue --- modules/backend/widgets/Form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 6fb98a8fb..c9851b21e 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -759,7 +759,7 @@ class Form extends WidgetBase * Number fields should be converted to integers */ foreach ($this->fields as $field) { - if ($field->type != 'number') + if ($field->type != 'number') { continue; } From 230a7377cfe05e0bb327ec352aedb59343ea98b1 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 11 Oct 2014 14:33:40 +0200 Subject: [PATCH 24/30] Updating files in modules/cms --- modules/cms/classes/CmsCompoundObject.php | 4 ++-- modules/cms/classes/ComponentHelpers.php | 4 +++- modules/cms/lang/es-ar/lang.php | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/cms/classes/CmsCompoundObject.php b/modules/cms/classes/CmsCompoundObject.php index 1210d3fda..872780919 100644 --- a/modules/cms/classes/CmsCompoundObject.php +++ b/modules/cms/classes/CmsCompoundObject.php @@ -259,7 +259,7 @@ class CmsCompoundObject extends CmsObject */ public function getComponent($componentName) { - if (!($componentSection = $this->hasComponent($componentName))) + if (!($componentSection = $this->hasComponent($componentName))) { return null; } @@ -277,7 +277,7 @@ class CmsCompoundObject extends CmsObject */ public function hasComponent($componentName) { - foreach ($this->settings['components'] as $sectionName=>$values) { + foreach ($this->settings['components'] as $sectionName => $values) { if ($sectionName == $componentName) { return $componentName; } diff --git a/modules/cms/classes/ComponentHelpers.php b/modules/cms/classes/ComponentHelpers.php index e29adcb00..101eca678 100644 --- a/modules/cms/classes/ComponentHelpers.php +++ b/modules/cms/classes/ComponentHelpers.php @@ -54,7 +54,9 @@ class ComponentHelpers } if (is_array($value)) { - array_walk($property[$name], function(&$_value, $key) { $_value = Lang::get($_value); }); + array_walk($property[$name], function (&$_value, $key) { + $_value = Lang::get($_value); + }); } else { $property[$name] = Lang::get($value); } diff --git a/modules/cms/lang/es-ar/lang.php b/modules/cms/lang/es-ar/lang.php index 709b74b52..65160c2de 100644 --- a/modules/cms/lang/es-ar/lang.php +++ b/modules/cms/lang/es-ar/lang.php @@ -170,4 +170,4 @@ return [ 'manage_partials' => 'Gestionar parciales', 'manage_themes' => 'Gestionar plantilla' ] -]; \ No newline at end of file +]; From dcb292b24600d92206784e74c76a433f41adac4c Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sun, 12 Oct 2014 13:43:50 +0200 Subject: [PATCH 25/30] Fixing incorrect brackets --- modules/backend/classes/Controller.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/backend/classes/Controller.php b/modules/backend/classes/Controller.php index b95f7150c..8a842824e 100644 --- a/modules/backend/classes/Controller.php +++ b/modules/backend/classes/Controller.php @@ -172,10 +172,9 @@ class Controller extends Extendable // Not logged in, redirect to login screen or show ajax error if (!BackendAuth::check()) { - return Request::ajax() { + return Request::ajax() ? Response::make(Lang::get('backend::lang.page.access_denied.label'), 403) : Redirect::guest(Backend::url('backend/auth')); - } } // Check his access groups against the page definition From acf2304ce2b2832dc10f96cae694f68933f54903 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sun, 12 Oct 2014 14:23:47 +0200 Subject: [PATCH 26/30] Fixing test SectionParserTest::testParseOffset --- modules/cms/classes/SectionParser.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/cms/classes/SectionParser.php b/modules/cms/classes/SectionParser.php index 11bee8b22..ebd321064 100644 --- a/modules/cms/classes/SectionParser.php +++ b/modules/cms/classes/SectionParser.php @@ -153,8 +153,7 @@ class SectionParser * PHP namespaced line (use x;) { * Don't increase the line count, it will be rewritten by Cms\Classes\CodeParser */ - if (preg_match_all('/(use\s+[a-z0-9_\\\\]+; - }\n?)/mi', $line) == 1) { + if (preg_match_all('/(use\s+[a-z0-9_\\\\]+;\n?)/mi', $line) == 1) { continue; } From f85087eac615c00ddb9d93fccd6aedf19ce95abb Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 18 Oct 2014 11:58:50 +0200 Subject: [PATCH 27/30] Updating modules/system --- modules/system/ServiceProvider.php | 102 ++++++---- modules/system/aliases.php | 2 +- modules/system/behaviors/SettingsModel.php | 22 ++- .../system/classes/ApplicationException.php | 2 +- modules/system/classes/Controller.php | 29 ++- modules/system/classes/ErrorHandler.php | 34 ++-- modules/system/classes/ExceptionBase.php | 67 ++++--- modules/system/classes/MarkupManager.php | 59 +++--- modules/system/classes/ModelBehavior.php | 3 +- modules/system/classes/PluginBase.php | 12 +- modules/system/classes/PluginManager.php | 121 +++++++----- modules/system/classes/SettingsManager.php | 45 +++-- modules/system/classes/SystemException.php | 2 +- modules/system/classes/UpdateManager.php | 60 +++--- modules/system/classes/VersionManager.php | 79 +++++--- modules/system/console/CacheClear.php | 6 +- modules/system/console/OctoberDown.php | 13 +- modules/system/console/OctoberUp.php | 6 +- modules/system/console/OctoberUpdate.php | 4 +- modules/system/console/OctoberUtil.php | 16 +- modules/system/console/PluginInstall.php | 6 +- modules/system/console/PluginRefresh.php | 9 +- modules/system/console/PluginRemove.php | 16 +- modules/system/controllers/EventLogs.php | 3 +- modules/system/controllers/MailLayouts.php | 3 +- modules/system/controllers/MailTemplates.php | 14 +- modules/system/controllers/RequestLogs.php | 3 +- modules/system/controllers/Settings.php | 16 +- modules/system/controllers/Updates.php | 89 +++++---- ...2013_10_01_000001_Db_Deferred_Bindings.php | 4 +- .../2013_10_01_000002_Db_System_Files.php | 4 +- ...10_01_000003_Db_System_Plugin_Versions.php | 4 +- ..._10_01_000004_Db_System_Plugin_History.php | 4 +- .../2013_10_01_000005_Db_System_Settings.php | 5 +- ...2013_10_01_000006_Db_System_Parameters.php | 3 +- ..._01_000007_Db_System_Add_Disabled_Flag.php | 7 +- ..._10_01_000008_Db_System_Mail_Templates.php | 4 +- ...13_10_01_000009_Db_System_Mail_Layouts.php | 4 +- .../2013_10_01_000010_Db_Cron_Queue.php | 4 +- ...2014_10_01_000011_Db_System_Event_Logs.php | 4 +- ...14_10_01_000012_Db_System_Request_Logs.php | 4 +- .../2014_10_01_000013_Db_System_Sessions.php | 4 +- .../system/database/seeds/DatabaseSeeder.php | 3 +- .../database/seeds/SeedSetupMailLayouts.php | 3 +- modules/system/lang/de/lang.php | 2 +- modules/system/lang/de/validation.php | 174 +++++++++--------- modules/system/lang/es-ar/lang.php | 2 +- modules/system/lang/es-ar/validation.php | 2 +- modules/system/lang/nl/lang.php | 2 +- modules/system/lang/sv/lang.php | 2 +- modules/system/lang/tr/validation.php | 2 +- modules/system/models/EventLog.php | 9 +- modules/system/models/File.php | 10 +- modules/system/models/MailLayout.php | 6 +- modules/system/models/MailSettings.php | 5 +- modules/system/models/MailTemplate.php | 27 ++- modules/system/models/Parameters.php | 9 +- modules/system/models/PluginVersion.php | 11 +- modules/system/models/RequestLog.php | 6 +- modules/system/providers.php | 2 +- modules/system/reportwidgets/Status.php | 5 +- modules/system/routes.php | 2 +- modules/system/traits/AssetMaker.php | 83 ++++++--- modules/system/traits/ConfigMaker.php | 54 +++--- modules/system/traits/PropertyContainer.php | 2 +- modules/system/traits/ViewMaker.php | 45 +++-- modules/system/twig/Engine.php | 3 +- modules/system/twig/Extension.php | 3 +- modules/system/twig/Loader.php | 14 +- 69 files changed, 796 insertions(+), 590 deletions(-) diff --git a/modules/system/ServiceProvider.php b/modules/system/ServiceProvider.php index 89275e896..a90a90fa7 100644 --- a/modules/system/ServiceProvider.php +++ b/modules/system/ServiceProvider.php @@ -47,19 +47,37 @@ class ServiceProvider extends ModuleServiceProvider /* * Define path constants */ - if (!defined('PATH_APP')) define('PATH_APP', app_path()); - if (!defined('PATH_BASE')) define('PATH_BASE', base_path()); - if (!defined('PATH_PUBLIC')) define('PATH_PUBLIC', public_path()); - if (!defined('PATH_STORAGE')) define('PATH_STORAGE', storage_path()); - if (!defined('PATH_PLUGINS')) define('PATH_PLUGINS', base_path() . Config::get('cms.pluginsDir', '/plugins')); + if (!defined('PATH_APP')) { + define('PATH_APP', app_path()); + } + if (!defined('PATH_BASE')) { + define('PATH_BASE', base_path()); + } + if (!defined('PATH_PUBLIC')) { + define('PATH_PUBLIC', public_path()); + } + if (!defined('PATH_STORAGE')) { + define('PATH_STORAGE', storage_path()); + } + if (!defined('PATH_PLUGINS')) { + define('PATH_PLUGINS', base_path() . Config::get('cms.pluginsDir', '/plugins')); + } /* * Register singletons */ - App::singleton('string', function(){ return new \October\Rain\Support\Str; }); - App::singleton('backend.helper', function(){ return new \Backend\Classes\BackendHelper; }); - App::singleton('backend.menu', function() { return \Backend\Classes\NavigationManager::instance(); }); - App::singleton('backend.auth', function() { return \Backend\Classes\AuthManager::instance(); }); + App::singleton('string', function () { + return new \October\Rain\Support\Str; + }); + App::singleton('backend.helper', function () { + return new \Backend\Classes\BackendHelper; + }); + App::singleton('backend.menu', function () { + return \Backend\Classes\NavigationManager::instance(); + }); + App::singleton('backend.auth', function () { + return \Backend\Classes\AuthManager::instance(); + }); /* * Check for CLI or system/updates route and disable any plugin initialization @@ -67,12 +85,14 @@ class ServiceProvider extends ModuleServiceProvider */ $requestPath = \October\Rain\Router\Helper::normalizeUrl(\Request::path()); $systemPath = \October\Rain\Router\Helper::normalizeUrl(Config::get('cms.backendUri') . '/system/updates'); - if (stripos($requestPath, $systemPath) === 0) + if (stripos($requestPath, $systemPath) === 0) { PluginManager::$noInit = true; + } $updateCommands = ['october:up', 'october:update']; - if (App::runningInConsole() && count(array_intersect($updateCommands, Request::server('argv'))) > 0) + if (App::runningInConsole() && count(array_intersect($updateCommands, Request::server('argv'))) > 0) { PluginManager::$noInit = true; + } /* * Register all plugins @@ -83,7 +103,7 @@ class ServiceProvider extends ModuleServiceProvider /* * Error handling for uncaught Exceptions */ - App::error(function(\Exception $exception, $httpCode){ + App::error(function (\Exception $exception, $httpCode) { $handler = new ErrorHandler; return $handler->handleException($exception, $httpCode); }); @@ -91,9 +111,10 @@ class ServiceProvider extends ModuleServiceProvider /* * Write all log events to the database */ - Event::listen('illuminate.log', function($level, $message, $context){ - if (!DbDongle::hasDatabase()) + Event::listen('illuminate.log', function ($level, $message, $context) { + if (!DbDongle::hasDatabase()) { return; + } EventLog::add($message, $level); }); @@ -101,7 +122,7 @@ class ServiceProvider extends ModuleServiceProvider /* * Register basic Twig */ - App::bindShared('twig', function($app) { + App::bindShared('twig', function ($app) { $twig = new Twig_Environment(new TwigLoader(), ['auto_reload' => true]); $twig->addExtension(new TwigExtension); return $twig; @@ -110,14 +131,14 @@ class ServiceProvider extends ModuleServiceProvider /* * Register .htm extension for Twig views */ - App::make('view')->addExtension('htm', 'twig', function() { + App::make('view')->addExtension('htm', 'twig', function () { return new TwigEngine(App::make('twig')); }); /* * Register Twig that will parse strings */ - App::bindShared('twig.string', function($app) { + App::bindShared('twig.string', function ($app) { $twig = $app['twig']; $twig->setLoader(new Twig_Loader_String); return $twig; @@ -126,31 +147,35 @@ class ServiceProvider extends ModuleServiceProvider /* * Override system mailer with mail settings */ - Event::listen('mailer.beforeRegister', function() { - if (MailSettings::isConfigured()) + Event::listen('mailer.beforeRegister', function () { + if (MailSettings::isConfigured()) { MailSettings::applyConfigValues(); + } }); /* * Override standard Mailer content with template */ - Event::listen('mailer.beforeAddContent', function($mailer, $message, $view, $plain, $data){ - if (MailTemplate::addContentToMailer($message, $view, $data)) + Event::listen('mailer.beforeAddContent', function ($mailer, $message, $view, $plain, $data) { + if (MailTemplate::addContentToMailer($message, $view, $data)) { return false; + } }); /* * Register other module providers */ foreach (Config::get('cms.loadModules', []) as $module) { - if (strtolower(trim($module)) == 'system') continue; + if (strtolower(trim($module)) == 'system') { + continue; + } App::register('\\' . $module . '\ServiceProvider'); } /* * Register navigation */ - BackendMenu::registerCallback(function($manager) { + BackendMenu::registerCallback(function ($manager) { $manager->registerMenuItems('October.System', [ 'system' => [ 'label' => 'system::lang.system.menu_label', @@ -165,7 +190,7 @@ class ServiceProvider extends ModuleServiceProvider /* * Register report widgets */ - WidgetManager::instance()->registerReportWidgets(function($manager){ + WidgetManager::instance()->registerReportWidgets(function ($manager) { $manager->registerReportWidget('System\ReportWidgets\Status', [ 'label' => 'backend::lang.dashboard.status.widget_title_default', 'context' => 'dashboard' @@ -175,18 +200,27 @@ class ServiceProvider extends ModuleServiceProvider /* * Register permissions */ - BackendAuth::registerCallback(function($manager) { + BackendAuth::registerCallback(function ($manager) { $manager->registerPermissions('October.System', [ - 'system.manage_settings' => ['label' => 'system::lang.permissions.manage_system_settings', 'tab' => 'System'], - 'system.manage_updates' => ['label' => 'system::lang.permissions.manage_software_updates', 'tab' => 'System'], - 'system.manage_mail_templates' => ['label' => 'system::lang.permissions.manage_mail_templates', 'tab' => 'System'], + 'system.manage_settings' => [ + 'label' => 'system::lang.permissions.manage_system_settings', + 'tab' => 'System' + ], + 'system.manage_updates' => [ + 'label' => 'system::lang.permissions.manage_software_updates', + 'tab' => 'System' + ], + 'system.manage_mail_templates' => [ + 'label' => 'system::lang.permissions.manage_mail_templates', + 'tab' => 'System' + ], ]); }); /* * Register markup tags */ - MarkupManager::instance()->registerCallback(function($manager){ + MarkupManager::instance()->registerCallback(function ($manager) { $manager->registerFunctions([ // Functions 'post' => 'post', @@ -227,7 +261,7 @@ class ServiceProvider extends ModuleServiceProvider /* * Register settings */ - SettingsManager::instance()->registerCallback(function($manager){ + SettingsManager::instance()->registerCallback(function ($manager) { $manager->registerSettingItems('October.System', [ 'administrators' => [ 'label' => 'backend::lang.user.menu_label', @@ -298,14 +332,18 @@ class ServiceProvider extends ModuleServiceProvider /* * Override clear cache command */ - App::bindShared('command.cache.clear', function($app) { + App::bindShared('command.cache.clear', function ($app) { return new \System\Console\CacheClear($app['cache'], $app['files']); }); /* * Register the sidebar for the System main menu */ - BackendMenu::registerContextSidenavPartial('October.System', 'system', '@/modules/system/partials/_system_sidebar.htm'); + BackendMenu::registerContextSidenavPartial( + 'October.System', + 'system', + '@/modules/system/partials/_system_sidebar.htm' + ); } /** diff --git a/modules/system/aliases.php b/modules/system/aliases.php index 539d54398..ebeb29483 100644 --- a/modules/system/aliases.php +++ b/modules/system/aliases.php @@ -54,4 +54,4 @@ return [ 'SystemException' => 'System\Classes\SystemException', 'ApplicationException' => 'System\Classes\ApplicationException', 'ValidationException' => 'October\Rain\Support\ValidationException', -]; \ No newline at end of file +]; diff --git a/modules/system/behaviors/SettingsModel.php b/modules/system/behaviors/SettingsModel.php index c3228c1f1..cf5cee027 100644 --- a/modules/system/behaviors/SettingsModel.php +++ b/modules/system/behaviors/SettingsModel.php @@ -71,8 +71,9 @@ class SettingsModel extends ModelBehavior */ public function instance() { - if (isset(self::$instances[$this->recordCode])) + if (isset(self::$instances[$this->recordCode])) { return self::$instances[$this->recordCode]; + } if (!$item = $this->getSettingsRecord()) { $this->model->initSettingsData(); @@ -127,8 +128,9 @@ class SettingsModel extends ModelBehavior */ public function getSettingsValue($key, $default = null) { - if (array_key_exists($key, $this->fieldValues)) + if (array_key_exists($key, $this->fieldValues)) { return $this->fieldValues[$key]; + } return $default; } @@ -136,7 +138,9 @@ class SettingsModel extends ModelBehavior /** * Default values to set for this model, override */ - public function initSettingsData(){} + public function initSettingsData() + { + } /** * Populate the field values from the database record. @@ -164,8 +168,9 @@ class SettingsModel extends ModelBehavior public function beforeModelSave() { $this->model->item = $this->recordCode; - if ($this->fieldValues) + if ($this->fieldValues) { $this->model->value = $this->fieldValues; + } } /** @@ -182,8 +187,9 @@ class SettingsModel extends ModelBehavior */ public function setModelAttribute($key, $value) { - if ($this->isKeyAllowed($key)) + if ($this->isKeyAllowed($key)) { return; + } $this->fieldValues[$key] = $value; } @@ -197,14 +203,16 @@ class SettingsModel extends ModelBehavior /* * Let the core columns through */ - if ($key == 'id' || $key == 'value' || $key == 'item') + if ($key == 'id' || $key == 'value' || $key == 'item') { return true; + } /* * Let relations through */ - if ($this->model->hasRelation($key)) + if ($this->model->hasRelation($key)) { return true; + } return false; } diff --git a/modules/system/classes/ApplicationException.php b/modules/system/classes/ApplicationException.php index bdfe601c7..ff4f950a7 100644 --- a/modules/system/classes/ApplicationException.php +++ b/modules/system/classes/ApplicationException.php @@ -9,4 +9,4 @@ */ class ApplicationException extends ExceptionBase { -} \ No newline at end of file +} diff --git a/modules/system/classes/Controller.php b/modules/system/classes/Controller.php index a49caa6f9..bbd5d756a 100644 --- a/modules/system/classes/Controller.php +++ b/modules/system/classes/Controller.php @@ -21,19 +21,18 @@ class Controller extends BaseController */ public function combine($name) { - try { - if (!strpos($name, '-')) - throw new ApplicationException(Lang::get('system::lang.combiner.not_found', ['name'=>$name])); - - $parts = explode('-', $name); - $cacheId = $parts[0]; - - $combiner = new CombineAssets; - return $combiner->getContents($cacheId); - } - catch (Exception $ex) { - return '/* '.$ex->getMessage().' */'; - } + try { + if (!strpos($name, '-')) { + throw new ApplicationException(Lang::get('system::lang.combiner.not_found', ['name' => $name])); + } + + $parts = explode('-', $name); + $cacheId = $parts[0]; + + $combiner = new CombineAssets; + return $combiner->getContents($cacheId); + } catch (Exception $ex) { + return '/* '.$ex->getMessage().' */'; + } } - -} \ No newline at end of file +} diff --git a/modules/system/classes/ErrorHandler.php b/modules/system/classes/ErrorHandler.php index 29334ca82..ddc4d0046 100644 --- a/modules/system/classes/ErrorHandler.php +++ b/modules/system/classes/ErrorHandler.php @@ -40,32 +40,34 @@ class ErrorHandler public function handleException(\Exception $proposedException, $httpCode = 500) { // Disable the error handler for test and CLI environment - if (App::runningUnitTests() || App::runningInConsole()) + if (App::runningUnitTests() || App::runningInConsole()) { return; + } // Detect AJAX request and use error 500 - if (Request::ajax()) - return Response::make($proposedException->getMessage(), $httpCode); + if (Request::ajax()) { + return Response::make($proposedException->getMessage(), $httpCode); + } // Clear the output buffer - while (ob_get_level()) + while (ob_get_level()) { ob_end_clean(); + } // Friendly error pages are used - if (Config::get('cms.customErrorPage')) + if (Config::get('cms.customErrorPage')) { return $this->handleCustomError(); + } // If the exception is already our brand, use it. if ($proposedException instanceof BaseException) { $exception = $proposedException; - } // If there is an active mask prepared, use that. - elseif (static::$activeMask !== null) { + } elseif (static::$activeMask !== null) { $exception = static::$activeMask; $exception->setMask($proposedException); - } // Otherwise we should mask it with our own default scent. - else { + } else { $exception = new ApplicationException($proposedException->getMessage(), 0); $exception->setMask($proposedException); } @@ -83,8 +85,9 @@ class ErrorHandler */ public static function applyMask(\Exception $exception) { - if (static::$activeMask !== null) + if (static::$activeMask !== null) { array_push(static::$maskLayers, static::$activeMask); + } static::$activeMask = $exception; } @@ -95,10 +98,11 @@ class ErrorHandler */ public static function removeMask() { - if (count(static::$maskLayers) > 0) + if (count(static::$maskLayers) > 0) { static::$activeMask = array_pop(static::$maskLayers); - else + } else { static::$activeMask = null; + } } /** @@ -112,12 +116,12 @@ class ErrorHandler // Use the default view if no "/error" URL is found. $router = new Router($theme); - if (!$router->findByUrl('/error')) + if (!$router->findByUrl('/error')) { return View::make('cms::error'); + } // Route to the CMS error page. $controller = new Controller($theme); return $controller->run('/error'); } - -} \ No newline at end of file +} diff --git a/modules/system/classes/ExceptionBase.php b/modules/system/classes/ExceptionBase.php index 7112a1923..45a178c72 100644 --- a/modules/system/classes/ExceptionBase.php +++ b/modules/system/classes/ExceptionBase.php @@ -60,7 +60,7 @@ class ExceptionBase extends Exception $this->className = get_called_class(); } - if ($this->errorType === null) { + if ($this->errorType === null) { $this->errorType = 'Undefined'; } @@ -140,8 +140,9 @@ class ExceptionBase extends Exception */ public function getTrueException() { - if ($this->mask !== null) + if ($this->mask !== null) { return $this->mask; + } return $this; } @@ -157,8 +158,9 @@ class ExceptionBase extends Exception */ public function getHighlight() { - if ($this->highlight !== null) + if ($this->highlight !== null) { return $this->highlight; + } if (!$this->fileContent && File::exists($this->file) && is_readable($this->file)) { $this->fileContent = @file($this->file); @@ -167,13 +169,15 @@ class ExceptionBase extends Exception $errorLine = $this->line - 1; $startLine = $errorLine - 6; - if ($startLine < 0) + if ($startLine < 0) { $startLine = 0; + } $endLine = $startLine + 12; $lineNum = count($this->fileContent); - if ($endLine > $lineNum-1) + if ($endLine > $lineNum-1) { $endLine = $lineNum-1; + } $areaLines = array_slice($this->fileContent, $startLine, $endLine - $startLine + 1); @@ -222,8 +226,8 @@ class ExceptionBase extends Exception foreach ($traceInfo as $index => $event) { - $functionName = (isset($event['class']) && strlen($event['class'])) - ? $event['class'].$event['type'].$event['function'] + $functionName = (isset($event['class']) && strlen($event['class'])) + ? $event['class'].$event['type'].$event['function'] : $event['function']; $file = isset($event['file']) ? URL::to(str_replace(public_path(), '', $event['file'])) : null; @@ -261,13 +265,18 @@ class ExceptionBase extends Exception */ $useFilter = false; foreach ($traceInfo as $event) { - if (isset($event['class']) && $event['class'] == 'Illuminate\Exception\Handler' && $event['function'] == 'handleError') { + if ( + isset($event['class']) && + $event['class'] == 'Illuminate\Exception\Handler' && + $event['function'] == 'handleError' + ) { $useFilter = true; } } - if (!$useFilter) + if (!$useFilter) { return $traceInfo; + } $filterResult = []; $pruneResult = true; @@ -275,13 +284,18 @@ class ExceptionBase extends Exception /* * Prune the tail end of the trace from the framework exception handler. */ - if (isset($event['class']) && $event['class'] == 'Illuminate\Exception\Handler' && $event['function'] == 'handleError') { + if ( + isset($event['class']) && + $event['class'] == 'Illuminate\Exception\Handler' && + $event['function'] == 'handleError' + ) { $pruneResult = false; continue; } - if ($pruneResult) + if ($pruneResult) { continue; + } $filterResult[$index] = $event; } @@ -304,42 +318,39 @@ class ExceptionBase extends Exception $items = array(); foreach ($argument as $index => $obj) { - if (is_array($obj)) + if (is_array($obj)) { $value = 'array('.count($obj).')'; - - elseif (is_object($obj)) + } elseif (is_object($obj)) { $value = 'object('.get_class($obj).')'; - - elseif (is_integer($obj)) + } elseif (is_integer($obj)) { $value = $obj; - - elseif ($obj === null) + } elseif ($obj === null) { $value = "null"; - - else + } else { $value = "'".$obj."'"; + } $items[] = $index . ' => ' . $value; } - if (count($items)) + if (count($items)) { $arg = 'array(' . count($argument) . ') [' . implode(', ', $items) . ']'; - else + } else { $arg = 'array(0)'; - } - elseif (is_object($argument)) + } + } elseif (is_object($argument)) { $arg = 'object('.get_class($argument).')'; - elseif ($argument === null) + } elseif ($argument === null) { $arg = "null"; - elseif (is_integer($argument)) + } elseif (is_integer($argument)) { $arg = $argument; - else + } else { $arg = "'".$argument."'"; + } $argsArray[] = $arg; } return implode(', ', $argsArray); } - } diff --git a/modules/system/classes/MarkupManager.php b/modules/system/classes/MarkupManager.php index 37cf11193..01a86e58f 100644 --- a/modules/system/classes/MarkupManager.php +++ b/modules/system/classes/MarkupManager.php @@ -60,12 +60,14 @@ class MarkupManager foreach ($plugins as $id => $plugin) { $items = $plugin->registerMarkupTags(); - if (!is_array($items)) + if (!is_array($items)) { continue; + } foreach ($items as $type => $definitions) { - if (!is_array($definitions)) + if (!is_array($definitions)) { continue; + } $this->registerExtensions($type, $definitions); } @@ -103,23 +105,24 @@ class MarkupManager */ public function registerExtensions($type, array $definitions) { - if (is_null($this->items)) + if (is_null($this->items)) { $this->items = []; + } - if (!array_key_exists($type, $this->items)) + if (!array_key_exists($type, $this->items)) { $this->items[$type] = []; + } foreach ($definitions as $name => $definition) { switch ($type) { case self::EXTENSION_TOKEN_PARSER: $this->items[$type][] = $definition; - break; - + break; case self::EXTENSION_FILTER: case self::EXTENSION_FUNCTION: $this->items[$type][$name] = $definition; - break; + break; } } } @@ -158,11 +161,13 @@ class MarkupManager */ public function listExtensions($type) { - if ($this->items === null) + if ($this->items === null) { $this->loadExtensions(); + } - if (!isset($this->items[$type]) || !is_array($this->items[$type])) + if (!isset($this->items[$type]) || !is_array($this->items[$type])) { return []; + } return $this->items[$type]; } @@ -201,8 +206,9 @@ class MarkupManager */ public function makeTwigFunctions($functions = []) { - if (!is_array($functions)) + if (!is_array($functions)) { $functions = []; + } foreach ($this->listFunctions() as $name => $callable) { @@ -210,15 +216,16 @@ class MarkupManager * Handle a wildcard function */ if (strpos($name, '*') !== false && $this->isWildCallable($callable)) { - $callable = function($name) use ($callable) { + $callable = function ($name) use ($callable) { $arguments = array_slice(func_get_args(), 1); $method = $this->isWildCallable($callable, Str::camel($name)); return call_user_func_array($method, $arguments); }; } - if (!is_callable($callable)) + if (!is_callable($callable)) { throw new ApplicationException(sprintf('The markup function for %s is not callable.', $name)); + } $functions[] = new Twig_SimpleFunction($name, $callable, ['is_safe' => ['html']]); } @@ -233,8 +240,9 @@ class MarkupManager */ public function makeTwigFilters($filters = []) { - if (!is_array($filters)) + if (!is_array($filters)) { $filters = []; + } foreach ($this->listFilters() as $name => $callable) { @@ -242,15 +250,16 @@ class MarkupManager * Handle a wildcard function */ if (strpos($name, '*') !== false && $this->isWildCallable($callable)) { - $callable = function($name) use ($callable) { + $callable = function ($name) use ($callable) { $arguments = array_slice(func_get_args(), 1); $method = $this->isWildCallable($callable, Str::camel($name)); return call_user_func_array($method, $arguments); }; } - if (!is_callable($callable)) + if (!is_callable($callable)) { throw new ApplicationException(sprintf('The markup filter for %s is not callable.', $name)); + } $filters[] = new Twig_SimpleFilter($name, $callable, ['is_safe' => ['html']]); } @@ -265,13 +274,15 @@ class MarkupManager */ public function makeTwigTokenParsers($parsers = []) { - if (!is_array($parsers)) + if (!is_array($parsers)) { $parsers = []; + } $extraParsers = $this->listTokenParsers(); foreach ($extraParsers as $obj) { - if (!$obj instanceof Twig_TokenParser) + if (!$obj instanceof Twig_TokenParser) { continue; + } $parsers[] = $obj; } @@ -290,30 +301,30 @@ class MarkupManager { $isWild = false; - if (is_string($callable) && strpos($callable, '*') !== false) + if (is_string($callable) && strpos($callable, '*') !== false) { $isWild = $replaceWith ? str_replace('*', $replaceWith, $callable) : true; + } if (is_array($callable)) { if (is_string($callable[0]) && strpos($callable[0], '*') !== false) { if ($replaceWith) { $isWild = $callable; $isWild[0] = str_replace('*', $replaceWith, $callable[0]); - } - else + } else { $isWild = true; + } } if (!empty($callable[1]) && strpos($callable[1], '*') !== false) { if ($replaceWith) { $isWild = $isWild ?: $callable; $isWild[1] = str_replace('*', $replaceWith, $callable[1]); - } - else + } else { $isWild = true; + } } } return $isWild; } - -} \ No newline at end of file +} diff --git a/modules/system/classes/ModelBehavior.php b/modules/system/classes/ModelBehavior.php index 73352b21b..2959a0b13 100644 --- a/modules/system/classes/ModelBehavior.php +++ b/modules/system/classes/ModelBehavior.php @@ -39,5 +39,4 @@ class ModelBehavior extends ModelBehaviorBase } } } - -} \ No newline at end of file +} diff --git a/modules/system/classes/PluginBase.php b/modules/system/classes/PluginBase.php index 355ec9c44..a5509104a 100644 --- a/modules/system/classes/PluginBase.php +++ b/modules/system/classes/PluginBase.php @@ -28,12 +28,16 @@ abstract class PluginBase extends ServiceProviderBase /** * Register method, called when the plugin is first registered. */ - public function register() {} + public function register() + { + } /** * Boot method, called right before the request route. */ - public function boot() {} + public function boot() + { + } /** * Registers CMS markup tags introduced by this plugin. @@ -125,10 +129,10 @@ abstract class PluginBase extends ServiceProviderBase public function registerConsoleCommand($key, $class) { $key = 'command.'.$key; - $this->app[$key] = $this->app->share(function($app) use ($class){ + $this->app[$key] = $this->app->share(function ($app) use ($class) { return new $class; }); $this->commands($key); } -} \ No newline at end of file +} diff --git a/modules/system/classes/PluginManager.php b/modules/system/classes/PluginManager.php index 9d5616105..a9545d518 100644 --- a/modules/system/classes/PluginManager.php +++ b/modules/system/classes/PluginManager.php @@ -88,12 +88,14 @@ class PluginManager $pluginClassName = $className.'\Plugin'; // Autoloader failed? - if (!class_exists($pluginClassName)) + if (!class_exists($pluginClassName)) { include_once $classPath.'/Plugin.php'; + } // Not a valid plugin! - if (!class_exists($pluginClassName)) + if (!class_exists($pluginClassName)) { continue; + } $classObj = new $pluginClassName($this->app); $classId = $this->getIdentifier($classObj); @@ -101,8 +103,9 @@ class PluginManager /* * Check for disabled plugins */ - if ($this->isDisabled($classId)) + if ($this->isDisabled($classId)) { $classObj->disabled = true; + } $this->plugins[$classId] = $classObj; $this->pathMap[$classId] = $classPath; @@ -116,15 +119,18 @@ class PluginManager */ public function registerAll() { - if ($this->registered) + if ($this->registered) { return; + } foreach ($this->plugins as $pluginId => $plugin) { - if ($plugin->disabled) + if ($plugin->disabled) { continue; + } - if (!self::$noInit) + if (!self::$noInit) { $plugin->register(); + } $pluginPath = $this->getPluginPath($plugin); $pluginNamespace = strtolower($pluginId); @@ -133,36 +139,41 @@ class PluginManager * Register plugin class autoloaders */ $autoloadPath = $pluginPath . '/vendor/autoload.php'; - if (File::isFile($autoloadPath)) + if (File::isFile($autoloadPath)) { require_once $autoloadPath; + } /* * Register language namespaces */ $langPath = $pluginPath . '/lang'; - if (File::isDirectory($langPath)) + if (File::isDirectory($langPath)) { Lang::addNamespace($pluginNamespace, $langPath); + } /* * Register configuration path */ $configPath = $pluginPath . '/config'; - if (File::isDirectory($configPath)) + if (File::isDirectory($configPath)) { Config::package($pluginNamespace, $configPath, $pluginNamespace); + } /* * Register views path */ $viewsPath = $pluginPath . '/views'; - if (File::isDirectory($viewsPath)) + if (File::isDirectory($viewsPath)) { View::addNamespace($pluginNamespace, $viewsPath); + } /* * Add routes, if available */ $routesFile = $pluginPath . '/routes.php'; - if (File::exists($routesFile)) + if (File::exists($routesFile)) { require $routesFile; + } } $this->registered = true; @@ -173,15 +184,18 @@ class PluginManager */ public function bootAll() { - if ($this->booted) + if ($this->booted) { return; + } foreach ($this->plugins as $plugin) { - if ($plugin->disabled) + if ($plugin->disabled) { continue; + } - if (!self::$noInit) + if (!self::$noInit) { $plugin->boot(); + } } $this->booted = true; @@ -202,8 +216,9 @@ class PluginManager public function getPluginPath($id) { $classId = $this->getIdentifier($id); - if (!isset($this->pathMap[$classId])) + if (!isset($this->pathMap[$classId])) { return null; + } return $this->pathMap[$classId]; } @@ -234,8 +249,9 @@ class PluginManager */ public function findByNamespace($namespace) { - if (!$this->hasPlugin($namespace)) + if (!$this->hasPlugin($namespace)) { return null; + } $classId = $this->getIdentifier($namespace); return $this->plugins[$classId]; @@ -246,11 +262,13 @@ class PluginManager */ public function findByIdentifier($identifier) { - if (!isset($this->plugins[$identifier])) + if (!isset($this->plugins[$identifier])) { $identifier = $this->normalizeIdentifier($identifier); + } - if (!isset($this->plugins[$identifier])) + if (!isset($this->plugins[$identifier])) { return null; + } return $this->plugins[$identifier]; } @@ -290,8 +308,9 @@ class PluginManager $plugins = []; $dirPath = $this->getPath(); - if (!File::isDirectory($dirPath)) + if (!File::isDirectory($dirPath)) { return $plugins; + } $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirPath)); $it->setMaxDepth(2); @@ -319,8 +338,9 @@ class PluginManager public function getIdentifier($namespace) { $namespace = Str::normalizeClassName($namespace); - if (strpos($namespace, '\\') === null) + if (strpos($namespace, '\\') === null) { return $namespace; + } $parts = explode('\\', $namespace); $slice = array_slice($parts, 1, 2); @@ -336,8 +356,9 @@ class PluginManager public function normalizeIdentifier($identifier) { foreach ($this->plugins as $id => $object) { - if (strtolower($id) == strtolower($identifier)) + if (strtolower($id) == strtolower($identifier)) { return $id; + } } return $identifier; @@ -361,15 +382,15 @@ class PluginManager $path = $this->metaPath.'/disabled.json'; if (($configDisabled = Config::get('cms.disablePlugins')) && is_array($configDisabled)) { - foreach ($configDisabled as $disabled) + foreach ($configDisabled as $disabled) { $this->disabledPlugins[$disabled] = true; + } } if (File::exists($path)) { $disabled = json_decode(File::get($path), true); $this->disabledPlugins = array_merge($this->disabledPlugins, $disabled); - } - else { + } else { $this->writeDisabled(); } } @@ -382,8 +403,9 @@ class PluginManager public function isDisabled($id) { $code = $this->getIdentifier($id); - if (array_key_exists($code, $this->disabledPlugins)) + if (array_key_exists($code, $this->disabledPlugins)) { return true; + } } /** @@ -403,14 +425,16 @@ class PluginManager public function disablePlugin($id, $isUser = false) { $code = $this->getIdentifier($id); - if (array_key_exists($code, $this->disabledPlugins)) + if (array_key_exists($code, $this->disabledPlugins)) { return false; + } $this->disabledPlugins[$code] = $isUser; $this->writeDisabled(); - if ($pluginObj = $this->findByIdentifier($code)) + if ($pluginObj = $this->findByIdentifier($code)) { $pluginObj->disabled = true; + } return true; } @@ -423,18 +447,21 @@ class PluginManager public function enablePlugin($id, $isUser = false) { $code = $this->getIdentifier($id); - if (!array_key_exists($code, $this->disabledPlugins)) + if (!array_key_exists($code, $this->disabledPlugins)) { return false; + } // Prevent system from enabling plugins disabled by the user - if (!$isUser && $this->disabledPlugins[$code] === true) + if (!$isUser && $this->disabledPlugins[$code] === true) { return false; + } unset($this->disabledPlugins[$code]); $this->writeDisabled(); - if ($pluginObj = $this->findByIdentifier($code)) + if ($pluginObj = $this->findByIdentifier($code)) { $pluginObj->disabled = false; + } return true; } @@ -450,22 +477,24 @@ class PluginManager protected function loadDependencies() { foreach ($this->plugins as $id => $plugin) { - if (!$required = $this->getDependencies($plugin)) + if (!$required = $this->getDependencies($plugin)) { continue; + } $disable = false; foreach ($required as $require) { - if (!$this->hasPlugin($require)) + if (!$this->hasPlugin($require)) { $disable = true; - - elseif (($pluginObj = $this->findByIdentifier($require)) && $pluginObj->disabled) + } elseif (($pluginObj = $this->findByIdentifier($require)) && $pluginObj->disabled) { $disable = true; + } } - if ($disable) + if ($disable) { $this->disablePlugin($id); - else + } else { $this->enablePlugin($id); + } } } @@ -476,11 +505,13 @@ class PluginManager */ public function getDependencies($plugin) { - if (is_string($plugin) && (!$plugin = $this->findByIdentifier($identifer))) + if (is_string($plugin) && (!$plugin = $this->findByIdentifier($identifer))) { return false; + } - if (!isset($plugin->require) || !$plugin->require) + if (!isset($plugin->require) || !$plugin->require) { return null; + } return is_array($plugin->require) ? $plugin->require : [$plugin->require]; } @@ -493,8 +524,9 @@ class PluginManager */ public function sortByDependencies($plugins = null) { - if (!is_array($plugins)) + if (!is_array($plugins)) { $plugins = $this->getPlugins(); + } $result = []; $checklist = $plugins; @@ -502,8 +534,9 @@ class PluginManager $loopCount = 0; while (count($checklist)) { - if (++$loopCount > 999) + if (++$loopCount > 999) { throw new ApplicationException('Too much recursion'); + } foreach ($checklist as $code => $plugin) { @@ -511,7 +544,7 @@ class PluginManager * Get dependencies and remove any aliens */ $depends = $this->getDependencies($plugin) ?: []; - $depends = array_filter($depends, function($pluginCode) use ($plugins) { + $depends = array_filter($depends, function ($pluginCode) use ($plugins) { return isset($plugins[$pluginCode]); }); @@ -528,8 +561,9 @@ class PluginManager * Find dependencies that have not been checked */ $depends = array_diff($depends, $result); - if (count($depends) > 0) + if (count($depends) > 0) { continue; + } /* * All dependencies are checked @@ -542,5 +576,4 @@ class PluginManager return $result; } - -} \ No newline at end of file +} diff --git a/modules/system/classes/SettingsManager.php b/modules/system/classes/SettingsManager.php index d8517c7d8..df880ccea 100644 --- a/modules/system/classes/SettingsManager.php +++ b/modules/system/classes/SettingsManager.php @@ -99,8 +99,9 @@ class SettingsManager foreach ($plugins as $id => $plugin) { $items = $plugin->registerSettings(); - if (!is_array($items)) + if (!is_array($items)) { continue; + } $this->registerSettingItems($id, $items); } @@ -108,7 +109,7 @@ class SettingsManager /* * Sort settings items */ - usort($this->items, function($a, $b) { + usort($this->items, function ($a, $b) { return $a->order - $b->order; }); @@ -122,11 +123,11 @@ class SettingsManager * Process each item in to a category array */ $catItems = []; - foreach ($this->items as $item) - { + foreach ($this->items as $item) { $category = $item->category ?: 'Misc'; - if (!isset($catItems[$category])) + if (!isset($catItems[$category])) { $catItems[$category] = []; + } $catItems[$category][] = $item; } @@ -140,11 +141,13 @@ class SettingsManager */ public function listItems($context = null) { - if ($this->items === null) + if ($this->items === null) { $this->loadItems(); + } - if ($context !== null) + if ($context !== null) { return $this->filterByContext($this->items, $context); + } return $this->items; } @@ -163,12 +166,14 @@ class SettingsManager $filteredCategory = []; foreach ($category as $item) { $itemContext = is_array($item->context) ? $item->context : [$item->context]; - if (in_array($context, $itemContext)) + if (in_array($context, $itemContext)) { $filteredCategory[] = $item; + } } - if (count($filteredCategory)) + if (count($filteredCategory)) { $filteredItems[$categoryName] = $filteredCategory; + } } return $filteredItems; @@ -209,8 +214,9 @@ class SettingsManager */ public function registerSettingItems($owner, array $definitions) { - if (!$this->items) + if (!$this->items) { $this->items = []; + } foreach ($definitions as $code => $definition) { $item = array_merge(self::$itemDefaults, array_merge($definition, [ @@ -228,9 +234,9 @@ class SettingsManager list($author, $plugin) = explode('.', $owner); $uri[] = strtolower($author); $uri[] = strtolower($plugin); - } - else + } else { $uri[] = strtolower($owner); + } $uri[] = strtolower($code); $uri = implode('/', $uri); @@ -264,7 +270,7 @@ class SettingsManager { return (object)[ 'itemCode' => $this->contextItemCode, - 'owner' => $this->contextOwner + 'owner' => $this->contextOwner ]; } @@ -276,15 +282,17 @@ class SettingsManager */ public function findSettingItem($owner, $code) { - if ($this->allItems === null) + if ($this->allItems === null) { $this->loadItems(); + } $owner = strtolower($owner); $code = strtolower($code); foreach ($this->allItems as $item) { - if (strtolower($item->owner) == $owner && strtolower($item->code) == $code) + if (strtolower($item->owner) == $owner && strtolower($item->code) == $code) { return $item; + } } return false; @@ -298,13 +306,14 @@ class SettingsManager */ protected function filterItemPermissions($user, array $items) { - array_filter($items, function($item) use ($user) { - if (!$item->permissions || !count($item->permissions)) + array_filter($items, function ($item) use ($user) { + if (!$item->permissions || !count($item->permissions)) { return true; + } return $user->hasAnyAccess($item->permissions); }); return $items; } -} \ No newline at end of file +} diff --git a/modules/system/classes/SystemException.php b/modules/system/classes/SystemException.php index 1a94ac72d..cad2361cd 100644 --- a/modules/system/classes/SystemException.php +++ b/modules/system/classes/SystemException.php @@ -16,4 +16,4 @@ class SystemException extends ExceptionBase parent::__construct($message, $code, $previous); Log::error($this); } -} \ No newline at end of file +} diff --git a/modules/system/classes/UpdateManager.php b/modules/system/classes/UpdateManager.php index 7ac9dc4ab..0c8fd3761 100644 --- a/modules/system/classes/UpdateManager.php +++ b/modules/system/classes/UpdateManager.php @@ -78,8 +78,9 @@ class UpdateManager /* * Ensure temp directory exists */ - if (!File::isDirectory($this->tempDirectory)) + if (!File::isDirectory($this->tempDirectory)) { File::makeDirectory($this->tempDirectory, 0777, true); + } } /** @@ -98,8 +99,9 @@ class UpdateManager * Update modules */ $modules = Config::get('cms.loadModules', []); - foreach ($modules as $module) + foreach ($modules as $module) { $this->migrateModule($module); + } /* * Update plugins @@ -117,8 +119,9 @@ class UpdateManager */ if ($firstUp) { $modules = Config::get('cms.loadModules', []); - foreach ($modules as $module) + foreach ($modules as $module) { $this->seedModule($module); + } } return $this; @@ -136,22 +139,23 @@ class UpdateManager * Already know about updates, never retry. */ $oldCount = Parameters::get('system::update.count'); - if ($oldCount > 0) + if ($oldCount > 0) { return $oldCount; + } /* * Retry period not passed, skipping. */ if (!$force && ($retryTimestamp = Parameters::get('system::update.retry'))) { - if (Carbon::createFromTimeStamp($retryTimestamp)->isFuture()) + if (Carbon::createFromTimeStamp($retryTimestamp)->isFuture()) { return $oldCount; + } } try { $result = $this->requestUpdateList(); $newCount = array_get($result, 'update', 0); - } - catch (Exception $ex) { + } catch (Exception $ex) { $newCount = 0; } @@ -211,8 +215,9 @@ class UpdateManager */ $themes = []; foreach (array_get($result, 'themes', []) as $code => $info) { - if (!$this->isThemeInstalled($code)) + if (!$this->isThemeInstalled($code)) { $themes[$code] = $info; + } } $result['themes'] = $themes; @@ -265,7 +270,9 @@ class UpdateManager $this->note($note); } - if ($count == 0) break; + if ($count == 0) { + break; + } } Schema::dropIfExists('migrations'); @@ -310,8 +317,9 @@ class UpdateManager public function seedModule($module) { $className = '\\'.$module.'\Database\Seeds\DatabaseSeeder'; - if (!class_exists($className)) + if (!class_exists($className)) { return; + } $seeder = App::make($className); $seeder->run(); @@ -340,8 +348,9 @@ class UpdateManager { $filePath = $this->getFilePath('core'); - if (!Zip::extract($filePath, $this->baseDirectory)) + if (!Zip::extract($filePath, $this->baseDirectory)) { throw new ApplicationException(Lang::get('system::lang.zip.extract_failed', ['file' => $filePath])); + } @unlink($filePath); @@ -437,8 +446,9 @@ class UpdateManager $fileCode = $name . $hash; $filePath = $this->getFilePath($fileCode); - if (!Zip::extract($filePath, $this->baseDirectory . '/plugins/')) + if (!Zip::extract($filePath, $this->baseDirectory . '/plugins/')) { throw new ApplicationException(Lang::get('system::lang.zip.extract_failed', ['file' => $filePath])); + } @unlink($filePath); } @@ -467,8 +477,9 @@ class UpdateManager $fileCode = $name . $hash; $filePath = $this->getFilePath($fileCode); - if (!Zip::extract($filePath, $this->baseDirectory . '/themes/')) + if (!Zip::extract($filePath, $this->baseDirectory . '/themes/')) { throw new ApplicationException(Lang::get('system::lang.zip.extract_failed', ['file' => $filePath])); + } $this->setThemeInstalled($name); @unlink($filePath); @@ -541,12 +552,13 @@ class UpdateManager */ public function requestServerData($uri, $postData = []) { - $result = Http::post($this->createServerUrl($uri), function($http) use ($postData) { + $result = Http::post($this->createServerUrl($uri), function ($http) use ($postData) { $this->applyHttpAttributes($http, $postData); }); - if ($result->code == 404) + if ($result->code == 404) { throw new ApplicationException(Lang::get('system::lang.server.response_not_found')); + } if ($result->code != 200) { throw new ApplicationException( @@ -560,13 +572,13 @@ class UpdateManager try { $resultData = @json_decode($result->body, true); - } - catch (Exception $ex) { + } catch (Exception $ex) { throw new ApplicationException(Lang::get('system::lang.server.response_invalid')); } - if ($resultData === false || (is_string($resultData) && !strlen($resultData))) + if ($resultData === false || (is_string($resultData) && !strlen($resultData))) { throw new ApplicationException(Lang::get('system::lang.server.response_invalid')); + } return $resultData; } @@ -587,13 +599,14 @@ class UpdateManager $postData['project'] = $projectId; } - $result = Http::post($this->createServerUrl($uri), function($http) use ($postData, $filePath) { + $result = Http::post($this->createServerUrl($uri), function ($http) use ($postData, $filePath) { $this->applyHttpAttributes($http, $postData); $http->toFile($filePath); }); - if ($result->code != 200) + if ($result->code != 200) { throw new ApplicationException(File::get($filePath)); + } if (md5_file($filePath) != $expectedHash) { @unlink($filePath); @@ -631,8 +644,9 @@ class UpdateManager protected function createServerUrl($uri) { $gateway = Config::get('cms.updateServer', 'http://octobercms.com/api'); - if (substr($gateway, -1) != '/') + if (substr($gateway, -1) != '/') { $gateway .= '/'; + } return $gateway . $uri; } @@ -653,8 +667,9 @@ class UpdateManager $http->header('Rest-Sign', $this->createSignature($postData, $this->secret)); } - if ($credentials = Config::get('cms.updateAuth')) + if ($credentials = Config::get('cms.updateAuth')) { $http->auth($credentials); + } $http->noRedirect(); $http->data($postData); @@ -678,5 +693,4 @@ class UpdateManager { return base64_encode(hash_hmac('sha512', http_build_query($data, '', '&'), base64_decode($secret), true)); } - } diff --git a/modules/system/classes/VersionManager.php b/modules/system/classes/VersionManager.php index 1a0d6c641..962c42a9f 100644 --- a/modules/system/classes/VersionManager.php +++ b/modules/system/classes/VersionManager.php @@ -74,8 +74,9 @@ class VersionManager { $code = (is_string($plugin)) ? $plugin : $this->pluginManager->getIdentifier($plugin); - if (!$this->hasVersionFile($code)) + if (!$this->hasVersionFile($code)) { return false; + } $currentVersion = $this->getLatestFileVersion($code); $databaseVersion = $this->getDatabaseVersion($code); @@ -102,8 +103,7 @@ class VersionManager if (is_array($details)) { $comment = array_shift($details); $scripts = $details; - } - else { + } else { $comment = $details; $scripts = []; } @@ -112,8 +112,9 @@ class VersionManager * Apply scripts, if any */ foreach ($scripts as $script) { - if ($this->hasDatabaseHistory($code, $version, $script)) + if ($this->hasDatabaseHistory($code, $version, $script)) { continue; + } $this->applyDatabaseScript($code, $version, $script); } @@ -121,8 +122,9 @@ class VersionManager /* * Register the comment and update the version */ - if (!$this->hasDatabaseHistory($code, $version)) + if (!$this->hasDatabaseHistory($code, $version)) { $this->applyDatabaseComment($code, $version, $comment); + } $this->setDatabaseVersion($code, $version); @@ -136,24 +138,32 @@ class VersionManager { $code = (is_string($plugin)) ? $plugin : $this->pluginManager->getIdentifier($plugin); - if (!$this->hasVersionFile($code)) + if (!$this->hasVersionFile($code)) { return false; + } $pluginHistory = $this->getDatabaseHistory($code); $pluginHistory = array_reverse($pluginHistory); foreach ($pluginHistory as $history) { - if ($history->type == self::HISTORY_TYPE_COMMENT) + if ($history->type == self::HISTORY_TYPE_COMMENT) { $this->removeDatabaseComment($code, $history->version); - elseif ($history->type == self::HISTORY_TYPE_SCRIPT) + } elseif ($history->type == self::HISTORY_TYPE_SCRIPT) { $this->removeDatabaseScript($code, $history->version, $history->detail); + } } $this->setDatabaseVersion($code); - if (isset($this->fileVersions[$code])) unset($this->fileVersions[$code]); - if (isset($this->databaseVersions[$code])) unset($this->databaseVersions[$code]); - if (isset($this->databaseHistory[$code])) unset($this->databaseHistory[$code]); + if (isset($this->fileVersions[$code])) { + unset($this->fileVersions[$code]); + } + if (isset($this->databaseVersions[$code])) { + unset($this->databaseVersions[$code]); + } + if (isset($this->databaseHistory[$code])) { + unset($this->databaseHistory[$code]); + } return true; } @@ -165,12 +175,14 @@ class VersionManager public function purgePlugin($pluginCode) { $versions = Db::table('system_plugin_versions')->where('code', $pluginCode); - if ($countVersions = $versions->count()) + if ($countVersions = $versions->count()) { $versions->delete(); + } $history = Db::table('system_plugin_history')->where('code', $pluginCode); - if ($countHistory = $history->count()) + if ($countHistory = $history->count()) { $history->delete(); + } return (($countHistory + $countVersions) > 0) ? true : false; } @@ -185,10 +197,11 @@ class VersionManager protected function getLatestFileVersion($code) { $versionInfo = $this->getFileVersions($code); - if (!$versionInfo) + if (!$versionInfo) { return self::NO_VERSION_VALUE; + } - $latest = trim(key(array_slice($versionInfo, -1 , 1))); + $latest = trim(key(array_slice($versionInfo, -1, 1))); return $latest; } @@ -197,8 +210,9 @@ class VersionManager */ protected function getNewFileVersions($code, $version = null) { - if ($version === null) + if ($version === null) { $version = self::NO_VERSION_VALUE; + } $versions = $this->getFileVersions($code); $position = array_search($version, array_keys($versions)); @@ -210,14 +224,15 @@ class VersionManager */ protected function getFileVersions($code) { - if ($this->fileVersions !== null && array_key_exists($code, $this->fileVersions)) + if ($this->fileVersions !== null && array_key_exists($code, $this->fileVersions)) { return $this->fileVersions[$code]; + } $versionFile = $this->getVersionFile($code); $versionInfo = Yaml::parseFile($versionFile); if ($versionInfo) { - uksort($versionInfo, function($a, $b){ + uksort($versionInfo, function ($a, $b) { return version_compare($a, $b); }); } @@ -257,7 +272,10 @@ class VersionManager } if (!isset($this->databaseVersions[$code])) { - $this->databaseVersions[$code] = Db::table('system_plugin_versions')->where('code', $code)->pluck('version'); + $this->databaseVersions[$code] = Db::table('system_plugin_versions') + ->where('code', $code) + ->pluck('version') + ; } return (isset($this->databaseVersions[$code])) @@ -278,14 +296,12 @@ class VersionManager 'version' => $version, 'created_at' => new Carbon ]); - } - elseif ($version && $currentVersion){ + } elseif ($version && $currentVersion) { Db::table('system_plugin_versions')->where('code', $code)->update([ 'version' => $version, 'created_at' => new Carbon ]); - } - elseif ($currentVersion) { + } elseif ($currentVersion) { Db::table('system_plugin_versions')->where('code', $code)->delete(); } @@ -362,8 +378,9 @@ class VersionManager */ protected function getDatabaseHistory($code) { - if ($this->databaseHistory !== null && array_key_exists($code, $this->databaseHistory)) + if ($this->databaseHistory !== null && array_key_exists($code, $this->databaseHistory)) { return $this->databaseHistory[$code]; + } $historyInfo = Db::table('system_plugin_history')->where('code', $code)->get(); return $this->databaseHistory[$code] = $historyInfo; @@ -375,18 +392,22 @@ class VersionManager protected function hasDatabaseHistory($code, $version, $script = null) { $historyInfo = $this->getDatabaseHistory($code); - if (!$historyInfo) + if (!$historyInfo) { return false; + } foreach ($historyInfo as $history) { - if ($history->version != $version) + if ($history->version != $version) { continue; + } - if ($history->type == self::HISTORY_TYPE_COMMENT && !$script) + if ($history->type == self::HISTORY_TYPE_COMMENT && !$script) { return true; + } - if ($history->type == self::HISTORY_TYPE_SCRIPT && $history->detail == $script) + if ($history->type == self::HISTORY_TYPE_SCRIPT && $history->detail == $script) { return true; + } } return false; @@ -425,4 +446,4 @@ class VersionManager $this->notes = []; return $this; } -} \ No newline at end of file +} diff --git a/modules/system/console/CacheClear.php b/modules/system/console/CacheClear.php index 3676f6512..995e986be 100644 --- a/modules/system/console/CacheClear.php +++ b/modules/system/console/CacheClear.php @@ -55,8 +55,8 @@ class CacheClear extends ClearCommand $command = App::make('System\Console\CacheClear'); $command->setLaravel(App::make('app')); $command->fire(); + } catch (\Exception $ex) { + } - catch (\Exception $ex) {} } - -} \ No newline at end of file +} diff --git a/modules/system/console/OctoberDown.php b/modules/system/console/OctoberDown.php index 0c0185975..253f2db35 100644 --- a/modules/system/console/OctoberDown.php +++ b/modules/system/console/OctoberDown.php @@ -33,13 +33,15 @@ class OctoberDown extends Command */ public function fire() { - if (!$this->confirmToProceed('This will DESTROY all database tables.')) + if (!$this->confirmToProceed('This will DESTROY all database tables.')) { return; + } $manager = UpdateManager::instance()->resetNotes()->uninstall(); - foreach ($manager->getNotes() as $note) + foreach ($manager->getNotes() as $note) { $this->output->writeln($note); + } } /** @@ -66,7 +68,8 @@ class OctoberDown extends Command */ protected function getDefaultConfirmCallback() { - return function() { return true; }; + return function () { + return true; + }; } - -} \ No newline at end of file +} diff --git a/modules/system/console/OctoberUp.php b/modules/system/console/OctoberUp.php index 9a12da19a..228a0fcb6 100644 --- a/modules/system/console/OctoberUp.php +++ b/modules/system/console/OctoberUp.php @@ -35,8 +35,9 @@ class OctoberUp extends Command $this->output->writeln('Migrating application and plugins...'); - foreach ($manager->getNotes() as $note) + foreach ($manager->getNotes() as $note) { $this->output->writeln($note); + } } /** @@ -54,5 +55,4 @@ class OctoberUp extends Command { return []; } - -} \ No newline at end of file +} diff --git a/modules/system/console/OctoberUpdate.php b/modules/system/console/OctoberUpdate.php index 8d95e71ef..d2a3883d1 100644 --- a/modules/system/console/OctoberUpdate.php +++ b/modules/system/console/OctoberUpdate.php @@ -65,8 +65,7 @@ class OctoberUpdate extends Command if ($updates == 0) { $this->output->writeln('No new updates found'); return; - } - else { + } else { $this->output->writeln(sprintf('Found %s new %s!', $updates, Str::plural('update', $updates))); } @@ -125,5 +124,4 @@ class OctoberUpdate extends Command ['plugins', null, InputOption::VALUE_NONE, 'Update plugin files only.'], ]; } - } diff --git a/modules/system/console/OctoberUtil.php b/modules/system/console/OctoberUtil.php index 4a09bb911..9854c02f4 100644 --- a/modules/system/console/OctoberUtil.php +++ b/modules/system/console/OctoberUtil.php @@ -79,11 +79,13 @@ class OctoberUtil extends Command protected function utilPurgeThumbs() { - if (!$uploadsDir = Config::get('cms.uploadsDir')) + if (!$uploadsDir = Config::get('cms.uploadsDir')) { return $this->error('No uploads directory defined in config (cms.uploadsDir)'); + } - if (!$this->confirmToProceed('This will PERMANENTLY DELETE all thumbs in the uploads directory.')) + if (!$this->confirmToProceed('This will PERMANENTLY DELETE all thumbs in the uploads directory.')) { return; + } $uploadsDir = base_path() . $uploadsDir; $totalCount = 0; @@ -92,7 +94,7 @@ class OctoberUtil extends Command * Recursive function to scan the directory for files beginning * with "thumb_" and repeat itself on directories. */ - $purgeFunc = function($targetDir) use (&$purgeFunc, &$totalCount) { + $purgeFunc = function ($targetDir) use (&$purgeFunc, &$totalCount) { if ($files = File::glob($targetDir.'/thumb_*')) { foreach ($files as $file) { $this->info('Purged: '. basename($file)); @@ -110,10 +112,10 @@ class OctoberUtil extends Command $purgeFunc($uploadsDir); - if ($totalCount > 0) + if ($totalCount > 0) { $this->comment(sprintf('Successfully deleted %s thumbs', $totalCount)); - else + } else { $this->comment('No thumbs found to delete'); + } } - -} \ No newline at end of file +} diff --git a/modules/system/console/PluginInstall.php b/modules/system/console/PluginInstall.php index ce59f4f6d..9538d1140 100644 --- a/modules/system/console/PluginInstall.php +++ b/modules/system/console/PluginInstall.php @@ -57,8 +57,9 @@ class PluginInstall extends Command PluginManager::instance()->loadPlugins(); $manager->updatePlugin($code); - foreach ($manager->getNotes() as $note) + foreach ($manager->getNotes() as $note) { $this->output->writeln($note); + } } /** @@ -80,5 +81,4 @@ class PluginInstall extends Command { return []; } - -} \ No newline at end of file +} diff --git a/modules/system/console/PluginRefresh.php b/modules/system/console/PluginRefresh.php index 9f7e2c899..45be43384 100644 --- a/modules/system/console/PluginRefresh.php +++ b/modules/system/console/PluginRefresh.php @@ -42,15 +42,17 @@ class PluginRefresh extends Command $manager = UpdateManager::instance()->resetNotes(); $manager->rollbackPlugin($pluginName); - foreach ($manager->getNotes() as $note) + foreach ($manager->getNotes() as $note) { $this->output->writeln($note); + } $manager->resetNotes(); $this->output->writeln('Reinstalling plugin...'); $manager->updatePlugin($pluginName); - foreach ($manager->getNotes() as $note) + foreach ($manager->getNotes() as $note) { $this->output->writeln($note); + } } /** @@ -72,5 +74,4 @@ class PluginRefresh extends Command { return []; } - -} \ No newline at end of file +} diff --git a/modules/system/console/PluginRemove.php b/modules/system/console/PluginRemove.php index cae780827..fbf95307f 100644 --- a/modules/system/console/PluginRemove.php +++ b/modules/system/console/PluginRemove.php @@ -43,11 +43,13 @@ class PluginRemove extends Command $pluginName = $this->argument('name'); $pluginName = $pluginManager->normalizeIdentifier($pluginName); - if (!$pluginManager->hasPlugin($pluginName)) + if (!$pluginManager->hasPlugin($pluginName)) { return $this->error(sprintf('Unable to find a registered plugin called "%s"', $pluginName)); + } - if (!$this->confirmToProceed(sprintf('This will DELETE "%s" from the filesystem and database.', $pluginName))) + if (!$this->confirmToProceed(sprintf('This will DELETE "%s" from the filesystem and database.', $pluginName))) { return; + } /* * Rollback plugin @@ -55,8 +57,9 @@ class PluginRemove extends Command $manager = UpdateManager::instance()->resetNotes(); $manager->rollbackPlugin($pluginName); - foreach ($manager->getNotes() as $note) + foreach ($manager->getNotes() as $note) { $this->output->writeln($note); + } /* * Delete from file system @@ -95,7 +98,8 @@ class PluginRemove extends Command */ protected function getDefaultConfirmCallback() { - return function() { return true; }; + return function () { + return true; + }; } - -} \ No newline at end of file +} diff --git a/modules/system/controllers/EventLogs.php b/modules/system/controllers/EventLogs.php index 8e30a8e8d..bc50755cd 100644 --- a/modules/system/controllers/EventLogs.php +++ b/modules/system/controllers/EventLogs.php @@ -48,5 +48,4 @@ class EventLogs extends Controller Flash::success(Lang::get('system::lang.event_log.empty_success')); return $this->listRefresh(); } - -} \ No newline at end of file +} diff --git a/modules/system/controllers/MailLayouts.php b/modules/system/controllers/MailLayouts.php index 572f0f43d..17885ce76 100644 --- a/modules/system/controllers/MailLayouts.php +++ b/modules/system/controllers/MailLayouts.php @@ -37,5 +37,4 @@ class MailLayouts extends Controller BackendMenu::setContext('October.System', 'system', 'settings'); SettingsManager::setContext('October.System', 'mail_templates'); } - -} \ No newline at end of file +} diff --git a/modules/system/controllers/MailTemplates.php b/modules/system/controllers/MailTemplates.php index 4b8b5a04f..0ff8d5281 100644 --- a/modules/system/controllers/MailTemplates.php +++ b/modules/system/controllers/MailTemplates.php @@ -45,7 +45,11 @@ class MailTemplates extends Controller public function index() { - /* @todo Remove line if year >= 2015 */ if (!\System\Models\MailLayout::whereCode('default')->count()) { \Eloquent::unguard(); with(new \System\Database\Seeds\SeedSetupMailLayouts)->run(); } + /* @todo Remove lines if year >= 2015 */ + if (!\System\Models\MailLayout::whereCode('default')->count()) { + \Eloquent::unguard(); + with(new \System\Database\Seeds\SeedSetupMailLayouts)->run(); + } MailTemplate::syncAll(); $this->asExtension('ListController')->index(); @@ -67,16 +71,14 @@ class MailTemplates extends Controller 'email' => $user->email, 'name' => $user->full_name, ]; - Mail::send($model->code, [], function($message) use ($vars) { + Mail::send($model->code, [], function ($message) use ($vars) { extract($vars); $message->to($email, $name); }); Flash::success('The test message has been successfully sent.'); - } - catch (Exception $ex) { + } catch (Exception $ex) { Flash::error($ex->getMessage()); } } - -} \ No newline at end of file +} diff --git a/modules/system/controllers/RequestLogs.php b/modules/system/controllers/RequestLogs.php index 6c461e2e5..23b4f4f18 100644 --- a/modules/system/controllers/RequestLogs.php +++ b/modules/system/controllers/RequestLogs.php @@ -48,5 +48,4 @@ class RequestLogs extends Controller Flash::success(Lang::get('system::lang.request_log.empty_success')); return $this->listRefresh(); } - -} \ No newline at end of file +} diff --git a/modules/system/controllers/Settings.php b/modules/system/controllers/Settings.php index 0e5e98601..56777beb4 100644 --- a/modules/system/controllers/Settings.php +++ b/modules/system/controllers/Settings.php @@ -62,8 +62,9 @@ class Settings extends Controller $this->vars['parentLabel'] = Lang::get('system::lang.settings.menu_label'); try { - if (!$item = $this->findSettingItem($author, $plugin, $code)) + if (!$item = $this->findSettingItem($author, $plugin, $code)) { throw new ApplicationException(Lang::get('system::lang.settings.not_found')); + } $this->pageTitle = $item->label; @@ -74,8 +75,7 @@ class Settings extends Controller $model = $this->createModel($item); $this->initWidgets($model); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->handleError($ex); } } @@ -111,8 +111,9 @@ class Settings extends Controller */ public function formRender($options = []) { - if (!$this->formWidget) + if (!$this->formWidget) { throw new ApplicationException(Lang::get('backend::lang.form.behavior_not_ready')); + } return $this->formWidget->render($options); } @@ -138,9 +139,9 @@ class Settings extends Controller */ protected function createModel($item) { - if (!isset($item->class) || !strlen($item->class)) + if (!isset($item->class) || !strlen($item->class)) { throw new ApplicationException(Lang::get('system::lang.settings.missing_model')); - + } $class = $item->class; $model = $class::instance(); @@ -166,5 +167,4 @@ class Settings extends Controller return $item; } - -} \ No newline at end of file +} diff --git a/modules/system/controllers/Updates.php b/modules/system/controllers/Updates.php index a0996ab9b..6d795a065 100644 --- a/modules/system/controllers/Updates.php +++ b/modules/system/controllers/Updates.php @@ -77,17 +77,21 @@ class Updates extends Controller */ public function listInjectRowClass($record, $definition = null) { - if ($record->disabledByConfig) + if ($record->disabledByConfig) { return 'hidden'; + } - if ($record->orphaned || $record->is_disabled) + if ($record->orphaned || $record->is_disabled) { return 'safe disabled'; + } - if ($definition != 'manage') + if ($definition != 'manage') { return; + } - if ($record->disabledBySystem) + if ($record->disabledBySystem) { return 'negative'; + } return 'positive'; } @@ -100,20 +104,25 @@ class Updates extends Controller /* * Address timeout limits */ - if (!ini_get('safe_mode')) + if (!ini_get('safe_mode')) { set_time_limit(3600); + } $manager = UpdateManager::instance(); $stepCode = post('code'); switch ($stepCode) { case 'downloadCore': - if ($this->disableCoreUpdates) return; + if ($this->disableCoreUpdates) { + return; + } $manager->downloadCore(post('hash')); break; case 'extractCore': - if ($this->disableCoreUpdates) return; + if ($this->disableCoreUpdates) { + return; + } $manager->extractCore(post('hash'), post('build')); break; @@ -170,8 +179,7 @@ class Updates extends Controller $this->vars['hasUpdates'] = array_get($result, 'update', false); $this->vars['pluginList'] = array_get($result, 'plugins', []); $this->vars['themeList'] = array_get($result, 'themes', []); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->handleError($ex); } @@ -217,8 +225,7 @@ class Updates extends Controller ]; $this->vars['updateSteps'] = $updateSteps; - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->handleError($ex); } @@ -236,10 +243,14 @@ class Updates extends Controller $core = [$coreHash, $coreBuild]; $plugins = post('plugins', []); - if (!is_array($plugins)) $plugins = []; + if (!is_array($plugins)) { + $plugins = []; + } $themes = post('themes', []); - if (!is_array($themes)) $themes = []; + if (!is_array($themes)) { + $themes = []; + } /* * Update steps @@ -255,8 +266,7 @@ class Updates extends Controller ]; $this->vars['updateSteps'] = $updateSteps; - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->handleError($ex); } @@ -265,14 +275,17 @@ class Updates extends Controller protected function buildUpdateSteps($core, $plugins, $themes) { - if (!is_array($core)) + if (!is_array($core)) { $core = [null, null]; + } - if (!is_array($plugins)) + if (!is_array($plugins)) { $plugins = []; + } - if (!is_array($themes)) + if (!is_array($themes)) { $themes = []; + } $updateSteps = []; list($coreHash, $coreBuild) = $core; @@ -357,8 +370,9 @@ class Updates extends Controller public function onAttachProject() { try { - if (!$projectId = post('project_id')) + if (!$projectId = post('project_id')) { throw new ApplicationException(Lang::get('system::lang.project.id.missing')); + } $manager = UpdateManager::instance(); $result = $manager->requestProjectDetails($projectId); @@ -370,8 +384,7 @@ class Updates extends Controller ]); return $this->onForceUpdate(); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->handleError($ex); return $this->makePartial('project_form'); } @@ -399,14 +412,16 @@ class Updates extends Controller public function onInstallPlugin() { try { - if (!$code = post('code')) + if (!$code = post('code')) { throw new ApplicationException(Lang::get('system::lang.install.missing_plugin_name')); + } $manager = UpdateManager::instance(); $result = $manager->requestPluginDetails($code); - if (!isset($result['code']) || !isset($result['hash'])) + if (!isset($result['code']) || !isset($result['hash'])) { throw new ApplicationException(Lang::get('system::lang.server.response_invalid')); + } $name = $result['code']; $hash = $result['hash']; @@ -428,8 +443,7 @@ class Updates extends Controller $this->vars['updateSteps'] = $updateSteps; return $this->makePartial('execute'); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->handleError($ex); return $this->makePartial('plugin_form'); } @@ -444,8 +458,9 @@ class Updates extends Controller if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) { foreach ($checkedIds as $objectId) { - if (!$object = PluginVersion::find($objectId)) + if (!$object = PluginVersion::find($objectId)) { continue; + } /* * Rollback plugin @@ -478,8 +493,9 @@ class Updates extends Controller $manager = UpdateManager::instance(); foreach ($checkedIds as $objectId) { - if (!$object = PluginVersion::find($objectId)) + if (!$object = PluginVersion::find($objectId)) { continue; + } /* * Refresh plugin @@ -499,8 +515,7 @@ class Updates extends Controller { try { $this->vars['checked'] = post('checked'); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->handleError($ex); } return $this->makePartial('disable_form'); @@ -514,13 +529,15 @@ class Updates extends Controller $manager = PluginManager::instance(); foreach ($checkedIds as $objectId) { - if (!$object = PluginVersion::find($objectId)) + if (!$object = PluginVersion::find($objectId)) { continue; + } - if ($disable) + if ($disable) { $manager->disablePlugin($object->code, true); - else + } else { $manager->enablePlugin($object->code, true); + } $object->is_disabled = $disable; $object->save(); @@ -528,12 +545,12 @@ class Updates extends Controller } - if ($disable) + if ($disable) { Flash::success(Lang::get('system::lang.plugins.disable_success')); - else + } else { Flash::success(Lang::get('system::lang.plugins.enable_success')); + } return Redirect::to(Backend::url('system/updates/manage')); } - -} \ No newline at end of file +} diff --git a/modules/system/database/migrations/2013_10_01_000001_Db_Deferred_Bindings.php b/modules/system/database/migrations/2013_10_01_000001_Db_Deferred_Bindings.php index f7b92aa43..3daa8efe2 100644 --- a/modules/system/database/migrations/2013_10_01_000001_Db_Deferred_Bindings.php +++ b/modules/system/database/migrations/2013_10_01_000001_Db_Deferred_Bindings.php @@ -8,8 +8,7 @@ class DbDeferredBindings extends Migration public function up() { - Schema::create('deferred_bindings', function(Blueprint $table) - { + Schema::create('deferred_bindings', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->string('master_type')->index(); @@ -26,5 +25,4 @@ class DbDeferredBindings extends Migration { Schema::dropIfExists('deferred_bindings'); } - } diff --git a/modules/system/database/migrations/2013_10_01_000002_Db_System_Files.php b/modules/system/database/migrations/2013_10_01_000002_Db_System_Files.php index 641fa36c0..35fea40cd 100644 --- a/modules/system/database/migrations/2013_10_01_000002_Db_System_Files.php +++ b/modules/system/database/migrations/2013_10_01_000002_Db_System_Files.php @@ -8,8 +8,7 @@ class DbSystemFiles extends Migration public function up() { - Schema::create('system_files', function(Blueprint $table) - { + Schema::create('system_files', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->string('disk_name'); @@ -31,5 +30,4 @@ class DbSystemFiles extends Migration { Schema::dropIfExists('system_files'); } - } diff --git a/modules/system/database/migrations/2013_10_01_000003_Db_System_Plugin_Versions.php b/modules/system/database/migrations/2013_10_01_000003_Db_System_Plugin_Versions.php index 3cfe13e2d..270784081 100644 --- a/modules/system/database/migrations/2013_10_01_000003_Db_System_Plugin_Versions.php +++ b/modules/system/database/migrations/2013_10_01_000003_Db_System_Plugin_Versions.php @@ -8,8 +8,7 @@ class DbSystemPluginVersions extends Migration public function up() { - Schema::create('system_plugin_versions', function(Blueprint $table) - { + Schema::create('system_plugin_versions', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->string('code')->index(); @@ -22,5 +21,4 @@ class DbSystemPluginVersions extends Migration { Schema::dropIfExists('system_plugin_versions'); } - } diff --git a/modules/system/database/migrations/2013_10_01_000004_Db_System_Plugin_History.php b/modules/system/database/migrations/2013_10_01_000004_Db_System_Plugin_History.php index 41f60654e..522e27aa7 100644 --- a/modules/system/database/migrations/2013_10_01_000004_Db_System_Plugin_History.php +++ b/modules/system/database/migrations/2013_10_01_000004_Db_System_Plugin_History.php @@ -8,8 +8,7 @@ class DbSystemPluginHistory extends Migration public function up() { - Schema::create('system_plugin_history', function(Blueprint $table) - { + Schema::create('system_plugin_history', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->string('code')->index(); @@ -24,5 +23,4 @@ class DbSystemPluginHistory extends Migration { Schema::dropIfExists('system_plugin_history'); } - } diff --git a/modules/system/database/migrations/2013_10_01_000005_Db_System_Settings.php b/modules/system/database/migrations/2013_10_01_000005_Db_System_Settings.php index b370125eb..a61043cf5 100644 --- a/modules/system/database/migrations/2013_10_01_000005_Db_System_Settings.php +++ b/modules/system/database/migrations/2013_10_01_000005_Db_System_Settings.php @@ -3,12 +3,11 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class DbSystemSettings extends Migration +class DbSystemSettings extends Migration { public function up() { - Schema::create('system_settings', function($table) - { + Schema::create('system_settings', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->string('item')->nullable()->index(); diff --git a/modules/system/database/migrations/2013_10_01_000006_Db_System_Parameters.php b/modules/system/database/migrations/2013_10_01_000006_Db_System_Parameters.php index 89c5520ce..9ba0d1274 100644 --- a/modules/system/database/migrations/2013_10_01_000006_Db_System_Parameters.php +++ b/modules/system/database/migrations/2013_10_01_000006_Db_System_Parameters.php @@ -7,8 +7,7 @@ class DbSystemParameters extends Migration { public function up() { - Schema::create('system_parameters', function($table) - { + Schema::create('system_parameters', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->string('namespace', 100); diff --git a/modules/system/database/migrations/2013_10_01_000007_Db_System_Add_Disabled_Flag.php b/modules/system/database/migrations/2013_10_01_000007_Db_System_Add_Disabled_Flag.php index 634e00cd7..d8a9bc784 100644 --- a/modules/system/database/migrations/2013_10_01_000007_Db_System_Add_Disabled_Flag.php +++ b/modules/system/database/migrations/2013_10_01_000007_Db_System_Add_Disabled_Flag.php @@ -8,18 +8,15 @@ class DbSystemAddDisabledFlag extends Migration public function up() { - Schema::table('system_plugin_versions', function(Blueprint $table) - { + Schema::table('system_plugin_versions', function (Blueprint $table) { $table->boolean('is_disabled')->default(0); }); } public function down() { - Schema::table('system_plugin_versions', function($table) - { + Schema::table('system_plugin_versions', function (Blueprint $table) { $table->dropColumn('is_disabled'); }); } - } diff --git a/modules/system/database/migrations/2013_10_01_000008_Db_System_Mail_Templates.php b/modules/system/database/migrations/2013_10_01_000008_Db_System_Mail_Templates.php index 53fdc6d29..2c455355c 100644 --- a/modules/system/database/migrations/2013_10_01_000008_Db_System_Mail_Templates.php +++ b/modules/system/database/migrations/2013_10_01_000008_Db_System_Mail_Templates.php @@ -8,8 +8,7 @@ class DbSystemMailTemplates extends Migration public function up() { - Schema::create('system_mail_templates', function(Blueprint $table) - { + Schema::create('system_mail_templates', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->string('code')->nullable(); @@ -27,5 +26,4 @@ class DbSystemMailTemplates extends Migration { Schema::dropIfExists('system_mail_templates'); } - } diff --git a/modules/system/database/migrations/2013_10_01_000009_Db_System_Mail_Layouts.php b/modules/system/database/migrations/2013_10_01_000009_Db_System_Mail_Layouts.php index d8259a029..a6580f4a3 100644 --- a/modules/system/database/migrations/2013_10_01_000009_Db_System_Mail_Layouts.php +++ b/modules/system/database/migrations/2013_10_01_000009_Db_System_Mail_Layouts.php @@ -8,8 +8,7 @@ class DbSystemMailLayouts extends Migration public function up() { - Schema::create('system_mail_layouts', function(Blueprint $table) - { + Schema::create('system_mail_layouts', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->string('name')->nullable(); @@ -26,5 +25,4 @@ class DbSystemMailLayouts extends Migration { Schema::dropIfExists('system_mail_layouts'); } - } diff --git a/modules/system/database/migrations/2013_10_01_000010_Db_Cron_Queue.php b/modules/system/database/migrations/2013_10_01_000010_Db_Cron_Queue.php index 33e42b6d7..0720b97e8 100644 --- a/modules/system/database/migrations/2013_10_01_000010_Db_Cron_Queue.php +++ b/modules/system/database/migrations/2013_10_01_000010_Db_Cron_Queue.php @@ -8,8 +8,7 @@ class DbCronQueue extends Migration public function up() { - Schema::create('cron_queue', function(Blueprint $table) - { + Schema::create('cron_queue', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->integer('delay')->default(0); @@ -24,5 +23,4 @@ class DbCronQueue extends Migration { Schema::dropIfExists('cron_queue'); } - } diff --git a/modules/system/database/migrations/2014_10_01_000011_Db_System_Event_Logs.php b/modules/system/database/migrations/2014_10_01_000011_Db_System_Event_Logs.php index abebefa58..739a8dd99 100644 --- a/modules/system/database/migrations/2014_10_01_000011_Db_System_Event_Logs.php +++ b/modules/system/database/migrations/2014_10_01_000011_Db_System_Event_Logs.php @@ -8,8 +8,7 @@ class DbSystemEventLogs extends Migration public function up() { - Schema::create('system_event_logs', function(Blueprint $table) - { + Schema::create('system_event_logs', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->string('level')->nullable()->index(); @@ -23,5 +22,4 @@ class DbSystemEventLogs extends Migration { Schema::dropIfExists('system_event_logs'); } - } diff --git a/modules/system/database/migrations/2014_10_01_000012_Db_System_Request_Logs.php b/modules/system/database/migrations/2014_10_01_000012_Db_System_Request_Logs.php index 7d31258c3..168f3d1bc 100644 --- a/modules/system/database/migrations/2014_10_01_000012_Db_System_Request_Logs.php +++ b/modules/system/database/migrations/2014_10_01_000012_Db_System_Request_Logs.php @@ -8,8 +8,7 @@ class DbSystemRequestLogs extends Migration public function up() { - Schema::create('system_request_logs', function(Blueprint $table) - { + Schema::create('system_request_logs', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id'); $table->integer('status_code')->nullable(); @@ -24,5 +23,4 @@ class DbSystemRequestLogs extends Migration { Schema::dropIfExists('system_request_logs'); } - } diff --git a/modules/system/database/migrations/2014_10_01_000013_Db_System_Sessions.php b/modules/system/database/migrations/2014_10_01_000013_Db_System_Sessions.php index 66592ac6f..3342db939 100644 --- a/modules/system/database/migrations/2014_10_01_000013_Db_System_Sessions.php +++ b/modules/system/database/migrations/2014_10_01_000013_Db_System_Sessions.php @@ -13,8 +13,7 @@ class DbSystemSessions extends Migration */ public function up() { - Schema::create('sessions', function(Blueprint $table) - { + Schema::create('sessions', function (Blueprint $table) { $table->string('id')->unique(); $table->text('payload')->nullable(); $table->integer('last_activity')->nullable(); @@ -30,5 +29,4 @@ class DbSystemSessions extends Migration { Schema::dropIfExists('sessions'); } - } diff --git a/modules/system/database/seeds/DatabaseSeeder.php b/modules/system/database/seeds/DatabaseSeeder.php index 56fdd7588..f2f924b13 100644 --- a/modules/system/database/seeds/DatabaseSeeder.php +++ b/modules/system/database/seeds/DatabaseSeeder.php @@ -17,5 +17,4 @@ class DatabaseSeeder extends Seeder $this->call('System\Database\Seeds\SeedSetupMailLayouts'); } - -} \ No newline at end of file +} diff --git a/modules/system/database/seeds/SeedSetupMailLayouts.php b/modules/system/database/seeds/SeedSetupMailLayouts.php index 126e6ce2a..020645286 100644 --- a/modules/system/database/seeds/SeedSetupMailLayouts.php +++ b/modules/system/database/seeds/SeedSetupMailLayouts.php @@ -75,5 +75,4 @@ This is an automatic message. Please do not reply to it. 'content_text' => $text, ]); } - -} \ No newline at end of file +} diff --git a/modules/system/lang/de/lang.php b/modules/system/lang/de/lang.php index 16a95f080..31a6446d5 100644 --- a/modules/system/lang/de/lang.php +++ b/modules/system/lang/de/lang.php @@ -139,4 +139,4 @@ return [ 'zip' => [ 'extract_failed' => "Konnte Core-Datei ':file' nicht entpacken.", ], -]; \ No newline at end of file +]; diff --git a/modules/system/lang/de/validation.php b/modules/system/lang/de/validation.php index 894e01caf..838649d6d 100644 --- a/modules/system/lang/de/validation.php +++ b/modules/system/lang/de/validation.php @@ -2,97 +2,97 @@ return array( - /* - |-------------------------------------------------------------------------- - | Validation Language Lines - |-------------------------------------------------------------------------- - | - | The following language lines contain the default error messages used by - | the validator class. Some of these rules have multiple versions such - | such as the size rules. Feel free to tweak each of these messages. - | - */ + /* + |-------------------------------------------------------------------------- + | Validation Language Lines + |-------------------------------------------------------------------------- + | + | The following language lines contain the default error messages used by + | the validator class. Some of these rules have multiple versions such + | such as the size rules. Feel free to tweak each of these messages. + | + */ - "accepted" => ":attribute muss bestätigt werden.", - "active_url" => ":attribute ist keine gültige URL.", - "after" => ":attribute muss ein Datum nach :date sein.", - "alpha" => ":attribute darf nur Buchstaben enthalten.", - "alpha_dash" => ":attribute darf nur Buchstaben, Ziffern und Bindestriche enthalten.", - "alpha_num" => ":attribute darf nur Buchstaben und Ziffern enthalten.", - "array" => ":attribute muss ein Array sein.", - "before" => ":attribute muss ein Datum vor :date sein.", - "between" => array( - "numeric" => ":attribute muss zwischen :min und :max liegen.", - "file" => ":attribute muss zwischen :min und :max kilobytes groß sein.", - "string" => ":attribute-Zeichenanzahl muss zwischen :min und :max liegen.", - "array" => ":attribute-Elementanzahl muss zwischen :min und :max liegen.", - ), - "confirmed" => "Bestätigung zu :attribute stimmt nicht überein", - "date" => ":attribute ist kein gültiges Datum.", - "date_format" => ":attribute hat kein gültiges Datumsformat :format.", - "different" => ":attribute und :other müssen sich unterscheiden.", - "digits" => "Das :attribute benötigt :digits Zeichen.", - "digits_between" => ":attribute-Zeichenanzahl muss zwischen :min und :max liegen.", - "email" => "Format von :attribute ist ungültig.", - "exists" => "Das ausgewählte Attribut :attribute ist ungültig.", - "image" => ":attribute muss ein Bild sein.", - "in" => "Das ausgewählte Attribut :attribute ist ungültig.", - "integer" => ":attribute muss eine Ganzzahl (integer) sein.", - "ip" => ":attribute muss eine gültige IP-Adresse sein.", - "max" => array( - "numeric" => ":attribute darf nicht größer als :max sein.", - "file" => ":attribute darf nicht größer als :max kilobytes sein.", - "string" => "Dateiname von :attribute darf nicht mehr als :max Zeichen haben.", - "array" => ":attribute darf nicht mehr als :max Elemente besitzen.", - ), - "mimes" => ":attribute muss eine Datei des Typs: :values sein.", - "min" => array( - "numeric" => ":attribute muss mindestens :min sein.", - "file" => ":attribute darf nicht kleiner als :min kilobytes sein.", - "string" => "Dateiname von :attribute darf nicht weniger als :min Zeichen haben.", - "array" => ":attribute darf nicht weniger als :min Elemente besitzen.", - ), - "not_in" => "Das ausgewählte Attribut :attribute ist ungültig.", - "numeric" => ":attribute muss eine Zahl sein.", - "regex" => "Format von :attribute ist ungültig.", - "required" => ":attribute wird benötigt.", - "required_if" => ":attribute wird benötigt, wenn :other den Wert :value hat.", - "required_with" => ":attribute wird benötigt, wenn :values existiert.", - "required_without" => ":attribute wird benötigt, wenn :values nicht existiert.", - "same" => ":attribute und :other müssen übereinstimmen.", - "size" => array( - "numeric" => ":attribute muss :size groß sein.", - "file" => ":attribute muss :size kilobytes groß sein.", - "string" => "Name von :attribute muss :size Zeichen beinhalten.", - "array" => ":attribute muss :size Elemente beinhalten.", - ), - "unique" => ":attribute muss eindeutig sein.", - "url" => "Format von :attribute ist ungültig.", + "accepted" => ":attribute muss bestätigt werden.", + "active_url" => ":attribute ist keine gültige URL.", + "after" => ":attribute muss ein Datum nach :date sein.", + "alpha" => ":attribute darf nur Buchstaben enthalten.", + "alpha_dash" => ":attribute darf nur Buchstaben, Ziffern und Bindestriche enthalten.", + "alpha_num" => ":attribute darf nur Buchstaben und Ziffern enthalten.", + "array" => ":attribute muss ein Array sein.", + "before" => ":attribute muss ein Datum vor :date sein.", + "between" => array( + "numeric" => ":attribute muss zwischen :min und :max liegen.", + "file" => ":attribute muss zwischen :min und :max kilobytes groß sein.", + "string" => ":attribute-Zeichenanzahl muss zwischen :min und :max liegen.", + "array" => ":attribute-Elementanzahl muss zwischen :min und :max liegen.", + ), + "confirmed" => "Bestätigung zu :attribute stimmt nicht überein", + "date" => ":attribute ist kein gültiges Datum.", + "date_format" => ":attribute hat kein gültiges Datumsformat :format.", + "different" => ":attribute und :other müssen sich unterscheiden.", + "digits" => "Das :attribute benötigt :digits Zeichen.", + "digits_between" => ":attribute-Zeichenanzahl muss zwischen :min und :max liegen.", + "email" => "Format von :attribute ist ungültig.", + "exists" => "Das ausgewählte Attribut :attribute ist ungültig.", + "image" => ":attribute muss ein Bild sein.", + "in" => "Das ausgewählte Attribut :attribute ist ungültig.", + "integer" => ":attribute muss eine Ganzzahl (integer) sein.", + "ip" => ":attribute muss eine gültige IP-Adresse sein.", + "max" => array( + "numeric" => ":attribute darf nicht größer als :max sein.", + "file" => ":attribute darf nicht größer als :max kilobytes sein.", + "string" => "Dateiname von :attribute darf nicht mehr als :max Zeichen haben.", + "array" => ":attribute darf nicht mehr als :max Elemente besitzen.", + ), + "mimes" => ":attribute muss eine Datei des Typs: :values sein.", + "min" => array( + "numeric" => ":attribute muss mindestens :min sein.", + "file" => ":attribute darf nicht kleiner als :min kilobytes sein.", + "string" => "Dateiname von :attribute darf nicht weniger als :min Zeichen haben.", + "array" => ":attribute darf nicht weniger als :min Elemente besitzen.", + ), + "not_in" => "Das ausgewählte Attribut :attribute ist ungültig.", + "numeric" => ":attribute muss eine Zahl sein.", + "regex" => "Format von :attribute ist ungültig.", + "required" => ":attribute wird benötigt.", + "required_if" => ":attribute wird benötigt, wenn :other den Wert :value hat.", + "required_with" => ":attribute wird benötigt, wenn :values existiert.", + "required_without" => ":attribute wird benötigt, wenn :values nicht existiert.", + "same" => ":attribute und :other müssen übereinstimmen.", + "size" => array( + "numeric" => ":attribute muss :size groß sein.", + "file" => ":attribute muss :size kilobytes groß sein.", + "string" => "Name von :attribute muss :size Zeichen beinhalten.", + "array" => ":attribute muss :size Elemente beinhalten.", + ), + "unique" => ":attribute muss eindeutig sein.", + "url" => "Format von :attribute ist ungültig.", - /* - |-------------------------------------------------------------------------- - | Custom Validation Language Lines - |-------------------------------------------------------------------------- - | - | Here you may specify custom validation messages for attributes using the - | convention "attribute.rule" to name the lines. This makes it quick to - | specify a specific custom language line for a given attribute rule. - | - */ + /* + |-------------------------------------------------------------------------- + | Custom Validation Language Lines + |-------------------------------------------------------------------------- + | + | Here you may specify custom validation messages for attributes using the + | convention "attribute.rule" to name the lines. This makes it quick to + | specify a specific custom language line for a given attribute rule. + | + */ - 'custom' => array(), + 'custom' => array(), - /* - |-------------------------------------------------------------------------- - | Custom Validation Attributes - |-------------------------------------------------------------------------- - | - | The following language lines are used to swap attribute place-holders - | with something more reader friendly such as E-Mail Address instead - | of "email". This simply helps us make messages a little cleaner. - | - */ + /* + |-------------------------------------------------------------------------- + | Custom Validation Attributes + |-------------------------------------------------------------------------- + | + | The following language lines are used to swap attribute place-holders + | with something more reader friendly such as E-Mail Address instead + | of "email". This simply helps us make messages a little cleaner. + | + */ - 'attributes' => array(), + 'attributes' => array(), ); diff --git a/modules/system/lang/es-ar/lang.php b/modules/system/lang/es-ar/lang.php index 9e66b7480..75396e9aa 100644 --- a/modules/system/lang/es-ar/lang.php +++ b/modules/system/lang/es-ar/lang.php @@ -237,4 +237,4 @@ return [ 'manage_other_administrators' => 'Gestionar otros administradores', 'view_the_dashboard' => 'Ver el Tablero' ] -]; \ No newline at end of file +]; diff --git a/modules/system/lang/es-ar/validation.php b/modules/system/lang/es-ar/validation.php index 39db8a462..783396d13 100644 --- a/modules/system/lang/es-ar/validation.php +++ b/modules/system/lang/es-ar/validation.php @@ -95,4 +95,4 @@ return array( 'attributes' => array(), -); \ No newline at end of file +); diff --git a/modules/system/lang/nl/lang.php b/modules/system/lang/nl/lang.php index b66c03f53..1584b2bb8 100644 --- a/modules/system/lang/nl/lang.php +++ b/modules/system/lang/nl/lang.php @@ -237,4 +237,4 @@ return [ 'manage_other_administrators' => 'Beheer mede-beheerders', 'view_the_dashboard' => 'Bekijk het dashboard' ] -]; \ No newline at end of file +]; diff --git a/modules/system/lang/sv/lang.php b/modules/system/lang/sv/lang.php index 0d4b45306..8f79658ec 100644 --- a/modules/system/lang/sv/lang.php +++ b/modules/system/lang/sv/lang.php @@ -139,4 +139,4 @@ return [ 'zip' => [ 'extract_failed' => "Kunde inte packa upp core-fil ':file'.", ], -]; \ No newline at end of file +]; diff --git a/modules/system/lang/tr/validation.php b/modules/system/lang/tr/validation.php index c40becc52..3c9086dae 100644 --- a/modules/system/lang/tr/validation.php +++ b/modules/system/lang/tr/validation.php @@ -105,4 +105,4 @@ return array( 'attributes' => array(), -); \ No newline at end of file +); diff --git a/modules/system/models/EventLog.php b/modules/system/models/EventLog.php index ec37b3fd5..f23cb81a9 100644 --- a/modules/system/models/EventLog.php +++ b/modules/system/models/EventLog.php @@ -35,8 +35,9 @@ class EventLog extends Model $record->message = $message; $record->level = $level; - if ($details !== null) + if ($details !== null) { $record->details = (array) $details; + } $record->save(); @@ -60,10 +61,10 @@ class EventLog extends Model */ public function getSummaryAttribute() { - if (preg_match("/with message '(.+)' in/", $this->message, $match)) + if (preg_match("/with message '(.+)' in/", $this->message, $match)) { return $match[1]; + } return Str::limit($this->message, 100); } - -} \ No newline at end of file +} diff --git a/modules/system/models/File.php b/modules/system/models/File.php index 4bcfe3b22..d6e621bb1 100644 --- a/modules/system/models/File.php +++ b/modules/system/models/File.php @@ -27,10 +27,11 @@ class File extends FileBase public function getStorageDirectory() { $uploadsDir = Config::get('cms.uploadsDir'); - if ($this->isPublic()) + if ($this->isPublic()) { return base_path() . $uploadsDir . '/public/'; - else + } else { return base_path() . $uploadsDir . '/protected/'; + } } /** @@ -39,9 +40,10 @@ class File extends FileBase public function getPublicDirectory() { $uploadsDir = Config::get('cms.uploadsDir'); - if ($this->isPublic()) + if ($this->isPublic()) { return Request::getBasePath() . $uploadsDir . '/public/'; - else + } else { return Request::getBasePath() . $uploadsDir . '/protected/'; + } } } diff --git a/modules/system/models/MailLayout.php b/modules/system/models/MailLayout.php index 9024f5272..99af49b87 100644 --- a/modules/system/models/MailLayout.php +++ b/modules/system/models/MailLayout.php @@ -26,8 +26,8 @@ class MailLayout extends Model public function beforeDelete() { - if ($this->is_locked) + if ($this->is_locked) { throw new ApplicationException('Cannot delete this template because it is locked'); - + } } -} \ No newline at end of file +} diff --git a/modules/system/models/MailSettings.php b/modules/system/models/MailSettings.php index 87cd1203f..ef5c2ef97 100644 --- a/modules/system/models/MailSettings.php +++ b/modules/system/models/MailSettings.php @@ -61,8 +61,7 @@ class MailSettings extends Model if ($settings->smtp_authorization) { $config->set('mail.username', $settings->smtp_user); $config->set('mail.password', $settings->smtp_password); - } - else { + } else { $config->set('mail.username', null); $config->set('mail.password', null); } @@ -78,4 +77,4 @@ class MailSettings extends Model break; } } -} \ No newline at end of file +} diff --git a/modules/system/models/MailTemplate.php b/modules/system/models/MailTemplate.php index 85fd63e56..c5fba664c 100644 --- a/modules/system/models/MailTemplate.php +++ b/modules/system/models/MailTemplate.php @@ -55,18 +55,21 @@ class MailTemplate extends Model * Clean up non-customized templates */ foreach ($dbTemplates as $code => $is_custom) { - if ($is_custom) + if ($is_custom) { continue; + } - if (!array_key_exists($code, $templates)) + if (!array_key_exists($code, $templates)) { self::whereCode($code)->delete(); + } } /* * Create new templates */ - if (count($newTemplates)) + if (count($newTemplates)) { $categories = MailLayout::lists('id', 'code'); + } foreach ($newTemplates as $code => $description) { $sections = self::getTemplateSections($code); @@ -99,13 +102,14 @@ class MailTemplate extends Model public static function addContentToMailer($message, $code, $data) { if (!isset(self::$cache[$code])) { - if (!$template = self::whereCode($code)->first()) + if (!$template = self::whereCode($code)->first()) { return false; + } self::$cache[$code] = $template; - } - else + } else { $template = self::$cache[$code]; + } /* * Get Twig to load from a string @@ -158,8 +162,9 @@ class MailTemplate extends Model $plugins = PluginManager::instance()->getPlugins(); foreach ($plugins as $pluginId => $pluginObj) { $templates = $pluginObj->registerMailTemplates(); - if (!is_array($templates)) + if (!is_array($templates)) { continue; + } $this->registerMailTemplates($templates); } @@ -171,8 +176,9 @@ class MailTemplate extends Model */ public function listRegisteredTemplates() { - if (self::$registeredTemplates === null) + if (self::$registeredTemplates === null) { $this->loadRegisteredTemplates(); + } return self::$registeredTemplates; } @@ -199,9 +205,10 @@ class MailTemplate extends Model */ public function registerMailTemplates(array $definitions) { - if (!static::$registeredTemplates) + if (!static::$registeredTemplates) { static::$registeredTemplates = []; + } static::$registeredTemplates = array_merge(static::$registeredTemplates, $definitions); } -} \ No newline at end of file +} diff --git a/modules/system/models/Parameters.php b/modules/system/models/Parameters.php index eb141eff2..de75ed071 100644 --- a/modules/system/models/Parameters.php +++ b/modules/system/models/Parameters.php @@ -36,12 +36,14 @@ class Parameters extends Model */ public static function get($key, $default = null) { - if (array_key_exists($key, static::$cache)) + if (array_key_exists($key, static::$cache)) { return static::$cache[$key]; + } $record = static::findRecord($key)->first(); - if (!$record) + if (!$record) { return static::$cache[$key] = $default; + } return static::$cache[$key] = $record->value; } @@ -93,5 +95,4 @@ class Parameters extends Model return $query; } - -} \ No newline at end of file +} diff --git a/modules/system/models/PluginVersion.php b/modules/system/models/PluginVersion.php index 073c3419a..b6eb920b8 100644 --- a/modules/system/models/PluginVersion.php +++ b/modules/system/models/PluginVersion.php @@ -56,18 +56,18 @@ class PluginVersion extends Model $this->{$attribute} = Lang::get($info); } - if ($this->is_disabled) + if ($this->is_disabled) { $manager->disablePlugin($this->code, true); - else + } else { $manager->enablePlugin($this->code, true); + } $this->disabledBySystem = $pluginObj->disabled; if (($configDisabled = Config::get('cms.disablePlugins')) && is_array($configDisabled)) { $this->disabledByConfig = in_array($this->code, $configDisabled); } - } - else { + } else { $this->name = $this->code; $this->description = Lang::get('system::lang.plugins.unknown_plugin'); $this->orphaned = true; @@ -90,5 +90,4 @@ class PluginVersion extends Model ? self::$versionCache[$pluginCode] : null; } - -} \ No newline at end of file +} diff --git a/modules/system/models/RequestLog.php b/modules/system/models/RequestLog.php index ca2859b39..a2cc31b24 100644 --- a/modules/system/models/RequestLog.php +++ b/modules/system/models/RequestLog.php @@ -47,12 +47,10 @@ class RequestLog extends Model if (!$record->exists) { $record->count = 1; $record->save(); - } - else { + } else { $record->increment('count'); } return $record; } - -} \ No newline at end of file +} diff --git a/modules/system/providers.php b/modules/system/providers.php index 4e3b26f89..d4b4eb790 100644 --- a/modules/system/providers.php +++ b/modules/system/providers.php @@ -45,4 +45,4 @@ return [ */ 'Indatus\Dispatcher\ServiceProvider', -]; \ No newline at end of file +]; diff --git a/modules/system/reportwidgets/Status.php b/modules/system/reportwidgets/Status.php index 31f31f0eb..a78065fdd 100644 --- a/modules/system/reportwidgets/Status.php +++ b/modules/system/reportwidgets/Status.php @@ -20,8 +20,7 @@ class Status extends ReportWidgetBase { try { $this->loadData(); - } - catch (Exception $ex) { + } catch (Exception $ex) { $this->vars['error'] = $ex->getMessage(); } @@ -46,4 +45,4 @@ class Status extends ReportWidgetBase $manager = UpdateManager::instance(); $this->vars['updates'] = $manager->check(); } -} \ No newline at end of file +} diff --git a/modules/system/routes.php b/modules/system/routes.php index 343340be0..4cf0d0b53 100644 --- a/modules/system/routes.php +++ b/modules/system/routes.php @@ -3,7 +3,7 @@ /* * Register System routes before all user routes. */ -App::before(function($request) { +App::before(function ($request) { /* * Combine JavaScript and StyleSheet assets diff --git a/modules/system/traits/AssetMaker.php b/modules/system/traits/AssetMaker.php index 5d404db44..2fc6b3386 100644 --- a/modules/system/traits/AssetMaker.php +++ b/modules/system/traits/AssetMaker.php @@ -35,22 +35,27 @@ trait AssetMaker */ public function makeAssets($type = null) { - if ($type != null) $type = strtolower($type); + if ($type != null) { + $type = strtolower($type); + } $result = null; $reserved = ['build']; $pathCache = []; - if ($type == null || $type == 'css'){ + if ($type == null || $type == 'css') { foreach ($this->assets['css'] as $asset) { /* * Prevent duplicates */ $path = $this->getAssetEntryBuildPath($asset); - if (isset($pathCache[$path])) continue; + if (isset($pathCache[$path])) { + continue; + } $pathCache[$path] = true; - $attributes = HTML::attributes(array_merge([ + $attributes = HTML::attributes(array_merge( + [ 'rel' => 'stylesheet', 'href' => $path ], @@ -61,17 +66,20 @@ trait AssetMaker } } - if ($type == null || $type == 'rss'){ + if ($type == null || $type == 'rss') { foreach ($this->assets['rss'] as $asset) { /* * Prevent duplicates */ $path = $this->getAssetEntryBuildPath($asset); - if (isset($pathCache[$path])) continue; + if (isset($pathCache[$path])) { + continue; + } $pathCache[$path] = true; - $attributes = HTML::attributes(array_merge([ + $attributes = HTML::attributes(array_merge( + [ 'rel' => 'alternate', 'href' => $path, 'title' => 'RSS', @@ -91,10 +99,13 @@ trait AssetMaker * Prevent duplicates */ $path = $this->getAssetEntryBuildPath($asset); - if (isset($pathCache[$path])) continue; + if (isset($pathCache[$path])) { + continue; + } $pathCache[$path] = true; - $attributes = HTML::attributes(array_merge([ + $attributes = HTML::attributes(array_merge( + [ 'src' => $path ], array_except($asset['attributes'], $reserved) @@ -118,16 +129,19 @@ trait AssetMaker { $jsPath = $this->getAssetPath($name); - if (isset($this->controller)) + if (isset($this->controller)) { $this->controller->addJs($jsPath, $attributes); + } - if (is_string($attributes)) + if (is_string($attributes)) { $attributes = ['build' => $attributes]; + } $jsPath = $this->getAssetScheme($jsPath); - if (!in_array($jsPath, $this->assets['js'])) + if (!in_array($jsPath, $this->assets['js'])) { $this->assets['js'][] = ['path' => $jsPath, 'attributes' => $attributes]; + } } /** @@ -141,16 +155,19 @@ trait AssetMaker { $cssPath = $this->getAssetPath($name); - if (isset($this->controller)) + if (isset($this->controller)) { $this->controller->addCss($cssPath, $attributes); + } - if (is_string($attributes)) + if (is_string($attributes)) { $attributes = ['build' => $attributes]; + } $cssPath = $this->getAssetScheme($cssPath); - if (!in_array($cssPath, $this->assets['css'])) + if (!in_array($cssPath, $this->assets['css'])) { $this->assets['css'][] = ['path' => $cssPath, 'attributes' => $attributes]; + } } /** @@ -164,16 +181,19 @@ trait AssetMaker { $rssPath = $this->getAssetPath($name); - if (isset($this->controller)) + if (isset($this->controller)) { $this->controller->addRss($rssPath, $attributes); + } - if (is_string($attributes)) + if (is_string($attributes)) { $attributes = ['build' => $attributes]; + } $rssPath = $this->getAssetScheme($rssPath); - if (!in_array($rssPath, $this->assets['rss'])) + if (!in_array($rssPath, $this->assets['rss'])) { $this->assets['rss'][] = ['path' => $rssPath, 'attributes' => $attributes]; + } } /** @@ -202,22 +222,27 @@ trait AssetMaker */ public function getAssetPath($fileName, $assetPath = null) { - if (preg_match("/(\/\/|http|https)/", $fileName)) + if (preg_match("/(\/\/|http|https)/", $fileName)) { return $fileName; + } - if (!$assetPath) + if (!$assetPath) { $assetPath = $this->assetPath; + } - if (substr($fileName, 0, 1) == '/' || $assetPath === null) + if (substr($fileName, 0, 1) == '/' || $assetPath === null) { return $fileName; + } - if (!is_array($assetPath)) + if (!is_array($assetPath)) { $assetPath = [$assetPath]; + } foreach ($assetPath as $path) { $_fileName = $path . '/' . $fileName; - if (File::isFile(PATH_BASE . '/' . $_fileName)) + if (File::isFile(PATH_BASE . '/' . $_fileName)) { break; + } } return $_fileName; @@ -243,10 +268,11 @@ trait AssetMaker if (isset($asset['attributes']['build'])) { $build = $asset['attributes']['build']; - if ($build == 'core') + if ($build == 'core') { $build = 'v' . Parameters::get('system::core.build', 1); - elseif ($pluginVersion = PluginVersion::getVersion($build)) + } elseif ($pluginVersion = PluginVersion::getVersion($build)) { $build = 'v' . $pluginVersion; + } $path .= '?' . $build; } @@ -261,13 +287,14 @@ trait AssetMaker */ protected function getAssetScheme($asset) { - if (preg_match("/(\/\/|http|https)/", $asset)) + if (preg_match("/(\/\/|http|https)/", $asset)) { return $asset; + } - if (substr($asset, 0, 1) == '/') + if (substr($asset, 0, 1) == '/') { $asset = Request::getBasePath() . $asset; + } return $asset; } - } diff --git a/modules/system/traits/ConfigMaker.php b/modules/system/traits/ConfigMaker.php index 7c0d40be7..904b4d0d1 100644 --- a/modules/system/traits/ConfigMaker.php +++ b/modules/system/traits/ConfigMaker.php @@ -33,27 +33,28 @@ trait ConfigMaker */ if (is_object($configFile)) { $config = $configFile; - } - /* * Embedded config */ - elseif (is_array($configFile)) { + } elseif (is_array($configFile)) { $config = $this->makeConfigFromArray($configFile); - } - /* * Process config from file contents */ - else { + } else { - if (isset($this->controller) && method_exists($this->controller, 'getConfigPath')) + if (isset($this->controller) && method_exists($this->controller, 'getConfigPath')) { $configFile = $this->controller->getConfigPath($configFile); - else + } else { $configFile = $this->getConfigPath($configFile); + } - if (!File::isFile($configFile)) - throw new SystemException(Lang::get('system::lang.config.not_found', ['file' => $configFile, 'location' => get_called_class()])); + if (!File::isFile($configFile)) { + throw new SystemException(Lang::get( + 'system::lang.config.not_found', + ['file' => $configFile, 'location' => get_called_class()] + )); + } $config = Yaml::parse(File::get($configFile)); @@ -63,7 +64,9 @@ trait ConfigMaker $publicFile = File::localToPublic($configFile); if ($results = Event::fire('system.extendConfigFile', [$publicFile, $config])) { foreach ($results as $result) { - if (!is_array($result)) continue; + if (!is_array($result)) { + continue; + } $config = array_merge($config, $result); } } @@ -75,8 +78,12 @@ trait ConfigMaker * Validate required configuration */ foreach ($requiredConfig as $property) { - if (!property_exists($config, $property)) - throw new SystemException(Lang::get('system::lang.config.required', ['property' => $property, 'location' => get_called_class()])); + if (!property_exists($config, $property)) { + throw new SystemException(Lang::get( + 'system::lang.config.required', + ['property' => $property, 'location' => get_called_class()] + )); + } } return $config; @@ -92,8 +99,9 @@ trait ConfigMaker { $object = new stdClass(); - if (!is_array($configArray)) + if (!is_array($configArray)) { return $object; + } foreach ($configArray as $name => $value) { $_name = camel_case($name); @@ -113,24 +121,29 @@ trait ConfigMaker */ public function getConfigPath($fileName, $configPath = null) { - if (!isset($this->configPath)) + if (!isset($this->configPath)) { $this->configPath = $this->guessConfigPath(); + } - if (!$configPath) + if (!$configPath) { $configPath = $this->configPath; + } $fileName = File::symbolizePath($fileName, $fileName); - if (File::isLocalPath($fileName) || realpath($fileName) !== false) + if (File::isLocalPath($fileName) || realpath($fileName) !== false) { return $fileName; + } - if (!is_array($configPath)) + if (!is_array($configPath)) { $configPath = [$configPath]; + } foreach ($configPath as $path) { $_fileName = $path . '/' . $fileName; - if (File::isFile($_fileName)) + if (File::isFile($_fileName)) { break; + } } return $_fileName; @@ -160,5 +173,4 @@ trait ConfigMaker $guessedPath = $classFile ? $classFile . '/' . $classFolder . $suffix : null; return $guessedPath; } - -} \ No newline at end of file +} diff --git a/modules/system/traits/PropertyContainer.php b/modules/system/traits/PropertyContainer.php index 6bc0a6fe4..40528e7a4 100644 --- a/modules/system/traits/PropertyContainer.php +++ b/modules/system/traits/PropertyContainer.php @@ -96,4 +96,4 @@ trait PropertyContainer { return []; } -} \ No newline at end of file +} diff --git a/modules/system/traits/ViewMaker.php b/modules/system/traits/ViewMaker.php index c74859d4c..6771a8a33 100644 --- a/modules/system/traits/ViewMaker.php +++ b/modules/system/traits/ViewMaker.php @@ -49,16 +49,18 @@ trait ViewMaker */ public function makePartial($partial, $params = [], $throwException = true) { - if (!File::isPathSymbol($partial) && realpath($partial) === false) + if (!File::isPathSymbol($partial) && realpath($partial) === false) { $partial = '_' . strtolower($partial) . '.htm'; + } $partialPath = $this->getViewPath($partial); if (!File::isFile($partialPath)) { - if ($throwException) + if ($throwException) { throw new SystemException(Lang::get('backend::lang.partial.not_found', ['name' => $partialPath])); - else + } else { return false; + } } return $this->makeFileContents($partialPath, $params); @@ -85,8 +87,9 @@ trait ViewMaker */ public function makeViewContent($contents, $layout = null) { - if ($this->suppressLayout || $this->layout == '') + if ($this->suppressLayout || $this->layout == '') { return $contents; + } // Append any undefined block content to the body block Block::set('undefinedBlock', $contents); @@ -105,16 +108,18 @@ trait ViewMaker public function makeLayout($name = null, $params = [], $throwException = true) { $layout = ($name === null) ? $this->layout : $name; - if ($layout == '') + if ($layout == '') { return; + } $layoutPath = $this->getViewPath($layout . '.htm', $this->layoutPath); if (!File::isFile($layoutPath)) { - if ($throwException) + if ($throwException) { throw new SystemException(Lang::get('cms::lang.layout.not_found', ['name' => $layoutPath])); - else + } else { return false; + } } return $this->makeFileContents($layoutPath, $params); @@ -128,8 +133,9 @@ trait ViewMaker */ public function makeLayoutPartial($partial, $params = []) { - if (!File::isLocalPath($partial) && !File::isPathSymbol($partial)) + if (!File::isLocalPath($partial) && !File::isPathSymbol($partial)) { $partial = '_' . strtolower($partial); + } return $this->makeLayout($partial, $params); } @@ -144,24 +150,29 @@ trait ViewMaker */ public function getViewPath($fileName, $viewPath = null) { - if (!isset($this->viewPath)) + if (!isset($this->viewPath)) { $this->viewPath = $this->guessViewPath(); + } - if (!$viewPath) + if (!$viewPath) { $viewPath = $this->viewPath; + } $fileName = File::symbolizePath($fileName, $fileName); - if (File::isLocalPath($fileName) || realpath($fileName) !== false) + if (File::isLocalPath($fileName) || realpath($fileName) !== false) { return $fileName; + } - if (!is_array($viewPath)) + if (!is_array($viewPath)) { $viewPath = [$viewPath]; + } foreach ($viewPath as $path) { $_fileName = $path . '/' . $fileName; - if (File::isFile($_fileName)) + if (File::isFile($_fileName)) { break; + } } return $_fileName; @@ -176,11 +187,13 @@ trait ViewMaker */ public function makeFileContents($filePath, $extraParams = []) { - if (!strlen($filePath) || !File::isFile($filePath)) + if (!strlen($filePath) || !File::isFile($filePath)) { return; + } - if (!is_array($extraParams)) + if (!is_array($extraParams)) { $extraParams = []; + } $vars = array_merge($this->vars, $extraParams); @@ -216,4 +229,4 @@ trait ViewMaker $guessedPath = $classFile ? $classFile . '/' . $classFolder . $suffix : null; return ($isPublic) ? File::localToPublic($guessedPath) : $guessedPath; } -} \ No newline at end of file +} diff --git a/modules/system/twig/Engine.php b/modules/system/twig/Engine.php index 92f3dcfa0..f776f63a7 100644 --- a/modules/system/twig/Engine.php +++ b/modules/system/twig/Engine.php @@ -29,5 +29,4 @@ class Engine implements EngineInterface $template = $this->environment->loadTemplate($path); return $template->render($vars); } - -} \ No newline at end of file +} diff --git a/modules/system/twig/Extension.php b/modules/system/twig/Extension.php index 22ec306f1..4b59b3ea2 100644 --- a/modules/system/twig/Extension.php +++ b/modules/system/twig/Extension.php @@ -102,5 +102,4 @@ class Extension extends Twig_Extension { return URL::to($url); } - -} \ No newline at end of file +} diff --git a/modules/system/twig/Loader.php b/modules/system/twig/Loader.php index c34733066..73f4302e2 100644 --- a/modules/system/twig/Loader.php +++ b/modules/system/twig/Loader.php @@ -32,15 +32,18 @@ class Loader implements Twig_LoaderInterface { $finder = App::make('view')->getFinder(); - if (isset($this->cache[$name])) + if (isset($this->cache[$name])) { return $this->cache[$name]; + } - if (File::isFile($name)) + if (File::isFile($name)) { return $this->cache[$name] = $name; + } $view = $name; - if (File::extension($view) == $this->extension) + if (File::extension($view) == $this->extension) { $view = substr($view, 0, -strlen($this->extension)); + } $path = $finder->find($view); return $this->cache[$name] = $path; @@ -71,9 +74,8 @@ class Loader implements Twig_LoaderInterface try { $this->findTemplate($name); return true; - } - catch (Exception $exception) { + } catch (Exception $exception) { return false; } } -} \ No newline at end of file +} From 509e7d2a12be20806fd92ea9e5d92f4f4231f5d3 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 18 Oct 2014 12:03:48 +0200 Subject: [PATCH 28/30] Fixing issues with files in modules/cms --- modules/cms/classes/CmsCompoundObject.php | 1 + modules/cms/classes/Controller.php | 3 ++- modules/cms/twig/PlaceholderTokenParser.php | 9 +++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/cms/classes/CmsCompoundObject.php b/modules/cms/classes/CmsCompoundObject.php index ad9275c4c..a28613ed2 100644 --- a/modules/cms/classes/CmsCompoundObject.php +++ b/modules/cms/classes/CmsCompoundObject.php @@ -231,6 +231,7 @@ class CmsCompoundObject extends CmsObject $content[] = 'code.PHP_EOL.'?>'; } else { $content[] = $this->code; + } } $content[] = $this->markup; diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index f2f79c142..0c4bca326 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -278,8 +278,9 @@ class Controller extends BaseController $template = $this->twig->loadTemplate($this->page->getFullPath()); $this->pageContents = $template->render($this->vars); CmsException::unmask(); - } else + } else { $this->pageContents = $apiResult; + } /* * Render the layout diff --git a/modules/cms/twig/PlaceholderTokenParser.php b/modules/cms/twig/PlaceholderTokenParser.php index ba4518ef7..767b6a0a0 100644 --- a/modules/cms/twig/PlaceholderTokenParser.php +++ b/modules/cms/twig/PlaceholderTokenParser.php @@ -43,8 +43,9 @@ class PlaceholderTokenParser extends Twig_TokenParser $body = $this->parser->subparse([$this, 'decidePlaceholderEnd'], true); $stream->expect(Twig_Token::BLOCK_END_TYPE); - } else + } else { $params = $this->loadParams($stream); + } return new PlaceholderNode($name, $params, $body, $token->getLine(), $this->getTag()); } @@ -75,7 +76,11 @@ class PlaceholderTokenParser extends Twig_TokenParser break; default: - throw new Twig_Error_Syntax(sprintf('Invalid syntax in the placeholder tag. Line %s', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename()); + throw new Twig_Error_Syntax( + sprintf('Invalid syntax in the placeholder tag. Line %s', $lineno), + $stream->getCurrent()->getLine(), + $stream->getFilename() + ); break; } } From 0a05e08a385cbab91c6b0b4e6a9b959d38f191e7 Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 18 Oct 2014 12:05:51 +0200 Subject: [PATCH 29/30] Fixing issues with files in modules/backend --- modules/backend/formwidgets/ColorPicker.php | 2 +- modules/backend/lang/es-ar/lang.php | 2 +- modules/backend/models/BrandSettings.php | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/backend/formwidgets/ColorPicker.php b/modules/backend/formwidgets/ColorPicker.php index 05b3a93f9..463109843 100644 --- a/modules/backend/formwidgets/ColorPicker.php +++ b/modules/backend/formwidgets/ColorPicker.php @@ -78,4 +78,4 @@ class ColorPicker extends FormWidgetBase { return strlen($value) ? $value : null; } -} \ No newline at end of file +} diff --git a/modules/backend/lang/es-ar/lang.php b/modules/backend/lang/es-ar/lang.php index 2577371be..c940312e9 100644 --- a/modules/backend/lang/es-ar/lang.php +++ b/modules/backend/lang/es-ar/lang.php @@ -251,4 +251,4 @@ return [ 'filter' => [ 'all' => 'Todo' ] -]; \ No newline at end of file +]; diff --git a/modules/backend/models/BrandSettings.php b/modules/backend/models/BrandSettings.php index 3367f2648..0061c3042 100644 --- a/modules/backend/models/BrandSettings.php +++ b/modules/backend/models/BrandSettings.php @@ -65,8 +65,9 @@ class BrandSettings extends Model public static function getLogo() { $settings = self::instance(); - if (!$settings->logo) + if (!$settings->logo) { return null; + } return $settings->logo->getPath(); } @@ -83,10 +84,11 @@ class BrandSettings extends Model 'secondary-color-dark' => self::get('secondary_color_dark', self::SECONDARY_DARK), ]); - $parser->parse(File::get(PATH_BASE.'/modules/backend/models/brandsettings/custom.less').self::get('custom_css')); + $parser->parse( + File::get(PATH_BASE.'/modules/backend/models/brandsettings/custom.less').self::get('custom_css') + ); $css = $parser->getCss(); return $css; } - -} \ No newline at end of file +} From 018e0a417293b15d010358715fa637e39a783e9b Mon Sep 17 00:00:00 2001 From: Stefan Talen Date: Sat, 18 Oct 2014 12:49:29 +0200 Subject: [PATCH 30/30] Updating plugin folder --- plugins/october/demo/Plugin.php | 3 +-- plugins/october/demo/components/Todo.php | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/october/demo/Plugin.php b/plugins/october/demo/Plugin.php index 5ebc66572..46767095e 100644 --- a/plugins/october/demo/Plugin.php +++ b/plugins/october/demo/Plugin.php @@ -25,5 +25,4 @@ class Plugin extends PluginBase '\October\Demo\Components\Todo' => 'demoTodo' ]; } - -} \ No newline at end of file +} diff --git a/plugins/october/demo/components/Todo.php b/plugins/october/demo/components/Todo.php index 78bf289bc..7c3b56b1e 100644 --- a/plugins/october/demo/components/Todo.php +++ b/plugins/october/demo/components/Todo.php @@ -31,13 +31,14 @@ class Todo extends ComponentBase { $items = post('items', []); - if (count($items) >= $this->property('max')) + if (count($items) >= $this->property('max')) { throw new \Exception(sprintf('Sorry only %s items are allowed.', $this->property('max'))); + } - if (($newItem = post('newItem')) != '') + if (($newItem = post('newItem')) != '') { $items[] = $newItem; + } $this->page['items'] = $items; } - -} \ No newline at end of file +}