Jump to content

How do I add an admin panel/page to processwire where I can see reported content?


desbest
 Share

Recommended Posts

I am new to processwire and I want to have a processwire site where people click a link to report a page then I login to the admin panel and see all the pieces of content, or pages that were reported. Then I choose to delete the page or keep it up and class the report as "read" instead of unread so it's no longer on my system.

However I don't see any good tutorials on how to create modules, and the module API is just a list of functions, so there's no way for me to know how to get started coding this.

In fact I am trying to see if creating a site like this would be much quicker than using a framework like CodeIgniter, Laravel, Yii or CakePHP.

  • Like 1
Link to comment
Share on other sites

1 hour ago, desbest said:

I am new to processwire and I want to have a processwire site where people click a link to report a page then I login to the admin panel and see all the pieces of content, or pages that were reported. Then I choose to delete the page or keep it up and class the report as "read" instead of unread so it's no longer on my system.

However I don't see any good tutorials on how to create modules, and the module API is just a list of functions, so there's no way for me to know how to get started coding this.

In fact I am trying to see if creating a site like this would be much quicker than using a framework like CodeIgniter, Laravel, Yii or CakePHP.

Hi the truth is, you must dedicate some time to understand how Processwire works, I went through this *trap* trying to to apply MVC concept in Processwire, once you get the philosphy behind Processwire, it will be easy to work according to PW way, however you can visit my link it's been updated to adding content to your admin, most likely to finish that today, I have too much task and personal issues taking my time sadly. 

  • Like 2
Link to comment
Share on other sites

@desbest: You don't even need to write a module for that kind of thing, but you will have to build the logic for reporting and storing reported pages somewhere - that storage though may well be a page in the admin with e.g. a Page Table field or a Repeater, but you'll have to read up on those a bit to get a feel for what each entails. The logic to report a page can be built into the main page or into a page on its own (with its own template), where the later options gives you more flexibility and avoids a page reload if you popup the form for reporting in an iframe. Your backend interface to the reported pages list can then be built using the AdminCustomPages module.

Since you're new to PW, there will be a bit of a learning curve, and I'd guess that it won't be much quicker initially than using a barebone framework where you can plumb a few odd pieces together until it works, but in the long run, it will be far easier to extend and much more intuitive to maintain, since all you'll be dealing with will be PW pages and fields.

Link to comment
Share on other sites

12 hours ago, cstevensjr said:

A simple google search "create processwire module" or "processwire module tutorial" will give you many pieces of useful information.

