Announcement

  •  » Engine
  •  » Piwigo and AJAX

#1 2013-01-23 09:19:31

EvilKant
Member
Russia
1970-01-01
98

Piwigo and AJAX

I'm trying to learn AJAX. Can you give me some advises how using AJAX in plugins for piwigo? That is possible? I don't find plugins with ajax, except rv_tscroller, but it don't help me.

Offline

 

#2 2013-01-23 09:47:43

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: Piwigo and AJAX

[extension by mistic100] User Collections
[extension by mistic100] Batch Downloader
the core Batch Manager, plugins and themes updater
all my import plugins

all these use AJAX (with or without queue manager)


what do you want to do ?

Offline

 

#3 2013-01-23 18:11:53

EvilKant
Member
Russia
1970-01-01
98

Re: Piwigo and AJAX

mistic100 wrote:

what do you want to do ?

I want get data from database with AJAX.

I have question about {footer_script}. In BatchDownloader you write just

Code:

{footer_script require='jquery'}...{/footer_script}

and it is works. But I must write

Code:

{footer_script}{literal}...{/literal}{/footer_script}

. Without {literal} SMARTY swear javascript syntax. What I doing wrong?

Offline

 

#4 2013-01-23 18:13:49

flop25
Piwigo Team
2006-07-06
7037

Re: Piwigo and AJAX

Nope you're right. Literal is needed as soon as you write a {


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#5 2013-01-23 18:21:31

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: Piwigo and AJAX

or you escape all "{" with "{ldelim}" (if you need smarty variables inside the javascript, as I do)

Offline

 

#6 2013-01-23 18:25:07

flop25
Piwigo Team
2006-07-06
7037

Re: Piwigo and AJAX

mistic100 wrote:

or you escape all "{" with "{ldelim}" (if you need smarty variables inside the javascript, as I do)

Hs: I don't get it. Literal is way better : it's less Smarty tag finally and the js code is more readable and you need to care about forgetting {to escape. Maybe it's a matter of taste


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#7 2013-01-23 18:27:41

flop25
Piwigo Team
2006-07-06
7037

Re: Piwigo and AJAX

EvilKant wrote:

I understood! Instead "{" Mistic wrote "{ldelim}". I thought it is variable.

The Smarty documentation is very well;  you should take a look


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#8 2013-01-23 18:41:49

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: Piwigo and AJAX

flop25 wrote:

mistic100 wrote:

or you escape all "{" with "{ldelim}" (if you need smarty variables inside the javascript, as I do)

Hs: I don't get it. Literal is way better : it's less Smarty tag finally and the js code is more readable and you need to care about forgetting {to escape. Maybe it's a matter of taste

I agree if you have pure javascript, but sometimes I need smarty variables inside the javascript and I don't want to declare multiple JS variables

Offline

 

#9 2013-01-23 18:45:31

flop25
Piwigo Team
2006-07-06
7037

Re: Piwigo and AJAX

mistic100 wrote:

flop25 wrote:

mistic100 wrote:

or you escape all "{" with "{ldelim}" (if you need smarty variables inside the javascript, as I do)

Hs: I don't get it. Literal is way better : it's less Smarty tag finally and the js code is more readable and you need to care about forgetting {to escape. Maybe it's a matter of taste

I agree if you have pure javascript, but sometimes I need smarty variables inside the javascript and I don't want to declare multiple JS variables

Why not /literal var literal? That Washington my point


To get a better help : Politeness like Hello-A link-Your past actions precisely described
Check my extensions : more than 30 available
who I am and what I do : http://fr.gravatar.com/flop25
My gallery : an illustration of how to integrate Piwigo in your website

Offline

 

#10 2013-01-23 18:53:32

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: Piwigo and AJAX

this way I don't understand my code afterwards :)

imagine 10 {/literal}{$thats_my_vat}{literal}, I don't like it

Offline

 

#11 2013-01-30 17:46:26

EvilKant
Member
Russia
1970-01-01
98

Re: Piwigo and AJAX

I was turn Evil_Blog to AJAX. But now I have problem with support of Extended Description: I can't get ExDesc functions from separate php script. Do you have ideas?

Beta-version you can get here http://picmun.ru/Evil_Blog.zip

and codes:
separate php script which geting posts from database:

Code:

<?php
define('PHPWG_ROOT_PATH', '../../');
include(PHPWG_ROOT_PATH.'include/common.inc.php');

if (isset($_POST['number'])) {
    $query =   "SELECT id, UNIX_TIMESTAMP(date) AS date, header, text
          FROM `".Evil_Blog_Table."`
          WHERE 1
          ORDER BY `date` DESC
          LIMIT ".$_POST['number'].", 1";
    $result = pwg_query($query);
    $row = pwg_db_fetch_assoc($result); //более вменяемая обработка результата из базы, нужно для нормальной работы SMARTY
    if (isset($_POST['date_format'])){
      $row['date'] = date($_POST['date_format'], $row['date']);
      }
    $ExDesc = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';"));
    if($ExDesc['state'] == 'active') {
      $row['text'] = get_extended_desc($row['text']);
      $row['header'] = get_user_language_desc($row['header']);
      }
      $rez= $row['id'].'|'.$row['date'].'|'.$row['header'].'|'.$row['text'];
    echo $rez;
}

?>

and AJAX code in .tpl-file:

Code:

{footer_script require='jquery'}
  function ajax_load_post(n){ldelim}
    $.ajax({ldelim}
      url: "plugins/Evil_Blog/ajax_load_posts.php",  
      type: "POST",
      data: {ldelim} "number": n, "date_format": "{$date_format}"},
      async: false,
            success: function(data){ldelim}
            var posts = data.split('|');
            var header = 
              '<span class="post_title">'+
                {if isset($show_number) and $show_number}
                  '<span class="post_number">'+posts[0]+'</span> * '+
                {/if}
                '<span class="post_header"><a href="{$ROOT_URL}?/blog/id/'+posts[0]+'">'+posts[2]+'</a></span>'+
                {if isset($show_date) and $show_date}
                  '<span class="post_date">'+posts[1]+'</span>'+
                {/if}
              '</span>';
            $('<li class="thumbnailCategory" id="post_'+n+'"></li>')
              .hide()
              .append(header)
              .append('<div class="post_description">'+posts[3]+'</div>')
              .appendTo('.evil_blog_posts')
              .fadeIn(500);
            }
      });
    };
  $(document).ready(function() {ldelim}
    for (var i = 0; i <= {$post_per_page-1}; i++) {ldelim} 
      ajax_load_post({$number}+i);
      }
    });
{/footer_script}

Offline

 
  •  » Engine
  •  » Piwigo and AJAX

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact