Author: Chema (chema@open-classifieds.com)
Exemplo n.º 1
0
 /**
  * @param Widget $fieldWidget Field widget
  * @param array $config Configuration options
  * @param string $config['align'] Alignment mode, either 'left', 'right', 'top' or 'inline'
  *   (default: 'left')
  * @param string $config['help'] Explanatory text shown as a '?' icon.
  */
 public function __construct($fieldWidget, array $config = array())
 {
     // Allow passing positional parameters inside the config array
     if (is_array($fieldWidget) && isset($fieldWidget['fieldWidget'])) {
         $config = $fieldWidget;
         $fieldWidget = $config['fieldWidget'];
     }
     $hasInputWidget = $fieldWidget instanceof InputWidget;
     // Config initialization
     $config = array_merge(array('align' => 'left'), $config);
     // Parent constructor
     parent::__construct($config);
     // Properties
     $this->fieldWidget = $fieldWidget;
     $this->field = new Tag('div');
     $this->body = new Tag($hasInputWidget ? 'label' : 'div');
     if (isset($config['help'])) {
         $this->help = new ButtonWidget(array('classes' => array('oo-ui-fieldLayout-help'), 'framed' => false, 'icon' => 'info', 'title' => $config['help']));
     } else {
         $this->help = '';
     }
     // Mixins
     $this->mixin(new LabelElement($this, $config));
     // Initialization
     $this->addClasses(array('oo-ui-fieldLayout'))->appendContent($this->help, $this->body);
     $this->body->addClasses(array('oo-ui-fieldLayout-body'));
     $this->field->addClasses(array('oo-ui-fieldLayout-field'))->toggleClasses(array('oo-ui-fieldLayout-disable'), $this->fieldWidget->isDisabled())->appendContent($this->fieldWidget);
     $this->setAlignment($config['align']);
 }
Exemplo n.º 2
0
 /**
  * Guess the position of the widget relatively to the positionReference
  *
  * @param Widget  $widget            The widget to position
  * @param integer $positionReference Id of the parent widget
  *
  * @return WidgetMap The position of the widget
  */
 public function generateWidgetPosition(WidgetMap $widgetMapEntry, $widget, $widgetMap, $positionReference)
 {
     $position = 1;
     $slotId = $widget->getSlot();
     if (empty($widgetMap[$slotId])) {
         $widgetMapEntry->setPosition($position);
         return $widgetMapEntry;
     }
     $slot = $widgetMap[$slotId];
     $referenceWidget = $this->em->getRepository('Victoire\\Bundle\\WidgetBundle\\Entity\\Widget')->findOneById($positionReference);
     //If we added a widget just after a parent widget
     //The position of the new widget is the one just after the parent widget
     if ($referenceWidget && $widget->getView() !== $referenceWidget->getView()) {
         $position = 1;
         $widgetMapEntry->setPosition($position);
         $widgetMapEntry->setPositionReference($positionReference);
     } else {
         foreach ($slot as $key => $_widgetMap) {
             if ($_widgetMap->getWidgetId() === (int) $positionReference) {
                 $widgetMapEntry->setPosition($_widgetMap->getPosition() + 1);
                 break;
             } elseif (0 === (int) $positionReference) {
                 $widgetMapEntry->setPosition(1);
             }
         }
     }
     return $widgetMapEntry;
 }
 /**
  * Build storage facility object from result set row
  * 
  * @param array $row
  * @return Widget 
  */
 public function buildFromRow(array $row)
 {
     $obj = new Widget();
     $obj->setId($row['id']);
     $obj->setName($row['name']);
     return $obj;
 }
