Jump to content

titanium

Members
  • Posts

    161
  • Joined

  • Last visited

Posts posted by titanium

  1. I tried this great module a few minutes ago - with ProCache disabled, it works as expected. With ProCache enabled, it doesn't: given one main domain and one  "campaign" domain, the browser displays the start page of the domain which was called first. I think it has to do with the .htaccess rules ProCache depends on.

  2. Does it work, means is there no timeout? I just removed a line that was not needed.

    Yes, it definitely works. There is no timeout, the page loads instantly. I did test it with 52 images with a total of 292 MB (the images are huge), it works as desired.

    One thing I don't understand is: I thought it would be clever to use the ID of the field instead of the name:

    if ($field->id != 146) {
      return;
    }
    

    I assumed it would be better for me to use the id, because I tend to rename the fields sometimes and using the ID saves me from hunting down the changed name everywhere :-)

    But that doesn't work (146 is the id of my "images" field for sure) - if I do this, the images aren't resized anymore. I even don't know how I can debug the module. I tried

    var_dump($field);
    break;
    

    and

    var_dump($field);
    exit;
    

    but had no luck.

  3. bluewithoutgreen, you didn't tell us what the problem is, so I just can guess. As far as I can see, your code outputs the same thumbnail four times, and you get as many unordered lists as you have got pictures in $feature->thumbnail.

    I think what you really want to do is:

    $output = '';  // holds the HTML to output
    
    foreach($features as $feature) {
        $thumb = $feature->thumbnail ? $feature->thumbnail->width(800)->url : 'http://i.imgur.com/1zxfxMW.jpg'; // if no thumbnail, replace by placeholder
        $output .= '<li><img src="' . $thumb . '" alt="" /></li>';
    }
    
    echo '<ul class="bxslider">' . $output . '</ul>';
    • Like 1
  4. Dear forum members,

    I implemented a very basic picture gallery in a client's website. Basically all images are uploaded to an image field. The pictures are resized and brought to output like this:

    foreach ($page->images as $image) {
    	$output .= '<a href="' . $image->width(1000)->url . '" title="' . $image->description . '"><img src="' . $image->size(100, 100)->url . '" height="100" width="100"></a>';
    }
    

    I think that's common practice so far and it works nicely with a limited number of images.

    Since the client is uploading a lot of images, the page loading times in the frontend exceed the webserver's processing timeout limit of 30 seconds. The browser displays a script timeout error then.

    Is there anything I can do to avoid this? Setting up the script timeout is not an option, because it doesn't scale. I think the best way would be to resize the images to the two formats (100x100 pixels and 1000 x proportional height pixels) right at upload. I guess a module for this could be handy. Has anyone did that already or could give me a hint in the right direction?

    Thanks a lot!

  5. Hi,

    I wonder if there is an easy way to resize an image in the filesystem? Reason is: I need to display the same image in different sizes in some templates, but the image is already in the filesystem (in fact, it is deployed by another system). Since it should work automatically, I don't want to use the backend and create a field for it by hand.

    For example: instead of doing something like this (every picture has to be sized with Photoshop beforehand):

    <img src="/mypath/myimage.png" width="250" alt=""/>
    <img src="/mypath/myimage.png" width="500" alt=""/>
    

    it would be convenient to do something like this (does NOT work, just for illustrating what I would like to achieve):

    <?php $image = new PageImage('/var/www/mypath/myimage.png'); ?>
    <img src="<?php echo $image->size(250,0)->url; ?>" width="250" alt=""/>
    <img src="<?php echo $image->size(500,0)->url; ?>" width="500" alt=""/>
    

    In this manner the system would do the resizing, and Photoshop could rest in peace.

    I know phpThumb or timThumb can do this similar as well, but I would like to do it the Processwire way.

    Any hints welcome :-)

  6. Thanks to all who participate in this discussion and your point of views. I do clearly understand the good arguments of getting in control of how content is structured and presented - we are definitely of the same opinion! For example, using TinyMce is a nightmare for me (and in the long run) for editors too, because it's results are often unpredictable and not maintainable. I want to get rid of such an RTE concept, because that's not what structured HTML is for in principle.

    On the other hand, take a look at content heavy websites like a newspaper website, for instance. The content areas of these sites are mostly build up of a headline, an introductory text, an image (or an image gallery), a voting, some links... These block elements are limited (good to control, just a hand full of structured code, read: some templates), but it's up to the editor where the voting part or the image gallery is placed. It's part of _his_ creative process. It's not up to me to say: "wait, image galleries always belong to the bottom of the page!". No - it belongs where it best fits, mostly at that place where the according (con)text is placed. An editor may have good reasons why he might use two votings instead of one, followed by an image gallery and some text in between. I can't predict all these nearly infinite combinations and make a template for each of these. Think of "Lego" (oh god, I loved that stuff so much as a child :-) - the elements are limited and easy to control (counted/changed/updated/deleted whatever Processwire does best), but the possibilities are unlimited!

    What I'm voting for is basically nothing more than a page field, which has the possibility not only to select an existing page, but to create a new page also. This function already exists, but it does only work if the parent template of the "new-to-create" child page is firmly set. That would shorten the process of creating these child pages, the editor wouldn't have to leave the page he is currently working on.

    Another approach would be a repeater, which has the possibility to select a different template for each row.

    All in all, please don't understand me wrong - I don't want to turn Processwire into a messy pile. I would like to optimize the backend usefulness at some corners. Some of you said "it's doable" and you have great conceptual ideas, I would wish that I have the coding skills to bring them to life.

    • Like 1
  7. Processwire a very efficient CRUD tool with a strong API, but there is the "one" thing which my clients are requesting: They would like to build pages which don't fit in the somewhat rigid grid the developer defines: They would like to build pages which are made of an collection of building blocks (some examples: a Google map; a picture gallery; a pic with lightbox functionality on the left with text floating on the right and so on).

    The blocks can (and should) be defined by the developer in advance, but the clients/editors would like to combine them as they wish. The nearest close answer Processwire delivers to this request is the "Page" field. The pages can be build with that, but it's not very user-friendly: The editor has first to set up each of the child pages, and after that he returns to the page with the page field (I call it "master page") and adds the child pages one by one to the page field. If the master page is viewed, it renders the child blocks quite nicely - but the whole process of content editing takes just too long and it doesn't feel comfortable.

    I have watched out here in the forum for similar requests (there are a few), but unfortunately, no concrete solutions yet. Is there anything in the pipeline to fullfill these kind of needs?

    • Like 1
  8. $config->scripts and $config->styles are meant to hold filenames, not entire tags.

    In the past, it seems that I have somewhat "abused" $config-scripts and put some dynamically generated js scripts to it. It worked fine so far, but I'm willing to learn how to do it better.

    Do you have some advise for me what would be best if I have to put some JS before the closing body-tag? The js should echo some php variables like this:

    $("#carousel").carousel({
    	interval: <?php echo $page->carouselInterval; ?>
    })
    

    In this case, static js files can't be used...

    This by the way is one reason why I think using a main.php is a little better than head.inc/foot.inc.

    Whoever reads this and is wondering about what could be meant by "main.php": I strongly advise to download Ryan's Blog profile. I wish I had done this much sooner, it's a great example which shows clearly the concept behind "main.php". This approach is discussed here (very interesting to read, I think).

  9. public function init()
    {
    	$this->addHookAfter('PageEdit::execute', $this, 'example');
    }
    
    public function example($event)
    {
    	var_dump($event->return); # does not get even executed in backend
    }
    

    Hi teppo, hmm... I suppose the method name hooked to is wrong, isn't it? Oh boy, I have the feeling I don't know anything  :mellow:

  10. Little bit of background information would be useful here: you're saying that you've got a field you're using to create an image. What type of field is it, what kind of content does it have, does it store that too or is it cleared after image has been created? Is created image always at same location and does it's name vary?

    Depending on what you're doing exactly you might want to a) create new inputfield and/or fieldtype for this purpose or b) create an autoload module that hooks into ProcessPageEdit::execute (or something more appropriate) and if an image is found from pre-specified location renders it somewhere (positioning could be done with JS, if that's necessary.)

    I really appreciate your help, teppo and Nico. I should have been more specific. I've already done some custom backend forms in the past, they where done as a process module like the following example - this renders a table in the backend, if bound to an admin page as a process. I think something like this was meant by Nico:

    class ProcessTable extends Process implements Module {
    
    	public static function getModuleInfo() {
    		return array(
    			'title' => __('Table showcase', __FILE__),
    			'version' => 100,
    			'summary' => __('Example of a table in backend', __FILE__),
    			'author' => 'Yes, it was me! :-)',
    			'href' => '',
    			'autoload' => false,
    			'singular' => true,
    			'permanent' => false
    		);
    	}
    
    	public function init() {
    		parent::init();
    		ini_set('auto_detect_line_endings', true);
    	}
    
    	public function ___execute()
    	{
    		$this->setFuel('processHeadline', 'Example of a table');
    		$table = $this->modules->get('MarkupAdminDataTable');
    		$table->headerRow(array('Header col1', 'Header col2'));
    		$table->row(array('col1', 'col2'));
    		return $table->render();
    	}
    }
    

    it would be easy to render a picture in such a custom form.

    In contrast to this, I would like to show a picture in one of the forms as they get rendered by Processwire by default when a new page is created and a template gets selected. I hope you have an idea of what I'm trying to say - I'm in lack of the correct terminology for these forms  :)

    The picture should be rendered below the fields the template already has. The dynamically generated picture is saved to an image field, which I've set to hidden because it's filled by an extra module on its own - this part is already working. The picture can be addressed normally like every other picture, e. g. echo $page-myPic->size(120, 0) etc.

    teppo said: "b) create an autoload module that hooks into ProcessPageEdit::execute (or something more appropriate)". That sounds like the route I'm trying to find. Do you know how I can access the form Processwire renders? Maybe I can somehow append my custom output  to it.

  11. This is probably an easy one! I'm trying to list pages with a given tag. But I need that tag to be a variable.

    It works without the variable:

    foreach ($page->find('template=placemarks, tag=1009') as $child){
    

    ...but this doesn't work:

    $tag="1009";
    foreach ($page->find('template=placemarks, tag=$tag') as $child){
    

    What am I doing wrong?

    Or this (I'm a fan of single quotes, because it's generally a little bit faster, because the PHP parser has less to do Edit: not true anymore, if it every was - but single quotes do look much better in my favorite IDE. Thanks to teppo for myth busting  :)

    $page->find('template=placemarks, tag=' . $tag)
    
  12. I have a template with four or five fields - so far, so normal. One of these fields is used to generate some image with gd outside of PW. The generated image itself is saved in its own field with the help of the API.

    I would like to display this image right in the backend, next to the other fields. How can I achieve this? The image field is obviously not suitable, because the image shouldn't be editable. I guess I have to write a module for this and hook somewhere... how to start?

  13. There seems to be a bug: I've just noticed that I can't even use explicit php (float) type casting or floatval() in my template code - it delivers "," as decimal point, not ".", if I'm using german as default language.

    Workaround: in line 144 of /wire/modules/LanguageSupport/LanguageSupport.module it says:

    $locale = $this->_('0'); // Value to pass to PHP's setlocale(LC_ALL, 'value') function when initializing this language // Default is 'C'. Specify '0' to skip the setlocale() call (and carry on system default).
    if($locale != '0') setlocale(LC_ALL, $locale); 
    

    If it is set to $locale = $this->_('0') floats are working as expected. Don't know if this has other side effects though.

    How can I made this change "upgrade-save"? Copying the whole module to /site/ gives an error about dependencies.

    Ryan, what about changing this module to be configurable?

    Since I don't need float-types that often, I found a better solution for me. If I'm using float(), I set

    setLocale(LC_NUMERIC, 'C');
    

    in the affected template a line before. The file LanguageSupport.module does not need to be changed then.

  14. I've noticed that my installation has the same problem. It seems that it has something to do with the language the user has activated. Normally, I use "german" for my main language. In this case the floats are saved integers, no matter if I put 0,35 or 0.35 in the field. If I switch to english, it works. Is there anything I can configure for german?

    There seems to be a bug: I've just noticed that I can't even use explicit php (float) type casting or floatval() in my template code - it delivers "," as decimal point, not ".", if I'm using german as default language.

    Workaround: in line 144 of /wire/modules/LanguageSupport/LanguageSupport.module it says:

    $locale = $this->_('0'); // Value to pass to PHP's setlocale(LC_ALL, 'value') function when initializing this language // Default is 'C'. Specify '0' to skip the setlocale() call (and carry on system default).
    if($locale != '0') setlocale(LC_ALL, $locale); 
    

    If it is set to $locale = $this->_('0') floats are working as expected. Don't know if this has other side effects though.

    How can I made this change "upgrade-save"? Copying the whole module to /site/ gives an error about dependencies.

    Ryan, what about changing this module to be configurable?

  15. Just noticed that with the latest dev, floats are stored as integers in the db.

    For example: 0.3423 -> 0, 3.5 -> 3

    I'm using text-fields and cast them in PHP to (float) or (double) when needed.

    I've noticed that my installation has the same problem. It seems that it has something to do with the language the user has activated. Normally, I use "german" for my main language. In this case the floats are saved integers, no matter if I put 0,35 or 0.35 in the field. If I switch to english, it works. Is there anything I can configure for german?

  16. You could also use PWs $config->scripts->add(path) and $config->styles->add(path) to register scripts and output them same way as in the default.php found in templates-admin. https://ryancramerdesign/ProcessWire/blob/master/wire/templates-admin/default.php#L67

    Hmmm... I stumbled upon the same problem today again. Given the following setup: my page template includes head.inc and foot.inc.

    head.inc contains before closing </head>:

    <?php
    foreach ($config->styles->unique() as $style) {
        echo $style;
    }
    ?>

    foot.inc contains before closing </body>:

    <?php
    foreach ($config->scripts->unique() as $script)
    {
        echo $script;
    }
    ?>

    My page template contains:

    <?php
    $config->styles->add('<link rel="stylesheet" href="mystyle.css" />');
    $config->scripts->add('<script src="myscript.js"></script>');
    ?>

    Result:

    myscript.js gets injected in the output html footer, but mystyle.css does NOT get into header (as I wanted to and I assumed that it works this way). Did I do something wrong? Did I misunderstand the use of $config->styles->add?

×
×
  • Create New...