Webylon 3.1 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • auth
  • Booking
  • cart
    • shipping
    • steppedcheckout
  • Catalog
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • Address
  • AddSubsiteTask
  • Announcement
  • AnnouncementDecorator
  • AnnouncementHolder
  • AssociatedFolderDecorator
  • AttachedFiles
  • AudioPhpCaptcha
  • AutoCompleteField
  • BaseMediawebImportParser
  • BookingOrder_StatusLog
  • CalendarUtil
  • CalendarWidgetExtention
  • CatalogCatalogLinkedDecorator
  • CatalogImportTask
  • CatalogOldFieldsDecorator
  • CatalogProductLinkedDecorator
  • CheckoutStep_ShippingMethod
  • ChequePayment
  • ClearHistoryTask
  • ClientEmailOrderNotification_SiteConfig
  • ClientVKOrderNotification_SiteConfig
  • CommentsSiteConfig
  • ContactsPage
  • CookieExtention
  • CostTableShippingRate
  • CustomMenu
  • CustomMenuAdmin
  • CustomMenuDecorator
  • CustomMenuHolder
  • CustomMenuItem
  • CustomPayment
  • DataObjectLoggerExtension
  • DataObjectSubsites
  • DefaultCMSActionDecorator
  • DeleteOldAssociatedFoldersTask
  • DocPage
  • DocumentDirection
  • DocumentHaving
  • DocumentSearchForm
  • DocumentSiteConfig
  • DocumentsPage
  • DocumentType
  • DOMUtil
  • ExtendPageAnnouncement
  • ExtendPageNews
  • ExtendPagePoll
  • FileOversizeDecorator
  • FindCyrillicSiteConfig
  • FolderRenameTask
  • GDMergeAlpha
  • HomePage
  • ImageAutoResize
  • ImageResizeTask
  • ImportAdmin
  • ImportAutoStartTask
  • ImportCatalogMessage
  • ImportConfig
  • ImportLog
  • ImportSiteConfig
  • ImportTask
  • LoggerAdmin
  • LogItem
  • ManagerEmailOrderNotification_SiteConfig
  • MapObject
  • MapObjectGroup
  • MapPage
  • MediawebForm
  • MediawebImportParser
  • MemberLoggerExtension
  • MultiUploadConfig
  • NearestEventExtention
  • NewDocumentsAdmin
  • News_Controller
  • NewsEntry
  • NewsEntry_Controller
  • NewsHolder
  • NewsHolder_Controller
  • NewsLiveCalendarWidget
  • NewsSiteConfig
  • Order_StatusLog
  • Orders1CExchange
  • PageHideFieldsExtension
  • PageInformerRates
  • PageInformerWeather
  • Payment_Failure
  • Payment_Processing
  • Payment_Result
  • Payment_Success
  • PaymentMethod
  • PaymentSiteConfig
  • PayPalPayment
  • PayPalPayment_Handler
  • PhoneField
  • PhotoAlbumExtentions
  • PhpCaptcha
  • PhpCaptchaColour
  • PhpCaptchaField
  • phpMorphy
  • phpMorphy_AncodesResolver_AsIs
  • phpMorphy_AncodesResolver_Proxy
  • phpMorphy_AncodesResolver_ToDialingAncodes
  • phpMorphy_AncodesResolver_ToText
  • phpMorphy_AnnotDecoder_Base
  • phpMorphy_AnnotDecoder_Common
  • phpMorphy_AnnotDecoder_Factory
  • phpMorphy_AnnotDecoder_Predict
  • phpMorphy_FilesBundle
  • phpMorphy_Fsa
  • phpMorphy_Fsa_Decorator
  • phpMorphy_Fsa_Proxy
  • phpMorphy_Fsa_Sparse_File
  • phpMorphy_Fsa_Sparse_Mem
  • phpMorphy_Fsa_Sparse_Shm
  • phpMorphy_Fsa_Tree_File
  • phpMorphy_Fsa_Tree_Mem
  • phpMorphy_Fsa_Tree_Shm
  • phpMorphy_Fsa_WordsCollector
  • phpMorphy_GramInfo
  • phpMorphy_GramInfo_AncodeCache
  • phpMorphy_GramInfo_Decorator
  • phpMorphy_Graminfo_File
  • phpMorphy_Graminfo_Mem
  • phpMorphy_GramInfo_Proxy
  • phpMorphy_GramInfo_Proxy_WithHeader
  • phpMorphy_GramInfo_RuntimeCaching
  • phpMorphy_Graminfo_Shm
  • phpMorphy_GrammemsProvider_Base
  • phpMorphy_GrammemsProvider_Decorator
  • phpMorphy_GrammemsProvider_Empty
  • phpMorphy_GrammemsProvider_Factory
  • phpMorphy_GrammemsProvider_ForFactory
  • phpMorphy_GrammemsProvider_ru_RU
  • phpMorphy_GramTab
  • phpMorphy_GramTab_Empty
  • phpMorphy_GramTab_Proxy
  • phpMorphy_Link
  • phpMorphy_Link_Annot
  • phpMorphy_Link_Base
  • phpMorphy_Morphier_Base
  • phpMorphy_Morphier_Bulk
  • phpMorphy_Morphier_Common
  • phpMorphy_Morphier_Empty
  • phpMorphy_Morphier_Finder_Base
  • phpMorphy_Morphier_Finder_Common
  • phpMorphy_Morphier_Finder_Predict_Databse
  • phpMorphy_Morphier_Finder_Predict_Suffix
  • phpMorphy_Morphier_Helper
  • phpMorphy_Morphier_Predict_Database
  • phpMorphy_Morphier_Predict_Suffix
  • phpMorphy_Morphier_PredictCollector
  • phpMorphy_Semaphore
  • phpMorphy_Semaphore_Empty
  • phpMorphy_Semaphore_Nix
  • phpMorphy_Semaphore_Win
  • phpMorphy_Shm_Cache
  • phpMorphy_Shm_Cache_FileDescriptor
  • phpMorphy_Shm_Header
  • phpMorphy_Source_Dba
  • phpMorphy_Source_Fsa
  • phpMorphy_State
  • phpMorphy_Storage
  • phpMorphy_Storage_Factory
  • phpMorphy_Storage_File
  • phpMorphy_Storage_Mem
  • phpMorphy_Storage_Proxy
  • phpMorphy_Storage_Shm
  • phpMorphy_UnicodeHelper
  • phpMorphy_UnicodeHelper_Base
  • phpMorphy_UnicodeHelper_MultiByteFixed
  • phpMorphy_UnicodeHelper_singlebyte
  • phpMorphy_UnicodeHelper_ucs_2be
  • phpMorphy_UnicodeHelper_ucs_2le
  • phpMorphy_UnicodeHelper_ucs_4be
  • phpMorphy_UnicodeHelper_ucs_4le
  • phpMorphy_UnicodeHelper_utf_16_Base
  • phpMorphy_UnicodeHelper_utf_16be
  • phpMorphy_UnicodeHelper_utf_16le
  • phpMorphy_UnicodeHelper_utf_32_Base
  • phpMorphy_UnicodeHelper_utf_32be
  • phpMorphy_UnicodeHelper_utf_32le
  • phpMorphy_UnicodeHelper_utf_8
  • phpMorphy_WordDescriptor
  • phpMorphy_WordDescriptor_Collection
  • phpMorphy_WordDescriptor_Collection_Serializer
  • phpMorphy_WordForm
  • ProductImportV1Decorator
  • ProductOldFieldsDecorator
  • ProductProductLinkedDecorator
  • PublHolder
  • Publication
  • PublicationSiteTree
  • RatingDataObject
  • RatingExtension
  • RealtySiteConfigDecorator
  • RecentComments
  • RecentFiles
  • RecentPages
  • RelatedPageLink
  • RepairImportTask
  • RoomRate_PriceField
  • RussianUpLower
  • SberbankPayment
  • SberbankPayment_Handler
  • SetMainSiteHomePageTypeTask
  • ShippingEstimator
  • ShippingPackage
  • ShowUserFromExtension
  • SiteConfigDecorator
  • SiteConfigSubsites
  • SiteTreeSubsites
  • SMSCOrderNotification_SiteConfig
  • SMSOrderNotification_SiteConfig
  • SortCMSActionDecorator
  • SS_Report_FakeQuery
  • SSMorphy
  • SSNController
  • SteppedCheckout_PageMessages
  • SubpageListField
  • SubscribeFormAllPagesExtension
  • SubsiteDropdownField
  • SubsiteReportWrapper
  • TableShippingRate
  • UnitellerPayment
  • UnitellerPayment_Handler
  • UnmoderatedComments
  • VideoManager
  • VideoSiteConfig
  • WatermarkImage
  • WatermarkSiteConfig
  • WebylonImportAdmin
  • WebylonImportCatalog
  • WeightTableShippingRate
  • XMLValidate
  • YaMoneyPayment
  • YaMoneyPayment_Handler
  • YMLExporter
  • YMLSiteConfig

