plugins/SpecialPageFuncs.php
changeset 335 67bd3121a12e
parent 334 c72b545f1304
child 343 eefe9ab7fe7c
equal deleted inserted replaced
334:c72b545f1304 335:67bd3121a12e
    70 // function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace>
    70 // function names are IMPORTANT!!! The name pattern is: page_<namespace ID>_<page URLname, without namespace>
    71 
    71 
    72 function page_Special_CreatePage()
    72 function page_Special_CreatePage()
    73 {
    73 {
    74   global $db, $session, $paths, $template, $plugins; // Common objects
    74   global $db, $session, $paths, $template, $plugins; // Common objects
       
    75   global $lang;
       
    76   
    75   if ( isset($_POST['do']) )
    77   if ( isset($_POST['do']) )
    76   {
    78   {
    77     $p = $_POST['pagename'];
    79     $p = $_POST['pagename'];
    78     $k = array_keys($paths->nslist);
    80     $k = array_keys($paths->nslist);
    79     for ( $i = 0; $i < sizeof( $paths->nslist ); $i++ )
    81     for ( $i = 0; $i < sizeof( $paths->nslist ); $i++ )
    86     }
    88     }
    87     if ( $namespace == 'Special' || ( $namespace == 'System' && $session->user_level < USER_LEVEL_ADMIN ) || $namespace == 'Admin')
    89     if ( $namespace == 'Special' || ( $namespace == 'System' && $session->user_level < USER_LEVEL_ADMIN ) || $namespace == 'Admin')
    88     {
    90     {
    89       $template->header();
    91       $template->header();
    90       
    92       
    91       echo '<h3>The page could not be created.</h3><p>The name "'.$p.'" is invalid.</p>';
    93       echo '<h3>' . $lang->get('pagetools_create_err_title') . '</h3>
       
    94              <p>' . $lang->get('pagetools_create_err_name_invalid', array('page_name' => htmlspecialchars($p))) . '</p>';
    92       
    95       
    93       $template->footer();
    96       $template->footer();
    94       $db->close();
    97       $db->close();
    95       
    98       
    96       exit;
    99       exit;
   100     $namespace = $_POST['namespace'];
   103     $namespace = $_POST['namespace'];
   101     if ( $namespace == 'Special' || ( $namespace == 'System' && $session->user_level < USER_LEVEL_ADMIN ) || $namespace == 'Admin')
   104     if ( $namespace == 'Special' || ( $namespace == 'System' && $session->user_level < USER_LEVEL_ADMIN ) || $namespace == 'Admin')
   102     {
   105     {
   103       $template->header();
   106       $template->header();
   104       
   107       
   105       echo '<h3>The page could not be created.</h3><p>The name "'.$paths->nslist[$namespace].$p.'" is invalid.</p>';
   108       echo '<h3>' . $lang->get('pagetools_create_err_title') . '</h3>
       
   109              <p>' . $lang->get('pagetools_create_err_name_invalid', array('page_name' => htmlspecialchars($paths->nslist[$namespace].$p))) . '</p>';
   106       
   110       
   107       $template->footer();
   111       $template->footer();
   108       $db->close();
   112       $db->close();
   109       
   113       
   110       exit;
   114       exit;
   116     }
   120     }
   117     if ( substr($urlname, 0, 8) == 'Project:' )
   121     if ( substr($urlname, 0, 8) == 'Project:' )
   118     {
   122     {
   119       $template->header();
   123       $template->header();
   120       
   124       
   121       echo '<h3>The page could not be created.</h3><p>The page title can\'t start with "Project:" because this prefix is reserved for a parser shortcut.</p>';
   125       echo '<h3>' . $lang->get('pagetools_create_err_title') . '</h3>
       
   126              <p>' . $lang->get('pagetools_create_err_project_shortcut', array('page_name' => htmlspecialchars($p))) . '</p>';
   122       
   127       
   123       $template->footer();
   128       $template->footer();
   124       $db->close();
   129       $db->close();
   125       
   130       
   126       exit;
   131       exit;
   127     }
   132     }
   128     
   133     
   129     $tn = $paths->nslist[$_POST['namespace']] . $urlname;
   134     $tn = $paths->nslist[$_POST['namespace']] . $urlname;
   130     if ( isset($paths->pages[$tn]) )
   135     if ( isset($paths->pages[$tn]) )
   131     {
   136     {
   132       die_friendly('Error creating page', '<p>The page already exists.</p>');
   137       die_friendly($lang->get('pagetools_create_err_title'), '<p>' . $lang->get('pagetools_create_err_already_exist') . '</p>');
   133     }
   138     }
   134     
   139     
   135     if ( $paths->nslist[$namespace] == substr($urlname, 0, strlen($paths->nslist[$namespace]) ) )
   140     if ( $paths->nslist[$namespace] == substr($urlname, 0, strlen($paths->nslist[$namespace]) ) )
   136     {
   141     {
   137       $urlname = substr($urlname, strlen($paths->nslist[$namespace]), strlen($urlname));
   142       $urlname = substr($urlname, strlen($paths->nslist[$namespace]), strlen($urlname));
   152     $urlname = sanitize_page_id($urlname);
   157     $urlname = sanitize_page_id($urlname);
   153     $urlname = $db->escape($urlname);
   158     $urlname = $db->escape($urlname);
   154     
   159     
   155     $perms = $session->fetch_page_acl($urlname, $namespace);
   160     $perms = $session->fetch_page_acl($urlname, $namespace);
   156     if ( !$perms->get_permissions('create_page') )
   161     if ( !$perms->get_permissions('create_page') )
   157       die_friendly('Error creating page', '<p>An access control rule is preventing you from creating pages.</p>');
   162       die_friendly($lang->get('pagetools_create_err_title'), '<p>An access control rule is preventing you from creating pages.</p>');
   158     
   163     
   159     $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'create\', \''.$session->username.'\', \''.$urlname.'\', \''.$_POST['namespace'].'\');');
   164     $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,author,page_id,namespace) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'create\', \''.$session->username.'\', \''.$urlname.'\', \''.$_POST['namespace'].'\');');
   160     if ( !$q )
   165     if ( !$q )
   161     {
   166     {
   162       $db->_die('The page log could not be updated.');
   167       $db->_die('The page log could not be updated.');
   186     $db->close();
   191     $db->close();
   187     
   192     
   188     exit;
   193     exit;
   189   }
   194   }
   190   */
   195   */
   191   echo RenderMan::render('Using the form below you can create a page.');
   196   echo '<p>' . $lang->get('pagetools_create_blurb') . '</p>';
   192   ?>
   197   ?>
   193   <form action="" method="post">
   198   <form action="" method="post">
   194     <p>
   199     <p>
   195       <select name="namespace">
   200       <select name="namespace">
   196         <?php
   201         <?php
   197         $k = array_keys($paths->nslist);
   202         $k = array_keys($paths->nslist);
   198         for ( $i = 0; $i < sizeof($k); $i++ )
   203         for ( $i = 0; $i < sizeof($k); $i++ )
   199         {
   204         {
   200           if ( $paths->nslist[$k[$i]] == '' )
   205           if ( $paths->nslist[$k[$i]] == '' )
   201           {
   206           {
   202             $s = '[No prefix]';
   207             $s = $lang->get('pagetools_create_namespace_none');
   203           }
   208           }
   204           else
   209           else
   205           {
   210           {
   206             $s = $paths->nslist[$k[$i]];
   211             $s = $paths->nslist[$k[$i]];
   207           }
   212           }
   210             echo '<option value="'.$k[$i].'">'.$s.'</option>';
   215             echo '<option value="'.$k[$i].'">'.$s.'</option>';
   211           }
   216           }
   212         }
   217         }
   213         ?>
   218         ?>
   214       </select> <input type="text" name="pagename" /></p>
   219       </select> <input type="text" name="pagename" /></p>
   215       <p><input type="submit" name="do" value="Create Page" /></p>
   220       <p><input type="submit" name="do" value="<?php echo $lang->get('pagetools_create_btn_create'); ?>" /></p>
   216   </form>
   221   </form>
   217   <?php
   222   <?php
   218   $template->footer();
   223   $template->footer();
   219 }
   224 }
   220 
   225 
   261 
   266 
   262 function page_Special_AllPages() 
   267 function page_Special_AllPages() 
   263 {
   268 {
   264   // This should be an easy one
   269   // This should be an easy one
   265   global $db, $session, $paths, $template, $plugins; // Common objects
   270   global $db, $session, $paths, $template, $plugins; // Common objects
       
   271   global $lang;
       
   272   
   266   $template->header();
   273   $template->header();
   267   $sz = sizeof( $paths->pages ) / 2;
   274   $sz = sizeof( $paths->pages ) / 2;
   268   echo '<p>Below is a list of all of the pages on this website.</p>';
   275   echo '<p>' . $lang->get('pagetools_allpages_blurb') . '</p>';
   269   
   276   
   270   $q = $db->sql_query('SELECT COUNT(urlname) FROM '.table_prefix.'pages WHERE visible!=0;');
   277   $q = $db->sql_query('SELECT COUNT(urlname) FROM '.table_prefix.'pages WHERE visible!=0;');
   271   if ( !$q )
   278   if ( !$q )
   272     $db->_die();
   279     $db->_die();
   273   $row = $db->fetchrow_num();
   280   $row = $db->fetchrow_num();
   326 {
   333 {
   327   // This should be an easy one
   334   // This should be an easy one
   328   global $db, $session, $paths, $template, $plugins; // Common objects
   335   global $db, $session, $paths, $template, $plugins; // Common objects
   329   $template->header();
   336   $template->header();
   330   $sz = sizeof($paths->pages) / 2;
   337   $sz = sizeof($paths->pages) / 2;
   331   echo '<p>Below is a list of all of the special pages on this website.</p><div class="tblholder"><table border="0" width="100%" cellspacing="1" cellpadding="4">';
   338   echo '<p>' . $lang->get('pagetools_specialpages_blurb') . '</p><div class="tblholder"><table border="0" width="100%" cellspacing="1" cellpadding="4">';
   332   $cclass='row1';
   339   $cclass='row1';
   333   for ( $i = 0; $i < $sz; $i = $i)
   340   for ( $i = 0; $i < $sz; $i = $i)
   334   {
   341   {
   335     if ( $cclass == 'row1' )
   342     if ( $cclass == 'row1' )
   336     {
   343     {
   384   $template->header();
   391   $template->header();
   385   ?>
   392   ?>
   386   <br />
   393   <br />
   387   <div class="tblholder">
   394   <div class="tblholder">
   388     <table border="0" cellspacing="1" cellpadding="4">
   395     <table border="0" cellspacing="1" cellpadding="4">
   389       <tr><th colspan="2" style="text-align: left;">About the Enano Content Management System</th></tr>
   396       <tr><th colspan="2" style="text-align: left;"><?php echo $lang->get('meta_enano_about_th'); ?></th></tr>
   390       <tr><td colspan="2" class="row3">
   397       <tr><td colspan="2" class="row3">
   391         <?php
   398         <?php
   392         echo $lang->get('meta_enano_about_poweredby');
   399         echo $lang->get('meta_enano_about_poweredby');
   393         $subst = array(
   400         $subst = array(
   394             'gpl_link' => makeUrlNS('Special', 'GNU_General_Public_License')
   401             'gpl_link' => makeUrlNS('Special', 'GNU_General_Public_License')
   499 }
   506 }
   500 
   507 
   501 function page_Special_GNU_General_Public_License()
   508 function page_Special_GNU_General_Public_License()
   502 {
   509 {
   503   global $db, $session, $paths, $template, $plugins; // Common objects
   510   global $db, $session, $paths, $template, $plugins; // Common objects
       
   511   global $lang;
       
   512   
   504   $template->header();
   513   $template->header();
   505   if(file_exists(ENANO_ROOT.'/GPL'))
   514   if(file_exists(ENANO_ROOT . '/GPL'))
   506   {
   515   {
       
   516     echo '<p>' . $lang->get('pagetools_gpl_blurb', array('about_url' => makeUrlNS('Special', 'About_Enano'))) . '</p>';
       
   517     
       
   518     if ( $lang->lang_code != 'eng' ):
       
   519     // Do not remove this block of code. Doing so is a violation of the GPL. (A copy of the GPL in other languages
       
   520     // must be accompanied by a copy of the English GPL.)
   507     echo '<p>The following text represents the license that the <a href="'.makeUrlNS('Special', 'About_Enano').'">Enano</a> content management system is under. To make it easier to read, the text has been wiki-formatted; in no other way has it been changed.</p>';
   521     echo '<p>The following text represents the license that the <a href="'.makeUrlNS('Special', 'About_Enano').'">Enano</a> content management system is under. To make it easier to read, the text has been wiki-formatted; in no other way has it been changed.</p>';
       
   522     endif;
       
   523     
       
   524     if ( file_exists(ENANO_ROOT . "/GPL_{$lang->lang_code}") )
       
   525     {
       
   526       echo '<h2>' . $lang->get('pagetools_gpl_title_native') . '</h2>';
       
   527       echo '<p><a href="#gpl_english">' . $lang->get('pagetools_gpl_link_to_english') . ' / View the license in English' . '</a></p>';
       
   528       echo RenderMan::render( file_get_contents ( ENANO_ROOT . "/GPL_{$lang->lang_code}" ) );
       
   529       echo '<h2>' . $lang->get('pagetools_gpl_title_english') . ' / English version<a name="gpl_english" id="gpl_english"></a></h2>';
       
   530     }
       
   531     
   508     echo RenderMan::render( file_get_contents ( ENANO_ROOT . '/GPL' ) );
   532     echo RenderMan::render( file_get_contents ( ENANO_ROOT . '/GPL' ) );
   509   }
   533   }
   510   else
   534   else
   511   {
   535   {
   512     echo '<p>It appears that the file "GPL" is missing from your Enano installation. You may find a wiki-formatted copy of the GPL at: <a href="http://enanocms.org/GPL">http://enanocms.org/GPL</a>.</p>';
   536     echo '<p>' . $lang->get('pagetools_gpl_err_file_missing') . '</p>';
       
   537     if ( $lang->lang_code != 'eng')
       
   538       // Also print out English version
       
   539       // Do not remove the following line of code; doing so would be a violation of the GPL.
       
   540       echo '<p>It appears that the file "GPL" is missing from your Enano installation. You may find a wiki-formatted copy of the GPL at: <a href="http://enanocms.org/GPL">http://enanocms.org/GPL</a>. In the mean time, you may wish to contact the site administration and ask them to replace the GPL file.</p>';
   513   }
   541   }
   514   $template->footer();
   542   $template->footer();
   515 }
   543 }
   516 
   544 
   517 function page_Special_TagCloud()
   545 function page_Special_TagCloud()
   518 {
   546 {
   519   global $db, $session, $paths, $template, $plugins; // Common objects
   547   global $db, $session, $paths, $template, $plugins; // Common objects
       
   548   global $lang;
   520   
   549   
   521   $template->header();
   550   $template->header();
   522   
   551   
   523   if ( $tag = $paths->getParam(0) )
   552   if ( $tag = $paths->getParam(0) )
   524   {
   553   {
   528       $db->_die();
   557       $db->_die();
   529     if ( $row = $db->fetchrow() )
   558     if ( $row = $db->fetchrow() )
   530     {
   559     {
   531       echo '<div class="tblholder">
   560       echo '<div class="tblholder">
   532               <table border="0" cellspacing="1" cellpadding="4">';
   561               <table border="0" cellspacing="1" cellpadding="4">';
   533       echo '<tr><th colspan="2">Pages tagged "' . htmlspecialchars($tag) . '"</th></tr>';
   562       echo '<tr><th colspan="2">' . $lang->get('pagetools_tagcloud_pagelist_th', array('tag' => htmlspecialchars($tag))) . '</th></tr>';
   534       echo '<tr>';
   563       echo '<tr>';
   535       $i = 0;
   564       $i = 0;
   536       $td_class = 'row1';
   565       $td_class = 'row1';
   537       do
   566       do
   538       {
   567       {
   557         $i++;
   586         $i++;
   558         echo "<td class=\"$td_class\" style=\"width: 50%;\"></td>";
   587         echo "<td class=\"$td_class\" style=\"width: 50%;\"></td>";
   559       }
   588       }
   560       // " workaround for jEdit highlighting bug
   589       // " workaround for jEdit highlighting bug
   561       echo '<tr>
   590       echo '<tr>
   562               <th colspan="2" class="subhead"><a href="' . makeUrlNS('Special', 'TagCloud') . '" style="color: white;">&laquo; Return to tag cloud</a></th>
   591               <th colspan="2" class="subhead"><a href="' . makeUrlNS('Special', 'TagCloud') . '">&laquo; ' . $lang->get('pagetools_tagcloud_btn_return') . '</a></th>
   563             </tr>';
   592             </tr>';
   564       echo '</table>';
   593       echo '</table>';
   565       echo '</div>';
   594       echo '</div>';
   566     }
   595     }
   567   }
   596   }
   572     $q = $db->sql_query('SELECT tag_name FROM '.table_prefix.'tags;');
   601     $q = $db->sql_query('SELECT tag_name FROM '.table_prefix.'tags;');
   573     if ( !$q )
   602     if ( !$q )
   574       $db->_die();
   603       $db->_die();
   575     if ( $db->numrows() < 1 )
   604     if ( $db->numrows() < 1 )
   576     {
   605     {
   577       echo '<p>No pages are tagged yet.</p>';
   606       echo '<p>' . $lang->get('pagetools_tagcloud_msg_no_tags') . '</p>';
   578     }
   607     }
   579     else
   608     else
   580     {
   609     {
   581       echo '<h3>Summary of page tagging</h3>';
   610       echo '<h3>' . $lang->get('pagetools_tagcloud_blurb') . '</h3>';
   582       while ( $row = $db->fetchrow() )
   611       while ( $row = $db->fetchrow() )
   583       {
   612       {
   584         $cloud->add_word($row['tag_name']);
   613         $cloud->add_word($row['tag_name']);
   585       }
   614       }
   586       echo $cloud->make_html('normal');
   615       echo $cloud->make_html('normal');
   587       echo '<p>Hover your mouse over a tag to see how many pages have the tag. Click on a tag to see a list of the pages that have it.</p>';
   616       echo '<p>' . $lang->get('pagetools_tagcloud_instructions') . '</p>';
   588     }
   617     }
   589   }
   618   }
   590   
   619   
   591   $template->footer();
   620   $template->footer();
   592 }
   621 }
   593 
   622 
   594 // tag cloud sidebar block
   623 // tag cloud sidebar block
   595 function sidebar_add_tag_cloud()
   624 function sidebar_add_tag_cloud()
   596 {
   625 {
   597   global $db, $session, $paths, $template, $plugins; // Common objects
   626   global $db, $session, $paths, $template, $plugins; // Common objects
       
   627   global $lang;
   598   $cloud = new TagCloud();
   628   $cloud = new TagCloud();
   599     
   629     
   600   $q = $db->sql_query('SELECT tag_name FROM '.table_prefix.'tags;');
   630   $q = $db->sql_query('SELECT tag_name FROM '.table_prefix.'tags;');
   601   if ( !$q )
   631   if ( !$q )
   602     $db->_die();
   632     $db->_die();
   603   if ( $db->numrows() < 1 )
   633   if ( $db->numrows() < 1 )
   604   {
   634   {
   605     $sb_html = 'No pages are tagged yet.';
   635     $sb_html = $lang->get('pagetools_tagcloud_msg_no_tags');
   606   }
   636   }
   607   else
   637   else
   608   {
   638   {
   609     while ( $row = $db->fetchrow() )
   639     while ( $row = $db->fetchrow() )
   610     {
   640     {
   611       $cloud->add_word($row['tag_name']);
   641       $cloud->add_word($row['tag_name']);
   612     }
   642     }
   613     $sb_html = $cloud->make_html('small', 'justify') . '<br /><a style="text-align: center;" href="' . makeUrlNS('Special', 'TagCloud') . '">Larger version</a>';
   643     $sb_html = $cloud->make_html('small', 'justify') . '<br /><a style="text-align: center;" href="' . makeUrlNS('Special', 'TagCloud') . '">' . $lang->get('pagetools_tagcloud_sidebar_btn_larger') . '</a>';
   614   }
   644   }
   615   $template->sidebar_widget('Tag cloud', "<div style='padding: 5px;'>$sb_html</div>");
   645   $template->sidebar_widget($lang->get('pagetools_tagcloud_sidebar_title'), "<div style='padding: 5px;'>$sb_html</div>");
   616 }
   646 }
   617 
   647 
   618 $plugins->attachHook('compile_template', 'sidebar_add_tag_cloud();');
   648 $plugins->attachHook('compile_template', 'sidebar_add_tag_cloud();');
   619 
   649 
   620 ?>
   650 ?>