idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
48,800
public function setBasicCriteria ( array $ archives , $ sorting = null ) { $ archives = $ this -> parseIds ( $ archives ) ; if ( 0 === \ count ( $ archives ) ) { throw new NoNewsException ( ) ; } $ t = $ this -> getNewsModelAdapter ( ) -> getTable ( ) ; $ this -> columns [ ] = "$t.pid IN(" . \ implode ( ',' , \ array_map ( 'intval' , $ archives ) ) . ')' ; switch ( $ sorting ) { case 'order_headline_asc' : $ this -> options [ 'order' ] = "$t.headline" ; break ; case 'order_headline_desc' : $ this -> options [ 'order' ] = "$t.headline DESC" ; break ; case 'order_random' : $ this -> options [ 'order' ] = 'RAND()' ; break ; case 'order_date_asc' : $ this -> options [ 'order' ] = "$t.date" ; break ; default : $ this -> options [ 'order' ] = "$t.date DESC" ; break ; } if ( ! BE_USER_LOGGED_IN || TL_MODE === 'BE' ) { $ dateAdapter = $ this -> framework -> getAdapter ( Date :: class ) ; $ time = $ dateAdapter -> floorToMinute ( ) ; $ this -> columns [ ] = "($t.start=? OR $t.start<=?) AND ($t.stop=? OR $t.stop>?) AND $t.published=?" ; $ this -> values = \ array_merge ( $ this -> values , [ '' , $ time , '' , ( $ time + 60 ) , 1 ] ) ; } }
Set the basic criteria .
48,801
public function setFeatured ( $ enable ) { $ t = $ this -> getNewsModelAdapter ( ) -> getTable ( ) ; if ( true === $ enable ) { $ this -> columns [ ] = "$t.featured=?" ; $ this -> values [ ] = 1 ; } elseif ( false === $ enable ) { $ this -> columns [ ] = "$t.featured=?" ; $ this -> values [ ] = '' ; } }
Set the features items .
48,802
public function setTimeFrame ( $ begin , $ end ) { $ t = $ this -> getNewsModelAdapter ( ) -> getTable ( ) ; $ this -> columns [ ] = "$t.date>=? AND $t.date<=?" ; $ this -> values [ ] = $ begin ; $ this -> values [ ] = $ end ; }
Set the time frame .
48,803
public function setDefaultCategories ( array $ defaultCategories , $ includeSubcategories = true , $ order = null ) { $ defaultCategories = $ this -> parseIds ( $ defaultCategories ) ; if ( 0 === \ count ( $ defaultCategories ) ) { throw new NoNewsException ( ) ; } if ( $ includeSubcategories ) { $ newsCategoryModel = $ this -> framework -> getAdapter ( NewsCategoryModel :: class ) ; $ defaultCategories = $ newsCategoryModel -> getAllSubcategoriesIds ( $ defaultCategories ) ; } $ model = $ this -> framework -> getAdapter ( Model :: class ) ; $ newsIds = $ model -> getReferenceValues ( 'tl_news' , 'categories' , $ defaultCategories ) ; $ newsIds = $ this -> parseIds ( $ newsIds ) ; if ( 0 === \ count ( $ newsIds ) ) { throw new NoNewsException ( ) ; } $ t = $ this -> getNewsModelAdapter ( ) -> getTable ( ) ; $ this -> columns [ 'defaultCategories' ] = "$t.id IN(" . \ implode ( ',' , $ newsIds ) . ')' ; if ( $ order === 'best_match' ) { $ mapper = [ ] ; foreach ( array_unique ( $ newsIds ) as $ newsId ) { $ mapper [ $ newsId ] = count ( array_intersect ( $ defaultCategories , array_unique ( $ model -> getRelatedValues ( $ t , 'categories' , $ newsId ) ) ) ) ; } arsort ( $ mapper ) ; $ this -> options [ 'order' ] = Database :: getInstance ( ) -> findInSet ( "$t.id" , array_keys ( $ mapper ) ) ; } }
Set the default categories .
48,804
public function setCategory ( $ category , $ preserveDefault = false , $ includeSubcategories = false ) { $ model = $ this -> framework -> getAdapter ( Model :: class ) ; if ( $ includeSubcategories ) { $ newsCategoryModel = $ this -> framework -> getAdapter ( NewsCategoryModel :: class ) ; $ category = $ newsCategoryModel -> getAllSubcategoriesIds ( $ category ) ; } $ newsIds = $ model -> getReferenceValues ( 'tl_news' , 'categories' , $ category ) ; $ newsIds = $ this -> parseIds ( $ newsIds ) ; if ( 0 === \ count ( $ newsIds ) ) { throw new NoNewsException ( ) ; } if ( ! $ preserveDefault ) { unset ( $ this -> columns [ 'defaultCategories' ] ) ; } $ t = $ this -> getNewsModelAdapter ( ) -> getTable ( ) ; $ this -> columns [ ] = "$t.id IN(" . \ implode ( ',' , $ newsIds ) . ')' ; }
Set the category .
48,805
public function setExcludedNews ( array $ newsIds ) { $ newsIds = $ this -> parseIds ( $ newsIds ) ; if ( 0 === \ count ( $ newsIds ) ) { throw new NoNewsException ( ) ; } $ t = $ this -> getNewsModelAdapter ( ) -> getTable ( ) ; $ this -> columns [ ] = "$t.id NOT IN (" . \ implode ( ',' , $ newsIds ) . ')' ; }
Set the excluded news IDs .
48,806
private function parseIds ( array $ ids ) { $ ids = \ array_map ( 'intval' , $ ids ) ; $ ids = \ array_filter ( $ ids ) ; $ ids = \ array_unique ( $ ids ) ; return \ array_values ( $ ids ) ; }
Parse the record IDs .
48,807
public function onSubmitCallback ( DataContainer $ dc ) { if ( 'tl_news_category' === $ dc -> table && $ dc -> id ) { $ modelAdapter = $ this -> framework -> getAdapter ( Model :: class ) ; $ newsIds = $ modelAdapter -> getReferenceValues ( 'tl_news' , 'categories' , $ dc -> id ) ; $ newsIds = \ array_map ( 'intval' , \ array_unique ( $ newsIds ) ) ; if ( \ count ( $ newsIds ) > 0 ) { $ archiveIds = $ this -> db -> executeQuery ( 'SELECT DISTINCT(pid) FROM tl_news WHERE id IN (' . \ implode ( ',' , $ newsIds ) . ')' ) -> fetchAll ( \ PDO :: FETCH_COLUMN , 0 ) ; $ session = $ this -> session -> get ( 'news_feed_updater' ) ; $ session = \ array_merge ( ( array ) $ session , $ archiveIds ) ; $ this -> session -> set ( 'news_feed_updater' , \ array_unique ( $ session ) ) ; } } }
On data container submit callback .
48,808
public function onPasteButtonCallback ( DataContainer $ dc , array $ row , $ table , $ cr , array $ clipboard = null ) { $ disablePA = false ; $ disablePI = false ; if ( null !== $ clipboard && ( ( 'cut' === $ clipboard [ 'mode' ] && ( $ cr || ( int ) $ clipboard [ 'id' ] === ( int ) $ row [ 'id' ] ) ) || ( 'cutAll' === $ clipboard [ 'mode' ] && ( $ cr || \ in_array ( ( int ) $ row [ 'id' ] , \ array_map ( 'intval' , $ clipboard [ 'id' ] ) , true ) ) ) ) ) { $ disablePA = true ; $ disablePI = true ; } $ return = '' ; if ( $ row [ 'id' ] > 0 ) { $ return = $ this -> generatePasteImage ( 'pasteafter' , $ disablePA , $ table , $ row , $ clipboard ) ; } return $ return . $ this -> generatePasteImage ( 'pasteinto' , $ disablePI , $ table , $ row , $ clipboard ) ; }
On paste button callback .
48,809
public function onLabelCallback ( array $ row , $ label , DataContainer $ dc , $ attributes ) { $ imageAdapter = $ this -> framework -> getAdapter ( Image :: class ) ; if ( false !== \ stripos ( $ attributes , 'style="' ) ) { $ attributes = \ str_replace ( 'style="' , 'style="vertical-align:text-top;' , $ attributes ) ; } else { $ attributes .= \ trim ( $ attributes . ' style="vertical-align:text-top;"' ) ; } return $ imageAdapter -> getHtml ( 'iconPLAIN.svg' , '' , $ attributes ) . ' ' . $ label ; }
On label callback .
48,810
public function onGenerateAlias ( $ value , DataContainer $ dc ) { $ autoAlias = false ; if ( ! $ value ) { $ autoAlias = true ; $ value = StringUtil :: generateAlias ( $ dc -> activeRecord -> frontendTitle ? : $ dc -> activeRecord -> title ) ; } if ( MultilingualHelper :: isActive ( ) && $ dc instanceof Driver ) { $ exists = $ this -> db -> fetchColumn ( "SELECT id FROM {$dc->table} WHERE alias=? AND id!=? AND {$dc->getLanguageColumn()}=?" , [ $ value , $ dc -> activeRecord -> id , $ dc -> getCurrentLanguage ( ) ] ) ; } else { $ exists = $ this -> db -> fetchColumn ( "SELECT id FROM {$dc->table} WHERE alias=? AND id!=?" , [ $ value , $ dc -> activeRecord -> id ] ) ; } if ( $ exists ) { if ( $ autoAlias ) { $ value .= '-' . $ dc -> activeRecord -> id ; } else { throw new \ RuntimeException ( \ sprintf ( $ GLOBALS [ 'TL_LANG' ] [ 'ERR' ] [ 'aliasExists' ] , $ value ) ) ; } } return $ value ; }
On generate the category alias .
48,811
private function generatePasteImage ( $ type , $ disabled , $ table , array $ row , array $ clipboard = null ) { $ backendAdapter = $ this -> framework -> getAdapter ( Backend :: class ) ; $ imageAdapter = $ this -> framework -> getAdapter ( Image :: class ) ; if ( $ disabled ) { return $ imageAdapter -> getHtml ( $ type . '_.svg' ) . ' ' ; } $ url = \ sprintf ( 'act=%s&amp;mode=%s&amp;pid=%s' , $ clipboard [ 'mode' ] , ( 'pasteafter' === $ type ? 1 : 2 ) , $ row [ 'id' ] ) ; if ( ! \ is_array ( $ clipboard [ 'id' ] ) ) { $ url .= '&amp;id=' . $ clipboard [ 'id' ] ; } return \ sprintf ( '<a href="%s" title="%s" onclick="Backend.getScrollOffset()">%s</a> ' , $ backendAdapter -> addToUrl ( $ url ) , specialchars ( \ sprintf ( $ GLOBALS [ 'TL_LANG' ] [ $ table ] [ $ type ] [ 1 ] , $ row [ 'id' ] ) ) , $ imageAdapter -> getHtml ( $ type . '.svg' , \ sprintf ( $ GLOBALS [ 'TL_LANG' ] [ $ table ] [ $ type ] [ 1 ] , $ row [ 'id' ] ) ) ) ; }
Generate the paste image .
48,812
public function onParseArticles ( FrontendTemplate $ template , array $ data , Module $ module ) { $ newsCategoryModelAdapter = $ this -> framework -> getAdapter ( NewsCategoryModel :: class ) ; if ( null === ( $ models = $ newsCategoryModelAdapter -> findPublishedByNews ( $ data [ 'id' ] ) ) ) { return ; } $ this -> addCategoriesToTemplate ( $ template , $ module , $ models ) ; }
On parse the articles .
48,813
private function addCategoriesToTemplate ( FrontendTemplate $ template , Module $ module , Collection $ categories ) { $ data = [ ] ; $ list = [ ] ; $ cssClasses = trimsplit ( ' ' , $ template -> class ) ; foreach ( $ categories as $ category ) { if ( ! $ this -> manager -> isVisibleForModule ( $ category , $ module ) ) { continue ; } $ data [ $ category -> id ] = $ this -> generateCategoryData ( $ category , $ module ) ; $ list [ $ category -> id ] = $ category -> getTitle ( ) ; $ cssClasses = \ array_merge ( $ cssClasses , trimsplit ( ' ' , $ category -> getCssClass ( ) ) ) ; } \ uasort ( $ data , function ( $ a , $ b ) { return \ strnatcasecmp ( $ a [ 'name' ] , $ b [ 'name' ] ) ; } ) ; \ asort ( $ list ) ; $ template -> categories = $ data ; $ template -> categoriesList = $ list ; if ( count ( $ cssClasses = \ array_unique ( $ cssClasses ) ) > 0 ) { $ template -> class = ' ' . \ implode ( ' ' , $ cssClasses ) ; } }
Add categories to the template .
48,814
private function generateCategoryData ( NewsCategoryModel $ category , Module $ module ) { $ data = $ category -> row ( ) ; $ data [ 'model' ] = $ category ; $ data [ 'name' ] = $ category -> getTitle ( ) ; $ data [ 'class' ] = $ category -> getCssClass ( ) ; $ data [ 'href' ] = '' ; $ data [ 'hrefWithParam' ] = '' ; $ data [ 'targetPage' ] = null ; $ stringUtilAdapter = $ this -> framework -> getAdapter ( StringUtil :: class ) ; $ data [ 'linkTitle' ] = $ stringUtilAdapter -> specialchars ( $ data [ 'name' ] ) ; $ pageAdapter = $ this -> framework -> getAdapter ( PageModel :: class ) ; if ( $ module -> news_categoryFilterPage && null !== ( $ targetPage = $ pageAdapter -> findPublishedById ( $ module -> news_categoryFilterPage ) ) ) { $ data [ 'href' ] = $ this -> manager -> generateUrl ( $ category , $ targetPage ) ; $ data [ 'hrefWithParam' ] = $ data [ 'href' ] ; $ data [ 'targetPage' ] = $ targetPage ; } elseif ( null !== ( $ targetPage = $ this -> manager -> getTargetPage ( $ category ) ) ) { $ data [ 'href' ] = $ targetPage -> getFrontendUrl ( ) ; $ data [ 'hrefWithParam' ] = $ this -> manager -> generateUrl ( $ category , $ targetPage ) ; $ data [ 'targetPage' ] = $ targetPage ; } $ data [ 'generateUrl' ] = function ( PageModel $ page , $ absolute = false ) use ( $ category ) { return $ this -> manager -> generateUrl ( $ category , $ page , $ absolute ) ; } ; if ( null !== ( $ image = $ this -> manager -> getImage ( $ category ) ) ) { $ controllerAdapter = $ this -> framework -> getAdapter ( Controller :: class ) ; $ data [ 'image' ] = new \ stdClass ( ) ; $ controllerAdapter -> addImageToTemplate ( $ data [ 'image' ] , [ 'singleSRC' => $ image -> path , 'size' => $ module -> news_categoryImgSize ] ) ; } else { $ data [ 'image' ] = null ; } return $ data ; }
Generate the category data .
48,815
protected function validator ( $ input ) { $ this -> checkValue ( $ input ) ; if ( $ this -> hasErrors ( ) ) { return '' ; } if ( ! $ input ) { if ( $ this -> mandatory ) { $ this -> addError ( sprintf ( $ GLOBALS [ 'TL_LANG' ] [ 'ERR' ] [ 'mandatory' ] , $ this -> strLabel ) ) ; } return '' ; } elseif ( false === strpos ( $ input , ',' ) ) { return $ this -> multiple ? [ ( int ) $ input ] : ( int ) $ input ; } $ arrValue = array_map ( 'intval' , array_filter ( explode ( ',' , $ input ) ) ) ; return $ this -> multiple ? $ arrValue : $ arrValue [ 0 ] ; }
Return an array if the multiple attribute is set .
48,816
protected function checkValue ( $ input ) { if ( '' === $ input || ! is_array ( $ this -> rootNodes ) ) { return ; } if ( false === strpos ( $ input , ',' ) ) { $ ids = [ ( int ) $ input ] ; } else { $ ids = array_map ( 'intval' , array_filter ( explode ( ',' , $ input ) ) ) ; } if ( count ( array_diff ( $ ids , array_merge ( $ this -> rootNodes , Database :: getInstance ( ) -> getChildRecords ( $ this -> rootNodes , 'tl_news_category' ) ) ) ) > 0 ) { $ this -> addError ( $ GLOBALS [ 'TL_LANG' ] [ 'ERR' ] [ 'invalidPages' ] ) ; } }
Check the selected value .
48,817
public function onGetNewsModules ( ) { $ modules = [ ] ; $ records = $ this -> db -> fetchAll ( "SELECT m.id, m.name, t.name AS theme FROM tl_module m LEFT JOIN tl_theme t ON m.pid=t.id WHERE m.type IN ('newslist', 'newsarchive') ORDER BY t.name, m.name" ) ; foreach ( $ records as $ record ) { $ modules [ $ record [ 'theme' ] ] [ $ record [ 'id' ] ] = \ sprintf ( '%s (ID %s)' , $ record [ 'name' ] , $ record [ 'id' ] ) ; } return $ modules ; }
Get news modules and return them as array .
48,818
public function getCriteriaForArchiveModule ( array $ archives , $ begin , $ end , Module $ module ) { $ criteria = new NewsCriteria ( $ this -> framework ) ; try { $ criteria -> setBasicCriteria ( $ archives , $ module -> news_order ) ; $ criteria -> setTimeFrame ( $ begin , $ end ) ; $ this -> setRegularListCriteria ( $ criteria , $ module ) ; } catch ( NoNewsException $ e ) { return null ; } return $ criteria ; }
Get the criteria for archive module .
48,819
public function getCriteriaForListModule ( array $ archives , $ featured , Module $ module ) { $ criteria = new NewsCriteria ( $ this -> framework ) ; try { $ criteria -> setBasicCriteria ( $ archives , $ module -> news_order ) ; if ( null !== $ featured ) { $ criteria -> setFeatured ( $ featured ) ; } if ( $ module -> news_relatedCategories ) { $ this -> setRelatedListCriteria ( $ criteria , $ module ) ; } else { $ this -> setRegularListCriteria ( $ criteria , $ module ) ; } } catch ( NoNewsException $ e ) { return null ; } return $ criteria ; }
Get the criteria for list module .
48,820
public function getCriteriaForMenuModule ( array $ archives , Module $ module ) { $ criteria = new NewsCriteria ( $ this -> framework ) ; try { $ criteria -> setBasicCriteria ( $ archives , $ module -> news_order ) ; $ this -> setRegularListCriteria ( $ criteria , $ module ) ; } catch ( NoNewsException $ e ) { return null ; } return $ criteria ; }
Get the criteria for menu module .
48,821
private function setRegularListCriteria ( NewsCriteria $ criteria , Module $ module ) { if ( \ count ( $ default = StringUtil :: deserialize ( $ module -> news_filterDefault , true ) ) > 0 ) { $ criteria -> setDefaultCategories ( $ default ) ; } if ( $ module -> news_filterCategoriesCumulative ) { $ input = $ this -> framework -> getAdapter ( Input :: class ) ; $ param = $ this -> manager -> getParameterName ( ) ; if ( $ aliases = $ input -> get ( $ param ) ) { $ aliases = StringUtil :: trimsplit ( CumulativeFilterModule :: getCategorySeparator ( ) , $ aliases ) ; $ aliases = array_unique ( array_filter ( $ aliases ) ) ; if ( count ( $ aliases ) > 0 ) { $ model = $ this -> framework -> getAdapter ( NewsCategoryModel :: class ) ; foreach ( $ aliases as $ alias ) { if ( null === ( $ category = $ model -> findPublishedByIdOrAlias ( $ alias ) ) ) { throw new CategoryNotFoundException ( sprintf ( 'News category "%s" was not found' , $ alias ) ) ; } $ criteria -> setCategory ( $ category -> id , ( bool ) $ module -> news_filterPreserve , ( bool ) $ module -> news_includeSubcategories ) ; } } } return ; } if ( $ module -> news_filterCategories ) { $ input = $ this -> framework -> getAdapter ( Input :: class ) ; $ param = $ this -> manager -> getParameterName ( ) ; if ( $ alias = $ input -> get ( $ param ) ) { $ model = $ this -> framework -> getAdapter ( NewsCategoryModel :: class ) ; if ( null === ( $ category = $ model -> findPublishedByIdOrAlias ( $ alias ) ) ) { throw new CategoryNotFoundException ( sprintf ( 'News category "%s" was not found' , $ alias ) ) ; } $ criteria -> setCategory ( $ category -> id , ( bool ) $ module -> news_filterPreserve , ( bool ) $ module -> news_includeSubcategories ) ; } } }
Set the regular list criteria .
48,822
private function setRelatedListCriteria ( NewsCriteria $ criteria , Module $ module ) { if ( null === ( $ news = $ module -> currentNews ) ) { throw new NoNewsException ( ) ; } $ adapter = $ this -> framework -> getAdapter ( Model :: class ) ; $ categories = \ array_unique ( $ adapter -> getRelatedValues ( $ news -> getTable ( ) , 'categories' , $ news -> id ) ) ; if ( 0 === \ count ( $ categories ) ) { throw new NoNewsException ( ) ; } $ categories = \ array_map ( 'intval' , $ categories ) ; $ excluded = $ this -> db -> fetchAll ( 'SELECT id FROM tl_news_category WHERE excludeInRelated=1' ) ; foreach ( $ excluded as $ category ) { if ( false !== ( $ index = \ array_search ( ( int ) $ category [ 'id' ] , $ categories , true ) ) ) { unset ( $ categories [ $ index ] ) ; } } if ( $ module -> news_categoriesRoot > 0 ) { $ categories = array_intersect ( $ categories , NewsCategoryModel :: getAllSubcategoriesIds ( $ module -> news_categoriesRoot ) ) ; } if ( 0 === \ count ( $ categories ) ) { throw new NoNewsException ( ) ; } $ criteria -> setDefaultCategories ( $ categories , ( bool ) $ module -> news_includeSubcategories , $ module -> news_relatedCategoriesOrder ) ; $ criteria -> setExcludedNews ( [ $ news -> id ] ) ; }
Set the related list criteria .
48,823
private function updateAlias ( ChangelanguageNavigationEvent $ event ) { $ modelAdapter = $ this -> framework -> getAdapter ( NewsCategoryModel :: class ) ; $ param = $ this -> manager -> getParameterName ( ) ; if ( ! ( $ alias = $ event -> getUrlParameterBag ( ) -> getUrlAttribute ( $ param ) ) ) { return ; } $ model = $ modelAdapter -> findPublishedByIdOrAlias ( $ alias ) ; if ( null !== $ model && $ model instanceof Multilingual ) { $ event -> getUrlParameterBag ( ) -> setUrlAttribute ( $ param , $ model -> getAlias ( $ event -> getNavigationItem ( ) -> getRootPage ( ) -> rootLanguage ) ) ; } }
Update the category alias value .
48,824
private function updateParameter ( ChangelanguageNavigationEvent $ event ) { $ currentParam = $ this -> manager -> getParameterName ( ) ; $ newParam = $ this -> manager -> getParameterName ( $ event -> getNavigationItem ( ) -> getRootPage ( ) -> id ) ; $ parameters = $ event -> getUrlParameterBag ( ) ; $ attributes = $ parameters -> getUrlAttributes ( ) ; if ( ! isset ( $ attributes [ $ currentParam ] ) ) { return ; } $ attributes [ $ newParam ] = $ attributes [ $ currentParam ] ; unset ( $ attributes [ $ currentParam ] ) ; $ parameters -> setUrlAttributes ( $ attributes ) ; }
Update the parameter name .
48,825
protected function getActiveCategories ( array $ customCategories = [ ] ) { $ param = System :: getContainer ( ) -> get ( 'codefog_news_categories.manager' ) -> getParameterName ( ) ; if ( ! ( $ aliases = Input :: get ( $ param ) ) ) { return null ; } $ aliases = StringUtil :: trimsplit ( static :: getCategorySeparator ( ) , $ aliases ) ; $ aliases = array_unique ( array_filter ( $ aliases ) ) ; if ( count ( $ aliases ) === 0 ) { return null ; } $ models = NewsCategoryModel :: findPublishedByArchives ( $ this -> news_archives , $ customCategories , $ aliases ) ; if ( $ models === null && count ( $ aliases ) !== 0 ) { Controller :: redirect ( $ this -> getTargetPage ( ) -> getFrontendUrl ( ) ) ; } if ( $ models !== null ) { $ realAliases = [ ] ; foreach ( $ models as $ model ) { $ realAliases [ ] = $ this -> manager -> getCategoryAlias ( $ model , $ GLOBALS [ 'objPage' ] ) ; } if ( count ( array_diff ( $ aliases , $ realAliases ) ) > 0 ) { Controller :: redirect ( $ this -> getTargetPage ( ) -> getFrontendUrl ( sprintf ( '/%s/%s' , $ this -> manager -> getParameterName ( $ GLOBALS [ 'objPage' ] -> rootId ) , implode ( static :: getCategorySeparator ( ) , $ realAliases ) ) ) ) ; } } return $ models ; }
Get the active categories
48,826
protected function getInactiveCategories ( array $ customCategories = [ ] ) { if ( $ this -> activeCategories !== null ) { $ columns = [ ] ; $ values = [ ] ; foreach ( $ this -> activeCategories as $ activeCategory ) { $ criteria = new NewsCriteria ( System :: getContainer ( ) -> get ( 'contao.framework' ) ) ; try { $ criteria -> setBasicCriteria ( $ this -> news_archives ) ; $ criteria -> setCategory ( $ activeCategory -> id , false , ( bool ) $ this -> news_includeSubcategories ) ; } catch ( NoNewsException $ e ) { continue ; } $ columns = array_merge ( $ columns , $ criteria -> getColumns ( ) ) ; $ values = array_merge ( $ values , $ criteria -> getValues ( ) ) ; } if ( count ( $ columns ) === 0 ) { return null ; } $ newsIds = Database :: getInstance ( ) -> prepare ( 'SELECT id FROM tl_news WHERE ' . implode ( ' AND ' , $ columns ) ) -> execute ( $ values ) -> fetchEach ( 'id' ) ; if ( count ( $ newsIds ) === 0 ) { return null ; } $ categoryIds = Model :: getRelatedValues ( 'tl_news' , 'categories' , $ newsIds ) ; $ categoryIds = \ array_map ( 'intval' , $ categoryIds ) ; $ categoryIds = \ array_unique ( \ array_filter ( $ categoryIds ) ) ; if ( $ this -> news_includeSubcategories ) { foreach ( $ categoryIds as $ categoryId ) { $ categoryIds = array_merge ( $ categoryIds , Database :: getInstance ( ) -> getParentRecords ( $ categoryId , 'tl_news_category' ) ) ; } } $ categoryIds = array_diff ( $ categoryIds , $ this -> activeCategories -> fetchEach ( 'id' ) ) ; if ( count ( $ customCategories ) > 0 ) { $ categoryIds = array_intersect ( $ categoryIds , $ customCategories ) ; } if ( count ( $ categoryIds ) === 0 ) { return null ; } $ customCategories = $ categoryIds ; } return NewsCategoryModel :: findPublishedByArchives ( $ this -> news_archives , $ customCategories ) ; }
Get the inactive categories
48,827
protected function getTargetPage ( ) { static $ page ; if ( null === $ page ) { if ( $ this -> jumpTo > 0 && ( int ) $ GLOBALS [ 'objPage' ] -> id !== ( int ) $ this -> jumpTo && null !== ( $ target = PageModel :: findPublishedById ( $ this -> jumpTo ) ) ) { $ page = $ target ; } else { $ page = $ GLOBALS [ 'objPage' ] ; } } return $ page ; }
Get the target page .
48,828
protected function getCurrentNewsCategories ( ) { if ( ! ( $ alias = Input :: getAutoItem ( 'items' , false , true ) ) || null === ( $ news = NewsModel :: findPublishedByParentAndIdOrAlias ( $ alias , $ this -> news_archives ) ) ) { return [ ] ; } $ ids = Model :: getRelatedValues ( 'tl_news' , 'categories' , $ news -> id ) ; $ ids = \ array_map ( 'intval' , \ array_unique ( $ ids ) ) ; return $ ids ; }
Get the category IDs of the current news item .
48,829
protected function generateItemCssClass ( NewsCategoryModel $ category ) { $ cssClasses = [ $ category -> getCssClass ( ) ] ; if ( \ in_array ( ( int ) $ category -> id , $ this -> manager -> getTrailIds ( $ category ) , true ) ) { $ cssClasses [ ] = 'trail' ; } if ( \ in_array ( ( int ) $ category -> id , $ this -> currentNewsCategories , true ) ) { $ cssClasses [ ] = 'news_trail' ; } return \ implode ( ' ' , $ cssClasses ) ; }
Generate the item CSS class .
48,830
protected function compileYearlyMenu ( ) { $ arrData = array ( ) ; $ time = \ Date :: floorToMinute ( ) ; $ newsIds = $ this -> getFilteredNewsIds ( ) ; $ objDates = $ this -> Database -> query ( "SELECT FROM_UNIXTIME(date, '%Y') AS year, COUNT(*) AS count FROM tl_news WHERE pid IN(" . implode ( ',' , array_map ( 'intval' , $ this -> news_archives ) ) . ")" . ( ( ! BE_USER_LOGGED_IN || TL_MODE == 'BE' ) ? " AND (start='' OR start<='$time') AND (stop='' OR stop>'" . ( $ time + 60 ) . "') AND published='1'" : "" ) . ( ( count ( $ newsIds ) > 0 ) ? ( " AND id IN (" . implode ( ',' , $ newsIds ) . ")" ) : "" ) . " GROUP BY year ORDER BY year DESC" ) ; while ( $ objDates -> next ( ) ) { $ arrData [ $ objDates -> year ] = $ objDates -> count ; } ( $ this -> news_order == 'ascending' ) ? ksort ( $ arrData ) : krsort ( $ arrData ) ; $ arrItems = array ( ) ; $ count = 0 ; $ limit = count ( $ arrData ) ; foreach ( $ arrData as $ intYear => $ intCount ) { $ intDate = $ intYear ; $ quantity = sprintf ( ( ( $ intCount < 2 ) ? $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'entry' ] : $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'entries' ] ) , $ intCount ) ; $ arrItems [ $ intYear ] [ 'date' ] = $ intDate ; $ arrItems [ $ intYear ] [ 'link' ] = $ intYear ; $ arrItems [ $ intYear ] [ 'href' ] = $ this -> strUrl . '?year=' . $ intDate ; $ arrItems [ $ intYear ] [ 'title' ] = \ StringUtil :: specialchars ( $ intYear . ' (' . $ quantity . ')' ) ; $ arrItems [ $ intYear ] [ 'class' ] = trim ( ( ( ++ $ count == 1 ) ? 'first ' : '' ) . ( ( $ count == $ limit ) ? 'last' : '' ) ) ; $ arrItems [ $ intYear ] [ 'isActive' ] = ( \ Input :: get ( 'year' ) == $ intDate ) ; $ arrItems [ $ intYear ] [ 'quantity' ] = $ quantity ; } $ this -> Template -> yearly = true ; $ this -> Template -> items = $ arrItems ; $ this -> Template -> showQuantity = ( $ this -> news_showQuantity != '' ) ; }
Generate the yearly menu
48,831
protected function generateCategoryUrl ( ) { if ( $ this -> jumpTo && ( $ target = $ this -> objModel -> getRelated ( 'jumpTo' ) ) instanceof PageModel ) { $ page = $ target ; } else { $ page = $ GLOBALS [ 'objPage' ] ; } $ manager = System :: getContainer ( ) -> get ( 'codefog_news_categories.manager' ) ; $ category = NewsCategoryModel :: findPublishedByIdOrAlias ( Input :: get ( $ manager -> getParameterName ( ) ) ) ; if ( $ category !== null ) { $ url = $ manager -> generateUrl ( $ category , $ page ) ; } else { $ url = $ page -> getFrontendUrl ( ) ; } return $ url ; }
Generate the menu URL with category
48,832
protected function getFilteredNewsIds ( ) { try { $ criteria = System :: getContainer ( ) -> get ( 'codefog_news_categories.news_criteria_builder' ) -> getCriteriaForMenuModule ( $ this -> news_archives , $ this ) ; } catch ( CategoryNotFoundException $ e ) { throw new PageNotFoundException ( $ e -> getMessage ( ) ) ; } if ( $ criteria === null ) { return [ ] ; } $ table = $ criteria -> getNewsModelAdapter ( ) -> getTable ( ) ; return Database :: getInstance ( ) -> prepare ( "SELECT id FROM $table WHERE " . implode ( ' AND ' , $ criteria -> getColumns ( ) ) ) -> execute ( $ criteria -> getValues ( ) ) -> fetchEach ( 'id' ) ; }
Get the filtered news IDs
48,833
public function onLoadCallback ( DataContainer $ dc ) { if ( ! $ dc -> id ) { return ; } $ input = $ this -> framework -> getAdapter ( Input :: class ) ; if ( $ input -> get ( 'act' ) === 'editAll' || $ input -> get ( 'act' ) === 'overrideAll' ) { $ categories = $ this -> db -> fetchColumn ( 'SELECT categories FROM tl_news_archive WHERE limitCategories=1 AND id=?' , [ $ dc -> id ] ) ; } else { $ categories = $ this -> db -> fetchColumn ( 'SELECT categories FROM tl_news_archive WHERE limitCategories=1 AND id=(SELECT pid FROM tl_news WHERE id=?)' , [ $ dc -> id ] ) ; } if ( ! $ categories || 0 === \ count ( $ categories = StringUtil :: deserialize ( $ categories , true ) ) ) { return ; } $ GLOBALS [ 'TL_DCA' ] [ $ dc -> table ] [ 'fields' ] [ 'categories' ] [ 'eval' ] [ 'rootNodes' ] = $ categories ; }
On data container load . Limit the categories set in the news archive settings .
48,834
public function onSubmitCallback ( DataContainer $ dc ) { if ( $ this -> permissionChecker -> canUserAssignCategories ( ) || $ dc -> activeRecord -> tstamp > 0 ) { return ; } $ dc -> field = 'categories' ; $ relations = new Relations ( ) ; $ relations -> updateRelatedRecords ( $ this -> permissionChecker -> getUserDefaultCategories ( ) , $ dc ) ; $ dc -> field = null ; }
On submit record . Update the category relations .
48,835
public function onCategoriesOptionsCallback ( ) { $ input = $ this -> framework -> getAdapter ( Input :: class ) ; if ( $ input -> get ( 'act' ) && $ input -> get ( 'act' ) !== 'select' ) { return [ ] ; } return $ this -> generateOptionsRecursively ( ) ; }
On categories options callback
48,836
private function generateOptionsRecursively ( $ pid = 0 , $ prefix = '' ) { $ options = [ ] ; $ records = $ this -> db -> fetchAll ( 'SELECT * FROM tl_news_category WHERE pid=? ORDER BY sorting' , [ $ pid ] ) ; foreach ( $ records as $ record ) { $ options [ $ record [ 'id' ] ] = $ prefix . $ record [ 'title' ] ; foreach ( $ this -> generateOptionsRecursively ( $ record [ 'id' ] , $ record [ 'title' ] . ' / ' ) as $ k => $ v ) { $ options [ $ k ] = $ v ; } } return $ options ; }
Generate the options recursively
48,837
public function getCssClass ( ) { $ cssClasses = [ 'news_category_' . $ this -> id , 'category_' . $ this -> id , ] ; if ( $ this -> cssClass ) { $ cssClasses [ ] = $ this -> cssClass ; } return \ implode ( ' ' , \ array_unique ( $ cssClasses ) ) ; }
Get the CSS class .
48,838
public static function findPublishedByArchives ( array $ archives , array $ ids = [ ] , array $ aliases = [ ] ) { if ( 0 === \ count ( $ archives ) || false === ( $ relation = Relations :: getRelation ( 'tl_news' , 'categories' ) ) ) { return null ; } $ t = static :: getTableAlias ( ) ; $ values = [ ] ; $ subSelect = "SELECT {$relation['related_field']} FROM {$relation['table']} WHERE {$relation['reference_field']} IN (SELECT id FROM tl_news WHERE pid IN (" . \ implode ( ',' , \ array_map ( 'intval' , $ archives ) ) . ')' ; if ( ! BE_USER_LOGGED_IN ) { $ time = Date :: floorToMinute ( ) ; $ subSelect .= ' AND (start=? OR start<=?) AND (stop=? OR stop>?) AND published=?' ; $ values = \ array_merge ( $ values , [ '' , $ time , '' , $ time + 60 , 1 ] ) ; } $ subSelect .= ')' ; $ columns = [ "$t.id IN ($subSelect)" ] ; if ( \ count ( $ ids ) > 0 ) { $ columns [ ] = "$t.id IN (" . \ implode ( ',' , \ array_map ( 'intval' , $ ids ) ) . ')' ; } if ( \ count ( $ aliases ) > 0 ) { $ columns [ ] = "$t.alias IN ('" . \ implode ( "','" , $ aliases ) . "')" ; } if ( ! BE_USER_LOGGED_IN ) { $ columns [ ] = "$t.published=?" ; $ values [ ] = 1 ; } return static :: findBy ( $ columns , $ values , [ 'order' => "$t.sorting" ] ) ; }
Find published news categories by news criteria .
48,839
public static function findPublishedByIdOrAlias ( $ idOrAlias ) { $ values = [ ] ; $ columns = [ ] ; $ t = static :: getTableAlias ( ) ; if ( is_numeric ( $ idOrAlias ) ) { $ columns [ ] = "$t.id=?" ; $ values [ ] = ( int ) $ idOrAlias ; } else { if ( MultilingualHelper :: isActive ( ) ) { $ columns [ ] = '(t1.alias=? OR t2.alias=?)' ; $ values [ ] = $ idOrAlias ; $ values [ ] = $ idOrAlias ; } else { $ columns [ ] = "$t.alias=?" ; $ values [ ] = $ idOrAlias ; } } if ( ! BE_USER_LOGGED_IN ) { $ columns [ ] = "$t.published=?" ; $ values [ ] = 1 ; } return static :: findOneBy ( $ columns , $ values ) ; }
Find published category by ID or alias .
48,840
public static function findPublishedByIds ( array $ ids , $ pid = null ) { if ( 0 === \ count ( $ ids ) ) { return null ; } $ t = static :: getTableAlias ( ) ; $ columns = [ "$t.id IN (" . \ implode ( ',' , \ array_map ( 'intval' , $ ids ) ) . ')' ] ; $ values = [ ] ; if ( null !== $ pid ) { $ columns [ ] = "$t.pid=?" ; $ values [ ] = $ pid ; } if ( ! BE_USER_LOGGED_IN ) { $ columns [ ] = "$t.published=?" ; $ values [ ] = 1 ; } return static :: findBy ( $ columns , $ values , [ 'order' => "$t.sorting" ] ) ; }
Find published news categories by parent ID and IDs .
48,841
public static function findPublishedByPid ( $ pid ) { $ t = static :: getTableAlias ( ) ; $ columns = [ "$t.pid=?" ] ; $ values = [ $ pid ] ; if ( ! BE_USER_LOGGED_IN ) { $ columns [ ] = "$t.published=?" ; $ values [ ] = 1 ; } return static :: findBy ( $ columns , $ values , [ 'order' => "$t.sorting" ] ) ; }
Find published news categories by parent ID .
48,842
public static function findPublishedByNews ( $ newsId ) { if ( 0 === \ count ( $ ids = Model :: getRelatedValues ( 'tl_news' , 'categories' , $ newsId ) ) ) { return null ; } $ t = static :: getTableAlias ( ) ; $ columns = [ "$t.id IN (" . \ implode ( ',' , \ array_map ( 'intval' , \ array_unique ( $ ids ) ) ) . ')' ] ; $ values = [ ] ; if ( ! BE_USER_LOGGED_IN ) { $ columns [ ] = "$t.published=?" ; $ values [ ] = 1 ; } return static :: findBy ( $ columns , $ values , [ 'order' => "$t.sorting" ] ) ; }
Find the published categories by news .
48,843
public static function getUsage ( array $ archives = [ ] , $ category = null , $ includeSubcategories = false , array $ cumulativeCategories = [ ] ) { $ t = NewsModel :: getTable ( ) ; if ( null !== $ category && $ includeSubcategories ) { $ category = static :: getAllSubcategoriesIds ( $ category ) ; } $ ids = Model :: getReferenceValues ( $ t , 'categories' , $ category ) ; if ( count ( $ cumulativeCategories ) > 0 ) { $ cumulativeIds = null ; foreach ( $ cumulativeCategories as $ cumulativeCategory ) { $ tmp = Model :: getReferenceValues ( $ t , 'categories' , $ cumulativeCategory ) ; if ( $ includeSubcategories ) { $ tmp = static :: getAllSubcategoriesIds ( $ tmp ) ; } if ( $ cumulativeIds === null ) { $ cumulativeIds = $ tmp ; } else { $ cumulativeIds = array_intersect ( $ cumulativeIds , $ tmp ) ; } } $ ids = array_intersect ( $ ids , $ cumulativeIds ) ; } if ( 0 === \ count ( $ ids ) ) { return 0 ; } $ columns = [ "$t.id IN (" . \ implode ( ',' , \ array_unique ( $ ids ) ) . ')' ] ; $ values = [ ] ; if ( \ count ( $ archives ) ) { $ columns [ ] = "$t.pid IN (" . \ implode ( ',' , \ array_map ( 'intval' , $ archives ) ) . ')' ; } if ( ! BE_USER_LOGGED_IN ) { $ time = Date :: floorToMinute ( ) ; $ columns [ ] = "($t.start=? OR $t.start<=?) AND ($t.stop=? OR $t.stop>?) AND $t.published=?" ; $ values = \ array_merge ( $ values , [ '' , $ time , '' , $ time + 60 , 1 ] ) ; } return NewsModel :: countBy ( $ columns , $ values ) ; }
Count the published news by archives .
48,844
public static function getAllSubcategoriesIds ( $ category ) { $ ids = Database :: getInstance ( ) -> getChildRecords ( $ category , static :: $ strTable , false , ( array ) $ category , ( ! BE_USER_LOGGED_IN ? 'published=1' : '' ) ) ; $ ids = \ array_map ( 'intval' , $ ids ) ; return $ ids ; }
Get all subcategory IDs .
48,845
public function generateUrl ( NewsCategoryModel $ category , PageModel $ page , $ absolute = false ) { $ page -> loadDetails ( ) ; $ params = '/' . $ this -> getParameterName ( $ page -> rootId ) . '/' . $ this -> getCategoryAlias ( $ category , $ page ) ; return $ absolute ? $ page -> getAbsoluteUrl ( $ params ) : $ page -> getFrontendUrl ( $ params ) ; }
Generate the category URL .
48,846
public function getImage ( NewsCategoryModel $ category ) { if ( null === ( $ image = $ category -> getImage ( ) ) || ! \ is_file ( TL_ROOT . '/' . $ image -> path ) ) { return null ; } return $ image ; }
Get the image .
48,847
public function getCategoryAlias ( NewsCategoryModel $ category , PageModel $ page ) { if ( $ category instanceof Multilingual ) { return $ category -> getAlias ( $ page -> language ) ; } return $ category -> alias ; }
Get the category alias
48,848
public function getParameterName ( $ rootId = null ) { $ rootId = $ rootId ? : $ GLOBALS [ 'objPage' ] -> rootId ; if ( ! $ rootId || null === ( $ rootPage = PageModel :: findByPk ( $ rootId ) ) ) { return '' ; } return $ rootPage -> newsCategories_param ? : 'category' ; }
Get the parameter name .
48,849
public function getTargetPage ( NewsCategoryModel $ category ) { $ pageId = $ category -> jumpTo ; if ( ! $ pageId ) { $ pid = $ category -> pid ; do { $ parent = $ category -> findByPk ( $ pid ) ; if ( null !== $ parent ) { $ pid = $ parent -> pid ; $ pageId = $ parent -> jumpTo ; } } while ( $ pid && ! $ pageId ) ; } if ( $ pageId ) { $ pageAdapter = $ this -> framework -> getAdapter ( PageModel :: class ) ; return $ pageAdapter -> findPublishedById ( $ pageId ) ; } return null ; }
Get the category target page .
48,850
public function getTrailIds ( NewsCategoryModel $ category ) { static $ ids ; if ( ! \ is_array ( $ ids ) ) { $ db = $ this -> framework -> createInstance ( Database :: class ) ; $ ids = $ db -> getParentRecords ( $ category -> id , $ category -> getTable ( ) ) ; $ ids = \ array_map ( 'intval' , \ array_unique ( $ ids ) ) ; unset ( $ ids [ \ array_search ( $ category -> id , $ ids , true ) ] ) ; } return $ ids ; }
Get the category trail IDs .
48,851
public function isVisibleForModule ( NewsCategoryModel $ category , Module $ module ) { if ( $ category -> hideInList && ( $ module instanceof ModuleNewsList || $ module instanceof ModuleNewsArchive ) ) { return false ; } if ( $ category -> hideInReader && $ module instanceof ModuleNewsReader ) { return false ; } return true ; }
Return true if the category is visible for module .
48,852
public function canUserAssignCategories ( ) { $ user = $ this -> getUser ( ) ; return $ user -> isAdmin || \ in_array ( 'tl_news::categories' , $ user -> alexf , true ) ; }
Return true if the user can assign news categories .
48,853
public function getUserAllowedRoots ( ) { $ user = $ this -> getUser ( ) ; if ( $ user -> isAdmin ) { return null ; } return \ array_map ( 'intval' , ( array ) $ user -> newscategories_roots ) ; }
Get the user allowed roots . Return null if the user has no limitation .
48,854
public function isUserAllowedNewsCategory ( $ categoryId ) { if ( null === ( $ roots = $ this -> getUserAllowedRoots ( ) ) ) { return true ; } $ db = $ this -> framework -> createInstance ( Database :: class ) ; $ ids = $ db -> getChildRecords ( $ roots , 'tl_news_category' , false , $ roots ) ; $ ids = \ array_map ( 'intval' , $ ids ) ; return \ in_array ( ( int ) $ categoryId , $ ids , true ) ; }
Return if the user is allowed to manage the news category .
48,855
public function addCategoryToAllowedRoots ( $ categoryId ) { if ( null === ( $ roots = $ this -> getUserAllowedRoots ( ) ) ) { return ; } $ categoryId = ( int ) $ categoryId ; $ user = $ this -> getUser ( ) ; $ stringUtil = $ this -> framework -> getAdapter ( StringUtil :: class ) ; if ( 'custom' !== $ user -> inherit ) { $ groups = $ this -> db -> fetchAll ( 'SELECT id, newscategories, newscategories_roots FROM tl_user_group WHERE id IN(' . \ implode ( ',' , \ array_map ( 'intval' , $ user -> groups ) ) . ')' ) ; foreach ( $ groups as $ group ) { $ permissions = $ stringUtil -> deserialize ( $ group [ 'newscategories' ] , true ) ; if ( \ in_array ( 'manage' , $ permissions , true ) ) { $ categoryIds = $ stringUtil -> deserialize ( $ group [ 'newscategories_roots' ] , true ) ; $ categoryIds [ ] = $ categoryId ; $ this -> db -> update ( 'tl_user_group' , [ 'newscategories_roots' => \ serialize ( $ categoryIds ) ] , [ 'id' => $ group [ 'id' ] ] ) ; } } } if ( 'group' !== $ user -> inherit ) { $ userData = $ this -> db -> fetchAssoc ( 'SELECT newscategories, newscategories_roots FROM tl_user WHERE id=?' , [ $ user -> id ] ) ; $ permissions = $ stringUtil -> deserialize ( $ userData [ 'newscategories' ] , true ) ; if ( \ in_array ( 'manage' , $ permissions , true ) ) { $ categoryIds = $ stringUtil -> deserialize ( $ userData [ 'newscategories_roots' ] , true ) ; $ categoryIds [ ] = $ categoryId ; $ this -> db -> update ( 'tl_user' , [ 'newscategories_roots' => \ serialize ( $ categoryIds ) ] , [ 'id' => $ user -> id ] ) ; } } $ user -> newscategories_roots = \ array_merge ( $ roots , [ $ categoryId ] ) ; }
Add the category to allowed roots .
48,856
public function generate ( ) { if ( TL_MODE === 'BE' ) { $ template = new BackendTemplate ( 'be_wildcard' ) ; $ template -> wildcard = '### ' . Utf8 :: strtoupper ( $ GLOBALS [ 'TL_LANG' ] [ 'FMD' ] [ 'newscategories' ] [ 0 ] ) . ' ###' ; $ template -> title = $ this -> headline ; $ template -> id = $ this -> id ; $ template -> link = $ this -> name ; $ template -> href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $ this -> id ; return $ template -> parse ( ) ; } $ this -> news_archives = $ this -> sortOutProtected ( StringUtil :: deserialize ( $ this -> news_archives , true ) ) ; if ( 0 === \ count ( $ this -> news_archives ) ) { return '' ; } $ this -> manager = System :: getContainer ( ) -> get ( 'codefog_news_categories.manager' ) ; $ this -> currentNewsCategories = $ this -> getCurrentNewsCategories ( ) ; return parent :: generate ( ) ; }
Display a wildcard in the back end .
48,857
protected function getCategories ( ) { $ customCategories = $ this -> news_customCategories ? StringUtil :: deserialize ( $ this -> news_categories , true ) : [ ] ; if ( \ count ( $ customCategories ) > 0 ) { $ customCategories = NewsCategoryModel :: getAllSubcategoriesIds ( $ customCategories ) ; } if ( $ this -> news_showEmptyCategories ) { if ( \ count ( $ customCategories ) > 0 ) { $ categories = NewsCategoryModel :: findPublishedByIds ( $ customCategories ) ; } else { $ categories = NewsCategoryModel :: findPublished ( ) ; } } else { $ categories = NewsCategoryModel :: findPublishedByArchives ( $ this -> news_archives , $ customCategories ) ; } return $ categories ; }
Get the categories
48,858
protected function generateItem ( $ url , $ link , $ title , $ cssClass , $ isActive , $ subitems = '' , NewsCategoryModel $ category = null ) { $ data = [ ] ; if ( null !== $ category ) { $ data = $ category -> row ( ) ; } $ data [ 'isActive' ] = $ isActive ; $ data [ 'subitems' ] = $ subitems ; $ data [ 'class' ] = $ cssClass ; $ data [ 'title' ] = StringUtil :: specialchars ( $ title ) ; $ data [ 'linkTitle' ] = StringUtil :: specialchars ( $ title ) ; $ data [ 'link' ] = $ link ; $ data [ 'href' ] = ampersand ( $ url ) ; $ data [ 'quantity' ] = 0 ; if ( $ isActive ) { $ data [ 'class' ] = \ trim ( $ data [ 'class' ] . ' active' ) ; } if ( $ subitems ) { $ data [ 'class' ] = \ trim ( $ data [ 'class' ] . ' submenu' ) ; } if ( $ this -> news_showQuantity ) { if ( null === $ category ) { $ data [ 'quantity' ] = NewsCategoryModel :: getUsage ( $ this -> news_archives ) ; } else { $ data [ 'quantity' ] = NewsCategoryModel :: getUsage ( $ this -> news_archives , $ category -> id , ( bool ) $ this -> news_includeSubcategories ) ; } } if ( null !== $ category && null !== ( $ image = $ this -> manager -> getImage ( $ category ) ) ) { $ data [ 'image' ] = new \ stdClass ( ) ; Controller :: addImageToTemplate ( $ data [ 'image' ] , [ 'singleSRC' => $ image -> path , 'size' => $ this -> news_categoryImgSize , 'alt' => $ title , 'imageTitle' => $ title , ] ) ; } else { $ data [ 'image' ] = null ; } return $ data ; }
Generate the item .
48,859
protected function countNewsItems ( $ begin , $ end ) { if ( ( $ criteria = $ this -> getSearchCriteria ( $ begin , $ end ) ) === null ) { return 0 ; } return NewsModel :: countBy ( $ criteria -> getColumns ( ) , $ criteria -> getValues ( ) ) ; }
Count the news items
48,860
protected function fetchNewsItems ( $ begin , $ end , $ limit = null , $ offset = null ) { if ( ( $ criteria = $ this -> getSearchCriteria ( $ begin , $ end ) ) === null ) { return null ; } $ criteria -> setLimit ( $ limit ) ; $ criteria -> setOffset ( $ offset ) ; return NewsModel :: findBy ( $ criteria -> getColumns ( ) , $ criteria -> getValues ( ) , $ criteria -> getOptions ( ) ) ; }
Fetch the news items
48,861
protected function getSearchCriteria ( $ begin , $ end ) { try { $ criteria = System :: getContainer ( ) -> get ( 'codefog_news_categories.news_criteria_builder' ) -> getCriteriaForArchiveModule ( $ this -> news_archives , $ begin , $ end , $ this ) ; } catch ( CategoryNotFoundException $ e ) { throw new PageNotFoundException ( $ e -> getMessage ( ) ) ; } return $ criteria ; }
Get the search criteria
48,862
function getSignature ( array $ params , $ method = null ) { ksort ( $ params ) ; unset ( $ params [ 'sign' ] ) ; unset ( $ params [ 'signature' ] ) ; array_push ( $ params , $ this -> secretKey ) ; if ( $ method ) { array_unshift ( $ params , $ method ) ; } return hash ( 'sha256' , join ( '{up}' , $ params ) ) ; }
Create SHA - 256 digital signature
48,863
public function form ( $ publicKey , $ sum , $ account , $ desc , $ currency = 'RUB' , $ locale = 'ru' ) { $ vitalParams = array ( 'account' => $ account , 'currency' => $ currency , 'desc' => $ desc , 'sum' => $ sum ) ; $ this -> params = array_merge ( $ this -> params , $ vitalParams ) ; if ( $ this -> secretKey ) { $ this -> params [ 'signature' ] = $ this -> getSignature ( $ vitalParams ) ; } $ this -> params [ 'locale' ] = $ locale ; return self :: FORM_URL . $ publicKey . '?' . http_build_query ( $ this -> params ) ; }
Get URL for pay through the form
48,864
public function setCashItems ( $ items ) { $ this -> params [ 'cashItems' ] = base64_encode ( json_encode ( array_map ( function ( $ item ) { return array ( 'name' => $ item -> getName ( ) , 'count' => $ item -> getCount ( ) , 'price' => $ item -> getPrice ( ) ) ; } , $ items ) ) ) ; return $ this ; }
Set list of paid goods
48,865
public function checkHandlerRequest ( ) { $ ip = $ this -> getIp ( ) ; if ( ! isset ( $ _GET [ 'method' ] ) ) { throw new InvalidArgumentException ( 'Method is null' ) ; } if ( ! isset ( $ _GET [ 'params' ] ) ) { throw new InvalidArgumentException ( 'Params is null' ) ; } list ( $ method , $ params ) = array ( $ _GET [ 'method' ] , $ _GET [ 'params' ] ) ; if ( ! in_array ( $ method , $ this -> supportedPartnerMethods ) ) { throw new UnexpectedValueException ( 'Method is not supported' ) ; } if ( ! isset ( $ params [ 'signature' ] ) || $ params [ 'signature' ] != $ this -> getSignature ( $ params , $ method ) ) { throw new InvalidArgumentException ( 'Wrong signature' ) ; } if ( ! in_array ( $ ip , $ this -> supportedUnitpayIp ) ) { throw new InvalidArgumentException ( 'IP address Error' ) ; } return true ; }
Check request on handler from UnitPay
48,866
public function saveAccessTokenToDB ( $ accessToken ) { $ data = array ( 'access_token' => $ accessToken , 'created_at' => \ Carbon \ Carbon :: now ( ) , ) ; if ( \ Config :: get ( 'laravel-youtube::auth' ) == true ) { $ data [ 'user_id' ] = \ Auth :: user ( ) -> id ; } \ DB :: table ( \ Config :: get ( 'laravel-youtube::table_name' ) ) -> insert ( $ data ) ; }
Saves the access token to the database .
48,867
public function upload ( array $ data ) { $ accessToken = $ this -> client -> getAccessToken ( ) ; if ( is_null ( $ accessToken ) ) { throw new \ Exception ( 'You need an access token to upload' ) ; } if ( $ this -> client -> isAccessTokenExpired ( ) ) { $ accessToken = json_decode ( $ accessToken ) ; $ refreshToken = $ accessToken -> refresh_token ; $ this -> client -> refreshToken ( $ refreshToken ) ; $ newAccessToken = $ this -> client -> getAccessToken ( ) ; $ this -> saveAccessTokenToDB ( $ newAccessToken ) ; } $ snippet = new \ Google_Service_YouTube_VideoSnippet ( ) ; if ( array_key_exists ( 'title' , $ data ) ) { $ snippet -> setTitle ( $ data [ 'title' ] ) ; } if ( array_key_exists ( 'description' , $ data ) ) { $ snippet -> setDescription ( $ data [ 'description' ] ) ; } if ( array_key_exists ( 'tags' , $ data ) ) { $ snippet -> setTags ( $ data [ 'tags' ] ) ; } if ( array_key_exists ( 'category_id' , $ data ) ) { $ snippet -> setCategoryId ( $ data [ 'category_id' ] ) ; } $ status = new \ Google_Service_YouTube_VideoStatus ( ) ; if ( array_key_exists ( 'status' , $ data ) ) { $ status -> privacyStatus = $ data [ 'status' ] ; } $ video = new \ Google_Service_YouTube_Video ( ) ; $ video -> setSnippet ( $ snippet ) ; $ video -> setStatus ( $ status ) ; $ result = $ this -> youtube -> videos -> insert ( 'status,snippet' , $ video , array ( 'data' => file_get_contents ( $ data [ 'video' ] -> getRealPath ( ) ) , 'mimeType' => $ data [ 'video' ] -> getMimeType ( ) , 'uploadType' => 'multipart' ) ) ; if ( ! ( $ result instanceof \ Google_Service_YouTube_Video ) ) { throw new \ Exception ( 'Expecting instance of Google_Service_YouTube_Video, got:' . $ result ) ; } return $ result -> getId ( ) ; }
Uploads the passed video to the YouTube account identified by the access token in the DB and returns the uploaded video s YouTube Video ID . Attempts to automatically refresh the token if it s expired .
48,868
public function delete ( $ video_id ) { $ accessToken = $ this -> client -> getAccessToken ( ) ; if ( is_null ( $ accessToken ) ) { throw new \ Exception ( 'You need an access token to delete.' ) ; } if ( $ this -> client -> isAccessTokenExpired ( ) ) { $ accessToken = json_decode ( $ accessToken ) ; $ refreshToken = $ accessToken -> refresh_token ; $ this -> client -> refreshToken ( $ refreshToken ) ; $ newAccessToken = $ this -> client -> getAccessToken ( ) ; $ this -> saveAccessTokenToDB ( $ newAccessToken ) ; } $ result = $ this -> youtube -> videos -> delete ( $ video_id ) ; if ( ! $ result ) { throw new \ Exception ( "Couldn't delete the video from the youtube account." ) ; } return $ result -> getId ( ) ; }
Deletes a video from the account specified by the Access Token Attempts to automatically refresh the token if it s expired .
48,869
public function revisionLog ( $ action , $ table , $ id , array $ old = [ ] , array $ new = [ ] , $ user = null ) { $ user = $ this -> parseUser ( $ user ) ; $ connection = $ this -> getCurrentConnection ( ) ; $ format = $ connection -> getQueryGrammar ( ) -> getDateFormat ( ) ; $ connection -> table ( $ this -> table ) -> insert ( [ 'action' => substr ( $ action , 0 , 255 ) , 'table_name' => substr ( $ table , 0 , 255 ) , 'row_id' => substr ( $ id , 0 , 255 ) , 'old' => json_encode ( $ old ) , 'new' => json_encode ( $ new ) , 'user' => substr ( $ user , 0 , 255 ) , 'ip' => substr ( $ this -> getFromServer ( 'REMOTE_ADDR' ) , 0 , 255 ) ? : null , 'ip_forwarded' => substr ( $ this -> getFromServer ( 'HTTP_X_FORWARDED_FOR' ) , 0 , 255 ) ? : null , 'created_at' => ( new DateTime ( ) ) -> format ( $ format ) , ] ) ; $ this -> resetConnection ( ) ; }
Log data revisions in the db .
48,870
protected function getRevisionableItems ( array $ values ) { if ( count ( $ this -> getRevisionable ( ) ) > 0 ) { return array_intersect_key ( $ values , array_flip ( $ this -> getRevisionable ( ) ) ) ; } return array_diff_key ( $ values , array_flip ( $ this -> getNonRevisionable ( ) ) ) ; }
Get an array of revisionable attributes .
48,871
public function wrapRevision ( $ history ) { if ( $ history && $ presenter = $ this -> getRevisionPresenter ( ) ) { return $ presenter :: make ( $ history , $ this ) ; } return $ history ; }
Wrap revision model with the presenter if provided .
48,872
public function getFieldHistory ( string $ field ) : Collection { return $ this -> revisions -> map ( function ( $ revision ) use ( $ field ) : ? array { if ( $ revision -> old ( $ field ) == $ revision -> new ( $ field ) ) { return null ; } return [ 'created_at' => ( string ) $ revision -> created_at , 'user_id' => $ revision -> executor -> id ?? null , 'user_email' => $ revision -> executor -> email ?? null , 'old' => $ revision -> old ( $ field ) , 'new' => $ revision -> new ( $ field ) , ] ; } ) -> filter ( ) -> values ( ) ; }
Get all updates for a given field .
48,873
protected function bindSentinelProvider ( ) { $ this -> app -> singleton ( 'revisionable.userprovider' , function ( $ app ) { $ field = $ app [ 'config' ] -> get ( 'sofa_revisionable.userfield' ) ; return new Adapters \ Sentinel ( $ app [ 'sentinel' ] , $ field ) ; } ) ; }
Bind adapter for Sentinel to the IoC .
48,874
private function bindJwtAuthProvider ( ) { $ this -> app -> singleton ( 'revisionable.userprovider' , function ( $ app ) { $ field = $ app [ 'config' ] -> get ( 'sofa_revisionable.userfield' ) ; return new Adapters \ JwtAuth ( $ app [ 'tymon.jwt.auth' ] , $ field ) ; } ) ; }
Bind adapter for JWT Auth to the IoC .
48,875
protected function bindGuardProvider ( ) { $ this -> app -> singleton ( 'revisionable.userprovider' , function ( $ app ) { $ field = $ app [ 'config' ] -> get ( 'sofa_revisionable.userfield' ) ; return new Adapters \ Guard ( $ app [ 'auth' ] -> guard ( ) , $ field ) ; } ) ; }
Bind adapter for Illuminate Guard to the IoC .
48,876
protected function registerCommands ( ) { $ this -> app -> singleton ( 'revisions.migration' , function ( $ app ) { return new RevisionsTableCommand ( $ app [ 'files' ] , $ app [ 'composer' ] ) ; } ) ; $ this -> app -> singleton ( 'revisions.upgrade5_3' , function ( $ app ) { return new RevisionsUpgradeCommand ( $ app [ 'files' ] , $ app [ 'composer' ] ) ; } ) ; $ this -> commands ( [ 'revisions.migration' , 'revisions.upgrade5_3' , ] ) ; }
Register revisions migration generator command .
48,877
public function action ( ) { $ action = $ this -> revision -> action ; return array_get ( $ this -> actions , $ action , $ action ) ; }
Present action field .
48,878
public function getFromRevision ( $ version , $ key ) { return ( $ this -> isPassedThrough ( $ key ) ) ? $ this -> passThrough ( $ version , $ key ) : array_get ( $ this -> { $ version } , $ key ) ; }
Get value from the revision .
48,879
protected function passThrough ( $ version , $ key ) { $ revisioned = $ this -> getVersion ( $ version ) ; $ needle = $ this -> passThrough [ $ key ] ; return $ this -> dataGet ( $ revisioned , $ needle ) ; }
Get value from the relation .
48,880
protected function dataGet ( $ target , $ key ) { foreach ( explode ( '.' , $ key ) as $ segment ) { if ( is_object ( $ target ) && in_array ( Revisionable :: class , class_uses_recursive ( get_class ( $ target ) ) ) ) { $ target = $ this -> passThroughRevisionable ( $ target , $ segment ) ; } elseif ( $ target instanceof self || $ target instanceof Revision ) { $ target = $ this -> passThroughRevision ( $ target , $ segment ) ; } elseif ( $ target instanceof Model ) { $ target = $ this -> passThroughModel ( $ target , $ segment ) ; } else { $ target = null ; } if ( ! $ target ) { return ; } } return $ target ; }
Get pass through value using dot notation .
48,881
protected function passThroughRevision ( $ revision , $ key ) { $ action = $ revision -> getAttribute ( 'action' ) ; if ( in_array ( $ action , [ 'created' , 'updated' ] ) ) { return $ revision -> new ( $ key ) ; } }
Get pass through value from another revision .
48,882
protected function getVersion ( $ version ) { if ( ! $ this -> { $ version . 'Version' } ) { $ revisioned = get_class ( $ this -> revisioned ) ; $ revision = new $ revisioned ( ) ; $ revision -> setRawAttributes ( $ this -> { $ version } ) ; $ this -> { $ version . 'Version' } = $ revision ; } return $ this -> { $ version . 'Version' } ; }
Get revisioned model with appropriate attributes .
48,883
protected static function getMapCallback ( $ revisioned ) { $ presenter = get_called_class ( ) ; return function ( $ revision ) use ( $ presenter , $ revisioned ) { return new $ presenter ( $ revision , $ revisioned ) ; } ; }
Get callback for the array map .
48,884
public function getActionsAttribute ( ) { if ( ! $ this -> relationLoaded ( 'actions' ) ) { $ this -> load ( 'actions' ) ; } return $ this -> getRelation ( 'actions' ) -> load ( 'revisioned' ) -> map ( function ( $ revision ) { if ( $ revisioned = $ revision -> revisioned ) { return $ revisioned -> wrapRevision ( $ revision ) ; } return $ revision ; } ) ; }
Accessor for actions property .
48,885
public function scopeFor ( $ query , $ table ) { if ( $ table instanceof Model ) { $ table = $ table -> getTable ( ) ; } return $ query -> where ( 'table_name' , $ table ) ; }
Query scope for .
48,886
public function updateFormFields ( FieldList $ fields , $ controller , $ formName , $ context ) { $ image = isset ( $ context [ 'Record' ] ) ? $ context [ 'Record' ] : null ; if ( $ image && $ image -> appCategory ( ) === 'image' ) { $ fields -> insertAfter ( 'Title' , FocusPointField :: create ( 'FocusPoint' , $ image -> fieldLabel ( 'FocusPoint' ) , $ image ) -> setReadonly ( $ formName === 'fileSelectForm' ) ) ; } }
Add FocusPoint field for selecting focus .
48,887
public function calculateCrop ( $ width , $ height , $ originalWidth , $ originalHeight ) { $ cropData = [ 'CropAxis' => 0 , 'CropOffset' => 0 , ] ; $ cropData [ 'x' ] = [ 'FocusPoint' => $ this -> getX ( ) , 'OriginalLength' => $ originalWidth , 'TargetLength' => round ( $ width ) , ] ; $ cropData [ 'y' ] = [ 'FocusPoint' => $ this -> getY ( ) , 'OriginalLength' => $ originalHeight , 'TargetLength' => round ( $ height ) , ] ; if ( ! ( $ cropData [ 'x' ] [ 'OriginalLength' ] > 0 && $ cropData [ 'y' ] [ 'OriginalLength' ] > 0 ) ) { return false ; } $ cropAxis = false ; $ cropData [ 'x' ] [ 'ScaleRatio' ] = $ cropData [ 'x' ] [ 'OriginalLength' ] / $ cropData [ 'x' ] [ 'TargetLength' ] ; $ cropData [ 'y' ] [ 'ScaleRatio' ] = $ cropData [ 'y' ] [ 'OriginalLength' ] / $ cropData [ 'y' ] [ 'TargetLength' ] ; if ( $ cropData [ 'x' ] [ 'ScaleRatio' ] < $ cropData [ 'y' ] [ 'ScaleRatio' ] ) { $ cropAxis = 'y' ; $ scaleRatio = $ cropData [ 'x' ] [ 'ScaleRatio' ] ; } elseif ( $ cropData [ 'x' ] [ 'ScaleRatio' ] > $ cropData [ 'y' ] [ 'ScaleRatio' ] ) { $ cropAxis = 'x' ; $ scaleRatio = $ cropData [ 'y' ] [ 'ScaleRatio' ] ; } $ cropData [ 'CropAxis' ] = $ cropAxis ; if ( $ cropAxis ) { $ focusOffset = $ this -> focusCoordToOffset ( $ cropData [ $ cropAxis ] [ 'FocusPoint' ] ) ; $ scaledImageLength = floor ( $ cropData [ $ cropAxis ] [ 'OriginalLength' ] / $ scaleRatio ) ; $ focusPos = floor ( $ focusOffset * $ scaledImageLength ) ; $ frameCenter = floor ( $ cropData [ $ cropAxis ] [ 'TargetLength' ] / 2 ) ; $ focusShift = $ focusPos - $ frameCenter ; $ remainder = $ scaledImageLength - $ focusPos ; $ croppedRemainder = $ cropData [ $ cropAxis ] [ 'TargetLength' ] - $ frameCenter ; if ( $ remainder < $ croppedRemainder ) { $ focusShift -= $ croppedRemainder - $ remainder ; } if ( $ focusShift < 0 ) { $ focusShift = 0 ; } $ cropData [ 'CropOffset' ] = $ focusShift ; $ newFocusOffset = ( $ focusPos - $ focusShift ) / $ cropData [ $ cropAxis ] [ 'TargetLength' ] ; $ cropData [ $ cropAxis ] [ 'FocusPoint' ] = $ this -> focusOffsetToCoord ( $ newFocusOffset ) ; } return $ cropData ; }
Caluclate crop data given the desired width and height as well as original width and height . Calculates required crop coordinates using current FocusX and FocusY
48,888
public function FocusFill ( $ width , $ height , AssetContainer $ image , $ upscale = true ) { if ( ! $ image && $ this -> record instanceof Image ) { $ image = $ this -> record ; } $ width = intval ( $ width ) ; $ height = intval ( $ height ) ; $ imgW = $ image -> getWidth ( ) ; $ imgH = $ image -> getHeight ( ) ; if ( ! $ upscale ) { $ widthRatio = $ imgW / $ width ; $ heightRatio = $ imgH / $ height ; if ( $ widthRatio < 1 && $ widthRatio <= $ heightRatio ) { $ width = $ imgW ; $ height = intval ( round ( $ height * $ widthRatio ) ) ; } elseif ( $ heightRatio < 1 ) { $ height = $ imgH ; $ width = intval ( round ( $ width * $ heightRatio ) ) ; } } if ( $ image -> isSize ( $ width , $ height ) && ! Config :: inst ( ) -> get ( DBFile :: class , 'force_resample' ) ) { return $ image ; } elseif ( $ cropData = $ this -> calculateCrop ( $ width , $ height , $ imgW , $ imgH ) ) { $ variant = $ image -> variantName ( __FUNCTION__ , $ width , $ height , $ cropData [ 'CropAxis' ] , $ cropData [ 'CropOffset' ] ) ; $ cropped = $ image -> manipulateImage ( $ variant , function ( Image_Backend $ backend ) use ( $ width , $ height , $ cropData ) { $ img = null ; $ cropAxis = $ cropData [ 'CropAxis' ] ; $ cropOffset = $ cropData [ 'CropOffset' ] ; if ( $ cropAxis == 'x' ) { $ img = $ backend -> resizeByHeight ( $ height ) -> crop ( 0 , $ cropOffset , $ width , $ height ) ; } elseif ( $ cropAxis == 'y' ) { $ img = $ backend -> resizeByWidth ( $ width ) -> crop ( $ cropOffset , 0 , $ width , $ height ) ; } else { $ img = $ backend -> resize ( $ width , $ height ) ; } if ( ! $ img ) { return null ; } return $ img ; } ) ; $ cropped -> FocusPoint = DBField :: create_field ( static :: class , [ 'X' => $ cropData [ 'x' ] [ 'FocusPoint' ] , 'Y' => $ cropData [ 'y' ] [ 'FocusPoint' ] ] ) ; return $ cropped ; } return null ; }
Generate a cropped version of the given image
48,889
public static function check ( ) { $ collections = self :: getCollection ( ) ; $ jsonLastError = json_last_error ( ) ; return isset ( $ jsonLastError ) ? $ collections [ $ jsonLastError ] : $ collections [ 'default' ] ; }
Check for errors .
48,890
public static function getCollection ( ) { $ collections = [ JSON_ERROR_NONE => null , JSON_ERROR_DEPTH => [ 'message' => 'Maximum stack depth exceeded' , 'error-code' => 1 , ] , JSON_ERROR_STATE_MISMATCH => [ 'message' => 'Underflow or the modes mismatch' , 'error-code' => 2 , ] , JSON_ERROR_CTRL_CHAR => [ 'message' => 'Unexpected control char found' , 'error-code' => 3 , ] , JSON_ERROR_SYNTAX => [ 'message' => 'Syntax error, malformed JSON' , 'error-code' => 4 , ] , JSON_ERROR_UTF8 => [ 'message' => 'Malformed UTF-8 characters' , 'error-code' => 5 , ] , JSON_ERROR_RECURSION => [ 'message' => 'Recursion error in value to be encoded' , 'error-code' => 6 , ] , JSON_ERROR_INF_OR_NAN => [ 'message' => 'Error NAN/INF in value to be encoded' , 'error-code' => 7 , ] , JSON_ERROR_UNSUPPORTED_TYPE => [ 'message' => 'Type value given cannot be encoded' , 'error-code' => 8 , ] , 'default' => [ 'message' => 'Unknown error' , 'error-code' => 999 , ] , ] ; if ( version_compare ( PHP_VERSION , '7.0.0' , '>=' ) ) { $ collections [ JSON_ERROR_INVALID_PROPERTY_NAME ] = [ 'message' => 'Name value given cannot be encoded' , 'error-code' => 9 , ] ; $ collections [ JSON_ERROR_UTF16 ] = [ 'message' => 'Malformed UTF-16 characters' , 'error-code' => 10 , ] ; } return $ collections ; }
Get collection of JSON errors .
48,891
public static function arrayToFile ( $ array , $ file ) { self :: createDirectory ( $ file ) ; $ lastError = JsonLastError :: check ( ) ; $ json = json_encode ( $ lastError ? $ lastError : $ array , JSON_PRETTY_PRINT ) ; self :: saveFile ( $ file , $ json ) ; return is_null ( $ lastError ) ; }
Creating JSON file from array .
48,892
public static function fileToArray ( $ file ) { if ( ! is_file ( $ file ) && ! filter_var ( $ file , FILTER_VALIDATE_URL ) ) { self :: arrayToFile ( [ ] , $ file ) ; } $ json = @ file_get_contents ( $ file ) ; $ array = json_decode ( $ json , true ) ; $ lastError = JsonLastError :: check ( ) ; return $ array === null || ! is_null ( $ lastError ) ? false : $ array ; }
Save to array the JSON file content .
48,893
private static function createDirectory ( $ file ) { $ basename = is_string ( $ file ) ? basename ( $ file ) : '' ; $ path = str_replace ( $ basename , '' , $ file ) ; if ( ! empty ( $ path ) && ! is_dir ( $ path ) ) { if ( ! mkdir ( $ path , 0755 , true ) ) { $ message = 'Could not create directory in' ; throw new JsonException ( $ message . ' ' . $ path ) ; } } }
Create directory recursively if it doesn t exist .
48,894
public function getUser ( $ credentials , UserProviderInterface $ userProvider ) { if ( isset ( $ credentials [ $ this -> username_attribute ] ) ) { return $ userProvider -> loadUserByUsername ( $ credentials [ $ this -> username_attribute ] ) ; } else { return null ; } }
Calls the UserProvider providing a valid User
48,895
public function start ( Request $ request , AuthenticationException $ authException = null ) { return new RedirectResponse ( $ this -> server_login_url . '?' . $ this -> query_service_parameter . '=' . urlencode ( $ request -> getUri ( ) ) ) ; }
Called when authentication is needed redirect to your CAS server authentication form
48,896
protected function removeCasTicket ( $ uri ) { $ parsed_url = parse_url ( $ uri ) ; if ( empty ( $ parsed_url [ 'query' ] ) ) { return $ uri ; } parse_str ( $ parsed_url [ 'query' ] , $ query_params ) ; if ( ! isset ( $ query_params [ $ this -> query_ticket_parameter ] ) ) { return $ uri ; } unset ( $ query_params [ $ this -> query_ticket_parameter ] ) ; if ( empty ( $ query_params ) ) { unset ( $ parsed_url [ 'query' ] ) ; } else { $ parsed_url [ 'query' ] = http_build_query ( $ query_params ) ; } $ scheme = isset ( $ parsed_url [ 'scheme' ] ) ? $ parsed_url [ 'scheme' ] . '://' : '' ; $ host = isset ( $ parsed_url [ 'host' ] ) ? $ parsed_url [ 'host' ] : '' ; $ port = isset ( $ parsed_url [ 'port' ] ) ? ':' . $ parsed_url [ 'port' ] : '' ; $ user = isset ( $ parsed_url [ 'user' ] ) ? $ parsed_url [ 'user' ] : '' ; $ pass = isset ( $ parsed_url [ 'pass' ] ) ? ':' . $ parsed_url [ 'pass' ] : '' ; $ pass = ( $ user || $ pass ) ? "$pass@" : '' ; $ path = isset ( $ parsed_url [ 'path' ] ) ? $ parsed_url [ 'path' ] : '' ; $ query = isset ( $ parsed_url [ 'query' ] ) ? '?' . $ parsed_url [ 'query' ] : '' ; $ fragment = isset ( $ parsed_url [ 'fragment' ] ) ? '#' . $ parsed_url [ 'fragment' ] : '' ; return "$scheme$user$pass$host$port$path$query$fragment" ; }
Strip the CAS ticket parameter from a uri .
48,897
public function loadUserByUsername ( $ username ) { if ( $ username ) { $ password = '...' ; $ salt = "" ; $ roles = [ "ROLE_USER" ] ; return new CasUser ( $ username , $ password , $ salt , $ roles ) ; } throw new UsernameNotFoundException ( sprintf ( 'Username "%s" does not exist.' , $ username ) ) ; }
Provides the authenticated user a ROLE_USER
48,898
private function _saveDropdownOptions ( $ attribute , $ request ) { if ( null !== $ request -> get ( 'dropdown-options' ) ) { if ( null != $ attribute -> attributeDropdownOptions ( ) -> get ( ) && $ attribute -> attributeDropdownOptions ( ) -> get ( ) -> count ( ) >= 0 ) { $ attribute -> attributeDropdownOptions ( ) -> delete ( ) ; } foreach ( $ request -> get ( 'dropdown-options' ) as $ key => $ val ) { if ( $ key == '__RANDOM_STRING__' ) { continue ; } $ attribute -> attributeDropdownOptions ( ) -> create ( $ val ) ; } } }
Save Attribute Drop down Options .
48,899
protected function registerMiddleware ( ) { $ router = $ this -> app [ 'router' ] ; $ router -> aliasMiddleware ( 'currency' , SiteCurrencyMiddleware :: class ) ; $ router -> aliasMiddleware ( 'admin.api.auth' , AdminApiAuth :: class ) ; $ router -> aliasMiddleware ( 'admin.auth' , AdminAuth :: class ) ; $ router -> aliasMiddleware ( 'admin.guest' , RedirectIfAdminAuth :: class ) ; $ router -> aliasMiddleware ( 'permission' , Permission :: class ) ; }
Registering AvoRed E commerce Middleware .