Jump to content

blackeye1987

Members
  • Posts

    37
  • Joined

  • Last visited

Everything posted by blackeye1987

  1. found something intressting due to the new adminTemplate, hope someone can help me out here. since every User is able to use the HeadButton (top right in breadcrumb), which seem to contain, on page/index , all templates you are allowed to create. This will make my Startpoint irrelevant cause a User could "hack into other pages" through this little thing. since my user is allowed to put in some content he can use the link "/page/add/?template_id=51" to see all pages (he shouldn't be allowed to) so i thought "k fine.. gonna hook that" when i was done i wanted to double check this hook with checking if i am allowed to still add pages so by clicking a page in the admin menu -> new i got this link "/page/add/?parent_id=1311" nothing new for everyone who used PW so far. but now comes the thing which wonders me. my hook looked like this: echo wire('user')->gsv_startingpoint->id; if(wire('user')->gsv_startingpoint->id){ $event->replace = true; } (i replace page/add when my startingpoint was set to a pageId) wouldn't this mean that booth wouldn't give me any form ? (well should afaik) /page/add/?parent_id=1311 /page/add/?template_id=51 but it doesn't /page/add/?parent_id=1311 (normal functionality, also no echo is set at any point) /page/add/?template_id=51 (no functionality as intended) can someone explain me why it is like this ? or help me with a workaround. i had 2 ideas: 1. Edit the AdminTemplate Module (removing the HeadButton, but i actually like the functionality) 2. Hooking into PageAdd and removing its functionality when a starting point is set (when i crossed this weird bug)
  2. Based on my Previous thread: https://processwire.com/talk/topic/7194-templatelist-inside-module-configuration/ here is an automatic child creater if you need on creation of a parent element a bunch of Child Elements. what also works: multiple diffrent childs on same parent caution: sadly what also works: first entry: parent_id = 47 child_id = 13 child_name = something child_numbers = 1 second entry: parent_id = 13 child_id = 47 ... ... this should afaik (not tested) kill your System by having a infinite Loop. because (first entry creates a child which call second entry which would then call first entry and so on). <?php /** * Created by PhpStorm. * User: Kielbasa * Date: 04.08.14 * Time: 10:09 */ class CustomChildCreater extends Process { public static function getModuleInfo() { return array( 'title' => 'CustomChildCreater', 'version' => 100, 'summary' => 'Child creator for Pages with Specific Parent', 'href' => '', 'singular' => true, 'autoload' => true, ); } public function ___execute() { $this->setFuel('processHeadline', 'Child Creater'); $table = $this->modules->get("MarkupAdminDataTable"); $table->setEncodeEntities(false); $table->headerRow(array('Edit','Parent Template', 'Child Template','Name of new Childs (childname+{n})', '{n} - Childs', 'Delete')); $result = $this->db->query("SELECT * FROM {$this->className} ORDER BY parent_template"); while($row = $result->fetch_assoc()) { // output in table rows with edit link and delete checkbox? $table->row(array( 'edit' => 'edit/?id='.$row['id'], $this->templates->get($row['parent_template'])->name , $this->templates->get($row['child_template'])->name, $row['child_name'], $row['child_numbers'], "<input type='checkbox' name='delete[]' value='$row[id]' />" )); } $button = $this->modules->get("InputfieldButton"); $button->type = 'submit'; $button->id = 'submit_delete'; $button->value = 'Remove selected sources'; $table->action(array('Add source' => 'add/')); // Is there clean way to add button to right side? return "<form action='./delete/' method='post'>" .$table->render() . $button->render() . "</form>"; } public function ___executeAdd() { $this->fuel->breadcrumbs->add(new Breadcrumb('../', 'Child Creater')); $this->setFuel('processHeadline', "new Instance"); $form = $this->modules->get("InputfieldForm"); $form->method = 'post'; $form->action = '../save/'; //--Parent Template $field = wire('modules')->get('InputfieldSelect'); $field->attr('name', 'parent_template'); $field->label = __('Parent Template'); foreach(wire('templates') as $template){ $field->addOption($template->id, $template->name); } $form->add($field); //--Child Template $field = wire('modules')->get('InputfieldSelect'); $field->attr('name', 'child_template'); $field->label = __('Child Template'); foreach(wire('templates') as $template){ $field->addOption($template->id, $template->name); } $form->add($field); //--Child Name $field = wire('modules')->get('InputfieldText'); $field->attr('name', 'child_name'); $field->label = __('Child Name'); $form->add($field); //--Children to Create $field = wire('modules')->get('InputfieldInteger'); $field->attr('name', 'child_number'); $field->label = __('Childs to Create'); $form->add($field); $field = $this->modules->get("InputfieldButton"); $field->type = 'submit'; $field->value = 'Create'; $form->add($field); return $form->render(); } public function ___executeSave() { $parent_id = (int) $this->input->post->parent_template; $child_id = (int) $this->input->post->child_template; $child_name = $this->input->post->child_name; $child_numbers = (int) $this->input->post->child_number; //no i am not allowing you to kill your system if($parent_id != $child_id){ $sql = "INSERT INTO {$this->className} SET parent_template = '$parent_id', child_template = '$child_id', child_name = '$child_name', child_numbers = '$child_numbers' ON DUPLICATE KEY UPDATE id = id;"; $this->db->query($sql); $this->message("Save Successful"); $this->session->redirect("../"); } $this->message("Parent and Child should not be the same!"); $this->session->redirect("../"); } public function ___executeEdit(){ if(!isset($_GET['id'])){ $this->session->redirect("../"); } $id = (int) $_GET['id']; $result = $this->db->query("SELECT * FROM {$this->className} WHERE id=$id"); $data = $result->fetch_array(); $form = $this->modules->get("InputfieldForm"); $form->method = 'post'; $form->action = '../update/'; $field = $this->modules->get("InputfieldHidden"); $field->name = 'id'; $field->value = $id; $form->add($field); //--Parent Template $field = wire('modules')->get('InputfieldSelect'); $field->attr('name', 'parent_template'); $field->label = __('Parent Template'); foreach(wire('templates') as $template){ $field->addOption($template->id, $template->name); } $field->value = $data['parent_template']; $form->add($field); //--Child Template $field = wire('modules')->get('InputfieldSelect'); $field->attr('name', 'child_template'); $field->label = __('Child Template'); foreach(wire('templates') as $template){ $field->addOption($template->id, $template->name); } $field->value = $data['child_template']; $form->add($field); //--Child Name $field = wire('modules')->get('InputfieldText'); $field->attr('name', 'child_name'); $field->label = __('Child Name'); $field->value = $data['child_name']; $form->add($field); //--Children to Create $field = wire('modules')->get('InputfieldInteger'); $field->attr('name', 'child_number'); $field->value = $data['child_numbers']; $field->label = __('Childs to Create'); $form->add($field); $field = $this->modules->get("InputfieldButton"); $field->type = 'submit'; $field->value = 'Save'; $form->add($field); return $form->render(); } public function ___executeUpdate(){ $this->fuel->breadcrumbs->add(new Breadcrumb('../', 'Data imports')); $id = $this->input->post->id; $parent_id = (int) $this->input->post->parent_template; $child_id = (int) $this->input->post->child_template; $child_name = $this->input->post->child_name; $child_numbers = (int) $this->input->post->child_number; //no i am not allowing you to kill your system if($parent_id != $child_id){ $this->db->query("UPDATE {$this->className} SET parent_template = '$parent_id', child_template = '$child_id', child_name = '$child_name', child_numbers = '$child_numbers' WHERE id=$id"); $this->message("Update Successful"); $this->session->redirect("../"); } $this->message("Parent and Child should not be the same!"); $this->session->redirect("../"); } public function ___executeDelete() { $count = 0; if(!is_array($this->input->post->delete) || empty($this->input->post->delete)) { $this->message("Nothing to delete"); $this->session->redirect("../"); // back to list } foreach($this->input->post->delete as $id) { $id = (int) $id; $this->db->query("DELETE FROM {$this->className} WHERE id=$id"); $count++; } $this->message("Deleted " . $count . " data sources"); $this->session->redirect("../"); // back to list } public function ___install() { parent::___install(); $p = new Page(); $p->template = $this->templates->get("admin"); $p->parent = $this->pages->get("template=admin, name=setup"); $p->title = 'Child Creater'; $p->name = 'child-creater'; $p->process = $this; $p->save(); $sql = <<< _END CREATE TABLE {$this->className} ( id int unsigned NOT NULL auto_increment, parent_template int unsigned NOT NULL, child_template int unsigned NOT NULL, child_name varchar(255) NOT NULL, child_numbers int unsigned NOT NULL, PRIMARY KEY(id) ) ENGINE = MYISAM; _END; $this->db->query($sql); } public function ___uninstall() { $p = $this->pages->get('template=admin, name=child-creater'); $p->delete(); $this->db->query("DROP TABLE {$this->className}"); } public function init() { parent::init(); // add a hook after the $pages->save, to issue a notice every time a page is saved $this->pages->addHookAfter('added', $this, 'createChildren'); } public function createChildren($event){ $page = $event->arguments[0]; $query = $this->db->query("SELECT * FROM {$this->className};"); //foreach child creater object foreach($query as $cco){ $t = $cco['parent_template']; $ct = $cco['child_template']; $cn = $cco['child_name']; $ci = (int) $cco['child_numbers']; $c = ''; //will be used as new Page if($t == $page->template->id){ if($ci > 0){ for($i=1;$i <= $ci;$i++){ $c = new Page(); $c->template = $ct; $c->parent = $page; // set the parent $c->name = $cn.$i; // give it a name used in the url for the page $c->title = $c->name; $c->gsv_tab_position = $i; $c->save(); } } } } } } Tell me your thoughts
  3. little bugfix in the top code: it has to be : if(!$this->user->get($sp_p)){ return; } change it already so everyone can still use the code on top
  4. in the beginning me neither got the idea when i edited a page, so i tried it ! on the other hand i want everyone to know, i didn't made any security checks because other modules do this already. i could have integrated them, but i think the original content would be better in use (in case of updates aswell) so what you should use is: somas HideSettings.module (couldn't find it as module but in the forum) ryans PageEditPerUser.module (url : https://github.com/ryancramerdesign/PageEditPerUser/) with those 3 in combination everything should be set and done and the user shouldn't be able to "fool around"
  5. sooooo, maybe this is overkill or totally Wrong but i got it to work. offcourse in a module as it should if someone needs this feel free to use: <?php /** * Created by PhpStorm. * User: Blackeye1987 * Date: 04.08.14 * Time: 10:09 */ class CustomStartpoint extends WireData implements Module, ConfigurableModule { public static function getModuleInfo() { return array( 'title' => 'CustomStartpoint', 'version' => 100, 'summary' => "Access Startpoint for Users *needs (type:page | single page or boolean | Input field type PageListSelect+) set to user template* *Consider Taking in Account using ALSO ryancramers PageEditPerUser.module for extended User Control -> https://github.com/ryancramerdesign/PageEditPerUser/", 'href' => '', 'singular' => true, 'autoload' => true, ); } public static function getModuleConfigInputfields(array $data){ $inputfields = new InputfieldWrapper(); $field = wire('modules')->get('InputfieldSelect'); $field->attr('name', 'startpoint_field'); $field->label = __('Starting Point'); $uT = wire('templates')->get('user'); $fL = $uT->fields; foreach($fL as $f){ $field->addOption($f->name,$f->name); } //set your named custom field for the startingpoint of the user $field->attr('value', isset($data['startpoint_field']) ? $data['startpoint_field'] : ''); $inputfields->add($field); return $inputfields; } public function init() { $this->addHookBefore('ProcessPageList::execute', $this, 'startpoint'); } public function startpoint($event){ $page = $event->arguments[0]; //startpoint page $sp_p = $this->get('startpoint_field'); $id = $this->user->get($sp_p)->id; //if no page is set run normally if(!$this->user->get($sp_p)){ return; } if(!isset($_GET['id'])){ $_GET['id'] = $id; } //if user tries to overwrite id, still edit needs to be allowed //--can be handled through ryans module! //do not allow them to edit the pages and you are done if($_GET['id'] != $id && !strpos($_SERVER['REQUEST_URI'],'/page/edit/') > 0){ $this->message(__('You are not allowed here')); return; } //bugfix pw ? //open needs to be removed because: //if open is a childid of id, id will be opened twice (why ?) unset($_GET['open']); $_GET['id'] = $id; if(strpos($_SERVER['REQUEST_URI'],'open=') > 0){ $this->session->redirect(substr($_SERVER['REQUEST_URI'],0,strpos($_SERVER['REQUEST_URI'],'open='))); } return; } } readme: 1: Create new Field : type: Page Details (Single Page or boolean) Input: Select Parent (Home is fine because as admin you set this Value) Input: Input field type PageListSelect 2. Assign to UserTemplate 3. Set Startingpoint for the User who needs the Startingpoint 4. Login with User who should now have a Startingpoint 5. Wish me Luck no one will kill me for this Code if anyone wants to proof read the code or has any questions or suggested improvements, just reply.
  6. Tried them already, couldn't get the result i wanted. it is important that they are not able to see the other content
  7. okay i found a way to more or less execute this. if i hook myself before ProcessPageList ___execute and overwrite id into the id the user should only see. public function ___execute() { $langID = (int) $this->wire('input')->get->lang; if($langID) $this->wire('user')->language = $this->languages->get($langID); //overwriting $_GET['id'] with the id i will put into his useraccount if(!$this->id) $this->id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $this->openPage = $this->input->get->open ? $this->pages->get((int) $this->input->get->open) : new NullPage(); $this->page = $this->pages->get("id=" . ($this->id ? $this->id : 1) . ", status<" . Page::statusMax); if(!$this->page) throw new Wire404Exception("Unable to load page {$this->id}"); if(!$this->page->listable()) throw new WirePermissionException("You don't have access to list page {$this->page->url}"); $this->page->setOutputFormatting(false); // ensure that we use the page's title is always consistent in the admin (i.e. 'Pages' not 'Page List') $p = wire('page'); if($p->name == 'list' && $p->process == $this) $p->title = $p->parent->title; return $this->render(); } i would have the opportunity to get somewhat of an result what i want. what wont be solved is a szenario i do not have, but could happen. for example: susi should be able to edit not only: susi: content -> news -> security but also content -> history but now to something diffrent i will run into somewhat of an error. if i overwrite id to lock the user into a childpage i am not able to use "open" anymore. this is what i get when i use id on my "new" root and open for a child of this id: http://myadress.com/processwire/page/?id=1054&open=1055 someone halp ? :-\ P.s.: sorry if its hard to read
  8. hi, i just want to get deeper in one thing here. what if i want that a certain user is for example not able to see a Page ? in my example we have some editors who should only be able to see their part of content (for security reasons) also they should not be able to edit the content of others (which should be set and done if they cannot even see the others content) example: susi: content -> news -> security sarah : content -> news -> banking mark : content -> news -> online-help all these editors put their content pages into : content->news->"their part"->article 1 , article 2 ,article 3 and so on i hope someone is going to read this could really need an answer. edit: on the other hand letting the user start in a subdirectory after login would solve the issue aswell (in this case)
  9. okay found a way myself : foreach(wire('templates') as $template){ $field->addOption($template->name, $template->name); } hint: i found it in AdminThemeDefualtHelpers.php if anyone needs this feel free to copy public static function getModuleConfigInputfields(array $data){ $inputfields = new InputfieldWrapper(); //--Parent Template $field = wire('modules')->get('InputfieldSelect'); $field->attr('name', 'parent_template'); $field->label = __('Parent Template'); foreach(wire('templates') as $template){ $field->addOption($template->name, $template->name); } $field->attr('value', isset($data['parent_template']) ? $data['parent_template'] : ''); $inputfields->add($field); //--Child Template $field = wire('modules')->get('InputfieldSelect'); $field->attr('name', 'child_template'); $field->label = __('Child Template'); foreach(wire('templates') as $template){ $field->addOption('$template->name', $template->name); } $field->attr('value', isset($data['child_template']) ? $data['child_template'] : ''); $inputfields->add($field); //--Child Name $field = wire('modules')->get('InputfieldText'); $field->attr('name', 'child_name'); $field->label = __('Child Name'); $field->attr('value', isset($data['child_name']) ? $data['child_name'] : ''); $inputfields->add($field); //--Children to Create $field = wire('modules')->get('InputfieldInteger'); $field->attr('name', 'child_number'); $field->label = __('Childs to Create'); $field->attr('value', isset($data['child_number']) ? $data['child_number'] : ''); $inputfields->add($field); return $inputfields; }
  10. Hi there, Is there a way to get: foreach($templates as $template){ $options.= "<li>{$template->name}</li>"; } to work for a selectbox inside "getModuleConfigInputfields"? i am implementing a module which hooks after page->save. i need the Values (Parent Template, Child Template, Child number, Child name) to be set. I would rather do this with a selectbox of all Templates then with a Textfield. idea behind this is that a customer should be able create a page and gets always the same amount of children inside the page, which should be configurable on the module, because i need this similar tool already 3 times. thanks for every help
  11. Hey so Thanks for the Answer and the Links quiet helped me. i couldn't find any solution how i want to get my result so i splitted the whole thing a bit up. so my next problem is that. if i want to add an picture to a coupon where the "new" image field is only allowed to have 1 picture with : $thisPage->image->add($filename) the field will have after the next upoad 2 pictures (this doesn't seem to be right ) so what i did was putting this in front of the add: $thisPage->image->remove($thisPage->image->first()); it works now but seems a bit odd to handle is there any direct way ? or am i doing something wrong ? for all those who will have similar problems so far here is my code: //if i upload a file then files will be filled so it will be a diffrent form then when i post my data with the "new" coupons if(!empty($_FILES)){ $thisPage = $pages->get($_POST['couponid']); $thisPage->setOutputFormatting(false); $u = new WireUpload('image'); $u->setMaxFiles(1); $u->setOverwrite(true); $u->setDestinationPath($thisPage->image->path()); $u->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png')); $thisPage->image->remove($thisPage->image->first()); foreach($u->execute() as $filename) { $thisPage->image->add($filename); } $thisPage->save(); } //if its a post without a file it has to be the array with new coupons if(!empty($_POST)){ //i wanted to be able to make more coupons in just 1 sitting (better use handling) foreach($_POST['data'] as $newcoupon){ // first create the coupon page //in PW i have my template coupon where all coupons are in so i get the last id of the children and add 1 for the name and my "own id" $last_id = $pages->get(1164)->children()->last()->id; $last_id += 1; $t = new Page(); $t->template = $templates->get('coupon'); $t->c_id = $last_id; $t->parent = $pages->get(1164); // 1164 => /coupons/ $t->title = 'coupon_'.$last_id; $t->blz = $user->blz; $t->company = $newcoupon['company']; $t->what_does = $newcoupon['what_does']; $t->from = $newcoupon['from']; $t->to = $newcoupon['to']; foreach($newcoupon['categories'] as $category => $not_in_use){ $categories .= $category.' '; } $t->category = $categories; $t->save(); } } the made coupons are listed for the admin to add the images afterwards for each coupon i couldn't find a way to add 1 image to each coupon i make all combined in 1 big post so i splitted it up. hope everyone who will have the same issue will find his or hers solution here and thanks for the help so far if anyone has some ideas how to make the code better like to hear it. so far have a nice day and thanks
  12. hi, so far i am learnin a lot of new stuff using Processwire and i like the way it works. but i got to a point where i am confused i got a dynamic form (made with jquery) which has : company name (string) description (string) categories (checkboxes) image (file) after sending the post i have inside my $_POST my important data for the Page which is fine so far my template or the Company has the standart images field from PW while creating the page for the new company i have no clue how to get my image into the page so my question is when should i use WireUpload and how ? my guess so far was : creating page get created page upload image edit page so the page has the file and then save the page again this seems a bit odd aswell so i just decided to ask you guys thanks for the help already and have a good day
×
×
  • Create New...