Exemplo n.º 1
0
 protected function process()
 {
     $data = $this->preparse_data();
     $data = $this->parse_data($data);
     $save = Request::from(['path' => Operation::encode("{$this->module}/save")], [$_SERVER]);
     #
     # override form
     #
     $core->events->attach(function (Operation\GetFormEvent $event, SaveOperation $operation) use($save) {
         if ($event->request !== $save) {
             return;
         }
         $event->form = new Form();
     });
     /*
     $siteid = $core->site_id;
     $keys = $core->models['nodes']->select('nid')->filter_by_siteid($siteid)->all(\PDO::FETCH_COLUMN);
     
     if ($keys)
     {
     	$core->models['nodes']->where([ 'nid' => $keys ])->delete();
     	$core->models['pages']->where([ 'nid' => $keys ])->delete();
     	$core->models['pages/contents']->where([ 'pageid' => $keys ])->delete();
     }
     */
     $this->import($data, $save);
     $this->response->message = "Records were successfuly imported.";
     return true;
 }
Exemplo n.º 2
0
 /**
  * Tries to create an {@link Operation} instance from the specified request. The operation
  * is then executed and its response returned.
  *
  * If an operation could be created from the request, the `operation` property of the request's
  * context is set to that operation.
  *
  * For forwarded operation, successful responses are not returned unless the request is an XHR
  * or the response has a location.
  *
  * @inheritdoc
  */
 public function __invoke(Request $request)
 {
     $request->context->operation = $operation = Operation::from($request);
     if (!$operation) {
         return null;
     }
     return $this->respond($operation, $request);
 }
Exemplo n.º 3
0
 protected function preview($path)
 {
     global $core;
     $w = $this->w;
     $h = $this->h;
     $url = Operation::encode('thumbnailer/get', array('src' => $path, 'w' => $w, 'h' => $h, 'format' => 'jpeg', 'quality' => 90, 'background' => 'silver,white,medium', 'uniqid' => uniqid()));
     $img = new Element('img', array('src' => $url, 'width' => $w, 'height' => $h, 'alt' => ''));
     $repository = $core->config['repository.temp'];
     if (strpos($path, $repository) === 0) {
         return $img;
     }
     return '<a href="' . $path . '&amp;uniqid=' . uniqid() . '" rel="lightbox">' . $img . '</a>';
 }
    public static function create_attachment($entry, $hard_bond = false)
    {
        global $core;
        $hiddens = null;
        $links = array();
        $i = uniqid();
        $size = \ICanBoogie\I18n\format_size($entry->size);
        $preview = null;
        if ($entry instanceof Uploaded) {
            $title = $entry->name;
            $extension = $entry->extension;
            $hiddens .= '<input type="hidden" class="file" name="nodes_attachments[' . $i . '][file]" value="' . \ICanBoogie\escape(basename($entry->location)) . '" />' . PHP_EOL;
            $hiddens .= '<input type="hidden" name="nodes_attachments[' . $i . '][mime]" value="' . \ICanBoogie\escape($entry->mime) . '" />' . PHP_EOL;
            $links = array('<a href="#remove" class="btn btn-warning">' . I18n\t('label.remove') . '</a>');
        } else {
            $fid = $entry->nid;
            $title = $entry->title;
            $extension = substr($entry->path, strrpos($entry->path, '.'));
            $hiddens .= '<input type="hidden" name="nodes_attachments[' . $i . '][fileid]" value="' . $fid . '" />';
            $links = array('<a href="' . \ICanBoogie\Routing\contextualize('/admin/files/' . $fid . '/edit') . '" class="btn"><i class="icon-pencil"></i> ' . I18n\t('label.edit') . '</a>', '<a href="' . Operation::encode('files/' . $fid . '/download') . '" class="btn"><i class="icon-download-alt"></i> ' . I18n\t('label.download') . '</a>', $hard_bond ? '<a href="#delete" class="btn btn-danger"><i class="icon-remove icon-white"></i> ' . I18n\t('Delete file') . '</a>' : '<a href="#remove" class="btn btn-warning"><i class="icon-remove"></i> ' . t('Break link') . '</a>');
            $node = $core->models['nodes'][$entry->nid];
            if ($node instanceof \Icybee\Modules\Images\Image) {
                $preview = $node->thumbnail('$icon')->to_element(array('data-popover-image' => $node->thumbnail('$popup')->url));
            }
        }
        $title = \ICanBoogie\escape($title);
        $links = empty($links) ? '' : ' &ndash; ' . implode(' ', $links);
        if ($extension) {
            $extension = '<span class="lighter">(' . $extension . ')</span>';
        }
        return <<<EOT
<li>
\t<span class="handle">↕</span>{$preview}<input type="text" name="nodes_attachments[{$i}][title]" value="{$title}" />
\t<span class="small">
\t\t<span class="info light">{$size} {$extension}</span> {$links}
\t</span>

\t{$hiddens}
</li>
EOT;
    }