Exemplo n.º 4
0
function page()
{
    global $db, $user, $session, $sites;
    /*
         * Lets send a test message to the logged in user
        $message = new Message();
        $message->to(1);
        $message->from(0); //0 will be "system";
        $message->setSubject('This is a second test message');
        $message->setBody("This would be an actual message had this not been a test.");
        $message->send();
    */
    print "Set site is " . $session->current_site;
    ?>
    <h3>Dashboard</h3>
    <section id="widget-grid" class="">

            <!-- row -->
            <div class="row">
                <article class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                    <?php 
    $test = new Widget();
    $test->setTitle('My first widget');
    $action2 = array('label' => 'Test', 'url' => '/pages/user/users.php', 'class' => 'danger');
    $test->setActions($action2);
    $actions = array('label' => 'Users', 'subitems' => array(array('label' => 'Users2', 'url' => '/pages/user/users.php'), array('label' => 'Users3', 'url' => '/pages/user/users.php')));
    $test->setActions($actions);
    $test->render();
    $test2 = new Widget();
    $test2->setTitle('My second widget');
    $headers = array('First Name', 'Last Name');
    $data = $db->select('firstname,lastname')->from('users')->limit(10)->fetch();
    $test2->addTable($headers, $data);
    $test2->render();
    print "Cookies<br>";
    if (isset($_COOKIE)) {
        foreach ($_COOKIE as $name => $value) {
            $name = htmlspecialchars($name);
            $value = htmlspecialchars($value);
            echo "{$name} : {$value} <br />\n";
        }
    }
    ?>
                </article>

                <article class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                    <?php 
    $test3 = new Widget();
    $test3->setTitle('My third widget');
    $test3->addContent("<p>Sites allowed:</p>" . $user->sites('list'));
    $test3->render();
    ?>
                </article>
            </div>
        </section>

    <?php 
}
Exemplo n.º 5
0
 /**
  * @dataProvider getData
  */
 public function testExchangeArray($data)
 {
     $model = new Widget();
     $out = $model->exchangeArray($data);
     $this->assertInternalType('array', $out);
     foreach (array('id', 'name', 'description', 'sold', 'price', 'currency') as $c) {
         $this->assertArrayHasKey($c, $out);
     }
 }
Exemplo n.º 6
0
 public function widget_create($tipo)
 {
     $widget = new Widget();
     $widget->nombre = 'Nuevo widget';
     $widget->tipo = $tipo;
     $widget->cuenta_id = UsuarioBackendSesion::usuario()->cuenta_id;
     $widget->save();
     redirect($this->input->server('HTTP_REFERER'));
 }
 /**
  * Add the custom regexp "dezimal" to Contao.
  */
 public function hookAddCustomRegexp($strRegexp, $varValue, \Widget $objWidget)
 {
     if ($strRegexp == 'dezimal') {
         if (!preg_match('/^\\-?\\d+(,\\d+)?$/', trim($varValue))) {
             $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['digit'], $objWidget->label));
         }
         return true;
     }
     return false;
 }
Exemplo n.º 8
0
 function let(\Widget $widget)
 {
     $widget->getErrors()->willReturn(array());
     $this->beConstructedWith($widget);
     if (!class_exists('FrontendTemplate', false)) {
         class_alias('spec\\Netzmacht\\Contao\\FormHelper\\FrontendTemplate', 'FrontendTemplate');
     }
     if (!isset($GLOBALS['TL_FFL'])) {
         $GLOBALS['TL_FFL'] = array();
     }
 }
 public function validateVotingEmailFormField(\Widget $objWidget, $intId)
 {
     if (($objForm = \FormModel::findBy('alias', str_replace('auto_', '', $intId))) !== null && $objForm->maxVoteCount) {
         // check if a voting from the mail address already exists
         $db = \Database::getInstance();
         $objEmailCheck = $db->prepare('SELECT * FROM tl_formdata_details fdt INNER JOIN tl_formdata fd ON fdt.pid=fd.id INNER JOIN tl_form f ON fd.form=f.title WHERE fdt.ff_name=? AND fdt.value=? AND f.alias=?')->execute('email', $objWidget->value, $objForm->alias);
         if ($objEmailCheck->numRows > 0 && $objEmailCheck->numRows >= $objForm->maxVoteCount) {
             $objWidget->addError(sprintf($GLOBALS['TL_LANG']['email_voting']['maxVoteCount'], $objForm->maxVoteCount));
         }
     }
     return $objWidget;
 }
