Leaderboard
Popular Content
Showing content with the highest reputation on 04/22/2013 in all areas
-
Something to add to WillyC's example is checking whether the given page is active for the language. This is only necessary if you are selectively having some pages published in one language and not in another (meaning, you are using the "active" checkboxes to the right of the language-specific page names). echo "<ul>"; foreach($languages as $language) { if(!$page->viewable($language)) continue; // check if page not published for this language $class = "$language" == "$user->language" ? "active" : ""; $url = $page->localUrl($language); echo "<li class='$class'><a href='$url'>$language->title</a></li>"; } echo "</ul>"; The only change I added above was the if(!$page->viewable($language)) continue; That makes it skip over languages that aren't published for $page. If that check weren't there, then the user would just see a 404 page when attempting to view in the unpublished language.4 points
-
I have written a little module that extends Somas awesome Images Manager. Also it's written with Somas kind help, (thanks!) It adds auto filling of EXIF or IPTC fields where available on upload of new images through Images Manager. How to use it: You, of course have Images Manager installed and ready to run. Now you have to create some fields that should take your exif data: fieldname prefix is exif_ followed by the original exif-fieldname but lowercase! ( exif_author, exif_copyright, etc.) ALSO you have to create one TextArea field called (by default) image_exif, - this one and ... (not needed, only optional to get the full raw EXIF-data stored) all your exif_fields you have to add to the image-template that is used by Images Manager for creating the new Image Pages. then download and install the ImagesManagerMetadata module. here are a little screencast I've done with it: https://youtu.be/wjhJdT7Tf5Y this is alpha, version 0.0.2 ImagesManagerMetadata.zip2 points
-
The post isellsoap linked to above has Ryan's explanation on why it's not straightforward to compare two fields - and yes, there's a solution also. But I'd like to propose another solution as well in case you'd need better performance or native pagination (lots of pages for example). You could add a helper field "f1_f2_difference" and populate it on page save with the difference of field1 and field2 (field2-field1). Then you'd be able to do this: echo $pages->find("has_parent=/features/, f1_f2_difference>0"); There's an example of pretty much the same thing in the final post of this thread and for some more information read also this thread. But you've got a working solution already so there's probably no need to take this route . -- @adrian: your suggestion would be fine when the fields are in the same database table (like created and modified are). Here field1 and field2 are presumably custom fields and thus in their own tables. An SQL JOIN would still do it, but using selectors gives the advantage of grants and visibility being taken care of.2 points
-
One small addition to diogo's solution: You should calculate time() - $page->date, otherwise the first if is always true and the second can't be. if ((time() - $page->date) < (3 * 60 * 60)) { // 3 hours in unix time or take the absolute value of the difference: if (abs($page->date - time()) < (3 * 60 * 60)) {2 points
-
PW Images Manager (beta) Just a weird little screencast trying to show how it works. (out of date a little, tags now use a textfield for easy copy/paste) This module allows you to manage images from one central repository. You create a root page "/images/" where you can then add categories and images as pages. From there the new admin page created "ImagesManager" will show categories and images added in a ajax data table, from where you can see and search/filter all images, upload and create new categories and edit images too. Every image will also show an image tag generated to copy into a textarea. This tag looks like this: {image=/path/to/image/imagename/, width=200}The width=100 is the thumbnail size used to output the image.You can also have additional segment to contain classes: {image=/path/to/image/imagename/, width=100, class=align_left}Or you can enter the id directly: {image=1033, width=100}Once inserted into a textarea field it will get parsed when saved and loaded automaticly. It will store an abstract id tag in Database and convert it back to the image HTML tag. So after first save you'll see the image inserted in a Wysiwyg and be able to resize and place it as usual. Once it's inserted somewhere Images Manager will show a search link with the pages containing the image (you can configure the fields int the module setting). You can change the image or move it to a different category, it will still work and show the correct image. This also works with multi-language fields.You can still also use the regular insert image dialog in TinyMCE and chose image from those pages. And it will start keeping track of those as well (they're the same after all). You can use those central images pages also with page fields to reference them single or even whole categories, search them with API and do what you like. Images Manager will also parse the page render on front-end and replace any found image tags with the HTML code. It will also look for a description on the image and output it as alt tag. If you want to have multi-language description you can add a `image_description` TextLanguage field to the image page template and have images parser use them. Along with this module, you can also install the `PageListImageLabel` module to add thumbnails to the image pages in the tree. To get it working you need to have the basic setup: 1. Create new `image` field with input setting to 1 max image 2. Create new `image` template and add `title` and the `image` field created before 3. Create a 'image-category' template with only title and allow the `image` template and `image-category` as child pages under family settings. 4. Create a `image-root` template with only the title field for the root of the images tree. Allow only `image-category` as child page under family settings. 5. Create the root page with the `image-root` under the home page as "/images/" 6. Done. The structure of the image repository looks like this /images/ /cagetory1/ /imagesxy/ /category2/ /image2/ /image3/ Now you can use the ImagesManager to add categories and images. But you can also still use the page tree to add new stuff as usual. The root path, template names and fields are configurable in the module settings. How to install the module: - Download the contents of this repository and put the folder renamed as "ImagesManager" into your site/modules/ folder - Login in to ProcessWire and got to Modules page and click "Check for new modules". You should see a note that the two new module were found. Install the "ImagesManager" module. - A new admin page "ImagesManager" should appear in the top menu. - You may configure the option on the module screen to suit your needs. Download at github https://github.com/somatonic/ImagesManager Thanks and enjoy.1 point
-
Hi, @MarcC Ideally having a check for data and populate fields would be a great idea. In my case my setup looks like this. As you can see there'll be scans from the YashicatMat that probably won't show anything because it records no data and I haven't written anything down for the shot .1 point
-
Nice one Horst! I don't think you have to add the images_exif textarea to have it work. I thought the meta data function always gets called regardless, it's just that it only tries to write infos when that field is found. Second one is I pushed an silent little update to the FF bug with the tag field some time ago already.1 point
-
here is the little module that adds auto population for single textfields with exif or iptc data: http://processwire.com/talk/topic/3398-working-with-processwire-getting-exif-data-from-images/#entry33552 Many thanks for your kind help Soma!1 point
-
Hey Peter glad you like it. 1. I think there's tons of examples out there. I agree it can be tricky if you're not into it so much. I often use a drop-down script (with some basic CSS) I modified some time ago, it's also used in my Teflon theme. https://github.com/somatonic/droppy it doesn't require anything except jQuery and some CSS. There's also CSS only ways to do it. 2. I'm a little careful not to add even more options. This I agree can be handy, since it's also possible use external urls. I think there's different ways to achieve it already what you want without adding more. xtemplates, xitem_tpl, options for example, but it would only be possible to add it to all links that have the template you define there. But there's another way that is possible since a couple versions. Adding a hook to the link item being constructed and modify it. Here simple example for use in templates: function getTagsString(HookEvent $event){ $tpl = $event->arguments[0]; // the template string $page = $event->arguments[1]; // the page getting rendered if($page->open_blank){ // $event->return is the complete link you get from the hook, modify to you needs $event->return = str_replace('href=','target="_blank" href=', $event->return); } } $treeMenu->addHookAfter('getTagsString', null, "getTagsString"); echo $treeMenu->render();1 point
-
I think you should do this control in the templates. You can have a page for each drama, and children pages or a repeater for all the shows of that drama. On them you will have a date field with the time of the show. Then on the template you can do this: if (($page->date - time()) < (3 * 60 * 60)) { // 3 hours in unix time // tickets can't be sold anymore } and if (($page->date - time()) > (7 * 24 * 60 * 60)) { // one week in unix time // tickets are available from now on }1 point
-
Solved. Anyway, I am always interested to expand my PW network. ...There will be more projects soon. Let me know if you are interested to join in.1 point
-
Hey Nico - thanks for the suggestion, but the page worked in other browsers and even an incognito Chrome window. Once the cookies/cache were cleared it also worked fine in a standard Chrome window. So it was all solved with no code changes. The weird thing though is that there was that one line of code that could be removed and it would load in standard Chrome window as well. I even had a live version of the site (as opposed to the dev version) with exactly the same code on that page that also worked fine. Anyway, my post here was really just a general heads up in case someone else gets this error. I do like Chrome, but I find its aggressive caching annoying at times. One other thing I did in fixing this page is flush the DNS cache in chrome and my OS. I don't think this is related but it was suggested when I was researching the no data received error!1 point
-
Nothing will be as fast as going straight to a dedicated targeted SQL query like that. But if you wanted to use PW selectors, this is still quite fast: for($n = ord('A'); $n <= ord('Z'); $n++) { $letter = chr($n); $cnt = $pages->count("surname^=$letter"); echo "<li>$letter - $cnt people</li>"; }1 point
-
Manual sorting is intended for reasonably sized lists, like navigation. For large groups of pages that have a chronological basis, you should always use some kind of date sorting. If you need to go outside that in certain instances, then add a "sticky" or "featured" checkbox, so that the client can override what gets shown first on the front-end when they want to. For example, if we wanted to retrieve a list of all news articles by date, but with "featured" ones showing up first, we could do this: $articles = $pages->find("template=article, sort=-featured, sort=-date");1 point
-
Without emulating $imgArray = $images->getArray(); natsort($imgArray); // continue with $imgArray or... $images = new WireArray(); $images->import($imgArray); Not tested1 point
-
Thanks guys! That really helped me to do what I wanted to achieve. Thanks a lot for the help and for making such good tools. Have a nice weekend!1 point
-
this another language.swatch work wit any num.languagees new localUrl func echo "<ul>"; foreach($languages as $language) { $class="$language"=="$user->language" ? "active" : ""; $url=$page->localUrl($language); echo "<li class=\"$class\"><a href=\"$url\">$language->title</a></li>"; } echo "</ul>"1 point
-
... and end up in endless loop land. ;-) Better just save the field only $item->save('sort_title') so the hook doesnt get called again and again and...1 point
-
Thanks guys! Yes there I see some room for improvements to select the tag and also show some infos of the image size. It's impossible to have image field select from those images. It would require a new image fueldtype. But that's not something that has to be connected to ImagesManager but just a field you can select an image page. Thats the great thing about this approach. But you can do it with a page field easily. I'm doing it. If you use PageListSelect you'll even see the image thumb. And it would also be possible to select multiple or even just categories. This is even better than a dedicated fieldtype.1 point
-
Bravo! This'll open the flood gates to folk who expect this functionality in whatever CMS they use. "Somehow connect the image manager to a standard image field" <- An uber image field I rarely stick images into a wysiwyg editor and I have dreams where the standard image field can either accept an upload or link to another image on another page.1 point
-
Awesome! I had no idea it was so easy to drop straight to SQL. You continue to surprise me with practical, useful solutions! Best, Rick1 point
-
Selectors have to have a defined value after the operator. There is no defined value in "modified>created", as those are two fields. You can go straight to SQL to accomplish this one: $pageIDs = array(); $result = $db->query("SELECT id FROM pages WHERE modified>created"); while($row = $result->fetch_row()) $pageIDs[] = $row[0]; $pageArray = $pages->getById($pageIDs); // $pageArray contains what you want1 point
-
Try this: $allPages = $pages->find("anySelector"); foreach($allPages as $p) if($p->modified == $p->created) $allPages->remove($p); //I'm using == instead of <= because modified would never be smaller than created $allPages should hold your desired results now1 point
-
Hello there, First of all, letting a client post HTML straight into a field and then echoing it (especially without escaping anything) could potentially break things up and cause quite a bit of confusion / extra work for you, so I wouldn't really suggest it. IMHO better option would be to ask the client to post WordPress embed tag offered by SoundCloud to the body field (or any other field you've specified, actually) and then replace that with actually player code at your template. WordPress embed tags look like this: [soundcloud url="http://api.soundcloud.com/tracks/59233018" iframe="true" /] Simply ask your client to post these tags to whatever field you've specified, each as it's own paragraph (just paste and hit enter when field has TinyMCE enabled.) Then include this code in your template (I'm using body field as an example here): <?php $replacement = '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F$1&show_artwork=true"></iframe>'; $page->body = preg_replace("#<p>[^\w]*\[soundcloud url=\"http:\/\/api.soundcloud.com\/tracks\/([0-9]+)?\"[\w\=\" ]* \/\]</p>#i", $replacement, $page->body); That should do the trick. EDIT: once again I've been too slow.. damnit. Oh well, now there's twice the regexp fun to check out. EDIT 2: @danielholanda, even though both answers so far have certain similarities (regexp ftw), there's actually one important difference just in case you've missed it: the method diogo provided is based on adding a specific field for songs. This way if you want multiple songs on one page you could add that field inside a repeater and loop through it's content. The method I posted above is based on the assumption that you could be using that same field for both "typical" content and (multiple) SoundCloud embeds. I'm adding this just to clarify both methods a bit and make it easier to choose which method you're going to use. This really depends on how your client will manage this content too; especially if each SoundCloud clip has it's own page there's very little point for using the latter method.1 point
-
Welcome to the forums abe.izar. Seems like they should make json_encode at least attempt to typecast an object to a string (which would convert to IDs here). Maybe I can update wireEncodeJSON (a front-end to json_encode) do that. However, if you really want to export pages and all their data to JSON, here's how you can do it: function pagesToJSON(PageArray $items) { $a = array(); foreach($items as $item) { $a[] = pageToArray($item); } return json_encode($a); } function pageToArray(Page $page) { $outputFormatting = $page->outputFormatting; $page->setOutputFormatting(false); $data = array( 'id' => $page->id, 'parent_id' => $page->parent_id, 'templates_id' => $page->templates_id, 'name' => $page->name, 'status' => $page->status, 'sort' => $page->sort, 'sortfield' => $page->sortfield, 'numChildren' => $page->numChildren, 'template' => $page->template->name, 'parent' => $page->parent->path, 'data' => array(), ); foreach($page->template->fieldgroup as $field) { if($field->type instanceof FieldtypeFieldsetOpen) continue; $value = $page->get($field->name); $data['data'][$field->name] = $field->type->sleepValue($page, $field, $value); } $page->setOutputFormatting($outputFormatting); return $data; }1 point