Ejemplo n.º 1
0
function media_file_image_tag(DmMedia $file, $options = array()) {
  $options = array_merge(array(
              'width' => $file->isImage() ? 128 : 64,
              'height' => $file->isImage() ? 98 : 64
          ), dmString::toArray($options, true));

  if ($file->isImage()) {
    $image = _media($file);
  } else {
    if (file_exists(
            dmOs::join(
                    sfConfig::get('sf_web_dir')
                    .
                    '/dmCorePlugin/images/media/'
                    .
                    dmOs::getFileExtension($file->getFile(), false)
                    . '.png'
            )
    )) {
      $image = _media('/dmCorePlugin/images/media/' . dmOs::getFileExtension($file->getFile(), false) . '.png');
    } else {
      $image = _media('/dmCorePlugin/images/media/unknown.png');
    }
  }

  return $image->size($options['width'], $options['height']);
}
Ejemplo n.º 2
0
 public function label($label = null, $attributes = array())
 {
     $attributes = dmString::toArray($attributes);
     $attributes['class'] = dmArray::toHtmlCssClasses(empty($attributes['class']) ? array('label') : array_merge((array) $attributes['class'], array('label')));
     $label = null === $label ? $this->parent->getWidget()->getLabel($this->name) : $label;
     $this->htmlBuffer .= parent::renderLabel($label, $attributes);
     return $this;
 }
Ejemplo n.º 3
0
function media_file_image_tag($file, $options = array())
{
    $options = array_merge(array('width' => $file->isImage() ? 128 : 64, 'height' => $file->isImage() ? 98 : 64), dmString::toArray($options, true));
    if ($file->isImage()) {
        $image = _media($file)->size($options['width'], $options['height']);
    } else {
        $image = _media('dmCore/images/media/unknown.png')->size($options['width'], $options['height']);
    }
    return $image;
}
Ejemplo n.º 4
0
  public function renderBodyTag($options = array())
  {
    $options = dmString::toArray($options);

    $options['class'] = dmArray::toHtmlCssClasses(array_merge(dmArray::get($options, 'class', array()), array(
      'page_'.$this->page->get('module').'_'.$this->page->get('action'),
      $this->page->getPageView()->getLayout()->get('css_class')
    )));
    
    return parent::renderBodyTag($options);
  }