As someone who has used php and ruby frameworks and has made a Magento plugin which is one of the hardest plugins to make, I do not find Processwire beginner friendly.  :(

I found...

http://soma.urlich.ch/posts/create-a-helper-module-for-processwire/

http://www.flamingruby.com/blog/taking-apart-a-simple-textformatter-module/

http://designtutorial.website/extending-the-processwire-admin-using-custom-modules

https://webdesign.tutsplus.com/tutorials/a-beginners-introduction-to-writing-modules-in-processwire--cms-26862

https://webdesign.tutsplus.com/tutorials/extending-the-processwire-admin-using-custom-modules--cms-26863

 

12 hours ago, fbg13 said:

Take a look here

I haven't read it all but it covers what you need to some extent.

I've done that now and all that comes up is how to make X module, instead of here is all the Y's you need to make whatever module you have in mind.

How to create a Hello World module, how to create a text formatter module, and one two of the tutorials found with google do not work, there is nothing about how to create the module I want to create. Part of reporting links (or pages) which I want my module to do, is to check the reported links in the admin panel for link rot, and delete the bad outdated links and once a report is viewed it becomes read. None of the tutorials I've made teach how to create custom admin panels.

When I use a php framework such as Laravel, Symfony, CakePHP, FuelPHP, Fat Free Framework, Yii, Phalcon etc or even ruby Ramaze, when I check the documentation, all the tools I need to create a site is there, Controllers, Models, Views, Routing, Helpers, Sessions etc. However when I try to create a simple Processwire module, I cannot find a comprehensive place of all the tools or documentation I need to create a new module that has a page in the admin panel. I find it disappointing that when searching Google for "create processwire module" or "processwire module tutorial", that I am told how to make X module, without being given the information on how to create the module I want. Some parts are useful, such as how to define the module information or creating and dropping a database table upon installation and installation, but there is nothing much than that. Here's an example of an easy to understand documentation. 

http://ramaze.net/documentation/index.html 

https://web.archive.org/web/20120421091700/http://www.magentocommerce.com/knowledge-base/categories/category/development

 

Quote

You don't even need to write a module for that kind of thing

I do, as processwire doesn't have this functionality out of the box. I need a way to review reported links or pages in the admin panel, when someone clicks to report a link, a new report is created for me to review. I have to review these links or pages in the admin panel. The only way for me to have a page in the admin panel where I review all the reported pages (or links), is to create a module.

1 hour ago, BitPoet said:

@desbest

Since you're new to PW, there will be a bit of a learning curve, and I'd guess that it won't be much quicker initially than using a barebone framework where you can plumb a few odd pieces together until it works, but in the long run, it will be far easier to extend and much more intuitive to maintain, since all you'll be dealing with will be PW pages and fields.

Then what is the point of using processwire?

Why do people use content management systems instead of handling all the pages as html files? Because it saves time.

Why do people use Wordpress to make blogs instead of its competitor Textpattern or b2evolution? Because it saves time.

As the maxim goes, don't reinvent the wheel. I don't believe in reinventing the wheel. If something saves time and works, then do it! :rolleyes:

If it takes much longer time to create a website in Processwire than it would in a php framework, then what is the point of using processwire??? I thought the pages, API and modules system would make it quicker to make sites than a php framework. If it takes longer then I cannot use it.

Is there any comprehensive tutorial for how to make a processwire module, that doesn't tell me how to make X module, but instead gives me all the tools that teach me how to do it?

What I'm asking is very simple. When someone clicks a link, a page is modified so a checkbox field is checked inside a page is checked. I then check all these checked pages in the admin panel, once seen it changes from unread to read, until there are no more unread. When seeing these checked pages, I can choose to delete the page or leave it as it is.

So what have I learnt from the tutorials so far? How to define the metadata of a plugin and how to define what database table inserts and deletes happen when a plugin is installed and uninstalled.

Link to comment
Share on other sites

Quote

I've done that now and all that comes up is how to make X module, instead of here is all the Y's you need to make whatever module you have in mind.

The tutorial simply touches on creating modules that require Admin Interface and not just the general module, although I have to admit, I faced the similar issues of trying to get all information in one place like the Symfony Documentation, However with my tutorial you have the basic stub to generate the menu before focusing on your specific needs, so i guess the question I will ask is what are the task you need to achieve, I can assist in telling you how to go about them in the PW way, I came from a Zend Framework,Yii2 framework and It was hard for me at first, which is why i said things are a bit different here. reply and I will post how to go about them. 

 

1 hour ago, desbest said:

Is there any comprehensive tutorial for how to make a processwire module, that doesn't tell me how to make X module, but instead gives me all the tools that teach me how to do it?

 

Hmmmm i initially had the plan to list the information needed rather than an example, but I was of the opinion people needed a simple example but then again you are a more advanced developer so examples are limiting, I will write a basic tutorial after this which touches on Module creation and classes needed.

 

1 hour ago, desbest said:

What I'm asking is very simple. When someone clicks a link, a page is modified so a checkbox field is checked inside a page is checked. I then check all these checked pages in the admin panel, once seen it changes from unread to read, until there are no more unread. When seeing these checked pages, I can choose to delete the page or leave it as it is.

 

Okay so first I am assuming the link is on the front page right, and that link is attached to a template which has a field, so remember that you can have logic in your template, as the template in some similar way is similar your controller. you can simply have a code that respond to a specific GET URL variable and check the field.

<?php
//Pseudo Code
if($input->get('url_variable_goes_here')){
 if($page->field_for_checked_element !== 1){ 
 $page->field_for_checked_element=1; 
 }
}

Now remember all fields are tied to a template, so from the Admin you can simply use the $pages->find() to simply list the specific fields in this case the checkbox and while listing them, am guessing you can pull the Page data from the them and simply render on the admin page.

 

If this isn't clear please do let me know.

Also let me post info about Processwire classes and what their role serve. 

 

Link to comment
Share on other sites

1 hour ago, desbest said:

If it takes much longer time to create a website in Processwire than it would in a php framework, then what is the point of using processwire??? I thought the pages, API and modules system would make it quicker to make sites than a php framework. If it takes longer then I cannot use it.

Coming from Yii2 and Zend Framework 2, I can tell you it takes less time, however the only catch is that you need to overcome the learning curve first and understand the Processwire API. My first project took me a while because am quite versed with other frameworks and tried using that same approach in this forum 

 

Please reply if you have any question and also if you have an feedback about my tutorial so i can adjust take care

Link to comment
Share on other sites

10 minutes ago, desbest said:

 

Quote

You don't even need to write a module for that kind of thing

I do, as processwire doesn't have this functionality out of the box. I need a way to review reported links or pages in the admin panel, when someone clicks to report a link, a new report is created for me to review. I have to review these links or pages in the admin panel. The only way for me to have a page in the admin panel where I review all the reported pages (or links), is to create a module.

Believe me, you don't. If you'd followed my link, you would have realized that too. Ranting without reading the help given won't get you closer to a solution.

As for the time issues you mention: there's always the choice between doing things quick&dirty and doing things right, especially in programming. Why do people build regular pages on Wordpress? Because they know it and get a quick solution to an immediate problem, but in the long run, they fight against the software they are using because it wasn't meant for this kind of thing.

When I estimated that the time would, initially, be roughly the same for using PW and another framework, I was taking into account starting at zero with both, since there's yet no clickading thingy that plucks ideas from a brain and automagically adds it to a web page. ProcessWire is a framework too, and it also has its concepts and best practices. They aren't that many, but they need to be understood. The docs do give a good introduction to them, and there's plenty of information in the forum if you search for the keywords if you need more explanation.

Here's a short step-by-step approach to solving your task without a custom module and just one non-core module:

Preparations

The template with the fields used to store reports

  • Create a new field "reported_page" and set the field type as Page, in the settings select "single page or null page"
  • Create a new field "report_message" and set the field type to Text
  • Create a new field "report_read" and set the field type to Checkbox
  • Create a new template "pagereport" in the backend and add the three fields you just created, ignore the message that there isn't a template file present

The backend interface

  • Create a file named "_pagereport_backend.php" in site/templates
  • Go to "Page" and expand the tree to "Admin" -> "Pages", then click "New" next to that
  • Set the title of the new page "Manage Reported Pages" and save. The template will automatically be set to "admin".
  • Now, as the process for this template, select "ProcessAdminCustomPages". You can now select the "_pagereport_backend.php" file you created earlier.
  • Click "Publish"

The frontend page with the reporting form

  • Create a file named "enterreport.php" in site/templates
  • Create a new template and check "enterreport"
  • Save
  • Create a new page under "home", title it "Report Page" and select the template "enterreport"
  • On the "Settings" tab, check "hidden" so it won't appear in searches and lists
  • Publish

You're all set up now, all you need is the PHP code and markup now.

Edit "_pagereport_backend.php" and enter the following code, which will render a table with all reports, has links to the reported page and lets you directly mark them as read. It uses the core module MarkupAdminDataTable so you don't have to build the table manually.

<?php

if($input->get->mark_id_read) {
	$report = $pages->get($input->get->mark_id_read);
	$report->of(false);
	$report->report_read = 1;
	$report->save();
}

$children = $page->children("sort=report_read, sort=-created");

$table = $modules->get("MarkupAdminDataTable");
$table->setEncodeEntities(false);

$table->headerRow(array(
	"Reported",
	"Page",
	"Message",
	"Read"
));

foreach($children as $report) {
	$table->row(array(
		strftime("%Y-%m-%d %H:%M", $report->created),
		"<a href='{$report->reported_page->url}' target='_blank'>{$report->reported_page->title}</a>",
		$report->report_message,
		$report->report_read ? "Yes" : "<a href='$page->url?mark_id_read={$report->id}'>No</a>"
	));
}

echo "<h1>Reports to manage:</h1>\n" . $table->render();

Now, edit the "enterreport.php" file and add the code to enter a report:

<?php

if($input->get->page_id) {
	$pg = $pages->get($input->get->page_id);
?>
	<h1>Report page <?= $pg->title ?> (<?= $pg->url ?>)</h1>
	<form method="POST" action="<?= $page->url ?>">
		<input type="hidden" name="page_id" value="<?= $input->get->page_id ?>">
		Please leave a short reason why you are reporting this page (e.g. SPAM or offensive):<br />
		<input type="text" name="report_message" size="80"><br />
		<input type="submit" name="submit_report" value="Report this page">
	</form>
<?php
} else if($input->post->submit_report) {
	$pg = $pages->get($input->post->page_id);
	$prnt = $pages->get("name=manage-reported-pages");
	
	$report = new Page();
	$report->template = "pagereport";
	$report->parent = $prnt;
	$report->name = (new DateTime)->format("Ymd-Hisu");
	$report->reported_page = $input->post->page_id;
	$report->report_message = $input->post->report_message;
	$report->save();
	
	echo "<h1>Page '{$pg->title}' has been reported. Thank you!</h1><a href='#' onclick='window.close();'>Close this window</a>";
} else {
	echo "<p>No page given. If this problem persists when you try to report a page, please contant the administrator.</p>";
}

All that's left to do is add the link to the report page somewhere in your template file, e.g. in a basic profile in _foot.php:

<a href="<?= $pages->get("name=report-page")->url ?>?page_id=<?= $page->id ?>" target="_blank">Report this page</a>

Creating a module would just mean wrapping most of the things I described here into an install routine and adding some shortcut routines (e.g. for rendering the markup that links to the report page form).

You can now easily tweak the interface, e.g. by filtering the children in _pagereport_backend.php by "report_read!=1" to only show unread reports. You can add a field (e.g. the client IP) to the reportpage template and need only two lines in enterreport.php to render and save it and two in _pagereport_backend.php to display it (column header and value). Each report is actually a page underneath Manage Reported Pages, and you can even use PW's regular page tree to view or delete reports.

  • Like 9
Link to comment
Share on other sites

AdminCustomPages deserves its own website for being a versatile tool, and it deserves better documentation.

The author says the documentation is on github, but when I look there, I don't see much documentation.

There is no way that a processwire newbie would figure out how to add an admin panel page for reported content, without outside help, as the documentation is lacking.

Link to comment
Share on other sites

Post a Gist let me see how your code looks like now however let me share a code that's similar to yours

$f = $this->modules->get('InputfieldButton'); 
		$f->value = $this->_('New Backup'); 
		$f->icon = 'database';
		$f->href = "./backup/"; 
		$f->addClass('head_button_clone'); 
		$out .= $f->render();

howver not sure how u handle the url in AdminCustom

Link to comment
Share on other sites

Can i see a screenshot of the viewed report so i can know what you mean ? my previous code still works, it will just generate the HTML for the button and once you click, you just need to handle the action for delete the reports, however let me see a screenshot and are the reports "Pages" ?

Link to comment
Share on other sites

There is no need for more documentation...you can simple create Admin pages that using a simple template file without creating a own process module.

THIS is the way every newbie add admin pages/dashboards  with simplest PHP...

There is absolute nothing fancy. All Adminpages need a ProcessModule.

AdminCustomPages is as plain as simple in around about important 15 lines of code the Process connects the created Adminpage wich Template file under /site/templats/ should called....and search for some related CSS/JS files...

The rest (i think what you mean - the tables and the rendering stuff ) is all basic Processwire UI Coremodules or other such called MarkupModules that simple rendering a UI - like you see in the great example from BitPeot you can call it simple like:

//render a table for me
$table = $modules->get("MarkupAdminDataTable");
//fill $table with stuff

//render a PageList or use some Inputfields and you could use even the $form creating from the API...search for it in the forum there is //only one important topic that has all informations
//or simple use PHP to render what ever
echo "FooBar";

And one important tipp - i don't know how much well documenated other projects (you mentioned some above) are, but all PW core modules and many third party modules are very very well documentated in its codebase itself. For you as experienced dev this should be great news...;)

https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Markup/MarkupAdminDataTable/MarkupAdminDataTable.module

https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Process/ProcessPageList/ProcessPageList.module

https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Inputfield/InputfieldCheckboxes/InputfieldCheckboxes.module

I have to admit that processwire is not for everyone a conclusive concept from the start. But personally for me as "longtime PHP scrub", i don't get the the basics of OOP programming until i found PW - where OOP is not only a programming concept - it is the whole system.

Even it was deadsimple for me to create own modules, as textformatters, markupmodules and many other stuff...but in the most cases i'll stick to simple PHP template code that works. On other CMS/Frameworks you need complex basic structures to build up on them, with PW you have to build your own structure with the great API and how complex you like it.

regards mr-fan

 

  • Like 3
Link to comment
Share on other sites

I'll break it down very simply. If I am working with CRUD (create, read, update, delete), then there should be a page somewhere documenting how to do it. For example, if a variable doesn't suffice to store information, there better be information on arrays, if arrays and variables aren't a sufficient means of storing information, there better be information on cookies, sessions and parsing xml, json and yaml, for the example of javascript and php. W3Schools and Tizag are popular because they teach people what method to make their information work with CRUD. Good documentation lets people know how to make information work with CRUD.

When I want to do something in processwire as a newbie, I find it hard to find the exact documentation page which will teach me how to do it.

I wanted to loop pages in a category. The https://processwire.com/api/selectors/ page didn't help me properly, as there is no example given with foreach so I copied that from the foreach Smashing Magazine article.

I wanted to know how to create a module and arrange the admin page, and I couldn't find any pages to teach me how to do it, and I was thankfully told that I don't need to create a module as I can use AdminCustomPage. I was given a tutorial as a starting point.

Now I want to create a button, but there are no pages on the internet to teach me how to create a button, but I was given sample code, but sample code isn't documentation.

I sadly can't find any page on the internet that teaches me how to make a button in the admin page I've just created, and have that button do something. There is no function for me to lookup.

 

Link to comment
Share on other sites

5 minutes ago, desbest said:

 

I'll break it down very simply. If I am working with CRUD (create, read, update, delete), then there should be a page somewhere documenting how to do it.

 

I think you over-thinking things, it could be any button, the code i have is just an helper and nothing more, The only reason I use such is because the theme generation for that button is one used by the admin theme, Even the markup table, there's really anything special to them, other than to give a simple way to create markups with ease.  My best advice is to take a Processwire Module install and compare the code , because there are somethings the documentations don't cover. It's something that can be looked into as to how it can be improved and also community efforts. 

 

However i am still of the opinion you use the standard way of creating modules than AdminCustomPages, it's more verbose and there's a page describing the methods

http://processwire.com/api/ref/process/

 

Link to comment
Share on other sites

It's actually not difficult at all to add the button and make it do what you want. PW is all about HTML + PHP, no fancy magical layers and MV(V)C patterns to bump your head against (unless you really want them, that is). Like @Sephiroth said, you can use PW's Inputfields to get consistent appearance for the backend, but you don't have to.

The code in _pagereport_backend.php echoes the HTML making up the interface, so just output a button with a unique name you can check for as well:

echo "<h1>Reports to manage:</h1>\n" .
	 "<form method='POST' action='$page->url'><input type='submit' name='delete_read' value='Delete all read'></form><br />\n" .
	 $table->render();

Now you only have to check at the top of _pagereport_backend.php if a POST value of delete_read has been passed, and if yes, find all pages with report_read=1 and delete them. Deleting pages is done through the $pages variable, and finding them can be either done through $pages too, directly through the current page ($page->find()) or by limiting $page->children() to those with a read status. The syntax for finding pages (i.e. selectors) is well-documented.

It boils down to snippet of code like this:

if($input->post->delete_read) {
	foreach($page->children("report_read=1") as $read) {
		$pages->delete($read);
		// Could also use $pages->trash($read) instead to have a failsafe
	}
}

 

  • Like 3
Link to comment
Share on other sites

Now how do I add these green links next to reported pages in my AdminCustomPage, where the reported page is mentioned with its name?

I hate to ask noobish questions, but there is no documentation page I can go on, which will teach me how to do it.

edit and view.png

Link to comment
Share on other sites

hi desbest, welcome to the forum :)

i did not read the whole thread but wanted to mention that there is also the helloworld module where you can see how easy it is to develop a module in processwire https://github.com/ryancramerdesign/ProcessWire/blob/master/site-default/modules/Helloworld.module

other than that i would recommend using tracy to inspect whats going on (eg make a inspectable dump of a page object in the console:)

2016-09-17 20_27_31-Pages • ProcessWire • mentalestaerke.at.png

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...