Jump to content

hellomoto

Members
  • Posts

    372
  • Joined

Everything posted by hellomoto

  1. I have an importer function that goes like this so far function importCSV($filepath, $template, $parent_id = null, $grandparent_id = null) { $csv = array_map('str_getcsv', file($filepath)); array_walk($csv, function(&$a) use ($csv) { $a = array_combine($csv[0], $a); # set header keys }); array_shift($csv); # remove column header //echo '<pre>'; print_r($csv); echo '</pre>'; foreach($csv as $r) { $p = new Page(); $p->name = wire('sanitizer')->pageName($r['title']); $p->template = $template; if($parent_id !== 0||null) { $p->parent_id = $parent_id; } elseif($parent_id == 0||null) { //echo $r['parent'].' '; $parent = wire('sanitizer')->pageName($r['parent']); $parent = str_replace('---','-',$parent); //echo $parent.' ';//echo $grandparent_id.'gp '; $parent = wire('pages')->get('title=' . $r['parent'] . ', parent_id=' . $grandparent_id)->id; //echo $parent.'p '; $p->parent_id = $parent; unset($r['parent']); } $p->save(); var_dump($r); foreach($r as $k=>$v) { $fieldtype = wire('fields')->get('name='.$k)->type; echo $fieldtype.' '; if($fieldtype->name == 'FieldtypeImage') { $imgs = explode('|', $v); foreach($imgs as $i) { $p->$k = $i; } } elseif($fieldtype->name == 'FieldtypeMapMarker') { echo 'mapmarker'; $p->set($k->address, $v); } else $p->$k = $v; } $p->save(); echo '<br><br>'; } } It reads the field as being a MapMarker but does not input the address data?
  2. I added support for FieldtypeMapMarker (->location) if you want to incorporate into the module master, here
  3. I'm trying to alter some code I used to do something similar (fields for selected template) on another project (here) and so far just this simple direct snippet is not doing anything: public function init() { $this->pages->addHookAfter('render', $this, 'filterModels'); } public function filterModels($event) { $page = $event->arguments('page'); if($page->template != 'boat_vessel') return; $this->message("models filter"); } The module is active... Why no results?
  4. Actually it does, but you have to save the page to get the childpages field options. How can I auto-save the parentpage field on selection change and immediately subsequently auto-refresh the childpage field?
  5. I have a manufacturers page select field and a dependent models one with pages of template `model` which are allowed children of pages with template `manufacturer`. So I have this as the findPagesCode for the models page options field: return $page->manufacturer->children(); However this requires the page be saved in order to display options. This is not ideal. I have a singular autoload module with the following: public function init() { $this->pages->addHookAfter('render', $this, 'filterModels'); } public function filterModels($event) { $page = $event->arguments('page'); if($page->template != 'boat_vessel') return; $this->message("models filter"); } It's doing nothing. I was thinking I could work out something with this example but I would need the above test to be working first anyway... $this->pages->addHookAfter('changed', function(HookEvent $event) { $page = $event->object; $change = $event->arguments(0); if($page->template == 'boat_vessel' && $change == 'manufacturer') { // execute some code } }); But what? How do I refresh the models field? Is there a way to do this in the field settings? I would think in the custom PHP textarea that `return $page->manufacturer->children();` would work but it doesn't.
  6. Sometimes my file uploads get stuck on 100% and do not complete, even if I try with a zipped version. So then I try adding the file to the page files directory and inserting a new record in the field's table. Sometimes this works, sometimes not. When it doesn't, what to do? Is there a way to add the db record via API that'll register in the page? The existence of the record itself should present, I don't understand.
  7. Apparently it comes from line 6 in this file (vessels.csv) <?php namespace ProcessWire; $mmpid = wire('pages')->get('template.name=mamo_makes')->id; importCSV(__DIR__.'/manufacturers.csv', 'mamo_manufacturer', $mmpid); importCSV(__DIR__.'/models.csv', 'mamo_model', 0, $mmpid); importCSV(__DIR__.'/vessels.csv', 'boat_vessel', wire('pages')->get('template.name=boat_index')->id, 0); function importCSV($filepath, $template, $parent_id = null, $grandparent_id = null) { $csv = array_map('str_getcsv', file($filepath)); array_walk($csv, function(&$a) use ($csv) { $a = array_combine($csv[0], $a); }); array_shift($csv); # remove column header //echo '<pre>'; print_r($csv); echo '</pre>'; foreach($csv as $r) { $p = new Page(); $p->name = wire('sanitizer')->pageName($r['title']); $p->template = $template; if($parent_id !== 0||null) { $p->parent_id = $parent_id; } elseif($parent_id == 0||null) { //echo $r['parent'].' '; $parent = wire('sanitizer')->pageName($r['parent']); $parent = str_replace('---','-',$parent); //echo $parent.' ';//echo $grandparent_id.'gp '; $parent = wire('pages')->get('title=' . $r['parent'] . ', parent_id=' . $grandparent_id)->id; //echo $parent.'p '; $p->parent_id = $parent; unset($r['parent']); } $p->save(); foreach($r as $k=>$v) $p->$k = $v; // if MapMarker field set to ADDRESS subfield $p->save(); //echo '<br>'; } } That's odd because this isn't even supposed to be deleting anything, it's imports. How does this happen? This same code was working before, imported the boats just fine, I would just have to refresh the page once to clear that same error, but it would clear itself.
  8. I have a cleanup file running before a file that sets up all the fields and templates, that includes the following: foreach($fields->find('tags*=ccbo') as $f) $fields->delete($f); When I comment it out, the field is created, yet I still get this error halting the script procession: If I comment out the block of code creating it, the same error is displayed for the next field.
  9. mamo_length_ft is not a field. I don't see it anywhere in the database neither. Where could this possibly be stemming from?
  10. Never mind this works the mmpid was 0 had wrong template name. <?php $mmpid = wire('pages')->get('template.name=mamo_makemodel')->id; echo $mmpid.'<br><br>'; // Manufacturers: importCSV(__DIR__.'/manufacturers.csv', 'mamo_manufacturer', $mmpid); // Models: importCSV(__DIR__.'/models.csv', 'mamo_model', 0, $mmpid); function importCSV($filepath, $template, $parent_id = null, $grandparent_id = null) { $csv = array_map('str_getcsv', file($filepath)); array_walk($csv, function(&$a) use ($csv) { $a = array_combine($csv[0], $a); }); array_shift($csv); # remove column header //echo '<pre>'; print_r($csv); echo '</pre>'; foreach($csv as $r) { $p = new Page(); $p->name = wire('sanitizer')->pageName($r['title']); $p->template = $template; if($parent_id !== 0||null) { $p->parent_id = $parent_id; } elseif($parent_id == 0||null) { //$parent = wire('pages')->get('title=' . $r['parent']); //echo $parent.' ';// echo $r['parent'].' '; $parent = wire('sanitizer')->pageName($r['parent']); $parent = str_replace('---','-',$parent); echo $parent.' '; echo $grandparent_id.'gp '; $parent = wire('pages')->get('title=' . $r['parent'] . ', parent_id=' . $grandparent_id)->id; echo $parent.'p '; $p->parent_id = $parent; unset($r['parent']); } $p->save(); foreach($r as $k=>$v) $p->$k = $v; $p->save(); echo '<br>'; } }
  11. I have the following import script being included in the homepage template file: <?php $mmpid = wire('pages')->get('template.name=makes')->id; // Manufacturers: $file = __DIR__.'/manufacturers.csv'; importCSV($file, 'mamo_manufacturer', $mmpid); // Models: $file = __DIR__.'/models.csv'; importCSV($file, 'mamo_model', 0, $mmpid); function importCSV($filepath, $template, $parent_id = null, $grandparent_id = null) { $csv = array_map('str_getcsv', file($filepath)); array_walk($csv, function(&$a) use ($csv) { $a = array_combine($csv[0], $a); }); array_shift($csv); # remove column header //echo '<pre>'; print_r($csv); echo '</pre>'; foreach($csv as $r) { $p = new Page(); $p->name = wire('sanitizer')->pageName($r['title']); $p->template = $template; if($parent_id !== 0||null) { $p->parent_id = $parent_id; } elseif($parent_id == 0||null) { //$parent = wire('pages')->get('title=' . $r['parent']); //echo $parent.' ';// echo $r['parent'].' '; echo $grandparent_id.' '; $parent = wire('pages')->get('title=' . $r['parent'] . ', parent_id=' . $grandparent_id)->id; echo $parent.' '; $p->parent_id = $parent; unset($r['parent']); } $p->save(); foreach($r as $k=>$v) $p->$k = $v; $p->save(); echo '<br>'; } } Output = Why is it running the ELSE when the condition for the IF is met? (the first 9 lines) All 14 models (lines past 9) are created under the first manufacturer. I've been messing with it, been able to get them to display the page IDs proper at one point for the models but still there's the standing issue of all of them being created under the first manufacturer nonetheless and also the ELSE running despite not being a condition of ELSE. What's up please...
  12. I have a module that I am using to create an image field like so: $mf[] = [[ 'tags' => $tag, 'name' => $pre.'logo', 'type' => wire('modules')->get('FieldtypeImage'), ],[ 'label' => 'Logo', 'columnWidth' => 50, 'inputfieldClass' => 'InputfieldImage', ]]; Yet upon its creation, initially, when I try creating a page of a template including it, it says that the field must first be configured. Once I go and save the field as-is, everything's honkey dory. It's just an annoyance, with every image field. I figured it would be the required inputfieldClass field field, but as you can see, that's included up in there, and it's still not good to go off the bat.
  13. It's shorthand for creating new fields, templates, fieldgroups, and pages via the API. See bb for example usage.
  14. Line 663 = if(count($page->template->childTemplates) && !in_array($addPage->template->id, $page->template->childTemplates)) { The template has no child templates and is the sole child template of its parent template; why this notice?
  15. I replaced /wire/, /.htaccess and /index.php those of the with current development version and it does that.
  16. RewriteEngine on RewriteBase / RewriteRule ^index.php$ / [NC,R,L] RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ RewriteRule . %1/%2 [R=301,L] # mask primary domain subdir. location RewriteCond %{HTTP_HOST} ^(www\.)?audino\.us$ [NC] RewriteRule ^(.*)$ /audino\.us%{REQUEST_URI} [L,NC,QSA] The above seems effective overall, except that (www.)?example.com/example.com(.*) need hide that tricky subdirectory from the URI. Also I need to know how to either force or omit the www. prefix while also pointing to & hiding the subdirectory serving the site.
  17. Christophe: that line #11 you mention is commented out in [public_html/].htaccess. The www I hadn't yet decided whether to force or omit. How do I prevent / from rendering the URL as /audino.us/?
  18. [public_html]/audino.us/.htaccess RewriteBase /audino.us/
  19. Now I have RewriteEngine on RewriteBase / RewriteRule ^index.php$ / [NC,R,L] # remove double/more slashes in url RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ RewriteRule . %1/%2 [R=301,L] RewriteCond %{HTTP_HOST} ^(www\.)?audino\.us$ [NC] #RewriteBase /audino.us RewriteRule !^audino\.us/ /audino\.us%{REQUEST_URI} [L,NC] # above 2 lines same effect and in site/ready.php $config->urls->root = '/'; thus: ^(www.)?example.com => example.com/example.com/ ^(www.)?example.com/pw, ^(www.)?example.com/pw/ => example.com/pw/ How to remedy this? Also I am still unable to login; I've tried resetting the password via API in case I had it wrong.
  20. I have RewriteBase / in the PW htaccess, so / but: / => example.com /pw => example.com/example.com/pw/ /pw/ => example.com/pw/ www. => www.example.com/example.com/ (root links also = "", as opposed to www.example.com How can I fix this? root .htaccess = RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} ^(www.)?example\.com$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(www\.)?example\.com/?(.*)$ http://example.com/$1 [R] RewriteCond %{HTTP_HOST} ^(www.)?example\.com$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /example.com/$1 [L,QSA] oh and so much for hiding the domain I did just because you said but you didn't but that's a ok
  21. I have web hosting with the following .htaccess en root, to point it to a subdirectory "audino.us", wherein I have PW installed: RewriteEngine on RewriteCond %{HTTP_HOST} ^(www.)?something.com$ RewriteCond %{REQUEST_URI} !^/something.com/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /audino.us/$1 RewriteCond %{HTTP_HOST} ^(www.)?something.com$ RewriteRule ^(/)?$ something.com/index.php [L] RewriteCond %{HTTP_HOST} ^(www.)?something.com$ RewriteRule ^(/)?$ something.com [L] However when I go to audino.us/pw to access the admin, it becomes audino.us/audino.us/pw, and doesn't allow me to log in. How do I render the above to be recursive (?), i.e., to apply to all subordinate URLs? Is this to be done within the .htaccess in /audino.us, or in the root .htaccess above? Please help, I can't log in. Thanks much.
  22. Updated bulkup(): private function bulkup($form) { if($this->input->post->import) { $files = $this->input->post->bla_upload; if(!count($files)) { return "No files were found."; }else{ $list = ''; foreach($files as $f) { $list .= $f . PHP_EOL; } return count($files)."\n".$list; } } } Like this it returns: when I upload just 1 file... it counts 2... and there is (and was before) a directory for the process page's ID in site/assets/files, but it remains empty still. I'm blue, need a clue.
  23. I have a process module like so: public function execute() { $output = 'mad music archive/bulk uploadability management'; $form = $this->makeForm(); if($this->input->post->import) $output .= $this->bulkup($form); else $output .= $form->render(); return $output; } public function ___install() { $mkr = new ImportShorthand(); $p = [[ 'template' => 'admin', 'parent_id' => 2, 'name' => self::PGNAME, 'title' => '[Blaudio] Mgmt', ],[ 'process' => $this, ]]; $mkr->newPage($p); } public function ___uninstall() { $wp = wire('pages'); $pg = $wp->get('template.id=2, parent.id=2, name='.self::PGNAME); if($pg->id) $wp->delete($pg, true); } private function bulkup($form) { if($this->input->post->import) { $form->processInput($this->input->post); return; if(!$form->getErrors()) { $files = $form->get("bla_upload")->value; if(count($files)) { return count($files);/* $bulkload = $bulk_upload->first(); //$bulkload->rename("address-import.csv"); $bulkloadname = $bulkload->filename;*/ }else{ return "No files were found"; } //$this->session->redirect("../edit/?id=$list_id"); } } } private function makeForm() { So far, returning early in the bulkup() function, submitting the form with an acceptable file results in this error message: Upon reloading the page (afresh, without the submitted data; i.e., clicking its link in the nav) this error is displayed within the upload field: I'm assuming this is due to the fact that this is a process page. How do I ensure temporary storage? My goal ultimately is to insert a new page for each valid file. Thanks much in advance.
  24. The page is not deleteable, but I am logged in as superadmin.
×
×
  • Create New...