Exemplo n.º 5
0
 /**
  * Replaces managed images with width or height attributes by thumbnails, and transform markup
  * when the original image can be displayed in a lightbox.
  *
  * @see Icybee\Modules\Editor.Editor::render()
  */
 public function render($content)
 {
     return preg_replace_callback('#<img\\s+[^>]+>#', function ($match) {
         global $core;
         preg_match_all('#([\\w\\-]+)\\s*=\\s*\\"([^"]+)#', $match[0], $attributes);
         $attributes = array_combine($attributes[1], $attributes[2]);
         $attributes = array_map(function ($v) {
             return html_entity_decode($v, ENT_COMPAT, \ICanBoogie\CHARSET);
         }, $attributes);
         $attributes += array('width' => null, 'height' => null, 'data-nid' => null);
         $w = $attributes['width'];
         $h = $attributes['height'];
         $nid = $attributes['data-nid'];
         if ($w && $h && $nid) {
             $attributes['src'] = Operation::encode('images/' . $nid . '/' . $w . 'x' . $h);
         } else {
             if (($w || $h) && preg_match('#^/repository/files/image/(\\d+)#', $attributes['src'], $matches)) {
                 $nid = $matches[1];
                 $options = $attributes;
                 unset($options['src']);
                 $thumbnail = new Thumbnail($core->models['images'][$nid], $options);
                 $attributes['src'] = $thumbnail->url;
             }
         }
         $path = null;
         if (isset($attributes['data-lightbox']) && $nid) {
             $attributes['src'] = preg_replace('#\\&amp;lightbox=true#', '', $attributes['src']);
             $path = $core->models['images']->select('path')->filter_by_nid($nid)->rc;
         }
         unset($attributes['data-nid']);
         unset($attributes['data-lightbox']);
         $rc = (string) new Element('img', $attributes);
         if ($path) {
             $rc = '<a href="' . \ICanBoogie\escape($path) . '" rel="lightbox[]">' . $rc . '</a>';
         }
         return $rc;
     }, $content);
 }
Exemplo n.º 6
0
 /**
  * Controls for the operation: form.
  */
 protected function get_controls()
 {
     return array(self::CONTROL_FORM => true) + parent::get_controls();
 }
Exemplo n.º 7
0
 /**
  * Adds the {@link CONTROL_RECORD} control.
  */
 protected function get_controls()
 {
     return [self::CONTROL_RECORD => true] + parent::get_controls();
 }
Exemplo n.º 8
0
 /**
  * Controls for the operation: permission(maintain), record and ownership.
  */
 protected function get_controls()
 {
     return [self::CONTROL_PERMISSION => Module::PERMISSION_MAINTAIN, self::CONTROL_RECORD => true, self::CONTROL_OWNERSHIP => true] + parent::get_controls();
 }
Exemplo n.º 9
0
 /**
  * Controls for the operation: authentication, permission(create)
  */
 protected function get_controls()
 {
     return array(self::CONTROL_AUTHENTICATION => true, self::CONTROL_PERMISSION => Module::PERMISSION_CREATE) + parent::get_controls();
 }
Exemplo n.º 10
0
 protected function get_controls()
 {
     return array(self::CONTROL_RECORD) + parent::get_controls();
 }
 /**
  * @todo-20131009: remove this when Operation is cleverer.
  */
 public function __construct($request = null)
 {
     global $core;
     parent::__construct($request);
     $this->module = $core->modules['users.noncelogin'];
 }
Exemplo n.º 12
0
 protected function get_controls()
 {
     return array(self::CONTROL_PERMISSION => Module::PERMISSION_CREATE, self::CONTROL_RECORD => true) + parent::get_controls();
 }
Exemplo n.º 13
0
 protected function get_controls()
 {
     return array(self::CONTROL_PERMISSION => Module::PERMISSION_ADMINISTER) + parent::get_controls();
 }
Exemplo n.º 14
0
 /**
  * Clears the `core.modules`, `core.configs` and `core.catalogs` caches.
  */
 public static function clear_modules_cache()
 {
     Request::from(Operation::encode('cache/core.modules/clear'))->post();
     Request::from(Operation::encode('cache/core.configs/clear'))->post();
     Request::from(Operation::encode('cache/core.catalogs/clear'))->post();
 }
Exemplo n.º 15
0
 public function __construct(array $attributes = array())
 {
     $attributes += [self::POP_OPTIONS => [], self::UPLOAD_OPTIONS => []];
     parent::__construct('div', $attributes + array(Element::CHILDREN => array($this->pop_image = new PopImage($attributes[self::POP_OPTIONS]), $this->upload_image = new UploadImage($attributes[self::UPLOAD_OPTIONS] + [UploadImage::FILE_WITH_LIMIT => true, 'data-name' => Image::PATH, 'data-upload-url' => Operation::encode('images/save')])), Element::WIDGET_CONSTRUCTOR => 'PopOrUploadImage'));
 }
Exemplo n.º 16
0
 public function __invoke(Request $request)
 {
     global $core;
     $core->session->install['done'][$this->installer_operation_id] = false;
     return parent::__invoke($request);
 }
Exemplo n.º 17
0
 protected function get_controls()
 {
     return array(self::CONTROL_RECORD => true, self::CONTROL_PERMISSION => true, self::CONTROL_FORM => true) + parent::get_controls();
 }
Exemplo n.º 18
0
 protected function get_controls()
 {
     return array(self::CONTROL_AUTHENTICATION => true) + parent::get_controls();
 }
Exemplo n.º 19
0
 /**
  * Overrides the method in order for the control to pass if the operation key is empty, which
  * is the case when creating a new record.
  */
 protected function control_record()
 {
     return $this->key ? parent::control_record() : true;
 }
Exemplo n.º 20
0
 public function __invoke(Request $request)
 {
     global $core;
     $this->module = $core->modules['pages'];
     return parent::__invoke($request);
 }
Exemplo n.º 21
0
 /**
  * Revokes the cache.
  */
 public static function revoke()
 {
     Request::from(Operation::encode('cache/icybee.views/clear'))->post();
 }