Jump to content

hollyvalero

Members
  • Posts

    118
  • Joined

  • Last visited

Posts posted by hollyvalero

  1. 17 hours ago, adrian said:

    Yep, there must be more - just backspace until the ; is removed on each line and type it again - that will clear everything up.

    -- Thanks again for your help!  I was able to get it working and get all the data imported after a little tinkering. Also, that server lag? It's a perpetual slow spot outside of chicago that I seem to run into using traceroute, so I don't think it's Batch Child Editor...

  2. 11 minutes ago, adrian said:

    Damned if there wasn't ... I removed it and now I'm getting 

    Parse Error: syntax error, unexpected '$assessment' (T_VARIABLE)

    2 lines down, so maybe there are some other invisibles.  I'll try scanning it with fresh eyes tomorrow...  Batch child editor... the data is fairly complex with dropdown menus, etc. and there are about 50 fields in it...  I think it is overall server lag and I'm going to ping the host about that since even the export script has about a 13 second lag before it downloads.  It's on a shared server so I can't really up the limits.

     

     

    11 minutes ago, adrian said:

     

     

    @hollyvalero - you have a strange hidden character at the end of this line: $parent = wire('pages')->get("/assessments/"); that is causing the problem - just remove that and it will be fine.

    I would like to know what BCE was timing out for you and your own script isn't. Usually the easiest option is to up execution and php memory and these scripts will run until completed without any problems.*

    * yes I should probably build in some chunking to prevent the need to do this for large imports/exports, but I haven't gotten around to it yet ?

     

     

  3. On 12/30/2010 at 9:26 AM, ryan said:

     Meanwhile, decades later... I have a big database import/export of around 50 fields.  My batch child editor keeps stalling on import or export of the 350ish records, so I tried to write a simple csv export script and was successful. Now, overly confident I tried writing an import script with all my fields minus the top line and index.php reference since it's in a template.

    Getting "Parse Error: syntax error, unexpected 'while' (T_WHILE) "

    But I can't see why. the brackets {} are matched... data is defined... don't see any obvious missing ; ...


     

    <?php

    $fp = fopen("./assessmentsimport.csv", "r");
    $template = wire('templates')->get("upa");
    $parent = wire('pages')->get("/assessments/");

    while(($data = fgetcsv($fp)) !== FALSE) {
    // create the page and set template and parent
    $assessment = new Page();
    $assessment->template = $template;
    $assessment->parent = $parent;

    // set the assessment fields from the CSV
    list($title, $upa_startdate, $upa_homevisitorid, $upa_pyramid, $upa_evidence, $upa_evidence_ot, $upa_organization, $upa_organization_ot, $upa_region, $upa_age, $upa_caregiverd, $upa_familycomp, $upa_substanceabuse, $upa_numchildren, $upa_primarychildage, $upa_referral, $upa_casestatus, $upa_enrollment, $upa_leaving, $upa_1pre, $upa_1post, $upa_2pre, $upa_2post, $upa_3pre, $upa_3post, $upa_4pre, $upa_4post, $upa_5pre, $upa_5post, $upa_6pre, $upa_6post, $upa_7pre, $upa_7post, $upa_8pre, $upa_8post, $upa_9pre, $upa_9post, $upa_10pre, $upa_10post, $upa_phq2, $upa_phqtypeofscreen, $upa_phqdatecompleted, $upa_phq2score, $upa_epds, $upa_epdstypeofscreen, $upa_epdsdatecompleted, $upa_epdsscore, $upa_pcd_receivingservices, $upa_pcdreferred, $upa_pcdwherereferred, $upa_updated) = $data;

    $assessment->title = $title;
    (and all the other fields) 


    // set the URL name using the assessment title
    $assessment->name = $title;

    // save the UPA
    $assessment->save();

    echo "Created assessment: {$assessment->url}\n";
    }




     

     

    On 12/30/2010 at 9:26 AM, ryan said:

     

    
    #!/usr/local/bin/php -q
    <?php
    
    // include ProcessWire's index file for API access
    // (this isn't necessary if you are doing this from a template file)
    include("./index.php"); 
    
    $fp = fopen("./skyscrapers.csv", "r");
    $template = wire('templates')->get("skyscraper");
    $parent = wire('pages')->get("/skyscrapers/");
    
    while(($data = fgetcsv($fp)) !== FALSE) {
    
    // create the page and set template and parent
    $skyscraper = new Page();
    $skyscraper->template = $template; 
    $skyscraper->parent = $parent; 
    
    // set the skyscraper fields from the CSV	
    list($building, $city, $height) = $data; 
    $skyscraper->title = $building; 
    $skyscraper->city = $city; 
    $skyscraper->height = $height; 
    
    // set the URL name, i.e. Sears Tower becomes "sears-tower" automatically
    $skyscraper->name = $building; 
    
    // save the skyscraper
    $skyscraper->save();
    
    echo "Created skyscraper: {$skyscraper->url}\n";
    }
     

     

  4. On 7/19/2018 at 4:43 PM, adrian said:
    
    foreach($subjects as $subject) {
        echo "<option value='".$sanitizer->alpha($subject->title, Sanitizer::translate)."'>{$subject->title}</option>";
    }

     

    Check out the inspection of the select options and you can see it's working as expected.

    image.png.46f5e25412fa2f47b2ce968b23f958a9.png

     

    So this code:

     

    $subjects = $pages->find("template=subject, limit=100, sort=title");
    foreach($subjects as $subject) {
        echo "<option value='".$sanitizer->alpha($subject->title, Sanitizer::translate)."'>{$subject->title}</option>";
    }

    Does product the single name dropdown, lower case without the & or spaces. 

    <option value='artandculture'>Art and Culture</option>
    <option value='mapsampgeo'>Maps &amp; Geo</option>
    <option value='Science'>
    Science</option> 


    I thought it was working, but realized I need to include a leading PERIOD in the option value before the name in order for mixitup to work... :


    <option value='.mapsampgeo'>Maps &amp; Geo</option>
    <option value='.artandculture'>
    Art and Culture</option>


    Is there a way using this sanitize string to add the "." back in or do I need to go back to 2-3 steps to launder stuff out?

     


     

     

     
     


     

     

     

     

     

  5. Just now, adrian said:

    They will be removed as you'll see in my example - isn't that what you want?

    It is... just don't know how to code that... I haven't tried this... but something like this?

    foreach($subjects as $subject) {

          $submix = $subject->title;
          $submix =  ($sanitizer->alpha('$submix', Sanitizer::translate) ) ;     
         echo "<option value='.$submix'>{$subject->title}</option>" ;
         }

     

     

     

     

  6. The sample page name is my working "worst case scenario" but there's no way of guessing what page titles will be. I've got multiple versions of this foreach loop...

    $submix = $subject->title; (maps & geolocation, math, STEM, and a zillion others)

    $resmix = $resourcetype->title; (videos, games, magazines, etc.)

    $audmix = $audience->title;  (kids, taxpayers, college bound, whatever)

     

    Assuming I might have to convert each title variable back to HTML, then remove "&amp;" or all special characters...
    Then spaces... and dashes

    I think caps and lowercase will work fine, however.

  7. Hi!  I've got 3 page reference fields (multipage) used to tag database entries by audience, subject area, and resource type. These can be created on the fly, so you can ideally curate a special collection and have processwire generate pages, sorted displays, etc. 

    Using Mixitup to create a nice sift and sort with multiple drop down menus. Mixitup doesn't like spaces, dashes, special characters - just letters. Rather than tell everyone, "don't use special characters!" I'd like to assume the worst and strip them out behind the scenes.  The option value and card class are both invisible, so as long as it's just letters it should work whether it's upper or lower case. 

     

    For the drop down menu I need to generate something like this:

    <option value='.ResumesJobs'>Résumés & Jobs</option>

     

    And then the actual card display below will contain a matching ID:

    <div class="mix  ResumesJobs">
    ---etc.
    </div>

     

    I've got the basics working... I can remove extra spaces. I can get rid of special characters. But I keep getting dashes and amp; in the displays.  Tried the sanitizer->pageName which didn't get rid of the amp. Sample of my sad code below... gather all pages listed under subjects... create a variable $submix for the title... then try to strip out spaces and characters:

     foreach($subjects as $subject) {

         $submix = $subject->title;
                 $submix = str_replace(' ', '', $submix);
                 preg_replace('/[^A-Za-z0-9\-]/', '', $submix);

         echo "<option value='.$submix'>{$subject->title}</option>" ;
         }
     

    Is there a better single process? Sanitizer seems like overkill since this in internal stuff, not user input. Tried to html encode &amp; back to & and then strip spaces, characters, etc. but bogging down in errors and unable to get rid of dashes.

    Would appreciate any insights.

     

     

     

     

     

     

     

     

     

     

  8. Hi, I'm coding a pile of research that ends up being tagged for a variety of issue areas: early childhood, human rights, justice, etc. Using a multiple page array field to make it easy to select an unlimited number of issues.

    In most cases I want to spit out that whole list when the research blocks come up with titles, links, images, etc. so people can click any issue area listed... like this...

    foreach($feature->issue as $item) {
     echo "<li class='iss uk-text-tiny bold caps'><a href='$item->url'>$item->title</a></li>";
     }
                                  

    But for the home page, I'd like to restrict the listing of issues to just the first one in the list, as that will be the primary issue area... rather than create a separate field.  The total count doesn't matter because I want to use just the first and ignore the rest...

     

    foreach($feature->issue as $item) {

    [select the first issue in the list of supplied issues and then spit that one out linked]

     echo "<p class='iss uk-text-tiny bold caps'><a href='$item->url'>$item->title</a></p>";
     }

    I'm getting better and bringing back everything but don't know if I should try to  put in a counter? Establish a limit? ... appreciate any help. 

     

     

     

     

     

     

     

  9. I like the Reno wrapper for the admin.  After looking at UIKit, then switching back to Reno, the back end is all Reno but the basic back end login page /processwire or /whateveryoucallit is displaying the original Default instead of the Reno login.  I realize this is a first world problem, but I can't seem to reinstate the Reno login.  Tried installing/uninstalling...  It's not the same page code and it's not the same style sheets... I can't uninstall the default ...what am I doing wrong?

    defaultlogin.png

  10. 7 hours ago, LostKobrakai said:

    Simply try to develop in an environment, where your site is accessed without subfolders in your url (or with the correct one if it'll later live under a subfolder). The domain itself does not matter that much because ProcessWire does not add it anywhere without you actively requesting it. That's why I suggested a simple subdomain of some domain you already own.

    Yeah, I think you're right. Just need to mimic the final destination... domain or subdomain for those that will be at the root.  Or, identical folder name for those that will be in a subdirectory.  

  11. 8 hours ago, LostKobrakai said:

    Does your hoster allow domains to point to that subfolder directly (without having it bought)?

    If so, enable that and use your local hosts file on your computer to have newdomain.com point to your hosters IP. This way you can develop with the new domain even without the public dns present and without your subfolder in urls.

    Otherwise try to point a subdomain of your active domain to that folder because changes of (sub)domain -> domain are far easier to pull of than subfolder -> no subfolder. The biggest (if not only) issue here being rich content editor entries. Most other things in processwire are relative anyways.

    Additionally if your hoster cannot map domains directly to your subfolder you'd need some additional .htaccess in your root folder to forward requests of your new domain to your subfolder.

    Yeah, trying to avoid further obfuscating DNS stuff, since that's the kind of thing that inevitably falls through the cracks later... no one remembers... the site grows big...  It's not a huge site and grepping out all the paths will not take more than maybe an hour or two... I think.  I'd rather do it now, before it gets bigger...  Just wondered if there was a way to establish the root path within processwire.  

    This is also helpful for developing a new site at an existing server... you'd want to build in a separate directory and move it up one while the current site is live and uncompromised.  It's an administrative detail that always pops up in redesign.  It would be the kind of thing that -- if it was part of Export Site Profile? Well, that would take care of it... if you could say "reset root path to..." with a domain name or domain.com/directory/path ...

     

     

     

     

  12. I have a website on a shared server that I use to store a few sites. My active domain is at the top.  The new website domain hasn't been activated yet, but the path would be something like:  myactivedomain.com/newdomain.com/ and once the DNS is flipped, just newdomain.com/

    As I am building and adding a load of PDFs, all the links default to /newdomain.com/site/assets/files/etc...

    This isn't migration, but a DNS activation.  Once that is updated, I'm still going to have a bunch of /newdomain.com/ links in there to pages, pdfs, images, etc. 

    Before I resign myself to grepping out page-by-page all the "/newdomain.com/" references I thought I would see if there's a way to update these automatically in processwire but I'm seeing stuff on migration... stuff in the rich editors about correcting links, but I don't see anything that covers this.  Is there a way to do this automatically? Via module? I didn't see anything in the config file... but would be grateful to anyone who can shed some light... 

     

  13. On 2/15/2013 at 9:01 AM, ryan said:

    Just wanted to reiterate what Wanze said about this:

    
    <input type='text' name='first_name' value='{$input->post->first_name}'>

    This is a major security hole. For example, try submitting this in the first_name field:

    
    '><script>alert('Gotcha!');</script>

    ...and if you can do that, you can do some pretty bad stuff.

    Definitely entity encode user submitted input that gets output again. Wanze's example:

    
    $v = $sanitizer->entities($input->post->first_name);
    echo "<input type='text' name='first_name' value='$v'>";

    If you are running an older version of PW that doesn't have the $sanitizer->entities() method (a fairly recent addition) then do this:

    
    $v = htmlentities($input->post->first_name, ENT_QUOTES, 'UTF-8'); 

     

    I'm don't know how to implement this. Does every input field in the form need to be replace with a $variable . So the username field:

                        <label class='label' for='username'>Username</label>
                         <p class='control'>
                         <span class='help is-info'>Please ensure your username contains <b>no spaces</b>. </span>
                         <input type='text' class='input' name='username' value='{$v}'>
                         </p>
     

    Does the entities string go before or after the form entry above?  Do I batch all the sanitizer entries first?                   
    
          $v = $sanitizer->entities($input->post->first_name);
    
    
    Further down I am creating a user. Does this:
    
          $u->name = $sanitizer->username($input->post->username);
    
    Need to be changed to:
    
          $u->name = $sanitizer->username($v);
    
    If I can figure out the order for one field, I can apply it to all of them.
     

     

     

     

  14. 13 minutes ago, pwFoo said:

    @hollyvalero FrontendUser should be stable with older PW modules. I think some users here use it with prod websites too. It should work with PW 3, but there seems to be a problem with a password inputfield change ("Not yet validInvalidToo shortToo commonWeakOkGoodExcellent"). Additional css / js is needed to fix it.

     After seaching the blog I think this update causes the issue with the
    https://processwire.com/blog/posts/upgrades-optimizations-pw-3.0.22/#major-enhancements-to-our-password-field

    If I'm right the module should work fine / stable with PW <3.0.22 / <2.8.22. Newer version needs a workaround like @jmartsch mentioned earlier.

     

    I'm running the latest version of PW, but if the only problem is the PW nag?  I think I'll export the site profile, load it to a second spot and try front end user... with the added js/css for the field validation and see if it works.  If it does, then we're all set.  I also looked at the subscribers module ... that too seemed to be in alpha :-D ...  I'll try Front End User first.

×
×
  • Create New...