/** Display settings in Overview page * * This function tries to get find a display function per type of control * */ public static function getDisplay($args = array(), $class = "") { //$controls = call_user_func_array($c.'::getControls',$c); faf_debug(version_compare(PHP_VERSION, "5.3.0", "<")); // php 5.2 workarounds if (version_compare(PHP_VERSION, "5.3.0", "<")) { $controls = call_user_func_array($class . '::getControls', $class); } else { $c = get_called_class(); $controls = $c::getControls(); } echo "<div class='faf_filterSetting'>"; foreach ($controls as $control) { $cname = $control["name"]; if (isset($args[$cname])) { $value = $args[$cname]; } else { $value = ""; } $type = $control["type"]; if (method_exists($c, "display_" . $type)) { $method = "display_" . $type; // php 5.2 workarounds if (version_compare(PHP_VERSION, "5.3.0", "<")) { call_user_func_array($c . '::' . $method, array($control, $value)); } else { $c::$method($control, $value); } } } echo "</div>"; }
private function save_content() { $xpath = "/html/body/bogus/child::node()"; $DOMXPath = new DOMXPath($this->dom); $snippetNode = $DOMXPath->query($xpath); $targetDom = new DomDocument(); $childNodes = $snippetNode; for ($i = 0; $i < $childNodes->length; $i++) { $importNode = $childNodes->item($i); $importedSnippetNode = $targetDom->importNode($importNode, true); // and append to our child $targetDom->appendChild($importedSnippetNode); } faf_debug($targetDom->saveHTML()); return trim($targetDom->saveHTML()); // trim because saveHTML adds enters for some reason }
/** Sets the metadata of the image for process_complete * * Since post_id's are inserted after the feed update is completed, images are added without any attachment to posts * To fix this this function will set specified metadata to the database (temporary) to match attachment_id's with * post_id's later. This procedure is the same for featured images * * @param $post Array The Post Array * @param $args Array The Filter Args Array * @return array The modified $post Array * */ private function set_metadata($post, $args) { $image_array = $this->image_array; $image_featured = isset($args["faf_image_featured"]) ? $args["faf_image_featured"] : 0; $process = array(); //faf_debug($image_array); foreach ($image_array as $image) { $attach_id = $image["attach_id"]; if (isset($image["attach_id"]) && is_numeric($image["attach_id"])) { if ($image_featured == 1 && !isset($post["meta"]["faf_featured_image"])) { $post["meta"]["faf_featured_image"] = $attach_id; if (isset($image["process_type"])) { $process_type = $image["process_type"]; $img_src = $image["img_src"]; // rather dirty :/ preg_match_all('/<img[^>]+src\\s*=\\s*["\']?([^"\' ]+)[^>]*>/i', $post["post_{$process_type}"], $m, PREG_SET_ORDER); foreach ($m as $match) { if ($match[1] == $img_src) { $post["post_{$process_type}"] = str_replace($match[0], "", $post["post_{$process_type}"]); } } } } $process[] = $attach_id; } else { faf_debug("error with metadata in {$image}"); } } $post["meta"]["faf_process_image"] = implode(",", $process); return $post; }
/** * Filter processing of posts * * Decides on basis of available filters and set options which filters should be invoked * Relies on get_filter_tree to get correct filter sets * * @param Array $args Assoc Array with Wordpress post * @param Object $args2 SyndiPost (Feedwordpress) Object * * @return Array $post Assoc Array with (updated) Wordpress post */ public function faf_decide_filter($args, $args2) { // Syndicate_item hook. $args = assoc array of post to be inserted faf_debug("FAF deciding on filters on post to be syndicated:"); faf_debug($args["post_title"]); faf_debug($args); // return $args; $post = $args; $av_filters = $this->available_filters; if (empty($av_filters)) { // something really wrong return; } // nothing to do // will loop trough all filters selected with this feed. $syndiPost = $args2; // args 2 is of Syndipost class $filter_array = $this->get_filter_tree($syndiPost->link); if (empty($filter_array) || !is_array($filter_array)) { return $post; } // context is page like posts or categories. Defines available filters. foreach ($filter_array as $context => $filters) { foreach ($filters as $index => $filter) { if (isset($filter["filter_name"])) { $filter_name = $filter["filter_name"]; } else { $filter_name = ""; } // no filter no action if (isset($av_filters[$context][$filter_name])) { $filter_function = $av_filters[$context][$filter_name]["filter_function"]; $filter_args = $filter["filter_args"]; faf_debug("Doing filter:" . $filter_function); $filterObj = new $filter_function($post, $filter_args); $post = $filterObj->execute(); // do it! } } } // quality control in case filter crashes, still syndicate posts if (!is_array($post) || count($post) < 1) { faf_debug("Serious problem: Filters returned no post"); $post = $args; } faf_debug("Decide filter: Returning post, everything seems orderly :" . $post["post_title"]); faf_debug($post); return $post; }