Announcement

  •  » Extensions
  •  » Creating plug-in "Blog for mainpage"

#1 2012-04-06 14:15:18

EvilKant
Member
Russia
1970-01-01
98

Creating plug-in "Blog for mainpage"

I try create my plug-in like a little blog on mainpage of piwigo. It is allready working on my local server - posts from database showing on mainpage, just need cosmetic improvements. I stopped at paginal output. I try use standart GET-method to send page numbers for script, but piwigo dont understand it and display only simple mainpage. In 'additional pages' plug-in I spied array $tokens and try use it like in 'additional pages' - no effect. Can you advise something? Somewhere exist a technical documentation in English?

Last edited by EvilKant (2012-04-06 14:21:22)

Offline

 

#2 2012-04-06 22:46:22

flop25
Piwigo Team
2006-07-06
7037

Re: Creating plug-in "Blog for mainpage"

Hello
good news to see someone doing a great usefull project like that
Could you show us some code ?
About docs, the French one is much more documented, but not so technical; the best way is to learn with examples. I did the same


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

 

#3 2012-04-07 11:02:23

EvilKant
Member
Russia
1970-01-01
98

Re: Creating plug-in "Blog for mainpage"

posts.tpl

Code:

{php}
  global $tokens;
  $post_per_page = 5;
///////Here I try get number of page from previous session///////////////
  if ($tokens[0] == 'blog_page') {
    if ((!empty($tokens[1])) and ($tokens[1]<=0)) {
      $number = 0;
      } else {
      $npage = $tokens[1];
      $number=($tokens[1]-1)*$post_per_page;
      }
    } else { $number = 0; }
/////////////////////////////////////////////////////////////////////////////////////    
  error_reporting(0);
  $link = mysqli_connect("localhost", "*****", "*****", "picmun");
  if (!$link) {
    echo "MySQL говорит об ошибке: " . mysqli_connect_error();
    }
  
  $query =   "SELECT *
        FROM `evil_blog`
        WHERE 1
        ORDER BY `date` DESC
        LIMIT ".$number.",".$post_per_page;
  $result = mysqli_query($link, $query);  
{/php}
  
  <div class='content' id="comments">
    <div class="titrePage">Новости!
      <ul class="categoryActions"><li>
      </li></ul>
    </div>
    <ul class="thumbnailCategories">
      {php} while ($row = mysqli_fetch_array($result)) { {/php}
        <li>
          <div class="thumbnailCategory">
            {php} echo $row["id"]."* ". $row["date"]." - ".$row["header"];{/php}
            <div class="description">
              {php} echo $row["text"];{/php}
            </div>
          </div>
        </li>
      {php} } {/php}
    </ul>
    <form action="" method="GET">
    
    {php}
      $result = mysqli_query($link, "SELECT COUNT(*) FROM `evil_blog`");  
      $row = mysqli_fetch_array($result);
      $pages = ($row["COUNT(*)"] / $post_per_page)+1;
    {/php}

///////////////////////////Navigation Bar///////////////////////////////////////
    <div class="navigationBar">
      <a href="index.php" rel="first">{'First'|@translate}</a> |
      <a href="index.php?/blog_page/{php}echo $npage-1;{/php}" rel="prev">{'Previous'|@translate}</a> |
          {php}
          for ($it=1; $it<=$pages; $it++) {
            echo '<span class=""><a href="index.php?/blog_page/'.$it.'">'.$it.'</a> | </span>';
          }
          {/php}
      <a href="index.php?/blog_page/{php}echo $npage+1;{/php}" rel="next">{'Next'|@translate}</a> |
      <a href="index.php?/blog_page/{php}echo $pages;{/php}" rel="last">{'Last'|@translate}</a>
    </div>
////////////////////////////////////////////////////////////////////////////////////
    </form>
  </div>
  
{php}  mysqli_close($link);

{/php}

I don't use SMARTY, becouse I want learn PHP.

Maybe I must register $tokens's values? But in "Additional pages" I have not found something like this.

Last edited by EvilKant (2012-04-07 11:37:15)

Offline

 

#4 2012-04-07 13:41:33

flop25
Piwigo Team
2006-07-06
7037

Re: Creating plug-in "Blog for mainpage"