Exemplo n.º 10
0
 protected function createWidget($widgetName, $attributes = array())
 {
     $o = new Widget($this);
     foreach ($attributes as $aname => $avalue) {
         $o->setAttribute($aname, $avalue);
     }
     $o->setAttribute('do', $widgetName);
     if (in_array($widgetName, array('textInput', 'button', 'checkBox', 'radioButton', 'fieldsetSwitch'))) {
         $this->describeWidgets[] = $o;
     }
     return $o;
 }
Exemplo n.º 11
0
 function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     echo $before_widget;
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     $gallery = new Widget();
     echo $gallery->buildGallery($instance);
     echo $after_widget;
 }
Exemplo n.º 12
0
 public function positiveFloatRegExpHook($strRegexp, $varValue, \Widget $objWidget)
 {
     if ($strRegexp == 'posfloat') {
         if (strpos($varValue, ',') != false) {
             $objWidget->addError($GLOBALS['TL_LANG']['ERR']['posFloat']['commaFound']);
         }
         if (!preg_match('/^\\d+(?:\\.\\d+)?$/', $varValue)) {
             $objWidget->addError($GLOBALS['TL_LANG']['ERR']['posFloat']['noFloat']);
         }
         return true;
     }
     return false;
 }
Exemplo n.º 13
0
 public function addWidgets()
 {
     $widgets = $this->twig->getLoader()->searchTemplates('widgets/*.twig');
     foreach ($widgets as $template => $name) {
         $id = str_replace('/', '\\', substr($template, 1, -5));
         $widget = new Widget($id, $name, $template, $this->container, $this->twig, $this->wpWrapper, $this->formManager);
         if ($widget->isInternal()) {
             $this->internalWidgets[$widget->id_base] = $widget;
         } else {
             $this->wpWrapper->registerWidget('Neochic\\Woodlets\\_Widgets\\' . $id, $widget);
         }
     }
 }
Exemplo n.º 14
0
 function it_creates_a_view(\Widget $widget, EventDispatcher $eventDispatcher)
 {
     $widget->getErrors()->willReturn(array());
     $eventDispatcher->dispatch(Events::CREATE_VIEW, Argument::type(self::VIEW_EVENT_CLASS))->shouldBeCalled();
     $eventDispatcher->dispatch(Events::CREATE_ELEMENT, Argument::type(self::CREATE_ELEMENT_EVENT_CLASS))->will(function ($args) {
         /** @var CreateElementEvent $event */
         $event = $args[1];
         $event->setElement(new Node('input'));
     });
     $eventDispatcher->dispatch(Events::PRE_GENERATE_VIEW, Argument::type(self::VIEW_EVENT_CLASS))->shouldBeCalled();
     $eventDispatcher->dispatch(Events::GENERATE_VIEW, Argument::type(self::VIEW_EVENT_CLASS))->shouldBeCalled();
     $this->createView($widget)->shouldBeAnInstanceOf(self::VIEW_CLASS);
 }
Exemplo n.º 15
0
 function __construct($group, $owner = null, $action = null)
 {
     parent::__construct($action);
     $this->group = $group;
     $this->owner = $owner;
     $this->action = $action;
 }
Exemplo n.º 16
0
 public function init()
 {
     parent::init();
     if (!$this->model instanceof ActiveRecord) {
         throw new CException("Параметр model Должен быть объектом класса ActiveRecord");
     }
 }
