Jump to content

BitPoet

Members
  • Posts

    1,327
  • Joined

  • Last visited

  • Days Won

    61

Community Answers

  1. BitPoet's post in How to change dbCHARSET? was marked as the answer   
    Sort order isn't really part of the character set, it's decided by the accompanying collation. Currently, PW doesn't set this explicitly, which means it defaults to the default setting of the database (as far as that is applicable to the individual table's character set). Changing the charset to a single-byte one is not advisable nowadays, but you shouldn't need to anyway.
    Simply set your database's collation to utf8_swedish_ci before you install PW.
    ALTER DATABASE whateveryounamedit CHARACTER SET utf8 COLLATE utf8_swedish_ci; After that, any newly created tables with utf8 charset follow the Swedish sorting and substitution rules.
  2. BitPoet's post in Issue with installing third-party module through Processwire 3.0.14 ClassName-Download function was marked as the answer   
    Looks like phil is trying to install it on PW 2.x where namespaces aren't supported. Perhaps add a requirement in getModuleInfo for >= 3.0.10 for all those not looking at the module's description?
        requires => array('ProcessWire>=3.0.10')
  3. BitPoet's post in My replace Textformatter does not work. Please help was marked as the answer   
    The mix of preg_replace_callback and str_replace here doesn't work (throws an "Array to string conversion" error), as the $match passed to the callable is an array of matches (with $match[0] being the entire matched string and $match[1..n] the first to nth capturing group). It would need to either be written as
    function replace($match){ return 'P. Jentschura'; } or, as the others wrote, simply get rid of preg_replace_callback completely and directly perform a str_replace.
    public function formatValue(Page $page, Field $field, &$value) { $value = str_replace('P. Jentschura', 'P. Jentschura', $value); }
  4. BitPoet's post in Remove multiple items from PageArray was marked as the answer   
    $largePargeArray->removeItems($subsetPageArray); should work as PageArray inherits from WireArray.
  5. BitPoet's post in How to create a new user in api with multiple template or parent was marked as the answer   
    (Untested) It should be sufficient to assign the correct value for parent (the User class inherits from Page) and pass the correct template in the constructor.
    $u = new User($templates->get('my-user-parent')); // pass the Template object $u->parent = 222; // you can also pass a Page object or selector string here // continue as usual...
  6. BitPoet's post in Template: Allowed page id(s) for parent was marked as the answer   
    You mean something like this?
  7. BitPoet's post in Absolute URLs for image Paths was marked as the answer   
    Just use httpUrl instead of url.
  8. BitPoet's post in PW3 - ProcessWire::getArray problem was marked as the answer   
    Replace the fuel() call with wire('all') or wire('*') should get it working in 3.0, as LostKobrakai pointed out in this thread.
  9. BitPoet's post in Single Page not returning page? was marked as the answer   
    Can you make sure it isn't a permissions issue (e.g. /styles/base/black being hidden)?
  10. BitPoet's post in Change field-label after page save was marked as the answer   
    Try
    wire('fields')
  11. BitPoet's post in Deleting items in AsmSelect was marked as the answer   
    "equipment" is a page array. You can use the removeAll method to clear it of all items:
    $player->of(false); $player->equipment->removeAll(); $player->save(); $player->of(true);
  12. BitPoet's post in Fieldtype vs. Inputfield - What's the difference? was marked as the answer   
    A good place to start reading would also be the Map Marker field module, which Ryan created as an example.
    In short:
    The Fieldtype is responsible for taking care of saving to and loading from the database as well as sanitizing values, creating the database table(s) and assembling the correct database query from a selector.
    The Inputfield renders the input form elements and processes form input.
    InputfieldMapMarker generates its input elements manually in the render method, but you can also use InputfieldXXX modules (like it does in ___getConfigInputfields) and add those to an InputfieldWrapper, then render that.
  13. BitPoet's post in 404 on Field Save was marked as the answer   
    I wouldn't rule out mod_security then, it's famous for returning that kind of random errors, as there are a lot of parameters that work together to trigger an exception. If possible, I'd look into mod_security's log file to either rule it out or confirm the exact trigger(s), and go from there.
  14. BitPoet's post in "not ready to use" error of FieldtypeImage was marked as the answer   
    It should be sufficient to set the extensions property (i.e. valid file extensions).
  15. BitPoet's post in How to add additional button next to the save button on top (backend) was marked as the answer   
    AFAIK all that's needed should be what ProcessPageEdit::___buildForm does for the "Save + Keep Unpublished" button:
        $submit2->class .= ' ui-priority-secondary head_button_clone';
  16. BitPoet's post in Selector to omit templates that don't have a template file? was marked as the answer   
    It doesn't. Whether a template file matching the name of the template (or the alternative name in the template config) is in fact present in the file system isn't stored in the database.
    You could assemble a list of all templates without file and put that into a selector though:
    $missing = array(); foreach($templates->find("flags!={template::flagSystem}") as $tpl) { if(! $tpl->filenameExists()) $missing[] = $tpl->name; } // Now you can get all pages with missing template file: $pages->find("template=" . implode("|", $missing)); // Or just children $page->children("template=" . implode("|", $missing));
  17. BitPoet's post in Help understanding search results was marked as the answer   
    This is documented behavior. From PW's selector documentation:
  18. BitPoet's post in Can I use Stored Procedure in PW? was marked as the answer   
    Just use PW's $db object and pass the call statement to query() or (prepare()/execute() if you want to reuse the call or use bound parameters). PW's database object is just a wrapper around PHP's PDO class.
  19. BitPoet's post in How can i list child pages regardless of his parents? was marked as the answer   
    All the selector possibilities can be quite a handful to wrap your head around    One nice thing about PageArrays is that they stringify into a pipe-delimitied list of the ids of its contained pages perfect for a selector expression, so you could generalize your code to:
    $categories = wire('pages')->get('/news/')->children(); foreach( wire('pages')->find("parent=$categories, sort=-published") as $news ) {     echo $news->title . '<br>'; }
  20. BitPoet's post in Problem with sorting was marked as the answer   
    The problem's here:
    <?php echo date("Y/m/d h:s", $note->modified); ?> You're outputting seconds instead of minutes. Use "Y/m/d h:i" instead.
  21. BitPoet's post in Find all fields that are multi language was marked as the answer   
    Untested, but every multi language field class should implement FieldtypeLanguageInterface, which you should be able to check for using instanceof.
    if($f->type instanceof FieldtypeLanguageInterface) $langFields->add($f);
  22. BitPoet's post in Import Extern Image to Intern Page Image Field was marked as the answer   
    Looks like allow_url_fopen is disabled in your server's php settings, preventing file functions like copy or file_get_contents from working on URLs. If you can't change that setting, you could download the file manually into a temporary folder using curl and then assign the local path to the temp file (making sure the directory in $config->paths->tmp actually exists beforehand). A quick&dirty take:
    // ...         $localPath = download_file($content->pt_embed_youtube, $config->paths->tmp);         $content->pt_embed_youtube_pixel = $localPath; // ... function download_file($url, $tempdir) {     $fp = $tempdir . basename(parse_url($url, PHP_URL_PATH));     $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; }
  23. BitPoet's post in Weird/rare "SQLSTATE[HY000]: General error: 1116 Too many tables" seen was marked as the answer   
    Huh. This looks like your MySQL server is reachable from everywhere in the internet, which is rarely a good idea. I usually bind only to localhost (if its running on the webserver itself), or add an iptables rule that only allows access from the servers I explicitely grant access to port 3306. For maintenance access, there's always the possibility to use ssh (MySQL CC has that built-in) to forward the connection to *nix systems, or VPN when using Windows hosts. One important measure to be able to pin-point problems quickly is to eliminate as much of the background noise as possible beforehand which port scans and distributed dictionary attacks tend to produce in the logs. Not letting these get to your services in the first place makes your logs much more meaningful.
    I don't think the database log will tell you much though, and the above lines just say that there was a connection attempt from a host that didn't resolve to a name. The most likely source of information would be the webserver log for that time, where you can see the real URL that was requested. If you can get that, also look out for POST requests in the timeframe in question. Mysterious error like yours can (I don't want to stir up panic there, but it would feel wrong not to mention it) sometimes also point to issues that arise by passing on unsanitized form values. The answer is likely much more less dangerous, but taking a look at that never hurts.
    Keep in mind that MySQL sits on the end of the food chain. The webserver log is your most important means to deduce what happened, then the application logs may give you further insight about how it happened.
  24. BitPoet's post in using PW via command line interpreter include was marked as the answer   
    Run "php -i" from the command line. It will list all installed modules, and even more, it will give you the location of the php.ini file used by the php cli - it's not neccessarily the same as your webserver module uses. So on linux, running
    php -i | grep php.ini or on windows
    php -i | findstr php.ini will give you a line reading "Loaded Configuration File => PATH/TO/php.ini". Make sure that this file also loads all required modules.
    It might also be worth it to make sure that the php executable you start in fact belongs to the same installation as the library loaded into the webserver. With the popularity of bundles like [X|W|L|M]AMP I've often seen the path still pointing to outdated older php installations while the server used a far newer version.
  25. BitPoet's post in PW built-in Json API was marked as the answer   
    For users with page-edit permissions, there's also the JSON API in ProcessPageSearch, callable like
    <?= $config->urls->admin ?>page/search/for?template=basic-page&include=hidden
×
×
  • Create New...