I think you just misunderstood the tokens : its a security protection when sensible data are transmitted. A unique string is generated for a very limited time : it's the token
The pagination is used -as far as i remember- in the global $page : you can use this variable too


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 2012-04-07 17:59:50

EvilKant
Member
Russia
1970-01-01
98

Re: Creating plug-in "Blog for mainpage"

I forgot about POST-method. Whith POST all is working... Now I need turn <a> to "submit".

Offline

 

#6 2012-04-09 19:26:23

EvilKant
Member
Russia
1970-01-01
98

Re: Creating plug-in "Blog for mainpage"

Damn... I begin hate jQuery...

If I do this:

Code:

echo "<input type='text' name='npage'>";
echo "<input type='submit' value='Send'>";

All is working. I can see and first, and second page of blog.

But if I try do this with jQuery, all is not working:

Code:

<script type="text/javascript">{literal}    
    $(function(){
      $('.blog_pagination').click(function() {
        $.post('index.php', {npage: '2'}); //here I just want see second page, but still see first page, and $_POST array still empty.
        });
    return false;
    });
    {/literal}
    </script>
<a class='blog_pagination' href='' rel='".$it."'>".$it."</a>

I think, I misunderstood $.post function, but google can't advise something other... Everything works except line with $.post .

Until I find a solution to this problem, I can't begin do other parts :( . Without paginal output plugin will be unusable.

Offline

 

#7 2012-04-09 22:34:43

EvilKant
Member
Russia
1970-01-01
98

Re: Creating plug-in "Blog for mainpage"

At last I found a solution! I did hidden input and with javascript send data like from form.

Code:

 
<script type="text/javascript">{literal}    
    function subnum (num) {
      document.blog_pagination.npage.value=num;
      document.blog_pagination.submit();
    }
    {/literal}
    </script>
{php}
echo "<input type='text' name='npage' style='visibility: hidden; position: absolute;'>";
for ($it=1; $it<=$pages; $it++) {
  echo "<a class='blog_pagination' href='#' onclick='subnum(";
  echo '"'.$it.'"';
  echo ")'>".$it."</a> | ";
  }
{/php}

Offline

 

#8 2012-06-24 20:22:50

EvilKant
Member
Russia
1970-01-01
98

Re: Creating plug-in "Blog for mainpage"

Offline

 

#9 2012-06-24 20:42:26

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: Creating plug-in "Blog for mainpage"

:-)
Can you add on SVN ?


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#10 2012-06-24 22:15:02

EvilKant
Member
Russia
1970-01-01
98

Re: Creating plug-in "Blog for mainpage"

ddtddt wrote:

:-)
Can you add on SVN ?

First I must understand how it works

Offline

 

#11 2012-06-24 23:02:02

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: Creating plug-in "Blog for mainpage"

EvilKant wrote:

ddtddt wrote:

:-)
Can you add on SVN ?

First I must understand how it works

What your OS ?
mac ? linux ? windows ?


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#12 2012-06-24 23:18:47

EvilKant
Member
Russia
1970-01-01
98

Re: Creating plug-in "Blog for mainpage"

ddtddt wrote:

What your OS ?
mac ? linux ? windows ?

windows XP

Offline

 

#13 2012-06-24 23:21:41

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: Creating plug-in "Blog for mainpage"

EvilKant wrote:

ddtddt wrote:

What your OS ?
mac ? linux ? windows ?

windows XP

Dowload and install tortoiseSVN -> http://tortoisesvn.net/downloads.html ;-)


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#14 2012-06-25 18:23:37

skpManiac
Member
England
2012-02-15
140

Re: Creating plug-in "Blog for mainpage"

Hi there, I've not got this installed yet, but it sounds great - are you going to update it for 2.4?


Share & Enjoy

Offline

 

#15 2012-06-25 23:21:49

EvilKant
Member
Russia
1970-01-01
98

Re: Creating plug-in "Blog for mainpage"

skpManiac wrote:

Hi there, I've not got this installed yet, but it sounds great - are you going to update it for 2.4?

EdwinKort wrote:

And it works with 2.4 :)

Offline

 
  •  » Extensions
  •  » Creating plug-in "Blog for mainpage"

Board footer

Powered by FluxBB

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