Exemplo n.º 17
0
 public static function newInstance()
 {
     if (!self::$instance instanceof self) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 public function executePostActionsHook($strAction, \DataContainer $dc)
 {
     if ($strAction == FieldPalette::$strFieldpaletteRefreshAction) {
         if (\Input::post('field')) {
             \Controller::loadDataContainer($dc->table);
             $strName = \Input::post('field');
             $arrField = $GLOBALS['TL_DCA'][$dc->table]['fields'][$strName];
             // Die if the field does not exist
             if (!is_array($arrField)) {
                 header('HTTP/1.1 400 Bad Request');
                 die('Bad Request');
             }
             /** @var \Widget $strClass */
             $strClass = $GLOBALS['BE_FFL'][$arrField['inputType']];
             // Die if the class is not defined or inputType is not fieldpalette
             if ($arrField['inputType'] != 'fieldpalette' || !class_exists($strClass)) {
                 header('HTTP/1.1 400 Bad Request');
                 die('Bad Request');
             }
             $arrData = \Widget::getAttributesFromDca($arrField, $strName, $dc->activeRecord->{$strName}, $strName, $dc->table, $dc);
             /** @var \Widget $objWidget */
             $objWidget = new $strClass($arrData);
             $objWidget->currentRecord = $dc->id;
             die(json_encode(array('field' => $strName, 'target' => '#ctrl_' . $strName, 'content' => $objWidget->generate())));
         }
         header('HTTP/1.1 400 Bad Request');
         die('Bad Request');
     }
 }
Exemplo n.º 19
0
 /**
  * Return a parameter
  * @param string
  * @return mixed
  */
 public function __get($strKey)
 {
     if ($strKey == 'options') {
         return $this->arrOptions;
     }
     return parent::__get($strKey);
 }
Exemplo n.º 20
0
 function view()
 {
     $this->_Parent->Page->addStylesheetToHead(URL . '/extensions/members/assets/styles.css', 'screen', 70);
     $create_button = Widget::Anchor('Create a New Role', extension_members::baseURL() . 'new/', 'Create a new role', 'create button');
     $this->setPageType('table');
     $this->appendSubheading('Member Roles ' . $create_button->generate(false));
     $aTableHead = array(array('Name', 'col'), array('Members', 'col'));
     $roles = $this->_driver->fetchRoles();
     $aTableBody = array();
     if (!is_array($roles) || empty($roles)) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None Found.'), 'inactive', NULL, count($aTableHead)))));
     } else {
         $sectionManager = new SectionManager($this->_Parent);
         $section = $sectionManager->fetch($this->_Parent->Database->fetchVar('parent_section', 0, "SELECT `parent_section` FROM `tbl_fields` WHERE `id` = '" . $this->_driver->usernameAndPasswordField() . "' LIMIT 1"));
         $bEven = true;
         $role_field_name = $this->_Parent->Database->fetchVar('element_name', 0, "SELECT `element_name` FROM `tbl_fields` WHERE `id` = '" . $this->_driver->roleField() . "' LIMIT 1");
         foreach ($roles as $role) {
             $member_count = $this->_Parent->Database->fetchVar('count', 0, "SELECT COUNT(*) AS `count` FROM `tbl_entries_data_" . $this->_driver->roleField() . "` WHERE `role_id` = '" . $role->id() . "'");
             ## Setup each cell
             $td1 = Widget::TableData(Widget::Anchor($role->name(), extension_members::baseURL() . 'edit/' . $role->id() . '/', NULL, 'content'));
             $td2 = Widget::TableData(Widget::Anchor("{$member_count}", URL . '/symphony/publish/' . $section->get('handle') . '/?filter=' . $role_field_name . ':' . $role->id()));
             ## Add a row to the body array, assigning each cell to the row
             $aTableBody[] = Widget::TableRow(array($td1, $td2), $bEven ? 'odd' : NULL);
             $bEven = !$bEven;
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody));
     $this->Form->appendChild($table);
 }
Exemplo n.º 21
0
 /**
  * {@inheritDoc}
  */
 protected function validator($varInput)
 {
     if (is_array($varInput)) {
         return parent::validator($varInput);
     }
     return parent::validator(trim($varInput));
 }
