code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
protected function createHandler($level) { $handler = new DatabaseHandler($level); // set a more basic formatter. $output = '%message%'; $formatter = new LineFormatter($output, null, true); $handler->setFormatter($formatter); return $handler; }
{@inheritdoc} @see \Concrete\Core\Logging\Configuration\SimpleConfiguration::createHandler()
createHandler
php
concretecms/concretecms
concrete/src/Logging/Configuration/SimpleDatabaseConfiguration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Configuration/SimpleDatabaseConfiguration.php
MIT
public function __construct($filename, $coreLevel = Logger::DEBUG) { $this->filename = $filename; parent::__construct($coreLevel); }
Initialize the instance. @param string $filename the file to log to @param int $coreLevel the logging level to care about for all core logs (one of the Monolog\Logger constants) @see \Monolog\Logger
__construct
php
concretecms/concretecms
concrete/src/Logging/Configuration/SimpleFileConfiguration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Configuration/SimpleFileConfiguration.php
MIT
public function createHandler($level) { return new StreamHandler($this->filename, $this->coreLevel); }
{@inheritdoc} @see \Concrete\Core\Logging\Configuration\SimpleConfiguration::createHandler()
createHandler
php
concretecms/concretecms
concrete/src/Logging/Configuration/SimpleFileConfiguration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Configuration/SimpleFileConfiguration.php
MIT
public function __construct(User $applier, Key $key, Access $access) { $this->applier = $applier; $this->key = $key; $this->access = $access; }
Assignment constructor. @param User $applier @param Key $key @param Access $access
__construct
php
concretecms/concretecms
concrete/src/Logging/Entry/Permission/Assignment/Assignment.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Entry/Permission/Assignment/Assignment.php
MIT
public function __construct($username, $requestPath, $groups = [], $errors = []) { $this->username = $username; $this->requestPath = $requestPath; $this->groups = $groups; $this->errors = $errors; }
LoginAttempt constructor. @param string $username The username used when attempting to log in @param string $requestPath The path that is being requested @param string[] $groups The groups the user would have access to @param string[] $errors
__construct
php
concretecms/concretecms
concrete/src/Logging/Entry/User/LoginAttempt.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Entry/User/LoginAttempt.php
MIT
public function getMessage() { $successString = $this->errors ? 'Failed' : 'Successful'; return "{$successString} login attempt for \"{$this->username}\""; }
Convert this entry into something that can be inserted into the log @return string
getMessage
php
concretecms/concretecms
concrete/src/Logging/Entry/User/LoginAttempt.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Entry/User/LoginAttempt.php
MIT
public function getContext() { return [ 'username' => $this->username, 'requestPath' => $this->requestPath, 'errors' => $this->errors, 'groups' => $this->groups, 'successful' => !$this->errors ]; }
Get the added context for the log entry Ex: ["username": "...", "email": "...", "id": "...", "created_by": "..."] @return array
getContext
php
concretecms/concretecms
concrete/src/Logging/Entry/User/LoginAttempt.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Entry/User/LoginAttempt.php
MIT
public static function clearAll() { $db = app(Connection::class); $db->executeStatement('delete from Logs'); }
Clears all log entries. Requires the database handler.
clearAll
php
concretecms/concretecms
concrete/src/Logging/Handler/DatabaseHandler.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Handler/DatabaseHandler.php
MIT
public static function clearByChannel($channel) { $db = app(Connection::class); $db->delete('Logs', ['channel' => $channel]); }
Clears log entries by channel. Requires the database handler. @param $channel string
clearByChannel
php
concretecms/concretecms
concrete/src/Logging/Handler/DatabaseHandler.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Handler/DatabaseHandler.php
MIT
protected function write(array $record) { if (!$this->shouldWrite($record)) { return; } parent::write($record); }
{@inheritdoc} @see \Monolog\Handler\StreamHandler::write()
write
php
concretecms/concretecms
concrete/src/Logging/Handler/StreamHandler.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Handler/StreamHandler.php
MIT
public function enhance(\Throwable $error): ?\Throwable { return $error instanceof UserMessageException ? $error : null; }
Don't touch UserMessageException exceptions. {@inheritdoc} @see \Symfony\Component\ErrorHandler\ErrorEnhancer\ErrorEnhancerInterface::enhance()
enhance
php
concretecms/concretecms
concrete/src/Logging/Handler/ErrorEnhancer/UserMessageExceptionEnhancer.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Handler/ErrorEnhancer/UserMessageExceptionEnhancer.php
MIT
public function __invoke(array $record) { $page = Page::getCurrentPage(); if ($page && !$page->isError()) { $record['extra']['page'] = [$page->getCollectionID(), $page->getCollectionName()]; } return $record; }
Invoke this processor @param array $record The given monolog record @return array The modified record
__invoke
php
concretecms/concretecms
concrete/src/Logging/Processor/ConcretePageProcessor.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Processor/ConcretePageProcessor.php
MIT
public function __invoke(array $record) { $user = $this->getLoggedInUser(); if ($user && $user->isRegistered()) { $record['extra']['user'] = [$user->getUserID(), $user->getUserName()]; } return $record; }
Invoke this processor @param array $record The given monolog record @return array The modified record
__invoke
php
concretecms/concretecms
concrete/src/Logging/Processor/ConcreteUserProcessor.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Processor/ConcreteUserProcessor.php
MIT
protected function getLoggedInUser() { if (!$this->user) { $this->user = $this->app->make(User::class); } return $this->user; }
Resolve a user intance from the IOC container and cache it @return User|mixed
getLoggedInUser
php
concretecms/concretecms
concrete/src/Logging/Processor/ConcreteUserProcessor.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Processor/ConcreteUserProcessor.php
MIT
public function __construct(array $includeKeys) { $this->includeKeys = $includeKeys; }
ServerInfoProcessor constructor. @param string[] $includeKeys The keys to pull from `$_SERVER`
__construct
php
concretecms/concretecms
concrete/src/Logging/Processor/ServerInfoProcessor.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Processor/ServerInfoProcessor.php
MIT
public function __invoke(array $record) { if (!isset($record['extra']['_SERVER'])) { $record['extra']['_SERVER'] = []; } foreach ($this->includeKeys as $includeKey) { if (isset($_SERVER[$includeKey])) { $record['extra']['_SERVER'][$includeKey] = $_SERVER[$includeKey]; } } return $record; }
Invoke this processor @param array $record The given monolog record @return array The modified record
__invoke
php
concretecms/concretecms
concrete/src/Logging/Processor/ServerInfoProcessor.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Processor/ServerInfoProcessor.php
MIT
public static function getCollectionTime($logEntry) { $app = Application::getFacadeApplication(); /** @var Date $dateHelper */ $dateHelper = $app->make(Date::class); return $dateHelper->formatDateTime($logEntry->getTime()); }
@param LogEntry $logEntry @return string @throws Exception @throws BadArgumentType @noinspection PhpUnused
getCollectionTime
php
concretecms/concretecms
concrete/src/Logging/Search/ColumnSet/DefaultSet.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Search/ColumnSet/DefaultSet.php
MIT
public static function getUser($logEntry) { $user = $logEntry->getUser(); if ($user instanceof UserInfo) { return '<a href="' . \URL::to('/dashboard/users/search', 'edit', $logEntry->getUser()->getUserID()) . '">' . h($logEntry->getUser()->getUserName()) . '</a>'; } else { return t('None'); } }
@param LogEntry $logEntry @return string @noinspection PhpUnused
getUser
php
concretecms/concretecms
concrete/src/Logging/Search/ColumnSet/DefaultSet.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Search/ColumnSet/DefaultSet.php
MIT
public static function getPage($logEntry) { $page = $logEntry->getPage(); if ($page instanceof Page) { return '<a href="' . (string) $page->getCollectionLink() . '">' . h($page->getCollectionName()) . '</a>'; } else { return t('None'); } }
@param LogEntry $logEntry @return string @noinspection PhpUnused
getPage
php
concretecms/concretecms
concrete/src/Logging/Search/ColumnSet/DefaultSet.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Search/ColumnSet/DefaultSet.php
MIT
public static function getCollectionLevel($logEntry) { return Levels::getLevelDisplayName($logEntry->getLevel()); }
@param LogEntry $logEntry @return string @noinspection PhpUnused
getCollectionLevel
php
concretecms/concretecms
concrete/src/Logging/Search/ColumnSet/DefaultSet.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Search/ColumnSet/DefaultSet.php
MIT
public static function getFormattedMessage($logEntry) { $app = Application::getFacadeApplication(); /** @var TextService $textHelper */ $textHelper = $app->make(TextService::class); return $textHelper->makenice($logEntry->getMessage()); }
@param $logEntry LogEntry @return string @throws \Illuminate\Contracts\Container\BindingResolutionException
getFormattedMessage
php
concretecms/concretecms
concrete/src/Logging/Search/ColumnSet/DefaultSet.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Search/ColumnSet/DefaultSet.php
MIT
public function filterListAtOffset(PagerProviderInterface $itemList, $mixed) { $query = $itemList->getQueryObject(); $sort = $this->getColumnSortDirection() == 'desc' ? '<' : '>'; $where = sprintf('l.channel %s :channel', $sort); $query->setParameter('channel', $mixed->getChannel()); $this->andWhereNotExists($query, $where); }
@param LogList $itemList @param $mixed LogEntry @noinspection PhpDocSignatureInspection
filterListAtOffset
php
concretecms/concretecms
concrete/src/Logging/Search/ColumnSet/Column/ChannelColumn.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Search/ColumnSet/Column/ChannelColumn.php
MIT
public function filterListAtOffset(PagerProviderInterface $itemList, $mixed) { $query = $itemList->getQueryObject(); $sort = $this->getColumnSortDirection() == 'desc' ? '<' : '>'; $where = sprintf('l.level %s :level', $sort); $query->setParameter('level', $mixed->getLevel()); $this->andWhereNotExists($query, $where); }
@param LogList $itemList @param $mixed LogEntry @noinspection PhpDocSignatureInspection
filterListAtOffset
php
concretecms/concretecms
concrete/src/Logging/Search/ColumnSet/Column/LevelColumn.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Search/ColumnSet/Column/LevelColumn.php
MIT
public function filterListAtOffset(PagerProviderInterface $itemList, $mixed) { $query = $itemList->getQueryObject(); $sort = $this->getColumnSortDirection() == 'desc' ? '<' : '>'; $where = sprintf('l.logID %s :logID', $sort); $query->setParameter('logID', $mixed->getId()); $this->andWhereNotExists($query, $where); }
@param LogList $itemList @param $mixed LogEntry @noinspection PhpDocSignatureInspection
filterListAtOffset
php
concretecms/concretecms
concrete/src/Logging/Search/ColumnSet/Column/LogIdentifierColumn.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Search/ColumnSet/Column/LogIdentifierColumn.php
MIT
public function filterListAtOffset(PagerProviderInterface $itemList, $mixed) { $query = $itemList->getQueryObject(); $sort = $this->getColumnSortDirection() == 'desc' ? '<' : '>'; $where = sprintf('l.message %s :message', $sort); $query->setParameter('message', $mixed->getMessage()); $this->andWhereNotExists($query, $where); }
@param LogList $itemList @param $mixed LogEntry @noinspection PhpDocSignatureInspection
filterListAtOffset
php
concretecms/concretecms
concrete/src/Logging/Search/ColumnSet/Column/MessageColumn.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Search/ColumnSet/Column/MessageColumn.php
MIT
public function filterListAtOffset(PagerProviderInterface $itemList, $mixed) { if ($mixed->getPage() instanceof Page) { $query = $itemList->getQueryObject(); $sort = $this->getColumnSortDirection() == 'desc' ? '<' : '>'; $where = sprintf('l.cID %s :cID', $sort); $query->setParameter('uID', $mixed->getPage()->getCollectionID()); $this->andWhereNotExists($query, $where); } }
@param LogList $itemList @param $mixed LogEntry @noinspection PhpDocSignatureInspection
filterListAtOffset
php
concretecms/concretecms
concrete/src/Logging/Search/ColumnSet/Column/PageColumn.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Search/ColumnSet/Column/PageColumn.php
MIT
public function filterListAtOffset(PagerProviderInterface $itemList, $mixed) { if ($mixed->getTime() instanceof DateTime) { $query = $itemList->getQueryObject(); $sort = $this->getColumnSortDirection() == 'desc' ? '<' : '>'; $where = sprintf('l.time %s :time', $sort); $query->setParameter('time', $mixed->getTime()->getTimestamp()); $this->andWhereNotExists($query, $where); } }
@param LogList $itemList @param $mixed LogEntry @noinspection PhpDocSignatureInspection
filterListAtOffset
php
concretecms/concretecms
concrete/src/Logging/Search/ColumnSet/Column/TimeColumn.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Search/ColumnSet/Column/TimeColumn.php
MIT
public function filterListAtOffset(PagerProviderInterface $itemList, $mixed) { if ($mixed->getUser() instanceof UserInfo) { $query = $itemList->getQueryObject(); $sort = $this->getColumnSortDirection() == 'desc' ? '<' : '>'; $where = sprintf('l.uID %s :uID', $sort); $query->setParameter('uID', $mixed->getUser()->getUserID()); $this->andWhereNotExists($query, $where); } }
@param LogList $itemList @param $mixed LogEntry @noinspection PhpDocSignatureInspection
filterListAtOffset
php
concretecms/concretecms
concrete/src/Logging/Search/ColumnSet/Column/UserIdentifierColumn.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Logging/Search/ColumnSet/Column/UserIdentifierColumn.php
MIT
public function addEntries(iterable $entries): self { foreach ($entries as $entry) { $this->addEntry($entry); } return $this; }
@param \Concrete\Core\Mail\SenderConfiguration\Entry[] $entries @return $this
addEntries
php
concretecms/concretecms
concrete/src/Mail/SenderConfiguration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/SenderConfiguration.php
MIT
public function addEntry(SenderConfiguration\Entry $entry): self { $prefix = $entry->getPackageHandle(); if ($prefix !== '') { $prefix = "{$prefix}::"; } $key = $prefix . $entry->getEmailKey(); if (in_array($key, $this->allConfigurationKeys, true)) { throw new RuntimeException(t('The configuration key %s has been already specified.', $key)); } $this->allConfigurationKeys[] = $key; if ($entry->getNameKey() !== '') { $key = $prefix . $entry->getNameKey(); if (in_array($key, $this->allConfigurationKeys, true)) { throw new RuntimeException(t('The configuration key %s has been already specified.', $key)); } $this->allConfigurationKeys[] = $key; } $this->entries[] = $entry; return $this; }
@throws \RuntimeException in case of duplicated configuration keys @return $this
addEntry
php
concretecms/concretecms
concrete/src/Mail/SenderConfiguration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/SenderConfiguration.php
MIT
public function getEntries(): array { $this->sortEntries(); return $this->entries; }
@return \Concrete\Core\Mail\SenderConfiguration\Entry[]
getEntries
php
concretecms/concretecms
concrete/src/Mail/SenderConfiguration.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/SenderConfiguration.php
MIT
public function __construct(Application $app, TransportInterface $transport) { $this->app = $app; $this->transport = $transport; $this->reset(); }
Initialize the instance. @param Application $app the application instance @param TransportInterface $transport the transport to be used to delivery the messages
__construct
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function reset() { $this->headers = []; $this->to = []; $this->replyto = []; $this->cc = []; $this->bcc = []; $this->from = []; $this->data = []; $this->subject = ''; $this->attachments = []; $this->template = ''; $this->body = false; $this->bodyHTML = false; $this->testing = false; $this->throwOnFailure = false; }
Clean up the instance of this object (reset the class scope variables).
reset
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function addParameter($key, $val) { $this->data[$key] = $val; }
Adds a parameter for the mail template. @param string $key the name of the parameter @param mixed $val the value of the parameter
addParameter
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function addAttachment(File $file) { $this->addAttachmentWithHeaders($file, []); }
Add a File entity as an attachment of the message. @param File $file The file to attach to the message
addAttachment
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function addAttachmentWithHeaders(File $file, array $headers) { $fileVersion = $file->getVersion(); $resource = $fileVersion->getFileResource(); if (array_key_exists('filename', $headers)) { $filename = $headers['filename']; unset($headers['filename']); } else { $filename = $fileVersion->getFilename(); } if (!array_key_exists('mimetype', $headers)) { $headers['mimetype'] = $resource->getMimetype(); } $this->addRawAttachmentWithHeaders( $resource->read(), $filename, $headers ); }
Add a File entity as an attachment of the message, specifying the headers of the mail MIME part. @param File $file The file to attach to the message @param array $headers Additional headers fo the MIME part. Valid values are: - filename: The name to give to the attachment (it will be used as the filename part of the Content-Disposition header) [default: the filename of the File instance] - mimetype: the main value of the Content-Type header [default: the content type of the file] - disposition: the main value of the Content-Disposition header [default: attachment] - encoding: the value of the Content-Transfer-Encoding header [default: base64] - charset: the charset value of the Content-Type header - boundary: the boundary value of the Content-Type header - id: the value of the Content-ID header (without angular brackets) - description: the value of the Content-Description header - location: the value of the Content-Location header - language: the value of the Content-Language header
addAttachmentWithHeaders
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function addRawAttachment($content, $filename, $mimetype = 'application/octet-stream') { $this->addRawAttachmentWithHeaders( $content, $filename, [ 'mimetype' => $mimetype, ] ); }
Add a mail attachment by specifying its raw binary data. @param string $content The binary data of the attachemt @param string $filename The name to give to the attachment (it will be used as the filename part of the Content-Disposition header) @param string $mimetype The MIME type of the attachment (it will be the main value of the Content-Type header)
addRawAttachment
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function addRawAttachmentWithHeaders($content, $filename, array $headers = []) { $headers += [ 'mimetype' => 'application/octet-stream', 'disposition' => Mime::DISPOSITION_ATTACHMENT, 'encoding' => Mime::ENCODING_BASE64, 'charset' => '', 'boundary' => '', 'id' => '', 'description' => '', 'location' => '', 'language' => '', ]; $mp = new MimePart($content); $mp ->setFileName($filename) ->setType($headers['mimetype']) ->setDisposition($headers['disposition']) ->setEncoding($headers['encoding']) ->setCharset($headers['charset']) ->setBoundary($headers['boundary']) ->setId($headers['id']) ->setDescription($headers['description']) ->setLocation($headers['location']) ->setLanguage($headers['language']) ; $this->attachments[] = $mp; }
Add a mail attachment by specifying its raw binary data, specifying the headers of the mail MIME part. @param string $content The binary data of the attachemt @param string $filename The name to give to the attachment (it will be used as the filename part of the Content-Disposition header) @param array $headers Additional headers fo the MIME part. Valid values are: - mimetype: the main value of the Content-Type header [default: application/octet-stream] - disposition: the main value of the Content-Disposition header [default: attachment] - encoding: the value of the Content-Transfer-Encoding header [default: base64] - charset: the charset value of the Content-Type header - boundary: the boundary value of the Content-Type header - id: the value of the Content-ID header (without angular brackets) - description: the value of the Content-Description header - location: the value of the Content-Location header - language: the value of the Content-Language header
addRawAttachmentWithHeaders
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function load($template, $pkgHandle = null) { extract($this->data); if (file_exists(DIR_FILES_EMAIL_TEMPLATES . "/{$template}.php")) { include DIR_FILES_EMAIL_TEMPLATES . "/{$template}.php"; } else { if ($pkgHandle != null) { if (is_dir(DIR_PACKAGES . '/' . $pkgHandle)) { include DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_MAIL_TEMPLATES . "/{$template}.php"; } else { include DIR_PACKAGES_CORE . '/' . $pkgHandle . '/' . DIRNAME_MAIL_TEMPLATES . "/{$template}.php"; } } else { include DIR_FILES_EMAIL_TEMPLATES_CORE . "/{$template}.php"; } } if (isset($from) && is_array($from) && isset($from[0])) { $this->from($from[0], isset($from[1]) ? $from[1] : null); } $this->template = $template; if (isset($subject)) { $this->subject = $subject; } $this->body = (isset($body) && is_string($body)) ? $body : false; $this->bodyHTML = (isset($bodyHTML) && is_string($bodyHTML)) ? $bodyHTML : false; }
Load an email template from the /mail/ directory. @param string $template The template to load @param string|null $pkgHandle The handle of the package associated to the template
load
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function setBody($body) { $this->body = $body; }
Manually set the plain text body of a mail message (typically the body is set in the template + load method). @param string|false $body Set the text body (false to not use a plain text body)
setBody
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function setSubject($subject) { $this->subject = $subject; }
Manually set the message's subject (typically the body is set in the template + load method). @param string $subject
setSubject
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function getSubject() { return $this->subject; }
Get the message subject. @return string
getSubject
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function getBody() { return $this->body; }
Get the plain text body. @return string|false
getBody
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function getBodyHTML() { return $this->bodyHTML; }
Get the html body. @return string|false
getBodyHTML
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function setBodyHTML($html) { $this->bodyHTML = $html; }
Manually set the HTML body of a mail message (typically the body is set in the template + load method). @param string|false $html Set the html body (false to not use an HTML body)
setBodyHTML
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function enableMailResponseProcessing($importer, $data) { foreach ($this->to as $em) { $importer->setupValidation($em[0], $data); } $this->from($importer->getMailImporterEmail()); $this->body = $importer->setupBody(($this->body === false) ? '' : $this->body); }
@param \Concrete\Core\Mail\Importer\MailImporter $importer @param array $data
enableMailResponseProcessing
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function from($email, $name = null) { $this->from = [$email, $name]; }
Set the from address on the message. @param string $email @param string|null $name
from
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function to($email, $name = null) { if (strpos($email, ',') > 0) { $email = explode(',', $email); foreach ($email as $em) { $this->to[] = [$em, $name]; } } else { $this->to[] = [$email, $name]; } }
Add one or more "To" recipients to the message. @param string $email (separate multiple email addresses with commas) @param string|null $name The name to associate to the email address
to
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function cc($email, $name = null) { if (strpos($email, ',') > 0) { $email = explode(',', $email); foreach ($email as $em) { $this->cc[] = [$em, $name]; } } else { $this->cc[] = [$email, $name]; } }
Add one or more "CC" recipients to the message. @param string $email (separate multiple email addresses with commas) @param string|null $name The name to associate to the email address
cc
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function bcc($email, $name = null) { if (strpos($email, ',') > 0) { $email = explode(',', $email); foreach ($email as $em) { $this->bcc[] = [$em, $name]; } } else { $this->bcc[] = [$email, $name]; } }
Add one or more "BCC" recipients to the message. @param string $email (separate multiple email addresses with commas) @param string|null $name The name to associate to the email address
bcc
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function replyto($email, $name = null) { if (strpos($email, ',') > 0) { $email = explode(',', $email); foreach ($email as $em) { $this->replyto[] = [$em, $name]; } } else { $this->replyto[] = [$email, $name]; } }
Sets the Reply-To addresses of the message. @param string $email (separate multiple email addresses with commas) @param string|null $name The name to associate to the email address
replyto
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function setTesting($testing) { $this->testing = $testing ? true : false; }
Set the testing state (if true the email logging never occurs and sending errors will throw an exception). @param bool $testing
setTesting
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function getTesting() { return $this->testing; }
Retrieve the testing state. @return bool
getTesting
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function setIsThrowOnFailure($throwOnFailure) { $this->throwOnFailure = (bool) $throwOnFailure; return $this; }
Should an exception be thrown if the delivery fails (if false, the sendMail() method will simply return false on failure). @param bool $throwOnFailure @return $this
setIsThrowOnFailure
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function isThrowOnFailure() { return $this->throwOnFailure; }
Should an exception be thrown if the delivery fails (if false, the sendMail() method will simply return false on failure). @return bool
isThrowOnFailure
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function setAdditionalHeaders($headers) { $this->headers = $headers; }
Set additional message headers. @param array $headers
setAdditionalHeaders
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function sendMail($resetData = true) { $config = $this->app->make('config'); $fromStr = $this->generateEmailStrings([$this->from]); $toStr = $this->generateEmailStrings($this->to); $replyStr = $this->generateEmailStrings($this->replyto); $mail = (new Message())->setEncoding(APP_CHARSET); if (is_array($this->from) && count($this->from)) { if ($this->from[0] != '') { $from = $this->from; } } if (!isset($from)) { $from = [$config->get('concrete.email.default.address'), $config->get('concrete.email.default.name')]; $fromStr = $config->get('concrete.email.default.address'); } // The currently included Laminas library has a bug in setReplyTo that // adds the Reply-To address as a recipient of the email. We must // set the Reply-To before any header with addresses and then clear // all recipients so that a copy is not sent to the Reply-To address. if (is_array($this->replyto)) { foreach ($this->replyto as $reply) { $mail->setReplyTo($reply[0], $reply[1]); } } $mail->setFrom($from[0], $from[1]); $mail->setSubject($this->subject); foreach ($this->to as $to) { $mail->addTo($to[0], $to[1]); } if (is_array($this->cc) && count($this->cc)) { foreach ($this->cc as $cc) { $mail->addCc($cc[0], $cc[1]); } } if (is_array($this->bcc) && count($this->bcc)) { foreach ($this->bcc as $bcc) { $mail->addBcc($bcc[0], $bcc[1]); } } $headers = $mail->getHeaders(); if ($headers->has('messageid')) { $messageIdHeader = $headers->get('messageid'); } else { $messageIdHeader = new MessageIdHeader(); $headers->addHeader($messageIdHeader); } $headers->addHeaders($this->headers); $messageIdHeader->setId(); $body = new MimeMessage(); $textPart = $this->buildTextPart(); $htmlPart = $this->buildHtmlPart(); if ($textPart === null && $htmlPart === null) { $emptyPart = new MimePart(''); $emptyPart->setType(Mime::TYPE_TEXT); $emptyPart->setCharset(APP_CHARSET); $body->addPart($emptyPart); } elseif ($textPart !== null && $htmlPart !== null) { $alternatives = new MimeMessage(); $alternatives->addPart($textPart); $alternatives->addPart($htmlPart); $alternativesPart = new MimePart($alternatives->generateMessage()); $alternativesPart->setType(Mime::MULTIPART_ALTERNATIVE); $alternativesPart->setBoundary($alternatives->getMime()->boundary()); $body->addPart($alternativesPart); } else { if ($textPart !== null) { $body->addPart($textPart); } if ($htmlPart !== null) { $body->addPart($htmlPart); } } foreach ($this->attachments as $attachment) { if (!$this->isInlineAttachment($attachment)) { $body->addPart($attachment); } } $mail->setBody($body); $sendError = null; if ($config->get('concrete.email.enabled')) { try { $this->transport->send($mail); } catch (Exception $x) { $sendError = $x; } catch (Throwable $x) { $sendError = $x; } } if ($sendError !== null) { if ($this->getTesting()) { throw $sendError; } $l = new GroupLogger(Channels::CHANNEL_EXCEPTIONS, Logger::CRITICAL); $l->write(t('Mail Exception Occurred. Unable to send mail: ') . $sendError->getMessage()); $l->write($sendError->getTraceAsString()); $l->close(); } if ($this->isMetaDataLoggingEnabled() && !$this->getTesting()) { $l = new GroupLogger(Channels::CHANNEL_EMAIL, Logger::NOTICE); $l->write(t('Template Used') . ': ' . $this->template); $l->write(t('To') . ': ' . $toStr); $l->write(t('From') . ': ' . $fromStr); if (isset($this->replyto)) { $l->write(t('Reply-To') . ': ' . $replyStr); } $l->write(t('Subject') . ': ' . $this->subject); $l->write(t('Body') . ': ' . $this->body); if ($config->get('concrete.email.enabled')) { if ($sendError === null) { $l->write('**' . t('EMAILS ARE ENABLED. THIS EMAIL HAS BEEN SENT') . '**'); } else { $l->write('**' . t('EMAILS ARE ENABLED. THIS EMAIL HAS NOT BEEN SENT') . '**'); } } else { $l->write('**' . t('EMAILS ARE DISABLED. THIS EMAIL WAS LOGGED BUT NOT SENT') . '**'); } $l->write(t('Template Used') . ': ' . $this->template); if ($this->isBodyLoggingEnabled()) { // Clone the mail without attachments for logging $mailWithoutAttachments = clone $mail; $attachedFiles = []; if ($mailWithoutAttachments->getBody() instanceof \Laminas\Mime\Message) { $parts = $mailWithoutAttachments->getBody()->getParts(); if (is_array($parts)) { foreach ($parts as $key => $part) { $partHeaders = $part->getHeadersArray(); if (!(isset($partHeaders["disposition"]) && $partHeaders["disposition"] === Mime::DISPOSITION_ATTACHMENT)) { $attachedFiles[] = $part->getFileName(); unset($parts[$key]); } } $mailWithoutAttachments->getBody()->setParts($parts); } } $mailDetails = $mailWithoutAttachments->toString(); $encoding = $mailWithoutAttachments->getHeaders()->get('Content-Transfer-Encoding'); if (is_object($encoding) && $encoding->getFieldValue() === 'quoted-printable') { $mailDetails = quoted_printable_decode($mailDetails); } // append the attached file names to the mail log foreach($attachedFiles as $attachedFile) { $mailDetails .= t("[Attached File: %s]" , $attachedFile) . Headers::EOL; } $l->write(t('Mail Details: %s', $mailDetails)); } $l->close(); } if ($sendError !== null && $this->isThrowOnFailure()) { if ($resetData) { $this->reset(); } throw $sendError; } // clear data if applicable if ($resetData) { $this->reset(); } return $sendError === null; }
Sends the email. @param bool $resetData Whether or not to reset the service to its default when this method is done @throws Exception Throws an exception if the delivery fails and if the service is in "testing" state or throwOnFailure is true @return bool Returns true upon success, or false if the delivery fails and if the service is not in "testing" state and throwOnFailure is false
sendMail
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public static function getMailerObject() { $app = ApplicationFacade::getFacadeApplication(); return [ 'mail' => (new Message())->setEncoding(APP_CHARSET), 'transport' => $app->make(TransportInterface::class), ]; }
@deprecated To get the mail transport, call \Core::make(\Laminas\Mail\Transport\TransportInterface::class)
getMailerObject
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
protected function generateEmailStrings($arr) { $str = ''; for ($i = 0; $i < count($arr); ++$i) { $v = $arr[$i]; if (isset($v[1])) { $str .= '"' . $v[1] . '" <' . $v[0] . '>'; } elseif (isset($v[0])) { $str .= $v[0]; } if (($i + 1) < count($arr)) { $str .= ', '; } } return $str; }
Convert a list of email addresses to a string. @param array $arr @return string
generateEmailStrings
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
protected function buildTextPart() { if ($this->body === false) { $result = null; } else { $result = new MimePart($this->body); $result->setType(Mime::TYPE_TEXT); $result->setCharset(APP_CHARSET); $result->setEncoding(Mime::ENCODING_QUOTEDPRINTABLE); } return $result; }
Get the MIME part for the plain text body (if available). @return MimePart|null
buildTextPart
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
protected function isInlineAttachment(MimePart $attachment) { return $this->bodyHTML !== false && $attachment->getId() && in_array((string) $attachment->getDisposition(), ['', Mime::DISPOSITION_INLINE], true) ; }
Determine if an attachment should be used as an inline attachment associated to the HTML body. @param MimePart $attachment @return bool
isInlineAttachment
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
protected function buildHtmlPart() { if ($this->bodyHTML === false) { $result = null; } else { $html = new MimePart($this->bodyHTML); $html->setType(Mime::TYPE_HTML); $html->setCharset(APP_CHARSET); $html->setEncoding(Mime::ENCODING_QUOTEDPRINTABLE); $inlineAttachments = []; foreach ($this->attachments as $attachment) { if ($this->isInlineAttachment($attachment)) { $inlineAttachments[] = $attachment; } } if (empty($inlineAttachments)) { $result = $html; } else { $related = new MimeMessage(); $related->addPart($html); foreach ($inlineAttachments as $inlineAttachment) { $related->addPart($inlineAttachment); } $result = new MimePart($related->generateMessage()); $result->setType(Mime::MULTIPART_RELATED); $result->setBoundary($related->getMime()->boundary()); } } return $result; }
Get the MIME part for the plain text body (if available). @return MimePart|null
buildHtmlPart
php
concretecms/concretecms
concrete/src/Mail/Service.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Service.php
MIT
public function getProcessedBody() { $r = preg_split(MailImporter::getMessageBodyHashRegularExpression(), $this->body); $message = $r[0]; $r = preg_replace(array( '/^On (.*) at (.*), (.*) wrote:/sm', '/[\n\r\s\>]*\Z/i', ), '', $message); return $r; }
Returns the relevant content of the email message, minus any quotations, and the line that includes the validation hash.
getProcessedBody
php
concretecms/concretecms
concrete/src/Mail/Importer/MailImportedMessage.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Importer/MailImportedMessage.php
MIT
public function validate() { if (!$this->validationHash) { return false; } $db = Database::connection(); $row = $db->GetRow("select * from MailValidationHashes where mHash = ? order by mDateGenerated desc limit 1", $this->validationHash); if ($row['mvhID'] > 0) { // Can't do this even though it's a good idea //if ($row['email'] != $this->sender) { // return false; //} else { return $row['mDateRedeemed'] == 0; //} } }
Validates the email message - checks the validation hash found in the body with one in the database. Checks the from address as well.
validate
php
concretecms/concretecms
concrete/src/Mail/Importer/MailImportedMessage.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Importer/MailImportedMessage.php
MIT
public function delete() { $this->oMail->removeMessage($this->oMail->getNumberByUniqueId($this->oMailID)); }
Deletes this mail by unique id
delete
php
concretecms/concretecms
concrete/src/Mail/Importer/MailImportedMessage.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Importer/MailImportedMessage.php
MIT
public function moveTo($folder) { $this->oMail->moveMessage($this->oMail->getNumberByUniqueId($this->oMailID), $folder); }
Moves this mail by unique id (folder starts with '/')
moveTo
php
concretecms/concretecms
concrete/src/Mail/Importer/MailImportedMessage.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Importer/MailImportedMessage.php
MIT
public function isSendError() { $message = $this->getOriginalMessageObject(); $headers = $message->getHeaders(); $isSendError = false; if (is_array($headers) && count($headers)) { foreach (array_keys($headers) as $key) { if (strstr($key, 'x-fail') !== false) { $isSendError = true; break; } } } return $isSendError; }
checks to see if the message is a bounce or delivery failure. @return bool
isSendError
php
concretecms/concretecms
concrete/src/Mail/Importer/MailImportedMessage.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Importer/MailImportedMessage.php
MIT
public function getMessageBodyHeader() { return t('--- Reply ABOVE. Do not alter this line --- [' . $this->validationHash . '] ---'); }
gets the text string that's used to identify the body of the message. @return string
getMessageBodyHeader
php
concretecms/concretecms
concrete/src/Mail/Importer/MailImporter.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Importer/MailImporter.php
MIT
public function createTransportFromConfig(Repository $config) { return $this->createTransportFromArray($config->get('concrete.mail')); }
* Create a Transport instance from a configuration repository. @param Repository $config @return \Laminas\Mail\Transport\TransportInterface
createTransportFromConfig
php
concretecms/concretecms
concrete/src/Mail/Transport/Factory.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Transport/Factory.php
MIT
public function createTransportFromArray(array $array) { switch (array_get($array, 'method')) { case 'smtp': return $this->createSmtpTransportFromArray(array_get($array, 'methods.smtp')); case 'PHP_MAIL': default: return $this->createPhpMailTransportFromArray(array_get($array, 'methods.php_mail') ?: []); } }
Create a Transport instance from a configuration array. @param array $array @return \Laminas\Mail\Transport\TransportInterface
createTransportFromArray
php
concretecms/concretecms
concrete/src/Mail/Transport/Factory.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Transport/Factory.php
MIT
public function createPhpMailTransportFromArray(array $array) { $parameters = isset($array['parameters']) ? $array['parameters'] : ''; return new SendmailTransport($parameters); }
@param array $array @return \Laminas\Mail\Transport\Sendmail
createPhpMailTransportFromArray
php
concretecms/concretecms
concrete/src/Mail/Transport/Factory.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Transport/Factory.php
MIT
public function getSmtpTransport() { return $this->transport; }
Get the actual transport instance. @return \Laminas\Mail\Transport\Smtp
getSmtpTransport
php
concretecms/concretecms
concrete/src/Mail/Transport/LimitedSmtp.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Transport/LimitedSmtp.php
MIT
public function send(Message $message) { $this->transport->send($message); $this->trackLimit(); }
{@inheritdoc} @see \Laminas\Mail\Transport\TransportInterface::send()
send
php
concretecms/concretecms
concrete/src/Mail/Transport/LimitedSmtp.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Transport/LimitedSmtp.php
MIT
private function trackLimit() { ++$this->sent; if ($this->sent >= $this->limit) { $this->sent = 0; $this->transport->disconnect(); } }
Increment the counter of sent messages and disconnect the underlying transport if needed.
trackLimit
php
concretecms/concretecms
concrete/src/Mail/Transport/LimitedSmtp.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Mail/Transport/LimitedSmtp.php
MIT
public static function downloadRemoteFile($file) { // Get the marketplace instance $marketplace = static::getInstance(); $file .= '?csiURL=' . urlencode($marketplace->getSiteURL()) . '&csiVersion=' . APP_VERSION; $timestamp = time(); $tmpFile = $marketplace->fileHelper->getTemporaryDirectory() . '/' . $timestamp . '.zip'; $error = $marketplace->app->make('error'); $chunksize = 1 * (1024 * 1024); // split into 1MB chunks $handle = fopen($file, 'rb'); $fp = fopen($tmpFile, 'w'); if ($handle === false) { $error->add(t('An error occurred while downloading the package.')); } elseif ($fp === false) { $error->add(t('Concrete was not able to save the package.')); } else { while (!feof($handle)) { $data = fread($handle, $chunksize); $data = is_numeric($data) ? (int) $data : $data; if ($data === Package::E_PACKAGE_INVALID_APP_VERSION) { $error->add(t('This package isn\'t currently available for this version of Concrete . Please contact the maintainer of this package for assistance.')); } else { fwrite($fp, $data, strlen($data)); } } fclose($handle); fclose($fp); } if ($error->has()) { if (file_exists($tmpFile)) { @unlink($tmpFile); } return $error; } return $timestamp; }
@param $file @return int|mixed|string
downloadRemoteFile
php
concretecms/concretecms
concrete/src/Marketplace/Marketplace.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Marketplace/Marketplace.php
MIT
public static function checkPackageUpdates() { $marketplace = static::getInstance(); $skipPackages = $marketplace->config->get('concrete.updates.skip_packages'); if ($skipPackages === true) { return; } if (!$skipPackages) { // In case someone uses false or NULL or an empty string $skipPackages = []; } else { // In case someone uses a single package handle $skipPackages = (array) $skipPackages; } /** @var EntityManagerInterface $em */ $em = $marketplace->app->make(EntityManagerInterface::class); /** @var PackageService $packageService */ $packageService = $marketplace->app->make(PackageService::class); $items = self::getAvailableMarketplaceItems(false); foreach ($items as $i) { if (in_array($i->getHandle(), $skipPackages, true)) { continue; } $p = $packageService->getByHandle($i->getHandle()); if (is_object($p)) { /** * @var \Concrete\Core\Entity\Package $p */ $p->setPackageAvailableVersion($i->getVersion()); $em->persist($p); } } $em->flush(); }
Runs through all packages on the marketplace, sees if they're installed here, and updates the available version number for them.
checkPackageUpdates
php
concretecms/concretecms
concrete/src/Marketplace/Marketplace.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Marketplace/Marketplace.php
MIT
private function get($url) { try { $result = $this->fileHelper->getContents( $url, $this->config->get('concrete.marketplace.request_timeout') ); } catch (Exception $e) { $this->connectionError = self::E_GENERAL_CONNECTION_ERROR; return null; } if ($result === false) { $this->connectionError = self::E_GENERAL_CONNECTION_ERROR; } return $result ?: null; }
Get the contents of a URL. @param $url @return string|null
get
php
concretecms/concretecms
concrete/src/Marketplace/Marketplace.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Marketplace/Marketplace.php
MIT
public function update(ConnectionInterface $connection, array $updatedFields): void { try { $formParams = []; foreach ($updatedFields as $field) { $formParams[$field->getName()] = $field->getData(); } $request = $this->authenticate($this->requestFor('POST', 'update'), $connection); $response = $this->client->post($request->getUri(), ['form_params' => $formParams]); } catch (\Exception $e) { // https://github.com/concretecms/concretecms/issues/12079 // We don't want to be noisy _every_ when doing these updates. throw new ErrorSavingRemoteDataException($e->getMessage()); } }
@param ConnectionInterface $connection @param UpdatedFieldInterface[] $updatedFields @return void
update
php
concretecms/concretecms
concrete/src/Marketplace/PackageRepository.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Marketplace/PackageRepository.php
MIT
public static function getByHandle($mpHandle) { return self::getRemotePackageObject('mpHandle', $mpHandle); }
@return \Concrete\Core\Marketplace\RemoteItem; @param $mpID @throws Exception
getByHandle
php
concretecms/concretecms
concrete/src/Marketplace/RemoteItem.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Marketplace/RemoteItem.php
MIT
public static function getByID($mpID) { return self::getRemotePackageObject('mpID', $mpID); }
@return \Concrete\Core\Marketplace\RemoteItem; @param $mpID @throws Exception
getByID
php
concretecms/concretecms
concrete/src/Marketplace/RemoteItem.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Marketplace/RemoteItem.php
MIT
private function shouldHandle(Envelope $envelope, HandlerDescriptor $handlerDescriptor): bool { if (null === $received = $envelope->last(ReceivedStamp::class)) { return true; } if (null === $expectedTransport = $handlerDescriptor->getOption('from_transport')) { return true; } return $received->getTransportName() === $expectedTransport; }
Note: This was taken from the Symfony HandlersLocator class. I wish it were a trait or something more reusable but the logic seems important so we should add it to our own. @param Envelope $envelope @param HandlerDescriptor $handlerDescriptor @return bool
shouldHandle
php
concretecms/concretecms
concrete/src/Messenger/HandlersLocator.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Messenger/HandlersLocator.php
MIT
public function __construct(EntityManager $entityManager, TransportManager $transportManager) { $this->entityManager = $entityManager; $this->transportManager = $transportManager; }
MessengerConsumeResponseFactory constructor. @param EntityManager $entityManager @param TransportManager $transportManager
__construct
php
concretecms/concretecms
concrete/src/Messenger/MessengerConsumeResponseFactory.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Messenger/MessengerConsumeResponseFactory.php
MIT
public static function getByID($cID, $cvID = 'RECENT') { $entity = self::getLocaleFromHomePageID($cID); if ($entity) { $obj = parent::getByID($cID, $cvID); $obj->setLocale($entity); return $obj; } return false; }
Returns an instance of MultilingualSection for the given page ID. @param int $cID @param int|string $cvID @return self|false
getByID
php
concretecms/concretecms
concrete/src/Multilingual/Page/Section/Section.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Page/Section/Section.php
MIT
public function getNumberOfPluralForms() { return (int) $this->locale->getNumPlurals(); }
Returns the number of plural forms. @return int @example For Japanese: returns 1 @example For English: returns 2 @example For French: returns 2 @example For Russian returns 3
getNumberOfPluralForms
php
concretecms/concretecms
concrete/src/Multilingual/Page/Section/Section.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Page/Section/Section.php
MIT
public function getPluralsRule() { return (string) $this->locale->getPluralRule(); }
Returns the rule to determine which plural we should use (in gettext notation). @return string @example For Japanese: returns '0' @example For English: returns 'n != 1' @example For French: returns 'n > 1' @example For Russian returns '(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2)'
getPluralsRule
php
concretecms/concretecms
concrete/src/Multilingual/Page/Section/Section.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Page/Section/Section.php
MIT
public static function getByLanguage($language, ?Site $site = null) { if (!$site) { $site = \Core::make('site')->getSite(); } $em = Database::get()->getEntityManager(); /** * @var $section Locale */ $section = $em->getRepository('Concrete\Core\Entity\Site\Locale') ->findOneBy(['site' => $site, 'msLanguage' => $language]); if (is_object($section)) { $obj = parent::getByID($section->getSiteTree()->getSiteHomePageID(), 'RECENT'); $obj->setLocale($section); return $obj; } return false; }
@param string $language @return Section|false
getByLanguage
php
concretecms/concretecms
concrete/src/Multilingual/Page/Section/Section.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Page/Section/Section.php
MIT
public static function getByLocale($locale, ?Site $site = null) { if (!$site) { $site = \Core::make('site')->getSite(); } if ($locale) { if (!is_object($locale)) { $locale = explode('_', $locale); if (!isset($locale[1])) { $locale[1] = ''; } $em = Database::get()->getEntityManager(); $locale = $em->getRepository('Concrete\Core\Entity\Site\Locale') ->findOneBy(['site' => $site, 'msLanguage' => $locale[0], 'msCountry' => $locale[1]]); } if (is_object($locale)) { $obj = parent::getByID($locale->getSiteTree()->getSiteHomePageID(), 'RECENT'); $obj->setLocale($locale); return $obj; } } return false; }
@param string $language @return Section|false
getByLocale
php
concretecms/concretecms
concrete/src/Multilingual/Page/Section/Section.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Page/Section/Section.php
MIT
public static function getCurrentSection() { static $lang; if (!isset($lang)) { $c = Page::getCurrentPage(); if ($c instanceof Page) { $lang = self::getBySectionOfSite($c); } } return $lang; }
Gets the MultilingualSection object for the current section of the site. @return Section
getCurrentSection
php
concretecms/concretecms
concrete/src/Multilingual/Page/Section/Section.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Page/Section/Section.php
MIT
public function getTranslatedPageID($page) { $ids = static::getIDList(); if (in_array($page->getCollectionID(), $ids)) { return $this->locale->getSiteTree()->getSiteHomePageID(); } $mpRelationID = self::getMultilingualPageRelationID($page->getCollectionID()); if ($mpRelationID) { $cID = self::getCollectionIDForLocale($mpRelationID, $this->getLocale()); return $cID; } }
Receives a page in a different language tree, and tries to return the corresponding page in the current language tree. @return int|null
getTranslatedPageID
php
concretecms/concretecms
concrete/src/Multilingual/Page/Section/Section.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Page/Section/Section.php
MIT
public function getSectionInterfaceTranslations($untranslatedFirst = false) { $translations = new Translations(); $translations->setLanguage($this->getLocale()); $translations->setPluralForms($this->getNumberOfPluralForms(), $this->getPluralsRule()); $db = \Database::get(); $r = $db->query( "select * from MultilingualTranslations where mtSectionID = ? order by ".($untranslatedFirst ? "if(ifnull(msgstr, '') = '', 0, 1), " : "")."mtID", [$this->getCollectionID()] ); while ($row = $r->fetch()) { $t = Translation::getByRow($row); if (isset($t)) { $translations[] = $t; } } return $translations; }
Loads the translations of this multilingual section. @param bool $untranslatedFirst Set to true to have untranslated strings first @return \Gettext\Translations
getSectionInterfaceTranslations
php
concretecms/concretecms
concrete/src/Multilingual/Page/Section/Section.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Page/Section/Section.php
MIT
public function getActiveSection(Page $c): ?Section { if ($this->cache->isEnabled()) { $key = '/multilingual/detector/section/' . $c->getCollectionID(); $item = $this->cache->getItem($key); if ($item->isHit()) { return $item->get(); } } $locale = null; $al = Section::getBySectionOfSite($c); if ($al) { $locale = $al->getLocale(); } if (!$locale) { $locale = Localization::activeLocale(); $al = Section::getByLocale($locale); } if ($al) { if (isset($item) && $item->isMiss()) { $item->set($al); $this->cache->save($item); } return $al; } return null; }
Returns the Multilingual Page Section based on the Page object. @param Page $c @return Section|null
getActiveSection
php
concretecms/concretecms
concrete/src/Multilingual/Service/Detector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Service/Detector.php
MIT
public function getActiveLocale(Page $c): string { if ($this->cache->isEnabled()) { $key = '/multilingual/detector/locale/' . $c->getCollectionID(); $item = $this->cache->getItem($key); if ($item->isHit()) { return $item->get(); } } $al = $this->getActiveSection($c); if ($al) { $locale = $al->getLocale(); } else { $locale = Localization::activeLocale(); } if (isset($item) && $item->isMiss()) { $item->set($locale); $this->cache->save($item); } return $locale; }
Returns the locale string (e.g. en_US) based on the Page object. @param Page $c @return string
getActiveLocale
php
concretecms/concretecms
concrete/src/Multilingual/Service/Detector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Service/Detector.php
MIT
public function getAvailableSections(): array { if ($this->cache->isEnabled()) { $key = '/multilingual/detector/section/list'; $item = $this->cache->getItem($key); if ($item->isHit()) { return $item->get(); } } $sections = Section::getList($this->getSite()); if (isset($item) && $item->isMiss()) { $item->set($sections); $this->cache->save($item); } return $sections; }
Returns all Multilingual Sections on the current site. @return Section[]
getAvailableSections
php
concretecms/concretecms
concrete/src/Multilingual/Service/Detector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Service/Detector.php
MIT
public function getRelatedPage(Page $currentPage, Section $targetSection): Page { if ($this->cache->isEnabled()) { $key = '/multilingual/detector/link/' . $currentPage->getCollectionID() . '/' . $targetSection->getCollectionID(); $item = $this->cache->getItem($key); if ($item->isHit()) { return $item->get(); } } $relatedPage = null; if ($currentPage->isGeneratedCollection() && $currentPage->getSiteTreeID() == 0) { // If the current page is a single page, there is no translated page. $relatedPage = $currentPage; } else { $relatedID = $targetSection->getTranslatedPageID($currentPage); if ($relatedID) { $c = Page::getByID($relatedID); if ($c) { $relatedPage = $c; } } } // If we fail to get a translated page, get the home page of the target language as a fallback. if (!$relatedPage) { $relatedPage = $targetSection; } if (isset($item) && $item->isMiss()) { $item->set($relatedPage); $this->cache->save($item); } return $relatedPage; }
Returns a translated page based on the Page object. @param Page $currentPage @param Section $targetSection @return Section|Page
getRelatedPage
php
concretecms/concretecms
concrete/src/Multilingual/Service/Detector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Service/Detector.php
MIT
public function getSwitchLink($currentPageID, $targetSectionID): string { /** @var ResolverManagerInterface $resolver */ $resolver = $this->app->make(ResolverManagerInterface::class); return (string) $resolver->resolve(['/ccm/frontend/multilingual/switch_language', $currentPageID, $targetSectionID]); }
Get a switch language link URL to redirect to the target section from the current page. @param mixed $currentPageID @param mixed $targetSectionID
getSwitchLink
php
concretecms/concretecms
concrete/src/Multilingual/Service/Detector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Service/Detector.php
MIT
public function getPreferredSection() { if ($this->preferredSection === false) { /** @var Session $session */ $session = $this->app->make('session'); /** @var Strings $stringsValidator */ $stringsValidator = $this->app->make(Strings::class); $section = null; $default_locale = null; if ($section === null) { $locale = false; // Detect locale by value stored in session or cookie if ($this->canSetSessionValue() && $session->has('multilingual_default_locale')) { $locale = $session->get('multilingual_default_locale'); } else { $cookie = $this->app->make('cookie'); if ($cookie->has('multilingual_default_locale')) { $locale = $cookie->get('multilingual_default_locale'); } } if ($locale) { $home = Section::getByLocale($locale); if (is_object($home)) { $section = $home; $default_locale = $locale; } } } if ($section === null) { // Detect locale by user's preferred language $u = $this->app->make(User::class); if ($u->isRegistered()) { $userDefaultLanguage = $u->getUserDefaultLanguage(); if ($userDefaultLanguage) { $home = Section::getByLocaleOrLanguage($userDefaultLanguage); if (is_object($home)) { $section = $home; $default_locale = $home->getLocale(); } } } } if ($section === null) { // Detect locale by browsers headers $siteConfig = $this->getSite()->getConfigRepository(); if ($siteConfig->get('multilingual.use_browser_detected_locale')) { $browserLocales = Misc::getBrowserLocales(); foreach (array_keys($browserLocales) as $browserLocale) { $home = Section::getByLocaleOrLanguage($browserLocale); if (is_object($home)) { $section = $home; $default_locale = $browserLocale; break; } } } } if ($section === null) { // Use the default site locale $locale = $this->getSite()->getDefaultLocale(); if (is_object($locale)) { $home = Section::getByLocale($locale->getLocale()); if ($home) { $section = $home; $default_locale = $locale->getLocale(); } } } if ($section !== null && $stringsValidator->notempty($default_locale) && $this->canSetSessionValue()) { $session->set('multilingual_default_locale', $default_locale); } $this->preferredSection = $section; } return $this->preferredSection; }
Returns the preferred section based on session, cookie, user object, default browser (if allowed), and finally site preferences. Since the user's language is not a locale but a language, attempts to determine best section for the given language. @return Section|null
getPreferredSection
php
concretecms/concretecms
concrete/src/Multilingual/Service/Detector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Service/Detector.php
MIT
public function setupSiteInterfaceLocalization(?Page $c = null) { $loc = $this->app->make(Localization::class); $locale = null; if ($c === null) { $c = Page::getCurrentPage(); } if ($c) { $pageController = $c->getPageController(); if (is_object($pageController) && is_callable([$pageController, 'useUserLocale'])) { $useUserLocale = $pageController->useUserLocale(); } else { $dh = $this->app->make('helper/concrete/dashboard'); $useUserLocale = $dh->inDashboard($c); } if ($useUserLocale) { $u = $this->app->make(User::class); $locale = $u->getUserLanguageToDisplay(); } else { if ($this->isEnabled()) { $ms = Section::getBySectionOfSite($c); if (!$ms) { $ms = $this->getPreferredSection(); } if ($ms) { $locale = $ms->getLocale(); if ($this->canSetSessionValue()) { $this->app->make('session')->set('multilingual_default_locale', $locale); } } } if (!$locale) { $siteTree = $c->getSiteTreeObject(); if ($siteTree) { $locale = $siteTree->getLocale()->getLocale(); } } } } if (!$locale) { $localeEntity = $this->getSite()->getDefaultLocale(); if ($localeEntity) { $locale = $localeEntity->getLocale(); } } if (!$locale) { $locale = $this->app->make('config')->get('concrete.locale'); } $loc->setContextLocale(Localization::CONTEXT_SITE, $locale); }
Set the locale associated to the 'site' localization context. @param Page $c The page to be used to determine the site locale (if null we'll use the current page) @throws \Exception
setupSiteInterfaceLocalization
php
concretecms/concretecms
concrete/src/Multilingual/Service/Detector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Service/Detector.php
MIT
public function isEnabled() { if ($this->enabled === null) { $result = false; if ($this->app->isInstalled()) { $site = $this->getSite(); if (count($site->getLocales()) > 1) { $result = true; } } $this->enabled = $result; } return $this->enabled; }
Check if there's some multilingual section. @throws \Exception @return bool
isEnabled
php
concretecms/concretecms
concrete/src/Multilingual/Service/Detector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Service/Detector.php
MIT
public function assumeEnabled() { $this->enabled = true; return $this; }
Assume that the site is multilingual enabled. @return $this
assumeEnabled
php
concretecms/concretecms
concrete/src/Multilingual/Service/Detector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Service/Detector.php
MIT
protected function canSetSessionValue() { // If we already started the session, return true. if ($this->app->make(SessionValidatorInterface::class)->hasActiveSession()) { return true; } // If the site config value is true, it may start a new session without sign in to concrete5. $site = $this->getSite(); if ($site !== null) { $siteConfig = $site->getConfigRepository(); return (bool) $siteConfig->get('multilingual.always_track_user_locale'); } return false; }
Check if we can set a session value. @return bool
canSetSessionValue
php
concretecms/concretecms
concrete/src/Multilingual/Service/Detector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Multilingual/Service/Detector.php
MIT