Jump to content

kongondo

PW-Moderators
  • Posts

    7,479
  • Joined

  • Last visited

  • Days Won

    146

Community Answers

  1. kongondo's post in Restore a previous site was marked as the answer   
    http://bfy.tw/5mfF : migrate site

    Please have a look at the results and let us know if you still have a specific need...
  2. kongondo's post in Simple navigation was marked as the answer   
    The topics I linked to should be able to help you (@see my edited post above yours). The code at the first link is pretty straight forward and solid...
     
    Edit:
     
    If you don't want to use a function and you'll have no more than 2 levels, you could probably get way with this:
    <div class="collapse navbar-collapse navbar-right"> <ul class="nav navbar-nav menu navbar-right"> <?php $out = ''; $root = $pages->get("/"); $children = $root->children("limit=7"); $children->prepend($root); foreach($children as $child) { $out .= "<li><a href='{$child->url}'>{$child->title}</a></li>"; if($child->numChildren) {// @note: you could do some more checks here; foreach($child->children as $c) { $out .= "<ul>"; $out .= "<li><a href='{$c->url}'>{$c->title}</a></li>"; $out .= "</ul>"; } } } echo $out; ?> </ul> </div>
  3. kongondo's post in Using child pages as part of parent page was marked as the answer   
    Aah, I see. If you need to use the template file of the child pages, have a look at this long thread. @jonathan's post may be of special interest in your case.
    You do not need to use the redirect module for such a simple redirect. For such you use $session->redirect('url') like I indicated  . Have a read here about the session variable.
  4. kongondo's post in Problem retrieving filename from image field in API generated page was marked as the answer   
  5. kongondo's post in How do i remove system flag of a template ? was marked as the answer   
    $t->flags = Template::flagSystemOverride; $t->flags = 0; // etc... save here or delete $t->save();  
  6. kongondo's post in Help placing items in multiple categories using Page Fieldtype? was marked as the answer   
    Hi @holmescreek,
    Welcome to ProcessWire and the forums. You might want to have a read here first about various approaches to categorising site content. 
    I have only had a quick glance at the PDF. I notice you are creating the ABBA page directly under POP then also having the possibility to select POP (the parent page) within ABBA. That's not the 'usual' way we got about this.
    What would work best is something like this (page tree):
    Genres (template genres)
        Pop (template genre)
        Foreign
       Rock
    Artists (template artists)
       ABBA (template artist)
       U2
       Rolling Stones
    Then, in the template artist (for individual artists), add a page field of type multiple, called, for example, genres. In the page field genres, in template of selectable pages, set that to 'genre'. Then, in your artist pages, say when editing ABBA, you can choose all the genres you want for the band, e.g. 'Foreign' and 'Pop'. In the front-end end you can then do something like:
    // grab all pop bands (if many, you may want to place a limit and use pagination) $pop = $pages->get('/genres/pop/'); $artists = $pages->find("template=artist, genres=$pop"); // or, if users are viewing the POP page $artists = $pages->find("template=artist, genres=$page"); Of course, it is possible to search for multiple genres in a single query. See the selectors' docs here.
    This type of organisation keeps duplicity to a minimum.
  7. kongondo's post in Render options, documentation? was marked as the answer   
    @jtborger,
    You are not wasting anyone's time. The fact of the matter is that overall, there is still a lot of room to improve ProcessWire's documentation and tutorials across a range of topics spanning both basic and advanced stuff. It is something we are aware of and are keen to improve. Part of the Road Map for 2016 is exactly that...'continued and greater focus on documentation and tutorials'. Of course this does not mean everything will be done and dusted by the end of play 2016 but there should be some positive advances nevertheless.  Whilst there are some great examples in the forums regarding various uses of the ProcessWire API, those cannot and should not be considered as a long term solution in lieu of proper documentation. In the meantime though, they are a good place to start if you are searching for particular answers.
    Welcome back to the forums
  8. kongondo's post in Comments Manager Module Error [Using/Uninstall] || Comments NOT working 2.7.2 was marked as the answer   
    And we are back...
    I now recall I have seen this error before (when I was playing around with enhancing the Comments Manager). Yeah, the error is not very intuitive. ProcessCommentsManager should at least catch the error and give a more informative message. What is happening is this. In line #92, Comments manager is calling a constant from the Comment Class. The Comment Class is not a module but a .php file. It is loaded/required_once in FieldtypeComments.module line #22. So, unless you at created at least one field of type Comments, you will get that error. That field does not have even have to be added to a template yet for this to work. If such a field is present, it calls FieldtypeComments.module which in turn loads the Comment.php class and everything is fine and dandy. 
    So, long story short, first create a field of type Comments before attempting to load ProcessCommentsManager. I would also file a request on GitHub for @ryan to consider catching the above error and returning a more meaningful error message for supersusers.
  9. kongondo's post in jQuery functions and path was marked as the answer   
    Might be of use..
    https://processwire.com/talk/topic/8343-access-page-and-pages-variables-from-inside-a-javascript-file/
    https://processwire.com/talk/topic/5162-how-to-load-js-css-plugins-colorbox-cycle2/
  10. kongondo's post in Accessing file->description within a repeater was marked as the answer   
    Worked as expected in my testing (PW 2.7.2). Are you getting any errors?
    Btw, you are naming your fields using upper-case first letters? It still works but it's a good idea to follow the recommendation about naming fields:
  11. kongondo's post in new image option was marked as the answer   
    That's still in the works.
    ProcessWire 3 is here:
    https://github.com/ryancramerdesign/ProcessWire/tree/devns
    Version 3 has gone beyond 'alpha', btw.
  12. kongondo's post in How to generate auto summary of long CNKEditor content, with valid XHTML was marked as the answer   
    Simplest way I can think of is to use PHP substr and strip_tags. The latter is very greedy so you need to tell it what to avoid [allowable tags]...(it get could messy very quickly). Anyhow, this is how we do it in the Blog module using those two PHP functions.
  13. kongondo's post in My slideshow does not appear! was marked as the answer   
    Try removing the isset condition...
    <?php if($page->slideshow->count()):?>// or below if this doesn't work.. // <?php if(count($page->slideshow)):?>
  14. kongondo's post in Additional properties for field types was marked as the answer   
    Welcome to the forums and ProcessWire
    You got two options:
    Use the ImageExtra module If you are using the page itself as a store for the image, you can use your page's title as the image's title By the way, in case you haven't seen it, you can enable image tags when editing your image fields.
  15. kongondo's post in Displaying Parent Page title in child page was marked as the answer   
    echo $page->parent->title;
    echo $page->parent->name;
    echo $page->parent->id;
    echo $page->parent->whatever_property;// non-array property

  16. kongondo's post in Duplication in Query Results was marked as the answer   
    Use getQueryLog()
    Maybe something like:
    $queries = $database->getQueryLog(); foreach($queries as $query){ if (strpos($query, 'classification')) {//just to limit our search since there could be other queries echo '<pre>' . $query . '</pre>'; } }
  17. kongondo's post in sorting by subfields was marked as the answer   
    Andrey,
    sort by the real name of the database column (in your case it is 'data') and it will work, i.e.
    $query = 'template=mytemplate,sort=myfield.data';//data here = real name of the mysubfield, not its alias At the moment, I don't know how to tell sort to sort by the alias of a subfield...Searching using an alias (if set) works fine though, e.g. 
    $p = $pages->get('template=mytemplate, myfield.mysubfield=whatever');
  18. kongondo's post in Selector for "does not contain" was marked as the answer   
    Peter, 
    http://processwire.com/api/selectors/#operators
  19. kongondo's post in preventing duplicate user emails was marked as the answer   
    Andrey,
    With adapted code stolen from Soma here: https://processwire.com/talk/topic/4476-validating-field-before-page-save/ (post #2), you can do something like below in an autoload module. Be sure to read Soma's explanations as well in that post/thread.
    <?php class ValidateEmail extends WireData implements Module { /** * Return information about this module (required). * * @access public * @return array module info * */ public static function getModuleInfo() { return array( 'title' => 'Validate Unique Email', 'summary' => 'Ensure Uniqueness of Emails across site', 'author' => 'Kongondo, Soma', 'version' => 001, 'singular' => true, 'autoload' => true, ); } public function init(){ $this->addHookAfter("InputfieldEmail::processInput", $this, "validEmail"); } public function validEmail($event){ $field = $event->object; if($field->name == 'mail'){ $page = $this->modules->ProcessPageEdit->getPage(); $oldEmail = $page->get($field->name); $newEmail = $field->value; #$this->message("old value: $oldEmail"); #$this->message("new value: $newEmail"); $existEmail = $this->wire('pages')->get("id!=$page->id, template=basic-page, mail=$newEmail, mail!=''"); if($existEmail && $existEmail->id > 0) { $field->value = $oldEmail; $field->error($this->_("That email $newEmail is already taken mate; go fishing! :-)")); } } } } This will save if unique, keep old value if not unique and show error. I am not sure what you mean by admin gets error notification; you mean send them an email or log the error? I'll let you Google that 
  20. kongondo's post in Difference betweeen $page->delete() and $page->trash() was marked as the answer   
    Delete is permanent (be careful with that) deletion/removal of that record (from the database)....trash is well, send it to the trash...can be retrieved later in case you change your mind (unless of course you empty the trash, then its deleted).....
    http://cheatsheet.processwire.com/
    Welcome to the forums
  21. kongondo's post in sorting images using pages was marked as the answer   
    Have you tried sort=sort in your find?
    $projects = $pages->find("parent=/work/, sort=sort");
  22. kongondo's post in Mass create pages OR mass upload images and thus create pages was marked as the answer   
    UNTESTED, probably have some typos + poorly formatted code (I gotta run...)
    You want to add this to your template file....Wrap it around code that ensures only Superuser can load the code...
    //absolute path to a directory called 'tmp' within the site folder where we have our images $dir = $config->paths->site . 'tmp'; $addAndPublish = false;//true if you want to publish on save //prepare some variables we'll need later $a = 0;//for photo pages count $failed = array(); $parent =$pages->get('/portraits/'); $t = wire('templates')->get('your-portrait-template-name'); //if we found the directory (here we use Standard PHP Library (SPL)) if (is_dir($dir)) { $directory = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS); //iterate through each file in this directory foreach ($directory as $path ) { set_time_limit(30);//we try to avoid timing out //Remove and delete invalid file types $validImagesExts = array('jpg', 'png', 'gif', 'jpeg'); if($path->isFile() && !in_array($path->getExtension(), $validImagesExts)) { unlink($path);//we delete the invalid file continue; } //if valid image file we create a page named after it and later save it to the page if($path->isFile()) { //we are ready to start creating pages... $p = new Page(); $p->parent =$parent; $p->template = $t; $title = $path->getBasename('.' . $path->getExtension()); $p->title = $this->sanitizer->text($title); if (!$p->title) continue;//skip to next if no title found (just in case) $p->name = $this->sanitizer->pageName($p->title);//sanitize and convert to a URL friendly page name //check if name already taken if($p->parent->child("name={$p->name}, include=all")->id) { //if the same name already exists, add it to the $failed array [to display to user in error later] and skip to next title if ($path->isFile()) { $failed [] = $path->getFilename(); } continue; } //if add and publish is false, we save new page unpublished if (!$addAndPublish) $p->addStatus(Page::statusUnpublished); $p->save(); //add image to the page and save again $p->images_field->add($dir . '/' . $path->getFilename()); $p->save(); $a++; unlink($path);//we delete the temp file } }//end foreach //delete the tmp directory wireRmdir($dir, $recursive = true); //create a string of "failed" category titles to add to error message $failedTitles = implode(', ', $failed); //give the user some feedback... if($a > 0) echo 'Added' . $a . 'Portraits<br>'; if($failedTitles) echo 'Some Portraits not added because names already in use. These are:' . $failedTitles; }//end if (is_dir($dir))) else echo 'No Such Directory Found!';
  23. kongondo's post in New Header.inc based on Parent Page was marked as the answer   
    You have two options for the dropdown: Page Field or Select Options Fieldtype
  24. kongondo's post in How to fill a field automatically after a page is published? was marked as the answer   
    Maybe how we do it in the Blog Module can be of help. Have a look at the Hooks here.
  25. kongondo's post in $pages->find("template=xxxx") not working for certain template was marked as the answer   
    Is it a case of:
    Or...?
    If you are able to fetch (i.e. $my_array is NOT empty) but not display, then, as suggested, check the template file. If you cannot access (i.e. returns nothing), then check access controls, e.g. are the pages hidden? For instance, 'find' will not retrieve hidden pages although 'get' will...
×
×
  • Create New...