Jump to content

ryan

Administrators
  • Posts

    17,242
  • Joined

  • Days Won

    1,704

Everything posted by ryan

  1. I think I might know what the deal is. Try changing this line: $gigNameUrl = $wire->sanitizer->pageName($gigName); To this: $gigNameUrl = $wire->sanitizer->pageName($gigName, true); The second param "true", tells it to beautify (remove doubled chars and stuff). I forgot that the Page class uses that beautify option, so adding the "true" will ensure it's consistent in how it generates the page name. I bet this will fix the problem.
  2. Actually this is a duplicate entry error. I've setup MySQL to maintain a unique index between the page name and the parent_id, so that it's impossible to have two pages with the same name under the same parent. So the error you got here is from MySQL telling you that you are attempting to insert a page with the same name as one that's already there. Can you check if a page named "project-decay-nor-w-viisikko-fleshpress-1751059" is already there?
  3. Using name may be better just because it can only consist of these ascii characters: -_.a-z0-9. Meaning it's easy to validate, and easy to use as a urlSegment or GET variable. If all of your artists are in one dir, then you can also change your selector to: $support = $wire->pages->get("/artists/$name/"); There may not necessarily be any advantage to doing that over what you were doing, but it's just an alternate approach. Nothing wrong with coding while ill, just drink Dayquil rather than Nyquil (I speak from experience). (if they have that cold medicine in Finland?). Or better yet, coffee, or both.
  4. For something like this, I usually prefer to use the name field over the title field just because there's no worry about escaping quotes, whitespace, etc. But if your $supporter is never going to have double quotes in it, then you are probably fine to use title. Speed wise, I don't think you are paying any penalty by using the title--it should have a full index in the DB, which will keep it just as fast as name. However, I do think you could improve this by only doing one call to $pages->find(). In addition, yo should probably use $pages->get() rather than $pages->find() since your $supporter_pages[] = $support seems to assume that $support is a Page rather than a PageArray. Here is what I would change it to: <?php $support = $wire->pages->get('template=artist, title="' . $supporter . '"'); if($support->id) { $supporter_pages[] = $support; } else { $support = new Page(); ... } If you want to use the name field instead of the title field (though it may not be necessary), you could do this: <?php $name = $wire->sanitizer->pageName($supporter); $support = $wire->pages->get("template=artist, name=$name"); ...
  5. If you want, feel free to email me the script and I can track it down more easily being able to see it all.
  6. Is there a $gig->save(); somewhere? (to make sure the change was saved)
  7. The syntax in your second example is correct. When you say it didn't work, can you describe further? Was there an error message?
  8. To get it working temporarily, you can set the value of $rootURL in /index.php manually to the correct value: "/racconti-erotici/". But I can see that the problem is that rootPath and DOCUMENT_ROOT are not consistent with each other. They should be referring to the same path, and instead they are referring to different paths. There must be some aliasing going in with the paths at the server side. We've seen this happen in another case, so I think it's something that ProcessWire needs to account for rather than an actual problem at the server. Now to figure out a solution...
  9. I just checked and see that I've got a couple of PW2 sites running in subdirs with "-" in them, so I don't think that is it. I'm wondering if you might be running into the same issue as this? http://processwire.com/talk/index.php/topic,46.0.html Though if that were the case, you'd get the same errors whether at a subdir or root... have you tried installation to root in this hosting environment? If you haven't no need to try, but if you can try creating a test.php file with this in it (from that other thread), and posting theresult, I think it may help to reveal what the problem is: <?php $rootPath = dirname(__FILE__); echo "RootPath:".$rootPath."</br>"; if(DIRECTORY_SEPARATOR != '/') $rootPath = str_replace(DIRECTORY_SEPARATOR, '/', $rootPath); echo "NewRootPath:".$rootPath."</br>"; echo "HTTP_HOST:".$_SERVER['HTTP_HOST']."<br/>"; echo "DOCUMENT_ROOT:".$_SERVER['DOCUMENT_ROOT']."<br/>"; $rootURL = isset($_SERVER['HTTP_HOST']) ? substr($rootPath, strlen(rtrim($_SERVER['DOCUMENT_ROOT'], '/'))) . '/' : '/'; echo "RootURL:".$rootURL; ?>
  10. That's odd -- does it work in a subdir without the "-" in it? I can't think of any reason why that would be the case, but just wanted to check. Also, what is the context of the hosting environment?
  11. PeterB, Looks great! If you want, you can also delete this part at the top of the class, since those don't appear to be variables that you are using: protected $form; protected $field; protected $id; If you want to make it traverse all levels, making it recursive is easier than you might think. Here's a site map example, which would probably be the same approach you'd want (at least from the recursion aspect): http://processwire.com/api/include/ Also, I wanted to inquire about the context of your individual use. Since it exports data for a Flash site, it seems like you would need to run this Process every time you made an update that you wanted reflected in the flash site? If you wanted it to be dynamic, you could take the contents of your executeExport function and put it into a template and have it echo to the screen (rather than writing to a file). Everything you've written still applies in this case. You would create a new page that uses that template, and name it website.xml. Also, you may want to turn off the trailing URL slash in your template settings, so that it doesn't convert it to yoursite.com/website.xml/". Start your template with a header function like this, so that the client reads it as XML: <?php header("Content-Type: text/xml"); // followed by the contents of your executeExport function This is just an idea on how to expand the utility of the code you've created, but it may or may not be applicable in your case.
  12. There's a way to do everything. But I'm not sure you want to attempt this in TinyMCE. It may be possible, but I wouldn't take that route unless this is a one time need. Instead, I would just look at it from a markup perspective and figure out what markup it will take to produce that layout. Here is the existing markup pulled from the page you linked to: <div style="float: left; width: 354px; height: 177px;"> <img src="images/10%20Red%20eared%20slider%20copyright%202005%20Pierre%20Fidenci%20-thumb-.jpeg" alt="Red Ear Slider" style="float: right;" height="127" width="192"> <p style="float: left;"><em> Red-Eared Slider <br> (Trachemys scripta elegans).<br> Side view of the <br> head of a Red-eared<br> slider, clearly showing <br> the markings that give<br> the turtle its name.<br> © Pierre Fidenci 2005.</em> </p> </div> <div style="float: right; height: 177px;"> <img src="images/11%20red%20eared%20slider%20copyright%202008%20lisa%20powers.jpeg" alt="Red Ear Slider" style="float: left;" height="127" width="192"> <p style="float: right;"><em> Red-Eared Slider <br> (Trachemys scripta elegans).<br> Juvenile individual, this <br> cute little baby will <br> eventually grow to be the<br> size of a dinner plate.<br> © Lisa Powers 2008.<br></em> </p> </div> To reproduce this in your template, we'll use the same markup and we'll add two image fields to your template called img1 and img2 (though you could also use a multi-image field if you preferred). You will place your image captions in the image description field. You may also want to set your image description field to have multiple rows to better support your captions. <?php $img1 = $page->img1->size(192, 127); $img2 = $page->img2->size(192, 127); ?> <div style="float: left; width: 354px; height: 177px;"> <img src="<?=$img1->url?>" alt="<?=$img1->description?>" style="float: right;"> <p style="float: left;"><em><?=$img1->description?></em></p> </div> <div style="float: right; height: 177px;"> <img src="<?=$img2->url?>" alt="<?=$img2->description?>" style="float: left;"> <p style="float: right;"><em><?=$img2->description?></em></p> </div> Those inline styles would better be placed in a separate css file, but hopefully this is still makes sense. The result produced by the code above would be roughly the same as the markup in the page you linked to. If you need the explicit <br> tags in your image caption (like in the linked markup), you would want to output your image description in your paragraph like: <?php echo nl2br($img1->description); ?> rather than <?=$img1->description?>. However, I think you are better off to let the copy wrap naturally, as the <br> tags are being used for formatting a specific type size (something that you can't always count on).
  13. Sorry trying to do this from an iPhone and it's not working so well
  14. Adam, You can crop just by using the size() function, and setting the dimension you don't want to change. So to crop the height ,get the existing width to maintain it $w = $page->image->width(); $image = $page->image->size($w, 200); That would Maintain the width but crop the height
  15. Adam, The image functions just do resize and crop to center at the moment (more advanced functions coming soon). ProcessWire just uses php for these functions, not a separate script/library. But what I would suggest is to exec() to ImageMagick, which is installed on almost all unix hosting accounts, and will accomplish what you need relatively easily. Let me know how it works out. Thanks, Ryan
  16. You can install it at any directory level and it should work just fine. ProcessWire doesn't care if it's in the root, a subdirectory, tertiary directory, etc. You don't need to configure anything for this, as it will pick it up automatically.
  17. Also see: /wire/core/Array.php There are lots of different methods in there, most based on jQuery traversal methods. This class is the basis for almost all ProcessWire arrays, including images. I use it for reference all the time. But I am working on getting an online reference for this class and others.
  18. Mike, For this example, I'll assume your field is called "images". To get the first image, you would do this: $firstImage = $page->images->first(); To get a numbered index, you would do: $nthImage = $page->images->eq($n); // where $n is a 0-based index Or, of course you can iterate the images too: $n = 0; foreach($page->images as $image) { echo "Image $n - " . $image->url; $n++; }
  19. Thanks for posting the fix. I also have an MT gridserver, though not sure I've ever tried to install ProcessWire there recently. Assuming I can reproduce the issue, I will implement a built-in solution.
  20. There isn't at present. Mainly because I couldn't think of a situation where you would be echoing someone's email on a public site. But if that's something you need to do, I would suggest iterating the comments field directly (as in the example above), as this is very simple to do and gives you access to every bit of comment data.
  21. I've removed the home link from the admin breadcrumbs in the latest commit. https://github.com/ryancramerdesign/ProcessWire/commit/f50cd4ad76cbfc8693ce25b8fec026278d02af46
  22. I understand that other CMSs have places where you might edit code in the CMS, and I also understand there is a convenience factor in many cases. But the main reason why I want to support snippets is actually to encourage sharing of code snippets. It's feasible that we can have a library of snippets that people can just paste in, and this is accessible to anyone. This is the area where I think the snippets may be worth the compromise of their downside. But I will do as you suggested and document why people might want to avoid using snippets for custom site-specific code, or plugging things into live sites. Thanks, Ryan
  23. Sure--let me know how it works for you and if you have any thoughts on expanding it further. Thanks, Ryan
  24. Hi Peter, I'm glad to see you extended a Process module and used it in the Admin. I think you are the first to do this. To iterate the fields in a template, you would do: <?php foreach($template->fields as $field) { echo "<li>{$field->name} is a field of type {$field->type}</li>"; } In the top of your .module file, I recommend adding one or more lines indicating that you are the author and any related contact info (website, etc.). Likewise, in your getModuleInfo() function, I recommend changing it to: public static function getModuleInfo() { return array( 'title' => 'Export XML for Flash', 'version' => 100, 'summary' => 'A module to export XML for flash by PeterB', ); } There is still a lot of stuff left in your module from the one you adapted it from, so you can remove lots of unnecessary code, which I'll cover below. Remove your init() function, you don't need it or anything that's in it. You don't need the code that is in your execute() function. You can change your execute() function to be just: public function ___execute() { return "<p><a href='./export'>Export XML for Flash</a></p>"; } In your executeExport function: It's not safe to assume that the assets dir is "../assets/". Instead, you should set your filename like this: $myFile = $this->config->paths->assets . "website.xml"; In general purpose situations, it's probably not safe to find your homepage with a selector like $pages->get("title=Home"). That's because it's feasible that other pages could have that title. I would instead suggest using the homepage's path, like $pages->get("/"); There are also other instances where you are retrieving a page with it's title field. If that's something that you need to do, I would suggest instead using the page's path/url or ID, as those are the only two things guaranteed to be unique about any given page. For pages with the same parent, you can also assume that it's "name" will be unique among it's siblings. On this line (119): $subpage = $this->pages->get("title=$section->title"); $stories = $subpage->children; Is that necessary? On briefly looking at the code, it looks to me like this would achieve the same thing: (?) $stories = $section->children; In your code, you are referring to a field called "page_type". Since this is essentially what a template is, you may want to see if using a Template for a page type would suite your needs (it's possible it may not). At the end of your executeExport function, you have the following: $out = $this->showListFilters || $this->config->advanced ? $this->renderListFilters() : ''; $table = $this->modules->get("MarkupAdminDataTable"); $table->action(array('Export XML for Flash' => './export')); $table->message("Exported!"); return $out . $table->render(); I believe you can delete all of that and replace it with: $this->message("Exported!"); return $this->execute(); Also, you can delete everything after your executeExport() function, as they are functions specific to the Fields module, and ConfigurableModule interface, and they aren't used here. Lastly, go back to the beginning of the file and change your class definition to be just: class ProcessExportFlashXml extends Process { You want to make sure you remove the "implements ConfigurableModule" since it will throw an error if you don't (since I told you to remove everything below your executeExport function.
  25. The reason it's not working is because a page's output formatting is usually only turned on for template use, and off elsewhere. Technically, all image fields can contain multiple images, but ProcessWire automatically reduces them for templates when you want them to be just one (likewise for Page references). It doesn't do this for the rest of the API just so that the same bits of code can always be used regardless of the image settings. Whereas in your templates, it lets you choose. Here's a couple of options to make it work in your instance: $url = $section->imagefield->first()->url; Or $section->setOutputFormatting(true); $url = $section->imagefield->url; $section->setOutputFormatting(false);
×
×
  • Create New...