Interfaces

  • ImportInterface
  • PaymentObjectInterface
  • phpMorphy_AncodesResolver_Interface
  • phpMorphy_AnnotDecoder_Interface
  • phpMorphy_Fsa_Interface
  • phpMorphy_GramInfo_Interace
  • phpMorphy_GrammemsProvider_Interface
  • phpMorphy_GramTab_Interface
  • phpMorphy_Morphier_Finder_Interface
  • phpMorphy_Morphier_Interface
  • phpMorphy_Shm_Cache_Interface
  • phpMorphy_Source_Interface

Exceptions

  • phpMorphy_Exception

Functions

  • column_sort
  • column_sort_callback_basic
  • encodeFileForEmail
  • encodeMultipart
  • getMimeType
  • htmlEmail
  • loadMimeTypes
  • phpmorphy_overload_mb_funcs
  • plaintextEmail
  • processHeaders
  • QuotedPrintable_encode
  • supressOutput
  • validateError
  • validEmailAddr
  • wrapImagesInline
  • wrapImagesInline_rewriter
  1 <?php
  2 
  3 /**
  4  * Description of PetromapImport
  5  *
  6  * @author inxo
  7  */
  8 class BaseMediawebImportParser {
  9 
 10     static $dtd = 'http://import.mediaweb.ru/import.dtd';
 11     private $filename;
 12     private $ImageFolder;
 13     private $encoding;
 14     private $disableValidation = false;
 15     private $message = '';
 16     protected $categories = array();
 17     protected $offers = array();
 18     protected $currency = array();
 19 
 20     public function __construct($filename, $imagefolder = null, $encoding='UTF-8') {
 21         $this->encoding = $encoding;
 22         $this->filename = $filename;
 23         $this->ImageFolder = $imagefolder;
 24     }
 25 
 26     public function setDisableValidation() {
 27         $this->disableValidation = true;
 28     }
 29 
 30     public function parse() {
 31         $valid = $this->validate();
 32 
 33         if (!$valid) {
 34             $this->setDisableValidation();
 35             $valid = true;
 36         }
 37         //Debug::dump($valid);
 38         if (!$valid) return false;
 39         
 40         $xml = simplexml_load_file($this->filename);
 41         foreach ($xml as $element => $value) {
 42             switch ($element) {
 43                 case 'currencies':
 44                     $result = $this->parse_currency($value);
 45                     break;
 46 
 47                 case 'categories':
 48                     $result = $this->parse_categories($value);
 49                     break;
 50 
 51                 case 'offers':
 52                     $result = $this->parse_offers($value);
 53                     break;
 54 
 55                 default:
 56                     $this->setMessage('Invalid XML element: ' . $element);
 57                     $result = false;
 58                     break;
 59             }
 60             if (!$result) {
 61                 return false;
 62             }
 63         }
 64         if (!$this->saveImages()) {
 65             //Debug::dump('error image');
 66             return false;
 67         }
 68         return true;
 69     }
 70 
 71     public function saveImages() {
 72         if ($this->ImageFolder) {
 73             $i = 0;
 74             // этот код не работает !!!
 75             foreach ($this->offers as $offer) {
 76                 if (isset($offer->photo)) {
 77                     if (isset($offer->image)) {
 78                         $img = base64_decode($offer->image);
 79                         $filename = $this->ImageFolder . '/' . $offer->photo;
 80                     } else {
 81                         $img = file_get_contents($offer->photo);
 82                         $filename = $this->ImageFolder . '/' . time() . '.' . substr(strrchr($offer->photo, '.'), 1);
 83                     }
 84                     if (!isset($filename)) {
 85                         return false;
 86                     }
 87                     $f = fopen($filename, 'w+');
 88                     if (!fwrite($f, $img))
 89                         return false;
 90                     else {
 91                         $this->offers[$i]->photo = $filename;
 92                     }
 93                     fclose($f);
 94                 }
 95             }
 96         }
 97         return true;
 98     }
 99 
100     public function setImageFolder($folder) {
101         $this->ImageFolder = $folder;
102     }
103 
104     public function getImageFolder() {
105         return $this->ImageFolder;
106     }
107 
108     public function setMessage($val) {
109         $this->message = $val;
110     }
111 
112     public function getMessage() {
113         return $this->message;
114     }
115 
116     public function validate() {
117         if ($this->disableValidation) {
118             return true;
119         }
120         if (!file_exists($this->filename)) {
121             $this->setMessage('XML file not found');
122             return false;
123         }
124         $xml = file_get_contents($this->filename);
125 
126         $dom = new DOMDocument;
127         $dom->loadXML($xml, LIBXML_PARSEHUGE);
128 
129         if ($dom->validate())
130             return true;
131         $this->setMessage('DOM Validation failed');
132         return false;
133     }
134 
135     private function parse_currency($elements) {
136         foreach ($elements as $currency) {
137             if ($currency->getName() != 'currency') {
138                 $this->setMessage('Invalid currency element: ' . $currency->getName());
139                 return false;
140             }
141 
142             // set default rate for currency = 1
143             $rate = 1;
144             if ($currency->attributes()->rate)
145                 $rate = (float) $currency->attributes ()->rate;
146 
147             $this->currency[(string) $currency->attributes()->id] = array(
148                 'rate' => $rate
149             );
150         }
151         //var_dump($this->currency);
152         return true;
153     }
154 
155     private function parse_categories($elements) {
156         foreach ($elements as $category) {
157             if ($category->getName() != 'category') {
158                 $this->setMessage('Invalid category element: ' . $category->getName());
159                 return false;
160             }
161             $parentid = (isset($category->attributes()->parentId)) ? (string) $category->attributes()->parentId : NULL;
162             array_push($this->categories, array(
163                 'id' => (string) $category->attributes()->id,
164                 'parentid' => $parentid,
165                 'title' => $this->convert((string) $category)
166             ));
167         }
168         //var_dump($this->categories);
169         return true;
170     }
171 
172     private function parse_offers($elements) {
173         foreach ($elements as $offer) {
174             if ($offer->getName() != 'offer') {
175                 $this->setMessage('Invalid offer element: ' . $offer->getName());
176                 return false;
177             }
178 
179             $url = (isset($offer->url)) ? $this->convert((string) $offer->url) : NULL;
180             $description = (isset($offer->description)) ? $this->convert((string) $offer->description) : NULL;
181             $fulldesc = (isset($offer->fulldesc)) ? $this->convert((string) $offer->fulldesc) : NULL;
182             $picture = (isset($offer->picture)) ? $this->convert((string) $offer->picture) : NULL;
183             $image = (isset($offer->image)) ? $this->convert((string) $offer->image) : NULL;
184             $typePrefix = (isset($offer->typePrefix)) ? $this->convert((string) $offer->typePrefix) : NULL;
185             $xCategory = (isset($offer->xCategory)) ? $this->convert((string) $offer->xCategory) : NULL;
186             $vendor = (isset($offer->vendor)) ? $this->convert((string) $offer->vendor) : NULL;
187             $vendorCode = (isset($offer->vendorCode)) ? $this->convert((string) $offer->vendorCode) : NULL;
188             $model = (isset($offer->model)) ? $this->convert((string) $offer->model) : NULL;
189 
190             $categories = NULL;
191             if ($offer->categoryId) {
192                 $categories = array();
193                 foreach ($offer->categoryId as $categoryId) {
194                     array_push($categories, array(
195                         'id' => (string) $this->convert($categoryId),
196                         'type' => (isset($categoryId->attributes()->type)) ? (string) $categoryId->attributes()->type : 'Own'
197                     ));
198                 }
199             }
200 
201             $special = NULL;
202             if ($offer->special) {
203                 $special = array();
204                 foreach ($offer->special as $obj) {
205                     array_push($special, array(
206                         'id' => (string) $obj->attributes()->id,
207                         'url' => (string) $obj->attributes()->url,
208                         'siteid' => (string) $obj->attributes()->siteid,
209                     ));
210                 }
211             }
212 
213             $params = array();
214             if ($offer->param) {
215                 foreach ($offer->param as $param) {
216                     array_push($params, array(
217                         'name' => (string) $param->attributes()->name,
218                         'value' => (string) $param
219                     ));
220                 }
221             }
222             
223             array_push($this->offers, array(
224                 // обязательные параметры
225                 'id' => (string) $offer->attributes()->id,
226                 'available' => ($offer->attributes()->available == 'true') ? 1 : 0,
227                 'title' => $this->convert((string) $offer->title),
228                 'price' => (float) str_replace(',', '.', $this->convert((string) $offer->price)),
229                 'currencyId' => $this->convert((string) $offer->currencyId),
230                 // возможные параметры
231                 'description' => $description,
232                 'url' => $url,
233                 'picture' => $picture,
234                 'image' => $image,
235                 'fulldesc' => $fulldesc,
236                 'typePrefix' => $typePrefix,
237                 'xCategory' => $xCategory,
238                 'vendor' => $vendor,
239                 'vendorCode' => $vendorCode,
240                 'model' => $model,
241                 // множественные параметры
242                 'categories' => $categories,
243                 'special' => $special,
244                 'params' => $params
245             ));
246         }
247         //var_dump($this->offers);
248         return true;
249     }
250 
251     private function convert($string) {
252         $string = htmlspecialchars_decode($string);
253         return $string;
254     }
255     
256 }
257 
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -
Webylon 3.1 API Docs API documentation generated by ApiGen 2.8.0