function send_mail($email, $subject, $send_email, $send_name, $content, $send_time, $client, $token) { $send_group = intval(create_email($email, $client, $token)); $template_id = intval(create_template($subject, $send_email, $send_name, $content, $client, $token)); $send_group = $send_group . ''; try { //禁止发送的组,多个组用英文逗号隔开 $forbidden_group = '-1'; $client->createPlan($token, $template_id, $send_time, $send_group, $forbidden_group); return "success"; } catch (XML_RPC2_FaultException $e) { // The XMLRPC server returns a XMLRPC error return 'Exception #' . $e->getFaultCode() . ' : ' . $e->getFaultString(); } catch (Exception $e) { // Other errors (HTTP or networking problems...) return 'Exception : ' . $e->getMessage(); } }
function replicate_site($template_descriptions) { global $sites_dir, $source_admin, $target_url, $target_admin, $template_metadata_file; //we first extract all the metadata of the target account, as we will need it to find which files already exists //and therefore should be updated but not created and which do not. These last will have to be created and populated $template_metadata_file = $sites_dir . $target_admin . "_metadata.txt"; generate_ids($target_url, false); /* we will be calling create_template for each of the files passed on the file_description argument. That argument should be a file containing one entry for each file that has to be replicated the structire of each entry is the following: $id:$type:$system_name:$title:$path:$draft:$section_name:$section_id:$layout_name:$layout_id:$liquid_enabled:$handler; In this script, that file is created in the generate_ids function. So, basically what we need to do here is parse each line of that file and replicate the file described in there */ if (!file_exists($template_descriptions)) { fwrite(STDOUT, "ERROR: the file to read the templates description (\"" . $template_descriptions . "\") does not seem to exist."); exit(1); } $templates = file($template_descriptions, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); for ($i = 0; $i < count($templates); $i++) { $id = preg_split("/[:]/", $templates[$i])[0]; $type = preg_split("/[:]/", $templates[$i])[1]; $system_name = preg_split("/[:]/", $templates[$i])[2]; $title = preg_split("/[:]/", $templates[$i])[3]; $path = preg_split("/[:]/", $templates[$i])[4]; $section_name = preg_split("/[:]/", $templates[$i])[5]; $section_id = preg_split("/[:]/", $templates[$i])[6]; $layout_name = preg_split("/[:]/", $templates[$i])[7]; $layout_id = preg_split("/[:]/", $templates[$i])[8]; $liquid_enabled = preg_split("/[:]/", $templates[$i])[9]; $handler = preg_split("/[:]/", $templates[$i])[10]; fwrite(STDOUT, "id=" . $id . ", type=" . $type . ", system_name=" . $system_name . ", title=" . $title . ", path=" . $path . "\n"); //according to the API documentation, all the content of the file to be created shoudl be on the "draft" parameter, so we will extract it from the "published" //section of the source files //if $draft is empty that means that we hsould use all the content of the file in the new destination if ($type == "layout" || $type == "page" || $type == "partial") { $content = file_get_contents($sites_dir . $source_admin . "/" . $title); } else { $content = file_get_contents($sites_dir . $source_admin . "/" . $system_name); } if (!strpos($content, '<published>') == FALSE) { if ($type == "layout" || $type == "page" || $type == "partial") { $content = simplexml_load_file($sites_dir . $source_admin . "/" . $title); } else { $content = simplexml_load_file($sites_dir . $source_admin . "/" . $system_name); } $draft = $content->{'published'}; } else { fwrite(STDOUT, $content); $draft = $content; } /*in order to check if the template exists on the target account, we can check the file <destination_account>_metadata.txt that was created at the beginning of this function if there is a file with the same system_name or path, then we should skip its creation and do the update instead we can use the template_exists function to check if a template is already there */ $exists = template_exists($templates[$i], $template_metadata_file); if ($exists == 0) { //fwrite(STDOUT,"\tCreating template (".$templates[$i].")\n"); create_template($type, $system_name, $title, $path, $section_name, $section_id, $layout_name, $layout_id, $liquid_enabled, $handler, $draft); //fwrite(STDOUT,"\tCREATING>".$type.", ".$system_name.", ".$title.", ".$path.", ".$section_name.", ".$section_id.", ".$layout_name.", ".$layout_id.", ".$liquid_enabled.", ".$handler."\n\n"); } else { //fwrite(STDOUT,"\tUpdating template (".$templates[$i]."), matching id=".$exists."\n"); //update_template($exists,$type,$system_name,$title,$path,$section_name,$section_id,$layout_name,$layout_id,$liquid_enabled,$handler,$draft); //fwrite(STDOUT,"\tUPDATING>".$type.", ".$system_name.", ".$title.", ".$path.", ".$section_name.", ".$section_id.", ".$layout_name.", ".$layout_id.", ".$liquid_enabled.", ".$handler."\n\n"); } } }
/** * Used for editing templates: Either shows show_templates(), edit_template(), save_template() or * create_template() * * @see show_templates(), edit_template(), save_template(), create_template() */ function templates() { global $Pivot_Vars; PageHeader(lang('adminbar', 'templates_title'), 1); PageAnkeiler(lang('userbar', 'admin') . ' » ' . lang('adminbar', 'templates_title')); // if there is an 'action' to do if (isset($Pivot_Vars['doaction'])) { files_action($Pivot_Vars['action'], $Pivot_Vars['check']); } if (isset($Pivot_Vars['edit']) && !isset($Pivot_Vars['template'])) { edit_template(); } else { if (isset($Pivot_Vars['template'])) { save_template(); } else { if (isset($Pivot_Vars['create'])) { create_template(); } else { show_templates(); } } } }