Jump to content

rushy

Members
  • Posts

    49
  • Joined

  • Last visited

Everything posted by rushy

  1. I'm having a problem with writing data in the back end from time to time. On my front end I have a login form that authenticates a user and if login is successful certain commands are exposed in the front end, such as add, delete and rename which are not visible to guest users. I simply use the api function $user->isLoggedin() and to determine whether to show the commands or not. In the back end I have a kind of web service page that handles these commands and will only act on them if $user->isLoggedin() is also true there. I also set a $session timeout in my config.php. This works fine, if the session has timed out the command is still shown on home page but will fail in back end and will then say session timeout and refresh home page by session redirect. BUT sometimes when session is still active a command is actioned by back end but times out.... if I try again the action then always succeeds. Any ideas what could cause this. I note that exceptions.txt log file shows SQLSTATE[HY000]: General error: 2006 MySQL server has gone away (in /wire/core/WireDatabasePDO.php line 583 !! but I have no idea why it would "go away" and then work next time. Thanks for any pointers...
  2. Machine learning is quite an amazing thing and I have recently looked at what happened with the Google Alpha Zero program using neural networks. In board games like Chess and Go the machine was given only the rules of the game and objective and then given huge amounts of historical games to learn from. It was also playing itself millions of times and learning from this. Apparently after 4 hours it became stronger than the strongest program (Stockfish) and plays in a radically different way compared to previous Non AI programs, even showing moves that seemed alien to human grand masters but when analysed were found to be previously undiscovered winning strategies. This completely amazed me. So I think that AI will be very powerful organising a database into very pertinent and relevant responses and will only get better and more accurate over time with the neural networks they are using now. Of course humans will intervene and make corrections but the program will "learn" from this.
  3. Just giving AIOM a try and installed it and it works on my JS files but not my CSS files. In my home index page I am using a pattern like this :- <?php namespace ProcessWire; include_once("./_func.php"); if(!$config->ajax){ include("./_init.php"); } ?> ..HTML / Ajax here ... <?php if(!$config->ajax){ include("./_main.php"); } ?> and my _init.php has simply the Doctype, <html> opening <head> and my css declarations, closing </head> and opening <body> my _main.php has my JS includes, closing </body> and </html> Without AIOM it all works as I expect and validates correctly on W3. But when I add the AIOM to my css in my _init.php as below, I get Class 'ProcessWire\AllInOneMinify' not found. <link rel="stylesheet" type="text/css" href="<?php echo AllInOneMinify::CSS('css/stylesheet.css'); ?>"> If I remove it from the css files it works fine on the JS files in the _main.php. I can't understand why it won't work on the css in the head of my project. Any ideas? Next day: As a test, I moved one of my css links from the _init.php to the _main.php and hey presto it worked! I don't want it in the body part of my project as that's not the correct place for css files is it? I just wonder why when it's included in the head by my _init.php it doesn't know what AllInOneMinify is?
  4. SOLVED! My custom image field was working fine, I simply did not realise that Adminer truncates long text at 200 chars! It has to limit the display at some point and I should have guessed that. Anyway it seems to be storing my long text fields correctly as I just stored and then retrieved 612 char text so this bodes well.
  5. Hello. I have an image field on my page and was using the default description field to hold some text relating to the image. However I decided that I would sometimes like to store a longer text description such as an article about the image, for example a text several 1000 characters long. So I defined an image_fields template and added to it a text_article field of type textarea and tried to store long text there but it gets truncated around 200 chars, I can see that in Adminer. Any tips on how I should go about this? Thinking some more about this, perhaps I should just store a text document somewhere and reference it from PW, rather than store the text in the database, store a link to a document. Any comments on this? Many thanks - Paul
  6. Thank you Andreas. That is very slick and impressive! I hadn't thought of creating a hidden page for selections and time limiting the page. I think it could work for my images too. I'll have to explore Page References too as I never used them before. Paul Thanks for the heads up. I will take a look at this. Paul
  7. Hello. I've made an online photo gallery with albums and like to share some of the albums from time to time by providing a link that I email to selected people. I've made a page that acts as what I call an external viewer for this purpose. It takes a url with parameters to build a gallery from it. Now I'd like to be able to make this link time limited and what has come to mind is to generate a token and date/time that is stored as a field and may be compared to the link when someone attempts to view the shared link. If the token is valid then the date/time is checked to see if it's still current and access is allowed or not. Do you think this is a good way to handle this feature and is there anything in ProcessWire that can help me implement this that would help me? Many thanks for all your knowledge here! Paul
  8. Just to confirm the WireCache worked a treat for my drop list. Many thanks.
  9. Thank you Zeka and horst. I will try the $config->adminThumbOptions that you suggested horst. I am using proportional thumbnails and I note it's now deprecated in admin. I set a fixed height and calculate a scaling factor for proportional width as in the function below. It seems to work ok but I'm not sure it's the best way to tackle this. function getScaledThumbNail($image) { $justHt = wire('pages')->get('/')->gal_just_row_height; $scale = $image->height / $justHt; if($scale <= 0) { $thumb = null; }else { $tnW = $image->width / $scale; $thumb = $image->size($tnW, $justHt); } return $thumb; }
  10. Hi to everyone. I have created an online photo album using PW and I have a front end implementation to upload images into my albums. The problem I encounter is if / when I log in to the backend and view any album there are potentially several thousand images in each album and PW then generates it's default image thumbnails which effectively times out my request and also generates thousands of unwanted thumbnails. How can I tweak things so these do not get created? Just wondered if it's possible to change this default behaviour. Many thanks
  11. I just tried your site and it loaded very quickly it didn't seem slow at all.
  12. Hi @Zeka thanks for the idea of using WireCache. It does seem suitable for my needs so I'll give that a try. Many thanks!
  13. I've been working on making an online photo gallery for some time now and I have it working well using ProcessWire for storage and indexing of my images. Basically I have a series of albums represented by pages using my album template and this contains a images collection (usual Pageimages). I'm using the tags feature to tag the images so I can search across all the albums for a subject of interest to see all images for any tag in one view. This work well, and when I initialise I scan all images and build a list of all tags with the number of images with each tag and populate a drop down list with this info. so a user can select a tag from the list and see just the tag of interest. So far so good, but as I now have around 8000 images in the database the initial scanning does take a few seconds. It occurred to me that once this scan is done, it would be better to store this info on disc as this data will only change infrequently and only need rescanning if a tag is changed (such as an image is deleted or added). My question is how should I store this info? For example should I use an XML file? Or perhaps JSON? I could check for this file at start up and simply load that data into my drop list which would speed up start up. But I wondered if I could keep this list in a PW field somewhere. It's basically just a text list, but it does not seem obvious to me how to best store this in PW. Any ideas on how one would tackle this would be very interesting to me.... Thanks!
  14. SOLVED. As usual with processwire it's very easy. I just needed to do use add() function to add a copy to the album and then delete the relocated image. In the code below $instr contains the album name for destination album. case 'move': // Move image(s) from one album to another $out = "<p>Move $nosel images(s) to album $instr</p>"; $newalb = $pages->get("/{$instr}/"); $newalb->of(false); foreach($selected as $item){ $album = $pages->get($item->album); $album->of(false); $image = $album->images->getFile($item->file); $basename = $image->basename; $filename = $image->filename(); $out .= "<p>{$basename} in {$album->title}</p>"; $newalb->images->add($filename); // delete the relocated image $album->images->delete($image); } $newalb->save('images'); $newalb->of(true); $out .= saveUpdatedAlbums($pages, $selected); $out .= "<p>Updated album $newalb->title</p>"; $response['message'] = $out; break;
  15. Hi all Continuing my first project where I am creating and manipulating stuff from the frontend. Till now I've always added things like images from the backend, but in this project I need to add and move images from a frontend control. This is a photo album where images are stored in albums, each album being a page containing a Pageimages array in the usual way. So what I want to know is how do I move an image from one album (page) to another in the frontend? I just need some guidance on how to approach this. I suppose I need to do a copy and delete - but how do I copy an image or images from one page to another? What function should I use to create a new image on an existing page? I include a code snippet from the server side of my delete image request and it works fine. I'd like to implement something similar for a move and upload new image request. Many thanks for any help. Paul <?php namespace ProcessWire; // sanitize inputs as 1-line text $action = $sanitizer->text($input->post('action')); $instr = $sanitizer->text($input->post('input')); $sel = $input->post('selected'); // Expect JSON for image selected image list $selected = json_decode($sel); $nosel = count($selected); $response = array(); // for building JSON response switch($action) { // delete selected images case 'delete': $out = "<p>Deleted $nosel image(s)</p>"; foreach($selected as $item){ $album = $pages->get($item->album); $album->of(false); $out .= "<p>Image {$item->file} from album {$album->title}</p>"; $album->images->delete($item->file); $album->of(true); } $out .= saveUpdatedAlbums($pages, $selected); // add the response message for the delete $response['message'] = $out; break; ...... // save any album that had an image deleted function saveUpdatedAlbums($pages, $selected) { $cur = ''; $out = ''; foreach($selected as $item){ $album = $pages->get($item->album); if($album->id != $cur) { $album->of(false); $album->save('images'); $album->of(true); $cur = $album->id; $out .= "<p>Updated album {$pages->get($cur)->title}</p>"; } } return $out; }
  16. I confirm that this works - when I called trackChange before save the change to the image description field was savedA. Thanks again Horst. As a footnote, when updating tags I found that I can use $image->addTag('foo,bar,baz') without trackChange and tags were saved because it's a dedicated function to add tags. Regards
  17. Thanks Horst. My file basename is correct as I am able to echo out all the properties of the image, but I did not know about trackChange perhaps that is the missing bit. $pgfile = $al->images->getFile($file); if($pgfile) { echo "basename => $pgfile->basename \n"; echo "description => $pgfile->description \n"; echo "ext => $pgfile->ext \n"; echo "filename => $pgfile->filename \n"; echo "filesize => $pgfile->filesize \n"; echo "filesizeStr => $pgfile->filesizeStr \n"; } The above echoes out all the properties as expected , but assigning description to something does not update it when I save page. I guess I'm only changing a local copy here and it's not "connected" to the page. I imagine the trackChange makes that happen. I will try it and report back. Many thanks
  18. Bit of a newbie type question, even though I've been using PW for quite a while, I've not had to manipulate assets from the front end before. I now have a need to update image properties from the front end and I'm trying to update an image description and tags when clicking on a link. I get the selected image and for example I can delete it with the code below. But I am missing some basic understanding when updating image description field as nothing happens, no errors but the description field remains empty. Any idea what steps I am missing? Many thanks. // how to update image description? $al = $pages->get($album); $pgfile = $al->images->getFile($file); $al->of(false); $pgfile->description = "Test description"; $al->save(); // to delete an image - this works $al->of(false); $al->images->delete($file); $al->save();
  19. Thank you. That works! But I now realise I need to iterate each album to build a list of tagged images matching. I wonder if there is a sub selector that can do that? Thanks again I can get on with it now ?
  20. Hi I have a number of pages with images and I'm having a problem selecting on the image descriptions. In the code snippet below, the I added images.description field to my selector and it does work in that I get the expected no. of matches. So findTag gets me a list of images matching the tags in the code, but if I swap that line for the commented line $match->images->find it does not work giving 0 results. There is findTag for tags but for description there is not a dedicated function, so I should use find. But what selector will give me a list of images matched by image description? Many thanks. if($q !== '') { $keywords = $sanitizer->selectorValue($q); $matches = $pages->find("template=album, title|summary|images.tags|images.description~=$keywords"); echo "<p>match count: $matches->count</p>"; foreach($matches as $match){ echo "<p>{$match->title}</p>"; $i = $match->images->findTag($keywords); //$i = $match->images->find("template=album, images.description~=$keywords"); GIVES ZERO MATCHES $j = count($i); echo "<p>No. of image matching: $j</p>"; foreach($i as $img){ echo "<img src='{$img->url}' alt='{$img->description}'>"; } } }
  21. Thanks Horst. I created a test file with echo phpinfo() and found in the core table output the following listed as disabled: disable_functions shell_exec ,exec, system, popen, set_time_limit this for both local and master value columns in the table. i note your comments about switching or upgrading host! Paul
  22. I had no luck with any of the above, in the _init or config.php it gave an error as it's disabled by the host and in .htaccess the site did not run it just displayed a config error. Fasthosts have replied to my question saying there is no option to use set _time_limit on shared hosting. (see below) As a workaround I have commented out the set_time_limit call in the core and it works ok - for now...
  23. Hi. I've been using Processwire for a few years now and installed it on a few different shared hosting servers without issues, but I'm now running into an issue on a Fasthosts shared server that I've not seen before. The installation goes ok and I have a working default site profile but I am unable to complete any uploads of images. It just hangs at the progress spinner during the upload. I thought it might be a priviledge issue so have temporarily set the dir / file privs. as 777 / 666 just to test that but it made no difference. I have no errors in the wire log. In server error log I have: set_time_limit() has been disabled for security reasons in ....htdocs/wire/core/ImageSizerEngine.php on line 1035 and i note in the assets/file dir. where the image is being stored the date on the file being created has a year of 1970 and 0 length. If I leave the page this file disappears and nothing has been stored. Does anyone know how I can enable set_time_limit if this is likely to be the problem? Many thanks! Paul
  24. So far I found that using if(!$config->ajax): in my _main.php around head and foot parts and having a div targetted by Javascript as is commonly used - but in the case of an Ajax call I use wireRenderFile() to load markup from a file containing just the markup I need seems to work.... but I'm still playing with this. Paul
  25. Hello. I have recently adopted PW markup regions and really like this way of working. However, I am also trying to learn how to use Ajax and I am not sure of a good way to use the two together. Has anyone got any experience, tips or hints on using them together? For ajax - I've used a simple scheme where I have a "webservice" template and page that handles Ajax requests and returns the appropriate content wrapped with some markup for the requesting page. I have markup regions enabled and all my pages (bar webservice) include a _main.php which brings in the headers, a default body and the footer. My javascript intercepts the page links and does my ajax call to webservice and that sends back the appropriate markup which is then placed by in the div #body defined in _main.php. Does this seem a reasonable way to work? I guess I am looking for some advice before I invest too much time going the wrong way! Any guidance, remarks, comments, or a nudge in the right direction greatly appreciated. Paul
×
×
  • Create New...