idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
18,100
protected function addTarget ( CNabuSiteTarget $ nb_site_target , $ default = false ) { $ nb_site = $ this -> nb_engine -> getHTTPServer ( ) -> getSite ( ) ; if ( $ nb_site instanceof CNabuSite ) { return $ nb_site -> addTarget ( $ nb_site_target , $ default ) ; } else { throw new ENabuCoreException ( ENabuCoreException :: ERROR_SITE_NOT_INSTANTIATED ) ; } }
Adds an existing Site Target instance to the list of targets .
18,101
public function setLoginTarget ( CNabuSiteTarget $ nb_site_target ) { $ nb_site = $ this -> nb_engine -> getHTTPServer ( ) -> getSite ( ) ; if ( $ nb_site instanceof CNabuSite ) { return $ nb_site -> setLoginTarget ( $ nb_site_target ) ; } else { throw new ENabuCoreException ( ENabuCoreException :: ERROR_SITE_NOT_INSTANTIATED ) ; } }
Sets the Login Target when private zones are requested .
18,102
public function addRootSiteMapForURL ( $ order , CNabuRole $ nb_role = null ) { if ( $ nb_role === null ) { $ nb_role = $ this -> nb_engine -> getHTTPServer ( ) -> getSite ( ) -> getDefaultRole ( ) ; } $ nb_site_map = new CNabuBuiltInSiteMap ( ) ; $ nb_site_map -> setOrder ( $ order ) ; return $ this -> addRootSiteMap ( $ nb_site_map ) ; }
Adds a new Site Map root node of type URL .
18,103
public function addRootSiteMapForTarget ( CNabuSiteTarget $ nb_site_target , $ order , CNabuRole $ nb_role = null ) { if ( $ nb_role === null ) { $ nb_role = $ this -> nb_engine -> getHTTPServer ( ) -> getSite ( ) -> getDefaultRole ( ) ; } $ nb_site_map = new CNabuBuiltInSiteMap ( ) ; $ nb_site_map -> setSiteTarget ( $ nb_site_target ) -> setOrder ( $ order ) ; return $ this -> addRootSiteMap ( $ nb_site_map ) ; }
Adds a new Site Map root node of type Target .
18,104
public function addRootSiteMap ( CNabuSiteMap $ nb_site_map ) { $ nb_site = $ this -> nb_engine -> getHTTPServer ( ) -> getSite ( ) ; if ( $ nb_site instanceof CNabuSite ) { return $ nb_site -> addSiteMap ( $ nb_site_map ) ; } else { throw new ENabuCoreException ( ENabuCoreException :: ERROR_SITE_NOT_INSTANTIATED ) ; } }
Add an existing Site Map root node .
18,105
public function newMedioteca ( $ key ) { $ nb_medioteca = new CNabuBuiltInMedioteca ( ) ; $ nb_medioteca -> setKey ( $ key ) ; return $ this -> addMedioteca ( $ nb_medioteca ) ; }
Creates a new BuiltIn Medioteca and adds them to the Mediotecas Manager .
18,106
public function getPrimaryKey ( ) { if ( $ this -> primaryKey === null ) { $ schema = $ this -> getSchema ( ) ; $ pk = [ ] ; foreach ( $ schema -> getSchemaArray ( ) [ 'properties' ] as $ column => $ property ) { if ( ! empty ( $ property [ 'primary' ] ) ) { $ pk [ ] = $ column ; } } $ this -> primaryKey = $ pk ; } return $ this -> primaryKey ; }
Get the primaryKey .
18,107
protected function mapID ( $ id ) { $ idArray = ( array ) $ id ; $ result = [ ] ; foreach ( $ this -> getPrimaryKey ( ) as $ i => $ column ) { if ( isset ( $ idArray [ $ i ] ) ) { $ result [ $ column ] = $ idArray [ $ i ] ; } elseif ( isset ( $ idArray [ $ column ] ) ) { $ result [ $ column ] = $ idArray [ $ column ] ; } else { $ result [ $ column ] = null ; } } return $ result ; }
Map primary key values to the primary key name .
18,108
final public function getSchema ( ) { if ( $ this -> schema === null ) { $ this -> schema = $ this -> fetchSchema ( ) ; } return $ this -> schema ; }
Gets the row schema for this model .
18,109
protected function fetchSchema ( ) { $ columns = $ this -> getDb ( ) -> fetchColumnDefs ( $ this -> name ) ; if ( $ columns === null ) { throw new \ InvalidArgumentException ( "Cannot fetch schema foor {$this->name}." ) ; } $ schema = [ 'type' => 'object' , 'dbtype' => 'table' , 'properties' => $ columns ] ; $ required = $ this -> requiredFields ( $ columns ) ; if ( ! empty ( $ required ) ) { $ schema [ 'required' ] = $ required ; } return new Schema ( $ schema ) ; }
Fetch the row schema from the database meta info .
18,110
private function requiredFields ( array $ columns ) { $ required = [ ] ; foreach ( $ columns as $ name => $ column ) { if ( empty ( $ column [ 'autoIncrement' ] ) && ! isset ( $ column [ 'default' ] ) && empty ( $ column [ 'allowNull' ] ) ) { $ required [ ] = $ name ; } } return $ required ; }
Figure out the schema required fields from a list of columns .
18,111
public function get ( array $ where ) { $ options = [ Db :: OPTION_FETCH_MODE => $ this -> getFetchArgs ( ) , 'rowCallback' => [ $ this , 'unserialize' ] ] ; $ qry = new TableQuery ( $ this -> name , $ where , $ this -> db , $ options ) ; $ qry -> setLimit ( $ this -> getDefaultLimit ( ) ) -> setOrder ( ... $ this -> getDefaultOrder ( ) ) ; return $ qry ; }
Query the model .
18,112
public function query ( array $ where , array $ options = [ ] ) { $ options += [ 'order' => $ this -> getDefaultOrder ( ) , 'limit' => $ this -> getDefaultLimit ( ) , Db :: OPTION_FETCH_MODE => $ this -> getFetchArgs ( ) ] ; $ stmt = $ this -> db -> get ( $ this -> name , $ where , $ options ) ; return $ stmt ; }
Query the database directly .
18,113
public function updateID ( $ id , array $ set ) : int { $ r = $ this -> update ( $ set , $ this -> mapID ( $ id ) ) ; return $ r ; }
Update a row in the database with a known primary key .
18,114
public function validate ( $ row , $ sparse = false ) { $ schema = $ this -> getSchema ( ) ; $ valid = $ schema -> validate ( $ row , [ 'sparse' => $ sparse ] ) ; return $ valid ; }
Validate a row of data .
18,115
public function index ( ) { if ( ! userHasPermission ( 'admin:captcha:settings:*' ) ) { unauthorised ( ) ; } $ oDb = Factory :: service ( 'Database' ) ; $ oInput = Factory :: service ( 'Input' ) ; $ oCaptchaDriverService = Factory :: service ( 'CaptchaDriver' , 'nails/module-captcha' ) ; if ( $ oInput -> post ( ) ) { $ sKeyCaptchaDriver = $ oCaptchaDriverService -> getSettingKey ( ) ; $ oFormValidation = Factory :: service ( 'FormValidation' ) ; $ oFormValidation -> set_rules ( $ sKeyCaptchaDriver , '' , 'required' ) ; if ( $ oFormValidation -> run ( ) ) { try { $ oDb -> trans_begin ( ) ; $ oCaptchaDriverService -> saveEnabled ( $ oInput -> post ( $ sKeyCaptchaDriver ) ) ; $ oDb -> trans_commit ( ) ; $ this -> data [ 'success' ] = 'Captcha settings were saved.' ; } catch ( \ Exception $ e ) { $ oDb -> trans_rollback ( ) ; $ this -> data [ 'error' ] = 'There was a problem saving settings. ' . $ e -> getMessage ( ) ; } } else { $ this -> data [ 'error' ] = lang ( 'fv_there_were_errors' ) ; } } $ this -> data [ 'settings' ] = appSetting ( null , 'nails/module-captcha' , true ) ; $ this -> data [ 'captcha_drivers' ] = $ oCaptchaDriverService -> getAll ( ) ; $ this -> data [ 'captcha_drivers_enabled' ] = $ oCaptchaDriverService -> getEnabledSlug ( ) ; Helper :: loadView ( 'index' ) ; }
Manage Captcha settings
18,116
protected function askQuestion ( ) { $ this -> data [ 'page' ] -> title = lang ( 'auth_twofactor_answer_title' ) ; $ this -> loadStyles ( NAILS_APP_PATH . 'application/modules/auth/views/mfa/question/ask.php' ) ; Factory :: service ( 'View' ) -> load ( [ 'structure/header/blank' , 'auth/mfa/question/ask' , 'structure/footer/blank' , ] ) ; }
Asks one of the user s questions
18,117
public function isPresentable ( $ presenter = null ) { if ( is_bool ( $ presenter ) ) { $ this -> presentable = $ presenter ; } return $ this -> presentable ; }
Determine if the model is for presentation or editing .
18,118
public function setContainerObj ( $ obj ) { if ( $ obj === null ) { $ this -> containerObj = null ; return $ this ; } if ( ! $ obj instanceof AttachmentContainerInterface ) { throw new InvalidArgumentException ( sprintf ( 'Container object must be an instance of %s; received %s' , AttachmentContainerInterface :: class , ( is_object ( $ obj ) ? get_class ( $ obj ) : gettype ( $ obj ) ) ) ) ; } if ( ! $ obj -> id ( ) ) { throw new InvalidArgumentException ( sprintf ( 'Container object must have an ID.' , ( is_object ( $ obj ) ? get_class ( $ obj ) : gettype ( $ obj ) ) ) ) ; } $ this -> containerObj = $ obj ; return $ this ; }
Set the attachment s container instance .
18,119
public function microType ( ) { $ classname = get_called_class ( ) ; if ( ! isset ( static :: $ resolvedType [ $ classname ] ) ) { $ reflect = new ReflectionClass ( $ this ) ; static :: $ resolvedType [ $ classname ] = strtolower ( $ reflect -> getShortName ( ) ) ; } return static :: $ resolvedType [ $ classname ] ; }
Retrieve the unqualified class name .
18,120
public function heading ( ) { $ heading = $ this -> render ( ( string ) $ this -> heading ) ; if ( ! $ heading ) { $ heading = $ this -> translator ( ) -> translation ( '{{ objType }} #{{ id }}' , [ '{{ objType }}' => ucfirst ( $ this -> microType ( ) ) , '{{ id }}' => $ this -> id ( ) ] ) ; } return $ heading ; }
Retrieve the attachment s heading template .
18,121
public function setDescription ( $ description ) { $ this -> description = $ this -> translator ( ) -> translation ( $ description ) ; if ( $ this -> isPresentable ( ) ) { foreach ( $ this -> description -> data ( ) as $ lang => $ trans ) { $ this -> description [ $ lang ] = $ this -> resolveUrls ( $ trans ) ; } } return $ this ; }
Set the attachment s description .
18,122
public function setFileSize ( $ size ) { if ( $ size === null ) { $ this -> fileSize = null ; return $ this ; } if ( ! is_numeric ( $ size ) ) { throw new InvalidArgumentException ( 'File size must be an integer or a float.' ) ; } $ this -> fileSize = $ size ; return $ this ; }
Set the size of the attached file .
18,123
public function preDelete ( ) { $ attId = $ this -> id ( ) ; $ joinProto = $ this -> modelFactory ( ) -> get ( Join :: class ) ; $ loader = $ this -> collectionLoader ( ) ; $ loader -> setModel ( $ joinProto ) ; $ collection = $ loader -> addFilter ( 'attachment_id' , $ attId ) -> load ( ) ; foreach ( $ collection as $ obj ) { $ obj -> delete ( ) ; } return parent :: preDelete ( ) ; }
Event called before _deleting_ the attachment .
18,124
public function getFileArray ( ) { if ( ! $ this -> FileArray ) { $ user = $ this -> getConfig ( 'user' ) ; is_true_or_fail ( is_positive ( $ user ) , __d ( 'me_cms' , 'You have to set a valid user id' ) , InvalidArgumentException :: class ) ; $ this -> FileArray = new FileArray ( LOGIN_RECORDS . 'user_' . $ user . '.log' ) ; } return $ this -> FileArray ; }
Gets the FileArray instance
18,125
public function extensions ( ) { foreach ( $ this -> extensionsToCheck as $ extension ) { $ extensions [ $ extension ] = extension_loaded ( $ extension ) ; } return $ extensions ; }
Checks if some extensions are loaded
18,126
public function getCurrentRealmsIncrement ( ) : int { $ currentDifficulty = $ this -> getValue ( ) ; $ maximalDifficulty = $ this -> getMaximal ( ) ; if ( $ currentDifficulty <= $ maximalDifficulty ) { return 0 ; } $ additionalDifficulty = $ currentDifficulty - $ maximalDifficulty ; $ steps = $ additionalDifficulty / $ this -> getDifficultyAddition ( ) -> getDifficultyAdditionPerStep ( ) ; $ realmsIncrement = $ steps * $ this -> getDifficultyAddition ( ) -> getRealmsChangePerAdditionStep ( ) ; return ( int ) \ ceil ( $ realmsIncrement ) ; }
How much have to be realms increased to manage total difficulty
18,127
protected function configure ( ) { if ( empty ( static :: COMMAND ) ) { throw new NailsException ( 'static::COMMAND must be defined' ) ; } if ( empty ( static :: ALIAS ) ) { throw new NailsException ( 'static::ALIAS must be defined' ) ; } $ this -> setName ( static :: ALIAS ) ; $ this -> setDescription ( 'Alias to <info>' . static :: COMMAND . '</info>' ) ; }
Configures the app
18,128
public function setContentType ( string $ contentType , string $ contentCharset = null ) : self { $ this -> contentType = $ contentType ; if ( $ contentCharset !== null ) { $ this -> setContentCharset ( $ contentCharset ) ; } return $ this ; }
Set content type .
18,129
public function isImage ( ) : bool { return is_resource ( $ this -> content ) && in_array ( $ this -> contentType , [ self :: CONTENT_TYPE_IMAGE_JPEG , self :: CONTENT_TYPE_IMAGE_PNG , self :: CONTENT_TYPE_IMAGE_GIF , ] ) ; }
Is image .
18,130
public function getRate ( $ fromCurrency , $ toCurrency ) { if ( $ fromCurrency === $ toCurrency ) { return 1 ; } $ currencyString = "{$fromCurrency}-{$toCurrency}" ; if ( ! isset ( $ this -> rates [ $ currencyString ] ) ) { throw new NoExchangeRateException ( sprintf ( 'Cannot convert %s to %s, no exchange rate found.' , $ fromCurrency , $ toCurrency ) ) ; } return $ this -> rates [ $ currencyString ] ; }
Returns the conversion rate between two currencies .
18,131
public function view ( $ slug = null ) { if ( $ this -> request -> getQuery ( 'q' ) ) { return $ this -> redirect ( [ $ this -> request -> getQuery ( 'q' ) ] ) ; } $ category = $ this -> PagesCategories -> findActiveBySlug ( $ slug ) -> select ( [ 'id' , 'title' ] ) -> contain ( $ this -> PagesCategories -> Pages -> getAlias ( ) , function ( Query $ q ) { return $ q -> find ( 'active' ) -> select ( [ 'category_id' , 'slug' , 'title' ] ) ; } ) -> cache ( sprintf ( 'category_%s' , md5 ( $ slug ) ) , $ this -> PagesCategories -> getCacheName ( ) ) -> firstOrFail ( ) ; $ this -> set ( compact ( 'category' ) ) ; }
Lists pages for a category
18,132
public function getObject ( ) { if ( $ this -> sourceObject === null && $ this -> isSourceObjectResolved === false ) { $ this -> isSourceObjectResolved = true ; try { $ model = $ this -> modelFactory ( ) -> create ( $ this -> objectType ( ) ) -> load ( $ this -> objectId ( ) ) ; if ( $ model -> id ( ) ) { $ this -> sourceObject = $ model ; } } catch ( Exception $ e ) { throw new LogicException ( sprintf ( 'Could not load the source object of the relationship: %s' , $ e -> getMessage ( ) ) , 0 , $ e ) ; } } return $ this -> sourceObject ; }
Retrieve the source object of the relationship .
18,133
public function getAttachment ( ) { if ( $ this -> relatedObject === null && $ this -> isRelatedObjectResolved === false ) { $ this -> isRelatedObjectResolved = true ; try { $ model = $ this -> modelFactory ( ) -> create ( Attachment :: class ) -> load ( $ this -> attachmentId ( ) ) ; if ( $ model -> id ( ) ) { $ this -> relatedObject = $ model ; $ type = $ model -> type ( ) ; if ( $ type !== $ model -> objType ( ) ) { $ this -> relatedObject = $ this -> modelFactory ( ) -> create ( $ type ) -> setData ( $ model -> data ( ) ) ; } } } catch ( Exception $ e ) { throw new LogicException ( sprintf ( 'Could not load the related object of the relationship: %s' , $ e -> getMessage ( ) ) , 0 , $ e ) ; } } return $ this -> relatedObject ; }
Retrieve the related object of the relationship .
18,134
public function getParent ( ) { if ( $ this -> parentRelation === null && $ this -> isParentRelationResolved === false ) { $ this -> isParentRelationResolved = true ; try { $ source = $ this -> getObject ( ) ; if ( $ source instanceof AttachmentContainerInterface ) { $ model = $ this -> modelFactory ( ) -> create ( self :: class ) -> loadFrom ( 'attachment_id' , $ source -> id ( ) ) ; if ( $ model -> id ( ) ) { $ this -> parentRelation = $ model ; } } } catch ( Exception $ e ) { throw new LogicException ( sprintf ( 'Could not load the parent relationship: %s' , $ e -> getMessage ( ) ) , 0 , $ e ) ; } } return $ this -> parentRelation ; }
Retrieve the parent relationship if any .
18,135
public function setPosition ( $ position ) { if ( $ position === null ) { $ this -> position = null ; return $ this ; } if ( ! is_numeric ( $ position ) ) { throw new InvalidArgumentException ( 'Position must be an integer.' ) ; } $ this -> position = ( int ) $ position ; return $ this ; }
Set the relationship s position .
18,136
public function render ( ElementInterface $ element ) { $ renderer = $ this -> getView ( ) ; $ headscript = $ renderer -> plugin ( 'headscript' ) ; $ basepath = $ renderer -> plugin ( 'basepath' ) ; $ headscript -> appendFile ( $ basepath ( 'modules/Settings/js/forms.decfs.js' ) ) ; return '<ul class="disable-elements-list" id="' . $ element -> getAttribute ( 'id' ) . '-list"' . '>' . $ this -> renderCheckboxes ( $ element -> getCheckboxes ( ) ) . '</ul>' ; }
Renders a disabe form elements toggle checkboxes element .
18,137
protected function renderCheckboxes ( $ checkboxes ) { $ markup = '' ; foreach ( $ checkboxes as $ boxes ) { $ markup .= '<li class="disable-element">' ; if ( is_array ( $ boxes ) ) { if ( isset ( $ boxes [ '__all__' ] ) ) { $ markup .= $ this -> renderCheckbox ( $ boxes [ '__all__' ] , 'disable-elements-toggle' ) ; unset ( $ boxes [ '__all__' ] ) ; } $ markup .= '<ul class="disable-elements">' . $ this -> renderCheckboxes ( $ boxes ) . '</ul>' ; } else { $ markup .= $ this -> renderCheckbox ( $ boxes ) ; } $ markup .= '</li>' ; } return $ markup ; }
Recursively renders checkboxes .
18,138
protected function instantiate ( ) { $ oOptions = new Options ( ) ; $ aOptions = [ ] ; foreach ( self :: DEFAULT_OPTIONS as $ sOption => $ mValue ) { $ aOptions [ $ sOption ] = $ mValue ; } foreach ( $ this -> aCustomOptions as $ sOption => $ mValue ) { $ aOptions [ $ sOption ] = $ mValue ; } foreach ( $ aOptions as $ sOption => $ mValue ) { $ oOptions -> set ( $ sOption , $ mValue ) ; } $ this -> oDomPdf = new Dompdf ( $ oOptions ) ; $ this -> setPaperSize ( $ this -> sPaperSize , $ this -> sPaperOrientation ) ; return $ this ; }
Instantiate a new instance of DomPDF
18,139
public function setOption ( $ sOption , $ mValue ) { $ this -> aCustomOptions [ $ sOption ] = $ mValue ; $ this -> oDomPdf -> set_option ( $ sOption , $ mValue ) ; return $ this ; }
Defines a DomPDF constant if not already defined
18,140
public function setPaperSize ( $ sSize = null , $ sOrientation = null ) { $ this -> sPaperSize = $ sSize ? : static :: DEFAULT_PAPER_SIZE ; $ this -> sPaperOrientation = $ sOrientation ? : static :: DEFAULT_PAPER_ORIENTATION ; $ this -> oDomPdf -> setPaper ( $ this -> sPaperSize , $ this -> sPaperOrientation ) ; return $ this ; }
Alias for setting the paper size
18,141
public function loadView ( $ mViews , $ aData = [ ] ) { $ sHtml = '' ; $ aViews = array_filter ( ( array ) $ mViews ) ; $ oView = Factory :: service ( 'View' ) ; foreach ( $ aViews as $ sView ) { $ sHtml .= $ oView -> load ( $ sView , $ aData , true ) ; } $ this -> oDomPdf -> loadHtml ( $ sHtml ) ; }
Loads CI views and passes it as HTML to DomPDF
18,142
public function download ( $ sFilename = '' , $ aOptions = [ ] ) { $ sFilename = $ sFilename ? $ sFilename : self :: DEFAULT_FILE_NAME ; $ aOptions [ 'Attachment' ] = 1 ; $ this -> oDomPdf -> render ( ) ; $ this -> oDomPdf -> stream ( $ sFilename , $ aOptions ) ; exit ( ) ; }
Renders the PDF and sends it to the browser as a download .
18,143
public function save ( $ sPath , $ sFilename ) { if ( ! is_writable ( $ sPath ) ) { $ this -> setError ( 'Cannot write to ' . $ sPath ) ; return false ; } $ this -> oDomPdf -> render ( ) ; $ bResult = ( bool ) file_put_contents ( rtrim ( $ sPath , '/' ) . '/' . $ sFilename , $ this -> oDomPdf -> output ( ) ) ; $ this -> reset ( ) ; return $ bResult ; }
Saves a PDF to disk
18,144
public function saveToCdn ( $ sFilename , $ sBucket = null ) { if ( Components :: exists ( 'nails/module-cdn' ) ) { $ sCacheDir = CACHE_PATH ; $ sCacheFile = 'TEMP-PDF-' . md5 ( uniqid ( ) . microtime ( true ) ) . '.pdf' ; if ( $ this -> save ( $ sCacheDir , $ sCacheFile ) ) { $ oCdn = Factory :: service ( 'Cdn' , 'nails/module-cdn' ) ; $ oResult = $ oCdn -> objectCreate ( $ sCacheDir . $ sCacheFile , $ sBucket , [ 'filename_display' => $ sFilename ] ) ; if ( $ oResult ) { @ unlink ( $ sCacheDir . $ sCacheFile ) ; $ this -> reset ( ) ; return $ oResult ; } else { $ this -> setError ( $ oCdn -> lastError ( ) ) ; return false ; } } else { return false ; } } else { $ this -> setError ( 'CDN module is not available' ) ; return false ; } }
Saves the PDF to the CDN
18,145
public function findPageById ( $ pageId ) { $ this -> makeCollectionPageSelect ( true ) ; $ this -> sql .= ' and p.id = ?' ; $ this -> bindValues [ ] = $ pageId ; return $ this -> findRow ( ) ; }
Find Page by ID
18,146
public function findPublishedPageBySlug ( $ pageSlug ) { $ this -> makeSelect ( ) ; if ( is_string ( $ pageSlug ) ) { $ this -> sql .= ' and collection_id is null and slug = ?' ; $ this -> bindValues [ ] = $ pageSlug ; } else { throw new Exception ( 'Unknown page identifier type' ) ; } $ this -> sql .= " and published_date <= '{$this->today()}'" ; return $ this -> findRow ( ) ; }
Find Published Page By Slug
18,147
public function findPages ( $ unpublished = false ) { $ this -> makeSelect ( ) ; $ this -> sql .= " and collection_id is null" ; if ( ! $ unpublished ) { $ this -> sql .= " and published_date <= '{$this->today()}'" ; } return $ this -> find ( ) ; }
Find All Pages
18,148
public function findCollectionPagesById ( $ collectionId , $ published = true ) { $ this -> makeCollectionPageSelect ( ) ; $ this -> sql .= ' and c.id = ?' ; $ this -> bindValues [ ] = $ collectionId ; if ( $ published ) { $ this -> sql .= " and p.published_date <= '{$this->today()}'" ; } return $ this -> find ( ) ; }
Find Collection Pages by ID
18,149
public function findPublishedCollectionPageBySlug ( $ collectionSlug , $ pageSlug ) { $ this -> makeCollectionPageSelect ( ) ; $ this -> sql .= " and p.published_date <= '{$this->today()}'" ; $ this -> sql .= ' and c.slug = ? and p.slug = ?' ; $ this -> bindValues [ ] = $ collectionSlug ; $ this -> bindValues [ ] = $ pageSlug ; return $ this -> findRow ( ) ; }
Find Published Collection Page By Slug
18,150
public function setData ( array $ data ) { foreach ( $ data as $ prop => $ val ) { $ func = [ $ this , $ this -> setter ( $ prop ) ] ; if ( is_callable ( $ func ) ) { call_user_func ( $ func , $ val ) ; } else { $ this -> { $ prop } = $ val ; } } return $ this ; }
Set the email s data .
18,151
public function campaign ( ) { if ( $ this -> campaign === null ) { $ this -> campaign = $ this -> generateCampaign ( ) ; } return $ this -> campaign ; }
Get the campaign identifier .
18,152
public function from ( ) { if ( $ this -> from === null ) { $ this -> setFrom ( $ this -> config ( ) -> defaultFrom ( ) ) ; } return $ this -> from ; }
Get the sender s email address .
18,153
public function replyTo ( ) { if ( $ this -> replyTo === null ) { $ this -> replyTo = $ this -> config ( ) -> defaultReplyTo ( ) ; } return $ this -> replyTo ; }
Get email address to reply to the message .
18,154
public function msgHtml ( ) { if ( $ this -> msgHtml === null ) { $ this -> msgHtml = $ this -> generateMsgHtml ( ) ; } return $ this -> msgHtml ; }
Get the email s HTML message body .
18,155
public function msgTxt ( ) { if ( $ this -> msgTxt === null ) { $ this -> msgTxt = $ this -> stripHtml ( $ this -> msgHtml ( ) ) ; } return $ this -> msgTxt ; }
Get the email s plain - text message body .
18,156
public function log ( ) { if ( $ this -> log === null ) { $ this -> log = $ this -> config ( ) -> defaultLog ( ) ; } return $ this -> log ; }
Determine if logging is enabled for this particular email .
18,157
public function track ( ) { if ( $ this -> track === null ) { $ this -> track = $ this -> config ( ) -> defaultTrack ( ) ; } return $ this -> track ; }
Determine if tracking is enabled for this particular email .
18,158
public function send ( ) { $ this -> logger -> debug ( 'Attempting to send an email' , $ this -> to ( ) ) ; $ mail = $ this -> phpMailer ; try { $ this -> setSmtpOptions ( $ mail ) ; $ mail -> CharSet = 'UTF-8' ; $ replyTo = $ this -> replyTo ( ) ; if ( $ replyTo ) { $ replyArr = $ this -> emailToArray ( $ replyTo ) ; $ mail -> addReplyTo ( $ replyArr [ 'email' ] , $ replyArr [ 'name' ] ) ; } $ from = $ this -> from ( ) ; $ fromArr = $ this -> emailToArray ( $ from ) ; $ mail -> setFrom ( $ fromArr [ 'email' ] , $ fromArr [ 'name' ] ) ; $ to = $ this -> to ( ) ; foreach ( $ to as $ recipient ) { $ toArr = $ this -> emailToArray ( $ recipient ) ; $ mail -> addAddress ( $ toArr [ 'email' ] , $ toArr [ 'name' ] ) ; } $ cc = $ this -> cc ( ) ; foreach ( $ cc as $ ccRecipient ) { $ ccArr = $ this -> emailToArray ( $ ccRecipient ) ; $ mail -> addCC ( $ ccArr [ 'email' ] , $ ccArr [ 'name' ] ) ; } $ bcc = $ this -> bcc ( ) ; foreach ( $ bcc as $ bccRecipient ) { $ bccArr = $ this -> emailToArray ( $ bccRecipient ) ; $ mail -> addBCC ( $ bccArr [ 'email' ] , $ bccArr [ 'name' ] ) ; } $ attachments = $ this -> attachments ( ) ; foreach ( $ attachments as $ att ) { $ mail -> addAttachment ( $ att ) ; } $ mail -> isHTML ( true ) ; $ mail -> Subject = $ this -> subject ( ) ; $ mail -> Body = $ this -> msgHtml ( ) ; $ mail -> AltBody = $ this -> msgTxt ( ) ; $ ret = $ mail -> send ( ) ; $ this -> logSend ( $ ret , $ mail ) ; return $ ret ; } catch ( Exception $ e ) { $ this -> logger -> error ( sprintf ( 'Error sending email: %s' , $ e -> getMessage ( ) ) ) ; } }
Send the email to all recipients
18,159
protected function setSmtpOptions ( PHPMailer $ mail ) { $ config = $ this -> config ( ) ; if ( ! $ config [ 'smtp' ] ) { return ; } $ this -> logger -> debug ( sprintf ( 'Using SMTP "%s" server to send email' , $ config [ 'smtp_hostname' ] ) ) ; $ mail -> isSMTP ( ) ; $ mail -> Host = $ config [ 'smtp_hostname' ] ; $ mail -> Port = $ config [ 'smtp_port' ] ; $ mail -> SMTPAuth = $ config [ 'smtp_auth' ] ; $ mail -> Username = $ config [ 'smtp_username' ] ; $ mail -> Password = $ config [ 'smtp_password' ] ; $ mail -> SMTPSecure = $ config [ 'smtp_security' ] ; }
Set the SMTP s options for PHPMailer .
18,160
public function queue ( $ ts = null ) { $ recipients = $ this -> to ( ) ; $ author = $ this -> from ( ) ; $ subject = $ this -> subject ( ) ; $ msgHtml = $ this -> msgHtml ( ) ; $ msgTxt = $ this -> msgTxt ( ) ; $ campaign = $ this -> campaign ( ) ; $ queueId = $ this -> queueId ( ) ; foreach ( $ recipients as $ to ) { $ queueItem = $ this -> queueItemFactory ( ) -> create ( EmailQueueItem :: class ) ; $ queueItem -> setTo ( $ to ) ; $ queueItem -> setFrom ( $ author ) ; $ queueItem -> setSubject ( $ subject ) ; $ queueItem -> setMsgHtml ( $ msgHtml ) ; $ queueItem -> setMsgTxt ( $ msgTxt ) ; $ queueItem -> setCampaign ( $ campaign ) ; $ queueItem -> setProcessingDate ( $ ts ) ; $ queueItem -> setQueueId ( $ queueId ) ; $ res = $ queueItem -> save ( ) ; } return true ; }
Enqueue the email for each recipient .
18,161
public function viewController ( ) { $ templateIdent = $ this -> templateIdent ( ) ; if ( ! $ templateIdent ) { return [ ] ; } $ templateFactory = clone ( $ this -> templateFactory ( ) ) ; $ templateFactory -> setDefaultClass ( GenericEmailTemplate :: class ) ; $ template = $ templateFactory -> create ( $ templateIdent ) ; $ template -> setData ( $ this -> templateData ( ) ) ; return $ template ; }
Get the custom view controller for rendering the email s HTML message .
18,162
protected function generateMsgHtml ( ) { $ templateIdent = $ this -> templateIdent ( ) ; if ( ! $ templateIdent ) { $ message = '' ; } else { $ message = $ this -> renderTemplate ( $ templateIdent ) ; } return $ message ; }
Get the email s HTML message from the template if applicable .
18,163
protected function stripHtml ( $ html ) { $ str = html_entity_decode ( $ html ) ; $ str = preg_replace ( '#<br[^>]*?>#siu' , "\n" , $ str ) ; $ str = preg_replace ( [ '#<applet[^>]*?.*?</applet>#siu' , '#<embed[^>]*?.*?</embed>#siu' , '#<head[^>]*?>.*?</head>#siu' , '#<noframes[^>]*?.*?</noframes>#siu' , '#<noscript[^>]*?.*?</noscript>#siu' , '#<noembed[^>]*?.*?</noembed>#siu' , '#<object[^>]*?.*?</object>#siu' , '#<script[^>]*?.*?</script>#siu' , '#<style[^>]*?>.*?</style>#siu' ] , '' , $ str ) ; $ str = strip_tags ( $ str ) ; $ str = str_replace ( "\t" , '' , $ str ) ; $ str = preg_replace ( '#\n\r|\r\n#' , "\n" , $ str ) ; $ str = preg_replace ( '#\n{3,}#' , "\n\n" , $ str ) ; $ str = preg_replace ( '/ {2,}/' , ' ' , $ str ) ; $ str = implode ( "\n" , array_map ( 'trim' , explode ( "\n" , $ str ) ) ) ; $ str = trim ( $ str ) . "\n" ; return $ str ; }
Convert an HTML string to plain - text .
18,164
protected function logSend ( $ result , $ mailer ) { if ( $ this -> log ( ) === false ) { return ; } if ( ! $ result ) { $ this -> logger -> error ( 'Email could not be sent.' ) ; } else { $ this -> logger -> debug ( sprintf ( 'Email "%s" sent successfully.' , $ this -> subject ( ) ) , $ this -> to ( ) ) ; } $ recipients = array_merge ( $ this -> to ( ) , $ this -> cc ( ) , $ this -> bcc ( ) ) ; foreach ( $ recipients as $ to ) { $ log = $ this -> logFactory ( ) -> create ( 'charcoal/email/email-log' ) ; $ log -> setType ( 'email' ) ; $ log -> setAction ( 'send' ) ; $ log -> setRawResponse ( $ mailer ) ; $ log -> setMessageId ( $ mailer -> getLastMessageId ( ) ) ; $ log -> setCampaign ( $ this -> campaign ( ) ) ; $ log -> setSendDate ( 'now' ) ; $ log -> setFrom ( $ mailer -> From ) ; $ log -> setTo ( $ to ) ; $ log -> setSubject ( $ this -> subject ( ) ) ; $ log -> save ( ) ; } }
Log the send event for each recipient .
18,165
public function get ( $ original ) { $ original = ( string ) $ original ; if ( isset ( $ this -> messages [ $ original ] ) ) { return $ this -> messages [ $ original ] ; } return false ; }
Returns the translations for the given original string
18,166
protected function extract ( ) { $ magic = $ this -> readInt ( 'V' ) ; if ( ( $ magic === self :: MAGIC1 ) || ( $ magic === self :: MAGIC3 ) ) { $ byteOrder = 'V' ; } elseif ( $ magic === ( self :: MAGIC2 & 0xFFFFFFFF ) ) { $ byteOrder = 'N' ; } else { throw new \ Aimeos \ MW \ Translation \ Exception ( 'Invalid MO file' ) ; } $ this -> readInt ( $ byteOrder ) ; $ total = $ this -> readInt ( $ byteOrder ) ; $ originals = $ this -> readInt ( $ byteOrder ) ; $ trans = $ this -> readInt ( $ byteOrder ) ; $ this -> seekto ( $ originals ) ; $ originalTable = $ this -> readIntArray ( $ byteOrder , $ total * 2 ) ; $ this -> seekto ( $ trans ) ; $ translationTable = $ this -> readIntArray ( $ byteOrder , $ total * 2 ) ; return $ this -> extractTable ( $ originalTable , $ translationTable , $ total ) ; }
Extracts the messages and translations from the MO file
18,167
protected function extractTable ( $ originalTable , $ translationTable , $ total ) { $ messages = [ ] ; for ( $ i = 0 ; $ i < $ total ; ++ $ i ) { $ plural = null ; $ next = $ i * 2 ; $ this -> seekto ( $ originalTable [ $ next + 2 ] ) ; $ original = $ this -> read ( $ originalTable [ $ next + 1 ] ) ; $ this -> seekto ( $ translationTable [ $ next + 2 ] ) ; $ translated = $ this -> read ( $ translationTable [ $ next + 1 ] ) ; if ( $ original === '' || $ translated === '' ) { continue ; } if ( strpos ( $ original , "\x04" ) !== false ) { list ( $ context , $ original ) = explode ( "\x04" , $ original , 2 ) ; } if ( strpos ( $ original , "\000" ) !== false ) { list ( $ original , $ plural ) = explode ( "\000" , $ original ) ; } if ( $ plural === null ) { $ messages [ $ original ] = $ translated ; continue ; } $ messages [ $ original ] = [ ] ; foreach ( explode ( "\x00" , $ translated ) as $ idx => $ value ) { $ messages [ $ original ] [ $ idx ] = $ value ; } } return $ messages ; }
Extracts the messages and their translations
18,168
protected function readInt ( $ byteOrder ) { if ( ( $ content = $ this -> read ( 4 ) ) === false ) { return false ; } $ content = unpack ( $ byteOrder , $ content ) ; return array_shift ( $ content ) ; }
Returns a single integer starting from the current position
18,169
public function pages ( ) { if ( $ this -> request -> isUrl ( [ '_name' => 'pagesCategories' ] ) ) { return ; } $ pages = $ this -> Pages -> find ( 'active' ) -> select ( [ 'title' , 'slug' ] ) -> order ( [ sprintf ( '%s.title' , $ this -> Pages -> getAlias ( ) ) => 'ASC' ] ) -> cache ( sprintf ( 'widget_list' ) , $ this -> Pages -> getCacheName ( ) ) -> all ( ) ; $ this -> set ( compact ( 'pages' ) ) ; }
Pages list widget
18,170
public function generate ( ) { try { if ( ! $ this -> isEnabled ( ) ) { throw new CaptchaDriverException ( 'Captcha driver has not been configured.' ) ; } $ oResponse = $ this -> oDriver -> generate ( ) ; if ( ! ( $ oResponse instanceof CaptchaForm ) ) { throw new CaptchaDriverException ( 'Driver must return an instance of \Nails\Captcha\Factory\CaptchaForm.' ) ; } } catch ( \ Exception $ e ) { $ oResponse = Factory :: factory ( 'CaptchaForm' , 'nails/module-captcha' ) ; $ oResponse -> setHtml ( '<p style="color: red; padding: 1rem; border: 1px solid red;">ERROR: ' . $ e -> getMessage ( ) . '</p>' ) ; } return $ oResponse ; }
Returns the form markup for the captcha
18,171
public function getPdo ( ) { if ( $ this -> pdo === null ) { $ this -> pdo = $ this -> doConnect ( ) ; } return $ this -> pdo ; }
Gets the PDO connection of the database . And connect to the database if not connected yet .
18,172
public function disconnect ( ) { if ( $ this -> pdo !== null ) { $ this -> doDisconnect ( $ this -> pdo ) ; $ this -> pdo = null ; } }
Disconnects the connection .
18,173
protected function performAjaxValidation ( $ model ) { if ( isset ( $ _POST [ 'ajax' ] ) && $ _POST [ 'ajax' ] === 'ommu-meta-form' ) { echo CActiveForm :: validate ( $ model ) ; Yii :: app ( ) -> end ( ) ; } }
Performs the AJAX validation .
18,174
public function setAsDefault ( $ mGroupIdOrSlug ) { $ oGroup = $ this -> getByIdOrSlug ( $ mGroupIdOrSlug ) ; if ( ! $ oGroup ) { $ this -> setError ( 'Invalid Group' ) ; } $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> trans_begin ( ) ; $ oDb -> set ( 'is_default' , false ) ; $ oDb -> set ( 'modified' , 'NOW()' , false ) ; if ( isLoggedIn ( ) ) { $ oDb -> set ( 'modified_by' , activeUser ( 'id' ) ) ; } $ oDb -> where ( 'is_default' , true ) ; $ oDb -> update ( $ this -> getTableName ( ) ) ; $ oDb -> set ( 'is_default' , true ) ; $ oDb -> set ( 'modified' , 'NOW()' , false ) ; if ( isLoggedIn ( ) ) { $ oDb -> set ( 'modified_by' , activeUser ( 'id' ) ) ; } $ oDb -> where ( 'id' , $ oGroup -> id ) ; $ oDb -> update ( $ this -> getTableName ( ) ) ; if ( $ oDb -> trans_status ( ) === false ) { $ oDb -> trans_rollback ( ) ; return false ; } else { $ oDb -> trans_commit ( ) ; $ this -> getDefaultGroup ( ) ; return true ; } }
Set s a group as the default group
18,175
public function getDefaultGroup ( ) { $ aGroups = $ this -> getAll ( [ 'where' => [ [ 'is_default' , true ] , ] , ] ) ; if ( empty ( $ aGroups ) ) { throw new NailsException ( 'A default user group must be defined.' ) ; } $ this -> oDefaultGroup = reset ( $ aGroups ) ; return $ this -> oDefaultGroup ; }
Returns the default user group
18,176
public function hasPermission ( $ sSearch , $ mGroup ) { if ( is_numeric ( $ mGroup ) ) { $ oGroup = $ this -> getById ( $ mGroup ) ; if ( isset ( $ oGroup -> acl ) ) { $ aAcl = $ oGroup -> acl ; unset ( $ oGroup ) ; } else { return false ; } } elseif ( isset ( $ mGroup -> acl ) ) { $ aAcl = $ mGroup -> acl ; } else { return false ; } if ( ! $ aAcl ) { return false ; } $ oInput = Factory :: service ( 'Input' ) ; if ( in_array ( 'admin:superuser' , $ aAcl ) || $ oInput :: isCli ( ) ) { return true ; } $ bHasPermission = false ; $ sSearch = preg_replace ( '/:\*/' , ':.*' , $ sSearch ) ; foreach ( $ aAcl as $ sPermission ) { $ sPattern = '/^' . $ sSearch . '$/' ; $ bMatch = preg_match ( $ sPattern , $ sPermission ) ; if ( $ bMatch ) { $ bHasPermission = true ; break ; } } return $ bHasPermission ; }
Determines whether the specified group has a certain ACL permission
18,177
protected static function defineCharsetConstants ( ) { $ sCharset = strtoupper ( config_item ( 'charset' ) ) ; ini_set ( 'default_charset' , $ sCharset ) ; if ( extension_loaded ( 'mbstring' ) ) { define ( 'MB_ENABLED' , true ) ; @ ini_set ( 'mbstring.internal_encoding' , $ sCharset ) ; mb_substitute_character ( 'none' ) ; } else { define ( 'MB_ENABLED' , false ) ; } if ( extension_loaded ( 'iconv' ) ) { define ( 'ICONV_ENABLED' , true ) ; @ ini_set ( 'iconv.internal_encoding' , $ sCharset ) ; } else { define ( 'ICONV_ENABLED' , false ) ; } if ( is_php ( '5.6' ) ) { ini_set ( 'php.internal_encoding' , $ sCharset ) ; } }
This method defines some items which are declared by CodeIgniter
18,178
protected function sortData ( ) { $ columns = $ this -> getOrder ( ) ; $ order = [ ] ; foreach ( $ columns as $ column ) { if ( $ column [ 0 ] === '-' ) { $ column = substr ( $ column , 1 ) ; $ order [ $ column ] = - 1 ; } else { $ order [ $ column ] = 1 ; } } $ cmp = function ( $ a , $ b ) use ( $ order ) { foreach ( $ order as $ column => $ desc ) { $ r = strnatcmp ( $ a [ $ column ] , $ b [ $ column ] ) ; if ( $ r !== 0 ) { return $ r * $ desc ; } } return 0 ; } ; usort ( $ this -> data , $ cmp ) ; }
Sort the internal array .
18,179
public function getData ( ) { if ( $ this -> toSort && ! empty ( $ this -> getOrder ( ) ) ) { $ this -> sortData ( ) ; } if ( $ this -> getLimit ( ) ) { return array_slice ( $ this -> data , $ this -> getOffset ( ) , $ this -> getLimit ( ) ) ; } else { return $ this -> data ; } }
Get the underlying data array .
18,180
public function setData ( $ data ) { if ( $ data instanceof \ Traversable ) { $ this -> data = iterator_to_array ( $ data ) ; } else { $ this -> data = $ data ; } if ( ! empty ( $ this -> getOrder ( ) ) ) { $ this -> toSort = true ; } return $ this ; }
Set the underlying data array .
18,181
public static function decryptMail ( $ mail , $ key = null , $ hmacSalt = null ) { return parent :: decrypt ( base64_decode ( $ mail ) , $ key ? : Configure :: read ( 'RecaptchaMailhide.encryptKey' ) , $ hmacSalt ) ; }
Decrypts and decodes an email address
18,182
public static function encryptMail ( $ mail , $ key = null , $ hmacSalt = null ) { return base64_encode ( parent :: encrypt ( $ mail , $ key ? : Configure :: read ( 'RecaptchaMailhide.encryptKey' ) , $ hmacSalt ) ) ; }
Encrypts and encodes an email address
18,183
protected function loadStyles ( $ sView ) { if ( ! is_file ( $ sView ) ) { $ oAsset = Factory :: service ( 'Asset' ) ; $ oAsset -> clear ( ) ; $ oAsset -> load ( 'nails.min.css' , 'nails/common' ) ; $ oAsset -> load ( 'styles.min.css' , 'nails/module-auth' ) ; } }
Loads Auth styles if supplied view does not exist
18,184
public function getJson ( $ jsonFile , $ jsonSchema = null ) { if ( isset ( $ jsonSchema ) && array_key_exists ( $ jsonSchema , $ this -> validation ) ) { $ validation = $ this -> validation [ $ jsonSchema ] ; } elseif ( $ jsonSchema === null ) { $ validation = $ jsonSchema ; } else { throw new Exception ( 'Invalid jsonSchema validation key' ) ; } try { return $ this -> decodeFile ( $ jsonFile , $ validation ) ; } catch ( \ RuntimeException $ e ) { $ this -> errors [ ] = $ e -> getMessage ( ) ; } catch ( ValidationFailedException $ e ) { $ this -> errors [ ] = $ e -> getMessage ( ) ; } catch ( \ Exception $ e ) { $ this -> errors [ ] = 'Unknown Exception in getPageDefinition()' ; $ this -> errors [ ] = $ e -> getMessage ( ) ; } return null ; }
Get JSON Definition
18,185
public function acceptCookies ( ) { $ this -> response = $ this -> response -> withCookie ( ( new Cookie ( 'cookies-policy' , true ) ) -> withNeverExpire ( ) ) ; return $ this -> redirect ( $ this -> referer ( [ '_name' => 'homepage' ] , true ) ) ; }
Accept cookies policy . It sets the cookie to remember the user accepted the cookie policy and redirects
18,186
public function contactUs ( ) { if ( ! getConfig ( 'default.contact_us' ) ) { $ this -> Flash -> error ( I18N_DISABLED ) ; return $ this -> redirect ( [ '_name' => 'homepage' ] ) ; } $ contact = new ContactUsForm ; if ( $ this -> request -> is ( 'post' ) ) { if ( ! getConfig ( 'security.recaptcha' ) || $ this -> Recaptcha -> verify ( ) ) { if ( $ contact -> execute ( $ this -> request -> getData ( ) ) ) { $ this -> Flash -> success ( I18N_OPERATION_OK ) ; return $ this -> redirect ( [ '_name' => 'homepage' ] ) ; } $ this -> Flash -> error ( I18N_OPERATION_NOT_OK ) ; } else { $ this -> Flash -> error ( __d ( 'me_cms' , 'You must fill in the {0} control correctly' , 'reCAPTCHA' ) ) ; } } $ this -> set ( compact ( 'contact' ) ) ; }
Contact us form
18,187
public function ipNotAllowed ( ) { if ( ! $ this -> request -> isBanned ( ) ) { return $ this -> redirect ( $ this -> referer ( [ '_name' => 'homepage' ] , true ) ) ; } $ this -> viewBuilder ( ) -> setLayout ( 'login' ) ; }
IP not allowed page
18,188
public function sitemap ( ) { if ( is_readable ( SITEMAP ) ) { $ time = Time :: createFromTimestamp ( filemtime ( SITEMAP ) ) ; if ( ! $ time -> modify ( getConfigOrFail ( 'main.sitemap_expiration' ) ) -> isPast ( ) ) { $ sitemap = file_get_contents ( SITEMAP ) ; } } if ( empty ( $ sitemap ) ) { $ sitemap = gzencode ( Sitemap :: generate ( ) , 9 ) ; ( new File ( SITEMAP , true , 0777 ) ) -> write ( $ sitemap ) ; } return $ this -> response -> withFile ( SITEMAP ) ; }
Returns the site sitemap . If the sitemap doesn t exist or has expired it generates and writes the sitemap .
18,189
public function add ( ) { $ album = $ this -> PhotosAlbums -> newEntity ( ) ; if ( $ this -> request -> is ( 'post' ) ) { $ album = $ this -> PhotosAlbums -> patchEntity ( $ album , $ this -> request -> getData ( ) ) ; if ( $ this -> PhotosAlbums -> save ( $ album ) ) { $ this -> Flash -> success ( I18N_OPERATION_OK ) ; return $ this -> redirect ( [ 'action' => 'index' ] ) ; } $ this -> Flash -> error ( I18N_OPERATION_NOT_OK ) ; } $ this -> set ( compact ( 'album' ) ) ; }
Adds photos album
18,190
public function edit ( $ id = null ) { $ album = $ this -> PhotosAlbums -> get ( $ id ) ; if ( $ this -> request -> is ( [ 'patch' , 'post' , 'put' ] ) ) { $ album = $ this -> PhotosAlbums -> patchEntity ( $ album , $ this -> request -> getData ( ) ) ; if ( $ this -> PhotosAlbums -> save ( $ album ) ) { $ this -> Flash -> success ( I18N_OPERATION_OK ) ; return $ this -> redirect ( [ 'action' => 'index' ] ) ; } $ this -> Flash -> error ( I18N_OPERATION_NOT_OK ) ; } $ this -> set ( compact ( 'album' ) ) ; }
Edits photos album
18,191
public function delete ( $ id = null ) { $ this -> request -> allowMethod ( [ 'post' , 'delete' ] ) ; $ album = $ this -> PhotosAlbums -> get ( $ id ) ; if ( ! $ album -> photo_count ) { $ this -> PhotosAlbums -> deleteOrFail ( $ album ) ; $ this -> Flash -> success ( I18N_OPERATION_OK ) ; } else { $ this -> Flash -> alert ( I18N_BEFORE_DELETE ) ; } return $ this -> redirect ( [ 'action' => 'index' ] ) ; }
Deletes photos album
18,192
public function getAmount ( MoneyInterface $ money = null , $ currency = null ) { if ( null === $ money ) { return 0.0 ; } $ reduced = $ this -> bank -> reduce ( $ money , $ currency ) ; return $ reduced -> getAmount ( ) ; }
Gets the amount .
18,193
public function truncateHtmlText ( $ text , $ characters = 300 ) { $ text = preg_replace ( '/<[^>]*>/' , ' ' , $ text ) ; $ text = str_replace ( "\r" , '' , $ text ) ; $ text = str_replace ( "\n" , ' ' , $ text ) ; $ text = str_replace ( "\t" , ' ' , $ text ) ; $ text = preg_replace ( '/\s+/' , ' ' , $ text ) ; $ text = preg_replace ( '/^[\s]/' , '' , $ text ) ; $ text = preg_replace ( '/[\s]$/' , '' , $ text ) ; if ( mb_strlen ( $ text ) <= $ characters ) { return $ text ; } $ text = substr ( $ text , 0 , $ characters ) ; $ lastSpacePosition = strrpos ( $ text , ' ' ) ; if ( isset ( $ lastSpacePosition ) ) { $ text = substr ( $ text , 0 , $ lastSpacePosition ) ; } return $ text ; }
Truncate HTML Text
18,194
public function getDirectoryFiles ( $ dirPath , $ ignore = null ) { $ files = [ ] ; $ pattern = '/^\..+' ; $ splitCamelCase = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/' ; $ ignoreDirectories = false ; if ( is_string ( $ ignore ) && ! empty ( $ ignore ) ) { if ( $ ignore === 'dir' || $ ignore === 'directory' ) { $ ignoreDirectories = true ; } else { $ pattern .= '|' . $ ignore ; } } elseif ( is_array ( $ ignore ) ) { if ( in_array ( 'dir' , $ ignore ) || in_array ( 'directory' , $ ignore ) ) { $ ignoreDirectories = true ; $ ignore = array_diff ( $ ignore , [ 'dir' , 'directory' ] ) ; } $ multiIgnores = implode ( '|' , $ ignore ) ; $ pattern .= empty ( $ multiIgnores ) ? '' : '|' . $ multiIgnores ; } $ pattern .= '/' ; if ( is_dir ( $ dirPath ) ) { foreach ( new FilesystemIterator ( $ dirPath ) as $ dirObject ) { if ( ( $ ignoreDirectories && $ dirObject -> isDir ( ) ) || preg_match ( $ pattern , $ dirObject -> getFilename ( ) ) ) { continue ; } $ baseName = $ dirObject -> getBasename ( '.' . $ dirObject -> getExtension ( ) ) ; $ readableFileName = preg_replace ( $ splitCamelCase , '$1 ' , $ baseName ) ; $ readableFileName = ucwords ( $ readableFileName ) ; $ files [ ] = [ 'filename' => $ dirObject -> getFilename ( ) , 'basename' => $ baseName , 'readname' => $ readableFileName ] ; } } return $ files ; }
Get Directory Files
18,195
protected function getOrderedByDistanceAsc ( ) : array { $ values = $ this -> getIndexedValues ( ) ; uksort ( $ values , function ( $ oneDistanceInMeters , $ anotherDistanceInMeters ) { $ oneDistanceInMeters = ToFloat :: toPositiveFloat ( $ oneDistanceInMeters ) ; $ anotherDistanceInMeters = ToFloat :: toPositiveFloat ( $ anotherDistanceInMeters ) ; return $ oneDistanceInMeters <=> $ anotherDistanceInMeters ; } ) ; return $ values ; }
Values may be already ordered from file but have to be sure .
18,196
protected function buildSelect ( $ table , array $ where , array $ options = [ ] ) { $ options += [ 'limit' => 0 ] ; $ sql = '' ; if ( ! empty ( $ options [ 'columns' ] ) ) { $ columns = array ( ) ; foreach ( $ options [ 'columns' ] as $ value ) { $ columns [ ] = $ this -> escape ( $ value ) ; } $ sql .= 'select ' . implode ( ', ' , $ columns ) ; } else { $ sql .= "select *" ; } if ( $ table instanceof Literal ) { $ table = $ table -> getValue ( $ this ) ; } else { $ table = $ this -> prefixTable ( $ table ) ; } $ sql .= "\nfrom $table" ; $ whereString = $ this -> buildWhere ( $ where , Db :: OP_AND ) ; if ( $ whereString ) { $ sql .= "\nwhere " . $ whereString ; } if ( ! empty ( $ options [ 'order' ] ) ) { $ orders = [ ] ; foreach ( $ options [ 'order' ] as $ column ) { if ( $ column [ 0 ] === '-' ) { $ order = $ this -> escape ( substr ( $ column , 1 ) ) . ' desc' ; } else { $ order = $ this -> escape ( $ column ) ; } $ orders [ ] = $ order ; } $ sql .= "\norder by " . implode ( ', ' , $ orders ) ; } if ( ! empty ( $ options [ 'limit' ] ) ) { $ limit = ( int ) $ options [ 'limit' ] ; $ sql .= "\nlimit $limit" ; } if ( ! empty ( $ options [ 'offset' ] ) ) { $ sql .= ' offset ' . ( ( int ) $ options [ 'offset' ] ) ; } elseif ( isset ( $ options [ 'page' ] ) ) { $ offset = $ options [ 'limit' ] * ( $ options [ 'page' ] - 1 ) ; $ sql .= ' offset ' . $ offset ; } return $ sql ; }
Build a sql select statement .
18,197
private function getDbName ( ) { if ( ! isset ( $ this -> dbname ) ) { $ this -> dbname = $ this -> getPDO ( ) -> query ( 'select database()' ) -> fetchColumn ( ) ; } return $ this -> dbname ; }
Get the current database name .
18,198
protected function fetchIndexesDb ( $ table = '' ) { $ stm = $ this -> get ( new Identifier ( 'information_schema' , 'STATISTICS' ) , [ 'TABLE_SCHEMA' => $ this -> getDbName ( ) , 'TABLE_NAME' => $ this -> prefixTable ( $ table , false ) ] , [ 'columns' => [ 'INDEX_NAME' , 'COLUMN_NAME' , 'NON_UNIQUE' ] , 'order' => [ 'INDEX_NAME' , 'SEQ_IN_INDEX' ] ] ) ; $ indexRows = $ stm -> fetchAll ( PDO :: FETCH_ASSOC | PDO :: FETCH_GROUP ) ; $ indexes = [ ] ; foreach ( $ indexRows as $ indexName => $ columns ) { $ index = [ 'type' => null , 'columns' => array_column ( $ columns , 'COLUMN_NAME' ) , 'name' => $ indexName ] ; if ( $ indexName === 'PRIMARY' ) { $ index [ 'type' ] = Db :: INDEX_PK ; } else { $ index [ 'type' ] = $ columns [ 0 ] [ 'NON_UNIQUE' ] ? Db :: INDEX_IX : Db :: INDEX_UNIQUE ; } $ indexes [ ] = $ index ; } return $ indexes ; }
Get the indexes from the database .
18,199
protected function buildInsert ( $ table , array $ row , $ options = [ ] ) { if ( self :: val ( Db :: OPTION_UPSERT , $ options ) ) { return $ this -> buildUpsert ( $ table , $ row , $ options ) ; } elseif ( self :: val ( Db :: OPTION_IGNORE , $ options ) ) { $ sql = 'insert ignore ' ; } elseif ( self :: val ( Db :: OPTION_REPLACE , $ options ) ) { $ sql = 'replace ' ; } else { $ sql = 'insert ' ; } $ sql .= $ this -> prefixTable ( $ table ) ; $ sql .= "\n" . $ this -> bracketList ( array_keys ( $ row ) , '`' ) . "\nvalues" . $ this -> bracketList ( $ row , "'" ) ; return $ sql ; }
Build an insert statement .