/** * Executes this filter. * * @param sfFilterChain $filterChain A sfFilterChain instance */ public function execute($filterChain) { if ($this->request->getParameter('dm_embed')) { sfConfig::set('dm_admin_embedded', true); sfConfig::set('dm_toolBar_enabled', false); } $this->saveApplicationUrl(); $this->loadAssetConfig(); if (sfConfig::get('dm_admin_embedded')) { $this->response->addStylesheet('admin.embed', 'last'); $this->getContext()->getEventDispatcher()->connect('admin.save_object', array($this, 'listenToAdminSaveObjectWhenEmbedded')); } $this->updateLock(); $filterChain->execute(); if (sfConfig::get('dm_admin_embedded')) { $this->response->addStylesheet('admin.embed'); } else { // If response has no title, generate one with the H1 if ($this->response->isHtmlForHuman() && !$this->response->getTitle()) { preg_match('|<h1[^>]*>(.*)</h1>|iuUx', $this->response->getContent(), $matches); if (isset($matches[1])) { $title = 'Admin : ' . strip_tags($matches[1]) . ' - ' . dmConfig::get('site_name'); $this->response->setContent(str_replace('<title></title>', '<title>' . $title . '</title>', $this->response->getContent())); } } } }
protected function useSearchIndex($slug) { if (!dmConfig::get('smart_404')) { return false; } try { $searchIndex = $this->serviceContainer->get('search_engine')->getCurrentIndex(); $queryString = str_replace('/', ' ', dmString::unSlugify($slug)); $query = Zend_Search_Lucene_Search_QueryParser::parse($queryString); $results = $searchIndex->search($query); $foundPage = null; foreach ($results as $result) { if ($result->getScore() > 0.5) { if ($foundPage = $result->getPage()) { break; } } else { break; } } if ($foundPage) { return $this->serviceContainer->getService('helper')->link($foundPage)->getHref(); } } catch (Exception $e) { $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Can not use search index to find redirection for slug ' . $slug, sfLogger::ERR))); if (sfConfig::get('dm_debug')) { throw $e; } } }
public function renderGoogleAnalytics() { if (($gaKey = dmConfig::get('ga_key')) && !$this->getService('user')->can('admin') && !dmOs::isLocalhost()) { return $this->getGoogleAnalyticsCode($gaKey); } return ''; }
public function executeFormWidget(dmWebRequest $request) { $form = new OrderForm(); if ($request->hasParameter($form->getName()) && $form->bindAndValid($request)) { $order = $form->save(); $order->setUid(md5(rand(1111, 9999) . time())); $order->save(); // link order details $this->shopping_cart = $shopping_cart = $this->getUser()->getShoppingCart(); $this->items = $shopping_cart->getItems(); foreach ($shopping_cart->getItems() as $i => $item) { $od = new OrderDetail(); $od->fromArray(array('product_id' => $item->getId(), 'order_id' => $order->id, 'quantity' => $item->getQuantity(), 'price' => $item->getPrice())); $od->save(); } if (sfConfig::get('app_send_order', false)) { dm::enableMailer(); //send mail $message = $this->getMailer()->compose($_from = dmConfig::get('orderEmail'), $_to = array($order->email, dmConfig::get('orderEmail')), $_subj = '[' . dmConfig::get('siteName') . '] thanks for order'); $message->setBody($this->getPartial('order/mailOrder', array('order' => $order, 'companyName' => dmConfig::get('companyName'), 'companyPhone' => dmConfig::get('companyPhone'), 'siteUrl' => dmConfig::get('siteUrl'), 'siteName' => dmConfig::get('siteName')))); $message->setContentType('text/html'); $this->getMailer()->send($message); } // if send order // clear cart now $shopping_cart->clear(); //redirect to order info $this->redirect($this->getHelper()->link('main/ordershow?uid=' . $order->uid)->getHref()); //$this->redirectBack(); } $this->forms['Order'] = $form; }
protected function secure() { $user = $this->getUser(); $accessDenied = // the site is not active and requires the site_view permission to be displayed (!dmConfig::get('site_active') && !$user->can('site_view')) // the page is not active and requires the site_view permission to be displayed || (!$this->page->get('is_active') && !$user->can('site_view')) // the page is secured and requires authentication to be displayed || ($this->page->get('is_secure') && !$user->isAuthenticated()) // the page is secured and the user has not required credentials || ($this->page->get('is_secure') && $this->page->get('credentials') && !$user->can($this->page->get('credentials'))) ; $accessDenied = $this->getDispatcher()->filter( new sfEvent($this, 'dm.page.deny_access', array('page' => $this->page, 'context' => $this->context)), $accessDenied )->getReturnValue(); if($accessDenied) { if(!$this->page->get('is_active')) { $this->forward404(); } // use main/signin page $this->getRequest()->setParameter('dm_page', dmDb::table('DmPage')->fetchSignin()); $this->getResponse()->setStatusCode($user->isAuthenticated() ? 403 : 401); $this->forward('dmFront', 'page'); } }
public function configure() { $this->widgetSchema['media_id'] = new sfWidgetFormDoctrineChoice(array('model' => 'DmMedia', 'multiple' => true)); $this->validatorSchema['media_id'] = new sfValidatorDoctrineChoice(array('model' => 'DmMedia', 'multiple' => true)); $this->validatorSchema['media_link'] = new sfValidatorPass(); $this->validatorSchema['media_alt'] = new sfValidatorPass(); $this->validatorSchema['media_position'] = new sfValidatorPass(); $this->widgetSchema['width'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['width'] = new dmValidatorCssSize(array('required' => false)); $this->widgetSchema['height'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['height'] = new dmValidatorCssSize(array('required' => false)); $this->widgetSchema['cols'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['cols'] = new sfValidatorNumber(array('required' => false, 'min' => 1, 'max' => 20)); if (!$this->hasDefault('cols')) { $this->setDefault('cols', 3); } $this->widgetSchema['rows'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['rows'] = new sfValidatorNumber(array('required' => false, 'min' => 1, 'max' => 20)); if (!$this->hasDefault('rows')) { $this->setDefault('rows', 3); } $this->widgetSchema['margin'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['margin'] = new dmValidatorCssSize(array('required' => false)); $this->widgetSchema['big_width'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['big_width'] = new dmValidatorCssSize(array('required' => false)); $this->widgetSchema['big_height'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['big_height'] = new dmValidatorCssSize(array('required' => false)); $methods = $this->getService('i18n')->translateArray(self::$methods); $this->widgetSchema['method'] = new sfWidgetFormSelect(array('choices' => $methods)); $this->validatorSchema['method'] = new sfValidatorChoice(array('choices' => array_keys($methods))); if (!$this->getDefault('method')) { $this->setDefault('method', dmConfig::get('image_resize_method', 'center')); } $transitions = $this->getService('i18n')->translateArray(self::$transitions); $this->widgetSchema['transition'] = new sfWidgetFormSelect(array('choices' => $transitions)); $this->validatorSchema['transition'] = new sfValidatorChoice(array('choices' => array_keys($transitions))); if (!$this->getDefault('transition')) { $this->setDefault('transition', dmArray::first(array_keys($transitions))); } $this->widgetSchema['speed'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['speed'] = new sfValidatorNumber(array('required' => false, 'min' => 0, 'max' => 2000)); $this->widgetSchema['opacity'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['opacity'] = new sfValidatorNumber(array('required' => false, 'min' => 0, 'max' => 1)); $this->widgetSchema['config'] = new sfWidgetFormTextarea(array(), array('cols' => 15, 'rows' => 3)); $this->validatorSchema['config'] = new sfValidatorString(array('required' => false)); $this->widgetSchema['quality'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['quality'] = new sfValidatorInteger(array('required' => false, 'min' => 0, 'max' => 100)); if (!$this->getDefault('medias')) { $this->setDefault('medias', array()); } // $this->widgetSchema['background'] = new sfWidgetFormInputText(array(), array('size' =>7)); // $this->validatorSchema['background'] = new sfValidatorString(array( // 'required' => false // )); $this->validatorSchema['widget_width'] = new sfValidatorInteger(array('required' => false)); parent::configure(); }
protected function configureFromData($data) { if (!$this->getOption('file_name')) { $this->setOption('file_name', dmString::slugify(dmConfig::get('site_name')) . '-' . dmString::random(8)); } if (!$this->getOption('file_size')) { $this->setOption('file_size', strlen($data)); } }
/** * Gets credentials the user must have to access this action. * * @return mixed An array or a string describing the credentials the user must have to access this action */ public function getCredential() { $credentials = parent::getCredential(); if (!dmConfig::get('site_active')) { $credentials = (array) $credentials; $credentials[] = 'site_view'; } return $credentials; }
protected function initialize(array $options) { try { $this->gapi = $this->serviceContainer->getService('gapi')->authenticate(null, null, dmConfig::get('ga_token')); } catch (dmGapiException $e) { $this->available = false; if (sfConfig::get('dm_debug')) { throw $e; } } parent::initialize($options); }
protected function secure() { $user = $this->getUser(); $accessDenied = !dmConfig::get('site_active') && !$user->can('site_view') || !$this->page->get('is_active') && !$user->can('site_view') || $this->page->get('is_secure') && !$user->isAuthenticated() || $this->page->get('is_secure') && $this->page->get('credentials') && !$user->can($this->page->get('credentials')); $accessDenied = $this->getDispatcher()->filter(new sfEvent($this, 'dm.page.deny_access', array('page' => $this->page, 'context' => $this->context)), $accessDenied)->getReturnValue(); if ($accessDenied) { // use main/signin page $this->getRequest()->setParameter('dm_page', dmDb::table('DmPage')->fetchSignin()); $this->getResponse()->setStatusCode($user->isAuthenticated() ? 403 : 401); $this->forward('dmFront', 'page'); } }
protected function saveApplicationUrl() { if (dmConfig::isCli()) { return; } $knownBaseUrls = json_decode(dmConfig::get('base_urls', '[]'), true); $appUrlKey = implode('-', array(sfConfig::get('sf_app'), sfConfig::get('sf_environment'))); $appUrl = $this->request->getUriPrefix() . $this->request->getScriptName(); if (!isset($knownBaseUrls[$appUrlKey]) || $knownBaseUrls[$appUrlKey] !== $appUrl) { $knownBaseUrls[$appUrlKey] = $appUrl; dmConfig::set('base_urls', json_encode($knownBaseUrls)); } }
public function configure() { $this->widgetSchema['key'] = new sfWidgetFormInputText(); $this->validatorSchema['key'] = new sfValidatorString(array('required' => false)); $this->widgetSchema->setHelp('key', dmDb::table('DmSetting')->findOneByName('ga_key')->description); $this->setDefault('key', dmConfig::get('ga_key')); $this->widgetSchema['email'] = new sfWidgetFormInputText(); $this->validatorSchema['email'] = new sfValidatorEmail(array('required' => false)); $this->widgetSchema->setHelp('email', 'Required to display google analytics data into Diem'); $this->widgetSchema['password'] = new sfWidgetFormInputPassword(); $this->validatorSchema['password'] = new sfValidatorString(array('required' => false)); $this->widgetSchema->setHelp('password', 'Required to display google analytics data into Diem'); $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'tokenize')))); }
public function getReportId() { if ($this->reportId) { return $this->reportId; } if (!($gaKey = dmConfig::get('ga_key'))) { throw new dmGapiException('You must configure a ga_key in the configuration panel'); } foreach ($this->requestAccountData() as $account) { if ($account->getWebPropertyId() === $gaKey) { return $this->reportId = $account->getProfileId(); } } throw new dmGapiException('Current report not found for ga key : ' . $gaKey); }
public function executeGetProcessedImageURL(dmWebRequest $request) { if (!$this->isAuthorized('media')) { return $this->forwardSecure(); } if (!($mediaId = $request->getParameter('media_id'))) { return $this->forward404(); } $media = dmDb::table('DmMedia')->findOneBy('id', $mediaId); $src = '/' . $media->getWebPath(); $width = $request->getParameter('width') ? intval($request->getParameter('width')) : null; $height = $request->getParameter('height') ? intval($request->getParameter('height')) : null; if ($width || $height) { $src = $this->getHelper()->media($media)->size($width, $height)->method($request->getParameter('method') ? $request->getParameter('method') : dmConfig::get('image_resize_method'))->getSrc(); } return $this->renderJson(array('src' => $src)); }
public function get($app = null, $env = null, $culture = null) { $app = null === $app ? sfConfig::get('sf_app') : $app; $env = null === $env ? sfConfig::get('sf_environment') : $env; $culture = null === $culture ? $this->culture : $culture; if ($config = dmConfig::get('base_urls')) { $knownAppUrls = json_decode($config, true); } else { $knownAppUrls = array(); } $appUrlKey = implode('-', array($app, $env, $culture)); if (!($appUrl = dmArray::get($knownAppUrls, $appUrlKey))) { if (!($script = $this->guessBootScriptFromWebDir($app, $env))) { throw new dmException(sprintf('Diem can not guess %s app url', $app)); } $appUrl = $this->requestContext['absolute_url_root'] . '/' . $script; } return $appUrl; }
protected function loadMailTemplates() { $array = array('dm_user_forgot_password' => array('description' => 'Sent to a user that requests a new password', 'vars' => 'username, email, step2_url', 'from_email' => '*****@*****.**', 'to_email' => '%email%', 'subject' => dmConfig::get('site_name') . ': change your password', 'body' => 'Hello %username%' . "\n" . 'You can choose a new password at %step2_url%')); $table = dmDb::table('DmMailTemplate'); foreach ($array as $name => $data) { if (!($mailTemplate = $table->findOneByNameWithI18n($name))) { $table->create(array_merge($data, array('name' => $name)))->save(); } elseif (!$mailTemplate->hasCurrentTranslation()) { /* * Try to find an existing config from another culture */ $existing = dmDb::query('DmMailTemplate t')->where('t.id = ?', $mailTemplate->id)->limit(1)->fetchArray(); if ($existing = dmArray::first($existing)) { $data = $existing; unset($data['id'], $data['lang']); } $mailTemplate->fromArray($data)->getCurrentTranslation()->save(); } } }
public function configure() { $this->widgetSchema['media_id'] = new sfWidgetFormDoctrineChoice(array('model' => 'DmMedia', 'multiple' => true)); $this->validatorSchema['media_id'] = new sfValidatorDoctrineChoice(array('model' => 'DmMedia', 'multiple' => true)); $this->validatorSchema['media_link'] = new sfValidatorPass(); $this->validatorSchema['media_alt'] = new sfValidatorPass(); $this->validatorSchema['media_position'] = new sfValidatorPass(); $this->widgetSchema['width'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['width'] = new dmValidatorCssSize(array('required' => false)); $this->widgetSchema['height'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['height'] = new dmValidatorCssSize(array('required' => false)); $methods = $this->getService('i18n')->translateArray(self::$methods); $this->widgetSchema['method'] = new sfWidgetFormSelect(array('choices' => $methods)); $this->validatorSchema['method'] = new sfValidatorChoice(array('choices' => array_keys($methods))); if (!$this->getDefault('method')) { $this->setDefault('method', dmConfig::get('image_resize_method', 'center')); } $this->widgetSchema['show_pager'] = new sfWidgetFormInputCheckbox(); $this->validatorSchema['show_pager'] = new sfValidatorBoolean(); $animations = $this->getService('i18n')->translateArray(self::$animations); $this->widgetSchema['animation'] = new sfWidgetFormSelect(array('choices' => $animations)); $this->validatorSchema['animation'] = new sfValidatorChoice(array('choices' => array_keys($animations))); if (!$this->getDefault('animation')) { $this->setDefault('animation', dmArray::first(array_keys($animations))); } $this->widgetSchema['delay'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['delay'] = new sfValidatorNumber(array('required' => false, 'min' => 0, 'max' => 1000)); if (!$this->hasDefault('delay')) { $this->setDefault('delay', 3); } $this->widgetSchema['quality'] = new sfWidgetFormInputText(array(), array('size' => 5)); $this->validatorSchema['quality'] = new sfValidatorInteger(array('required' => false, 'min' => 0, 'max' => 100)); if (!$this->getDefault('medias')) { $this->setDefault('medias', array()); } $this->widgetSchema['background'] = new sfWidgetFormInputText(array(), array('size' => 7)); $this->validatorSchema['background'] = new sfValidatorString(array('required' => false)); $this->validatorSchema['widget_width'] = new sfValidatorInteger(array('required' => false)); parent::configure(); }
public function executeIndex(dmWebRequest $request) { if ($this->getUser()->can('google_analytics')) { $this->form = new dmGoogleAnalyticsForm(); $this->form->setGapi($this->getService('gapi')); if ($request->isMethod('post')) { dmConfig::set('ga_key', dmArray::get($request->getParameter($this->form->getName()), 'key')); if ($this->form->bindAndValid($request)) { $this->form->save(); return $this->redirect('@dm_google_analytics'); } } } $this->gapiConnected = false; if (dmConfig::get('ga_token')) { try { $this->getService('gapi')->authenticate(null, null, dmConfig::get('ga_token')); $this->gapiConnected = true; } catch (dmGapiException $e) { // bad token } } }
protected function updateFilePath($file, Swift_Message $message, $templateName) { $id = str_replace('dmFile-', '', $file->id); if (!$id) { $id = $file->getAttribute('data-dm-file-id'); } if (is_numeric($id)) { $mediaRecord = dmDb::table('dmMedia')->findOneByIdWithFolder($id); if ($mediaRecord) { $embed = false; $embedExtensions = array_map('trim', explode(',', dmConfig::get('mail_template_embed_file_types', 'doc,docx,xls,xlsx,ppt,pptx,pdf,mdb'))); foreach ($embedExtensions as $ext) { if (dmString::endsWith($file->href, '.' . $ext, false)) { $embed = true; break; } } if (dmConfig::get('mail_template_embed_local_files_as_attachments', true) && $embed) { try { $file->href = $message->embed(Swift_EmbeddedFile::fromPath(dmOs::join(sfConfig::get('sf_web_dir'), $mediaRecord->getWebPath()))); } catch (Exception $e) { $this->logError($templateName, 'local', 'file', $file->href); $file->href = ''; } } else { if (file_exists(dmOs::join(sfConfig::get('sf_web_dir'), $link = $mediaRecord->getWebPath()))) { $file->href = $this->basePath . '/' . $mediaRecord->getWebPath(); } else { $this->logError($templateName, 'local', 'file', $file->href); $file->href = ''; } } return $file; } } if (dmString::startsWith($file->href, sfConfig::get('sf_root_dir')) || dmString::startsWith($file->href, $this->basePath)) { return $this->updateLocalFilePath($file, $message, $templateName); } else { return $this->updateRemoteFilePath($file, $message, $templateName); } }
<?php echo _open('div.dm.dm_auth.unsupported_browser'); echo _tag('h1.site_name', dmConfig::get('site_name')); echo _tag('div.message', _tag('p.dm_browser_unsupported.mt10', __("Sorry, it looks like you're using a browser that isn't supported.")) . _tag('p.dm_browser_suggestion.mt10', __("We suggest that you use one of these browsers:")) . _tag('div.dm_suggested_browsers.clearfix', _link('http://www.mozilla.com/firefox/')->text(_media('dmCore/images/64/firefox.png')->size(64, 64) . 'Firefox') . _link('http://www.google.com/chrome')->text(_media('dmCore/images/64/chrome.png')->size(64, 64) . 'Chrome') . _link('http://www.apple.com/safari/')->text(_media('dmCore/images/64/safari.png')->size(64, 64) . 'Safari') . _link('http://www.opera.com/browser/')->text(_media('dmCore/images/64/opera.png')->size(64, 64) . 'Opera')) . _tag('div.dm_skip_browser_detection', _link('@signin?skip_browser_detection=1')->text(__('Or continue at your own peril')))); echo _close('div'); echo _link('http://diem-project.org/')->text('Diem CMF CMS for symfony')->set('.generator_link');
$defaultCulture = sfConfig::get('sf_default_culture'); $user->setCulture($defaultCulture); dmDb::query('DmSetting s')->where('s.name = ?', 'test')->delete()->execute(); $t->diag('create new setting'); $setting = dmDb::create('DmSetting', array('name' => 'test', 'description' => 'This is just a test setting', 'value' => $defaultCulture . ' value', 'default_value' => $defaultCulture . ' default', 'type' => 'text', 'group_name' => 'test group'))->saveGet(); dmConfig::load(); try { dmConfig::get('i_do_not_exist_for_sure'); $t->pass('Get non-existant config'); } catch (dmException $e) { $t->fail('Get non-existant config'); } try { dmConfig::set('i_do_not_exist_for_sure', 'value'); $t->pass('Set non-existant config'); } catch (dmException $e) { $t->fail('Set non-existant config'); } $t->is(dmConfig::get('test'), $defaultCulture . ' value', 'test value is ' . $defaultCulture . ' value'); dmConfig::set('test', 'new ' . $defaultCulture . ' value'); $t->is(dmConfig::get('test'), 'new ' . $defaultCulture . ' value', 'test value is new ' . $defaultCulture . ' value'); dmConfig::load(); $t->is(dmConfig::get('test'), 'new ' . $defaultCulture . ' value', 'test value is new ' . $defaultCulture . ' value'); $user->setCulture('c1'); $t->is(dmConfig::get('test'), 'new ' . $defaultCulture . ' value', 'test value is new ' . $defaultCulture . ' value ( by non-existing c1 culture fallback )'); dmConfig::set('test', 'c1 value'); $t->is(dmConfig::get('test'), 'c1 value', 'test value is c1 value'); $user->setCulture($defaultCulture); $t->is(dmConfig::get('test'), 'new ' . $defaultCulture . ' value', 'test value is new ' . $defaultCulture . ' value'); $user->setCulture($userCulture); $setting->delete();
/** * @param string $content A HTML content to parse * @param bool $removeAttributes Flag should custom data attributes be removed with parsing, default false * @param bool $removeMissingElements Flag should missing elements be removed, default false * @return string Parsed HTML string with updated links */ public function parse($content, $removeAttributes = false, $removeMissingElements = false) { $html = str_get_html($content); foreach ($html->find('img') as $image) { if ($id = intval($image->getAttribute('data-dme-media-id'))) { $media = dmDb::table('dmMedia')->findOneByIdWithFolder($id); if ($media) { $src = '/' . $media->getWebPath(); $width = $image->width ? $image->width : null; $height = $image->height ? $image->height : null; if ($width || $height) { $src = $this->getHelper()->media($media)->size($width, $height)->method($image->getAttribute('data-dme-media-resize-method') ? $image->getAttribute('data-dme-media-resize-method') : dmConfig::get('image_resize_method'))->getSrc(); } $image->src = $src; if ($removeAttributes) { $image->removeAttribute('data-dme-media-id'); $image->removeAttribute('data-dme-media-resize-method'); } } else { $this->log($id, $image->src, 'image'); if ($removeMissingElements) { $image->outertext = ''; } } } } foreach ($html->find('a') as $link) { if ($id = intval($link->getAttribute('data-dme-media-id'))) { $media = dmDb::table('dmMedia')->findOneByIdWithFolder($id); if ($media) { $link->href = '/' . $media->getWebPath(); if ($removeAttributes) { $image->removeAttribute('data-dme-media-id'); } } else { $this->log($id, $link->href, 'media link'); if ($removeMissingElements) { $link->innertext = ''; $link->outertext = ''; } } } elseif ($id = intval($link->getAttribute('data-dme-page-id'))) { $page = dmDb::table('DmPage')->createQuery('P')->withI18n()->where('P.id = ?', $id)->fetchOne(); if ($page) { $link->href = '/' . $page->getSlug(); if ($removeAttributes) { $image->removeAttribute('data-dme-page-id'); } } else { $this->log($id, $link->href, 'page link'); if ($removeMissingElements) { $link->innertext = ''; $link->outertext = ''; } } } } $content = $html->save(); $html->clear(); unset($html); return $content; }
/** * @return array of words we do not want to index ( like "the", "a", to"... ) */ public function getStopWords() { return str_word_count(dmString::strtolower(dmConfig::get('search_stop_words')), 1); }
public function getFirstDefaults() { return array_merge(parent::getFirstDefaults(), array('method' => dmConfig::get('image_resize_method', 'center'), 'background' => 'FFFFFF')); }
public function __construct(array $options) { $options = array_merge($this->getDefaultOptions(), $options); parent::__construct($options['default_headers'], $options['adapter_class'], $options['adapter_options']); $this->setUserAgent(sprintf('%s (%s) Diem/%s (%s)', dmConfig::get('site_name'), dmArray::get($_SERVER, 'HTTP_HOST', '?'), DIEM_VERSION, 'http://diem-project.org')); }
protected function doExport(array $options) { /* * get data in an array */ $exportClass = $options['exportClass']; $export = new $exportClass($options['module']->getTable()); $data = $export->generate($options['format']); /* * transform into downloadable data */ switch ($options['extension']) { default: $csv = new dmCsvWriter(',', '"'); $csv->setCharset($options['encoding']); $data = $csv->convert($data); $mime = 'text/csv'; } $this->download($data, array('file_name' => sprintf('%s-%s_%s.%s', dmConfig::get('site_name'), dm::getI18n()->__($options['module']->getName()), date('Y-m-d'), $options['extension']), 'mime_type' => sprintf('%s; charset=%s', $mime, $options['encoding']))); }
$t->like($html, '_^<form\\s(.|\\n)*</form>$_', 'Successfully obtained and rendered a ' . $formClass . ' instance'); $t->is($form->getStylesheets(), array(), 'This widget form requires no additional stylesheet'); $t->is($form->getJavascripts(), array(), 'This widget form requires no additional javascript'); $t->comment('Submit an empty form'); $form->bind(array(), array()); $t->is($form->isValid(), false, 'The form is not valid'); $t->comment('Use a bad media id'); $form->bind(array('mediaId' => 9999999999999), array()); $t->is($form->isValid(), false, 'The form is not valid'); $t->comment('Use a good media id : ' . $media->id); $form->bind(array('mediaId' => $media->id), array()); $t->is($form->isValid(), true, 'The form is valid'); $t->comment('Save the widget'); $form->updateWidget()->save(); $t->ok($widget->exists(), 'Widget has been saved'); $expected = array('mediaId' => $media->id, 'legend' => '', 'width' => '1000', 'height' => '', 'method' => dmConfig::get('image_resize_method'), 'background' => 'FFFFFF', 'quality' => NULL, 'link' => ''); ksort($expected); $widgetValues = $widget->values; ksort($widgetValues); $t->is_deeply($widgetValues, $expected, 'Widget values are correct'); $t->comment('Recreate the form from the saved widget'); $form = new $formClass($widget); $form->removeCsrfProtection(); $t->is($form->getDefault('mediaId'), $media->id, 'The form default mediaId is correct'); $t->comment('Submit form without additional data'); $form->bind($form->getDefaults(), array()); $t->is($form->isValid(), true, 'The form is valid'); $t->comment('Change widget options'); $form->bind(array_merge($form->getDefaults(), array('legend' => 'test legend', 'width' => 300, 'height' => 200, 'cssClass' => 'test css_class', 'method' => 'fit', 'quality' => 50, 'link' => 'http://diem-project.org')), array()); $t->is($form->isValid(), true, 'The form is valid'); if (!$form->isValid()) {