Exemplo n.º 22
0
 public function view(SymphonyDOMElement $wrapper, MessageStack $errors)
 {
     $layout = new Layout();
     $left = $layout->createColumn(Layout::SMALL);
     $right = $layout->createColumn(Layout::LARGE);
     //	Essentials --------------------------------------------------------
     $fieldset = Widget::Fieldset(__('Essentials'));
     // Name:
     $label = Widget::Label(__('Name'));
     $input = Widget::Input('fields[about][name]', General::sanitize($this->about()->name));
     $label->appendChild($input);
     if (isset($errors->{'about::name'})) {
         $label = Widget::wrapFormElementWithError($label, $errors->{'about::name'});
     }
     $fieldset->appendChild($label);
     $left->appendChild($fieldset);
     $fieldset = Widget::Fieldset(__('Content'));
     $label = Widget::Label(__('Source XML'));
     $input = Widget::Textarea('fields[xml]', $this->parameters()->{'xml'}, array('rows' => '24', 'cols' => '50', 'class' => 'code'));
     $label->appendChild($input);
     if (isset($errors->{'xml'})) {
         $label = Widget::wrapFormElementWithError($label, $errors->{'xml'});
     }
     $fieldset->appendChild($label);
     $right->appendChild($fieldset);
     $layout->appendTo($wrapper);
 }
Exemplo n.º 23
0
 /**
  * Constructor
  *
  */
 function __construct()
 {
     // Call the Widget constructor
     parent::__construct();
     // Create a instance to CI
     $CI =& get_instance();
 }
 public function displaySettingsPanel(&$wrapper, $errors = NULL)
 {
     parent::displaySettingsPanel($wrapper, $errors);
     $sectionManager = new SectionManager($this->_engine);
     $sections = $sectionManager->fetch(NULL, 'ASC', 'sortorder');
     $options = array();
     // iterate over sections to build list of fields
     if (is_array($sections) && !empty($sections)) {
         foreach ($sections as $section) {
             $section_fields = $section->fetchFields();
             if (!is_array($section_fields)) {
                 continue;
             }
             $fields = array();
             foreach ($section_fields as $f) {
                 // only show select box link fields
                 if ($f->get('type') == 'selectbox_link') {
                     $fields[] = array($f->get('id'), $this->get('related_sbl_id') == $f->get('id'), $f->get('label'));
                 }
             }
             if (!empty($fields)) {
                 $options[] = array('label' => $section->get('name'), 'options' => $fields);
             }
         }
     }
     $group = new XMLElement('div', NULL, array('class' => 'group'));
     $label = Widget::Label(__('Child Select Box Link'));
     $label->appendChild(Widget::Select('fields[' . $this->get('sortorder') . '][related_sbl_id]', $options));
     if (isset($errors['related_sbl_id'])) {
         $group->appendChild(Widget::wrapFormElementWithError($label, $errors['related_sbl_id']));
     } else {
         $group->appendChild($label);
     }
     $wrapper->appendChild($group);
 }
Exemplo n.º 25
0
 /**
  * Add specific attributes
  * @param string
  * @param mixed
  */
 public function __set($strKey, $varValue)
 {
     switch ($strKey) {
         case 'maxlength':
             // Do not add as attribute (see #3094)
             $this->arrConfiguration['maxlength'] = $varValue;
             break;
         case 'mandatory':
             if ($varValue) {
                 $this->arrAttributes['required'] = 'required';
             } else {
                 unset($this->arrAttributes['required']);
             }
             parent::__set($strKey, $varValue);
             break;
         case 'fSize':
             if ($varValue > 0) {
                 $this->arrAttributes['size'] = $varValue;
             }
             break;
         default:
             parent::__set($strKey, $varValue);
             break;
     }
 }
