Jump to content

Valery

Members
  • Posts

    121
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Valery

  1. Hey, Here's a snippet that does the job for me. $file_source = 'http://www.openbsd.org/images/puffy54.gif'; $file_content = file_get_contents($file_source); $target_page_id = '9999'; // replace with a real id $target_page = $pages->get($target_page_id); $target_page->of(false); $file_target = $config->paths->files . $target_page_id . '/' . 'puffy54.gif'; // or do basename() on $file_source file_put_contents($file_target, $file_content); $file_field_name = 'attachment'; $target_page->$file_field_name->add($file_target); $target_page->save();
  2. Had the exact same issue with a stubborn Trash. Patched my 2.3.1 installation manually -- thanks Ryan!
  3. Thanks adrian. I am running 2.3.1 and the Ryan's fix worked like magic!
  4. Hi guys, Long story short: I played with ProcessWire and broke something (I guess I moved some old repeater pages in Trash (which one should not do). Now I cannot empty Trash: Error: Call to a member function hasRole() on a non-object (line 1275 of /.../wire/core/Page.php) I attach a screenshot if it might help. Thanks for your help. Any tips of how to fix my non-emptying Trash are appreciated!
  5. Valery

    MariaDB

    Thanks, diogo. I am planning to upgrade my OpenBSD box and give the 5.5 a run. If only shared web hosters would abopt it, too.
  6. Thanks, Soma! I'd just add that the following selects an option in the radio button list: $labelFieldName = fields->get("related")->labelFieldName; $inputfield->setAttribute('value', $page->$labelFieldName);
  7. Hi guys, I've been trying to play with $field->getInputfield() to get my PW field data displayed as part of a form. $category = $fields->get('related'); $field = $category->getInputfield($page); echo $field->render(); 'related' is a Page field configured to be displayed as Radios ("Input Field Type" = Radios). The question is, how do I access this Inputfield's values before rendering the output? I did var_dump on it and here is what it gave me: object(InputfieldPage)#272 (12) { ["inputfieldWidget":protected]=> object(InputfieldRadios)#284 (11) { ["options":protected]=> array(7) { [1277]=> int(1277) [1280]=> int(1280) [1281]=> int(1281) [1282]=> int(1282) [1283]=> int(1283) [1284]=> int(1284) [1394]=> int(1394) } ["optionAttributes":protected]=> array(0) { } I need to edit the options before rendering the Radios field but how would I go about doing it? Please help!
  8. Thanks, Ryan. I believe this can be linked to the post on page numbers.
  9. Thanks, Ryan. I like your solution better because it turned out that loading pages into DOM really slows things down.
  10. Hello guys, I decided to give the PagePaths module a try and installed it. But PW keeps saying Error: Exception: Operator '~=' is not supported for path or url unless you install the PagePaths module. (in /var/www/docs/wire/core/PageFinder.php line 625) each time I try something like "echo $pages->get("url~=/wallpapers/page4")->id;" Is there anything else I should look into? I am sensing that the PW core is not aware that I have the module installed.
  11. A well-formed question is half the answer Actually, the answer can be found here: http://stackoverflow.com/a/4349042 Which can be roughly implemented as: $url = 'http://host/gallery/page3'; if ($pages->get(parse_url($url, PHP_URL_PATH))->id == 0) { $doc = new DOMDocument(); @$doc->loadHTMLFile($i->url); $xpath = new DOMXPath($doc); $title = $xpath->query('//title')->item(0)->nodeValue . "\n"; } else { $title = $pages->get(parse_url($url, PHP_URL_PATH))->title; } Summary: if you cannot get a page by its path, then you will have to do it the hard way.
  12. Hello everyone, I use an external page ranking service which gives me back URLs of the most popular pages from my PW-powered web site. To display page titles instead of URLs to my visitors, I try to call $pages->get(...)->title to get a title for each page. Generally it works, but there is a problem: if a page uses a pagination-enabled template, I often end up with URLs like http://host/gallery/page10. And $pages->get("/gallery/page10") gives me a '0'. So, is there a common approach in ProcessWire to find a page by its URL if its template uses pagination? Thanks.
  13. Hello. I am designing a publisher's backend where a lot of functions are equal to what ProcessWire's admin backend offers. Ryan's answer about dumping page Inputfields into a form struck me. I wrote so much redundant code while the solution was so close. But indiscriminantly dumping Inputfields from a page into a form gives us a very rough solution. What if one needs to be able to select particular fields of interest and create Inputfields for them in a form? Here is a quickie I did for this task. I have repeaters in my project, so played with them. Ryan is right: repeaters are beasts of a different type. This is why I decided to use them to show a way to create HTML form controls which would automatically match the field type and get the field value. The code is loosely based on Ryan's code above. // make a form $form = $modules->get('InputfieldForm'); $form->method = 'post'; $form->action = './'; foreach ($pages->get(1213)->repeater as $v) { $rfs = $fields->get('repeater')->repeaterFields; // get an array of field names inside this repeater foreach ($rfs as $rf) { $field = $fields->get($rf); // here's a trick: here, the repeater is iterated by selecting its "child" pages. // They are visible under Admin->Repeaters in the admin backend. $pg = $pages->get("$v"); // weird: selector works only with the double quotes. $fld = $field->getInputfield($pg); $fld->set('value', $pg->$field); // you need to explicitly set the value $form->append($fld); } } $submit = $modules->get('InputfieldSubmit'); $submit->name = 'submit'; $form->add($submit); // process the form if it was submitted if ($input->post->submit) $form->processInput($input->post); // render the form output echo $form->render(); Of course, before $form->append() you can do setAttribute(), set('skipLabel', 2) to remove the label and other customizations. Thanks for reading and commenting.
  14. Hi people, I've been trying to tailor the HTML output of my InputfieldRadios, to no avail so far. Here's the code: $field = $modules->get("InputfieldRadios"); $field->label = 'Radio controls'; $field->attr('id+name', 'radios'); $field->addOption('1', 'Option 1'); $field->attr('value', '1'); $field->addOption('2', 'Option 2'); $form->append($field); $form->setMarkup(array( 'list' => "<div {attrs}>{out}</div>", 'item' => "<div {attrs}>{out}</div>" )); However, I still keep getting <ul> for the radio buttons: <ul class='InputfieldRadiosStacked'> <li><label><input checked='checked' type='radio' name='radios' id='radios_1' value='1' /> Option 1</label></li> <li><label><input type='radio' name='radios' id='radios_2' value='2' /> Option 2</label></li> </ul> Is there a way to fix it? I looked into how the admin backend is styled and radio buttons are wrapped in <ul> in there, though the list bullets are removed. But I'd like my radio buttons wrapped in <div>'s rather than <ul>'s. Thank you for any hints.
  15. Thanks, Soma. Here's what it looks like now: $field = $modules->get("InputfieldSelectMultiple"); $field->label = "Multiple select"; $field->attr('id+name', 'options'); $field->setAttribute('multiple', 'multiple'); $field->setAttribute('size', '8'); $field->addOption('121', '121-22'); $field->attr("value", "121-22"); $field->addOption('122', '122-23'); $form->append($field); And here's what it does: <select id="options" name="options[]" multiple="multiple" size="8"> <option selected='selected' value='121'>121-22</option> <option value='122'>122-23</option> </select>
  16. Hello everybody, I am playing with the InputfieldSelectMultiple module, and I was wondering how to set the "selected" attribute for an Option? I have the following code: $field = $modules->get("InputfieldSelectMultiple"); $field->label = "Multiple select"; $field->attr('id+name', 'options'); $field->setAttribute('multiple', 'multiple'); $field->setAttribute('size', '8'); $field->addOption('121', '121-22', array('selected' => 'selected')); Which gives me this: <option selected='selected' selected="selected" value='121'>121-22</option> While it technically makes an option selected, this also produces redundant HTML code which does not validate. So, what's the right way to use addOption() so that the output is more like <option selected value=...> ? Thanks.
  17. Good job! Thanks for the tip. Please note, people, that before implementing this you must check your PHP zlib configuration. Because the official PHP documentation states that To check, either run php -i | grep zlib.output_compression if you are on a console, or do the usual phpinfo() thing and search for zlib.output_compression. To note the obvious: if you are using PW 2.3.0, the default file names are: $config->prependTemplateFile = '_init.php'; and $config->appendTemplateFile = '_done.php'; With the almost untouched default site profile, I got 34 kbytes without uncompression vs 8 kbytes with compression (page /about/; traffic measured with Comodo Dragon (based on Chromium). Screenshots are attached). One last remark: the PHP docs recommend turning on zlib.output_compression. Which is understandable once you start taking PW caching into account.
  18. Thanks, Ryan! That was exactly what was needed--and now I know what the little gear sign next to a module name is for
  19. Thanks, Hani. PHP 5.5 dropped JSON support due to the developer's aesotheric license. But those of us who are not yet at the front line are fine
  20. Hello, I had troubles understanding how Repeaters work, so I posted a question about it and got useful answers. So, basically, to delete all Repeaters from a page, you do something like that: $page = $pages->get(0000); foreach($page->repeater as $r) { $r->delete(); } $page->save();
  21. Hello, everyone. I am building a web site for Cyrillic-reading audience. I wanted to convert Cyrillic user names into ASCII and it seems I found a problem. Capitalized Cyrillic letters are stripped out after Sanitizer::translate. E.g. "Иван" becomes "van". There's a workaround, however: $sanitizer->pageName(mb_strtolower($text), Sanitizer::translate); This problem also impacts page name translations to ASCII, so whenever I create a page from the Admin backend, I have to get back after saving, and correct the page name. Here I cannot use the above workaround because I can damage the PW core (which is the last thing one would like to do). I am posting this for any other developers working with Cyrillic, and maybe for Ryan to look at this issue Thanks!
  22. Hi mangopo, This might be a case of incorrect transfer. Here's what Ryan recommends: So, basically it comprises the following steps: 1. Clean up the new environment (database, target PW installation directory). 2. Tar the PW directory or, better, rsync it if you have SSH in your hosting package. 3. Dump the PW database and restore it on the new (target) environment. 4. update your ../site/config.php with the new database host, login and password. Please report if this helped you with your problem.
  23. A fan of NetBeans, I sometimes TextWrangler on my old PowerBook.
×
×
  • Create New...