/** * Creates new MMStaticPage and associated blocks from old eZ static page * * @param string $url Url of new static page * @param string $clusterIdentifier Cluster identifier of new static page * @param string $headline Headline of new static page (html) * @param string $content Core content of new static page (html) * @param arary $templates List of templates that will be converted into * "MMStaticPageBlock"s and associated with the new * static page. **/ public function import( $url, $clusterIdentifier, $headline, $content, $templates ) { $staticPage = new MMStaticPage(); $staticPage->setAttribute( 'url', $url ); $staticPage->setAttribute( 'cluster_identifier', $clusterIdentifier ); // We don't export full headline HTML anymore, a simple headline // is created either by trying to parse the HTML or from the URL $pattern = "/<h2 class=\"title\">(.*?)<\/h2>/"; preg_match($pattern, $headline, $matches); if(!is_null($matches[1])) { $staticPage->setAttribute( 'headline', $matches[1]); } else { $staticPage->setAttribute( 'headline', str_replace('-', ' ', ltrim( $url, '/' )) ); } $staticPage->setAttribute( 'core_content', $content ); $staticPage->setAttribute( 'environment', 1 ); $staticPage->setAttribute( 'target_platform', 'WEB' ); $staticPage->setAttribute( 'title', ltrim( $url, '/' ) ); $staticPage->setAttribute( 'internal_id', uniqid() ); $actionBar = array(); if( strstr( $content, 'btn-back' ) ) { $actionBar[] = 'BACK'; } if( strstr( $content, 'btn-print' ) ) { $actionBar[] = 'PRINT'; } if( count( $actionBar ) > 0 ) { $staticPage->setAttribute( 'action_bar', implode( ';', $actionBar ) ); } $staticPage->store(); foreach( $templates as $index => $template ) { $block = $this->fetchOrCreateBlock( $template, $staticPage->ID ); $blockRelation = new MMStaticPageBlockRelation(); $blockRelation->setAttribute( 'static_page_id', $staticPage->ID ); $blockRelation->setAttribute( 'static_block_id', $block->ID ); $blockRelation->setAttribute( 'position', $index + 1 ); $blockRelation->store(); } }