Ejemplo n.º 5
0
 public function render($attributes = array())
 {
     $attributes = dmString::toArray($attributes, true);
     return $this->open($attributes) . '<ul class="dm_form_elements">' . $this->getFormFieldSchema()->render($attributes) . '</ul>' . sprintf('<div class="actions">
     <div class="actions_part clearfix">
       %s%s
     </div>
     <div class="actions_part clearfix">
       %s%s
     </div>
   </div>', sprintf('<a class="cancel dm close_dialog dm button fleft">%s</a>', $this->__('Cancel')), sprintf('<input type="submit" class="submit try blue fright" name="try" value="%s" />', $this->__('Try')), sprintf('<a class="delete dm button red fleft" title="%s">%s</a>', $this->__('Delete this zone'), $this->__('Delete')), sprintf('<input type="submit" class="submit and_save green fright" name="and_save" value="%s" />', $this->__('Save and close'))) . $this->close();
 }
Ejemplo n.º 6
0
 public function render($options = array())
 {
     $this->options = array_merge(dmString::toArray($options, true), $this->options);
     $this->html = $this->helper->open('ul', $this->options);
     $this->lastLevel = false;
     foreach ($this->tree as $node) {
         $this->level = $node[4];
         $this->html .= $this->renderNode($node);
         $this->lastLevel = $this->level;
     }
     $this->html .= str_repeat('</li></ul>', $this->lastLevel + 1);
     return $this->html;
 }
Ejemplo n.º 7
0
 public function render($options = array(), $treeOptions = array())
 {
     $this->options = array_merge(dmString::toArray($options, true), $this->options);
     $rootColumnName = $this->getTree()->getAttribute('rootColumnName');
     $this->html = '';
     if ($rootColumnName) {
         foreach ($this->getTree()->fetchRoots() as $root) {
             $treeOptions = array_merge($treeOptions, array('root_id' => $root->{$rootColumnName}));
             $this->renderTree($options, $treeOptions);
         }
     } else {
         $this->renderTree($options, $treeOptions);
     }
     return $this->html;
 }
Ejemplo n.º 8
0
 public function renderNavigation($options = array())
 {
     if (!$this->pager->haveToPaginate()) {
         return '';
     }
     if (!empty($options)) {
         $this->setOptions(array_merge($this->getOptions(), dmString::toArray($options, true)));
     }
     $this->initBaseHref();
     $cacheKey = $this->calculateCacheKey();
     if (isset($this->navigationCache[$cacheKey])) {
         return $this->navigationCache[$cacheKey];
     }
     $html = $this->openPager() . $this->renderFirstAndPreviousLinks() . $this->renderPageLinks() . $this->renderNextAndLastLinks() . $this->closePager();
     if ($this->getOption('ajax')) {
         $this->context->getResponse()->addJavascript('front.ajaxPager');
     }
     $this->navigationCache[$cacheKey] = $html;
     return $html;
 }
 public function renderArea($name, $options = array())
 {
     $options = dmString::toArray($options);
     //Set id of page we need
     $this->global_area_id = dmArray::get($options, 'global_area', null);
     unset($options['global_area']);
     $tagName = $this->getAreaTypeTagName($name);
     $area = $this->getArea($name);
     list($prefix, $type) = explode('.', $name);
     $options['class'] = array_merge(dmArray::get($options, 'class', array()), array('dm_area', 'dm_' . $prefix . '_' . $type, 'dm_area_' . $area['id'], $prefix == 'layout' ? 'dm_layout_shared' : '', $this->behaviorsManager->isAreaAttachable() ? 'dm_behaviors_attachable' : ''));
     $options['id'] = dmArray::get($options, 'id', 'dm_area_' . $area['id']);
     $html = '';
     /*
      * Add a content id for accessibility purpose ( access link )
      */
     if ('content' === $type) {
         $html .= '<div id="dm_content">';
     }
     $html .= $this->helper->open($tagName, $options);
     if ($this->behaviorsManager->isAreaAttachable()) {
         $html .= '<a class="dm dm_area_edit' . ($this->user->can('behavior_add') ? ' dm_behaviors_droppable' : '') . '">' . ('content' === $type ? $this->i18n->__('Content') : $this->i18n->__('Layout')) . '</a>';
         if ($this->user->can('behavior_edit') || $this->user->can('behavior_delete')) {
             $html .= '<a class="dm dm_edit_behaviors_icon dm_edit_behaviors_area_icon s16_gear s16" title="' . $this->i18n->__('Edit behaviors') . '"></a>';
         }
     }
     $html .= '<div class="dm_zones clearfix">';
     $html .= $this->renderAreaInner($area);
     $html .= '</div>';
     $html .= sprintf('</%s>', $tagName);
     /*
      * Add a content id for accessibility purpose ( access links )
      */
     if ('content' === $type) {
         $html .= '</div>';
     }
     return $html;
 }
 protected function compileVars(array $vars = array())
 {
     $this->compiledVars = array_merge(array(), (array) json_decode((string) $this->behavior['dm_behavior_value'], true), array('dm_behavior_id' => $this->behavior['id'], 'dm_behavior_key' => $this->behavior['dm_behavior_key'], 'dm_behavior_attached_to' => $this->behavior['dm_behavior_attached_to'], 'dm_behavior_attached_to_id' => (int) $this->behavior['dm_page_id'] + $this->behavior['dm_area_id'] + $this->behavior['dm_zone_id'] + $this->behavior['dm_widget_id'], 'dm_behavior_attached_to_content' => $this->behavior['dm_behavior_attached_to_selector'] != '' ? true : false, 'dm_behavior_attached_to_selector' => $this->behavior['dm_behavior_attached_to_selector'] != '' ? $this->behavior['dm_behavior_attached_to_selector'] : null, 'dm_behavior_sequence' => $this->behavior['position'], 'dm_behavior_enabled' => $this->isEnabled(), 'dm_behavior_valid' => true), dmString::toArray($vars));
 }
Ejemplo n.º 11
0
$t->is_deeply($string, '', '::retrieveOptFromString() sets the string parameter to an empty string');
// string overwrites opt
$t->diag('  ::retrieveOptFromString() overwriting');
$string = 'x=string';
$opt = array('x' => 'opt');
dmString::retrieveOptFromString($string, $opt);
$t->is_deeply($opt, array('x' => 'string'), '::retrieveOptFromString() string has the precedence over opt');
// ::retrieveCssFromString()
$t->diag('::retrieveCssFromString');
$cssFromStringsTests = array(array('', array(), '', array(), 'empty string'), array('#an_id', array(), '', array('id' => 'an_id'), 'one id only'), array('#an_id', array('id' => 'old'), '', array('id' => 'an_id'), 'id in opts is overridden'), array('.a_class', array(), '', array('class' => array('a_class')), 'one class only'), array('.a_class.another_class', array(), '', array('class' => array('a_class', 'another_class')), 'multiple classes'), array('#an_id.a_class', array(), '', array('id' => 'an_id', 'class' => array('a_class')), 'an id and a class'), array('#an_id.a_class href="/page"', array(), ' href="/page"', array('id' => 'an_id', 'class' => array('a_class')), 'garbage string after'), array('href="/page" a#an_id.a_class', array(), 'href="/page" a#an_id.a_class', array(), 'garbage string before'), array('#an_id alt="I am. Are you?"', array(), ' alt="I am. Are you?"', array('id' => 'an_id'), 'dots are not taken into account if not classes'), array('#an_id.imaclass alt="I am. Are you?"', array(), ' alt="I am. Are you?"', array('id' => 'an_id', 'class' => array('imaclass')), 'dots are not taken into account if not classes'), array('#an_id.imaclass alt="I am. Are you? and.imaclass"', array(), ' alt="I am. Are you? and.imaclass"', array('id' => 'an_id', 'class' => array('imaclass')), 'dots are not taken into account if not classes, and a class with same name exists'), array('.cls href="#anchor"', array(), ' href="#anchor"', array('class' => array('cls')), '# are not taken into account if not ids'), array('.cls href="page#anchor"', array(), ' href="page#anchor"', array('class' => array('cls')), '# are not taken into account if not ids, even if they have text before'));
foreach ($cssFromStringsTests as $cssFromStringsTest) {
    list($str, $opts, $expectedStr, $expectedOpts, $msg) = $cssFromStringsTest;
    dmString::retrieveCssFromString($str, $opts);
    $t->comment('  ::retrieveCssFromString() ' . $msg);
    $t->is_deeply($str, $expectedStr, '::retrieveCssFromString() ' . $msg . ': testing resulting string');
    $t->is_deeply($opts, $expectedOpts, '::retrieveCssFromString() ' . $msg . ': testing resulting opts');
}
// ::toArray()
$t->diag('::toArray()');
$t->is_deeply(dmString::toArray($arr = array('some' => 'array')), $arr, '::toArray() with an array returns the array');
$t->is_deeply(dmString::toArray(''), array(), '::toArray() with an empty string returns an empty array');
$t->is_deeply(dmString::toArray('#an_id.a_class.another_class'), array('id' => 'an_id', 'class' => array('a_class', 'another_class')), '::toArray() jquery style');
$t->is_deeply(dmString::toArray('an_option=a_value other_option=other_value'), array('an_option' => 'a_value', 'other_option' => 'other_value'), '::toArray() symfony style');
$t->is_deeply(dmString::toArray('#an_id.a_class.another_class an_option=a_value other_option=other_value'), array('id' => 'an_id', 'class' => array('a_class', 'another_class'), 'an_option' => 'a_value', 'other_option' => 'other_value'), '::toArray() with jquery AND symfony styles');
$t->is_deeply(dmString::toArray('#jquery id=symfony'), array('id' => 'symfony'), '::toArray() symfony style has precedence over jquery style');
$t->is_deeply(dmString::toArray('#an_id.a_class.another_class href=page#anchor'), array('id' => 'an_id', 'class' => array('a_class', 'another_class'), 'href' => 'page#anchor'), '::toArray() if a symfony style option contains a #');
$t->is_deeply(dmString::toArray('#an_id.a_class.another_class an_option=a_value other_option=other_value', true), array('id' => 'an_id', 'class' => 'a_class another_class', 'an_option' => 'a_value', 'other_option' => 'other_value'), '::toArray() with implodeClasses = true');
$t->is_deeply(dmString::toArray('action="http://site.com/url"'), array('action' => 'http://site.com/url'), 'correctly extract action');
$t->is_deeply(dmString::toArray('.class action="http://site.com/url"'), array('class' => array('class'), 'action' => 'http://site.com/url'), 'correctly extract action and class');
$t->is_deeply(dmString::toArray('#id.class action="http://site.com/url"'), array('id' => 'id', 'action' => 'http://site.com/url', 'class' => array('class')), 'correctly extract action, id and class');
Ejemplo n.º 12
0
function markdown($markdown, $opt = array())
{
    return _tag('div.markdown', dmString::toArray($opt), sfContext::getInstance()->get('markdown')->toHtml($markdown));
}
 public function render($attributes = array())
 {
     $attributes = dmString::toArray($attributes, true);
     return $this->open($attributes) . $this->renderContent($attributes) . $this->renderActions() . $this->close();
 }
 public function renderBodyTag($options = array())
 {
     return $this->getHelper()->open('body', dmString::toArray($options));
 }
Ejemplo n.º 15
0
 public function renderBodyTag($options = array())
 {
     $options = dmString::toArray($options);
     $options['class'] = array_merge(dmArray::get($options, 'class', array()), array($this->serviceContainer->getParameter('controller.module') . '_' . $this->serviceContainer->getParameter('controller.action')));
     return parent::renderBodyTag($options);
 }
Ejemplo n.º 16
0
 public function open($opt = array())
 {
     $opt = dmString::toArray($opt, true);
     $defaults = array('class' => dmArray::get($opt, 'class'), 'id' => $this->getKey(), 'anchor' => false);
     if (isset($opt['class'])) {
         unset($opt['class']);
     }
     $opt = array_merge($defaults, $opt);
     if ($action = dmArray::get($opt, 'action')) {
         $action = $this->getHelper()->link($action)->getHref();
     } else {
         $action = $this->getService('request')->getUri();
     }
     if (array_key_exists('anchor', $opt)) {
         if (!empty($opt['anchor']) && strpos($action, '#') === false) {
             $action .= '#' . (is_string($opt['anchor']) ? $opt['anchor'] : $this->getKey());
         }
         unset($opt['anchor']);
     }
     if (!isset($opt['method'])) {
         $opt['method'] = 'post';
     }
     if (isset($opt['action'])) {
         unset($opt['action']);
     }
     return $this->renderFormTag($action, $opt);
 }
 public function render($attributes = array())
 {
     $attributes = dmString::toArray($attributes, true);
     return $this->open($attributes) . $this->getHelper()->open('ul.dm_form_elements') . $this->getHelper()->tag('li.dm_form_element clearfix', $this['content']->field()->error()) . $this->getHelper()->tag('li.dm_form_element clearfix', $this['cssClass']->label()->field()->error()) . $this->getHelper()->close('ul') . $this->renderActions() . $this->close();
 }
Ejemplo n.º 18
0
 public function renderArea($name, $options = array())
 {
     $options = dmString::toArray($options);
     //Set id of page we need
     $this->global_area_id = dmArray::get($options, 'global_area', null);
     unset($options['global_area']);
     $tagName = $this->getAreaTypeTagName($name);
     $area = $this->getArea($name);
     list($prefix, $type) = explode('.', $name);
     $options['class'] = array_merge(dmArray::get($options, 'class', array()), array('dm_area', 'dm_' . $prefix . '_' . $type));
     $options['id'] = dmArray::get($options, 'id', 'dm_area_' . $area['id']);
     $html = '';
     /*
      * Add a content id for accessibility purpose ( access link )
      */
     if ('content' === $type) {
         $html .= '<div id="dm_content">';
     }
     $html .= $this->helper->open($tagName, $options);
     $html .= '<div class="dm_zones clearfix">';
     $html .= $this->renderAreaInner($area);
     $html .= '</div>';
     $html .= sprintf('</%s>', $tagName);
     /*
      * Add a content id for accessibility purpose ( access links )
      */
     if ('content' === $type) {
         $html .= '</div>';
     }
     return $html;
 }
Ejemplo n.º 19
0
 protected static function debugger($var, $level = 1, $opt = array())
 {
     $CR = "\n";
     $die = $level > 2;
     $opt = dmString::toArray($opt);
     if (!sfConfig::get('sf_debug') && !dmArray::get($opt, "force")) {
         return;
     }
     $tag = dmArray::get($opt, "tag", "pre");
     if (dmArray::get($opt, "to_string", false) && is_array($var)) {
         array_walk_recursive($var, create_function('&$val', 'if(is_object($val)) {
       if (method_exists($val, "toString")) {
         $val = get_class($val)." : ".$val->toString();
       }
       elseif (method_exists($val, "__toString")) {
         $val = get_class($val)." : ".$val->__toString();
       }
     }'));
     } elseif (is_array($var)) {
         array_walk_recursive($var, create_function('&$val', 'if(is_object($val)) {
       if (method_exists($val, "toDebug")) {
         $val = get_class($val)." : ".print_r($val->toDebug(), true);
       }
       elseif (method_exists($val, "toArray")) {
         $val = get_class($val)." : ".print_r($val->toArray(), true);
       }
     }'));
     }
     if (dmConfig::isCli()) {
         $debugString = print_r($var, true);
         $debugString = substr($debugString, 0, self::MAX_DEBUG_LENGTH);
         echo $debugString;
         if (strlen($debugString) > self::MAX_DEBUG_LENGTH) {
             echo "\n---TRUNCATED---\n";
         }
         if ($die) {
             die;
         }
     } else {
         array_walk_recursive($var, create_function('&$val', 'if(is_string($val)) { $val = htmlspecialchars($val); }'));
         if (count($var) == 1) {
             $var = dmArray::first($var);
         }
         if (dmContext::hasInstance() && ($request = dm::getRequest())) {
             if ($request->isXmlHttpRequest()) {
                 echo "\n<{$tag}>";
                 $debugString = print_r($var, true);
                 echo substr($debugString, 0, self::MAX_DEBUG_LENGTH);
                 if (strlen($debugString) > self::MAX_DEBUG_LENGTH) {
                     echo "\n---TRUNCATED---\n";
                 }
                 echo "</{$tag}>\n";
                 if ($die) {
                     die;
                 }
                 return;
             }
         }
         ob_start();
         if ($level > 1) {
             print '<br /><' . $tag . ' style="text-align: left; border: 1px solid #aaa; border-left-width: 10px; background-color: #f4F4F4; color: #000; margin: 3px; padding: 3px; font-size: 11px;">';
             $debugString = print_r($var, true);
             echo substr($debugString, 0, self::MAX_DEBUG_LENGTH);
             if (strlen($debugString) > self::MAX_DEBUG_LENGTH) {
                 echo "\n---TRUNCATED---\n";
             }
             print "</{$tag}>";
         }
         $buffer = ob_get_clean();
         if ($level == 4) {
             ob_start();
             echo '<pre>';
             debug_print_backtrace();
             echo '</pre>';
             $dieMsg = ob_get_clean();
         } else {
             $backtrace = debug_backtrace();
             $dieMsg = str_replace(sfConfig::get("sf_root_dir"), "", dmArray::get($backtrace[1], 'file')) . " l." . dmArray::get($backtrace[1], 'line');
             //      $dieMsg  = '<pre>';
             //      $dieMsg .= isset($backtrace[0]['file']) ?     '> file     : <b>'.
             //      $backtrace[1]['file'] .'</b>'. $CR : '';
             //      $dieMsg .= isset($backtrace[0]['line']) ?     '> line     : <b>'.
             //      $backtrace[1]['line'] .'</b>'. $CR : '';
             //      $dieMsg .= isset($backtrace[1]['class']) ?    '> class    : <b>'.
             //      dmArray::get(dmArray::get($backtrace, 2, array()), 'class') .'</b>'. $CR : '';
             //      $dieMsg .= isset($backtrace[1]['function']) ? '> function : <b>'.
             //      dmArray::get(dmArray::get($backtrace, 2, array()), 'function') .'</b>'. $CR : '';
             //      $dieMsg .= '</pre>';
         }
         if ($level > 1) {
             print $buffer;
             if ($die) {
                 die($dieMsg);
             } else {
                 print $dieMsg;
             }
         } else {
             sfWebDebug::getInstance()->logShortMessage($buffer . $dieMsg);
         }
     }
 }
Ejemplo n.º 20
0
 protected function compileVars(array $vars = array())
 {
     $this->compiledVars = array_merge(array('cssClass' => isset($this->widget['css_class']) ? $this->widget['css_class'] : null), (array) json_decode((string) $this->widget['value'], true), dmString::toArray($vars));
 }
Ejemplo n.º 21
0
 public function renderArea($type, $options = array())
 {
     $options = dmString::toArray($options);
     $tagName = $this->getAreaTypeTagName($type);
     $area = $this->getArea($type);
     $options['class'] = array_merge(dmArray::get($options, 'class', array()), array('dm_area', 'content' === $type ? 'dm_content' : 'dm_layout_' . $type));
     $options['id'] = dmArray::get($options, 'id', 'dm_area_' . $area['id']);
     $html = '';
     /*
      * Add a content id for accessibility purpose ( access link )
      */
     if ('content' === $type) {
         $html .= '<div id="dm_content">';
     }
     $html .= $this->helper->open($tagName, $options);
     $html .= '<div class="dm_zones clearfix">';
     $html .= $this->renderAreaInner($area);
     $html .= '</div>';
     $html .= sprintf('</%s>', $tagName);
     /*
      * Add a content id for accessibility purpose ( access links )
      */
     if ('content' === $type) {
         $html .= '</div>';
     }
     return $html;
 }
Ejemplo n.º 22
0
 protected function compileVars(array $vars = array())
 {
     $this->compiledVars = array_merge(array(), (array) json_decode((string) $this->widget['value'], true), dmString::toArray($vars));
 }