Exemplo n.º 26
0
 /**
  * Trim values
  * @param mixed
  * @return mixed
  */
 protected function validator($varInput)
 {
     $varInput[0] = parent::validator($varInput[0]);
     $varInput[1] = parent::validator($varInput[1]);
     $varInput[2] = preg_replace('/[^a-z0-9_]+/', '', $varInput[2]);
     return $varInput;
 }
 /**
  * renderFile 
  * 重写renderFile.可以自由组合参数进行模板输出
  * @param string $templateFile 
  * @param string $var 
  * @param string $charset 
  * @access protected
  * @return maxed
  */
 protected function renderFile($templateFile = '', $var = '', $charset = 'utf-8')
 {
     //if( empty( $var ) ){
     //$var = $this->tVar;
     //}
     return parent::renderFile($templateFile . 'Widget', $var, $charset);
 }
 public function __viewIndex()
 {
     $this->setPageType('table');
     $this->setTitle('Symphony &ndash; Importers');
     $tableHead = array(array('Name', 'col'), array('Version', 'col'), array('Author', 'col'));
     $tableBody = array();
     if (!is_array($this->_importers) or empty($this->_importers)) {
         $tableBody = array(Widget::TableRow(array(Widget::TableData(__('None Found.'), 'inactive', null, count($tableHead)))));
     } else {
         foreach ($this->_importers as $importer) {
             $importer = (object) $importer;
             $col_name = Widget::TableData(Widget::Anchor($this->_driver->truncateValue($importer->name), $this->_uri . "/importers/edit/{$importer->handle}/"));
             $col_name->appendChild(Widget::Input("items[{$importer->id}]", null, 'checkbox'));
             $col_version = Widget::TableData($this->_driver->truncateValue($importer->version));
             $col_author = Widget::TableData($this->_driver->truncateValue($importer->version));
             if (isset($importer->author['website']) and preg_match('/^[^\\s:\\/?#]+:(?:\\/{2,3})?[^\\s.\\/?#]+(?:\\.[^\\s.\\/?#]+)*(?:\\/[^\\s?#]*\\??[^\\s?#]*(#[^\\s#]*)?)?$/', $importer->author['website'])) {
                 $col_author = Widget::Anchor($importer->author['name'], General::validateURL($importer->author['website']));
             } elseif (isset($importer->author['email']) and preg_match('/^\\w(?:\\.?[\\w%+-]+)*@\\w(?:[\\w-]*\\.)+?[a-z]{2,}$/i', $importer->author['email'])) {
                 $col_author = Widget::Anchor($importer->author['name'], 'mailto:' . $importer->author['email']);
             } else {
                 $col_author = $importer->author['name'];
             }
             $col_author = Widget::TableData($col_author);
             $tableBody[] = Widget::TableRow(array($col_name, $col_version, $col_author));
         }
     }
     $table = Widget::Table(Widget::TableHead($tableHead), null, Widget::TableBody($tableBody));
     $this->Form->appendChild($table);
 }
Exemplo n.º 29
0
 /**
  * Add site preferences
  */
 public function __addPreferences($context)
 {
     // Get selected languages
     $selection = Symphony::Configuration()->get('datetime');
     if (empty($selection)) {
         $selection = array();
     }
     // Build default options
     $options = array();
     foreach ($this->languages as $name => $codes) {
         $options[$name] = array($name . '::' . $codes, array_key_exists($name, $selection) ? true : false, __(ucfirst($name)));
     }
     // Add custom options
     foreach (array_diff_key($selection, $this->languages) as $name => $codes) {
         $options[$name] = array($name . '::' . $codes, true, __(ucfirst($name)));
     }
     // Sort options
     ksort($options);
     // Add fieldset
     $group = new XMLElement('fieldset', '<legend>' . __('Date and Time') . '</legend>', array('class' => 'settings'));
     $select = Widget::Select('settings[datetime][]', $options, array('multiple' => 'multiple'));
     $label = Widget::Label('Languages included in the Date and Time Data Source', $select);
     $group->appendChild($label);
     $help = new XMLElement('p', __('You can add more languages in you configuration file.'), array('class' => 'help'));
     $group->appendChild($help);
     $context['wrapper']->appendChild($group);
 }
Exemplo n.º 30
0
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->merge(new FieldSet(new OptionsetField('DisplayMode', _t('ArchiveWidget.DispBY', 'Display by'), array('month' => _t('ArchiveWidget.MONTH', 'month'), 'year' => _t('ArchiveWidget.YEAR', 'year')))));
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }