Jump to content

KarlvonKarton

Members
  • Posts

    118
  • Joined

  • Last visited

Everything posted by KarlvonKarton

  1. I suspected that the route I was crawling was not the correct one, so I ended up changing the course... with more succes ? field type <?php namespace ProcessWire; class FieldtypeTextZabun extends FieldtypeText implements ConfigurableModule { public static function getModuleInfo() { return array( 'title' => 'Zabun FieldtypeText', 'version' => 1, 'summary' => 'Zabun selector.', 'installs' => 'InputfieldTextZabun', 'icon' => 'home', ); } public function getInputfield(Page $page, Field $field) { $inputfield = $this->modules->get('InputfieldTextZabun'); /*$inputfield->set('zabundatabase', $this->get('zabundatabase')); $inputfield->set('zabunlocation', $this->get('zabunlocation')); $inputfield->set('zabunusername', $this->get('zabunusername')); $inputfield->set('zabunpass', $this->get('zabunpass'));*/ return $inputfield; } public static function getModuleConfigInputfields(array $data) { $inputfields = new InputfieldWrapper(); $f = wire('modules')->get('InputfieldText'); $f->attr('name', 'zabundatabase'); $f->label = __('Zabun database'); $f->icon = 'database'; $f->description = 'Zabun database'; $f->attr('value', isset($data['zabundatabase']) ? $data['zabundatabase'] : ''); $inputfields->add($f); $f = wire('modules')->get('InputfieldText'); $f->attr('name', 'zabunlocation'); $f->label = __('Zabun location'); $f->icon = 'server'; $f->description = 'Zabun location'; $f->attr('value', isset($data['zabunlocation']) ? $data['zabunlocation'] : ''); $inputfields->add($f); $f = wire('modules')->get('InputfieldText'); $f->attr('name', 'zabunusername'); $f->label = __('Zabun username'); $f->icon = 'user'; $f->description = 'Zabun username'; $f->attr('value', isset($data['zabunusername']) ? $data['zabunusername'] : ''); $inputfields->add($f); $f = wire('modules')->get('InputfieldText'); $f->attr('name', 'zabunpass'); $f->label = __('Zabun password'); $f->icon = 'key'; $f->description = 'Zabun password'; $f->attr('value', isset($data['zabunpass']) ? $data['zabunpass'] : ''); $inputfields->add($f); return $inputfields; } public function ___install() { // add dependencies copy( dirname(__FILE__).'/src/ZabunApi-master.php', $_SERVER['DOCUMENT_ROOT'].'/zabunapi.php' ); } public function ___uninstall() { // remove dependencies unlink( $_SERVER['DOCUMENT_ROOT'].'/zabunapi.php' ); } } input field: <?php namespace ProcessWire; class InputfieldTextZabun extends InputfieldText { public static function getModuleInfo() { return array( 'title' => 'Zabun InputfieldText', 'version' => 1, 'summary' => "Provides input for the Zabun Fieldtype", 'requires' => 'FieldtypeTextZabun', 'icon' => 'home', ); } public function __construct() { parent::__construct(); } public function renderReady(Inputfield $parent = null, $renderValueMode = false) { $url = 'https://unpkg.com/vue@3.2.22/dist/vue.global.prod.js'; $this->config->scripts->add($url); return parent::renderReady($parent, $renderValueMode); } public function ___render() { // $database = $this->zabundatabase; $out = '<div id="App">'; $out .= '<input '.$this->getAttributesString().' />'; $out .= '<div v-html="avar"></div>'; $out .= '</div>'; return $out; } } Thanks for reading my ramblings!
  2. The custom fieldtype / inputfield can not add a record to the inputfield table... But if I add a record manually to the inputfield table, then I can edit the value with the module. As long as I don't empty the inputfield via the module and save, because then the record is deleted by the module. I don't know what I'm doing wrong. Can someone help me? FieldtypeZabun.module : <?php namespace ProcessWire; class FieldtypeZabun extends Fieldtype implements ConfigurableModule { public static function getModuleInfo() { return array( 'title' => 'Zabun Fieldtype', 'version' => 1, 'summary' => 'Zabun selector.', 'installs' => 'InputfieldZabun', 'icon' => 'home', ); } public function __construct() { parent::__construct(); } public function sanitizeValue(Page $page, Field $field, $value) { return $value; } public function ___wakeupValue(Page $page, Field $field, $value){ return $value; } public function ___sleepValue(Page $page, Field $field, $value) { return $value; } public function getInputfield(Page $page, Field $field) { $inputfield = $this->modules->get('InputfieldZabun'); $inputfield->set('zabundatabase', $this->get('zabundatabase')); $inputfield->set('zabunlocation', $this->get('zabunlocation')); $inputfield->set('zabunusername', $this->get('zabunusername')); $inputfield->set('zabunpass', $this->get('zabunpass')); return $inputfield; } public function getCompatibleFieldtypes(Field $field){ return null; } public function getDatabaseSchema(Field $field) { $schema = parent::getDatabaseSchema($field); $schema['data'] = "TEXT NOT NULL DEFAULT ''"; $schema['keys']['data'] = 'FULLTEXT KEY `data` (`data`)'; return $schema; } public static function getModuleConfigInputfields(array $data) { $inputfields = new InputfieldWrapper(); $f = wire('modules')->get('InputfieldText'); $f->attr('name', 'zabundatabase'); $f->label = __('Zabun database'); $f->icon = 'database'; $f->description = 'Zabun database'; $f->attr('value', isset($data['zabundatabase']) ? $data['zabundatabase'] : ''); $inputfields->add($f); $f = wire('modules')->get('InputfieldText'); $f->attr('name', 'zabunlocation'); $f->label = __('Zabun location'); $f->icon = 'server'; $f->description = 'Zabun location'; $f->attr('value', isset($data['zabunlocation']) ? $data['zabunlocation'] : ''); $inputfields->add($f); $f = wire('modules')->get('InputfieldText'); $f->attr('name', 'zabunusername'); $f->label = __('Zabun username'); $f->icon = 'user'; $f->description = 'Zabun username'; $f->attr('value', isset($data['zabunusername']) ? $data['zabunusername'] : ''); $inputfields->add($f); $f = wire('modules')->get('InputfieldText'); $f->attr('name', 'zabunpass'); $f->label = __('Zabun password'); $f->icon = 'key'; $f->description = 'Zabun password'; $f->attr('value', isset($data['zabunpass']) ? $data['zabunpass'] : ''); $inputfields->add($f); return $inputfields; } } InputfieldZabun.module : <?php namespace ProcessWire; class InputfieldZabun extends Inputfield { public static function getModuleInfo() { return array( 'title' => 'Zabun Inputfield', 'version' => 1, 'summary' => "Provides input for the Zabun Fieldtype", 'requires' => 'FieldtypeZabun', 'icon' => 'home', ); } public function __construct() { //require_once(dirname(__FILE__) . '/ZabunClass.php'); $this->zabundatabase = $this->get('zabundatabase'); $this->zabunlocation = $this->get('zabunlocation'); $this->zabunusername = $this->get('zabunusername'); $this->zabunpass = $this->get('zabunpass'); parent::__construct(); } public function renderReady(Inputfield $parent = null, $renderValueMode = false) { $url = 'https://unpkg.com/vue@3.2.22/dist/vue.global.prod.js'; $this->config->scripts->add($url); return parent::renderReady($parent, $renderValueMode); } public function ___render() { $this->setAttribute('type', 'text'); $this->setAttribute('id', 'zabunselector'); $this->setAttribute('name', 'zabunselector'); $out = ''; $out .= '<div id="App"><input '.$this->getAttributesString().' /></div>'; return $out; } public function ___processInput(WireInputData $input) { parent::___processInput($input); $this->value = $input['zabunselector']; return $this; } }
  3. For a customer I needed a bunch of pictures to make a mosaic in Photoshop (cropped as a square) ? 20 lines of ProcessWire "et voila": a folder full of first pictures of every page from a certain template. <?php namespace ProcessWire; // boot api include('index.php'); // find estates from web database $estates = $pages->find("template=archief-pand"); // if estates count not zero if(count($estates)){ // loop over estates ($e is single estate) foreach($estates as $e){ // if images not null if(count($e->images)){ // get first image of estate gallery $firstPic = $e->images->first(); // resize and crop image to square 800x800px $firstPic = $firstPic->size(800,800); // if picture not null then copy picture to folder propics if(!empty($firstPic)) copy($_SERVER['DOCUMENT_ROOT'].$firstPic->url, $_SERVER['DOCUMENT_ROOT'].'/propics/'.$firstPic); } } }
  4. Is there a reason why multiLine and newlineReplacement are not in the API doc? (but still work)
  5. I have a problem with the redirects: I have one redirect: /site/be/en/ ->/projects/belgium/ But when I add another one like under, then I get error "The Redirect From URL already exists as a page path. Redirect not added. " /site/be/nl/ -> /nl/projects/belgium/ Why is this?
  6. I don't know if this is known by you guys, but when I click on "I consent" in the notice panel and then go to manage with the js-pwcmb-notice-toggle, none of the checkboxes are checked. After a refresh at least one of the checkboxes is correctly checked in the manage panel. Curiously if not clicking on "I consent" in the notice panel, but going passing by preferences instead, then everything works as expected.
  7. I guess you are commenting on sortNames? In the development it is easier for me to use a multidimensional array. It will eventually change. PS: But if it wasn't for the array, then I would never have noticed the behavior of _init.php and $LANG = ...
  8. I have done a var_dump on the variable $LANG (user logged in or not logged in). When the user is NOT logged in, then the variable is a string: string(2) "FR" When the user is logged in, then the variable is an object: object(ProcessWire\LanguagesPageFieldValue)#331 (2) { ["default"]=> string(2) "FR" ["fr"]=> string(2) "FR" } Is this a bug or not? EDIT: $LANG is only an object on the home page and when logged in...
  9. Some more info: Apparently the strange behavior only happens when a user is logged in...
  10. Is this a bug in Processwire or some PHP behavior? In _init.php there are two variables ($LANG and $sortNames): $LANG = $user->language->title; // in uppercase NL or FR $sortNames = array( 'NL' => array( 'apartment'=>'Appartement/Studio', 'house'=>'Huis/Villa', 'terrain'=>'Grond', 'parking'=>'Garage/Parkeerplaats', 'other'=>'Andere', 'commerce'=>'Commercieel' ), 'FR' => array( 'apartment'=>'Appartement/Studio', 'house'=>'Maison/Villa', 'terrain'=>'Terrain', 'parking'=>'Garage/Place', 'other'=>'Autre', 'commerce'=>'Commerce' ) ); If I use the variables in several templates, the the $LANG variable stays uppercase: echo $LANG; // gives the desired NL or FR foreach($sortNames[$LANG] as $k => $v){ echo $k.' '.$v.'<br>'; // gives the desired output from $sortNames } But if I do the same on the home template, then the $sortNames gives no output: echo $LANG; // gives the desired NL or FR foreach($sortNames[$LANG] as $k => $v){ echo $k.' '.$v.'<br>'; // stays empty !!! } The solution is simple but highly unusual, but in _init.php I done the following to correct the strange behavior: $LANG = strtoupper($user->language->title); Anyone has a clue why this is happening on home?
  11. The issue has been fixed! FYI https://github.com/processwire/processwire-issues/issues/1031
  12. I did not report my own post, but the one of someone with the same issue from 2016. My only goal is to get this resolved, but I don't use Github. All issues got resolved via the forum until now. I don't know why this issue is not.
  13. And what is this forum for then?
  14. Why is this issue not getting resolved?
  15. I even tried to delete 1 page (which has a repeater) with the API and add a new page (which has a repeater) in 1 run... It doesn't work...
  16. What is the use of an API if you can not delete and then add in one run? That is what I ask myself...
  17. I have the same issue. When I delete all pages (that have a repeater) from a parent and then add new pages (with repeater) to the same parent, then only one page is added and I get the same error: "Can't save page 0: /xxxxxxxx-xx-x/: It has no parent assigned" In the repeater_field in the DB there is no data, count=0 and a parent_id=0... Is there any chance this gets resolved anytime soon? (I guess not since this a thread of 2016 ? ) PS: If I delete the pages in a seperate call and add new pages in a second call, then the issue doesn't happen...
  18. I did the same mistake as someone here above... I did not echo the render() nor the getScript() ... (my form is in plain HTML and not in a var called $out, therefrom...) It's working now. ;-)
  19. I use the module regularly on sites (with Pw form API), but for the first time I needed to implement the module in a plain HTML form, but without any luck. render() will not render anything and the getScript() does not add the script at the bottom of my form. Does plain HTML still work?
  20. I see the E_WARNING because of the PHP set_error_handler I use. Which I log in a mysql table. All the pictures are JPG, but maybe the "problem" is triggered by different camera models, I don't know. I've asked the provider of the API, but they can not figure it out (yet). I'm still waiting for their answer. PS: I wouldn't mind so much if it were only an E_NOTICE...
  21. Never mind... In the ready.php of course... Sorry for being too quick and not testing first ;-)
  22. I have been testing a bit more and I narrowed down the problem to just the size(600,0) part. So when I take an image and make a thumbnail of it with size() , then I get an E_WARNING. (I don't even have to save the thumbnail to another field) But I still have no clue why this happens.
  23. Hello, I'm filling an image field from an 3th party API with the Processwire API. All goes well: 1. images are correctly uploaded in images field 2. the first image is correctly converted to a thumbnail and added to another field (thumbnails) 3. the script does not break But: i get a warning like (example) on almost every picture (twice, what is more strange): exif_read_data(17-1.600x0.jpg): File not supported What am I doing wrong? My code: $picture = $this->getImageAPI($pic['mediumUrl']['href'],$pic['rentalUnit']['objectID'].'-'.$pic['order']); if($picture != ''){ $pictel++; $p->oe_images->add('./'.$picture); $lastPic = $p->oe_images->last(); unlink('./'.$picture); $p->save(); } if($pictel == 1){ $thumbnail = $lastPic->size(600,0); $p->oe_thumbnails->add($thumbnail); $p->save(); }
×
×
  • Create New...