News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

How to create custom page?

Started by MiB3Avenger, April 28, 2015, 04:33:24 AM

Previous topic - Next topic

MiB3Avenger

Hello all!

I want to create one page, which has the url: www.mysite.com/index.php?action=page [nofollow]. I've edited subs.php and added the tab for it also added
'href' => $scripturl . '?action=page'. Now I want to create a page so that the code within it appears in the url mentioned above and not www.mysite.com/page.php [nofollow]

How shall I do it?


MiB3Avenger

I did the things in that, but when I enter www.mysite.com/index.php?action=page [nofollow], it shows "Unable to load the 'main' template." What should I do now?

Edit: I tried to do it once again, and now it works. @Mods can lock this topic.

MiB3Avenger

When I tried to add require() in custom action, it shows the following error:

QuoteFatal error: require(): Failed opening required './simpledom.php' (include_path='.:/opt/php-5.5/pear') in /home/u690784558/public_html/forum/Sources/Load.php(2204) : eval()'d code on line 17

What should I do to fix this?

Kindred

1- what do you mean "in custom action"?
2- What was the full code that you attempted to add?
3- where is your simpledom.php file located

4- this is not a support request, this is a coding question. (moving)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

MiB3Avenger

1: Adding a custom action, like in here.
2:
Quoterequire("./simpledom.php");
   
   function file_get_contents_curl($url)
   {
      $ch = curl_init();

      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
      curl_setopt($ch, CURLOPT_URL, $url);
      
      if(preg_match("/https/is", $url)) curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

      $data = curl_exec($ch);
      curl_close($ch);
      
      return $data;
   }

   $link = "http://prakashsoft.co.in/index.html"; [nofollow]
   
   $html = str_get_html(file_get_contents_curl($link));
        echo $html
3: It's located the main directory, "public_html".
@Kindred

Kindred

that is not how you add a custom action...

a custom action is added to the action array in the root forum index.php


'youraction' => array('YourAction.php', 'YourActionMain'),


you, on the other hand, appear to have added a required include file...
which, apparently the system can not find.

Where (what file?) did you add the code that you listed?

Where (what directory) is your SMF installation located in?


also, please do not start multiple topics on the same question... even if it is two sides to the question, the fatal error on include and the unable to local main template are both due (based on your description) to your attempts to perform a custom action....



Once you have created the custom action and called the function/file from the action array, you have to correctly build the file... which includes calls to the templates - per the wiki page.
Please include (or attach) your custom action php file?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

MiB3Avenger

Well, adding custom action was not a problem.

I've added an apps.template.php in /Themes/default directory and apps.php in Sources directory as given in the Adding Custom Action page. The simpledom.php is in the main directory which is /public_html directory. The SMF is in /public_html/forum directory.

Edit:
apps.php:
Quote<?php

// First of all, we make sure we are accessing the source file via SMF so that people can not directly access the file.
if (!defined('SMF'))
   die('Hack Attempt...');

function appsMain()
{

   // Second, give ourselves access to all the global variables we will need for this action
   global $context, $scripturl, $txt, $smcFunc;

   // Third, Load the specialty template for this action.
   loadTemplate('apps');

   //Fourth, Come up with a page title for the main page
   $context['page_title'] = $txt['apps_PageTitle'];
   $context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title']));


   //Fifth, define the navigational link tree to be shown at the top of the page.
   $context['linktree'][] = array(
        'url' => $scripturl. '?action=apps',
      'name' => $txt['apps'],
   );

   //Sixth, begin doing all the stuff that we want this action to display
   //    Store the results of this stuff in the $context array. 
   //    This action's template(s) will display the contents of $context.
   $context['apps_Head'] = $txt['apps'];
}

?>
apps.template.php:
Quote<?php

function template_main()
{

   // Make sure we have all the global variables we need
   global $context;

   // Catbg header
   echo '<div class="cat_bar">
            <h3 class="catbg">', $context['apps_Head'], '</h3>
   </div>';

   // Windowbg2 Content
   echo '<div class="windowbg2">
           <span class="topslice"><span></span></span>
                <div class="content">', require './simpledom.php';
   
   function file_get_contents_curl($url)
   {
      $ch = curl_init();

      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
      curl_setopt($ch, CURLOPT_URL, $url);
      
      if(preg_match("/https/is", $url)) curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

      $data = curl_exec($ch);
      curl_close($ch);
      
      return $data;
   }

   $link = "http://prakashsoft.co.in/index.html"; [nofollow]
   
   $html = str_get_html(file_get_contents_curl($link));
    echo $html, '</div>
           <span class="botslice"><span></span></span>
   </div><br />';

}

?>
Edit 2: Sorry for making 2 topics, I'll make sure that this won't happen next time.

Kindred

Quote from: MiB3Avenger on April 28, 2015, 07:56:54 AM
The simpledom.php is in the main directory which is /public_html directory. The SMF is in /public_html/forum directory.

and that would be your problem....


  require("./simpledom.php");

is looking for the simpledom.php file in the same directory as SMF...
  require("../simpledom.php");
(what file are you running the "require" and that new function in, anyway?)
(personally, I almost always use absolute paths when building my own, custom includes...)




As for your custom action...

did you build a template_main function in your template file?
did you build a loadTemplate function into your source file?


Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

MiB3Avenger

I just followed the steps given in the page here

Kindred

you keep repeating that you followed those steps...   and yet, your results suggest otherwise.

Please include the files that I asked for so that we can confirm your code
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: