-
Posts
4,077 -
Joined
-
Last visited
-
Days Won
87
Everything posted by horst
-
I think you first have to check where you are in the tree. If you have different templates for the pages p and subpages this is easy, but if you have not, you have to check for parents and childrens. Something like: if( count($page->children) > 0 ) { $url = $page->children->first()->url; } this is true if you are on p1 or p2, then you want to go to the first child-page. If the current page has no children, you want to go to the next page, but you also have to check if there is a next page or if you are allready on the last one: if( 0 != $page->next->id ) { $url = $page->next->url; } else { $url = $page->parents->next->url; } If it's the last one you want go to the next sibling of your current parent. But you also have to check if your current parent is the last one and there is no next one too: if( 0 != $page->next->id ) { $url = $page->next->url; } elseif( 0 != $page->parents->next->id ) { $url = $page->parents->next->url; } else { // do something when on last page, hmm, - yeah ok: $url = $page->parents->first()->url; } So, this is written in the browser and not tested, but something like this will work.
-
"Best Practice" - "Cloning" Sites | Reuse of basic installation...
horst replied to DV-JF's topic in General Support
But it (actually) do not work with PW 2.3 when you have MultiLanguage enabled. If you do not use MultiLanguage, it still works pretty fine! -
Bootstrapping Processwire to my Websocket server problem
horst replied to Harmster's topic in API & Templates
so, the OP also uses other variables in his functions from global scope: global $Server; he also can set it like this: global $Server, $wire; and than it should work. But personally I only use the wire('something')->Version within functions. -
Thanks Ryan. It was really massive learning to write this together. In fact I have (re)written it three to four times. Every time I want it to do something from what I don't know the PW-way, I have done it old-schooled first. Then a few days later, I've found informations here in Forum or in the docu that show me how to do it better. And I have rewritten it. Much work, much fun, me.better PW.coder now. ( but also much.much.much.more to learn ) The only downside with that project is that I now don't like my (before LocalAudioFiles) new created (but still not finished) portfolio site any more. I have trashed it and started new from scratch. With it there are new things like sessions, redirects, cookies and, ... yes, again: much.learning!
-
That should work, yes! But that's not exactly what I am suggesting, no! It depends on if you have different kind of registered users. If all registered users are allowed to add-review, you don't need extra permission, you only check if user has the role. And if you have registered users that are allowed and some that are not allowed, you need other rules to check. As an example: If you have registered users that have allready bought tickets and users that have not, and only the users that have bought tickets should be allowed to add-review, you want to check for: $user->hasRole($role) && count($pages->find("ticket_reference=$user")) > 0 I think you only would check for a permission if you have different roles, and some have the permission and some have not. So you have to check only one thing. EDIT: sorry, last post has taken a bit time, (has to do a phone call), and now you are allready done.
- 7 replies
-
- 2
-
- comments by users
- permissions
-
(and 1 more)
Tagged with:
-
Hi, I don't know if it is the right way to add a permission, or if it just would be enough to check a users role. But I think the system only knows what you implements If you use permissions, you want to check: $user->hasPermission($permission) If you use roles, you want to check: $user->hasRole($role) More variations can be found in CheatSheet under user, roles, permission. (But don't forget to click the advanced-button! in TopNav the right one!)
- 7 replies
-
- 1
-
- comments by users
- permissions
-
(and 1 more)
Tagged with:
-
Hi Soma, only want to drop a short note: when working with the ImagesManager in a MultiLanguageSite and the current AdminUser has another Language than the default one when creating new CategoryPages the PageTitle is only set for the current UserLanguage, default-LanguageTitle is left empty! With PageName, you populate all LanguageFields with the CategoryName. With the TitleField I think the defaultLanguage should be filled too, because it is the fallback for other empty TitleFields. PS: it's really fun to work with the ImagesManager!
-
Using methods/props on non existent fields in a template
horst replied to owzim's topic in API & Templates
<just-kidding>You can create a module, the SexyApiCode.module. That has to hook somehow into ErrorHandler and if a call to a nonexistent PageProperty (optionally: that matches one in PropertyList from ModuleConfig) has raised the Error, don't throw exception but continue with next codeline.</just-kidding> -
Hi all, I'm actually try to handle some mixed sort of adaptive and responsive image display in a gallery. That means I want to serve one out of three or four image-length that best fit to the current client-device-viewport, (to avoid sending 1600x1200 images to smartphones). The plan is as follows: The first page displays only thumbnails, so with them there is only one length. When the thumbnail page is loaded, it should send the actual viewport dimensions to PW. Dimensions get stored in session. Image-src is linked to /img/ID/, /img/ is a PW php script that compare last stored viewport dimensions against the width-height of desired image and send that one that fits best. As I have half of that already running long time on my old website (but with prototype and scriptaculous) I think I can solve that with jquery too. But with browser compatibility and all that stuff I'm feeling pretty much uncomfortable, so I want to ask if the following JS-code is bullet proof and also up to date for my needs or if I should use something different these days: function sendViewportDimensions() { // some jquery-ajax code } document.observe('dom:loaded', function() { sendViewportDimensions(); Event.observe(document.onresize ? document : window, "resize", function() { sendViewportDimensions(); }); }); And second question is if I have to add some kind of session-id to the ajax-request or if that is send automatically with it, or if it is send only sometimes automatically and sometimes not? (and I better have to add it to be save) ??
- 3 replies
-
- javascript
- sessions
-
(and 1 more)
Tagged with:
-
LiveDemo I have uploaded a small LiveDemo with only 7 truncated songs. But it's pretty fine to view all Demos and the additional $page->properties. demo song page demo album page demo artist page demo genre page
-
?? uhhm, - you first have to run the ShellImporterScript, then the Examples & Demos have some 'food' to work (They don't within an empty DB) No sorry, there is no LiveDemo.
-
Hhm, once I have written a PHP-alternative for apaches mod_rewrite, but unfortunately it needs a single entry in the .htaccess file to function And also if you could include it somehow into the processwire index.php without the need of the .htacess entry, I'm not sure if it is worth the work you have to do. Better you take the needed energy and talk to your client! ---- Technically you would have to buffer the complete output of every page, and with PW you first have to check if it is a page that has output for the browser!!. If it has, you have to loop through the output and rewrite all url-containing tags like href|src|action|area|...etc with prepending a new root-segment that points to a script that do the (emulated) mod_rewrite. I have written this class about nine yers ago, and of course, it was at the beginning time of my coder-carrier, so, it could be done much much better, but the basics are the same with todays PHP 5.2 and up. But once again, you would have to spent 1-2 days to get this achieved and tested!, - I think if your client want to save some money, he better should use another host, maybe in addition to the Yahoo! thing they have (maybe they have emails configured there and want avoid new setup for all that), only for the http-protocol (the website)! --- And, assuming that you don't have a part in your written contract that says something like that your work and the price for it is (only) valid for installation on standard-hosts that provide standard technics like Serverscripts (PHP) Servertechnics via .htaccess (mod_rewrite, protection, etc), from now on you should add it to every proposal / contract by default. (To be on a more secure side) Good Luck for you! and insight | intelligence | understanding for your client!
-
look here: http://processwire.com/talk/topic/3627-memcache-error-during-installation-process/#entry35527 you have to modify this line to suite your needs
-
Don't know if I understand your needs right: Under Setup -> Templates -> URLs is the option should page URLs end with a slash? Or maybe you can redirect the old pageURL to the new one via .htaccess EDIT: I think redirect can be done like this: Redirect 301 /store_item_detail.cfm http://example.com/new_pw_page_for_that/ Another way would be to use ModRewrite, but with Redirect 301 (permanent) you also tell google and other crawlers that they can update their cache with the new URL.
-
There is so much to explore and learn with PW, - so, only overlook a single method isn't that bad. I have to go to CheatSheet too when writing the code example. First, before looking to the CheatSheet, I have tried with $img->path instead of your $img->url but the right property is $img->filename. It takes time to learn all the usefull stuff. The CheatSheet is my best friend besides the great people here.
-
Hi Alex, welcome to the forum. To be save: your $page->Image is a real ImageInputfield that is assigned to a template? With [FIELD SETTINGS FOR NEW PAGE] you also have set the right template (that one that contains an ImageInputField named Image) ?? Assuming the both questions answered with yes, you can pass the images filename to the exif_imagetype function: <?php $map = array( IMAGETYPE_JPEG=>'jpg', IMAGETYPE_PNG=>'png', IMAGETYPE_GIF=>'gif' ); $url = 'http://nogajski.de/_grafik/0815.png'; // a jpeg with wrong extension! $p = new Page(); // create page and assign image from url .... $p->save(); $p->Image = $url; $p->save(); $img = $p->Image->first(); // get your ImageObject, * read below ... $ext_im = $map[exif_imagetype($img->filename)];// compare imagetype against file extension $ext_fn = strtolower($img->ext); if($ext_im != $ext_fn) { // if not match, rename it $newFilename = str_replace('.'.$img->ext, '.'.$ext_im, $img->name); $img->rename($newFilename); $p->save(); } * how to get the imageObject depends a bit on your settings for the ImageField under Setup->Fields-> (your Image field) -> Details -> Maximum files allowed. If you have set it to 1 or if you allow multiple. (not really sure) but I think this could work for both situations EDIT: -> http://cheatsheet.processwire.com/ the FILES -> properties and ->methods()
-
A little change in the importer script has to be done: - added a line that prevents the Shellwindow from closing when the wrong username/password was provided. With the fix now it stays open and the user get the info. LocalAudioFilesImportShellScript.zip (is included in the above Version 1.0.5 now)
-
Local Audio Files - MP3-DB The Local Audio Files DB is a combination of a Module and a SiteProfile. It is intended to import MP3-files from your filesystem into ProcessWire, read ID3-Tags and pull coverImages from it to feed the DB. It is thought as a starting point for your own site creation. A sort of comfortable aggregated reuseable code for PW-lovers. How to Install Grab a copy of the latest ProcessWire. Replace the install, modules and templates directories with those in this profile, as shown below: /site-default/install/ /site-default/modules/ /site-default/templates/ With SiteProfile-Installs normally that is all there is to do. With this Profile you also have to copy the file LocalAudioFilesImportShellScript.php (for simplicity) to your PW-rootfolder, (where the index.php reside). If you are on Windows you also should copy mp3_import_starter4win.cmd to the same location. Now install ProcessWire as per the instructions included with it and it will install the LocalAudioFiles profile automatically. After that you find a Quickstart Guide at the homepage of the profile: Follow the 3 steps and you are done! How does it work? The Site has 4 sibling Tree Branches: genres - artists - albums - songs. Each of them hold child-pages: genre - artist - album - song. The logical relations are nested parent-children ones: a genre hold artists, each artist hold albums, each album hold songs. To support both, slim and fast data relations & the logical hirarchy, the module extends the ProcessWire variable $page with some additions. It uses the addHookProperty mechanism to achieve that. It uses an own caching mechanism for large lists, that can be prebuild when running the importer-shellscript, or it build the cache on demand. Also it comes with a FrontEndHandler class that provides a lot of functionality, for example fully customizable FormSelectFields of all genres, artists or albums. More detailed informations and code examples are collected in a demo section of the site. The extended $page variable together with the LocalAudioFiles-FrontEndHandler gives you comprehensive tools to work with your music collection. Download Modules Directory LocalAudioFiles-SiteProfile_v0.1.5.zip LiveDemo I have uploaded a small LiveDemo with only 7 truncated songs. But it's pretty fine to view all Demos and the additional $page->proterties. demo song page demo album page demo artist page demo genre page Graphical overview Screencast of installation https://youtu.be/-qYyppvEF1k History of origins http://processwire.com/talk/topic/3322-how-to-setup-relations-for-a-mp3-db-with-pw/ http://processwire.com/talk/topic/3462-pages-get-return-nullpage-but-page-exists/
-
I'm not totally sure but it seems that you can read the dBase file directly with PHP, so you will be able to read the records from the file and use the API to import them. http://php.net/manual/en/ref.dbase.php EDIT: here is a guy who has converted dBase to CSV: http://www.dev-zero.de/php/mit-php-dbase-zu-csv-konvertieren.html He uses a dbase class from another guy: http://www.dev-zero.de/downloads/dbf_class.php and the code to do the convert is short: <?php include("dbf_class.php"); // include the class $dbaseDB = ‘DB.dbf’; $dbf = new dbf_class($dbaseDB); // open the dBase file $csvFile = ‘file.csv’; // create a CSV file $csv = fopen($csvFile,"w"); // get record count, loop through and convert to csv $num_rec=$dbf->dbf_num_rec; fputcsv($csv, array_keys($dbf->getRowAssoc(0))); for($i=0; $i<$num_rec; $i++) { fputcsv($csv, $dbf->getRow($i)); } fclose($csv); // ready! now use Ryans CSV-Importer But want to note that I only have googled that and have not tested / used this by myself, so- no warranties ;-)
-
I have successful hooked new properties to the existing pages (parents: genre|artist|album) and (children: artists|albums|songs), and some more. With the demos I have made some progress, and I have made a graphical overview: Edit: new Mindmap
-
current situation is as follows: With my MP3-DB I create extended page-objects that have some additional Properties and tweaked Children. Now I've thought if it would be better to use the 'real' $page variable for that. Extending it with some Properties could be done like explained in the Hooks-API-Doc: http://processwire.com/api/hooks/#add_new_property But, I need to tweak the $page->children and $page->childNum. Is there any chance to do that? ------------ why do i want this to have: if one is, for example on a album-page, the album-page has no children, because the DB-Structure has sibling branches for albums and songs. But human logic says an album must have children (the songs)
-
Programmatically changing a Pageimages field
horst replied to Sinmok's topic in Module/Plugin Development
Hi <eagle eye>kongondo</eagle eye>, this would probably be useful to me too. -
Hi, when surfin' to http://processwire.com/api/cheatsheet/ I only see blank page, whereas all other API-Docs are shown correctly. Can someone validate this please?