Leaderboard
Popular Content
Showing content with the highest reputation on 06/11/2015 in all areas
-
Hello everyone, greetings from Belo Horizonte / Brazil. I'm on the process of converting a site from WP to Processwire, this one: http://www.ricardo-vargas.com I needed a simple Flickr Gallery and tried to find a way to create album pages via API and download the images to the local filesystem (just a few, for cache purposes). So I created yesterday a simple script that, given an album ID, download its data using cURL and save the photos to a temp dir. After that, add them to a new page under /pictures/ Feel free to comment on the code, I'm a designer, not a developer, and this is my first time using PW API You can grab it on GitHub: https://github.com/sjardim/processwire-simple-flickr-album Instructions Download the files Put the templates/get_flickr_sets.php on your templates/ folder. Create a page on Processwire using this template Create or edit the page where the albums will be created. In my case it was /pictures/ IMPORTANT: Add guest edit/create permissions to this /pictures/ page, otherwise the script won't work Create a temp dir on your server and set it on the previous file Get a Flickr API on https://www.flickr.com/services/apps/create/ Add one or more Flickr album IDs on get_flickr_sets.php Open the page using the get_flickr_sets.php template on your browser <?php include "../lib/curl.class.php"; // You will need to get a Flick API Key // Get it here: https://www.flickr.com/services/apps/create/ // Load it on the file below include "../lib/flickr_album_utils.php"; function download_file($url) { // Save the image on local filesystem (You need to create this folder first) // On your server it can be /var/www/name_of_folder/ $tempdir = '/Users/XXX/phpFlickrCache/'; $fp = $tempdir . basename(parse_url($url, PHP_URL_PATH)); // if we already downloaded the images for some reason (like testing), just return it if (!file_exists($fp)) { $fh = fopen($fp, 'wb'); $curl = curl_init($url); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1); curl_setopt($curl, CURLOPT_FILE, $fh); curl_exec($curl); curl_close($curl); fclose($fh); } return $fp; } // Get some public album id to test $albumID = ["72157636029541784"]; //$albumID = ["72157649576832173", "72157633296236495", "72157644132091553", "72157636029541784"]; // Load ProcessWire API $pages = wire('pages')->get('/pictures/'); /* -------------------------- GET ALBUM INFO FROM FLICKR -------------------------- */ foreach($albumID as $album) { // Via GET, return album and its photos info $album = fa_get_album($album); // create a new post $page = new Page(); $page->template = 'picture_album'; $page->parent = $pages; // disable page output formatting $page->of(false); $page->name = wire('sanitizer')->pageName($album['title'], true); $page->flickr_album_id = $album['id']; $page->title = $album['title']; $page->generic_integer = $album['total']; //total number of photos on flickr album – OPTIONAL //My client albums descriptions have two phrases, one in English and other in Portuguese // let's separate then by the period, but sometimes there is no period, so the PT description will remain blank $description = explode('.', $album['description']); $en = $languages->get("default"); $page->summary->setLanguageValue($en, $description[0]); $pt = $languages->get("portuguese"); $page->summary->setLanguageValue($pt, $description[1]); $page->set("status$pt", 1); //activate portuguese page $page->save(); // We need to save the page BEFORE adding images /* ------------------------------------ DOWNLOAD AND SAVE IMAGES FROM FLICKR ------------------------------------ */ $images = array(); $i=1; $maxImages = 11; foreach($album["all_images"] as $f) { //we do not want all the photos, just a little bit if ($i >= $maxImages) break; // mount the flickr photo url using its attributes $photo_url = 'https://farm'.$f["farm"].'.staticflickr.com/'.$f["server"].'/'.$f["id"].'_'.$f["secret"].'_b.jpg'; // download and return the image file in the filesystem $images[$album['id']][$i] = download_file($photo_url); // add images to the current page in the loop $page->images->add($images[$album['id']][$i]); $i++; } $page->save(); echo "<p>Created page for album: <strong>".$album['title']. "</strong></p>"; // Tip: Now, after we saved the images to ProcessWire /site/assets/files/, we can safely delete them from the $tempdir if needed } print "<pre>"; print_r($images); print "</pre>"; Admin Screenshot4 points
-
Getting ready to launch. Needs some finishing touches but wanted to share it http://www.gabrielaestates.com4 points
-
I'm using FormBuilder for mostly all forms its a small investment (since it is a commercial module). But it saved many hours of coding and debugging. And as additional benefit it supports Ryan (the creator of ProcessWire) in a little way.3 points
-
Hello Martijn Geerts, I am very new to this forum. Just joined yesterday. If it is wrong to ask another question under a previous topic then i extremely sorry. I will post that question again as a new topic. Thanks.2 points
-
In this tutorial we make a simple function that becomes part of every PageArray. Once hooked to the PageArray class, you can call this function from anything returned from $pages->find(), $page->children(), or your own page references like $page->categories from the blog profile, etc. It essentially becomes a new function available to you from any PageArray anywhere in your site. First, lets look at what convenience the hook function adds and how we might use it. We'll call the hook function "renderLinks", but you could of course call it whatever you wanted. We call that renderLinks() function from any PageArray, and it returns a string representing that PageArray as a list of links. By default, this renderLinks() functions separates each page with a comma, and outputs the page's title as the anchor text. We can change that to be anything by specifying arguments to the call. The first argument is the delimiter, which defaults to a comma ", " if not specified. The second argument is the name of the field to output, which defaults to "title" if not specified. Next are 3 examples of how this renderLinks hook function could be used. Usage Examples: Example 1: render a comma-separated list of links: echo $pages->find("parent=/")->renderLinks(); Output: <a href='/about/'>About Us</a>, <a href='/contact/'>Contact Us</a>, <a href='/site-map/'>Site Map</a> Example 2: render a <ul> of $categories links: <ul> <li> <?php echo $page->categories->renderLinks('</li><li>', 'title'); ?> </li> </ul> Output: <ul> <li><a href='/categories/category1/'>Category 1</a></li> <li><a href='/categories/category2/'>Category 2</a></li> <li><a href='/categories/category3/'>Category 3</a></li> </ul> Example 3: render a breadcrumb trail: <p class='breadcrumbs'> <?= $page->parents->renderLinks(' / ') ?> </p> Output: <p class='breadcrumbs'> <a href='/parent1/'>Parent 1</a> / <a href='/parent1/parent2/'>Parent 2</a> / <a href='/parent1/parent2/parent3/'>Parent 3</a> </p> Those examples above show some of the potential of how you might use such a function. Next is the hook function itself. In order to be available to all templates in your site, it needs to be defined somewhere consistent that is always loaded... Where to put the hook function: If using the basic profile (that comes with ProcessWire) you could put the hook function at the top of your /site/templates/head.inc file. If using the Foundation or Skyscrapers profile, you could put the hook function in your /site/templates/_init.php file. This is the method that I use. If using something else, you could create a /site/templates/_init.php file with your hook function(s) in it, and then edit your /site/config.php to point to it with the $config->prependTemplateFile = '_init.php'; so that it is automatically loaded on every request. Note that the name "_init.php" is not required, you can name it whatever you want. You could put it in an autoload module... but that might be overkill here. The actual hook function: wire()->addHook("PageArray::renderLinks", function(HookEvent $event) { // first argument is the delimiter - what separates each link (default=comma) $delimiter = $event->arguments(0); if(empty($delimiter)) $delimiter = ", "; // second argument is the property to render from each $page (default=title) $property = $event->arguments(1); if(empty($property)) $property = "title"; // $out contains the output this function returns $out = ''; // loop through each item in the PageArray and render the links foreach($event->object as $page) { $value = $page->get($property); if(!strlen($value)) continue; // skip empty values if(strlen($out)) $out .= $delimiter; if($page->viewable()) { // if page is viewable, make it a link $out .= "<a href='$page->url'>$value</a>"; } else { // if page is not viewable, just display the value $out .= $value; } } // populate the return value $event->return = $out; }); If using PHP before 5.3, or using an older version of ProcessWire, you'll need to change the first line to this (below). This syntax also works with newer versions as well, but it's not as pretty as the new syntax. wire()->addHook("PageArray::renderLinks", null, 'hookRenderLinks'); function hookRenderLinks(HookEvent $event) {1 point
-
I'm not sure if i understand your question entirely, it seems too obvious to me, so it might be i miss understood. Anyway, you can connect to as many subdomains as you like. There are no restrictions on linking from pages. On the other hand, you might need to consult your hosting party, if they support subdomains, since this is something that differs from one provider to the other. Maybe you can explain in detail what the goal is for connecting to a subdomain, so that people might give a more specific answer.1 point
-
1 point
-
@Craig: first of all thanks for this module! I did run into a small issue while using it on a SSL server. Mandrill gave me a "Unable to get local issuer SSL certificate" error and did not want to send any e-mails. It was a relatively easy fix but it does require changes in the Mandrill.php. I don't know if it should be changed in the module, but I'm posting it here for anybody else who runs headfirst into this error. 1) I downloaded the following file, renamed it to carcert.pem and placed it in the Mandrill directory. 2) I added the following code after line 72 of Mandrill.php curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, TRUE); curl_setopt($this->ch, CURLOPT_CAINFO, __DIR__ . "/cacert.pem"); And boom! It works (well for me at least). I hope this helps somebody.1 point
-
Hi there! This module might be your easiest option: http://modules.processwire.com/modules/simple-contact-form/ There are other modules and you can also build a contact form manually, so let us know if this doesn't suit your needs and we can provide more info.1 point
-
Maybe Horst module will help you: http://modules.processwire.com/modules/page-tree-add-new-childs-reverse/1 point
-
1: Edit the parent page and under the "Children" tab, there is a "Sort settings..." setting at the bottom. Select "created" from the dropdown and check "Reverse sort direction?" afterwards. 2: There's an autocomplete input field in the popup window at the top saying "Enter a URL, email address, anchor, or enter word(s) to find a page.". Start typing and pages will appear. (you need to enable "pwlink" plugin in your CKEditor field's settings ("Input" tab) to be able to add links) 3. In your actual template, see the "List of fields to display in the admin Page List" setting under the "Advanced" tab. I don't know how to truncate titles though. Using PW 2.6.0 here.1 point
-
wrote an article http://www.okeowoaderemi.com/articles/posts/wordpress-to-processwire-a-guide-for-developers/1 point
-
Got it - thanks to this lovely site: http://www.flamingruby.com/blog/using-hooks-to-alter-default-behavior-of-processwire/1 point
-
You can use the InputfieldMarkup to add custom markup. $field = $modules->get("InputfieldMarkup"); $field->markupText = "<p>your html string here</p>";1 point
-
Just hitting my head to a wall with this: I have defined a field like this: $field = $modules->get("InputfieldRadios"); $field->label = "Gender"; $field->addOption('girl', 'Girl'); $field->addOption('boy', 'Boy'); $field->attr("name+id",'gender'); $form->append($field); and try to save the field after submit with this: $form->processInput($input->post); $uploadpage = new Page(); $uploadpage->gender = $form->gender->value; //OR $uploadpage->set($form->gender->name, $form->gender->value); But it doesn't save the field value. With Ryans FormTemplateProcessor module this template works, but trying to do the "dirty work" manually, I just can't get radiobuttons or checkboxes to save. What is it that I don't understand here? EDIT: OK, Soma helped me on IRC: Change $field->addOption('girl','Girl'); to this: $gender = $pages->get("/options/gender/")->children(); foreach ($gender as $p) { $field->addOption($p->id,$p->title); } This is because I am using pages as options. Then save the field like this: $uploadpage->set($form->gender->name, $form->gender->value); Thanks to Soma!1 point